@@ -7,14 +7,14 @@ 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
+ import dotty .tools .dotc .classpath .FileUtils .{ isTasty , isBestEffortTasty }
11
11
import dotty .tools .io .{ ClassPath , ClassRepresentation , AbstractFile }
12
12
import dotty .tools .backend .jvm .DottyBackendInterface .symExtensions
13
13
14
14
import Contexts ._ , Symbols ._ , Flags ._ , SymDenotations ._ , Types ._ , Scopes ._ , Names ._
15
15
import NameOps ._
16
16
import StdNames ._
17
- import classfile .{ClassfileParser , ClassfileTastyUUIDParser , BestEffortTastyParser }
17
+ import classfile .{ClassfileParser , ClassfileTastyUUIDParser }
18
18
import Decorators ._
19
19
20
20
import util .Stats
@@ -198,7 +198,7 @@ object SymbolLoaders {
198
198
enterToplevelsFromSource(owner, nameOf(classRep), src)
199
199
case (Some (bin), _) =>
200
200
val completer =
201
- if bin.isTasty then ctx.platform.newTastyLoader(bin)
201
+ if bin.isTasty || bin.isBestEffortTasty then ctx.platform.newTastyLoader(bin)
202
202
else ctx.platform.newClassLoader(bin)
203
203
enterClassAndModule(owner, nameOf(classRep), completer)
204
204
}
@@ -411,40 +411,38 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
411
411
412
412
override def doComplete (root : SymDenotation )(using Context ): Unit =
413
413
val (classRoot, moduleRoot) = rootDenots(root.asClass)
414
- val isBestEffortTasty = classfile.name.endsWith(" .betasty" )
415
- val result =
416
- if isBestEffortTasty then // TODO move to TastyLoader
417
- new BestEffortTastyParser (classfile, classRoot, moduleRoot)(ctx).run()
418
- else
419
- new ClassfileParser (classfile, classRoot, moduleRoot)(ctx).run()
420
-
421
- if (mayLoadTreesFromTasty || (isBestEffortTasty && ctx.withBestEffortTasty))
422
- result match {
423
- case Some (unpickler : tasty.DottyUnpickler ) =>
424
- classRoot.classSymbol.rootTreeOrProvider = unpickler
425
- moduleRoot.classSymbol.rootTreeOrProvider = unpickler
426
- case _ =>
427
- }
414
+ val result = new ClassfileParser (classfile, classRoot, moduleRoot)(ctx).run()
415
+ result match {
416
+ case Some (unpickler : tasty.DottyUnpickler ) =>
417
+ classRoot.classSymbol.rootTreeOrProvider = unpickler
418
+ moduleRoot.classSymbol.rootTreeOrProvider = unpickler
419
+ case _ =>
420
+ }
428
421
429
- private def mayLoadTreesFromTasty (using Context ): Boolean =
430
- ctx.settings.YretainTrees .value || ctx.settings.fromTasty.value
431
422
}
432
423
433
424
class TastyLoader (val tastyFile : AbstractFile ) extends SymbolLoader {
434
425
435
426
override def sourceFileOrNull : AbstractFile | Null = tastyFile
436
427
437
- def description (using Context ): String = " TASTy file " + tastyFile.toString
428
+ def description (using Context ): String =
429
+ if tastyFile.extension == " .betasty" then " Best Effort TASTy file " + tastyFile.toString
430
+ else " TASTy file " + tastyFile.toString
438
431
439
432
override def doComplete (root : SymDenotation )(using Context ): Unit =
440
433
val (classRoot, moduleRoot) = rootDenots(root.asClass)
434
+ val isBestEffortTasty = tastyFile.name.endsWith(" .betasty" )
441
435
val tastyBytes = tastyFile.toByteArray
442
- val unpickler = new tasty.DottyUnpickler (tastyBytes)
436
+ val unpickler = new tasty.DottyUnpickler (tastyBytes, withBestEffortTasty = ctx.withBestEffortTasty )
443
437
unpickler.enter(roots = Set (classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource ))
444
- if mayLoadTreesFromTasty then
438
+ if mayLoadTreesFromTasty || (isBestEffortTasty && ctx.withBestEffortTasty) then
445
439
classRoot.classSymbol.rootTreeOrProvider = unpickler
446
440
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
447
- checkTastyUUID(tastyFile, tastyBytes)
441
+ if isBestEffortTasty then
442
+ checkBeTastyUUID(tastyFile, tastyBytes)
443
+ ctx.setUsesBestEffortTasty()
444
+ else
445
+ checkTastyUUID(tastyFile, tastyBytes)
448
446
449
447
450
448
private def checkTastyUUID (tastyFile : AbstractFile , tastyBytes : Array [Byte ])(using Context ): Unit =
@@ -458,6 +456,9 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
458
456
// This will be the case in any of our tests that compile with `-Youtput-only-tasty`
459
457
report.inform(s " No classfiles found for $tastyFile when checking TASTy UUID " )
460
458
459
+ private def checkBeTastyUUID (tastyFile : AbstractFile , tastyBytes : Array [Byte ])(using Context ): Unit =
460
+ new TastyHeaderUnpickler (tastyBytes).readHeader(true )
461
+
461
462
private def mayLoadTreesFromTasty (using Context ): Boolean =
462
463
ctx.settings.YretainTrees .value || ctx.settings.fromTasty.value
463
464
}
0 commit comments