Skip to content

feat: support dynamic allocation and arrays#48

Merged
qartik merged 7 commits intomainfrom
ks-issue-46-dynamic-alloc-arrays-resume
Apr 29, 2026
Merged

feat: support dynamic allocation and arrays#48
qartik merged 7 commits intomainfrom
ks-issue-46-dynamic-alloc-arrays-resume

Conversation

@qartik
Copy link
Copy Markdown
Member

@qartik qartik commented Mar 20, 2026

Summary

Fixes #46 by adding Adaptive Profile support for dynamic_qubit_management, dynamic_result_management, and fixed-size pointer arrays, and by hardening the Selene smoke coverage needed to exercise the new path on CI.

Included

  • support dynamic qubit allocate/release and array allocate/release
  • support dynamic result allocate/release, array allocate/release, and record_output using compiler-managed result slots
  • support fixed-size pointer-array flows through alloca, load, store, getelementptr, extractvalue, insertvalue, compatible bitcast-backed storage, and zero-index getelementptr views of fixed [N x ptr] backing arrays
  • emit result-array outputs as real array-valued RESULT_ARRAY records through print_bool_arr(...)
  • reject unsupported capability-gated runtime usage, invalid helper collisions, helper-local dynamic result allocation, mismatched fixed-size array backing, and result_array_record_output lengths that do not fit the current downstream i32 array ABI
  • update qtm-qir-reference.md to document the supported surface
  • add fixture, snapshot, property, fuzz-corpus, and main.py regression coverage for the new dynamic allocation and array behaviors

CI

  • add tests/test_main.py smoke coverage to the workflow
  • use released selene-sim 0.2.15 from the package index for the Selene smoke environment

Validation

  • make lint
  • make test

@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch 2 times, most recently from 74e0b5b to dc39cde Compare March 20, 2026 22:39
@qartik qartik marked this pull request as ready for review March 20, 2026 22:39
Copilot AI review requested due to automatic review settings March 20, 2026 22:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Adaptive Profile support for capability-gated dynamic qubit/result allocation and fixed-size pointer arrays, including validation + lowering paths, with new/updated snapshot fixtures and documentation updates.

Changes:

  • Add capability-flag parsing/validation and gate dynamic RT API acceptance on module flags.
  • Lower dynamic qubit/result allocation/release and result-array output recording (compiler-managed result slots).
  • Expand fixtures/snapshots and align linting across pre-commit and CI.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/lib.rs Implements capability-flag parsing, capability-gated validation, and new lowering paths for dynamic allocation/arrays.
