@@ -5003,6 +5003,8 @@ object Types extends TypeUtils {
5003
5003
case ex : Throwable =>
5004
5004
handleRecursive(" normalizing" , s " ${scrutinee.show} match ... " , ex)
5005
5005
5006
+ private def thisMatchType = this
5007
+
5006
5008
def reduced (using Context ): Type = {
5007
5009
5008
5010
def contextInfo (tp : Type ): Type = tp match {
@@ -5021,12 +5023,44 @@ object Types extends TypeUtils {
5021
5023
reductionContext = util.HashMap ()
5022
5024
for (tp <- footprint)
5023
5025
reductionContext(tp) = contextInfo(tp)
5024
- typr .println(i " footprint for $this $hashCode: ${footprint.toList.map(x => (x, contextInfo(x)))}%, % " )
5026
+ matchTypes .println(i " footprint for $this $hashCode: ${footprint.toList.map(x => (x, contextInfo(x)))}%, % " )
5025
5027
5026
5028
def isUpToDate : Boolean =
5027
- reductionContext.keysIterator.forall { tp =>
5029
+ reductionContext.keysIterator.forall: tp =>
5028
5030
reductionContext(tp) `eq` contextInfo(tp)
5029
- }
5031
+
5032
+ def computeFootprint (): Unit =
5033
+ new TypeTraverser :
5034
+ var footprint : Set [Type ] = Set ()
5035
+ var deep : Boolean = true
5036
+ val seen = util.HashSet [Type ]()
5037
+ def traverse (tp : Type ) =
5038
+ if ! seen.contains(tp) then
5039
+ seen += tp
5040
+ tp match
5041
+ case tp : NamedType =>
5042
+ if tp.symbol.is(TypeParam ) then footprint += tp
5043
+ traverseChildren(tp)
5044
+ case _ : AppliedType | _ : RefinedType =>
5045
+ if deep then traverseChildren(tp)
5046
+ case TypeBounds (lo, hi) =>
5047
+ traverse(hi)
5048
+ case tp : TypeVar =>
5049
+ footprint += tp
5050
+ traverse(tp.underlying)
5051
+ case tp : TypeParamRef =>
5052
+ footprint += tp
5053
+ case _ =>
5054
+ traverseChildren(tp)
5055
+ end traverse
5056
+
5057
+ traverse(scrutinee)
5058
+ deep = false
5059
+ cases.foreach(traverse)
5060
+ reductionContext = util.HashMap ()
5061
+ for tp <- footprint do
5062
+ reductionContext(tp) = contextInfo(tp)
5063
+ matchTypes.println(i " footprint for $thisMatchType $hashCode: ${footprint.toList.map(x => (x, contextInfo(x)))}%, % " )
5030
5064
5031
5065
record(" MatchType.reduce called" )
5032
5066
if ! Config .cacheMatchReduced
@@ -5038,19 +5072,21 @@ object Types extends TypeUtils {
5038
5072
if (myReduced != null ) record(" MatchType.reduce cache miss" )
5039
5073
myReduced =
5040
5074
trace(i " reduce match type $this $hashCode" , matchTypes, show = true )(inMode(Mode .Type ) {
5075
+ computeFootprint()
5041
5076
def matchCases (cmp : TrackingTypeComparer ): Type =
5042
5077
val saved = ctx.typerState.snapshot()
5043
5078
try cmp.matchCases(scrutinee.normalized, cases.map(MatchTypeCaseSpec .analyze(_)))
5044
5079
catch case ex : Throwable =>
5045
5080
handleRecursive(" reduce type " , i " $scrutinee match ... " , ex)
5046
5081
finally
5047
- updateReductionContext(cmp.footprint)
5082
+ // updateReductionContext(cmp.footprint)
5048
5083
ctx.typerState.resetTo(saved)
5049
5084
// this drops caseLambdas in constraint and undoes any typevar
5050
5085
// instantiations during matchtype reduction
5051
5086
5052
5087
TypeComparer .tracked(matchCases)
5053
5088
})
5089
+ // else println(i"no change for $this $hashCode / $myReduced")
5054
5090
myReduced.nn
5055
5091
}
5056
5092
0 commit comments