@@ -27,37 +27,41 @@ object LambdaLift {
2727 val name : String = " lambdaLift"
2828
2929 /** The core lambda lift functionality. */
30- class Lifter (thisPhase : MiniPhase & DenotTransformer )(using Context ) extends DependencyCollector :
31-
32- /** A map storing the free variable proxies of functions and classes.
33- * For every function and class, this is a map from the free variables
34- * of that function or class to the proxy symbols accessing them.
35- */
36- private val proxyMap = new LinkedHashMap [Symbol , Map [Symbol , Symbol ]]
30+ class Lifter (thisPhase : MiniPhase & DenotTransformer )(using Context ):
3731
3832 /** The outer parameter of a constructor */
3933 private val outerParam = new HashMap [Symbol , Symbol ]
4034
4135 /** Buffers for lifted out classes and methods, indexed by owner */
4236 val liftedDefs : mutable.HashMap [Symbol , mutable.ListBuffer [Tree ]] = new HashMap
4337
44- def proxyOf (sym : Symbol , fv : Symbol ): Symbol = proxyMap.getOrElse(sym, Map .empty)(fv)
38+ val deps = new Dependencies (ctx.withPhase(thisPhase)):
39+ def enclosure (using Context ) = ctx.owner.enclosingMethod
40+ def isExpr (sym : Symbol )(using Context ): Boolean = sym.is(Method )
41+
42+ override def process (tree : Tree )(using Context ): Unit =
43+ super .process(tree)
44+ tree match
45+ case tree : DefDef if tree.symbol.isConstructor =>
46+ tree.termParamss.head.find(_.name == nme.OUTER ) match
47+ case Some (vdef) => outerParam(tree.symbol) = vdef.symbol
48+ case _ =>
49+ case tree : Template =>
50+ liftedDefs(tree.symbol.owner) = new mutable.ListBuffer
51+ case _ =>
52+ end deps
53+ export deps .{liftedOwner , free }
4554
46- def proxies (sym : Symbol ): List [Symbol ] = freeVars(sym).map(proxyOf(sym, _))
55+ /** A map storing the free variable proxies of functions and classes.
56+ * For every function and class, this is a map from the free variables
57+ * of that function or class to the proxy symbols accessing them.
58+ */
59+ private val proxyMap = new LinkedHashMap [Symbol , Map [Symbol , Symbol ]]
4760
48- def enclosure (using Context ) = ctx.owner.enclosingMethod
49- def isExpr (sym : Symbol )(using Context ): Boolean = sym.is(Method )
61+ def proxyOf (sym : Symbol , fv : Symbol ): Symbol = proxyMap.getOrElse(sym, Map .empty)(fv)
5062
51- override def process (tree : Tree )(using Context ): Unit =
52- super .process(tree)
53- tree match
54- case tree : DefDef if tree.symbol.isConstructor =>
55- tree.termParamss.head.find(_.name == nme.OUTER ) match
56- case Some (vdef) => outerParam(tree.symbol) = vdef.symbol
57- case _ =>
58- case tree : Template =>
59- liftedDefs(tree.symbol.owner) = new mutable.ListBuffer
60- case _ =>
63+ def proxies (sym : Symbol ): List [Symbol ] =
64+ deps.freeVars(sym).toList.map(proxyOf(sym, _))
6165
6266 private def newName (sym : Symbol )(using Context ): Name =
6367 if (sym.isAnonymousFunction && sym.owner.is(Method ))
@@ -133,9 +137,6 @@ object LambdaLift {
133137 }
134138
135139 // initialization
136- atPhase(thisPhase) {
137- collectDependencies()
138- }
139140 atPhase(thisPhase.next) {
140141 generateProxies()
141142 liftLocals()
@@ -205,7 +206,7 @@ object LambdaLift {
205206
206207 /** Initialize proxy fields from proxy parameters and map `rhs` from fields to parameters */
207208 def copyParams (rhs : Tree ) = {
208- val fvs = freeVars(sym.owner)
209+ val fvs = deps. freeVars(sym.owner).toList
209210 val classProxies = fvs.map(proxyOf(sym.owner, _))
210211 val constrProxies = fvs.map(proxyOf(sym, _))
211212 report.debuglog(i " copy params ${constrProxies.map(_.showLocated)}%, % to ${classProxies.map(_.showLocated)}%, %} " )
0 commit comments