diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index c71ad928a7d2..4a103c7787fb 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -117,9 +117,12 @@ object Types { case t: TypeRef => !t.currentSymbol.isStatic && { (t: Type).mightBeProvisional = false // break cycles - t.symbol.is(Provisional) + // We can use flagsUNSAFE here because in the worth case, we + // will overapproximate isProvisional by returning true if the + // denotation has not been completed yet. + t.symbol.flagsUNSAFE.is(Provisional) || test(t.prefix, theAcc) - || t.info.match + || t.denot.infoOrCompleter.match case info: AliasingBounds => test(info.alias, theAcc) case TypeBounds(lo, hi) => test(lo, theAcc) || test(hi, theAcc) case _ => false @@ -2072,7 +2075,7 @@ object Types { private var myNarrow: TermRef | Null = null override def narrow(using Context): TermRef = { if (myNarrow == null) myNarrow = super.narrow - myNarrow.nn + myNarrow.uncheckedNN } } @@ -3024,7 +3027,7 @@ object Types { def recThis: RecThis = { if (myRecThis == null) myRecThis = new RecThisImpl(this) - myRecThis.nn + myRecThis.uncheckedNN } override def underlying(using Context): Type = parent @@ -3446,7 +3449,7 @@ object Types { case _ :: rest => newParamRef(i) :: recur(rest, i + 1) case _ => Nil myParamRefs = recur(paramNames, 0) - myParamRefs.nn + myParamRefs.uncheckedNN } /** Like `paramInfos` but substitute parameter references with the given arguments */ @@ -4212,7 +4215,17 @@ object Types { def isUnreducibleWild(using Context): Boolean = tycon.isLambdaSub && hasWildcardArg && !isMatchAlias - def tryCompiletimeConstantFold(using Context): Type = tycon match { + var myTryCompiletimeConstantFold: Type | Null = null + var myTryCompiletimeConstantFoldPeriod: Period = Nowhere + + def tryCompiletimeConstantFold(using Context): Type = + if myTryCompiletimeConstantFoldPeriod != ctx.period then + myTryCompiletimeConstantFold = tryCompiletimeConstantFoldImpl + if !isProvisional then + myTryCompiletimeConstantFoldPeriod = ctx.period + myTryCompiletimeConstantFold.uncheckedNN + + private def tryCompiletimeConstantFoldImpl(using Context): Type = tycon match { case tycon: TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) => extension (tp: Type) def fixForEvaluation: Type = tp.normalized.dealias match { @@ -4634,7 +4647,7 @@ object Types { private var myRepr: Name | Null = null def repr(using Context): Name = { if (myRepr == null) myRepr = SkolemName.fresh() - myRepr.nn + myRepr.uncheckedNN } override def toString: String = s"Skolem($hashCode)" @@ -4873,7 +4886,7 @@ object Types { TypeComparer.tracked(matchCases) } - myReduced.nn + myReduced.uncheckedNN } override def computeHash(bs: Binders): Int = doHash(bs, scrutinee, bound :: cases) @@ -4932,14 +4945,14 @@ object Types { else if (ctx.erasedTypes) appliedRef else AndType(givenSelf, appliedRef) } - selfTypeCache.nn + selfTypeCache.uncheckedNN } def appliedRef(using Context): Type = { if (appliedRefCache == null) appliedRefCache = TypeRef(prefix, cls).appliedTo(cls.classDenot.typeParams.map(_.typeRef)) - appliedRefCache.nn + appliedRefCache.uncheckedNN } // cached because baseType needs parents @@ -4948,7 +4961,7 @@ object Types { override def parents(using Context): List[Type] = { if (parentsCache == null) parentsCache = declaredParents.mapConserve(_.asSeenFrom(prefix, cls.owner)) - parentsCache.nn + parentsCache.uncheckedNN } protected def newLikeThis(prefix: Type, declaredParents: List[Type], decls: Scope, selfInfo: TypeOrSymbol)(using Context): ClassInfo =