Skip to content

Commit dcc4d35

Browse files
committed
Cache applied match alias reductions
1 parent b46a60c commit dcc4d35

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,6 +4407,10 @@ object Types {
44074407
private var myEvalRunId: RunId = NoRunId
44084408
private var myEvalued: Type = uninitialized
44094409

4410+
private var myReducing: Boolean = false
4411+
private var myUnreduced: Type = uninitialized
4412+
private var myUnreduceRunId: RunId = NoRunId
4413+
44104414
def isGround(acc: TypeAccumulator[Boolean])(using Context): Boolean =
44114415
if myGround == 0 then myGround = if acc.foldOver(true, this) then 1 else -1
44124416
myGround > 0
@@ -4467,10 +4471,23 @@ object Types {
44674471
case tycon: TypeRef =>
44684472
def tryMatchAlias = tycon.info match {
44694473
case MatchAlias(alias) =>
4470-
trace(i"normalize $this", typr, show = true) {
4471-
MatchTypeTrace.recurseWith(this) {
4472-
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
4473-
}
4474+
trace(i"normalize($this)", typr) {
4475+
if myReducing then
4476+
NoType
4477+
else try
4478+
myReducing = true
4479+
MatchTypeTrace.recurseWith(this) {
4480+
val app = if myUnreduceRunId != ctx.runId then
4481+
val app = alias.applyIfParameterized(args)
4482+
if !isProvisional then
4483+
myUnreduced = app
4484+
myUnreduceRunId = ctx.runId
4485+
app
4486+
else myUnreduced
4487+
val norm = app.tryNormalize
4488+
if norm eq this then NoType else norm
4489+
}
4490+
finally myReducing = false
44744491
}
44754492
case _ =>
44764493
NoType

0 commit comments

Comments
 (0)