@@ -466,7 +466,7 @@ object Types extends TypeUtils {
466
466
case _ => false
467
467
468
468
/** Does this application expand to a match type? */
469
- def isMatchAlias (using Context ): Boolean = underlyingMatchType.exists
469
+ def isMatchAlias (using Context ): Boolean = underlyingNormalizable.isMatch
470
470
471
471
/** Is this a higher-kinded type lambda with given parameter variances?
472
472
* These lambdas are used as the RHS of higher-kinded abstract types or
@@ -1519,27 +1519,23 @@ object Types extends TypeUtils {
1519
1519
}
1520
1520
deskolemizer(this )
1521
1521
1522
- /** Constant fold applied compiletime operations if possible */
1523
- final def compiletimeConstantFolded (using Context ) = this match
1524
- case tp : AppliedType => tp.tryCompiletimeConstantFold.orElse(this )
1525
- case tp => tp
1526
-
1527
1522
/** The result of normalization, or the type itself if none apply. */
1528
1523
final def normalized (using Context ): Type = tryNormalize.orElse(this )
1529
1524
1530
- /** If this type has an underlying match type, the result after applying all
1531
- * toplevel normalizations, otherwise NoType.
1525
+ /** If this type has an underlying match type or applied compiletime.ops,
1526
+ * then the result after applying all toplevel normalizations, otherwise NoType.
1532
1527
*/
1533
- def tryNormalize (using Context ): Type = underlyingMatchType match
1528
+ def tryNormalize (using Context ): Type = underlyingNormalizable match
1534
1529
case mt : MatchType => mt.reduced.normalized
1530
+ case tp : AppliedType => tp.tryCompiletimeConstantFold
1535
1531
case _ => NoType
1536
1532
1537
1533
/** Perform successive dealiasings and beta-reductions of applied types until
1538
1534
* a match type is reached if any, otherwise NoType.
1539
1535
*/
1540
- def underlyingMatchType (using Context ): Type = this .safeDealias.stripLazyRef match
1536
+ def underlyingNormalizable (using Context ): Type = this .safeDealias.stripLazyRef match
1541
1537
case tp : MatchType => tp
1542
- case tp : AppliedType => tp.underlyingMatchType
1538
+ case tp : AppliedType => tp.underlyingNormalizable
1543
1539
case _ => NoType
1544
1540
1545
1541
private def widenDealias1 (keep : AnnotatedType => Context ?=> Boolean )(using Context ): Type = {
@@ -4586,8 +4582,8 @@ object Types extends TypeUtils {
4586
4582
private var myEvalRunId : RunId = NoRunId
4587
4583
private var myEvalued : Type = uninitialized
4588
4584
4589
- private var validUnderlyingMatch : Period = Nowhere
4590
- private var cachedUnderlyingMatch : Type = uninitialized
4585
+ private var validUnderlyingNormalizable : Period = Nowhere
4586
+ private var cachedUnderlyingNormalizable : Type = uninitialized
4591
4587
4592
4588
def isGround (acc : TypeAccumulator [Boolean ])(using Context ): Boolean =
4593
4589
if myGround == 0 then myGround = if acc.foldOver(true , this ) then 1 else - 1
@@ -4649,11 +4645,13 @@ object Types extends TypeUtils {
4649
4645
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4650
4646
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
4651
4647
*/
4652
- override def underlyingMatchType (using Context ): Type =
4653
- if ctx.period != validUnderlyingMatch then
4654
- validUnderlyingMatch = if tycon.isProvisional then Nowhere else ctx.period
4655
- cachedUnderlyingMatch = superType.underlyingMatchType
4656
- cachedUnderlyingMatch
4648
+ override def underlyingNormalizable (using Context ): Type =
4649
+ if ctx.period != validUnderlyingNormalizable then
4650
+ validUnderlyingNormalizable = if tycon.isProvisional then Nowhere else ctx.period
4651
+ cachedUnderlyingNormalizable = tycon match
4652
+ case tycon : TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) => this
4653
+ case _ => superType.underlyingNormalizable
4654
+ cachedUnderlyingNormalizable
4657
4655
4658
4656
override def tryNormalize (using Context ): Type =
4659
4657
if MatchTypeTrace .isRecording && isMatchAlias then
@@ -5153,8 +5151,7 @@ object Types extends TypeUtils {
5153
5151
myReduced = trace(i " reduce match type $this $hashCode" , matchTypes, show = true ):
5154
5152
withMode(Mode .Type ):
5155
5153
TypeComparer .reduceMatchWith: cmp =>
5156
- val scrutNormed = scrutinee.normalized.compiletimeConstantFolded
5157
- cmp.matchCases(scrutNormed, cases.map(MatchTypeCaseSpec .analyze))
5154
+ cmp.matchCases(scrutinee.normalized, cases.map(MatchTypeCaseSpec .analyze))
5158
5155
catch case ex : Throwable =>
5159
5156
myReduced = NoType
5160
5157
handleRecursive(" reduce type " , i " $scrutinee match ... " , ex)
@@ -5188,7 +5185,7 @@ object Types extends TypeUtils {
5188
5185
def apply (bound : Type , scrutinee : Type , cases : List [Type ])(using Context ): MatchType =
5189
5186
unique(new CachedMatchType (bound, scrutinee, cases))
5190
5187
5191
- def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp.underlyingMatchType match
5188
+ def thatReducesUsingGadt (tp : Type )(using Context ): Boolean = tp.underlyingNormalizable match
5192
5189
case mt : MatchType => mt.reducesUsingGadt
5193
5190
case _ => false
5194
5191
0 commit comments