Skip to content

Commit ea75836

Browse files
committed
revert context cache, use local cache, always give classfile
1 parent 529eaf4 commit ea75836

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

compiler/src/dotty/tools/dotc/classpath/FileUtils.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ object FileUtils {
1717
extension (file: AbstractFile) {
1818
def isPackage: Boolean = file.isDirectory && mayBeValidPackage(file.name)
1919

20-
def isClass: Boolean = !file.isDirectory && file.hasExtension("class") && !file.name.endsWith("$class.class")
20+
def isClass: Boolean = !file.isDirectory && hasClassExtension && !file.name.endsWith("$class.class")
2121
// FIXME: drop last condition when we stop being compatible with Scala 2.11
2222

23-
def isClassExtension: Boolean = file.hasExtension("class")
23+
def hasClassExtension: Boolean = file.hasExtension("class")
2424

25-
def isTastyExtension: Boolean = file.hasExtension("tasty")
25+
def hasTastyExtension: Boolean = file.hasExtension("tasty")
2626

27-
def isTasty: Boolean = !file.isDirectory && file.hasExtension("tasty")
27+
def isTasty: Boolean = !file.isDirectory && hasTastyExtension
2828

2929
def isScalaBinary: Boolean = file.isClass || file.isTasty
3030

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,6 @@ 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 className = tastyFile.name.stripSuffix(".tasty")
278-
val classfile0 = tastyFile.resolveSibling(className + ".class")
279-
if classfile0 == null then
280-
NoAbstractFile
281-
else
282-
classfile0
283-
})
284-
285275
private var related: SimpleIdentityMap[Phase | SourceFile, Context] | Null = null
286276

