RFR: 7903587: Revisit inlining of struct layouts into other layouts/descriptors
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Dec 12 12:33:52 UTC 2023
This PR completes the sequence of changes that I've been working on, by allowing layout and descriptor strings to be generated directly from jextract types. This allows for generated layouts to respect the "structure" found in the corresponding C header. Consider this case:
struct Point {
int x;
int y;
};
struct Rectangle {
struct Point topLeft;
struct Point bottomRight;
};
With the changes in this PR, the generate layout for `Rectangle` becomes:
private static final MemoryLayout $LAYOUT = MemoryLayout.structLayout(
Point.$LAYOUT().withName("topLeft"),
Point.$LAYOUT().withName("bottomRight")
).withName("Rectangle");
Note how the layout for `Point` is no longer inlined, but instead is referred to "by name".
The patch is quite straightforward, and aims at replacing the functions Declaration/Type.layoutFor/descriptorFor with new functions (now in the builder hierarchy) which generate layout and descriptor strings from the corresponding jextract types.
Note: this patch introduces some additional issues when it comes with static initializer circularities. These issues will be dealt with in a separate change (since we have started accumulating some of these since https://git.openjdk.org/jextract/pull/145)
-------------
Commit messages:
- Fix whitespaces
- Remove unused imports
- Initial push
Changes: https://git.openjdk.org/jextract/pull/157/files
Webrev: https://webrevs.openjdk.org/?repo=jextract&pr=157&range=00
Issue: https://bugs.openjdk.org/browse/CODETOOLS-7903587
Stats: 686 lines in 16 files changed: 130 ins; 509 del; 47 mod
Patch: https://git.openjdk.org/jextract/pull/157.diff
Fetch: git fetch https://git.openjdk.org/jextract.git pull/157/head:pull/157
PR: https://git.openjdk.org/jextract/pull/157
More information about the jextract-dev
mailing list