Skip to content

Commit 8a477c7

Browse files
committed
Rename ctx.erasedTypes -> Phases.currentlyAfterErasure
1 parent 5eb5a6b commit 8a477c7

19 files changed

+61
-58
lines changed
Submodule dotty-cps-async updated 32 files

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Decorators.{given _}, DenotTransformers._
1313
import collection.{immutable, mutable}
1414
import util.{Property, SourceFile, NoSource}
1515
import NameKinds.{TempResultName, OuterSelectName}
16-
import Phases.currentPhase
16+
import Phases.{currentPhase, currentlyAfterErasure}
1717
import typer.ConstFold
1818

1919
import scala.annotation.tailrec
@@ -415,7 +415,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
415415
ref(NamedType(sym.owner.thisType, sym.name, sym.denot))
416416

417417
private def followOuterLinks(t: Tree)(using Context) = t match {
418-
case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
418+
case t: This if currentlyAfterErasure && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
419419
// after erasure outer paths should be respected
420420
ExplicitOuter.OuterOps(ctx).path(toCls = t.tpe.widen.classSymbol)
421421
case t =>
@@ -459,7 +459,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
459459
def newArr =
460460
ref(defn.DottyArraysModule).select(defn.newArrayMethod).withSpan(span)
461461

462-
if (!ctx.erasedTypes) {
462+
if (!currentlyAfterErasure) {
463463
assert(!TypeErasure.isGeneric(elemTpe), elemTpe) //needs to be done during typer. See Applications.convertNewGenericArray
464464
newArr.appliedToTypeTrees(TypeTree(returnTpe) :: Nil).appliedToArgs(clsOf(elemTpe) :: clsOf(returnTpe) :: dims :: Nil).withSpan(span)
465465
}
@@ -963,7 +963,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
963963
/** cast tree to `tp`, assuming no exception is raised, i.e the operation is pure */
964964
def cast(tp: Type)(using Context): Tree = {
965965
assert(tp.isValueType, i"bad cast: $tree.asInstanceOf[$tp]")
966-
tree.select(if (ctx.erasedTypes) defn.Any_asInstanceOf else defn.Any_typeCast)
966+
tree.select(if (currentlyAfterErasure) defn.Any_asInstanceOf else defn.Any_typeCast)
967967
.appliedToType(tp)
968968
}
969969

@@ -973,7 +973,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
973973
*/
974974
def ensureConforms(tp: Type)(using Context): Tree =
975975
if (tree.tpe <:< tp) tree
976-
else if (!ctx.erasedTypes) cast(tp)
976+
else if (!currentlyAfterErasure) cast(tp)
977977
else Erasure.Boxing.adaptToType(tree, tp)
978978

979979
/** `tree ne null` (might need a cast to be type correct) */
@@ -1157,7 +1157,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11571157

11581158
/** A tree that corresponds to `Predef.classOf[$tp]` in source */
11591159
def clsOf(tp: Type)(using Context): Tree =
1160-
if ctx.erasedTypes then
1160+
if currentlyAfterErasure then
11611161
def TYPE(module: TermSymbol) = ref(module).select(nme.TYPE_)
11621162
defn.scalaClassName(tp) match
11631163
case tpnme.Boolean => TYPE(defn.BoxedBooleanModule)

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,6 @@ object Contexts {
436436
fresh.setImportInfo(ImportInfo(sym, imp.selectors, impNameOpt))
437437
}
438438

439-
/** Does current phase use an erased types interpretation? */
440-
def erasedTypes: Boolean = currentPhase(using this).erasedTypes
441-
442439
/** Is the debug option set? */
443440
def debug: Boolean = base.settings.Ydebug.value
444441

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ class Definitions {
905905

906906
object ArrayOf {
907907
def apply(elem: Type)(using Context): Type =
908-
if (ctx.erasedTypes) JavaArrayType(elem)
908+
if (currentlyAfterErasure) JavaArrayType(elem)
909909
else ArrayType.appliedTo(elem :: Nil)
910910
def unapply(tp: Type)(using Context): Option[Type] = tp.dealias match {
911911
case AppliedType(at, arg :: Nil) if at.isRef(ArrayType.symbol) => Some(arg)
@@ -1020,7 +1020,7 @@ class Definitions {
10201020
@tu lazy val Function0_apply: Symbol = ImplementedFunctionType(0).symbol.requiredMethod(nme.apply)
10211021

10221022
def FunctionType(n: Int, isContextual: Boolean = false, isErased: Boolean = false)(using Context): TypeRef =
1023-
if (n <= MaxImplementedFunctionArity && (!isContextual || ctx.erasedTypes) && !isErased) ImplementedFunctionType(n)
1023+
if (n <= MaxImplementedFunctionArity && (!isContextual || currentlyAfterErasure) && !isErased) ImplementedFunctionType(n)
10241024
else FunctionClass(n, isContextual, isErased).typeRef
10251025

10261026
lazy val PolyFunctionClass = requiredClass("scala.PolyFunction")
@@ -1285,7 +1285,7 @@ class Definitions {
12851285
*/
12861286
object ContextFunctionType:
12871287
def unapply(tp: Type)(using Context): Option[(List[Type], Type, Boolean)] =
1288-
if ctx.erasedTypes then
1288+
if currentlyAfterErasure then
12891289
atPhase(erasurePhase)(unapply(tp))
12901290
else
12911291
val tp1 = tp.dealias

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Flags._
1515
import DenotTransformers._
1616
import Decorators._
1717
import Signature.MatchDegree._
18-
import Phases.currentPhase
18+
import Phases.{currentPhase, currentlyAfterErasure}
1919
import printing.Texts._
2020
import printing.Printer
2121
import io.AbstractFile
@@ -978,10 +978,10 @@ object Denotations {
978978
true
979979
case MethodNotAMethodMatch =>
980980
// Java allows defining both a field and a zero-parameter method with the same name
981-
!ctx.erasedTypes && !(symbol.is(JavaDefined) && other.symbol.is(JavaDefined))
981+
!currentlyAfterErasure && !(symbol.is(JavaDefined) && other.symbol.is(JavaDefined))
982982
case ParamMatch =>
983983
// The signatures do not tell us enough to be sure about matching
984-
!ctx.erasedTypes && info.matches(other.info)
984+
!currentlyAfterErasure && info.matches(other.info)
985985
case noMatch =>
986986
false
987987
end matches

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ object Phases {
3131

3232
def currentlyAfterTyper(using Context): Boolean = ctx.base.isAfterTyper(currentPhase)
3333

34+
def currentlyAfterErasure(using Context): Boolean = currentPhase.erasedTypes
35+
3436
trait PhasesBase {
3537
this: ContextBase =>
3638

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ object SymDenotations {
864864
def membersNeedAsSeenFrom(pre: Type)(using Context): Boolean =
865865
!( this.isTerm
866866
|| this.isStaticOwner && !this.seesOpaques
867-
|| ctx.erasedTypes
867+
|| currentlyAfterErasure
868868
|| (pre eq NoPrefix)
869869
|| (pre eq thisType)
870870
)
@@ -877,7 +877,7 @@ object SymDenotations {
877877
* Default parameters are recognized until erasure.
878878
*/
879879
def hasDefaultParams(using Context): Boolean =
880-
if ctx.erasedTypes then false
880+
if currentlyAfterErasure then false
881881
else if is(HasDefaultParams) then true
882882
else if is(NoDefaultParams) then false
883883
else
@@ -1643,7 +1643,7 @@ object SymDenotations {
16431643
override final def typeParams(using Context): List[TypeSymbol] = {
16441644
if (myTypeParams == null)
16451645
myTypeParams =
1646-
if (ctx.erasedTypes || is(Module)) Nil // fast return for modules to avoid scanning package decls
1646+
if (currentlyAfterErasure || is(Module)) Nil // fast return for modules to avoid scanning package decls
16471647
else {
16481648
val di = initial
16491649
if (this ne di) di.typeParams
@@ -1731,7 +1731,7 @@ object SymDenotations {
17311731

17321732
def computeBaseData(implicit onBehalf: BaseData, ctx: Context): (List[ClassSymbol], BaseClassSet) = {
17331733
def emptyParentsExpected =
1734-
is(Package) || (symbol == defn.AnyClass) || ctx.erasedTypes && (symbol == defn.ObjectClass)
1734+
is(Package) || (symbol == defn.AnyClass) || currentlyAfterErasure && (symbol == defn.ObjectClass)
17351735
if (classParents.isEmpty && !emptyParentsExpected)
17361736
onBehalf.signalProvisional()
17371737
val builder = new BaseDataBuilder
@@ -1827,7 +1827,7 @@ object SymDenotations {
18271827
*/
18281828
def ensureTypeParamsInCorrectOrder()(using Context): Unit = {
18291829
val tparams = typeParams
1830-
if (!ctx.erasedTypes && !typeParamsFromDecls.corresponds(tparams)(_.name == _.name)) {
1830+
if (!currentlyAfterErasure && !typeParamsFromDecls.corresponds(tparams)(_.name == _.name)) {
18311831
val decls = info.decls
18321832
val decls1 = newScope
18331833
for (tparam <- typeParams) decls1.enter(decls.lookup(tparam.name))

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import util.Stats._
1111
import Names._
1212
import NameOps._
1313
import Flags.Module
14+
import Phases.currentlyAfterErasure
1415
import Variances.variancesConform
1516
import dotty.tools.dotc.config.Config
1617

@@ -287,7 +288,7 @@ class TypeApplications(val self: Type) extends AnyVal {
287288
val typParams = self.typeParams
288289
val stripped = self.stripTypeVar
289290
val dealiased = stripped.safeDealias
290-
if (args.isEmpty || ctx.erasedTypes) self
291+
if (args.isEmpty || currentlyAfterErasure) self
291292
else dealiased match {
292293
case dealiased: HKTypeLambda =>
293294
def tryReduce =

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
260260
// This is safe because X$ self-type is X.type
261261
sym1 = sym1.companionModule
262262
if ((sym1 ne NoSymbol) && (sym1 eq sym2))
263-
ctx.erasedTypes ||
263+
currentlyAfterErasure ||
264264
sym1.isStaticOwner ||
265265
isSubPrefix(tp1.prefix, tp2.prefix) ||
266266
thirdTryNamed(tp2)
@@ -1861,7 +1861,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
18611861
final def glb(tps: List[Type]): Type = tps.foldLeft(AnyType: Type)(glb)
18621862

18631863
def widenInUnions(using Context): Boolean =
1864-
migrateTo3 || ctx.erasedTypes
1864+
migrateTo3 || currentlyAfterErasure
18651865

18661866
/** The least upper bound of two types
18671867
* @param canConstrain If true, new constraints might be added to simplify the lub.
@@ -2020,7 +2020,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
20202020
}
20212021

20222022
private def andTypeGen(tp1: Type, tp2: Type, op: (Type, Type) => Type,
2023-
original: (Type, Type) => Type = _ & _, isErased: Boolean = ctx.erasedTypes): Type = trace(s"glb(${tp1.show}, ${tp2.show})", subtyping, show = true) {
2023+
original: (Type, Type) => Type = _ & _, isErased: Boolean = currentlyAfterErasure): Type = trace(s"glb(${tp1.show}, ${tp2.show})", subtyping, show = true) {
20242024
val t1 = distributeAnd(tp1, tp2)
20252025
if (t1.exists) t1
20262026
else {
@@ -2048,7 +2048,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
20482048
* Finally, refined types with the same refined name are
20492049
* opportunistically merged.
20502050
*/
2051-
final def andType(tp1: Type, tp2: Type, isErased: Boolean = ctx.erasedTypes): Type =
2051+
final def andType(tp1: Type, tp2: Type, isErased: Boolean = currentlyAfterErasure): Type =
20522052
andTypeGen(tp1, tp2, AndType(_, _), isErased = isErased)
20532053

20542054
final def simplifyAndTypeWithFallback(tp1: Type, tp2: Type, fallback: Type): Type =
@@ -2063,7 +2063,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
20632063
* @param isErased Apply erasure semantics. If erased is true, instead of creating
20642064
* an OrType, the lub will be computed using TypeCreator#erasedLub.
20652065
*/
2066-
final def orType(tp1: Type, tp2: Type, isErased: Boolean = ctx.erasedTypes): Type = {
2066+
final def orType(tp1: Type, tp2: Type, isErased: Boolean = currentlyAfterErasure): Type = {
20672067
val t1 = distributeOr(tp1, tp2)
20682068
if (t1.exists) t1
20692069
else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ object TypeErasure {
132132

133133
/** The current context with a phase no later than erasure */
134134
def preErasureCtx(using Context) =
135-
if (ctx.erasedTypes) ctx.withPhase(erasurePhase) else ctx
135+
if (currentlyAfterErasure) ctx.withPhase(erasurePhase) else ctx
136136

137137
/** The standard erasure of a Scala type. Value classes are erased as normal classes.
138138
*
@@ -608,7 +608,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
608608
else
609609
val cls = normalizeClass(sym.asClass)
610610
val fullName =
611-
if !ctx.erasedTypes then
611+
if !currentlyAfterErasure then
612612
// It's important to use the initial symbol to compute the full name
613613
// because the current symbol might have a different name or owner
614614
// and signatures are required to be stable before erasure.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import util.SourcePosition
1010
import NameKinds.DepParamName
1111
import Decorators._
1212
import StdNames._
13-
import Phases.currentPhase
13+
import Phases.{currentPhase, currentlyAfterErasure}
1414
import collection.mutable
1515
import ast.tpd._
1616
import reporting.{trace, Message}
@@ -193,7 +193,7 @@ object TypeOps:
193193
val accu1 = if (accu exists (_ derivesFrom c)) accu else c :: accu
194194
if (cs == c.baseClasses) accu1 else dominators(rest, accu1)
195195
case Nil => // this case can happen because after erasure we do not have a top class anymore
196-
assert(ctx.erasedTypes || ctx.reporter.errorsReported)
196+
assert(currentlyAfterErasure || ctx.reporter.errorsReported)
197197
defn.ObjectClass :: Nil
198198
}
199199

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ object Types {
14131413
TermRef(this, name, member(name))
14141414

14151415
def select(name: TermName, sig: Signature)(using Context): TermRef =
1416-
TermRef(this, name, member(name).atSignature(sig, relaxed = !ctx.erasedTypes))
1416+
TermRef(this, name, member(name).atSignature(sig, relaxed = !currentlyAfterErasure))
14171417

14181418
// ----- Access to parts --------------------------------------------
14191419

@@ -1601,8 +1601,8 @@ object Types {
16011601
def toFunctionType(dropLast: Int = 0)(using Context): Type = this match {
16021602
case mt: MethodType if !mt.isParamDependent =>
16031603
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
1604-
val isContextual = mt.isContextualMethod && !ctx.erasedTypes
1605-
val isErased = mt.isErasedMethod && !ctx.erasedTypes
1604+
val isContextual = mt.isContextualMethod && !currentlyAfterErasure
1605+
val isErased = mt.isErasedMethod && !currentlyAfterErasure
16061606
val result1 = mt.nonDependentResultApprox match {
16071607
case res: MethodType => res.toFunctionType()
16081608
case res => res
@@ -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 atPhase(erasurePhase)(computeSignature)
1907+
else if currentlyAfterErasure 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 atPhase(erasurePhase)(currentSignature)
1921+
else if currentlyAfterErasure then atPhase(erasurePhase)(currentSignature)
19221922
else
19231923
val sym = currentSymbol
19241924
if sym.exists then sym.asSeenFrom(prefix).signature
@@ -1964,6 +1964,7 @@ object Types {
19641964
case _ => if (denotationIsCurrent) lastDenotation.symbol else NoSymbol
19651965
}
19661966

1967+
19671968
/** Retrieves currently valid symbol without necessarily updating denotation.
19681969
* Assumes that symbols do not change between periods in the same run.
19691970
* Used to get the class underlying a ThisType.
@@ -2036,7 +2037,7 @@ object Types {
20362037

20372038
private def disambiguate(d: Denotation, sig: Signature)(using Context): Denotation =
20382039
if (sig != null)
2039-
d.atSignature(sig, relaxed = !ctx.erasedTypes) match {
2040+
d.atSignature(sig, relaxed = !currentlyAfterErasure) match {
20402041
case d1: SingleDenotation => d1
20412042
case d1 =>
20422043
d1.atSignature(sig, relaxed = false) match {
@@ -2559,7 +2560,7 @@ object Types {
25592560
}
25602561

25612562
override def underlying(using Context): Type =
2562-
if (ctx.erasedTypes) tref
2563+
if (currentlyAfterErasure) tref
25632564
else cls.info match {
25642565
case cinfo: ClassInfo => cinfo.selfType
25652566
case _: ErrorType | NoType if ctx.mode.is(Mode.Interactive) => cls.info
@@ -2727,7 +2728,7 @@ object Types {
27272728
else make(RefinedType(parent, names.head, infos.head), names.tail, infos.tail)
27282729

27292730
def apply(parent: Type, name: Name, info: Type)(using Context): RefinedType = {
2730-
assert(!ctx.erasedTypes)
2731+
assert(!currentlyAfterErasure)
27312732
unique(new CachedRefinedType(parent, name, info)).checkInst
27322733
}
27332734
}
@@ -4378,7 +4379,7 @@ object Types {
43784379
val givenSelf = clsd.givenSelfType
43794380
if (!givenSelf.isValueType) appliedRef
43804381
else if (clsd.is(Module)) givenSelf
4381-
else if (ctx.erasedTypes) appliedRef
4382+
else if (currentlyAfterErasure) appliedRef
43824383
else AndType(givenSelf, appliedRef)
43834384
}
43844385
selfTypeCache

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ object ContextFunctionResults:
120120
* @param `n` the select nodes seen in previous recursive iterations of this method
121121
*/
122122
def integrateSelect(tree: untpd.Tree, n: Int = 0)(using Context): Boolean =
123-
if ctx.erasedTypes then
123+
if currentlyAfterErasure then
124124
atPhase(erasurePhase)(integrateSelect(tree, n))
125125
else tree match
126126
case Select(qual, name) =>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class TreeChecker extends Phase with SymTransformer {
318318
override def typed(tree: untpd.Tree, pt: Type = WildcardType)(using Context): Tree = {
319319
val tpdTree = super.typed(tree, pt)
320320
Typer.assertPositioned(tree)
321-
if (ctx.erasedTypes)
321+
if (currentlyAfterErasure)
322322
// Can't be checked in earlier phases since `checkValue` is only run in
323323
// Erasure (because running it in Typer would force too much)
324324
checkIdentNotJavaClass(tpdTree)
@@ -384,7 +384,7 @@ class TreeChecker extends Phase with SymTransformer {
384384
val tpe = tree.typeOpt
385385
val sym = tree.symbol
386386
val symIsFixed = tpe match {
387-
case tpe: TermRef => ctx.erasedTypes || !tpe.isMemberRef
387+
case tpe: TermRef => currentlyAfterErasure || !tpe.isMemberRef
388388
case _ => false
389389
}
390390
if (sym.exists && !sym.is(Private) &&
@@ -455,7 +455,7 @@ class TreeChecker extends Phase with SymTransformer {
455455
(ddef.tparams :: ddef.vparamss).filter(!_.isEmpty).map(_.map(_.symbol))
456456
def layout(symss: List[List[Symbol]]): String =
457457
symss.map(syms => i"($syms%, %)").mkString
458-
assert(ctx.erasedTypes || sym.rawParamss == defParamss,
458+
assert(currentlyAfterErasure || sym.rawParamss == defParamss,
459459
i"""param mismatch for ${sym.showLocated}:
460460
|defined in tree = ${layout(defParamss)}
461461
|stored in symbol = ${layout(sym.rawParamss)}""")

0 commit comments

Comments
 (0)