carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

`ref` parameters, arguments, returns and `let` returns

Open josh11b opened this issue 6 months ago • 0 comments

  • A parameter binding can be marked ref instead of var or the default. It will bind to reference argument expressions in the caller and produces a reference expression in the callee.
    • Unlike pointers, a ref binding can't be rebound to a different object.
    • This replaces addr, and is not restricted to the self parameter.
    • A ref binding, like a let binding, can't be used in fields of classes or structs.
    • When calling functions, arguments to non-self ref parameters are also marked with ref.
  • The return of a function can optionally be marked ref, let, or var. These control the category of the call expression invoking the function, and how the return expression is returned.
    • These may be mixed for functions returning parens or brace forms.
  • Any parameters whose lifetime needs to contain the lifetime of the return must be marked bound.
  • The address of a ref binding is nocapture and noalias.
  • We mark parameters of a function that may be referenced by the return value with bound.

josh11b avatar May 06 '25 23:05 josh11b