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

Chen Liang liach at openjdk.org
Thu Jul 3 20:50:40 UTC 2025


On Thu, 3 Jul 2025 19:45:04 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

>> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Further improvements and testing per suggestions
>
> 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`.

This is not really a lhs - we are trying to generate "statement; expression", maybe rename this to `prefixStatement`?

> test/langtools/tools/javac/patterns/PrimitiveUnconditionallyExactTest.java line 86:
> 
>> 84:     @Test
>> 85:     public void testExpressionExecution() {
>> 86:         int a = 0;
> 
> I wonder, should we also include a test that uses assignment to a reference type? 
> 
> e.g., `Long` so that we generate both the `null` check and the ECS call. I am 95% sure that everything will be fine. Up to you @liach

This test aims to ensure side effects are generated. Do we have no such tests yet? I think they better belong to the other 2 existing tests modified.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26107#discussion_r2183724653
PR Review Comment: https://git.openjdk.org/jdk/pull/26107#discussion_r2183727330


More information about the compiler-dev mailing list