RFR: 7903644: typedef of anonymous struct generates a redundant class [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Jan 25 22:03:03 UTC 2024


On Thu, 25 Jan 2024 20:33:30 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> src/main/java/org/openjdk/jextract/impl/NameMangler.java line 211:
>> 
>>> 209:             // We may potentially generate a class for a typedef. Make sure
>>> 210:             // class name is unique in the current nesting context.
>>> 211:             javaName = curScope.uniqueNestedClassName(typedef.name());
>> 
>> This logic is a bit subtle: we have to avoid calling `uniqueNestedClassName` in case there's a struct that will inherit the typedef name - otherwise the mangler will see _two_ attempts to add the typedef name to the current scope, which will result in extra mangling.
>
> This seems a bit ad-hoc... Suggestion: the `Scope` constructor tries to generate a unique nested class name if `parent` is not `null`. That's only the case when calling `newStruct`, which is only called from `visitScoped`. So, I think we can move the logic that computes the nested class name from the `Scope` constructor to `visitScoped` (to the `else` branch this patch adds). Then we can just pass the unmangled name from the `if` branch to `newStruct`, and there should be no need to have this logic here.

Thanks for the suggestion - I did think of something similar, but had not realized we only needed the mangling in one place. Updated the code, looks a bit better I think.

-------------

PR Review Comment: https://git.openjdk.org/jextract/pull/195#discussion_r1467006896


More information about the jextract-dev mailing list