Skip to content

[wildcard] Replace depth-bounded AST loan re-walking and A5 callback escapes with Tarjan-SCC effect-polymorphic fn summaries (flips GUARANTEES Rows 5 & 9) #1714

Open

Description

@ryder777777

The idea, in a paragraph

Delete hy-check/src/loans.rs's five depth-bounded (depth <= 4) interprocedural AST body re-walkers AND eliminate the A5 closure/callback escape blind spot (GUARANTEES.md Rows 5 & 9) in one paradigm shift: equip TypeExpr::Fn with inferred region-flow & invocation-multiplicity effect summaries (Φ = (slot_shares ⊆ k×k, ret_shares ⊆ r×r, mult ∈ {0, 1, sync*, async*})), synthesized modularly bottom-up per Tarjan SCC fixpoint with zero user annotations on .hy functions and a single 2-bit callback multiplicity tag on curated Go stdlib higher-order APIs (sort.slice = sync*, sync.once.do = 1, http.handle_func / time.after_func = async*).

Which assumption it breaks

It kills two sacred cows simultaneously:

  1. Whole-AST interprocedural body re-walking in loans.rs (collect_callee_param_stores, walk_call_param_stores, callee_shared_return_pairs, collect_callee_const_return_roots, callee_spawns_or_sends_param) and its depth <= 4 horizon (which caused live P0 go run -race data races on depth > 4 call chains and indirect fn bindings in #1698).
  2. GUARANTEES.md Row 5 & Row 9 ("captures without a boundary statement are outside (A5)" / "Values escaping into Go APIs (net/http handlers, callbacks): No checker claim"): today Hybrid gives up on every callback escape because fn(...) types erase whether a callback is invoked synchronously on the caller's stack before return (sort.Slice) or concurrently across goroutines (http.HandleFunc, time.AfterFunc).

Why this is a breakthrough, not an increment

Patching loans.rs by raising depth from 4 to 8 or Conservatively linking all arguments on indirect calls (#1698) is an increment that hits a hard precision-vs-soundness wall:

  • Without effect-bearing fn types, any safe higher-order .hy helper (apply(cb, m, xs)) or sequential stdlib callback (sort.slice(xs, fn(i, j) { swaps += 1; ... })) must either fail open (unsound P0 race on http.handle_func) or fail closed on every mutating capture (forcing managed noise on purely sequential sort.slice / strings.map / iterator callbacks).
  • Lifting storage-flow (slot_shares, ret_shares) and invocation multiplicity (1 | sync* | async*) into the principal signature of every fn SCC turns interprocedural ownership checking from exponential/depth-capped AST re-traversal into modular $O(|V| \cdot k^3)$ algebraic composition — exact at depth 1,000 and across mutual recursion, while flipping GUARANTEES.md Rows 5 & 9 from "outside / no checker claim" to Guaranteed in the checked subset without analyzing foreign Go stdlib bodies.

How we would know it works (or doesn't)

Pre-registered falsifiable milestones (backed by an executable prototype in spikes/effect-polymorphic-fn-summaries/):

  • M1 / H1 (Depth-unbounded soundness & speed): Tarjan-SCC fixpoint summary inference catches 100% of parameter-store and multi-return alias flows at call-chain depth 100 and across mutually recursive SCCs (ping <-> pong) in < 5 ms (< 1 ms measured on a 102-node call graph), deleting depth <= 4 completely.
  • M1 / H2 (Row 5 & Row 9 differential -race precision): Across a differential suite of sequential callbacks (sort.Slice, bytes.Map, user for_each) vs concurrent/escaped callbacks (http.HandleFunc, time.AfterFunc, goroutine-spawning higher-order .hy helpers), sync* accepts sequential mutating captures with 0 go run -race warnings and 0 managed blocks, while async* rejects concurrent mutating captures with HYB-E3002.
  • Falsifier F1 (Stored fn fields & contravariant subtyping): When a closure is stored into a heap struct field (h.cb = fn() { x += 1 }) rather than called immediately, call-site multiplicity is unknown at creation time. The proposal fails if stored fn fields require heavy region annotations in user code; it succeeds only if defaulting unannotated stored fn fields to async* (with optional sync fn(...) parameter qualifier for borrowed callbacks) keeps corpus false-positive rate <= 2% on tests/checker-corpus/ (SPEC §9.7 tripwire).

Cost honesty (optional but powerful)

  • Deleted (~900 LOC in hy-check/src/loans.rs): All five depth <= 4 recursive AST body walkers and ad-hoc closure_defs side tables are replaced by a single pre-pass (hy-check/src/summaries.rs, ~300 LOC) run between resolve and loans.
  • Changed (hy-syntax / hy-check/src/shapes.rs): TypeExpr::Fn gains an internal inferred effect summary (no mandatory surface syntax change for .hy code), and curated callback entries in shapes.rs (sort.slice, filepath.walk_dir, http.handle_func, time.after_func, sync.once.do) carry a 2-bit multiplicity tag (One, SyncMany, AsyncMany), with uncurated foreign callbacks failing closed as AsyncMany per O4.9.

Track terms

  • I understand no prototype is required and failure-with-knowledge is a valid, paid outcome
  • I understand all outcomes (including declines and failures) are published in MOONSHOT.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions