[foreign-preview] RFR: 8282026: Remove support for unbound sequence layouts [v3]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon Feb 21 11:41:49 UTC 2022


> When doing a pass over the memory layout API, I couldn't help noting that the API implementation and specification are made more complex by the fact that we have to specify what happens when a sequence layout *without a size* is found. Support for unbounded sequence layout was added many moons ago, with the understanding that it would have made life for jextract easier.
> 
> This is not the case; all cases where jextract is using an unbounded sequence layout today can be replaced with using a simple zero-length sequence (which is allowed by the API, as are empty structs/unions).
> 
> I also found that the only real use case for using unbounded sequence layout came from a quirk in the API to obtain var handles from layout. That is, if we want to obtain an indexed var handle into a JAVA_INT, we have to do the following:
> 
> 
> VarHandle intHandle = MemoryLayout.newSequenceLayout(JAVA_INT)
>             .varHandle(PathElement.sequenceLayout());
> 
> 
> In hindsight, this is just boilerplate: in this case the user only cares about the element layout (`JAVA_INT`), but the API wants the user to wrap that element layout in a new sequence layout, only to then provide a path inside the sequence layout (which will add a free dimension to the resulting var handle).
> 
> It is not hard to see that all the above can be simplified, by adding an extra API method on memory layouts:
> 
> 
> VarHandle intHandle = JAVA_INT.arrayElementVarHandle(JAVA_INT);
> 
> 
> This more explicit, succint, and provdies less opportunities for bugs to hide.
> 
> Therefore, this patch removes support for unbounded sequence element; the net effect is that now _all_ layouts have a size - which significantly simplifies the use sites where layout sizes are computed (no need to use optional there). All without losing much in terms of expressiveness: zero-length sequence layout can be used in basically the same way in which unbounded sequence layouts were used before.

Maurizio Cimadamore has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains two new commits since the last revision:

 - Drop arrayElementSliceHandle
 - Remove unused imports

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

Changes:
  - all: https://git.openjdk.java.net/panama-foreign/pull/642/files
  - new: https://git.openjdk.java.net/panama-foreign/pull/642/files/a954e84e..bd95f06d

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=642&range=02
 - incr: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=642&range=01-02

  Stats: 47 lines in 2 files changed: 0 ins; 47 del; 0 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/642.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/642/head:pull/642

PR: https://git.openjdk.java.net/panama-foreign/pull/642


More information about the panama-dev mailing list