-
Notifications
You must be signed in to change notification settings - Fork 429
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
base: master
Are you sure you want to change the base?
Conversation
Mathlib CI status (docs):
|
awaiting-review |
There was a problem hiding this 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.
prelude | ||
import Lean.Expr | ||
|
||
/-! # `ToLevel` class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/-! # `ToLevel` class | |
/-! | |
# `ToLevel` class |
/-- The universe itself. This is only here to avoid the "unused universe parameter" error. | ||
We'll remove this field once https://github.com/leanprover/lean4/issues/2116 gets fixed. | ||
-/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tweaks to emphasize that it's a hack and to deemphasize any promises that it'll ever be removed (I hope it does, but I haven't heard any motion on 2116 one way or another yet)
/-- The universe itself. This is only here to avoid the "unused universe parameter" error. | |
We'll remove this field once https://github.com/leanprover/lean4/issues/2116 gets fixed. | |
-/ | |
/-- A hack to avoid the "unused universe parameter" error. | |
We can remove this field pending issue https://github.com/leanprover/lean4/issues/2116 -/ |
/-- The universe itself. This is only here to avoid the "unused universe parameter" error. | ||
We'll remove this field once https://github.com/leanprover/lean4/issues/2116 gets fixed. | ||
-/ | ||
univ : ∃ x, x = PUnit.unit.{u} := ⟨_, rfl⟩ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really doesn't matter, but some alternative encodings if you want:
univ : ∃ x, x = PUnit.unit.{u} := ⟨_, rfl⟩ | |
univ : PUnit.{u} → True := fun _ => trivial |
univ : ∃ x, x = PUnit.unit.{u} := ⟨_, rfl⟩ | |
univ : ∀ x : PUnit.{u}, x = x := fun _ => rfl |
Or, for fun, one that doesn't make use of anything but the basic logic:
univ : ∃ x, x = PUnit.unit.{u} := ⟨_, rfl⟩ | |
univ : ∀ (_ : Sort u) (p : Prop), p → p := fun _ _ h => h |
|
||
namespace Lean | ||
|
||
universe w |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that Lean core makes use of autoImplicit, could you remove this universe
command and the universe u v
command later on?
| none => mkApp (mkConst ``Option.none [levelZero]) type | ||
| some a => mkApp2 (mkConst ``Option.some [levelZero]) type (toExpr a), | ||
toTypeExpr := mkApp (mkConst ``Option [levelZero]) type } | ||
| none => mkApp (mkConst ``Option.none [l.toLevel]) type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the style should be using toLevel.{u}
rather than naming the ToLevel
instance:
| none => mkApp (mkConst ``Option.none [l.toLevel]) type | |
| none => mkApp (mkConst ``Option.none [toLevel.{u}]) type |
This PR upstreams the
ToLevel
typeclass from mathlib and uses it to fix the existingToExpr
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 ofToLevel
to ensure the class always lives inType
, 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.