Skip to content

Commit 96e1870

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

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,22 +4177,20 @@ object Types {
41774177
case nil => x
41784178
foldArgs(op(x, tycon), args)
41794179

4180-
override def tryNormalize(using Context): Type = tycon.stripTypeVar match {
4181-
case tycon: TypeRef =>
4182-
def tryMatchAlias = tycon.info match {
4183-
case MatchAlias(alias) =>
4184-
trace(i"normalize $this", typr, show = true) {
4185-
MatchTypeTrace.recurseWith(this) {
4186-
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
4180+
override def tryNormalize(using Context): Type =
4181+
tycon.stripTypeVar match
4182+
case tycon: TypeRef =>
4183+
def tryMatchAlias = tycon.info match
4184+
case MatchAlias(alias) =>
4185+
trace(i"normalize $this", typr, show = true) {
4186+
MatchTypeTrace.recurseWith(this) {
4187+
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
4188+
}
41874189
}
4188-
}
4189-
case _ =>
4190-
NoType
4191-
}
4192-
tryCompiletimeConstantFold.orElse(tryMatchAlias)
4193-
case _ =>
4194-
NoType
4195-
}
4190+
case _ => NoType
4191+
tryCompiletimeConstantFold.orElse(tryMatchAlias)
4192+
case _ =>
4193+
NoType
41964194

41974195
/** Does this application expand to a match type? */
41984196
def isMatchAlias(using Context): Boolean = tycon.stripTypeVar match
@@ -4212,7 +4210,16 @@ object Types {
42124210
def isUnreducibleWild(using Context): Boolean =
42134211
tycon.isLambdaSub && hasWildcardArg && !isMatchAlias
42144212

4215-
def tryCompiletimeConstantFold(using Context): Type = tycon match {
4213+
var myTryCompiletimeConstantFold: Type | Null = null
4214+
var myTryCompiletimeConstantFoldPeriod: Period = Nowhere
4215+
4216+
def tryCompiletimeConstantFold(using Context): Type =
4217+
if myTryCompiletimeConstantFoldPeriod != ctx.period then
4218+
myTryCompiletimeConstantFoldPeriod = ctx.period
4219+
myTryCompiletimeConstantFold = tryCompiletimeConstantFoldImpl
4220+
myTryCompiletimeConstantFold.nn
4221+
4222+
private def tryCompiletimeConstantFoldImpl(using Context): Type = tycon match {
42164223
case tycon: TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
42174224
extension (tp: Type) def fixForEvaluation: Type =
42184225
tp.normalized.dealias match {

0 commit comments

Comments
 (0)