Skip to content

The C backend drops a map's elements: a fixture for clear and scope exit with owning keys and values (#1192) - #3564

Merged
ehartford merged 1 commit into
mainfrom
emit-c-map-drops
Nov 23, 2026
Merged

ehartford merged 1 commit into
mainfrom
emit-c-map-drops

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #1192.

The issue said the C backend emitted with_hashmap_clear and with_hashmap_remove with no element drops and never freed a map's keys or values. That is no longer true on main: clear walks the live entries, remove takes the stored key out and drops it, and a map leaving scope releases its entries. test/emit_c/drop_collection_mutations.with (#983) covers insert-over, remove and scope exit, but nothing covered clear on a populated map or set, or an owning value type dropped all the way down.

This adds that fixture: HashMap[str, List[str]] and HashSet[str], cleared while populated, refilled, then leaving scope. The C-built program reports leak count=0 allocations=43 under the debug allocator, the same as the LLVM build.

No compiler change. :emit-c-smoke green with the fixture; battery green.

@ehartford
ehartford merged commit 0c27245 into main Nov 23, 2026
@ehartford
ehartford deleted the emit-c-map-drops branch November 23, 2026 14:15
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.

emit-c: map keys and values are never dropped (clear, remove and scope exit leak owning elements)

1 participant