Skip to content

Commit 4695364

Browse files
committed
Fixes to pickling and unpickling untyped trees
Among others, adds new tag for EMPTYTREE. The serialized info is ambiguous otherwise. E.g. TypeBounds(Empty, B) and TypeBounds(B, Empty) serialize in the same way.
1 parent f0c3408 commit 4695364

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ object TastyFormat {
311311
final val MACRO = 34
312312
final val ERASED = 35
313313
final val PARAMsetter = 36
314+
final val EMPTYTREE = 37
314315

315316
// Cat. 2: tag Nat
316317

@@ -446,7 +447,7 @@ object TastyFormat {
446447

447448
/** Useful for debugging */
448449
def isLegalTag(tag: Int) =
449-
firstSimpleTreeTag <= tag && tag <= PARAMsetter ||
450+
firstSimpleTreeTag <= tag && tag <= EMPTYTREE ||
450451
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
451452
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
452453
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -543,6 +544,7 @@ object TastyFormat {
543544
case DEFAULTparameterized => "DEFAULTparameterized"
544545
case STABLE => "STABLE"
545546
case PARAMsetter => "PARAMsetter"
547+
case EMPTYTREE => "EMPTYTREE"
546548

547549
case SHAREDterm => "SHAREDterm"
548550
case SHAREDtype => "SHAREDtype"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,8 @@ class TreePickler(pickler: TastyPickler) {
859859
writeByte(TYPEDSPLICE)
860860
withLength { pickleTree(splice) }
861861
case Thicket(trees) =>
862-
trees.foreach(pickleUntyped)
862+
if (trees.isEmpty) writeByte(EMPTYTREE)
863+
else trees.foreach(pickleUntyped)
863864
case _ =>
864865
pickleUntyped(desugar(tree))
865866
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,11 @@ class TreeUnpickler(reader: TastyReader,
11991199
def readIdent(): untpd.Ident = readUntyped().asInstanceOf[untpd.Ident]
12001200

12011201
def readParams[T <: untpd.MemberDef](tag: Int): List[T] =
1202-
collectWhile(nextByte == tag)(readUntyped().asInstanceOf[T])
1202+
collectWhile(nextByte == tag) {
1203+
import untpd.modsDeco
1204+
val m: T = readUntyped().asInstanceOf[T]
1205+
m.withMods(m.mods | Param).asInstanceOf[T]
1206+
}
12031207

12041208
def readParamss(): List[List[untpd.ValDef]] =
12051209
collectWhile(nextByte == PARAMS) {
@@ -1242,8 +1246,11 @@ class TreeUnpickler(reader: TastyReader,
12421246
untpd.ByNameTypeTree(readUntyped())
12431247
case NAMEDARG =>
12441248
untpd.NamedArg(readName(), readUntyped())
1249+
case EMPTYTREE =>
1250+
untpd.EmptyTree
12451251
case SHAREDtype =>
1246-
assert(readNat() == 0)
1252+
val b = readNat()
1253+
assert(b == 0, i"bad shared type $b at $currentAddr when reading ${ctx.owner.ownersIterator.toList}%, %")
12471254
untpd.TypeTree()
12481255
case _ =>
12491256
untpd.Literal(readConstant(tag))
@@ -1349,7 +1356,11 @@ class TreeUnpickler(reader: TastyReader,
13491356
untpd.TypedSplice(readTerm())
13501357
case FUNCTION =>
13511358
val body = readUntyped()
1352-
val params = until(end)(readUntyped())
1359+
import untpd.modsDeco
1360+
val params = until(end)(readUntyped()).map {
1361+
case param: untpd.ValDef => param.withMods(param.mods | Param)
1362+
case param => param
1363+
}
13531364
untpd.Function(params, body)
13541365
case INFIXOP =>
13551366
untpd.InfixOp(readUntyped(), readIdent(), readUntyped())

0 commit comments

Comments
 (0)