Skip to content

Commit 6f37050

Browse files
committed
cache associated classfile of tasty
1 parent 087fdd0 commit 6f37050

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,19 @@ object Contexts {
272272
/** AbstractFile with given path, memoized */
273273
def getFile(name: String): AbstractFile = getFile(name.toTermName)
274274

275+
def getSiblingClassfile(tastyFile: AbstractFile): AbstractFile =
276+
base.siblingClassfiles.getOrElseUpdate(tastyFile, {
277+
val classfile0 = tastyFile.resolveSibling(tastyFile.name.stripSuffix(".tasty") + ".class")
278+
if classfile0 == null then
279+
val classfile = tastyFile.resolveSibling(tastyFile.name.stripSuffix(".tasty") + "$.class")
280+
if classfile == null then
281+
NoAbstractFile
282+
else
283+
classfile
284+
else
285+
classfile0
286+
})
287+
275288
private var related: SimpleIdentityMap[Phase | SourceFile, Context] | Null = null
276289

277290
private def lookup(key: Phase | SourceFile): Context | Null =
@@ -948,6 +961,7 @@ object Contexts {
948961
/** Sources and Files that were loaded */
949962
val sources: util.HashMap[AbstractFile, SourceFile] = util.HashMap[AbstractFile, SourceFile]()
950963
val files: util.HashMap[TermName, AbstractFile] = util.HashMap()
964+
val siblingClassfiles: util.HashMap[AbstractFile, AbstractFile] = util.HashMap()
951965

952966
// Types state
953967
/** A table for hash consing unique types */
@@ -1052,6 +1066,7 @@ object Contexts {
10521066
errorTypeMsg.clear()
10531067
sources.clear()
10541068
files.clear()
1069+
siblingClassfiles.clear()
10551070
comparers.clear() // forces re-evaluation of top and bottom classes in TypeComparer
10561071

10571072
// Test that access is single threaded

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,9 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
432432

433433

434434
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
435+
import dotty.tools.io.NoAbstractFile
436+
val classfile = ctx.getSiblingClassfile(tastyFile)
437+
if classfile != NoAbstractFile then
439438
val tastyUUID = new TastyHeaderUnpickler(tastyBytes).readHeader()
440439
new ClassfileTastyUUIDParser(classfile)(ctx).checkTastyUUID(tastyUUID)
441440
else

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import dotty.tools.dotc.core.Types._
2121
import dotty.tools.dotc.transform.SymUtils._
2222
import dotty.tools.dotc.util.{SrcPos, NoSourcePosition}
2323
import dotty.tools.io
24-
import dotty.tools.io.{AbstractFile, PlainFile, ZipArchive}
24+
import dotty.tools.io.{AbstractFile, PlainFile, ZipArchive, NoAbstractFile}
2525
import xsbti.UseScope
2626
import xsbti.api.DependencyContext
2727
import xsbti.api.DependencyContext._
@@ -462,8 +462,8 @@ class DependencyRecorder {
462462
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
463463
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
464464
if depFile.isTastyExtension then
465-
val depClassFile = depFile.resolveSibling(depFile.name.stripSuffix(".tasty") + ".class")
466-
if depClassFile != null then
465+
val depClassFile = ctx.getSiblingClassfile(depFile)
466+
if depClassFile != NoAbstractFile then
467467
// did not find associated class file, e.g. for a TASTy-only classpath.
468468
// The file that Zinc recieves with binaryDependency is used to lookup any either any
469469
// generated non-local classes or produced xsbti.API associated with the file.

compiler/src/dotty/tools/io/AbstractFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
253253
/** Returns the sibling abstract file in the parent of this abstract file or directory.
254254
* If there is no such file, returns `null`.
255255
*/
256-
def resolveSibling(name: String): AbstractFile | Null =
256+
final def resolveSibling(name: String): AbstractFile | Null =
257257
container.lookupName(name, directory = false)
258258

259259
private def fileOrSubdirectoryNamed(name: String, isDir: Boolean): AbstractFile =

compiler/src/dotty/tools/io/ZipArchive.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ abstract class ZipArchive(override val jpath: JPath, release: Option[String]) ex
7272
// have to keep this name for compat with sbt's compiler-interface
7373
def getArchive: ZipFile = null
7474
override def underlyingSource: Option[ZipArchive] = Some(self)
75-
override def resolveSibling(name: String): AbstractFile =
76-
parent.lookupName(name, directory = false)
75+
override def container: Entry = parent
7776
override def toString: String = self.path + "(" + path + ")"
7877
}
7978

0 commit comments

Comments
 (0)