Skip to content

Commit 37e4b27

Browse files
committed
Move isCurrentlyAfterTyper to Context
The idea is that all core operation that query or set the current context should be in Contexts. That way they are easier to import. Also: Do some cleanups on phases names
1 parent bec52f3 commit 37e4b27

15 files changed

+27
-34
lines changed

compiler/src/dotty/tools/dotc/Run.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Scopes._
1010
import typer.{ImportInfo, Typer}
1111
import Decorators._
1212
import io.{AbstractFile, PlainFile}
13-
import Phases.curPhases
13+
import Phases.unfusedPhases
1414

1515
import scala.io.Codec
1616
import util.{Set => _, _}
@@ -165,7 +165,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
165165
else ctx.settings.YstopAfter.value
166166

167167
val pluginPlan = ctx.base.addPluginPhases(ctx.base.phasePlan)
168-
val phases = ctx.base.squashPhases(pluginPlan,
168+
val phases = ctx.base.fusePhases(pluginPlan,
169169
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
170170
ctx.base.usePhases(phases)
171171

@@ -195,7 +195,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
195195

196196
val runCtx = ctx.fresh
197197
runCtx.setProfiler(Profiler())
198-
curPhases.foreach(_.initContext(runCtx))
198+
unfusedPhases.foreach(_.initContext(runCtx))
199199
runPhases(using runCtx)
200200
if (!ctx.reporter.hasErrors) Rewrites.writeBack()
201201
while (finalizeActions.nonEmpty) {

compiler/src/dotty/tools/dotc/core/Contexts.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ object Contexts {
8383

8484
inline def currentPhaseId(using ctx: Context): Int = ctx.period.phaseId
8585

86+
def currentlyAfterTyper(using Context): Boolean = ctx.base.isAfterTyper(currentPhase)
8687

8788
/** A context is passed basically everywhere in dotc.
8889
* This is convenient but carries the risk of captured contexts in
@@ -784,7 +785,7 @@ object Contexts {
784785
private[dotc] var phases: Array[Phase] = _
785786

786787
/** Phases with consecutive Transforms grouped into a single phase, Empty array if squashing is disabled */
787-
private[core] var squashedPhases: Array[Phase] = Array.empty[Phase]
788+
private[core] var fusedPhases: Array[Phase] = Array.empty[Phase]
788789

789790
/** Next denotation transformer id */
790791
private[core] var nextDenotTransformerId: Array[Int] = _

compiler/src/dotty/tools/dotc/core/Periods.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tools.dotc.core
22

33
import Contexts._
4-
import Phases.curPhases
4+
import Phases.unfusedPhases
55

66
object Periods {
77

@@ -22,8 +22,8 @@ object Periods {
2222
val period = currentPeriod
2323
period == p ||
2424
period.runId == p.runId &&
25-
curPhases(period.phaseId).sameBaseTypesStartId ==
26-
curPhases(p.phaseId).sameBaseTypesStartId
25+
unfusedPhases(period.phaseId).sameBaseTypesStartId ==
26+
unfusedPhases(p.phaseId).sameBaseTypesStartId
2727

2828
/** A period is a contiguous sequence of phase ids in some run.
2929
* It is coded as follows:

compiler/src/dotty/tools/dotc/core/Phases.scala

+9-11
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ object Phases {
2727
inline def phaseOf(id: PhaseId)(using Context): Phase =
2828
ctx.base.phases(id)
2929

30-
def currentlyAfterTyper(using Context): Boolean = ctx.base.isAfterTyper(currentPhase)
31-
3230
trait PhasesBase {
3331
this: ContextBase =>
3432

3533
// drop NoPhase at beginning
36-
def allPhases: Array[Phase] = (if (squashedPhases.nonEmpty) squashedPhases else phases).tail
34+
def allPhases: Array[Phase] = (if (fusedPhases.nonEmpty) fusedPhases else phases).tail
3735

3836
object NoPhase extends Phase {
3937
override def exists: Boolean = false
@@ -63,12 +61,12 @@ object Phases {
6361
* Each TreeTransform gets own period,
6462
* whereas a combined TreeTransformer gets period equal to union of periods of it's TreeTransforms
6563
*/
66-
final def squashPhases(phasess: List[List[Phase]],
64+
final def fusePhases(phasess: List[List[Phase]],
6765
phasesToSkip: List[String],
6866
stopBeforePhases: List[String],
6967
stopAfterPhases: List[String],
7068
YCheckAfter: List[String])(using Context): List[Phase] = {
71-
val squashedPhases = ListBuffer[Phase]()
69+
val fusedPhases = ListBuffer[Phase]()
7270
var prevPhases: Set[String] = Set.empty
7371
val YCheckAll = YCheckAfter.contains("all")
7472

@@ -111,17 +109,17 @@ object Phases {
111109
prevPhases += phase.phaseName
112110
phase
113111
}
114-
squashedPhases += phaseToAdd
112+
fusedPhases += phaseToAdd
115113
val shouldAddYCheck = YCheckAfter.containsPhase(phaseToAdd) || YCheckAll
116114
if (shouldAddYCheck) {
117115
val checker = new TreeChecker
118-
squashedPhases += checker
116+
fusedPhases += checker
119117
}
120118
}
121119

122120
i += 1
123121
}
124-
squashedPhases.toList
122+
fusedPhases.toList
125123
}
126124

127125
/** Use the following phases in the order they are given.
@@ -192,9 +190,9 @@ object Phases {
192190
}
193191

194192
if (squash)
195-
this.squashedPhases = (NoPhase :: phasess).toArray
193+
this.fusedPhases = (NoPhase :: phasess).toArray
196194
else
197-
this.squashedPhases = this.phases
195+
this.fusedPhases = this.phases
198196

199197
config.println(s"Phases = ${phases.toList}")
200198
config.println(s"nextDenotTransformerId = ${nextDenotTransformerId.toList}")
@@ -421,7 +419,7 @@ object Phases {
421419
def flattenPhase(using Context): Phase = ctx.base.flattenPhase
422420
def genBCodePhase(using Context): Phase = ctx.base.genBCodePhase
423421

424-
def curPhases(using Context): Array[Phase] = ctx.base.phases
422+
def unfusedPhases(using Context): Array[Phase] = ctx.base.phases
425423

426424
/** Replace all instances of `oldPhaseClass` in `current` phases
427425
* by the result of `newPhases` applied to the old phase.

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ package core
44

55
import Periods._, Contexts._, Symbols._, Denotations._, Names._, NameOps._, Annotations._
66
import Types._, Flags._, Decorators._, DenotTransformers._, StdNames._, Scopes._
7-
import NameOps._, NameKinds._, Phases._
8-
import Phases.typerPhase
7+
import NameOps._, NameKinds._
8+
import Phases.{Phase, typerPhase, unfusedPhases}
99
import Constants.Constant
1010
import TypeApplications.TypeParamInfo
1111
import Scopes.Scope
@@ -2577,8 +2577,8 @@ object SymDenotations {
25772577
def isValidAt(phase: Phase)(using Context) =
25782578
checkedPeriod == currentPeriod ||
25792579
createdAt.runId == currentRunId &&
2580-
createdAt.phaseId < curPhases.length &&
2581-
sameGroup(curPhases(createdAt.phaseId), phase) &&
2580+
createdAt.phaseId < unfusedPhases.length &&
2581+
sameGroup(unfusedPhases(createdAt.phaseId), phase) &&
25822582
{ checkedPeriod = currentPeriod; true }
25832583
}
25842584

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package dotc
33
package core
44

55
import Types._, Contexts._, Symbols._, Flags._, Names._, NameOps._, Denotations._
6-
import Decorators._, Phases._
6+
import Decorators._
7+
import Phases.gettersPhase
78
import StdNames.nme
89
import TypeOps.refineUsingParent
910
import collection.mutable

compiler/src/dotty/tools/dotc/typer/Applications.scala

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import util.Stats.record
99
import util.{SourcePosition, NoSourcePosition, SourceFile}
1010
import Trees.Untyped
1111
import Contexts._
12-
import Phases.currentlyAfterTyper
1312
import Flags._
1413
import Symbols._
1514
import Denotations.Denotation

compiler/src/dotty/tools/dotc/typer/Checking.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import CheckRealizable._
1818
import ErrorReporting.errorTree
1919
import rewrites.Rewrites.patch
2020
import util.Spans.Span
21-
import Phases.{refchecksPhase, currentlyAfterTyper}
21+
import Phases.refchecksPhase
2222

2323
import util.SourcePosition
2424
import util.Spans.Span

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Flags._
1010
import Symbols._
1111
import Names._
1212
import StdNames._
13-
import Phases.currentlyAfterTyper
1413
import NameKinds.UniqueName
1514
import util.Spans._
1615
import collection.mutable

compiler/src/dotty/tools/dotc/typer/Implicits.scala

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import Constants._
2424
import ProtoTypes._
2525
import ErrorReporting._
2626
import reporting.Message
27-
import Phases.currentlyAfterTyper
2827
import Inferencing.{fullyDefinedType, isFullyDefined}
2928
import Trees._
3029
import transform.SymUtils._

compiler/src/dotty/tools/dotc/typer/Namer.scala

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import config.{Config, Feature}
2020
import config.Printers.typr
2121
import Annotations._
2222
import Inferencing._
23-
import Phases.currentlyAfterTyper
2423
import transform.ValueClasses._
2524
import transform.TypeUtils._
2625
import transform.SymUtils._

compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import Types._
1212
import Decorators._
1313
import NameKinds._
1414
import StdNames.nme
15-
import Contexts.{Context, ctx}
15+
import Contexts._
1616
import Names.Name
1717
import NameKinds.{InlineAccessorName, UniqueInlineName}
1818
import NameOps._
1919
import Annotations._
20-
import Phases.currentlyAfterTyper
2120
import transform.{AccessProxies, PCPCheckAndHeal, Splicer, TreeMapWithStages}
2221
import config.Printers.inlining
2322
import util.{Property, SourcePosition}

compiler/src/dotty/tools/dotc/typer/ReTyper.scala

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Symbols._
88
import StdNames._
99
import Decorators._
1010
import typer.ProtoTypes._
11-
import Phases.currentlyAfterTyper
1211
import ast.{tpd, untpd, Trees}
1312
import Trees._
1413
import scala.util.control.NonFatal

compiler/src/dotty/tools/dotc/typer/Typer.scala

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import Decorators.{given _}
2525
import ErrorReporting._
2626
import Checking._
2727
import Inferencing._
28-
import Phases.currentlyAfterTyper
2928
import EtaExpansion.etaExpand
3029
import util.Spans._
3130
import util.common._

compiler/src/dotty/tools/repl/ReplDriver.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.io.{File => JFile, PrintStream}
55
import dotty.tools.dotc.ast.Trees._
66
import dotty.tools.dotc.ast.{tpd, untpd}
77
import dotty.tools.dotc.core.Contexts._
8-
import dotty.tools.dotc.core.Phases.{curPhases, typerPhase}
8+
import dotty.tools.dotc.core.Phases.{unfusedPhases, typerPhase}
99
import dotty.tools.dotc.core.Denotations.Denotation
1010
import dotty.tools.dotc.core.Flags._
1111
import dotty.tools.dotc.core.Mode
@@ -223,7 +223,7 @@ class ReplDriver(settings: Array[String],
223223
}
224224

225225
def extractTopLevelImports(ctx: Context): List[tpd.Import] =
226-
curPhases(using ctx).collectFirst { case phase: CollectTopLevelImports => phase.imports }.get
226+
unfusedPhases(using ctx).collectFirst { case phase: CollectTopLevelImports => phase.imports }.get
227227

228228
implicit val state = {
229229
val state0 = newRun(istate)

0 commit comments

Comments
 (0)