Skip to content

Commit 0b87d7f

Browse files
Regroup tryNormalize logic
1 parent 309b1cf commit 0b87d7f

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

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

+15-19
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,6 @@ object Types extends TypeUtils {
491491
/** Does this application expand to a match type? */
492492
def isMatchAlias(using Context): Boolean = underlyingNormalizable.isMatch
493493

494-
def underlyingNormalizable(using Context): Type = stripped.stripLazyRef match
495-
case tp: MatchType => tp
496-
case tp: AppliedType => tp.underlyingNormalizable
497-
case _ => NoType
498-
499494
/** Is this a higher-kinded type lambda with given parameter variances?
500495
* These lambdas are used as the RHS of higher-kinded abstract types or
501496
* type aliases. The variance info is strictly needed only for abstract types.
@@ -1547,22 +1542,25 @@ object Types extends TypeUtils {
15471542
}
15481543
deskolemizer(this)
15491544

1550-
/** The result of normalization using `tryNormalize`, or the type itself if
1551-
* tryNormlize yields NoType
1552-
*/
1553-
final def normalized(using Context): Type = {
1554-
val normed = tryNormalize
1555-
if (normed.exists) normed else this
1556-
}
1545+
/** The result of normalization, or the type itself if none apply. */
1546+
final def normalized(using Context): Type = tryNormalize.orElse(this)
15571547

15581548
/** If this type has an underlying match type or applied compiletime.ops,
15591549
* then the result after applying all toplevel normalizations, otherwise NoType.
15601550
*/
15611551
def tryNormalize(using Context): Type = underlyingNormalizable match
1562-
case mt: MatchType => mt.tryNormalize
1552+
case mt: MatchType => mt.reduced.normalized
15631553
case tp: AppliedType => tp.tryCompiletimeConstantFold
15641554
case _ => NoType
15651555

1556+
/** Perform successive strippings, and beta-reductions of applied types until
1557+
* a match type or applied compiletime.ops is reached, if any, otherwise NoType.
1558+
*/
1559+
def underlyingNormalizable(using Context): Type = stripped.stripLazyRef match
1560+
case tp: MatchType => tp
1561+
case tp: AppliedType => tp.underlyingNormalizable
1562+
case _ => NoType
1563+
15661564
private def widenDealias1(keep: AnnotatedType => Context ?=> Boolean)(using Context): Type = {
15671565
val res = this.widen.dealias1(keep, keepOpaques = false)
15681566
if (res eq this) res else res.widenDealias1(keep)
@@ -4677,9 +4675,10 @@ object Types extends TypeUtils {
46774675
case nil => x
46784676
foldArgs(op(x, tycon), args)
46794677

4680-
/** Exists if the tycon is a TypeRef of an alias with an underlying match type.
4681-
* Anything else should have already been reduced in `appliedTo` by the TypeAssigner.
4682-
* May reduce several HKTypeLambda applications before the underlying MatchType is reached.
4678+
/** Exists if the tycon is a TypeRef of an alias with an underlying match type,
4679+
* or a compiletime applied type. Anything else should have already been
4680+
* reduced in `appliedTo` by the TypeAssigner. This may reduce several
4681+
* HKTypeLambda applications before the underlying normalizable type is reached.
46834682
*/
46844683
override def underlyingNormalizable(using Context): Type =
46854684
if ctx.period != validUnderlyingNormalizable then tycon match
@@ -5157,9 +5156,6 @@ object Types extends TypeUtils {
51575156
private var myReduced: Type | Null = null
51585157
private var reductionContext: util.MutableMap[Type, Type] | Null = null
51595158

5160-
override def tryNormalize(using Context): Type =
5161-
reduced.normalized
5162-
51635159
private def thisMatchType = this
51645160

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

0 commit comments

Comments
 (0)