Skip to content

Commit 2ccebc5

Browse files
committed
Move phase back to Context
1 parent 1679663 commit 2ccebc5

27 files changed

+65
-68
lines changed

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

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

237237
private def printTree(last: PrintedTree)(using Context): PrintedTree = {
238238
val unit = ctx.compilationUnit
239-
val prevPhase = currentPhase.prev // can be a mini-phase
239+
val prevPhase = ctx.phase.prev // can be a mini-phase
240240
val squashedPhase = ctx.base.squashed(prevPhase)
241241
val treeString = unit.tpdTree.show(using ctx.withProperty(XprintMode, Some(())))
242242

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
828828
* owner by `from` to `to`.
829829
*/
830830
def changeOwnerAfter(from: Symbol, to: Symbol, trans: DenotTransformer)(using Context): ThisTree =
831-
if (currentPhase == trans.next) {
831+
if (ctx.phase == trans.next) {
832832
val traverser = new TreeTraverser {
833833
def traverse(tree: Tree)(using Context) = tree match {
834834
case tree: DefTree =>

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,20 @@ object Contexts {
7272
atPhase(phase.id)(op)
7373

7474
inline def atNextPhase[T](inline op: Context ?=> T)(using Context): T =
75-
atPhase(currentPhase.next)(op)
75+
atPhase(ctx.phase.next)(op)
7676

7777
inline def atPhaseNoLater[T](limit: Phase)(inline op: Context ?=> T)(using Context): T =
78-
op(using if !limit.exists || currentPhase <= limit then ctx else ctx.withPhase(limit))
78+
op(using if !limit.exists || ctx.phase <= limit then ctx else ctx.withPhase(limit))
7979

8080
inline def atPhaseNoEarlier[T](limit: Phase)(inline op: Context ?=> T)(using Context): T =
81-
op(using if !limit.exists || limit <= currentPhase then ctx else ctx.withPhase(limit))
81+
op(using if !limit.exists || limit <= ctx.phase then ctx else ctx.withPhase(limit))
8282

8383
inline def currentPeriod(using ctx: Context): Period = ctx.period
8484

85-
inline def currentPhase(using ctx: Context): Phase = ctx.base.phases(ctx.period.firstPhaseId)
86-
87-
inline def currentRunId(using ctx: Context): Int = ctx.period.runId
88-
89-
inline def currentPhaseId(using ctx: Context): Int = ctx.period.phaseId
90-
91-
def currentlyAfterTyper(using Context): Boolean = ctx.base.isAfterTyper(currentPhase)
85+
def currentlyAfterTyper(using Context): Boolean = ctx.base.isAfterTyper(ctx.phase)
9286

9387
/** Does current phase use an erased types interpretation? */
94-
def currentlyAfterErasure(using Context): Boolean = currentPhase.erasedTypes
88+
def currentlyAfterErasure(using Context): Boolean = ctx.phase.erasedTypes
9589

9690
inline def inMode[T](mode: Mode)(inline op: Context ?=> T)(using ctx: Context): T =
9791
op(using if mode != ctx.mode then ctx.fresh.setMode(mode) else ctx)
@@ -369,8 +363,11 @@ object Contexts {
369363
/** The current reporter */
370364
def reporter: Reporter = typerState.reporter
371365

366+
final def phase: Phase = base.phases(period.firstPhaseId)
372367
final def runId = period.runId
373368
final def phaseId = period.phaseId
369+
final def erasedTypes = phase.erasedTypes
370+
final def isAfterTyper = base.isAfterTyper(phase)
374371

375372
/** Is this a context for the members of a class definition? */
376373
def isClassDefContext: Boolean =

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ class Definitions {
867867

868868
def ClassType(arg: Type)(using Context): Type = {
869869
val ctype = ClassClass.typeRef
870-
if (currentPhase.erasedTypes) ctype else ctype.appliedTo(arg)
870+
if (ctx.phase.erasedTypes) ctype else ctype.appliedTo(arg)
871871
}
872872

873873
/** The enumeration type, goven a value of the enumeration */
@@ -1041,13 +1041,13 @@ class Definitions {
10411041
name.drop(prefix.length).forall(_.isDigit))
10421042

10431043
def isBottomClass(cls: Symbol): Boolean =
1044-
if (ctx.explicitNulls && !currentPhase.erasedTypes) cls == NothingClass
1044+
if (ctx.explicitNulls && !ctx.phase.erasedTypes) cls == NothingClass
10451045
else isBottomClassAfterErasure(cls)
10461046

10471047
def isBottomClassAfterErasure(cls: Symbol): Boolean = cls == NothingClass || cls == NullClass
10481048

10491049
def isBottomType(tp: Type): Boolean =
1050-
if (ctx.explicitNulls && !currentPhase.erasedTypes) tp.derivesFrom(NothingClass)
1050+
if (ctx.explicitNulls && !ctx.phase.erasedTypes) tp.derivesFrom(NothingClass)
10511051
else isBottomTypeAfterErasure(tp)
10521052

10531053
def isBottomTypeAfterErasure(tp: Type): Boolean =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object DenotTransformers {
4343
if (info1 eq ref.info) ref
4444
else ref match {
4545
case ref: SymDenotation =>
46-
ref.copySymDenotation(info = info1).copyCaches(ref, currentPhase.next)
46+
ref.copySymDenotation(info = info1).copyCaches(ref, ctx.phase.next)
4747
case _ =>
4848
ref.derivedSingleDenotation(ref.symbol, info1)
4949
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ object Denotations {
842842
}
843843

844844
private def demandOutsideDefinedMsg(using Context): String =
845-
s"demanding denotation of $this at phase ${currentPhase}(${ctx.phaseId}) outside defined interval: defined periods are${definedPeriodsString}"
845+
s"demanding denotation of $this at phase ${ctx.phase}(${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.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ object SymDenotations {
762762

763763
/** Is this symbol a class of which `null` is a value? */
764764
final def isNullableClass(using Context): Boolean =
765-
if (ctx.explicitNulls && !currentPhase.erasedTypes) symbol == defn.NullClass || symbol == defn.AnyClass
765+
if (ctx.explicitNulls && !ctx.phase.erasedTypes) symbol == defn.NullClass || symbol == defn.AnyClass
766766
else isNullableClassAfterErasure
767767

768768
/** Is this symbol a class of which `null` is a value after erasure?
@@ -849,7 +849,7 @@ object SymDenotations {
849849
|| this.is(Protected) &&
850850
( superAccess
851851
|| pre.isInstanceOf[ThisType]
852-
|| currentPhase.erasedTypes
852+
|| ctx.phase.erasedTypes
853853
|| isProtectedAccessOK
854854
)
855855
)
@@ -1325,7 +1325,7 @@ object SymDenotations {
13251325
final def accessBoundary(base: Symbol)(using Context): Symbol =
13261326
if (this.is(Private)) owner
13271327
else if (this.isAllOf(StaticProtected)) defn.RootClass
1328-
else if (privateWithin.exists && !currentPhase.erasedTypes) privateWithin
1328+
else if (privateWithin.exists && !ctx.phase.erasedTypes) privateWithin
13291329
else if (this.is(Protected)) base
13301330
else defn.RootClass
13311331

@@ -1451,7 +1451,7 @@ object SymDenotations {
14511451
val initFlags1 = (if (initFlags != UndefinedFlags) initFlags else this.flags)
14521452
val info1 = if (info != null) info else this.info
14531453
if (currentlyAfterTyper && changedClassParents(info, info1, completersMatter = false))
1454-
assert(currentPhase.changesParents, i"undeclared parent change at ${currentPhase} for $this, was: $info, now: $info1")
1454+
assert(ctx.phase.changesParents, i"undeclared parent change at ${ctx.phase} for $this, was: $info, now: $info1")
14551455
val privateWithin1 = if (privateWithin != null) privateWithin else this.privateWithin
14561456
val annotations1 = if (annotations != null) annotations else this.annotations
14571457
val rawParamss1 = if rawParamss != null then rawParamss else this.rawParamss
@@ -2592,7 +2592,7 @@ object SymDenotations {
25922592
private var cache: SimpleIdentityMap[NameFilter, Set[Name]] = SimpleIdentityMap.Empty
25932593

25942594
final def isValid(using Context): Boolean =
2595-
cache != null && isValidAt(currentPhase)
2595+
cache != null && isValidAt(ctx.phase)
25962596

25972597
private var locked = false
25982598

@@ -2634,7 +2634,7 @@ object SymDenotations {
26342634
private var locked = false
26352635
private var provisional = false
26362636

2637-
final def isValid(using Context): Boolean = valid && isValidAt(currentPhase)
2637+
final def isValid(using Context): Boolean = valid && isValidAt(ctx.phase)
26382638

26392639
def invalidate(): Unit =
26402640
if (valid && !locked) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
388388
}
389389
case tp1: SkolemType =>
390390
tp2 match {
391-
case tp2: SkolemType if !currentPhase.isTyper && recur(tp1.info, tp2.info) => true
391+
case tp2: SkolemType if !ctx.phase.isTyper && recur(tp1.info, tp2.info) => true
392392
case _ => thirdTry
393393
}
394394
case tp1: TypeVar =>
@@ -808,7 +808,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
808808
case _ => tp2.isAnyRef
809809
}
810810
compareJavaArray
811-
case tp1: ExprType if currentPhase.id > gettersPhase.id =>
811+
case tp1: ExprType if ctx.phase.id > gettersPhase.id =>
812812
// getters might have converted T to => T, need to compensate.
813813
recur(tp1.widenExpr, tp2)
814814
case _ =>
@@ -1233,7 +1233,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
12331233
* for equality would give the wrong result, so we should not use the sets
12341234
* for comparisons.
12351235
*/
1236-
def canCompare(ts: Set[Type]) = currentPhase.isTyper || {
1236+
def canCompare(ts: Set[Type]) = ctx.phase.isTyper || {
12371237
val hasSkolems = new ExistsAccumulator(_.isInstanceOf[SkolemType]) {
12381238
override def stopAtStatic = true
12391239
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ object TypeOps:
122122
}
123123

124124
def isLegalPrefix(pre: Type)(using Context): Boolean =
125-
pre.isStable || !currentPhase.isTyper
125+
pre.isStable || !ctx.phase.isTyper
126126

127127
/** Implementation of Types#simplified */
128128
def simplify(tp: Type, theMap: SimplifyMap)(using Context): Type = {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ object Types {
980980
*/
981981
def matches(that: Type)(using Context): Boolean = {
982982
record("matches")
983-
ctx.typeComparer.matchesType(this, that, relaxed = !currentPhase.erasedTypes)
983+
ctx.typeComparer.matchesType(this, that, relaxed = !ctx.phase.erasedTypes)
984984
}
985985

986986
/** This is the same as `matches` except that it also matches => T with T and
@@ -2094,7 +2094,7 @@ object Types {
20942094
else {
20952095
if (!ctx.reporter.errorsReported)
20962096
throw new TypeError(
2097-
i"""bad parameter reference $this at ${currentPhase}
2097+
i"""bad parameter reference $this at ${ctx.phase}
20982098
|the parameter is ${param.showLocated} but the prefix $prefix
20992099
|does not define any corresponding arguments.""")
21002100
NoDenotation
@@ -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 ${ctx.runId}""")
2158+
|period = ${ctx.phase} at run ${ctx.runId}""")
21592159
}
21602160

21612161
/** A reference with the initial symbol in `symd` has an info that
@@ -2489,7 +2489,7 @@ object Types {
24892489

24902490
/** Assert current phase does not have erasure semantics */
24912491
private def assertUnerased()(using Context) =
2492-
if (Config.checkUnerased) assert(!currentPhase.erasedTypes)
2492+
if (Config.checkUnerased) assert(!ctx.phase.erasedTypes)
24932493

24942494
/** The designator to be used for a named type creation with given prefix, name, and denotation.
24952495
* This is the denotation's symbol, if it exists and the prefix is not the this type

0 commit comments

Comments
 (0)