feat(runtime): add HashMap.entries() -> Vec<(K, V)> - #2866
Conversation
Implements the remaining additive slice of the collection remove/sentinel reshape (hew-lang#2414): `HashMap.entries()` returning an owned `Vec<(K, V)>`. Wiring spans the full stack: checker dispatch/admissibility and method resolution, MIR facts and runtime symbols, codegen layout, llvm and runtime ABI, plus the `hew_hashmap_entries_layout` runtime kernel which clones each key/value pair into a tuple element and transfers ownership into the result vector. Tests: - hew-runtime/tests/hashmap_entries_owned_balance.rs asserts an exact owned-allocation balance (allocations == frees) across map ingress, the entries clone, map free and vec free. - tests/hew/hashmap_entries.hew end-to-end coverage. - tests/vertical-slice/accept/hashmap_entries_asan.hew wired into scripts/asan-fixture-check.sh for leak detection under ASan. The balance test is load-bearing: reverting the ownership transfer so an extra owned clone escapes yields 6 allocations against 4 frees and fails the assertion. Refs: hew-lang#2414
…losure Satisfies clippy::undocumented_unsafe_blocks on the nine unsafe blocks in hew_hashmap_entries_layout and clippy::redundant_closure_for_method_calls in the owned-balance test. No behaviour change.
The fixture now calls `m.entries()` alongside keys()/values(), which adds a `hew_hashmap_entries_layout` builtin call, a new `Vec<(string, i64)>` binding, and renumbers the downstream blocks/temps. The goldens were not recaptured in the commit that changed the fixture, so `make checked-mir-verify` failed on the Linux leg of CI. checked-mir-golden: 2 changed, 0 new, 112 unchanged CHANGED hashmap_keys_values.raw.mir (+64 -50) CHANGED hashmap_keys_values.elab.mir (+61 -49) No behaviour change; `make checked-mir-verify` now reports OK (57 fixtures x 2 stages byte-identical, manifest in sync).
Recapturing the hashmap_keys_values goldens made the checked-MIR corpus materialise `hew_hashmap_entries_layout`, so the EXPECTED_UNCOVERED pin (and its now-false justification about the hidden tuple descriptor) is stale. corpus_covers_every_family_or_pins_the_gap failed with exactly: Now covered (remove from EXPECTED_UNCOVERED): ["hew_hashmap_entries_layout"] No longer covered (add a fixture or justify the pin): [] Coverage moves 135/257 -> 136/257. Test passes locally.
The fixture gained `let es = m.entries(); println(es.len());` in 38cd195 but its .expected was never regenerated, so `make checked-mir-run` failed with a one-line TRANSCRIPT MISMATCH on Linux: the corpus printed a third `2` the expectation did not list. The runtime is correct -- the map holds two entries, so keys(), values() and entries() all report 2. Only the expectation was stale.
|
The nine They were raised against the original feature commit Verified directly against the pushed head, all nine flagged lines (1803, 1805, 1808, 1820, 1830, 1836, 1842, 1844, 1850) carry a preceding
No code change is needed; the alerts should clear or be dismissed as fixed. Flagging so the review isn't held up by phantom findings — CI is 9/9 green and the PR is MERGEABLE. |
Closes #2414.
Implements the remaining additive slice of the collection remove/sentinel reshape:
HashMap.entries()returning an ownedVec<(K, V)>.Implementation
Wiring spans the full stack:
entries().hew_hashmap_entries_layoutclones each key/value pair into a tupleelement and transfers ownership into the result vector.
Proof bar
The issue asked for three things; each is covered:
tests/hew/hashmap_entries.hewplus additions tohew-codegen-rs/tests/exec/hashmap_keys_values_exec.rs.hew-runtime/tests/hashmap_entries_owned_balance.rsasserts
allocations == freesacross map ingress, the entries clone, map free,and vec free.
tests/vertical-slice/accept/hashmap_entries_asan.hewwired into
scripts/asan-fixture-check.sh.The balance test is load-bearing (verified by actual revert)
Reverting the ownership transfer so an extra owned clone escapes produces
6 allocations against 4 frees and fails the assertion:
Scope note for reviewers: those counters instrument the test's own owned payloads,
so the test targets element-ownership balance. A leak of the runtime's internal
scratch buffer is outside its window — that case is what the ASan fixture covers.
Verification
cargo test -p hew-runtime --lib— 2240 passed, run 3x.cargo test -p hew-types— all suites green (1748 + 339 + 282 + 232 + 125 + 72 + 22 + 8).mainat the time of submission.One flaky failure was observed in
transport::tests::framed_send_to_broken_pipe_fails_closed_without_signal(abroken-pipe/signal-timing test unrelated to this change). It was not reproducible:
the full lib suite passes 2240/2240 on this branch across three consecutive runs, and
the test passes in isolation on both this branch and the pristine base.