A Tail Call Transformer
What it does:
Finds method calls in tail-position and replaces them with jumps.
A call is in a tail-position if it is the last instruction to be
executed in the body of a method. This is done by recursing over
the trees that may contain calls in tail-position (trees that can't
contain such calls are not transformed). However, they are not that
Self-recursive calls in tail-position are replaced by jumps to a
label at the beginning of the method. As the JVM provides no way to
jump from a method to another one, non-recursive calls in
tail-position are not optimized.
A method call is self-recursive if it calls the current method and
the method is final (otherwise, it could
be a call to an overridden method in a subclass). Furthermore, If
the method has type parameters, the call must contain these
parameters as type arguments. Recursive calls on a different instance
are optimized. Since 'this' is not a local variable, a dummy local val
is added and used as a label parameter. The backend knows to load
the corresponding argument in the 'this' (local at index 0). This dummy local
is never used and should be cleand up by dead code elimination (when enabled).
This phase has been moved before pattern matching to catch more
of the common cases of tail recursive functions. This means that
more cases should be taken into account (like nested function, and
If a method contains self-recursive calls, a label is added to at
the beginning of its body and the calls are replaced by jumps to
Assumes: Uncurry has been run already, and no multiple
parameter lists exit.
Rewrite this tree to contain no tail recursive calls