Skip to content

Commit 4118884

Browse files
committed
Drop EMPTYTREE tag in Tasty
Needs a revised Inlined pickling format
1 parent 432d471 commit 4118884

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,11 +949,6 @@ object Trees {
949949
case ys => Thicket(ys)
950950
}
951951

952-
/** Extractor for the synthetic scrutinee tree of an implicit match */
953-
object ImplicitScrutinee {
954-
def apply() = Ident(nme.IMPLICITkw)
955-
def unapply(id: Ident): Boolean = id.name == nme.IMPLICITkw && !id.isInstanceOf[BackquotedIdent]
956-
}
957952
// ----- Helper classes for copying, transforming, accumulating -----------------
958953

959954
val cpy: TreeCopier

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ Standard-Section: "ASTs" TopLevelStat*
5555
Stat
5656
5757
Stat = Term
58-
VALDEF Length NameRef type_Term rhs_Term? Modifier*
59-
DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term?
60-
Modifier*
58+
ValOrDefDef
6159
TYPEDEF Length NameRef (type_Term | Template) Modifier*
6260
OBJECTDEF Length NameRef Template Modifier*
6361
IMPORT Length qual_Term Selector*
62+
ValOrDefDef = VALDEF Length NameRef type_Term rhs_Term? Modifier*
63+
DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term?
64+
Modifier*
6465
Selector = IMPORTED name_NameRef
6566
RENAMED to_NameRef
6667
@@ -85,7 +86,7 @@ Standard-Section: "ASTs" TopLevelStat*
8586
TYPED Length expr_Term ascriptionType_Tern
8687
ASSIGN Length lhs_Term rhs_Term
8788
BLOCK Length expr_Term Stat*
88-
INLINED Length call_Term expr_Term Stat*
89+
INLINED Length expr_Term call_Term? ValOrDefDef*
8990
LAMBDA Length meth_Term target_Type?
9091
IF Length cond_Term then_Term else_Term
9192
MATCH Length sel_Term CaseDef*
@@ -109,7 +110,6 @@ Standard-Section: "ASTs" TopLevelStat*
109110
ORtpt Length left_Term right_Term
110111
MATCHtpt Length bound_Term? sel_Term CaseDef*
111112
BYNAMEtpt underlying_Term
112-
EMPTYTREE
113113
SHAREDterm term_ASTRef
114114
HOLE Length idx_Nat arg_Tree*
115115
@@ -310,7 +310,6 @@ object TastyFormat {
310310
final val MACRO = 34
311311
final val ERASED = 35
312312
final val PARAMsetter = 36
313-
final val EMPTYTREE = 37
314313

315314
// Cat. 2: tag Nat
316315

@@ -441,7 +440,7 @@ object TastyFormat {
441440

442441
/** Useful for debugging */
443442
def isLegalTag(tag: Int) =
444-
firstSimpleTreeTag <= tag && tag <= EMPTYTREE ||
443+
firstSimpleTreeTag <= tag && tag <= PARAMsetter ||
445444
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
446445
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
447446
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -539,7 +538,6 @@ object TastyFormat {
539538
case DEFAULTparameterized => "DEFAULTparameterized"
540539
case STABLE => "STABLE"
541540
case PARAMsetter => "PARAMsetter"
542-
case EMPTYTREE => "EMPTYTREE"
543541

544542
case SHAREDterm => "SHAREDterm"
545543
case SHAREDtype => "SHAREDtype"

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,14 @@ class TreePickler(pickler: TastyPickler) {
448448
case Inlined(call, bindings, expansion) =>
449449
writeByte(INLINED)
450450
bindings.foreach(preRegister)
451-
withLength { pickleTree(call); pickleTree(expansion); bindings.foreach(pickleTree) }
451+
withLength {
452+
pickleTree(expansion)
453+
if (!call.isEmpty) pickleTree(call)
454+
bindings.foreach { b =>
455+
assert(b.isInstanceOf[DefDef] || b.isInstanceOf[ValDef])
456+
pickleTree(b)
457+
}
458+
}
452459
case Bind(name, body) =>
453460
registerDef(tree.symbol)
454461
writeByte(BIND)
@@ -563,8 +570,6 @@ class TreePickler(pickler: TastyPickler) {
563570
pickleTree(lo);
564571
if (hi ne lo) pickleTree(hi)
565572
}
566-
case EmptyTree =>
567-
writeByte(EMPTYTREE)
568573
case Hole(idx, args) =>
569574
writeByte(HOLE)
570575
withLength {

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,23 +1045,12 @@ class TreeUnpickler(reader: TastyReader,
10451045
ByNameTypeTree(readTpt())
10461046
case NAMEDARG =>
10471047
NamedArg(readName(), readTerm())
1048-
case EMPTYTREE =>
1049-
EmptyTree
10501048
case _ =>
10511049
readPathTerm()
10521050
}
10531051

10541052
def readLengthTerm(): Tree = {
10551053
val end = readEnd()
1056-
1057-
def readBlock(mkTree: (List[Tree], Tree) => Tree): Tree = {
1058-
val exprReader = fork
1059-
skipTree()
1060-
val stats = readStats(ctx.owner, end)
1061-
val expr = exprReader.readTerm()
1062-
mkTree(stats, expr)
1063-
}
1064-
10651054
val result =
10661055
(tag: @switch) match {
10671056
case SUPER =>
@@ -1080,10 +1069,22 @@ class TreeUnpickler(reader: TastyReader,
10801069
case ASSIGN =>
10811070
Assign(readTerm(), readTerm())
10821071
case BLOCK =>
1083-
readBlock(Block)
1072+
val exprReader = fork
1073+
skipTree()
1074+
val stats = readStats(ctx.owner, end)
1075+
val expr = exprReader.readTerm()
1076+
Block(stats, expr)
10841077
case INLINED =>
1085-
val call = readTerm()
1086-
readBlock((defs, expr) => Inlined(call, defs.asInstanceOf[List[MemberDef]], expr))
1078+
val exprReader = fork
1079+
skipTree()
1080+
def maybeCall = nextUnsharedTag match {
1081+
case VALDEF | DEFDEF => EmptyTree
1082+
case _ => readTerm()
1083+
}
1084+
val call = ifBefore(end)(maybeCall, EmptyTree)
1085+
val bindings = readStats(ctx.owner, end).asInstanceOf[List[ValOrDefDef]]
1086+
val expansion = exprReader.readTerm() // need bindings in scope, so needs to be read before
1087+
Inlined(call, bindings, expansion)
10871088
case IF =>
10881089
If(readTerm(), readTerm(), readTerm())
10891090
case LAMBDA =>
@@ -1298,8 +1299,10 @@ class TreeUnpickler(reader: TastyReader,
12981299
def search(cs: List[OwnerTree], current: Symbol): Symbol =
12991300
try cs match {
13001301
case ot :: cs1 =>
1301-
if (ot.addr.index == addr.index)
1302+
if (ot.addr.index == addr.index) {
1303+
assert(current.exists, i"no symbol at $addr")
13021304
current
1305+
}
13031306
else if (ot.addr.index < addr.index && addr.index < ot.end.index)
13041307
search(ot.children, reader.symbolAt(ot.addr))
13051308
else

0 commit comments

Comments
 (0)