@@ -70,17 +70,14 @@ class ExtractDependencies extends Phase {
70
70
71
71
if (dumpInc) {
72
72
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 ]
75
74
Arrays .sort(names)
76
75
Arrays .sort(deps)
77
- Arrays .sort(inhDeps)
78
76
79
77
val pw = io.File (sourceFile.jpath).changeExtension(" inc" ).toFile.printWriter()
80
78
try {
81
79
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(" ," )}" )
84
81
} finally pw.close()
85
82
}
86
83
@@ -102,9 +99,7 @@ class ExtractDependencies extends Phase {
102
99
}
103
100
}
104
101
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)
108
103
}
109
104
}
110
105
}
@@ -131,12 +126,12 @@ class ExtractDependencies extends Phase {
131
126
* that is coming from either source code (not necessarily compiled in this compilation
132
127
* run) or from class file and calls respective callback method.
133
128
*/
134
- def recordDependency (dep : ClassDependency , context : DependencyContext , allowLocal : Boolean )(implicit ctx : Context ): Unit = {
129
+ def recordDependency (dep : ClassDependency )(implicit ctx : Context ): Unit = {
135
130
val fromClassName = classNameAsString(dep.from)
136
131
val sourceFile = ctx.compilationUnit.source.file.file
137
132
138
133
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)
140
135
141
136
def processExternalDependency (depFile : AbstractFile ) = {
142
137
def binaryClassName (classSegments : List [String ]) =
@@ -164,14 +159,16 @@ class ExtractDependencies extends Phase {
164
159
165
160
val depFile = dep.to.associatedFile
166
161
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
167
164
if (depFile.extension == " class" ) {
168
165
// Dependency is external -- source is undefined
169
166
processExternalDependency(depFile)
170
167
} else if (allowLocal || depFile.file != sourceFile) {
171
168
// We cannot ignore dependencies coming from the same source file because
172
169
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
173
170
val toClassName = classNameAsString(dep.to)
174
- ctx.sbtCallback.classDependency(toClassName, fromClassName, context)
171
+ ctx.sbtCallback.classDependency(toClassName, fromClassName, dep. context)
175
172
}
176
173
}
177
174
}
@@ -185,7 +182,7 @@ object ExtractDependencies {
185
182
sym.ownersIterator.exists(_.isTerm)
186
183
}
187
184
188
- private case class ClassDependency (from : Symbol , to : Symbol )
185
+ private case class ClassDependency (from : Symbol , to : Symbol , context : DependencyContext )
189
186
190
187
private final class NameUsedInClass {
191
188
// Default names and other scopes are separated for performance reasons
@@ -229,24 +226,16 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
229
226
import ExtractDependencies ._
230
227
231
228
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 ]
234
230
235
231
/** The names used in this class, this does not include names which are only
236
232
* defined and not referenced.
237
233
*/
238
234
def usedNames : collection.Map [String , NameUsedInClass ] = _usedNames
239
235
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.
243
237
*/
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
250
239
251
240
private def addUsedName (enclosingSym : Symbol , name : Name ) = {
252
241
val enclosingName =
@@ -263,10 +252,10 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
263
252
val tlClass = sym.topLevelClass
264
253
if (tlClass.ne(NoSymbol )) {
265
254
if (currentClass == defn.RootClass ) {
266
- _topLevelDependencies += ClassDependency (responsibleForImports, tlClass)
255
+ _dependencies += ClassDependency (responsibleForImports, tlClass, DependencyByMemberRef )
267
256
} else {
268
257
// Some synthetic type aliases like AnyRef do not belong to any class
269
- _topLevelDependencies += ClassDependency (currentClass, tlClass)
258
+ _dependencies += ClassDependency (currentClass, tlClass, DependencyByMemberRef )
270
259
}
271
260
}
272
261
addUsedName(nonLocalEnclosingClass(ctx.owner), sym.name.stripModuleClassSuffix)
@@ -289,7 +278,7 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
289
278
sym.isAnonymousClass
290
279
291
280
private def addInheritanceDependency (parent : Symbol )(implicit ctx : Context ): Unit =
292
- _topLevelInheritanceDependencies += ClassDependency (currentClass, parent.topLevelClass)
281
+ _dependencies += ClassDependency (currentClass, parent.topLevelClass, DependencyByInheritance )
293
282
294
283
private class PatMatDependencyTraverser (ctx0 : Context ) extends ExtractTypesCollector (ctx0) {
295
284
override protected def addDependency (symbol : Symbol )(implicit ctx : Context ): Unit = {
0 commit comments