File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -457,6 +457,12 @@ object PatternMatcher {
457
457
apply(initializer(plan.sym))
458
458
plan
459
459
}
460
+ override def apply (plan : SeqPlan ): Plan = {
461
+ apply(plan.head)
462
+ if (canFallThrough(plan.head))
463
+ apply(plan.tail)
464
+ plan
465
+ }
460
466
}
461
467
refCounter(plan)
462
468
refCounter.count
@@ -564,8 +570,10 @@ object PatternMatcher {
564
570
new MergeTests ()(plan)
565
571
}
566
572
567
- /** Inline let-bound trees that are referenced only once.
568
- * Drop all variables that are not referenced anymore after this.
573
+ /** Inline let-bound trees that are referenced only once and eliminate dead code.
574
+ *
575
+ * - Drop all variables that are not referenced anymore after inlining.
576
+ * - Drop the `tail` of `SeqPlan`s whose `head` cannot fall through.
569
577
*/
570
578
private def inlineVars (plan : Plan ): Plan = {
571
579
val refCount = varRefCount(plan)
@@ -597,6 +605,18 @@ object PatternMatcher {
597
605
plan
598
606
}
599
607
}
608
+ override def apply (plan : SeqPlan ): Plan = {
609
+ val newHead = apply(plan.head)
610
+ if (! canFallThrough(newHead)) {
611
+ // If the head cannot fall through, the tail is dead code
612
+ newHead
613
+ }
614
+ else {
615
+ plan.head = newHead
616
+ plan.tail = apply(plan.tail)
617
+ plan
618
+ }
619
+ }
600
620
}
601
621
Inliner (plan)
602
622
}
You can’t perform that action at this time.
0 commit comments