Skip to content

Commit c1fe213

Browse files
author
som-snytt
authored
Merge pull request scala#10687 from som-snytt/issue/8755-phase-ass
Rewrite phase assembly (`DependencyGraph`) [ci: last-only]
2 parents bea510c + f5ed670 commit c1fe213

19 files changed

+583
-288
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
581581
// phaseName = "specialize"
582582
object specializeTypes extends {
583583
val global: Global.this.type = Global.this
584-
val runsAfter = List("")
584+
val runsAfter = Nil
585585
val runsRightAfter = Some("tailcalls")
586586
} with SpecializeTypes
587587

@@ -595,14 +595,14 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
595595
// phaseName = "erasure"
596596
override object erasure extends {
597597
val global: Global.this.type = Global.this
598-
val runsAfter = List("explicitouter")
598+
val runsAfter = Nil
599599
val runsRightAfter = Some("explicitouter")
600600
} with Erasure
601601

602602
// phaseName = "posterasure"
603603
override object postErasure extends {
604604
val global: Global.this.type = Global.this
605-
val runsAfter = List("erasure")
605+
val runsAfter = Nil
606606
val runsRightAfter = Some("erasure")
607607
} with PostErasure
608608

@@ -667,7 +667,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
667667
val global: Global.this.type = Global.this
668668
} with SubComponent {
669669
val phaseName = "terminal"
670-
val runsAfter = List("jvm")
670+
val runsAfter = Nil
671671
val runsRightAfter = None
672672
override val terminal = true
673673

@@ -696,10 +696,10 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
696696
/** Add the internal compiler phases to the phases set.
697697
* This implementation creates a description map at the same time.
698698
*/
699-
protected def computeInternalPhases(): Unit = {
699+
protected def computeInternalPhases(): Unit =
700700
// Note: this fits -Xshow-phases into 80 column width, which is
701701
// desirable to preserve.
702-
val phs = List(
702+
List(
703703
syntaxAnalyzer -> "parse source into ASTs, perform simple desugaring",
704704
analyzer.namerFactory -> "resolve names, attach symbols to named trees",
705705
analyzer.packageObjects -> "load package objects",
@@ -724,19 +724,16 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
724724
cleanup -> "platform-specific cleanups, generate reflective calls",
725725
terminal -> "the last phase during a compilation run"
726726
)
727+
.foreach((addToPhasesSet _).tupled)
727728

728-
phs foreach (addToPhasesSet _).tupled
729-
}
730729
// This is slightly inelegant but it avoids adding a new member to SubComponent,
731730
// and attractive -Vphases output is unlikely if the descs span 20 files anyway.
732731
private val otherPhaseDescriptions = Map(
733732
"flatten" -> "eliminate inner classes",
734733
"jvm" -> "generate JVM bytecode"
735734
) withDefaultValue ""
736735

737-
protected def computePlatformPhases() = platform.platformPhases foreach { sub =>
738-
addToPhasesSet(sub, otherPhaseDescriptions(sub.phaseName))
739-
}
736+
protected def computePlatformPhases() = platform.platformPhases.foreach(p => addToPhasesSet(p, otherPhaseDescriptions(p.phaseName)))
740737

741738
// sequences the phase assembly
742739
protected def computePhaseDescriptors: List[SubComponent] = {
@@ -769,7 +766,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
769766
/** The names of the phases. */
770767
lazy val phaseNames = {
771768
new Run // force some initialization
772-
phaseDescriptors map (_.phaseName)
769+
phaseDescriptors.map(_.phaseName)
773770
}
774771

775772
/** A description of the phases that will run in this configuration, or all if -Vdebug. */
@@ -1292,10 +1289,13 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
12921289
} else phs
12931290
}
12941291
// Create phases and link them together. We supply the previous, and the ctor sets prev.next.
1295-
val last = components.foldLeft(NoPhase: Phase)((prev, c) => c newPhase prev)
1296-
val phaseList = Iterator.iterate(last)(_.prev).takeWhile(_ != NoPhase).toList.reverse
1297-
val maxId = phaseList.map(_.id).max
1298-
nextFrom = Array.tabulate(maxId)(i => infoTransformers.nextFrom(i))
1292+
val phaseList = {
1293+
val last = components.foldLeft(NoPhase: Phase)((prev, c) => c.newPhase(prev))
1294+
Iterator.iterate(last)(_.prev).takeWhile(_ != NoPhase).toList.reverse
1295+
}
1296+
nextFrom = Array.tabulate(phaseList.maxBy(_.id).id)(infoTransformers.nextFrom(_))
1297+
//println(s"nextFrom: ${scala.runtime.ScalaRunTime.stringOf(nextFrom.map(_.pid))}")
1298+
//println(s"phaseList: ${scala.runtime.ScalaRunTime.stringOf(phaseList.map(_.name))}")
12991299
val first = phaseList.head
13001300
val ss = settings
13011301

0 commit comments

Comments
 (0)