Skip to content

Commit 8888767

Browse files
committed
Hide liftedOwner
1 parent 1d55a77 commit 8888767

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

compiler/src/dotty/tools/dotc/transform/DependencyCollector.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import annotation.constructorOnly
2727
abstract class Dependencies(@constructorOnly rootContext: Context):
2828
import ast.tpd._
2929

30-
def enclosure(using Context): Symbol
31-
def isExpr(sym: Symbol)(using Context): Boolean
30+
protected def enclosure(using Context): Symbol
31+
protected def isExpr(sym: Symbol)(using Context): Boolean
3232

3333
type SymSet = TreeSet[Symbol]
3434

@@ -45,7 +45,7 @@ abstract class Dependencies(@constructorOnly rootContext: Context):
4545
* Note: During tree transform (which runs at phase LambdaLift + 1), liftedOwner
4646
* is also used to decide whether a method had a term owner before.
4747
*/
48-
val liftedOwner = new LinkedHashMap[Symbol, Symbol]
48+
private val depOwner = new LinkedHashMap[Symbol, Symbol]
4949

5050
/** A flag to indicate whether new free variables have been found */
5151
private var changedFreeVars: Boolean = _
@@ -63,6 +63,8 @@ abstract class Dependencies(@constructorOnly rootContext: Context):
6363

6464
def tracked: Iterable[Symbol] = free.keys
6565

66+
def dependentOwner: collection.Map[Symbol, Symbol] = depOwner
67+
6668
/** A symbol is local if it is owned by a term or a local trait,
6769
* or if it is a constructor of a local symbol.
6870
* Note: we count members of local traits as local since their free variables
@@ -80,12 +82,12 @@ abstract class Dependencies(@constructorOnly rootContext: Context):
8082
*/
8183
private def narrowLiftedOwner(sym: Symbol, owner: Symbol)(using Context): Unit =
8284
if sym.maybeOwner.isTerm
83-
&& owner.isProperlyContainedIn(liftedOwner(sym))
85+
&& owner.isProperlyContainedIn(depOwner(sym))
8486
&& owner != sym
8587
then
8688
report.log(i"narrow lifted $sym to $owner")
8789
changedLiftedOwner = true
88-
liftedOwner(sym) = owner
90+
depOwner(sym) = owner
8991

9092
private class NoPath extends Exception
9193

@@ -202,7 +204,7 @@ abstract class Dependencies(@constructorOnly rootContext: Context):
202204
narrowTo(tree.symbol.asClass)
203205
case tree: DefDef =>
204206
if sym.owner.isTerm then
205-
liftedOwner(sym) = sym.enclosingPackageClass
207+
depOwner(sym) = sym.enclosingPackageClass
206208
// this will make methods in supercall constructors of top-level classes owned
207209
// by the enclosing package, which means they will be static.
208210
// On the other hand, all other methods will be indirectly owned by their
@@ -215,7 +217,7 @@ abstract class Dependencies(@constructorOnly rootContext: Context):
215217
// the free variables of the class.
216218
symSet(called, sym) += sym.owner
217219
case tree: TypeDef =>
218-
if sym.owner.isTerm then liftedOwner(sym) = sym.topLevelClass.owner
220+
if sym.owner.isTerm then depOwner(sym) = sym.topLevelClass.owner
219221
case _ =>
220222
end process
221223

@@ -252,7 +254,7 @@ abstract class Dependencies(@constructorOnly rootContext: Context):
252254
do
253255
val normalizedCallee = callee.skipConstructor
254256
val calleeOwner = normalizedCallee.owner
255-
if calleeOwner.isTerm then narrowLiftedOwner(caller, liftedOwner(normalizedCallee))
257+
if calleeOwner.isTerm then narrowLiftedOwner(caller, depOwner(normalizedCallee))
256258
else
257259
assert(calleeOwner.is(Trait))
258260
// methods nested inside local trait methods cannot be lifted out

compiler/src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ object LambdaLift {
5050
liftedDefs(tree.symbol.owner) = new mutable.ListBuffer
5151
case _ =>
5252
end deps
53-
export deps.{liftedOwner}
5453

5554
/** A map storing the free variable proxies of functions and classes.
5655
* For every function and class, this is a map from the free variables
@@ -95,7 +94,7 @@ object LambdaLift {
9594
}
9695

9796
private def liftLocals()(using Context): Unit = {
98-
for ((local, lOwner) <- liftedOwner) {
97+
for ((local, lOwner) <- deps.dependentOwner) {
9998
val (newOwner, maybeStatic) =
10099
if (lOwner is Package) {
101100
val encClass = local.enclosingClass
@@ -131,7 +130,7 @@ object LambdaLift {
131130
info = liftedInfo(local)).installAfter(thisPhase)
132131
}
133132
for (local <- deps.tracked)
134-
if (!liftedOwner.contains(local))
133+
if (!deps.dependentOwner.contains(local))
135134
local.copySymDenotation(info = liftedInfo(local)).installAfter(thisPhase)
136135
}
137136

@@ -148,7 +147,8 @@ object LambdaLift {
148147
sym.enclosure == currentEnclosure
149148

150149
private def proxy(sym: Symbol)(using Context): Symbol = {
151-
def liftedEnclosure(sym: Symbol) = liftedOwner.getOrElse(sym, sym.enclosure)
150+
def liftedEnclosure(sym: Symbol) =
151+
deps.dependentOwner.getOrElse(sym, sym.enclosure)
152152
def searchIn(enclosure: Symbol): Symbol = {
153153
if (!enclosure.exists) {
154154
def enclosures(encl: Symbol): List[Symbol] =
@@ -228,7 +228,7 @@ object LambdaLift {
228228
EmptyTree
229229
}
230230

231-
def needsLifting(sym: Symbol): Boolean = liftedOwner contains sym
231+
def needsLifting(sym: Symbol): Boolean = deps.dependentOwner.contains(sym)
232232
end Lifter
233233
}
234234

0 commit comments

Comments
 (0)