[foreign-jextract] RFR: 8252759: Jextract flattens nested anonymous structs and unions when computing layouts
Jorn Vernee
jvernee at openjdk.java.net
Fri Jan 15 12:13:09 UTC 2021
On Fri, 15 Jan 2021 11:58:31 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/RecordLayoutComputer.java line 108:
>>
>>> 106:
>>> 107: void addFieldLayout(long offset, Type parent, Cursor c) {
>>> 108: MemoryLayout memoryLayout = c.isAnonymousStruct()
>>
>> So, am I right that this avoid flattening of the anon structs fields into enclosing layout - e.g. layouts coming out of the parser now are non-flattened, but we tag them with an attribute so that we can emit flattened accessors later?
>
> Yeah. The layout is only tagged if it is nested inside a parent record layout, since we can only assign a synthetic unique name to it in the context of the parent layout. But, the layout attached to the Declaration object for the anonymous struct will not have this name, since it is created separately outside of the context of the parent struct.
>
> That means that when generating code, and when we counter an anonymous nested struct/union decl in visitScoped, we have to look up it's layout in the layout of the parent in order to find the context dependent name we attached here. The attribute is used to find anonymous layouts. Technically we could also check if the name starts with `$anon$` instead of looking for the attribute, but doing it this way seemed more robust.
The name on the anonymous struct itself is needed to create a layout path to the nested field.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/434
More information about the panama-dev
mailing list