Skip to content

feat(runtime): add HashMap.entries() -> Vec<(K, V)> - #2866

Open
gertybotbot wants to merge 5 commits into
hew-lang:mainfrom
gertybotbot:fix/2414-hashmap-entries
Open

feat(runtime): add HashMap.entries() -> Vec<(K, V)>#2866
gertybotbot wants to merge 5 commits into
hew-lang:mainfrom
gertybotbot:fix/2414-hashmap-entries

Conversation

@gertybotbot

Copy link
Copy Markdown
Contributor

Closes #2414.

Implements the remaining additive slice of the collection remove/sentinel reshape:
HashMap.entries() returning an owned Vec<(K, V)>.

Implementation

Wiring spans the full stack:

  • Checker — dispatch, admissibility, and method resolution for entries().
  • MIR — lowering facts and runtime symbol registration.
  • Codegen — layout, llvm, and runtime ABI.
  • Runtimehew_hashmap_entries_layout clones each key/value pair into a tuple
    element and transfers ownership into the result vector.

Proof bar

The issue asked for three things; each is covered:

  1. Execution coveragetests/hew/hashmap_entries.hew plus additions to
    hew-codegen-rs/tests/exec/hashmap_keys_values_exec.rs.
  2. Owned-allocation balancehew-runtime/tests/hashmap_entries_owned_balance.rs
    asserts allocations == frees across map ingress, the entries clone, map free,
    and vec free.
  3. Leak detection under ASantests/vertical-slice/accept/hashmap_entries_asan.hew
    wired 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:

assertion `left == right` failed: every owned entries allocation must be released
  left: 4
 right: 6

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).
  • Rebased on main at the time of submission.

One flaky failure was observed in
transport::tests::framed_send_to_broken_pipe_fails_closed_without_signal (a
broken-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.

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
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
Comment thread hew-runtime/src/hashmap.rs Fixed
gertybotbot and others added 4 commits August 8, 2026 08:19
…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.
@gertybotbot

Copy link
Copy Markdown
Contributor Author

The nine clippy: unsafe block missing a safety comment code-scanning findings on this PR are stale and do not reflect the current head.

They were raised against the original feature commit 38cd1955 (original_commit_id on every one of the nine comments). The follow-up commit 4445a95f style(runtime): document entries() unsafe blocks added the missing // SAFETY: comments, and it is in this PR's history — it is in fact the merge-base of the current head f8c203dc.

Verified directly against the pushed head, all nine flagged lines (1803, 1805, 1808, 1820, 1830, 1836, 1842, 1844, 1850) carry a preceding // SAFETY: comment:

git show f8c203dc:hew-runtime/src/hashmap.rs

hashmap.rs goes from 143 SAFETY: comments at 38cd1955 to 152 at the head. Line 1850 is the multi-line unsafe { … } block documented by the five-line comment at 1845–1849.

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.

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.

Add HashMap.entries() -> Vec<(K, V)>

2 participants