Skip to content

Commit 14bbce6

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 33c078c commit 14bbce6

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

@@ -445,7 +446,7 @@ object TastyFormat {
445446

446447
/** Useful for debugging */
447448
def isLegalTag(tag: Int) =
448-
firstSimpleTreeTag <= tag && tag <= PARAMsetter ||
449+
firstSimpleTreeTag <= tag && tag <= EMPTYTREE ||
449450
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
450451
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
451452
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -542,6 +543,7 @@ object TastyFormat {
542543
case DEFAULTparameterized => "DEFAULTparameterized"
543544
case STABLE => "STABLE"
544545
case PARAMsetter => "PARAMsetter"
546+
case EMPTYTREE => "EMPTYTREE"
545547

546548
case SHAREDterm => "SHAREDterm"
547549
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
@@ -1203,7 +1203,11 @@ class TreeUnpickler(reader: TastyReader,
12031203
def readIdent(): untpd.Ident = readUntyped().asInstanceOf[untpd.Ident]
12041204

12051205
def readParams[T <: untpd.MemberDef](tag: Int): List[T] =
1206-
collectWhile(nextByte == tag)(readUntyped().asInstanceOf[T])
1206+
collectWhile(nextByte == tag) {
1207+
import untpd.modsDeco
1208+
val m: T = readUntyped().asInstanceOf[T]
1209+
m.withMods(m.mods | Param).asInstanceOf[T]
1210+
}
12071211

12081212
def readParamss(): List[List[untpd.ValDef]] =
12091213
collectWhile(nextByte == PARAMS) {
@@ -1246,8 +1250,11 @@ class TreeUnpickler(reader: TastyReader,
12461250
untpd.ByNameTypeTree(readUntyped())
12471251
case NAMEDARG =>
12481252
untpd.NamedArg(readName(), readUntyped())
1253+
case EMPTYTREE =>
1254+
untpd.EmptyTree
12491255
case SHAREDtype =>
1250-
assert(readNat() == 0)
1256+
val b = readNat()
1257+
assert(b == 0, i"bad shared type $b at $currentAddr when reading ${ctx.owner.ownersIterator.toList}%, %")
12511258
untpd.TypeTree()
12521259
case _ =>
12531260
untpd.Literal(readConstant(tag))
@@ -1353,7 +1360,11 @@ class TreeUnpickler(reader: TastyReader,
13531360
untpd.TypedSplice(readTerm())
13541361
case FUNCTION =>
13551362
val body = readUntyped()
1356-
val params = until(end)(readUntyped())
1363+
import untpd.modsDeco
1364+
val params = until(end)(readUntyped()).map {
1365+
case param: untpd.ValDef => param.withMods(param.mods | Param)
1366+
case param => param
1367+
}
13571368
untpd.Function(params, body)
13581369
case INFIXOP =>
13591370
untpd.InfixOp(readUntyped(), readIdent(), readUntyped())

0 commit comments

Comments
 (0)