Skip to content

Commit c3a0acb

Browse files
committed
Better dead-code-elimination inside PatternMatcher.
If the head of a `SeqPlan` cannot fall through, the tail is unreachable and can be removed.
1 parent 1d24eaa commit c3a0acb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ object PatternMatcher {
457457
apply(initializer(plan.sym))
458458
plan
459459
}
460+
override def apply(plan: SeqPlan): Plan = {
461+
apply(plan.head)
462+
if (canFallThrough(plan.head))
463+
apply(plan.tail)
464+
plan
465+
}
460466
}
461467
refCounter(plan)
462468
refCounter.count
@@ -597,6 +603,16 @@ object PatternMatcher {
597603
plan
598604
}
599605
}
606+
override def apply(plan: SeqPlan): Plan = {
607+
val newHead = apply(plan.head)
608+
if (!canFallThrough(newHead))
609+
newHead
610+
else {
611+
plan.head = newHead
612+
plan.tail = apply(plan.tail)
613+
plan
614+
}
615+
}
600616
}
601617
Inliner(plan)
602618
}

0 commit comments

Comments
 (0)