Dotty Documentation

0.1.1-bin-SNAPSHOT

class LabelDefs
extends MiniPhaseTransform

Verifies that each Label DefDef has only a single address to jump back and reorders them such that they are not nested and this address is a fall-through address for the JVM.

<label> def foo(i: Int) = {
 <label> def bar = 0
 <label> def dough(i: Int) = if (i == 0) bar else foo(i-1)
 dough(i)
}

foo(100)

will get rewritten to:

<label> def foo(i: Int) = dough(i)
<label> def dough(i: Int) = if (i == 0) bar else foo(i-1)
<label> def bar = 2
 foo(100)

Proposed way to generate this pattern in backend is:

foo(100)
<jump foo>
<label> def foo(i: Int) = dough(i)
// <jump a>                           // unreachable
<label> def dough(i: Int) = if (i == 0) bar else foo(i-1)
// <jump a>                           // unreachable
<label> def bar = 2
// <jump a>                           // unreachable
<asm point a>

Unreachable jumps will be eliminated by local dead code analysis. After JVM is smart enough to remove next-line jumps

Note that Label DefDefs can be only nested in Block, otherwise no one would be able to call them Other DefDefs are eliminated

[-] Constructors

LabelDefs ( )

[-] Members

[+] object collectLabelDefs
[+] val beingAppended : HashSet [ Symbol ]
[+] var labelLevel : Int
[+] val queue : ArrayBuffer [ Tree ]
[+] def labelLevel_= ( x$1: Int ) : Unit
[+] def phaseName : String

A name given to the Phase that can be used to debug the compiler. For instance, it is possible to print trees after a given phase using:

$ ./bin/dotc -Xprint:<phaseNameHere> sourceFile.scala
[+] override def transformDefDef ( tree: DefDef ) ( implicit ctx: Context , info: TransformerInfo ) : Tree