Integrated: 8262891: Compiler implementation for Pattern Matching for switch (Preview)

Jan Lahoda jlahoda at
Mon Jun 7 07:05:12 UTC 2021

On Tue, 4 May 2021 16:41:44 GMT, Jan Lahoda <jlahoda at> wrote:

> This is a preview of a patch implementing JEP 406: Pattern Matching for switch (Preview):
> The current draft of the specification is here:
> A summary of notable parts of the patch:
> -to support cases expressions and patterns in cases, there is a new common superinterface for expressions and patterns, `CaseLabelTree`, which expressions and patterns implement, and a list of case labels is returned from `CaseTree.getLabels()`.
> -to support `case default`, there is an implementation of `CaseLabelTree` that represents it (`DefaultCaseLabelTree`). It is used also to represent the conventional `default` internally and in the newly added methods.
> -in the parser, parenthesized patterns and expressions need to be disambiguated when parsing case labels.
> -Lower has been enhanced to handle `case null` for ordinary (boxed-primitive, String, enum) switches. This is a bit tricky for boxed primitives, as there is no value that is not part of the input domain so that could be used to represent `case null`. Requires a bit shuffling with values.
> -TransPatterns has been enhanced to handle the pattern matching switch. It produces code that delegates to a new bootstrap method, that will classify the input value to the switch and return the case number, to which the switch then jumps. To support guards, the switches (and the bootstrap method) are restartable. The bootstrap method as such is written very simply so far, but could be much more optimized later.
> -nullable type patterns are `case String s, null`/`case null, String s`/`case null: case String s:`/`case String s: case null:`, handling of these required a few tricks in `Attr`, `Flow` and `TransPatterns`.
> The specdiff for the change is here (to be updated):

This pull request has now been integrated.

Changeset: 908aca29
Author:    Jan Lahoda <jlahoda at>
Stats:     4940 lines in 79 files changed: 4621 ins; 118 del; 201 mod

8262891: Compiler implementation for Pattern Matching for switch (Preview)

Co-authored-by: Brian Goetz <briangoetz at>
Co-authored-by: Mandy Chung <mchung at>
Co-authored-by: Jan Lahoda <jlahoda at>
Reviewed-by: mcimadamore, forax, godin, psandoz, mchung



More information about the core-libs-dev mailing list