Skip to content

Commit 08967f6

Browse files
committed
Regroup tryNormalize logic
[Cherry-picked 0b87d7f][modified]
1 parent dc2d31b commit 08967f6

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,6 @@ object Types extends TypeUtils {
461461
/** Does this application expand to a match type? */
462462
def isMatchAlias(using Context): Boolean = underlyingNormalizable.isMatch
463463

464-
def underlyingNormalizable(using Context): Type = stripped.stripLazyRef match
465-
case tp: MatchType => tp
466-
case tp: AppliedType => tp.underlyingNormalizable
467-
case _ => NoType
468-
469464
/** Is this a higher-kinded type lambda with given parameter variances?
470465
* These lambdas are used as the RHS of higher-kinded abstract types or
471466
* type aliases. The variance info is strictly needed only for abstract types.
@@ -1480,22 +1475,25 @@ object Types extends TypeUtils {
14801475
}
14811476
deskolemizer(this)
14821477

1483-
/** The result of normalization using `tryNormalize`, or the type itself if
1484-
* tryNormlize yields NoType
1485-
*/
1486-
final def normalized(using Context): Type = {
1487-
val normed = tryNormalize
1488-
if (normed.exists) normed else this
1489-
}
1478+
/** The result of normalization, or the type itself if none apply. */
1479+
final def normalized(using Context): Type = tryNormalize.orElse(this)
14901480

14911481
/** If this type has an underlying match type or applied compiletime.ops,
14921482
* then the result after applying all toplevel normalizations, otherwise NoType.
14931483
*/
14941484
def tryNormalize(using Context): Type = underlyingNormalizable match
1495-
case mt: MatchType => mt.tryNormalize
1485+
case mt: MatchType => mt.reduced.normalized
14961486
case tp: AppliedType => tp.tryCompiletimeConstantFold
14971487
case _ => NoType
14981488

1489+
/** Perform successive strippings, and beta-reductions of applied types until
1490+
* a match type or applied compiletime.ops is reached, if any, otherwise NoType.
1491+
*/
1492+
def underlyingNormalizable(using Context): Type = stripped.stripLazyRef match
1493+
case tp: MatchType => tp
1494+
case tp: AppliedType => tp.underlyingNormalizable
1495+
case _ => NoType
1496+
14991497
private def widenDealias1(keep: AnnotatedType => Context ?=> Boolean)(using Context): Type = {
15001498
val res = this.widen.dealias1(keep, keepOpaques = false)
15011499
if (res eq this) res else res.widenDealias1(keep)
@@ -4517,9 +4515,10 @@ object Types extends TypeUtils {
45174515
case nil => x
45184516
foldArgs(op(x, tycon), args)
45194517

4520-
/** Exists if the tycon is a TypeRef of an alias with an underlying match type.
4521-
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4522-
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
4518+
/** Exists if the tycon is a TypeRef of an alias with an underlying match type,
4519+
* or a compiletime applied type. Anything else should have already been
4520+
* reduced in `appliedTo` by the TypeAssigner. This may reduce several
4521+
* HKTypeLambda applications before the underlying normalizable type is reached.
45234522
*/
45244523
override def underlyingNormalizable(using Context): Type =
45254524
if ctx.period != validUnderlyingNormalizable then tycon match
@@ -4957,8 +4956,6 @@ object Types extends TypeUtils {
49574956
private var myReduced: Type | Null = null
49584957
private var reductionContext: util.MutableMap[Type, Type] = _
49594958

4960-
override def tryNormalize(using Context): Type =
4961-
reduced.normalized
49624959

49634960
def reduced(using Context): Type = atPhaseNoLater(elimOpaquePhase) {
49644961

0 commit comments

Comments
 (0)