@@ -45,7 +45,12 @@ class PatternMatcher extends MiniPhaseTransform {
45
45
object PatternMatcher {
46
46
import ast .tpd ._
47
47
48
- final val selfCheck = true // debug option, if on we check that no case gets generated twice
48
+ final val selfCheck = false // debug option, if on we check that no case gets generated twice
49
+
50
+ /** Was symbol generated by pattern matcher? */
51
+ def isPatmatGenerated (sym : Symbol )(implicit ctx : Context ): Boolean =
52
+ sym.is(Synthetic ) &&
53
+ (sym.name.is(PatMatStdBinderName ) || sym.name.is(PatMatCaseName ))
49
54
50
55
/** The pattern matching translator.
51
56
* Its general structure is a pipeline:
@@ -77,6 +82,7 @@ object PatternMatcher {
77
82
private def newVar (rhs : Tree , flags : FlagSet ): TermSymbol =
78
83
ctx.newSymbol(ctx.owner, PatMatStdBinderName .fresh(), Synthetic | Case | flags,
79
84
sanitize(rhs.tpe), coord = rhs.pos)
85
+ // TODO: Drop Case once we use everywhere else `isPatmatGenerated`.
80
86
81
87
/** The plan `let x = rhs in body(x)` where `x` is a fresh variable */
82
88
private def letAbstract (rhs : Tree )(body : Symbol => Plan ): Plan = {
@@ -93,11 +99,6 @@ object PatternMatcher {
93
99
LabelledPlan (label, body(CallPlan (label, Nil )), Nil )
94
100
}
95
101
96
- /** Was symbol generated by pattern matcher? */
97
- private def isPatmatGenerated (sym : Symbol ) =
98
- sym.is(Synthetic ) &&
99
- (sym.is(Label ) || sym.name.is(PatMatStdBinderName ))
100
-
101
102
/** Test whether a type refers to a pattern-generated variable */
102
103
private val refersToInternal = new TypeAccumulator [Boolean ] {
103
104
def apply (x : Boolean , tp : Type ) =
@@ -687,7 +688,11 @@ object PatternMatcher {
687
688
val LetPlan (topSym, _) = plan
688
689
689
690
def toDrop (sym : Symbol ) =
690
- initializer.contains(sym) && isPatmatGenerated(sym) && refCount(sym) <= 1 && sym != topSym
691
+ initializer.contains(sym) &&
692
+ isPatmatGenerated(sym) &&
693
+ refCount(sym) <= 1 &&
694
+ sym != topSym &&
695
+ isPureExpr(initializer(sym))
691
696
692
697
object Inliner extends PlanTransform {
693
698
override val treeMap = new TreeMap {
0 commit comments