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