Skip to content

Cache myReduced = NoType if match type reduction overflowed #20214

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

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5124,6 +5124,7 @@ object Types extends TypeUtils {
}

def isUpToDate: Boolean =
(reductionContext ne null) &&
reductionContext.keysIterator.forall: tp =>
reductionContext(tp) `eq` contextInfo(tp)

Expand Down Expand Up @@ -5169,21 +5170,20 @@ object Types extends TypeUtils {
then
record("MatchType.reduce computed")
if (myReduced != null) record("MatchType.reduce cache miss")
myReduced =
trace(i"reduce match type $this $hashCode", matchTypes, show = true):
if !isUpToDate then setReductionContext()
val saved = ctx.typerState.snapshot()
try
myReduced = trace(i"reduce match type $this $hashCode", matchTypes, show = true):
withMode(Mode.Type):
setReductionContext()
def matchCases(cmp: MatchReducer): Type =
val saved = ctx.typerState.snapshot()
try
cmp.matchCases(scrutinee.normalized, cases.map(MatchTypeCaseSpec.analyze(_)))
catch case ex: Throwable =>
handleRecursive("reduce type ", i"$scrutinee match ...", ex)
finally
ctx.typerState.resetTo(saved)
// this drops caseLambdas in constraint and undoes any typevar
// instantiations during matchtype reduction
TypeComparer.reduceMatchWith(matchCases)
TypeComparer.reduceMatchWith: cmp =>
cmp.matchCases(scrutinee.normalized, cases.map(MatchTypeCaseSpec.analyze))
catch case ex: Throwable =>
myReduced = NoType
handleRecursive("reduce type ", i"$scrutinee match ...", ex)
finally
ctx.typerState.resetTo(saved)
// this drops caseLambdas in constraint and undoes any typevar
// instantiations during matchtype reduction

//else println(i"no change for $this $hashCode / $myReduced")
myReduced.nn
Expand Down
Loading