mirror of
https://github.com/leanprover/lean4.git
synced 2026-03-17 10:24:07 +00:00
chore: deprecate levelZero and levelOne (#12720)
This PR deprecates `levelZero` in favor of `Level.zero` and `levelOne`
in favor of the new `Level.one`, and updates all usages throughout the
codebase. The `levelZero` alias was previously required for computed
field `data` to work, but this is no longer needed.
🤖 Prepared with Claude Code
This commit is contained in:
@@ -542,8 +542,8 @@ private def withLocalIdentFor (stx : Term) (e : Expr) (k : Term → TermElabM Ex
|
||||
let mut mStx := stx[2]
|
||||
if mStx.getKind == ``Lean.Parser.Term.macroDollarArg then
|
||||
mStx := mStx[1]
|
||||
let m ← elabTerm mStx (← mkArrow (mkSort levelOne) (mkSort levelOne))
|
||||
let ω ← mkFreshExprMVar (mkSort levelOne)
|
||||
let m ← elabTerm mStx (← mkArrow (mkSort Level.one) (mkSort Level.one))
|
||||
let ω ← mkFreshExprMVar (mkSort Level.one)
|
||||
let stWorld ← mkAppM ``STWorld #[ω, m]
|
||||
discard <| mkInstMVar stWorld
|
||||
mkAppM ``StateRefT' #[ω, σ, m]
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace Lean.Elab.Term
|
||||
open Meta
|
||||
|
||||
@[builtin_term_elab «prop»] def elabProp : TermElab := fun _ _ =>
|
||||
return mkSort levelZero
|
||||
return mkSort Level.zero
|
||||
|
||||
private def elabOptLevel (stx : Syntax) : TermElabM Level :=
|
||||
if stx.isNone then
|
||||
pure levelZero
|
||||
pure Level.zero
|
||||
else
|
||||
elabLevel stx[0]
|
||||
|
||||
|
||||
@@ -754,10 +754,10 @@ def runTermElabM (elabFn : Array Expr → TermElabM α) : CommandElabM α := do
|
||||
if xs.all (·.isFVar) then
|
||||
Term.withoutAutoBoundImplicit <| elabFn xs
|
||||
else
|
||||
-- Abstract any mvars that appear in `xs` using `mkForallFVars` (the type `mkSort levelZero` is an arbitrary placeholder)
|
||||
-- Abstract any mvars that appear in `xs` using `mkForallFVars` (the type `mkSort Level.zero` is an arbitrary placeholder)
|
||||
-- and then rebuild the local context from scratch.
|
||||
-- Resetting prevents the local context from including the original fvars from `xs`.
|
||||
let ctxType ← Meta.mkForallFVars' xs (mkSort levelZero)
|
||||
let ctxType ← Meta.mkForallFVars' xs (mkSort Level.zero)
|
||||
Meta.withLCtx {} {} <| Meta.forallBoundedTelescope ctxType xs.size fun xs _ =>
|
||||
Term.withoutAutoBoundImplicit <| elabFn xs
|
||||
|
||||
|
||||
@@ -95,8 +95,8 @@ private partial def winnowExpr (e : Expr) : MetaM Expr := do
|
||||
visit (body.instantiate1 arg)
|
||||
| .letE _n _t v b _ => visit (b.instantiate1 v)
|
||||
| .sort .. =>
|
||||
if e.isProp then return .sort levelZero
|
||||
else if e.isType then return .sort levelOne
|
||||
if e.isProp then return .sort Level.zero
|
||||
else if e.isType then return .sort Level.one
|
||||
else return .sort (.param `u)
|
||||
| .const name .. => return .const name []
|
||||
| .mdata _ e' => visit e'
|
||||
|
||||
@@ -249,7 +249,7 @@ def mkEnumOfNatThm (declName : Name) : MetaM Unit := do
|
||||
withLocalDeclD `x enumType fun x => do
|
||||
let resultType := mkApp2 eqEnum (mkApp ofNat (mkApp ctorIdx x)) x
|
||||
let motive ← mkLambdaFVars #[x] resultType
|
||||
let casesOn := mkConst (mkCasesOnName declName) (levelZero :: levels)
|
||||
let casesOn := mkConst (mkCasesOnName declName) (Level.zero :: levels)
|
||||
let mut value := mkApp2 casesOn motive x
|
||||
for ctor in ctors do
|
||||
value := mkApp value (mkApp rflEnum (mkConst ctor levels))
|
||||
|
||||
@@ -546,7 +546,7 @@ def elabBinRelCore (noProp : Bool) (stx : Syntax) (expectedType? : Option Expr)
|
||||
let mut maxType := r.max?.get!
|
||||
/- If `noProp == true` and `maxType` is `Prop`, then set `maxType := Bool`. `See toBoolIfNecessary` -/
|
||||
if noProp then
|
||||
if (← withNewMCtxDepth <| isDefEq maxType (mkSort levelZero)) then
|
||||
if (← withNewMCtxDepth <| isDefEq maxType (mkSort Level.zero)) then
|
||||
maxType := Lean.mkConst ``Bool
|
||||
let result ← toExprCore (← applyCoe tree maxType (isPred := true))
|
||||
trace[Elab.binrel] "result: {result}"
|
||||
@@ -557,7 +557,7 @@ where
|
||||
toBoolIfNecessary (e : Expr) : TermElabM Expr := do
|
||||
if noProp then
|
||||
-- We use `withNewMCtxDepth` to make sure metavariables are not assigned
|
||||
if (← withNewMCtxDepth <| isDefEq (← inferType e) (mkSort levelZero)) then
|
||||
if (← withNewMCtxDepth <| isDefEq (← inferType e) (mkSort Level.zero)) then
|
||||
return (← ensureHasType (Lean.mkConst ``Bool) e)
|
||||
return e
|
||||
|
||||
|
||||
@@ -737,7 +737,7 @@ private partial def simplifyResultingUniverse (u : Level) (paramConst := false)
|
||||
-- If there's a variable, then these dominate at infinity; constants can be eliminated
|
||||
if (acc.any fun l _ => varies l) then acc.filter (fun l _ => varies l) else acc
|
||||
let germMax (acc : LevelMap Nat) : Level :=
|
||||
(simpAcc acc).fold (init := levelZero) fun u l offset => mkLevelMax' u (l.addOffset offset)
|
||||
(simpAcc acc).fold (init := Level.zero) fun u l offset => mkLevelMax' u (l.addOffset offset)
|
||||
let accInsert (acc : LevelMap Nat) (u : Level) (offset : Nat) : LevelMap Nat :=
|
||||
acc.alter u (fun offset? => some (max (offset?.getD 0) offset))
|
||||
-- Simplifies `u+offset`, accumulating `max` arguments in `acc`.
|
||||
@@ -748,7 +748,7 @@ private partial def simplifyResultingUniverse (u : Level) (paramConst := false)
|
||||
| .max a b => simp b offset (simp a offset acc)
|
||||
| .imax a b =>
|
||||
if b.isAlwaysZero then
|
||||
accInsert acc levelZero offset
|
||||
accInsert acc Level.zero offset
|
||||
else if a.isAlwaysZero || b.isNeverZero then
|
||||
simp b offset (simp a offset acc)
|
||||
else
|
||||
@@ -796,7 +796,7 @@ private structure AccLevelState where
|
||||
/--
|
||||
The constraint `u ≤ ?r + k` is represented by `levels[u] := k`.
|
||||
When `k` is negative, this represents `u + (-k) ≤ ?r`.
|
||||
The level `u` is either a parameter, metavariable, or `levelZero`.
|
||||
The level `u` is either a parameter, metavariable, or `Level.zero`.
|
||||
|
||||
When `k ≥ 0`, this is potentially a "bad" level constraint.
|
||||
-/
|
||||
@@ -951,8 +951,8 @@ private def inferResultingUniverse (views : Array InductiveView)
|
||||
-- For `Prop` candidates, need to examine `u` itself, rather than `univForInfer` (which has been simplified).
|
||||
if let Level.mvar mvarId := u.normalize then
|
||||
if ← isPropCandidate numParams indTypes indFVars then
|
||||
-- May as well assign now, since `levelZero` is already normalized.
|
||||
assignLevelMVar mvarId levelZero
|
||||
-- May as well assign now, since `Level.zero` is already normalized.
|
||||
assignLevelMVar mvarId Level.zero
|
||||
return { u := u, assign? := none }
|
||||
-- Proceed with non-`Prop`-candidate case.
|
||||
let univForInfer ← withViewTypeRef views <| processResultingUniverseForInference u
|
||||
@@ -975,13 +975,13 @@ private def inferResultingUniverse (views : Array InductiveView)
|
||||
(l, k) :: parts
|
||||
trace[Elab.inductive] "inferResultingUniverse r: {r}, rOffset: {rOffset}, rConstraints: {rConstraints}"
|
||||
/- Compute the inferred `r` -/
|
||||
let rInferred := Level.normalize <| rConstraints.foldl (init := levelZero) fun u' (level, k) =>
|
||||
let rInferred := Level.normalize <| rConstraints.foldl (init := Level.zero) fun u' (level, k) =>
|
||||
-- If `k ≤ 0`, then add `level + (-k) ≤ ?r` constraint, otherwise add `level ≤ ?r`.
|
||||
mkLevelMax' u' <| level.addOffset (-k).toNat
|
||||
let uInferred := (u.replace fun v => if v == r then some rInferred else none).normalize
|
||||
/- Analyze "bad" constraints if there are any, and report an error if needed. -/
|
||||
if rConstraints.any (fun (_, k) => k > 0) then
|
||||
let uAtZero := u.replace fun v => if v == r then some levelZero else none
|
||||
let uAtZero := u.replace fun v => if v == r then some Level.zero else none
|
||||
/- For "bad" level constraints (those of the form `l ≤ ?r + k` where `k > 0`),
|
||||
we add `rOffset - k` to both sides to get the ideal constraint. -/
|
||||
let uIdeal := Level.normalize <| rConstraints.foldl (init := uAtZero) fun u' (level, k) =>
|
||||
|
||||
@@ -67,7 +67,7 @@ private def setLevelMVarsAtPreDef (preDef : PreDefinition) : PreDefinition :=
|
||||
let value' :=
|
||||
preDef.value.replaceLevel fun l =>
|
||||
match l with
|
||||
| .mvar _ => levelZero
|
||||
| .mvar _ => Level.zero
|
||||
| _ => none
|
||||
{ preDef with value := value' }
|
||||
else
|
||||
|
||||
@@ -104,7 +104,7 @@ def IndGroupInst.nestedTypeFormers (igi : IndGroupInst) : MetaM (Array Expr) :=
|
||||
assert! recInfo.numMotives = igi.numMotives
|
||||
let lvls :=
|
||||
if igi.levels.length = recInfo.levelParams.length then igi.levels
|
||||
else levelZero :: igi.levels
|
||||
else Level.zero :: igi.levels
|
||||
let aux := mkAppN (.const recName lvls) igi.params
|
||||
let motives ← inferArgumentTypesN recInfo.numMotives aux
|
||||
let auxMotives : Array Expr := motives[igi.all.size...*]
|
||||
|
||||
@@ -434,9 +434,9 @@ instance : ToFormat GuessLexRel where
|
||||
|
||||
/-- Given a `GuessLexRel`, produce a binary `Expr` that relates two `Nat` values accordingly. -/
|
||||
def GuessLexRel.toNatRel : GuessLexRel → Expr
|
||||
| lt => mkAppN (mkConst ``LT.lt [levelZero]) #[mkConst ``Nat, mkConst ``instLTNat]
|
||||
| eq => mkAppN (mkConst ``Eq [levelOne]) #[mkConst ``Nat]
|
||||
| le => mkAppN (mkConst ``LE.le [levelZero]) #[mkConst ``Nat, mkConst ``instLENat]
|
||||
| lt => mkAppN (mkConst ``LT.lt [Level.zero]) #[mkConst ``Nat, mkConst ``instLTNat]
|
||||
| eq => mkAppN (mkConst ``Eq [Level.one]) #[mkConst ``Nat]
|
||||
| le => mkAppN (mkConst ``LE.le [Level.zero]) #[mkConst ``Nat, mkConst ``instLENat]
|
||||
| no_idea => unreachable!
|
||||
|
||||
/--
|
||||
|
||||
@@ -26,7 +26,7 @@ def mkType (w : Expr) : Expr := mkApp (.const ``BitVec []) w
|
||||
def mkInstMul (w : Expr) : Expr := mkApp (.const ``BitVec.instMul []) w
|
||||
|
||||
def mkInstHMul (w : Expr) : Expr :=
|
||||
mkApp2 (mkConst ``instHMul [levelZero]) (BitVec.mkType w) (mkInstMul w)
|
||||
mkApp2 (mkConst ``instHMul [Level.zero]) (BitVec.mkType w) (mkInstMul w)
|
||||
|
||||
end BitVec
|
||||
|
||||
|
||||
@@ -723,7 +723,7 @@ def mkInstOfNatNat (n : Expr) : Expr :=
|
||||
mkApp (mkConst ``instOfNatNat) n
|
||||
|
||||
def mkNatLitCore (n : Expr) : Expr :=
|
||||
mkApp3 (mkConst ``OfNat.ofNat [levelZero]) (mkConst ``Nat) n (mkInstOfNatNat n)
|
||||
mkApp3 (mkConst ``OfNat.ofNat [Level.zero]) (mkConst ``Nat) n (mkInstOfNatNat n)
|
||||
|
||||
/--
|
||||
Returns a natural number literal used in the frontend. It is a `OfNat.ofNat` application.
|
||||
@@ -867,7 +867,7 @@ Return `true` if the given expression is a free variable with the given id.
|
||||
Examples:
|
||||
- `isFVarOf (.fvar id) id` is `true`
|
||||
- ``isFVarOf (.fvar id) id'`` is `false`
|
||||
- ``isFVarOf (.sort levelZero) id`` is `false`
|
||||
- ``isFVarOf (.sort Level.zero) id`` is `false`
|
||||
-/
|
||||
def isFVarOf : Expr → FVarId → Bool
|
||||
| .fvar fvarId, fvarId' => fvarId == fvarId'
|
||||
@@ -1175,7 +1175,7 @@ private def getAppArgsAux : Expr → Array Expr → Nat → Array Expr
|
||||
|
||||
/-- Given `f a₁ a₂ ... aₙ`, returns `#[a₁, ..., aₙ]` -/
|
||||
@[inline] def getAppArgs (e : Expr) : Array Expr :=
|
||||
let dummy := mkSort levelZero
|
||||
let dummy := mkSort Level.zero
|
||||
let nargs := e.getAppNumArgs
|
||||
getAppArgsAux e (.replicate nargs dummy) (nargs-1)
|
||||
|
||||
@@ -1190,7 +1190,7 @@ In particular, given `f a₁ a₂ ... aₙ`, returns `#[aₖ₊₁, ..., aₙ]`
|
||||
where `k` is minimal such that the size of this array is at most `maxArgs`.
|
||||
-/
|
||||
@[inline] def getBoundedAppArgs (maxArgs : Nat) (e : Expr) : Array Expr :=
|
||||
let dummy := mkSort levelZero
|
||||
let dummy := mkSort Level.zero
|
||||
let nargs := min maxArgs e.getAppNumArgs
|
||||
getBoundedAppArgsAux e (.replicate nargs dummy) nargs
|
||||
|
||||
@@ -1208,7 +1208,7 @@ private def getAppRevArgsAux : Expr → Array Expr → Array Expr
|
||||
|
||||
/-- Given `e = f a₁ a₂ ... aₙ`, returns `k f #[a₁, ..., aₙ]`. -/
|
||||
@[inline] def withApp (e : Expr) (k : Expr → Array Expr → α) : α :=
|
||||
let dummy := mkSort levelZero
|
||||
let dummy := mkSort Level.zero
|
||||
let nargs := e.getAppNumArgs
|
||||
withAppAux k e (.replicate nargs dummy) (nargs-1)
|
||||
|
||||
@@ -1222,7 +1222,7 @@ Note that `f` may be an application.
|
||||
The resulting array has size `n` even if `f.getAppNumArgs < n`.
|
||||
-/
|
||||
@[inline] def getAppArgsN (e : Expr) (n : Nat) : Array Expr :=
|
||||
let dummy := mkSort levelZero
|
||||
let dummy := mkSort Level.zero
|
||||
loop n e (.replicate n dummy)
|
||||
where
|
||||
loop : Nat → Expr → Array Expr → Array Expr
|
||||
@@ -2179,23 +2179,23 @@ namespace Nat
|
||||
protected def mkType : Expr := mkConst ``Nat
|
||||
|
||||
def mkInstAdd : Expr := mkConst ``instAddNat
|
||||
def mkInstHAdd : Expr := mkApp2 (mkConst ``instHAdd [levelZero]) Nat.mkType mkInstAdd
|
||||
def mkInstHAdd : Expr := mkApp2 (mkConst ``instHAdd [Level.zero]) Nat.mkType mkInstAdd
|
||||
|
||||
def mkInstSub : Expr := mkConst ``instSubNat
|
||||
def mkInstHSub : Expr := mkApp2 (mkConst ``instHSub [levelZero]) Nat.mkType mkInstSub
|
||||
def mkInstHSub : Expr := mkApp2 (mkConst ``instHSub [Level.zero]) Nat.mkType mkInstSub
|
||||
|
||||
def mkInstMul : Expr := mkConst ``instMulNat
|
||||
def mkInstHMul : Expr := mkApp2 (mkConst ``instHMul [levelZero]) Nat.mkType mkInstMul
|
||||
def mkInstHMul : Expr := mkApp2 (mkConst ``instHMul [Level.zero]) Nat.mkType mkInstMul
|
||||
|
||||
def mkInstDiv : Expr := mkConst ``Nat.instDiv
|
||||
def mkInstHDiv : Expr := mkApp2 (mkConst ``instHDiv [levelZero]) Nat.mkType mkInstDiv
|
||||
def mkInstHDiv : Expr := mkApp2 (mkConst ``instHDiv [Level.zero]) Nat.mkType mkInstDiv
|
||||
|
||||
def mkInstMod : Expr := mkConst ``Nat.instMod
|
||||
def mkInstHMod : Expr := mkApp2 (mkConst ``instHMod [levelZero]) Nat.mkType mkInstMod
|
||||
def mkInstHMod : Expr := mkApp2 (mkConst ``instHMod [Level.zero]) Nat.mkType mkInstMod
|
||||
|
||||
def mkInstNatPow : Expr := mkConst ``instNatPowNat
|
||||
def mkInstPow : Expr := mkApp2 (mkConst ``instPowNat [levelZero]) Nat.mkType mkInstNatPow
|
||||
def mkInstHPow : Expr := mkApp3 (mkConst ``instHPow [levelZero, levelZero]) Nat.mkType Nat.mkType mkInstPow
|
||||
def mkInstPow : Expr := mkApp2 (mkConst ``instPowNat [Level.zero]) Nat.mkType mkInstNatPow
|
||||
def mkInstHPow : Expr := mkApp3 (mkConst ``instHPow [Level.zero, Level.zero]) Nat.mkType Nat.mkType mkInstPow
|
||||
|
||||
def mkInstLT : Expr := mkConst ``instLTNat
|
||||
def mkInstLE : Expr := mkConst ``instLENat
|
||||
@@ -2261,23 +2261,23 @@ protected def mkType : Expr := mkConst ``Int
|
||||
def mkInstNeg : Expr := mkConst ``Int.instNegInt
|
||||
|
||||
def mkInstAdd : Expr := mkConst ``Int.instAdd
|
||||
def mkInstHAdd : Expr := mkApp2 (mkConst ``instHAdd [levelZero]) Int.mkType mkInstAdd
|
||||
def mkInstHAdd : Expr := mkApp2 (mkConst ``instHAdd [Level.zero]) Int.mkType mkInstAdd
|
||||
|
||||
def mkInstSub : Expr := mkConst ``Int.instSub
|
||||
def mkInstHSub : Expr := mkApp2 (mkConst ``instHSub [levelZero]) Int.mkType mkInstSub
|
||||
def mkInstHSub : Expr := mkApp2 (mkConst ``instHSub [Level.zero]) Int.mkType mkInstSub
|
||||
|
||||
def mkInstMul : Expr := mkConst ``Int.instMul
|
||||
def mkInstHMul : Expr := mkApp2 (mkConst ``instHMul [levelZero]) Int.mkType mkInstMul
|
||||
def mkInstHMul : Expr := mkApp2 (mkConst ``instHMul [Level.zero]) Int.mkType mkInstMul
|
||||
|
||||
def mkInstDiv : Expr := mkConst ``Int.instDiv
|
||||
def mkInstHDiv : Expr := mkApp2 (mkConst ``instHDiv [levelZero]) Int.mkType mkInstDiv
|
||||
def mkInstHDiv : Expr := mkApp2 (mkConst ``instHDiv [Level.zero]) Int.mkType mkInstDiv
|
||||
|
||||
def mkInstMod : Expr := mkConst ``Int.instMod
|
||||
def mkInstHMod : Expr := mkApp2 (mkConst ``instHMod [levelZero]) Int.mkType mkInstMod
|
||||
def mkInstHMod : Expr := mkApp2 (mkConst ``instHMod [Level.zero]) Int.mkType mkInstMod
|
||||
|
||||
def mkInstPow : Expr := mkConst ``Int.instNatPow
|
||||
def mkInstPowNat : Expr := mkApp2 (mkConst ``instPowNat [levelZero]) Int.mkType mkInstPow
|
||||
def mkInstHPow : Expr := mkApp3 (mkConst ``instHPow [levelZero, levelZero]) Int.mkType Nat.mkType mkInstPowNat
|
||||
def mkInstPowNat : Expr := mkApp2 (mkConst ``instPowNat [Level.zero]) Int.mkType mkInstPow
|
||||
def mkInstHPow : Expr := mkApp3 (mkConst ``instHPow [Level.zero, Level.zero]) Int.mkType Nat.mkType mkInstPowNat
|
||||
|
||||
def mkInstLT : Expr := mkConst ``Int.instLTInt
|
||||
def mkInstLE : Expr := mkConst ``Int.instLEInt
|
||||
@@ -2369,17 +2369,17 @@ def mkIntDvd (a b : Expr) : Expr :=
|
||||
|
||||
def mkIntLit (n : Int) : Expr :=
|
||||
let r := mkRawNatLit n.natAbs
|
||||
let r := mkApp3 (mkConst ``OfNat.ofNat [levelZero]) Int.mkType r (mkApp (mkConst ``instOfNat) r)
|
||||
let r := mkApp3 (mkConst ``OfNat.ofNat [Level.zero]) Int.mkType r (mkApp (mkConst ``instOfNat) r)
|
||||
if n < 0 then
|
||||
mkIntNeg r
|
||||
else
|
||||
r
|
||||
|
||||
def reflBoolTrue : Expr :=
|
||||
mkApp2 (mkConst ``Eq.refl [levelOne]) (mkConst ``Bool) (mkConst ``Bool.true)
|
||||
mkApp2 (mkConst ``Eq.refl [Level.one]) (mkConst ``Bool) (mkConst ``Bool.true)
|
||||
|
||||
def reflBoolFalse : Expr :=
|
||||
mkApp2 (mkConst ``Eq.refl [levelOne]) (mkConst ``Bool) (mkConst ``Bool.false)
|
||||
mkApp2 (mkConst ``Eq.refl [Level.one]) (mkConst ``Bool) (mkConst ``Bool.false)
|
||||
|
||||
def eagerReflBoolTrue : Expr :=
|
||||
mkApp2 (mkConst ``eagerReduce [0]) (mkApp3 (mkConst ``Eq [1]) (mkConst ``Bool) (mkConst ``Bool.true) (mkConst ``Bool.true)) reflBoolTrue
|
||||
|
||||
@@ -129,8 +129,8 @@ def hasParam (u : Level) : Bool :=
|
||||
|
||||
end Level
|
||||
|
||||
@[expose, implicit_reducible] def levelZero :=
|
||||
Level.zero
|
||||
@[deprecated Level.zero (since := "2026-02-27")] -- This was previously required in order to get the computed field `data` to work, but it is no longer needed.
|
||||
abbrev levelZero := Level.zero
|
||||
|
||||
def mkLevelMVar (mvarId : LMVarId) :=
|
||||
Level.mvar mvarId
|
||||
@@ -147,9 +147,12 @@ def mkLevelMax (u v : Level) :=
|
||||
def mkLevelIMax (u v : Level) :=
|
||||
Level.imax u v
|
||||
|
||||
def levelOne := mkLevelSucc levelZero
|
||||
abbrev Level.one := mkLevelSucc .zero
|
||||
|
||||
@[export lean_level_mk_zero] def mkLevelZeroEx : Unit → Level := fun _ => levelZero
|
||||
@[deprecated Level.one (since := "2026-02-27")]
|
||||
abbrev levelOne := Level.one
|
||||
|
||||
@[export lean_level_mk_zero] def mkLevelZeroEx : Unit → Level := fun _ => .zero
|
||||
@[export lean_level_mk_succ] def mkLevelSuccEx : Level → Level := mkLevelSucc
|
||||
@[export lean_level_mk_mvar] def mkLevelMVarEx : LMVarId → Level := mkLevelMVar
|
||||
@[export lean_level_mk_param] def mkLevelParamEx : Name → Level := mkLevelParam
|
||||
@@ -214,7 +217,7 @@ def isAlwaysZero : Level → Bool
|
||||
| imax _ l₂ => isAlwaysZero l₂
|
||||
|
||||
@[expose, implicit_reducible] def ofNat : Nat → Level
|
||||
| 0 => levelZero
|
||||
| 0 => Level.zero
|
||||
| n+1 => mkLevelSucc (ofNat n)
|
||||
|
||||
instance instOfNat (n : Nat) : OfNat Level n where
|
||||
@@ -388,7 +391,7 @@ partial def normalize (l : Level) : Level :=
|
||||
let lvl₁ := lvls[i]!
|
||||
let prev := lvl₁.getLevelOffset
|
||||
let prevK := lvl₁.getOffset
|
||||
mkMaxAux lvls k (i+1) prev prevK levelZero
|
||||
mkMaxAux lvls k (i+1) prev prevK Level.zero
|
||||
| imax l₁ l₂ =>
|
||||
if l₂.isNeverZero then addOffset (normalize (mkLevelMax l₁ l₂)) k
|
||||
else
|
||||
@@ -580,7 +583,7 @@ def updateIMax! (lvl : Level) (newLhs : Level) (newRhs : Level) : Level :=
|
||||
| _ => panic! "imax level expected"
|
||||
|
||||
def mkNaryMax : List Level → Level
|
||||
| [] => levelZero
|
||||
| [] => Level.zero
|
||||
| [u] => u
|
||||
| u::us => mkLevelMax' u (mkNaryMax us)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ def mkExpectedTypeHintCore (e : Expr) (expectedType : Expr) (expectedTypeUniv :
|
||||
Given `proof` s.t. `inferType proof` is definitionally equal to `expectedProp`, returns
|
||||
term `@id expectedProp proof`. -/
|
||||
def mkExpectedPropHint (proof : Expr) (expectedProp : Expr) : Expr :=
|
||||
mkExpectedTypeHintCore proof expectedProp levelZero
|
||||
mkExpectedTypeHintCore proof expectedProp Level.zero
|
||||
|
||||
/--
|
||||
Given `e` s.t. `inferType e` is definitionally equal to `expectedType`, returns
|
||||
|
||||
@@ -2293,7 +2293,7 @@ Return `true` if `indVal` is an inductive predicate. That is, `inductive` type i
|
||||
def isInductivePredicateVal (indVal : InductiveVal) : MetaM Bool := do
|
||||
forallTelescopeReducing indVal.type fun _ type => do
|
||||
match (← whnfD type) with
|
||||
| .sort u .. => return u == levelZero
|
||||
| .sort u .. => return u == Level.zero
|
||||
| _ => return false
|
||||
|
||||
/--
|
||||
|
||||
@@ -65,7 +65,7 @@ public def mkCtorIdx (indName : Name) : MetaM Unit :=
|
||||
pure (mkRawNatLit 0)
|
||||
else
|
||||
let motive ← mkLambdaFVars (indices.push x) natType
|
||||
let mut value := mkConst casesOnName (levelOne::us)
|
||||
let mut value := mkConst casesOnName (Level.one::us)
|
||||
value := mkAppN value params
|
||||
value := mkApp value motive
|
||||
value := mkAppN value indices
|
||||
|
||||
@@ -186,7 +186,7 @@ def mkBRecOn (ctx : Context) : MetaM Unit := do
|
||||
withBRecOnArgs (ctx := ctx) fun newMinors proofArgs => do
|
||||
let nmotives := ctx.motives.size
|
||||
let lparams := ctx.levelParams.map Level.param
|
||||
let lparams := if ctx.largeElim then levelZero :: lparams else lparams
|
||||
let lparams := if ctx.largeElim then Level.zero :: lparams else lparams
|
||||
for i in *...nmotives do
|
||||
let motive := ctx.motives[i]!
|
||||
let motiveType ← inferType motive
|
||||
|
||||
@@ -107,9 +107,9 @@ mutual
|
||||
return LBool.undef
|
||||
| _, Level.mvar .. => return LBool.undef -- Let `solve v u` to handle this case
|
||||
| Level.zero, Level.max v₁ v₂ =>
|
||||
Bool.toLBool <$> (isLevelDefEqAux levelZero v₁ <&&> isLevelDefEqAux levelZero v₂)
|
||||
Bool.toLBool <$> (isLevelDefEqAux Level.zero v₁ <&&> isLevelDefEqAux Level.zero v₂)
|
||||
| Level.zero, Level.imax _ v₂ =>
|
||||
Bool.toLBool <$> isLevelDefEqAux levelZero v₂
|
||||
Bool.toLBool <$> isLevelDefEqAux Level.zero v₂
|
||||
| Level.zero, Level.succ .. => return LBool.false
|
||||
| Level.succ u, v =>
|
||||
if v.isParam then
|
||||
|
||||
@@ -1045,7 +1045,7 @@ private partial def process (p : Problem) : StateRefT State MetaM Unit := do
|
||||
throwNonSupported p
|
||||
|
||||
private def getUElimPos? (matcherLevels : List Level) (uElim : Level) : MetaM (Option Nat) :=
|
||||
if uElim == levelZero then
|
||||
if uElim == Level.zero then
|
||||
return none
|
||||
else match matcherLevels.idxOf? uElim with
|
||||
| none => throwError "Dependent match elimination failed: Universe level not found"
|
||||
@@ -1155,10 +1155,10 @@ def mkMatcher (input : MkMatcherInput) : MetaM MatcherResult := withCleanLCtxFor
|
||||
forallBoundedTelescope matchType numDiscrs fun discrs matchTypeBody => do
|
||||
/- We generate an matcher that can eliminate using different motives with different universe levels.
|
||||
`uElim` is the universe level the caller wants to eliminate to.
|
||||
If it is not levelZero, we create a matcher that can eliminate in any universe level.
|
||||
If it is not Level.zero, we create a matcher that can eliminate in any universe level.
|
||||
This is useful for implementing `MatcherApp.addArg` because it may have to change the universe level. -/
|
||||
let uElim ← getLevel matchTypeBody
|
||||
let uElimGen ← if uElim == levelZero then pure levelZero else mkFreshLevelMVar
|
||||
let uElimGen ← if uElim == Level.zero then pure Level.zero else mkFreshLevelMVar
|
||||
let mkMatcher (type val : Expr) (altInfos : Array AltParamInfo) (s : State) : MetaM MatcherResult := do
|
||||
trace[Meta.Match.debug] "matcher value: {val}\ntype: {type}"
|
||||
/- The option `bootstrap.gen_matcher_code` is a helper hack. It is useful, for example,
|
||||
@@ -1252,7 +1252,7 @@ def getMkMatcherInputInContext (matcherApp : MatcherApp) (unfoldNamed : Bool) :
|
||||
let u :=
|
||||
if let some idx := matcherInfo.uElimPos?
|
||||
then mkLevelParam matcherConst.levelParams.toArray[idx]!
|
||||
else levelZero
|
||||
else Level.zero
|
||||
forallBoundedTelescope matcherType (some matcherInfo.numDiscrs) fun discrs _ => do
|
||||
mkForallFVars discrs (mkConst ``PUnit [u])
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ def refineThrough (matcherApp : MatcherApp) (e : Expr) : MetaM (Array Expr) :=
|
||||
let matcherLevels ← match matcherApp.uElimPos? with
|
||||
| none => pure matcherApp.matcherLevels
|
||||
| some pos =>
|
||||
pure <| matcherApp.matcherLevels.set! pos levelZero
|
||||
pure <| matcherApp.matcherLevels.set! pos Level.zero
|
||||
let motive ← mkLambdaFVars motiveArgs eEq
|
||||
let aux := mkAppN (mkConst matcherApp.matcherName matcherLevels.toList) matcherApp.params
|
||||
let aux := mkApp aux motive
|
||||
@@ -421,7 +421,7 @@ def inferMatchType (matcherApp : MatcherApp) : MetaM MatcherApp := do
|
||||
matcherApp.transform (useSplitter := true)
|
||||
(onMotive := fun motiveArgs body => do
|
||||
let extraParams ← arrowDomainsN nExtra body
|
||||
let propMotive ← mkLambdaFVars motiveArgs (.sort levelZero)
|
||||
let propMotive ← mkLambdaFVars motiveArgs (.sort Level.zero)
|
||||
let propAlts ← matcherApp.alts.mapM fun termAlt =>
|
||||
lambdaTelescope termAlt fun xs termAltBody => do
|
||||
-- We have alt parameters and parameters corresponding to the extra args
|
||||
@@ -436,7 +436,7 @@ def inferMatchType (matcherApp : MatcherApp) : MetaM MatcherApp := do
|
||||
mkLambdaFVars xs1 altType
|
||||
let matcherLevels ← match matcherApp.uElimPos? with
|
||||
| none => pure matcherApp.matcherLevels
|
||||
| some pos => pure <| matcherApp.matcherLevels.set! pos levelOne
|
||||
| some pos => pure <| matcherApp.matcherLevels.set! pos Level.one
|
||||
let typeMatcherApp := { matcherApp with
|
||||
motive := propMotive
|
||||
matcherLevels := matcherLevels
|
||||
|
||||
@@ -136,7 +136,7 @@ partial def mkSizeOfFn (recName : Name) (declName : Name): MetaM Unit := do
|
||||
let nat := mkConst ``Nat
|
||||
mkLocalInstances params fun localInsts =>
|
||||
mkSizeOfMotives motiveFVars fun motives => do
|
||||
let us := levelOne :: levelParams.map mkLevelParam -- universe level parameters for `rec`-application
|
||||
let us := Level.one :: levelParams.map mkLevelParam -- universe level parameters for `rec`-application
|
||||
let recFn := mkConst recName us
|
||||
let val := mkAppN recFn (params ++ motives)
|
||||
forallBoundedTelescope (← inferType val) recInfo.numMinors fun minorFVars' _ =>
|
||||
@@ -294,7 +294,7 @@ mutual
|
||||
| some (_, us) =>
|
||||
let recName := mkRecName info.name
|
||||
let recInfo ← getConstInfoRec recName
|
||||
let r := mkConst recName (levelZero :: us)
|
||||
let r := mkConst recName (Level.zero :: us)
|
||||
let r := mkAppN r majorTypeArgs[*...info.numParams]
|
||||
forallBoundedTelescope (← inferType r) recInfo.numMotives fun motiveFVars _ => do
|
||||
let mut r := r
|
||||
|
||||
@@ -105,7 +105,7 @@ def mkLabeledSorry (type : Expr) (synthetic : Bool) (unique : Bool) : MetaM Expr
|
||||
return .app e (toExpr tag)
|
||||
else
|
||||
let e ← mkSorry (mkForall `tag .default (mkConst ``Unit) type) synthetic
|
||||
let tag' := mkApp4 (mkConst ``Function.const [levelOne, levelOne]) (mkConst ``Unit) (mkConst ``Lean.Name) (mkConst ``Unit.unit) (toExpr tag)
|
||||
let tag' := mkApp4 (mkConst ``Function.const [Level.one, Level.one]) (mkConst ``Unit) (mkConst ``Lean.Name) (mkConst ``Unit.unit) (toExpr tag)
|
||||
return .app e tag'
|
||||
|
||||
/--
|
||||
|
||||
@@ -834,10 +834,10 @@ where doRealize (inductName : Name) := do
|
||||
|
||||
let e' ← match_expr funBody with
|
||||
| fix@WellFounded.fix α _motive rel wf _body _target =>
|
||||
let e' := .const ``WellFounded.fix [fix.constLevels![0]!, levelZero]
|
||||
let e' := .const ``WellFounded.fix [fix.constLevels![0]!, Level.zero]
|
||||
pure <| mkApp4 e' α motiveArg rel wf
|
||||
| fix@WellFounded.Nat.fix α _motive measure _body _target =>
|
||||
let e' := .const `WellFounded.Nat.fix [fix.constLevels![0]!, levelZero]
|
||||
let e' := .const `WellFounded.Nat.fix [fix.constLevels![0]!, Level.zero]
|
||||
pure <| mkApp3 e' α motiveArg measure
|
||||
| _ =>
|
||||
if funBody.isAppOf ``WellFounded.fix || funBody.isAppOf `WellFounded.Nat.Fix then
|
||||
|
||||
@@ -165,7 +165,7 @@ private def mkContext
|
||||
let h := mkLetOfMap polyDecls h (cond prime `p' `p) (mkConst ``Int.Linear.Poly) fun p => toExpr <| p.renameVars varRename
|
||||
let h := h.abstract #[ctxVar]
|
||||
if h.hasLooseBVars then
|
||||
let ctxType := mkApp (mkConst ``RArray [levelZero]) Int.mkType
|
||||
let ctxType := mkApp (mkConst ``RArray [Level.zero]) Int.mkType
|
||||
let ctxVal ← toContextExprCore vars Int.mkType
|
||||
return .letE (cond prime `ctx' `ctx) ctxType ctxVal h (nondep := false)
|
||||
else
|
||||
@@ -183,7 +183,7 @@ private def mkRingContext (h : Expr) : ProofM Expr := do
|
||||
let h := mkLetOfMap (← get).ringPolyDecls h `rp (mkConst ``Grind.CommRing.Poly) fun p => toExpr <| p.renameVars varRename
|
||||
let h := h.abstract #[(← read).ringCtx]
|
||||
if h.hasLooseBVars then
|
||||
let ctxType := mkApp (mkConst ``RArray [levelZero]) Int.mkType
|
||||
let ctxType := mkApp (mkConst ``RArray [Level.zero]) Int.mkType
|
||||
let ctxVal ← toContextExprCore vars Int.mkType
|
||||
return .letE `rctx ctxType ctxVal h (nondep := false)
|
||||
else
|
||||
|
||||
@@ -70,7 +70,7 @@ private def closeGoalWithTrueEqFalse : GoalM Unit := do
|
||||
let mvarId := (← get).mvarId
|
||||
unless (← mvarId.isAssigned) do
|
||||
let trueEqFalse ← mkEqFalseProof (← getTrueExpr)
|
||||
let falseProof := mkApp4 (mkConst ``Eq.mp [levelZero]) (← getTrueExpr) (← getFalseExpr) trueEqFalse (mkConst ``True.intro)
|
||||
let falseProof := mkApp4 (mkConst ``Eq.mp [Level.zero]) (← getTrueExpr) (← getFalseExpr) trueEqFalse (mkConst ``True.intro)
|
||||
closeGoal falseProof
|
||||
|
||||
/--
|
||||
@@ -82,7 +82,7 @@ private def closeGoalWithValuesEq (lhs rhs : Expr) : GoalM Unit := do
|
||||
let hp ← mkEqProof lhs rhs
|
||||
let d ← mkDecide p
|
||||
let pEqFalse := mkApp3 (mkConst ``eq_false_of_decide) p d.appArg! eagerReflBoolFalse
|
||||
let falseProof := mkApp4 (mkConst ``Eq.mp [levelZero]) p (← getFalseExpr) pEqFalse hp
|
||||
let falseProof := mkApp4 (mkConst ``Eq.mp [Level.zero]) p (← getFalseExpr) pEqFalse hp
|
||||
closeGoal falseProof
|
||||
|
||||
/--
|
||||
|
||||
@@ -40,7 +40,7 @@ def instantiateExtTheorem (thm : Ext.ExtTheorem) (e : Expr) : GoalM Unit := with
|
||||
-- `e` is equal to `False`
|
||||
let eEqFalse ← mkEqFalseProof e
|
||||
-- So, we use `Eq.mp` to build a `proof` of `False`
|
||||
let proof := mkApp4 (mkConst ``Eq.mp [levelZero]) e (← getFalseExpr) eEqFalse proof
|
||||
let proof := mkApp4 (mkConst ``Eq.mp [Level.zero]) e (← getFalseExpr) eEqFalse proof
|
||||
let mvars ← mvars.filterM fun mvar => return !(← mvar.mvarId!.isAssigned)
|
||||
let proof' ← instantiateMVars (← mkLambdaFVars mvars proof)
|
||||
let prop' ← inferType proof'
|
||||
|
||||
@@ -275,7 +275,7 @@ private def assertAt (proof : Expr) (prop : Expr) (generation : Nat) : Action :=
|
||||
let goal ← GoalM.run' goal do
|
||||
let r ← preprocess prop
|
||||
let prop' := r.expr
|
||||
let proof' := mkApp4 (mkConst ``Eq.mp [levelZero]) prop r.expr (← r.getProof) proof
|
||||
let proof' := mkApp4 (mkConst ``Eq.mp [Level.zero]) prop r.expr (← r.getProof) proof
|
||||
add prop' proof' generation
|
||||
kp goal
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ private def discharge? (e : Expr) : SimpM (Option Expr) := do
|
||||
let e := e.cleanupAnnotations
|
||||
let r ← Simp.simp e
|
||||
if let some p ← Simp.dischargeRfl r.expr then
|
||||
return some (mkApp4 (mkConst ``Eq.mpr [levelZero]) e r.expr (← r.getProof) p)
|
||||
return some (mkApp4 (mkConst ``Eq.mpr [Level.zero]) e r.expr (← r.getProof) p)
|
||||
else if r.expr.isTrue then
|
||||
return some (← mkOfEqTrue (← r.getProof))
|
||||
else
|
||||
|
||||
@@ -79,7 +79,7 @@ def pushNewFact' (prop : Expr) (proof : Expr) (generation : Nat := 0) : GoalM Un
|
||||
let r ← preprocess prop
|
||||
let prop' := r.expr
|
||||
let proof := if let some h := r.proof? then
|
||||
mkApp4 (mkConst ``Eq.mp [levelZero]) prop prop' h proof
|
||||
mkApp4 (mkConst ``Eq.mp [Level.zero]) prop prop' h proof
|
||||
else
|
||||
proof
|
||||
trace[grind.debug.pushNewFact] "{prop} ==> {prop'}"
|
||||
|
||||
@@ -19,7 +19,7 @@ The following table is used to bypass synthInstance for the builtin cases.
|
||||
private def builtinInsts : Std.HashMap Expr Expr :=
|
||||
let nat := Nat.mkType
|
||||
let int := Int.mkType
|
||||
let us := [levelZero, levelZero, levelZero]
|
||||
let us := [Level.zero, Level.zero, Level.zero]
|
||||
Std.HashMap.ofList [
|
||||
(mkApp3 (mkConst ``HAdd us) nat nat nat, Nat.mkInstHAdd),
|
||||
(mkApp3 (mkConst ``HSub us) nat nat nat, Nat.mkInstHSub),
|
||||
|
||||
@@ -127,7 +127,7 @@ def simpRel? (e : Expr) : MetaM (Option (Expr × Expr)) := do
|
||||
| _ => pure ()
|
||||
let some eNew := eNew? | return none
|
||||
let some (eNew', h₂) ← simpLe? eNew (checkIfModified := false) | return (eNew, h₁)
|
||||
let h := mkApp6 (mkConst ``Eq.trans [levelOne]) (mkSort levelZero) e eNew eNew' h₁ h₂
|
||||
let h := mkApp6 (mkConst ``Eq.trans [Level.one]) (mkSort Level.zero) e eNew eNew' h₁ h₂
|
||||
return some (eNew', h)
|
||||
else
|
||||
simpLe? e (checkIfModified := true)
|
||||
|
||||
@@ -61,7 +61,7 @@ def simpCnstr? (e : Expr) : MetaM (Option (Expr × Expr)) := do
|
||||
| _ => pure ()
|
||||
let some eNew := eNew? | return none
|
||||
let some (eNew', h₂) ← simpCnstrPos? eNew | return (eNew, h₁)
|
||||
let h := mkApp6 (mkConst ``Eq.trans [levelOne]) (mkSort levelZero) e eNew eNew' h₁ h₂
|
||||
let h := mkApp6 (mkConst ``Eq.trans [Level.one]) (mkSort Level.zero) e eNew eNew' h₁ h₂
|
||||
return some (eNew', h)
|
||||
else
|
||||
simpCnstrPos? e
|
||||
|
||||
@@ -136,37 +136,37 @@ private def NatOffset.fromExpr? (e : Expr) (inc : Nat := 0) : Meta.SimpM (Option
|
||||
| some (b, o) => pure (some (offset b (toExpr o) o))
|
||||
|
||||
private def mkAddNat (x y : Expr) : Expr :=
|
||||
let lz := levelZero
|
||||
let lz := Level.zero
|
||||
let nat := mkConst ``Nat
|
||||
let instHAdd := mkAppN (mkConst ``instHAdd [lz]) #[nat, mkConst ``instAddNat]
|
||||
mkAppN (mkConst ``HAdd.hAdd [lz, lz, lz]) #[nat, nat, nat, instHAdd, x, y]
|
||||
|
||||
private def mkSubNat (x y : Expr) : Expr :=
|
||||
let lz := levelZero
|
||||
let lz := Level.zero
|
||||
let nat := mkConst ``Nat
|
||||
let instSub := mkConst ``instSubNat
|
||||
let instHSub := mkAppN (mkConst ``instHSub [lz]) #[nat, instSub]
|
||||
mkAppN (mkConst ``HSub.hSub [lz, lz, lz]) #[nat, nat, nat, instHSub, x, y]
|
||||
|
||||
private def mkEqNat (x y : Expr) : Expr :=
|
||||
mkAppN (mkConst ``Eq [levelOne]) #[mkConst ``Nat, x, y]
|
||||
mkAppN (mkConst ``Eq [Level.one]) #[mkConst ``Nat, x, y]
|
||||
|
||||
private def mkBEqNatInstance : Expr :=
|
||||
mkAppN (mkConst ``instBEqOfDecidableEq [levelZero]) #[mkConst ``Nat, mkConst ``instDecidableEqNat []]
|
||||
mkAppN (mkConst ``instBEqOfDecidableEq [Level.zero]) #[mkConst ``Nat, mkConst ``instDecidableEqNat []]
|
||||
|
||||
private def mkBEqNat (x y : Expr) : Expr :=
|
||||
mkAppN (mkConst ``BEq.beq [levelZero]) #[mkConst ``Nat, mkBEqNatInstance, x, y]
|
||||
mkAppN (mkConst ``BEq.beq [Level.zero]) #[mkConst ``Nat, mkBEqNatInstance, x, y]
|
||||
|
||||
private def mkBneNat (x y : Expr) : Expr :=
|
||||
mkAppN (mkConst ``bne [levelZero]) #[mkConst ``Nat, mkBEqNatInstance, x, y]
|
||||
mkAppN (mkConst ``bne [Level.zero]) #[mkConst ``Nat, mkBEqNatInstance, x, y]
|
||||
|
||||
private def mkLENat (x y : Expr) : Expr :=
|
||||
mkAppN (.const ``LE.le [levelZero]) #[mkConst ``Nat, mkConst ``instLENat, x, y]
|
||||
mkAppN (.const ``LE.le [Level.zero]) #[mkConst ``Nat, mkConst ``instLENat, x, y]
|
||||
|
||||
private def mkGENat (x y : Expr) : Expr := mkLENat y x
|
||||
|
||||
private def mkLTNat (x y : Expr) : Expr :=
|
||||
mkAppN (.const ``LT.lt [levelZero]) #[mkConst ``Nat, mkConst ``instLTNat, x, y]
|
||||
mkAppN (.const ``LT.lt [Level.zero]) #[mkConst ``Nat, mkConst ``instLTNat, x, y]
|
||||
|
||||
private def mkGTNat (x y : Expr) : Expr := mkLTNat y x
|
||||
|
||||
|
||||
@@ -390,8 +390,8 @@ def simpForall (e : Expr) : SimpM Result := withParent e do
|
||||
let p₂ := rd.expr
|
||||
let q₁ := mkLambda e.bindingName! e.bindingInfo! p₁ e.bindingBody!
|
||||
let result ← withLocalDecl e.bindingName! e.bindingInfo! p₂ fun a => withNewLemmas #[a] do
|
||||
let prop := mkSort levelZero
|
||||
let h₁_substr_a := mkApp6 (mkConst ``Eq.substr [levelOne]) prop (mkLambda `x .default prop (mkBVar 0)) p₂ p₁ h₁ a
|
||||
let prop := mkSort Level.zero
|
||||
let h₁_substr_a := mkApp6 (mkConst ``Eq.substr [Level.one]) prop (mkLambda `x .default prop (mkBVar 0)) p₂ p₁ h₁ a
|
||||
let q_h₁_substr_a := e.bindingBody!.instantiate1 h₁_substr_a
|
||||
let rb ← simp q_h₁_substr_a
|
||||
let h₂ ← mkLambdaFVars #[a] (← rb.getProof)
|
||||
@@ -806,7 +806,7 @@ This method assumes `mvarId` is not assigned, and we are already using `mvarId`s
|
||||
def applySimpResult (mvarId : MVarId) (val : Expr) (type : Expr) (r : Simp.Result) (mayCloseGoal := true) : MetaM (Option (Expr × Expr)) := do
|
||||
if mayCloseGoal && r.expr.isFalse then
|
||||
match r.proof? with
|
||||
| some eqProof => mvarId.assign (← mkFalseElim (← mvarId.getType) (mkApp4 (mkConst ``Eq.mp [levelZero]) type r.expr eqProof val))
|
||||
| some eqProof => mvarId.assign (← mkFalseElim (← mvarId.getType) (mkApp4 (mkConst ``Eq.mp [Level.zero]) type r.expr eqProof val))
|
||||
| none => mvarId.assign (← mkFalseElim (← mvarId.getType) val)
|
||||
return none
|
||||
else
|
||||
|
||||
@@ -630,7 +630,7 @@ def dischargeDefault? (e : Expr) : SimpM (Option Expr) := do
|
||||
if let some r ← dischargeEqnThmHypothesis? e then return some r
|
||||
let r ← simp e
|
||||
if let some p ← dischargeRfl r.expr then
|
||||
return some (mkApp4 (mkConst ``Eq.mpr [levelZero]) e r.expr (← r.getProof) p)
|
||||
return some (mkApp4 (mkConst ``Eq.mpr [Level.zero]) e r.expr (← r.getProof) p)
|
||||
else if r.expr.isTrue then
|
||||
return some (← mkOfEqTrue (← r.getProof))
|
||||
else
|
||||
|
||||
@@ -190,7 +190,7 @@ private def toCtorWhenStructure (inductName : Name) (major : Expr) : MetaM Expr
|
||||
return major
|
||||
match majorType.getAppFn with
|
||||
| Expr.const d us =>
|
||||
if (← whnfD (← inferType majorType)) == mkSort levelZero then
|
||||
if (← whnfD (← inferType majorType)) == mkSort Level.zero then
|
||||
return major -- We do not perform eta for propositions, see implementation in the kernel
|
||||
else
|
||||
let some ctorName ← getFirstCtor d | pure major
|
||||
|
||||
@@ -858,7 +858,7 @@ where
|
||||
if i < hNames?.size then
|
||||
if let some name := hNames?[i]! then
|
||||
let n' ← getUnusedName name body
|
||||
withLocalDecl n' .default (.sort levelZero) (kind := .implDetail) fun _ =>
|
||||
withLocalDecl n' .default (.sort Level.zero) (kind := .implDetail) fun _ =>
|
||||
withDummyBinders hNames? body m (acc.push n')
|
||||
else
|
||||
withDummyBinders hNames? body m (acc.push none)
|
||||
|
||||
@@ -3,10 +3,10 @@ import Lean
|
||||
open Lean
|
||||
|
||||
def mkEqX (bidx : Nat) : Expr :=
|
||||
mkApp3 (mkConst ``Eq [levelOne]) (mkConst ``Nat []) (.bvar bidx) (.bvar bidx)
|
||||
mkApp3 (mkConst ``Eq [Level.one]) (mkConst ``Nat []) (.bvar bidx) (.bvar bidx)
|
||||
|
||||
def mkReflX (bidx : Nat) : Expr :=
|
||||
mkApp2 (mkConst ``Eq.refl [levelOne]) (mkConst ``Nat []) (.bvar bidx)
|
||||
mkApp2 (mkConst ``Eq.refl [Level.one]) (mkConst ``Nat []) (.bvar bidx)
|
||||
|
||||
def mkAnds (n : Nat) : Expr :=
|
||||
match n with
|
||||
|
||||
@@ -7,12 +7,12 @@ def x : PUnit := ()
|
||||
@[app_unexpander foo] def unexpandFoo : Unexpander := fun _ => `(sorry)
|
||||
|
||||
#eval do
|
||||
let e : Expr := mkApp (mkMData {} $ mkConst `foo [levelOne]) (mkConst `x)
|
||||
let e : Expr := mkApp (mkMData {} $ mkConst `foo [Level.one]) (mkConst `x)
|
||||
formatTerm (← delab e)
|
||||
|
||||
#eval do
|
||||
let opts := ({}: MData).set `pp.universes true
|
||||
-- the MData annotation should make it not a regular application,
|
||||
-- so the unexpander should not be called.
|
||||
let e : Expr := mkApp (mkMData opts $ mkConst `foo [levelOne]) (mkConst `x)
|
||||
let e : Expr := mkApp (mkMData opts $ mkConst `foo [Level.one]) (mkConst `x)
|
||||
formatTerm (← delab e)
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Export
|
||||
|
||||
structure State where
|
||||
names : Alloc Name := ⟨(∅ : Std.HashMap Name Nat).insert Name.anonymous 0, 1⟩
|
||||
levels : Alloc Level := ⟨(∅ : Std.HashMap Level Nat).insert levelZero 0, 1⟩
|
||||
levels : Alloc Level := ⟨(∅ : Std.HashMap Level Nat).insert Level.zero 0, 1⟩
|
||||
exprs : Alloc Expr
|
||||
defs : Std.HashSet Name
|
||||
stk : Array (Bool × Entry)
|
||||
|
||||
@@ -254,7 +254,7 @@ def getDeclTypeValueDagSize (declName : Name) : CoreM Nat := do
|
||||
#eval getDeclTypeValueDagSize `test8
|
||||
|
||||
def reduceAndGetDagSize (declName : Name) : MetaM Nat := do
|
||||
let c := mkConst declName [levelOne]
|
||||
let c := mkConst declName [Level.one]
|
||||
let e ← Meta.reduce c
|
||||
trace[Meta.debug] "{e}"
|
||||
e.dagSize
|
||||
|
||||
@@ -27,7 +27,7 @@ instance : Coe Name LMVarId where
|
||||
def tst1 : MetaM Unit := do
|
||||
let u := mkLevelParam `u
|
||||
let v := mkLevelMVar `v
|
||||
let m1 ← mkFreshExprMVar (mkSort levelOne)
|
||||
let m1 ← mkFreshExprMVar (mkSort Level.one)
|
||||
withLocalDeclD `α (mkSort u) $ fun α => do
|
||||
withLocalDeclD `β (mkSort v) $ fun β => do
|
||||
let m2 ← mkFreshExprMVar (← mkArrow α m1)
|
||||
@@ -53,8 +53,8 @@ withLocalDeclD `α (mkSort (mkLevelSucc u)) $ fun α => do
|
||||
withLocalDeclD `v1 (mkApp2 (mkConst `Vec [u]) α (mkNatLit 10)) $ fun v1 =>
|
||||
withLetDecl `n (mkConst `Nat) (mkNatLit 10) $ fun n =>
|
||||
withLocalDeclD `v2 (mkApp2 (mkConst `Vec [u]) α n) $ fun v2 => do
|
||||
let m ← mkFreshExprMVar (← mkArrow (mkApp2 (mkConst `Vec [u]) α (mkNatLit 10)) (mkSort levelZero))
|
||||
withLocalDeclD `p (mkSort levelZero) $ fun p => do
|
||||
let m ← mkFreshExprMVar (← mkArrow (mkApp2 (mkConst `Vec [u]) α (mkNatLit 10)) (mkSort Level.zero))
|
||||
withLocalDeclD `p (mkSort Level.zero) $ fun p => do
|
||||
let t ← mkEq v1 v2
|
||||
let t := mkApp2 (mkConst `And) t (mkApp2 (mkConst `Or) (mkApp m v2) p)
|
||||
let e ← mkAuxDefinitionFor `foo2 t
|
||||
|
||||
@@ -21,4 +21,4 @@ info: ∀ {α : Type} (xs xs_1 : Array α) (e_xs : xs = xs_1) (i i_1 : USize) (e
|
||||
xs.uget i h = xs_1.uget i_1 ⋯
|
||||
-/
|
||||
#guard_msgs in
|
||||
#eval test (mkConst ``Array.uget [levelZero])
|
||||
#eval test (mkConst ``Array.uget [Level.zero])
|
||||
|
||||
@@ -145,7 +145,7 @@ return s.getUnusedLevelParam
|
||||
/- Return `Prop` if `inProf == true` and `Sort u` otherwise, where `u` is a fresh universe level parameter. -/
|
||||
private def mkElimSort (majors : List Expr) (lhss : List AltLHS) (inProp : Bool) : MetaM Expr := do
|
||||
if inProp then
|
||||
return mkSort levelZero
|
||||
return mkSort Level.zero
|
||||
else
|
||||
let v ← getUnusedLevelParam majors lhss
|
||||
return mkSort $ v
|
||||
|
||||
@@ -64,8 +64,8 @@ do let f := mkConst `f [];
|
||||
let x1 := mkBVar 1;
|
||||
let t1 := mkAppN f #[a, b];
|
||||
let t2 := mkAppN f #[a, x0];
|
||||
let t3 := mkLambda `x BinderInfo.default (mkSort levelZero) (mkAppN f #[a, x0]);
|
||||
let t4 := mkLambda `x BinderInfo.default (mkSort levelZero) (mkAppN f #[a, x1]);
|
||||
let t3 := mkLambda `x BinderInfo.default (mkSort Level.zero) (mkAppN f #[a, x0]);
|
||||
let t4 := mkLambda `x BinderInfo.default (mkSort Level.zero) (mkAppN f #[a, x1]);
|
||||
unless (!t1.hasLooseBVar 0) do throw $ IO.userError "failed-1";
|
||||
unless (t2.hasLooseBVar 0) do throw $ IO.userError "failed-2";
|
||||
unless (!t3.hasLooseBVar 0) do throw $ IO.userError "failed-3";
|
||||
|
||||
@@ -2,7 +2,7 @@ import Lean.Expr
|
||||
|
||||
open Lean
|
||||
|
||||
def exprType : Expr := mkSort levelOne
|
||||
def exprType : Expr := mkSort Level.one
|
||||
def biDef := BinderInfo.default
|
||||
def exprNat := mkConst `Nat []
|
||||
-- Type -> Type
|
||||
|
||||
@@ -19,6 +19,6 @@ def tstHCongr (f : Expr) : MetaM Unit := do
|
||||
unless (← isDefEq result.type (← inferType result.proof)) do
|
||||
throwError "invalid proof"
|
||||
|
||||
#eval tstHCongr (mkConst ``Vec.map [levelZero, levelZero])
|
||||
#eval tstHCongr (mkConst ``Vec.map [Level.zero, Level.zero])
|
||||
|
||||
#eval tstHCongr (mkApp2 (mkConst ``Vec.map [levelZero, levelZero]) (mkConst ``Nat) (mkConst ``Nat))
|
||||
#eval tstHCongr (mkApp2 (mkConst ``Vec.map [Level.zero, Level.zero]) (mkConst ``Nat) (mkConst ``Nat))
|
||||
|
||||
@@ -6,9 +6,9 @@ unsafe def tst : IO Unit :=
|
||||
withImportModules #[{module := `Init.Data.Array}] {} fun env =>
|
||||
match env.find? `Array.foldl with
|
||||
| some info => do
|
||||
IO.println (info.instantiateTypeLevelParams [levelZero, levelZero])
|
||||
IO.println (info.instantiateValueLevelParams! [levelZero, levelZero])
|
||||
IO.println (info.instantiateValueLevelParams! [levelZero])
|
||||
IO.println (info.instantiateTypeLevelParams [Level.zero, Level.zero])
|
||||
IO.println (info.instantiateValueLevelParams! [Level.zero, Level.zero])
|
||||
IO.println (info.instantiateValueLevelParams! [Level.zero])
|
||||
| none => IO.println "Array.foldl not found"
|
||||
|
||||
#eval tst
|
||||
|
||||
@@ -10,7 +10,7 @@ def tst : MetaM Unit := do
|
||||
withLocalDeclD `x m1 fun x => do
|
||||
trace[Meta.debug] "{x} : {← inferType x}"
|
||||
trace[Meta.debug] "{m1} : {← inferType m1}"
|
||||
let m2 ← mkFreshExprMVar (mkSort levelOne)
|
||||
let m2 ← mkFreshExprMVar (mkSort Level.one)
|
||||
let t ← mkAppM ``f #[m2]
|
||||
trace[Meta.debug] "{m2} : {← inferType m2}"
|
||||
unless (← fullApproxDefEq <| isDefEq m1 t) do -- m1 := f m3 -- where `m3` has a smaller scope than `m2`
|
||||
|
||||
@@ -2,8 +2,8 @@ import Lean.Level
|
||||
|
||||
open Lean
|
||||
|
||||
#guard levelZero == levelZero
|
||||
#guard levelZero != mkLevelSucc levelZero
|
||||
#guard mkLevelMax (mkLevelSucc levelZero) levelZero != mkLevelSucc levelZero
|
||||
#guard mkLevelMax (mkLevelSucc levelZero) levelZero == mkLevelMax (mkLevelSucc levelZero) levelZero
|
||||
#guard Level.zero == Level.zero
|
||||
#guard Level.zero != mkLevelSucc Level.zero
|
||||
#guard mkLevelMax (mkLevelSucc Level.zero) Level.zero != mkLevelSucc Level.zero
|
||||
#guard mkLevelMax (mkLevelSucc Level.zero) Level.zero == mkLevelMax (mkLevelSucc Level.zero) Level.zero
|
||||
#guard Level.geq (.max (.param `u) (.param `v)) (.imax (.param `u) (.param `v))
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace Level
|
||||
def mkMax (xs : Array Level) : Level :=
|
||||
xs.foldl (start := 1) (init := xs[0]!) mkLevelMax
|
||||
|
||||
#eval toString $ normalize $ mkLevelSucc $ mkLevelSucc $ mkMax #[levelZero, mkLevelParam `w, mkLevelSucc (mkLevelSucc (mkLevelSucc (mkLevelParam `z))), levelOne, mkLevelSucc (mkLevelSucc (mkLevelParam `x)), levelZero, mkLevelParam `x, mkLevelParam `y, mkLevelParam `x, mkLevelParam `z, mkLevelSucc levelOne, mkLevelParam `w, mkLevelSucc (mkLevelParam `x)]
|
||||
#eval toString $ normalize $ mkLevelMax levelZero (mkLevelParam `x)
|
||||
#eval toString $ normalize $ mkLevelMax (mkLevelParam `x) levelZero
|
||||
#eval toString $ normalize $ mkLevelMax levelZero levelOne
|
||||
#eval toString $ normalize $ mkLevelSucc $ mkLevelSucc $ mkMax #[Level.zero, mkLevelParam `w, mkLevelSucc (mkLevelSucc (mkLevelSucc (mkLevelParam `z))), Level.one, mkLevelSucc (mkLevelSucc (mkLevelParam `x)), Level.zero, mkLevelParam `x, mkLevelParam `y, mkLevelParam `x, mkLevelParam `z, mkLevelSucc Level.one, mkLevelParam `w, mkLevelSucc (mkLevelParam `x)]
|
||||
#eval toString $ normalize $ mkLevelMax Level.zero (mkLevelParam `x)
|
||||
#eval toString $ normalize $ mkLevelMax (mkLevelParam `x) Level.zero
|
||||
#eval toString $ normalize $ mkLevelMax Level.zero Level.one
|
||||
#eval toString $ normalize $ mkLevelSucc (mkLevelMax (mkLevelParam `x) (mkLevelParam `x))
|
||||
#eval toString $ normalize $ mkLevelMax (mkLevelIMax (mkLevelParam `x) levelOne) (mkLevelMax (mkLevelSucc (mkLevelParam `x)) (mkLevelParam `x))
|
||||
#eval toString $ normalize $ mkLevelIMax (mkLevelIMax (mkLevelParam `x) levelOne) (mkLevelMax (mkLevelSucc (mkLevelParam `x)) (mkLevelParam `x))
|
||||
#eval toString $ #[levelZero, mkLevelSucc (mkLevelSucc (mkLevelParam `z)), levelOne, mkLevelSucc (mkLevelSucc (mkLevelParam `x)), levelZero, mkLevelParam `x, mkLevelParam `y, mkLevelParam `x, mkLevelParam `z, mkLevelSucc (mkLevelParam `x)].qsort normLt
|
||||
#eval toString $ normalize $ mkLevelMax (mkLevelIMax (mkLevelParam `x) Level.one) (mkLevelMax (mkLevelSucc (mkLevelParam `x)) (mkLevelParam `x))
|
||||
#eval toString $ normalize $ mkLevelIMax (mkLevelIMax (mkLevelParam `x) Level.one) (mkLevelMax (mkLevelSucc (mkLevelParam `x)) (mkLevelParam `x))
|
||||
#eval toString $ #[Level.zero, mkLevelSucc (mkLevelSucc (mkLevelParam `z)), Level.one, mkLevelSucc (mkLevelSucc (mkLevelParam `x)), Level.zero, mkLevelParam `x, mkLevelParam `y, mkLevelParam `x, mkLevelParam `z, mkLevelSucc (mkLevelParam `x)].qsort normLt
|
||||
|
||||
end Level
|
||||
end Lean
|
||||
|
||||
@@ -34,7 +34,7 @@ error: (kernel) invalid projection
|
||||
safety := .safe
|
||||
value :=
|
||||
mkProj ``Exists 0 <|
|
||||
mkApp4 (mkConst ``Exists.intro [levelOne])
|
||||
mkApp4 (mkConst ``Exists.intro [Level.one])
|
||||
(mkConst ``Nat)
|
||||
(mkLambda `x .default (mkConst ``Nat) (mkConst ``True))
|
||||
(mkConst ``Nat.zero)
|
||||
@@ -54,7 +54,7 @@ error: (kernel) invalid projection
|
||||
safety := .safe
|
||||
value :=
|
||||
mkProj ``Subtype 0 <|
|
||||
mkApp4 (mkConst ``Subtype.mk [levelOne])
|
||||
mkApp4 (mkConst ``Subtype.mk [Level.one])
|
||||
(mkConst ``Nat)
|
||||
(mkLambda `x .default (mkConst ``Nat) (mkConst ``True))
|
||||
(mkConst ``Nat.zero)
|
||||
@@ -80,14 +80,14 @@ error: (kernel) invalid projection
|
||||
levelParams := []
|
||||
type :=
|
||||
mkForall `h .default
|
||||
(mkApp2 (mkConst ``Exists [levelOne]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp3 (mkConst ``Eq [levelZero])
|
||||
(mkApp2 (mkConst ``Exists [Level.one]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp3 (mkConst ``Eq [Level.zero])
|
||||
(mkConst ``True)
|
||||
(mkProj ``Exists 1 (mkBVar 0))
|
||||
(mkProj ``Exists 1 (mkBVar 0)))
|
||||
value := mkLambda `h .default
|
||||
(mkApp2 (mkConst ``Exists [levelOne]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp2 (mkConst ``Eq.refl [levelZero]) (mkConst ``True) (mkProj ``Exists 1 (mkBVar 0)))
|
||||
(mkApp2 (mkConst ``Exists [Level.one]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp2 (mkConst ``Eq.refl [Level.zero]) (mkConst ``True) (mkProj ``Exists 1 (mkBVar 0)))
|
||||
}
|
||||
|
||||
/-!
|
||||
@@ -100,12 +100,12 @@ error: (kernel) invalid projection
|
||||
levelParams := []
|
||||
type :=
|
||||
mkForall `h .default
|
||||
(mkApp2 (mkConst ``Subtype [levelOne]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp3 (mkConst ``Eq [levelZero])
|
||||
(mkApp2 (mkConst ``Subtype [Level.one]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp3 (mkConst ``Eq [Level.zero])
|
||||
(mkConst ``True)
|
||||
(mkProj ``Subtype 1 (mkBVar 0))
|
||||
(mkProj ``Subtype 1 (mkBVar 0)))
|
||||
value := mkLambda `h .default
|
||||
(mkApp2 (mkConst ``Subtype [levelOne]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp2 (mkConst ``Eq.refl [levelZero]) (mkConst ``True) (mkProj ``Subtype 1 (mkBVar 0)))
|
||||
(mkApp2 (mkConst ``Subtype [Level.one]) (mkConst ``Nat) (mkLambda `x .default (mkConst ``Nat) (mkConst ``True)))
|
||||
(mkApp2 (mkConst ``Eq.refl [Level.zero]) (mkConst ``True) (mkProj ``Subtype 1 (mkBVar 0)))
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ def proveGoal : MetaM Unit := do
|
||||
IO.println (← ppGoal m)
|
||||
IO.println "-----"
|
||||
-- The `apply` tactic generates 0 or more subgoals
|
||||
let [m] ← m.apply (mkConst ``Eq.symm [levelOne]) | throwError "unexpected number of subgoals"
|
||||
let [m] ← m.apply (mkConst ``Eq.symm [Level.one]) | throwError "unexpected number of subgoals"
|
||||
IO.println (← ppGoal m)
|
||||
IO.println "-----"
|
||||
m.assumption
|
||||
|
||||
@@ -19,7 +19,7 @@ unsafe def tstIsProp (e : Expr) : CoreM Unit := do
|
||||
IO.println (toString e ++ ", isProp: " ++ toString b)
|
||||
|
||||
def t1 : Expr :=
|
||||
let map := mkConst `List.map [levelOne, levelOne];
|
||||
let map := mkConst `List.map [Level.one, Level.one];
|
||||
let nat := mkConst `Nat [];
|
||||
let bool := mkConst `Bool [];
|
||||
mkAppN map #[nat, bool]
|
||||
@@ -29,7 +29,7 @@ mkAppN map #[nat, bool]
|
||||
#eval tstInferType t1
|
||||
|
||||
def t2 : Expr :=
|
||||
let prop := mkSort levelZero;
|
||||
let prop := mkSort Level.zero;
|
||||
mkForall `x BinderInfo.default prop prop
|
||||
|
||||
/-- info: Prop -> Prop : Type -/
|
||||
@@ -70,12 +70,12 @@ set_option pp.all true
|
||||
#check @List.cons Nat
|
||||
|
||||
def t6 : Expr :=
|
||||
let map := mkConst `List.map [levelOne, levelOne];
|
||||
let map := mkConst `List.map [Level.one, Level.one];
|
||||
let nat := mkConst `Nat [];
|
||||
let add := mkConst `Nat.add [];
|
||||
let f := mkLambda `x BinderInfo.default nat (mkAppN add #[mkBVar 0, mkLit (Literal.natVal 1)]);
|
||||
let cons := mkApp (mkConst `List.cons [levelZero]) nat;
|
||||
let nil := mkApp (mkConst `List.nil [levelZero]) nat;
|
||||
let cons := mkApp (mkConst `List.cons [Level.zero]) nat;
|
||||
let nil := mkApp (mkConst `List.nil [Level.zero]) nat;
|
||||
let one := mkLit (Literal.natVal 1);
|
||||
let four := mkLit (Literal.natVal 4);
|
||||
let xs := mkApp (mkApp cons one) (mkApp (mkApp cons four) nil);
|
||||
@@ -95,13 +95,13 @@ info: List.map.{1, 1} Nat Nat (fun (x : Nat) => Nat.add x 1) (List.cons.{0} Nat
|
||||
|
||||
/-- info: Prop : Type -/
|
||||
#guard_msgs in
|
||||
#eval tstInferType $ mkSort levelZero
|
||||
#eval tstInferType $ mkSort Level.zero
|
||||
|
||||
/--
|
||||
info: fun {a : Type} (x : a) (xs : List.{0} a) => xs : forall {a : Type}, a -> (List.{0} a) -> (List.{0} a)
|
||||
-/
|
||||
#guard_msgs in
|
||||
#eval tstInferType $ mkLambda `a BinderInfo.implicit (mkSort levelOne) (mkLambda `x BinderInfo.default (mkBVar 0) (mkLambda `xs BinderInfo.default (mkApp (mkConst `List [levelZero]) (mkBVar 1)) (mkBVar 0)))
|
||||
#eval tstInferType $ mkLambda `a BinderInfo.implicit (mkSort Level.one) (mkLambda `x BinderInfo.default (mkBVar 0) (mkLambda `xs BinderInfo.default (mkApp (mkConst `List [Level.zero]) (mkBVar 1)) (mkBVar 0)))
|
||||
|
||||
def t7 : Expr :=
|
||||
let nat := mkConst `Nat [];
|
||||
@@ -132,7 +132,7 @@ mkLet `x nat one (mkAppN add #[one, mkBVar 0])
|
||||
|
||||
def t9 : Expr :=
|
||||
let nat := mkConst `Nat [];
|
||||
mkLet `a (mkSort levelOne) nat (mkForall `x BinderInfo.default (mkBVar 0) (mkBVar 1))
|
||||
mkLet `a (mkSort Level.one) nat (mkForall `x BinderInfo.default (mkBVar 0) (mkBVar 1))
|
||||
|
||||
/-- info: let a : Type := Nat; a -> a : Type -/
|
||||
#guard_msgs in
|
||||
@@ -156,7 +156,7 @@ mkLet `a (mkSort levelOne) nat (mkForall `x BinderInfo.default (mkBVar 0) (mkBVa
|
||||
|
||||
def t10 : Expr :=
|
||||
let nat := mkConst `Nat [];
|
||||
let refl := mkApp (mkConst `Eq.refl [levelOne]) nat;
|
||||
let refl := mkApp (mkConst `Eq.refl [Level.one]) nat;
|
||||
mkLambda `a BinderInfo.default nat (mkApp refl (mkBVar 0))
|
||||
|
||||
/-- info: fun (a : Nat) => Eq.refl.{1} Nat a : forall (a : Nat), Eq.{1} Nat a a -/
|
||||
@@ -178,23 +178,23 @@ mkLambda `a BinderInfo.default nat (mkApp refl (mkBVar 0))
|
||||
-- Example where isPropQuick fails
|
||||
/-- info: id.{0} Prop (And True True), isProp: true -/
|
||||
#guard_msgs in
|
||||
#eval tstIsProp (mkAppN (mkConst `id [levelZero]) #[mkSort levelZero, mkAppN (mkConst `And []) #[mkConst `True [], mkConst
|
||||
#eval tstIsProp (mkAppN (mkConst `id [Level.zero]) #[mkSort Level.zero, mkAppN (mkConst `And []) #[mkConst `True [], mkConst
|
||||
`True []]])
|
||||
|
||||
/-- info: Eq.{1} Nat 0 1, isProp: true -/
|
||||
#guard_msgs in
|
||||
#eval tstIsProp (mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkLit (Literal.natVal 0), mkLit (Literal.natVal 1)])
|
||||
#eval tstIsProp (mkAppN (mkConst `Eq [Level.one]) #[mkConst `Nat [], mkLit (Literal.natVal 0), mkLit (Literal.natVal 1)])
|
||||
|
||||
/-- info: forall (x : Nat), Eq.{1} Nat x 1, isProp: true -/
|
||||
#guard_msgs in
|
||||
#eval tstIsProp $
|
||||
mkForall `x BinderInfo.default (mkConst `Nat [])
|
||||
(mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkBVar 0, mkLit (Literal.natVal 1)])
|
||||
(mkAppN (mkConst `Eq [Level.one]) #[mkConst `Nat [], mkBVar 0, mkLit (Literal.natVal 1)])
|
||||
|
||||
/-- info: (fun (x : Nat) => Eq.{1} Nat x 1) 0, isProp: true -/
|
||||
#guard_msgs in
|
||||
#eval tstIsProp $
|
||||
mkApp
|
||||
(mkLambda `x BinderInfo.default (mkConst `Nat [])
|
||||
(mkAppN (mkConst `Eq [levelOne]) #[mkConst `Nat [], mkBVar 0, mkLit (Literal.natVal 1)]))
|
||||
(mkAppN (mkConst `Eq [Level.one]) #[mkConst `Nat [], mkBVar 0, mkLit (Literal.natVal 1)]))
|
||||
(mkLit (Literal.natVal 0))
|
||||
|
||||
@@ -27,7 +27,7 @@ def succ := mkConst `Nat.succ
|
||||
def zero := mkConst `Nat.zero
|
||||
def add := mkConst `Nat.add
|
||||
def io := mkConst `IO
|
||||
def type := mkSort levelOne
|
||||
def type := mkSort Level.one
|
||||
def boolFalse := mkConst `Bool.false
|
||||
def boolTrue := mkConst `Bool.true
|
||||
|
||||
@@ -548,21 +548,21 @@ print "----- tst29 -----";
|
||||
let u := mkLevelParam `u;
|
||||
let v := mkLevelParam `v;
|
||||
let u1 := mkLevelSucc u;
|
||||
let m := mkLevelMax levelOne u1;
|
||||
let m := mkLevelMax Level.one u1;
|
||||
print (norm m);
|
||||
checkM $ pure $ norm m == u1;
|
||||
let m := mkLevelMax u1 levelOne;
|
||||
let m := mkLevelMax u1 Level.one;
|
||||
print (norm m);
|
||||
checkM $ pure $ norm m == u1;
|
||||
let m := mkLevelMax (mkLevelMax levelOne (mkLevelSucc u1)) (mkLevelSucc levelOne);
|
||||
let m := mkLevelMax (mkLevelMax Level.one (mkLevelSucc u1)) (mkLevelSucc Level.one);
|
||||
checkM $ pure $ norm m == mkLevelSucc u1;
|
||||
print m;
|
||||
print (norm m);
|
||||
let m := mkLevelMax (mkLevelMax (mkLevelSucc (mkLevelSucc u1)) (mkLevelSucc u1)) (mkLevelSucc levelOne);
|
||||
let m := mkLevelMax (mkLevelMax (mkLevelSucc (mkLevelSucc u1)) (mkLevelSucc u1)) (mkLevelSucc Level.one);
|
||||
print m;
|
||||
print (norm m);
|
||||
checkM $ pure $ norm m == mkLevelSucc (mkLevelSucc u1);
|
||||
let m := mkLevelMax (mkLevelMax (mkLevelSucc v) (mkLevelSucc u1)) (mkLevelSucc levelOne);
|
||||
let m := mkLevelMax (mkLevelMax (mkLevelSucc v) (mkLevelSucc u1)) (mkLevelSucc Level.one);
|
||||
print m;
|
||||
print (norm m);
|
||||
pure ()
|
||||
@@ -620,7 +620,7 @@ let aeqb ← mkEq a b;
|
||||
withLocalDeclD `h2 aeqb $ fun h2 => do
|
||||
let t ← mkEq (mkApp2 add a a) a;
|
||||
print t;
|
||||
let motive := mkLambda `x BinderInfo.default nat (mkApp3 (mkConst `Eq [levelOne]) nat (mkApp2 add a (mkBVar 0)) a);
|
||||
let motive := mkLambda `x BinderInfo.default nat (mkApp3 (mkConst `Eq [Level.one]) nat (mkApp2 add a (mkBVar 0)) a);
|
||||
withLocalDeclD `h1 t $ fun h1 => do
|
||||
let r ← mkEqNDRec motive h1 h2;
|
||||
print r;
|
||||
@@ -647,8 +647,8 @@ withLocalDeclD `h2 aeqb $ fun h2 => do
|
||||
let t ← mkEq (mkApp2 add a a) a;
|
||||
let motive :=
|
||||
mkLambda `x BinderInfo.default nat $
|
||||
mkLambda `h BinderInfo.default (mkApp3 (mkConst `Eq [levelOne]) nat a (mkBVar 0)) $
|
||||
(mkApp3 (mkConst `Eq [levelOne]) nat (mkApp2 add a (mkBVar 1)) a);
|
||||
mkLambda `h BinderInfo.default (mkApp3 (mkConst `Eq [Level.one]) nat a (mkBVar 0)) $
|
||||
(mkApp3 (mkConst `Eq [Level.one]) nat (mkApp2 add a (mkBVar 1)) a);
|
||||
withLocalDeclD `h1 t $ fun h1 => do
|
||||
let r ← mkEqRec motive h1 h2;
|
||||
print r;
|
||||
@@ -667,7 +667,7 @@ trace: [Meta.debug] ----- tst33 -----
|
||||
|
||||
def tst34 : MetaM Unit := do
|
||||
print "----- tst34 -----";
|
||||
let type := mkSort levelOne;
|
||||
let type := mkSort Level.one;
|
||||
withLocalDeclD `α type $ fun α => do
|
||||
let m ← mkFreshExprMVar type;
|
||||
let t ← mkLambdaFVars #[α] (← mkArrow m m);
|
||||
@@ -683,7 +683,7 @@ trace: [Meta.debug] ----- tst34 -----
|
||||
|
||||
def tst35 : MetaM Unit := do
|
||||
print "----- tst35 -----";
|
||||
let type := mkSort levelOne;
|
||||
let type := mkSort Level.one;
|
||||
withLocalDeclD `α type $ fun α => do
|
||||
let m1 ← mkFreshExprMVar type;
|
||||
let m2 ← mkFreshExprMVar (← mkArrow nat type);
|
||||
@@ -709,13 +709,13 @@ trace: [Meta.debug] ----- tst35 -----
|
||||
|
||||
def tst36 : MetaM Unit := do
|
||||
print "----- tst36 -----";
|
||||
let type := mkSort levelOne;
|
||||
let type := mkSort Level.one;
|
||||
let m1 ← mkFreshExprMVar (← mkArrow type type);
|
||||
withLocalDeclD `α type $ fun α => do
|
||||
let m2 ← mkFreshExprMVar type;
|
||||
let t ← mkAppM `Id #[m2];
|
||||
checkM $ approxDefEq $ isDefEq (mkApp m1 α) t;
|
||||
checkM $ approxDefEq $ isDefEq m1 (mkConst `Id [levelZero]);
|
||||
checkM $ approxDefEq $ isDefEq m1 (mkConst `Id [Level.zero]);
|
||||
pure ()
|
||||
|
||||
/-- trace: [Meta.debug] ----- tst36 ----- -/
|
||||
|
||||
@@ -23,7 +23,7 @@ do let v? ← getExprMVarAssignment? m.mvarId!;
|
||||
|
||||
def nat := mkConst `Nat
|
||||
def succ := mkConst `Nat.succ
|
||||
def add := mkAppN (mkConst `Add.add [levelZero]) #[nat, mkConst `Nat.add]
|
||||
def add := mkAppN (mkConst `Add.add [Level.zero]) #[nat, mkConst `Nat.add]
|
||||
|
||||
def tst1 : MetaM Unit :=
|
||||
do let d : DiscrTree Nat := {};
|
||||
|
||||
@@ -15,7 +15,7 @@ def succ := mkConst `Nat.succ
|
||||
def zero := mkConst `Nat.zero
|
||||
def add := mkConst `Nat.add
|
||||
def io := mkConst `IO
|
||||
def type := mkSort levelOne
|
||||
def type := mkSort Level.one
|
||||
def mkArrow (d b : Expr) : Expr := mkForall `_ BinderInfo.default d b
|
||||
|
||||
def tst1 : MetaM Unit := do
|
||||
@@ -87,7 +87,7 @@ def tst5 : MetaM Unit := do
|
||||
let arrayNat ← mkAppM `Array #[nat];
|
||||
withLocalDeclD `a arrayNat fun a => do
|
||||
withLocalDeclD `b arrayNat fun b => do
|
||||
let motiveType := _root_.mkArrow arrayNat (mkSort levelZero);
|
||||
let motiveType := _root_.mkArrow arrayNat (mkSort Level.zero);
|
||||
withLocalDeclD `motive motiveType fun motive => do
|
||||
let mvarType := mkApp motive a;
|
||||
let mvar ← mkFreshExprSyntheticOpaqueMVar mvarType;
|
||||
|
||||
@@ -124,7 +124,7 @@ trace: [Meta.debug] ----- tst4 -----
|
||||
|
||||
def tst5 : MetaM Unit := do
|
||||
print "----- tst5 -----";
|
||||
let prop := mkSort levelZero;
|
||||
let prop := mkSort Level.zero;
|
||||
withLocalDeclD `p prop fun p =>
|
||||
withLocalDeclD `q prop fun q => do
|
||||
withLocalDeclD `h₁ p fun h₁ => do
|
||||
@@ -278,11 +278,11 @@ def tst12 : MetaM Unit := do
|
||||
let nat := mkConst `Nat
|
||||
withLocalDeclD `x nat fun x =>
|
||||
withLocalDeclD `y nat fun y => do
|
||||
let val ← mkAppM' (mkConst `Add.add [levelZero]) #[mkNatLit 10, y];
|
||||
let val ← mkAppM' (mkConst `Add.add [Level.zero]) #[mkNatLit 10, y];
|
||||
check val; print val
|
||||
let val ← mkAppM' (mkApp (mkConst ``Add.add [levelZero]) (mkConst ``Int)) #[mkApp (mkConst ``Int.ofNat) (mkNatLit 10), mkApp (mkConst ``Int.ofNat) y];
|
||||
let val ← mkAppM' (mkApp (mkConst ``Add.add [Level.zero]) (mkConst ``Int)) #[mkApp (mkConst ``Int.ofNat) (mkNatLit 10), mkApp (mkConst ``Int.ofNat) y];
|
||||
check val; print val
|
||||
let val ← mkAppOptM' (mkConst `Add.add [levelZero]) #[mkConst ``Nat, none, mkNatLit 10, y];
|
||||
let val ← mkAppOptM' (mkConst `Add.add [Level.zero]) #[mkConst ``Nat, none, mkNatLit 10, y];
|
||||
check val; print val
|
||||
pure ()
|
||||
|
||||
|
||||
@@ -12,15 +12,15 @@ def test (e : Expr) : MetaM Unit := do
|
||||
#eval test (mkBVar 0)
|
||||
|
||||
-- anonymous binder
|
||||
#eval test (mkLambda Name.anonymous BinderInfo.default (mkSort levelZero) (mkBVar 0))
|
||||
#eval test (mkLambda Name.anonymous BinderInfo.default (mkSort Level.zero) (mkBVar 0))
|
||||
|
||||
-- pp annotations
|
||||
#eval test $
|
||||
mkAppN (mkConst `id [levelOne]) #[
|
||||
mkAppN (mkConst `id [Level.one]) #[
|
||||
mkConst `Nat,
|
||||
mkMData (KVMap.empty.set `pp.explicit true) $ mkAppN (mkConst `id [levelOne]) #[
|
||||
mkMData (KVMap.empty.set `pp.explicit true) $ mkAppN (mkConst `id [Level.one]) #[
|
||||
mkConst `Nat,
|
||||
mkAppN (mkConst `id [levelOne]) #[
|
||||
mkAppN (mkConst `id [Level.one]) #[
|
||||
mkConst `Nat,
|
||||
mkConst `Nat.zero
|
||||
]]]
|
||||
|
||||
@@ -29,7 +29,7 @@ trace[Meta.synthInstance] (toString a)
|
||||
|
||||
|
||||
def tst1 : MetaM Unit := do
|
||||
let inst ← mkAppM `HasCoerce #[mkConst `Nat, mkSort levelZero]
|
||||
let inst ← mkAppM `HasCoerce #[mkConst `Nat, mkSort Level.zero]
|
||||
let r ← synthInstance inst
|
||||
print r
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ open Lean Meta
|
||||
-- In a new MCtx depth, metavariables should not be assignable by `isDefEq`.
|
||||
|
||||
run_meta do
|
||||
let m ← mkFreshExprMVar (Expr.sort levelOne) MetavarKind.syntheticOpaque
|
||||
let m ← mkFreshExprMVar (Expr.sort Level.one) MetavarKind.syntheticOpaque
|
||||
withAssignableSyntheticOpaque do
|
||||
withNewMCtxDepth do
|
||||
let eq ← isDefEq m (.const ``Nat [])
|
||||
|
||||
@@ -11,11 +11,11 @@ do let f := mkConst `f [];
|
||||
let t4 := mkProj `Prod 1 x;
|
||||
let t5 := t4.updateProj! y;
|
||||
let t6 := t4.updateProj! x;
|
||||
let x₁ := x.updateConst! [levelOne];
|
||||
let x₁ := x.updateConst! [Level.one];
|
||||
let x₂ := x.updateConst! [];
|
||||
let s := mkSort levelOne;
|
||||
let s₁ := s.updateSort! levelOne;
|
||||
let s₂ := s.updateSort! levelZero;
|
||||
let s := mkSort Level.one;
|
||||
let s₁ := s.updateSort! Level.one;
|
||||
let s₂ := s.updateSort! Level.zero;
|
||||
let a := mkForall `x BinderInfo.default s s;
|
||||
let a₁ := a.updateForall! BinderInfo.default s s;
|
||||
let a₂ := a.updateForall! BinderInfo.default s₂ s;
|
||||
|
||||
@@ -3,8 +3,8 @@ import Lean
|
||||
open Lean
|
||||
|
||||
unsafe def tst1 : MetaM Unit := do
|
||||
let e := mkApp (mkSort levelZero) (mkSort levelZero)
|
||||
let e' := e.updateApp! (mkSort levelZero) (mkSort levelZero)
|
||||
let e := mkApp (mkSort Level.zero) (mkSort Level.zero)
|
||||
let e' := e.updateApp! (mkSort Level.zero) (mkSort Level.zero)
|
||||
assert! ptrAddrUnsafe e == ptrAddrUnsafe e'
|
||||
let e' := e.replace fun _ => none
|
||||
assert! ptrAddrUnsafe e == ptrAddrUnsafe e'
|
||||
|
||||
@@ -4,14 +4,14 @@ open Lean
|
||||
@[noinline] def noinline (a : α) := a
|
||||
|
||||
#eval
|
||||
let b := levelZero
|
||||
let b := Level.zero
|
||||
let a1 := mkLevelParam `a
|
||||
let a2 := mkLevelParam (noinline `a)
|
||||
let l := mkLevelMax a1 b
|
||||
(l.updateMax! a1 b).isMax == (l.updateMax! a2 b).isMax
|
||||
|
||||
#eval
|
||||
let b := levelZero
|
||||
let b := Level.zero
|
||||
let a1 := mkLevelParam `a
|
||||
let l := mkLevelMax a1 b
|
||||
assert! (l.updateMax! a1 b) == a1
|
||||
|
||||
Reference in New Issue
Block a user