summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-06-13 15:09:46 +0000
committerMartin Odersky <odersky@gmail.com>2007-06-13 15:09:46 +0000
commit2140a3b04a8e07592d8fe1792c323cef16afe704 (patch)
treeaf55d61cd53c3f55632938f59677918142cccc44
parentfc5d8ffdb08bd6fff8de51885194d449a3a34019 (diff)
downloadscala-2140a3b04a8e07592d8fe1792c323cef16afe704.tar.gz
scala-2140a3b04a8e07592d8fe1792c323cef16afe704.tar.bz2
scala-2140a3b04a8e07592d8fe1792c323cef16afe704.zip
rehash symbols if their names change
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Scopes.scala31
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala13
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala2
3 files changed, 42 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala
index 3cb50c09ab..abf977fd3d 100644
--- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala
@@ -157,7 +157,7 @@ trait Scopes {
enter(sym)
}
- def createHash() {
+ private def createHash(): unit = {
hashtable = new Array[ScopeEntry](HASHSIZE)
enterInHash(elems)
}
@@ -171,6 +171,30 @@ trait Scopes {
}
}
+ def rehash(sym: Symbol, newname: Name): unit =
+ if (hashtable ne null) {
+ val index = sym.name.start & HASHMASK
+ var e1 = hashtable(index)
+ var e: ScopeEntry = null
+ if (e1 != null) {
+ if (e1.sym == sym) {
+ hashtable(index) = e1.tail
+ e = e1
+ } else {
+ while (e1.tail != null && e1.tail.sym != sym) e1 = e1.tail
+ if (e1.tail != null) {
+ e = e1.tail
+ e1.tail = e.tail
+ }
+ }
+ }
+ if (e != null) {
+ val newindex = newname.start & HASHMASK
+ e.tail = hashtable(newindex)
+ hashtable(newindex) = e
+ }
+ }
+
/** remove entry
*
* @param e ...
@@ -184,9 +208,10 @@ trait Scopes {
e1.next = e.next
}
if (hashtable ne null) {
- var e1 = hashtable(e.sym.name.start & HASHMASK)
+ val index = e.sym.name.start & HASHMASK
+ var e1 = hashtable(index)
if (e1 == e) {
- hashtable(e.sym.name.start & HASHMASK) = e.tail
+ hashtable(index) = e.tail
} else {
while (e1.tail != e) e1 = e1.tail;
e1.tail = e.tail
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index cca6ba2b46..6c108ca709 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -363,7 +363,18 @@ trait Symbols {
def name: Name = rawname
- final def name_=(name: Name) { rawname = name }
+ final def name_=(name: Name) {
+ if (name != rawname) {
+ if (owner.isClass) {
+ var ifs = owner.infos
+ while (ifs != null) {
+ ifs.info.decls.rehash(this, name)
+ ifs = ifs.prev
+ }
+ }
+ rawname = name
+ }
+ }
/** If this symbol has an expanded name, its original name, otherwise its name itself.
* @see expandName
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 40eaef0f6f..3a15c2e77b 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -2352,12 +2352,14 @@ A type's symbol should never be inspected directly.
sym
} else {
var rebind0 = pre.findMember(sym.name, BRIDGE, 0, true)
+/*
if (rebind0 == NoSymbol && (sym hasFlag EXPANDEDNAME)) {
// problem is that symbols with expanded names might be in the wrong hash bucket
// in a previous scope. We account for that by re-creating the hash as a last attempt.
sym.owner.info.decls.createHash()
rebind0 = pre.findMember(sym.name, BRIDGE, 0, true)
}
+*/
if (rebind0 == NoSymbol) { assert(false, ""+pre+"."+sym+" does no longer exist, phase = "+phase) }
/** The two symbols have the same fully qualified name */
def corresponds(sym1: Symbol, sym2: Symbol): Boolean =