@@ -7,6 +7,7 @@ import java.nio.channels.ClosedByInterruptException
7
7
8
8
import scala .util .control .NonFatal
9
9
10
+ import dotty .tools .dotc .classpath .FileUtils .isTasty
10
11
import dotty .tools .io .{ ClassPath , ClassRepresentation , AbstractFile }
11
12
import dotty .tools .backend .jvm .DottyBackendInterface .symExtensions
12
13
@@ -192,10 +193,13 @@ object SymbolLoaders {
192
193
if (ctx.settings.verbose.value) report.inform(" [symloader] picked up newer source file for " + src.path)
193
194
enterToplevelsFromSource(owner, nameOf(classRep), src)
194
195
case (None , Some (src)) =>
195
- if (ctx.settings.verbose.value) report.inform(" [symloader] no class, picked up source file for " + src.path)
196
+ if (ctx.settings.verbose.value) report.inform(" [symloader] no class or tasty , picked up source file for " + src.path)
196
197
enterToplevelsFromSource(owner, nameOf(classRep), src)
197
198
case (Some (bin), _) =>
198
- enterClassAndModule(owner, nameOf(classRep), ctx.platform.newClassLoader(bin))
199
+ val completer =
200
+ if bin.isTasty then ctx.platform.newTastyLoader(bin)
201
+ else ctx.platform.newClassLoader(bin)
202
+ enterClassAndModule(owner, nameOf(classRep), completer)
199
203
}
200
204
201
205
def needCompile (bin : AbstractFile , src : AbstractFile ): Boolean =
@@ -404,20 +408,27 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
404
408
def description (using Context ): String = " class file " + classfile.toString
405
409
406
410
override def doComplete (root : SymDenotation )(using Context ): Unit =
407
- load(root)
408
-
409
- def load (root : SymDenotation )(using Context ): Unit = {
410
411
val (classRoot, moduleRoot) = rootDenots(root.asClass)
411
412
val classfileParser = new ClassfileParser (classfile, classRoot, moduleRoot)(ctx)
412
- val result = classfileParser.run()
413
- if (mayLoadTreesFromTasty)
414
- result match {
415
- case Some (unpickler : tasty.DottyUnpickler ) =>
416
- classRoot.classSymbol.rootTreeOrProvider = unpickler
417
- moduleRoot.classSymbol.rootTreeOrProvider = unpickler
418
- case _ =>
419
- }
420
- }
413
+ classfileParser.run()
414
+ }
415
+
416
+ class TastyLoader (val tastyFile : AbstractFile ) extends SymbolLoader {
417
+
418
+ override def sourceFileOrNull : AbstractFile | Null = tastyFile
419
+
420
+ def description (using Context ): String = " TASTy file " + tastyFile.toString
421
+
422
+ override def doComplete (root : SymDenotation )(using Context ): Unit =
423
+ val (classRoot, moduleRoot) = rootDenots(root.asClass)
424
+ val unpickler =
425
+ val tastyBytes = tastyFile.toByteArray
426
+ new tasty.DottyUnpickler (tastyBytes)
427
+ unpickler.enter(roots = Set (classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource ))
428
+ if mayLoadTreesFromTasty then
429
+ classRoot.classSymbol.rootTreeOrProvider = unpickler
430
+ moduleRoot.classSymbol.rootTreeOrProvider = unpickler
431
+ // TODO check TASTy UUID matches classfile
421
432
422
433
private def mayLoadTreesFromTasty (using Context ): Boolean =
423
434
ctx.settings.YretainTrees .value || ctx.settings.fromTasty.value
0 commit comments