RFR: 8291769: Translation of switch with record patterns could be improved [v6]

Vicente Romero vromero at openjdk.org
Fri Sep 30 15:19:23 UTC 2022


On Fri, 30 Sep 2022 12:31:09 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java line 819:
>> 
>>> 817:                 }
>>> 818:             } else if (currentBinding != null &&
>>> 819:                        commonBinding.type.tsym == currentBinding.type.tsym &&
>> 
>> question, what about having a map relating commonBindings and accumulators, shouldn't this allow you to group common patterns even if they are not consecutive?
>
> This would mean we would change the order of the cases, which is something I'd like to avoid in this patch, for several reasons. Partly because there's a fairly big set of cases where it is unclear if we can do the reordering (and the exact rules when we can do reordering are debatable, and sometimes depend on very particular aspects of the spec), and partly because this patch seems complex enough without reordering.
> 
> One possibility we could do case reordering as a separate step before coalescing the prefixes, as simple use of map would not necessarily allow to avoid coalescing in cases like:
> 
> switch (o) {
>      case I1 i when <condition1> -> {}
>      case I2 i when <condition2> -> {}
>      case I1 i when <condition3> -> {}
> }
> 
> (where `I1` and `I2` are unrelated interfaces, we cannot easily change the order of the cases here, as `o` may be an object that implements both, and `<condition1>` might be `false`).

got it I agree, thanks

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

PR: https://git.openjdk.org/jdk/pull/9746


More information about the compiler-dev mailing list