Skip to content

Commit 51bc54a

Browse files
Merge pull request #3492 from dotty-staging/add-missing-pickler
Keep loaded pickled tasty when compiling from tasty
2 parents e675e6b + 88200a8 commit 51bc54a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ object Symbols {
604604

605605
/** If this is either:
606606
* - a top-level class and `-Yretain-trees` is set
607-
* - a top-level class loaded from TASTY and `-Xlink-optimise` is set
607+
* - a top-level class loaded from TASTY and `-tasty` or `-Xlink` is set
608608
* then return the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
609609
* This will force the info of the class.
610610
*/
@@ -615,7 +615,8 @@ object Symbols {
615615
assert(myTree.isEmpty)
616616
val body = unpickler.body(ctx.addMode(Mode.ReadPositions))
617617
myTree = body.headOption.getOrElse(tpd.EmptyTree)
618-
unpickler = null
618+
if (!ctx.settings.tasty.value)
619+
unpickler = null
619620
}
620621
myTree
621622
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ class TastyUnpickler(reader: TastyReader) {
9999
def unpickle[R](sec: SectionUnpickler[R]): Option[R] =
100100
for (reader <- sectionReader.get(sec.name)) yield
101101
sec.unpickle(reader, nameAtRef)
102+
103+
private[dotc] def bytes: Array[Byte] = reader.bytes
102104
}

compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ class ReadTastyTreesFromClasses extends FrontEnd {
2525
tree(className).flatMap {
2626
case (clsd, unpickled) =>
2727
if (unpickled.isEmpty) None
28-
else Some(CompilationUnit.mkCompilationUnit(clsd, unpickled, forceTrees = true))
29-
28+
else {
29+
val unit = CompilationUnit.mkCompilationUnit(clsd, unpickled, forceTrees = true)
30+
val cls = clsd.symbol.asClass
31+
unit.pickled += (cls -> cls.unpickler.unpickler.bytes)
32+
cls.unpickler = null
33+
Some(unit)
34+
}
3035
}
3136
}
3237
// The TASTY section in a/b/C.class may either contain a class a.b.C, an object a.b.C, or both.
@@ -41,12 +46,13 @@ class ReadTastyTreesFromClasses extends FrontEnd {
4146
val clsd = ctx.base.staticRef(className)
4247
ctx.base.staticRef(className) match {
4348
case clsd: ClassDenotation =>
49+
val cls = clsd.symbol.asClass
4450
def cannotUnpickle(reason: String) =
4551
ctx.error(s"class $className cannot be unpickled because $reason")
4652
def tryToLoad = clsd.infoOrCompleter match {
4753
case info: ClassfileLoader =>
4854
info.load(clsd)
49-
Option(clsd.symbol.asClass.tree).orElse {
55+
Option(cls.tree).orElse {
5056
cannotUnpickle(s"its class file ${info.classfile} does not have a TASTY attribute")
5157
None
5258
}
@@ -55,7 +61,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
5561
cannotUnpickle(s"its info of type ${info.getClass} is not a ClassfileLoader")
5662
None
5763
}
58-
Option(clsd.symbol.asClass.tree).orElse(tryToLoad).map(tree => (clsd, tree))
64+
Option(cls.tree).orElse(tryToLoad).map(tree => (clsd, tree))
5965

6066
case _ =>
6167
ctx.error(s"class not found: $className")

0 commit comments

Comments
 (0)