fix: over-specialized backward rules in vcgen's spec rule cache#14431
Merged
Conversation
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
This PR fixes `vcgen` failing with `Failed to apply rule` when the same equality spec matches two different programs within one run, e.g. the equations of a recursive function registered via `vcgen [f]`: the cached backward rule was specialized to the first matched program and could not be applied to the next one. The rule built from an equality spec unified the equation's LHS with the goal's program, baking the first program's arguments and dictionaries into a rule that is cached per spec theorem, `WP` instance and excess argument count. Rule construction now treats equality specs like `⊑ wp` specs: it pins only what the cache key determines, namely the monad, the value and predicate types and the `WP` instance, and leaves the equation's remaining variables, including instance binders, as schematic rule parameters that applying the rule binds against the concrete goal program. Dictionary projections this substitution exposes in the premise program are reduced by the existing head-reduction step before the next spec lookup, which also makes the construction-time dictionary synthesis and projection reduction unnecessary.
sgraf812
force-pushed
the
sg/vcgen-spec-rule-cache
branch
from
July 17, 2026 12:02
ac4bc45 to
19589be
Compare
Contributor
Author
|
!bench |
|
Benchmark results for 19589be against a104164 are in. No significant results found. @sgraf812
Medium changes (1✅)
Small changes (1✅, 1🟥)
|
sgraf812
marked this pull request as ready for review
July 17, 2026 14:41
sgraf812
enabled auto-merge
July 17, 2026 14:41
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 fixes
vcgenfailing withFailed to apply rulewhen the same equality spec matches two different programs within one run, e.g. the equations of a recursive function registered viavcgen [f]: the cached backward rule was specialized to the first matched program and could not be applied to the next one.The rule built from an equality spec unified the equation's LHS with the goal's program, baking the first program's arguments and dictionaries into a rule that is cached per spec theorem,
WPinstance and excess argument count. Rule construction now treats equality specs like⊑ wpspecs: it pins only what the cache key determines, namely the monad, the value and predicate types and theWPinstance, and leaves the equation's remaining variables, including instance binders, as schematic rule parameters that applying the rule binds against the concrete goal program. Dictionary projections this substitution exposes in the premise program are reduced by the existing head-reduction step before the next spec lookup, which also makes the construction-time dictionary synthesis and projection reduction unnecessary.