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

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Oct 25 11:36:07 UTC 2024


On Thu, 24 Oct 2024 22:14:40 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).
>
> Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Address review

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

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

I would rewrite this (for improved readability) as:


JCVariableDecl that = (JCVariableDecl) parameter;
 result =
                scan(tree.mods, that.mods)
                        && scan(tree.nameexpr, that.nameexpr)
                        && scan(tree.vartype, that.vartype)
                        && scan(tree.init, that.init);

if (tree.sym.owner.type.hasTag(TypeTag.CLASS)) {
    // field names are important!
    result &= tree.name == that.name;
}

if (result) {
     equiv.put(tree.sym, that.sym);
}

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

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


More information about the compiler-dev mailing list