refactor(codegen): type safe inkwell types#202
Merged
baszalmstra merged 7 commits intomun-lang:masterfrom Jun 2, 2020
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #202 +/- ##
==========================================
- Coverage 82.95% 82.08% -0.87%
==========================================
Files 163 174 +11
Lines 11514 11665 +151
==========================================
+ Hits 9551 9575 +24
- Misses 1963 2090 +127
Continue to review full report at Codecov.
|
61c12b2 to
f6d8cb3
Compare
9352194 to
a4ed234
Compare
Wodann
requested changes
Jun 1, 2020
Collaborator
Wodann
left a comment
There was a problem hiding this comment.
Props for this change. 👏 I had some minor requests for change.
Wodann
reviewed
Jun 2, 2020
0b64c3b to
305b008
Compare
Wodann
approved these changes
Jun 2, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inkwell uses types that lose a lot of type information. An
u8,u16,i8, and16are all represented by anIntValue. This takes some careful management of these types. ForIntValuethe problem is not so bad but forPointerValueandStructValuethis is a real issue. By usingStructValueyou lose all information in the type with what kind of value you are actually working. This is not so much a problem for dynamic types (like Mun structs) but it is a major risk when using abi types. I feel that this is major technical depth.This PR introduces a new type
Value<T>that contains an inkwell value but it is typed onTwhich is the type that constructed the value. This allows you to write:It also allows much cleaner conversion from regular Rust types to inkwell types. e.g.
There are 3 ways to enable custom types to work with this system:
Implement the
TransparentValuetrait which converts the implementor into anotherValue<T>. But in turn it also allows the implementor to be represented as aValue<Self>:The resulting IR type will be an anonymous type:
type { u32, f32 }Auto derive the
AsValuetrait e.g.:The resulting IR type will be a named type:
%Foo = type { u32, f32 }You can also implement all the support traits yourself for a custom type.
I already found a few bugs in the LLVM ir that have been fixed.
TODO
abi_types.rsto use the types fromValue<T>sValue<T>typesir::TypeInfoshould equalabi::TypeInfo)ir.rs) (do in a later PR)