Skip to content

Commit e9df00a

Browse files
EugeneFlesselleWojciechMazur
authored andcommitted
Regroup tryNormalize logic
[Cherry-picked 0b87d7f]
1 parent 0b6900e commit e9df00a

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
@@ -492,11 +492,6 @@ object Types extends TypeUtils {
492492
/** Does this application expand to a match type? */
493493
def isMatchAlias(using Context): Boolean = underlyingNormalizable.isMatch
494494

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)