RFR: 7903584: Revisit struct accessors
Jorn Vernee
jvernee at openjdk.org
Mon Jan 15 15:24:14 UTC 2024
Drop the `$get` and `$set` from the getter/setter names.
To ensure that we don't run into any clashes with the indexed accessors on structs (e.g. because a `long` field setter would clash with the indexed getter), we replace the indexed accessors with a 'asSlice' method which can be used to slice a given pointer using an index. This turns the following access pattern:
MemorySegment arr = ...
int x = Foo.x$get(arr, 10); // old
Into this:
MemorySegment arr = ...
MemorySegment theFoo = Foo.asSlice(arr, 10);
int x = Foo.x(theFoo); // new
This then allows us to drop the indexed accessors altogether, thus avoiding a name clash.
---
This patch also drops the getters (both fro globals and struct fields) which return instances of a functional interface. There is an issue that the new getter name will clash with the FI instance getter (which was already using the nice name), but when discussing this with Maurizio we realized that returning wrappers, like these FI instances, is not really in the spirit of the current 'all-static' approach that jextract takes. So, this patch drops the FI instance getters. For now, the samples will manually wrap the address in an FI instance, until we address: https://bugs.openjdk.org/browse/CODETOOLS-7903628
Note: I did not test the LibffmpegMain and PanamaTime changes.
-------------
Commit messages:
- rename emitAsSlice
- update non-windows samples too (eyeballed)
- rename $at to asSlice
- drop FI getters
- rename global getters too
- drop $get $set and $slice from names
- add $at method
Changes: https://git.openjdk.org/jextract/pull/175/files
Webrev: https://webrevs.openjdk.org/?repo=jextract&pr=175&range=00
Issue: https://bugs.openjdk.org/browse/CODETOOLS-7903584
Stats: 247 lines in 32 files changed: 15 ins; 112 del; 120 mod
Patch: https://git.openjdk.org/jextract/pull/175.diff
Fetch: git fetch https://git.openjdk.org/jextract.git pull/175/head:pull/175
PR: https://git.openjdk.org/jextract/pull/175
More information about the jextract-dev
mailing list