Skip to content

Commit 898c48a

Browse files
committed
Infere if this TASTY tree is top level or a term
1 parent 4a5c690 commit 898c48a

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
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), isTopLevel = true)
761+
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))
762762
Some(unpickler)
763763
}
764764

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ object PickledQuotes {
110110
/** Unpickle TASTY bytes into it's tree */
111111
private def unpickle(bytes: Array[Byte], splices: Seq[Any])(implicit ctx: Context): Tree = {
112112
val unpickler = new TastyUnpickler(bytes, splices)
113-
unpickler.enter(Set(ctx.owner), isTopLevel = false)
113+
unpickler.enter(Set(ctx.owner))
114114
val tree = unpickler.tree
115115
if (pickling ne noPrinter) {
116116
println(i"**** unpickled quote for \n${tree.show}")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +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], isTopLevel: Boolean)(implicit ctx: Context): Unit =
47-
treeUnpickler.enter(roots, isTopLevel)
46+
def enter(roots: Set[SymDenotation])(implicit ctx: Context): Unit =
47+
treeUnpickler.enter(roots)
4848

4949
protected def treeSectionUnpickler(posUnpicklerOpt: Option[PositionUnpickler]): TreeSectionUnpickler = {
5050
new TreeSectionUnpickler(posUnpicklerOpt)

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ 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-
5855
/** The root symbol denotation which are defined by the Tasty file associated with this
5956
* TreeUnpickler. Set by `enterTopLevel`.
6057
*/
@@ -74,20 +71,19 @@ class TreeUnpickler(reader: TastyReader,
7471
/** Enter all toplevel classes and objects into their scopes
7572
* @param roots a set of SymDenotations that should be overwritten by unpickling
7673
*/
77-
def enter(roots: Set[SymDenotation], isTopLevel: Boolean)(implicit ctx: Context): Unit = {
78-
this.isTopLevel = isTopLevel
74+
def enter(roots: Set[SymDenotation])(implicit ctx: Context): Unit = {
7975
this.roots = roots
8076
val rdr = new TreeReader(reader).fork
8177
ownerTree = new OwnerTree(NoAddr, 0, rdr.fork, reader.endAddr)
82-
if (isTopLevel)
78+
if (rdr.isTopLevel)
8379
rdr.indexStats(reader.endAddr)
8480
}
8581

8682
/** The unpickled trees */
8783
def unpickle()(implicit ctx: Context): List[Tree] = {
8884
assert(roots != null, "unpickle without previous enterTopLevel")
8985
val rdr = new TreeReader(reader)
90-
if (isTopLevel) rdr.readTopLevel()
86+
if (rdr.isTopLevel) rdr.readTopLevel()
9187
else rdr.readTerm() :: Nil
9288
}
9389

@@ -849,15 +845,15 @@ class TreeUnpickler(reader: TastyReader,
849845
}
850846

851847
def skipToplevel()(implicit ctx: Context): Unit= {
852-
if (!isAtEnd)
853-
nextByte match {
854-
case IMPORT | PACKAGE =>
855-
skipTree()
856-
skipToplevel()
857-
case _ =>
858-
}
848+
if (!isAtEnd && isTopLevel) {
849+
skipTree()
850+
skipToplevel()
851+
}
859852
}
860853

854+
def isTopLevel(implicit ctx: Context): Boolean =
855+
nextByte == IMPORT || nextByte == PACKAGE
856+
861857
def readTopLevel()(implicit ctx: Context): List[Tree] = {
862858
@tailrec def read(acc: ListBuffer[Tree]): List[Tree] = nextByte match {
863859
case IMPORT | PACKAGE =>

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(), isTopLevel = true)
97+
unpickler.enter(roots = Set())
9898
cls -> unpickler
9999
}
100100
pickling.println("************* entered toplevel ***********")

0 commit comments

Comments
 (0)