Skip to content

Commit daf159c

Browse files
committed
add todo, address comments
1 parent ea75836 commit daf159c

File tree

3 files changed

+45
-47
lines changed

3 files changed

+45
-47
lines changed

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

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -426,29 +426,28 @@ class DependencyRecorder {
426426

427427
private val _siblingClassfiles = new mutable.HashMap[PlainFile, Path]
428428

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-
})
429+
/**Constructs a sibling class to the `jpath`.
430+
* Does not validate if it exists as a real file.
431+
* The way this works is that by the end of compilation analysis,
432+
* there should be a corresponding NonLocalClass sent to zinc with the same class file name.
433+
*
434+
* FIXME: we still need a way to resolve the correct classfile when we split tasty and classes between
435+
* different outputs (e.g. stdlib-bootstrapped).
436+
*/
437+
private def siblingClass(pf: PlainFile): Path =
438+
_siblingClassfiles.getOrElseUpdate(pf, {
439+
val jpath = pf.jpath
440+
jpath.getParent.resolve(jpath.getFileName.toString.stripSuffix(".tasty") + ".class")
441+
})
443442

444443
/** Clear all state. */
445-
def clear(): Unit =
446-
_usedNames.clear()
447-
_classDependencies.clear()
448-
_siblingClassfiles.clear()
449-
lastOwner = NoSymbol
450-
lastDepSource = NoSymbol
451-
_responsibleForImports = NoSymbol
444+
def clear(): Unit =
445+
_usedNames.clear()
446+
_classDependencies.clear()
447+
_siblingClassfiles.clear()
448+
lastOwner = NoSymbol
449+
lastDepSource = NoSymbol
450+
_responsibleForImports = NoSymbol
452451

453452
/** Handles dependency on given symbol by trying to figure out if represents a term
454453
* that is coming from either source code (not necessarily compiled in this compilation
@@ -461,32 +460,34 @@ class DependencyRecorder {
461460
def binaryDependency(path: Path, binaryClassName: String) =
462461
cb.binaryDependency(path, binaryClassName, fromClassName, sourceFile, dep.context)
463462

464-
def processExternalDependency(depFile: AbstractFile, binaryClassName: String, convertTasty: Boolean) = {
465-
depFile match {
466-
case ze: ZipArchive#Entry => // The dependency comes from a JAR
467-
ze.underlyingSource match
468-
case Some(zip) if zip.jpath != null =>
469-
binaryDependency(zip.jpath, binaryClassName)
470-
case _ =>
471-
case pf: PlainFile => // The dependency comes from a class file, Zinc handles JRT filesystem
472-
binaryDependency(if convertTasty then pf.siblingClass else pf.jpath, binaryClassName)
473-
case _ =>
474-
internalError(s"Ignoring dependency $depFile of unknown class ${depFile.getClass}}", dep.fromClass.srcPos)
475-
}
476-
}
477-
478-
val depFile = dep.toClass.associatedFile
463+
val depClass = dep.toClass
464+
val depFile = depClass.associatedFile
479465
if depFile != null then {
480466
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
481467
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
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)
468+
val isTasty = depFile.hasTastyExtension
469+
470+
def processExternalDependency() = {
471+
val binaryClassName = depClass.binaryClassName
472+
depFile match {
473+
case ze: ZipArchive#Entry => // The dependency comes from a JAR
474+
ze.underlyingSource match
475+
case Some(zip) if zip.jpath != null =>
476+
binaryDependency(zip.jpath, binaryClassName)
477+
case _ =>
478+
case pf: PlainFile => // The dependency comes from a class file, Zinc handles JRT filesystem
479+
binaryDependency(if isTasty then siblingClass(pf) else pf.jpath, binaryClassName)
480+
case _ =>
481+
internalError(s"Ignoring dependency $depFile of unknown class ${depFile.getClass}}", dep.fromClass.srcPos)
482+
}
483+
}
484+
485+
if isTasty || depFile.hasClassExtension then
486+
processExternalDependency()
486487
else if allowLocal || depFile != sourceFile.file then
487488
// We cannot ignore dependencies coming from the same source file because
488489
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
489-
val toClassName = classNameAsString(dep.toClass)
490+
val toClassName = classNameAsString(depClass)
490491
cb.classDependency(toClassName, fromClassName, dep.context)
491492
}
492493
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
9797
/** Returns the path of this abstract file in a canonical form. */
9898
def canonicalPath: String = if (jpath == null) path else jpath.normalize.toString
9999

100-
/** Checks extension case insensitively. */
100+
/** Checks extension case insensitively. TODO: change to enum */
101101
def hasExtension(other: String): Boolean = extension == other.toLowerCase
102+
103+
/** Returns the extension of this abstract file. TODO: store as an enum to avoid costly comparisons */
102104
val extension: String = Path.extension(name)
103105

104106
/** The absolute file, if this is a relative file. */

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ 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-
121116
/** Does this abstract file denote an existing file? */
122117
def create(): Unit = if (!exists) givenPath.createFile()
123118

0 commit comments

Comments
 (0)