Skip to content

Commit cc65c3a

Browse files
oderskyDarkDimius
authored andcommitted
Simplifications to pickled flags
1) Avoiud serializing redunant flags that come with modules 2) Drop DEFAULTinit flag - it's not used.
1 parent cb86676 commit cc65c3a

File tree

4 files changed

+27
-32
lines changed

4 files changed

+27
-32
lines changed

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,6 @@ object Flags {
321321
/** A type that is defined by a type bind */
322322
final val BindDefinedType = typeFlag(27, "<bind-defined>")
323323

324-
/** Symbol is initialized to the default value, e.g. var x: T = _ */
325-
final val DefaultInit = termFlag(28, "<defaultinit>")
326-
327324
/** Symbol is inlined */
328325
final val Inline = commonFlag(29, "inline")
329326

src/dotty/tools/dotc/core/pickling/PickleFormat.scala

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ Standard-Section: "ASTs" TopLevelStat*
7979
NAMEDARG Length paramName_NameRef arg_Term
8080
ASSIGN Length lhs_Term rhs_Term
8181
BLOCK Length expr_Term Stat*
82+
LAMBDA Length meth_Term target_Type
8283
IF Length cond_Term then_Term else_Term
83-
CLOSURE Length meth_Term target_Type env_Term*
8484
MATCH Length sel_Term CaseDef*
85-
RETURN Length meth_ASTRef expr_Term?
8685
TRY Length expr_Term CaseDef* finalizer_Term?
86+
RETURN Length meth_ASTRef expr_Term?
8787
REPEATED Length elem_Term*
8888
BIND Length boundName_NameRef patType_Type pat_Term
8989
ALTERNATIVE Length alt_Term*
@@ -141,7 +141,6 @@ Standard-Section: "ASTs" TopLevelStat*
141141
POLYtype Length result_Type NamesTypes // needed for refinements
142142
METHODtype Length result_Type NamesTypes // needed for refinements
143143
PARAMtype Length binder_ASTref paramNum_Nat // needed for refinements
144-
NOTYPE
145144
SHARED type_ASTRef
146145
NamesTypes = ParamType*
147146
NameType = paramName_NameRef typeOrBounds_ASTRef
@@ -174,7 +173,6 @@ Standard-Section: "ASTs" TopLevelStat*
174173
CONTRAVARIANT // type param marked “-”
175174
SCALA2X // Imported from Scala2.x
176175
DEFAULTparameterized // Method with default params
177-
DEFAULTinit // variable with “_” initializer
178176
INSUPERCALL // defined in the argument of a constructor supercall
179177
Annotation
180178
Annotation = ANNOTATION Length tycon_Type fullAnnotation_Term
@@ -224,7 +222,6 @@ object PickleFormat {
224222

225223
// AST tags
226224

227-
final val NOTYPE = 1
228225
final val UNITconst = 2
229226
final val FALSEconst = 3
230227
final val TRUEconst = 4
@@ -255,8 +252,7 @@ object PickleFormat {
255252
final val CONTRAVARIANT = 29
256253
final val SCALA2X = 30
257254
final val DEFAULTparameterized = 31
258-
final val DEFAULTinit = 32
259-
final val INSUPERCALL = 33
255+
final val INSUPERCALL = 32
260256

261257
final val SHARED = 64
262258
final val TERMREFdirect = 65
@@ -308,7 +304,7 @@ object PickleFormat {
308304
final val ASSIGN = 145
309305
final val BLOCK = 146
310306
final val IF = 147
311-
final val CLOSURE = 148
307+
final val LAMBDA = 148
312308
final val MATCH = 149
313309
final val RETURN = 150
314310
final val TRY = 151
@@ -332,7 +328,7 @@ object PickleFormat {
332328
final val PARAMtype = 176
333329
final val ANNOTATION = 178
334330

335-
final val firstSimpleTreeTag = NOTYPE
331+
final val firstSimpleTreeTag = UNITconst
336332
final val firstNatTreeTag = SHARED
337333
final val firstASTTreeTag = THIS
338334
final val firstNatASTTreeTag = IDENT
@@ -367,7 +363,6 @@ object PickleFormat {
367363
| CONTRAVARIANT
368364
| SCALA2X
369365
| DEFAULTparameterized
370-
| DEFAULTinit
371366
| INSUPERCALL
372367
| ANNOTATION
373368
| PRIVATEqualified
@@ -386,7 +381,6 @@ object PickleFormat {
386381
}
387382

388383
def astTagToString(tag: Int): String = tag match {
389-
case NOTYPE => "NOTYPE"
390384
case UNITconst => "UNITconst"
391385
case FALSEconst => "FALSEconst"
392386
case TRUEconst => "TRUEconst"
@@ -417,7 +411,6 @@ object PickleFormat {
417411
case CONTRAVARIANT => "CONTRAVARIANT"
418412
case SCALA2X => "SCALA2X"
419413
case DEFAULTparameterized => "DEFAULTparameterized"
420-
case DEFAULTinit => "DEFAULTinit"
421414
case INSUPERCALL => "INSUPERCALL"
422415

423416
case SHARED => "SHARED"
@@ -461,7 +454,7 @@ object PickleFormat {
461454
case ASSIGN => "ASSIGN"
462455
case BLOCK => "BLOCK"
463456
case IF => "IF"
464-
case CLOSURE => "CLOSURE"
457+
case LAMBDA => "LAMBDA"
465458
case MATCH => "MATCH"
466459
case RETURN => "RETURN"
467460
case TRY => "TRY"

src/dotty/tools/dotc/core/pickling/TreePickler.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class TreePickler(pickler: TastyPickler) {
497497
}
498498
if (flags is Private) writeByte(PRIVATE)
499499
if (flags is Protected) if (!privateWithin.exists) writeByte(PROTECTED)
500-
if (flags is Final) writeByte(FINAL)
500+
if ((flags is Final) && !(sym is Module)) writeByte(FINAL)
501501
if (flags is Case) writeByte(CASE)
502502
if (flags is Override) writeByte(OVERRIDE)
503503
if (flags is Inline) writeByte(INLINE)
@@ -510,13 +510,12 @@ class TreePickler(pickler: TastyPickler) {
510510
if (flags is InSuperCall) writeByte(INSUPERCALL)
511511
if (sym.isTerm) {
512512
if (flags is Implicit) writeByte(IMPLICIT)
513-
if (flags is Lazy) writeByte(LAZY)
513+
if ((flags is Lazy) && !(sym is Module)) writeByte(LAZY)
514514
if (flags is AbsOverride) writeByte(ABSOVERRIDE)
515515
if (flags is Mutable) writeByte(MUTABLE)
516516
if (flags is Accessor) writeByte(FIELDaccessor)
517517
if (flags is CaseAccessor) writeByte(CASEaccessor)
518518
if (flags is DefaultParameterized) writeByte(DEFAULTparameterized)
519-
if (flags is DefaultInit) writeByte(DEFAULTinit)
520519
} else {
521520
if (flags is Sealed) writeByte(SEALED)
522521
if (flags is Abstract) writeByte(ABSTRACT)

src/dotty/tools/dotc/core/pickling/TreeUnpickler.scala

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,24 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
322322
val lctx = ctx.fresh.setOwner(owner)
323323
if (owner.isClass) lctx.setScope(owner.unforcedDecls) else lctx.setNewScope
324324
}
325+
326+
private def normalizeFlags(tag: Int, givenFlags: FlagSet, name: Name, isAbstractType: Boolean, rhsIsEmpty: Boolean)(implicit ctx: Context): FlagSet = {
327+
val lacksDefinition =
328+
rhsIsEmpty && !name.isConstructorName && !givenFlags.is(ParamOrAccessor) ||
329+
isAbstractType
330+
var flags = givenFlags
331+
if (lacksDefinition) flags |= Deferred
332+
if (tag == DEFDEF) flags |= Method
333+
if (givenFlags is Module)
334+
flags = flags | (if (tag == VALDEF) ModuleCreationFlags else ModuleClassCreationFlags)
335+
if (ctx.mode.is(Mode.InSuperCall) && !flags.is(ParamOrAccessor)) flags |= InSuperCall
336+
if (ctx.owner.isClass) {
337+
if (tag == TYPEPARAM) flags |= Param | ExpandedName // TODO check name to determine ExpandedName
338+
else if (tag == PARAM) flags |= ParamAccessor
339+
}
340+
else if (isParamTag(tag)) flags |= Param
341+
flags
342+
}
325343

326344
/** Create symbol of definition node and enter in symAtAddr map
327345
* @return true iff the definition does not contain initialization code
@@ -340,18 +358,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
340358
if (!rhsIsEmpty) skipTree()
341359
val (givenFlags, annots, privateWithin) = readModifiers(end)
342360
pickling.println(i"creating symbol $name at $start with flags $givenFlags")
343-
val lacksDefinition =
344-
rhsIsEmpty && !name.isConstructorName && !givenFlags.is(ParamOrAccessor) ||
345-
isAbstractType
346-
var flags = givenFlags
347-
if (lacksDefinition) flags |= Deferred
348-
if (tag == DEFDEF) flags |= Method
349-
if (ctx.mode.is(Mode.InSuperCall) && !flags.is(ParamOrAccessor)) flags |= InSuperCall
350-
if (ctx.owner.isClass) {
351-
if (tag == TYPEPARAM) flags |= Param | ExpandedName // TODO check name to determine ExpandedName
352-
else if (tag == PARAM) flags |= ParamAccessor
353-
}
354-
else if (isParamTag(tag)) flags |= Param
361+
val flags = normalizeFlags(tag, givenFlags, name, isAbstractType, rhsIsEmpty)
355362
val nameMatches = (_: Denotation).symbol.name == name
356363
val prevDenot: SymDenotation =
357364
if (ctx.owner.is(Package)) ctx.effectiveScope.lookup(name)
@@ -431,7 +438,6 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
431438
case CONTRAVARIANT => addFlag(Contravariant)
432439
case SCALA2X => addFlag(Scala2x)
433440
case DEFAULTparameterized => addFlag(DefaultParameterized)
434-
case DEFAULTinit => addFlag(DefaultInit)
435441
case INSUPERCALL => addFlag(InSuperCall)
436442
case PRIVATEqualified =>
437443
readByte()

0 commit comments

Comments
 (0)