Skip to content

Commit f908e75

Browse files
committed
Fix scala#2903: Reduce the depth of trees generated in PatternMatcher
* Extract all match arguments before checking conditions on them like scalac does. This avoids an extra nested block for each match variable. * Merge conditions of nested `if` expressions if their `else` branch is the same. This optimization combined with the previous removes most of the nested `if`s created to check the matched args.
1 parent 140faba commit f908e75

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,11 @@ object PatternMatcher {
846846
/** Merge nested `if`s that have the same `else` branch into a single `if`.
847847
* This optimization targets calls to label defs for case failure jumps to next case.
848848
*/
849-
def emmitWithMashedConditions(plans: List[TestPlan]): Tree = {
849+
def emitWithMashedConditions(plans: List[TestPlan]): Tree = {
850850
val plan = plans.head
851851
plan.onSuccess match {
852852
case plan2: TestPlan if plan.onFailure == plan2.onFailure =>
853-
emmitWithMashedConditions(plan2 :: plans)
853+
emitWithMashedConditions(plan2 :: plans)
854854
case _ =>
855855
def emitCondWithPos(plan: TestPlan) = emitCondition(plan).withPos(plan.pos)
856856
val conditions =
@@ -862,7 +862,7 @@ object PatternMatcher {
862862
}
863863

864864
}
865-
emmitWithMashedConditions(plan :: Nil)
865+
emitWithMashedConditions(plan :: Nil)
866866
}
867867
case LetPlan(sym, body) =>
868868
seq(ValDef(sym, initializer(sym).ensureConforms(sym.info)) :: Nil, emit(body))

0 commit comments

Comments
 (0)