feat: add warn.redundantExpose for redundant @[expose]/@[no_expose] attributes (#13359)
This PR adds a `linter.redundantExpose` option (default `true`) that warns when `@[expose]` or `@[no_expose]` attributes have no effect: - `@[expose]` on `abbrev` (always exposed) or non-Prop `instance` (always exposed) - `@[expose]` on a `def` inside an `@[expose] section` (already exposed by the section) - `@[expose]`/`@[no_expose]` in a non-`module` file (no module system) - `@[no_expose]` on a declaration that wouldn't be exposed by default --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
824ccd9662
commit
7f5fac9d9f
40 changed files with 204 additions and 208 deletions
|
|
@ -48,7 +48,7 @@ instance (priority := 500) instForInOfForIn' [ForIn' m ρ α d] : ForIn m ρ α
|
||||||
/--
|
/--
|
||||||
Extracts the value from a `ForInStep`, ignoring whether it is `ForInStep.done` or `ForInStep.yield`.
|
Extracts the value from a `ForInStep`, ignoring whether it is `ForInStep.done` or `ForInStep.yield`.
|
||||||
-/
|
-/
|
||||||
@[expose] def ForInStep.value (x : ForInStep α) : α :=
|
def ForInStep.value (x : ForInStep α) : α :=
|
||||||
match x with
|
match x with
|
||||||
| ForInStep.done b => b
|
| ForInStep.done b => b
|
||||||
| ForInStep.yield b => b
|
| ForInStep.yield b => b
|
||||||
|
|
|
||||||
|
|
@ -19,29 +19,27 @@ non-algebraic higher-order effect combinators such as `tryCatch`.
|
||||||
-/
|
-/
|
||||||
|
|
||||||
/-- A wrapper around `ExceptT` signifying early return. -/
|
/-- A wrapper around `ExceptT` signifying early return. -/
|
||||||
@[expose]
|
|
||||||
abbrev EarlyReturnT (ρ m α) := ExceptT ρ m α
|
abbrev EarlyReturnT (ρ m α) := ExceptT ρ m α
|
||||||
|
|
||||||
/-- Exit a computation by returning a value `r : ρ` early. -/
|
/-- Exit a computation by returning a value `r : ρ` early. -/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
abbrev EarlyReturnT.return {ρ m α} [Monad m] (r : ρ) : EarlyReturnT ρ m α :=
|
abbrev EarlyReturnT.return {ρ m α} [Monad m] (r : ρ) : EarlyReturnT ρ m α :=
|
||||||
throw r
|
throw r
|
||||||
|
|
||||||
/-- A specialization of `Except.casesOn`. -/
|
/-- A specialization of `Except.casesOn`. -/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
abbrev EarlyReturn.runK {ρ α : Type u} {β : Type v} (x : Except ρ α) (ret : ρ → β) (pure : α → β) : β :=
|
abbrev EarlyReturn.runK {ρ α : Type u} {β : Type v} (x : Except ρ α) (ret : ρ → β) (pure : α → β) : β :=
|
||||||
x.casesOn ret pure
|
x.casesOn ret pure
|
||||||
|
|
||||||
/-- A wrapper around `OptionT` signifying `break` in a loop. -/
|
/-- A wrapper around `OptionT` signifying `break` in a loop. -/
|
||||||
@[expose]
|
|
||||||
abbrev BreakT := OptionT
|
abbrev BreakT := OptionT
|
||||||
|
|
||||||
/-- Exit a loop body via `break`. -/
|
/-- Exit a loop body via `break`. -/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
abbrev BreakT.break {m : Type w → Type x} [Monad m] : BreakT m α := failure
|
abbrev BreakT.break {m : Type w → Type x} [Monad m] : BreakT m α := failure
|
||||||
|
|
||||||
/-- A specialization of `Option.casesOn`. -/
|
/-- A specialization of `Option.casesOn`. -/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
abbrev Break.runK {α : Type u} {β : Type v} (x : Option α) (breakK : Unit → β) (successK : α → β) : β :=
|
abbrev Break.runK {α : Type u} {β : Type v} (x : Option α) (breakK : Unit → β) (successK : α → β) : β :=
|
||||||
-- Note: The matcher below is used in the elaborator targeting `forIn` loops.
|
-- Note: The matcher below is used in the elaborator targeting `forIn` loops.
|
||||||
-- If you change the order of match arms here, you may need to adjust the elaborator.
|
-- If you change the order of match arms here, you may need to adjust the elaborator.
|
||||||
|
|
@ -50,14 +48,13 @@ abbrev Break.runK {α : Type u} {β : Type v} (x : Option α) (breakK : Unit →
|
||||||
| none => breakK ()
|
| none => breakK ()
|
||||||
|
|
||||||
/-- A wrapper around `OptionT` signifying `continue` in a loop. -/
|
/-- A wrapper around `OptionT` signifying `continue` in a loop. -/
|
||||||
@[expose]
|
|
||||||
abbrev ContinueT := OptionT
|
abbrev ContinueT := OptionT
|
||||||
|
|
||||||
/-- Exit a loop body via `continue`. -/
|
/-- Exit a loop body via `continue`. -/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
abbrev ContinueT.continue {m : Type w → Type x} [Monad m] : ContinueT m α := failure
|
abbrev ContinueT.continue {m : Type w → Type x} [Monad m] : ContinueT m α := failure
|
||||||
|
|
||||||
/-- A specialization of `Option.casesOn`. -/
|
/-- A specialization of `Option.casesOn`. -/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
abbrev Continue.runK {α : Type u} {β : Type v} (x : Option α) (continueK : Unit → β) (successK : α → β) : β :=
|
abbrev Continue.runK {α : Type u} {β : Type v} (x : Option α) (continueK : Unit → β) (successK : α → β) : β :=
|
||||||
x.casesOn continueK (fun a _ => successK a) ()
|
x.casesOn continueK (fun a _ => successK a) ()
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ end Except
|
||||||
/--
|
/--
|
||||||
Adds exceptions of type `ε` to a monad `m`.
|
Adds exceptions of type `ε` to a monad `m`.
|
||||||
-/
|
-/
|
||||||
@[expose] def ExceptT (ε : Type u) (m : Type u → Type v) (α : Type u) : Type v :=
|
def ExceptT (ε : Type u) (m : Type u → Type v) (α : Type u) : Type v :=
|
||||||
m (Except ε α)
|
m (Except ε α)
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -137,7 +137,7 @@ may throw the corresponding exception.
|
||||||
|
|
||||||
This is the inverse of `ExceptT.run`.
|
This is the inverse of `ExceptT.run`.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def ExceptT.mk {ε : Type u} {m : Type u → Type v} {α : Type u} (x : m (Except ε α)) : ExceptT ε m α := x
|
def ExceptT.mk {ε : Type u} {m : Type u → Type v} {α : Type u} (x : m (Except ε α)) : ExceptT ε m α := x
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -145,14 +145,14 @@ Use a monadic action that may throw an exception as an action that may return an
|
||||||
|
|
||||||
This is the inverse of `ExceptT.mk`.
|
This is the inverse of `ExceptT.mk`.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def ExceptT.run {ε : Type u} {m : Type u → Type v} {α : Type u} (x : ExceptT ε m α) : m (Except ε α) := x
|
def ExceptT.run {ε : Type u} {m : Type u → Type v} {α : Type u} (x : ExceptT ε m α) : m (Except ε α) := x
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Use a monadic action that may throw an exception by providing explicit success and failure
|
Use a monadic action that may throw an exception by providing explicit success and failure
|
||||||
continuations.
|
continuations.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def ExceptT.runK [Monad m] (x : ExceptT ε m α) (ok : α → m β) (error : ε → m β) : m β :=
|
def ExceptT.runK [Monad m] (x : ExceptT ε m α) (ok : α → m β) (error : ε → m β) : m β :=
|
||||||
x.run >>= (·.casesOn error ok)
|
x.run >>= (·.casesOn error ok)
|
||||||
|
|
||||||
|
|
@ -161,7 +161,7 @@ Returns the value of a computation, forgetting whether it was an exception or a
|
||||||
|
|
||||||
This corresponds to early return.
|
This corresponds to early return.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def ExceptT.runCatch [Monad m] (x : ExceptT α m α) : m α :=
|
def ExceptT.runCatch [Monad m] (x : ExceptT α m α) : m α :=
|
||||||
x.runK pure pure
|
x.runK pure pure
|
||||||
|
|
||||||
|
|
@ -172,14 +172,14 @@ variable {ε : Type u} {m : Type u → Type v} [Monad m]
|
||||||
/--
|
/--
|
||||||
Returns the value `a` without throwing exceptions or having any other effect.
|
Returns the value `a` without throwing exceptions or having any other effect.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
protected def pure {α : Type u} (a : α) : ExceptT ε m α :=
|
protected def pure {α : Type u} (a : α) : ExceptT ε m α :=
|
||||||
ExceptT.mk <| pure (Except.ok a)
|
ExceptT.mk <| pure (Except.ok a)
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Handles exceptions thrown by an action that can have no effects _other_ than throwing exceptions.
|
Handles exceptions thrown by an action that can have no effects _other_ than throwing exceptions.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
protected def bindCont {α β : Type u} (f : α → ExceptT ε m β) : Except ε α → m (Except ε β)
|
protected def bindCont {α β : Type u} (f : α → ExceptT ε m β) : Except ε α → m (Except ε β)
|
||||||
| Except.ok a => f a
|
| Except.ok a => f a
|
||||||
| Except.error e => pure (Except.error e)
|
| Except.error e => pure (Except.error e)
|
||||||
|
|
@ -188,14 +188,14 @@ protected def bindCont {α β : Type u} (f : α → ExceptT ε m β) : Except ε
|
||||||
Sequences two actions that may throw exceptions. Typically used via `do`-notation or the `>>=`
|
Sequences two actions that may throw exceptions. Typically used via `do`-notation or the `>>=`
|
||||||
operator.
|
operator.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
protected def bind {α β : Type u} (ma : ExceptT ε m α) (f : α → ExceptT ε m β) : ExceptT ε m β :=
|
protected def bind {α β : Type u} (ma : ExceptT ε m α) (f : α → ExceptT ε m β) : ExceptT ε m β :=
|
||||||
ExceptT.mk <| ma >>= ExceptT.bindCont f
|
ExceptT.mk <| ma >>= ExceptT.bindCont f
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Transforms a successful computation's value using `f`. Typically used via the `<$>` operator.
|
Transforms a successful computation's value using `f`. Typically used via the `<$>` operator.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
protected def map {α β : Type u} (f : α → β) (x : ExceptT ε m α) : ExceptT ε m β :=
|
protected def map {α β : Type u} (f : α → β) (x : ExceptT ε m α) : ExceptT ε m β :=
|
||||||
ExceptT.mk <| x >>= fun a => match a with
|
ExceptT.mk <| x >>= fun a => match a with
|
||||||
| (Except.ok a) => pure <| Except.ok (f a)
|
| (Except.ok a) => pure <| Except.ok (f a)
|
||||||
|
|
@ -204,7 +204,7 @@ protected def map {α β : Type u} (f : α → β) (x : ExceptT ε m α) : Excep
|
||||||
/--
|
/--
|
||||||
Runs a computation from an underlying monad in the transformed monad with exceptions.
|
Runs a computation from an underlying monad in the transformed monad with exceptions.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
protected def lift {α : Type u} (t : m α) : ExceptT ε m α :=
|
protected def lift {α : Type u} (t : m α) : ExceptT ε m α :=
|
||||||
ExceptT.mk <| Except.ok <$> t
|
ExceptT.mk <| Except.ok <$> t
|
||||||
|
|
||||||
|
|
@ -215,7 +215,7 @@ instance : MonadLift m (ExceptT ε m) := ⟨ExceptT.lift⟩
|
||||||
/--
|
/--
|
||||||
Handles exceptions produced in the `ExceptT ε` transformer.
|
Handles exceptions produced in the `ExceptT ε` transformer.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
protected def tryCatch {α : Type u} (ma : ExceptT ε m α) (handle : ε → ExceptT ε m α) : ExceptT ε m α :=
|
protected def tryCatch {α : Type u} (ma : ExceptT ε m α) (handle : ε → ExceptT ε m α) : ExceptT ε m α :=
|
||||||
ExceptT.mk <| ma >>= fun res => match res with
|
ExceptT.mk <| ma >>= fun res => match res with
|
||||||
| Except.ok a => pure (Except.ok a)
|
| Except.ok a => pure (Except.ok a)
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ eq_norm ctx p q (eagerReduce (Eq.refl true)) h
|
||||||
to instruct the kernel to use eager reduction when establishing that `(p.norm == q) = true` is
|
to instruct the kernel to use eager reduction when establishing that `(p.norm == q) = true` is
|
||||||
definitionally equal to `true = true`.
|
definitionally equal to `true = true`.
|
||||||
-/
|
-/
|
||||||
@[expose] def eagerReduce {α : Sort u} (a : α) : α := a
|
def eagerReduce {α : Sort u} (a : α) : α := a
|
||||||
|
|
||||||
/--
|
/--
|
||||||
`flip f a b` is `f b a`. It is useful for "point-free" programming,
|
`flip f a b` is `f b a`. It is useful for "point-free" programming,
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ end subsingleton
|
||||||
section zero_allOnes
|
section zero_allOnes
|
||||||
|
|
||||||
/-- Returns a bitvector of size `n` where all bits are `0`. -/
|
/-- Returns a bitvector of size `n` where all bits are `0`. -/
|
||||||
@[expose] protected def zero (n : Nat) : BitVec n := .ofNatLT 0 (Nat.two_pow_pos n)
|
protected def zero (n : Nat) : BitVec n := .ofNatLT 0 (Nat.two_pow_pos n)
|
||||||
instance : Inhabited (BitVec n) where default := .zero n
|
instance : Inhabited (BitVec n) where default := .zero n
|
||||||
|
|
||||||
/-- Returns a bitvector of size `n` where all bits are `1`. -/
|
/-- Returns a bitvector of size `n` where all bits are `1`. -/
|
||||||
|
|
@ -83,10 +83,10 @@ section getXsb
|
||||||
/--
|
/--
|
||||||
Returns the `i`th least significant bit.
|
Returns the `i`th least significant bit.
|
||||||
-/
|
-/
|
||||||
@[inline, expose] def getLsb (x : BitVec w) (i : Fin w) : Bool := x.toNat.testBit i
|
@[inline] def getLsb (x : BitVec w) (i : Fin w) : Bool := x.toNat.testBit i
|
||||||
|
|
||||||
/-- Returns the `i`th least significant bit, or `none` if `i ≥ w`. -/
|
/-- Returns the `i`th least significant bit, or `none` if `i ≥ w`. -/
|
||||||
@[inline, expose] def getLsb? (x : BitVec w) (i : Nat) : Option Bool :=
|
@[inline] def getLsb? (x : BitVec w) (i : Nat) : Option Bool :=
|
||||||
if h : i < w then some (getLsb x ⟨i, h⟩) else none
|
if h : i < w then some (getLsb x ⟨i, h⟩) else none
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -99,7 +99,7 @@ Returns the `i`th most significant bit.
|
||||||
if h : i < w then some (getMsb x ⟨i, h⟩) else none
|
if h : i < w then some (getMsb x ⟨i, h⟩) else none
|
||||||
|
|
||||||
/-- Returns the `i`th least significant bit or `false` if `i ≥ w`. -/
|
/-- Returns the `i`th least significant bit or `false` if `i ≥ w`. -/
|
||||||
@[inline, expose] def getLsbD (x : BitVec w) (i : Nat) : Bool :=
|
@[inline] def getLsbD (x : BitVec w) (i : Nat) : Bool :=
|
||||||
x.toNat.testBit i
|
x.toNat.testBit i
|
||||||
|
|
||||||
/-- Returns the `i`th most significant bit, or `false` if `i ≥ w`. -/
|
/-- Returns the `i`th most significant bit, or `false` if `i ≥ w`. -/
|
||||||
|
|
@ -139,7 +139,6 @@ section Int
|
||||||
/--
|
/--
|
||||||
Interprets the bitvector as an integer stored in two's complement form.
|
Interprets the bitvector as an integer stored in two's complement form.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def toInt (x : BitVec n) : Int :=
|
protected def toInt (x : BitVec n) : Int :=
|
||||||
if 2 * x.toNat < 2^n then
|
if 2 * x.toNat < 2^n then
|
||||||
x.toNat
|
x.toNat
|
||||||
|
|
@ -153,7 +152,6 @@ over- and underflowing as needed.
|
||||||
The underlying `Nat` is `(2^n + (i mod 2^n)) mod 2^n`. Converting the bitvector back to an `Int`
|
The underlying `Nat` is `(2^n + (i mod 2^n)) mod 2^n`. Converting the bitvector back to an `Int`
|
||||||
with `BitVec.toInt` results in the value `i.bmod (2^n)`.
|
with `BitVec.toInt` results in the value `i.bmod (2^n)`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def ofInt (n : Nat) (i : Int) : BitVec n := .ofNatLT (i % (Int.ofNat (2^n))).toNat (by
|
protected def ofInt (n : Nat) (i : Int) : BitVec n := .ofNatLT (i % (Int.ofNat (2^n))).toNat (by
|
||||||
apply (Int.toNat_lt _).mpr
|
apply (Int.toNat_lt _).mpr
|
||||||
· apply Int.emod_lt_of_pos
|
· apply Int.emod_lt_of_pos
|
||||||
|
|
@ -228,14 +226,12 @@ Usually accessed via the `-` prefix operator.
|
||||||
|
|
||||||
SMT-LIB name: `bvneg`.
|
SMT-LIB name: `bvneg`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def neg (x : BitVec n) : BitVec n := .ofNat n (2^n - x.toNat)
|
protected def neg (x : BitVec n) : BitVec n := .ofNat n (2^n - x.toNat)
|
||||||
instance : Neg (BitVec n) := ⟨.neg⟩
|
instance : Neg (BitVec n) := ⟨.neg⟩
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Returns the absolute value of a signed bitvector.
|
Returns the absolute value of a signed bitvector.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def abs (x : BitVec n) : BitVec n := if x.msb then .neg x else x
|
protected def abs (x : BitVec n) : BitVec n := if x.msb then .neg x else x
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -244,7 +240,6 @@ modulo `2^n`. Usually accessed via the `*` operator.
|
||||||
|
|
||||||
SMT-LIB name: `bvmul`.
|
SMT-LIB name: `bvmul`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def mul (x y : BitVec n) : BitVec n := BitVec.ofNat n (x.toNat * y.toNat)
|
protected def mul (x y : BitVec n) : BitVec n := BitVec.ofNat n (x.toNat * y.toNat)
|
||||||
instance : Mul (BitVec n) := ⟨.mul⟩
|
instance : Mul (BitVec n) := ⟨.mul⟩
|
||||||
|
|
||||||
|
|
@ -255,7 +250,6 @@ Note that this is currently an inefficient implementation,
|
||||||
and should be replaced via an `@[extern]` with a native implementation.
|
and should be replaced via an `@[extern]` with a native implementation.
|
||||||
See https://github.com/leanprover/lean4/issues/7887.
|
See https://github.com/leanprover/lean4/issues/7887.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def pow (x : BitVec n) (y : Nat) : BitVec n :=
|
protected def pow (x : BitVec n) (y : Nat) : BitVec n :=
|
||||||
match y with
|
match y with
|
||||||
| 0 => 1
|
| 0 => 1
|
||||||
|
|
@ -267,7 +261,6 @@ instance : Pow (BitVec n) Nat where
|
||||||
Unsigned division of bitvectors using the Lean convention where division by zero returns zero.
|
Unsigned division of bitvectors using the Lean convention where division by zero returns zero.
|
||||||
Usually accessed via the `/` operator.
|
Usually accessed via the `/` operator.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def udiv (x y : BitVec n) : BitVec n :=
|
def udiv (x y : BitVec n) : BitVec n :=
|
||||||
(x.toNat / y.toNat)#'(by exact Nat.lt_of_le_of_lt (Nat.div_le_self _ _) x.isLt)
|
(x.toNat / y.toNat)#'(by exact Nat.lt_of_le_of_lt (Nat.div_le_self _ _) x.isLt)
|
||||||
instance : Div (BitVec n) := ⟨.udiv⟩
|
instance : Div (BitVec n) := ⟨.udiv⟩
|
||||||
|
|
@ -277,7 +270,6 @@ Unsigned modulo for bitvectors. Usually accessed via the `%` operator.
|
||||||
|
|
||||||
SMT-LIB name: `bvurem`.
|
SMT-LIB name: `bvurem`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def umod (x y : BitVec n) : BitVec n :=
|
def umod (x y : BitVec n) : BitVec n :=
|
||||||
(x.toNat % y.toNat)#'(by exact Nat.lt_of_le_of_lt (Nat.mod_le _ _) x.isLt)
|
(x.toNat % y.toNat)#'(by exact Nat.lt_of_le_of_lt (Nat.mod_le _ _) x.isLt)
|
||||||
instance : Mod (BitVec n) := ⟨.umod⟩
|
instance : Mod (BitVec n) := ⟨.umod⟩
|
||||||
|
|
@ -289,7 +281,6 @@ where division by zero returns `BitVector.allOnes n`.
|
||||||
|
|
||||||
SMT-LIB name: `bvudiv`.
|
SMT-LIB name: `bvudiv`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def smtUDiv (x y : BitVec n) : BitVec n := if y = 0 then allOnes n else udiv x y
|
def smtUDiv (x y : BitVec n) : BitVec n := if y = 0 then allOnes n else udiv x y
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -359,7 +350,6 @@ end arithmetic
|
||||||
section bool
|
section bool
|
||||||
|
|
||||||
/-- Turns a `Bool` into a bitvector of length `1`. -/
|
/-- Turns a `Bool` into a bitvector of length `1`. -/
|
||||||
@[expose]
|
|
||||||
def ofBool (b : Bool) : BitVec 1 := cond b 1 0
|
def ofBool (b : Bool) : BitVec 1 := cond b 1 0
|
||||||
|
|
||||||
@[simp, grind =] theorem ofBool_false : ofBool false = 0 := by trivial
|
@[simp, grind =] theorem ofBool_false : ofBool false = 0 := by trivial
|
||||||
|
|
@ -377,7 +367,6 @@ Unsigned less-than for bitvectors.
|
||||||
|
|
||||||
SMT-LIB name: `bvult`.
|
SMT-LIB name: `bvult`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def ult (x y : BitVec n) : Bool := x.toNat < y.toNat
|
protected def ult (x y : BitVec n) : Bool := x.toNat < y.toNat
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -385,7 +374,6 @@ Unsigned less-than-or-equal-to for bitvectors.
|
||||||
|
|
||||||
SMT-LIB name: `bvule`.
|
SMT-LIB name: `bvule`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def ule (x y : BitVec n) : Bool := x.toNat ≤ y.toNat
|
protected def ule (x y : BitVec n) : Bool := x.toNat ≤ y.toNat
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -397,7 +385,6 @@ Examples:
|
||||||
* `BitVec.slt 6#4 7 = true`
|
* `BitVec.slt 6#4 7 = true`
|
||||||
* `BitVec.slt 7#4 8 = false`
|
* `BitVec.slt 7#4 8 = false`
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def slt (x y : BitVec n) : Bool := x.toInt < y.toInt
|
protected def slt (x y : BitVec n) : Bool := x.toInt < y.toInt
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -405,7 +392,6 @@ Signed less-than-or-equal-to for bitvectors.
|
||||||
|
|
||||||
SMT-LIB name: `bvsle`.
|
SMT-LIB name: `bvsle`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def sle (x y : BitVec n) : Bool := x.toInt ≤ y.toInt
|
protected def sle (x y : BitVec n) : Bool := x.toInt ≤ y.toInt
|
||||||
|
|
||||||
end relations
|
end relations
|
||||||
|
|
@ -419,7 +405,7 @@ width `m`.
|
||||||
Using `x.cast eq` should be preferred over `eq ▸ x` because there are special-purpose `simp` lemmas
|
Using `x.cast eq` should be preferred over `eq ▸ x` because there are special-purpose `simp` lemmas
|
||||||
that can more consistently simplify `BitVec.cast` away.
|
that can more consistently simplify `BitVec.cast` away.
|
||||||
-/
|
-/
|
||||||
@[inline, expose] protected def cast (eq : n = m) (x : BitVec n) : BitVec m := .ofNatLT x.toNat (eq ▸ x.isLt)
|
@[inline] protected def cast (eq : n = m) (x : BitVec n) : BitVec m := .ofNatLT x.toNat (eq ▸ x.isLt)
|
||||||
|
|
||||||
@[simp, grind =] theorem cast_ofNat {n m : Nat} (h : n = m) (x : Nat) :
|
@[simp, grind =] theorem cast_ofNat {n m : Nat} (h : n = m) (x : Nat) :
|
||||||
(BitVec.ofNat n x).cast h = BitVec.ofNat m x := by
|
(BitVec.ofNat n x).cast h = BitVec.ofNat m x := by
|
||||||
|
|
@ -435,7 +421,6 @@ that can more consistently simplify `BitVec.cast` away.
|
||||||
Extracts the bits `start` to `start + len - 1` from a bitvector of size `n` to yield a
|
Extracts the bits `start` to `start + len - 1` from a bitvector of size `n` to yield a
|
||||||
new bitvector of size `len`. If `start + len > n`, then the bitvector is zero-extended.
|
new bitvector of size `len`. If `start + len > n`, then the bitvector is zero-extended.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def extractLsb' (start len : Nat) (x : BitVec n) : BitVec len := .ofNat _ (x.toNat >>> start)
|
def extractLsb' (start len : Nat) (x : BitVec n) : BitVec len := .ofNat _ (x.toNat >>> start)
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -446,7 +431,6 @@ The resulting bitvector has size `hi - lo + 1`.
|
||||||
|
|
||||||
SMT-LIB name: `extract`.
|
SMT-LIB name: `extract`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def extractLsb (hi lo : Nat) (x : BitVec n) : BitVec (hi - lo + 1) := extractLsb' lo _ x
|
def extractLsb (hi lo : Nat) (x : BitVec n) : BitVec (hi - lo + 1) := extractLsb' lo _ x
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -455,7 +439,6 @@ Increases the width of a bitvector to one that is at least as large by zero-exte
|
||||||
This is a constant-time operation because the underlying `Nat` is unmodified; because the new width
|
This is a constant-time operation because the underlying `Nat` is unmodified; because the new width
|
||||||
is at least as large as the old one, no overflow is possible.
|
is at least as large as the old one, no overflow is possible.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def setWidth' {n w : Nat} (le : n ≤ w) (x : BitVec n) : BitVec w :=
|
def setWidth' {n w : Nat} (le : n ≤ w) (x : BitVec n) : BitVec w :=
|
||||||
x.toNat#'(by
|
x.toNat#'(by
|
||||||
apply Nat.lt_of_lt_of_le x.isLt
|
apply Nat.lt_of_lt_of_le x.isLt
|
||||||
|
|
@ -464,7 +447,6 @@ def setWidth' {n w : Nat} (le : n ≤ w) (x : BitVec n) : BitVec w :=
|
||||||
/--
|
/--
|
||||||
Returns `zeroExtend (w+n) x <<< n` without needing to compute `x % 2^(2+n)`.
|
Returns `zeroExtend (w+n) x <<< n` without needing to compute `x % 2^(2+n)`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def shiftLeftZeroExtend (msbs : BitVec w) (m : Nat) : BitVec (w + m) :=
|
def shiftLeftZeroExtend (msbs : BitVec w) (m : Nat) : BitVec (w + m) :=
|
||||||
let shiftLeftLt {x : Nat} (p : x < 2^w) (m : Nat) : x <<< m < 2^(w + m) := by
|
let shiftLeftLt {x : Nat} (p : x < 2^w) (m : Nat) : x <<< m < 2^(w + m) := by
|
||||||
simp [Nat.shiftLeft_eq, Nat.pow_add]
|
simp [Nat.shiftLeft_eq, Nat.pow_add]
|
||||||
|
|
@ -521,7 +503,6 @@ SMT-LIB name: `bvand`.
|
||||||
Example:
|
Example:
|
||||||
* `0b1010#4 &&& 0b0110#4 = 0b0010#4`
|
* `0b1010#4 &&& 0b0110#4 = 0b0010#4`
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def and (x y : BitVec n) : BitVec n :=
|
protected def and (x y : BitVec n) : BitVec n :=
|
||||||
(x.toNat &&& y.toNat)#'(by exact Nat.and_lt_two_pow x.toNat y.isLt)
|
(x.toNat &&& y.toNat)#'(by exact Nat.and_lt_two_pow x.toNat y.isLt)
|
||||||
instance : AndOp (BitVec w) := ⟨.and⟩
|
instance : AndOp (BitVec w) := ⟨.and⟩
|
||||||
|
|
@ -534,7 +515,6 @@ SMT-LIB name: `bvor`.
|
||||||
Example:
|
Example:
|
||||||
* `0b1010#4 ||| 0b0110#4 = 0b1110#4`
|
* `0b1010#4 ||| 0b0110#4 = 0b1110#4`
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def or (x y : BitVec n) : BitVec n :=
|
protected def or (x y : BitVec n) : BitVec n :=
|
||||||
(x.toNat ||| y.toNat)#'(by exact Nat.or_lt_two_pow x.isLt y.isLt)
|
(x.toNat ||| y.toNat)#'(by exact Nat.or_lt_two_pow x.isLt y.isLt)
|
||||||
instance : OrOp (BitVec w) := ⟨.or⟩
|
instance : OrOp (BitVec w) := ⟨.or⟩
|
||||||
|
|
@ -547,7 +527,6 @@ SMT-LIB name: `bvxor`.
|
||||||
Example:
|
Example:
|
||||||
* `0b1010#4 ^^^ 0b0110#4 = 0b1100#4`
|
* `0b1010#4 ^^^ 0b0110#4 = 0b1100#4`
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def xor (x y : BitVec n) : BitVec n :=
|
protected def xor (x y : BitVec n) : BitVec n :=
|
||||||
(x.toNat ^^^ y.toNat)#'(by exact Nat.xor_lt_two_pow x.isLt y.isLt)
|
(x.toNat ^^^ y.toNat)#'(by exact Nat.xor_lt_two_pow x.isLt y.isLt)
|
||||||
instance : XorOp (BitVec w) := ⟨.xor⟩
|
instance : XorOp (BitVec w) := ⟨.xor⟩
|
||||||
|
|
@ -560,7 +539,6 @@ SMT-LIB name: `bvnot`.
|
||||||
Example:
|
Example:
|
||||||
* `~~~(0b0101#4) == 0b1010`
|
* `~~~(0b0101#4) == 0b1010`
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def not (x : BitVec n) : BitVec n := allOnes n ^^^ x
|
protected def not (x : BitVec n) : BitVec n := allOnes n ^^^ x
|
||||||
instance : Complement (BitVec w) := ⟨.not⟩
|
instance : Complement (BitVec w) := ⟨.not⟩
|
||||||
|
|
||||||
|
|
@ -570,7 +548,6 @@ equivalent to `x * 2^s`, modulo `2^n`.
|
||||||
|
|
||||||
SMT-LIB name: `bvshl` except this operator uses a `Nat` shift value.
|
SMT-LIB name: `bvshl` except this operator uses a `Nat` shift value.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def shiftLeft (x : BitVec n) (s : Nat) : BitVec n := BitVec.ofNat n (x.toNat <<< s)
|
protected def shiftLeft (x : BitVec n) (s : Nat) : BitVec n := BitVec.ofNat n (x.toNat <<< s)
|
||||||
instance : HShiftLeft (BitVec w) Nat (BitVec w) := ⟨.shiftLeft⟩
|
instance : HShiftLeft (BitVec w) Nat (BitVec w) := ⟨.shiftLeft⟩
|
||||||
|
|
||||||
|
|
@ -582,7 +559,6 @@ As a numeric operation, this is equivalent to `x / 2^s`, rounding down.
|
||||||
|
|
||||||
SMT-LIB name: `bvlshr` except this operator uses a `Nat` shift value.
|
SMT-LIB name: `bvlshr` except this operator uses a `Nat` shift value.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def ushiftRight (x : BitVec n) (s : Nat) : BitVec n :=
|
def ushiftRight (x : BitVec n) (s : Nat) : BitVec n :=
|
||||||
(x.toNat >>> s)#'(by
|
(x.toNat >>> s)#'(by
|
||||||
let ⟨x, lt⟩ := x
|
let ⟨x, lt⟩ := x
|
||||||
|
|
@ -600,7 +576,6 @@ As a numeric operation, this is equivalent to `x.toInt >>> s`.
|
||||||
|
|
||||||
SMT-LIB name: `bvashr` except this operator uses a `Nat` shift value.
|
SMT-LIB name: `bvashr` except this operator uses a `Nat` shift value.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def sshiftRight (x : BitVec n) (s : Nat) : BitVec n := .ofInt n (x.toInt >>> s)
|
def sshiftRight (x : BitVec n) (s : Nat) : BitVec n := .ofInt n (x.toInt >>> s)
|
||||||
|
|
||||||
instance {n} : HShiftLeft (BitVec m) (BitVec n) (BitVec m) := ⟨fun x y => x <<< y.toNat⟩
|
instance {n} : HShiftLeft (BitVec m) (BitVec n) (BitVec m) := ⟨fun x y => x <<< y.toNat⟩
|
||||||
|
|
@ -614,12 +589,10 @@ As a numeric operation, this is equivalent to `a.toInt >>> s.toNat`.
|
||||||
|
|
||||||
SMT-LIB name: `bvashr`.
|
SMT-LIB name: `bvashr`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def sshiftRight' (a : BitVec n) (s : BitVec m) : BitVec n := a.sshiftRight s.toNat
|
def sshiftRight' (a : BitVec n) (s : BitVec m) : BitVec n := a.sshiftRight s.toNat
|
||||||
|
|
||||||
/-- Auxiliary function for `rotateLeft`, which does not take into account the case where
|
/-- Auxiliary function for `rotateLeft`, which does not take into account the case where
|
||||||
the rotation amount is greater than the bitvector width. -/
|
the rotation amount is greater than the bitvector width. -/
|
||||||
@[expose]
|
|
||||||
def rotateLeftAux (x : BitVec w) (n : Nat) : BitVec w :=
|
def rotateLeftAux (x : BitVec w) (n : Nat) : BitVec w :=
|
||||||
x <<< n ||| x >>> (w - n)
|
x <<< n ||| x >>> (w - n)
|
||||||
|
|
||||||
|
|
@ -634,7 +607,6 @@ SMT-LIB name: `rotate_left`, except this operator uses a `Nat` shift amount.
|
||||||
Example:
|
Example:
|
||||||
* `(0b0011#4).rotateLeft 3 = 0b1001`
|
* `(0b0011#4).rotateLeft 3 = 0b1001`
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def rotateLeft (x : BitVec w) (n : Nat) : BitVec w := rotateLeftAux x (n % w)
|
def rotateLeft (x : BitVec w) (n : Nat) : BitVec w := rotateLeftAux x (n % w)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -642,7 +614,6 @@ def rotateLeft (x : BitVec w) (n : Nat) : BitVec w := rotateLeftAux x (n % w)
|
||||||
Auxiliary function for `rotateRight`, which does not take into account the case where
|
Auxiliary function for `rotateRight`, which does not take into account the case where
|
||||||
the rotation amount is greater than the bitvector width.
|
the rotation amount is greater than the bitvector width.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def rotateRightAux (x : BitVec w) (n : Nat) : BitVec w :=
|
def rotateRightAux (x : BitVec w) (n : Nat) : BitVec w :=
|
||||||
x >>> n ||| x <<< (w - n)
|
x >>> n ||| x <<< (w - n)
|
||||||
|
|
||||||
|
|
@ -657,7 +628,6 @@ SMT-LIB name: `rotate_right`, except this operator uses a `Nat` shift amount.
|
||||||
Example:
|
Example:
|
||||||
* `rotateRight 0b01001#5 1 = 0b10100`
|
* `rotateRight 0b01001#5 1 = 0b10100`
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def rotateRight (x : BitVec w) (n : Nat) : BitVec w := rotateRightAux x (n % w)
|
def rotateRight (x : BitVec w) (n : Nat) : BitVec w := rotateRightAux x (n % w)
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -669,7 +639,6 @@ SMT-LIB name: `concat`.
|
||||||
Example:
|
Example:
|
||||||
* `0xAB#8 ++ 0xCD#8 = 0xABCD#16`.
|
* `0xAB#8 ++ 0xCD#8 = 0xABCD#16`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def append (msbs : BitVec n) (lsbs : BitVec m) : BitVec (n+m) :=
|
def append (msbs : BitVec n) (lsbs : BitVec m) : BitVec (n+m) :=
|
||||||
shiftLeftZeroExtend msbs m ||| setWidth' (Nat.le_add_left m n) lsbs
|
shiftLeftZeroExtend msbs m ||| setWidth' (Nat.le_add_left m n) lsbs
|
||||||
|
|
||||||
|
|
@ -692,7 +661,6 @@ result of appending a single bit to the front in the naive implementation).
|
||||||
|
|
||||||
/-- Append a single bit to the end of a bitvector, using big endian order (see `append`).
|
/-- Append a single bit to the end of a bitvector, using big endian order (see `append`).
|
||||||
That is, the new bit is the least significant bit. -/
|
That is, the new bit is the least significant bit. -/
|
||||||
@[expose]
|
|
||||||
def concat {n} (msbs : BitVec n) (lsb : Bool) : BitVec (n+1) := msbs ++ (ofBool lsb)
|
def concat {n} (msbs : BitVec n) (lsb : Bool) : BitVec (n+1) := msbs ++ (ofBool lsb)
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -700,7 +668,6 @@ Shifts all bits of `x` to the left by `1` and sets the least significant bit to
|
||||||
|
|
||||||
This is a non-dependent version of `BitVec.concat` that does not change the total bitwidth.
|
This is a non-dependent version of `BitVec.concat` that does not change the total bitwidth.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def shiftConcat (x : BitVec n) (b : Bool) : BitVec n :=
|
def shiftConcat (x : BitVec n) (b : Bool) : BitVec n :=
|
||||||
(x.concat b).truncate n
|
(x.concat b).truncate n
|
||||||
|
|
||||||
|
|
@ -709,7 +676,6 @@ Prepends a single bit to the front of a bitvector, using big-endian order (see `
|
||||||
|
|
||||||
The new bit is the most significant bit.
|
The new bit is the most significant bit.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def cons {n} (msb : Bool) (lsbs : BitVec n) : BitVec (n+1) :=
|
def cons {n} (msb : Bool) (lsbs : BitVec n) : BitVec (n+1) :=
|
||||||
((ofBool msb) ++ lsbs).cast (Nat.add_comm ..)
|
((ofBool msb) ++ lsbs).cast (Nat.add_comm ..)
|
||||||
|
|
||||||
|
|
@ -734,10 +700,10 @@ def twoPow (w : Nat) (i : Nat) : BitVec w := 1#w <<< i
|
||||||
end bitwise
|
end bitwise
|
||||||
|
|
||||||
/-- The bitvector of width `w` that has the smallest value when interpreted as an integer. -/
|
/-- The bitvector of width `w` that has the smallest value when interpreted as an integer. -/
|
||||||
@[expose] def intMin (w : Nat) := twoPow w (w - 1)
|
def intMin (w : Nat) := twoPow w (w - 1)
|
||||||
|
|
||||||
/-- The bitvector of width `w` that has the largest value when interpreted as an integer. -/
|
/-- The bitvector of width `w` that has the largest value when interpreted as an integer. -/
|
||||||
@[expose] def intMax (w : Nat) := (twoPow w (w - 1)) - 1
|
def intMax (w : Nat) := (twoPow w (w - 1)) - 1
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Computes a hash of a bitvector, combining 64-bit words using `mixHash`.
|
Computes a hash of a bitvector, combining 64-bit words using `mixHash`.
|
||||||
|
|
@ -802,7 +768,6 @@ Checks whether subtraction of `x` and `y` results in *unsigned* overflow.
|
||||||
|
|
||||||
SMT-Lib name: `bvusubo`.
|
SMT-Lib name: `bvusubo`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def usubOverflow {w : Nat} (x y : BitVec w) : Bool := x.toNat < y.toNat
|
def usubOverflow {w : Nat} (x y : BitVec w) : Bool := x.toNat < y.toNat
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -811,7 +776,6 @@ Checks whether the subtraction of `x` and `y` results in *signed* overflow, trea
|
||||||
|
|
||||||
SMT-Lib name: `bvssubo`.
|
SMT-Lib name: `bvssubo`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def ssubOverflow {w : Nat} (x y : BitVec w) : Bool :=
|
def ssubOverflow {w : Nat} (x y : BitVec w) : Bool :=
|
||||||
(x.toInt - y.toInt ≥ 2 ^ (w - 1)) || (x.toInt - y.toInt < - 2 ^ (w - 1))
|
(x.toInt - y.toInt ≥ 2 ^ (w - 1)) || (x.toInt - y.toInt < - 2 ^ (w - 1))
|
||||||
|
|
||||||
|
|
@ -822,7 +786,6 @@ For a bitvector `x` with nonzero width, this only happens if `x = intMin`.
|
||||||
|
|
||||||
SMT-Lib name: `bvnego`.
|
SMT-Lib name: `bvnego`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def negOverflow {w : Nat} (x : BitVec w) : Bool :=
|
def negOverflow {w : Nat} (x : BitVec w) : Bool :=
|
||||||
x.toInt == - 2 ^ (w - 1)
|
x.toInt == - 2 ^ (w - 1)
|
||||||
|
|
||||||
|
|
@ -832,7 +795,6 @@ For BitVecs `x` and `y` with nonzero width, this only happens if `x = intMin` an
|
||||||
|
|
||||||
SMT-LIB name: `bvsdivo`.
|
SMT-LIB name: `bvsdivo`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
def sdivOverflow {w : Nat} (x y : BitVec w) : Bool :=
|
def sdivOverflow {w : Nat} (x y : BitVec w) : Bool :=
|
||||||
(2 ^ (w - 1) ≤ x.toInt / y.toInt) || (x.toInt / y.toInt < - 2 ^ (w - 1))
|
(2 ^ (w - 1) ≤ x.toInt / y.toInt) || (x.toInt / y.toInt < - 2 ^ (w - 1))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@ namespace Char
|
||||||
/--
|
/--
|
||||||
One character is less than another if its code point is strictly less than the other's.
|
One character is less than another if its code point is strictly less than the other's.
|
||||||
-/
|
-/
|
||||||
@[expose] protected def lt (a b : Char) : Prop := a.val < b.val
|
protected def lt (a b : Char) : Prop := a.val < b.val
|
||||||
|
|
||||||
/--
|
/--
|
||||||
One character is less than or equal to another if its code point is less than or equal to the
|
One character is less than or equal to another if its code point is less than or equal to the
|
||||||
other's.
|
other's.
|
||||||
-/
|
-/
|
||||||
@[expose] protected def le (a b : Char) : Prop := a.val ≤ b.val
|
protected def le (a b : Char) : Prop := a.val ≤ b.val
|
||||||
|
|
||||||
instance : LT Char := ⟨Char.lt⟩
|
instance : LT Char := ⟨Char.lt⟩
|
||||||
instance : LE Char := ⟨Char.le⟩
|
instance : LE Char := ⟨Char.le⟩
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ Returns `a` modulo `n` as a `Fin n`.
|
||||||
|
|
||||||
The assumption `NeZero n` ensures that `Fin n` is nonempty.
|
The assumption `NeZero n` ensures that `Fin n` is nonempty.
|
||||||
-/
|
-/
|
||||||
@[expose] protected def ofNat (n : Nat) [NeZero n] (a : Nat) : Fin n :=
|
protected def ofNat (n : Nat) [NeZero n] (a : Nat) : Fin n :=
|
||||||
⟨a % n, Nat.mod_lt _ (pos_of_neZero n)⟩
|
⟨a % n, Nat.mod_lt _ (pos_of_neZero n)⟩
|
||||||
|
|
||||||
@[simp]
|
@[simp]
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ For example, for `x : Fin k` and `n : Nat`,
|
||||||
it causes `x < n` to be elaborated as `x < ↑n` rather than `↑x < n`,
|
it causes `x < n` to be elaborated as `x < ↑n` rather than `↑x < n`,
|
||||||
silently introducing wraparound arithmetic.
|
silently introducing wraparound arithmetic.
|
||||||
-/
|
-/
|
||||||
@[expose, implicit_reducible]
|
@[implicit_reducible]
|
||||||
def instNatCast (n : Nat) [NeZero n] : NatCast (Fin n) where
|
def instNatCast (n : Nat) [NeZero n] : NatCast (Fin n) where
|
||||||
natCast a := Fin.ofNat n a
|
natCast a := Fin.ofNat n a
|
||||||
|
|
||||||
|
|
@ -131,7 +131,6 @@ attribute [scoped instance] instNatCast
|
||||||
|
|
||||||
end NatCast
|
end NatCast
|
||||||
|
|
||||||
@[expose]
|
|
||||||
def intCast [NeZero n] (a : Int) : Fin n :=
|
def intCast [NeZero n] (a : Int) : Fin n :=
|
||||||
if 0 ≤ a then
|
if 0 ≤ a then
|
||||||
Fin.ofNat n a.natAbs
|
Fin.ofNat n a.natAbs
|
||||||
|
|
@ -145,7 +144,7 @@ This is not a global instance, but may be activated locally via `open Fin.IntCas
|
||||||
|
|
||||||
See the doc-string for `Fin.NatCast.instNatCast` for more details.
|
See the doc-string for `Fin.NatCast.instNatCast` for more details.
|
||||||
-/
|
-/
|
||||||
@[expose, implicit_reducible]
|
@[implicit_reducible]
|
||||||
def instIntCast (n : Nat) [NeZero n] : IntCast (Fin n) where
|
def instIntCast (n : Nat) [NeZero n] : IntCast (Fin n) where
|
||||||
intCast := Fin.intCast
|
intCast := Fin.intCast
|
||||||
|
|
||||||
|
|
@ -909,7 +908,7 @@ parameter, `Fin.cases` is the corresponding case analysis operator, and `Fin.rev
|
||||||
version that starts at the greatest value instead of `0`.
|
version that starts at the greatest value instead of `0`.
|
||||||
-/
|
-/
|
||||||
-- FIXME: Performance review
|
-- FIXME: Performance review
|
||||||
@[elab_as_elim, expose] def induction {motive : Fin (n + 1) → Sort _} (zero : motive 0)
|
@[elab_as_elim] def induction {motive : Fin (n + 1) → Sort _} (zero : motive 0)
|
||||||
(succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) :
|
(succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) :
|
||||||
∀ i : Fin (n + 1), motive i
|
∀ i : Fin (n + 1), motive i
|
||||||
| ⟨i, hi⟩ => go i hi
|
| ⟨i, hi⟩ => go i hi
|
||||||
|
|
@ -951,7 +950,7 @@ The two cases are:
|
||||||
|
|
||||||
The corresponding induction principle is `Fin.induction`.
|
The corresponding induction principle is `Fin.induction`.
|
||||||
-/
|
-/
|
||||||
@[elab_as_elim, expose] def cases {motive : Fin (n + 1) → Sort _}
|
@[elab_as_elim] def cases {motive : Fin (n + 1) → Sort _}
|
||||||
(zero : motive 0) (succ : ∀ i : Fin n, motive i.succ) :
|
(zero : motive 0) (succ : ∀ i : Fin n, motive i.succ) :
|
||||||
∀ i : Fin (n + 1), motive i := induction zero fun i _ => succ i
|
∀ i : Fin (n + 1), motive i := induction zero fun i _ => succ i
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ Examples:
|
||||||
* `(0 : Int).natAbs = 0`
|
* `(0 : Int).natAbs = 0`
|
||||||
* `(-11 : Int).natAbs = 11`
|
* `(-11 : Int).natAbs = 11`
|
||||||
-/
|
-/
|
||||||
@[extern "lean_nat_abs", expose]
|
@[extern "lean_nat_abs"]
|
||||||
def natAbs (m : @& Int) : Nat :=
|
def natAbs (m : @& Int) : Nat :=
|
||||||
match m with
|
match m with
|
||||||
| ofNat m => m
|
| ofNat m => m
|
||||||
|
|
@ -413,20 +413,20 @@ instance : Min Int := minOfLe
|
||||||
instance : Max Int := maxOfLe
|
instance : Max Int := maxOfLe
|
||||||
|
|
||||||
/-- Equality predicate for kernel reduction. -/
|
/-- Equality predicate for kernel reduction. -/
|
||||||
@[expose] protected noncomputable def beq' (a b : Int) : Bool :=
|
protected noncomputable def beq' (a b : Int) : Bool :=
|
||||||
Int.rec
|
Int.rec
|
||||||
(fun a => Int.rec (fun b => Nat.beq a b) (fun _ => false) b)
|
(fun a => Int.rec (fun b => Nat.beq a b) (fun _ => false) b)
|
||||||
(fun a => Int.rec (fun _ => false) (fun b => Nat.beq a b) b) a
|
(fun a => Int.rec (fun _ => false) (fun b => Nat.beq a b) b) a
|
||||||
|
|
||||||
/-- `x ≤ y` for kernel reduction. -/
|
/-- `x ≤ y` for kernel reduction. -/
|
||||||
@[expose] protected noncomputable def ble' (a b : Int) : Bool :=
|
protected noncomputable def ble' (a b : Int) : Bool :=
|
||||||
Int.rec
|
Int.rec
|
||||||
(fun a => Int.rec (fun b => Nat.ble a b) (fun _ => false) b)
|
(fun a => Int.rec (fun b => Nat.ble a b) (fun _ => false) b)
|
||||||
(fun a => Int.rec (fun _ => true) (fun b => Nat.ble b a) b)
|
(fun a => Int.rec (fun _ => true) (fun b => Nat.ble b a) b)
|
||||||
a
|
a
|
||||||
|
|
||||||
/-- `x < y` for kernel reduction. -/
|
/-- `x < y` for kernel reduction. -/
|
||||||
@[expose] protected noncomputable def blt' (a b : Int) : Bool :=
|
protected noncomputable def blt' (a b : Int) : Bool :=
|
||||||
Int.rec
|
Int.rec
|
||||||
(fun a => Int.rec (fun b => Nat.blt a b) (fun _ => false) b)
|
(fun a => Int.rec (fun b => Nat.blt a b) (fun _ => false) b)
|
||||||
(fun a => Int.rec (fun _ => true) (fun b => Nat.blt b a) b)
|
(fun a => Int.rec (fun _ => true) (fun b => Nat.blt b a) b)
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ def Poly.combine' (fuel : Nat) (p₁ p₂ : Poly) : Poly :=
|
||||||
else
|
else
|
||||||
.add a₂ x₂ (combine' fuel (.add a₁ x₁ p₁) p₂)
|
.add a₂ x₂ (combine' fuel (.add a₁ x₁ p₁) p₂)
|
||||||
|
|
||||||
@[expose] abbrev hugeFuel := 100000000
|
abbrev hugeFuel := 100000000
|
||||||
|
|
||||||
@[expose]
|
@[expose]
|
||||||
def Poly.combine (p₁ p₂ : Poly) : Poly :=
|
def Poly.combine (p₁ p₂ : Poly) : Poly :=
|
||||||
|
|
|
||||||
|
|
@ -314,7 +314,6 @@ of another state. Having this proof bundled up with the step is important for te
|
||||||
|
|
||||||
See `IterM.Step` and `Iter.Step` for the concrete choice of the plausibility predicate.
|
See `IterM.Step` and `Iter.Step` for the concrete choice of the plausibility predicate.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
abbrev PlausibleIterStep (IsPlausibleStep : IterStep α β → Prop) := Subtype IsPlausibleStep
|
abbrev PlausibleIterStep (IsPlausibleStep : IterStep α β → Prop) := Subtype IsPlausibleStep
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -384,7 +383,7 @@ attribute [reducible] Iterator.IsPlausibleStep
|
||||||
section Monadic
|
section Monadic
|
||||||
|
|
||||||
/-- The constructor has been renamed. -/
|
/-- The constructor has been renamed. -/
|
||||||
@[deprecated IterM.mk (since := "2025-01-19"), inline, expose]
|
@[deprecated IterM.mk (since := "2025-01-19"), inline]
|
||||||
abbrev IterM.mk' {α : Type w} {m : Type w → Type w'} {β : Type w} (it : α) : IterM (α := α) m β :=
|
abbrev IterM.mk' {α : Type w} {m : Type w → Type w'} {β : Type w} (it : α) : IterM (α := α) m β :=
|
||||||
⟨it⟩
|
⟨it⟩
|
||||||
|
|
||||||
|
|
@ -434,7 +433,6 @@ abbrev IterM.IsPlausibleStep {α : Type w} {m : Type w → Type w'} {β : Type w
|
||||||
The type of the step object returned by `IterM.step`, containing an `IterStep`
|
The type of the step object returned by `IterM.step`, containing an `IterStep`
|
||||||
and a proof that this is a plausible step for the given iterator.
|
and a proof that this is a plausible step for the given iterator.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
abbrev IterM.Step {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β]
|
abbrev IterM.Step {α : Type w} {m : Type w → Type w'} {β : Type w} [Iterator α m β]
|
||||||
(it : IterM (α := α) m β) :=
|
(it : IterM (α := α) m β) :=
|
||||||
PlausibleIterStep it.IsPlausibleStep
|
PlausibleIterStep it.IsPlausibleStep
|
||||||
|
|
@ -493,7 +491,6 @@ section Pure
|
||||||
Asserts that certain step is plausibly the successor of a given iterator. What "plausible" means
|
Asserts that certain step is plausibly the successor of a given iterator. What "plausible" means
|
||||||
is up to the `Iterator` instance but it should be strong enough to allow termination proofs.
|
is up to the `Iterator` instance but it should be strong enough to allow termination proofs.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
abbrev Iter.IsPlausibleStep {α : Type w} {β : Type w} [Iterator α Id β]
|
abbrev Iter.IsPlausibleStep {α : Type w} {β : Type w} [Iterator α Id β]
|
||||||
(it : Iter (α := α) β) (step : IterStep (Iter (α := α) β) β) : Prop :=
|
(it : Iter (α := α) β) (step : IterStep (Iter (α := α) β) β) : Prop :=
|
||||||
it.toIterM.IsPlausibleStep (step.mapIterator Iter.toIterM)
|
it.toIterM.IsPlausibleStep (step.mapIterator Iter.toIterM)
|
||||||
|
|
@ -549,7 +546,6 @@ theorem IterM.IsPlausibleIndirectOutput.trans {α β : Type w} {m : Type w → T
|
||||||
The type of the step object returned by `Iter.step`, containing an `IterStep`
|
The type of the step object returned by `Iter.step`, containing an `IterStep`
|
||||||
and a proof that this is a plausible step for the given iterator.
|
and a proof that this is a plausible step for the given iterator.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
abbrev Iter.Step {α : Type w} {β : Type w} [Iterator α Id β] (it : Iter (α := α) β) :=
|
abbrev Iter.Step {α : Type w} {β : Type w} [Iterator α Id β] (it : Iter (α := α) β) :=
|
||||||
PlausibleIterStep (Iter.IsPlausibleStep it)
|
PlausibleIterStep (Iter.IsPlausibleStep it)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,6 @@ def Append.instFinitenessRelation [Monad m] [Iterator α₁ m β] [Iterator α
|
||||||
apply Append.rel_of_snd
|
apply Append.rel_of_snd
|
||||||
exact IterM.TerminationMeasures.Finite.rel_of_skip ‹_›
|
exact IterM.TerminationMeasures.Finite.rel_of_skip ‹_›
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Append.instFinite [Monad m] [Iterator α₁ m β] [Iterator α₂ m β]
|
instance Append.instFinite [Monad m] [Iterator α₁ m β] [Iterator α₂ m β]
|
||||||
[Finite α₁ m] [Finite α₂ m] : Finite (Append α₁ α₂ m β) m :=
|
[Finite α₁ m] [Finite α₂ m] : Finite (Append α₁ α₂ m β) m :=
|
||||||
.of_finitenessRelation instFinitenessRelation
|
.of_finitenessRelation instFinitenessRelation
|
||||||
|
|
|
||||||
|
|
@ -196,13 +196,11 @@ private def FilterMap.instFinitenessRelation {α β γ : Type w} {m : Type w →
|
||||||
case done h' =>
|
case done h' =>
|
||||||
cases h
|
cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance FilterMap.instFinite {α β γ : Type w} {m : Type w → Type w'}
|
instance FilterMap.instFinite {α β γ : Type w} {m : Type w → Type w'}
|
||||||
{n : Type w → Type w''} [Monad n] [Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α}
|
{n : Type w → Type w''} [Monad n] [Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α}
|
||||||
{f : β → PostconditionT n (Option γ)} [Finite α m] : Finite (FilterMap α m n lift f) n :=
|
{f : β → PostconditionT n (Option γ)} [Finite α m] : Finite (FilterMap α m n lift f) n :=
|
||||||
Finite.of_finitenessRelation FilterMap.instFinitenessRelation
|
Finite.of_finitenessRelation FilterMap.instFinitenessRelation
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Map.instFinite {α β γ : Type w} {m : Type w → Type w'} {n : Type w → Type w''} [Monad n]
|
instance Map.instFinite {α β γ : Type w} {m : Type w → Type w'} {n : Type w → Type w''} [Monad n]
|
||||||
[Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α} {f : β → PostconditionT n γ} [Finite α m] :
|
[Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α} {f : β → PostconditionT n γ} [Finite α m] :
|
||||||
Finite (Map α m n lift f) n :=
|
Finite (Map α m n lift f) n :=
|
||||||
|
|
@ -221,7 +219,6 @@ private def Map.instProductivenessRelation {α β γ : Type w} {m : Type w → T
|
||||||
case skip it' h =>
|
case skip it' h =>
|
||||||
exact h
|
exact h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Map.instProductive {α β γ : Type w} {m : Type w → Type w'}
|
instance Map.instProductive {α β γ : Type w} {m : Type w → Type w'}
|
||||||
{n : Type w → Type w''} [Monad n] [Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α}
|
{n : Type w → Type w''} [Monad n] [Iterator α m β] {lift : ⦃α : Type w⦄ → m α → n α}
|
||||||
{f : β → PostconditionT n γ} [Productive α m] :
|
{f : β → PostconditionT n γ} [Productive α m] :
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,6 @@ def Flatten.instFinitenessRelation [Monad m] [Iterator α m (IterM (α := α₂)
|
||||||
case innerDone =>
|
case innerDone =>
|
||||||
apply Flatten.rel_of_right₂
|
apply Flatten.rel_of_right₂
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
public instance Flatten.instFinite [Monad m] [Iterator α m (IterM (α := α₂) m β)] [Iterator α₂ m β]
|
public instance Flatten.instFinite [Monad m] [Iterator α m (IterM (α := α₂) m β)] [Iterator α₂ m β]
|
||||||
[Finite α m] [Finite α₂ m] : Finite (Flatten α α₂ β m) m :=
|
[Finite α m] [Finite α₂ m] : Finite (Flatten α α₂ β m) m :=
|
||||||
.of_finitenessRelation instFinitenessRelation
|
.of_finitenessRelation instFinitenessRelation
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ instance {n : Type max u v → Type v'} [Monad n] : Monad.{u} (ULiftT n) where
|
||||||
pure a := pure (f := n) (ULift.up a)
|
pure a := pure (f := n) (ULift.up a)
|
||||||
bind x f := bind (m := n) (x : n _) fun a => f a.down
|
bind x f := bind (m := n) (x : n _) fun a => f a.down
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance {n : Type max u v → Type v'} [Monad n] [LawfulMonad n] : LawfulMonad.{u} (ULiftT n) where
|
instance {n : Type max u v → Type v'} [Monad n] [LawfulMonad n] : LawfulMonad.{u} (ULiftT n) where
|
||||||
map_const := by simp [Functor.mapConst, Functor.map]
|
map_const := by simp [Functor.mapConst, Functor.map]
|
||||||
id_map := by simp [Functor.map]
|
id_map := by simp [Functor.map]
|
||||||
|
|
|
||||||
|
|
@ -572,7 +572,7 @@ Examples:
|
||||||
* `[1, 2, 3, 4].reverse = [4, 3, 2, 1]`
|
* `[1, 2, 3, 4].reverse = [4, 3, 2, 1]`
|
||||||
* `[].reverse = []`
|
* `[].reverse = []`
|
||||||
-/
|
-/
|
||||||
@[expose] def reverse (as : List α) : List α :=
|
def reverse (as : List α) : List α :=
|
||||||
reverseAux as []
|
reverseAux as []
|
||||||
|
|
||||||
@[simp, grind =] theorem reverse_nil : reverse ([] : List α) = [] := rfl
|
@[simp, grind =] theorem reverse_nil : reverse ([] : List α) = [] := rfl
|
||||||
|
|
@ -681,7 +681,7 @@ Examples:
|
||||||
* `List.singleton "green" = ["green"]`.
|
* `List.singleton "green" = ["green"]`.
|
||||||
* `List.singleton [1, 2, 3] = [[1, 2, 3]]`
|
* `List.singleton [1, 2, 3] = [[1, 2, 3]]`
|
||||||
-/
|
-/
|
||||||
@[inline, expose] protected def singleton {α : Type u} (a : α) : List α := [a]
|
@[inline] protected def singleton {α : Type u} (a : α) : List α := [a]
|
||||||
|
|
||||||
/-! ### flatMap -/
|
/-! ### flatMap -/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,6 @@ instance [LT α] [Std.Asymm (· < · : α → α → Prop)] :
|
||||||
Std.Total (· ≤ · : List α → List α → Prop) where
|
Std.Total (· ≤ · : List α → List α → Prop) where
|
||||||
total := List.le_total
|
total := List.le_total
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance instIsLinearOrder [LT α] [LE α] [IsLinearOrder α] [LawfulOrderLT α] :
|
instance instIsLinearOrder [LT α] [LE α] [IsLinearOrder α] [LawfulOrderLT α] :
|
||||||
IsLinearOrder (List α) := IsLinearOrder.of_le
|
IsLinearOrder (List α) := IsLinearOrder.of_le
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -656,19 +656,19 @@ namespace Ord
|
||||||
/--
|
/--
|
||||||
Constructs a `BEq` instance from an `Ord` instance.
|
Constructs a `BEq` instance from an `Ord` instance.
|
||||||
-/
|
-/
|
||||||
@[expose] protected abbrev toBEq (ord : Ord α) : BEq α :=
|
protected abbrev toBEq (ord : Ord α) : BEq α :=
|
||||||
beqOfOrd
|
beqOfOrd
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Constructs an `LT` instance from an `Ord` instance.
|
Constructs an `LT` instance from an `Ord` instance.
|
||||||
-/
|
-/
|
||||||
@[expose] protected abbrev toLT (ord : Ord α) : LT α :=
|
protected abbrev toLT (ord : Ord α) : LT α :=
|
||||||
ltOfOrd
|
ltOfOrd
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Constructs an `LE` instance from an `Ord` instance.
|
Constructs an `LE` instance from an `Ord` instance.
|
||||||
-/
|
-/
|
||||||
@[expose] protected abbrev toLE (ord : Ord α) : LE α :=
|
protected abbrev toLE (ord : Ord α) : LE α :=
|
||||||
leOfOrd
|
leOfOrd
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -694,7 +694,7 @@ The function `compareOn` can be used to perform this comparison without construc
|
||||||
/--
|
/--
|
||||||
Constructs the lexicographic order on products `α × β` from orders for `α` and `β`.
|
Constructs the lexicographic order on products `α × β` from orders for `α` and `β`.
|
||||||
-/
|
-/
|
||||||
@[expose] protected abbrev lex (_ : Ord α) (_ : Ord β) : Ord (α × β) :=
|
protected abbrev lex (_ : Ord α) (_ : Ord β) : Ord (α × β) :=
|
||||||
lexOrd
|
lexOrd
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ def Internal.iter [UpwardEnumerable α] (r : Rcc α) : Iter (α := Rxc.Iterator
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given closed range as a list in ascending order.
|
Returns the elements of the given closed range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toList [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxc.IsAlwaysFinite α] (r : Rcc α) : List α :=
|
[Rxc.IsAlwaysFinite α] (r : Rcc α) : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -46,7 +46,7 @@ def toList [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerabl
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given closed range as an array in ascending order.
|
Returns the elements of the given closed range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toArray [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxc.IsAlwaysFinite α] (r : Rcc α) : Array α :=
|
[Rxc.IsAlwaysFinite α] (r : Rcc α) : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -124,7 +124,7 @@ def Internal.iter [UpwardEnumerable α] (r : Rco α) : Iter (α := Rxo.Iterator
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-closed right-open range as a list in ascending order.
|
Returns the elements of the given left-closed right-open range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toList [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxo.IsAlwaysFinite α] (r : Rco α) : List α :=
|
[Rxo.IsAlwaysFinite α] (r : Rco α) : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -132,7 +132,7 @@ def toList [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerabl
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-closed right-open range as an array in ascending order.
|
Returns the elements of the given left-closed right-open range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toArray [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxo.IsAlwaysFinite α] (r : Rco α) : Array α :=
|
[Rxo.IsAlwaysFinite α] (r : Rco α) : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -210,7 +210,7 @@ def Internal.iter [UpwardEnumerable α] (r : Rci α) : Iter (α := Rxi.Iterator
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-closed right-unbounded range as a list in ascending order.
|
Returns the elements of the given left-closed right-unbounded range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] (r : Rci α) :
|
def toList [UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] (r : Rci α) :
|
||||||
List α :=
|
List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -218,7 +218,7 @@ def toList [UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-closed right-unbounded range as an array in ascending order.
|
Returns the elements of the given left-closed right-unbounded range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] (r : Rci α) :
|
def toArray [UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] (r : Rci α) :
|
||||||
Array α :=
|
Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -295,7 +295,7 @@ def Internal.iter [UpwardEnumerable α] (r : Roc α) : Iter (α := Rxc.Iterator
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-open right-closed range as a list in ascending order.
|
Returns the elements of the given left-open right-closed range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toList [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxc.IsAlwaysFinite α] (r : Roc α) : List α :=
|
[Rxc.IsAlwaysFinite α] (r : Roc α) : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -303,7 +303,7 @@ def toList [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerabl
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-open right-closed range as an array in ascending order.
|
Returns the elements of the given left-open right-closed range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toArray [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxc.IsAlwaysFinite α] (r : Roc α) : Array α :=
|
[Rxc.IsAlwaysFinite α] (r : Roc α) : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -376,7 +376,7 @@ def Internal.iter [UpwardEnumerable α] (r : Roo α) : Iter (α := Rxo.Iterator
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given open range as a list in ascending order.
|
Returns the elements of the given open range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toList [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxo.IsAlwaysFinite α] (r : Roo α) : List α :=
|
[Rxo.IsAlwaysFinite α] (r : Roo α) : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -384,7 +384,7 @@ def toList [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerabl
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given open range as an array in ascending order.
|
Returns the elements of the given open range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toArray [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxo.IsAlwaysFinite α] (r : Roo α) : Array α :=
|
[Rxo.IsAlwaysFinite α] (r : Roo α) : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -456,7 +456,7 @@ def Internal.iter [UpwardEnumerable α] (r : Roi α) : Iter (α := Rxi.Iterator
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-open right-unbounded range as a list in ascending order.
|
Returns the elements of the given left-open right-unbounded range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList[UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α]
|
def toList[UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α]
|
||||||
(r : Roi α) : List α :=
|
(r : Roi α) : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -464,7 +464,7 @@ def toList[UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given left-open right-unbounded range as an array in ascending order.
|
Returns the elements of the given left-open right-unbounded range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α]
|
def toArray [UpwardEnumerable α] [LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α]
|
||||||
(r : Roi α) : Array α :=
|
(r : Roi α) : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -532,7 +532,7 @@ def Internal.iter [Least? α] (r : Ric α) : Iter (α := Rxc.Iterator α) α :=
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given closed range as a list in ascending order.
|
Returns the elements of the given closed range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [Least? α] [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toList [Least? α] [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxc.IsAlwaysFinite α] (r : Ric α) : List α :=
|
[Rxc.IsAlwaysFinite α] (r : Ric α) : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -540,7 +540,7 @@ def toList [Least? α] [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpw
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given closed range as an array in ascending order.
|
Returns the elements of the given closed range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [Least? α] [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toArray [Least? α] [LE α] [DecidableLE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxc.IsAlwaysFinite α] (r : Ric α) : Array α :=
|
[Rxc.IsAlwaysFinite α] (r : Ric α) : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -607,7 +607,7 @@ def Internal.iter [UpwardEnumerable α] [Least? α] (r : Rio α) : Iter (α := R
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given closed range as a list in ascending order.
|
Returns the elements of the given closed range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [Least? α] [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toList [Least? α] [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxo.IsAlwaysFinite α] (r : Rio α) : List α :=
|
[Rxo.IsAlwaysFinite α] (r : Rio α) : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -615,7 +615,7 @@ def toList [Least? α] [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpw
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given closed range as an array in ascending order.
|
Returns the elements of the given closed range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray [Least? α] [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
def toArray [Least? α] [LT α] [DecidableLT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α]
|
||||||
[Rxo.IsAlwaysFinite α] (r : Rio α) : Array α :=
|
[Rxo.IsAlwaysFinite α] (r : Rio α) : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
@ -681,7 +681,7 @@ def Internal.iter [UpwardEnumerable α] [Least? α] (_ : Rii α) : Iter (α := R
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given full range as a list in ascending order.
|
Returns the elements of the given full range as a list in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toList [UpwardEnumerable α] [Least? α] (r : Rii α)
|
def toList [UpwardEnumerable α] [Least? α] (r : Rii α)
|
||||||
[Iterator (Rxi.Iterator α) Id α] [Finite (Rxi.Iterator α) Id] : List α :=
|
[Iterator (Rxi.Iterator α) Id α] [Finite (Rxi.Iterator α) Id] : List α :=
|
||||||
Internal.iter r |>.toList
|
Internal.iter r |>.toList
|
||||||
|
|
@ -689,7 +689,7 @@ def toList [UpwardEnumerable α] [Least? α] (r : Rii α)
|
||||||
/--
|
/--
|
||||||
Returns the elements of the given full range as an array in ascending order.
|
Returns the elements of the given full range as an array in ascending order.
|
||||||
-/
|
-/
|
||||||
@[always_inline, inline, expose]
|
@[always_inline, inline]
|
||||||
def toArray {α} [UpwardEnumerable α] [Least? α] (r : Rii α)
|
def toArray {α} [UpwardEnumerable α] [Least? α] (r : Rii α)
|
||||||
[Iterator (Rxi.Iterator α) Id α] [Finite (Rxi.Iterator α) Id] : Array α :=
|
[Iterator (Rxi.Iterator α) Id α] [Finite (Rxi.Iterator α) Id] : Array α :=
|
||||||
Internal.iter r |>.toArray
|
Internal.iter r |>.toArray
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,6 @@ private def Iterator.instFinitenessRelation [UpwardEnumerable α] [LE α] [Decid
|
||||||
· cases h
|
· cases h
|
||||||
subrelation := id
|
subrelation := id
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Iterator.instFinite [UpwardEnumerable α] [LE α] [DecidableLE α]
|
instance Iterator.instFinite [UpwardEnumerable α] [LE α] [DecidableLE α]
|
||||||
[LawfulUpwardEnumerable α] [Rxc.IsAlwaysFinite α] :
|
[LawfulUpwardEnumerable α] [Rxc.IsAlwaysFinite α] :
|
||||||
Finite (Rxc.Iterator α) Id :=
|
Finite (Rxc.Iterator α) Id :=
|
||||||
|
|
@ -300,7 +299,6 @@ private def Iterator.instProductivenessRelation [UpwardEnumerable α] [LE α] [D
|
||||||
· cases h
|
· cases h
|
||||||
· cases h
|
· cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Iterator.instProductive [UpwardEnumerable α] [LE α] [DecidableLE α]
|
instance Iterator.instProductive [UpwardEnumerable α] [LE α] [DecidableLE α]
|
||||||
[LawfulUpwardEnumerable α] :
|
[LawfulUpwardEnumerable α] :
|
||||||
Productive (Rxc.Iterator α) Id :=
|
Productive (Rxc.Iterator α) Id :=
|
||||||
|
|
@ -861,7 +859,6 @@ private def Iterator.instFinitenessRelation [UpwardEnumerable α] [LT α] [Decid
|
||||||
· cases h
|
· cases h
|
||||||
subrelation := id
|
subrelation := id
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Iterator.instFinite [UpwardEnumerable α] [LT α] [DecidableLT α]
|
instance Iterator.instFinite [UpwardEnumerable α] [LT α] [DecidableLT α]
|
||||||
[LawfulUpwardEnumerable α] [Rxo.IsAlwaysFinite α] :
|
[LawfulUpwardEnumerable α] [Rxo.IsAlwaysFinite α] :
|
||||||
Finite (Rxo.Iterator α) Id :=
|
Finite (Rxo.Iterator α) Id :=
|
||||||
|
|
@ -882,7 +879,6 @@ private def Iterator.instProductivenessRelation [UpwardEnumerable α] [LT α] [D
|
||||||
· cases h
|
· cases h
|
||||||
· cases h
|
· cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Iterator.instProductive [UpwardEnumerable α] [LT α] [DecidableLT α]
|
instance Iterator.instProductive [UpwardEnumerable α] [LT α] [DecidableLT α]
|
||||||
[LawfulUpwardEnumerable α] :
|
[LawfulUpwardEnumerable α] :
|
||||||
Productive (Rxo.Iterator α) Id :=
|
Productive (Rxo.Iterator α) Id :=
|
||||||
|
|
@ -1374,7 +1370,6 @@ private def Iterator.instFinitenessRelation [UpwardEnumerable α]
|
||||||
exact ih
|
exact ih
|
||||||
subrelation := id
|
subrelation := id
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Iterator.instFinite [UpwardEnumerable α]
|
instance Iterator.instFinite [UpwardEnumerable α]
|
||||||
[LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] :
|
[LawfulUpwardEnumerable α] [Rxi.IsAlwaysFinite α] :
|
||||||
Finite (Rxi.Iterator α) Id :=
|
Finite (Rxi.Iterator α) Id :=
|
||||||
|
|
@ -1391,7 +1386,6 @@ private def Iterator.instProductivenessRelation [UpwardEnumerable α]
|
||||||
Iterator.IsPlausibleStep, Monadic.step, instIteratorIteratorIdOfUpwardEnumerable] at h -- TODO
|
Iterator.IsPlausibleStep, Monadic.step, instIteratorIteratorIdOfUpwardEnumerable] at h -- TODO
|
||||||
split at h <;> cases h
|
split at h <;> cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance Iterator.instProductive [UpwardEnumerable α]
|
instance Iterator.instProductive [UpwardEnumerable α]
|
||||||
[LawfulUpwardEnumerable α] :
|
[LawfulUpwardEnumerable α] :
|
||||||
Productive (Rxi.Iterator α) Id :=
|
Productive (Rxi.Iterator α) Id :=
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,6 @@ private def finitenessRelation [Pure m] :
|
||||||
· cases h'
|
· cases h'
|
||||||
· cases h
|
· cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance [Pure m] : Std.Iterators.Finite (PosIterator s) m :=
|
instance [Pure m] : Std.Iterators.Finite (PosIterator s) m :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
||||||
|
|
@ -170,7 +169,6 @@ private def finitenessRelation [Pure m] :
|
||||||
· cases h'
|
· cases h'
|
||||||
· cases h
|
· cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance [Pure m] : Std.Iterators.Finite (RevPosIterator s) m :=
|
instance [Pure m] : Std.Iterators.Finite (RevPosIterator s) m :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
||||||
|
|
@ -247,7 +245,6 @@ private def finitenessRelation [Pure m] :
|
||||||
· cases h'
|
· cases h'
|
||||||
· cases h
|
· cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance [Pure m] : Std.Iterators.Finite ByteIterator m :=
|
instance [Pure m] : Std.Iterators.Finite ByteIterator m :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
||||||
|
|
@ -325,7 +322,6 @@ private def finitenessRelation [Pure m] :
|
||||||
· cases h'
|
· cases h'
|
||||||
· cases h
|
· cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance [Pure m] : Std.Iterators.Finite RevByteIterator m :=
|
instance [Pure m] : Std.Iterators.Finite RevByteIterator m :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,6 @@ private def finitenessRelation :
|
||||||
| .atEnd .. => simp
|
| .atEnd .. => simp
|
||||||
· cases h
|
· cases h
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance : Std.Iterators.Finite (ForwardSliceSearcher s) Id :=
|
instance : Std.Iterators.Finite (ForwardSliceSearcher s) Id :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ At runtime, this function is implemented by efficient, constant-time code.
|
||||||
def getUTF8Byte (s : @& String) (p : Pos.Raw) (h : p < s.rawEndPos) : UInt8 :=
|
def getUTF8Byte (s : @& String) (p : Pos.Raw) (h : p < s.rawEndPos) : UInt8 :=
|
||||||
s.toByteArray[p.byteIdx]
|
s.toByteArray[p.byteIdx]
|
||||||
|
|
||||||
@[deprecated getUTF8Byte (since := "2025-10-01"), extern "lean_string_get_byte_fast", expose]
|
@[deprecated getUTF8Byte (since := "2025-10-01"), extern "lean_string_get_byte_fast"]
|
||||||
abbrev getUtf8Byte (s : String) (p : Pos.Raw) (h : p < s.rawEndPos) : UInt8 :=
|
abbrev getUtf8Byte (s : String) (p : Pos.Raw) (h : p < s.rawEndPos) : UInt8 :=
|
||||||
s.getUTF8Byte p h
|
s.getUTF8Byte p h
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,6 @@ private def finitenessRelation [Std.Iterators.Finite (σ s) Id] :
|
||||||
| ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [SplitIterator.toOption, Option.lt]
|
| ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [SplitIterator.toOption, Option.lt]
|
||||||
| ⟨.atEnd⟩, _ => simp
|
| ⟨.atEnd⟩, _ => simp
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance [Std.Iterators.Finite (σ s) Id] : Std.Iterators.Finite (SplitIterator pat s) Id :=
|
instance [Std.Iterators.Finite (σ s) Id] : Std.Iterators.Finite (SplitIterator pat s) Id :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
||||||
|
|
@ -301,7 +300,6 @@ private def finitenessRelation [Std.Iterators.Finite (σ s) Id] :
|
||||||
| ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [SplitInclusiveIterator.toOption, Option.lt]
|
| ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [SplitInclusiveIterator.toOption, Option.lt]
|
||||||
| ⟨.atEnd⟩, _ => simp
|
| ⟨.atEnd⟩, _ => simp
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance [Std.Iterators.Finite (σ s) Id] :
|
instance [Std.Iterators.Finite (σ s) Id] :
|
||||||
Std.Iterators.Finite (SplitInclusiveIterator pat s) Id :=
|
Std.Iterators.Finite (SplitInclusiveIterator pat s) Id :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
@ -661,7 +659,6 @@ private def finitenessRelation [Std.Iterators.Finite (σ s) Id] :
|
||||||
| ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [RevSplitIterator.toOption, Option.lt]
|
| ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [RevSplitIterator.toOption, Option.lt]
|
||||||
| ⟨.atEnd⟩, _ => simp
|
| ⟨.atEnd⟩, _ => simp
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
instance [Std.Iterators.Finite (σ s) Id] : Std.Iterators.Finite (RevSplitIterator ρ s) Id :=
|
instance [Std.Iterators.Finite (σ s) Id] : Std.Iterators.Finite (RevSplitIterator ρ s) Id :=
|
||||||
.of_finitenessRelation finitenessRelation
|
.of_finitenessRelation finitenessRelation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -502,12 +502,12 @@ natural numbers. Usually accessed via the `<` operator.
|
||||||
-/
|
-/
|
||||||
-- These need to be exposed as `Init.Prelude` already has an instance for bootstrapping purposes and
|
-- These need to be exposed as `Init.Prelude` already has an instance for bootstrapping purposes and
|
||||||
-- they should be defeq
|
-- they should be defeq
|
||||||
@[expose] protected def UInt32.lt (a b : UInt32) : Prop := a.toBitVec < b.toBitVec
|
protected def UInt32.lt (a b : UInt32) : Prop := a.toBitVec < b.toBitVec
|
||||||
/--
|
/--
|
||||||
Non-strict inequality of 32-bit unsigned integers, defined as inequality of the corresponding
|
Non-strict inequality of 32-bit unsigned integers, defined as inequality of the corresponding
|
||||||
natural numbers. Usually accessed via the `≤` operator.
|
natural numbers. Usually accessed via the `≤` operator.
|
||||||
-/
|
-/
|
||||||
@[expose] protected def UInt32.le (a b : UInt32) : Prop := a.toBitVec ≤ b.toBitVec
|
protected def UInt32.le (a b : UInt32) : Prop := a.toBitVec ≤ b.toBitVec
|
||||||
|
|
||||||
instance : Mul UInt32 := ⟨UInt32.mul⟩
|
instance : Mul UInt32 := ⟨UInt32.mul⟩
|
||||||
instance : Pow UInt32 Nat := ⟨UInt32.pow⟩
|
instance : Pow UInt32 Nat := ⟨UInt32.pow⟩
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ inductive IntInterval : Type where
|
||||||
namespace IntInterval
|
namespace IntInterval
|
||||||
|
|
||||||
/-- The interval `[0, 2^n)`. -/
|
/-- The interval `[0, 2^n)`. -/
|
||||||
@[expose] abbrev uint (n : Nat) := IntInterval.co 0 (2 ^ n)
|
abbrev uint (n : Nat) := IntInterval.co 0 (2 ^ n)
|
||||||
/-- The interval `[-2^(n-1), 2^(n-1))`. -/
|
/-- The interval `[-2^(n-1), 2^(n-1))`. -/
|
||||||
@[expose] abbrev sint (n : Nat) := IntInterval.co (-(2 ^ (n - 1))) (2 ^ (n - 1))
|
abbrev sint (n : Nat) := IntInterval.co (-(2 ^ (n - 1))) (2 ^ (n - 1))
|
||||||
|
|
||||||
/-- The lower bound of the interval, if finite. -/
|
/-- The lower bound of the interval, if finite. -/
|
||||||
@[expose] def lo? (i : IntInterval) : Option Int :=
|
@[expose] def lo? (i : IntInterval) : Option Int :=
|
||||||
|
|
|
||||||
|
|
@ -2346,7 +2346,7 @@ Returns `a` modulo `n` as a `Fin n`.
|
||||||
|
|
||||||
This function exists for bootstrapping purposes. Use `Fin.ofNat` instead.
|
This function exists for bootstrapping purposes. Use `Fin.ofNat` instead.
|
||||||
-/
|
-/
|
||||||
@[expose] protected def Fin.Internal.ofNat (n : Nat) (hn : LT.lt 0 n) (a : Nat) : Fin n :=
|
protected def Fin.Internal.ofNat (n : Nat) (hn : LT.lt 0 n) (a : Nat) : Fin n :=
|
||||||
⟨HMod.hMod a n, Nat.mod_lt _ hn⟩
|
⟨HMod.hMod a n, Nat.mod_lt _ hn⟩
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -2388,7 +2388,7 @@ protected def BitVec.ofNatLT {w : Nat} (i : Nat) (p : LT.lt i (hPow 2 w)) : BitV
|
||||||
/--
|
/--
|
||||||
The bitvector with value `i mod 2^n`.
|
The bitvector with value `i mod 2^n`.
|
||||||
-/
|
-/
|
||||||
@[expose, match_pattern]
|
@[match_pattern]
|
||||||
protected def BitVec.ofNat (n : Nat) (i : Nat) : BitVec n where
|
protected def BitVec.ofNat (n : Nat) (i : Nat) : BitVec n where
|
||||||
toFin := Fin.Internal.ofNat (HPow.hPow 2 n) (Nat.pow_pos (Nat.zero_lt_succ _)) i
|
toFin := Fin.Internal.ofNat (HPow.hPow 2 n) (Nat.pow_pos (Nat.zero_lt_succ _)) i
|
||||||
|
|
||||||
|
|
@ -2397,7 +2397,6 @@ Return the underlying `Nat` that represents a bitvector.
|
||||||
|
|
||||||
This is O(1) because `BitVec` is a (zero-cost) wrapper around a `Nat`.
|
This is O(1) because `BitVec` is a (zero-cost) wrapper around a `Nat`.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
protected def BitVec.toNat (x : BitVec w) : Nat := x.toFin.val
|
protected def BitVec.toNat (x : BitVec w) : Nat := x.toFin.val
|
||||||
|
|
||||||
instance : LT (BitVec w) where lt := (LT.lt ·.toNat ·.toNat)
|
instance : LT (BitVec w) where lt := (LT.lt ·.toNat ·.toNat)
|
||||||
|
|
@ -2924,7 +2923,7 @@ Examples:
|
||||||
* `(some "hello").getD "goodbye" = "hello"`
|
* `(some "hello").getD "goodbye" = "hello"`
|
||||||
* `none.getD "goodbye" = "goodbye"`
|
* `none.getD "goodbye" = "goodbye"`
|
||||||
-/
|
-/
|
||||||
@[macro_inline, expose] def Option.getD (opt : Option α) (dflt : α) : α :=
|
@[macro_inline] def Option.getD (opt : Option α) (dflt : α) : α :=
|
||||||
match opt with
|
match opt with
|
||||||
| some x => x
|
| some x => x
|
||||||
| none => dflt
|
| none => dflt
|
||||||
|
|
@ -3215,7 +3214,7 @@ def Array.mkEmpty {α : Type u} (c : @& Nat) : Array α where
|
||||||
/--
|
/--
|
||||||
Constructs a new empty array with initial capacity `c`.
|
Constructs a new empty array with initial capacity `c`.
|
||||||
-/
|
-/
|
||||||
@[extern "lean_mk_empty_array_with_capacity", expose]
|
@[extern "lean_mk_empty_array_with_capacity"]
|
||||||
def Array.emptyWithCapacity {α : Type u} (c : @& Nat) : Array α where
|
def Array.emptyWithCapacity {α : Type u} (c : @& Nat) : Array α where
|
||||||
toList := List.nil
|
toList := List.nil
|
||||||
|
|
||||||
|
|
@ -3224,7 +3223,7 @@ Constructs a new empty array with initial capacity `0`.
|
||||||
|
|
||||||
Use `Array.emptyWithCapacity` to create an array with a greater initial capacity.
|
Use `Array.emptyWithCapacity` to create an array with a greater initial capacity.
|
||||||
-/
|
-/
|
||||||
@[expose, inline]
|
@[inline]
|
||||||
def Array.empty {α : Type u} : Array α := emptyWithCapacity 0
|
def Array.empty {α : Type u} : Array α := emptyWithCapacity 0
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
@ -3303,7 +3302,7 @@ Examples:
|
||||||
* `#[].push "apple" = #["apple"]`
|
* `#[].push "apple" = #["apple"]`
|
||||||
* `#["apple"].push "orange" = #["apple", "orange"]`
|
* `#["apple"].push "orange" = #["apple", "orange"]`
|
||||||
-/
|
-/
|
||||||
@[extern "lean_array_push", expose]
|
@[extern "lean_array_push"]
|
||||||
def Array.push {α : Type u} (a : Array α) (v : α) : Array α where
|
def Array.push {α : Type u} (a : Array α) (v : α) : Array α where
|
||||||
toList := List.concat a.toList v
|
toList := List.concat a.toList v
|
||||||
|
|
||||||
|
|
@ -3593,7 +3592,7 @@ instance : Inhabited Substring.Raw where
|
||||||
/--
|
/--
|
||||||
The number of bytes used by the string's UTF-8 encoding.
|
The number of bytes used by the string's UTF-8 encoding.
|
||||||
-/
|
-/
|
||||||
@[inline, expose] def Substring.Raw.bsize : Substring.Raw → Nat
|
@[inline] def Substring.Raw.bsize : Substring.Raw → Nat
|
||||||
| ⟨_, b, e⟩ => e.byteIdx.sub b.byteIdx
|
| ⟨_, b, e⟩ => e.byteIdx.sub b.byteIdx
|
||||||
|
|
||||||
/--
|
/--
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,6 @@ abbrev flag (default : Bool) : Type := Bool
|
||||||
Gadget that indicates that a function's parameter should be treated as a repeated (and thus
|
Gadget that indicates that a function's parameter should be treated as a repeated (and thus
|
||||||
optional) named argument when used in a docstring extension.
|
optional) named argument when used in a docstring extension.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
abbrev many (α : Type u) : Type u := Array α
|
abbrev many (α : Type u) : Type u := Array α
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1184,6 +1184,11 @@ register_builtin_option warn.exposeOnPrivate : Bool := {
|
||||||
descr := "warn about uses of `@[expose]` on private declarations"
|
descr := "warn about uses of `@[expose]` on private declarations"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
register_builtin_option warn.redundantExpose : Bool := {
|
||||||
|
defValue := true
|
||||||
|
descr := "warn about redundant `@[expose]`/`@[no_expose]` attributes"
|
||||||
|
}
|
||||||
|
|
||||||
def elabMutualDef (vars : Array Expr) (sc : Command.Scope) (views : Array DefView) : TermElabM Unit :=
|
def elabMutualDef (vars : Array Expr) (sc : Command.Scope) (views : Array DefView) : TermElabM Unit :=
|
||||||
if isExample views then
|
if isExample views then
|
||||||
withoutModifyingEnv do
|
withoutModifyingEnv do
|
||||||
|
|
@ -1328,35 +1333,49 @@ where
|
||||||
applyAttributesAt declId.declName view.modifiers.attrs .afterCompilation
|
applyAttributesAt declId.declName view.modifiers.attrs .afterCompilation
|
||||||
finishElab headers := withFunLocalDecls headers fun funFVars => do
|
finishElab headers := withFunLocalDecls headers fun funFVars => do
|
||||||
let env ← getEnv
|
let env ← getEnv
|
||||||
if warn.exposeOnPrivate.get (← getOptions) then
|
let inExposeSection := sc.attrs.any (· matches `(attrInstance| expose))
|
||||||
if env.header.isModule && !env.isExporting then
|
-- Determine whether each header would be exposed without any explicit `@[expose]`/`@[no_expose]`
|
||||||
for header in headers do
|
let wouldBeExposed ← headers.mapM fun header => do
|
||||||
for attr in header.modifiers.attrs do
|
if header.kind == .abbrev then return true
|
||||||
if attr.name == `expose then
|
if header.kind == .instance then
|
||||||
logWarningAt attr.stx m!"Redundant `[expose]` attribute, it is meaningful on public \
|
if !(← isProp header.type) then return true
|
||||||
definitions only"
|
if header.kind == .def && (!header.modifiers.isMeta || sc.isMeta) && inExposeSection then return true
|
||||||
|
return false
|
||||||
|
let hasExpose (header : DefViewElabHeader) := header.modifiers.attrs.any (·.name == `expose)
|
||||||
|
let hasNoExpose (header : DefViewElabHeader) := header.modifiers.attrs.any (·.name == `no_expose)
|
||||||
|
|
||||||
|
let opts ← getOptions
|
||||||
|
let warnExposeOnPrivate := warn.exposeOnPrivate.get opts
|
||||||
|
let warnRedundantExpose := warn.redundantExpose.get opts
|
||||||
|
for header in headers, exposed in wouldBeExposed do
|
||||||
|
for attr in header.modifiers.attrs do
|
||||||
|
-- skip macro-generated attributes
|
||||||
|
unless attr.stx.getHeadInfo matches .original .. do continue
|
||||||
|
match attr.name with
|
||||||
|
| `expose =>
|
||||||
|
if warnExposeOnPrivate && env.header.isModule && !env.isExporting then
|
||||||
|
logWarningAt attr.stx m!"Redundant `[expose]` attribute, it is meaningful on public \
|
||||||
|
definitions only"
|
||||||
|
if warnRedundantExpose then
|
||||||
|
if !env.header.isModule then
|
||||||
|
logWarningAt attr.stx m!"`@[expose]` has no effect outside a `module` file"
|
||||||
|
else if env.isExporting && exposed then
|
||||||
|
logWarningAt attr.stx m!"`@[expose]` has no effect; this declaration would be exposed by default"
|
||||||
|
| `no_expose =>
|
||||||
|
if warnRedundantExpose then
|
||||||
|
if !env.header.isModule then
|
||||||
|
logWarningAt attr.stx m!"`@[no_expose]` has no effect outside a `module` file"
|
||||||
|
else if env.isExporting && !exposed && !hasExpose header then
|
||||||
|
logWarningAt attr.stx m!"`@[no_expose]` has no effect; this declaration would not \
|
||||||
|
be exposed by default"
|
||||||
|
| _ => pure ()
|
||||||
|
|
||||||
-- Switch to private scope if...
|
|
||||||
withoutExporting (when :=
|
withoutExporting (when :=
|
||||||
(← headers.allM (fun header => do
|
(← (headers.zip wouldBeExposed).allM (fun (header, exposed) => do
|
||||||
-- ... there is a `@[no_expose]` attribute
|
if hasNoExpose header then return true
|
||||||
if header.modifiers.attrs.any (·.name == `no_expose) then
|
if exposed || hasExpose header then return false
|
||||||
return true
|
|
||||||
-- ... or NONE of the following:
|
|
||||||
-- ... this is a non-`meta` `def` inside a `@[expose] section`
|
|
||||||
if header.kind == .def && (!header.modifiers.isMeta || sc.isMeta) && sc.attrs.any (· matches `(attrInstance| expose)) then
|
|
||||||
return false
|
|
||||||
-- ... there is an `@[expose]` attribute directly on the def (of any kind or phase)
|
|
||||||
if header.modifiers.attrs.any (·.name == `expose) then
|
|
||||||
return false
|
|
||||||
-- ... this is an `abbrev`
|
|
||||||
if header.kind == .abbrev then
|
|
||||||
return false
|
|
||||||
-- ... this is a data instance
|
|
||||||
if header.kind == .instance then
|
|
||||||
if !(← isProp header.type) then
|
|
||||||
return false
|
|
||||||
return true))) do
|
return true))) do
|
||||||
|
|
||||||
-- Never export private decls from theorem bodies to make sure they stay irrelevant for rebuilds
|
-- Never export private decls from theorem bodies to make sure they stay irrelevant for rebuilds
|
||||||
withOptions (fun opts =>
|
withOptions (fun opts =>
|
||||||
if headers.any (·.kind.isTheorem) then ResolveName.backward.privateInPublic.set opts false else opts) do
|
if headers.any (·.kind.isTheorem) then ResolveName.backward.privateInPublic.set opts false else opts) do
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,6 @@ def Zipper.FinitenessRelation : FinitenessRelation (Zipper α β) Id where
|
||||||
simp only [h2, ← h'.1, Zipper.size_prependMap, Zipper.size, Nat.add_lt_add_iff_right,
|
simp only [h2, ← h'.1, Zipper.size_prependMap, Zipper.size, Nat.add_lt_add_iff_right,
|
||||||
Nat.lt_add_left_iff_pos, Nat.lt_add_one]
|
Nat.lt_add_left_iff_pos, Nat.lt_add_one]
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
public instance Zipper.instFinite : Finite (Zipper α β) Id :=
|
public instance Zipper.instFinite : Finite (Zipper α β) Id :=
|
||||||
.of_finitenessRelation Zipper.FinitenessRelation
|
.of_finitenessRelation Zipper.FinitenessRelation
|
||||||
|
|
||||||
|
|
@ -477,7 +476,6 @@ def RxcIterator.FinitenessRelation [Ord α] : FinitenessRelation (RxcIterator α
|
||||||
simp only [h2, ← h'.1, Zipper.size_prependMap, Zipper.size, Nat.add_lt_add_iff_right,
|
simp only [h2, ← h'.1, Zipper.size_prependMap, Zipper.size, Nat.add_lt_add_iff_right,
|
||||||
Nat.lt_add_left_iff_pos, Nat.lt_add_one]
|
Nat.lt_add_left_iff_pos, Nat.lt_add_one]
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
public instance instFinite [Ord α] : Finite (RxcIterator α β) Id :=
|
public instance instFinite [Ord α] : Finite (RxcIterator α β) Id :=
|
||||||
.of_finitenessRelation RxcIterator.FinitenessRelation
|
.of_finitenessRelation RxcIterator.FinitenessRelation
|
||||||
|
|
||||||
|
|
@ -606,7 +604,6 @@ def RxoIterator.instFinitenessRelation [Ord α] : FinitenessRelation (RxoIterato
|
||||||
simp only [h2, ← h'.1, Zipper.size_prependMap, Zipper.size, Nat.add_lt_add_iff_right,
|
simp only [h2, ← h'.1, Zipper.size_prependMap, Zipper.size, Nat.add_lt_add_iff_right,
|
||||||
Nat.lt_add_left_iff_pos, Nat.lt_add_one]
|
Nat.lt_add_left_iff_pos, Nat.lt_add_one]
|
||||||
|
|
||||||
@[no_expose]
|
|
||||||
public instance Rxo.instFinite [Ord α] : Finite (RxoIterator α β) Id :=
|
public instance Rxo.instFinite [Ord α] : Finite (RxoIterator α β) Id :=
|
||||||
.of_finitenessRelation RxoIterator.instFinitenessRelation
|
.of_finitenessRelation RxoIterator.instFinitenessRelation
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ attribute [-simp] HetT.mk.injEq
|
||||||
/--
|
/--
|
||||||
Converts `PostconditionT m α` to `HetT m α`, preserving the postcondition property.
|
Converts `PostconditionT m α` to `HetT m α`, preserving the postcondition property.
|
||||||
-/
|
-/
|
||||||
@[expose] noncomputable def HetT.ofPostconditionT [Monad m] (x : PostconditionT m α) : HetT m α :=
|
noncomputable def HetT.ofPostconditionT [Monad m] (x : PostconditionT m α) : HetT m α :=
|
||||||
⟨x.Property, inferInstance, USquash.deflate <$> x.operation⟩
|
⟨x.Property, inferInstance, USquash.deflate <$> x.operation⟩
|
||||||
|
|
||||||
noncomputable instance (m : Type w → Type w') [Monad m] : MonadLift m (HetT m) where
|
noncomputable instance (m : Type w → Type w') [Monad m] : MonadLift m (HetT m) where
|
||||||
|
|
@ -198,7 +198,7 @@ Lifts `x : m α` into `HetT m α` with the trivial postcondition.
|
||||||
|
|
||||||
Caution: This is not a lawful monad lifting function
|
Caution: This is not a lawful monad lifting function
|
||||||
-/
|
-/
|
||||||
@[expose] noncomputable def HetT.lift {α : Type w} {m : Type w → Type w'} [Monad m] (x : m α) :
|
noncomputable def HetT.lift {α : Type w} {m : Type w → Type w'} [Monad m] (x : m α) :
|
||||||
HetT m α :=
|
HetT m α :=
|
||||||
x
|
x
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ protected noncomputable def HetT.map {m : Type w → Type w'} [Functor m] {α :
|
||||||
/--
|
/--
|
||||||
A generalization of `HetT.bind` that provides the postcondition property to the mapping function.
|
A generalization of `HetT.bind` that provides the postcondition property to the mapping function.
|
||||||
-/
|
-/
|
||||||
@[expose] protected noncomputable def HetT.pbind {m : Type w → Type w'} [Monad m] {α : Type u} {β : Type v}
|
protected noncomputable def HetT.pbind {m : Type w → Type w'} [Monad m] {α : Type u} {β : Type v}
|
||||||
(x : HetT m α) (f : (a : α) → x.Property a → HetT m β) : HetT m β :=
|
(x : HetT m α) (f : (a : α) → x.Property a → HetT m β) : HetT m β :=
|
||||||
have := x.small
|
have := x.small
|
||||||
have := fun a h => (f a h).small
|
have := fun a h => (f a h).small
|
||||||
|
|
@ -290,7 +290,7 @@ theorem HetT.prun_ofPostconditionT [Monad m] [LawfulMonad m] {x : PostconditionT
|
||||||
/--
|
/--
|
||||||
If the monad `m` is liftable to `n`, lifts `HetT m α` to `HetT n α`.
|
If the monad `m` is liftable to `n`, lifts `HetT m α` to `HetT n α`.
|
||||||
-/
|
-/
|
||||||
@[expose] noncomputable def HetT.liftInner {m : Type w → Type w'} (n : Type w → Type w'') [MonadLiftT m n]
|
noncomputable def HetT.liftInner {m : Type w → Type w'} (n : Type w → Type w'') [MonadLiftT m n]
|
||||||
(x : HetT m α) : HetT n α :=
|
(x : HetT m α) : HetT n α :=
|
||||||
⟨x.Property, x.small, x.operation⟩
|
⟨x.Property, x.small, x.operation⟩
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,28 +29,28 @@ set_option linter.all true
|
||||||
/--
|
/--
|
||||||
Checks if a character is ASCII (Unicode code point < 128).
|
Checks if a character is ASCII (Unicode code point < 128).
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isAscii (c : Char) : Bool :=
|
def isAscii (c : Char) : Bool :=
|
||||||
c.toNat < 128
|
c.toNat < 128
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Checks if a byte represents an ASCII character (value < 128).
|
Checks if a byte represents an ASCII character (value < 128).
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isAsciiByte (c : UInt8) : Bool :=
|
def isAsciiByte (c : UInt8) : Bool :=
|
||||||
c < 128
|
c < 128
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Checks if a byte is a decimal digit (0-9).
|
Checks if a byte is a decimal digit (0-9).
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isDigitByte (c : UInt8) : Bool :=
|
def isDigitByte (c : UInt8) : Bool :=
|
||||||
c >= '0'.toUInt8 && c <= '9'.toUInt8
|
c >= '0'.toUInt8 && c <= '9'.toUInt8
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Checks if a byte is an alphabetic character (a-z or A-Z).
|
Checks if a byte is an alphabetic character (a-z or A-Z).
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isAlphaByte (c : UInt8) : Bool :=
|
def isAlphaByte (c : UInt8) : Bool :=
|
||||||
(c >= 'A'.toUInt8 && c <= 'Z'.toUInt8) || (c >= 'a'.toUInt8 && c <= 'z'.toUInt8)
|
(c >= 'A'.toUInt8 && c <= 'Z'.toUInt8) || (c >= 'a'.toUInt8 && c <= 'z'.toUInt8)
|
||||||
|
|
||||||
|
|
@ -196,7 +196,7 @@ def reasonPhraseChar (c : Char) : Bool :=
|
||||||
/--
|
/--
|
||||||
Checks if a character is a hexadecimal digit (0-9, a-f, or A-F).
|
Checks if a character is a hexadecimal digit (0-9, a-f, or A-F).
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isHexDigit (c : Char) : Bool :=
|
def isHexDigit (c : Char) : Bool :=
|
||||||
(c matches 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F') ||
|
(c matches 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F') ||
|
||||||
Char.isDigit c
|
Char.isDigit c
|
||||||
|
|
@ -204,7 +204,7 @@ def isHexDigit (c : Char) : Bool :=
|
||||||
/--
|
/--
|
||||||
Checks if a byte is a hexadecimal digit (0-9, a-f, or A-F).
|
Checks if a byte is a hexadecimal digit (0-9, a-f, or A-F).
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isHexDigitByte (c : UInt8) : Bool :=
|
def isHexDigitByte (c : UInt8) : Bool :=
|
||||||
(c ≥ '0'.toUInt8 && c ≤ '9'.toUInt8) ||
|
(c ≥ '0'.toUInt8 && c ≤ '9'.toUInt8) ||
|
||||||
(c ≥ 'a'.toUInt8 && c ≤ 'f'.toUInt8) ||
|
(c ≥ 'a'.toUInt8 && c ≤ 'f'.toUInt8) ||
|
||||||
|
|
@ -213,7 +213,7 @@ def isHexDigitByte (c : UInt8) : Bool :=
|
||||||
/--
|
/--
|
||||||
Checks if a byte is an alphanumeric digit (0-9, a-z, or A-Z).
|
Checks if a byte is an alphanumeric digit (0-9, a-z, or A-Z).
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isAlphaNum (c : UInt8) : Bool :=
|
def isAlphaNum (c : UInt8) : Bool :=
|
||||||
(c ≥ '0'.toUInt8 && c ≤ '9'.toUInt8) ||
|
(c ≥ '0'.toUInt8 && c ≤ '9'.toUInt8) ||
|
||||||
(c ≥ 'a'.toUInt8 && c ≤ 'z'.toUInt8) ||
|
(c ≥ 'a'.toUInt8 && c ≤ 'z'.toUInt8) ||
|
||||||
|
|
@ -222,7 +222,7 @@ def isAlphaNum (c : UInt8) : Bool :=
|
||||||
/--
|
/--
|
||||||
Checks whether `c` is an ASCII alphanumeric character.
|
Checks whether `c` is an ASCII alphanumeric character.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isAsciiAlphaNumChar (c : Char) : Bool :=
|
def isAsciiAlphaNumChar (c : Char) : Bool :=
|
||||||
isAscii c && (Char.isDigit c || Char.isAlpha c)
|
isAscii c && (Char.isDigit c || Char.isAlpha c)
|
||||||
|
|
||||||
|
|
@ -230,7 +230,7 @@ def isAsciiAlphaNumChar (c : Char) : Bool :=
|
||||||
Checks if a character is valid after the first character of a URI scheme.
|
Checks if a character is valid after the first character of a URI scheme.
|
||||||
Valid characters are ASCII alphanumeric, `+`, `-`, and `.`.
|
Valid characters are ASCII alphanumeric, `+`, `-`, and `.`.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isValidSchemeChar (c : Char) : Bool :=
|
def isValidSchemeChar (c : Char) : Bool :=
|
||||||
isAsciiAlphaNumChar c || (c matches '+' | '-' | '.')
|
isAsciiAlphaNumChar c || (c matches '+' | '-' | '.')
|
||||||
|
|
||||||
|
|
@ -238,7 +238,7 @@ def isValidSchemeChar (c : Char) : Bool :=
|
||||||
Checks if a character is valid for use in a domain name.
|
Checks if a character is valid for use in a domain name.
|
||||||
Valid characters are ASCII alphanumeric, hyphens, and dots.
|
Valid characters are ASCII alphanumeric, hyphens, and dots.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isValidDomainNameChar (c : Char) : Bool :=
|
def isValidDomainNameChar (c : Char) : Bool :=
|
||||||
isAsciiAlphaNumChar c || (c matches '-' | '.')
|
isAsciiAlphaNumChar c || (c matches '-' | '.')
|
||||||
|
|
||||||
|
|
@ -246,7 +246,7 @@ def isValidDomainNameChar (c : Char) : Bool :=
|
||||||
Checks if a byte is an unreserved character according to RFC 3986. Unreserved characters are:
|
Checks if a byte is an unreserved character according to RFC 3986. Unreserved characters are:
|
||||||
alphanumeric, hyphen, period, underscore, and tilde.
|
alphanumeric, hyphen, period, underscore, and tilde.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isUnreserved (c : UInt8) : Bool :=
|
def isUnreserved (c : UInt8) : Bool :=
|
||||||
isAlphaNum c ||
|
isAlphaNum c ||
|
||||||
(c = '-'.toUInt8 || c = '.'.toUInt8 || c = '_'.toUInt8 || c = '~'.toUInt8)
|
(c = '-'.toUInt8 || c = '.'.toUInt8 || c = '_'.toUInt8 || c = '~'.toUInt8)
|
||||||
|
|
@ -255,7 +255,7 @@ def isUnreserved (c : UInt8) : Bool :=
|
||||||
Checks if a byte is a sub-delimiter character according to RFC 3986.
|
Checks if a byte is a sub-delimiter character according to RFC 3986.
|
||||||
Sub-delimiters are: `!`, `$`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `;`, `=`.
|
Sub-delimiters are: `!`, `$`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `;`, `=`.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isSubDelims (c : UInt8) : Bool :=
|
def isSubDelims (c : UInt8) : Bool :=
|
||||||
c = '!'.toUInt8 || c = '$'.toUInt8 || c = '&'.toUInt8 || c = ('\'' : Char).toUInt8 ||
|
c = '!'.toUInt8 || c = '$'.toUInt8 || c = '&'.toUInt8 || c = ('\'' : Char).toUInt8 ||
|
||||||
c = '('.toUInt8 || c = ')'.toUInt8 || c = '*'.toUInt8 || c = '+'.toUInt8 ||
|
c = '('.toUInt8 || c = ')'.toUInt8 || c = '*'.toUInt8 || c = '+'.toUInt8 ||
|
||||||
|
|
@ -268,7 +268,7 @@ Checks if a byte is a valid path character (`pchar`) according to RFC 3986.
|
||||||
Note: The percent-encoding (`pct-encoded`) is handled separately by `isEncodedChar`,
|
Note: The percent-encoding (`pct-encoded`) is handled separately by `isEncodedChar`,
|
||||||
so this predicate only covers the non-percent characters.
|
so this predicate only covers the non-percent characters.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isPChar (c : UInt8) : Bool :=
|
def isPChar (c : UInt8) : Bool :=
|
||||||
isUnreserved c || isSubDelims c || c = ':'.toUInt8 || c = '@'.toUInt8
|
isUnreserved c || isSubDelims c || c = ':'.toUInt8 || c = '@'.toUInt8
|
||||||
|
|
||||||
|
|
@ -276,7 +276,7 @@ def isPChar (c : UInt8) : Bool :=
|
||||||
Checks if a byte is a valid character in a URI query component according to RFC 3986.
|
Checks if a byte is a valid character in a URI query component according to RFC 3986.
|
||||||
`query = *( pchar / "/" / "?" )`
|
`query = *( pchar / "/" / "?" )`
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isQueryChar (c : UInt8) : Bool :=
|
def isQueryChar (c : UInt8) : Bool :=
|
||||||
isPChar c || c = '/'.toUInt8 || c = '?'.toUInt8
|
isPChar c || c = '/'.toUInt8 || c = '?'.toUInt8
|
||||||
|
|
||||||
|
|
@ -284,7 +284,7 @@ def isQueryChar (c : UInt8) : Bool :=
|
||||||
Checks if a byte is a valid character in a URI fragment component according to RFC 3986.
|
Checks if a byte is a valid character in a URI fragment component according to RFC 3986.
|
||||||
`fragment = *( pchar / "/" / "?" )`
|
`fragment = *( pchar / "/" / "?" )`
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isFragmentChar (c : UInt8) : Bool :=
|
def isFragmentChar (c : UInt8) : Bool :=
|
||||||
isPChar c || c = '/'.toUInt8 || c = '?'.toUInt8
|
isPChar c || c = '/'.toUInt8 || c = '?'.toUInt8
|
||||||
|
|
||||||
|
|
@ -295,7 +295,7 @@ Checks if a byte is a valid character in a URI userinfo component according to R
|
||||||
Note: It avoids the pct-encoded of the original grammar because it is used with `Encoding.lean`
|
Note: It avoids the pct-encoded of the original grammar because it is used with `Encoding.lean`
|
||||||
that provides it.
|
that provides it.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isUserInfoChar (c : UInt8) : Bool :=
|
def isUserInfoChar (c : UInt8) : Bool :=
|
||||||
isUnreserved c || isSubDelims c || c = ':'.toUInt8
|
isUnreserved c || isSubDelims c || c = ':'.toUInt8
|
||||||
|
|
||||||
|
|
@ -306,7 +306,7 @@ excluding the typical key/value separators `&` and `=`.
|
||||||
Inspired by `query = *( pchar / "/" / "?" )` from RFC 3986,
|
Inspired by `query = *( pchar / "/" / "?" )` from RFC 3986,
|
||||||
but disallows `&` and `=` so they can be treated as structural separators.
|
but disallows `&` and `=` so they can be treated as structural separators.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def isQueryDataChar (c : UInt8) : Bool :=
|
def isQueryDataChar (c : UInt8) : Bool :=
|
||||||
isQueryChar c && c ≠ '&'.toUInt8 && c ≠ '='.toUInt8
|
isQueryChar c && c ≠ '&'.toUInt8 && c ≠ '='.toUInt8
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ set_option linter.all true
|
||||||
/--
|
/--
|
||||||
Predicate asserting that a string is in lowercase form.
|
Predicate asserting that a string is in lowercase form.
|
||||||
-/
|
-/
|
||||||
@[expose] def IsLowerCase (s : String) : Prop :=
|
def IsLowerCase (s : String) : Prop :=
|
||||||
s.toLower = s
|
s.toLower = s
|
||||||
|
|
||||||
private theorem Char.toLower_eq_self_iff {c : Char} : c.toLower = c ↔ c.isUpper = false := by
|
private theorem Char.toLower_eq_self_iff {c : Char} : c.toLower = c ↔ c.isUpper = false := by
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ deriving BEq
|
||||||
/--
|
/--
|
||||||
Inverts the message direction.
|
Inverts the message direction.
|
||||||
-/
|
-/
|
||||||
@[expose]
|
|
||||||
abbrev Direction.swap : Direction → Direction
|
abbrev Direction.swap : Direction → Direction
|
||||||
| .receiving => .sending
|
| .receiving => .sending
|
||||||
| .sending => .receiving
|
| .sending => .receiving
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ set_option linter.all true in
|
||||||
A `Bounded` is represented by an `Int` that is constrained by a lower and higher bounded using some
|
A `Bounded` is represented by an `Int` that is constrained by a lower and higher bounded using some
|
||||||
relation `rel`. It includes all the integers that `rel lo val ∧ rel val hi`.
|
relation `rel`. It includes all the integers that `rel lo val ∧ rel val hi`.
|
||||||
-/
|
-/
|
||||||
@[expose] def Bounded (rel : Int → Int → Prop) (lo : Int) (hi : Int) := { val : Int // rel lo val ∧ rel val hi }
|
def Bounded (rel : Int → Int → Prop) (lo : Int) (hi : Int) := { val : Int // rel lo val ∧ rel val hi }
|
||||||
|
|
||||||
namespace Bounded
|
namespace Bounded
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ namespace LE
|
||||||
/--
|
/--
|
||||||
Convert a `Nat` to a `Bounded.LE` by wrapping it.
|
Convert a `Nat` to a `Bounded.LE` by wrapping it.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def ofNatWrapping { lo hi : Int } (val : Int) (h : lo ≤ hi) : Bounded.LE lo hi := by
|
def ofNatWrapping { lo hi : Int } (val : Int) (h : lo ≤ hi) : Bounded.LE lo hi := by
|
||||||
let range := hi - lo + 1
|
let range := hi - lo + 1
|
||||||
have range_pos := Int.add_pos_of_nonneg_of_pos (b := 1) (Int.sub_nonneg_of_le h) (by decide)
|
have range_pos := Int.add_pos_of_nonneg_of_pos (b := 1) (Int.sub_nonneg_of_le h) (by decide)
|
||||||
|
|
@ -214,7 +214,7 @@ def toInt (n : Bounded.LE lo hi) : Int :=
|
||||||
/--
|
/--
|
||||||
Convert a `Bounded.LE` to a `Fin`.
|
Convert a `Bounded.LE` to a `Fin`.
|
||||||
-/
|
-/
|
||||||
@[inline, simp, expose]
|
@[inline, simp]
|
||||||
def toFin (n : Bounded.LE lo hi) (h₀ : 0 ≤ lo) : Fin (hi + 1).toNat := by
|
def toFin (n : Bounded.LE lo hi) (h₀ : 0 ≤ lo) : Fin (hi + 1).toNat := by
|
||||||
let h := n.property.right
|
let h := n.property.right
|
||||||
let h₁ := Int.le_trans h₀ n.property.left
|
let h₁ := Int.le_trans h₀ n.property.left
|
||||||
|
|
@ -284,7 +284,7 @@ def truncate (bounded : Bounded.LE n m) : Bounded.LE 0 (m - n) := by
|
||||||
Adjust the bounds of a `Bounded` by changing the higher bound if another value `j` satisfies the same
|
Adjust the bounds of a `Bounded` by changing the higher bound if another value `j` satisfies the same
|
||||||
constraint.
|
constraint.
|
||||||
-/
|
-/
|
||||||
@[inline, simp, expose]
|
@[inline, simp]
|
||||||
def truncateTop (bounded : Bounded.LE n m) (h : bounded.val ≤ j) : Bounded.LE n j := by
|
def truncateTop (bounded : Bounded.LE n m) (h : bounded.val ≤ j) : Bounded.LE n j := by
|
||||||
refine ⟨bounded.val, And.intro ?_ ?_⟩
|
refine ⟨bounded.val, And.intro ?_ ?_⟩
|
||||||
· exact bounded.property.left
|
· exact bounded.property.left
|
||||||
|
|
@ -312,7 +312,7 @@ def neg (bounded : Bounded.LE n m) : Bounded.LE (-m) (-n) := by
|
||||||
/--
|
/--
|
||||||
Adjust the bounds of a `Bounded` by adding a constant value to both the lower and upper bounds.
|
Adjust the bounds of a `Bounded` by adding a constant value to both the lower and upper bounds.
|
||||||
-/
|
-/
|
||||||
@[inline, simp, expose]
|
@[inline, simp]
|
||||||
def add (bounded : Bounded.LE n m) (num : Int) : Bounded.LE (n + num) (m + num) := by
|
def add (bounded : Bounded.LE n m) (num : Int) : Bounded.LE (n + num) (m + num) := by
|
||||||
refine ⟨bounded.val + num, And.intro ?_ ?_⟩
|
refine ⟨bounded.val + num, And.intro ?_ ?_⟩
|
||||||
all_goals apply (Int.add_le_add · (Int.le_refl num))
|
all_goals apply (Int.add_le_add · (Int.le_refl num))
|
||||||
|
|
@ -331,7 +331,7 @@ def addProven (bounded : Bounded.LE n m) (h₀ : bounded.val + num ≤ m) (h₁
|
||||||
/--
|
/--
|
||||||
Adjust the bounds of a `Bounded` by adding a constant value to the upper bounds.
|
Adjust the bounds of a `Bounded` by adding a constant value to the upper bounds.
|
||||||
-/
|
-/
|
||||||
@[inline, expose]
|
@[inline]
|
||||||
def addTop (bounded : Bounded.LE n m) (num : Int) (h : num ≥ 0) : Bounded.LE n (m + num) := by
|
def addTop (bounded : Bounded.LE n m) (num : Int) (h : num ≥ 0) : Bounded.LE n (m + num) := by
|
||||||
refine ⟨bounded.val + num, And.intro ?_ ?_⟩
|
refine ⟨bounded.val + num, And.intro ?_ ?_⟩
|
||||||
· let h := Int.add_le_add bounded.property.left h
|
· let h := Int.add_le_add bounded.property.left h
|
||||||
|
|
@ -362,7 +362,7 @@ def addBounds (bounded : Bounded.LE n m) (bounded₂ : Bounded.LE i j) : Bounded
|
||||||
/--
|
/--
|
||||||
Adjust the bounds of a `Bounded` by subtracting a constant value to both the lower and upper bounds.
|
Adjust the bounds of a `Bounded` by subtracting a constant value to both the lower and upper bounds.
|
||||||
-/
|
-/
|
||||||
@[inline, simp, expose]
|
@[inline, simp]
|
||||||
def sub (bounded : Bounded.LE n m) (num : Int) : Bounded.LE (n - num) (m - num) :=
|
def sub (bounded : Bounded.LE n m) (num : Int) : Bounded.LE (n - num) (m - num) :=
|
||||||
add bounded (-num)
|
add bounded (-num)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ set_option linter.all true
|
||||||
`Ordinal` represents a bounded value for second, which ranges between 0 and 59 or 60. This accounts
|
`Ordinal` represents a bounded value for second, which ranges between 0 and 59 or 60. This accounts
|
||||||
for potential leap second.
|
for potential leap second.
|
||||||
-/
|
-/
|
||||||
@[expose] def Ordinal (leap : Bool) := Bounded.LE 0 (.ofNat (if leap then 60 else 59))
|
def Ordinal (leap : Bool) := Bounded.LE 0 (.ofNat (if leap then 60 else 59))
|
||||||
|
|
||||||
instance : LE (Ordinal leap) where
|
instance : LE (Ordinal leap) where
|
||||||
le x y := LE.le x.val y.val
|
le x y := LE.le x.val y.val
|
||||||
|
|
@ -58,7 +58,7 @@ instance : LawfulEqOrd (Ordinal leap) := inferInstanceAs <| LawfulEqOrd (Bounded
|
||||||
/--
|
/--
|
||||||
`Offset` represents an offset in seconds. It is defined as an `Int`.
|
`Offset` represents an offset in seconds. It is defined as an `Int`.
|
||||||
-/
|
-/
|
||||||
@[expose] def Offset : Type := UnitVal 1
|
def Offset : Type := UnitVal 1
|
||||||
deriving Repr, DecidableEq, Inhabited, Add, Sub, Neg, LE, LT, ToString
|
deriving Repr, DecidableEq, Inhabited, Add, Sub, Neg, LE, LT, ToString
|
||||||
|
|
||||||
instance {x y : Offset} : Decidable (x ≤ y) :=
|
instance {x y : Offset} : Decidable (x ≤ y) :=
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ using the `fetch` function defined in this module.
|
||||||
namespace Lake
|
namespace Lake
|
||||||
|
|
||||||
/-- A type alias for `Option Package` that assists monad type class synthesis. -/
|
/-- A type alias for `Option Package` that assists monad type class synthesis. -/
|
||||||
@[expose] public abbrev CurrPackage := Option Package
|
public abbrev CurrPackage := Option Package
|
||||||
|
|
||||||
/-- Run the action `x` with `pkg?` as the current package or no package if `none`. -/
|
/-- Run the action `x` with `pkg?` as the current package or no package if `none`. -/
|
||||||
@[inline] public def withCurrPackage? [MonadWithReader CurrPackage m] (pkg? : Option Package) (x : m α): m α :=
|
@[inline] public def withCurrPackage? [MonadWithReader CurrPackage m] (pkg? : Option Package) (x : m α): m α :=
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ indexing fields more convenient.
|
||||||
namespace Lake
|
namespace Lake
|
||||||
|
|
||||||
/-- A JSON object (`Json.obj` data). -/
|
/-- A JSON object (`Json.obj` data). -/
|
||||||
@[expose] public abbrev JsonObject :=
|
public abbrev JsonObject :=
|
||||||
Std.TreeMap.Raw String Json
|
Std.TreeMap.Raw String Json
|
||||||
|
|
||||||
namespace JsonObject
|
namespace JsonObject
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import Std.Do.Triple.SpecLemmas
|
import Std.Do.Triple.SpecLemmas
|
||||||
|
|
||||||
@[specialize, expose]
|
@[specialize]
|
||||||
def List.newForIn (l : List α) (b : β) (kcons : α → (β → γ) → β → γ) (knil : β → γ) : γ :=
|
def List.newForIn (l : List α) (b : β) (kcons : α → (β → γ) → β → γ) (knil : β → γ) : γ :=
|
||||||
match l with
|
match l with
|
||||||
| [] => knil b
|
| [] => knil b
|
||||||
|
|
|
||||||
50
tests/elab/linterRedundantExpose.lean
Normal file
50
tests/elab/linterRedundantExpose.lean
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
module
|
||||||
|
|
||||||
|
/-! `warn.redundantExpose` tests -/
|
||||||
|
|
||||||
|
public section
|
||||||
|
|
||||||
|
-- `@[expose]` on abbrev should warn
|
||||||
|
/-- warning: `@[expose]` has no effect; this declaration would be exposed by default -/
|
||||||
|
#guard_msgs in
|
||||||
|
@[expose] abbrev myAbbrev := 1
|
||||||
|
|
||||||
|
-- `@[expose]` on a regular public def should not warn
|
||||||
|
@[expose] def myDef := 1
|
||||||
|
|
||||||
|
-- `@[no_expose]` on a regular def outside expose section should warn
|
||||||
|
/-- warning: `@[no_expose]` has no effect; this declaration would not be exposed by default -/
|
||||||
|
#guard_msgs in
|
||||||
|
@[no_expose] def myDef3 := 3
|
||||||
|
|
||||||
|
-- `@[expose]` on a data instance should warn
|
||||||
|
/-- warning: `@[expose]` has no effect; this declaration would be exposed by default -/
|
||||||
|
#guard_msgs in
|
||||||
|
@[expose] instance : Inhabited Nat := ⟨0⟩
|
||||||
|
|
||||||
|
-- `@[expose]` on a Prop instance should not warn
|
||||||
|
@[expose] instance : Nonempty Nat := ⟨0⟩
|
||||||
|
|
||||||
|
-- `@[no_expose]` on abbrev should not warn (it overrides auto-expose)
|
||||||
|
@[no_expose] abbrev myAbbrev2 := 5
|
||||||
|
|
||||||
|
-- `@[no_expose]` on a data instance should not warn (it overrides auto-expose)
|
||||||
|
@[no_expose] instance : Inhabited Bool := ⟨false⟩
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- `@[expose]` inside `@[expose] section` on a def should warn
|
||||||
|
@[expose] public section
|
||||||
|
/-- warning: `@[expose]` has no effect; this declaration would be exposed by default -/
|
||||||
|
#guard_msgs in
|
||||||
|
@[expose] def myDef2 := 2
|
||||||
|
|
||||||
|
-- `@[no_expose]` inside `@[expose] section` should not warn (it's meaningful)
|
||||||
|
@[no_expose] def myDef4 := 4
|
||||||
|
end
|
||||||
|
|
||||||
|
-- disabling the linter should suppress warnings
|
||||||
|
public section
|
||||||
|
set_option warn.redundantExpose false in
|
||||||
|
@[expose] abbrev myAbbrev3 := 6
|
||||||
|
end
|
||||||
Loading…
Add table
Reference in a new issue