🐛 Fix dangling references in collectQubitValuesInsideSCFOps#1749
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThe PR refactors the ChangesSCF Region Collection Logic
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mlir/lib/Conversion/QCToQCO/QCToQCO.cpp`:
- Around line 521-525: The local-definition check (isDefinedLocally) only
consults qubitInfoMap and misses values defined by ops inside the same region
(e.g., qc.alloc), causing region-local qubits/memrefs to be misclassified as
external; update that lambda to also consider a Value as local if its defining
operation exists and its defining operation's region
(definingOp->getParentRegion() or op->getParentRegion()) equals the region
argument, and apply the same logic to the memref-local checks that reference
memrefInfoMap (and any similar predicates around Lines 541–565) so both qubit
and memref lookups first accept values defined in the same region regardless of
whether they were recorded in the maps.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: fbe983ae-bf5a-489e-ae7c-a455a5e4d5af
📒 Files selected for processing (1)
mlir/lib/Conversion/QCToQCO/QCToQCO.cpp
|
@MatthiasReumann I think this should fix the issue. Let me know if there are any other problems. Btw: I have no idea what I did with the CI but there seems to be something broken. Do you know what this is? |
Signed-off-by: Lukas Burgholzer <burgholzer@me.com>
burgholzer
left a comment
There was a problem hiding this comment.
I pushed a commit that simplifies the diff a bit more and reduces the number of map lookups.
@li-mingbao Could you please add a test to the test suite covering this change? The test should fail before the commit and succeed afterwards.
This reverts commit f3905dd.
Description
Refactors
collectQubitValuesInsideSCFOpsin the QC to QCO conversion to directly usestate->mapsto store the values instead of using a reference to it. This avoids dangling references when the maps get rehashed/reallocated after inserting values.Fixes #1747
Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.