@@ -456,12 +456,10 @@ object Types extends TypeUtils {
456
456
*/
457
457
def isMatch (using Context ): Boolean = underlyingMatchType.exists
458
458
459
- def underlyingMatchType (using Context ): Type = stripped match {
459
+ def underlyingMatchType (using Context ): Type = stripped match
460
460
case tp : MatchType => tp
461
- case tp : HKTypeLambda => tp.resType.underlyingMatchType
462
- case tp : AppliedType if tp.isMatchAlias => tp.superType.underlyingMatchType
461
+ case tp : AppliedType => tp.underlyingMatchType
463
462
case _ => NoType
464
- }
465
463
466
464
/** Is this a higher-kinded type lambda with given parameter variances?
467
465
* These lambdas are used as the RHS of higher-kinded abstract types or
@@ -4455,6 +4453,9 @@ object Types extends TypeUtils {
4455
4453
private var myEvalRunId : RunId = NoRunId
4456
4454
private var myEvalued : Type = uninitialized
4457
4455
4456
+ private var validUnderlyingMatch : Period = Nowhere
4457
+ private var cachedUnderlyingMatch : Type = uninitialized
4458
+
4458
4459
def isGround (acc : TypeAccumulator [Boolean ])(using Context ): Boolean =
4459
4460
if myGround == 0 then myGround = if acc.foldOver(true , this ) then 1 else - 1
4460
4461
myGround > 0
@@ -4511,29 +4512,25 @@ object Types extends TypeUtils {
4511
4512
case nil => x
4512
4513
foldArgs(op(x, tycon), args)
4513
4514
4514
- override def tryNormalize (using Context ): Type = tycon.stripTypeVar match {
4515
- case tycon : TypeRef =>
4516
- def tryMatchAlias = tycon.info match {
4517
- case MatchAlias (alias) =>
4518
- trace(i " normalize $this" , typr, show = true ) {
4519
- MatchTypeTrace .recurseWith(this ) {
4520
- alias.applyIfParameterized(args).tryNormalize
4521
- /* `applyIfParameterized` may reduce several HKTypeLambda applications
4522
- * before the underlying MatchType is reached.
4523
- * Even if they do not involve any match type normalizations yet,
4524
- * we still want to record these reductions in the MatchTypeTrace.
4525
- * They should however only be attempted if they eventually expand
4526
- * to a match type, which is ensured by the `isMatchAlias` guard.
4527
- */
4528
- }
4529
- }
4530
- case _ =>
4531
- NoType
4532
- }
4533
- tryCompiletimeConstantFold.orElse(tryMatchAlias)
4534
- case _ =>
4535
- NoType
4536
- }
4515
+ /** Exists if the tycon is a TypeRef of an alias with an underlying match type.
4516
+ * Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4517
+ * May reduce several HKTypeLambda applications before the underlying MatchType is reached.
4518
+ */
4519
+ override def underlyingMatchType (using Context ): Type =
4520
+ if ctx.period != validUnderlyingMatch then
4521
+ cachedUnderlyingMatch = superType.underlyingMatchType
4522
+ validUnderlyingMatch = validSuper
4523
+ cachedUnderlyingMatch
4524
+
4525
+ override def tryNormalize (using Context ): Type =
4526
+ def tryMatchAlias =
4527
+ if isMatchAlias then trace(i " normalize $this" , typr, show = true ):
4528
+ if MatchTypeTrace .isRecording then
4529
+ MatchTypeTrace .recurseWith(this )(superType.tryNormalize)
4530
+ else
4531
+ underlyingMatchType.tryNormalize
4532
+ else NoType
4533
+ tryCompiletimeConstantFold.orElse(tryMatchAlias)
4537
4534
4538
4535
/** Does this application expand to a match type? */
4539
4536
def isMatchAlias (using Context ): Boolean = tycon.stripTypeVar match
0 commit comments