Skip to content

Commit f3e03fc

Browse files
committed
Move atPhase and friends to Contexts
1 parent a9c405f commit f3e03fc

27 files changed

+57
-55
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import dotty.tools.dotc.core.Symbols._
1919
import dotty.tools.dotc.transform.Erasure
2020
import dotty.tools.dotc.transform.SymUtils._
2121
import dotty.tools.dotc.util.Spans._
22+
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
2223

2324
/*
2425
*
@@ -1460,7 +1461,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
14601461
// TODO specialization
14611462
val constrainedType = new MethodBType(lambdaParamTypes.map(p => toTypeKind(p)), toTypeKind(lambdaTarget.info.resultType)).toASMType
14621463

1463-
val abstractMethod = ctx.atPhase(ctx.erasurePhase) {
1464+
val abstractMethod = atPhase(ctx.erasurePhase) {
14641465
val samMethods = toDenot(functionalInterface).info.possibleSamMethods.toList
14651466
samMethods match {
14661467
case x :: Nil => x.symbol

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import dotty.tools.dotc.ast.tpd
1313
import dotty.tools.dotc.ast.Trees
1414
import dotty.tools.dotc.core.Annotations._
1515
import dotty.tools.dotc.core.Constants._
16-
import dotty.tools.dotc.core.Contexts.Context
16+
import dotty.tools.dotc.core.Contexts.{Context, atPhase}
1717
import dotty.tools.dotc.core.Decorators._
1818
import dotty.tools.dotc.core.Flags._
1919
import dotty.tools.dotc.core.Names.Name
@@ -478,7 +478,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
478478
* @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
479479
*/
480480
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
481-
ctx.atPhase(ctx.erasurePhase) {
481+
atPhase(ctx.erasurePhase) {
482482
val memberTpe =
483483
if (sym.is(Method)) sym.denot.info
484484
else owner.denot.thisType.memberInfo(sym)
@@ -913,7 +913,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
913913
// But for now, just like we did in mixin, we just avoid writing a wrong generic signature
914914
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.
915915

916-
val memberTpe = ctx.atPhase(ctx.erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
916+
val memberTpe = atPhase(ctx.erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
917917
val erasedMemberType = TypeErasure.erasure(memberTpe)
918918
if (erasedMemberType =:= sym.denot.info)
919919
getGenericSignatureHelper(sym, moduleClass, memberTpe).orNull

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.collection.mutable
88
import scala.collection.generic.Clearable
99

1010
import dotty.tools.dotc.core.Flags._
11-
import dotty.tools.dotc.core.Contexts.inContext
11+
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
1212
import dotty.tools.dotc.core.Symbols._
1313
import dotty.tools.dotc.core.Phases.Phase
1414
import dotty.tools.dotc.transform.SymUtils._
@@ -212,7 +212,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
212212

213213
private def definedClasses(sym: Symbol, phase: Phase) =
214214
if (sym.isDefinedInCurrentRun)
215-
ctx.atPhase(phase) {
215+
atPhase(phase) {
216216
toDenot(sym).info.decls.filter(_.isClass)
217217
}
218218
else Nil

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object DottyBackendInterface {
160160
*/
161161
def isTopLevelModuleClass(using Context): Boolean =
162162
sym.is(ModuleClass) &&
163-
ctx.atPhase(ctx.flattenPhase) {
163+
atPhase(ctx.flattenPhase) {
164164
toDenot(sym).owner.is(PackageClass)
165165
}
166166

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using ctx: Context) exten
166166
if (classSymbol.effectiveName.toString < dupClassSym.effectiveName.toString) (classSymbol, dupClassSym)
167167
else (dupClassSym, classSymbol)
168168
val same = classSymbol.effectiveName.toString == dupClassSym.effectiveName.toString
169-
ctx.atPhase(ctx.typerPhase) {
169+
atPhase(ctx.typerPhase) {
170170
if (same)
171171
summon[Context].warning( // FIXME: This should really be an error, but then FromTasty tests fail
172172
s"${cl1.show} and ${cl2.showLocated} produce classes that overwrite one another", cl1.sourcePos)
@@ -271,7 +271,7 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using ctx: Context) exten
271271

272272
// ----------- compiler and sbt's callbacks
273273

274-
val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) {
274+
val (fullClassName, isLocal) = atPhase(ctx.sbtExtractDependenciesPhase) {
275275
(ExtractDependencies.classNameAsString(claszSymbol), claszSymbol.isLocal)
276276
}
277277

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ class JSCodeGen()(using genCtx: Context) {
21212121
if (isStat) {
21222122
boxedResult
21232123
} else {
2124-
val tpe = ctx.atPhase(ctx.elimErasedValueTypePhase) {
2124+
val tpe = atPhase(ctx.elimErasedValueTypePhase) {
21252125
sym.info.finalResultType
21262126
}
21272127
unbox(boxedResult, tpe)
@@ -2735,14 +2735,14 @@ class JSCodeGen()(using genCtx: Context) {
27352735
def paramNamesAndTypes(using Context): List[(Names.TermName, Type)] =
27362736
sym.info.paramNamess.flatten.zip(sym.info.paramInfoss.flatten)
27372737

2738-
val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) {
2738+
val wereRepeated = atPhase(ctx.elimRepeatedPhase) {
27392739
val list =
27402740
for ((name, tpe) <- paramNamesAndTypes)
27412741
yield (name -> tpe.isRepeatedParam)
27422742
list.toMap
27432743
}
27442744

2745-
val paramTypes = ctx.atPhase(ctx.elimErasedValueTypePhase) {
2745+
val paramTypes = atPhase(ctx.elimErasedValueTypePhase) {
27462746
paramNamesAndTypes.toMap
27472747
}
27482748

compiler/src/dotty/tools/backend/sjs/JSInterop.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object JSInterop {
1616
/** Is this symbol a JavaScript type? */
1717
def isJSType(sym: Symbol)(using Context): Boolean = {
1818
//sym.hasAnnotation(jsdefn.RawJSTypeAnnot)
19-
ctx.atPhase(ctx.erasurePhase) {
19+
atPhase(ctx.erasurePhase) {
2020
sym.derivesFrom(jsdefn.JSAnyClass)
2121
}
2222
}
@@ -32,7 +32,7 @@ object JSInterop {
3232
* much as *accessor* methods created for `val`s and `var`s.
3333
*/
3434
def isJSGetter(sym: Symbol)(using Context): Boolean = {
35-
sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) {
35+
sym.info.firstParamTypes.isEmpty && atPhase(ctx.erasurePhase) {
3636
sym.info.isParameterless
3737
}
3838
}

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Feature:
3636
* import owner.{ feature => _ }
3737
*/
3838
def enabledByImport(feature: TermName, owner: Symbol = NoSymbol)(using Context): Boolean =
39-
ctx.atPhase(ctx.typerPhase) {
39+
atPhase(ctx.typerPhase) {
4040
ctx.importInfo != null
4141
&& ctx.importInfo.featureImported(feature,
4242
if owner.exists then owner else defn.LanguageModule.moduleClass)

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ object Contexts {
5757
inline def inContext[T](c: Context)(inline op: Context ?=> T): T =
5858
op(using c)
5959

60+
/** Execute `op` at given period */
61+
inline def atPeriod[T](pd: Period)(inline op: Context ?=> T)(using Context): T =
62+
op(using ctx.fresh.setPeriod(pd))
63+
64+
/** Execute `op` at given phase id */
65+
inline def atPhase[T](pid: PhaseId)(inline op: Context ?=> T)(using Context): T =
66+
op(using ctx.withPhase(pid))
67+
68+
/** Execute `op` at given phase */
69+
inline def atPhase[T](phase: Phase)(inline op: Context ?=> T)(using Context): T =
70+
atPhase(phase.id)(op)
71+
72+
inline def atNextPhase[T](inline op: Context ?=> T)(using Context): T =
73+
atPhase(ctx.phase.next)(op)
74+
75+
inline def atPhaseNotLaterThan[T](limit: Phase)(inline op: Context ?=> T)(using Context): T =
76+
op(using if !limit.exists || ctx.phase <= limit then ctx else ctx.withPhase(limit))
77+
6078
/** A context is passed basically everywhere in dotc.
6179
* This is convenient but carries the risk of captured contexts in
6280
* objects that turn into space leaks. To combat this risk, here are some

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.dotc.core
22

33
import Contexts._
44

5-
/** Periods are the central "clock" of the compiler.
5+
/** Periods are the central "clock" of the compiler
66
* A period consists of a run id and a phase id.
77
* run ids represent compiler runs
88
* phase ids represent compiler phases
@@ -16,14 +16,6 @@ abstract class Periods { thisCtx: Context =>
1616
/** The current run identifier */
1717
def runId: Int = period.runId
1818

19-
/** Execute `op` at given period */
20-
def atPeriod[T](pd: Period)(op: Context => T): T =
21-
op(thisCtx.fresh.setPeriod(pd))
22-
23-
/** Execute `op` at given phase id */
24-
inline def atPhase[T](pid: PhaseId)(inline op: Context ?=> T): T =
25-
op(using thisCtx.withPhase(pid))
26-
2719
/** The period containing the current period where denotations do not change.
2820
* We compute this by taking as first phase the first phase less or equal to
2921
* the current phase that has the same "nextTransformerId". As last phase

0 commit comments

Comments
 (0)