Skip to content

Commit 087fdd0

Browse files
committed
reduce file-io in extractDependencies
1 parent 082dc6f commit 087fdd0

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ object FileUtils {
2020
def isClass: Boolean = !file.isDirectory && file.hasExtension("class") && !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")
24+
25+
def isTastyExtension: Boolean = file.hasExtension("tasty")
26+
2327
def isTasty: Boolean = !file.isDirectory && file.hasExtension("tasty")
2428

2529
def isScalaBinary: Boolean = file.isClass || file.isTasty

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

Lines changed: 12 additions & 10 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, isClass}
11+
import dotty.tools.dotc.classpath.FileUtils.{isTasty, isClassExtension, isTastyExtension}
1212
import dotty.tools.dotc.core.Contexts._
1313
import dotty.tools.dotc.core.Decorators._
1414
import dotty.tools.dotc.core.Flags._
@@ -458,21 +458,23 @@ class DependencyRecorder {
458458
}
459459

460460
val depFile = dep.toClass.associatedFile
461-
if (depFile != null) {
461+
if depFile != null then {
462462
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
463463
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
464-
val depClassFile =
465-
if depFile.isClass then depFile
466-
else depFile.resolveSibling(dep.toClass.binaryClassName + ".class")
467-
if (depClassFile != null) {
468-
// Dependency is external -- source is undefined
469-
processExternalDependency(depClassFile, dep.toClass.binaryClassName)
470-
} else if (allowLocal || depFile != sourceFile.file) {
464+
if depFile.isTastyExtension then
465+
val depClassFile = depFile.resolveSibling(depFile.name.stripSuffix(".tasty") + ".class")
466+
if depClassFile != null 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)
473+
else if allowLocal || depFile != sourceFile.file then
471474
// We cannot ignore dependencies coming from the same source file because
472475
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
473476
val toClassName = classNameAsString(dep.toClass)
474477
cb.classDependency(toClassName, fromClassName, dep.context)
475-
}
476478
}
477479
}
478480

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,15 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
102102
*/
103103
def lookupName(name: String, directory: Boolean): AbstractFile = {
104104
val child = givenPath / name
105-
if ((child.isDirectory && directory) || (child.isFile && !directory)) new PlainFile(child)
106-
else null
105+
if directory then
106+
if child.isDirectory /* IO! */ then
107+
new PlainFile(child)
108+
else
109+
null
110+
else if child.isFile /* IO! */ then
111+
new PlainFile(child)
112+
else
113+
null
107114
}
108115

109116
/** Does this abstract file denote an existing file? */

0 commit comments

Comments
 (0)