Skip to content

Commit 6964304

Browse files
EugeneFlesselleWojciechMazur
authored andcommitted
Cache underlying applied compiletime.ops
[Cherry-picked 68ca883]
1 parent 47d687b commit 6964304

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ object Types extends TypeUtils {
490490
case _ => false
491491

492492
/** Does this application expand to a match type? */
493-
def isMatchAlias(using Context): Boolean = underlyingMatchType.exists
493+
def isMatchAlias(using Context): Boolean = underlyingNormalizable.isMatch
494494

495-
def underlyingMatchType(using Context): Type = stripped match
495+
def underlyingNormalizable(using Context): Type = stripped match
496496
case tp: MatchType => tp
497-
case tp: AppliedType => tp.underlyingMatchType
497+
case tp: AppliedType => tp.underlyingNormalizable
498498
case _ => NoType
499499

500500
/** Is this a higher-kinded type lambda with given parameter variances?
@@ -4613,8 +4613,8 @@ object Types extends TypeUtils {
46134613
private var myEvalRunId: RunId = NoRunId
46144614
private var myEvalued: Type = uninitialized
46154615

4616-
private var validUnderlyingMatch: Period = Nowhere
4617-
private var cachedUnderlyingMatch: Type = uninitialized
4616+
private var validUnderlyingNormalizable: Period = Nowhere
4617+
private var cachedUnderlyingNormalizable: Type = uninitialized
46184618

46194619
def isGround(acc: TypeAccumulator[Boolean])(using Context): Boolean =
46204620
if myGround == 0 then myGround = if acc.foldOver(true, this) then 1 else -1
@@ -4682,19 +4682,23 @@ object Types extends TypeUtils {
46824682
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
46834683
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
46844684
*/
4685-
override def underlyingMatchType(using Context): Type =
4686-
if ctx.period != validUnderlyingMatch then
4687-
cachedUnderlyingMatch = superType.underlyingMatchType
4688-
validUnderlyingMatch = validSuper
4689-
cachedUnderlyingMatch
4685+
override def underlyingNormalizable(using Context): Type =
4686+
if ctx.period != validUnderlyingNormalizable then tycon match
4687+
case tycon: TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
4688+
cachedUnderlyingNormalizable = this
4689+
validUnderlyingNormalizable = ctx.period
4690+
case _ =>
4691+
cachedUnderlyingNormalizable = superType.underlyingNormalizable
4692+
validUnderlyingNormalizable = validSuper
4693+
cachedUnderlyingNormalizable
46904694

46914695
override def tryNormalize(using Context): Type =
46924696
def tryMatchAlias =
46934697
if isMatchAlias then trace(i"normalize $this", typr, show = true):
46944698
if MatchTypeTrace.isRecording then
46954699
MatchTypeTrace.recurseWith(this)(superType.tryNormalize)
46964700
else
4697-
underlyingMatchType.tryNormalize
4701+
underlyingNormalizable.tryNormalize
46984702
else NoType
46994703
tryCompiletimeConstantFold.orElse(tryMatchAlias)
47004704

@@ -5268,7 +5272,7 @@ object Types extends TypeUtils {
52685272
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
52695273
unique(new CachedMatchType(bound, scrutinee, cases))
52705274

5271-
def thatReducesUsingGadt(tp: Type)(using Context): Boolean = tp.underlyingMatchType match
5275+
def thatReducesUsingGadt(tp: Type)(using Context): Boolean = tp.underlyingNormalizable match
52725276
case mt: MatchType => mt.reducesUsingGadt
52735277
case _ => false
52745278

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
20312031
case _ => false
20322032
}
20332033

2034-
val result = pt.underlyingMatchType match {
2034+
val result = pt.underlyingNormalizable match {
20352035
case mt: MatchType if isMatchTypeShaped(mt) =>
20362036
typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt)
20372037
case _ =>

0 commit comments

Comments
 (0)