RFR: 8262889: Compiler implementation for Record Patterns [v2]

Jan Lahoda jlahoda at openjdk.java.net
Fri May 6 17:43:11 UTC 2022


On Fri, 6 May 2022 14:30:10 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Reflecting review feedback.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java line 752:
> 
>> 750:                                            Iterable<? extends JCCaseLabel> labels) {
>> 751:             Set<Symbol> coveredSymbols = new HashSet<>();
>> 752:             Map<Symbol, List<JCRecordPattern>> deconstructionPatternsBySymbol = new HashMap<>();
> 
> since you seem to have settled on "recordPattern" for implementation names - you can probably revisit some of these names to say "record" instead of "deconstruction".

Right. Will do.

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java line 801:
> 
>> 799:             //i.e. represent all possible combinations.
>> 800:             //This is done by categorizing the patterns based on the type covered by the given
>> 801:             //starting component.
> 
> Example needed here. For instance (I discussed this with @biboudis):
> 
> 
> record Outer(R r) { };
> sealed interface I { };
> class A implements I { };
> class B implements I { };
> sealed interface R { };
> record Foo(I i) implements R { }
> record Bar(I i) implements R { }
> 
> switch (o) {
>    case Outer(Foo(A), Foo(A)):
>    case Outer(Foo(B), Foo(B)):
>    case Outer(Foo(A), Foo(B)):
>    case Outer(Foo(B), Foo(A)):
>    case Outer(Bar(A), Bar(A)):
>    case Outer(Bar(B), Bar(B)):
>    case Outer(Bar(A), Bar(B)):
>    case Outer(Bar(B), Bar(A)):
> }
> 
> 
> Which generates two sets:
> 
> 
>    case Outer(Foo(A), Foo(A)):
>    case Outer(Foo(B), Foo(B)):
>    case Outer(Foo(A), Foo(B)):
>    case Outer(Foo(B), Foo(A)):
> 
> 
> And
> 
> 
>    case Outer(Bar(A), Bar(A)):
>    case Outer(Bar(B), Bar(B)):
>    case Outer(Bar(A), Bar(B)):
>    case Outer(Bar(B), Bar(A)):
> 
> 
> Sorry for being pedantic - this code is tricky and I'm worried we'll all forget exactly how it works in 2 months :-)

Sure. Will try to improve.

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

PR: https://git.openjdk.java.net/jdk/pull/8516


More information about the core-libs-dev mailing list