-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add @Type builtin #3111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add @Type builtin #3111
Conversation
6114c3d
to
73387d6
Compare
73387d6
to
b4fd04b
Compare
7174901
to
70ae090
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
src/ir.cpp
Outdated
@@ -19837,6 +19860,18 @@ static uint32_t ptr_len_to_size_enum_index(PtrLen ptr_len) { | |||
zig_unreachable(); | |||
} | |||
|
|||
static PtrLen size_enum_index_to_ptr_len(uint32_t size_enum_index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some way to set this up such that if that enum ever changes, we'll get a compile error here, or at least something easily debuggable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what I would do is define the enum values of builtin.Size
in some data structure, then generate both the builtin code and an enum that the C++ compiler can use. Then instead of using hardcoded values of 0
, 1
, 2
, and 3
, you could use something like BUILTIN_SIZE_ONE
BUILTIN_SIZE_MANY
BUILTIN_SIZE_SLICE
and BUILTIN_SLICE_C
.
But this design would take a bit of work, I would think it would warrant a separate PR. Unless you have a simpler idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a simpler idea: static_assert
. As long as we get a compile error nearby the code that needs to be changed, everything is fine.
679a427
to
9633196
Compare
9633196
to
b728cb6
Compare
Implement proposal #2907 (ability to create primitive types from TypeInfo, but not necessarily aggregate types)
Because of existing/surrounding code...this PR mostly wrote itself.
Let me know if you'd like me to implement any more types.