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: upstream ToLevel from mathlib #6285

Merged
merged 8 commits into from
Dec 5, 2024

Conversation

alexkeizer
Copy link
Contributor

@alexkeizer alexkeizer commented Dec 2, 2024

This PR upstreams the ToLevel typeclass from mathlib and uses it to fix the existing ToExpr instances so that they are truly universe polymorphic (previously it generated malformed expressions when the universe level was nonzero). We improve on the mathlib definition of ToLevel to ensure the class always lives in Type, irrespective of the universe parameter.

This implements part one of the plan to upstream a derive handler for ToExpr, as discussed in #5906 and #5909.

@alexkeizer alexkeizer marked this pull request as draft December 2, 2024 12:47
@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 2, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 2, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase e157fcbcd1643d6440926abcc9cafab1e59cae74 --onto 3c5e612dc54733cd707becb929457d2f9d8ca6fd. (2024-12-02 12:49:46)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase e157fcbcd1643d6440926abcc9cafab1e59cae74 --onto cb600ed9b436e4290b819b0529f8454490bffeb6. (2024-12-04 15:24:15)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f6e88e5a0525b744c5df018dd96d2f0cbca29435 --onto c5181569f959e4a0d9586954212125adcb6e44d0. (2024-12-05 04:58:34)

@alexkeizer alexkeizer marked this pull request as ready for review December 2, 2024 15:24
@alexkeizer
Copy link
Contributor Author

alexkeizer commented Dec 2, 2024

awaiting-review

@kmill

Copy link
Collaborator

@kmill kmill left a comment

Choose a reason for hiding this comment

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

Thanks! Just a few comments.

src/Lean/ToLevel.lean Outdated Show resolved Hide resolved
src/Lean/ToLevel.lean Outdated Show resolved Hide resolved
src/Lean/ToLevel.lean Outdated Show resolved Hide resolved
src/Lean/ToLevel.lean Outdated Show resolved Hide resolved
src/Lean/ToExpr.lean Outdated Show resolved Hide resolved
@kim-em kim-em added the awaiting-author Waiting for PR author to address issues label Dec 4, 2024
@alexkeizer
Copy link
Contributor Author

@kmill All comments addressed!

awaiting-review

@github-actions github-actions bot added awaiting-review Waiting for someone to review the PR and removed awaiting-author Waiting for PR author to address issues labels Dec 4, 2024
@alexkeizer
Copy link
Contributor Author

CI seems to be unhappy about a bunch of files that should use prelude; I didn't touch any of those files in this PR, though, so I assume that's safe to ignore?

@kmill
Copy link
Collaborator

kmill commented Dec 4, 2024

Would you mind merging/rebasing the master branch? I think there could be differences in the CI scripts causing an issue.

@kmill kmill added this pull request to the merge queue Dec 5, 2024
@kmill
Copy link
Collaborator

kmill commented Dec 5, 2024

(Thanks @tobiasgrosser, merging master worked!)

I just put this on the merge queue. Looking forward to the next PR @alexkeizer.

Merged via the queue into leanprover:master with commit 1400b95 Dec 5, 2024
14 checks passed
@kim-em
Copy link
Collaborator

kim-em commented Dec 5, 2024

@alexkeizer, @kmill, it would have been good to get a test against Mathlib before we merged this. There were some changes required in Mathlib to adapt.

@alexkeizer
Copy link
Contributor Author

Sorry for that! What's the proper workflow for testing things against Mathlib? Should I base the next PR off of nightly-with-mathlib as per the bot's comment?

@alexkeizer alexkeizer deleted the upstream-tolevel branch December 5, 2024 11:12
@kim-em
Copy link
Collaborator

kim-em commented Dec 5, 2024

Sorry for that! What's the proper workflow for testing things against Mathlib? Should I base the next PR off of nightly-with-mathlib as per the bot's comment?

Yes, that's it!

github-merge-queue bot pushed a commit that referenced this pull request Dec 31, 2024
This PR adds a deriving handler for the `ToExpr` class. It can handle
mutual and nested inductive types, however it falls back to creating
`partial` instances in such cases. This is upstreamed from the Mathlib
deriving handler written by @kmill, but has fixes to handle autoimplicit
universe level variables.

This is a followup to #6285 (adding the `ToLevel` class). This PR
supersedes #5906.

Co-authored-by: Alex Keizer <alex@keizer.dev>

---------

Co-authored-by: Alex Keizer <alex@keizer.dev>
luisacicolini pushed a commit to opencompl/lean4 that referenced this pull request Jan 21, 2025
This PR adds a deriving handler for the `ToExpr` class. It can handle
mutual and nested inductive types, however it falls back to creating
`partial` instances in such cases. This is upstreamed from the Mathlib
deriving handler written by @kmill, but has fixes to handle autoimplicit
universe level variables.

This is a followup to leanprover#6285 (adding the `ToLevel` class). This PR
supersedes leanprover#5906.

Co-authored-by: Alex Keizer <alex@keizer.dev>

---------

Co-authored-by: Alex Keizer <alex@keizer.dev>
JovanGerb pushed a commit to JovanGerb/lean4 that referenced this pull request Jan 21, 2025
This PR upstreams the `ToLevel` typeclass from mathlib and uses it to
fix the existing `ToExpr` instances so that they are truly universe
polymorphic (previously it generated malformed expressions when the
universe level was nonzero). We improve on the mathlib definition of
`ToLevel` to ensure the class always lives in `Type`, irrespective of
the universe parameter.

This implements part one of the plan to upstream a derive handler for
`ToExpr`, as discussed in leanprover#5906 and leanprover#5909.

---------

Co-authored-by: Kyle Miller <kmill31415@gmail.com>
Co-authored-by: Tobias Grosser <tobias@grosser.es>
JovanGerb pushed a commit to JovanGerb/lean4 that referenced this pull request Jan 21, 2025
This PR adds a deriving handler for the `ToExpr` class. It can handle
mutual and nested inductive types, however it falls back to creating
`partial` instances in such cases. This is upstreamed from the Mathlib
deriving handler written by @kmill, but has fixes to handle autoimplicit
universe level variables.

This is a followup to leanprover#6285 (adding the `ToLevel` class). This PR
supersedes leanprover#5906.

Co-authored-by: Alex Keizer <alex@keizer.dev>

---------

Co-authored-by: Alex Keizer <alex@keizer.dev>
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 changelog-other 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.

5 participants