@@ -24,10 +24,9 @@ import ast.desugar
24
24
25
25
import parsing .JavaParsers .OutlineJavaParser
26
26
import parsing .Parsers .OutlineParser
27
- import dotty .tools .tasty .{TastyHeaderUnpickler , UnpickleException , UnpicklerConfig }
27
+ import dotty .tools .tasty .{TastyHeaderUnpickler , UnpickleException , UnpicklerConfig , TastyVersion }
28
28
import dotty .tools .dotc .core .tasty .TastyUnpickler
29
29
30
-
31
30
object SymbolLoaders {
32
31
import ast .untpd .*
33
32
@@ -418,44 +417,54 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
418
417
419
418
class TastyLoader (val tastyFile : AbstractFile ) extends SymbolLoader {
420
419
421
- private val compUnitInfo = new CompilationUnitInfo (
422
- tastyFile,
423
- tastyVersionOpt = None // set on doComplete
420
+ private val unpickler : tasty.DottyUnpickler =
421
+ handleUnpicklingExceptions :
422
+ val tastyBytes = tastyFile.toByteArray
423
+ new tasty.DottyUnpickler (tastyBytes) // reads header and name table
424
+
425
+ def compilationUnitInfo : CompilationUnitInfo | Null =
426
+ val tastyHeader = unpickler.unpickler.header
427
+ new CompilationUnitInfo (
428
+ tastyFile,
429
+ tastyVersion = Some (
430
+ TastyVersion (
431
+ tastyHeader.majorVersion,
432
+ tastyHeader.minorVersion,
433
+ tastyHeader.experimentalVersion,
434
+ )
435
+ )
424
436
)
425
437
426
- def compilationUnitInfo : CompilationUnitInfo | Null = compUnitInfo
427
-
428
438
def description (using Context ): String = " TASTy file " + tastyFile.toString
429
439
430
440
override def doComplete (root : SymDenotation )(using Context ): Unit =
431
- try
441
+ handleUnpicklingExceptions :
442
+ checkTastyUUID()
432
443
val (classRoot, moduleRoot) = rootDenots(root.asClass)
433
- val tastyBytes = tastyFile.toByteArray
434
- val unpickler = new tasty.DottyUnpickler (tastyBytes)
435
- compUnitInfo.initTastyVersion(unpickler.tastyVersion)
436
444
unpickler.enter(roots = Set (classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource ))
437
445
if mayLoadTreesFromTasty then
438
446
classRoot.classSymbol.rootTreeOrProvider = unpickler
439
447
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
440
- checkTastyUUID(tastyFile, tastyBytes)
448
+
449
+ private def handleUnpicklingExceptions [T ](thunk : => T ): T =
450
+ try thunk
441
451
catch case e : RuntimeException =>
442
452
val message = e match
443
453
case e : UnpickleException =>
444
- i """ TASTy file ${tastyFile.canonicalPath} could not be read, failing with:
454
+ s """ TASTy file ${tastyFile.canonicalPath} could not be read, failing with:
445
455
| ${Option (e.getMessage).getOrElse(" " )}"""
446
456
case _ =>
447
- i """ TASTy file ${tastyFile.canonicalPath} is broken, reading aborted with ${e.getClass}
457
+ s """ TASTy file ${tastyFile.canonicalPath} is broken, reading aborted with ${e.getClass}
448
458
| ${Option (e.getMessage).getOrElse(" " )}"""
449
- if (ctx.debug) e.printStackTrace()
450
- throw IOException (message)
459
+ throw IOException (message, e)
451
460
452
461
453
- private def checkTastyUUID (tastyFile : AbstractFile , tastyBytes : Array [ Byte ] )(using Context ): Unit =
462
+ private def checkTastyUUID ()(using Context ): Unit =
454
463
val classfile =
455
464
val className = tastyFile.name.stripSuffix(" .tasty" )
456
465
tastyFile.resolveSibling(className + " .class" )
457
466
if classfile != null then
458
- val tastyUUID = new TastyHeaderUnpickler ( TastyUnpickler .scala3CompilerConfig, tastyBytes).readHeader()
467
+ val tastyUUID = unpickler.unpickler.header.uuid
459
468
new ClassfileTastyUUIDParser (classfile)(ctx).checkTastyUUID(tastyUUID)
460
469
else
461
470
// This will be the case in any of our tests that compile with `-Youtput-only-tasty`
0 commit comments