compiler/mir/tailcall_elim

  Source   Edit

Implements the MIR passes making up the portable tail-call elimination (a high-level description of how this works can be found here).

Procs

proc insertNewResult(body: var MirBody; g: ModuleGraph; owner: PSym;
                     env: var MirEnv) {....raises: [Exception, ERecoverableError,
    KeyError], tags: [RootEffect, ReadDirEffect].}
First part of the .tailcall lowering. Changes the 'result' type to a Continuation type and turns the previous 'result' variable (if any) into a normal local.   Source   Edit
proc insertTrampolines(tree: MirTree; g: ModuleGraph; owner: PSym;
                       env: var MirEnv; changes: var Changeset) {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
Turns all non-tailcall invocations of .tailcall procedures into trampolines.   Source   Edit
proc lowerProcvals(tree: MirTree; env: var MirEnv; changes: var Changeset) {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
Turns all procval creation for .tailcall procedures into procval creation of the associated application procedure.   Source   Edit
proc lowerTailcallBody(body: MirBody; g: ModuleGraph; owner: PSym;
                       env: var MirEnv; changes: var Changeset) {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
Second part of the .tailcall lowering. Lowers all 'tailcall' statements into constructing and returning a Continuation object.   Source   Edit