-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Sema: allow field access instructions to be emitted at comptime #15287
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
Conversation
Going to extend to a few other things (tuples, unions, arrays) |
a3186ea
to
b3307a3
Compare
#14819 changed some miscellaneous length accesses to magic numbers. It might be good to revert those changes if this PR re-enables the behavior. Example: |
Related to 34e4b07. This makes `struct.arr.len` succeed at comptime. Resolves: ziglang#15280
Comptime evaluation is allowed to create intermediate runtime instructions provided the final result is comptime-known, for accesses such as `runtime_arr.len` or `runtime_struct.comptime_field`.
b3307a3
to
fb6ee2f
Compare
Good shout - done. @ reviewers: regarding the second commit, it turned out that doing this validation everywhere made a lot of compile errors worse. This makes sense, since it's more useful for e.g. |
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 don't have a suggestion for a better name but the current one didn't immediately make it clear that the difference comes from explicitly using the comptime syntax.
@@ -24126,6 +24154,8 @@ fn tupleFieldValByIndex( | |||
field_index: u32, | |||
tuple_ty: Type, | |||
) CompileError!Air.Inst.Ref { | |||
_ = src; |
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.
Remove this parameter.
I'd like to give this another look - you mind rebasing and conflict fixing, @mlugg? |
Sure thing. I may be a bit busy over the next couple of days with work stuff, but I'll put this on my list and try to get it done within the next week or so! |
Closing abandoned PR |
Related to 34e4b07. This makes
struct.arr.len
succeed at comptime.Resolves: #15280