dotty.tools.dotc.transform

TailRec

Related Docs: object TailRec | package transform

class TailRec extends MiniPhaseTransform with DenotTransformer with FullParameterization

A Tail Rec Transformer

Self Type
TailRec
Version

1.1

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 many.

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).

Recursive calls on a different instance are optimized. Since 'this' is not a local variable it s added as a label parameter.

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 pattern cases).

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 that label.

In scalac, If the method had type parameters, the call must contain same parameters as type arguments. This is no longer case in dotc. In scalac, this is named tailCall but it does only provide optimization for self recursive functions, that's why it's renamed to tailrec

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. TailRec
  2. FullParameterization
  3. DenotTransformer
  4. MiniPhaseTransform
  5. MiniPhase
  6. Phase
  7. TreeTransform
  8. DotClass
  9. AnyRef
  10. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new TailRec()

Type Members

  1. class TailRecElimination extends ast.tpd.TreeMap

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def <=(that: Phase): Boolean

    Definition Classes
    Phase
  4. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  5. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  6. def atGroupEnd[T](action: (Context) ⇒ T)(implicit ctx: Context, info: TransformerInfo): T

    Definition Classes
    TreeTransform
  7. def checkPostCondition(tree: ast.tpd.Tree)(implicit ctx: Context): Unit

    Check what the phase achieves, to be called at any point after it is finished.

    Check what the phase achieves, to be called at any point after it is finished.

    Definition Classes
    Phase
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def description: String

    Definition Classes
    Phase
  10. def end: PhaseId

    Definition Classes
    Phase
  11. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  13. final def erasedTypes: Boolean

    Definition Classes
    Phase
  14. def exists: Boolean

    Definition Classes
    Phase
  15. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def flatClasses: Boolean

    Definition Classes
    Phase
  17. def forwarder(derived: TermSymbol, originalDef: ast.tpd.DefDef, abstractOverClass: Boolean = true, liftThisType: Boolean = false)(implicit ctx: Context): ast.tpd.Tree

    A forwarder expression which calls derived, passing along

    A forwarder expression which calls derived, passing along

    • if abstractOverClass the type parameters and enclosing class parameters of originalDef,
    • the this of the enclosing class,
    • the value parameters of the original method originalDef.
    Definition Classes
    FullParameterization
  18. def fullyParameterizedDef(derived: TermSymbol, originalDef: ast.tpd.DefDef, abstractOverClass: Boolean = true)(implicit ctx: Context): ast.tpd.Tree

    Given an instance method definition originalDef, return a fully parameterized method definition derived from originalDef, which has derived as symbol and fullyParameterizedType(originalDef.symbol.info) as info.

    Given an instance method definition originalDef, return a fully parameterized method definition derived from originalDef, which has derived as symbol and fullyParameterizedType(originalDef.symbol.info) as info. abstractOverClass defines weather the DefDef should abstract over type parameters of class that contained original defDef

    Definition Classes
    FullParameterization
  19. def fullyParameterizedType(info: Type, clazz: ClassSymbol, abstractOverClass: Boolean = true, liftThisType: Boolean = false)(implicit ctx: Context): Type

    Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional parameters.

    Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional parameters. Example:

    class Foo[+A <: AnyRef](val xs: List[A]) extends AnyVal { def baz[B >: A](x: B): List[B] = ... }

    leads to:

    object Foo { def extension$baz[B >: A <: Any, A >: Nothing <: AnyRef]($this: Foo[A])(x: B): List[B] }

    If a self type is present, $this has this self type as its type.

    abstractOverClass

    if true, include the type parameters of the class in the method's list of type parameters.

    liftThisType

    if true, require created $this to be $this: (Foo[A] & Foo,this). This is needed if created member stays inside scope of Foo(as in tailrec)

    Definition Classes
    FullParameterization
  20. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  21. final def hasNext: Boolean

    Definition Classes
    Phase
  22. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  23. def id: Int

    The sequence position of this phase in the given context where 0 is reserved for NoPhase and the first real phase is at position 1.

    The sequence position of this phase in the given context where 0 is reserved for NoPhase and the first real phase is at position 1. -1 if the phase is not installed in the context.

    Definition Classes
    Phase
  24. var idx: Int

    id of this mini phase in group

    id of this mini phase in group

    Definition Classes
    MiniPhase
  25. def init(base: ContextBase, id: Int): Unit

    Attributes
    protected[dotty.tools.dotc.core.Phases]
    Definition Classes
    Phase
  26. def init(base: ContextBase, start: Int, end: Int): Unit

    Attributes
    protected[dotty.tools.dotc.core.Phases]
    Definition Classes
    Phase
  27. def isCheckable: Boolean

    Output should be checkable by TreeChecker

    Output should be checkable by TreeChecker

    Definition Classes
    Phase
  28. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  29. def isTyper: Boolean

    Is this phase the standard typerphase? True for FrontEnd, but not for other first phases (such as FromTasty).

    Is this phase the standard typerphase? True for FrontEnd, but not for other first phases (such as FromTasty). The predicate is tested in some places that perform checks and corrections. It's different from isAfterTyper (and cheaper to test).

    Definition Classes
    Phase
  30. final def iterator: Iterator[Phase]

    Definition Classes
    Phase
  31. final val labelFlags: FlagSet

  32. final val labelPrefix: String("tailLabel")

  33. final def labelsReordered: Boolean

    Definition Classes
    Phase
  34. def lastPhaseId(implicit ctx: Context): Int

    The last phase during which the transformed denotations are valid

    The last phase during which the transformed denotations are valid

    Definition Classes
    DenotTransformer
  35. def mkTreeTransformer: TreeTransformer

    Attributes
    protected
    Definition Classes
    MiniPhase
  36. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  37. final def next: Phase

    Definition Classes
    Phase
  38. final def notify(): Unit

    Definition Classes
    AnyRef
  39. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  40. def period: Period

    Definition Classes
    Phase
  41. def phase: MiniPhaseTransform

    Definition Classes
    MiniPhaseTransformTreeTransform
  42. def phaseName: String

    Definition Classes
    TailRecPhase
  43. def prepareForAlternative(tree: ast.tpd.Alternative)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  44. def prepareForApply(tree: ast.tpd.Apply)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  45. def prepareForAssign(tree: ast.tpd.Assign)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  46. def prepareForBind(tree: ast.tpd.Bind)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  47. def prepareForBlock(tree: ast.tpd.Block)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  48. def prepareForCaseDef(tree: ast.tpd.CaseDef)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  49. def prepareForClosure(tree: ast.tpd.Closure)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  50. def prepareForDefDef(tree: ast.tpd.DefDef)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  51. def prepareForIdent(tree: ast.tpd.Ident)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  52. def prepareForIf(tree: ast.tpd.If)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  53. def prepareForInlined(tree: ast.tpd.Inlined)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  54. def prepareForLiteral(tree: ast.tpd.Literal)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  55. def prepareForMatch(tree: ast.tpd.Match)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  56. def prepareForNew(tree: ast.tpd.New)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  57. def prepareForPackageDef(tree: ast.tpd.PackageDef)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  58. def prepareForReturn(tree: ast.tpd.Return)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  59. def prepareForSelect(tree: ast.tpd.Select)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  60. def prepareForSeqLiteral(tree: ast.tpd.SeqLiteral)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  61. def prepareForStats(trees: List[ast.tpd.Tree])(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  62. def prepareForSuper(tree: ast.tpd.Super)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  63. def prepareForTemplate(tree: ast.tpd.Template)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  64. def prepareForThis(tree: ast.tpd.This)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  65. def prepareForTry(tree: ast.tpd.Try)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  66. def prepareForTypeApply(tree: ast.tpd.TypeApply)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  67. def prepareForTypeDef(tree: ast.tpd.TypeDef)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  68. def prepareForTypeTree(tree: ast.tpd.TypeTree)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  69. def prepareForTyped(tree: ast.tpd.Typed)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  70. def prepareForUnApply(tree: ast.tpd.UnApply)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  71. def prepareForUnit(tree: ast.tpd.Tree)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  72. def prepareForValDef(tree: ast.tpd.ValDef)(implicit ctx: Context): TreeTransform

    Definition Classes
    TreeTransform
  73. final def prev: Phase

    Definition Classes
    Phase
  74. final def refChecked: Boolean

    Definition Classes
    Phase
  75. def relaxedTyping: Boolean

    If set, allow missing or superfluous arguments in applications and type applications.

    If set, allow missing or superfluous arguments in applications and type applications.

    Definition Classes
    Phase
  76. def rewiredTarget(target: Symbol, derived: Symbol)(implicit ctx: Context): Symbol

    If references to original target from fully parameterized method derived should be rewired to some fully parameterized method, that method symbol, otherwise NoSymbol.

    If references to original target from fully parameterized method derived should be rewired to some fully parameterized method, that method symbol, otherwise NoSymbol.

    Attributes
    protected
    Definition Classes
    TailRecFullParameterization
  77. def rewiredTarget(tree: ast.tpd.Tree, derived: Symbol)(implicit ctx: Context): Symbol

    If references to some original symbol from given tree node within fully parameterized method derived should be rewired to some fully parameterized method, the rewiring target symbol, otherwise NoSymbol.

    If references to some original symbol from given tree node within fully parameterized method derived should be rewired to some fully parameterized method, the rewiring target symbol, otherwise NoSymbol. By default implemented as

    rewiredTarget(tree.symbol, derived)

    but can be overridden.

    Attributes
    protected
    Definition Classes
    FullParameterization
  78. def run(implicit ctx: Context): Unit

    Definition Classes
    MiniPhasePhase
  79. def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit]

    Definition Classes
    Phase
  80. def runsAfter: Set[Class[_ <: Phase]]

    List of names of phases that should precede this phase

    List of names of phases that should precede this phase

    Definition Classes
    Phase
  81. def runsAfterGroupsOf: Set[Class[_ <: Phase]]

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

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

    Definition Classes
    MiniPhase
  82. def start: Int

    Definition Classes
    Phase
  83. final def symbolicRefs: Boolean

    Definition Classes
    Phase
  84. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  85. def toString(): String

    Definition Classes
    Phase → AnyRef → Any
  86. def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation

    The transformation method

    The transformation method

    Definition Classes
    TailRecDenotTransformer
  87. def transform(tree: ast.tpd.Tree)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Transform tree using all transforms of current group (including this one)

    Transform tree using all transforms of current group (including this one)

    Definition Classes
    TreeTransform
  88. def transformAlternative(tree: ast.tpd.Alternative)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  89. def transformApply(tree: ast.tpd.Apply)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  90. def transformAssign(tree: ast.tpd.Assign)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  91. def transformBind(tree: ast.tpd.Bind)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  92. def transformBlock(tree: ast.tpd.Block)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  93. def transformCaseDef(tree: ast.tpd.CaseDef)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  94. def transformClosure(tree: ast.tpd.Closure)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  95. def transformDefDef(tree: ast.tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TailRecTreeTransform
  96. def transformFollowing(tree: ast.tpd.Tree)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Transform single node using all transforms following the current one in this group

    Transform single node using all transforms following the current one in this group

    Definition Classes
    TreeTransform
  97. def transformFollowingDeep(tree: ast.tpd.Tree)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Transform subtree using all transforms following the current one in this group

    Transform subtree using all transforms following the current one in this group

    Definition Classes
    TreeTransform
  98. def transformIdent(tree: ast.tpd.Ident)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  99. def transformIf(tree: ast.tpd.If)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  100. def transformInlined(tree: ast.tpd.Inlined)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  101. def transformLiteral(tree: ast.tpd.Literal)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  102. def transformMatch(tree: ast.tpd.Match)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  103. def transformNew(tree: ast.tpd.New)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  104. def transformOther(tree: ast.tpd.Tree)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  105. def transformPackageDef(tree: ast.tpd.PackageDef)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  106. def transformReturn(tree: ast.tpd.Return)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  107. def transformSelect(tree: ast.tpd.Select)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  108. def transformSeqLiteral(tree: ast.tpd.SeqLiteral)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  109. def transformStats(trees: List[ast.tpd.Tree])(implicit ctx: Context, info: TransformerInfo): List[ast.tpd.Tree]

    Definition Classes
    TreeTransform
  110. def transformSuper(tree: ast.tpd.Super)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  111. def transformTemplate(tree: ast.tpd.Template)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  112. def transformThis(tree: ast.tpd.This)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  113. def transformTry(tree: ast.tpd.Try)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  114. def transformTypeApply(tree: ast.tpd.TypeApply)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  115. def transformTypeDef(tree: ast.tpd.TypeDef)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  116. def transformTypeTree(tree: ast.tpd.TypeTree)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  117. def transformTyped(tree: ast.tpd.Typed)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TailRecTreeTransform
  118. def transformUnApply(tree: ast.tpd.UnApply)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  119. def transformUnit(tree: ast.tpd.Tree)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TailRecTreeTransform
  120. def transformValDef(tree: ast.tpd.ValDef)(implicit ctx: Context, info: TransformerInfo): ast.tpd.Tree

    Definition Classes
    TreeTransform
  121. def treeTransform: MiniPhaseTransform

    Definition Classes
    MiniPhaseTransformMiniPhase
  122. def treeTransformPhase: TailRec

    Definition Classes
    TailRecTreeTransform
  123. def unsupported(methodName: String): Nothing

    Throws an UnsupportedOperationException with the given method name.

    Throws an UnsupportedOperationException with the given method name.

    Definition Classes
    DotClass
  124. def validFor(implicit ctx: Context): Period

    The validity period of the transformer in the given context

    The validity period of the transformer in the given context

    Definition Classes
    DenotTransformer
  125. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  126. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  127. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from FullParameterization

Inherited from DenotTransformer

Inherited from MiniPhaseTransform

Inherited from MiniPhase

Inherited from Phase

Inherited from TreeTransform

Inherited from DotClass

Inherited from AnyRef

Inherited from Any

Ungrouped