Skip to content

Commit 95b56a8

Browse files
committed
Move runId, phaseId back to Context
1 parent 6e65e91 commit 95b56a8

15 files changed

+55
-52
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
8585

8686
/** The context created for this run */
8787
given runContext[Dummy_so_its_a_def] as Context = myCtx
88-
assert(currentRunId(using runContext) <= Periods.MaxPossibleRunId)
88+
assert(runContext.runId <= Periods.MaxPossibleRunId)
8989

9090
private var myUnits: List[CompilationUnit] = _
9191
private var myUnitsCached: List[CompilationUnit] = _

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object Annotations {
5959
case symFn: (Context ?=> Symbol) @unchecked =>
6060
mySym = null
6161
mySym = atPhaseNoLater(picklerPhase)(symFn)
62-
case sym: Symbol if sym.defRunId != currentRunId(using parentCtx) =>
62+
case sym: Symbol if sym.defRunId != parentCtx.runId =>
6363
mySym = sym.denot.current.symbol
6464
case _ =>
6565
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ object Contexts {
369369
/** The current reporter */
370370
def reporter: Reporter = typerState.reporter
371371

372+
final def runId = period.runId
373+
final def phaseId = period.phaseId
374+
372375
/** Is this a context for the members of a class definition? */
373376
def isClassDefContext: Boolean =
374377
owner.isClass && (owner ne outer.owner)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,9 +1356,9 @@ class Definitions {
13561356
private var current: RunId = NoRunId
13571357
private var cached: T = _
13581358
def apply()(using Context): T = {
1359-
if (current != currentRunId) {
1359+
if (current != ctx.runId) {
13601360
cached = generate
1361-
current = currentRunId
1361+
current = ctx.runId
13621362
}
13631363
cached
13641364
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object DenotTransformers {
2424

2525
/** The validity period of the transformed denotations in the given context */
2626
def validFor(using Context): Period =
27-
Period(currentRunId, id + 1, lastPhaseId)
27+
Period(ctx.runId, id + 1, lastPhaseId)
2828

2929
/** The transformation method */
3030
def transform(ref: SingleDenotation)(using Context): SingleDenotation

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,11 @@ object Denotations {
686686

687687
private def updateValidity()(using Context): this.type = {
688688
assert(
689-
currentRunId >= validFor.runId
689+
ctx.runId >= validFor.runId
690690
|| ctx.settings.YtestPickler.value // mixing test pickler with debug printing can travel back in time
691691
|| ctx.mode.is(Mode.Printing) // no use to be picky when printing error messages
692692
|| symbol.isOneOf(ValidForeverFlags),
693-
s"denotation $this invalid in run ${currentRunId}. ValidFor: $validFor")
693+
s"denotation $this invalid in run ${ctx.runId}. ValidFor: $validFor")
694694
var d: SingleDenotation = this
695695
while ({
696696
d.validFor = Period(currentPeriod.runId, d.validFor.firstPhaseId, d.validFor.lastPhaseId)
@@ -720,7 +720,7 @@ object Denotations {
720720
case _ =>
721721
}
722722
if (!symbol.exists) return updateValidity()
723-
if (!coveredInterval.containsPhaseId(currentPhaseId)) return NoDenotation
723+
if (!coveredInterval.containsPhaseId(ctx.phaseId)) return NoDenotation
724724
if (ctx.debug) traceInvalid(this)
725725
staleSymbolError
726726
}
@@ -842,7 +842,7 @@ object Denotations {
842842
}
843843

844844
private def demandOutsideDefinedMsg(using Context): String =
845-
s"demanding denotation of $this at phase ${currentPhase}(${currentPhaseId}) outside defined interval: defined periods are${definedPeriodsString}"
845+
s"demanding denotation of $this at phase ${currentPhase}(${ctx.phaseId}) outside defined interval: defined periods are${definedPeriodsString}"
846846

847847
/** Install this denotation to be the result of the given denotation transformer.
848848
* This is the implementation of the same-named method in SymDenotations.
@@ -851,16 +851,16 @@ object Denotations {
851851
*/
852852
protected def installAfter(phase: DenotTransformer)(using Context): Unit = {
853853
val targetId = phase.next.id
854-
if (currentPhaseId != targetId) atPhase(phase.next)(installAfter(phase))
854+
if (ctx.phaseId != targetId) atPhase(phase.next)(installAfter(phase))
855855
else {
856856
val current = symbol.current
857857
// println(s"installing $this after $phase/${phase.id}, valid = ${current.validFor}")
858858
// printPeriods(current)
859-
this.validFor = Period(currentRunId, targetId, current.validFor.lastPhaseId)
859+
this.validFor = Period(ctx.runId, targetId, current.validFor.lastPhaseId)
860860
if (current.validFor.firstPhaseId >= targetId)
861861
current.replaceWith(this)
862862
else {
863-
current.validFor = Period(currentRunId, current.validFor.firstPhaseId, targetId - 1)
863+
current.validFor = Period(ctx.runId, current.validFor.firstPhaseId, targetId - 1)
864864
insertAfter(current)
865865
}
866866
}
@@ -1071,7 +1071,7 @@ object Denotations {
10711071
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType) {
10721072
override def exists: Boolean = false
10731073
override def hasUniqueSym: Boolean = false
1074-
validFor = Period.allInRun(currentRunId)
1074+
validFor = Period.allInRun(ctx.runId)
10751075
protected def newLikeThis(s: Symbol, i: Type, pre: Type): SingleDenotation =
10761076
this
10771077
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ object Periods {
1111
* we take the next transformer id following the current phase.
1212
*/
1313
def currentStablePeriod(using Context): Period =
14-
var first = currentPhaseId
14+
var first = ctx.phaseId
1515
val nxTrans = ctx.base.nextDenotTransformerId(first)
1616
while (first - 1 > NoPhaseId && (ctx.base.nextDenotTransformerId(first - 1) == nxTrans))
1717
first -= 1
18-
Period(currentRunId, first, nxTrans)
18+
Period(ctx.runId, first, nxTrans)
1919

2020
/** Are all base types in the current period guaranteed to be the same as in period `p`? */
2121
def currentHasSameBaseTypesAs(p: Period)(using Context): Boolean =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ object Scopes {
265265

266266
/** enter a symbol in this scope. */
267267
final def enter[T <: Symbol](sym: T)(using Context): T = {
268-
if (sym.isType && currentPhaseId <= typerPhase.id)
268+
if (sym.isType && ctx.phaseId <= typerPhase.id)
269269
assert(lookup(sym.name) == NoSymbol,
270270
s"duplicate ${sym.debugString}; previous was ${lookup(sym.name).debugString}") // !!! DEBUG
271271
newScopeEntry(sym)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ object SymDenotations {
21042104
* `phase.next`, install a new denotation with a cloned scope in `phase.next`.
21052105
*/
21062106
def ensureFreshScopeAfter(phase: DenotTransformer)(using Context): Unit =
2107-
if (currentPhaseId != phase.next.id) atPhase(phase.next)(ensureFreshScopeAfter(phase))
2107+
if (ctx.phaseId != phase.next.id) atPhase(phase.next)(ensureFreshScopeAfter(phase))
21082108
else {
21092109
val prevClassInfo = atPhase(phase) {
21102110
current.asInstanceOf[ClassDenotation].classInfo
@@ -2154,8 +2154,8 @@ object SymDenotations {
21542154

21552155
/** The package objects in this class */
21562156
def packageObjs(using Context): List[ClassDenotation] = {
2157-
if (packageObjsRunId != currentRunId) {
2158-
packageObjsRunId = currentRunId
2157+
if (packageObjsRunId != ctx.runId) {
2158+
packageObjsRunId = ctx.runId
21592159
packageObjsCache = Nil // break cycle in case we are looking for package object itself
21602160
packageObjsCache = {
21612161
val pkgObjBuf = new mutable.ListBuffer[ClassDenotation]
@@ -2296,7 +2296,7 @@ object SymDenotations {
22962296
for (sym <- scope.toList.iterator)
22972297
// We need to be careful to not force the denotation of `sym` here,
22982298
// otherwise it will be brought forward to the current run.
2299-
if (sym.defRunId != currentRunId && sym.isClass && sym.asClass.assocFile == file)
2299+
if (sym.defRunId != ctx.runId && sym.isClass && sym.asClass.assocFile == file)
23002300
scope.unlink(sym, sym.lastKnownDenotation.name)
23012301
}
23022302
}
@@ -2348,7 +2348,7 @@ object SymDenotations {
23482348
else {
23492349
val initial = denot.initial
23502350
val firstPhaseId = initial.validFor.firstPhaseId.max(typerPhase.id)
2351-
if ((initial ne denot) || currentPhaseId != firstPhaseId)
2351+
if ((initial ne denot) || ctx.phaseId != firstPhaseId)
23522352
atPhase(firstPhaseId)(stillValidInOwner(initial))
23532353
else
23542354
stillValidInOwner(denot)
@@ -2381,7 +2381,7 @@ object SymDenotations {
23812381
if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass) true
23822382
else
23832383
val initial = denot.initial
2384-
if ((initial ne denot) || currentPhaseId != initial.validFor.firstPhaseId)
2384+
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId)
23852385
atPhase(initial.validFor.firstPhaseId)(traceInvalid(initial))
23862386
else try {
23872387
val owner = denot.owner.denot
@@ -2576,7 +2576,7 @@ object SymDenotations {
25762576

25772577
def isValidAt(phase: Phase)(using Context) =
25782578
checkedPeriod == currentPeriod ||
2579-
createdAt.runId == currentRunId &&
2579+
createdAt.runId == ctx.runId &&
25802580
createdAt.phaseId < unfusedPhases.length &&
25812581
sameGroup(unfusedPhases(createdAt.phaseId), phase) &&
25822582
{ checkedPeriod = currentPeriod; true }

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,24 @@ object Symbols {
134134

135135
/** Does this symbol come from a currently compiled source file? */
136136
final def isDefinedInCurrentRun(using Context): Boolean =
137-
span.exists && defRunId == currentRunId && {
137+
span.exists && defRunId == ctx.runId && {
138138
val file = associatedFile
139139
file != null && ctx.run.files.contains(file)
140140
}
141141

142142
/** Is symbol valid in current run? */
143143
final def isValidInCurrentRun(using Context): Boolean =
144-
(lastDenot.validFor.runId == currentRunId || stillValid(lastDenot)) &&
144+
(lastDenot.validFor.runId == ctx.runId || stillValid(lastDenot)) &&
145145
(lastDenot.symbol eq this)
146146
// the last condition is needed because under ctx.staleOK overwritten
147147
// members keep denotations pointing to the new symbol, so the validity
148148
// periods check out OK. But once a package member is overridden it is not longer
149149
// valid. If the option would be removed, the check would be no longer needed.
150150

151151
final def isTerm(using Context): Boolean =
152-
(if (defRunId == currentRunId) lastDenot else denot).isTerm
152+
(if (defRunId == ctx.runId) lastDenot else denot).isTerm
153153
final def isType(using Context): Boolean =
154-
(if (defRunId == currentRunId) lastDenot else denot).isType
154+
(if (defRunId == ctx.runId) lastDenot else denot).isType
155155
final def asTerm(using Context): TermSymbol = {
156156
assert(isTerm, s"asTerm called on not-a-Term $this" );
157157
asInstanceOf[TermSymbol]
@@ -204,7 +204,7 @@ object Symbols {
204204
* @pre Symbol is a class member
205205
*/
206206
def enteredAfter(phase: DenotTransformer)(using Context): this.type =
207-
if currentPhaseId != phase.next.id then
207+
if ctx.phaseId != phase.next.id then
208208
atPhase(phase.next)(enteredAfter(phase))
209209
else this.owner match {
210210
case owner: ClassSymbol =>
@@ -229,7 +229,7 @@ object Symbols {
229229
* @pre Symbol is a class member
230230
*/
231231
def dropAfter(phase: DenotTransformer)(using Context): Unit =
232-
if currentPhaseId != phase.next.id then
232+
if ctx.phaseId != phase.next.id then
233233
atPhase(phase.next)(dropAfter(phase))
234234
else {
235235
assert (!this.owner.is(Package))

0 commit comments

Comments
 (0)