Repository navigation
Conversation
No code change; keeps the branch's Match.lean byte-identical to the locally tested file.
Match the upstream text exactly; the only intended change on this branch is the synthesizeSyntheticMVars call in makeMatchCode.
…th master Upstream master bumped the toolchain past this branch (v4.36.0-rc2 -> v4.36.0 -> v4.37.0-rc1 in leanprover-community#179/leanprover-community#180), conflicting with the rc1->rc2 bump this branch carried from the fork's merge-base. Setting the branch's toolchain to master's makes the merge clean; the PR diff relative to the merge result is unchanged. Verified locally on leanprover/lean4:v4.37.0-rc1 (upstream master ad0c9f8 + this branch, toolchain conflict resolved to master's version): `lake build --wfail` passes (31 jobs, no warnings) and `lake test` passes (exit 0, incl. QqTest.matchNestedQuotation).
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.
Fixes #126.
Problem
The issue's
partial deffailed with(kernel) declaration has metavariables 'proveFoo._unsafe_rec'. Minimizing the report showed that recursion is not actually required: a plaindeffails the same way whenever aq(·)quotation is elaborated inside the body of a nested~qmatch:opaque Foo {α β : Type} (f : α → β) : Prop opaque someProp : Q(Prop) -- (kernel) declaration has metavariables 'nestedMatchQuotation' def nestedMatchQuotation {α β : Q(Type)} (f : Q($α → $β)) : MetaM Q(Foo $f) := do match β with | ~q(Nat) => failure | ~q(Int) => let t : Q(Prop) := someProp let ~q(@Foo $α'' $β'' $f'') := t | failure let _x := q($f) failureRoot cause
q(·)postpones its own elaboration when the expected type or the local context still contains metavariables (Qq/Macro.lean). Inside a nested_qq_match, the branch-local context built bymakeMatchCode(the pattern-variable lets and thematch_eqhypothesis) routinely contains metavariables, so a quotation in the branch body gets postponed.The postponed work was then synthesized only after the match code had been generated (at the end of the enclosing declaration's elaboration), and metavariables from that late elaboration survived into the compiled declaration — the kernel rejects it with
declaration has metavariables. (Withdebug.skipKernelTC, the same path panics inMkBindingwithunknown metavariable _uniq.N, i.e. the leaked ids have no declaration in the final metavariable context.)Fix
One call in
makeMatchCode, immediately after the branch body is elaborated (k expectedType) and before the result is instantiated and embedded into the generated match code:Postponed elaboration is now forced to complete while the match's own local context is still in scope, so no metavariables leak into the generated code. This mirrors what
elabPatand theq(·)elaborator already do after elaborating their subterms.Tests
New
QqTest/matchNestedQuotation.lean(picked up by theQqTest.+glob):nestedMatchQuotation— the minimized case above (plaindef, no recursion);proveFoo— the shape from the original report: apartialrecursive definition with nested~qmatches andproveFoo q($f)in the innermost body.Both fail on current
masterwith exactly the issue's kernel error (declaration has metavariables 'nestedMatchQuotation'/'proveFoo._unsafe_rec') and compile with this fix.Verification
On the pinned toolchain (
leanprover/lean4:v4.36.0-rc2):master, then minimized it through ~15 variants to isolate the actual trigger (nested~qmatch +q(·)in the branch body); all variants now compile with the fix.Qq/Match.leantomaster) and pass post-fix.lake build --wfail— passes (30 jobs, no warnings).lake test— passes (exit 0; fullQqTestsuite, 59 jobs, including the new regression file).sorry/admitintroduced; the change is one elaboration call inQq/Match.leanplus tests.git hash-object) to the locally built and tested sources.Branch note: my fork was one commit behind upstream, and the GitHub API offers no way to fast-forward it or to rebase this branch onto
b025662(the org'supdate-branchendpoint is OAuth-restricted). The PR diff therefore also shows the one-linelean-toolchainchange from #170, which upstream already has — merging is content-neutral for that file. The intended change is exactlyQq/Match.lean(+6 lines) and the newQqTest/matchNestedQuotation.lean; feel free to rebase/squash as usual.