Permalink
Browse files

SI-7149 Use a WeakHashSet for type uniqueness

Currently type uniqueness is done via a HashSet[Type], but
that means the Types live through an entire compile session, even
ones that are used once. The result is a huge amount of unnecessarily
retained memory. This commit uses a WeakHashSet instead so that Types
and their WeakReferences are cleaned up when no longer in use.
  • Loading branch information...
1 parent 3ada703 commit 989c3f85d95a22c95bc7ce936c4bd57ff0608bcd @gkossakowski gkossakowski committed Sep 4, 2013
@@ -279,6 +279,30 @@ filter {
{
matchName="scala.reflect.internal.util.WeakReferenceWithEquals"
problemName=MissingClassProblem
+ },
+ {
+ matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques"
+ problemName=IncompatibleResultTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques_="
+ problemName=IncompatibleMethTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques"
+ problemName=IncompatibleResultTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_="
+ problemName=IncompatibleMethTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques"
+ problemName=MissingMethodProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_="
+ problemName=MissingMethodProblem
}
]
}
@@ -1383,6 +1383,30 @@ filter {
{
matchName="scala.reflect.internal.util.WeakHashSet.reduceOption"
problemName=MissingMethodProblem
+ },
+ {
+ matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques"
+ problemName=IncompatibleResultTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.SymbolTable.scala$reflect$internal$Types$$uniques_="
+ problemName=IncompatibleMethTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques"
+ problemName=IncompatibleResultTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_="
+ problemName=IncompatibleMethTypeProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques"
+ problemName=MissingMethodProblem
+ },
+ {
+ matchName="scala.reflect.internal.Types.scala$reflect$internal$Types$$uniques_="
+ problemName=MissingMethodProblem
}
]
}
@@ -3935,13 +3935,13 @@ trait Types extends api.Types { self: SymbolTable =>
// Hash consing --------------------------------------------------------------
private val initialUniquesCapacity = 4096
- private var uniques: util.HashSet[Type] = _
+ private var uniques: util.WeakHashSet[Type] = _
private var uniqueRunId = NoRunId
protected def unique[T <: Type](tp: T): T = {
if (Statistics.canEnable) Statistics.incCounter(rawTypeCount)
if (uniqueRunId != currentRunId) {
- uniques = util.HashSet[Type]("uniques", initialUniquesCapacity)
+ uniques = util.WeakHashSet[Type](initialUniquesCapacity)
perRunCaches.recordCache(uniques)
uniqueRunId = currentRunId
}

0 comments on commit 989c3f8

Please sign in to comment.