Dotty Documentation

0.5.0-bin-SNAPSHOT

class CapturedVars
extends MiniPhase with IdentityDenotTransformer

This phase translates variables that are captured in closures to heap-allocated refs.

[-] Constructors

CapturedVars ( )

[-] Members

[+] private class CollectCaptured
[+] private class RefInfo
[+] private var Captured : Location [ Set [ Symbol ] ]
[+] private var myRefInfo : RefInfo
[+] val phaseName : String

the following two members override abstract members in Transform

[+] private def Captured_= ( x$1: Location [ Set [ Symbol ] ] ) : Unit
[+] private def captured ( implicit ctx: Context ) : Set [ Symbol ]
[+] override def initContext ( ctx: FreshContext ) : Unit
[+] override def prepareForUnit ( tree: Tree ) ( implicit ctx: Context ) : Context
[+] override def prepareForValDef ( vdef: ValDef ) ( implicit ctx: Context ) : Context
[+] def refClass ( cls: Symbol , isVolatile: Boolean ) ( implicit ctx: Context ) : Symbol

The {Volatile|}{Int|Double|...|Object}Ref class corresponding to the class cls, depending on whether the reference should be @volatile

[+] private def refInfo ( implicit ctx: Context ) : RefInfo
[+] override def transformAssign ( tree: Assign ) ( implicit ctx: Context ) : Tree

If assignment is to a boxed ref type, e.g.

intRef.elem = expr

rewrite using a temporary var to

val ev$n = expr
intRef.elem = ev$n

That way, we avoid the problem that expr might contain a try that would run on a non-empty stack (which is illegal under JVM rules). Note that LiftTry has already run before, so such trys would not be eliminated.

Also: If the ref type lhs is followed by a cast (can be an artifact of nested translation), drop the cast.

[+] override def transformIdent ( id: Ident ) ( implicit ctx: Context ) : Tree
[+] override def transformValDef ( vdef: ValDef ) ( implicit ctx: Context ) : Tree