Skip to content

Commit f9e8b36

Browse files
committed
Check TASTy UUIDs in classfiles
1 parent 607e4d5 commit f9e8b36

File tree

4 files changed

+320
-195
lines changed

4 files changed

+320
-195
lines changed

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions
1414
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, Names._
1515
import NameOps._
1616
import StdNames._
17-
import classfile.ClassfileParser
17+
import classfile.{ClassfileParser, ClassfileTastyUUIDParser}
1818
import Decorators._
1919

2020
import util.Stats
@@ -24,6 +24,7 @@ import ast.desugar
2424

2525
import parsing.JavaParsers.OutlineJavaParser
2626
import parsing.Parsers.OutlineParser
27+
import dotty.tools.tasty.TastyHeaderUnpickler
2728

2829

2930
object SymbolLoaders {
@@ -421,14 +422,25 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
421422

422423
override def doComplete(root: SymDenotation)(using Context): Unit =
423424
val (classRoot, moduleRoot) = rootDenots(root.asClass)
424-
val unpickler =
425-
val tastyBytes = tastyFile.toByteArray
426-
new tasty.DottyUnpickler(tastyBytes)
425+
val tastyBytes = tastyFile.toByteArray
426+
val unpickler = new tasty.DottyUnpickler(tastyBytes)
427427
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))
428428
if mayLoadTreesFromTasty then
429429
classRoot.classSymbol.rootTreeOrProvider = unpickler
430430
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
431-
// TODO check TASTy UUID matches classfile
431+
checkTastyUUID(tastyFile, tastyBytes)
432+
433+
434+
private def checkTastyUUID(tastyFile: AbstractFile, tastyBytes: Array[Byte])(using Context): Unit =
435+
var classfile = tastyFile.resolveSibling(tastyFile.name.stripSuffix(".tasty") + ".class")
436+
if classfile == null then
437+
classfile = tastyFile.resolveSibling(tastyFile.name.stripSuffix(".tasty") + "$.class")
438+
if classfile != null then
439+
val tastyUUID = new TastyHeaderUnpickler(tastyBytes).readHeader()
440+
new ClassfileTastyUUIDParser(classfile)(ctx).checkTastyUUID(tastyUUID)
441+
else
442+
// This will be the case in any of our tests that compile with `-Youtput-only-tasty`
443+
report.inform(s"No classfiles found for $tastyFile when checking TASTy UUID")
432444

433445
private def mayLoadTreesFromTasty(using Context): Boolean =
434446
ctx.settings.YretainTrees.value || ctx.settings.fromTasty.value

0 commit comments

Comments
 (0)