Skip to content

Commit 5c78f6a

Browse files
committed
Eliminate more withPhase calls
1 parent ef95267 commit 5c78f6a

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ object Contexts {
7272
inline def atNextPhase[T](inline op: Context ?=> T)(using Context): T =
7373
atPhase(currentPhase.next)(op)
7474

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

78+
inline def atPhaseNoEarlier[T](limit: Phase)(inline op: Context ?=> T)(using Context): T =
79+
op(using if !limit.exists || limit <= currentPhase then ctx else ctx.withPhase(limit))
80+
7881
inline def currentPeriod(using ctx: Context): Period = ctx.period
7982

8083
inline def currentPhase(using ctx: Context): Phase = ctx.base.phases(ctx.period.firstPhaseId)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ object Symbols {
431431
}
432432
case none => NoSource
433433
}
434-
sourceFromTopLevel(using ctx.withPhaseNoLater(flattenPhase))
434+
atPhaseNoLater(flattenPhase)(sourceFromTopLevel)
435435
}
436436
}
437437
mySource

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
607607
}
608608
atReadPos(startCoord(denot).toIndex,
609609
() => withMode(Mode.Scala2Unpickling) {
610-
atPhaseNotLaterThan(picklerPhase) {
610+
atPhaseNoLater(picklerPhase) {
611611
parseToCompletion(denot)
612612
}
613613
})

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

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

55
import core._
6-
import Contexts.{Context, ctx}
6+
import Contexts._
77
import Decorators._, Symbols._, Names._, NameOps._, Types._, Flags._, Phases._
88
import Denotations.SingleDenotation
99
import SymDenotations.SymDenotation
@@ -2011,9 +2011,8 @@ 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-
val elimErasedCtx = ctx.withPhaseNoEarlier(elimErasedValueTypePhase.next)
2015-
if (elimErasedCtx != ctx)
2016-
details(using elimErasedCtx)
2014+
if currentPhase.id <= elimErasedValueTypePhase.id then
2015+
atPhase(elimErasedValueTypePhase.next)(details)
20172016
else
20182017
"" // shouldn't be reachable
20192018
case ParamMatch =>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,13 @@ class ElimErasedValueType extends MiniPhase with InfoTransformer { thisPhase =>
105105
!info1.matchesLoosely(info2) && !bothPolyApply)
106106
report.error(DoubleDefinition(sym1, sym2, root), root.sourcePos)
107107
}
108-
val earlyCtx = ctx.withPhase(elimRepeatedPhase.next)
109108
while (opc.hasNext) {
110109
val sym1 = opc.overriding
111110
val sym2 = opc.overridden
112111
// Do the test at the earliest phase where both symbols existed.
113112
val phaseId =
114113
sym1.originDenotation.validFor.firstPhaseId max sym2.originDenotation.validFor.firstPhaseId
115-
checkNoConflict(sym1, sym2, sym1.info)(using earlyCtx)
114+
atPhase(elimRepeatedPhase.next)(checkNoConflict(sym1, sym2, sym1.info))
116115
opc.next()
117116
}
118117
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ object ExplicitOuter {
174174
outerThis.baseType(outerCls).orElse(
175175
outerCls.typeRef.appliedTo(outerCls.typeParams.map(_ => TypeBounds.empty)))
176176
val info = if (flags.is(Method)) ExprType(target) else target
177-
inContext(ctx.withPhaseNoEarlier(explicitOuterPhase.next)) { // outer accessors are entered at explicitOuter + 1, should not be defined before.
177+
atPhaseNoEarlier(explicitOuterPhase.next) { // outer accessors are entered at explicitOuter + 1, should not be defined before.
178178
newSymbol(owner, name, Synthetic | flags, info, coord = cls.coord)
179179
}
180180
}
@@ -300,7 +300,7 @@ object ExplicitOuter {
300300
else tpe.prefix
301301
case _ =>
302302
// Need to be careful to dealias before erasure, otherwise we lose prefixes.
303-
outerPrefix(tpe.underlying(using ctx.withPhaseNoLater(erasurePhase)))
303+
atPhaseNoLater(erasurePhase)(outerPrefix(tpe.underlying))
304304
}
305305
case tpe: TypeProxy =>
306306
outerPrefix(tpe.underlying)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object ValueClasses {
2323
}
2424

2525
def isMethodWithExtension(sym: Symbol)(using Context): Boolean =
26-
atPhaseNotLaterThan(extensionMethodsPhase) {
26+
atPhaseNoLater(extensionMethodsPhase) {
2727
val d = sym.denot
2828
d.validFor.containsPhaseId(currentPhaseId) &&
2929
d.isRealMethod &&

0 commit comments

Comments
 (0)