diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 2e3661a52039..fb2b45268927 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -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. */ @@ -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 } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala index c062e3fbae8e..394399d6bf60 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala @@ -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 } diff --git a/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala b/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala index 9ba0a19ca311..b7345f49e1c0 100644 --- a/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala +++ b/compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala @@ -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. @@ -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 } @@ -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")