Skip to content

Dealloc for ManagedVec items#2314

Open
andrei-marinica wants to merge 11 commits intofeat/mdropfrom
mdrop-vec
Open

Dealloc for ManagedVec items#2314
andrei-marinica wants to merge 11 commits intofeat/mdropfrom
mdrop-vec

Conversation

@andrei-marinica
Copy link
Contributor

@andrei-marinica andrei-marinica commented Mar 19, 2026

Pull request overview

This PR introduces handle-level deallocation support for ManagedVec items (primarily for StaticApi / scenario usage) by plumbing a requires_drop() signal through ManagedVecItem, updating ManagedVec operations to avoid handle aliasing/double-frees, and expanding scenario/bench coverage.

Changes:

  • Add requires_drop() propagation for ManagedVecItem (derive + many manual impls) and a backend capability flag (requires_managed_type_drop) exposed via scenario APIs.
  • Update ManagedVec to drop items when needed (on drop/clear/overwrite/remove/dedup), and make slicing deep-copy items when handle-level drop is required.
  • Add benchmarks and scenario tests validating new ManagedVec APIs/behavior and derive outputs.

@github-actions
Copy link

github-actions bot commented Mar 19, 2026

Contract comparison - from b9138e3 to 7345145

Path                                                                                             size                  has-allocator                     has-format
large-storage.wasm 1656 false None
vec-repeat.wasm 4876 false None
single-value-repeat.wasm 4257 false None
queue-repeat.wasm 5540 false None
linked-list-repeat.wasm 6842 false without message
map-repeat.wasm 7367 false without message
set-repeat.wasm 6515 false None
str-repeat.wasm 2733 false without message
str-repeat-mb-builder-cached.wasm 1109 false without message
str-repeat-mb-builder-basic.wasm 757 false None
send-tx-repeat.wasm 1292 false None
forwarder-queue-promises.wasm 13533 false without message
forwarder-queue.wasm 12908 false without message
recursive-caller.wasm 5163 false without message
local-esdt-and-nft.wasm 12568 false without message
forwarder-raw-init-async-call.wasm 2357 false None
forwarder-raw-init-sync-call.wasm 2938 false None
forwarder-raw.wasm 13193 false None
vault-upgrade.wasm 708 false None
vault.wasm 9035 false None
forwarder.wasm 49178 false without message
proxy-test-second.wasm 2329 false without message
parent.wasm 1979 false None
child.wasm 3982 false without message
transfer-role-features.wasm 8667 false without message
first-contract.wasm 3433 false None
second-contract.wasm 1158 false None
forwarder-blind.wasm 14098 false without message
proxy-test-first.wasm 5719 false without message
builtin-func-features.wasm 3820 false None
forwarder-legacy.wasm 33668 false without message
basic-features-small-int-bug.wasm 824 false None
basic-features.wasm 86355 ➡️ 86384 🔴 (+29) false without message
basic-features-storage-bytes.wasm 541 false None
abi-tester.wasm 8607 true without message
abi-tester-ev.wasm 760 false None
rust-snippets-generator-test.wasm 4710 false None
formatted-message-features.wasm 3600 false without message
use-module-view.wasm 736 false None
use-module.wasm 32776 ➡️ 32741 🟢 (-35) false without message
payable-features.wasm 5872 false None
exchange-features.wasm 1514 false None
forbidden-opcodes.wasm 842 false None
scenario-tester.wasm 1374 false None
std-contract.wasm 3469 true without message
big-float-features.wasm 6373 false without message
rust-testing-framework-tester.wasm 8608 false None
multi-contract-alt-impl.wasm 353 false None
multi-contract-features.wasm 681 false None
multi-contract-example-feature.wasm 680 false None
multi-contract-features-view.wasm 1113 false None
panic-message-features.wasm 13036 false with message
panic-message-std.wasm 16074 false with message
erc1155-user-mock.wasm 1229 false None
lottery-erc20.wasm 12893 false without message
erc721.wasm 2232 false None
crowdfunding-erc20.wasm 4910 false without message
erc1155-marketplace.wasm 10602 false without message
erc1155.wasm 12023 false without message
erc20.wasm 1870 false None
esdt-system-sc-mock.wasm 4623 false None
alloc-features.wasm 23267 false without message
alloc-mem-fail.wasm 17819 true without message
alloc-mem-leaking.wasm 23424 false without message
multiversx-wegld-swap-sc.wasm 4492 false None
multiversx-price-aggregator-sc.wasm 17910 false without message
ping-pong-egld.wasm 6397 false None
multisig-full.wasm 15130 false without message
multisig-view.wasm 5590 false None
multisig.wasm 13442 false without message
bonding-curve-contract.wasm 14126 ➡️ 14132 🔴 (+6) false None
kitty-genetic-alg.wasm 3494 false without message
kitty-auction.wasm 9411 false without message
kitty-ownership.wasm 12965 false without message
check-pause.wasm 1260 false None
digital-cash.wasm 9836 ➡️ 9845 🔴 (+9) false None
fractional-nfts.wasm 8306 false without message
adder.wasm 699 false None
order-book-pair.wasm 14229 false None
order-book-factory.wasm 3401 false None
empty.wasm 244 false None
esdt-transfer-with-fee.wasm 7502 false without message
nft-subscription.wasm 8840 false without message
proxy-pause.wasm 4148 false None
seed-nft-minter.wasm 14443 false without message
crowdfunding.wasm 3557 false None
nft-storage-prepay.wasm 2606 false None
crypto-bubbles.wasm 2541 false None
crypto-zombies.wasm 9255 false without message
nft-minter.wasm 9725 false without message
lottery-esdt.wasm 10578 false without message
factorial.wasm 579 false None
rewards-distribution.wasm 9553 ➡️ 9605 🔴 (+52) false without message
token-release.wasm 6977 false without message

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces handle-level deallocation support for ManagedVec items (primarily for StaticApi / scenario usage) by plumbing a requires_drop() signal through ManagedVecItem, updating ManagedVec operations to avoid handle aliasing/double-frees, and expanding scenario/bench coverage.

Changes:

  • Add requires_drop() propagation for ManagedVecItem (derive + many manual impls) and a backend capability flag (requires_managed_type_drop) exposed via scenario APIs.
  • Update ManagedVec to drop items when needed (on drop/clear/overwrite/remove/dedup), and make slicing deep-copy items when handle-level drop is required.
  • Add benchmarks and scenario tests validating new ManagedVec APIs/behavior and derive outputs.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/managed-mem-bench/src/main.rs Expands benchmarks to cover enums/structs and many ManagedVec<T> item shapes under StaticApi.
framework/scenario/tests/managed_vec_test.rs Adds tests for byte_len, is_empty, try_get, set, slice, remove, clear, find, contains (incl. BigUint cases).
framework/scenario/tests/derive_managed_vec_item_struct_3.rs Extends derive test assertions to validate requires_drop() for derived struct/enum.
framework/scenario/tests/derive_managed_vec_item_struct_2_test.rs Adds requires_drop() assertion for a derived struct.
framework/scenario/tests/derive_managed_vec_item_struct_1_test.rs Adds requires_drop() assertion for a derived struct.
framework/scenario/tests/derive_managed_vec_item_esdt_token_payment_test.rs Adds requires_drop() assertion for a derived managed-token struct.
framework/scenario/tests/derive_managed_vec_item_enum_simple.rs Adds requires_drop() assertion for a derived simple enum.
framework/scenario/tests/derive_managed_vec_item_enum_2_managed.rs Adds requires_drop() assertion for a derived enum containing managed fields.
framework/scenario/tests/derive_managed_vec_item_enum_1.rs Adds requires_drop() assertion for a derived enum.
framework/scenario/tests/derive_managed_vec_item_decimal_test.rs Adds requires_drop() assertion for a derived decimal wrapper.
framework/scenario/tests/derive_managed_vec_item_biguint_test.rs Adds requires_drop() assertion for a derived BigUint wrapper.
framework/scenario/src/api/managed_type_api_vh.rs Exposes requires_managed_type_drop() through ManagedTypeApiImpl for VMHooks-backed APIs.
framework/scenario/src/api/impl_vh/vm_hooks_backend.rs Adds a backend capability hook backend_requires_managed_type_drop().
framework/scenario/src/api/impl_vh/static_api.rs Enables managed-type dropping for StaticApi backend.
framework/scenario/src/api/impl_vh/single_tx_api.rs Disables managed-type dropping for SingleTxApi backend.
framework/scenario/src/api/impl_vh/debug_api.rs Disables managed-type dropping for DebugApi backend.
framework/derive/src/managed_vec_item_derive.rs Extends ManagedVecItem derive to compute requires_drop() from fields/variants.
framework/base/src/types/managed/wrapped/token/payment.rs Implements requires_drop() based on backend capability for Payment.
framework/base/src/types/managed/wrapped/token/fungible_payment.rs Implements requires_drop() based on backend capability for FungiblePayment.
framework/base/src/types/managed/wrapped/token/esdt_token_payment.rs Implements requires_drop() based on backend capability for EsdtTokenPayment.
framework/base/src/types/managed/wrapped/token/egld_or_esdt_token_payment.rs Implements requires_drop() based on backend capability for EgldOrEsdtTokenPayment.
framework/base/src/types/managed/wrapped/managed_vec_ref_mut.rs Adjusts write-back to avoid drop semantics during ManagedVecRefMut guard drop.
framework/base/src/types/managed/wrapped/managed_vec_item.rs Makes requires_drop() mandatory and implements it for primitives/managed types/options/tuples.
framework/base/src/types/managed/wrapped/managed_vec.rs Implements item-dropping behavior and updates slice, set, remove/take, append_vec, clear, dedup, and drop logic.
framework/base/src/types/managed/wrapped/managed_option.rs Adds backend-driven requires_drop() for ManagedOption as a ManagedVecItem.
framework/base/src/types/managed/wrapped/managed_decimal/managed_decimal_signed.rs Adds backend-driven requires_drop() for signed decimal variants.
framework/base/src/types/managed/wrapped/managed_decimal.rs Adds backend-driven requires_drop() for decimal variants.
framework/base/src/types/managed/multi_value/payment_multi_value.rs Adds backend-driven requires_drop() for multi-value payment wrapper.
framework/base/src/types/managed/multi_value/multi_value_managed_vec_counted.rs Adds backend-driven requires_drop() for counted vec multi-value wrapper.
framework/base/src/types/managed/multi_value/multi_value_managed_vec.rs Updates slice signature to match underlying ManagedVec requirements.
framework/base/src/types/managed/multi_value/esdt_token_payment_multi_value.rs Adds backend-driven requires_drop() for ESDT payment multi-value wrapper.
framework/base/src/types/managed/multi_value/egld_or_esdt_token_payment_multi_value.rs Adds backend-driven requires_drop() for EGLD/ESDT payment multi-value wrapper.
framework/base/src/types/interaction/managed_arg_buffer.rs Adds backend-driven requires_drop() for ManagedArgBuffer as a ManagedVecItem.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@andrei-marinica andrei-marinica marked this pull request as ready for review March 20, 2026 16:11
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.

2 participants