diff options
Diffstat (limited to 'src/dotty/tools/dotc')
5 files changed, 46 insertions, 28 deletions
diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index e57ba066e..4a016ba72 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -335,8 +335,8 @@ object Flags { final val JavaStaticTerm = JavaStatic.toTermFlags final val JavaStaticType = JavaStatic.toTypeFlags - /** Trait is not an interface, but does not have fields or intialization code */ - final val NoInits = typeFlag(32, "<noInits>") // TODO when unpickling, reconstitute from context + /** Trait is not an interface, but does not have fields or initialization code */ + final val NoInits = typeFlag(32, "<noInits>") /** Variable is accessed from nested function. */ final val Captured = termFlag(32, "<captured>") @@ -367,7 +367,7 @@ object Flags { /** Symbol always defines a fresh named type */ final val Fresh = commonFlag(45, "<fresh>") - /** Symbol is defined in a super call */ // TODO when unpickling, reconstitute from context + /** Symbol is defined in a super call */ final val InSuperCall = commonFlag(46, "<in supercall>") /** Symbol with private access is accessed outside its private scope */ diff --git a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala index 557a45f8c..a03da3a79 100644 --- a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala +++ b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala @@ -158,6 +158,7 @@ Standard-Section: "ASTs" TopLevelStat* ABSOVERRIDE // abstract override STATIC // mapped to static Java member MODULE // an object or its class + TRAIT LOCAL // private[this] or protected[this] SYNTHETIC // generated by Scala compiler ARTIFACT // to be tagged Java Synthetic @@ -237,20 +238,21 @@ object PickleFormat { final val ABSOVERRIDE = 17 final val STATIC = 18 final val MODULE = 19 - final val LOCAL = 20 - final val SYNTHETIC = 21 - final val ARTIFACT = 22 - final val MUTABLE = 23 - final val LABEL = 24 - final val FIELDaccessor = 25 - final val PARAMaccessor = 26 - final val CASEaccessor = 27 - final val COVARIANT = 28 - final val CONTRAVARIANT = 29 - final val SCALA2X = 30 - final val DEFAULTparameterized = 31 - final val DEFAULTinit = 32 - final val INSUPERCALL = 33 + final val TRAIT = 20 + final val LOCAL = 21 + final val SYNTHETIC = 22 + final val ARTIFACT = 23 + final val MUTABLE = 24 + final val LABEL = 25 + final val FIELDaccessor = 26 + final val PARAMaccessor = 27 + final val CASEaccessor = 28 + final val COVARIANT = 29 + final val CONTRAVARIANT = 30 + final val SCALA2X = 31 + final val DEFAULTparameterized = 32 + final val DEFAULTinit = 33 + final val INSUPERCALL = 34 final val SHARED = 64 final val TERMREFdirect = 65 @@ -332,11 +334,6 @@ object PickleFormat { final val firstNatASTTreeTag = IDENT final val firstLengthTreeTag = PACKAGE - def isDefTag(tag: Int) = tag match { - case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM => true - case _ => false - } - def isParamTag(tag: Int) = tag == PARAM || tag == TYPEPARAM def nameTagToString(tag: Int): String = tag match { @@ -370,6 +367,7 @@ object PickleFormat { case ABSOVERRIDE => "ABSOVERRIDE" case STATIC => "STATIC" case MODULE => "MODULE" + case TRAIT => "TRAIT" case LOCAL => "LOCAL" case SYNTHETIC => "SYNTHETIC" case ARTIFACT => "ARTIFACT" diff --git a/src/dotty/tools/dotc/core/pickling/TreePickler.scala b/src/dotty/tools/dotc/core/pickling/TreePickler.scala index 16c1ebd02..3212894c4 100644 --- a/src/dotty/tools/dotc/core/pickling/TreePickler.scala +++ b/src/dotty/tools/dotc/core/pickling/TreePickler.scala @@ -462,6 +462,7 @@ class TreePickler(pickler: TastyPickler) { } else { if (flags is Sealed) writeByte(SEALED) if (flags is Abstract) writeByte(ABSTRACT) + if (flags is Trait) writeByte(TRAIT) if (flags is Covariant) writeByte(COVARIANT) if (flags is Contravariant) writeByte(CONTRAVARIANT) } diff --git a/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala b/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala index 0c989cfdc..9a63c7038 100644 --- a/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala @@ -259,8 +259,10 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, // ------ Reading definitions ----------------------------------------------------- - /** Create symbol of definition node and enter in symAtAddr map */ - def createSymbol()(implicit ctx: Context): Unit = { + /** Create symbol of definition node and enter in symAtAddr map + * @return flag set over PureInterface | NoInits according to form of definition + */ + def createSymbol()(implicit ctx: Context): FlagSet = { val start = currentAddr val tag = readByte() val end = readEnd() @@ -317,6 +319,10 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, completer.withDecls(newScope) forkAt(templateStart).indexTemplateParams()(ctx.fresh.setOwner(sym)) } + var resultFlags: FlagSet = EmptyFlags + if (tag != VALDEF || rhsIsEmpty) resultFlags |= NoInits + if (tag != VALDEF && tag != DEFDEF || rhsIsEmpty) resultFlags |= PureInterface + resultFlags } /** Read modifier list into triplet of flags, annotations and a privateWithin @@ -346,6 +352,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, case ABSOVERRIDE => addFlag(AbsOverride) case STATIC => addFlag(JavaStatic) case MODULE => addFlag(Module) + case TRAIT => addFlag(Trait) case LOCAL => addFlag(Local) case SYNTHETIC => addFlag(Synthetic) case ARTIFACT => addFlag(Artifact) @@ -383,9 +390,19 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, /** Create symbols for a definitions in statement sequence between * current address and `end`. + * @return flag set over PureInterface | NoInits according to forms of statements */ - def indexStats(end: Addr)(implicit ctx: Context) = - until(end) { if (isDefTag(nextByte)) createSymbol() else skipTree() } + def indexStats(end: Addr)(implicit ctx: Context): FlagSet = { + val statFlags = + until(end) { + nextByte match { + case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM => createSymbol() + case EMPTYTREE | IMPORT => skipTree(); PureInterface | NoInits + case _ => skipTree(); EmptyFlags + } + } + ((PureInterface | NoInits) /: statFlags) (_ & _) + } /** Create symbols the longest consecutive sequence of parameters with given * `tag starting at current address. @@ -467,6 +484,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, impl.parents.map(_.tpe.asInstanceOf[TypeRef]), cls.unforcedDecls, if (impl.self.isEmpty) NoType else impl.self.tpt.tpe) + if (!cls.is(Trait)) cls.resetFlag(PureInterface) ta.assignType(untpd.TypeDef(sym.name.asTypeName, impl), sym) } else { @@ -506,7 +524,8 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, untpd.ValDef(readName(), readTpt(), EmptyTree).withType(NoType) } else EmptyValDef - fork.indexStats(end) + val additionalFlags = fork.indexStats(end) // PureInterface or NoInits + cls.setFlag(additionalFlags) // PureInterface will be reset later if cls is not a trait val constr = readIndexedDef().asInstanceOf[DefDef] val lazyStats = readLater(end, rdr => ctx => rdr.readIndexedStats(localDummy, end)(ctx)) setPos(start, diff --git a/src/dotty/tools/dotc/transform/FirstTransform.scala b/src/dotty/tools/dotc/transform/FirstTransform.scala index bde17c854..0de261149 100644 --- a/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -119,7 +119,7 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi /* A this reference hide in a self ident, and be subsequently missed when deciding on whether outer accessors are needed and computing outer paths. - sWe do this normalization directly after Typer, because during typer the + We do this normalization directly after Typer, because during typer the ident should rest available for hyperlinking.*/ This(tpe.cls).withPos(tree.pos) case _ => normalizeType(tree) |