File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed
compiler/src/dotty/tools/dotc/sbt Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -240,16 +240,32 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
240
240
_responsibleForImports
241
241
}
242
242
243
+ private [this ] var lastOwner : Symbol = _
244
+ private [this ] var lastDepSource : Symbol = _
245
+
243
246
/**
244
247
* Resolves dependency source (that is, the closest non-local enclosing
245
- * class from a given `currentOwner` set by the `Traverser`).
246
- *
247
- * TODO: cache and/or optimise?
248
+ * class from a given `ctx.owner`
248
249
*/
249
250
private def resolveDependencySource (implicit ctx : Context ): Symbol = {
250
- def isNonLocalClass (sym : Symbol ) = sym.isClass && ! isLocal(sym)
251
- val source = ctx.owner.ownersIterator.find(isNonLocalClass).get
252
- if (source.is(PackageClass )) responsibleForImports else source
251
+ def resolveDepSource : Symbol = {
252
+ val owners = ctx.owner.ownersIterator
253
+ while (owners.hasNext) {
254
+ val source = owners.next()
255
+ def isLocal = ! owners.exists(_.isTerm) // side-effectful: consume iterator elements
256
+ if (source.isClass && isLocal) return source
257
+ else if (source.is(PackageClass )) return responsibleForImports
258
+ }
259
+ assert(false , " unreachable" )
260
+ NoSymbol
261
+ }
262
+
263
+ if (lastOwner != ctx.owner) {
264
+ lastOwner = ctx.owner
265
+ lastDepSource = resolveDepSource
266
+ }
267
+
268
+ lastDepSource
253
269
}
254
270
255
271
private def addUsedName (fromClass : Symbol , name : Name , scope : UseScope ): Unit = {
You can’t perform that action at this time.
0 commit comments