@@ -5100,7 +5100,7 @@ object Types extends TypeUtils {
5100
5100
def underlying (using Context ): Type = bound
5101
5101
5102
5102
private var myReduced : Type | Null = null
5103
- private var reductionContext : util.MutableMap [Type , Type ] = uninitialized
5103
+ private var reductionContext : util.MutableMap [Type , Type ] | Null = null
5104
5104
5105
5105
override def tryNormalize (using Context ): Type =
5106
5106
try
@@ -5125,10 +5125,6 @@ object Types extends TypeUtils {
5125
5125
tp.underlying
5126
5126
}
5127
5127
5128
- def isUpToDate : Boolean =
5129
- reductionContext.keysIterator.forall: tp =>
5130
- reductionContext(tp) `eq` contextInfo(tp)
5131
-
5132
5128
def setReductionContext (): Unit =
5133
5129
new TypeTraverser :
5134
5130
var footprint : Set [Type ] = Set ()
@@ -5159,44 +5155,46 @@ object Types extends TypeUtils {
5159
5155
cases.foreach(traverse)
5160
5156
reductionContext = util.HashMap ()
5161
5157
for tp <- footprint do
5162
- reductionContext(tp) = contextInfo(tp)
5158
+ reductionContext.nn (tp) = contextInfo(tp)
5163
5159
matchTypes.println(i " footprint for $thisMatchType $hashCode: ${footprint.toList.map(x => (x, contextInfo(x)))}%, % " )
5164
5160
end setReductionContext
5165
5161
5162
+ def changedReductionContext (): Boolean =
5163
+ val isUpToDate = reductionContext != null && reductionContext.nn.iterator.forall(contextInfo(_) `eq` _)
5164
+ if ! isUpToDate then setReductionContext()
5165
+ ! isUpToDate
5166
+
5166
5167
record(" MatchType.reduce called" )
5167
5168
if ! Config .cacheMatchReduced
5168
5169
|| myReduced == null
5169
- || ! isUpToDate
5170
+ || changedReductionContext()
5170
5171
|| MatchTypeTrace .isRecording
5171
5172
then
5172
5173
record(" MatchType.reduce computed" )
5173
5174
if (myReduced != null ) record(" MatchType.reduce cache miss" )
5174
- myReduced =
5175
- trace(i " reduce match type $this $hashCode" , matchTypes, show = true ):
5175
+ val saved = ctx.typerState.snapshot()
5176
+ try
5177
+ myReduced = trace(i " reduce match type $this $hashCode" , matchTypes, show = true ):
5176
5178
withMode(Mode .Type ):
5177
- setReductionContext()
5178
- def matchCases (cmp : MatchReducer ): Type =
5179
- val saved = ctx.typerState.snapshot()
5180
- try
5181
- cmp.matchCases(scrutinee.normalized, cases.map(MatchTypeCaseSpec .analyze(_)))
5182
- catch case ex : Throwable =>
5183
- handleRecursive(" reduce type " , i " $scrutinee match ... " , ex)
5184
- finally
5185
- ctx.typerState.resetTo(saved)
5186
- // this drops caseLambdas in constraint and undoes any typevar
5187
- // instantiations during matchtype reduction
5188
- TypeComparer .reduceMatchWith(matchCases)
5179
+ TypeComparer .reduceMatchWith: cmp =>
5180
+ cmp.matchCases(scrutinee.normalized, cases.map(MatchTypeCaseSpec .analyze))
5181
+ catch case ex : Throwable =>
5182
+ myReduced = NoType
5183
+ handleRecursive(" reduce type " , i " $scrutinee match ... " , ex)
5184
+ finally
5185
+ ctx.typerState.resetTo(saved)
5186
+ // this drops caseLambdas in constraint and undoes any typevar
5187
+ // instantiations during matchtype reduction
5189
5188
5190
5189
// else println(i"no change for $this $hashCode / $myReduced")
5191
5190
myReduced.nn
5192
5191
}
5193
5192
5194
5193
/** True if the reduction uses GADT constraints. */
5195
5194
def reducesUsingGadt (using Context ): Boolean =
5196
- (reductionContext ne null ) && reductionContext.keysIterator.exists {
5197
- case tp : TypeRef => reductionContext(tp).exists
5198
- case _ => false
5199
- }
5195
+ reductionContext != null && reductionContext.nn.iterator.exists:
5196
+ case (tp : TypeRef , tpCtx) => tpCtx.exists
5197
+ case _ => false
5200
5198
5201
5199
override def computeHash (bs : Binders ): Int = doHash(bs, scrutinee, bound :: cases)
5202
5200
0 commit comments