Skip to content

feat: add hygiene info to paren/tuple/typeAscription syntaxes#9491

Merged
kmill merged 2 commits intoleanprover:masterfrom
kmill:kmill_cdot_hygienic_commit1
Jul 23, 2025
Merged

feat: add hygiene info to paren/tuple/typeAscription syntaxes#9491
kmill merged 2 commits intoleanprover:masterfrom
kmill:kmill_cdot_hygienic_commit1

Conversation

@kmill
Copy link
Copy Markdown
Collaborator

@kmill kmill commented Jul 23, 2025

This PR adds hygiene info to paren/tuple/typeAscription syntaxes, which will be used to implement hygienic cdot function expansion in #9443.

This PR adds hygiene info to paren/tuple/typeAscription syntaxes, which will be used to implement hygienic cdot function expansion in leanprover#9443.
@kmill kmill added the changelog-language Language features and metaprograms label Jul 23, 2025
@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 Jul 23, 2025
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2025-07-18 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2025-07-23 20:04:21)

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
@ghost ghost added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Jul 23, 2025
@ghost
Copy link
Copy Markdown

ghost commented Jul 23, 2025

Mathlib CI status (docs):

@kmill
Copy link
Copy Markdown
Collaborator Author

kmill commented Jul 23, 2025

Note: mathlib fails here, but it succeeds with #9443.

@kmill kmill added this pull request to the merge queue Jul 23, 2025
Merged via the queue into leanprover:master with commit 2412d52 Jul 23, 2025
23 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan changelog-language Language features 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.

2 participants