From 62131749d08657a0103c922c626a0b918cf385b5 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 19 Aug 2013 16:19:03 +0200 Subject: Several fixes and refactorings for typechecking 1) Refactoring of package loaders that ensures that a package is always loaded before new members are entered. This led to a refactoring of sourceModule in completers into its own trait 2) Refactoring of optSelfType ot selfInfo. Class Infos may now have a reference to a symbol in their selfInfo field, instead of always a type, as it was before. This allows to introduce laziness for self type evaluation. Laziness is needed so that modules can be desugared and the desugared version be compiled without special tricks. 3) and $init members are no longer inherited. 4) Refactoring of createSymbol and enterSym, so that creating symbols and entering them in a scope is decoupled. Renamed the driver operation form `enterSym(s)` to `index`. --- src/dotty/tools/dotc/core/pickling/UnPickler.scala | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/dotty/tools/dotc/core/pickling/UnPickler.scala') diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 23fb79f8f..2b18e2263 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -84,7 +84,7 @@ object UnPickler { tp.derivedPolyType(paramNames, tp.paramBounds, arrayToRepeated(tp.resultType)) } - def setClassInfo(denot: ClassDenotation, info: Type, optSelfType: Type = NoType)(implicit ctx: Context): Unit = { + def setClassInfo(denot: ClassDenotation, info: Type, selfInfo: Type = NoType)(implicit ctx: Context): Unit = { val cls = denot.classSymbol val (tparams, TempClassInfoType(parents, decls, clazz)) = info match { case TempPolyType(tps, cinfo) => (tps, cinfo) @@ -97,9 +97,9 @@ object UnPickler { else denot.enter(tparam, decls) } val ost = - if ((optSelfType eq NoType) && (denot is ModuleClass)) + if ((selfInfo eq NoType) && (denot is ModuleClass)) TermRef.withSym(denot.owner.thisType, denot.sourceModule.asTerm) - else optSelfType + else selfInfo denot.info = ClassInfo(denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost) } } @@ -452,13 +452,14 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: // create a type alias instead cctx.newSymbol(owner, name, flags, localMemberUnpickler, coord = start) else { - def completer(cls: Symbol) = new LocalClassUnpickler(cls) { - override def sourceModule = - if (flags is ModuleClass) - cls.owner.decls.lookup(cls.name.stripModuleClassSuffix.toTermName) - .suchThat(_ is Module).symbol - else NoSymbol - } + def completer(cls: Symbol) = + if (flags is ModuleClass) + new LocalClassUnpickler(cls) with ModuleClassCompleter { + override def sourceModule = + cls.owner.decls.lookup(cls.name.stripModuleClassSuffix.toTermName) + .suchThat(_ is Module).symbol + } + else new LocalClassUnpickler(cls) cctx.newClassSymbol(owner, name.asTypeName, flags, completer, coord = start) } case MODULEsym | VALsym => @@ -491,8 +492,8 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: val tp = at(inforef, readType) denot match { case denot: ClassDenotation => - val optSelfType = if (atEnd) NoType else readTypeRef() - setClassInfo(denot, tp, optSelfType) + val selfInfo = if (atEnd) NoType else readTypeRef() + setClassInfo(denot, tp, selfInfo) case denot => val tp1 = depoly(tp, denot) denot.info = if (tag == ALIASsym) TypeAlias(tp1) else tp1 @@ -529,7 +530,9 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: extends ClassCompleterWithDecls(symScope(cls), localMemberUnpickler) def rootClassUnpickler(start: Coord, cls: Symbol, module: Symbol) = - new ClassCompleterWithDecls(symScope(cls), new AtStartUnpickler(start)) with SymbolLoaders.SecondCompleter { + new ClassCompleterWithDecls(symScope(cls), new AtStartUnpickler(start)) + with ModuleClassCompleter + with SymbolLoaders.SecondCompleter { override def sourceModule = module } -- cgit v1.2.3