287277
private def lookup(key: Phase | SourceFile): Context | Null =
@@ -958,7 +948,6 @@ object Contexts {
958948
/** Sources and Files that were loaded */
959949
val sources: util.HashMap[AbstractFile, SourceFile] = util.HashMap[AbstractFile, SourceFile]()
960950
val files: util.HashMap[TermName, AbstractFile] = util.HashMap()
961-
val siblingClassfiles: util.HashMap[AbstractFile, AbstractFile] = util.HashMap()
962951

963952
// Types state
964953
/** A table for hash consing unique types */
@@ -1063,7 +1052,6 @@ object Contexts {
10631052
errorTypeMsg.clear()
10641053
sources.clear()
10651054
files.clear()
1066-
siblingClassfiles.clear()
10671055
comparers.clear() // forces re-evaluation of top and bottom classes in TypeComparer
10681056

10691057
// Test that access is single threaded

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

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

433433

434434
private def checkTastyUUID(tastyFile: AbstractFile, tastyBytes: Array[Byte])(using Context): Unit =
435-
import dotty.tools.io.NoAbstractFile
436-
val classfile = ctx.getSiblingClassfile(tastyFile)
437-
if classfile != NoAbstractFile then
435+
val classfile =
436+
val className = tastyFile.name.stripSuffix(".tasty")
437+
tastyFile.resolveSibling(className + ".class")
438+
if classfile != null then
438439
val tastyUUID = new TastyHeaderUnpickler(tastyBytes).readHeader()
439440
new ClassfileTastyUUIDParser(classfile)(ctx).checkTastyUUID(tastyUUID)
440441
else

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.nio.file.Path
88
import java.util.{Arrays, EnumSet}
99

1010
import dotty.tools.dotc.ast.tpd
11-
import dotty.tools.dotc.classpath.FileUtils.{isTasty, isClassExtension, isTastyExtension}
11+
import dotty.tools.dotc.classpath.FileUtils.{isTasty, hasClassExtension, hasTastyExtension}
1212
import dotty.tools.dotc.core.Contexts._
1313
import dotty.tools.dotc.core.Decorators._
1414
import dotty.tools.dotc.core.Flags._
@@ -424,10 +424,28 @@ class DependencyRecorder {
424424
classDependencies.foreach(recordClassDependency(cb, _))
425425
clear()
426426

427+
private val _siblingClassfiles = new mutable.HashMap[PlainFile, Path]
428+
429+
extension (pf: PlainFile)
430+
/**Constructs a sibling class to the `jpath`.
431+
* Does not validate if it exists as a real file.
432+
* The way this works is that by the end of compilation analysis,
433+
* there should be a corresponding NonLocalClass sent to zinc with the same class file name.
434+
*
435+
* FIXME: we still need a way to resolve the correct classfile when we split tasty and classes between
436+
* different outputs (e.g. stdlib-bootstrapped).
437+
*/
438+
private def siblingClass: Path =
439+
_siblingClassfiles.getOrElseUpdate(pf, {
440+
val jpath = pf.jpath
441+
jpath.getParent.resolve(jpath.getFileName.toString.stripSuffix(".tasty") + ".class")
442+
})
443+
427444
/** Clear all state. */
428445
def clear(): Unit =
429446
_usedNames.clear()
430447
_classDependencies.clear()
448+
_siblingClassfiles.clear()
431449
lastOwner = NoSymbol
432450
lastDepSource = NoSymbol
433451
_responsibleForImports = NoSymbol
@@ -440,18 +458,18 @@ class DependencyRecorder {
440458
val fromClassName = classNameAsString(dep.fromClass)
441459
val sourceFile = ctx.compilationUnit.source
442460

443-
def binaryDependency(file: Path, binaryClassName: String) =
444-
cb.binaryDependency(file, binaryClassName, fromClassName, sourceFile, dep.context)
461+
def binaryDependency(path: Path, binaryClassName: String) =
462+
cb.binaryDependency(path, binaryClassName, fromClassName, sourceFile, dep.context)
445463

446-
def processExternalDependency(depFile: AbstractFile, binaryClassName: String) = {
464+
def processExternalDependency(depFile: AbstractFile, binaryClassName: String, convertTasty: Boolean) = {
447465
depFile match {
448466
case ze: ZipArchive#Entry => // The dependency comes from a JAR
449467
ze.underlyingSource match
450468
case Some(zip) if zip.jpath != null =>
451469
binaryDependency(zip.jpath, binaryClassName)
452470
case _ =>
453471
case pf: PlainFile => // The dependency comes from a class file, Zinc handles JRT filesystem
454-
binaryDependency(pf.jpath, binaryClassName)
472+
binaryDependency(if convertTasty then pf.siblingClass else pf.jpath, binaryClassName)
455473
case _ =>
456474
internalError(s"Ignoring dependency $depFile of unknown class ${depFile.getClass}}", dep.fromClass.srcPos)
457475
}
@@ -461,15 +479,10 @@ class DependencyRecorder {
461479
if depFile != null then {
462480
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
463481
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
464-
if depFile.isTastyExtension then
465-
val depClassFile = ctx.getSiblingClassfile(depFile)
466-
if depClassFile != NoAbstractFile then
467-
// did not find associated class file, e.g. for a TASTy-only classpath.
468-
// The file that Zinc recieves with binaryDependency is used to lookup any either any
469-
// generated non-local classes or produced xsbti.API associated with the file.
470-
processExternalDependency(depClassFile, dep.toClass.binaryClassName)
471-
else if depFile.isClassExtension then
472-
processExternalDependency(depFile, dep.toClass.binaryClassName)
482+
if depFile.hasTastyExtension then
483+
processExternalDependency(depFile, dep.toClass.binaryClassName, convertTasty = true)
484+
else if depFile.hasClassExtension then
485+
processExternalDependency(depFile, dep.toClass.binaryClassName, convertTasty = false)
473486
else if allowLocal || depFile != sourceFile.file then
474487
// We cannot ignore dependencies coming from the same source file because
475488
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
113113
null
114114
}
115115

116+
final def fakeSibling(name: String): AbstractFile = {
117+
val child = givenPath.parent / name
118+
new PlainFile(child)
119+
}
120+
116121
/** Does this abstract file denote an existing file? */
117122
def create(): Unit = if (!exists) givenPath.createFile()
118123

0 commit comments

Comments
 (0)