@@ -24,10 +24,9 @@ import ast.desugar
2424
2525import parsing .JavaParsers .OutlineJavaParser
2626import parsing .Parsers .OutlineParser
27- import dotty .tools .tasty .{TastyHeaderUnpickler , UnpickleException , UnpicklerConfig }
27+ import dotty .tools .tasty .{TastyHeaderUnpickler , UnpickleException , UnpicklerConfig , TastyVersion }
2828import dotty .tools .dotc .core .tasty .TastyUnpickler
2929
30-
3130object SymbolLoaders {
3231 import ast .untpd .*
3332
@@ -418,44 +417,54 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
418417
419418class TastyLoader (val tastyFile : AbstractFile ) extends SymbolLoader {
420419
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+ )
424436 )
425437
426- def compilationUnitInfo : CompilationUnitInfo | Null = compUnitInfo
427-
428438 def description (using Context ): String = " TASTy file " + tastyFile.toString
429439
430440 override def doComplete (root : SymDenotation )(using Context ): Unit =
431- try
441+ handleUnpicklingExceptions :
442+ checkTastyUUID()
432443 val (classRoot, moduleRoot) = rootDenots(root.asClass)
433- val tastyBytes = tastyFile.toByteArray
434- val unpickler = new tasty.DottyUnpickler (tastyBytes)
435- compUnitInfo.initTastyVersion(unpickler.tastyVersion)
436444 unpickler.enter(roots = Set (classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource ))
437445 if mayLoadTreesFromTasty then
438446 classRoot.classSymbol.rootTreeOrProvider = unpickler
439447 moduleRoot.classSymbol.rootTreeOrProvider = unpickler
440- checkTastyUUID(tastyFile, tastyBytes)
448+
449+ private def handleUnpicklingExceptions [T ](thunk : => T ): T =
450+ try thunk
441451 catch case e : RuntimeException =>
442452 val message = e match
443453 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:
445455 | ${Option (e.getMessage).getOrElse(" " )}"""
446456 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}
448458 | ${Option (e.getMessage).getOrElse(" " )}"""
449- if (ctx.debug) e.printStackTrace()
450- throw IOException (message)
459+ throw IOException (message, e)
451460
452461
453- private def checkTastyUUID (tastyFile : AbstractFile , tastyBytes : Array [ Byte ] )(using Context ): Unit =
462+ private def checkTastyUUID ()(using Context ): Unit =
454463 val classfile =
455464 val className = tastyFile.name.stripSuffix(" .tasty" )
456465 tastyFile.resolveSibling(className + " .class" )
457466 if classfile != null then
458- val tastyUUID = new TastyHeaderUnpickler ( TastyUnpickler .scala3CompilerConfig, tastyBytes).readHeader()
467+ val tastyUUID = unpickler.unpickler.header.uuid
459468 new ClassfileTastyUUIDParser (classfile)(ctx).checkTastyUUID(tastyUUID)
460469 else
461470 // This will be the case in any of our tests that compile with `-Youtput-only-tasty`
0 commit comments