Skip to content

Commit e47f635

Browse files
Cache underlying applied compiletime.ops
1 parent a0839bc commit e47f635

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

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

+14-12
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,11 @@ object Types extends TypeUtils {
466466
case _ => false
467467

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

471-
def underlyingMatchType(using Context): Type = stripped match
471+
def underlyingNormalizable(using Context): Type = stripped match
472472
case tp: MatchType => tp
473-
case tp: AppliedType => tp.underlyingMatchType
473+
case tp: AppliedType => tp.underlyingNormalizable
474474
case _ => NoType
475475

476476
/** Is this a higher-kinded type lambda with given parameter variances?
@@ -4584,8 +4584,8 @@ object Types extends TypeUtils {
45844584
private var myEvalRunId: RunId = NoRunId
45854585
private var myEvalued: Type = uninitialized
45864586

4587-
private var validUnderlyingMatch: Period = Nowhere
4588-
private var cachedUnderlyingMatch: Type = uninitialized
4587+
private var validUnderlyingNormalizable: Period = Nowhere
4588+
private var cachedUnderlyingNormalizable: Type = uninitialized
45894589

45904590
def isGround(acc: TypeAccumulator[Boolean])(using Context): Boolean =
45914591
if myGround == 0 then myGround = if acc.foldOver(true, this) then 1 else -1
@@ -4647,19 +4647,21 @@ object Types extends TypeUtils {
46474647
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
46484648
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
46494649
*/
4650-
override def underlyingMatchType(using Context): Type =
4651-
if ctx.period != validUnderlyingMatch then
4652-
validUnderlyingMatch = if tycon.isProvisional then Nowhere else ctx.period
4653-
cachedUnderlyingMatch = superType.underlyingMatchType
4654-
cachedUnderlyingMatch
4650+
override def underlyingNormalizable(using Context): Type =
4651+
if ctx.period != validUnderlyingNormalizable then
4652+
validUnderlyingNormalizable = if tycon.isProvisional then Nowhere else ctx.period
4653+
cachedUnderlyingNormalizable = tycon match
4654+
case tycon: TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) => this
4655+
case _ => superType.underlyingNormalizable
4656+
cachedUnderlyingNormalizable
46554657

46564658
override def tryNormalize(using Context): Type =
46574659
def tryMatchAlias =
46584660
if isMatchAlias then trace(i"normalize $this", typr, show = true):
46594661
if MatchTypeTrace.isRecording then
46604662
MatchTypeTrace.recurseWith(this)(superType.tryNormalize)
46614663
else
4662-
underlyingMatchType.tryNormalize
4664+
underlyingNormalizable.tryNormalize
46634665
else NoType
46644666
tryCompiletimeConstantFold.orElse(tryMatchAlias)
46654667

@@ -5197,7 +5199,7 @@ object Types extends TypeUtils {
51975199
def apply(bound: Type, scrutinee: Type, cases: List[Type])(using Context): MatchType =
51985200
unique(new CachedMatchType(bound, scrutinee, cases))
51995201

5200-
def thatReducesUsingGadt(tp: Type)(using Context): Boolean = tp.underlyingMatchType match
5202+
def thatReducesUsingGadt(tp: Type)(using Context): Boolean = tp.underlyingNormalizable match
52015203
case mt: MatchType => mt.reducesUsingGadt
52025204
case _ => false
52035205

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
18471847
case _ => false
18481848
}
18491849

1850-
val result = pt.underlyingMatchType match {
1850+
val result = pt.underlyingNormalizable match {
18511851
case mt: MatchType if isMatchTypeShaped(mt) =>
18521852
typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt)
18531853
case _ =>

0 commit comments

Comments
 (0)