Dotty Documentation

0.6.0-bin-SNAPSHOT

class LambdaLift
extends MiniPhase with IdentityDenotTransformer

This phase performs the necessary rewritings to eliminate classes and methods nested in other methods. In detail: 1. It adds all free variables of local functions as additional parameters (proxies). 2. It rebinds references to free variables to the corresponding proxies, 3. It lifts all local functions and classes out as far as possible, but at least to the enclosing class. 4. It stores free variables of non-trait classes as additional fields of the class. The fields serve as proxies for methods in the class, which avoids the need of passing additional parameters to these methods.

A particularly tricky case are local traits. These cannot store free variables as field proxies, because LambdaLift runs after Mixin, so the fields cannot be expanded anymore. Instead, methods of local traits get free variables of the trait as additional proxy parameters. The difference between local classes and local traits is illustrated by the two rewritings below.

def f(x: Int) = { def f(x: Int) = new C(x).f2 class C { ==> class C(x$1: Int) { def f2 = x def f2 = x$1 } } new C().f2 }

def f(x: Int) = { def f(x: Int) = new C().f2(x) trait T { ==> trait T def f2 = x def f2(x$1: Int) = x$1 } } class C extends T class C extends T new C().f2 }

[-] Constructors

LambdaLift ( )

[-] Members

[+] private var Lifter : Location [ Lifter ]
[+] val phaseName : String

the following two members override abstract members in Transform

[+] private def Lifter_= ( x$1: Location [ Lifter ] ) : Unit
[+] override def initContext ( ctx: FreshContext ) : Unit
[+] private def lifter ( implicit ctx: Context ) : Lifter
[+] override def prepareForUnit ( tree: Tree ) ( implicit ctx: Context ) : Context
[+] override def relaxedTypingInGroup : Boolean

If set, use relaxed typing for all phases in group

[+] override def runsAfterGroupsOf : Set [ Class [ Nothing <: Phase ] ]

List of names of phases that should have finished their processing of all compilation units before this phase starts

[+] override def transformApply ( tree: Apply ) ( implicit ctx: Context ) : Tree
[+] override def transformClosure ( tree: Closure ) ( implicit ctx: Context ) : Tree
[+] override def transformDefDef ( tree: DefDef ) ( implicit ctx: Context ) : Tree
[+] override def transformIdent ( tree: Ident ) ( implicit ctx: Context ) : Tree
[+] override def transformReturn ( tree: Return ) ( implicit ctx: Context ) : Tree
[+] override def transformTemplate ( tree: Template ) ( implicit ctx: Context ) : Tree
[+] override def transformTypeDef ( tree: TypeDef ) ( implicit ctx: Context ) : Tree