Skip to content

Commit 45f5bd8

Browse files
Regroup tryNormalize logic
1 parent 3fc5826 commit 45f5bd8

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

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

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

471-
def underlyingNormalizable(using Context): Type = stripped.stripLazyRef match
472-
case tp: MatchType => tp
473-
case tp: AppliedType => tp.underlyingNormalizable
474-
case _ => NoType
475-
476471
/** Is this a higher-kinded type lambda with given parameter variances?
477472
* These lambdas are used as the RHS of higher-kinded abstract types or
478473
* type aliases. The variance info is strictly needed only for abstract types.
@@ -1524,22 +1519,25 @@ object Types extends TypeUtils {
15241519
}
15251520
deskolemizer(this)
15261521

1527-
/** The result of normalization using `tryNormalize`, or the type itself if
1528-
* tryNormlize yields NoType
1529-
*/
1530-
final def normalized(using Context): Type = {
1531-
val normed = tryNormalize
1532-
if (normed.exists) normed else this
1533-
}
1522+
/** The result of normalization, or the type itself if none apply. */
1523+
final def normalized(using Context): Type = tryNormalize.orElse(this)
15341524

15351525
/** If this type has an underlying match type or applied compiletime.ops,
15361526
* then the result after applying all toplevel normalizations, otherwise NoType.
15371527
*/
15381528
def tryNormalize(using Context): Type = underlyingNormalizable match
1539-
case mt: MatchType => mt.tryNormalize
1529+
case mt: MatchType => mt.reduced.normalized
15401530
case tp: AppliedType => tp.tryCompiletimeConstantFold
15411531
case _ => NoType
15421532

1533+
/** Perform successive strippings, and beta-reductions of applied types until
1534+
* a match type or applied compiletime.ops is reached, if any, otherwise NoType.
1535+
*/
1536+
def underlyingNormalizable(using Context): Type = stripped.stripLazyRef match
1537+
case tp: MatchType => tp
1538+
case tp: AppliedType => tp.underlyingNormalizable
1539+
case _ => NoType
1540+
15431541
private def widenDealias1(keep: AnnotatedType => Context ?=> Boolean)(using Context): Type = {
15441542
val res = this.widen.dealias1(keep, keepOpaques = false)
15451543
if (res eq this) res else res.widenDealias1(keep)
@@ -4643,9 +4641,10 @@ object Types extends TypeUtils {
46434641
case nil => x
46444642
foldArgs(op(x, tycon), args)
46454643

4646-
/** Exists if the tycon is a TypeRef of an alias with an underlying match type.
4647-
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4648-
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
4644+
/** Exists if the tycon is a TypeRef of an alias with an underlying match type,
4645+
* or a compiletime applied type. Anything else should have already been
4646+
* reduced in `appliedTo` by the TypeAssigner. This may reduce several
4647+
* HKTypeLambda applications before the underlying normalizable type is reached.
46494648
*/
46504649
override def underlyingNormalizable(using Context): Type =
46514650
if ctx.period != validUnderlyingNormalizable then
@@ -5085,9 +5084,6 @@ object Types extends TypeUtils {
50855084
private var myReduced: Type | Null = null
50865085
private var reductionContext: util.MutableMap[Type, Type] | Null = null
50875086

5088-
override def tryNormalize(using Context): Type =
5089-
reduced.normalized
5090-
50915087
private def thisMatchType = this
50925088

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

0 commit comments

Comments
 (0)