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

0 commit comments

Comments
 (0)