Skip to content

fix(hugr-llvm): free arrays after unpacking - #3324

Merged
qartik merged 1 commit into
codex-fix-borrow-array-conversion-leakfrom
codex-fix-array-unpack-leaks
Nov 5, 2026
Merged

qartik merged 1 commit into
codex-fix-borrow-array-conversion-leakfrom
codex-fix-array-unpack-leaks

Conversation

@qartik

@qartik qartik commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

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 -- --check passes.

@qartik
qartik added this pull request to stack #3323 November 4, 2026 21:56
@qartik
qartik marked this pull request as ready for review November 4, 2026 21:56
@qartik
qartik requested a review from a team as a code owner November 4, 2026 21:56
@qartik
qartik requested a review from croyzor November 4, 2026 21:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T21:57:47.391945Z d702917 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-04T22:01:09.072038Z d702917 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.11%. Comparing base (b71c0bd) to head (d702917).

Files with missing lines Patch % Lines
...ugr-llvm/src/extension/collections/borrow_array.rs 93.02% 1 Missing and 2 partials ⚠️
hugr-llvm/src/extension/collections/array.rs 0.00% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
python 89.72% <ø> (ø)
rust 80.93% <90.90%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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

@aborgna-q aborgna-q left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚀

@aborgna-q
aborgna-q removed the request for review from croyzor November 5, 2026 10:58
@qartik
qartik added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit d337a15 Nov 5, 2026
36 checks passed
@qartik
qartik deleted the codex-fix-array-unpack-leaks branch November 5, 2026 13:39
@hugrbot hugrbot mentioned this pull request Nov 5, 2026
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.

3 participants