-
Notifications
You must be signed in to change notification settings - Fork 68
7903933: Move sharable items from different generations to a common file #278
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back nbenalla! A progress list of the required criteria for merging this PR into |
@nizarbenalla 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 1 new commit pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@mcimadamore) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Webrevs
|
@nizarbenalla This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
cleanup: longer cmd option `framework` should use -- rather than - small other cleanups
I wasn't happy with the previous approach/implementation and started over from scratch, also did some small cleanup (the newly added option for framworks should use Shared items from multiple generation will only be moved to a class if the user specifies the |
Adding an option to move shared items in a separate class feels like taking a shortcut. Let's look what's inside this bag of shared items (it used to be much bigger, so good news there):
I believe (1) should probably not belong in a separate class from the headers. The way I see it is that it should belong where the library lookups belongs to. Even if you run multiple extractions it is less clear to me as to whether there should be a single lifetime for all the different libraries or not (and, eventually, we want aspects such as this to be customizable via subclassing). (2) seems a very useful debug option, and I think we should think about making it more official -- for instance with a linker option. (3) is a general purpose method that would make sense to feature in the main MemoryLayout API. (4) seems to be superseded by a similar method that was added in Java 23: (5) seems like it could be inlined in the functional interface classes (it's just an helper to allow clients to create an upcall stub w/o the need to do a MethodHandle lookup -- which needs a try/catch). Then there's (6). The first reaction I got was: well, whether primitive layouts should be emitted or not seems like another filtering decision (e.g. let's add some options to filter these out). Except this would not work -- it's not just about filtering -- it's also about telling every other file where to find the layouts for such primitive types. If they are defined somewhere else, then jextract need to know where to find them (e.g. if they are referenced by some other layout jextract is building). Which seems a similar problem as the one this PR is trying to solve anyway. Stepping back -- I think if we look back, jetxract used to generate a RuntimeHelper class, and then everything else. While we moved away from that generation scheme (now we just emit header classes), the shared functionalities are still there. Perhaps a move in a good direction would be to:
This is similar, in spirit, to what you have here, but with the advantage that there's only one generation scheme, not two -- e.g. the superclass with the shared symbol is always there -- only sometimes it can have a different name (because the user said so). Whether we want that default superclass name to be But I do think that we should try and make that shared class as small as possible -- most of the functionality there seems like it could belong in the main FFM API, and it would provide value even for clients not running on top of jextract. |
Note/history: while tempting, we can't really put (6) inside the main FFM API. We have thought about this for a long time -- the issue is that the types of the primitive layouts is not guaranteed to be stable. E.g. |
Also on this topic: for now we're mostly concerned about different extractions not repeating the code for primitive layouts and helper functions. This feels more like a "tip of the iceberg" kind of situation. For instance, you might have two libraries A and B, which both include the header of some third library C. Maybe you want to extract C separately, and then extract A and B so that they somehow magically point at the extracted bindings for C. Now sharing would be not just about primitive types, but about functions, structs and much more. At the same time, going down this path can be very complex: A and B might pull in slightly different versions of C, or use some So, hidden somewhere in here there's a theme of: how do we move jextract to go from a per-extraction set of bindings to a multi-extraction friendly model. And going down this path will likely, I think, result in opening a big and complicated can of worms. I'm not saying we'll never get there -- but there's a limit with what we can express with simple command line options. |
Should we just give the base header a common name then, so that if you generate multiple times, you get sharing automatically? Maybe it could be named something like |
Yes, see
|
I meant to remove this when targeting jdk 23, it seems I left it by mistake. I will remove it to reduce the number of shared items we're dealing with. |
- Add option to override the name of the shared symbol class
I've moved the shared symbols to a different class The new command line option was renamed to |
The option for changing header class name is called |
private static HeaderFileBuilder createFirstHeader(SourceFileBuilder sfb, List<Options.Library> libs, boolean useSystemLoadLibrary) { | ||
HeaderFileBuilder first = new HeaderFileBuilder(sfb, String.format("%1$s#{SUFFIX}",sfb.className()), null, sfb.className()); | ||
HeaderFileBuilder first = new HeaderFileBuilder(sfb, String.format("%1$s#{SUFFIX}",sfb.className()), SHARED, sfb.className()); | ||
first.appendBlankLine(); | ||
first.classBegin(); | ||
first.emitDefaultConstructor(); | ||
first.emitRuntimeHelperMethods(); |
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.
Shouldn't the runtime helper methods end up in the shared class?
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.
Fixed in 5c8802a, I thought only the shared symbols belonged in the separate class.
I did not move the library arena to the separate class and instead kept it close to the symbol lookup.
private void createSharedClass() { | ||
SourceFileBuilder sfb = SourceFileBuilder.newSourceFile(packageName(), SHARED); | ||
HeaderFileBuilder sharedBuilder = new HeaderFileBuilder(sfb, SHARED, null, SHARED); | ||
sharedBuilder.appendBlankLine(); |
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.
There seems to be a lot of overlapping between the code here and the one in nextHeader
-- especially now that the first header is not really meant to have a lot of special things (the only exception being the symbol lookup logic).
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.
Fixed, I consolidated the shared code in some methods. I ran into issues with the java files having the wrong name so I had to change the logic a little.
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.
Very nice cleanup! Looks good
I pushed a small test-only update, I was seeing some failures in the CI (that I didn't see locally). This fixes it, |
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.
Good catch!
Thanks for all the rounds of reviews. /integrate |
@nizarbenalla |
void emitLibaryArena(){appendIndentedLines(""" | ||
static final Arena LIBRARY_ARENA = Arena.ofAuto();"""); | ||
} |
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.
void emitLibaryArena(){appendIndentedLines(""" | |
static final Arena LIBRARY_ARENA = Arena.ofAuto();"""); | |
} | |
void emitLibaryArena(){ | |
appendIndentedLines(""" | |
static final Arena LIBRARY_ARENA = Arena.ofAuto();"""); | |
} |
public String sharedSymbolsFile; | ||
|
||
public String getSharedSymbolsFile() { | ||
return sharedSymbolsFile; | ||
} |
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.
Uhm, I think this should just be in Options
, not in IncludeHelper
, since it's not related to the --include
options.
@@ -43,48 +43,76 @@ class ToplevelBuilder implements OutputFactory.Builder { | |||
private static final int DECLS_PER_HEADER_CLASS = Integer.getInteger("jextract.decls.per.header", 1000); | |||
public static final String PREV_SUFFIX = "#{PREV_SUFFIX}"; | |||
private static final String SUFFIX = "#{SUFFIX}"; | |||
private static String SHARED; |
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.
I think this was supposed to be final
?
private static String SHARED; | |
private final String shared; |
| `--output <path>` | specify where to place generated files | | ||
| `--dump-includes <String>` | dump included symbols into specified file (see below) | | ||
| `--include-[function,constant,struct,union,typedef,var]<String>` | Include a symbol of the given name and kind in the generated bindings. When one of these options is specified, any symbol that is not matched by any specified filters is omitted from the generated bindings. | | ||
| `--symbols-class-name <name>` | override the name of the root header class | |
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.
| `--symbols-class-name <name>` | override the name of the root header class | | |
| `--symbols-class-name <name>` | override the name of the root header class | |
@@ -84,6 +85,7 @@ Option Description | |||
\ option is not specified, then current directory is used. \n\ | |||
-t, --target-package <package> target package name for the generated classes. If this option\n\ | |||
\ is not specified, then unnamed package is used. \n\ | |||
--symbols-class-name <name> override the name of the root header class \n\ |
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.
--symbols-class-name <name> override the name of the root header class \n\ | |
--symbols-class-name <name> override the name of the root header class \n\ |
@@ -42,7 +42,7 @@ final class FunctionalInterfaceBuilder extends ClassSourceBuilder { | |||
|
|||
private FunctionalInterfaceBuilder(SourceFileBuilder builder, String className, ClassSourceBuilder enclosing, | |||
String runtimeHelperName, Type.Function funcType, boolean isNested) { | |||
super(builder, isNested ? "public static" : "public", Kind.CLASS, className, null, enclosing, runtimeHelperName); | |||
super(builder, isNested ? "public final static" : "public final", Kind.CLASS, className, null, enclosing, runtimeHelperName); |
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.
Changes in this file seem unrelated? Leftover from other work?
@@ -192,7 +192,7 @@ public void testStructMember(String structName, MemoryLayout memberLayout, Class | |||
@Test(dataProvider = "functionalInterfaces") | |||
public void testFunctionalInterface(String name, MethodType type) { | |||
Class<?> fpClass = loader.loadClass("com.acme." + name); | |||
checkDefaultConstructor(fpClass); | |||
checkPrivateConstructor(fpClass); |
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.
Same here, these changes seem unrelated.
Please review this patch to move the
C_*
layouts and the static utility methods into separate classes:LayoutUtils.java
andFFMUtils.java
, respectively.-t
option is no used and the files are generated into the default package, in that case we use the classname to call the static methods or use theC_*
constants.Some tests had to be modified slightly, either by adding new static imports or replacing classnames.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jextract.git pull/278/head:pull/278
$ git checkout pull/278
Update a local copy of the PR:
$ git checkout pull/278
$ git pull https://git.openjdk.org/jextract.git pull/278/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 278
View PR using the GUI difftool:
$ git pr show -t 278
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jextract/pull/278.diff
Using Webrev
Link to Webrev Comment