feat: support a destructuring binder on a for … invariant loop - #14682
Merged
Conversation
This PR lets a `for` loop that destructures its binder carry an `invariant` clause, so a loop over a map may bind `(k, v)` and still state its invariant. A loop over several collections continues to reject the clause. The clause is carried through the expansion that replaces the pattern by a fresh binder and a `match`, which leaves it unchanged because it ranges over the consumed and remaining elements and the loop state rather than over the pattern.
…rified This PR reports a container that does not declare its loop effect-free at the `invariant` clause itself, naming the container and the missing `PureForIn` instance, rather than leaving a gadget that `vcgen` later reports as having no applicable specification. The clause elaborator synthesizes the class its specification is stated over. The check is skipped while the container type, the element type or the monad is still an open metavariable, so it reports only what it can see.
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
Registering the class as a synthetic instance metavariable lets elaboration postpone it while the container, element or monad type is still open, and reports it through the usual unresolved-instance error.
sgraf812
marked this pull request as ready for review
August 5, 2026 09:56
Keeps one contract per binder form, plain, membership and destructuring, and states the two rejected loops with a single-line body. The membership binder was covered three times over, once per container.
sgraf812
enabled auto-merge
August 5, 2026 10:04
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 lets a
forloop that destructures its binder carry aninvariantclause, so a loop over a map may bind(k, v)and still state its invariant. A container that the clause cannot verify is reported where the clause appears, naming thePureForIninstance it lacks, instead of surfacing later as avcgengadget with no applicable specification.