aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala131
-rw-r--r--src/dotty/tools/dotc/core/Referenceds.scala31
-rw-r--r--src/dotty/tools/dotc/core/Types.scala12
3 files changed, 96 insertions, 78 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index 383a46ccd..63f2976b6 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -9,39 +9,25 @@ import collection.immutable.BitSet
object Denotations {
- abstract class Denotation extends SymRefd {
+ /** A denotation represents the contents of a definition
+ * during a period.
+ */
+ abstract class Denotation(initFlags: FlagSet) extends SymRefd {
- def symbol: Symbol = ???
+ def symbol: Symbol
- def owner: Symbol = ???
+ def owner: Symbol
- def name: Name = ???
+ def name: Name
- def flags: FlagSet = ???
+ private[this] var currentFlags: FlagSet = initFlags
- def setFlag(flag: FlagSet): Unit = ???
+ def flags: FlagSet = currentFlags
- def tpe: Type = ???
+ def info: Type
- def info: Type = ???
-
- /* Validity and instance handling:
- *
- * Symbols have an interval of validity, defined
- * by their `valid` fields.
- *
- * There may be several symbols with different validity
- * representing the same underlying symbol at different phases.
- * These are called a "flock". Flock members are generated by
- * @see SymRef.trackSym. Flock members are connected in a ring
- * with their `nextInFlock` fields.
- *
- * There are the following invariants converning flock members
- *
- * 1) validity intervals must be non-overlapping
- * 2) the union of all validity intervals must be a contiguous
- * interval starting in FirstPhaseId.
- */
+ def setFlag(flag: FlagSet): Unit =
+ currentFlags = initFlags
/** is this symbol a class? */
def isClass: Boolean = false
@@ -57,36 +43,28 @@ object Denotations {
override protected def copy(s: Symbol, i: Type): SymRefd = new UniqueSymRefd(s, i, validFor)
}
- object NameFilter {
- final val WordSizeLog = 6
- final val DefinedNamesWords = 16
- final val DefinedNamesSize = DefinedNamesWords << WordSizeLog
- final val DefinedNamesMask = DefinedNamesSize - 1
-
- type FingerPrint = Array[Long]
-
- def includeName(bits: FingerPrint, name: Name): Unit = {
- val hash = name.start & DefinedNamesMask
- bits(hash >> 6) |= (1 << hash)
- }
-
- def includeFingerPrint(bits1: FingerPrint, bits2: FingerPrint): Unit =
- for (i <- 0 until DefinedNamesWords) bits1(i) |= bits2(i)
-
- def containsName(bits: FingerPrint, name: Name): Boolean = {
- val hash = name.start & DefinedNamesMask
- (bits(hash >> 6) & (1 << hash)) != 0
- }
-
- def newNameFilter: FingerPrint = new Array[Long](DefinedNamesWords)
- }
-
- class ClassDenotation(val parents: List[Type], val decls: Scope, val clazz: ClassSymbol) extends Denotation {
+ class NonClassDenotation(
+ override val symbol: Symbol,
+ override val owner: Symbol,
+ override val name: Name,
+ val initFlags: FlagSet,
+ override val info: Type
+ ) extends Denotation(initFlags)
+
+ class ClassDenotation(
+ override val symbol: ClassSymbol,
+ override val owner: Symbol,
+ override val name: Name,
+ val initFlags: FlagSet,
+ val parents: List[Type],
+ val decls: Scope)(implicit ctx: Context) extends Denotation(initFlags) {
import NameFilter._
import util.LRU8Cache
def typeParams: List[TypeSymbol] = ???
+ val info = ClassInfo(owner.thisType, this)
+
private var memberCacheVar: LRU8Cache[Name, ReferencedSet] = null
private def memberCache: LRU8Cache[Name, ReferencedSet] = {
@@ -98,7 +76,7 @@ object Denotations {
def thisType(implicit ctx: Context): Type = {
if (thisTypeCache == null)
- thisTypeCache = ThisType(clazz)
+ thisTypeCache = ThisType(symbol)
thisTypeCache
}
@@ -106,7 +84,7 @@ object Denotations {
def typeConstructor(implicit ctx: Context): Type = {
if (typeConstructorCache == null)
- typeConstructorCache = NamedType(thisType, clazz.name)
+ typeConstructorCache = NamedType(thisType, symbol.name)
typeConstructorCache
}
@@ -129,7 +107,7 @@ object Denotations {
case bc :: bcs1 =>
val id = bc.superId
if (seen contains id) to
- else if (locked contains id) throw new CyclicReference(clazz)
+ else if (locked contains id) throw new CyclicReference(symbol)
else {
locked += id
val bcs1added = addBaseClasses(bcs1, to)
@@ -145,7 +123,7 @@ object Denotations {
case _ =>
to
}
- baseClassesVar = clazz :: addParentBaseClasses(parents, Nil)
+ baseClassesVar = symbol :: addParentBaseClasses(parents, Nil)
superClassBitsVar = ctx.root.uniqueBits.findEntryOrUpdate(seen.toImmutable)
}
@@ -170,7 +148,7 @@ object Denotations {
var bits = newNameFilter
var e = decls.lastEntry
while (e != null) {
- includeName(bits, clazz.name)
+ includeName(bits, name)
e = e.prev
}
var ps = parents
@@ -193,7 +171,7 @@ object Denotations {
* someone does a findMember on a subclass.
*/
def enter(sym: Symbol)(implicit ctx: Context) = {
- require((clazz.flags & Frozen) == Flags.Empty)
+ require(!flags.hasFlagIn(Frozen))
decls enter sym
if (definedFingerPrintCache != null)
includeName(definedFingerPrintCache, sym.name)
@@ -206,7 +184,7 @@ object Denotations {
* someone does a findMember on a subclass.
*/
def delete(sym: Symbol)(implicit ctx: Context) = {
- require((clazz.flags & Frozen) == Flags.Empty)
+ require((flags & Frozen) == Flags.Empty)
decls unlink sym
if (definedFingerPrintCache != null)
computeDefinedFingerPrint
@@ -265,11 +243,11 @@ object Denotations {
case p :: ps1 => reduce(bt & baseTypeOf(p), ps1)
case _ => bt
}
- if (classd.clazz == clazz) tp.typeTemplate
- else reduce(NoType, classd.parents).substThis(classd.clazz, tp.prefix)
+ if (classd.symbol == symbol) tp.typeTemplate
+ else reduce(NoType, classd.parents).substThis(classd.symbol, tp.prefix)
}
- if (clazz.isStaticMono) clazz.typeConstructor
+ if (symbol.isStaticMono) symbol.typeConstructor
else tp match {
case tp: CachedType =>
if (baseTypeValid != ctx.runId) {
@@ -282,7 +260,7 @@ object Denotations {
basetp = computeBaseTypeOf(tp)
baseTypeCache.put(tp, basetp)
} else if (basetp == NoType) {
- throw new CyclicReference(clazz)
+ throw new CyclicReference(symbol)
}
basetp
case _ =>
@@ -306,11 +284,34 @@ object Denotations {
}
}
- object NoDenotation extends Denotation {
+ object NoDenotation extends Denotation(Flags.Empty) {
+ override def symbol: Symbol = NoSymbol
override def owner: Symbol = throw new AssertionError("NoDenotation.owner")
override def name: Name = BootNameTable.newTermName("<none>")
- override def flags = Flags.Empty
- override def tpe: Type = NoType
override def info: Type = NoType
}
+
+ object NameFilter {
+ final val WordSizeLog = 6
+ final val DefinedNamesWords = 16
+ final val DefinedNamesSize = DefinedNamesWords << WordSizeLog
+ final val DefinedNamesMask = DefinedNamesSize - 1
+
+ type FingerPrint = Array[Long]
+
+ def includeName(bits: FingerPrint, name: Name): Unit = {
+ val hash = name.start & DefinedNamesMask
+ bits(hash >> 6) |= (1 << hash)
+ }
+
+ def includeFingerPrint(bits1: FingerPrint, bits2: FingerPrint): Unit =
+ for (i <- 0 until DefinedNamesWords) bits1(i) |= bits2(i)
+
+ def containsName(bits: FingerPrint, name: Name): Boolean = {
+ val hash = name.start & DefinedNamesMask
+ (bits(hash >> 6) & (1 << hash)) != 0
+ }
+
+ def newNameFilter: FingerPrint = new Array[Long](DefinedNamesWords)
+ }
} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/Referenceds.scala b/src/dotty/tools/dotc/core/Referenceds.scala
index 61f95e0e0..f0db3ff6c 100644
--- a/src/dotty/tools/dotc/core/Referenceds.scala
+++ b/src/dotty/tools/dotc/core/Referenceds.scala
@@ -71,7 +71,7 @@ object Referenceds {
/** The type info of the reference, exists only for non-overloaded references */
def info: Type
- /** The interval during which this reference is valid */
+ /** The period during which this reference is valid. */
def validFor: Period
/** Is this a reference to a type symbol? */
@@ -215,9 +215,26 @@ object Referenceds {
// ------ Transformations -----------------------------------------
- var validFor: Period = Nowhere
-
- /** The next SymRefd in this run, with wrap-around from last to first. */
+ private[this] var _validFor: Period = Nowhere
+
+ def validFor = _validFor
+ def validFor_=(p: Period) =
+ _validFor = p
+
+ /** The next SymRefd in this run, with wrap-around from last to first.
+ *
+ * There may be several `SymRefd`s with different validity
+ * representing the same underlying definition at different phases.
+ * These are called a "flock". Flock members are generated by
+ * @see SymRef.current. Flock members are connected in a ring
+ * with their `nextInRun` fields.
+ *
+ * There are the following invariants converning flock members
+ *
+ * 1) validity periods must be non-overlapping
+ * 2) the union of all validity periods must be a contiguous
+ * interval starting in FirstPhaseId.
+ */
var nextInRun: SymRefd = this
/** The version of this SymRefd that was valid in the first phase
@@ -225,13 +242,13 @@ object Referenceds {
*/
def initial: SymRefd = {
var current = nextInRun
- while (current.validFor.code > this.validFor.code) current = current.nextInRun
+ while (current.validFor.code > this._validFor.code) current = current.nextInRun
current
}
def current(implicit ctx: Context): SymRefd = {
val currentPeriod = ctx.period
- val valid = validFor
+ val valid = _validFor
var current = this
if (currentPeriod.code > valid.code) {
// search for containing period as long as nextInRun increases.
@@ -242,7 +259,7 @@ object Referenceds {
next = next.nextInRun
}
if (next.validFor.code > valid.code) {
- // in this case, containsPeriod(next.validFor, currentPeriod)
+ // in this case, containsPeriod(next._validFor, currentPeriod)
current = next
} else {
// not found, current points to highest existing variant
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 4db037a86..be627faf4 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -62,7 +62,7 @@ object Types {
/** The type symbol associated with the type */
final def typeSymbol(implicit ctx: Context): Symbol = this match {
case tp: TypeRef => tp.symbol
- case tp: ClassInfo => tp.classd.clazz
+ case tp: ClassInfo => tp.classd.symbol
case _ => NoSymbol
}
@@ -283,7 +283,7 @@ object Types {
val resultSyms = candidates
.filterAccessibleFrom(pre)
.filterExcluded(excluded)
- .asSeenFrom(pre, classd.clazz)
+ .asSeenFrom(pre, classd.symbol)
if (resultSyms.exists) resultSyms.toRef
else new ErrorRefd // todo: refine
case tp: AndType =>
@@ -860,21 +860,21 @@ object Types {
abstract case class ClassInfo(prefix: Type, classd: ClassDenotation) extends CachedGroundType {
def typeTemplate(implicit ctx: Context): Type =
- classd.typeTemplate asSeenFrom (prefix, classd.clazz)
+ classd.typeTemplate asSeenFrom (prefix, classd.symbol)
def typeConstructor(implicit ctx: Context): Type =
- NamedType(prefix, classd.clazz.name)
+ NamedType(prefix, classd.symbol.name)
// cached because baseType needs parents
private var parentsCache: List[Type] = null
override def parents(implicit ctx: Context): List[Type] = {
if (parentsCache == null)
- parentsCache = classd.parents.mapConserve(_.substThis(classd.clazz, prefix))
+ parentsCache = classd.parents.mapConserve(_.substThis(classd.symbol, prefix))
parentsCache
}
- override def computeHash = doHash(classd.clazz, prefix)
+ override def computeHash = doHash(classd.symbol, prefix)
}
final class CachedClassInfo(prefix: Type, classd: ClassDenotation) extends ClassInfo(prefix, classd)