Skip to content

Commit 94a3cf2

Browse files
committed
Fix pickling of param setters
We now explicitly pickle the fact that they're param setters so that we can set the flag ParamAccessor at symbol creation, this is necessary because ParamAccessor is a FromStarts flag. Since this change isn't binary-compatible, bump TASTY to 6.0.
1 parent 3567d30 commit 94a3cf2

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ Standard-Section: "ASTs" TopLevelStat*
198198
SCALA2X // Imported from Scala2.x
199199
DEFAULTparameterized // Method with default parameters
200200
STABLE // Method that is assumed to be stable
201+
PARAMsetter // A setter without a body named `x_=` where `x` is pickled as a PARAM
201202
Annotation
202203
203204
Annotation = ANNOTATION Length tycon_Type fullAnnotation_Term
@@ -226,8 +227,8 @@ Standard Section: "Positions" Assoc*
226227
object TastyFormat {
227228

228229
final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
229-
val MajorVersion = 5
230-
val MinorVersion = 1
230+
val MajorVersion = 6
231+
val MinorVersion = 0
231232

232233
/** Tags used to serialize names */
233234
class NameTags {
@@ -268,6 +269,7 @@ object TastyFormat {
268269
// AST tags
269270
// Cat. 1: tag
270271

272+
final val firstSimpleTreeTag = UNITconst
271273
final val UNITconst = 2
272274
final val FALSEconst = 3
273275
final val TRUEconst = 4
@@ -300,6 +302,7 @@ object TastyFormat {
300302
final val STABLE = 31
301303
final val MACRO = 32
302304
final val ERASED = 33
305+
final val PARAMsetter = 34
303306

304307
// Cat. 2: tag Nat
305308

@@ -417,15 +420,14 @@ object TastyFormat {
417420

418421
final val HOLE = 255
419422

420-
final val firstSimpleTreeTag = UNITconst
421423
final val firstNatTreeTag = SHAREDterm
422424
final val firstASTTreeTag = THIS
423425
final val firstNatASTTreeTag = IDENT
424426
final val firstLengthTreeTag = PACKAGE
425427

426428
/** Useful for debugging */
427429
def isLegalTag(tag: Int) =
428-
firstSimpleTreeTag <= tag && tag <= ERASED ||
430+
firstSimpleTreeTag <= tag && tag <= PARAMsetter ||
429431
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
430432
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
431433
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -463,6 +465,7 @@ object TastyFormat {
463465
| SCALA2X
464466
| DEFAULTparameterized
465467
| STABLE
468+
| PARAMsetter
466469
| ANNOTATION
467470
| PRIVATEqualified
468471
| PROTECTEDqualified => true
@@ -518,6 +521,7 @@ object TastyFormat {
518521
case SCALA2X => "SCALA2X"
519522
case DEFAULTparameterized => "DEFAULTparameterized"
520523
case STABLE => "STABLE"
524+
case PARAMsetter => "PARAMsetter"
521525

522526
case SHAREDterm => "SHAREDterm"
523527
case SHAREDtype => "SHAREDtype"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ class TreePickler(pickler: TastyPickler) {
601601
if (flags is CaseAccessor) writeByte(CASEaccessor)
602602
if (flags is DefaultParameterized) writeByte(DEFAULTparameterized)
603603
if (flags is Stable) writeByte(STABLE)
604+
if ((flags is ParamAccessor) && sym.isSetter) writeByte(PARAMsetter)
604605
} else {
605606
if (flags is Sealed) writeByte(SEALED)
606607
if (flags is Abstract) writeByte(ABSTRACT)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ class TreeUnpickler(reader: TastyReader,
589589
case SCALA2X => addFlag(Scala2x)
590590
case DEFAULTparameterized => addFlag(DefaultParameterized)
591591
case STABLE => addFlag(Stable)
592+
case PARAMsetter =>
593+
addFlag(ParamAccessor)
592594
case PRIVATEqualified =>
593595
readByte()
594596
privateWithin = readType().typeSymbol
@@ -732,11 +734,6 @@ class TreeUnpickler(reader: TastyReader,
732734
vparamss.nestedMap(_.symbol), name == nme.CONSTRUCTOR)
733735
val resType = ctx.effectiveResultType(sym, typeParams, tpt.tpe)
734736
sym.info = ctx.methodType(typeParams, valueParamss, resType)
735-
if (sym.isSetter && sym.accessedFieldOrGetter.is(ParamAccessor)) {
736-
// reconstitute ParamAccessor flag of setters for var parameters, which is not pickled
737-
sym.setFlag(ParamAccessor)
738-
sym.resetFlag(Deferred)
739-
}
740737
DefDef(tparams, vparamss, tpt)
741738
case VALDEF =>
742739
val tpt = readTpt()(localCtx)

0 commit comments

Comments
 (0)