Repository navigation
fix(hugr-llvm): free arrays after unpacking - #3324
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## codex-fix-borrow-array-conversion-leak #3324 +/- ##
=======================================================================
Coverage 82.11% 82.11%
=======================================================================
Files 245 245
Lines 47651 47695 +44
Branches 41216 41260 +44
=======================================================================
+ Hits 39127 39167 +40
- Misses 6618 6619 +1
- Partials 1906 1909 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the array-unpack memory-leak fix.
No open issues 🎉
What changed in this PR
Fixes memory leaks in HUGR’s LLVM array-unpack lowering, extending the borrow-array cleanup work in the preceding PRs.
Changes:
- Frees element buffers after unpacking ordinary and borrow arrays, and frees borrow-array masks after borrow-status checks.
- Adds a regression test that repeats both unpack operations 100 times, checks returned values, and verifies allocation cleanup.
- Updates LLVM 21 snapshots to include the new frees.
| File | Description |
|---|---|
hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__borrow_array__test__emit_all_ops@pre-mem2reg@llvm21.snap |
Records buffer and mask frees before promotion. |
hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__borrow_array__test__emit_all_ops@llvm21.snap |
Records buffer and mask frees after promotion. |
hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__array__test__emit_all_ops@pre-mem2reg@llvm21.snap |
Records the ordinary-array buffer free before promotion. |
hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__array__test__emit_all_ops@llvm21.snap |
Records the ordinary-array buffer free after promotion. |
hugr-llvm/src/extension/collections/borrow_array.rs |
Frees unpacked buffers and masks; adds allocation-accounting coverage for both representations. |
hugr-llvm/src/extension/collections/array.rs |
Frees the element buffer after unpacking. |
Review effort: Balanced
Unpacking an array consumes it, but the LLVM lowering left its backing allocation live. Borrow-array unpacking also left its mask allocated. Free those allocations after loading the elements and checking their borrow status.
The ordinary array unpack lowering was introduced in #2339, and the borrow-array lowering in #2574.
Stacked on #3322 (which is stacked on #3321).
The execution regression repeatedly unpacks both array representations, checks the returned values, and verifies that every allocation is freed. It fails without the fix. LLVM snapshots are updated.
Validation: all 147 LLVM collection tests pass;
cargo fmt --all -- --checkpasses.