Skip to content

Commit 6daf060

Browse files
committed
Tweak Phases
1 parent 5eb598d commit 6daf060

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Phases.scala

+22-19
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import DenotTransformers.*
99
import Denotations.*
1010
import Decorators.*
1111
import config.Printers.config
12-
import scala.collection.mutable.ListBuffer
1312
import dotty.tools.dotc.transform.MegaPhase.*
1413
import dotty.tools.dotc.transform.*
14+
import dotty.tools.dotc.util.chaining.*
1515
import Periods.*
1616
import parsing.Parser
1717
import printing.XprintMode
@@ -20,8 +20,9 @@ import cc.CheckCaptures
2020
import typer.ImportInfo.withRootImports
2121
import ast.{tpd, untpd}
2222
import scala.annotation.internal.sharable
23-
import scala.util.control.NonFatal
23+
import scala.collection.mutable.ListBuffer
2424
import scala.compiletime.uninitialized
25+
import scala.util.control.NonFatal
2526

2627
object Phases {
2728

@@ -58,15 +59,15 @@ object Phases {
5859
final def phasePlan: List[List[Phase]] = this.phasesPlan
5960
final def setPhasePlan(phasess: List[List[Phase]]): Unit = this.phasesPlan = phasess
6061

61-
/** Squash TreeTransform's beloning to same sublist to a single TreeTransformer
62-
* Each TreeTransform gets own period,
63-
* whereas a combined TreeTransformer gets period equal to union of periods of it's TreeTransforms
64-
*/
62+
/** Squash TreeTransforms belonging to same sublist to a single TreeTransformer.
63+
* Each TreeTransform gets its own period,
64+
* whereas a combined TreeTransformer gets period equal to union of periods of its TreeTransforms.
65+
*/
6566
final def fusePhases(phasess: List[List[Phase]],
6667
phasesToSkip: List[String],
6768
stopBeforePhases: List[String],
6869
stopAfterPhases: List[String],
69-
YCheckAfter: List[String])(using Context): List[Phase] = {
70+
checkAfter: List[String])(using Context): List[Phase] = {
7071
val fusedPhases = ListBuffer[Phase]()
7172
var prevPhases: Set[String] = Set.empty
7273

@@ -110,7 +111,7 @@ object Phases {
110111
phase
111112
}
112113
fusedPhases += phaseToAdd
113-
val shouldAddYCheck = filteredPhases(i).exists(_.isCheckable) && YCheckAfter.containsPhase(phaseToAdd)
114+
val shouldAddYCheck = filteredPhases(i).exists(_.isCheckable) && checkAfter.containsPhase(phaseToAdd)
114115
if (shouldAddYCheck) {
115116
val checker = new TreeChecker
116117
fusedPhases += checker
@@ -130,10 +131,9 @@ object Phases {
130131

131132
val flatPhases = ListBuffer.empty[Phase]
132133

133-
phasess.foreach {
134+
phasess.foreach:
134135
case p: MegaPhase => flatPhases ++= p.miniPhases
135136
case p => flatPhases += p
136-
}
137137

138138
phases = (NoPhase :: flatPhases.toList ::: new TerminalPhase :: Nil).toArray
139139
setSpecificPhases()
@@ -565,23 +565,26 @@ object Phases {
565565
current.map(_.flatMap(phase =>
566566
if (oldPhaseClass.isInstance(phase)) newPhases(phase) else phase :: Nil))
567567

568-
def assemblePhases()(using Context): FreshContext =
569-
val runCtx = ctx.fresh
570-
568+
def assemblePhases()(using Context): FreshContext = ctx.fresh.tap: runCtx =>
571569
// If testing pickler, make sure to stop after pickling phase:
572570
val stopAfter =
573-
if (ctx.settings.YtestPickler.value) List("pickler")
571+
if ctx.settings.YtestPickler.value then List("pickler")
574572
else ctx.settings.YstopAfter.value
575573

576574
val pluginPlan = ctx.base.addPluginPhases(ctx.base.phasePlan)
577575
val phases = ctx.base.fusePhases(pluginPlan,
578-
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
576+
phasesToSkip = ctx.settings.Yskip.value,
577+
stopBeforePhases = ctx.settings.YstopBefore.value,
578+
stopAfterPhases = stopAfter,
579+
checkAfter = ctx.settings.Ycheck.value)
579580
ctx.base.usePhases(phases, runCtx)
580581

581-
val phasesSettings = List("-Vphases", "-Vprint")
582-
for phasesSetting <- ctx.settings.allSettings if phasesSettings.contains(phasesSetting.name) do
583-
for case vs: List[String] <- phasesSetting.userValue; p <- vs do
582+
val phasesSettings =
583+
val ss = ctx.settings
584+
import ss.*
585+
List(Vprint) // no check for Vphases
586+
for phasesSetting <- phasesSettings do
587+
for case ps: List[String] <- phasesSetting.userValue; p <- ps do
584588
if !phases.exists(List(p).containsPhase) then report.warning(s"'$p' specifies no phase")
585-
runCtx
586589
end assemblePhases
587590
}

0 commit comments

Comments
 (0)