openjdk / panama-foreign Public
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
8261511: jextract fails to handle name clashes between unrelated constants #468
Conversation
|
Webrevs
|
@@ -86,6 +86,10 @@ protected void emitImportSection() { | |||
|
|||
@Override | |||
protected void emitWithConstantClass(String javaName, Consumer<ConstantBuilder> constantConsumer) { | |||
enclosing.emitWithConstantClass(javaName, constantConsumer); | |||
if (kind == Kind.INTERFACE) { |
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.
Not super sure about this fix.
If I undrerstand correctly, this will generate a nested constant class inside the enclosing struct, right (rather than going back to the enclosing header class). This is ok for clashes between header functions and function pointers, but how about cases like:
struct Foo {
int (*sum)(int x, int y);
struct Bar {
int (*sum)(float x, float y);
} bar;
};
I tried this, and it seems like we're probably ok, there are only two possible cases here:
-
the innermost struct is anon (e.g. doesn't have a name, and doesn't introduce a new struct field) - in this case it is an error if the anon struct declares a field that clashes with some enclosing field
-
the innermost struct is not anon (e.g. has a name, or introduces a struct field name); in this case a nested struct class is generated, and constants are added in there instead.
So, I believe the logic works, but I think it generates a redundant constant class (note that the struct class already acts as a constant holder - in fact, StructBuilder extends ConstantBuilder).
It would be nice if, instead, this method would do something like:
public void emitWithConstantClass(String javaName, Consumer<ConstantBuilder> constantConsumer) {
if (this instanceof ConstantBuilder cb) {
// use this class to emit constants
constantConsumer.accept(cb);
} else {
enclosing.emitWithConstantClass(javaName, constantConsumer);
}
}
By doing so, we should skip the generation of the extra constant class?
Looks good - as discussed offline there is a risk (present already) that reusing structs as constant holder might end up with scalability issues (e.g, if a struct has too many fields) so we probably will have to keep an eye on this.
@sundararajana This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the
|
/integrate |
@sundararajana Pushed as commit a11bb7d. |
constants class is nested properly. piggybacking to fix long whitespace string in pretty printer
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/panama-foreign pull/468/head:pull/468
$ git checkout pull/468