aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-30 14:18:22 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-30 14:18:22 +0100
commit904f6c0f756167a1c67e279131b8480f800d94c8 (patch)
tree6e3b582c570f676233ac3e494f5c5ae15ce30234 /src/dotty/tools/dotc/typer/Namer.scala
parentdfc1a54b614ad64045bcf35f98c030ab04c9f5f2 (diff)
downloaddotty-904f6c0f756167a1c67e279131b8480f800d94c8.tar.gz
dotty-904f6c0f756167a1c67e279131b8480f800d94c8.tar.bz2
dotty-904f6c0f756167a1c67e279131b8480f800d94c8.zip
Replacing most occurrences of HashMap with AnyRefMap
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala30
1 files changed, 20 insertions, 10 deletions
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)