Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: process delayed assignment metavariables correctly in Lean.Meta.Closure #6414

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Dec 19, 2024

This PR fixes a bug in Lean.Meta.Closure that would introduce under-applied delayed assignment metavariables, which would keep them from ever getting instantiated. This bug affected match elaboration when the expected type contained postponed elaboration problems, for example tactic blocks.

Closes #5925, closes #6354

…Closure

This PR fixes a bug in `Lean.Meta.Closure` that would introduce under-applied delayed assignment metavariables, which would keep them from ever getting instantiated. This bug affected `match` elaboration when the expected type contains postponed elaboration problems, for example tactic blocks.

Closes leanprover#6354
@kmill kmill added the changelog-language Language features, tactics, and metaprograms label Dec 19, 2024
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 19, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 19, 2024

Mathlib CI status (docs):

@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Dec 19, 2024
@kmill kmill added the awaiting-review Waiting for someone to review the PR label Dec 19, 2024
if let some { fvars, .. } ← getDelayedMVarAssignment? mvarId then
-- Eta expand `e` for the requisite number of arguments.
forallBoundedTelescope mvarDecl.type fvars.size fun args _ => do
mkLambdaFVars args <| mkAppN e args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered other solutions that do not require eta-expansion for this issue, even if they apply only to special cases? If they are not worth pursuing, we should document that here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't think of any other solution @leodemoura, other than to relax the assumption on delayed assignment metavariables and have instantiateMVars itself do the eta expansion. This results in the same expression in the end, and it seems better to me to keep instantiateMVars simple.

It did cross my mind that I could try matching on the case where the delayed assignment metavariable is applied to fvars, but it wasn't clear to me that the added code complexity would be worth it. We would still need the eta expansion code path for correctness.

In another PR, I'm going to try to fix one of the main triggers of this bug, which comes from structure instance notation when there are autoParams and a structure that extends another structure. This won't eradicate the bug however.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did cross my mind that I could try matching on the case where the delayed assignment metavariable is applied to fvars, but it wasn't clear to me that the added code complexity would be worth it. We would still need the eta expansion code path for correctness.

Let's add an extra comment documenting this decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features, tactics, and metaprograms toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected kernel error involving two structures A "declaration has metavariables" error
3 participants