Skip to content

Commit e6ace3e

Browse files
committed
reduce file-io in extractDependencies
1 parent ce1ce99 commit e6ace3e

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
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: 11 additions & 8 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._
@@ -133,13 +133,16 @@ class ExtractDependencies extends Phase {
133133
if (depFile != null) {
134134
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
135135
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
136-
val depClassFile =
137-
if depFile.isClass then depFile
138-
else depFile.resolveSibling(dep.to.binaryClassName + ".class")
139-
if (depClassFile != null) {
140-
// Dependency is external -- source is undefined
141-
processExternalDependency(depClassFile, dep.to.binaryClassName)
142-
} else if (allowLocal || depFile != sourceFile.file) {
136+
if depFile.isTastyExtension then
137+
val depClassFile = depFile.resolveSibling(depFile.name.stripSuffix(".tasty") + ".class")
138+
if depClassFile != null then
139+
// did not find associated class file, e.g. for a TASTy-only classpath.
140+
// The file that Zinc recieves with binaryDependency is used to lookup any either any
141+
// generated non-local classes or produced xsbti.API associated with the file.
142+
processExternalDependency(depClassFile, dep.to.binaryClassName)
143+
else if depFile.isClassExtension then
144+
processExternalDependency(depFile, dep.to.binaryClassName)
145+
else if (allowLocal || depFile != sourceFile.file) {
143146
// We cannot ignore dependencies coming from the same source file because
144147
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
145148
val toClassName = classNameAsString(dep.to)

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)