aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/config/JavaPlatform.scala2
-rw-r--r--src/dotty/tools/dotc/config/Platform.scala2
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala13
-rw-r--r--src/dotty/tools/dotc/core/Definitions.scala2
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala4
-rw-r--r--src/dotty/tools/dotc/core/Periods.scala28
-rw-r--r--src/dotty/tools/dotc/core/Phases.scala6
-rw-r--r--src/dotty/tools/dotc/core/Scopes.scala21
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala27
-rw-r--r--src/dotty/tools/dotc/core/SymbolLoaders.scala38
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala36
-rw-r--r--src/dotty/tools/dotc/core/Types.scala54
-rw-r--r--src/dotty/tools/dotc/reporting/Reporter.scala3
13 files changed, 155 insertions, 81 deletions
diff --git a/src/dotty/tools/dotc/config/JavaPlatform.scala b/src/dotty/tools/dotc/config/JavaPlatform.scala
index 0698ac929..bf467ec1e 100644
--- a/src/dotty/tools/dotc/config/JavaPlatform.scala
+++ b/src/dotty/tools/dotc/config/JavaPlatform.scala
@@ -21,7 +21,7 @@ class JavaPlatform extends Platform {
def updateClassPath(subst: Map[ClassPath, ClassPath]) =
currentClassPath = Some(new DeltaClassPath(currentClassPath.get, subst))
- def rootLoader(implicit ctx: Context): SymbolLoader = new ctx.base.loaders.PackageLoader(classPath)(ctx.condensed)
+ def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = new ctx.base.loaders.PackageLoader(root, classPath)(ctx.condensed)
/** We could get away with excluding BoxedBooleanClass for the
* purpose of equality testing since it need not compare equal
diff --git a/src/dotty/tools/dotc/config/Platform.scala b/src/dotty/tools/dotc/config/Platform.scala
index 7dc2507f2..4909c8d68 100644
--- a/src/dotty/tools/dotc/config/Platform.scala
+++ b/src/dotty/tools/dotc/config/Platform.scala
@@ -16,7 +16,7 @@ import core.SymbolLoader
abstract class Platform {
/** The root symbol loader. */
- def rootLoader(implicit ctx: Context): SymbolLoader
+ def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader
/** The compiler classpath. */
def classPath(implicit ctx: Context): ClassPath
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index d33c93a3a..4b730a4aa 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -221,7 +221,7 @@ object Contexts {
*/
private class InitialContext(val base: ContextBase, settings: SettingGroup) extends FreshContext {
outer = NoContext
- period = Nowhere
+ period = InitialPeriod
constraints = Map()
position = NoPosition
plainPrinter = new PlainPrinter(_)
@@ -249,7 +249,11 @@ object Contexts {
val settings = new ScalaSettings
/** The initial context */
- val initialCtx: Context = new InitialContext(this, settings)
+ val initialCtx: Context =
+ new InitialContext(this, settings)
+ .withSetting(settings.verbose, true) // !!! for now
+ .withSetting(settings.debug, true)
+ .withSetting(settings.Ylogcp, true)
/** The symbol loaders */
val loaders = new SymbolLoaders
@@ -258,7 +262,10 @@ object Contexts {
val platform: Platform = new JavaPlatform
/** The loader that loads the members of _root_ */
- def rootLoader(implicit ctx: Context): SymbolLoader = platform.rootLoader
+ def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root)
+
+ NoPhase // initialize some phases
+ SomePhase // TODO: Is there a cleaner way to do this?
/** The standard definitions */
val definitions = new Definitions()(initialCtx)
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala
index bdc95ff16..d8235b1e4 100644
--- a/src/dotty/tools/dotc/core/Definitions.scala
+++ b/src/dotty/tools/dotc/core/Definitions.scala
@@ -52,7 +52,7 @@ class Definitions(implicit ctx: Context) {
}
lazy val RootClass: ClassSymbol = ctx.newPackageSymbol(
- NoSymbol, nme.ROOT, ctx.rootLoader).moduleClass.asClass
+ NoSymbol, nme.ROOT, (root, rootcls) => ctx.rootLoader(root)).moduleClass.asClass
lazy val RootPackage: TermSymbol = ctx.newSymbol(
NoSymbol, nme.ROOTPKG, PackageCreationFlags, TypeRef(NoPrefix, RootClass))
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index d7a559d53..dd740e916 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -111,7 +111,7 @@ object Denotations {
*
* Then the denotation of `y` is `SingleDenotation(NoSymbol, A | B)`.
*/
- abstract class Denotation extends DotClass {
+ abstract class Denotation extends DotClass with Showable {
/** The referencing symbol, exists only for non-overloaded denotations */
def symbol: Symbol
@@ -476,7 +476,7 @@ object Denotations {
if (denots.containsSig(signature)) NoDenotation else this
def filterAsSeenFrom(pre: Type, excluded: FlagSet)(implicit ctx: Context): PreDenotation = {
val sym = symbol
- if (!(sym is excluded) && sym.isAccessibleFrom(pre))
+ if (sym.exists && !(sym is excluded) && sym.isAccessibleFrom(pre))
derivedSingleDenotation(symbol, info.asSeenFrom(pre, symbol.owner))
else
NoDenotation
diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala
index 56343f0ac..55a485201 100644
--- a/src/dotty/tools/dotc/core/Periods.scala
+++ b/src/dotty/tools/dotc/core/Periods.scala
@@ -23,6 +23,24 @@ abstract class Periods extends DotClass { self: Context =>
/** Execute `op` at given phase id */
def atPhase[T](pid: PhaseId)(op: Context => T): T =
op(ctx.fresh.withPhase(pid))
+
+ /** The period containing the current period where denotations do not change.
+ * We compute this by taking as first phase the first phase less or equal to
+ * the current phase that has the same "nextTransformer". As last phase
+ * we take the phaseId of the nextTransformer - 1. This has the advantage that
+ * it works even if no transformer is installed other than the sentinel
+ * NoTransformer, which is always installed automatically.
+ */
+ def stablePeriod = {
+ var first = phaseId
+ val transformers = base.symTransformers
+ val nxTrans = transformers.nextTransformer(first)
+ while (first - 1 > NoPhaseId &&
+ (transformers.nextTransformer(first - 1) eq nxTrans)) {
+ first -= 1
+ }
+ Period(runId, first, nxTrans.phaseId - 1)
+ }
}
object Periods {
@@ -41,10 +59,7 @@ object Periods {
def runId: Int = code >>> (PhaseWidth * 2)
/** The phase identifier of this single-phase period. */
- def phaseId: Int = {
- assert((code & PhaseMask) == 0)
- (code >>> PhaseWidth) & PhaseMask
- }
+ def phaseId: Int = (code >>> PhaseWidth) & PhaseMask
/** The last phase of this period */
def lastPhaseId: Int =
@@ -91,6 +106,8 @@ object Periods {
this.lastPhaseId min that.lastPhaseId)
else
Nowhere
+
+ override def toString = s"Period($firstPhaseId..$lastPhaseId, run = $runId)"
}
object Period {
@@ -111,9 +128,12 @@ object Periods {
final val Nowhere = new Period(0)
+ final val InitialPeriod = Period(InitialRunId, FirstPhaseId, FirstPhaseId)
+
/** An ordinal number for compiler runs. First run has number 1. */
type RunId = Int
final val NoRunId = 0
+ final val InitialRunId = 1
/** An ordinal number for phases. First phase has number 1. */
type PhaseId = Int
diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala
index 3cc59292c..de86d3f85 100644
--- a/src/dotty/tools/dotc/core/Phases.scala
+++ b/src/dotty/tools/dotc/core/Phases.scala
@@ -9,7 +9,7 @@ trait Phases { self: Context =>
def phase: Phase = base.phases(period.phaseId)
def phasesStack: List[Phase] =
- if (phase == this.NoPhase) Nil
+ if ((this eq NoContext) || !phase.exists) Nil
else phase :: outersIterator.dropWhile(_.phase == phase).next.phasesStack
/** Execute `op` at given phase id */
@@ -30,6 +30,7 @@ object Phases {
lazy val allPhases = phases.slice(FirstPhaseId, nphases)
object NoPhase extends Phase(initialCtx) {
+ override def exists = false
def name = "<no phase>"
def run() { throw new Error("NoPhase.run") }
}
@@ -56,6 +57,7 @@ object Phases {
abstract class Phase(initctx: Context) {
val id: Int = initctx.nphases
+ initctx.phases(id) = this // TODO: Do explicit phase install instead?
initctx.nphases += 1
def name: String
@@ -66,7 +68,7 @@ object Phases {
def checkable: Boolean = true
- final def exists: Boolean = id != NoPhaseId
+ def exists: Boolean = true
final def <= (that: Phase) =
exists && id <= that.id
diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala
index f8a125a3b..42711e627 100644
--- a/src/dotty/tools/dotc/core/Scopes.scala
+++ b/src/dotty/tools/dotc/core/Scopes.scala
@@ -149,24 +149,21 @@ 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)
e.prev = lastEntry
lastEntry = e
+ if (hashTable ne null) enterInHash(e)
size += 1
elemsCache = null
- if (hashTable ne null) {
- ensureCapacity(hashTable.length)
- enterInHash(e)
- } else {
- ensureCapacity(MinHash)
- }
e
}
private def enterInHash(e: ScopeEntry)(implicit ctx: Context): Unit = {
- val i = e.sym.name.start & (hashTable.length - 1)
- e.tail = hashTable(i)
- hashTable(i) = e
+ val idx = e.sym.name.hashCode & (hashTable.length - 1)
+ e.tail = hashTable(idx)
+ assert(e.tail != e)
+ hashTable(idx) = e
}
/** enter a symbol in this scope. */
@@ -182,7 +179,7 @@ object Scopes {
}
private def ensureCapacity(tableSize: Int)(implicit ctx: Context): Unit =
- if (size > tableSize * FillFactor) createHash(tableSize * 2)
+ if (size >= tableSize * FillFactor) createHash(tableSize * 2)
private def createHash(tableSize: Int)(implicit ctx: Context): Unit =
if (size > tableSize * FillFactor) createHash(tableSize * 2)
@@ -218,7 +215,7 @@ object Scopes {
e1.prev = e.prev
}
if (hashTable ne null) {
- val index = e.sym.name.start & (hashTable.length - 1)
+ val index = e.sym.name.hashCode & (hashTable.length - 1)
var e1 = hashTable(index)
if (e1 == e)
hashTable(index) = e.tail
@@ -245,7 +242,7 @@ object Scopes {
override final def lookupEntry(name: Name)(implicit ctx: Context): ScopeEntry = {
var e: ScopeEntry = null
if (hashTable ne null) {
- e = hashTable(name.start & (hashTable.length - 1))
+ e = hashTable(name.hashCode & (hashTable.length - 1))
while ((e ne null) && e.sym.name != name) {
e = e.tail
}
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 6758ce4a1..f4d047d58 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -11,7 +11,7 @@ import scala.reflect.io.AbstractFile
import Decorators.SymbolIteratorDecorator
import annotation.tailrec
-trait SymDenotations {
+trait SymDenotations { this: Context =>
import SymDenotations._
/** Factory method for SymDenotion creation. All creations
@@ -23,10 +23,13 @@ trait SymDenotations {
name: Name,
initFlags: FlagSet,
initInfo: Type,
- initPrivateWithin: Symbol = NoSymbol)(implicit ctx: Context): SymDenotation =
- if (symbol.isClass) new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
- else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
-
+ initPrivateWithin: Symbol = NoSymbol)(implicit ctx: Context): SymDenotation = {
+ val result =
+ if (symbol.isClass) new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
+ else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
+ result.validFor = stablePeriod
+ result
+ }
}
object SymDenotations {
@@ -79,7 +82,7 @@ object SymDenotations {
}
private def completedInfo(completer: LazyType): Type = {
- if (_flags is CompletionStarted) throw new CyclicReference(symbol)
+ if (_flags is CompletionStarted) throw new CyclicReference(this)
_flags |= CompletionStarted
completer.complete(this)
info
@@ -374,6 +377,15 @@ object SymDenotations {
}
}
+ /** Do members of this symbol need translation via asSeenFrom when
+ * accessed via prefix `pre`?
+ */
+ def membersNeedAsSeenFrom(pre: Type)(implicit ctx: Context) =
+ !( (this is PackageClass)
+ || ctx.erasedTypes && symbol != defn.ArrayClass
+ || (pre eq thisType)
+ )
+
// def isOverridable: Boolean = !!! need to enforce that classes cannot be redefined
// def isSkolem: Boolean = ???
@@ -559,6 +571,8 @@ object SymDenotations {
s"$kindString $name"
}
+ val debugString = toString+"#"+symbol.id // !!! DEBUG
+
// ----- copies ------------------------------------------------------
override protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new UniqueRefDenotation(s, i, validFor)
@@ -887,6 +901,7 @@ object SymDenotations {
override def isTerm = false
override def isType = false
override def owner: Symbol = throw new AssertionError("NoDenotation.owner")
+ validFor = Period.allInRun(NoRunId) // will be brought forward automatically
}
// ---- Completion --------------------------------------------------------
diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala
index bd4ec13f7..41f45fcbd 100644
--- a/src/dotty/tools/dotc/core/SymbolLoaders.scala
+++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala
@@ -42,8 +42,8 @@ class SymbolLoaders {
/** Enter package with given `name` into scope of `owner`
* and give them `completer` as type.
*/
- def enterPackage(owner: Symbol, name: PreName, completer: SymbolLoader)(implicit ctx: Context): Symbol = {
- val pname = name.toTermName
+ def enterPackage(owner: Symbol, pkg: ClassPath)(implicit ctx: CondensedContext): Symbol = {
+ val pname = pkg.name.toTermName
val preExisting = owner.info.decls lookup pname
if (preExisting != NoSymbol) {
// Some jars (often, obfuscated ones) include a package and
@@ -53,7 +53,7 @@ class SymbolLoaders {
// require yjp.jar at runtime. See SI-2089.
if (ctx.settings.termConflict.isDefault)
throw new TypeError(
- s"""$owner contains object and package with same name: $name
+ s"""$owner contains object and package with same name: $pname
|one of them needs to be removed from classpath""".stripMargin)
else if (ctx.settings.termConflict.value == "package") {
ctx.warning(
@@ -65,7 +65,8 @@ class SymbolLoaders {
return NoSymbol
}
}
- ctx.newModuleSymbol(owner, pname, PackageCreationFlags, completer).entered
+ ctx.newModuleSymbol(owner, pname, PackageCreationFlags,
+ (module, modcls) => new PackageLoader(module, pkg)).entered
}
/** Enter class and module with given `name` into scope of `owner`
@@ -74,10 +75,13 @@ class SymbolLoaders {
def enterClassAndModule(owner: Symbol, name: PreName, completer: SymbolLoader, flags: FlagSet = EmptyFlags)(implicit ctx: Context) {
val clazz = enterClass(owner, name, completer, flags)
val module = enterModule(owner, name, completer, flags)
- if (!clazz.isAnonymousClass) {
+ /*
+ * !!! disabled for now because it causes CyclicReference. Need to revisit
+ * if (!clazz.isAnonymousClass) {
assert(clazz.companionModule == module, module)
assert(module.companionClass == clazz, clazz)
}
+ */
}
/** In batch mode: Enter class and module with given `name` into scope of `owner`
@@ -121,12 +125,16 @@ class SymbolLoaders {
/** Load contents of a package
*/
- class PackageLoader(classpath: ClassPath)(implicit val cctx: CondensedContext) extends SymbolLoader {
+ class PackageLoader(module: TermSymbol, classpath: ClassPath)(implicit val cctx: CondensedContext)
+ extends LazyModuleClassInfo(module) with SymbolLoader {
protected def description = "package loader " + classpath.name
protected override def doComplete(root: SymDenotation) {
assert(root.isPackageClass, root)
- root.info = ClassInfo(root.owner.thisType, root.symbol.asClass, Nil, newScope)
+ val pre = root.owner.thisType
+ root.info = ClassInfo(pre, root.symbol.asClass, Nil, newScope, TermRef(pre, module))
+ if (!module.isCompleted)
+ module.completer.complete(module)
if (!root.isRoot) {
for (classRep <- classpath.classes) {
initializeFromClassPath(root.symbol, classRep)
@@ -134,7 +142,7 @@ class SymbolLoaders {
}
if (!root.isEmptyPackage) {
for (pkg <- classpath.packages) {
- enterPackage(root.symbol, pkg.name, new PackageLoader(pkg))
+ enterPackage(root.symbol, pkg)
}
openPackageModule(root.symbol.asClass)
}
@@ -180,7 +188,7 @@ class SymbolLoaders {
/** A lazy type that completes itself by calling parameter doComplete.
* Any linked modules/classes or module classes are also initialized.
*/
-abstract class SymbolLoader extends LazyType {
+trait SymbolLoader extends LazyType {
implicit val cctx: CondensedContext
/** Load source or class file for `root`, return */
@@ -199,20 +207,26 @@ abstract class SymbolLoader extends LazyType {
val msg = ex.getMessage()
cctx.error(
if (msg eq null) "i/o error while loading " + root.name
- else "error while loading " + root.name + ", " + msg)
+ else "error while loading " + root.name + ",\n " + msg)
}
try {
+ // println("trying to complete "+root) // !!! DEBUG
val start = currentTime
doComplete(root)
cctx.informTime("loaded " + description, start)
} catch {
case ex: IOException =>
- signalError(ex)
+ signalError(ex)
+ case ex: Throwable => // !!! DEBUG
+ println("caught: "+ex)
+ ex.printStackTrace()
+ throw ex
} finally {
def postProcess(denot: SymDenotation) =
if (!denot.isCompleted) denot.markAbsent()
postProcess(root)
- postProcess(root.linkedClass.denot)
+ if (!root.isRoot)
+ postProcess(root.linkedClass.denot)
}
}
}
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index 5b3a63f3d..ddc667fd6 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -123,7 +123,7 @@ trait Symbols { this: Context =>
val mdenot = SymDenotation(
module, owner, name,
flags & RetainedModuleValFlags | ModuleCreationFlags,
- if (cdenot.isCompleted) modcls.symbolicRef
+ if (cdenot.isCompleted) TypeRef(owner.thisType, name.toTypeName, modcls)
else new LazyModuleInfo(modcls)(condensed))
module.denot = mdenot
modcls.denot = cdenot
@@ -147,7 +147,7 @@ trait Symbols { this: Context =>
newModuleSymbol(
owner, name, flags,
(module, modcls) => ClassInfo(
- owner.thisType, modcls, parents, decls, TermRef(owner.thisType, module)),
+ owner.thisType, modcls, parents, decls, TermRef(owner.thisType, name, module)),
privateWithin, coord, assocFile)
/** Create a package symbol with associated package class
@@ -156,8 +156,8 @@ trait Symbols { this: Context =>
def newPackageSymbol(
owner: Symbol,
name: TermName,
- info: LazyType): TermSymbol =
- newModuleSymbol(owner, name, PackageCreationFlags, info)
+ infoFn: (TermSymbol, ClassSymbol) => LazyType): TermSymbol =
+ newModuleSymbol(owner, name, PackageCreationFlags, infoFn)
/** Create a package symbol with associated package class
* from its non-info fields its member scope.
@@ -175,6 +175,7 @@ trait Symbols { this: Context =>
*/
def newStubSymbol(owner: Symbol, name: Name, file: AbstractFile = null): Symbol = {
def stub = new StubInfo()(condensed)
+ println(s"creating stub for $name") // !!! DEBUG
name match {
case name: TermName =>
newModuleSymbol(owner, name, EmptyFlags, stub, assocFile = file)
@@ -253,18 +254,28 @@ trait Symbols { this: Context =>
// ----- Locating predefined symbols ----------------------------------------
- def requiredPackage(path: PreName): TermSymbol =
- base.staticRef(path.toTermName).requiredSymbol(_.isPackage).asTerm
+ def requiredPackage(path: PreName): TermSymbol = {
+ val pathName = path.toTermName
+ base.staticRef(pathName).requiredSymbol(_.isPackage, pathName).asTerm
+ }
- def requiredClass(path: PreName): ClassSymbol =
- base.staticRef(path.toTypeName).requiredSymbol(_.isClass).asClass
+ def requiredClass(path: PreName): ClassSymbol = {
+ val pathName = path.toTypeName
+ val sym = base.staticRef(pathName).requiredSymbol(_.isClass, pathName).asClass
+ }
- def requiredModule(path: PreName): TermSymbol =
- base.staticRef(path.toTermName).requiredSymbol(_.isModule).asTerm
+ def requiredModule(path: PreName): TermSymbol = {
+ val pathName = path.toTermName
+ base.staticRef(pathName).requiredSymbol(_.isModule, pathName).asTerm
+ }
}
object Symbols {
+ var _nextId = 0 // !!! DEBUG
+ def nextId = { _nextId += 1; _nextId }
+
+
/** A Symbol represents a Scala definition/declaration or a package.
*/
class Symbol private[Symbols] (val coord: Coord) extends DotClass with Showable {
@@ -274,8 +285,8 @@ object Symbols {
private[this] var _id: Int = _
/** The unique id of this symbol */
- def id(implicit ctx: Context) = {
- if (_id == 0) _id = ctx.nextId
+ def id/*(implicit ctx: Context)*/ = { // !!! DEBUG
+ if (_id == 0) _id = /*ctx.*/nextId // !!! DEBUG
_id
}
@@ -311,6 +322,7 @@ object Symbols {
/** This symbol entered into owner's scope (owner must be a class). */
final def entered(implicit ctx: Context): this.type = {
+ assert(this.owner.isClass, this.owner.denot) // !!! DEBUG
this.owner.asClass.enter(this)
this
}
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index ab43a793d..b8993f71c 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -210,23 +210,26 @@ object Types {
EmptyScope
}
- /** A denotation containing the declaration(s) in this type with the given name */
+ /** A denotation containing the declaration(s) in this type with the given name.
+ * The result is either a SymDenotation or a MultiDenotation of SymDenotations.
+ * The info(s) are the original symbol infos, no translation takes place.
+ */
final def decl(name: Name)(implicit ctx: Context): Denotation =
- findDecl(name, this, EmptyFlags)
+ findDecl(name, EmptyFlags)
/** A denotation containing the non-private declaration(s) in this type with the given name */
final def nonPrivateDecl(name: Name)(implicit ctx: Context): Denotation =
- findDecl(name, this, Flags.Private)
+ findDecl(name, Private)
/** A denotation containing the declaration(s) in this type with the given
* name, as seen from prefix type `pre`. Declarations that have a flag
* in `excluded` are omitted.
*/
- final def findDecl(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation = this match {
+ final def findDecl(name: Name, excluded: FlagSet)(implicit ctx: Context): Denotation = this match {
case tp: ClassInfo =>
- tp.decls.denotsNamed(name).filterAsSeenFrom(pre, excluded).toDenot
+ tp.decls.denotsNamed(name).filterAsSeenFrom(NoPrefix, excluded).toDenot
case tp: TypeProxy =>
- tp.underlying.findDecl(name, pre, excluded)
+ tp.underlying.findDecl(name, excluded)
}
/** The member of this type with the given name */
@@ -310,10 +313,7 @@ object Types {
* declared in class `cls`.
*/
final def asSeenFrom(pre: Type, cls: Symbol)(implicit ctx: Context): Type =
- if ( (cls is PackageClass)
- || ctx.erasedTypes && cls != defn.ArrayClass
- || (pre eq cls.thisType)
- ) this
+ if (!cls.membersNeedAsSeenFrom(pre)) this
else ctx.asSeenFrom(this, pre, cls, null)
// ----- Subtype-related --------------------------------------------
@@ -768,7 +768,7 @@ object Types {
case _ => false
}
if (checkPrefix && !prefix.isLegalPrefix)
- throw new MalformedType(prefix, d.symbol)
+ throw new MalformedType(prefix, d.asInstanceOf[SymDenotation])
d
} else {// name has changed; try load in earlier phase and make current
denot(ctx.fresh.withPhase(ctx.phaseId - 1)).current
@@ -845,8 +845,8 @@ object Types {
}
}
- final class TermRefBySym(prefix: Type, val fixedSym: TermSymbol)(initctx: Context)
- extends TermRef(prefix, fixedSym.name(initctx).asTermName) with HasFixedSym {
+ final class TermRefBySym(prefix: Type, name: TermName, val fixedSym: TermSymbol)
+ extends TermRef(prefix, name) with HasFixedSym {
override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef =
if (prefix.baseType(fixedSym.owner).exists) TermRef(prefix, fixedSym)
else TermRef(prefix, name, fixedSym.signature)
@@ -861,8 +861,8 @@ object Types {
TermRef(prefix, name, sig)
}
- final class TypeRefBySym(prefix: Type, val fixedSym: TypeSymbol)(initctx: Context)
- extends TypeRef(prefix, fixedSym.name(initctx).asTypeName) with HasFixedSym {
+ final class TypeRefBySym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol)
+ extends TypeRef(prefix, name) with HasFixedSym {
override def newLikeThis(prefix: Type)(implicit ctx: Context): TypeRef =
if (prefix.baseType(fixedSym.owner).exists) TypeRef(prefix, fixedSym)
else TypeRef(prefix, name)
@@ -881,19 +881,23 @@ object Types {
}
object TermRef {
- def apply(prefix: Type, name: TermName)(implicit ctx: Context) =
+ def apply(prefix: Type, name: TermName)(implicit ctx: Context): TermRef =
unique(new CachedTermRef(prefix, name))
- def apply(prefix: Type, sym: TermSymbol)(implicit ctx: Context) =
- unique(new TermRefBySym(prefix, sym)(ctx))
- def apply(prefix: Type, name: TermName, sig: Signature)(implicit ctx: Context) =
+ def apply(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRefBySym =
+ apply(prefix, sym.name, sym)
+ def apply(prefix: Type, name: TermName, sym: TermSymbol)(implicit ctx: Context): TermRefBySym =
+ unique(new TermRefBySym(prefix, name, sym))
+ def apply(prefix: Type, name: TermName, sig: Signature)(implicit ctx: Context): TermRefWithSignature =
unique(new TermRefWithSignature(prefix, name, sig))
}
object TypeRef {
- def apply(prefix: Type, name: TypeName)(implicit ctx: Context) =
+ def apply(prefix: Type, name: TypeName)(implicit ctx: Context): TypeRef =
unique(new CachedTypeRef(prefix, name))
- def apply(prefix: Type, sym: TypeSymbol)(implicit ctx: Context) =
- unique(new TypeRefBySym(prefix, sym)(ctx))
+ def apply(prefix: Type, sym: TypeSymbol)(implicit ctx: Context): TypeRefBySym =
+ apply(prefix, sym.name, sym)
+ def apply(prefix: Type, name: TypeName, sym: TypeSymbol)(implicit ctx: Context): TypeRefBySym =
+ unique(new TypeRefBySym(prefix, name, sym))
}
// --- Other SingletonTypes: ThisType/SuperType/ConstantType ---------------------------
@@ -1478,8 +1482,10 @@ object Types {
class TypeError(msg: String) extends Exception(msg)
class FatalTypeError(msg: String) extends TypeError(msg)
- class MalformedType(pre: Type, sym: Symbol) extends FatalTypeError(s"malformed type: $pre.$sym")
- class CyclicReference(sym: Symbol) extends FatalTypeError("cyclic reference involving $sym")
+ class MalformedType(pre: Type, denot: SymDenotation)
+ extends FatalTypeError(s"malformed type: $pre is not a legal prefix for $denot")
+ class CyclicReference(denot: SymDenotation)
+ extends FatalTypeError(s"cyclic reference involving $denot")
// ----- Misc utilities ---------------------------------------------------------
diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala
index 83b97bea2..4b11b415a 100644
--- a/src/dotty/tools/dotc/reporting/Reporter.scala
+++ b/src/dotty/tools/dotc/reporting/Reporter.scala
@@ -15,7 +15,8 @@ trait Reporting { this: Context =>
def inform(msg: String, pos: Position = NoPosition): Unit = reporter.info(msg, pos)
def log(msg: => String)(implicit ctx: Context): Unit =
- if (this.settings.log.value.containsPhase(phase))
+ if (true || // !!! for now
+ this.settings.log.value.containsPhase(phase))
inform(s"[log ${ctx.phasesStack.reverse.mkString(" -> ")}] $msg")
def debuglog(msg: => String)(implicit ctx: Context): Unit =