src/convert.rs Updates native-call lowering to support dynamic qubit handles and propagates capability context into IR-defined lowering.
qtm-qir-reference.md Documents supported capability flags, accepted RT APIs, and the fixed-size pointer-array support boundary.
.pre-commit-config.yaml Aligns clippy invocation/strictness for local lint runs.
.github/workflows/CI.yml Switches CI lint job to run the same prek-based checks as local linting.
tests/data/dynamic_qubit_alloc.ll New input fixture covering dynamic qubit allocate/release.
tests/data/dynamic_qubit_array_ssa.ll New input fixture covering dynamic qubit arrays with SSA swapping patterns.
tests/data/dynamic_result_alloc.ll New input fixture covering dynamic result allocate/release + output.
tests/data/dynamic_result_array.ll New input fixture covering result arrays (allocate/record/release).
tests/data/dynamic_result_mixed_array_output.ll New input fixture covering mixed result allocation + array output flows.
tests/snaps/dynamic_qubit_alloc.ll.snap New snapshot for dynamic qubit allocation lowering output.
tests/snaps/dynamic_qubit_array_ssa.ll.snap New snapshot for dynamic qubit array SSA lowering output.
tests/snaps/dynamic_result_alloc.ll.snap New snapshot for dynamic result allocation lowering output.
tests/snaps/dynamic_result_array.ll.snap New snapshot for dynamic result array output/lowering output.
tests/snaps/dynamic_result_mixed_array_output.ll.snap New snapshot for mixed dynamic result + array output lowering output.
tests/snaps/barrier.ll.snap Updates snapshot expectations after internal lowering/refactor changes.
tests/snaps/barrier_multi.ll.snap Updates snapshot expectations after internal lowering/refactor changes.
tests/snaps/adaptive.ll.snap Updates snapshot expectations after internal lowering/refactor changes.
tests/snaps/adaptive_ir_fns.ll.snap Updates snapshot expectations after internal lowering/refactor changes.
tests/snaps/adaptive_iter.ll.snap Updates snapshot expectations after internal lowering/refactor changes.
tests/snaps/adaptive_iter_fn.ll.snap Updates snapshot expectations after internal lowering/refactor changes.
tests/snaps/adaptive_cond_loop.ll.snap Updates snapshot expectations after internal lowering/refactor changes.
tests/snaps/ArithOps_switch.ll.snap Updates snapshot expectations after internal lowering/refactor changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch from dc39cde to 104f727 Compare March 20, 2026 22:45
@qartik qartik requested a review from Copilot March 20, 2026 22:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch from b544aad to 1d86541 Compare March 23, 2026 20:51
@qartik qartik requested a review from Copilot March 23, 2026 21:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 27 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 27 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 25 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/convert.rs:1194

  • Allowing internal calls like ___qalloc/panic/print_* in any IR-defined function whose name starts with qir_qis. creates a namespace-injection risk: an input module can define qir_qis.* functions to make these internal calls appear “expected”, and (combined with helper-creation routines that reuse existing qir_qis.* functions) can change compiler behavior. It would be safer to reject/rename any user-supplied qir_qis.* definitions during validation, or to gate this exception on stronger properties (e.g., exact helper names + private linkage + expected signature).
        "___qalloc"
        | "___qfree"
        | "___reset"
        | "panic"
        | "___read_future_bool"
        | "___dec_future_refcount"
        | "print_int"
        | "print_bool" => {
            let defined_name = defined_fn.get_name().to_str().ok();
            if defined_name != Some(INIT_QARRAY_FN)
                && !defined_name.is_some_and(|name| name.starts_with("qir_qis."))
            {
                log::error!(
                    "Unexpected call to internal function: {fn_name} in function {}",
                    defined_fn.get_name().to_str().unwrap_or("unknown")
                );
                return Err(format!("Unexpected call to internal function: {fn_name}"));
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib.rs
Comment thread src/lib.rs
@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch from 7daa2f6 to c9cc10c Compare March 24, 2026 17:38
@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch from dd7de21 to f51d951 Compare April 9, 2026 21:34
@qartik qartik requested a review from Copilot April 9, 2026 23:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 34 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fuzz/fuzz_targets/mutated_fixture_contracts.rs Outdated
Comment thread fuzz/fuzz_targets/mutated_fixture_contracts.rs
Comment thread tests/test_main.py Outdated
Comment thread tests/test_main.py Outdated
@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch from 628e4b6 to 34b9593 Compare April 22, 2026 19:13
@qartik qartik requested a review from Copilot April 22, 2026 19:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_main.py
Comment thread .github/workflows/CI.yml Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/CI.yml
Comment thread .github/workflows/CI.yml Outdated
Comment thread tests/test_main.py Outdated
@qartik

This comment was marked as resolved.

@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch 2 times, most recently from 5147250 to bc0f3d2 Compare April 24, 2026 00:01
@qartik qartik requested a review from Copilot April 24, 2026 00:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@qartik
Copy link
Copy Markdown
Member Author

qartik commented Apr 24, 2026

@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch from e959ec1 to b05cbdd Compare April 28, 2026 14:17
@qartik qartik force-pushed the ks-issue-46-dynamic-alloc-arrays-resume branch from b05cbdd to 792ee59 Compare April 28, 2026 15:31
@qartik qartik marked this pull request as ready for review April 28, 2026 19:17
@qartik qartik requested a review from Copilot April 28, 2026 19:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 32 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_main.py Outdated
@qartik qartik merged commit 2876149 into main Apr 29, 2026
23 checks passed
@qartik qartik deleted the ks-issue-46-dynamic-alloc-arrays-resume branch April 29, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for dynamic allocation & arrays

2 participants