Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline tryNormalize with underlyingMatchType #20268

Merged
merged 10 commits into from
Jul 5, 2024
Prev Previous commit
Next Next commit
Use underlyingNormalizable in Type#tryNormalize
  • Loading branch information
EugeneFlesselle committed Jun 28, 2024
commit a6cadec56e92412b2866895f6fbfc6149193f32b
21 changes: 9 additions & 12 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1555,11 +1555,13 @@ object Types extends TypeUtils {
if (normed.exists) normed else this
}

/** If this type can be normalized at the top-level by rewriting match types
* of S[n] types, the result after applying all toplevel normalizations,
* otherwise NoType
/** If this type has an underlying match type or applied compiletime.ops,
* then the result after applying all toplevel normalizations, otherwise NoType.
*/
def tryNormalize(using Context): Type = NoType
def tryNormalize(using Context): Type = underlyingNormalizable match
case mt: MatchType => mt.tryNormalize
case tp: AppliedType => tp.tryCompiletimeConstantFold
case _ => NoType

private def widenDealias1(keep: AnnotatedType => Context ?=> Boolean)(using Context): Type = {
val res = this.widen.dealias1(keep, keepOpaques = false)
Expand Down Expand Up @@ -4692,14 +4694,9 @@ object Types extends TypeUtils {
cachedUnderlyingNormalizable

override def tryNormalize(using Context): Type =
def tryMatchAlias =
if isMatchAlias then trace(i"normalize $this", typr, show = true):
if MatchTypeTrace.isRecording then
MatchTypeTrace.recurseWith(this)(superType.tryNormalize)
else
underlyingNormalizable.tryNormalize
else NoType
tryCompiletimeConstantFold.orElse(tryMatchAlias)
if isMatchAlias && MatchTypeTrace.isRecording then
MatchTypeTrace.recurseWith(this)(superType.tryNormalize)
else super.tryNormalize

/** Is this an unreducible application to wildcard arguments?
* This is the case if tycon is higher-kinded. This means
Expand Down