sema: Improvements to union and struct layout resolution to solve a false-positive circular dependency error#17490
Conversation
|
I don't understand what the titular feature of this PR is doing. Clearly, in order to determine the ABI size of a union, we must know the size of all of its fields. Determining ABI size is a subset of layout resolution, so to resolve the former without resolving the latter (as is in the title of this PR) would imply that there exists some type whose size we can determine without fully resolving its in-memory layout. This seems contradictory to the whole idea of layout resolution. Do you have an example of such a case? (That is, a case where resolving a type's size requires less information than resolving its layout.) |
93d503c to
428f970
Compare
@mlugg Sorry, the original title was poor - it was the commit message of my initial changes before I really understood what was going on. I've updated the title and description now. |
88489bb to
981e001
Compare
- Add resolveUnionAlignment, to resolve a union's alignment only, without triggering layout resolution - Update resolveUnionLayout to cache size, alignment, and padding - Resolve a false-positive circular dependency error when a union or struct uses @typeinfo on itself (such as std.mem.zeroes)
981e001 to
3a89324
Compare
|
For reviewer's reference (and as a justification for |
|
After talking with @mlugg, I've decided to extra just the union alignment portion into #17658, and work on a different way to solve this circular dependency.
|
Fixes #17287
Fixes #17533
These changes bring unions up to speed with structs in terms of alignment and size resolution. The main goal of this PR was to resolve the circular dependency error you used to get when doing something like this:
Since the fields are pointer types, there isn't actually a circular dependency here.
Changes:
resolveUnionAlignment, to resolve a union's alignment only, without triggering layout resolution.resolveUnionLayoutto cache size, alignment, and padding.abiSizeAdvancedandabiAlignmentAdvancednow use this information instead of computing it each time.@typeInfoon itself (such as std.mem.zeroes), when it has a field who's type refers to the containing type through a pointer.