Skip to content

Commit e4d25ef

Browse files
committed
cache associated classfile of tasty
1 parent 745204d commit e4d25ef

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
@@ -262,6 +262,19 @@ object Contexts {
262262
/** AbstractFile with given path, memoized */
263263
def getFile(name: String): AbstractFile = getFile(name.toTermName)
264264

265+
def getSiblingClassfile(tastyFile: AbstractFile): AbstractFile =
266+
base.siblingClassfiles.getOrElseUpdate(tastyFile, {
267+
val classfile0 = tastyFile.resolveSibling(tastyFile.name.stripSuffix(".tasty") + ".class")
268+
if classfile0 == null then
269+
val classfile = tastyFile.resolveSibling(tastyFile.name.stripSuffix(".tasty") + "$.class")
270+
if classfile == null then
271+
NoAbstractFile
272+
else
273+
classfile
274+
else
275+
classfile0
276+
})
277+
265278
private var related: SimpleIdentityMap[Phase | SourceFile, Context] | Null = null
266279

267280
private def lookup(key: Phase | SourceFile): Context | Null =
@@ -938,6 +951,7 @@ object Contexts {
938951
/** Sources and Files that were loaded */
939952
val sources: util.HashMap[AbstractFile, SourceFile] = util.HashMap[AbstractFile, SourceFile]()
940953
val files: util.HashMap[TermName, AbstractFile] = util.HashMap()
954+
val siblingClassfiles: util.HashMap[AbstractFile, AbstractFile] = util.HashMap()
941955

942956
// Types state
943957
/** A table for hash consing unique types */
@@ -1042,6 +1056,7 @@ object Contexts {
10421056
errorTypeMsg.clear()
10431057
sources.clear()
10441058
files.clear()
1059+
siblingClassfiles.clear()
10451060
comparers.clear() // forces re-evaluation of top and bottom classes in TypeComparer
10461061

10471062
// 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
@@ -20,7 +20,7 @@ import dotty.tools.dotc.core.Types._
2020
import dotty.tools.dotc.transform.SymUtils._
2121
import dotty.tools.dotc.util.{SrcPos, NoSourcePosition}
2222
import dotty.tools.io
23-
import dotty.tools.io.{AbstractFile, PlainFile, ZipArchive}
23+
import dotty.tools.io.{AbstractFile, PlainFile, ZipArchive, NoAbstractFile}
2424
import xsbti.UseScope
2525
import xsbti.api.DependencyContext
2626
import xsbti.api.DependencyContext._
@@ -143,8 +143,8 @@ class ExtractDependencies extends Phase {
143143
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
144144
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
145145
if depFile.isTastyExtension then
146-
val depClassFile = depFile.resolveSibling(depFile.name.stripSuffix(".tasty") + ".class")
147-
if depClassFile != null then
146+
val depClassFile = ctx.getSiblingClassfile(depFile)
147+
if depClassFile != NoAbstractFile then
148148
// did not find associated class file, e.g. for a TASTy-only classpath.
149149
// The file that Zinc recieves with binaryDependency is used to lookup any either any
150150
// 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)