Skip to content

Commit 31a93a1

Browse files
committed
Merge two caches
1 parent cf20829 commit 31a93a1

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

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

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,14 @@ class ExtractDependencies extends Phase {
7070

7171
if (dumpInc) {
7272
val names = extractDeps.usedNames.map(_.toString).toArray[Object]
73-
val deps = extractDeps.topLevelDependencies.map(_.toString).toArray[Object]
74-
val inhDeps = extractDeps.topLevelInheritanceDependencies.map(_.toString).toArray[Object]
73+
val deps = extractDeps.dependencies.map(_.toString).toArray[Object]
7574
Arrays.sort(names)
7675
Arrays.sort(deps)
77-
Arrays.sort(inhDeps)
7876

7977
val pw = io.File(sourceFile.jpath).changeExtension("inc").toFile.printWriter()
8078
try {
8179
pw.println(s"// usedNames: ${names.mkString(",")}")
82-
pw.println(s"// topLevelDependencies: ${deps.mkString(",")}")
83-
pw.println(s"// topLevelInheritanceDependencies: ${inhDeps.mkString(",")}")
80+
pw.println(s"// Dependencies: ${deps.mkString(",")}")
8481
} finally pw.close()
8582
}
8683

@@ -102,9 +99,7 @@ class ExtractDependencies extends Phase {
10299
}
103100
}
104101

105-
// FIXME: https://github.com/sbt/zinc/commit/05482d131346d645375263e1420d2cd19b2ea6ef
106-
extractDeps.topLevelDependencies.foreach(dep => recordDependency(dep, DependencyByMemberRef, allowLocal = true))
107-
extractDeps.topLevelInheritanceDependencies.foreach(dep => recordDependency(dep, DependencyByInheritance, allowLocal = true))
102+
extractDeps.dependencies.foreach(recordDependency)
108103
}
109104
}
110105
}
@@ -131,12 +126,12 @@ class ExtractDependencies extends Phase {
131126
* that is coming from either source code (not necessarily compiled in this compilation
132127
* run) or from class file and calls respective callback method.
133128
*/
134-
def recordDependency(dep: ClassDependency, context: DependencyContext, allowLocal: Boolean)(implicit ctx: Context): Unit = {
129+
def recordDependency(dep: ClassDependency)(implicit ctx: Context): Unit = {
135130
val fromClassName = classNameAsString(dep.from)
136131
val sourceFile = ctx.compilationUnit.source.file.file
137132

138133
def binaryDependency(file: File, binaryClassName: String) =
139-
ctx.sbtCallback.binaryDependency(file, binaryClassName, fromClassName, sourceFile, context)
134+
ctx.sbtCallback.binaryDependency(file, binaryClassName, fromClassName, sourceFile, dep.context)
140135

141136
def processExternalDependency(depFile: AbstractFile) = {
142137
def binaryClassName(classSegments: List[String]) =
@@ -164,14 +159,16 @@ class ExtractDependencies extends Phase {
164159

165160
val depFile = dep.to.associatedFile
166161
if (depFile != null) {
162+
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
163+
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
167164
if (depFile.extension == "class") {
168165
// Dependency is external -- source is undefined
169166
processExternalDependency(depFile)
170167
} else if (allowLocal || depFile.file != sourceFile) {
171168
// We cannot ignore dependencies coming from the same source file because
172169
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
173170
val toClassName = classNameAsString(dep.to)
174-
ctx.sbtCallback.classDependency(toClassName, fromClassName, context)
171+
ctx.sbtCallback.classDependency(toClassName, fromClassName, dep.context)
175172
}
176173
}
177174
}
@@ -185,7 +182,7 @@ object ExtractDependencies {
185182
sym.ownersIterator.exists(_.isTerm)
186183
}
187184

188-
private case class ClassDependency(from: Symbol, to: Symbol)
185+
private case class ClassDependency(from: Symbol, to: Symbol, context: DependencyContext)
189186

190187
private final class NameUsedInClass {
191188
// Default names and other scopes are separated for performance reasons
@@ -229,24 +226,16 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
229226
import ExtractDependencies._
230227

231228
private[this] val _usedNames = new mutable.HashMap[String, NameUsedInClass]
232-
private[this] val _topLevelDependencies = new mutable.HashSet[ClassDependency]
233-
private[this] val _topLevelInheritanceDependencies = new mutable.HashSet[ClassDependency]
229+
private[this] val _dependencies = new mutable.HashSet[ClassDependency]
234230

235231
/** The names used in this class, this does not include names which are only
236232
* defined and not referenced.
237233
*/
238234
def usedNames: collection.Map[String, NameUsedInClass] = _usedNames
239235

240-
/** The set of top-level classes that the compilation unit depends on
241-
* because it refers to these classes or something defined in them.
242-
* This is always a superset of `topLevelInheritanceDependencies` by definition.
236+
/** The set of class dependencies from this compilation unit.
243237
*/
244-
def topLevelDependencies: Set[ClassDependency] = _topLevelDependencies
245-
246-
/** The set of top-level classes that the compilation unit extends or that
247-
* contain a non-top-level class that the compilaion unit extends.
248-
*/
249-
def topLevelInheritanceDependencies: Set[ClassDependency] = _topLevelInheritanceDependencies
238+
def dependencies: Set[ClassDependency] = _dependencies
250239

251240
private def addUsedName(enclosingSym: Symbol, name: Name) = {
252241
val enclosingName =
@@ -263,10 +252,10 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
263252
val tlClass = sym.topLevelClass
264253
if (tlClass.ne(NoSymbol)) {
265254
if (currentClass == defn.RootClass) {
266-
_topLevelDependencies += ClassDependency(responsibleForImports, tlClass)
255+
_dependencies += ClassDependency(responsibleForImports, tlClass, DependencyByMemberRef)
267256
} else {
268257
// Some synthetic type aliases like AnyRef do not belong to any class
269-
_topLevelDependencies += ClassDependency(currentClass, tlClass)
258+
_dependencies += ClassDependency(currentClass, tlClass, DependencyByMemberRef)
270259
}
271260
}
272261
addUsedName(nonLocalEnclosingClass(ctx.owner), sym.name.stripModuleClassSuffix)
@@ -289,7 +278,7 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
289278
sym.isAnonymousClass
290279

291280
private def addInheritanceDependency(parent: Symbol)(implicit ctx: Context): Unit =
292-
_topLevelInheritanceDependencies += ClassDependency(currentClass, parent.topLevelClass)
281+
_dependencies += ClassDependency(currentClass, parent.topLevelClass, DependencyByInheritance)
293282

294283
private class PatMatDependencyTraverser(ctx0: Context) extends ExtractTypesCollector(ctx0) {
295284
override protected def addDependency(symbol: Symbol)(implicit ctx: Context): Unit = {

0 commit comments

Comments
 (0)