Skip to content

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

Closed
milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-75-share-peer-non-owned-move
Closed

milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-75-share-peer-non-owned-move

Conversation

@milkingndb-oss

Copy link
Copy Markdown

Summary

Fixes #75 (soundness P0). check_non_owned_move (freeze.rs) derived non_owned_origin from the binding's own origin or its aliases-chain root only. The may-share graph (#27/#35 — undirected: shallow struct/array copies, re-slices, projections, composite captures) was not consulted, and record_alias's define-time origin inheritance only fires for reference-alias shapes (Map/Slice/Pointer). So a local share peer of a parameter moved at a concurrency boundary escaped O5.1:

  • m2 := m (map param) — correctly rejected HYB-E3004 (alias + inherited origin).
  • h2 := h (struct param carrying a map) — share edge but no origin: task worker(move h2, done) passed with OK (0 diagnostics) while the emitted Go raced (fatal error: concurrent map writes reproduced on go run, per the issue's report).
  • a2 := a ([2]map[string]int param) — same gap for fixed arrays (not reference aliases); also OK (0) pre-fix, same runtime fatal.

The O5.1 rationale the checker already applies to the parameter itself ("the caller retains the argument across intra-task calls") is storage-identity identical for its share peers: the moved local is not exclusively owned by the sending frame, and freezing it cannot reach the caller's live binding (O5.2 freeze-reach).

Fix

In check_non_owned_move, when the binding's own origin and its alias-root origin are both None, scan st.share_group(name) — and each peer's alias root — for a non_owned_origin, and reject with a may-share-peer-flavored HYB-E3004 (... not a may-share peer of parameter ...). Peers are scanned in sorted order for deterministic diagnostics. The own-origin path keeps its original message byte-for-byte (map-twin regression control pins the spelling).

Tests / gates

  • hy-check/tests/param_share_move.rs (6 new): struct peer of param (spawn + send forms) -> E3004; array peer of param -> E3004; map twin regression -> E3004 (non-share spelling preserved); pure-local peer stays free of E3004 (O5.2 E3003 still fires on post-move peer use); pure-local full-accept control (peer never used post-move -> clean Accept).
  • Corpus 29/30 (29-struct-param-share-move-reject.hy, 30-array-param-share-move-reject.hy, both REJECT A1b) + VERDICTS.md rows; distribution line recomputed (the old line undercounted after row 27 landed: 8+2+16=26 against 27 registered files — now ACCEPT 8 . ACCEPT-MANAGED 2 . REJECT 19 -- 29 programs). Numbering skips 28 to leave the slot for open PR fix(hy-check): edge call results to may-share arguments on define (#73) #74's generic-call corpus file. parse_all.rs 27->29.
  • cargo test --workspace: all green.
  • tools/corpus_harness.py: 29/29 verdict agreement; tripwire not fired (verdict-level 6.9%, as-written 10.3%).
  • Repros post-fix: struct peer and array peer both HYB-E3004 (issue's repro + array twin); map twin unchanged; hyb build --emit-go refuses the repro (exit 1).
  • All 10 examples: still OK (0 diagnostics).

Compatibility

Independent of open PR #74 (this PR does not edge call results; #74 does not scan the share group at move time). Merge seam if both land: parse_all.rs count and the VERDICTS.md distribution line will need a trivial rebase bump (27+2 new files here, 1 there -> 30).

AI-assisted fix (MiMo agent via opencode); reporter of record on #75: @milkingndb-oss.

…imitlessprojects#75)

check_non_owned_move derived non_owned_origin from the binding's own
origin or its aliases-chain root only; the may-share graph (limitlessprojects#27/limitlessprojects#35)
was not consulted, and define-time origin inheritance fires for
reference-alias shapes only. A shallow struct/array copy of a param
(h2 := h / a2 := a) recorded a share edge but no origin, so the move
passed with 0 diagnostics while the caller kept a live binding to the
same storage - go run hit 'fatal error: concurrent map writes'.

When both origin lookups miss, scan st.share_group(name) (and each
peer's alias root) for a non-owned origin and reject with a
may-share-peer-flavored HYB-E3004. Peers are scanned in sorted order
for deterministic diagnostics; the own-origin path keeps its original
message byte-for-byte.

Gates: cargo test --workspace all green (6 new tests in
hy-check/tests/param_share_move.rs: struct/array/map/pure-local,
spawn+send forms); corpus harness 29/29 (corpus 29 struct peer, 30
array peer, both REJECT A1b); tripwire not fired (6.9%/10.3%);
hyb check on the issue's repros now E3004 (struct+array) with the map
twin regression intact; emit-go refuses the repro (exit 1); all 10
examples still OK (0 diagnostics).
@limitlessprojects

Copy link
Copy Markdown
Owner

Your fix is on main — the port landed as the Batch W merge (d1d7e14 series): your check_non_owned_move may-share scan + the distinct teachable message ("not a may-share peer of …") + param_share_move.rs + corpus 29/30 all carried through, and the repro rejects with your message. One seam extension credited to a fellow contributor: rickymulya's #80 unioned the alias-root's share group into the peer scan — the two fixes compose. Your report was the first on the issue, so the bounty standing follows the first-reporter rule; closing as landed with full credit.

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