@@ -50,7 +50,7 @@ object LambdaLift {
5050 liftedDefs(tree.symbol.owner) = new mutable.ListBuffer
5151 case _ =>
5252 end deps
53- export deps .{liftedOwner , free }
53+ export deps .{liftedOwner }
5454
5555 /** A map storing the free variable proxies of functions and classes.
5656 * For every function and class, this is a map from the free variables
@@ -71,19 +71,18 @@ object LambdaLift {
7171 else sym.name.freshened
7272
7373 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
7576 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
7980 val proxyName = newName(fv)
8081 val proxy =
8182 newSymbol(owner, proxyName.asTermName, newFlags, fv.info, coord = fv.coord)
8283 .enteredAfter(thisPhase)
8384 (fv, proxy)
84- }
85- }.toMap
86- }
85+ proxyMap(owner) = freeProxyPairs.toMap
8786
8887 private def liftedInfo (local : Symbol )(using Context ): Type = local.info match {
8988 case MethodTpe (pnames, ptypes, restpe) =>
@@ -131,7 +130,7 @@ object LambdaLift {
131130 initFlags = initFlags,
132131 info = liftedInfo(local)).installAfter(thisPhase)
133132 }
134- for (local <- free.keys )
133+ for (local <- deps.tracked )
135134 if (! liftedOwner.contains(local))
136135 local.copySymDenotation(info = liftedInfo(local)).installAfter(thisPhase)
137136 }
@@ -190,10 +189,8 @@ object LambdaLift {
190189 }
191190
192191 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
197194
198195 def addFreeParams (tree : Tree , proxies : List [Symbol ])(using Context ): Tree = proxies match {
199196 case Nil => tree
@@ -319,7 +316,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
319316 // reload them manually here.
320317 // Note: If you tweak this code, make sure to test your changes with
321318 // `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
323320 tree.qualifier.select(sym).withSpan(tree.span)
324321 else tree
325322
@@ -333,7 +330,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisPhase =>
333330 val sym = tree.symbol
334331 val lft = lifter
335332 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 ]
337334 else tree
338335 if (lft.needsLifting(sym)) lft.liftDef(paramsAdded)
339336 else paramsAdded
0 commit comments