Repository navigation
fix(hy-check,hy-emit): assign key shape and emit key range on single-var map iteration (fixes #3422) - #3675
Merged
limitlessprojects merged 1 commit intoNov 5, 2026
Conversation
…var map iteration (fixes limitlessprojects#3422)
CarlitoDon
force-pushed
the
fix/issue-3422-single-var-map-iteration
branch
from
November 5, 2026 01:57
b6ac5a0 to
b5b2dac
Compare
limitlessprojects
merged commit Nov 5, 2026
f0bce7f
into
limitlessprojects:main
3 of 4 checks passed
limitlessprojects
pushed a commit
that referenced
this pull request
Nov 5, 2026
… iteration (fixes #3422) Verification evidence (battery on committed trial merge f0bce7f, tree 5b1724d): - merge gate: clean auto-merge of PR head b5b2dac with main - cargo test --workspace: 437 suites ok, 0 failed - corpus harness: verdict agreement 135/135, tripwire not fired - differential loop FULL: accept-side 45/45 build+run, reject-side 90/90 Contributions by CarlitoDon: - freeze.rs: replay loop var shape for Map now binds the KEY when iterating with a single variable (vars.len()==1), value only for two-variable form — per SPEC-LANGUAGE.md LX13 - shape.rs: shape_of_expr single-var map iteration vec![v] -> vec![k], same LX13 rule - new tests issue_3422_single_var_map_iteration.rs (checker: for k in m binds key, k/v two-var binds both) and issue_3422_single_var_map_range_emit.rs (emitted Go range form) CREDIT: @CarlitoDon
Owner
Landed: merged to main as
|
| Gate | Result |
|---|---|
| Merge gate | clean auto-merge with main |
| cargo test --workspace | 437 suites ok, 0 failed |
| Corpus harness | verdict agreement 135/135, tripwire not fired |
| Differential loop FULL | accept-side 45/45 build+run, reject-side 90/90 |
What landed
freeze.rs: single-variable map iteration now replays the key shape (vars.len()==1 → *k), value shape only for the two-variable form — per SPEC-LANGUAGE.md LX13.shape.rs:shape_of_exprsingle-var map armvec![v]→vec![k].- Two new suites pinning the checker behavior and the emitted
for k := range mlowering.
Both call sites were small and exactly where the LX13 rule lives; the two-variable path is untouched, matching the spec. The emitter side already produced the correct Go range form on current main, so no emit change was needed in the merge — your checker tests pin the contract.
Bounty: recorded per BOUNTY.md / discussion #295 against issue #3422.
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3422.
Per SPEC-LANGUAGE.md LX13, single-variable map iteration (
for k in m) binds the map key (for k := range min Go), whereas two-variable iteration (for k, v in m) binds key and value. Two soundness and lowering gaps were identified:hy-check: Inshape.rs:iterate_var_shapesandfreeze.rs, single-variable map iteration assigned the value shape(**v).clone()instead of the key shape(**k).clone(). For maps with pointer/reference keys (e.g.map[*box]int), this preventedalias := kfrom being tracked under alias sharing and allowed concurrent mutation after movingalias, causing runtime data races.hy-emit: Inlib.rs:binding_kind_of_tyandstmt.rs:is_map_expr, map type aliases and struct fields of map type were not unwrapped/resolved toBindingKind::Map, causing single-variable iteration to lower tofor _, k := range ...(value binding) instead offor k := range ...(key binding).Changes
compiler/crates/hy-check/src/shape.rsandsrc/freeze.rs: assignk(the key shape) on single-variable map iteration whenn_vars == 1/vars.len() == 1.compiler/crates/hy-emit/src/lib.rs(binding_kind_of_ty): recursively unwrap user type aliases (n5_aliases) to recognize map types.compiler/crates/hy-emit/src/stmt.rs(is_map_expr): resolve struct fields (n5_structs) to detect map fields and emitfor k := range h.m.compiler/crates/hy-check/tests/issue_3422_single_var_map_iteration.rscompiler/crates/hy-emit/tests/issue_3422_single_var_map_range_emit.rsVerification
cargo test --test issue_3422_single_var_map_iteration: passes (verdictRejecton data race repro).cargo test --test issue_3422_single_var_map_range_emit: passes (emitsfor k := range).make check: OK (all 33 differential loop tests, guarantees, runner, and cargo checks pass).Closes #3422
/claim #3422