@@ -27,37 +27,41 @@ object LambdaLift {
27
27
val name : String = " lambdaLift"
28
28
29
29
/** 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 ):
37
31
38
32
/** The outer parameter of a constructor */
39
33
private val outerParam = new HashMap [Symbol , Symbol ]
40
34
41
35
/** Buffers for lifted out classes and methods, indexed by owner */
42
36
val liftedDefs : mutable.HashMap [Symbol , mutable.ListBuffer [Tree ]] = new HashMap
43
37
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 }
45
54
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 ]]
47
60
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)
50
62
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, _))
61
65
62
66
private def newName (sym : Symbol )(using Context ): Name =
63
67
if (sym.isAnonymousFunction && sym.owner.is(Method ))
@@ -133,9 +137,6 @@ object LambdaLift {
133
137
}
134
138
135
139
// initialization
136
- atPhase(thisPhase) {
137
- collectDependencies()
138
- }
139
140
atPhase(thisPhase.next) {
140
141
generateProxies()
141
142
liftLocals()
@@ -205,7 +206,7 @@ object LambdaLift {
205
206
206
207
/** Initialize proxy fields from proxy parameters and map `rhs` from fields to parameters */
207
208
def copyParams (rhs : Tree ) = {
208
- val fvs = freeVars(sym.owner)
209
+ val fvs = deps. freeVars(sym.owner).toList
209
210
val classProxies = fvs.map(proxyOf(sym.owner, _))
210
211
val constrProxies = fvs.map(proxyOf(sym, _))
211
212
report.debuglog(i " copy params ${constrProxies.map(_.showLocated)}%, % to ${classProxies.map(_.showLocated)}%, %} " )
0 commit comments