Skip to content

feat(formal): grow P-3 to a real borrow graph (loan edges + move-locality)#627

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/lucid-cray-4a22dp
Jun 21, 2026
Merged

feat(formal): grow P-3 to a real borrow graph (loan edges + move-locality)#627
hyperpolymath merged 1 commit into
mainfrom
claude/lucid-cray-4a22dp

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What

P-3, Wave 1: the real borrow graph. Replaces P3_BorrowSound.v's single validity bit with the actual shape of a borrow checker — multiple resources (each live or moved) and an explicit borrow graph of loan edges (reference ↦ the resource it borrows). A deref is valid iff its loan target is still live — the flow-sensitive, Polonius-style (#553) reading: loans are tracked, validity = target liveness at the point of use.

Proven (axiom-free, no Admitted)

Discharges the Siblings_Stated P3 statements for the richer model.

Scope (honest)

Still a sequential op model — no aliasing of references, no mutable borrows, no loops/CFG. Those + the real lib/borrow.ml control-flow graph are further increments. But the borrow graph (loan edges) and target-liveness validity are now real.

Track status

9 files, 14 closure reports, zero axioms. P3_BorrowSound.v stays as the single-bit seed; P3_BorrowGraph.v is the grown model (the K1/K1Let pattern). justfile/_CoqProject build it; .hypatia-ignore extends the Coq-.v-isn't-V-lang carve-out; README + PROOF-NEEDS.adoc P-3 row updated.

just -f formal/justfile check

