-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
sema: analyze struct field bodies in a second pass, to allow them to use the layout of the struct itself #17692
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
6e2b8f0
to
99e04b5
Compare
Fixes #14005 |
I added this as a test case and it revealed an unnecessary call I was making to |
b1a7361
to
57dfc46
Compare
405a821
to
c6a0304
Compare
I've added a fix for the CBE not handling union representations with an unknown tag - this was broken since #17352. One of the new tests cases in this PR depends on this working. |
As a note, you accidentally left in both EDIT: ah, you removed it in a later commit - no worries, if it's okay with you @kcbanner I'm gonna force-push to your branch in a moment to reshuffle a few commits, but no material changes |
c6a0304
to
66c0110
Compare
I've addressed your feedback and made a couple fixes in the new test cases for big-endian arches. Feel free to shuffle commits, thanks! |
07fe641
to
da195f9
Compare
Rebased to resolve conflicts. |
da195f9
to
b999908
Compare
Fixes #17563 |
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.
Sorry for how long it took me to get around to this - it all looks good. I'm going to do one final rebase (and shuffle a few commits around), then I'll set this to auto-merge. Thanks!
(EDIT: "shuffle a few commits around" ended up meaning "squash basically everything", but I think everything's still there!)
b999908
to
59f145c
Compare
59f145c
to
1e6bcc5
Compare
This change allows struct field inits to use layout information of their own struct without causing a circular dependency. `semaStructFields` caches the ranges of the init bodies in the `StructType` trailing data. The init bodies are then resolved by `resolveStructFieldInits`, which is called before the inits are actually required. Within the init bodies, the struct decl's instruction is repurposed to refer to the field type itself. This is to allow us to easily rebuild the inst_map mapping required for the init body instructions to refer to the field type. Thanks to @mlugg for the guidance on this one!
This was regressed in d657b6c, when the comptime memory model for unions was changed to allow them to have no defined tag type.
…no defined tag type
1e6bcc5
to
1acb6a5
Compare
This broke #17892. I haven't tracked it down yet but I have a stack trace of optimized CBE: #17892 (comment) Also I don't like those changes to packed struct representation because I don't think a I should add though, thank you, this is good work 👍 |
Good point on the packed struct flags - I'm not sure if we can eliminate those bits entirely, but if not then I'd suggest we could perhaps repurpose a few bits of |
This caused a false
|
…tion pointer field b3462b7 caused a regression in a third-party project, since it forced resolution of field initializers for any field call 'foo.bar()', despite this only being necessary when 'bar' is a comptime field. See ziglang#17692 (comment).
If we can steal those two bits from |
…tion pointer field b3462b7 caused a regression in a third-party project, since it forced resolution of field initializers for any field call 'foo.bar()', despite this only being necessary when 'bar' is a comptime field. See #17692 (comment).
This PR is based off of #17658.
The main goal of this PR was to resolve the circular dependency error you used to get when doing something like this:
This is accomplished by breaking out the struct field init body resolution into a separate pass, so it can happen after the struct's layout has been resolved.
semaStructFields
now caches the ranges of the init bodies in theStructType
trailing data. The init bodies are then resolved byresolveStructFieldInits
, which is called before the inits are actually required. Within the init bodies, the struct decl's instruction is repurposed to refer to the field type itself. This is to allow us to easily rebuild theinst_map
mapping required for the init body instructions to refer to the field type. Thanks to @mlugg for the guidance on this one!An additional benefit of this change is that we no longer need to make incorrect guesses about struct alignment when a field init wants to use its container's alignment. Previously, this test would fail because the struct alignment would be guessed to be pointer-aligned:
I updated the alignment guessing logic to mark if the guess was made, and it's checked in
resolveStructLayout
. I added a similar check for unions as well.I checked to see if the guessing logic could be removed entirely, but there are some cases where it's still required:
I may look into how to resolve that in a future PR.
Additional changes: