feat: add an assert do element for intrinsic verification - #14602
Merged
Conversation
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
sgraf812
force-pushed
the
sg/assert-clause
branch
6 times, most recently
from
July 30, 2026 15:39
e3dc8cd to
3b5c07e
Compare
This PR adds an `assert` element to `do` notation for intrinsic verification. `assert P` states that `P` holds at that point in the program; `assert s => P s` binds the arguments of the assertion itself, such as the state of a state monad. `vcgen` reads the assertion from the program and proves it as a verification condition; at runtime the element does nothing. The runtime check `assert! cond` is unaffected. The element elaborates to `Std.Internal.Do.assertGadget`, whose `name` parameter is dropped. Its specification `Std.Internal.Do.Spec.assertGadget` is now tagged `@[spec]` so `vcgen` finds it.
sgraf812
force-pushed
the
sg/assert-clause
branch
from
July 30, 2026 16:38
3b5c07e to
e7a008a
Compare
sgraf812
marked this pull request as ready for review
July 30, 2026 16:46
Contributor
Author
|
!bench |
|
Benchmark results for e7a008a against 0a67f6b are in. There are significant results. @sgraf812
New metrics (9✅, 9🟥)
Medium changes (1✅)
Small changes (30🟥)
|
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 an
assertelement todonotation for intrinsic verification.assert Pstates thatPholds at that point in the program;assert s => P sbinds the arguments of the assertion itself, such as the state of a state monad, using the same bindersfunaccepts.vcgenreads the assertion from the program and proves it as a verification condition; at runtime the element does nothing.The parser is
Lean.Parser.Term.doAssertion, distinct from the existingdoAssertofassert!. It leads withnonReservedSymbol "assert" (includeIdent := true)at prioritydefault+10, so a bareassertin statement position wins the equal-length tie againstdoExpr;assert!is the longer token, so the tokenizer never offersassertthere. The clause body followsrequiresClause:atomic Term.basicFun <|> (ppSpace >> termParser).The element elaborates to
Std.Internal.Do.assertGadget, and reports a missing-import error whenStd.Internal.Dois absent.assertGadgetloses its unusednameparameter, and its specificationSpec.assertGadgetis now tagged@[spec]sovcgenfinds it.