Skip to content

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

Merged
merged 1 commit into from
Sep 4, 2019
Merged

Add @Type builtin #3111

merged 1 commit into from
Sep 4, 2019

Conversation

marler8997
Copy link
Contributor

@marler8997 marler8997 commented Aug 22, 2019

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.

@marler8997 marler8997 force-pushed the typeBuiltin branch 10 times, most recently from 6114c3d to 73387d6 Compare August 23, 2019 01:52
@marler8997 marler8997 marked this pull request as ready for review August 23, 2019 02:06
@marler8997 marler8997 force-pushed the typeBuiltin branch 4 times, most recently from 7174901 to 70ae090 Compare August 24, 2019 07:24
@andrewrk andrewrk added this to the 0.5.0 milestone Aug 27, 2019
Copy link
Member

@andrewrk andrewrk left a 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) {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

@andrewrk andrewrk Sep 4, 2019

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.

@marler8997 marler8997 force-pushed the typeBuiltin branch 3 times, most recently from 679a427 to 9633196 Compare September 4, 2019 04:45
@andrewrk andrewrk merged commit b728cb6 into ziglang:master Sep 4, 2019
@marler8997 marler8997 deleted the typeBuiltin branch September 4, 2019 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants