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

+1-1
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

+1-1
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

+3
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

+2-2
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

+1-1
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

+8-8
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

+2-2
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

+1-1
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

+7-7
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

+6-6
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))

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ object Types {
677677
}
678678
else
679679
val joint = pdenot.meet(
680-
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(currentRunId), pre),
680+
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre),
681681
pre,
682682
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
683683
joint match
@@ -1914,7 +1914,7 @@ object Types {
19141914
* some symbols change their signature at erasure.
19151915
*/
19161916
private def currentSignature(using Context): Signature =
1917-
if currentRunId == mySignatureRunId then mySignature
1917+
if ctx.runId == mySignatureRunId then mySignature
19181918
else
19191919
val lastd = lastDenotation
19201920
if lastd != null then sigFromDenot(lastd)
@@ -1948,7 +1948,7 @@ object Types {
19481948
* current run.
19491949
*/
19501950
def denotationIsCurrent(using Context): Boolean =
1951-
lastDenotation != null && lastDenotation.validFor.runId == currentRunId
1951+
lastDenotation != null && lastDenotation.validFor.runId == ctx.runId
19521952

19531953
/** If the reference is symbolic or the denotation is current, its symbol, otherwise NoDenotation.
19541954
*
@@ -1969,7 +1969,7 @@ object Types {
19691969
* Used to get the class underlying a ThisType.
19701970
*/
19711971
private[Types] def stableInRunSymbol(using Context): Symbol =
1972-
if (checkedPeriod.runId == currentRunId) lastSymbol
1972+
if (checkedPeriod.runId == ctx.runId) lastSymbol
19731973
else symbol
19741974

19751975
def info(using Context): Type = denot.info
@@ -2008,7 +2008,7 @@ object Types {
20082008
finish(memberDenot(name, allowPrivate))
20092009
case sym: Symbol =>
20102010
val symd = sym.lastKnownDenotation
2011-
if (symd.validFor.runId != currentRunId && !stillValid(symd))
2011+
if (symd.validFor.runId != ctx.runId && !stillValid(symd))
20122012
finish(memberDenot(symd.initial.name, allowPrivate = false))
20132013
else if (prefix.isArgPrefixOf(symd))
20142014
finish(argDenot(sym.asType))
@@ -2021,7 +2021,7 @@ object Types {
20212021
lastDenotation match {
20222022
case lastd0: SingleDenotation =>
20232023
val lastd = lastd0.skipRemoved
2024-
if (lastd.validFor.runId == currentRunId && (checkedPeriod != Nowhere)) finish(lastd.current)
2024+
if (lastd.validFor.runId == ctx.runId && (checkedPeriod != Nowhere)) finish(lastd.current)
20252025
else lastd match {
20262026
case lastd: SymDenotation =>
20272027
if (stillValid(lastd) && (checkedPeriod != Nowhere)) finish(lastd.current)
@@ -2053,9 +2053,9 @@ object Types {
20532053
if (!d.exists && !allowPrivate && ctx.mode.is(Mode.Interactive))
20542054
// In the IDE we might change a public symbol to private, and would still expect to find it.
20552055
d = memberDenot(prefix, name, true)
2056-
if (!d.exists && currentPhaseId > FirstPhaseId && lastDenotation.isInstanceOf[SymDenotation])
2056+
if (!d.exists && ctx.phaseId > FirstPhaseId && lastDenotation.isInstanceOf[SymDenotation])
20572057
// name has changed; try load in earlier phase and make current
2058-
d = atPhase(currentPhaseId - 1)(memberDenot(name, allowPrivate)).current
2058+
d = atPhase(ctx.phaseId - 1)(memberDenot(name, allowPrivate)).current
20592059
if (d.isOverloaded)
20602060
d = disambiguate(d)
20612061
d
@@ -2155,7 +2155,7 @@ object Types {
21552155
s"""data race? overwriting $lastSymbol with $sym in type $this,
21562156
|last sym id = ${lastSymbol.id}, new sym id = ${sym.id},
21572157
|last owner = ${lastSymbol.owner}, new owner = ${sym.owner},
2158-
|period = ${currentPhase} at run ${currentRunId}""")
2158+
|period = ${currentPhase} at run ${ctx.runId}""")
21592159
}
21602160

21612161
/** A reference with the initial symbol in `symd` has an info that
@@ -2980,12 +2980,12 @@ object Types {
29802980
private var myWidened: Type = _
29812981

29822982
private def ensureAtomsComputed()(using Context): Unit =
2983-
if atomsRunId != currentRunId then
2983+
if atomsRunId != ctx.runId then
29842984
myAtoms = tp1.atoms | tp2.atoms
29852985
val tp1w = tp1.widenSingletons
29862986
val tp2w = tp2.widenSingletons
29872987
myWidened = if ((tp1 eq tp1w) && (tp2 eq tp2w)) this else tp1w | tp2w
2988-
atomsRunId = currentRunId
2988+
atomsRunId = ctx.runId
29892989

29902990
override def atoms(using Context): Atoms =
29912991
ensureAtomsComputed()
@@ -3070,9 +3070,9 @@ object Types {
30703070
protected[dotc] def computeSignature(using Context): Signature
30713071

30723072
final override def signature(using Context): Signature = {
3073-
if (currentRunId != mySignatureRunId) {
3073+
if (ctx.runId != mySignatureRunId) {
30743074
mySignature = computeSignature
3075-
if (!mySignature.isUnderDefined) mySignatureRunId = currentRunId
3075+
if (!mySignature.isUnderDefined) mySignatureRunId = ctx.runId
30763076
}
30773077
mySignature
30783078
}
@@ -4994,11 +4994,11 @@ object Types {
49944994
case tp: LazyRef =>
49954995
LazyRef {
49964996
val ref1 = tp.ref
4997-
if currentRunId == currentRunId(using mapCtx) then this(ref1)
4997+
if ctx.runId == mapCtx.runId then this(ref1)
49984998
else // splice in new run into map context
49994999
val saved = mapCtx
50005000
mapCtx = mapCtx.fresh
5001-
.setPeriod(Period(currentRunId, currentPhaseId(using mapCtx)))
5001+
.setPeriod(Period(ctx.runId, mapCtx.phaseId))
50025002
.setRun(ctx.run)
50035003
try this(ref1) finally mapCtx = saved
50045004
}

compiler/src/dotty/tools/dotc/transform/Pickler.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Pickler extends Phase {
4747

4848
override def run(using Context): Unit = {
4949
val unit = ctx.compilationUnit
50-
pickling.println(i"unpickling in run ${currentRunId}")
50+
pickling.println(i"unpickling in run ${ctx.runId}")
5151

5252
for {
5353
cls <- dropCompanionModuleClasses(topLevelClasses(unit.tpdTree))
@@ -92,7 +92,7 @@ class Pickler extends Phase {
9292
if (ctx.settings.YtestPickler.value)
9393
testUnpickler(
9494
using ctx.fresh
95-
.setPeriod(Period(currentRunId + 1, FirstPhaseId))
95+
.setPeriod(Period(ctx.runId + 1, FirstPhaseId))
9696
.setReporter(new ThrowingReporter(ctx.reporter))
9797
.addMode(Mode.ReadPositions)
9898
.addMode(Mode.ReadComments)
@@ -101,7 +101,7 @@ class Pickler extends Phase {
101101
}
102102

103103
private def testUnpickler(using Context): Unit = {
104-
pickling.println(i"testing unpickler at run ${currentRunId}")
104+
pickling.println(i"testing unpickler at run ${ctx.runId}")
105105
ctx.initialize()
106106
val unpicklers =
107107
for ((cls, pickler) <- picklers) yield {

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class TreeChecker extends Phase with SymTransformer {
8989

9090
// Signatures are used to disambiguate overloads and need to stay stable
9191
// until erasure, see the comment above `Compiler#phases`.
92-
if (currentPhaseId <= erasurePhase.id) {
92+
if (ctx.phaseId <= erasurePhase.id) {
9393
val cur = symd.info
9494
val initial = symd.initial.info
9595
val curSig = cur match {

compiler/src/dotty/tools/dotc/transform/ValueClasses.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object ValueClasses {
2525
def isMethodWithExtension(sym: Symbol)(using Context): Boolean =
2626
atPhaseNoLater(extensionMethodsPhase) {
2727
val d = sym.denot
28-
d.validFor.containsPhaseId(currentPhaseId) &&
28+
d.validFor.containsPhaseId(ctx.phaseId) &&
2929
d.isRealMethod &&
3030
isDerivedValueClass(d.owner) &&
3131
!d.isConstructor &&

0 commit comments

Comments
 (0)