Skip to content

Commit 47d687b

Browse files
EugeneFlesselleWojciechMazur
authored andcommitted
Use cached underlyingMatchType when normalizing applied match aliases
Also fixes underlyingMatchType to not use the resType of HKTypeLambdas It should only be in `isMatch` used for `AliasingBounds`, not `isMatchAlias` [Cherry-picked ac98023]
1 parent 65748a8 commit 47d687b

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

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

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,10 @@ object Types extends TypeUtils {
492492
/** Does this application expand to a match type? */
493493
def isMatchAlias(using Context): Boolean = underlyingMatchType.exists
494494

495-
def underlyingMatchType(using Context): Type = stripped match {
495+
def underlyingMatchType(using Context): Type = stripped match
496496
case tp: MatchType => tp
497-
case tp: HKTypeLambda => tp.resType.underlyingMatchType
498497
case tp: AppliedType => tp.underlyingMatchType
499498
case _ => NoType
500-
}
501499

502500
/** Is this a higher-kinded type lambda with given parameter variances?
503501
* These lambdas are used as the RHS of higher-kinded abstract types or
@@ -4682,35 +4680,23 @@ object Types extends TypeUtils {
46824680

46834681
/** Exists if the tycon is a TypeRef of an alias with an underlying match type.
46844682
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4683+
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
46854684
*/
46864685
override def underlyingMatchType(using Context): Type =
46874686
if ctx.period != validUnderlyingMatch then
46884687
cachedUnderlyingMatch = superType.underlyingMatchType
46894688
validUnderlyingMatch = validSuper
46904689
cachedUnderlyingMatch
46914690

4692-
override def tryNormalize(using Context): Type = tycon.stripTypeVar match {
4693-
case tycon: TypeRef =>
4694-
def tryMatchAlias = tycon.info match
4695-
case AliasingBounds(alias) if isMatchAlias =>
4696-
trace(i"normalize $this", typr, show = true) {
4697-
MatchTypeTrace.recurseWith(this) {
4698-
alias.applyIfParameterized(args).tryNormalize
4699-
/* `applyIfParameterized` may reduce several HKTypeLambda applications
4700-
* before the underlying MatchType is reached.
4701-
* Even if they do not involve any match type normalizations yet,
4702-
* we still want to record these reductions in the MatchTypeTrace.
4703-
* They should however only be attempted if they eventually expand
4704-
* to a match type, which is ensured by the `isMatchAlias` guard.
4705-
*/
4706-
}
4707-
}
4708-
case _ =>
4709-
NoType
4710-
tryCompiletimeConstantFold.orElse(tryMatchAlias)
4711-
case _ =>
4712-
NoType
4713-
}
4691+
override def tryNormalize(using Context): Type =
4692+
def tryMatchAlias =
4693+
if isMatchAlias then trace(i"normalize $this", typr, show = true):
4694+
if MatchTypeTrace.isRecording then
4695+
MatchTypeTrace.recurseWith(this)(superType.tryNormalize)
4696+
else
4697+
underlyingMatchType.tryNormalize
4698+
else NoType
4699+
tryCompiletimeConstantFold.orElse(tryMatchAlias)
47144700

47154701
/** Is this an unreducible application to wildcard arguments?
47164702
* This is the case if tycon is higher-kinded. This means

0 commit comments

Comments
 (0)