Skip to content

core/mir/codegen: owned-value destruction and allocation follow-ups - #2121

Open
sbillig wants to merge 2 commits into
argotorg:masterfrom
sbillig:fix/owned-destruction-followups
Open

sbillig wants to merge 2 commits into
argotorg:masterfrom
sbillig:fix/owned-destruction-followups

Conversation

@sbillig

@sbillig sbillig commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add #[must_use] annotations to MemVec::{try_reserve, try_grow, try_resize}, MemBuffer::{try_reserve, try_resize}, and HashMap::{try_reserve, try_grow}.
  • Guard Box<T>::drop with needs_drop<T>() and Box<T>::{drop, into_inner} deallocation with size_of<T>() != 0.
  • Guard deallocations across MemArray, MemVec, MemBuffer, FixedMemBuffer, and HashMap, fix MemVec::into_array() capacity leak when len == 0 && capacity != 0, and prune unreachable functions after native and Wasm optimization so empty owners omit free declarations and calls at -O2.
  • Replace unrolled MIR array drop glue with a runtime loop (while idx < len) for len >= 2, hoisting non-memory array materialization before the loop and avoiding dead locals on memory-backed places.
  • Gate try_alloc_ptr and try_realloc_bytes on target = evm/native/wasm to omit dead null checks on EVM.

Testing

  • Added/updated uitests (must_use_try_alloc, shifted snapshots), evm_drops, native_backend, fe_test/drops.fe, and native_runtime.

- Annotate #[must_use] on MemVec::{try_reserve, try_grow, try_resize}, MemBuffer::{try_reserve, try_resize}, and HashMap::{try_reserve, try_grow}
- Guard Box<T>::drop with needs_drop<T>() and Box<T>::{drop, into_inner} dealloc with size_of<T>() != 0
- Guard dealloc in MemArray, MemVec, MemBuffer, FixedMemBuffer, and HashMap (and HashMap::{try_grow, alloc_table}) with length/capacity/size checks, fix MemVec::into_array() leaking capacity when len == 0 && capacity != 0, and prune unreachable functions after native and wasm optimization so empty owners omit free declarations and calls at -O2
- Replace unrolled array drop glue in MIR with a runtime loop (while idx < len) for len >= 2, hoisting non-memory array materialization before the loop and avoiding dead locals on memory-backed places
- Gate try_alloc_ptr and try_realloc_bytes on target = evm/native/wasm to omit dead null checks on EVM
- Add uitests, native/EVM IR tests, MIR drop loop tests, and runtime drop/balanced-allocator execution tests; update shifted uitest snapshots
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T20:56:46.495062Z dd50819 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.

This branch has not been deployed

No deployments
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.

1 participant