package patmat
- Alphabetic
- Public
- All
Type Members
- trait Debugging extends AnyRef
- trait Interface extends TreeDSL
- final class Lit extends AnyVal
- trait Logic extends Debugging
- trait MatchAnalysis extends MatchApproximation
- trait MatchApproximation extends TreeAndTypeAnalysis with ScalaLogic with MatchTreeMaking
-
trait
MatchCodeGen
extends Interface
Factory methods used by TreeMakers to make the actual trees.
Factory methods used by TreeMakers to make the actual trees.
We have two modes in which to emit trees: optimized (the default) and pure (aka "virtualized": match is parametric in its monad).
-
trait
MatchCps
extends AnyRef
Segregating this super hacky CPS code.
-
trait
MatchOptimization
extends MatchTreeMaking with MatchAnalysis
Optimize and analyze matches based on their TreeMaker-representation.
Optimize and analyze matches based on their TreeMaker-representation.
The patmat translation doesn't rely on this, so it could be disabled in principle.
- well, not quite: the backend crashes if we emit duplicates in switches (e.g. SI-7290)
-
trait
MatchTranslation
extends AnyRef
Translate typed Trees that represent pattern matches into the patternmatching IR, defined by TreeMakers.
-
trait
MatchTreeMaking
extends MatchCodeGen with Debugging
Translate our IR (TreeMakers) into actual Scala Trees using the factory methods in MatchCodeGen.
Translate our IR (TreeMakers) into actual Scala Trees using the factory methods in MatchCodeGen.
The IR is mostly concerned with sequencing, substitution, and rendering all necessary conditions, mostly agnostic to whether we're in optimized/pure (virtualized) mode.
- trait MatchWarnings extends AnyRef
-
trait
PatternExpander
[Pattern, Type] extends AnyRef
An extractor returns: F1, F2, ..., Fi, opt[Seq[E] or E*] A case matches: P1, P2, ..., Pj, opt[Seq[E]] Put together: P1/F1, P2/F2, ...
An extractor returns: F1, F2, ..., Fi, opt[Seq[E] or E*] A case matches: P1, P2, ..., Pj, opt[Seq[E]] Put together: P1/F1, P2/F2, ... Pi/Fi, Pi+1/E, Pi+2/E, ... Pj/E, opt[Seq[E]]
Here Pm/Fi is the last pattern to match the fixed arity section.
productArity: the value of i, i.e. the number of non-sequence types in the extractor nonStarArity: the value of j, i.e. the number of non-star patterns in the case definition elementArity: j - i, i.e. the number of non-star patterns which must match sequence elements starArity: 1 or 0 based on whether there is a star (sequence-absorbing) pattern totalArity: nonStarArity + starArity, i.e. the number of patterns in the case definition
Note that productArity is a function only of the extractor, and nonStar/star/totalArity are all functions of the patterns. The key value for aligning and typing the patterns is elementArity, as it is derived from both sets of information.
-
trait
PatternMatching
extends SubComponent with Transform with TypingTransformers with Debugging with Interface with MatchTranslation with MatchTreeMaking with MatchCodeGen with MatchCps with ScalaLogic with Solving with MatchAnalysis with MatchOptimization with MatchWarnings with ScalacPatternExpanders
Translate pattern matching.
Translate pattern matching.
Either into optimized if/then/else's, or virtualized as method calls (these methods form a zero-plus monad), similar in spirit to how for-comprehensions are compiled.
For each case, express all patterns as extractor calls, guards as 0-ary extractors, and sequence them using
flatMap
(lifting the body of the case into the monad usingone
).Cases are combined into a pattern match using the
orElse
combinator (the implicit failure case is expressed using the monad'szero
).TODO:
- DCE (on irrefutable patterns)
- update spec and double check it's implemented correctly (see TODO's)
(longer-term) TODO:
- user-defined unapplyProd
- recover GADT typing by locally inserting implicit witnesses to type equalities derived from the current case, and considering these witnesses during subtyping (?)
- recover exhaustivity/unreachability of user-defined extractors by partitioning the types they match on using an HList or similar type-level structure
- trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis
-
trait
ScalacPatternExpanders
extends AnyRef
This is scalac-specific logic layered on top of the scalac-agnostic "matching products to patterns" logic defined in PatternExpander.
-
trait
Solving
extends Logic
Solve pattern matcher exhaustivity problem via DPLL.
- trait TreeAndTypeAnalysis extends Debugging
Value Members
- object Lit
- object PatternMatchingStats
The Scala compiler API.
The following resources are useful for Scala plugin/compiler development: