fix: apply specs to goals with a registered WP instance in vcgen - #14883
Merged
Conversation
A monad may register a bespoke `WP` instance next to its `WPMonad` instance. The goal's `wp` application then carries the registered instance, while a backward rule built from a spec stated over `[WPMonad m Pred EPred]` carries the blanket `WPMonad.toWP` route. The two spellings are definitionally equal only at instance transparency, so rule application failed with "No spec applicable". `work` now canonicalizes the goal target with `Sym.canon`, and `tryMkBackwardRuleFromSpec` canonicalizes the constructed rule, so both sides carry the instance that `synthInstance` returns. The instance guard synthesizes the spec's outstanding instance parameters and compares the two concrete spellings at instance transparency. The regression test registers bespoke `WP` instances for two custom monads, one stating the `toWP` field by name and one via `inferInstance`. The `Std.WP` interpretations stay `instance_reducible` definitions: registering them as instances pins the `outParam` assertion types during synthesis and breaks lattice-generic contexts such as the section variables in `tests/elab/vcgenFrames.lean`.
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
`canonTarget` reuses `MVarId.replaceTargetDefEqFast` and drops the no-op check. The rule-construction instance guard compares the goal's `WP` instance against the spec's at default transparency (`withDefault <| isDefEqGuarded ...`), which suffices to match a bespoke goal instance against the spec's `WPMonad.toWP` spelling, replacing `isDefEqInstWP`.
Removed unnecessary explanation about canonicalization and instance arguments in the abstracted rule.
…s instances The default-transparency instance guard alone fixes spec application for goals with a registered `WP` instance: the rule conclusion pins the goal's own instance arguments, premises keep the spec's `WPMonad.toWP` spelling, and `synthPending` assigns the spec's `WPMonad` metavariable during the guard, so goals and rules stay consistent without canonicalizing either. `Sym.canon` on the constructed rule also rewrote tuple matchers into projections, which destroyed the binder names that `binderNameHint` consumption reads and broke `tests/elab/intrinsicVerification.lean` (also on CI). The `WP` interpretations in `Std.WP.Monad.Instances` are proper instances now, with `toWP _ := inferInstance`, so the existing tests exercise the registered-instance path and the dedicated regression test is gone. The `Id`-monad theorems in `tests/elab/vcgenFrames.lean` state their assertions at `Prop`: a hypothesis `[WPMonad Id Pred EPred]` over a generic `Pred` denotes no real instance, and instance search, which ignores `outParam` positions during selection, resolves `WP (Id β) …` to the registered `Prop` instance regardless.
sgraf812
marked this pull request as ready for review
August 22, 2026 08:42
sgraf812
enabled auto-merge
August 22, 2026 08:42
Contributor
Author
|
!bench |
|
Benchmark results for b93a53c against dd7716d are in. There are significant results. @sgraf812
Large changes (11✅, 3🟥)
Medium changes (14✅, 1🟥)
Small changes (12✅, 6🟥)
|
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 makes
vcgencanonicalizeWPinstances, so monads may register a diamondWPinstance in addition to the low priorityWPinstance synthesized fromWPMonad.toWP.