Skip to content

Commit 9b99a46

Browse files
committed
Move phase back to Context
1 parent a1f63e6 commit 9b99a46

27 files changed

+65
-68
lines changed

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

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

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

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

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

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

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

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

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

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

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

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class ClassfileParser(
309309

310310
/** Map direct references to Object to references to Any */
311311
final def objToAny(tp: Type)(using Context): Type =
312-
if (tp.isDirectRef(defn.ObjectClass) && !currentPhase.erasedTypes) defn.AnyType else tp
312+
if (tp.isDirectRef(defn.ObjectClass) && !ctx.phase.erasedTypes) defn.AnyType else tp
313313

314314
def constantTagToType(tag: Int)(using Context): Type =
315315
(tag: @switch) match {

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
986986
protected def deferredAnnot(end: Int)(using Context): Annotation = {
987987
val start = readIndex
988988
val atp = readTypeRef()
989-
val phase = currentPhase
989+
val phase = ctx.phase
990990
Annotation.deferred(atp.typeSymbol)(
991991
atReadPos(start, () => atPhase(phase)(readAnnotationContents(end))))
992992
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ object report:
9292
* "contains" here.
9393
*/
9494
def log(msg: => String, pos: SourcePosition = NoSourcePosition)(using Context): Unit =
95-
if (ctx.settings.Ylog.value.containsPhase(currentPhase))
96-
echo(s"[log $currentPhase] $msg", pos)
95+
if (ctx.settings.Ylog.value.containsPhase(ctx.phase))
96+
echo(s"[log $ctx.phase] $msg", pos)
9797

9898
def debuglog(msg: => String)(using Context): Unit =
9999
if (ctx.debug) log(msg)

compiler/src/dotty/tools/dotc/reporting/messages.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ import ast.tpd
20112011
case NoMatch =>
20122012
// If the signatures don't match at all at the current phase, then
20132013
// they might match after erasure.
2014-
if currentPhase.id <= elimErasedValueTypePhase.id then
2014+
if ctx.phase.id <= elimErasedValueTypePhase.id then
20152015
atPhase(elimErasedValueTypePhase.next)(details)
20162016
else
20172017
"" // shouldn't be reachable

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import util.SourcePosition
1414
class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
1515
import ast.tpd._
1616

17-
assert(currentPhase == erasurePhase.next)
17+
assert(ctx.phase == erasurePhase.next)
1818
private val preErasureCtx = ctx.withPhase(erasurePhase)
1919
private lazy val elimErasedCtx = ctx.withPhase(elimErasedValueTypePhase.next)
2020

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ class Erasure extends Phase with DenotTransformer {
5050
case ref: SymDenotation =>
5151
def isCompacted(symd: SymDenotation) =
5252
symd.isAnonymousFunction && {
53-
atPhase(currentPhase.next)(symd.info) match {
53+
atPhase(ctx.phase.next)(symd.info) match {
5454
case MethodType(nme.ALLARGS :: Nil) => true
5555
case _ => false
5656
}
5757
}
5858

59-
assert(currentPhase == this, s"transforming $ref at ${currentPhase}")
59+
assert(ctx.phase == this, s"transforming $ref at ${ctx.phase}")
6060
if (ref.symbol eq defn.ObjectClass) {
6161
// After erasure, all former Any members are now Object members
6262
val ClassInfo(pre, _, ps, decls, selfInfo) = ref.info
@@ -99,7 +99,7 @@ class Erasure extends Phase with DenotTransformer {
9999
then
100100
ref
101101
else
102-
assert(!ref.is(Flags.PackageClass), s"trans $ref @ ${currentPhase} oldOwner = $oldOwner, newOwner = $newOwner, oldInfo = $oldInfo, newInfo = $newInfo ${oldOwner eq newOwner} ${oldInfo eq newInfo}")
102+
assert(!ref.is(Flags.PackageClass), s"trans $ref @ ${ctx.phase} oldOwner = $oldOwner, newOwner = $newOwner, oldInfo = $oldInfo, newInfo = $newInfo ${oldOwner eq newOwner} ${oldInfo eq newInfo}")
103103
ref.copySymDenotation(
104104
symbol = newSymbol,
105105
owner = newOwner,
@@ -166,7 +166,7 @@ class Erasure extends Phase with DenotTransformer {
166166
isAllowed(defn.TupleClass, "Tuple.scala") ||
167167
isAllowed(defn.NonEmptyTupleClass, "Tuple.scala") ||
168168
isAllowed(defn.PairClass, "Tuple.scala"),
169-
i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree : ${tree.tpe} / ${tree.getClass} is illegal after erasure, phase = ${currentPhase.prev}")
169+
i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree : ${tree.tpe} / ${tree.getClass} is illegal after erasure, phase = ${ctx.phase.prev}")
170170
}
171171
}
172172

@@ -981,7 +981,7 @@ object Erasure {
981981

982982
override def adapt(tree: Tree, pt: Type, locked: TypeVars, tryGadtHealing: Boolean)(using Context): Tree =
983983
trace(i"adapting ${tree.showSummary}: ${tree.tpe} to $pt", show = true) {
984-
if currentPhase != erasurePhase && currentPhase != erasurePhase.next then
984+
if ctx.phase != erasurePhase && ctx.phase != erasurePhase.next then
985985
// this can happen when reading annotations loaded during erasure,
986986
// since these are loaded at phase typer.
987987
atPhase(erasurePhase.next)(adapt(tree, pt, locked))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
117117
case ClassInfo(pre, cls, _, _, _) if cls is ModuleClass =>
118118
cls.linkedClass match {
119119
case valueClass: ClassSymbol if isDerivedValueClass(valueClass) =>
120-
val info1 = atPhase(currentPhase.next)(cls.denot).asClass.classInfo.derivedClassInfo(prefix = pre)
120+
val info1 = atPhase(ctx.phase.next)(cls.denot).asClass.classInfo.derivedClassInfo(prefix = pre)
121121
ref.derivedSingleDenotation(ref.symbol, info1)
122122
case _ => ref
123123
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Staging extends MacroTransform {
3939
override def allowsImplicitSearch: Boolean = true
4040

4141
override def checkPostCondition(tree: Tree)(using Context): Unit =
42-
if (currentPhase <= reifyQuotesPhase) {
42+
if (ctx.phase <= reifyQuotesPhase) {
4343
// Recheck that PCP holds but do not heal any inconsistent types as they should already have been heald
4444
tree match {
4545
case PackageDef(pid, _) if tree.symbol.owner == defn.RootClass =>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
130130
case nme.productElementName => productElementNameBody(accessors.length, vrefss.head.head)
131131
case nme.ordinal => Select(This(clazz), nme.ordinalDollar)
132132
}
133-
report.log(s"adding $synthetic to $clazz at ${currentPhase}")
133+
report.log(s"adding $synthetic to $clazz at ${ctx.phase}")
134134
synthesizeDef(synthetic, syntheticRHS)
135135
}
136136

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
3737
def mkByNameClosure(arg: Tree, argType: Type)(using Context): Tree = unsupported(i"mkClosure($arg)")
3838

3939
override def transformApply(tree: Apply)(using Context): Tree =
40-
trace(s"transforming ${tree.show} at phase ${currentPhase}", show = true) {
40+
trace(s"transforming ${tree.show} at phase ${ctx.phase}", show = true) {
4141

4242
def transformArg(arg: Tree, formal: Type): Tree = formal.dealias match {
4343
case formalExpr: ExprType =>

0 commit comments

Comments
 (0)