Skip to content

Commit ac2ec4f

Browse files
committed
GC type lambdas that are not referenced from PolyTypes
In typerState,gc(), drop all type lambdas which are not referenced from normal PolyTypes.
1 parent f810de3 commit ac2ec4f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,30 @@ extends TyperState(r) {
140140
}
141141
for (poly <- toCollect)
142142
constraint = constraint.remove(poly)
143+
144+
lazy val keptLambdas: collection.Set[TypeLambda] = {
145+
val toKeep = mutable.Set.empty[TypeLambda]
146+
def keep(p: PolyParam) = p.binder match {
147+
case tl: TypeLambda => toKeep += tl
148+
case _ =>
149+
}
150+
for (poly <- constraint.domainPolys)
151+
if (poly.isInstanceOf[PolyType])
152+
for (param <- poly.paramRefs) {
153+
constraint.lower(param).foreach(keep)
154+
constraint.upper(param).foreach(keep)
155+
constraint.entry(param).foreachPart {
156+
case p: PolyParam if constraint contains p => keep(p)
157+
case _ =>
158+
}
159+
}
160+
toKeep
161+
}
162+
constraint.domainPolys.foreach {
163+
case tl: TypeLambda if !keptLambdas.contains(tl) =>
164+
constraint = constraint.remove(tl)
165+
case _ =>
166+
}
143167
}
144168

145169
/** Try operation `op`; if it produces errors, execute `fallback` with constraint and

0 commit comments

Comments
 (0)