Skip to content

Commit bd2b5dc

Browse files
committed
use export in ExtractDependencies
1 parent f91d4ec commit bd2b5dc

File tree

7 files changed

+41
-21
lines changed

7 files changed

+41
-21
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,6 @@ object Symbols {
370370

371371
private var myTree: TreeOrProvider = tpd.EmptyTree
372372

373-
private val myExportDependencies: util.HashSet[ClassSymbol] = util.HashSet()
374-
375-
def addExportDependency(dependency: ClassSymbol)(using Context): Unit =
376-
if !ctx.isAfterTyper then
377-
myExportDependencies += dependency
378-
379-
def exportDependencies: Iterator[ClassSymbol] = myExportDependencies.iterator
380-
381373
/** If this is a top-level class and `-Yretain-trees` (or `-from-tasty`) is set.
382374
* Returns the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
383375
* This will force the info of the class.

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,19 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
328328

329329
private def addInheritanceDependencies(tree: Template)(using Context): Unit =
330330
if (tree.parents.nonEmpty) {
331-
val cls = tree.symbol.owner.asClass
332-
val depContext =
333-
if cls.isLocal then LocalDependencyByInheritance
334-
else DependencyByInheritance
335-
val from = resolveDependencySource
336-
for parent <- tree.parents do
337-
_dependencies += ClassDependency(from, parent.tpe.classSymbol, depContext)
338-
for dep <- cls.exportDependencies if dep != cls do
339-
_dependencies += ClassDependency(from, dep, depContext)
331+
withinDepContext(tree.symbol.owner) { (depContext, from) =>
332+
for parent <- tree.parents do
333+
_dependencies += ClassDependency(from, parent.tpe.classSymbol, depContext)
334+
}
340335
}
341336

337+
private inline def withinDepContext(cls: Symbol)(inline op: (DependencyContext, Symbol) => Context ?=> Unit)(using Context): Unit =
338+
val depContext =
339+
if cls.isLocal then LocalDependencyByInheritance
340+
else DependencyByInheritance
341+
val from = resolveDependencySource
342+
op(depContext, from)
343+
342344
private def ignoreDependency(sym: Symbol)(using Context) =
343345
!sym.exists ||
344346
sym.isAbsent(canForce = false) || // ignore dependencies that have a symbol but do not exist.
@@ -366,6 +368,12 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
366368
addImported(sel.name)
367369
if sel.rename != sel.name then
368370
addUsedName(sel.rename, UseScope.Default)
371+
case exp @ Export(expr, selectors) =>
372+
val dep = expr.tpe.classSymbol
373+
if dep.exists && selectors.exists(_.isWildcard) then
374+
withinDepContext(ctx.owner.lexicallyEnclosingClass) { (depContext, from) =>
375+
_dependencies += ClassDependency(from, dep, depContext)
376+
}
369377
case t: TypeTree =>
370378
addTypeDependency(t.tpe)
371379
case ref: RefTree =>
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
class A {
2-
val b: B = new B
2+
3+
private val b: B = new B
34
export b._
5+
6+
class Inner {
7+
private val c: C = new C
8+
export c._
9+
}
10+
411
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class C {
2+
val y: Int = 47
3+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class B {
22
val x: Int = 23
3-
val y: Int = 30
3+
val z: Int = 30
44
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class C {
2+
val y: Int = 47
3+
val w: Int = 93
4+
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
> compile
22
$ copy-file changes/B1.scala B.scala
33
> compile
4-
# This should be 3 because of:
4+
$ copy-file changes/C1.scala C.scala
5+
> compile
6+
# This should be 5 because of:
57
# 1. the first `compile` call
68
# 2. the recompilation of B.scala
79
# 3. this recompilation triggering a recompilation of A.scala
810
# because B has a new member and A does a wildcard export
911
# of a value of type B.
10-
> checkIterations 3
12+
# 4. the recompilation of C.scala
13+
# 5. this recompilation triggering a recompilation of A.scala
14+
# because C has a new member and A.Inner does a wildcard export
15+
# of a value of type C.
16+
> checkIterations 5

0 commit comments

Comments
 (0)