Dotty Documentation

0.6.0-bin-SNAPSHOT

class LabelDefs
extends MiniPhase

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 his phase Ychecking this phase required softening scoping rules as it intentionally allowed to break scoping rules inside methods for labels. This is modified by setting labelsReordered flag in Phases.

[-] Constructors

LabelDefs ( )

[-] Members

[+] private def collectLabelDefs ( tree: Tree ) ( implicit ctx: Context ) : MutableSymbolMap [ DefDef ]
[+] 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 ) : Tree