Skip to content

Proof: borrow-graph soundness (no use-after-move + no conflict + BorrowOutlivesOwner) #515

Description

@hyperpolymath

Parent: #513

Statement

For the borrow checker in lib/borrow.ml, prove three soundness lemmas:

  1. No use-after-move: if a borrow-graph derivation accepts a program, no execution of that program reads from a binding after it has been moved.
  2. No conflicting borrows: no two live borrows of the same source can both be mutable, or one mutable and the other shared, at the same program point.
  3. BorrowOutlivesOwner: a reference's borrow scope is a subset of the lexical scope of its owner.

Concretely

The borrow checker emits a borrow graph + a move set per program point. Stating soundness against the operational semantics from lib/interp.ml:

borrow_ok(prog)  ⟹  ∀ trace t of prog.  ¬ uses_after_move(t)         (1)
borrow_ok(prog)  ⟹  ∀ trace t of prog.  ¬ conflicting_borrow(t)      (2)
borrow_ok(prog)  ⟹  ∀ ref-binding r in prog.  borrow_scope(r) ⊆ owner_scope(r)  (3)

Mechanisation

Lean 4. Target: formal/Borrow/{BorrowGraph.lean, NoUseAfterMove.lean, NoConflict.lean, BorrowScope.lean}. Borrow graph is a finite relation between program points and borrowed locations — Mathlib.Data.Finset.Basic handles the carrier comfortably.

Recent landings to lean on:

Size

XL. Estimate: 4–6 weeks. Can be sliced lemma-by-lemma; each of (1)/(2)/(3) is its own milestone.

Polonius origin variables (deferred)

ADR-022 / #407 is the long-tail follow-on. Out of scope here; keep the soundness proof for the current lexical borrow checker first.

Status

NOT STARTED.

🤖 Generated with Claude Code

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

    majorMajor issue — significant scope, broader impact than a feature/bugtech-debtKnown shortcut, drift, or hygiene owed - includes cleanup

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions