feat: intrinsic verification syntax for do-notation loops and def contracts#14389
Draft
sgraf812 wants to merge 6 commits into
Draft
feat: intrinsic verification syntax for do-notation loops and def contracts#14389sgraf812 wants to merge 6 commits into
sgraf812 wants to merge 6 commits into
Conversation
sgraf812
force-pushed
the
sg/kr1-intrinsic-do
branch
from
July 14, 2026 16:50
ae7fb19 to
2adc4e1
Compare
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
sgraf812
force-pushed
the
sg/kr1-intrinsic-do
branch
2 times, most recently
from
July 15, 2026 11:45
b94b350 to
fa3413e
Compare
Adds `Std.Internal.Do.ForIn.forInWithInvariant`, a `forIn` gadget annotated with its loop invariant so `vcgen` reads it from the program instead of an `invariants` clause. It is definitionally `forIn xs init f`, so the annotation is erased at runtime. Provides `@[spec]` specifications for `List` and `Std.Legacy.Range` loops plus the `ForIn.toList` bridge lemmas, and exposes `ForIn.toArray`/`ForIn.toList`.
Adds a `for x in xs invariant cur => I do …` clause to `do` blocks: the invariant is lowered onto the loop combinator as the `ForIn.forInInv` annotation, elaborated in the loop body's scope so mutable variables and outer-loop variables resolve by name. Registers the control-info handler so the form nests.
Adds `require P` and `ensures b => Q` clauses on `def` signatures. A definition carrying them expands to the plain definition plus an `@[spec]`-tagged specification theorem `f.spec : ⦃P⦄ f args ⦃(fun b => Q); ⊥⦄` proved by `vcgen [f] with finish`.
…t relocation Snapshot for main PR. Not for merge.
…es in require term
An @[macro] on `declaration` only fires when the defining module is imported; the builtin implementation makes `require`/`ensures` contracts work when a user imports only Std.Tactic.Do.
sgraf812
force-pushed
the
sg/kr1-intrinsic-do
branch
from
July 21, 2026 10:05
fa3413e to
2e74ff6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds intrinsic verification syntax for
Std.Internal.Dodo-notation: loop invariants and function contracts thatvcgendischarges automatically.A
for x in xs invariant cur => I do …loop annotates its invariant onto the loop combinator, elaborated in the loop body's scope so mutable variables and outer-loop variables resolve by name; nested loops are supported. Adefmay carryrequire Pandensures b => Qclauses on its signature, expanding to the plain definition plus an@[spec]-tagged specification theoremf.spec : ⦃P⦄ f args ⦃fun b => Q⦄proved byvcgen [f] with finish. The corpus examplefindSmallestis then fully automatic with zero manual proof.invariant,require, andensuresremain usable as ordinary identifiers; a bare occurrence only ends the preceding term in the position where the clause is expected. The contract expander is a builtin macro, so contracts work when onlyStd.Tactic.Dois imported. Scope is the MVP:forloops overListandStd.Legacy.Range;while,signals, and residual-VC discharge are not included.