Skip to content

Commit 16204b4

Browse files
committed
Simplify JAR tasty loading
1 parent 52b3cdf commit 16204b4

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -436,33 +436,12 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
436436
load(root)
437437

438438
def load(root: SymDenotation)(using Context): Unit = {
439-
val tastyBytes = loadTastyBytes()
439+
val tastyBytes = tastyFile.toByteArray
440440
val (classRoot, moduleRoot) = rootDenots(root.asClass)
441441
unpickleTASTY(tastyBytes, classRoot, moduleRoot)
442442
// TODO check TASTy UUID matches classfile
443443
}
444444

445-
def loadTastyBytes(): Array[Byte] =
446-
tastyFile match { // TODO: simplify when #3552 is fixed
447-
case tastyFile: io.ZipArchive#Entry => // We are in a jar
448-
val stream = tastyFile.input
449-
try {
450-
val tastyOutStream = new ByteArrayOutputStream()
451-
val buffer = new Array[Byte](1024)
452-
var read = stream.read(buffer, 0, buffer.length)
453-
while (read != -1) {
454-
tastyOutStream.write(buffer, 0, read)
455-
read = stream.read(buffer, 0, buffer.length)
456-
}
457-
tastyOutStream.flush()
458-
tastyOutStream.toByteArray.nn
459-
} finally {
460-
stream.close()
461-
}
462-
case _ =>
463-
tastyFile.toByteArray
464-
}
465-
466445
def unpickleTASTY(bytes: Array[Byte], classRoot: ClassDenotation, moduleRoot: ClassDenotation)(using Context): tasty.DottyUnpickler = {
467446
val unpickler = new tasty.DottyUnpickler(bytes)
468447
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,11 @@ class ClassfileParser(
946946
case None =>
947947
report.error(em"Could not find TASTY for $classfile")
948948
case Some(tastyFile) =>
949-
val tastyLoader = new TastyLoader(tastyFile)
950-
val tastyBytes: Array[Byte] = tastyLoader.loadTastyBytes()
951949
val expectedUUID =
952950
val reader = new TastyReader(bytes, 0, 16)
953951
new UUID(reader.readUncompressedLong(), reader.readUncompressedLong())
954952
val tastyUUID =
953+
val tastyBytes: Array[Byte] = tastyFile.toByteArray
955954
new TastyHeaderUnpickler(tastyBytes).readHeader()
956955
if (expectedUUID != tastyUUID)
957956
report.warning(s"$classfile is out of sync with its TASTy file. Loaded TASTy file. Try cleaning the project to fix this issue", NoSourcePosition)

0 commit comments

Comments
 (0)