Skip to content

Commit 2407a24

Browse files
authored
Merge pull request #2848 from dotty-staging/change/patmat-optimize
Add option -Yno-patmat-opt to disable pm optimizations
2 parents f14e289 + 7f12e94 commit 2407a24

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ScalaSettings extends Settings.SettingGroup {
9090
val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.")
9191
val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions.")
9292
val YnoDeepSubtypes = BooleanSetting("-Yno-deep-subtypes", "throw an exception on deep subtyping call stacks.")
93+
val YnoPatmatOpt = BooleanSetting("-Yno-patmat-opt", "disable all pattern matching optimizations.")
9394
val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.")
9495
val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.")
9596
val YprintDebug = BooleanSetting("-Yprint-debug", "when printing trees, print some extra information useful for debugging.")

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,12 @@ object PatternMatcher {
687687
val refCount = varRefCount(plan)
688688
val LetPlan(topSym, _) = plan
689689

690-
def toDrop(sym: Symbol) =
691-
initializer.contains(sym) &&
692-
isPatmatGenerated(sym) &&
693-
refCount(sym) <= 1 &&
694-
sym != topSym &&
695-
isPureExpr(initializer(sym))
690+
def toDrop(sym: Symbol) = initializer.get(sym) match {
691+
case Some(rhs) =>
692+
isPatmatGenerated(sym) && refCount(sym) <= 1 && sym != topSym && isPureExpr(rhs)
693+
case none =>
694+
false
695+
}
696696

697697
object Inliner extends PlanTransform {
698698
override val treeMap = new TreeMap {
@@ -924,10 +924,11 @@ object PatternMatcher {
924924
def translateMatch(tree: Match): Tree = {
925925
var plan = matchPlan(tree)
926926
patmatch.println(i"Plan for $tree: ${show(plan)}")
927-
for ((title, optimization) <- optimizations) {
928-
plan = optimization(plan)
929-
patmatch.println(s"After $title: ${show(plan)}")
930-
}
927+
if (!ctx.settings.YnoPatmatOpt.value)
928+
for ((title, optimization) <- optimizations) {
929+
plan = optimization(plan)
930+
patmatch.println(s"After $title: ${show(plan)}")
931+
}
931932
val result = emit(plan)
932933
checkSwitch(tree, result)
933934
result

0 commit comments

Comments
 (0)