Skip to content

explicit tail call syntax #694

@thejoshwolfe

Description

@thejoshwolfe

Progress


Proposal:

return @tailCall(foo, a, b, c);
// roughly equivalent to:
return foo(a, b, c);

The purpose of @tailCall() is to ensure that a tail call happens. If it cannot, the @tailCall() produces a compile error.

Here are some cases where a tail call is impossible:

  • if the @tailCall() expression is not the operand of a return operator. e.g. return @tailCall(foo) - 1.
  • if there are defer statements that would run after the @tailCall(). e.g. {defer bar(); return @tailCall(foo);}.
  • if there is an implicit cast to convert the return value of the called function into the return value of the calling function. e.g. foo returns u8 and the caller returns ?u8.

See also #157.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions