Repository navigation
Description
The idea, in a paragraph
Replace hy-check's AST-inlining interprocedural analysis (resolve_callee_slots_and_body in loans.rs, bounded at recursion depth 4) and ad-hoc single-pass loop back-edge replay (check_loop_backedge_replay in freeze.rs + closures.rs defer watch scans) with Polymorphic Relational Ownership Summaries (FnSummary) + Monotone Fixed-Point Abstract Interpretation over a Type-Erased Call/CFG Graph. Instead of re-walking callee AST bodies at every call site and replaying loop bodies once on a cloned FnState that gets discarded at loop exit, hy-check lowers each function once (in bottom-up SCC topological order over the call graph) into a compact, type-parameter-independent relational transfer summary f[T](...), and .hyi package boundaries without AST re-walking, and (2) guaranteed convergence on arbitrary
Which assumption it breaks
It kills three foundational assumptions of the current hy-check architecture (answering Active Solicitation #2 — "Replace the borrow-checker machinery"):
-
Kills "Interprocedural Tier-0 is depth-bounded AST inlining at call sites" (
loans.rs:resolve_callee_slots_and_body,depth > 4):
Today, every call site re-resolves the callee's AST body by syntactic callee expression shape (Expr::Ident,Expr::Field,Expr::Indexafter stripping[T]type arguments) and walks the callee's statements up todepth <= 4. That means:- Syntactic surface variations at the call site (such as explicit generic instantiation
link[int](&dst, &src)in [soundness] hy-check(loans): explicit generic type arguments on calls bypass interprocedural store tracking (HYB-E3003) and A3 map-slot loan invalidation (HYB-E3102) #4366 / PR fix(hy-check): strip explicit generic type arguments in interprocedural store and A3 callee lookups (fixes #4366) #4367) silently missed the callee lookup and failed open. - Any call chain of depth
$\ge 5$ or mutual recursion across helpers silently truncates interprocedural store/share/A3 propagation. - Cross-package calls across
.hyiinterface boundaries have no AST body to inline, forcing either conservative over-rejection or unsound under-tracking.
- Syntactic surface variations at the call site (such as explicit generic instantiation
-
Kills "Single-pass linear AST walk + 1-shot
check_loop_backedge_replaysuffices for loops" (freeze.rs:892–1211):
Today,Pass Bwalks statements once in lexical order andcheck_loop_backedgeruns a singlecheck_loop_backedge_replaypass oniter_stand then discardsreplay_st. As proven by the live P0 soundness bug that fell directly out of this proposal ([soundness] hy-check(freeze): single-pass check_loop_backedge_replay and discarded post-loop state miss multi-hop loop-carried aliases, non-owned origins, and borrows (HYB-E3003 / HYB-E3004 / HYB-E3104) #4375 / fix PR fix(hy-check): replay loop back-edges to fixed point and propagate loop-carried state (fixes #4375) #4376) and [soundness] hy-check(freeze): check_loop_backedge_replay discards HYB-E3101 and HYB-E3102, allowing loop-carried aliases to invalidate live map-slot loans #4370 / PR fix(hy-check): retain HYB-E3101 and HYB-E3102 diagnostics in check_loop_backedge_replay (fixes #4370) #4371:- A 2-hop loop-carried shift (
q = p; p = m2,q = p; p = param, orq = p; p = &local_ainsidefor i in 0..3) requires 2 back-edge hops beforeqcarries the alias/origin/borrow at the top of the loop body (i == 2), defeating any 1-pass back-edge replay (HYB-E3003,HYB-E3004,HYB-E3104). - Discarding the back-edge state at loop exit meant
for i in 0..2 { u = t; t = m }followed by post-looptask worker(move u, done); m[0] = 42was accepted with0 diagnosticsand raced immediately.
- A 2-hop loop-carried shift (
-
Kills "Ad-hoc syntactic statement pattern matching for
deferandclosures.rswatch sets":
Today,closures.rsmaintains bespoke statement pattern matchers (update_pre_defer_peers,update_post_defer_watch) separate fromloans.rs, so field/index store assignments (h.m = other,s[0] = other) were tracked inloans.rsbut missed inclosures.rs([soundness] hy-check(closures): update_pre_defer_peers and update_post_defer_watch ignore field/index store assignments, allowing defer to race with task move (HYB-E3003) #4368 / PR fix(hy-check): track field and index store assignments in defer peer and watch tracking (fixes #4368) #4369). Under abstract interpretation over$\mathcal{L}$ ,deferarguments and closure captures are simply terminal CFG observer nodes reading the unified abstract state.
Why this is a breakthrough, not an increment
A normal feature or soundness bounty patches one symptom at a time: strip [T] in resolve_callee_slots_and_body (#4366), add PlaceKind::Field | PlaceKind::Index to closures.rs (#4368), add HYB-E3101/HYB-E3102 to the replay filter (#4370), or add a bounded multi-hop loop in freeze.rs (#4375). Every one of those bugs existed because hy-check conflates syntax traversal with dataflow solver semantics:
-
Three parallel mini-interpreters (
loans.rsPass B,freeze.rscheck_loop_backedge_replay, andclosures.rscheck_body_boundaries/deferwatch) each re-implement a slightly different subset of statement transfer rules. Whenever one interpreter is missing a statement form or stops after$k=1$ replay, a P0 soundness hole opens. -
Replacing AST re-walking with Polymorphic Relational Summaries (
FnSummary) + a single monotone CFG dataflow engine changes whathy-checkis:-
One Transfer Function, Zero Drift: Every statement updates
$\mathcal{L}$ through a single monotone transfer function$\llbracket s \rrbracket : \mathcal{L} \to \mathcal{L}$ shared by straight-line code, loops,deferedges, and closure bodies. -
Polymorphic & Modular by Construction: Type erasure before summary generation means
fn link[T](dst *holder[T], src *holder[T])has the exact same relational summary$\Sigma_{\text{link}} = {\text{Share}(\text{param}_0, \text{param}_1)}$ regardless of whether it is called aslink(&a, &b)orlink[int](&a, &b). Summaries can be serialized directly into.hyiexport headers for zero-AST cross-package checking. -
Polynomial Worst-Case Bound: For a function with
$|V|$ bindings, the abstract lattice$\mathcal{L}$ has finite height$H \le |V|^2 + 3|V|$ . Monotone chaotic iteration over any loop (or recursive call SCC) is mathematically guaranteed to terminate in$\le H$ steps—turning loop/recursion soundness from a whack-a-mole of unrolling heuristics into a theorem (Tarski's Fixed-Point Theorem).
-
One Transfer Function, Zero Drift: Every statement updates
How we would know it works (or doesn't)
This proposal already yielded a live, race-verified P0 soundness discovery and fix (#4375 / PR #4376) per the MOONSHOT.md P0 fast-track rule. To evaluate the full architectural shift, we pre-register three concrete, falsifiable hypotheses and milestones:
-
Falsifier F1 (Convergence & Compile-Time Budget):
-
Hypothesis: Computing
$\text{lfp}(F)$ over$\mathcal{L}$ and bottom-upFnSummarySCC resolution across all 139 corpus programs and 480+ test suites requires$\le 4$ iterations at the 99th percentile of loops/SCCs and keeps totalhyb checkwall-clock p50/p99 within$\le 1.15\times$ of currentmain. -
Falsified if: Any real or adversarial nested-loop fixture causes
$|V|^2$ blowup exceeding$1.5\times$ check latency or$> 8$ fixed-point iterations on non-pathological code.
-
Hypothesis: Computing
-
Falsifier F2 (Soundness & Zero-False-Positive Precision on the 139-Program Corpus):
-
Hypothesis: Replacing
resolve_callee_slots_and_body(depth-4 AST walk) with relationalFnSummaryapplication and monotone loop fixed-point iteration preserves 139/139 verdict agreement (zero false positives on allACCEPTfixtures, includingok_fresh_rebindswhere loop variables are overwritten by fresh literals on every iteration) while rejecting:- Arbitrary
$k$ -hop loop-carried alias/origin/borrow chains ($k \in {2, 3, 5}$ ) both in-loop and post-loop ([soundness] hy-check(freeze): single-pass check_loop_backedge_replay and discarded post-loop state miss multi-hop loop-carried aliases, non-owned origins, and borrows (HYB-E3003 / HYB-E3004 / HYB-E3104) #4375 class), - Depth-6 interprocedural store chains (
f1 -> f2 -> f3 -> f4 -> f5 -> f6storingsrc.mintodst.m, which currentdepth > 4inloans.rsmisses!), - Mutually recursive helper pairs (
even_link$\leftrightarrow$ odd_link) that share storage across recursion.
- Arbitrary
-
Falsified if: Path-insensitive join
$\sqcup$ at loop headers introduces false-positiveHYB-E3003/HYB-E3004rejections on any existingACCEPTcorpus program where a binding is unconditionally killed/re-owned before use. (Remedy if fired: Gen/Kill relational transfer functions$f(X) = (X \setminus \text{Kill}) \cup \text{Gen}$ so an unconditional fresh-literal rebind kills prior alias edges while preserving back-edge reachability.)
-
Hypothesis: Replacing
-
Falsifier F3 (Code Deletion & Interpreter Unification Ratio):
-
Hypothesis: Unifying the transfer step across Pass B, loop back-edges, and
deferwatch tracking deletes$\ge 600$ lines of duplicated statement-walking boilerplate acrossloans.rs,freeze.rs, andclosures.rs.
-
Hypothesis: Unifying the transfer step across Pass B, loop back-edges, and
Cost honesty (optional but powerful)
- What gets rewritten:
loans.rs:resolve_callee_slots_and_body(the 4-level recursive AST walker for interprocedural parameter store and A3 map-mutation scanning) is replaced by a bottom-upFnSummarypass over the call-graph SCCs (TarjanSCCoverself.fns+self.method_decls).freeze.rs:check_loop_backedge_replayandloans.rs:replay_const_backedgeare unified into a single monotone loop fixed-point solver overFnState.closures.rs:update_pre_defer_peersandupdate_post_defer_watchdelegate to the same place/expression transfer primitives asloans.rs.
- What stays untouched:
- Surface syntax (
hy-syntax), emitter (hy-emit), runtime (libhyrt.a), diagnostic codes (HYB-E3001..HYB-E3104), andGUARANTEES.mduser-facing semantics remain 100% compatible.
- Surface syntax (
- Migration path:
- Can land incrementally in 2 self-contained stages: Stage 1 lands the monotone loop fixed-point + post-loop state propagation (prototyped and verified in PR fix(hy-check): replay loop back-edges to fixed point and propagate loop-carried state (fixes #4375) #4376 fixing [soundness] hy-check(freeze): single-pass check_loop_backedge_replay and discarded post-loop state miss multi-hop loop-carried aliases, non-owned origins, and borrows (HYB-E3003 / HYB-E3004 / HYB-E3104) #4375, 139/139 corpus green); Stage 2 lands the bottom-up
FnSummarytable replacingresolve_callee_slots_and_body's depth-4 AST walk.
- Can land incrementally in 2 self-contained stages: Stage 1 lands the monotone loop fixed-point + post-loop state propagation (prototyped and verified in PR fix(hy-check): replay loop back-edges to fixed point and propagate loop-carried state (fixes #4375) #4376 fixing [soundness] hy-check(freeze): single-pass check_loop_backedge_replay and discarded post-loop state miss multi-hop loop-carried aliases, non-owned origins, and borrows (HYB-E3003 / HYB-E3004 / HYB-E3104) #4375, 139/139 corpus green); Stage 2 lands the bottom-up
Payout wallet (Base USDC): 0x8E85C5d9a31198B71DA5cB59cE968363685e3eB7
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
Activity