Skip to content

Commit

Permalink
Cache applied match alias reductions
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jun 13, 2023
1 parent b46a60c commit dcc4d35
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4407,6 +4407,10 @@ object Types {
private var myEvalRunId: RunId = NoRunId
private var myEvalued: Type = uninitialized

private var myReducing: Boolean = false
private var myUnreduced: Type = uninitialized
private var myUnreduceRunId: RunId = NoRunId

def isGround(acc: TypeAccumulator[Boolean])(using Context): Boolean =
if myGround == 0 then myGround = if acc.foldOver(true, this) then 1 else -1
myGround > 0
Expand Down Expand Up @@ -4467,10 +4471,23 @@ object Types {
case tycon: TypeRef =>
def tryMatchAlias = tycon.info match {
case MatchAlias(alias) =>
trace(i"normalize $this", typr, show = true) {
MatchTypeTrace.recurseWith(this) {
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
}
trace(i"normalize($this)", typr) {
if myReducing then
NoType
else try
myReducing = true
MatchTypeTrace.recurseWith(this) {
val app = if myUnreduceRunId != ctx.runId then
val app = alias.applyIfParameterized(args)
if !isProvisional then
myUnreduced = app
myUnreduceRunId = ctx.runId
app
else myUnreduced
val norm = app.tryNormalize
if norm eq this then NoType else norm
}
finally myReducing = false
}
case _ =>
NoType
Expand Down

0 comments on commit dcc4d35

Please sign in to comment.