Make a TreeMaker that will result in an extractor call specified by extractor
the next TreeMaker (here, we don't know which it'll be) is chained after this one by flatMap'ing
a function with binder nextBinder
over our extractor's result
the function's body is determined by the next TreeMaker
(furthermore, the interpretation of flatMap
depends on the codegen instance we're using).
Make a TreeMaker that will result in an extractor call specified by extractor
the next TreeMaker (here, we don't know which it'll be) is chained after this one by flatMap'ing
a function with binder nextBinder
over our extractor's result
the function's body is determined by the next TreeMaker
(furthermore, the interpretation of flatMap
depends on the codegen instance we're using).
The values for the subpatterns, as computed by the extractor call in extractor
,
are stored in local variables that re-use the symbols in subPatBinders
.
This makes extractor patterns more debuggable (SI-5739).
Tree maker that captures sub pattern values during pattern match.
An optimized version of ExtractorTreeMaker for Products.
An optimized version of ExtractorTreeMaker for Products. For now, this is hard-coded to case classes, and we simply extract the case class fields.
The values for the subpatterns, as specified by the case class fields at the time of extraction,
are stored in local variables that re-use the symbols in subPatBinders
.
This makes extractor patterns more debuggable (SI-5739) as well as
avoiding mutation after the pattern has been matched (SI-5158, SI-6070)
TODO: make this user-definable as follows
When a companion object defines a method def unapply_1(x: T): U_1
, but no def unapply
or def unapplySeq
,
the extractor is considered to match any non-null value of type T
the pattern is expected to have as many sub-patterns as there are def unapply_I(x: T): U_I
methods,
and the type of the I'th sub-pattern is U_I
.
The same exception for Seq patterns applies: if the last extractor is of type Seq[U_N]
,
the pattern must have at least N arguments (exactly N if the last argument is annotated with : _*
).
The arguments starting at N (and beyond) are taken from the sequence returned by apply_N,
and it is checked that the sequence has enough elements to provide values for all expected sub-patterns.
For a case class C, the implementation is assumed to be def unapply_I(x: C) = x._I
,
and the extractor call is inlined under that assumption.
In scalac for such block x match { case d => <body> }
In scalac for such block x match { case d => <body> }
d inside <body> was to be substitued by x.
In dotty, SubstOnlyTreeMakers instead generate normal ValDef, and does not create a new substitution.
This was done for several reasons: 1) it is a lot easyer to Y-check, as d type could be used in <body>. 2) it would simplify debugging of the generated code as this works also for nested patterns, and previously they used unreadable names 3) It showed better(~30%), performance, Rebuilding tree and propagating types was taking substantial time.
implements the run-time aspects of (§8.2) (typedPattern has already done the necessary type transformations)
implements the run-time aspects of (§8.2) (typedPattern has already done the necessary type transformations)
Type patterns consist of types, type variables, and wildcards. A type pattern T is of one of the following forms: