Repository navigation
Description
The production borrow checker (lib/borrow.ml) accepts programs that use a value after it was moved, hold two live &mut to one place, write under a live shared borrow, and return a reference to a dead local. These are false negatives of the same class as #554: they accept wrong programs, which is the class #563 puts in its top tier (T0).
This also matters for the v1 decision. #563 words the fallback cut as "lexical checker + #554 fixed + disclosed over-rejection", which assumes the lexical checker is only incomplete. It is unsound.
Reproduce
Re-verified on main-based build 161eaaf: each program below prints Type checking passed, and each control is rejected with a borrow error.
module P;
fn pick(ref x: Int) -> ref Int { return &x; }
fn consume(own v: Int) -> Int { return v; }
fn main() -> Int { /* body from the table */ }
| Id | Class | main body |
Violation |
|---|---|---|---|
| U-A2 | borrow copied out of its binder into a tuple | let a: Int = 7; let r = &a; let t = (r, 0); let _g = consume(a); let v = *(t.0); return v; |
use after move |
| U-B2 | reference binder reassigned inside if |
let a: Int = 7; let b: Int = 8; let c = true; let mut r = pick(a); if c { r = pick(b); } let _g = consume(b); let v = *r; return v; |
use after move |
| U-C1 | closure captures a reference binder | let a: Int = 7; let r = &a; let f = fn() -> Int { *r }; let _g = consume(a); return f(); |
use after move |
| U-E3 | deref-reborrow records no loan | let x = 5; let r = &x; let r2 = &*r; let gone = consume(x); *r2 + gone |
use after move |
| K-2 (control) | let a: Int = 7; let r = &a; let _g = consume(a); return *r; |
rejected, correctly | |
| K-8 (control) | let a: Int = 7; let _g = consume(a); return a; |
rejected, correctly |
The full set has 15 unsound programs (all accepted) and 8 controls (all rejected) in five classes:
- A: a borrow copied into a tuple or array: use after move, a write under a shared borrow, two live
&mut, a dangling reference. - B: a reference binder reassigned inside a loop,
iformatch. - C: a closure capturing a reference binder.
- D: the return-borrow summary misses an aggregate-wrapped borrow.
- E:
&mut *r/&*rrecord no loan.
The full tables and a probe kit are in issues-drafts/10-borrow-checker-false-negatives-round4.adoc and in ADR-0028 appendix A.4 (PR #845).
What is and is not new
- Classes A and B are described in the "Still deferred" trailer of
lib/borrow.mlas accepted, low-severity residuals for tracking: ADR-022 Polonius origin/region variables — implementation M1–M4 (lib/borrow_polonius/) #553. - Classes D and E are holes 1 and 4 of the unfiled
issues-drafts/09-round3-borrow-affine-soundness-probe.adoc, and still reproduce. That draft's holes 2 and 3 are inlib/quantity.mland need their own issue. - Class C and probes U-A4 to U-A6 were not recorded anywhere.
docs/SOUNDNESS.adocsays "There are no soundness-relevant holes outside this table". None of these has a row or a pinned xfail.
Severity
Memory corruption was not demonstrated. On core wasm, &e copies the operand into a fresh heap cell, so a stale reference reads a stale copy (that copying is itself a separate bug, filed alongside this one). The interpreter rejects most reference programs at run time. The static guarantee "no use after move, no aliased &mut" is false today.
The test-only Polonius extractor (#553 M3) rejects only U-B1–U-B3 and accepts three of the controls, so wiring it in would not close this.
Handling
Options are in ADR-0028 (PR #845). In short: close these in an origin-based checker (#553), or restrict references for v1 so these constructs cannot be written. The ADR measured the restriction's impact on the repo corpus at zero files outside test//tests/.
Generated by Claude Code
Activity
whatproblem-ai commentedon Dec 1, 2026
Each unsound program comes with a rejected control (K-2, K-8) and a pinned build (
161eaaf), so every hole can be confirmed as a checker gap rather than a setup difference.Restated:
lib/borrow.mlstops tracking a loan once the borrow leaves its original binder. The borrow can be copied into a tuple or array, reassigned insideif/loop/match, captured by a closure, or reborrowed via&*r/&mut *r. In each case the checker accepts use-after-move, two live&mut, writes under a shared borrow, and dangling returns. That makes it unsound, not merely incomplete. This breaks the #563 v1 fallback premise, anddocs/SOUNDNESS.adoccurrently claims no such holes exist.Nothing is missing for a fixer. The open question is the policy choice in ADR-0028: an origin-based checker (#553) or restricting references for v1.
flowchart TD A[📱 let r = borrow of a] --> B{How the borrow escapes} B --> C[A: copied into tuple or array] B --> D[B: binder reassigned in branch] B --> E[C: captured by closure] B --> F[E: reborrow via deref] C --> G[⚠️ Loan no longer tracked] D --> G E --> G F --> G G --> H[consume a accepted] H --> I[🔴 Stale deref accepted]🏆 Clarity Score: 96% - Great detail! 💫
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
docs(adr): ADR-028 — cite #847 and #848 now that the holes are filed
docs(adr): ADR-028 — review corrections; a 16th unsound program chang…
hyperpolymath commentedon Dec 1, 2026
Addendum: a 16th unsound program, U-G1 (copying a
&mutbinder)Found by the #553 work (ADR-0028 §2.4, PR #845, commit
829091d) while testing whether option D's rule R3 closes class E. Re-verified on amain-based build that includes #841 (8659e16):checkType checking passed— accepted; unsoundlet mut x = 5; let a = &mut x; let b = &mut x; *a + *bBorrow error— rejected, correctlyCopying a
&mutbinder leaves two usable exclusive references tox. This uses no aggregate, closure, nested reassign or deref-reborrow, so it is outside classes A–E. The count of known unsound accepted programs is now 16.Consequences recorded in ADR-0028:
&/&mutexpressions for v1, keep parameter modes). D, plus a new rule R4 ("exclusive references are not copyable"), remains an upgrade path only if its experiment and a further probing round pass.Generated by Claude Code
whatproblem-ai commentedon Dec 1, 2026
U-G1 adds a sixth escape route: a plain
let r2 = rcopy of a&mutbinder leaves two live exclusive references, with no aggregate, branch, closure or reborrow involved. This is a liveness failure rather than a provenance one, so ADR option G alone would not close it. It also settles the policy question I left open, now that ADR-0028 recommends E, with D plus R4 kept only as an upgrade path.✅ Nothing further needed. Clarity: 92%
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
docs(adr): ADR-028 — three more unsound programs inside the second-cl…
formal: borrow-provenance experiment — D+R4 and three separate obliga…
formal: Agda experiment — provenance fibre as the spec for the v1 bor…
docs(adr): ADR-028 draft — borrow checking for v1: ADR-022 (Polonius)…
hyperpolymath commentedon Dec 1, 2026
Three more unsound programs, D-01, D-06 and D-19, are filed with repros as #857. That brings the known total to 19: the fifteen here, U-G1 (comment above) and those three. All three use a value after a move, and all three lie inside ADR-028 option D's fragment, which is why they are tracked separately. Re-verified on
main464f7c6.Generated by Claude Code