RFR: 8357185: Redundant local variables with unconditionally matching primitive patterns [v2]

Aggelos Biboudis abimpoudis at openjdk.org
Thu Jul 3 19:48:38 UTC 2025


On Thu, 3 Jul 2025 15:31:01 GMT, Chen Liang <liach at openjdk.org> wrote:

>> A commit in the implementation of JEP 455, https://github.com/openjdk/jdk/pull/15638/commits/ceee1e4c08457a0793fdfb556db99e057a947af1, added redundant synthetic local variable for trivial `instanceof int`-ish type conversion operations in the javac AST. Such conversions have been present since the introduction of record patterns, and previously they consistently lower to the part before `instanceof`. With this change, the introduced redundant variable is visible in the class file, as seen in the JBS issue.
>> 
>> Testing: langtools/tools/javac
>
> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Further improvements and testing per suggestions

Looks good from my side.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 2840:

> 2838:             if (types.isUnconditionallyExact(tree.expr.type, tree.pattern.type)) {
> 2839:                 // instanceOfExpr; true
> 2840:                 sideEffect = make.Exec(instanceOfExpr);

maybe `evaluatedLHS` or `memoizedLHS`.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 2880:

> 2878:                 }
> 2879:             } else {
> 2880:                 throw Assert.error("Non primitive or reference type");

Nice!

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

PR Comment: https://git.openjdk.org/jdk/pull/26107#issuecomment-3033424938
PR Review Comment: https://git.openjdk.org/jdk/pull/26107#discussion_r2183635855
PR Review Comment: https://git.openjdk.org/jdk/pull/26107#discussion_r2183636159


More information about the compiler-dev mailing list