Skip to content

Commit 3b181cf

Browse files
committed
Use atPhase instead of passing ctx.withPhase
1 parent cd9f05d commit 3b181cf

20 files changed

+47
-43
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
833833
def traverse(tree: Tree)(using Context) = tree match {
834834
case tree: DefTree =>
835835
val sym = tree.symbol
836-
val prevDenot = sym.denot(using ctx.withPhase(trans))
836+
val prevDenot = atPhase(trans)(sym.denot)
837837
if (prevDenot.effectiveOwner == from.skipWeakOwner) {
838838
val d = sym.copySymDenotation(owner = to)
839839
d.installAfter(trans)
@@ -847,7 +847,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
847847
traverser.traverse(tree)
848848
tree
849849
}
850-
else changeOwnerAfter(from, to, trans)(using ctx.withPhase(trans.next))
850+
else atPhase(trans.next)(changeOwnerAfter(from, to, trans))
851851

852852
/** A select node with the given selector name and a computed type */
853853
def select(name: Name)(using Context): Select =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ class Definitions {
12851285
object ContextFunctionType:
12861286
def unapply(tp: Type)(using Context): Option[(List[Type], Type, Boolean)] =
12871287
if ctx.erasedTypes then
1288-
unapply(tp)(using ctx.withPhase(erasurePhase))
1288+
atPhase(erasurePhase)(unapply(tp))
12891289
else
12901290
val tp1 = tp.dealias
12911291
if isContextFunctionClass(tp1.typeSymbol) then

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package core
44

55
import SymDenotations.{ SymDenotation, ClassDenotation, NoDenotation, LazyType }
6-
import Contexts.{Context, ctx, ContextBase}
6+
import Contexts._
77
import Names._
88
import NameKinds._
99
import StdNames._
@@ -797,7 +797,7 @@ object Denotations {
797797
val transformer = ctx.base.denotTransformers(nextTransformerId)
798798
//println(s"transforming $this with $transformer")
799799
try
800-
next = transformer.transform(cur)(using ctx.withPhase(transformer))
800+
next = atPhase(transformer)(transformer.transform(cur))
801801
catch {
802802
case ex: CyclicReference =>
803803
println(s"error while transforming $this") // DEBUG
@@ -834,7 +834,7 @@ object Denotations {
834834
// 10 times. Best out of 10: 18154ms with `prev` field, 17777ms without.
835835
cnt += 1
836836
if (cnt > MaxPossiblePhaseId)
837-
return current(using ctx.withPhase(coveredInterval.firstPhaseId))
837+
return atPhase(coveredInterval.firstPhaseId)(current)
838838
}
839839
cur
840840
}
@@ -851,7 +851,7 @@ object Denotations {
851851
*/
852852
protected def installAfter(phase: DenotTransformer)(using Context): Unit = {
853853
val targetId = phase.next.id
854-
if (ctx.phaseId != targetId) installAfter(phase)(using ctx.withPhase(phase.next))
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}")

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ object SymDenotations {
243243
myFlags |= Touched
244244

245245
// completions.println(s"completing ${this.debugString}")
246-
try completer.complete(this)(using ctx.withPhase(validFor.firstPhaseId))
246+
try atPhase(validFor.firstPhaseId)(completer.complete(this))
247247
catch {
248248
case ex: CyclicReference =>
249249
println(s"error while completing ${this.debugString}")
@@ -257,7 +257,7 @@ object SymDenotations {
257257
else {
258258
if (myFlags.is(Touched)) throw CyclicReference(this)
259259
myFlags |= Touched
260-
completer.complete(this)(using ctx.withPhase(validFor.firstPhaseId))
260+
atPhase(validFor.firstPhaseId)(completer.complete(this))
261261
}
262262

263263
protected[dotc] def info_=(tp: Type): Unit = {
@@ -847,13 +847,12 @@ object SymDenotations {
847847
isClass && derivesFrom(defn.JavaSerializableClass)
848848

849849
/** Is this symbol a class that extends `AnyVal`? */
850-
final def isValueClass(using Context): Boolean = {
850+
final def isValueClass(using Context): Boolean =
851851
val di = initial
852-
di.isClass &&
853-
di.derivesFrom(defn.AnyValClass)(using ctx.withPhase(di.validFor.firstPhaseId))
852+
di.isClass
853+
&& atPhase(di.validFor.firstPhaseId)(di.derivesFrom(defn.AnyValClass))
854854
// We call derivesFrom at the initial phase both because AnyVal does not exist
855855
// after Erasure and to avoid cyclic references caused by forcing denotations
856-
}
857856

858857
/** Is this symbol a class of which `null` is a value? */
859858
final def isNullableClass(using Context): Boolean =
@@ -2200,7 +2199,7 @@ object SymDenotations {
22002199
* `phase.next`, install a new denotation with a cloned scope in `phase.next`.
22012200
*/
22022201
def ensureFreshScopeAfter(phase: DenotTransformer)(using Context): Unit =
2203-
if (ctx.phaseId != phase.next.id) ensureFreshScopeAfter(phase)(using ctx.withPhase(phase.next))
2202+
if (ctx.phaseId != phase.next.id) atPhase(phase.next)(ensureFreshScopeAfter(phase))
22042203
else {
22052204
val prevClassInfo = atPhase(phase) {
22062205
current.asInstanceOf[ClassDenotation].classInfo

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ object Symbols {
585585
*/
586586
def enteredAfter(phase: DenotTransformer)(using Context): this.type =
587587
if ctx.phaseId != phase.next.id then
588-
enteredAfter(phase)(using ctx.withPhase(phase.next))
588+
atPhase(phase.next)(enteredAfter(phase))
589589
else this.owner match {
590590
case owner: ClassSymbol =>
591591
if (owner.is(Package)) {
@@ -610,7 +610,7 @@ object Symbols {
610610
*/
611611
def dropAfter(phase: DenotTransformer)(using Context): Unit =
612612
if ctx.phaseId != phase.next.id then
613-
dropAfter(phase)(using ctx.withPhase(phase.next))
613+
atPhase(phase.next)(dropAfter(phase))
614614
else {
615615
assert (!this.owner.is(Package))
616616
this.owner.asClass.ensureFreshScopeAfter(phase)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ object Types {
19041904
protected[dotc] def computeSignature(using Context): Signature =
19051905
val lastd = lastDenotation
19061906
if lastd != null then sigFromDenot(lastd)
1907-
else if ctx.erasedTypes then computeSignature(using ctx.withPhase(erasurePhase))
1907+
else if ctx.erasedTypes then atPhase(erasurePhase)(computeSignature)
19081908
else symbol.asSeenFrom(prefix).signature
19091909

19101910
/** The signature computed from the current denotation with `sigFromDenot` if it is
@@ -1918,7 +1918,7 @@ object Types {
19181918
else
19191919
val lastd = lastDenotation
19201920
if lastd != null then sigFromDenot(lastd)
1921-
else if ctx.erasedTypes then currentSignature(using ctx.withPhase(erasurePhase))
1921+
else if ctx.erasedTypes then atPhase(erasurePhase)(currentSignature)
19221922
else
19231923
val sym = currentSymbol
19241924
if sym.exists then sym.asSeenFrom(prefix).signature
@@ -2053,7 +2053,7 @@ object Types {
20532053
d = memberDenot(prefix, name, true)
20542054
if (!d.exists && ctx.phaseId > FirstPhaseId && lastDenotation.isInstanceOf[SymDenotation])
20552055
// name has changed; try load in earlier phase and make current
2056-
d = memberDenot(name, allowPrivate)(using ctx.withPhase(ctx.phaseId - 1)).current
2056+
d = atPhase(ctx.phaseId - 1)(memberDenot(name, allowPrivate)).current
20572057
if (d.isOverloaded)
20582058
d = disambiguate(d)
20592059
d

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ class ClassfileParser(
940940
val outerName = entry.outerName.stripModuleClassSuffix
941941
val innerName = entry.originalName
942942
val owner = classNameToSymbol(outerName)
943-
val result = getMember(owner, innerName.toTypeName)(using ctx.withPhase(typerPhase))
943+
val result = atPhase(typerPhase)(getMember(owner, innerName.toTypeName))
944944
assert(result ne NoSymbol,
945945
i"""failure to resolve inner class:
946946
|externalName = ${entry.externalName},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
986986
val atp = readTypeRef()
987987
val phase = ctx.phase
988988
Annotation.deferred(atp.typeSymbol)(
989-
atReadPos(start, () => readAnnotationContents(end)(using ctx.withPhase(phase))))
989+
atReadPos(start, () => atPhase(phase)(readAnnotationContents(end))))
990990
}
991991

992992
/* Read an abstract syntax tree */

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
7575
}
7676

7777
override def prepareForUnit(tree: Tree)(using Context): Context = {
78-
val captured = (new CollectCaptured)
79-
.runOver(ctx.compilationUnit.tpdTree)(using ctx.withPhase(thisPhase))
78+
val captured = atPhase(thisPhase) {
79+
CollectCaptured().runOver(ctx.compilationUnit.tpdTree)
80+
}
8081
ctx.fresh.updateStore(Captured, captured)
8182
}
8283

@@ -91,9 +92,9 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
9192
}
9293

9394
override def prepareForValDef(vdef: ValDef)(using Context): Context = {
94-
val sym = vdef.symbol(using ctx.withPhase(thisPhase))
95+
val sym = atPhase(thisPhase)(vdef.symbol)
9596
if (captured contains sym) {
96-
val newd = sym.denot(using ctx.withPhase(thisPhase)).copySymDenotation(
97+
val newd = atPhase(thisPhase)(sym.denot).copySymDenotation(
9798
info = refClass(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef,
9899
initFlags = sym.flags &~ Mutable)
99100
newd.removeAnnotation(defn.VolatileAnnot)
@@ -117,7 +118,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
117118
override def transformIdent(id: Ident)(using Context): Tree = {
118119
val vble = id.symbol
119120
if (captured.contains(vble))
120-
id.select(nme.elem).ensureConforms(vble.denot(using ctx.withPhase(thisPhase)).info)
121+
id.select(nme.elem).ensureConforms(atPhase(thisPhase)(vble.denot).info)
121122
else id
122123
}
123124

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ object ContextFunctionResults:
121121
*/
122122
def integrateSelect(tree: untpd.Tree, n: Int = 0)(using Context): Boolean =
123123
if ctx.erasedTypes then
124-
integrateSelect(tree, n)(using ctx.withPhase(erasurePhase))
124+
atPhase(erasurePhase)(integrateSelect(tree, n))
125125
else tree match
126126
case Select(qual, name) =>
127127
if name == nme.apply && defn.isContextFunctionClass(tree.symbol.maybeOwner) then

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Erasure extends Phase with DenotTransformer {
4949
case ref: SymDenotation =>
5050
def isCompacted(sym: Symbol) =
5151
sym.isAnonymousFunction && {
52-
sym.info(using ctx.withPhase(ctx.phase.next)) match {
52+
atPhase(ctx.phase.next)(sym.info) match {
5353
case MethodType(nme.ALLARGS :: Nil) => true
5454
case _ => false
5555
}
@@ -717,7 +717,9 @@ object Erasure {
717717
}
718718

719719
override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(using Context): Tree = {
720-
val ntree = interceptTypeApply(tree.asInstanceOf[TypeApply])(using ctx.withPhase(erasurePhase)).withSpan(tree.span)
720+
val ntree = atPhase(erasurePhase)(
721+
interceptTypeApply(tree.asInstanceOf[TypeApply])
722+
).withSpan(tree.span)
721723

722724
ntree match {
723725
case TypeApply(fun, args) =>
@@ -953,7 +955,7 @@ object Erasure {
953955
if ctx.phase != erasurePhase && ctx.phase != erasurePhase.next then
954956
// this can happen when reading annotations loaded during erasure,
955957
// since these are loaded at phase typer.
956-
adapt(tree, pt, locked)(using ctx.withPhase(erasurePhase.next))
958+
atPhase(erasurePhase.next)(adapt(tree, pt, locked))
957959
else if (tree.isEmpty) tree
958960
else if (ctx.mode is Mode.Pattern) tree // TODO: replace with assertion once pattern matcher is active
959961
else adaptToType(tree, pt)

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

Lines changed: 2 additions & 2 deletions
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 = cls.denot(using ctx.withPhase(ctx.phase.next)).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
}
@@ -135,7 +135,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
135135
(imeth.flags | Final) &~ (Override | Protected | AbsOverride),
136136
fullyParameterizedType(imeth.info, imeth.owner.asClass),
137137
privateWithin = imeth.privateWithin, coord = imeth.coord)
138-
extensionMeth.addAnnotations(imeth.annotations)(using ctx.withPhase(thisPhase))
138+
atPhase(thisPhase)(extensionMeth.addAnnotations(imeth.annotations))
139139
// need to change phase to add tailrec annotation which gets removed from original method in the same phase.
140140
extensionMeth
141141
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ast.untpd
99
import Flags._
1010
import Types._
1111
import Constants.Constant
12-
import Contexts.{Context, ctx}
12+
import Contexts._
1313
import Symbols._
1414
import Decorators._
1515
import scala.collection.mutable
@@ -129,7 +129,7 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
129129
}
130130

131131
override def transformStats(trees: List[Tree])(using Context): List[Tree] =
132-
ast.Trees.flatten(reorderAndComplete(trees)(using ctx.withPhase(thisPhase.next)))
132+
ast.Trees.flatten(atPhase(thisPhase.next)(reorderAndComplete(trees)))
133133

134134
private object collectBinders extends TreeAccumulator[List[Ident]] {
135135
def apply(annots: List[Ident], t: Tree)(using Context): List[Ident] = t match {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object GenericSignatures {
3535
def javaSig(sym0: Symbol, info: Type)(using Context): Option[String] =
3636
// Avoid generating a signature for local symbols.
3737
if (sym0.isLocal) None
38-
else javaSig0(sym0, info)(using ctx.withPhase(erasurePhase))
38+
else atPhase(erasurePhase)(javaSig0(sym0, info))
3939

4040
@noinline
4141
private final def javaSig0(sym0: Symbol, info: Type)(using Context): Option[String] = {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,10 @@ object LambdaLift {
374374
(new CollectDependencies).traverse(ctx.compilationUnit.tpdTree)
375375
computeFreeVars()
376376
computeLiftedOwners()
377-
generateProxies()(using ctx.withPhase(thisPhase.next))
378-
liftLocals()(using ctx.withPhase(thisPhase.next))
377+
}
378+
atPhase(thisPhase.next) {
379+
generateProxies()
380+
liftLocals()
379381
}
380382

381383
def currentEnclosure(using Context): Symbol =
@@ -421,7 +423,7 @@ object LambdaLift {
421423
}
422424

423425
def proxyRef(sym: Symbol)(using Context): Tree = {
424-
val psym = proxy(sym)(using ctx.withPhase(thisPhase))
426+
val psym = atPhase(thisPhase)(proxy(sym))
425427
thisPhase.transformFollowingDeep(if (psym.owner.isTerm) ref(psym) else memberRef(psym))
426428
}
427429

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class MacroTransform extends Phase {
1818

1919
override def run(using Context): Unit = {
2020
val unit = ctx.compilationUnit
21-
unit.tpdTree = newTransformer.transform(unit.tpdTree)(using ctx.withPhase(transformPhase))
21+
unit.tpdTree = atPhase(transformPhase)(newTransformer.transform(unit.tpdTree))
2222
}
2323

2424
protected def newTransformer(using Context): Transformer

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase {
424424

425425
override def run(using Context): Unit =
426426
ctx.compilationUnit.tpdTree =
427-
transformUnit(ctx.compilationUnit.tpdTree)(using ctx.withPhase(miniPhases.last.next))
427+
atPhase(miniPhases.last.next)(transformUnit(ctx.compilationUnit.tpdTree))
428428

429429
// Initialization code
430430

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ParamForwarding extends MiniPhase with IdentityDenotTransformer:
5656
val sym = mdef.symbol.asTerm
5757
if sym.is(SuperParamAlias) then
5858
assert(sym.is(ParamAccessor, butNot = Mutable))
59-
val alias = inheritedAccessor(sym)(using ctx.withPhase(thisPhase))
59+
val alias = atPhase(thisPhase)(inheritedAccessor(sym))
6060
if alias.exists then
6161
sym.copySymDenotation(
6262
name = ParamAccessorName(sym.name),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class SuperAccessors(thisPhase: DenotTransformer) {
147147
}
148148
if (name.isTermName && mix.name.isEmpty &&
149149
(clazz.is(Trait) || clazz != ctx.owner.enclosingClass || !validCurrentClass))
150-
superAccessorCall(sel)(using ctx.withPhase(thisPhase.next))
150+
atPhase(thisPhase.next)(superAccessorCall(sel))
151151
else sel
152152
}
153153

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor
2323

2424
/** The info of the tree's symbol before it is potentially transformed in this phase */
2525
private def originalDenotation(tree: Tree)(using Context) =
26-
tree.symbol.denot(using ctx.withPhase(thisPhase))
26+
atPhase(thisPhase)(tree.symbol.denot)
2727

2828
/** If denotation had an ExprType before, it now gets a function type */
2929
protected def exprBecomesFunction(symd: SymDenotation)(using Context): Boolean =

0 commit comments

Comments
 (0)