Skip to content

fix(hugr-llvm): free borrow array mask on discard - #3321

Merged
qartik merged 2 commits into
mainfrom
codex-fix-borrow-array-discard
Nov 5, 2026
Merged

qartik merged 2 commits into
mainfrom
codex-fix-borrow-array-discard

Conversation

@qartik

@qartik qartik commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

BArrayDiscard freed the elements buffer but left the borrow mask allocated. Free both pointers when discarding the array.

The borrow-array lowering was introduced in #2574.

Add a JIT regression test that creates, accesses, and discards an array 100 times while accounting for allocations and frees. The test fails when the mask free is removed. Update the LLVM snapshots.

Closes #3320

Validation

  • cargo test -p hugr-llvm extension::collections::borrow_array::test --lib (84 passed, LLVM 21)
  • cargo fmt --all -- --check and git diff --check
  • Snyk Code scan of borrow_array.rs: no findings

@qartik
qartik requested a review from a team as a code owner November 4, 2026 20:54
@qartik
qartik requested a review from aborgna-q November 4, 2026 20:54
@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:01:59.838639Z f283f3b New commits
🔒 Security Review ✅ Completed 2026-11-04T21:03:48.805536Z f283f3b New commits
ℹ️ 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.

@qartik qartik changed the title fix(llvm): free borrow array mask on discard fix(hugr-llvm): free borrow array mask on discard Nov 4, 2026
@qartik
qartik requested a balanced review from Copilot November 4, 2026 20:55

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 are recorded for the borrow-array discard leak fix.

No open issues 🎉

What changed in this PR

Fixes the borrow-array discard leak in hugr-llvm reported in #3320 by releasing both the elements buffer and the borrow mask.

Changes:

  • Frees both pointers in emit_barray_discard.
  • Adds a JIT regression test that checks allocation accounting across 100 create/access/discard cycles.
  • Updates LLVM 21 snapshots to include mask deallocation.
File Description
hugr-llvm/​src/​extension/​collections/​snapshots/​hugr_llvm__extension__collections__borrow_array__test__emit_get@pre-mem2reg@llvm21.snap Records mask deallocation before mem2reg for get/discard.
hugr-llvm/​src/​extension/​collections/​snapshots/​hugr_llvm__extension__collections__borrow_array__test__emit_get@llvm21.snap Records mask deallocation after mem2reg for get/discard.
hugr-llvm/​src/​extension/​collections/​snapshots/​hugr_llvm__extension__collections__borrow_array__test__emit_clone@pre-mem2reg@llvm21.snap Records both arrays’ mask deallocation before mem2reg.
hugr-llvm/​src/​extension/​collections/​snapshots/​hugr_llvm__extension__collections__borrow_array__test__emit_clone@llvm21.snap Records both arrays’ mask deallocation after mem2reg.
hugr-llvm/​src/​extension/​collections/​borrow_array.rs Fixes discard cleanup and adds the allocation-accounting regression test.

Review effort: Balanced

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.10%. Comparing base (ca20348) to head (f283f3b).

Files with missing lines Patch % Lines
...ugr-llvm/src/extension/collections/borrow_array.rs 88.88% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3321      +/-   ##
==========================================
+ Coverage   82.08%   82.10%   +0.01%     
==========================================
  Files         245      245              
  Lines       47579    47612      +33     
  Branches    41144    41177      +33     
==========================================
+ Hits        39056    39090      +34     
+ Misses       6619     6617       -2     
- Partials     1904     1905       +1     
Flag Coverage Δ
python 89.72% <ø> (ø)
rust 80.90% <88.88%> (+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.

@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.

LGTM 👍

@qartik
qartik added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit 56b4d4f Nov 5, 2026
35 checks passed
@qartik
qartik deleted the codex-fix-borrow-array-discard 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.

Borrow-array discard leaks the mask allocation

3 participants