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

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Oct 30 09:55:10 UTC 2024


On Tue, 29 Oct 2024 16:08:56 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:
> 
>   Assume that two lambdas that contain a class definition (any) are always different

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TreeHasher.java line 98:

> 96:     public void visitClassDef(JCClassDecl tree) {
> 97:         hash(tree.sym);
> 98:         super.visitClassDef(tree);

I would remove the recursive call here - the hash of a class is just that of its symbol - no need to scan its members recursively.

test/langtools/tools/javac/lambda/deduplication/Deduplication.java line 191:

> 189:                });
> 190: 
> 191:         group((Function<Object, Integer>) x -> {class C {} new C(); return 42; });

It feels like the test logic could be maybe cleaner if `group` had two variants `groupEquals` and `groupNotEquals` - e.g. in this case you want to make sure the lambdas in the group do NOT dedup.

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

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


More information about the compiler-dev mailing list