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 ToExpr deriving handler from Mathlib #6473

Merged
merged 4 commits into from
Dec 31, 2024

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Dec 29, 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

alexkeizer and others added 2 commits December 27, 2024 15:58
fix: use prelude in `ToLevel`

fix: ensure `ToLevel.{u}` lives in `Type u` (rather than `Type (u+1)`)

fix: ensure that `ToLevel.{u} : Type`, for all universes `u`

remove old ToLevel pre-merge

use Array.back!

move namespace to Lean.Elab.Deriving.ToExpr

This also ensures that `mkLet` is resolved to `Lean.Elab.Deriving.mkLet` (as intended) instead of `Lean.mkLet`

deriving test cases

The final test case currently fails, exposing a bug when auto implicits are disabled

expand test to actually exercise generated instance

expand tests to include ambient and directly specified universes

expand tests to exercise explicitly provided universes, even when autoImplicits are enabled

fix test by correctly scoping universe

fix: only explicitly declare universe levels that are *not* already present in the ambient context

"fix" test

Turns out I had a typo in the argument list. The problem was not with implicit universes, rather it was with implicit parameters.
Also adds new testcases to expose this bug properly
@kmill kmill added the changelog-language Language features, tactics, and metaprograms label Dec 29, 2024
@kmill kmill requested a review from kim-em as a code owner December 29, 2024 22:30
@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 29, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 29, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 29, 2024
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Dec 29, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 29, 2024

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 30, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 30, 2024
@leanprover-community-bot leanprover-community-bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Dec 30, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 30, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 30, 2024
@kmill kmill changed the title feat: upstream ToExpr deriving handler Mathlib feat: upstream ToExpr deriving handler from Mathlib Dec 31, 2024
@kmill kmill added this pull request to the merge queue Dec 31, 2024
Merged via the queue into leanprover:master with commit 8f5ce3a Dec 31, 2024
17 checks passed
jcommelin added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 17, 2025
* chore: bump to nightly-2024-12-23

* chore: adaptations for nightly-2024-12-23 (#20196)



Co-authored-by: Kim Morrison <kim@tqft.net>
Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com>
Co-authored-by: Mario Carneiro <di.gama@gmail.com>
Co-authored-by: Junyan Xu <junyanxu.math@gmail.com>
Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com>
Co-authored-by: Mitchell Lee <trivial171@gmail.com>
Co-authored-by: Joël Riou <joel.riou@universite-paris-saclay.fr>
Co-authored-by: Christian Merten <christian@merten.dev>
Co-authored-by: Artie Khovanov <artem.khovanov@gmail.com>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: Eric Wieser <efw@google.com>

* fix

* chore: bump to nightly-2024-12-24

* Merge master into nightly-testing

* chore: bump to nightly-2024-12-25

* Merge master into nightly-testing

* chore: bump to nightly-2024-12-26

* chore: bump to nightly-2024-12-27

* Merge master into nightly-testing

* chore: bump to nightly-2024-12-28

* Merge master into nightly-testing

* fix

* fix

* fix

* chore: bump to nightly-2024-12-29

* Merge master into nightly-testing

* deprecations

* revert

* revert

* revert

* Update lean-toolchain for testing leanprover/lean4#6473

* remove DeriveToExpr

* Trigger CI for leanprover/lean4#6473

* fix

* chore: bump to nightly-2024-12-30

* Merge master into nightly-testing

* Trigger CI for leanprover/lean4#6473

* chore: bump to nightly-2024-12-31

* Merge master into nightly-testing

* chore: bump to nightly-2025-01-01

* Merge master into nightly-testing

* chore: bump to nightly-2025-01-02

* fix

* partial fix

* fix hopefully

* chore: adaptations for nightly-2025-01-02

* chore: bump to nightly-2025-01-03

* chore: adaptations for nightly-2025-01-03

* chore: bump to nightly-2025-01-04

* fixes

* shake --update

* chore: bump to nightly-2025-01-05

* Merge master into nightly-testing

* chore: bump to nightly-2025-01-06

* bump batteries

* chore: bump to nightly-2025-01-07

* chore: bump to nightly-2025-01-08

* chore: bump to nightly-2025-01-09

* bump batteries

* bump deps

* fix

* chore: adaptations for nightly-2025-01-09

* chore: bump to nightly-2025-01-10

* remove upstreamed

* Update lean-toolchain for testing leanprover/lean4#6602

* Trigger CI for leanprover/lean4#6602

* fix breakage caused by leanprover/lean4#6602

* chore: adaptations for nightly-2025-01-10

* fix merge

* avoid nonrec for leanprover/lean4#6602

* Trigger CI for leanprover/lean4#6602

* chore: bump to nightly-2025-01-14

* bump

* fixes

* fixes

* fixes

* chore: bump to nightly-2025-01-15

* fix

* empty commit to bump CI

* Update lean-toolchain for testing leanprover/lean4#6660

* fixes for leanprover/lean4#6660

* chore: bump to nightly-2025-01-16

* fix

* move batteries back to nightly-testing

* move batteries back to nightly-testing

---------

Co-authored-by: leanprover-community-mathlib4-bot <leanprover-community-mathlib4-bot@users.noreply.github.com>
Co-authored-by: Johan Commelin <johan@commelin.net>
Co-authored-by: Mario Carneiro <di.gama@gmail.com>
Co-authored-by: Junyan Xu <junyanxu.math@gmail.com>
Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com>
Co-authored-by: Mitchell Lee <trivial171@gmail.com>
Co-authored-by: Joël Riou <joel.riou@universite-paris-saclay.fr>
Co-authored-by: Christian Merten <christian@merten.dev>
Co-authored-by: Artie Khovanov <artem.khovanov@gmail.com>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: Eric Wieser <efw@google.com>
Co-authored-by: Kyle Miller <kmill31415@gmail.com>
Co-authored-by: Parth Shastri <31370288+cppio@users.noreply.github.com>
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 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.

3 participants