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

feat: add option pp.mvars.delayed #5643

Merged
merged 3 commits into from
Oct 8, 2024
Merged

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Oct 7, 2024

Where before we had

#check fun x : Nat => ?a
-- fun x ↦ ?m.7 x : (x : Nat) → ?m.6 x

Now by default we have

#check fun x : Nat => ?a
-- fun x => ?a : (x : Nat) → ?m.6 x

In particular, delayed assignment metavariables such as ?m.7 pretty print using the name of the metavariable they are delayed assigned to, suppressing the bound variables used in the delayed assignment (hence ?a rather than ?a x). Hovering over ?a shows ?m.7 x.

The benefit is that users can see the user-provided name in local contexts. A justification for this pretty printing choice is that ?m.7 x is supposed to stand for ?a, and furthermore it is just as opaque to assignment in defeq as ?a is (however, when synthetic opaque metavariables are made assignable, delayed assignments can be a little less assignable than true synthetic opaque metavariables).

The original pretty printing behavior can be recovered using set_option pp.mvars.delayed true.

This PR also extends the documentation for holes and synthetic holes, with some technical details about what delayed assignments are. This likely should be moved to the reference manual, but for now it is included in this docstring.

(This PR is a simplified version of #3494, which has a round-trippable notation for delayed assignments. The pretty printing in this PR is unlikely to round trip, but it is better than the current situation, which is that delayed assignment metavariables never round trip, and plus it does not require introducing a new notation.)

Where before we had
```lean
#check fun x : Nat => ?a
-- fun x ↦ ?m.7 x : (x : Nat) → ?m.6 x
```
Now by default we have
```lean
#check fun x : Nat => ?a
-- fun x => ?a : (x : Nat) → ?m.6 x
```
in particular, delayed assignment metavariables such as `?m.7` pretty print using the name of the metavariable they are delayed assigned to, suppressing the arguments used in the delayed assignment (hence `?a` rather than `?a x`). Hovering over `?a` shows `?m.7 x`.

The benefit is that users can see the user-provided name in local contexts.

The original pretty printing behavior can be recovered using `set_option pp.mvars.delayed true`.

This PR also extends the documentation for holes and synthetic holes, with useful high-level technical details about what delayed assignments are.

(This PR supercedes leanprover#3494, which has a round-trippable notation for delayed assignments. The notation in this PR is unlikely to round trip, but it is better than the current situation, where delayed assignment metavariables never round trip.)
@kmill kmill requested a review from Kha as a code owner October 7, 2024 23:35
@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 Oct 7, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 7, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 7, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Oct 8, 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 Oct 8, 2024
src/Lean/Parser/Term.lean Outdated Show resolved Hide resolved
src/Lean/Parser/Term.lean Outdated Show resolved Hide resolved
Comment on lines 176 to 178
## Delayed assigned metavariables

This section gives a high-level overview of technical details of synthetic holes, which you should feel free to skip.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to write this up! But I’m wary of putting it anywhere where a beginner could accidentially stumble over it, such as hovers. In general, this is probably too long for a hover docstring. It should probably go into the reference manual and the docstring could indicate that there is more deeply technical information there.

Not sure if this should hold up the present PR, though; we could merge as it is right now and doc-refactor later.

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 agree. I've just added some more warnings not to read the section :-)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 8, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 8, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Oct 8, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Oct 8, 2024
@kmill kmill added this pull request to the merge queue Oct 8, 2024
Merged via the queue into leanprover:master with commit bd46319 Oct 8, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR 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.

3 participants