RFR: 8342967: Lambda deduplication fails with non-metafactory BSMs and mismatched local variables names

Chen Liang liach at openjdk.org
Thu Oct 24 16:49:08 UTC 2024


On Thu, 24 Oct 2024 15:19:16 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

> After experimentation and under certain conditions, a few equivalent lambdas (up to variable renaming) fail to deduplicate.
> 
> `TreeHasher` and `TreeDiffer` are now aware that other bootstraps may appear in lambda bodies (e.g. `SwitchBootstraps.typeSwitch`) and that variable names do not matter (when they appear in method/lambda definitions). In the first case equivalence is checked based on `bsmKey` and not the `Dynamic{Var, Method}Symbol` itself.
> 
> The test was also adjusted since it was assuming BSM with certain structure only (that `.get(1)` was unprotected).

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TreeDiffer.java line 224:

> 222:         Symbol otherSymbol = that.sym;
> 223: 
> 224:         result &= scan(symbol, otherSymbol);

I think we want to short circuit here, and `&=` will evaluate `scan` even if `result` is already `false`.
Suggestion:

        if (result)
            result = scan(symbol, otherSymbol);

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TreeDiffer.java line 693:

> 691: 
> 692:         if (!tree.sym.owner.type.hasTag(TypeTag.METHOD)) {
> 693:             result &= tree.name == that.name;

Same short-circuiting remark.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21687#discussion_r1815380394
PR Review Comment: https://git.openjdk.org/jdk/pull/21687#discussion_r1815380946


More information about the compiler-dev mailing list