aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-08-13 09:47:11 +0200
committerMartin Odersky <odersky@gmail.com>2013-08-13 09:47:11 +0200
commit606df6573f0d0323ba58d06e8af3c1aaf844b708 (patch)
treec6e8e55b7ccc758ecb21e6a59948e65014d53e74
parent401d2012f4c99b170dec99c1f7c4251dda0b20fd (diff)
downloaddotty-606df6573f0d0323ba58d06e8af3c1aaf844b708.tar.gz
dotty-606df6573f0d0323ba58d06e8af3c1aaf844b708.tar.bz2
dotty-606df6573f0d0323ba58d06e8af3c1aaf844b708.zip
Fixing validity checking of denotations.
To get this to work, we need to store the name of a scope netry irectly in the entry. This is arguably the right model anyway. A symbol can have different denotations with different names, and it might exist under different names in different scopes. In the previous model once a symbol's name changed in some phase, all scopes referring to that symbol from previous phases would become invalid. Now, the symbol is still visible under its original name.
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala9
-rw-r--r--src/dotty/tools/dotc/core/Scopes.scala16
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala3
3 files changed, 14 insertions, 14 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index 8b5dcc5dc..e551c8af2 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -454,11 +454,10 @@ object Denotations {
def current(implicit ctx: Context): SingleDenotation = {
val currentPeriod = ctx.period
val valid = myValidFor
- def stillValid(denot: SymDenotation) =
- !denot.exists || {
- val top = denot.topLevelSym
- top.owner.info.decl(top.name).symbol eq top
- }
+ def stillValid(denot: SymDenotation): Boolean =
+ if (!denot.exists || (denot.flags is PackageClass)) true
+ else if (denot.owner is PackageClass) denot.owner.decls.lookup(denot.name) eq symbol
+ else stillValid(denot.owner)
def bringForward(): SingleDenotation = this match {
case denot: SymDenotation if stillValid(denot) =>
var d: SingleDenotation = denot
diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala
index b622af6ac..3748801b9 100644
--- a/src/dotty/tools/dotc/core/Scopes.scala
+++ b/src/dotty/tools/dotc/core/Scopes.scala
@@ -33,7 +33,7 @@ object Scopes {
*/
private final val MaxRecursions = 1000
- class ScopeEntry private[Scopes] (val sym: Symbol, val owner: Scope) {
+ class ScopeEntry private[Scopes] (val name: Name, val sym: Symbol, val owner: Scope) {
/** the next entry in the hash bucket
*/
@@ -153,7 +153,7 @@ object Scopes {
/** create and enter a scope entry */
protected def newScopeEntry(sym: Symbol)(implicit ctx: Context): ScopeEntry = {
ensureCapacity(if (hashTable ne null) hashTable.length else MinHash)
- val e = new ScopeEntry(sym, this)
+ val e = new ScopeEntry(sym.name, sym, this)
e.prev = lastEntry
lastEntry = e
if (hashTable ne null) enterInHash(e)
@@ -163,7 +163,7 @@ object Scopes {
}
private def enterInHash(e: ScopeEntry)(implicit ctx: Context): Unit = {
- val idx = e.sym.name.hashCode & (hashTable.length - 1)
+ val idx = e.name.hashCode & (hashTable.length - 1)
e.tail = hashTable(idx)
assert(e.tail != e)
hashTable(idx) = e
@@ -222,7 +222,7 @@ object Scopes {
e1.prev = e.prev
}
if (hashTable ne null) {
- val index = e.sym.name.hashCode & (hashTable.length - 1)
+ val index = e.name.hashCode & (hashTable.length - 1)
var e1 = hashTable(index)
if (e1 == e)
hashTable(index) = e.tail
@@ -250,12 +250,12 @@ object Scopes {
var e: ScopeEntry = null
if (hashTable ne null) {
e = hashTable(name.hashCode & (hashTable.length - 1))
- while ((e ne null) && e.sym.name != name) {
+ while ((e ne null) && e.name != name) {
e = e.tail
}
} else {
e = lastEntry
- while ((e ne null) && e.sym.name != name) {
+ while ((e ne null) && e.name != name) {
e = e.prev
}
}
@@ -266,9 +266,9 @@ object Scopes {
override final def lookupNextEntry(entry: ScopeEntry)(implicit ctx: Context): ScopeEntry = {
var e = entry
if (hashTable ne null)
- do { e = e.tail } while ((e ne null) && e.sym.name != entry.sym.name)
+ do { e = e.tail } while ((e ne null) && e.name != entry.name)
else
- do { e = e.prev } while ((e ne null) && e.sym.name != entry.sym.name)
+ do { e = e.prev } while ((e ne null) && e.name != entry.name)
e
}
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index d2be45444..a3f83da47 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -494,7 +494,8 @@ object SymDenotations {
/** The top-level symbol containing this denotation. */
final def topLevelSym(implicit ctx: Context): Symbol =
- if (owner is PackageClass) symbol else owner.topLevelSym
+ if ((this is PackageClass) || (owner is PackageClass)) symbol
+ else owner.topLevelSym
/** The package containing this denotation */
final def enclosingPackage(implicit ctx: Context): Symbol =