Skip to content

fix(hy-check): edge call results to may-share arguments on define (#73) - #74

Closed
milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-73-call-result-may-share
Closed

milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-73-call-result-may-share

Conversation

@milkingndb-oss

Copy link
Copy Markdown

Fixes #73

What

record_may_share had no Expr::Call arm, and record_alias's Call arm only fires when the result shape is a reference alias (Map/Slice/Pointer). A call that hands back storage reachable from an argument therefore created an untracked peer: the later move froze only the original binding, and a write through the peer was accepted while the emitted Go raced.

Two repro families, one root cause (both reported and reproduced on main @ 8fb9238 with hyb check ? OK (0 diagnostics) and go run ? fatal error: concurrent map writes):

  1. Shallow struct copy through a call: h2 := alias_holder(h1) where fn alias_holder(h holder) holder { return h } - result shape is Struct, which is_reference_alias() excludes, and record_may_share skipped calls entirely. The direct form h2 := h1 was already correctly rejected ([soundness] Shallow struct/array copy and non-bare-ident aliases bypass O5.2 move freeze (h2 := h1, m2 := (agg), s2 := s1[:], holder{m: agg}) #27/checker: freeze all may-share aliases on move (fix #27) #35) - only the call spelling slipped through.
  2. Generic identity: m2 := id(m) with fn id[t any](x t) t - the result type resolves through the type parameter to Unknown, so even a map argument bypassed [soundness] Alias returned through a function call (alias := same(m)) is not frozen by move m, accepted with 0 diagnostics and races #38's alias recorder (the non-generic fn id(m map[string]int) map[string]int twin is correctly rejected today). Slice variant behaves the same.

The fix

Give record_may_share a Call arm with the same no-interprocedural-summary argument corpus 26 pinned for the alias path: when the result may share GC storage or is unresolvable (O4.9 fail-closed), edge the new binding to every non-move may-share argument root and to the method receiver (x := r.method(...)).

Precision: a concrete scalar/string result is a copy-out (no edge) - x := wrap(m) + move m still accepts, pinned by a control test. Reference-shaped results now record both the alias (#38, unchanged) and the share edge - the same twin recording m2 := m gets for the lexical form.

Verification

gate result
cargo test --workspace 294 passed, 0 failed (was 290; +4 new call_share tests)
tools/corpus_harness.py 28/28 verdict agreement, tripwire not fired (exit 0)
hyb check on all 10 examples/ all OK (0 diagnostics) (incl. 07-lru-generics - no generic false-rejects)
issue #73 repros (map/slice/struct) all now HYB-E3003 "write through a live alias of a moved value"
negative controls (direct copy, non-generic identity, scalar copy-out) unchanged - still reject / still accept as before

Test plan (for the reviewer)

  • cargo test -p hy-check --test call_share - struct form, generic spawn-form, scalar copy-out control, checker: freeze all may-share aliases on move (fix #27) #35 direct-copy regression.
  • python tools/corpus_harness.py --bin <target>/release/hyb - 28/28 including the new 28-generic-call-return-alias-freeze.hy (REJECT A1b, appended to VERDICTS.md per the amendment rule).
  • Repro files from the issue: hyb check rejects all three; before this commit they pass with 0 diagnostics and the emitted Go fatals.

Notes / out of scope


Before/after checker output (issue #73 repro 1)

$ hyb check call-struct.hy   # main @ 8fb9238
OK (0 diagnostics)
$ go run call-struct.go
fatal error: concurrent map writes

$ hyb check call-struct.hy   # this branch
error[HYB-E3003]: write through a live alias of a moved value
  --> call-struct.hy:22:9
  = ownership of `h2` left this task at the spawn `task worker(...)` ...

…mitlessprojects#73)

A define whose value is a call only recorded sharing when the RESULT
shape was a reference alias (limitlessprojects#38's record_alias Call arm), so two
forms created an untracked peer that the later `move` did not freeze:

  * a shallow struct copy through a call — `h2 := alias_holder(h1)`
    (result shape Struct: not a binding alias, and record_may_share
    had no Call arm at all), and
  * a generic identity — `m2 := id(m)` with `fn id[t any](x t) t`
    (the result type resolves through the type parameter to Unknown,
    so even a MAP argument bypassed both recorders).

Both passed `hyb check` with 0 diagnostics while the emitted Go
raced (`fatal error: concurrent map writes` — `go worker(agg)` and
the sender writing `alias` hit the same map store).

record_may_share now has a Call arm: when the result may share GC
storage (or is unresolvable — O4.9 fail-closed, same argument corpus
26 pinned for the alias path), edge the new binding to every
may-share argument root and to the method receiver. A concrete
scalar/string result stays a copy-out (no edge), so `x := wrap(m)` +
`move m` keeps accepting.

  * corpus 28 pins the generic send-form (REJECT A1b); VERDICTS.md
    row + distribution appended, parse count 27 -> 28
  * hy-check/tests/call_share.rs pins the struct form, the
    generic spawn-form, the scalar copy-out control, and the
    limitlessprojects#35 direct-copy regression
  * cargo test --workspace: 294 passed; corpus harness: 28/28
    verdict agreement; all 10 examples still check OK

Fixes limitlessprojects#73
@limitlessprojects

Copy link
Copy Markdown
Owner

Landed on main — the Batch S merge carries your Call arm in full (the struct-laundering and generic-identity shapes both reject now; the scalar copy-out control and your call_share.rs tests ride along). One mechanical note: your corpus program renumbered 28 → 31 on the way in (main's 28 was taken by the composite-nil follow-up batch that landed first — the file header and VERDICTS row were renumbered to match). Verified on main: the struct form rejects E3003, cargo 322/0, corpus 31/31, differential FULL. Closing as landed with credit — your report was first on the issue, so the bounty standing follows.

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.

[soundness] Call results that shallow-copy or launder argument storage escape the O5.2 freeze (h2 := alias_holder(h1); generic id(m))

2 participants