diff options
author | Martin Odersky <odersky@gmail.com> | 2015-03-11 18:07:13 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-18 11:16:37 +0100 |
commit | cc65c3a4b3193253e894a7b9643e8ee1d246fca5 (patch) | |
tree | b2c828efcd59b9bdebfe2abf3f1c04e1edfcd37d | |
parent | cb8667654ede78bd99b695196dd99a0ec6c9bfa6 (diff) | |
download | dotty-cc65c3a4b3193253e894a7b9643e8ee1d246fca5.tar.gz dotty-cc65c3a4b3193253e894a7b9643e8ee1d246fca5.tar.bz2 dotty-cc65c3a4b3193253e894a7b9643e8ee1d246fca5.zip |
Simplifications to pickled flags
1) Avoiud serializing redunant flags that come with modules
2) Drop DEFAULTinit flag - it's not used.
-rw-r--r-- | src/dotty/tools/dotc/core/Flags.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/PickleFormat.scala | 19 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/TreePickler.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala | 32 |
4 files changed, 27 insertions, 32 deletions
diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index 8094f922c..108a9edee 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -321,9 +321,6 @@ object Flags { /** A type that is defined by a type bind */ final val BindDefinedType = typeFlag(27, "<bind-defined>") - /** Symbol is initialized to the default value, e.g. var x: T = _ */ - final val DefaultInit = termFlag(28, "<defaultinit>") - /** Symbol is inlined */ final val Inline = commonFlag(29, "inline") diff --git a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala index cafd9cc50..8347c50a8 100644 --- a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala +++ b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala @@ -79,11 +79,11 @@ Standard-Section: "ASTs" TopLevelStat* NAMEDARG Length paramName_NameRef arg_Term ASSIGN Length lhs_Term rhs_Term BLOCK Length expr_Term Stat* + LAMBDA Length meth_Term target_Type IF Length cond_Term then_Term else_Term - CLOSURE Length meth_Term target_Type env_Term* MATCH Length sel_Term CaseDef* - RETURN Length meth_ASTRef expr_Term? TRY Length expr_Term CaseDef* finalizer_Term? + RETURN Length meth_ASTRef expr_Term? REPEATED Length elem_Term* BIND Length boundName_NameRef patType_Type pat_Term ALTERNATIVE Length alt_Term* @@ -141,7 +141,6 @@ Standard-Section: "ASTs" TopLevelStat* POLYtype Length result_Type NamesTypes // needed for refinements METHODtype Length result_Type NamesTypes // needed for refinements PARAMtype Length binder_ASTref paramNum_Nat // needed for refinements - NOTYPE SHARED type_ASTRef NamesTypes = ParamType* NameType = paramName_NameRef typeOrBounds_ASTRef @@ -174,7 +173,6 @@ Standard-Section: "ASTs" TopLevelStat* CONTRAVARIANT // type param marked “-” SCALA2X // Imported from Scala2.x DEFAULTparameterized // Method with default params - DEFAULTinit // variable with “_” initializer INSUPERCALL // defined in the argument of a constructor supercall Annotation Annotation = ANNOTATION Length tycon_Type fullAnnotation_Term @@ -224,7 +222,6 @@ object PickleFormat { // AST tags - final val NOTYPE = 1 final val UNITconst = 2 final val FALSEconst = 3 final val TRUEconst = 4 @@ -255,8 +252,7 @@ object PickleFormat { final val CONTRAVARIANT = 29 final val SCALA2X = 30 final val DEFAULTparameterized = 31 - final val DEFAULTinit = 32 - final val INSUPERCALL = 33 + final val INSUPERCALL = 32 final val SHARED = 64 final val TERMREFdirect = 65 @@ -308,7 +304,7 @@ object PickleFormat { final val ASSIGN = 145 final val BLOCK = 146 final val IF = 147 - final val CLOSURE = 148 + final val LAMBDA = 148 final val MATCH = 149 final val RETURN = 150 final val TRY = 151 @@ -332,7 +328,7 @@ object PickleFormat { final val PARAMtype = 176 final val ANNOTATION = 178 - final val firstSimpleTreeTag = NOTYPE + final val firstSimpleTreeTag = UNITconst final val firstNatTreeTag = SHARED final val firstASTTreeTag = THIS final val firstNatASTTreeTag = IDENT @@ -367,7 +363,6 @@ object PickleFormat { | CONTRAVARIANT | SCALA2X | DEFAULTparameterized - | DEFAULTinit | INSUPERCALL | ANNOTATION | PRIVATEqualified @@ -386,7 +381,6 @@ object PickleFormat { } def astTagToString(tag: Int): String = tag match { - case NOTYPE => "NOTYPE" case UNITconst => "UNITconst" case FALSEconst => "FALSEconst" case TRUEconst => "TRUEconst" @@ -417,7 +411,6 @@ object PickleFormat { case CONTRAVARIANT => "CONTRAVARIANT" case SCALA2X => "SCALA2X" case DEFAULTparameterized => "DEFAULTparameterized" - case DEFAULTinit => "DEFAULTinit" case INSUPERCALL => "INSUPERCALL" case SHARED => "SHARED" @@ -461,7 +454,7 @@ object PickleFormat { case ASSIGN => "ASSIGN" case BLOCK => "BLOCK" case IF => "IF" - case CLOSURE => "CLOSURE" + case LAMBDA => "LAMBDA" case MATCH => "MATCH" case RETURN => "RETURN" case TRY => "TRY" diff --git a/src/dotty/tools/dotc/core/pickling/TreePickler.scala b/src/dotty/tools/dotc/core/pickling/TreePickler.scala index c0914421f..d367ccb02 100644 --- a/src/dotty/tools/dotc/core/pickling/TreePickler.scala +++ b/src/dotty/tools/dotc/core/pickling/TreePickler.scala @@ -497,7 +497,7 @@ class TreePickler(pickler: TastyPickler) { } if (flags is Private) writeByte(PRIVATE) if (flags is Protected) if (!privateWithin.exists) writeByte(PROTECTED) - if (flags is Final) writeByte(FINAL) + if ((flags is Final) && !(sym is Module)) writeByte(FINAL) if (flags is Case) writeByte(CASE) if (flags is Override) writeByte(OVERRIDE) if (flags is Inline) writeByte(INLINE) @@ -510,13 +510,12 @@ class TreePickler(pickler: TastyPickler) { if (flags is InSuperCall) writeByte(INSUPERCALL) if (sym.isTerm) { if (flags is Implicit) writeByte(IMPLICIT) - if (flags is Lazy) writeByte(LAZY) + if ((flags is Lazy) && !(sym is Module)) writeByte(LAZY) if (flags is AbsOverride) writeByte(ABSOVERRIDE) if (flags is Mutable) writeByte(MUTABLE) if (flags is Accessor) writeByte(FIELDaccessor) if (flags is CaseAccessor) writeByte(CASEaccessor) if (flags is DefaultParameterized) writeByte(DEFAULTparameterized) - if (flags is DefaultInit) writeByte(DEFAULTinit) } else { if (flags is Sealed) writeByte(SEALED) if (flags is Abstract) writeByte(ABSTRACT) diff --git a/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala b/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala index 3bafa8b1f..4d3beb8fb 100644 --- a/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala @@ -322,6 +322,24 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { val lctx = ctx.fresh.setOwner(owner) if (owner.isClass) lctx.setScope(owner.unforcedDecls) else lctx.setNewScope } + + private def normalizeFlags(tag: Int, givenFlags: FlagSet, name: Name, isAbstractType: Boolean, rhsIsEmpty: Boolean)(implicit ctx: Context): FlagSet = { + val lacksDefinition = + rhsIsEmpty && !name.isConstructorName && !givenFlags.is(ParamOrAccessor) || + isAbstractType + var flags = givenFlags + if (lacksDefinition) flags |= Deferred + if (tag == DEFDEF) flags |= Method + if (givenFlags is Module) + flags = flags | (if (tag == VALDEF) ModuleCreationFlags else ModuleClassCreationFlags) + if (ctx.mode.is(Mode.InSuperCall) && !flags.is(ParamOrAccessor)) flags |= InSuperCall + if (ctx.owner.isClass) { + if (tag == TYPEPARAM) flags |= Param | ExpandedName // TODO check name to determine ExpandedName + else if (tag == PARAM) flags |= ParamAccessor + } + else if (isParamTag(tag)) flags |= Param + flags + } /** Create symbol of definition node and enter in symAtAddr map * @return true iff the definition does not contain initialization code @@ -340,18 +358,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { if (!rhsIsEmpty) skipTree() val (givenFlags, annots, privateWithin) = readModifiers(end) pickling.println(i"creating symbol $name at $start with flags $givenFlags") - val lacksDefinition = - rhsIsEmpty && !name.isConstructorName && !givenFlags.is(ParamOrAccessor) || - isAbstractType - var flags = givenFlags - if (lacksDefinition) flags |= Deferred - if (tag == DEFDEF) flags |= Method - if (ctx.mode.is(Mode.InSuperCall) && !flags.is(ParamOrAccessor)) flags |= InSuperCall - if (ctx.owner.isClass) { - if (tag == TYPEPARAM) flags |= Param | ExpandedName // TODO check name to determine ExpandedName - else if (tag == PARAM) flags |= ParamAccessor - } - else if (isParamTag(tag)) flags |= Param + val flags = normalizeFlags(tag, givenFlags, name, isAbstractType, rhsIsEmpty) val nameMatches = (_: Denotation).symbol.name == name val prevDenot: SymDenotation = if (ctx.owner.is(Package)) ctx.effectiveScope.lookup(name) @@ -431,7 +438,6 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { case CONTRAVARIANT => addFlag(Contravariant) case SCALA2X => addFlag(Scala2x) case DEFAULTparameterized => addFlag(DefaultParameterized) - case DEFAULTinit => addFlag(DefaultInit) case INSUPERCALL => addFlag(InSuperCall) case PRIVATEqualified => readByte() |