diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2011-01-10 11:52:18 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2011-01-10 11:52:18 +0000 |
commit | b05c8ebc8f7cf3240a2f9e18f1255b5bb64f2ab4 (patch) | |
tree | dc23371aa46a70bb137e3bcd0ac41b7e3ce893a5 /src/compiler | |
parent | b0fecaea9b596b1c1058bffc3eb81f8caaa341e1 (diff) | |
download | scala-b05c8ebc8f7cf3240a2f9e18f1255b5bb64f2ab4.tar.gz scala-b05c8ebc8f7cf3240a2f9e18f1255b5bb64f2ab4.tar.bz2 scala-b05c8ebc8f7cf3240a2f9e18f1255b5bb64f2ab4.zip |
Changing the intersectionWitness map to use wea...
Changing the intersectionWitness map to use weak references for the
value. A value may prevent parts of this map from collecting, since
the value may hold a (strong) reference to one of the keys in the map.
review by odersky.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/interactive/Global.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 13 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 1 |
3 files changed, 9 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 8af350c8b7..99619e3a2f 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -39,6 +39,7 @@ self => else NullLogger import log.logreplay + debugLog("logger: " + log.getClass + " writing to " + (new java.io.File(logName)).getAbsolutePath) /** Print msg only when debugIDE is true. */ @inline final def debugLog(msg: => String) = diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index ef45834ab7..e3fb82385b 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -8,6 +8,7 @@ package symtab import scala.collection.{ mutable, immutable } import scala.collection.mutable.ListBuffer +import scala.ref.WeakReference import ast.TreeGen import util.{ Position, NoPosition } import util.Statistics._ @@ -150,7 +151,7 @@ trait Types extends reflect.generic.Types { self: SymbolTable => * It makes use of the fact that these two operations depend only on the parents, * not on the refinement. */ - val intersectionWitness = new mutable.WeakHashMap[List[Type], Type] + val intersectionWitness = new mutable.WeakHashMap[List[Type], WeakReference[Type]] private object gen extends { val global : Types.this.type = Types.this @@ -1341,12 +1342,12 @@ trait Types extends reflect.generic.Types { self: SymbolTable => baseClassesCache } - def memo[A](op1: => A)(op2: Type => A) = intersectionWitness get parents match { - case Some(w) => - if (w eq this) op1 else op2(w) - case none => - intersectionWitness(parents) = this + def memo[A](op1: => A)(op2: Type => A) = { + (for (ref <- intersectionWitness.get(parents); w <- ref.get) + yield if (w eq this) op1 else op2(w)) getOrElse { + intersectionWitness(parents) = new WeakReference(this) op1 + } } override def baseType(sym: Symbol): Type = { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index bcb2767e6f..784531ba1e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -49,6 +49,7 @@ trait Typers extends Modes { resetNamer() resetImplicits() transformed.clear() + //println("%,d entries in intersectionWitness".format(intersectionWitness.size)) } object UnTyper extends Traverser { |