diff options
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 28 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymbolLoaders.scala | 37 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/ClassfileParser.scala | 18 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 39 | ||||
-rw-r--r-- | test/test/showClass.scala | 6 |
5 files changed, 44 insertions, 84 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index ad2b8834c..c6d90737d 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -160,7 +160,7 @@ object SymDenotations { * @pre: this is a class */ protected[core] final def preCompleteDecls: Scope = _info match { - case cinfo: LazyClassInfo => cinfo.decls + case cinfo: ClassCompleter => cinfo.decls case cinfo: ClassInfo => cinfo.decls case cinfo: LazyType => completeFrom(cinfo); preCompleteDecls case cinfo => throw new AssertionError(s"unexpected class completer for $debugString: ${cinfo.getClass}") @@ -178,7 +178,7 @@ object SymDenotations { * Drops package objects. Represents terms in the owner chain by a simple `separator`. */ def fullName(separator: Char)(implicit ctx: Context): Name = - if (this == NoSymbol || owner == NoSymbol || owner.isEffectiveRoot) name + if (symbol == NoSymbol || owner == NoSymbol || owner.isEffectiveRoot) name else { var owner = this var sep = "" @@ -430,7 +430,7 @@ object SymDenotations { final def sourceModule: Symbol = _info match { case ClassInfo(_, _, _, _, selfType: TermRefBySym) if this is ModuleClass => selfType.fixedSym - case info: LazyModuleClassInfo => + case info: ClassCompleter => info.module case _ => NoSymbol @@ -979,19 +979,19 @@ object SymDenotations { def apply(module: TermSymbol, modcls: ClassSymbol) = this } - /** A lazy type for classes that contains an initial pre-complete scope. - * Typically this is for type parameters - */ - trait LazyClassInfo extends LazyType { - val decls: Scope + class ClassCompleter(val decls: Scope, underlying: LazyType = NoCompleter) + extends LazyType { + def complete(denot: SymDenotation): Unit = underlying.complete(denot) + def module: Symbol = NoSymbol } - /** A lazy type for module classes that points back to the source module. - * Needed so that `sourceModule` works before completion. - */ - trait LazyModuleClassInfo extends LazyClassInfo { - def module: TermSymbol - override def toString = s"LazyModuleClassInfo($module)" + class ModuleClassCompleter(modul: Symbol, underlying: LazyType = NoCompleter) + extends ClassCompleter(newScope, underlying) { + override def module = modul + } + + object NoCompleter extends LazyType { + override def complete(denot: SymDenotation): Unit = unsupported("complete") } /** A lazy type for modules that points to the module class. diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index f2c3de9a7..387ca4afd 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -47,9 +47,10 @@ class SymbolLoaders { def enterModule( owner: Symbol, name: PreName, completer: SymbolLoader, modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: CondensedContext): Symbol = { - def moduleCompleterFn(modul: TermSymbol, cls: ClassSymbol): LazyType = - new ModuleClassCompleter(modul, completer) - val module = ctx.newModuleSymbol(owner, name.toTermName, modFlags, clsFlags, moduleCompleterFn, assocFile = completer.sourceFileOrNull) + val module = ctx.newModuleSymbol( + owner, name.toTermName, modFlags, clsFlags, + (modul, _) => new ModuleClassCompleter(modul, completer), + assocFile = completer.sourceFileOrNull) enterNew(owner, module, completer, scope) } @@ -140,12 +141,10 @@ class SymbolLoaders { /** Load contents of a package */ - class PackageLoader(val module: TermSymbol, classpath: ClassPath)(implicit val cctx: CondensedContext) - extends SymbolLoader with LazyModuleClassInfo { + class PackageLoader(override val module: TermSymbol, classpath: ClassPath)(implicit val cctx: CondensedContext) + extends ClassCompleter(newScope) with SymbolLoader { def description = "package loader " + classpath.name - val decls = newScope - def doComplete(root: SymDenotation) { assert(root is PackageClass, root) val pre = root.owner.thisType @@ -205,7 +204,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 */ @@ -272,17 +271,11 @@ class ClassfileLoader(val classfile: AbstractFile)(implicit val cctx: CondensedC cctx.newClassSymbol( rootDenot.owner, rootDenot.name.asTypeName, Synthetic, _ => NoType).classDenot - else { - def modClassCompleter(modul: TermSymbol, modcls: ClassSymbol) = - new LazyModuleClassInfo { - val decls = newScope - def module = modul - def complete(denot: SymDenotation) = unsupported("complete") - } + else cctx.newModuleSymbol( rootDenot.owner, rootDenot.name.toTermName, Synthetic, Synthetic, - modClassCompleter).moduleClass.denot.asClass - } + (module, _) => new ModuleClassCompleter(module)) + .moduleClass.denot.asClass } if (rootDenot is ModuleClass) (linkedDenot, rootDenot) else (rootDenot, linkedDenot) @@ -299,13 +292,3 @@ class SourcefileLoader(val srcfile: AbstractFile)(implicit val cctx: CondensedCo override def sourceFileOrNull = srcfile def doComplete(root: SymDenotation): Unit = unsupported("doComplete") } - -class ModuleClassCompleter(val module: TermSymbol, classCompleter: SymbolLoader)(implicit val cctx: CondensedContext) - extends SymbolLoader with LazyModuleClassInfo { - val decls = newScope - def description: String = classCompleter.description - override def sourceFileOrNull = classCompleter.sourceFileOrNull - def doComplete(root: SymDenotation): Unit = { - classCompleter.doComplete(root) - } -} diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index 73ba10a71..e273634ef 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -35,10 +35,7 @@ class ClassfileParser( protected var currentClassName: Name = _ // JVM name of the current class protected var classTParams = Map[Name,Symbol]() - classRoot.info = new LazyClassInfo { - val decls = instanceScope - def complete(denot: SymDenotation) = unsupported("complete") - } + classRoot.info = new ClassCompleter(instanceScope) private def currentIsTopLevel = classRoot.owner is Flags.PackageClass @@ -527,19 +524,6 @@ class ClassfileParser( new ClassfileLoader(file), FlagTranslation.classFlags(jflags), getScope(jflags)) - // println(s"entered inner class of ${getOwner(jflags)}: ${entry.originalName} from file $file") // !!! DEBUG - /* alternative: - val owner = getOwner(jflags) - val name = entry.originalName - val completer = new ClassfileLoader(file) - val flags = FlagTranslation.classFlags(jflags) - val cls = cctx.newClassSymbol(owner, name.toTypeName, flags, completer, assocFile = file) - def moduleCompleterFn(modul: TermSymbol, cls: ClassSymbol): LazyType = - new ModuleClassCompleter(modul, completer) - getScope(jflags).enter(cls) - val module = cctx.newModuleSymbol(owner, name.toTermName, Flags.EmptyFlags, Flags.EmptyFlags, /*???*/ moduleCompleterFn, assocFile = file) - getScope(jflags).enter(module) - */ } for (entry <- innerClasses.values) { diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index c09ff8072..92a44aaa1 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -450,19 +450,21 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: postReadOp = () => atReadPos(index(infoRef), readTypeParams) // force reading type params early, so they get entered in the right order. if (isClassRoot) completeRoot( - classRoot, - new ClassRootUnpickler(start, classRoot.symbol)) + classRoot, rootClassUnpickler(start, classRoot.symbol, NoSymbol)) else if (isModuleClassRoot) completeRoot( - moduleClassRoot, - new ModuleClassRootUnpickler(start, moduleClassRoot.symbol, moduleClassRoot.sourceModule.asTerm)) + moduleClassRoot, rootClassUnpickler(start, moduleClassRoot.symbol, moduleClassRoot.sourceModule)) else if (name == tpnme.REFINE_CLASS) // create a type alias instead cctx.newSymbol(owner, name, flags, localMemberUnpickler, coord = start) else { - val completer = - if (flags is ModuleClass) new LocalModuleClassUnpickler(_: Symbol) - else new LocalClassUnpickler(_: Symbol) + def completer(cls: Symbol) = new LocalClassUnpickler(cls) { + override def module = + if (flags is ModuleClass) + cls.owner.preCompleteDecls.lookup( + cls.name.stripModuleClassSuffix.toTermName).suchThat(_ is Module).symbol + else NoSymbol + } cctx.newClassSymbol(owner, name.asTypeName, flags, completer, coord = start) } case MODULEsym | VALsym => @@ -523,27 +525,18 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: } } - class LocalClassUnpickler(cls: Symbol) extends LocalUnpickler with LazyClassInfo { - val decls = symScope(cls) - } - - class LocalModuleClassUnpickler(cls: Symbol) extends LocalClassUnpickler(cls) with LazyModuleClassInfo { - def module = cls.owner.preCompleteDecls.lookup( - cls.name.stripModuleClassSuffix.toTermName).suchThat(_ is Module).symbol.asTerm + class AtStartUnpickler(start: Coord) extends LocalUnpickler { + override def startCoord(denot: SymDenotation): Coord = start } object localMemberUnpickler extends LocalUnpickler - class ClassRootUnpickler(start: Coord, cls: Symbol) - extends LocalClassUnpickler(cls) with SymbolLoaders.SecondCompleter { - override def startCoord(denot: SymDenotation): Coord = start - } - - class ModuleClassRootUnpickler(start: Coord, cls: Symbol, val module: TermSymbol) - extends LocalClassUnpickler(cls) with SymbolLoaders.SecondCompleter with LazyModuleClassInfo { - override def startCoord(denot: SymDenotation): Coord = start - } + class LocalClassUnpickler(cls: Symbol) extends ClassCompleter(symScope(cls), localMemberUnpickler) + def rootClassUnpickler(start: Coord, cls: Symbol, modul: Symbol) = + new ClassCompleter(symScope(cls), new AtStartUnpickler(start)) with SymbolLoaders.SecondCompleter { + override def module = modul + } /** Convert * tp { type name = sym } forSome { sym >: L <: H } diff --git a/test/test/showClass.scala b/test/test/showClass.scala index 6eb3d81d1..7951c0a95 100644 --- a/test/test/showClass.scala +++ b/test/test/showClass.scala @@ -6,9 +6,9 @@ object showClass extends ShowClassTests { def main(args: Array[String]) = { for (arg <- args) showPackage(ctx.requiredPackage(arg)) -// showClasses("scala.collection.TraversableOnce") - showPackage("scala.collection") -// showPackage("scala.collection") +// showClasses("scala.reflect.internal.StdCreators") + showPackage("scala.reflect") + showPackage("scala.collection") println("done") } } |