Skip to content

✨ Derive the qubit and tensor correspondence of a call from its callee - #2194

Merged
burgholzer merged 3 commits into
mainfrom
mlir/call-aware-iterators
Sep 1, 2026
Merged

burgholzer merged 3 commits into
mainfrom
mlir/call-aware-iterators

Conversation

@DRovara

@DRovara DRovara commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Second of a stack replacing #1970. Builds on #2193.

WireIterator now traverses func.call in both directions. atWireStart()
distinguishes a call result created by the callee from one continuing an
operand's wire.

CallQubitMapping and CallTensorMapping derive operand/result correspondence
by threading linear arguments through the callee body instead of assuming
positional pairing. Reordered, kept, and created values are therefore tracked
according to the callee's behavior. Declarations, recursion, incomplete
functions, and non-straight-line bodies fail closed because they do not prove a
safe correspondence.

CallQubitMapping::invalidate() remains because #2199 mutates callees while
reusing the mapping. No reverse-mapping or tensor-invalidation API is exposed
because the stack has no production consumer for it.

This also fixes two defects exposed by call-aware traversal:

  • Threading checked a body's terminator before establishing that one exists.
  • qtensor.from_elements was not treated as a qubit-wire sink even though it
    consumes qubits into a tensor.

Simplification audit

The Ponytail review removed duplicate pass-through, foreign-value, classical,
and invalid-input cases. The retained tests cover the distinct contracts:
nested reordered correspondence, kept/created values, bidirectional traversal,
and fail-closed declarations and recursion.

Testing

  • 118 QCO utility tests pass.
  • 7 QTensor utility tests pass.
  • The release build and all 3,923 configured tests pass on the final stack, with
    one expected skip.
  • uvx nox -s cpp-lint and uvx nox -s lint pass.

AI assistance

Code and this description were produced with Claude Code (Opus 5) and Codex,
acting on my instructions and within the scope I authorized.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.43434% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Dialect/QCO/Utils/WireIterator.cpp 94.0% 7 Missing ⚠️
mlir/lib/Dialect/QTensor/Utils/TensorIterator.cpp 92.4% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch 3 times, most recently from b6801d6 to cddcdbc Compare August 25, 2026 07:50
Base automatically changed from mlir/tensor-iteration-infra to main August 25, 2026 21:44
@burgholzer
burgholzer force-pushed the mlir/call-aware-iterators branch from a02e180 to a638b30 Compare August 25, 2026 21:44
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch from a638b30 to 06fdb61 Compare August 26, 2026 14:08
@DRovara
DRovara marked this pull request as ready for review August 26, 2026 14:36
@mergify mergify Bot added the conflict label Aug 26, 2026
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch from 58c8204 to c7d82fe Compare August 27, 2026 11:40
@mergify mergify Bot removed the conflict label Aug 27, 2026
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch from c7d82fe to 56a017d Compare August 27, 2026 13:16
@DRovara
DRovara requested a review from burgholzer August 28, 2026 07:17
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch 2 times, most recently from c7d82fe to 979bd40 Compare August 28, 2026 08:11
@burgholzer
burgholzer force-pushed the mlir/call-aware-iterators branch from 979bd40 to 79d8ea2 Compare August 28, 2026 12:30
@burgholzer burgholzer added feature New feature or request c++ Anything related to C++ code MLIR Anything related to MLIR labels Aug 28, 2026
@burgholzer
burgholzer force-pushed the mlir/call-aware-iterators branch from 79d8ea2 to b52f2e6 Compare August 30, 2026 14:21
@burgholzer burgholzer added enhancement Improvement of existing feature and removed feature New feature or request labels Aug 30, 2026
@burgholzer burgholzer added this to the MLIR Support milestone Aug 31, 2026

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@DRovara Thanks for your work on this!
I took this for a couple of spins and rebased it on the latest main.
Could you please go through the PR once more and check whether this makes sense? If it does, please feel free to merge!
I already partly reviewed and iterated the next PR in the stack 😌

@burgholzer

Copy link
Copy Markdown
Member

Moved this one to the 4.1.0 milestone because I think it is unrealistic to get the entire PR stack merged before the 4.0 release and I'd rather get this into the next minor release or the one after that.

@DRovara

DRovara commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@DRovara Thanks for your work on this! I took this for a couple of spins and rebased it on the latest main. Could you please go through the PR once more and check whether this makes sense? If it does, please feel free to merge! I already partly reviewed and iterated the next PR in the stack 😌

From a first glance, your changes seem only minimal, and with all the tests still passing I'm confident this is correct. I'm resolving the conflicts and then merging the PR

@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch from b52f2e6 to 93253e9 Compare September 1, 2026 16:46
@mergify mergify Bot added conflict and removed conflict labels Sep 1, 2026
DRovara and others added 3 commits September 1, 2026 18:05
Thread qubit and tensor arguments through supported callees and fail closed when their correspondence cannot be derived.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

Assisted-by: Codex
Exercise reordered, nested, kept, declared, and recursive call mappings together with iterator traversal in both directions.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

Assisted-by: Codex
Record the rebase, simplification, validation, and publication procedure for the interprocedural optimization stack.

Assisted-by: Codex
@burgholzer
burgholzer force-pushed the mlir/call-aware-iterators branch from 93253e9 to 3bd74e3 Compare September 1, 2026 18:07
@mergify mergify Bot added the conflict label Sep 1, 2026
@mergify mergify Bot removed the conflict label Sep 1, 2026
@burgholzer
burgholzer merged commit f52ea18 into main Sep 1, 2026
26 checks passed
@burgholzer
burgholzer deleted the mlir/call-aware-iterators branch September 1, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants