fix: return canonically typed subgoals from Sym.Pattern.unify? - #14569
Draft
sgraf812 wants to merge 1 commit into
Draft
fix: return canonically typed subgoals from Sym.Pattern.unify?#14569sgraf812 wants to merge 1 commit into
Sym.Pattern.unify?#14569sgraf812 wants to merge 1 commit into
Conversation
sgraf812
force-pushed
the
sg/sym-unify-canonical-subgoals
branch
from
July 27, 2026 16:24
68ddbf1 to
950d7a3
Compare
Contributor
Author
|
!bench |
|
Benchmark results for 950d7a3 against 58a8cd7 are in. No significant results found. @sgraf812
Small changes (1✅, 1🟥)
|
This PR makes `Sym.Pattern.unify?` instantiate assigned metavariables in the types of the metavariables it creates for pattern variables, so subgoals returned by `Sym.BackwardRule.apply` are typed canonically with respect to the assignments made during the application. All pattern-variable metavariables are created (`mkPreResult`) before the pending constraints are solved, so solving a pending constraint can assign a metavariable that already occurs in a sibling's type. Syntactic tests on such a subgoal type (`isForall`, `isProp`, head tests) then see a bare assigned metavariable where the pretty printer shows the instantiated type. The stored types are now updated in place (`MVarId.setType`) after pending constraints are processed; the instantiated type is definitionally equal to the stored one. Unassigned siblings remain metavariable references, so assignments made by the caller still propagate. The instantiation pass runs only when an assignment can have happened after minting (pending constraints, `tPending` type checks, a universe conflict resolved by `isLevelDefEq`, or instance synthesis on a type containing metavariables); a fully syntactic match skips it. `Pattern.match?` is unchanged.
sgraf812
force-pushed
the
sg/sym-unify-canonical-subgoals
branch
from
July 27, 2026 16:31
950d7a3 to
11af200
Compare
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
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
Sym.Pattern.unify?instantiate assigned metavariables in the types of the metavariables it creates for pattern variables, so subgoals returned bySym.BackwardRule.applyare typed canonically with respect to the assignments made during the application.All pattern-variable metavariables are created (
mkPreResult) before the pending constraints are solved, so solving a pending constraint can assign a metavariable that already occurs in a sibling's type. Syntactic tests on such a subgoal type (isForall,isProp, head tests) then see a bare assigned metavariable where the pretty printer shows the instantiated type;vcgen's excess-state introduction stalls on exactly this afterLean.Order.le_of_forall_le. The stored types are now updated in place (MVarId.setType) after pending constraints are processed; the instantiated type is definitionally equal to the stored one. Unassigned siblings remain metavariable references, so assignments made by the caller still propagate. The instantiation pass runs only when an assignment can have happened after minting (pending constraints,tPendingtype checks, a universe conflict resolved byisLevelDefEq, or instance synthesis on a type containing metavariables); a fully syntactic match skips it, which keeps the overhead at ≤0.4% instructions on an apply-heavy microbenchmark and at noise level onvcgen/grindworkloads.Pattern.match?is unchanged.