Skip to content

fix(hy-check): reject moving may-share peers of non-owned bindings (fixes #75) - #80

Closed
rickymulya wants to merge 1 commit into
limitlessprojects:mainfrom
rickymulya:fix-issue-75-may-share-non-owned-origin
Closed

rickymulya wants to merge 1 commit into
limitlessprojects:mainfrom
rickymulya:fix-issue-75-may-share-non-owned-origin

Conversation

@rickymulya

Copy link
Copy Markdown
Contributor

Summary

Fixes #75.

Moving a may-share peer of a non-owned binding (e.g. shallow struct or array copy of a parameter: h2 := h; task worker(move h2)) escaped the O5.1 non-owned check, causing fatal error: concurrent map writes at runtime.

Root Cause & Fix

In compiler/crates/hy-check/src/freeze.rs::check_non_owned_move, the check inspected only the binding's immediate non_owned_origin and its direct alias-root. Unlike freeze_binding (which unions in st.share_group(&m) to capture shallow struct/array copies and slices), check_non_owned_move did not consult the may-share graph.

Fix:
When the binding's own origin and direct alias root have non_owned_origin: None, check_non_owned_move now inspects sorted peers in st.share_group(name) (and st.share_group(&root)). If any peer in the connected component originated from a non-owned source (parameter, closure capture, range variable), the move is rejected with HYB-E3004 under O5.1 / O5.4.

Tests

Added regression cases in compiler/crates/hy-check/src/lib.rs::non_owned_param_capture_and_range_moves_reject_e3004:

  1. Struct parameter peer moved (h2 := h; task worker(move h2)): rejected with HYB-E3004.
  2. Array parameter peer moved (a2 := a; task worker(move a2)): rejected with HYB-E3004.
  3. Positive control: purely local struct copy moved (h := holder{...}; h2 := h; task worker(move h2)): accepted cleanly.

…ixes limitlessprojects#75)

In `check_non_owned_move`, if the binding's own origin and alias-root origin
are `None`, check `st.share_group(name)` (and alias root) for any peer binding
carrying a `non_owned_origin`. Shallow copies (structs, arrays, slices, projections)
of parameters or closure captures retain aliasing in the caller, violating O5.1
and escaping HYB-E3004.

- hy-check/src/freeze.rs: inspect sorted peers from `share_group` for `non_owned_origin`.
- hy-check/src/lib.rs: add regression unit tests for struct parameter peer,
  array parameter peer, and positive control for purely local struct copy.
@limitlessprojects

Copy link
Copy Markdown
Owner

Your fix is on main — the port landed as the Batch W merge (d1d7e14 series). Your scan is the one that made it in broader: the peer scan unions the alias-chain root's share group with the binding's own (all_peers.extend(st.share_group(&root))) — the rest of the port carries your fellow reporter's diagnostic wording and corpus programs (their #83, per the first-reporter rule), but the union is yours and the commit names it. Verified on main: the issue repro rejects E3004, cargo 306/0, corpus 30/30. Closing as landed with credit — thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants