Skip to content

Keep loaded pickled tasty when compiling from tasty #3492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ object Symbols {

/** If this is either:
* - a top-level class and `-Yretain-trees` is set
* - a top-level class loaded from TASTY and `-Xlink-optimise` is set
* - a top-level class loaded from TASTY and `-tasty` or `-Xlink` is set
* then return the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
* This will force the info of the class.
*/
Expand All @@ -615,7 +615,8 @@ object Symbols {
assert(myTree.isEmpty)
val body = unpickler.body(ctx.addMode(Mode.ReadPositions))
myTree = body.headOption.getOrElse(tpd.EmptyTree)
unpickler = null
if (!ctx.settings.tasty.value)
unpickler = null
}
myTree
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ class TastyUnpickler(reader: TastyReader) {
def unpickle[R](sec: SectionUnpickler[R]): Option[R] =
for (reader <- sectionReader.get(sec.name)) yield
sec.unpickle(reader, nameAtRef)

private[dotc] def bytes: Array[Byte] = reader.bytes
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ class ReadTastyTreesFromClasses extends FrontEnd {
tree(className).flatMap {
case (clsd, unpickled) =>
if (unpickled.isEmpty) None
else Some(CompilationUnit.mkCompilationUnit(clsd, unpickled, forceTrees = true))

else {
val unit = CompilationUnit.mkCompilationUnit(clsd, unpickled, forceTrees = true)
val cls = clsd.symbol.asClass
unit.pickled += (cls -> cls.unpickler.unpickler.bytes)
cls.unpickler = null
Some(unit)
}
}
}
// The TASTY section in a/b/C.class may either contain a class a.b.C, an object a.b.C, or both.
Expand All @@ -41,12 +46,13 @@ class ReadTastyTreesFromClasses extends FrontEnd {
val clsd = ctx.base.staticRef(className)
ctx.base.staticRef(className) match {
case clsd: ClassDenotation =>
val cls = clsd.symbol.asClass
def cannotUnpickle(reason: String) =
ctx.error(s"class $className cannot be unpickled because $reason")
def tryToLoad = clsd.infoOrCompleter match {
case info: ClassfileLoader =>
info.load(clsd)
Option(clsd.symbol.asClass.tree).orElse {
Option(cls.tree).orElse {
cannotUnpickle(s"its class file ${info.classfile} does not have a TASTY attribute")
None
}
Expand All @@ -55,7 +61,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
cannotUnpickle(s"its info of type ${info.getClass} is not a ClassfileLoader")
None
}
Option(clsd.symbol.asClass.tree).orElse(tryToLoad).map(tree => (clsd, tree))
Option(cls.tree).orElse(tryToLoad).map(tree => (clsd, tree))

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