aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-09-18 09:40:26 +0200
committerMartin Odersky <odersky@gmail.com>2013-09-18 09:40:26 +0200
commit283c41637ce5e50655c31e729fa4c0baf3ece185 (patch)
treeb0dfae2b98e126c9119d9cbbbd39a7627b3b1023 /src/dotty
parent64a312432ca2cded23ca2d9244276231c52a52c2 (diff)
downloaddotty-283c41637ce5e50655c31e729fa4c0baf3ece185.tar.gz
dotty-283c41637ce5e50655c31e729fa4c0baf3ece185.tar.bz2
dotty-283c41637ce5e50655c31e729fa4c0baf3ece185.zip
Experimental branch that drops {Term/Type}RefWithSym types
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala2
-rw-r--r--src/dotty/tools/dotc/core/Scopes.scala8
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala25
-rw-r--r--src/dotty/tools/dotc/core/Types.scala86
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala8
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala12
-rw-r--r--src/dotty/tools/dotc/typer/ImportInfo.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala2
8 files changed, 81 insertions, 64 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index 4307c81d4..841b83376 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -158,7 +158,7 @@ object Contexts {
def implicits: ContextualImplicits = {
if (implicitsCache == null )
implicitsCache = {
- val implicitRefs: List[TermRefBySym] =
+ val implicitRefs: List[TermRef] =
if (isClassDefContext) owner.thisType.implicitMembers
else if (isImportContext) importInfo.importedImplicits
else if (isNonEmptyScopeContext) scope.implicitDecls
diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala
index a308adf79..bd67801e1 100644
--- a/src/dotty/tools/dotc/core/Scopes.scala
+++ b/src/dotty/tools/dotc/core/Scopes.scala
@@ -7,7 +7,7 @@ package dotty.tools.dotc
package core
import Symbols._
-import Types.{TermRef, TermRefBySym, NoPrefix}
+import Types.{TermRef, NoPrefix}
import Flags.Implicit
import Names._
import Periods._
@@ -112,7 +112,7 @@ object Scopes {
syms
}
- def implicitDecls(implicit ctx: Context): List[TermRefBySym] = Nil
+ def implicitDecls(implicit ctx: Context): List[TermRef] = Nil
final def toText(printer: Printer): Text = printer.toText(this)
}
@@ -288,8 +288,8 @@ object Scopes {
elemsCache
}
- override def implicitDecls(implicit ctx: Context): List[TermRefBySym] = {
- var irefs = new ListBuffer[TermRefBySym]
+ override def implicitDecls(implicit ctx: Context): List[TermRef] = {
+ var irefs = new ListBuffer[TermRef]
var e = lastEntry
while (e ne null) {
if (e.sym is Implicit)
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 0d1c9b597..dee841102 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -104,6 +104,7 @@ object SymDenotations {
protected[dotc] final def info_=(tp: Type) = {
def illegal: String = s"illegal type for module $this: $tp"
+ /*
if (this is Module) // make sure module invariants that allow moduleClass and sourceModule to work are kept.
tp match {
case tp: ClassInfo => assert(tp.selfInfo.isInstanceOf[TermRefBySym], illegal)
@@ -111,6 +112,7 @@ object SymDenotations {
case tp: ExprType => assert(tp.resultType.isInstanceOf[TypeRefBySym], illegal)
case _ =>
}
+ */
myInfo = tp
}
@@ -416,7 +418,8 @@ object SymDenotations {
* accessed via prefix `pre`?
*/
def membersNeedAsSeenFrom(pre: Type)(implicit ctx: Context) =
- !( this.isStaticOwner
+ !( this.isTerm
+ || this.isStaticOwner
|| ctx.erasedTypes && symbol != defn.ArrayClass
|| (pre eq thisType)
)
@@ -452,20 +455,20 @@ object SymDenotations {
* the completers.
*/
/** The class implementing this module, NoSymbol if not applicable. */
- final def moduleClass: Symbol =
+ final def moduleClass(implicit ctx: Context): Symbol =
if (this is ModuleVal)
myInfo match {
- case info: TypeRefBySym => info.fixedSym
- case ExprType(info: TypeRefBySym) => info.fixedSym // needed after uncurry, when module terms might be accessor defs
- case info: LazyType => info.moduleClass
- case _ => println(s"missing module class for $name: $myInfo"); NoSymbol
+ case info: TypeRef => info.symbol
+ case ExprType(info: TypeRef) => info.symbol // needed after uncurry, when module terms might be accessor defs
+ case info: LazyType => info.moduleClass
+ case _ => println(s"missing module class for $name: $myInfo"); NoSymbol
}
else NoSymbol
/** The module implemented by this module class, NoSymbol if not applicable. */
- final def sourceModule: Symbol = myInfo match {
- case ClassInfo(_, _, _, _, selfType: TermRefBySym) if this is ModuleClass =>
- selfType.fixedSym
+ final def sourceModule(implicit ctx: Context): Symbol = myInfo match {
+ case ClassInfo(_, _, _, _, selfType: TermRef) if this is ModuleClass =>
+ selfType.symbol
case info: LazyType =>
info.sourceModule
case _ =>
@@ -617,13 +620,13 @@ object SymDenotations {
/** The symbolic typeref representing the type constructor for this type.
* @throws ClassCastException is this is not a type
*/
- final def symTypeRef(implicit ctx: Context): TypeRefBySym =
+ final def symTypeRef(implicit ctx: Context): TypeRef =
TypeRef.withSym(owner.thisType, symbol.asType)
/** The symbolic termref pointing to this termsymbol
* @throws ClassCastException is this is not a term
*/
- def symTermRef(implicit ctx: Context): TermRefBySym =
+ def symTermRef(implicit ctx: Context): TermRef =
TermRef.withSym(owner.thisType, symbol.asTerm)
def symRef(implicit ctx: Context): NamedType =
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 248a4fe2c..b97c569ef 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -436,7 +436,7 @@ object Types {
memberNames(typeNameFilter).map(member(_).asInstanceOf[SingleDenotation])
/** The set of implicit members of this type */
- final def implicitMembers(implicit ctx: Context): List[TermRefBySym] =
+ final def implicitMembers(implicit ctx: Context): List[TermRef] =
memberNames(implicitFilter).toList
.flatMap(name => member(name)
.altsWith(_ is Implicit)
@@ -1153,21 +1153,27 @@ object Types {
val prefix: Type
val name: Name
- private[this] var lastDenotation: Denotation = null
+ private[this] var lastDenotationOrSym: AnyRef = null
- def knownDenotation: Boolean = lastDenotation != null
+ def knownDenotation: Boolean = lastDenotationOrSym.isInstanceOf[Denotation]
/** The denotation currently denoted by this type */
- def denot(implicit ctx: Context): Denotation = {
- val validPeriods =
- if (lastDenotation != null) lastDenotation.validFor else Nowhere
- val thisPeriod = ctx.period
- if (!(validPeriods contains thisPeriod)) {
- lastDenotation =
- if (validPeriods.runId == thisPeriod.runId) {
- lastDenotation.current
- } else {
- val d = loadDenot
+ final def denot(implicit ctx: Context): Denotation = lastDenotationOrSym match {
+ case d: Denotation if d.validFor contains ctx.period => d
+ case _ => computeDenot
+ }
+
+ private def computeDenot(implicit ctx: Context): Denotation = {
+ val denot = lastDenotationOrSym match {
+ case d: Denotation =>
+ if (d.validFor.runId == ctx.period.runId) d.current
+ else loadDenot
+ case sym: Symbol =>
+ val d = sym.denot
+ val owner = d.owner
+ if (owner.isTerm) d else d.asSeenFrom(prefix)
+ case _ =>
+ loadDenot
/* need to do elsewhere as it leads to a cycle in subtyping here.
if (d.exists && !d.symbol.isAliasType && !prefix.isLegalPrefix) {
val ex = new MalformedType(prefix, d, prefix.memberNames(abstractTypeNameFilter))
@@ -1177,21 +1183,31 @@ object Types {
} else ctx.log(ex.getMessage)
}
*/
- if (d.exists || ctx.phaseId == FirstPhaseId)
- d
- else // name has changed; try load in earlier phase and make current
- denot(ctx.fresh.withPhase(ctx.phaseId - 1)).current
- }
}
- lastDenotation
+ lastDenotationOrSym = denot
+ denot
}
private[dotc] final def withDenot(denot: Denotation): this.type = {
- lastDenotation = denot
+ lastDenotationOrSym = denot
+ this
+ }
+
+ private[dotc] final def withSym(sym: Symbol): this.type = {
+ lastDenotationOrSym = sym
this
}
- protected def loadDenot(implicit ctx: Context) = prefix.member(name)
+ protected def loadDenot(implicit ctx: Context) = {
+ val d = prefix.member(name)
+ if (d.exists || ctx.phaseId == FirstPhaseId)
+ d
+ else {// name has changed; try load in earlier phase and make current
+ val d = denot(ctx.fresh.withPhase(ctx.phaseId - 1)).current
+ if (d.exists) d
+ else throw new Error(s"failure to reload $this")
+ }
+ }
def isType = name.isTypeName
def isTerm = name.isTermName
@@ -1277,6 +1293,7 @@ object Types {
override def computeHash = doHash(name, prefix)
}
+/*
trait HasFixedSym extends NamedType {
protected val fixedSym: Symbol
override def symbol(implicit ctx: Context): Symbol = fixedSym
@@ -1295,21 +1312,17 @@ object Types {
override def computeHash = doHash(fixedSym, prefix)
override def toString = super.toString + "(fixed sym)"
}
-
- final class TermRefBySym(prefix: Type, name: TermName, val fixedSym: TermSymbol)
- extends TermRef(prefix, name) with HasFixedSym
+ */
final class TermRefWithSignature(prefix: Type, name: TermName, override val sig: Signature) extends TermRef(prefix, name) {
+ assert(sig != NotAMethod)
override def signature(implicit ctx: Context) = sig
override def loadDenot(implicit ctx: Context): Denotation =
super.loadDenot.atSignature(sig)
- override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRefWithSignature =
+ override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef =
TermRef.withSig(prefix, name, sig)
}
- final class TypeRefBySym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol)
- extends TypeRef(prefix, name) with HasFixedSym
-
final class CachedTermRef(prefix: Type, name: TermName) extends TermRef(prefix, name)
final class CachedTypeRef(prefix: Type, name: TypeName) extends TypeRef(prefix, name)
@@ -1325,20 +1338,21 @@ object Types {
object TermRef {
def apply(prefix: Type, name: TermName)(implicit ctx: Context): TermRef =
unique(new CachedTermRef(prefix, name))
- def withSym(prefix: Type, name: TermName, sym: TermSymbol)(implicit ctx: Context): TermRefBySym =
- unique(new TermRefBySym(prefix, name, sym))
- def withSym(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRefBySym =
+ def withSym(prefix: Type, name: TermName, sym: TermSymbol)(implicit ctx: Context): TermRef =
+ apply(prefix, name) withSym sym
+ def withSym(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
withSym(prefix, sym.name, sym)
- def withSig(prefix: Type, name: TermName, sig: Signature)(implicit ctx: Context): TermRefWithSignature =
- unique(new TermRefWithSignature(prefix, name, sig))
+ def withSig(prefix: Type, name: TermName, sig: Signature)(implicit ctx: Context): TermRef =
+ if (sig == NotAMethod) apply(prefix, name)
+ else unique(new TermRefWithSignature(prefix, name, sig))
}
object TypeRef {
def apply(prefix: Type, name: TypeName)(implicit ctx: Context): TypeRef =
unique(new CachedTypeRef(prefix, name))
- def withSym(prefix: Type, name: TypeName, sym: TypeSymbol)(implicit ctx: Context): TypeRefBySym =
- unique(new TypeRefBySym(prefix, name, sym))
- def withSym(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRefBySym =
+ def withSym(prefix: Type, name: TypeName, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
+ apply(prefix, name) withSym sym
+ def withSym(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
withSym(prefix, sym.name, sym)
}
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index f0dcb7336..109987dcf 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -543,10 +543,10 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
case tp @ RefinedType(parent, name) =>
val parent1 = elim(tp.parent)
tp.refinedInfo match {
- case TypeAlias(info: TypeRefBySym) if boundSyms contains info.fixedSym =>
- RefinedType(parent1, name, info.fixedSym.info)
- case info: TypeRefBySym if boundSyms contains info.fixedSym =>
- val info1 = info.fixedSym.info
+ case TypeAlias(info: TypeRef) if boundSyms contains info.symbol =>
+ RefinedType(parent1, name, info.symbol.info)
+ case info: TypeRef if boundSyms contains info.symbol =>
+ val info1 = info.symbol.info
assert(info1.derivesFrom(defn.SingletonClass))
RefinedType(parent1, name, info1.mapAnd(removeSingleton))
case info =>
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index 2de8985d9..91bc769e9 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -66,7 +66,7 @@ object Implicits {
* name, b, whereas the name of the symbol is the original name, a.
* @param outerCtx the next outer context that makes visible further implicits
*/
- class ContextualImplicits(val refs: List[TermRefBySym], val outerCtx: Context)(initctx: Context) extends ImplicitRefs {
+ class ContextualImplicits(val refs: List[TermRef], val outerCtx: Context)(initctx: Context) extends ImplicitRefs {
implicit val ctx: Context =
if (initctx == NoContext) initctx else initctx retractMode Mode.ImplicitsEnabled
@@ -187,7 +187,7 @@ trait ImplicitRunInfo { self: RunInfo =>
val pre = tp.prefix
comps ++= implicitScope(pre).companionRefs
def addClassScope(cls: ClassSymbol): Unit = {
- def addRef(companion: TermRefBySym): Unit = {
+ def addRef(companion: TermRef): Unit = {
val comp1 @ TermRef(p, _) = companion.asSeenFrom(pre, companion.symbol.owner)
comps += TermRef.withSym(p, comp1.symbol.asTerm).withDenot(comp1.denot)
}
@@ -373,10 +373,10 @@ trait Implicits { self: Typer =>
}
/** A set of term references where equality is =:= */
-class TermRefSet(implicit ctx: Context) extends mutable.Traversable[TermRefBySym] {
+class TermRefSet(implicit ctx: Context) extends mutable.Traversable[TermRef] {
private val elems = new mutable.LinkedHashMap[TermSymbol, List[Type]]
- def += (ref: TermRefBySym): Unit = {
+ def += (ref: TermRef): Unit = {
val pre = ref.prefix
val sym = ref.symbol.asTerm
elems get sym match {
@@ -387,10 +387,10 @@ class TermRefSet(implicit ctx: Context) extends mutable.Traversable[TermRefBySym
}
}
- def ++= (refs: TraversableOnce[TermRefBySym]): Unit =
+ def ++= (refs: TraversableOnce[TermRef]): Unit =
refs foreach +=
- override def foreach[U](f: TermRefBySym => U): Unit =
+ override def foreach[U](f: TermRef => U): Unit =
for (sym <- elems.keysIterator)
for (pre <- elems(sym))
f(TermRef.withSym(pre, sym))
diff --git a/src/dotty/tools/dotc/typer/ImportInfo.scala b/src/dotty/tools/dotc/typer/ImportInfo.scala
index 92b980c01..7be914f8b 100644
--- a/src/dotty/tools/dotc/typer/ImportInfo.scala
+++ b/src/dotty/tools/dotc/typer/ImportInfo.scala
@@ -76,7 +76,7 @@ class ImportInfo(val sym: Symbol, val selectors: List[untpd.Tree], val rootImpor
}
/** The implicit references imported by this import clause */
- def importedImplicits: List[TermRefBySym] = {
+ def importedImplicits: List[TermRef] = {
val pre = site
if (wildcardImport) {
val refs = pre.implicitMembers
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 265326480..ca284edf7 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -323,7 +323,7 @@ class Namer { typer: Typer =>
def adjustIfModule(sig: Type): Type =
if (denot is Module)
sig match {
- case sig: TypeRefBySym =>
+ case sig: TypeRef =>
sig
case sig: TypeRef =>
TypeRef.withSym(sig.prefix, sig.symbol.asType)