Skip to content

Commit 8eeb070

Browse files
committed
Cache AppliedType#tryNormalize
1 parent 8d3083b commit 8eeb070

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ object Types {
117117
case t: TypeRef =>
118118
!t.currentSymbol.isStatic && {
119119
(t: Type).mightBeProvisional = false // break cycles
120-
t.symbol.is(Provisional)
120+
// We can use flagsUNSAFE here because in the worth case, we
121+
// will overapproximate isProvisional by returning true if the
122+
// denotation has not been completed yet.
123+
t.symbol.flagsUNSAFE.is(Provisional)
121124
|| test(t.prefix, theAcc)
122-
|| t.info.match
125+
|| t.denot.infoOrCompleter.match
123126
case info: AliasingBounds => test(info.alias, theAcc)
124127
case TypeBounds(lo, hi) => test(lo, theAcc) || test(hi, theAcc)
125128
case _ => false
@@ -4212,7 +4215,17 @@ object Types {
42124215
def isUnreducibleWild(using Context): Boolean =
42134216
tycon.isLambdaSub && hasWildcardArg && !isMatchAlias
42144217

4215-
def tryCompiletimeConstantFold(using Context): Type = tycon match {
4218+
var myTryCompiletimeConstantFold: Type | Null = null
4219+
var myTryCompiletimeConstantFoldPeriod: Period = Nowhere
4220+
4221+
def tryCompiletimeConstantFold(using Context): Type =
4222+
if myTryCompiletimeConstantFoldPeriod != ctx.period then
4223+
myTryCompiletimeConstantFold = tryCompiletimeConstantFoldImpl
4224+
if !isProvisional then
4225+
myTryCompiletimeConstantFoldPeriod = ctx.period
4226+
myTryCompiletimeConstantFold.nn
4227+
4228+
private def tryCompiletimeConstantFoldImpl(using Context): Type = tycon match {
42164229
case tycon: TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
42174230
extension (tp: Type) def fixForEvaluation: Type =
42184231
tp.normalized.dealias match {

0 commit comments

Comments
 (0)