@@ -50,7 +50,7 @@ object LambdaLift {
50
50
liftedDefs(tree.symbol.owner) = new mutable.ListBuffer
51
51
case _ =>
52
52
end deps
53
- export deps .{liftedOwner , free }
53
+ export deps .{liftedOwner }
54
54
55
55
/** A map storing the free variable proxies of functions and classes.
56
56
* For every function and class, this is a map from the free variables
@@ -71,19 +71,18 @@ object LambdaLift {
71
71
else sym.name.freshened
72
72
73
73
private def generateProxies ()(using Context ): Unit =
74
- for ((owner, freeValues) <- free.iterator) {
74
+ for owner <- deps.tracked do
75
+ val fvs = deps.freeVars(owner).toList
75
76
val newFlags = Synthetic | (if (owner.isClass) ParamAccessor | Private else Param )
76
- report.debuglog(i " free var proxy of ${owner.showLocated}: ${freeValues.toList} %, % " )
77
- proxyMap(owner) = {
78
- for ( fv <- freeValues.toList) yield {
77
+ report.debuglog(i " free var proxy of ${owner.showLocated}: $fvs %, % " )
78
+ val freeProxyPairs =
79
+ for fv <- fvs yield
79
80
val proxyName = newName(fv)
80
81
val proxy =
81
82
newSymbol(owner, proxyName.asTermName, newFlags, fv.info, coord = fv.coord)
82
83
.enteredAfter(thisPhase)
83
84
(fv, proxy)
84
- }
85
- }.toMap
86
- }
85
+ proxyMap(owner) = freeProxyPairs.toMap
87
86
88
87
private def liftedInfo (local : Symbol )(using Context ): Type = local.info match {
89
88
case MethodTpe (pnames, ptypes, restpe) =>
@@ -131,7 +130,7 @@ object LambdaLift {
131
130
initFlags = initFlags,
132
131
info = liftedInfo(local)).installAfter(thisPhase)
133
132
}
134
- for (local <- free.keys )
133
+ for (local <- deps.tracked )
135
134
if (! liftedOwner.contains(local))
136
135
local.copySymDenotation(info = liftedInfo(local)).installAfter(thisPhase)
137
136
}
@@ -190,10 +189,8 @@ object LambdaLift {
190
189
}
191
190
192
191
def addFreeArgs (sym : Symbol , args : List [Tree ])(using Context ): List [Tree ] =
193
- free get sym match {
194
- case Some (fvs) => fvs.toList.map(proxyRef(_)) ++ args
195
- case _ => args
196
- }
192
+ val fvs = deps.freeVars(sym)
193
+ if fvs.nonEmpty then fvs.toList.map(proxyRef(_)) ++ args else args
197
194
198
195
def addFreeParams (tree : Tree , proxies : List [Symbol ])(using Context ): Tree = proxies match {
199
196
case Nil => tree
@@ -319,7 +316,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
319
316
// reload them manually here.
320
317
// Note: If you tweak this code, make sure to test your changes with
321
318
// `Config.reuseSymDenotations` set to false to exercise this path more.
322
- if denot.isInstanceOf [NonSymSingleDenotation ] && lifter.free.contains (sym) then
319
+ if denot.isInstanceOf [NonSymSingleDenotation ] && lifter.deps.freeVars (sym).nonEmpty then
323
320
tree.qualifier.select(sym).withSpan(tree.span)
324
321
else tree
325
322
@@ -333,7 +330,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
333
330
val sym = tree.symbol
334
331
val lft = lifter
335
332
val paramsAdded =
336
- if ( lft.free.contains (sym)) lft.addFreeParams(tree, lft.proxies(sym)).asInstanceOf [DefDef ]
333
+ if lft.deps.freeVars (sym).nonEmpty then lft.addFreeParams(tree, lft.proxies(sym)).asInstanceOf [DefDef ]
337
334
else tree
338
335
if (lft.needsLifting(sym)) lft.liftDef(paramsAdded)
339
336
else paramsAdded
0 commit comments