Skip to content

✨ Support classical subroutines and array-reference parameters #2593

Description

@simon1hofmann

🤖 AI text below 🤖

Problem Statement

Classical OpenQASM def functions and array-reference parameters remain outside
the standalone array work in #2109. The existing #2429 covers only void
subroutines with quantum parameters and explicitly excludes classical parameters
and return values.

Without classical subroutines, programs cannot pass an angle table or update a
classical array through a reusable function.

Proposed Solution

Add classical subroutines and array-reference parameters as a coherent extension
of the frontend and shared function-call representation.

  • Support typed scalar arguments by value, scalar return values, local scope,
    and calls to defined non-recursive functions.
  • Support readonly array[...] and mutable array[...] reference parameters,
    with explicit shape or the language's rank-only #dim form.
  • Borrow caller-owned storage. Preserve writes through mutable references and
    reject writes through readonly references. Do not copy an entire array merely
    to pass it to a function.
  • Validate element type, shape/rank, initialization, and the language's alias
    restrictions, including overlapping mutable arguments. Include supported
    array slices in the reference contract rather than silently flattening them.
  • Preserve these calls through QC/QCO conversion and OpenQASM export. Define
    the supported QIR/jeff mappings and diagnose unsupported signatures instead
    of accepting syntax that fails later without explanation.

Acceptance tests should cover scalar calls/returns, readonly access, caller-visible
mutation, rank-only parameters, slices, nested calls, and negative type, alias,
mutability, and lifetime cases. Existing custom gates and quantum subroutines
must retain their behavior.

Parent backlog: #1733. The array-reference portion depends on #2109. Coordinate
with #2429 for shared def syntax and call handling; its quantum-only contract
does not implement this feature. Array-valued outputs are tracked separately in
#2592 and are not required for borrowed array parameters. extern, recursion,
and array-valued function returns are not part of this issue.

Language reference: OpenQASM subroutines.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

MLIRAnything related to MLIROpenQASMAnything related to OpenQASMfeatureNew feature or request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions