Skip to content

Run element destructors on refcount map iterator erase - #585

Open
perfloop-agent wants to merge 2 commits into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-rw6k6jshqr
Open

perfloop-agent wants to merge 2 commits into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-rw6k6jshqr

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

Refcount map iterator erase now calls the stored key and mapped-value C++ destructors before returning. Releasing Rust storage is not a substitute for these explicit callbacks, and unused iterator copies can keep that storage alive.

Both mutable and const iterator rules pass a finalizer to Map::erase. The runtime removes the entry from its links and ordered index and ends its borrows before invoking the finalizer. The rules reuse the existing destructor dispatch, so trivial key and value types need no new trait bounds. The rule-writing documentation explains this boundary.

Testing

On Linux Release and Debug, lit reports 1057 passed and 15 expected failures for tests/unit, 76 passed for tests/ub, and 20 passed for tests/multi-file per build, with no unexpected failures or skips. With only the new test files added to the base commit, unit lit reports 1056 passed, 15 expected failures and 1 failure: map_erase_destructor.cpp/refcount, whose generated output lacks the destructor hooks.

In both builds, the runtime tests report 70 passed, 0 failed and 0 ignored; the macro tests report 1 passed in the compile-fail runner and 22 passed in the control-flow runner, with 0 failed or ignored in either runner. Both crates report 0 doctests. ninja format completed successfully without changing tracked files.

tests/unit/map_erase_destructor.cpp compares native C++ with generated code for record/record, record/int, int/record and int/int entries. It checks callbacks at return and after unused iterator copies leave scope, plus successor, size, remaining element order and untouched live positions. The existing map fixtures check trivial-type behavior and key-copy counts.

tests/unit/map_erase_destructor.cpp remains an expected failure in the unsafe model; this repair is limited to refcount iterator erase. Whole-map destruction is unchanged. Unused iterator copies may still retain Rust storage.

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart. To ask for a change, comment or review in plain words. How Perfloop handles pull requests.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Tomás Senart <ts@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Tomás Senart <ts@perfloop.ai>

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