(P-2 Wave 1 — functions/binders/substitution — is next, as a separate PR.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr


Generated by Claude Code

Wave-1 increment for P-3, replacing P3_BorrowSound.v's single validity bit
with the real shape of a borrow checker: multiple resources (each live or
moved) and an explicit borrow GRAPH of loan edges (reference ↦ borrowed
resource). A deref is valid iff its loan target is still live — the
flow-sensitive, Polonius-style (#553) reading.

Proven, axiom-free (no Admitted):
  * borrow_soundness   — an accepted program never derefs a dangling reference;
  * borrow_complete    — the checker rejects exactly the use-after-move programs;
  * move_locality      — moving resource b cannot change the validity of a deref
                         borrowing some a <> b (the genuine borrow-graph
                         property: an OMove only reaches refs whose loan points
                         at the moved resource) — a non-trivial theorem;
  * rejects the multi-resource #554 program
    [ONew 0; OBorrow 0 0; OMove 0; OUseRef 0].

Discharges the Siblings_Stated P3 statements for the richer model. Still a
sequential op model (no aliasing/mutable borrows/loops/CFG) — those + the real
lib/borrow.ml graph are further increments.

Track now 9 files, 14 closure reports, no axioms. justfile/_CoqProject build
P3_BorrowGraph; .hypatia-ignore extends the Coq-not-V-lang carve-out; README +
PROOF-NEEDS P-3 row updated (P3_BorrowSound = single-bit seed, P3_BorrowGraph =
grown graph model).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr
@github-actions

Copy link
Copy Markdown

🔍 Hypatia Security Scan

Findings: 41 issues detected

Severity Count
🔴 Critical 2
🟠 High 23
🟡 Medium 16

⚠️ Action Required: Critical security issues found!

View findings
[
  {
    "reason": "Action denoland/setup-deno@v2 needs attention",
    "type": "unpinned_action",
    "file": "publish-jsr.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in instant-sync.yml",
    "type": "secret_action_without_presence_gate",
    "file": "instant-sync.yml",
    "action": "peter-evans/repository-dispatch",
    "rule_module": "workflow_audit",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affinescript-cli/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (2 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affine-vscode/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-vite/src/affine-plugin-improved.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "expect() in hot path (32 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/wasm_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "expect() in hot path (29 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/affine_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (2 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/panic.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (1 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/alloc.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (3 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/ffi.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  }
]

Powered by Hypatia Neurosymbolic CI/CD Intelligence

@hyperpolymath hyperpolymath marked this pull request as ready for review June 21, 2026 13:25
@hyperpolymath hyperpolymath merged commit 16a849a into main Jun 21, 2026
15 of 16 checks passed
@hyperpolymath hyperpolymath deleted the claude/lucid-cray-4a22dp branch June 21, 2026 13:25
hyperpolymath added a commit that referenced this pull request Jun 21, 2026
… xfail pin-liveness (#631)

Makes `docs/SOUNDNESS.adoc` keep every promise it makes. The ledger on
`main` is "prose ahead of mechanism" (it claims content-binding /
stamp-enforcement / pinned xfails, but the gate enforced only 2 of
those). This builds the missing mechanism, and folds in the closed-#625
capability-matrix anchoring.

## The five properties (each maps to a function in the gate)

| # | Property | Function | Provenance |
|---|----------|----------|-----------|
| 1 | Anchors exist | `check_anchors_exist` | Jonathan's #622 design
(kept) |
| 2 | Back-links | `check_backlinks` | Jonathan's #622 design (kept) |
| 3 | **Content-binding** | `check_content_binding` +
`tools/soundness-anchors.sha256` + `--reseal` | **new** |
| 4 | **Stamp-enforcement** | `check_stamp` | **new** |
| 5 | **Pin-liveness (xfail)** | `check_pins` +
`test/xfail/test_xfail_pins.ml` | **new** |

`## What this gate enforces` is documented at the top of the script.
Everything **fails closed**.

## Ground-truth correction (compiler wins)

Running the compiler showed **#559 generic-subsumption is already
detected/rejected** (`impl[T] Greet for Box[T]` vs `impl Greet for
Box[Int]` → "Trait coherence violation"). So the ledger's `open
(tracked)` "not yet detected" was stale **in the dangerous direction**.
Corrected to `fixed` with a positive test; the stale `test_e2e.ml`
comment fixed. → one fewer xfail pin than the spec assumed.

Also: the stub-return row uses **#624** (the real tracker); #560 is
*variable-string wasm ops*, unrelated — this change supplies the pin
#628 couldn't (the fixture/test now exist). Stamp re-pointed to
`dd6c19e` (a real main-ancestor; the old `d55e22c` was squash-orphaned).
Metatheory note updated for the new `formal/` proofs (#620#627).

## Self-tests — each new check watched failing

```
SELF-TEST 1 — Property 3 (mutate a fixture by one token):
  ERROR (property 3): anchor content drift vs tools/soundness-anchors.sha256 ...

SELF-TEST 2 — Property 4 (un-advanced/orphaned stamp + soundness change):
  ERROR (property 4): stamp d55e22c is not an ancestor of HEAD; re-point :ground-truth-sha: ...

SELF-TEST (5a) — Property 5 (pinned row names a missing pin):
  ERROR (property 1): test anchor not defined: test_stub_backend_return_DELETED
  FATAL: anchor test:test_stub_backend_return_DELETED: expected exactly one defining file, found 0 (fail closed)

SELF-TEST (5b) — Property 5 (an xfail pin flips to XPASS):
  ALARM (property 5): pin test_resume_nontail_xfail is PASSING — the hole may be fixed.
  Open docs/SOUNDNESS.adoc and update the row to 'fixed' (do NOT just silence the pin).
```

Full suite green (534 tests; xfail harness reports both pins
`XFAIL-OK`), all four guard gates green, `dune build`/`dune runtest`
green at `dd6c19e`.

## Claims I could not make fully mechanical (named, not silently
softened)

1. **Content-binding scope.** Fixtures + pinned-test *bodies* are
digest-bound (11/12 anchors); the one SUITE-file anchor (`#553` →
`test/test_borrow_polonius.ml`) is existence+stamp-checked only — a
whole-file hash is too coarse. The ledger sentence was tightened to say
exactly this.
2. **Stamp "advanced-in-this-change" detection** is robust for the
normal *branch-off-fresh-main* workflow (and the orphaned-stamp case
fails closed, self-test 2). It has a known edge in a
*multi-commit-since-stamp* history (stamp bumped in an earlier commit,
soundness changed again later without re-bump could read as "advanced");
decision-2's full "diff-on-main" freshness check is not separately
implemented. Flagged for your call.

## CI
`build` job now checks out `fetch-depth: 0` so property 4 can resolve
the stamp; the xfail harness is in `.ocamlformat-ignore` (authored
without ocamlformat available).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01BbxKhXQwTvVgkYDgBMLJoa

---
_Generated by [Claude
Code](https://claude.ai/code/session_01BbxKhXQwTvVgkYDgBMLJoa)_

Co-authored-by: Claude <noreply@anthropic.com>
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.

1 participant