Skip to content

feat: in/out/in out parameter modes #200

Description

@ganehag

Problem

Ada's parameter modes (in, out, in out) make mutation intent explicit at the call site and function signature. Gengo parameters are effectively pass-by-value (closures capture by cell; structs are passed by reference to the heap object but the binding is not re-assignable from the caller's side).

There is currently no way to signal at the signature or call site that a function mutates or initialises its argument.

Proposed direction

func swap(a in out int, b in out int) {
    a, b = b, a
}

swap(x, y)   // caller can see mutation is possible
  • in (default, may be omitted): read-only parameter; compiler rejects assignment to it inside the body
  • out: write-only; must be assigned before use inside the body; initialised on return
  • in out: readable and writable; changes are reflected at the call site

Notes

  • in is already the effective default (const params). Making it explicit is low cost.
  • out and in out require pass-by-reference semantics, which the current calling convention does not support for scalars. This may require VM changes.
  • Lower priority than exhaustiveness checking and typed errors. Needs design discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priorityarea:compilerLexer, parser, compilerdesignLanguage or API design decision neededenhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions