RFR: 7903587: Revisit inlining of struct layouts into other layouts/descriptors [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Dec 12 15:51:59 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)

Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:

  Add new packed struct test

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

Changes:
  - all: https://git.openjdk.org/jextract/pull/157/files
  - new: https://git.openjdk.org/jextract/pull/157/files/10544de7..39a0ea92

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jextract&pr=157&range=01
 - incr: https://webrevs.openjdk.org/?repo=jextract&pr=157&range=00-01

  Stats: 158 lines in 4 files changed: 147 ins; 1 del; 10 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