Skip to content

[wildcard] Kill AST-Inlining Interprocedural & Single-Replay Loop Analysis: Polymorphic Relational Summaries + Monotone Fixed-Point Abstract Interpretation #4377

Open

Description

@Mekdou23

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 $\Sigma_f = (\Delta_{\text{share}}, \Delta_{\text{origin}}, \Delta_{\text{loan}}, \Delta_{\text{mut}}, \Delta_{\text{consume}})$ over formal parameter/receiver/return slots, and solves intra-procedural loops via Chaotic Iteration to the least fixed point $\text{lfp}(F)$ over the finite product lattice $\mathcal{L} = \mathcal{P}(V \times V){\text{share}} \times (V \to \mathcal{P}(\text{Origin})) \times \mathcal{P}(\text{Loan}) \times \mathcal{P}(V){\text{defer}}$. What becomes possible that is impossible today: (1) sound, depth-unbounded interprocedural alias/loan/origin propagation across mutually recursive functions, generic instantiations f[T](...), and .hyi package boundaries without AST re-walking, and (2) guaranteed convergence on arbitrary $k$-hop loop-carried alias/loan/origin chains both inside and after loops.

Which assumption it breaks

It kills three foundational assumptions of the current hy-check architecture (answering Active Solicitation #2 — "Replace the borrow-checker machinery"):

  1. 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::Index after stripping [T] type arguments) and walks the callee's statements up to depth <= 4. That means:
  2. Kills "Single-pass linear AST walk + 1-shot check_loop_backedge_replay suffices for loops" (freeze.rs:892–1211):
    Today, Pass B walks statements once in lexical order and check_loop_backedge runs a single check_loop_backedge_replay pass on iter_st and then discards replay_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, or q = p; p = &local_a inside for i in 0..3) requires 2 back-edge hops before q carries 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-loop task worker(move u, done); m[0] = 42 was accepted with 0 diagnostics and raced immediately.
  3. Kills "Ad-hoc syntactic statement pattern matching for defer and closures.rs watch sets":
    Today, closures.rs maintains bespoke statement pattern matchers (update_pre_defer_peers, update_post_defer_watch) separate from loans.rs, so field/index store assignments (h.m = other, s[0] = other) were tracked in loans.rs but missed in closures.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}$, defer arguments 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.rs Pass B, freeze.rs check_loop_backedge_replay, and closures.rs check_body_boundaries / defer watch) 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 what hy-check is:
    1. 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, defer edges, and closure bodies.
    2. 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 as link(&a, &b) or link[int](&a, &b). Summaries can be serialized directly into .hyi export headers for zero-AST cross-package checking.
    3. 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).

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-up FnSummary SCC resolution across all 139 corpus programs and 480+ test suites requires $\le 4$ iterations at the 99th percentile of loops/SCCs and keeps total hyb check wall-clock p50/p99 within $\le 1.15\times$ of current main.
    • Falsified if: Any real or adversarial nested-loop fixture causes $|V|^2$ blowup exceeding $1.5\times$ check latency or $&gt; 8$ fixed-point iterations on non-pathological code.
  • Falsifier F2 (Soundness & Zero-False-Positive Precision on the 139-Program Corpus):
    • Hypothesis: Replacing resolve_callee_slots_and_body (depth-4 AST walk) with relational FnSummary application and monotone loop fixed-point iteration preserves 139/139 verdict agreement (zero false positives on all ACCEPT fixtures, including ok_fresh_rebinds where loop variables are overwritten by fresh literals on every iteration) while rejecting:
      1. 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),
      2. Depth-6 interprocedural store chains (f1 -> f2 -> f3 -> f4 -> f5 -> f6 storing src.m into dst.m, which current depth > 4 in loans.rs misses!),
      3. Mutually recursive helper pairs (even_link $\leftrightarrow$ odd_link) that share storage across recursion.
    • Falsified if: Path-insensitive join $\sqcup$ at loop headers introduces false-positive HYB-E3003/HYB-E3004 rejections on any existing ACCEPT corpus 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.)
  • Falsifier F3 (Code Deletion & Interpreter Unification Ratio):
    • Hypothesis: Unifying the transfer step across Pass B, loop back-edges, and defer watch tracking deletes $\ge 600$ lines of duplicated statement-walking boilerplate across loans.rs, freeze.rs, and closures.rs.

Cost honesty (optional but powerful)

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

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

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