Skip to content

Commit dbd166a

Browse files
committed
Join logic for unpickling top level and term tasty
1 parent efb8115 commit dbd166a

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ class ClassfileParser(
758758

759759
def unpickleTASTY(bytes: Array[Byte]): Some[Embedded] = {
760760
val unpickler = new tasty.DottyUnpickler(bytes)
761-
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))
761+
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule), isTopLevel = true)
762762
Some(unpickler)
763763
}
764764

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ object PickledQuotes {
9999

100100
/** Unpickle TASTY bytes into it's tree */
101101
private def unpickle(bytes: Array[Byte], splices: Seq[Any], isType: Boolean)(implicit ctx: Context): Tree = {
102-
val unpickler = new TastyUnpickler(bytes, splices)
103102
if (pickling ne noPrinter) {
104103
println(i"**** unpickling quote from TASTY")
105104
new TastyPrinter(bytes).printContents()
106105
}
107106

108-
val tree =
109-
if (isType) unpickler.unpickleTypeTree()
110-
else unpickler.unpickleExpr()
107+
val unpickler = new TastyUnpickler(bytes, splices)
108+
unpickler.enter(Set(ctx.owner), isTopLevel = false)
109+
val tree = unpickler.tree
111110

112111
if (pickling ne noPrinter)
113112
println(i"**** unpickle quote ${tree.show}")

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@ class DottyUnpickler(bytes: Array[Byte]) extends ClassfileParser.Embedded with t
4343
/** Enter all toplevel classes and objects into their scopes
4444
* @param roots a set of SymDenotations that should be overwritten by unpickling
4545
*/
46-
def enter(roots: Set[SymDenotation])(implicit ctx: Context): Unit =
47-
treeUnpickler.enterTopLevel(roots)
48-
49-
def unpickleExpr()(implicit ctx: Context): Tree =
50-
treeUnpickler.unpickleExpr()
46+
def enter(roots: Set[SymDenotation], isTopLevel: Boolean)(implicit ctx: Context): Unit =
47+
treeUnpickler.enter(roots, isTopLevel)
5148

5249
def unpickleTypeTree()(implicit ctx: Context): Tree =
5350
treeUnpickler.unpickleTypeTree()

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class TreeUnpickler(reader: TastyReader,
5252
*/
5353
private val typeAtAddr = new mutable.HashMap[Addr, Type]
5454

55+
/** If the Tasty corresponds to a top level tree. `flase` is used used for quotes */
56+
private[this] var isTopLevel: Boolean = true
57+
5558
/** The root symbol denotation which are defined by the Tasty file associated with this
5659
* TreeUnpickler. Set by `enterTopLevel`.
5760
*/
@@ -71,18 +74,13 @@ class TreeUnpickler(reader: TastyReader,
7174
/** Enter all toplevel classes and objects into their scopes
7275
* @param roots a set of SymDenotations that should be overwritten by unpickling
7376
*/
74-
def enterTopLevel(roots: Set[SymDenotation])(implicit ctx: Context): Unit = {
77+
def enter(roots: Set[SymDenotation], isTopLevel: Boolean)(implicit ctx: Context): Unit = {
78+
this.isTopLevel = isTopLevel
7579
this.roots = roots
7680
val rdr = new TreeReader(reader).fork
7781
ownerTree = new OwnerTree(NoAddr, 0, rdr.fork, reader.endAddr)
78-
rdr.indexStats(reader.endAddr)
79-
}
80-
81-
def unpickleExpr()(implicit ctx: Context): Tree = {
82-
this.roots = Set(ctx.owner)
83-
val rdr = new TreeReader(reader).fork
84-
ownerTree = new OwnerTree(NoAddr, 0, rdr.fork, reader.endAddr)
85-
rdr.readTerm()
82+
if (isTopLevel)
83+
rdr.indexStats(reader.endAddr)
8684
}
8785

8886
def unpickleTypeTree()(implicit ctx: Context): Tree = {
@@ -95,7 +93,9 @@ class TreeUnpickler(reader: TastyReader,
9593
/** The unpickled trees */
9694
def unpickle()(implicit ctx: Context): List[Tree] = {
9795
assert(roots != null, "unpickle without previous enterTopLevel")
98-
new TreeReader(reader).readTopLevel()
96+
val rdr = new TreeReader(reader)
97+
if (isTopLevel) rdr.readTopLevel()
98+
else rdr.readTerm() :: Nil
9999
}
100100

101101
class Completer(owner: Symbol, reader: TastyReader) extends LazyType {

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Pickler extends Phase {
9494
val unpicklers =
9595
for ((cls, pickler) <- picklers) yield {
9696
val unpickler = new DottyUnpickler(pickler.assembleParts())
97-
unpickler.enter(roots = Set())
97+
unpickler.enter(roots = Set(), isTopLevel = true)
9898
cls -> unpickler
9999
}
100100
pickling.println("************* entered toplevel ***********")

0 commit comments

Comments
 (0)