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

Aggelos Biboudis abimpoudis at openjdk.org
Tue Oct 29 16:13:14 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

In this [commit](https://github.com/openjdk/jdk/pull/21687/commits/afed36490a76d858b4909efb9fd5dc1487699cd2) I have added two groups of the same lambda (syntactically). There are
two checks in `DeduplicationTest.TreeDiffHashTaskListener.finished` as described in
the comments:

- // Scan the compilation for calls to a varargs method named 'group', whose arguments
   // are a group of lambdas that are equivalent to each other, but distinct from all
   // lambdas in the compilation unit outside of that group.
- // 1. Assert that all pairwise combinations of lambdas in the group are equal, and
   // hash to the same value.
- // 2. Assert that no lambdas in a group are equal to any lambdas outside that group,
   // or hash to the same value as lambda outside the group.

As a result, I added two groups (since there is no functionality to assert that
two lambdas in a group are different.) IIUC any lambda inside the group is
checked for non equality with each lambda outside the group.

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

I believe that now (since the same lambda is not equal to itself if it contains a class decl)
a reasonable if-test within the group, could be to test `if (rhs != lhs)`. Applying TreeDiff 
between the same lambda can yield an assertion error now. 

Let me know if I you believe that I misinterpreted the test in anyway.

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

PR Comment: https://git.openjdk.org/jdk/pull/21687#issuecomment-2444732437


More information about the compiler-dev mailing list