[code-reflection] RFR: Unify common code of SwitchStatementOp and SwitchExpressionOp [v2]

Paul Sandoz psandoz at openjdk.org
Mon Sep 9 16:30:25 UTC 2024


On Sat, 7 Sep 2024 02:41:57 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

>> Unify common code of SwitchStatementOp and SwitchExpressionOp.
>
> Mourad Abbay has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
> 
>  - Merge branch 'code-reflection' into unify-sw-op
>  - Refactor

src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 898:

> 896:     }
> 897: 
> 898:     abstract static sealed class JavaSwitch extends ExtendedOp implements Op.Nested, Op.Lowerable

Rename to `JavaSwitchOp` and make it public.

src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 973:

> 971:             } else {
> 972:                 exit = b.block(resultType());
> 973:                 if (result() != null) { // i.e. resultType not void

All operations in a built model have a result value, even if it's a void value. So this expression will always be true. Use a `this instanceof ...` test?

src/java.base/share/classes/java/lang/reflect/code/op/ExtendedOp.java line 1009:

> 1007:                         switch (op) {
> 1008:                             case YieldOp yop when yop.operands().isEmpty() -> block.op(branch(exit.successor()));
> 1009:                             case YieldOp yop -> block.op(branch(exit.successor(block.context().getValue(yop.yieldValue()))));

It might be clearer to test against the concrete switch class e.g., `case YieldOp yop when this instanceof ...`.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/222#discussion_r1750548469
PR Review Comment: https://git.openjdk.org/babylon/pull/222#discussion_r1750566611
PR Review Comment: https://git.openjdk.org/babylon/pull/222#discussion_r1750562530


More information about the babylon-dev mailing list