feat: add hygiene info to paren/tuple/typeAscription syntaxes#9491
Merged
kmill merged 2 commits intoleanprover:masterfrom Jul 23, 2025
Merged
feat: add hygiene info to paren/tuple/typeAscription syntaxes#9491kmill merged 2 commits intoleanprover:masterfrom
kmill merged 2 commits intoleanprover:masterfrom
Conversation
This PR adds hygiene info to paren/tuple/typeAscription syntaxes, which will be used to implement hygienic cdot function expansion in leanprover#9443.
Collaborator
|
Reference manual CI status:
|
ghost
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Jul 23, 2025
ghost
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Jul 23, 2025
|
Mathlib CI status (docs):
|
Collaborator
Author
|
Note: mathlib fails here, but it succeeds with #9443. |
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jul 24, 2025
This PR makes cdot function expansion take hygiene information into account, fixing "parenthesis capturing" errors that can make erroneous cdots trigger cdot expansion in conjunction with macros. For example, given ```lean macro "baz% " t:term : term => `(1 + ($t)) ``` it used to be that `baz% ·` would expand to `1 + fun x => x`, but now the parentheses in `($t)` do not capture the cdot. We also fix an oversight where cdot function expansion ignored the fact that type ascriptions and tuples were supposed to delimit expansion, and also now the quotation prechecker ignores the identifier in `hygieneInfo`. (#9491 added the hygiene information to the parenthesis and cdot syntaxes.) This fixes a bug discovered by [Google DeepMind](https://storage.googleapis.com/deepmind-media/DeepMind.com/Blog/imo-2024-solutions/P1/index.html), which made use of `useλy . x=>y.rec λS p=>?_`. The `use` tactic from Mathlib wrapped the provided term in a type ascription, and so this was equivalent to `use fun x => λy x x=>y.rec λS p=>?_`. (Note that cdot function expansion is not able to take into account *where* the cdots are located, and it is syntactically valid to insert an identifier into the binder list like this. If we ever want to address this in the future, we could have cdots expand into a special term that wraps an identifier that evaluates to a local, but which would cause errors in other contexts.) Design note: we put the `hygieneInfo` on the open parenthesis rather than at the end, since that way the hygiene information is available even when there are parsing errors. This is important since we rely on being able to elaborate partial syntax to get elab info (e.g. in `(a.` to get completion info). Note that syntax matchers check that the `hygieneInfo` is actually present, so such partial syntax would not be matched.
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 adds hygiene info to paren/tuple/typeAscription syntaxes, which will be used to implement hygienic cdot function expansion in #9443.