diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 33b2becb0b81..b96bdb47f160 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -90,6 +90,7 @@ class ScalaSettings extends Settings.SettingGroup { val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.") val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions.") val YnoDeepSubtypes = BooleanSetting("-Yno-deep-subtypes", "throw an exception on deep subtyping call stacks.") + val YnoPatmatOpt = BooleanSetting("-Yno-patmat-opt", "disable all pattern matching optimizations.") val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.") val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.") val YprintDebug = BooleanSetting("-Yprint-debug", "when printing trees, print some extra information useful for debugging.") diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 150aeb43c43c..5007f31007d6 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -687,12 +687,12 @@ object PatternMatcher { val refCount = varRefCount(plan) val LetPlan(topSym, _) = plan - def toDrop(sym: Symbol) = - initializer.contains(sym) && - isPatmatGenerated(sym) && - refCount(sym) <= 1 && - sym != topSym && - isPureExpr(initializer(sym)) + def toDrop(sym: Symbol) = initializer.get(sym) match { + case Some(rhs) => + isPatmatGenerated(sym) && refCount(sym) <= 1 && sym != topSym && isPureExpr(rhs) + case none => + false + } object Inliner extends PlanTransform { override val treeMap = new TreeMap { @@ -924,10 +924,11 @@ object PatternMatcher { def translateMatch(tree: Match): Tree = { var plan = matchPlan(tree) patmatch.println(i"Plan for $tree: ${show(plan)}") - for ((title, optimization) <- optimizations) { - plan = optimization(plan) - patmatch.println(s"After $title: ${show(plan)}") - } + if (!ctx.settings.YnoPatmatOpt.value) + for ((title, optimization) <- optimizations) { + plan = optimization(plan) + patmatch.println(s"After $title: ${show(plan)}") + } val result = emit(plan) checkSwitch(tree, result) result