diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-30 14:18:22 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-30 14:18:22 +0100 |
commit | 904f6c0f756167a1c67e279131b8480f800d94c8 (patch) | |
tree | 6e3b582c570f676233ac3e494f5c5ae15ce30234 /src/dotty | |
parent | dfc1a54b614ad64045bcf35f98c030ab04c9f5f2 (diff) | |
download | dotty-904f6c0f756167a1c67e279131b8480f800d94c8.tar.gz dotty-904f6c0f756167a1c67e279131b8480f800d94c8.tar.bz2 dotty-904f6c0f756167a1c67e279131b8480f800d94c8.zip |
Replacing most occurrences of HashMap with AnyRefMap
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/Main.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Implicits.scala | 31 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 30 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/FreshNameCreator.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/io/ClassPath.scala | 4 |
7 files changed, 43 insertions, 31 deletions
diff --git a/src/dotty/tools/dotc/Main.scala b/src/dotty/tools/dotc/Main.scala index a86422f52..8da5acf60 100644 --- a/src/dotty/tools/dotc/Main.scala +++ b/src/dotty/tools/dotc/Main.scala @@ -13,6 +13,7 @@ import reporting.Reporter * - review isSubType * - have a second look at normalization (leave at method types if pt is method type?) * - Don't open package objects from class files if they are present in source + * - check why we cannot access java.util.LinkedHashMap as a map * - Revise the way classes are inherited - when not followed by [...] or (...), * assume the unparameterized type and forward type parameters as we do now for the synthetic head class. */ diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 99f396e8b..0202a641b 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -399,7 +399,7 @@ object Contexts { private[core] var classOfId = new Array[TypeRef](InitialSuperIdsSize) /** A map from a the typeref of a class to its superclass id */ - private[core] val superIdOfClass = new mutable.HashMap[TypeRef, Int] + private[core] val superIdOfClass = new mutable.AnyRefMap[TypeRef, Int] /** The last allocated superclass id */ private[core] var lastSuperId = -1 diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 1684b23f3..17d4e874a 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -155,10 +155,10 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: private val entries = new Array[AnyRef](index.length) /** A map from symbols to their associated `decls` scopes */ - private val symScopes = mutable.HashMap[Symbol, Scope]() + private val symScopes = mutable.AnyRefMap[Symbol, Scope]() /** A map from refinement classes to their associated refinement types */ - private val refinementTypes = mutable.HashMap[Symbol, RefinedType]() + private val refinementTypes = mutable.AnyRefMap[Symbol, RefinedType]() protected def errorBadSignature(msg: String, original: Option[RuntimeException] = None) = { val ex = new BadSignature( diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index 5dc7c3c93..776d2ec9b 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -86,23 +86,24 @@ object Implicits { * @param outerCtx the next outer context that makes visible further implicits */ class ContextualImplicits(val refs: List[TermRef], val outerCtx: Context)(initctx: Context) extends ImplicitRefs(initctx) { - private val eligibleCache = new mutable.LinkedHashMap[Type, List[TermRef]] + private val eligibleCache = new mutable.AnyRefMap[Type, List[TermRef]] /** The implicit references that are eligible for type `tp`. */ def eligible(tp: Type): List[TermRef] = /*>|>*/ track(s"eligible in ctx") /*<|<*/ { if (tp.hash == NotCached) computeEligible(tp) - else { - eligibleCache get tp match { - case Some(_) => - def elided(ci: ContextualImplicits): Int = { - val n = ci.refs.length - if (ci.outerCtx == NoContext) n - else n + elided(ci.outerCtx.implicits) - } - record(s"elided eligible refs", elided(this)) - case None => - } - eligibleCache.getOrElseUpdate(tp, computeEligible(tp)) + else eligibleCache get tp match { + case Some(eligibles) => + def elided(ci: ContextualImplicits): Int = { + val n = ci.refs.length + if (ci.outerCtx == NoContext) n + else n + elided(ci.outerCtx.implicits) + } + if (monitored) record(s"elided eligible refs", elided(this)) + eligibles + case None => + val eligibles = computeEligible(tp) + eligibleCache(tp) = eligibles + eligibles } } @@ -195,7 +196,7 @@ import Implicits._ /** Info relating to implicits that is kept for one run */ trait ImplicitRunInfo { self: RunInfo => - private val implicitScopeCache = mutable.HashMap[Type, OfTypeImplicits]() + private val implicitScopeCache = mutable.AnyRefMap[Type, OfTypeImplicits]() /** The implicit scope of a type `tp` * @param liftingCtx A context to be used when computing the class symbols of @@ -564,7 +565,7 @@ class SearchHistory(val searchDepth: Int, val seen: Map[ClassSymbol, Int]) { /** A set of term references where equality is =:= */ class TermRefSet(implicit ctx: Context) extends mutable.Traversable[TermRef] { - private val elems = new mutable.LinkedHashMap[TermSymbol, List[Type]] + private val elems = new mutable.LinkedHashMap[TermSymbol, List[Type]] // todo: change to j.u.LinkedHashMap? def += (ref: TermRef): Unit = { val pre = ref.prefix diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 4dd400792..8e0b44b05 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -99,21 +99,21 @@ class Namer { typer: Typer => /** A partial map from unexpanded member and pattern defs and to their expansions. * Populated during enterSyms, emptied during typer. */ - lazy val expandedTree = new mutable.HashMap[DefTree, Tree] { - override def default(tree: DefTree) = tree - } + lazy val expandedTree = new mutable.AnyRefMap[DefTree, Tree] /*{ + override def default(tree: DefTree) = tree // can't have defaults on AnyRefMaps :-( + }*/ /** A map from expanded MemberDef, PatDef or Import trees to their symbols. * Populated during enterSyms, emptied at the point a typed tree * with the same symbol is created (this can be when the symbol is completed * or at the latest when the tree is typechecked. */ - lazy val symOfTree = new mutable.HashMap[Tree, Symbol] + lazy val symOfTree = new mutable.AnyRefMap[Tree, Symbol] /** A map from expanded trees to their typed versions. * Populated when trees are typechecked during completion (using method typedAhead). */ - lazy val typedTree = new mutable.HashMap[Tree, tpd.Tree] + lazy val typedTree = new mutable.AnyRefMap[Tree, tpd.Tree] /** A map from method symbols to nested typers. * Populated when methods are completed. Emptied when they are typechecked. @@ -121,7 +121,7 @@ class Namer { typer: Typer => * one, so that trees that are shared between different DefDefs can be independently * used as indices. It also contains a scope that contains nested parameters. */ - lazy val nestedTyper = new mutable.HashMap[Symbol, Typer] + lazy val nestedTyper = new mutable.AnyRefMap[Symbol, Typer] /** The scope of the typer. * For nested typers this is a place parameters are entered during completion @@ -246,7 +246,7 @@ class Namer { typer: Typer => /** The expanded version of this tree, or tree itself if not expanded */ def expanded(tree: Tree)(implicit ctx: Context): Tree = tree match { - case ddef: DefTree => expandedTree(ddef) + case ddef: DefTree => expandedTree.getOrElse(ddef, ddef) case _ => tree } @@ -326,7 +326,7 @@ class Namer { typer: Typer => classDef get name.toTypeName match { case Some(cdef) => val Thicket(vdef :: (mcls @ TypeDef(_, _, impl: Template)) :: Nil) = expandedTree(mdef) - expandedTree(cdef) match { + expandedTree.getOrElse(cdef, cdef) match { case Thicket(cls :: mval :: TypeDef(_, _, compimpl: Template) :: crest) => val mcls1 = cpy.TypeDef(mcls, mcls.mods, mcls.name, cpy.Template(impl, impl.constr, impl.parents, impl.self, @@ -435,8 +435,18 @@ class Namer { typer: Typer => } /** Typecheck tree during completion, and remember result in typedtree map */ - private def typedAheadImpl(tree: Tree, pt: Type)(implicit ctx: Context): tpd.Tree = - typedTree.getOrElseUpdate(expanded(tree), typer.typed(tree, pt)) + private def typedAheadImpl(tree: Tree, pt: Type)(implicit ctx: Context): tpd.Tree = { + val xtree = expanded(tree) + typedTree.get(xtree) match { + case Some(ttree) => ttree + case none => + val ttree = typer.typed(tree, pt) + typedTree(xtree) = ttree + ttree + } + // was: typedTree.getOrElseUpdate(expanded(tree), typer.typed(tree, pt)) + // but this fails for AnyRefMap with an ArrayIndexOutOfBounds exception in getOrElseUpdate + } def typedAheadType(tree: Tree, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree = typedAheadImpl(tree, pt)(ctx retractMode Mode.PatternOrType addMode Mode.Type) diff --git a/src/dotty/tools/dotc/util/FreshNameCreator.scala b/src/dotty/tools/dotc/util/FreshNameCreator.scala index ff9f68290..521947895 100644 --- a/src/dotty/tools/dotc/util/FreshNameCreator.scala +++ b/src/dotty/tools/dotc/util/FreshNameCreator.scala @@ -16,7 +16,7 @@ trait FreshNameCreator { object FreshNameCreator { class Default extends FreshNameCreator { protected var counter = 0 - protected val counters = mutable.HashMap[String, Int]() withDefaultValue 0 + protected val counters = mutable.AnyRefMap[String, Int]() withDefaultValue 0 /** * Create a fresh name with the given prefix. It is guaranteed diff --git a/src/dotty/tools/io/ClassPath.scala b/src/dotty/tools/io/ClassPath.scala index 749fae847..055ee9f88 100644 --- a/src/dotty/tools/io/ClassPath.scala +++ b/src/dotty/tools/io/ClassPath.scala @@ -339,7 +339,7 @@ extends ClassPath { lazy val classes: IndexedSeq[AnyClassRep] = { var count = 0 - val indices = mutable.HashMap[String, Int]() + val indices = mutable.AnyRefMap[String, Int]() val cls = new mutable.ArrayBuffer[AnyClassRep](1024) for (e <- entries; c <- e.classes) { @@ -364,7 +364,7 @@ extends ClassPath { lazy val packages: IndexedSeq[ClassPath] = { var count = 0 - val indices = mutable.HashMap[String, Int]() + val indices = mutable.AnyRefMap[String, Int]() val pkg = new mutable.ArrayBuffer[ClassPath](256) for (e <- entries; p <- e.packages) { |