Skip to content

Commit cd9f05d

Browse files
committed
Move individual phases to Phases
1 parent da6829b commit cd9f05d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+123
-106
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import dotty.tools.dotc.transform.Erasure
2020
import dotty.tools.dotc.transform.SymUtils._
2121
import dotty.tools.dotc.util.Spans._
2222
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
23+
import dotty.tools.dotc.core.Phases._
2324

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

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import dotty.tools.dotc.ast.Trees
1414
import dotty.tools.dotc.core.Annotations._
1515
import dotty.tools.dotc.core.Constants._
1616
import dotty.tools.dotc.core.Contexts.{Context, atPhase}
17+
import dotty.tools.dotc.core.Phases._
1718
import dotty.tools.dotc.core.Decorators._
1819
import dotty.tools.dotc.core.Flags._
1920
import dotty.tools.dotc.core.Names.Name
@@ -360,7 +361,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
360361
val narg = normalizeArgument(arg)
361362
// Transformation phases are not run on annotation trees, so we need to run
362363
// `constToLiteral` at this point.
363-
val t = constToLiteral(narg)(using ctx.withPhase(ctx.erasurePhase))
364+
val t = atPhase(erasurePhase)(constToLiteral(narg))
364365
t match {
365366
case Literal(const @ Constant(_)) =>
366367
const.tag match {
@@ -478,7 +479,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
478479
* @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
479480
*/
480481
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
481-
atPhase(ctx.erasurePhase) {
482+
atPhase(erasurePhase) {
482483
val memberTpe =
483484
if (sym.is(Method)) sym.denot.info
484485
else owner.denot.thisType.memberInfo(sym)
@@ -913,7 +914,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
913914
// But for now, just like we did in mixin, we just avoid writing a wrong generic signature
914915
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.
915916

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

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import scala.collection.generic.Clearable
99

1010
import dotty.tools.dotc.core.Flags._
1111
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
12+
import dotty.tools.dotc.core.Phases._
1213
import dotty.tools.dotc.core.Symbols._
1314
import dotty.tools.dotc.core.Phases.Phase
1415
import dotty.tools.dotc.transform.SymUtils._
@@ -203,12 +204,12 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
203204
/** For currently compiled classes: All locally defined classes including local classes.
204205
* The empty list for classes that are not currently compiled.
205206
*/
206-
private def getNestedClasses(sym: Symbol): List[Symbol] = definedClasses(sym, ctx.flattenPhase)
207+
private def getNestedClasses(sym: Symbol): List[Symbol] = definedClasses(sym, flattenPhase)
207208

208209
/** For currently compiled classes: All classes that are declared as members of this class
209210
* (but not inherited ones). The empty list for classes that are not currently compiled.
210211
*/
211-
private def getMemberClasses(sym: Symbol): List[Symbol] = definedClasses(sym, ctx.lambdaLiftPhase)
212+
private def getMemberClasses(sym: Symbol): List[Symbol] = definedClasses(sym, lambdaLiftPhase)
212213

213214
private def definedClasses(sym: Symbol, phase: Phase) =
214215
if (sym.isDefinedInCurrentRun)
@@ -229,11 +230,11 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
229230
// After lambdalift (which is where we are), the rawowoner field contains the enclosing class.
230231
val enclosingClassSym = {
231232
if (innerClassSym.isClass) {
232-
atPhase(ctx.flattenPhase.prev) {
233+
atPhase(flattenPhase.prev) {
233234
toDenot(innerClassSym).owner.enclosingClass
234235
}
235236
}
236-
else innerClassSym.enclosingClass(using ctx.withPhase(ctx.flattenPhase.prev))
237+
else atPhase(flattenPhase.prev)(innerClassSym.enclosingClass)
237238
} //todo is handled specially for JavaDefined symbols in scalac
238239

239240
val enclosingClass: ClassBType = classBTypeFromSymbol(enclosingClassSym)
@@ -257,7 +258,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
257258
if (innerClassSym.isAnonymousClass || innerClassSym.isAnonymousFunction) None
258259
else {
259260
val original = innerClassSym.initial
260-
Some(innerClassSym.name(using ctx.withPhase(original.validFor.phaseId)).mangledString) // moduleSuffix for module classes
261+
Some(atPhase(original.validFor.phaseId)(innerClassSym.name).mangledString) // moduleSuffix for module classes
261262
}
262263
}
263264

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty.tools.backend.jvm
22

33
import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.core.Contexts.{Context, ctx}
5+
import dotty.tools.dotc.core.Phases._
56
import dotty.tools.dotc.core.Symbols._
67
import dotty.tools.dotc.core.Flags.Trait
78
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
@@ -32,7 +33,7 @@ class CollectSuperCalls extends MiniPhase {
3233
}
3334

3435
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(using Context) = {
35-
ctx.genBCodePhase match {
36+
genBCodePhase match {
3637
case genBCodePhase: GenBCode =>
3738
genBCodePhase.registerSuperCall(sym, calls)
3839
case _ =>

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-
atPhase(ctx.flattenPhase) {
163+
atPhase(flattenPhase) {
164164
toDenot(sym).owner.is(PackageClass)
165165
}
166166

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import java.util.Optional
1515
import dotty.tools.dotc.core._
1616
import dotty.tools.dotc.sbt.ExtractDependencies
1717
import Contexts._
18+
import Phases._
1819
import Symbols._
1920
import Decorators._
2021

@@ -166,7 +167,7 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using ctx: Context) exten
166167
if (classSymbol.effectiveName.toString < dupClassSym.effectiveName.toString) (classSymbol, dupClassSym)
167168
else (dupClassSym, classSymbol)
168169
val same = classSymbol.effectiveName.toString == dupClassSym.effectiveName.toString
169-
atPhase(ctx.typerPhase) {
170+
atPhase(typerPhase) {
170171
if (same)
171172
summon[Context].warning( // FIXME: This should really be an error, but then FromTasty tests fail
172173
s"${cl1.show} and ${cl2.showLocated} produce classes that overwrite one another", cl1.sourcePos)
@@ -271,7 +272,7 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using ctx: Context) exten
271272

272273
// ----------- compiler and sbt's callbacks
273274

274-
val (fullClassName, isLocal) = atPhase(ctx.sbtExtractDependenciesPhase) {
275+
val (fullClassName, isLocal) = atPhase(sbtExtractDependenciesPhase) {
275276
(ExtractDependencies.classNameAsString(claszSymbol), claszSymbol.isLocal)
276277
}
277278

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

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Flags._
66
import Symbols._
77
import NameOps._
88
import StdNames._
9+
import Phases._
910
import NameKinds.DefaultGetterName
1011

1112
import JSDefinitions._
@@ -16,7 +17,7 @@ object JSInterop {
1617
/** Is this symbol a JavaScript type? */
1718
def isJSType(sym: Symbol)(using Context): Boolean = {
1819
//sym.hasAnnotation(jsdefn.RawJSTypeAnnot)
19-
atPhase(ctx.erasurePhase) {
20+
atPhase(erasurePhase) {
2021
sym.derivesFrom(jsdefn.JSAnyClass)
2122
}
2223
}
@@ -32,7 +33,7 @@ object JSInterop {
3233
* much as *accessor* methods created for `val`s and `var`s.
3334
*/
3435
def isJSGetter(sym: Symbol)(using Context): Boolean = {
35-
sym.info.firstParamTypes.isEmpty && atPhase(ctx.erasurePhase) {
36+
sym.info.firstParamTypes.isEmpty && atPhase(erasurePhase) {
3637
sym.info.isParameterless
3738
}
3839
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package ast
44

55
import core._
66
import util.Spans._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
7-
import Symbols._, StdNames._, Trees._
7+
import Symbols._, StdNames._, Trees._, Phases._
88
import Decorators.{given _}, transform.SymUtils._
99
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName}
1010
import typer.{FrontEnd, Namer}
@@ -1402,7 +1402,7 @@ object desugar {
14021402
*/
14031403
def makeAnnotated(fullName: String, tree: Tree)(using Context): Annotated = {
14041404
val parts = fullName.split('.')
1405-
val ttree = ctx.typerPhase match {
1405+
val ttree = typerPhase match {
14061406
case phase: FrontEnd if phase.stillToBeEntered(parts.last) =>
14071407
val prefix =
14081408
parts.init.foldLeft(Ident(nme.ROOTPKG): Tree)((qual, name) =>

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

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

55
import core._
6-
import Contexts._, Symbols._, Names._, NameOps._
6+
import Contexts._, Symbols._, Names._, NameOps._, Phases._
77
import StdNames.nme
88
import Decorators.{given _}
99
import util.SourcePosition
@@ -36,7 +36,7 @@ object Feature:
3636
* import owner.{ feature => _ }
3737
*/
3838
def enabledByImport(feature: TermName, owner: Symbol = NoSymbol)(using Context): Boolean =
39-
atPhase(ctx.typerPhase) {
39+
atPhase(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/Annotations.scala

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

4-
import Symbols._, Types._, Contexts._, Constants._, ast.tpd._
4+
import Symbols._, Types._, Contexts._, Constants._, ast.tpd._, Phases._
55
import config.ScalaVersion
66
import StdNames._
77
import dotty.tools.dotc.ast.tpd
@@ -58,7 +58,7 @@ object Annotations {
5858
// seems to be enough to ensure this (note that after erasure, `ctx.typer`
5959
// will be the Erasure typer, but that doesn't seem to affect the annotation
6060
// trees we create, so we leave it as is)
61-
ctx.withPhaseNoLater(ctx.picklerPhase)
61+
ctx.withPhaseNoLater(picklerPhase)
6262

6363
abstract class LazyAnnotation extends Annotation {
6464
protected var mySym: Symbol | (Context => Symbol)

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -517,30 +517,12 @@ object Contexts {
517517
(outersIterator.map(ctx => s" owner = ${ctx.owner}, scope = ${ctx.scope}, import = ${iinfo(using ctx)}").mkString("\n"))
518518
}
519519

520-
def typerPhase: Phase = base.typerPhase
521-
def postTyperPhase: Phase = base.postTyperPhase
522-
def sbtExtractDependenciesPhase: Phase = base.sbtExtractDependenciesPhase
523-
def picklerPhase: Phase = base.picklerPhase
524-
def reifyQuotesPhase: Phase = base.reifyQuotesPhase
525-
def refchecksPhase: Phase = base.refchecksPhase
526-
def patmatPhase: Phase = base.patmatPhase
527-
def elimRepeatedPhase: Phase = base.elimRepeatedPhase
528-
def extensionMethodsPhase: Phase = base.extensionMethodsPhase
529-
def explicitOuterPhase: Phase = base.explicitOuterPhase
530-
def gettersPhase: Phase = base.gettersPhase
531-
def erasurePhase: Phase = base.erasurePhase
532-
def elimErasedValueTypePhase: Phase = base.elimErasedValueTypePhase
533-
def lambdaLiftPhase: Phase = base.lambdaLiftPhase
534-
def flattenPhase: Phase = base.flattenPhase
535-
def genBCodePhase: Phase = base.genBCodePhase
536-
537520
def settings: ScalaSettings = base.settings
538521
def definitions: Definitions = base.definitions
539522
def platform: Platform = base.platform
540523
def pendingUnderlying: mutable.HashSet[Type] = base.pendingUnderlying
541524
def uniqueNamedTypes: Uniques.NamedTypeUniques = base.uniqueNamedTypes
542525
def uniques: util.HashSet[Type] = base.uniques
543-
def nextSymId: Int = base.nextSymId
544526

545527
def initialize()(using Context): Unit = base.initialize()
546528
}

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

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

55
import scala.annotation.{threadUnsafe => tu}
6-
import Types._, Contexts._, Symbols._, SymDenotations._, StdNames._, Names._
6+
import Types._, Contexts._, Symbols._, SymDenotations._, StdNames._, Names._, Phases._
77
import Flags._, Scopes._, Decorators._, NameOps._, Periods._, NullOpsDecorator._
88
import unpickleScala2.Scala2Unpickler.ensureConstructor
99
import scala.collection.mutable
@@ -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(ctx.erasurePhase))
1288+
unapply(tp)(using ctx.withPhase(erasurePhase))
12891289
else
12901290
val tp1 = tp.dealias
12911291
if isContextFunctionClass(tp1.typeSymbol) then

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,28 @@ object Phases {
411411
override def toString: String = phaseName
412412
}
413413

414-
def curPhases(using Context): Array[Phase] = ctx.base.phases
414+
def typerPhase(using Context): Phase = ctx.base.typerPhase
415+
def postTyperPhase(using Context): Phase = ctx.base.postTyperPhase
416+
def sbtExtractDependenciesPhase(using Context): Phase = ctx.base.sbtExtractDependenciesPhase
417+
def picklerPhase(using Context): Phase = ctx.base.picklerPhase
418+
def reifyQuotesPhase(using Context): Phase = ctx.base.reifyQuotesPhase
419+
def refchecksPhase(using Context): Phase = ctx.base.refchecksPhase
420+
def elimRepeatedPhase(using Context): Phase = ctx.base.elimRepeatedPhase
421+
def extensionMethodsPhase(using Context): Phase = ctx.base.extensionMethodsPhase
422+
def explicitOuterPhase(using Context): Phase = ctx.base.explicitOuterPhase
423+
def gettersPhase(using Context): Phase = ctx.base.gettersPhase
424+
def erasurePhase(using Context): Phase = ctx.base.erasurePhase
425+
def elimErasedValueTypePhase(using Context): Phase = ctx.base.elimErasedValueTypePhase
426+
def lambdaLiftPhase(using Context): Phase = ctx.base.lambdaLiftPhase
427+
def flattenPhase(using Context): Phase = ctx.base.flattenPhase
428+
def genBCodePhase(using Context): Phase = ctx.base.genBCodePhase
415429

430+
def curPhases(using Context): Array[Phase] = ctx.base.phases
416431

417432
/** Replace all instances of `oldPhaseClass` in `current` phases
418433
* by the result of `newPhases` applied to the old phase.
419434
*/
420-
def replace(oldPhaseClass: Class[? <: Phase], newPhases: Phase => List[Phase], current: List[List[Phase]]): List[List[Phase]] =
435+
private def replace(oldPhaseClass: Class[? <: Phase], newPhases: Phase => List[Phase], current: List[List[Phase]]): List[List[Phase]] =
421436
current.map(_.flatMap(phase =>
422437
if (oldPhaseClass.isInstance(phase)) newPhases(phase) else phase :: Nil))
423438
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Types.{TermRef, NoPrefix}
1212
import Flags._
1313
import Names._
1414
import Contexts._
15+
import Phases._
1516
import Denotations._
1617
import SymDenotations._
1718
import printing.Texts._
@@ -265,7 +266,7 @@ object Scopes {
265266

266267
/** enter a symbol in this scope. */
267268
final def enter[T <: Symbol](sym: T)(using Context): T = {
268-
if (sym.isType && ctx.phaseId <= ctx.typerPhase.id)
269+
if (sym.isType && ctx.phaseId <= typerPhase.id)
269270
assert(lookup(sym.name) == NoSymbol,
270271
s"duplicate ${sym.debugString}; previous was ${lookup(sym.name).debugString}") // !!! DEBUG
271272
newScopeEntry(sym)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package core
55
import Periods._, Contexts._, Symbols._, Denotations._, Names._, NameOps._, Annotations._
66
import Types._, Flags._, Decorators._, DenotTransformers._, StdNames._, Scopes._
77
import NameOps._, NameKinds._, Phases._
8+
import Phases.typerPhase
89
import Constants.Constant
910
import TypeApplications.TypeParamInfo
1011
import Scopes.Scope
@@ -53,7 +54,7 @@ trait SymDenotations { thisCtx: Context =>
5354
if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass || denot.isImport) true
5455
else {
5556
val initial = denot.initial
56-
val firstPhaseId = initial.validFor.firstPhaseId.max(thisCtx.typerPhase.id)
57+
val firstPhaseId = initial.validFor.firstPhaseId.max(typerPhase.id)
5758
if ((initial ne denot) || thisCtx.phaseId != firstPhaseId)
5859
thisCtx.withPhase(firstPhaseId).stillValidInOwner(initial)
5960
else

0 commit comments

Comments
 (0)