[code-reflection] RFR: Add isQuotable attribute to LambdaOp

Paul Sandoz psandoz at openjdk.org
Wed Sep 3 20:22:01 UTC 2025


On Wed, 3 Sep 2025 20:00:54 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

> In the `interpreter` and `ByteCodeGenerator` we detect if a lambda is quotable based on its functional interface. This approach will not work if intersection type is used e.g. `Runnable r = (Runnable & Quotable) () -> {};` This PR adds a flag to LambdaOp that will be set by the `javac` for quotable lambdas.

src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java line 177:

> 175:             public Builder quotable() {
> 176:                 this.quotable = true;
> 177:                 return this;

Instead return a new instance of the Builder so its immutable, thereby quotable can be final.

src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java line 191:

> 189:             boolean isQuotable = def.extractAttributeValue(ATTRIBUTE_LAMBDA_IS_QUOTABLE,
> 190:                     false, v -> switch (v) {
> 191:                         case Boolean b -> b;

Can we use the `boolean` primitive type?

src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java line 264:

> 262:             m.put(ATTRIBUTE_LAMBDA_IS_QUOTABLE, isQuotable);
> 263:             return Collections.unmodifiableMap(m);
> 264:         }

Use `Map.of`.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/545#discussion_r2320082653
PR Review Comment: https://git.openjdk.org/babylon/pull/545#discussion_r2320085867
PR Review Comment: https://git.openjdk.org/babylon/pull/545#discussion_r2320083208


More information about the babylon-dev mailing list