chore: snake-case attributes (part 2)
This commit is contained in:
parent
e86b8c65a8
commit
583e023314
145 changed files with 1100 additions and 1100 deletions
|
|
@ -14,7 +14,7 @@ def Functor.mapRev {f : Type u → Type v} [Functor f] {α β : Type u} : f α
|
|||
|
||||
infixr:100 " <&> " => Functor.mapRev
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def Functor.discard {f : Type u → Type v} {α : Type u} [Functor f] (x : f α) : f PUnit :=
|
||||
Functor.mapConst PUnit.unit x
|
||||
|
||||
|
|
@ -30,10 +30,10 @@ variable {f : Type u → Type v} [Alternative f] {α : Type u}
|
|||
|
||||
export Alternative (failure)
|
||||
|
||||
@[alwaysInline, inline] def guard {f : Type → Type v} [Alternative f] (p : Prop) [Decidable p] : f Unit :=
|
||||
@[always_inline, inline] def guard {f : Type → Type v} [Alternative f] (p : Prop) [Decidable p] : f Unit :=
|
||||
if p then pure () else failure
|
||||
|
||||
@[alwaysInline, inline] def optional (x : f α) : f (Option α) :=
|
||||
@[always_inline, inline] def optional (x : f α) : f (Option α) :=
|
||||
some <$> x <|> pure none
|
||||
|
||||
class ToBool (α : Type u) where
|
||||
|
|
@ -44,12 +44,12 @@ export ToBool (toBool)
|
|||
instance : ToBool Bool where
|
||||
toBool b := b
|
||||
|
||||
@[macroInline] def bool {β : Type u} {α : Type v} [ToBool β] (f t : α) (b : β) : α :=
|
||||
@[macro_inline] def bool {β : Type u} {α : Type v} [ToBool β] (f t : α) (b : β) : α :=
|
||||
match toBool b with
|
||||
| true => t
|
||||
| false => f
|
||||
|
||||
@[macroInline] def orM {m : Type u → Type v} {β : Type u} [Monad m] [ToBool β] (x y : m β) : m β := do
|
||||
@[macro_inline] def orM {m : Type u → Type v} {β : Type u} [Monad m] [ToBool β] (x y : m β) : m β := do
|
||||
let b ← x
|
||||
match toBool b with
|
||||
| true => pure b
|
||||
|
|
@ -57,7 +57,7 @@ instance : ToBool Bool where
|
|||
|
||||
infixr:30 " <||> " => orM
|
||||
|
||||
@[macroInline] def andM {m : Type u → Type v} {β : Type u} [Monad m] [ToBool β] (x y : m β) : m β := do
|
||||
@[macro_inline] def andM {m : Type u → Type v} {β : Type u} [Monad m] [ToBool β] (x y : m β) : m β := do
|
||||
let b ← x
|
||||
match toBool b with
|
||||
| true => y
|
||||
|
|
@ -65,7 +65,7 @@ infixr:30 " <||> " => orM
|
|||
|
||||
infixr:35 " <&&> " => andM
|
||||
|
||||
@[macroInline] def notM {m : Type → Type v} [Applicative m] (x : m Bool) : m Bool :=
|
||||
@[macro_inline] def notM {m : Type → Type v} [Applicative m] (x : m Bool) : m Bool :=
|
||||
not <$> x
|
||||
|
||||
/-!
|
||||
|
|
@ -199,7 +199,7 @@ class MonadControlT (m : Type u → Type v) (n : Type u → Type w) where
|
|||
|
||||
export MonadControlT (stM liftWith restoreM)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (m n o) [MonadControl n o] [MonadControlT m n] : MonadControlT m o where
|
||||
stM α := stM m n (MonadControl.stM n o α)
|
||||
liftWith f := MonadControl.liftWith fun x₂ => liftWith fun x₁ => f (x₁ ∘ x₂)
|
||||
|
|
@ -210,12 +210,12 @@ instance (m : Type u → Type v) [Pure m] : MonadControlT m m where
|
|||
liftWith f := f fun x => x
|
||||
restoreM x := pure x
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def controlAt (m : Type u → Type v) {n : Type u → Type w} [MonadControlT m n] [Bind n] {α : Type u}
|
||||
(f : ({β : Type u} → n β → m (stM m n β)) → m (stM m n α)) : n α :=
|
||||
liftWith f >>= restoreM
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def control {m : Type u → Type v} {n : Type u → Type w} [MonadControlT m n] [Bind n] {α : Type u}
|
||||
(f : ({β : Type u} → n β → m (stM m n β)) → m (stM m n α)) : n α :=
|
||||
controlAt m f
|
||||
|
|
@ -233,22 +233,22 @@ class ForM (m : Type u → Type v) (γ : Type w₁) (α : outParam (Type w₂))
|
|||
export ForM (forM)
|
||||
|
||||
/-- Left-to-right composition of Kleisli arrows. -/
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
def Bind.kleisliRight [Bind m] (f₁ : α → m β) (f₂ : β → m γ) (a : α) : m γ :=
|
||||
f₁ a >>= f₂
|
||||
|
||||
/-- Right-to-left composition of Kleisli arrows. -/
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
def Bind.kleisliLeft [Bind m] (f₂ : β → m γ) (f₁ : α → m β) (a : α) : m γ :=
|
||||
f₁ a >>= f₂
|
||||
|
||||
/-- Same as `Bind.bind` but with arguments swapped. -/
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
def Bind.bindLeft [Bind m] (f : α → m β) (ma : m α) : m β :=
|
||||
ma >>= f
|
||||
|
||||
-- Precedence choice taken to be the same as in haskell:
|
||||
-- https://hackage.haskell.org/package/base-4.17.0.0/docs/Control-Monad.html#v:-61--60--60-
|
||||
@[inheritDoc] infixr:55 " >=> " => Bind.kleisliRight
|
||||
@[inheritDoc] infixr:55 " <=< " => Bind.kleisliLeft
|
||||
@[inheritDoc] infixr:55 " =<< " => Bind.bindLeft
|
||||
@[inherit_doc] infixr:55 " >=> " => Bind.kleisliRight
|
||||
@[inherit_doc] infixr:55 " <=< " => Bind.kleisliLeft
|
||||
@[inherit_doc] infixr:55 " =<< " => Bind.bindLeft
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ variable {ε σ α β : Type u}
|
|||
|
||||
/-- Alternative orElse operator that allows to select which exception should be used.
|
||||
The default is to use the first exception since the standard `orElse` uses the second. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def orElse' {δ} [Backtrackable δ σ] (x₁ x₂ : EStateM ε σ α) (useFirstEx := true) : EStateM ε σ α := fun s =>
|
||||
let d := Backtrackable.save s;
|
||||
match x₁ s with
|
||||
|
|
@ -41,7 +41,7 @@ protected def orElse' {δ} [Backtrackable δ σ] (x₁ x₂ : EStateM ε σ α)
|
|||
| ok => ok
|
||||
| ok => ok
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : MonadFinally (EStateM ε σ) := {
|
||||
tryFinally' := fun x h s =>
|
||||
let r := x s
|
||||
|
|
@ -54,7 +54,7 @@ instance : MonadFinally (EStateM ε σ) := {
|
|||
| Result.error e₂ s => Result.error e₂ s
|
||||
}
|
||||
|
||||
@[alwaysInline, inline] def fromStateM {ε σ α : Type} (x : StateM σ α) : EStateM ε σ α := fun s =>
|
||||
@[always_inline, inline] def fromStateM {ε σ α : Type} (x : StateM σ α) : EStateM ε σ α := fun s =>
|
||||
match x.run s with
|
||||
| (a, s') => EStateM.Result.ok a s'
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ import Init.Coe
|
|||
namespace Except
|
||||
variable {ε : Type u}
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def pure (a : α) : Except ε α :=
|
||||
Except.ok a
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def map (f : α → β) : Except ε α → Except ε β
|
||||
| Except.error err => Except.error err
|
||||
| Except.ok v => Except.ok <| f v
|
||||
|
|
@ -27,31 +27,31 @@ protected def map (f : α → β) : Except ε α → Except ε β
|
|||
intro e
|
||||
simp [Except.map]; cases e <;> rfl
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def mapError (f : ε → ε') : Except ε α → Except ε' α
|
||||
| Except.error err => Except.error <| f err
|
||||
| Except.ok v => Except.ok v
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def bind (ma : Except ε α) (f : α → Except ε β) : Except ε β :=
|
||||
match ma with
|
||||
| Except.error err => Except.error err
|
||||
| Except.ok v => f v
|
||||
|
||||
/-- Returns true if the value is `Except.ok`, false otherwise. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def toBool : Except ε α → Bool
|
||||
| Except.ok _ => true
|
||||
| Except.error _ => false
|
||||
|
||||
abbrev isOk : Except ε α → Bool := Except.toBool
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def toOption : Except ε α → Option α
|
||||
| Except.ok a => some a
|
||||
| Except.error _ => none
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def tryCatch (ma : Except ε α) (handle : ε → Except ε α) : Except ε α :=
|
||||
match ma with
|
||||
| Except.ok a => Except.ok a
|
||||
|
|
@ -62,7 +62,7 @@ def orElseLazy (x : Except ε α) (y : Unit → Except ε α) : Except ε α :=
|
|||
| Except.ok a => Except.ok a
|
||||
| Except.error _ => y ()
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad (Except ε) where
|
||||
pure := Except.pure
|
||||
bind := Except.bind
|
||||
|
|
@ -73,44 +73,44 @@ end Except
|
|||
def ExceptT (ε : Type u) (m : Type u → Type v) (α : Type u) : Type v :=
|
||||
m (Except ε α)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def ExceptT.mk {ε : Type u} {m : Type u → Type v} {α : Type u} (x : m (Except ε α)) : ExceptT ε m α := x
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def ExceptT.run {ε : Type u} {m : Type u → Type v} {α : Type u} (x : ExceptT ε m α) : m (Except ε α) := x
|
||||
|
||||
namespace ExceptT
|
||||
|
||||
variable {ε : Type u} {m : Type u → Type v} [Monad m]
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def pure {α : Type u} (a : α) : ExceptT ε m α :=
|
||||
ExceptT.mk <| pure (Except.ok a)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def bindCont {α β : Type u} (f : α → ExceptT ε m β) : Except ε α → m (Except ε β)
|
||||
| Except.ok a => f a
|
||||
| Except.error e => pure (Except.error e)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def bind {α β : Type u} (ma : ExceptT ε m α) (f : α → ExceptT ε m β) : ExceptT ε m β :=
|
||||
ExceptT.mk <| ma >>= ExceptT.bindCont f
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def map {α β : Type u} (f : α → β) (x : ExceptT ε m α) : ExceptT ε m β :=
|
||||
ExceptT.mk <| x >>= fun a => match a with
|
||||
| (Except.ok a) => pure <| Except.ok (f a)
|
||||
| (Except.error e) => pure <| Except.error e
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def lift {α : Type u} (t : m α) : ExceptT ε m α :=
|
||||
ExceptT.mk <| Except.ok <$> t
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : MonadLift (Except ε) (ExceptT ε m) := ⟨fun e => ExceptT.mk <| pure e⟩
|
||||
instance : MonadLift m (ExceptT ε m) := ⟨ExceptT.lift⟩
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def tryCatch {α : Type u} (ma : ExceptT ε m α) (handle : ε → ExceptT ε m α) : ExceptT ε m α :=
|
||||
ExceptT.mk <| ma >>= fun res => match res with
|
||||
| Except.ok a => pure (Except.ok a)
|
||||
|
|
@ -118,24 +118,24 @@ protected def tryCatch {α : Type u} (ma : ExceptT ε m α) (handle : ε → Exc
|
|||
|
||||
instance : MonadFunctor m (ExceptT ε m) := ⟨fun f x => f x⟩
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad (ExceptT ε m) where
|
||||
pure := ExceptT.pure
|
||||
bind := ExceptT.bind
|
||||
map := ExceptT.map
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def adapt {ε' α : Type u} (f : ε → ε') : ExceptT ε m α → ExceptT ε' m α := fun x =>
|
||||
ExceptT.mk <| Except.mapError f <$> x
|
||||
|
||||
end ExceptT
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (m : Type u → Type v) (ε₁ : Type u) (ε₂ : Type u) [Monad m] [MonadExceptOf ε₁ m] : MonadExceptOf ε₁ (ExceptT ε₂ m) where
|
||||
throw e := ExceptT.mk <| throwThe ε₁ e
|
||||
tryCatch x handle := ExceptT.mk <| tryCatchThe ε₁ x handle
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (m : Type u → Type v) (ε : Type u) [Monad m] : MonadExceptOf ε (ExceptT ε m) where
|
||||
throw e := ExceptT.mk <| pure (Except.error e)
|
||||
tryCatch := ExceptT.tryCatch
|
||||
|
|
@ -152,13 +152,13 @@ variable {ε : Type u} {m : Type v → Type w}
|
|||
|
||||
/-- Alternative orelse operator that allows to select which exception should be used.
|
||||
The default is to use the first exception since the standard `orelse` uses the second. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def orelse' [MonadExcept ε m] {α : Type v} (t₁ t₂ : m α) (useFirstEx := true) : m α :=
|
||||
tryCatch t₁ fun e₁ => tryCatch t₂ fun e₂ => throw (if useFirstEx then e₁ else e₂)
|
||||
|
||||
end MonadExcept
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def observing {ε α : Type u} {m : Type u → Type v} [Monad m] [MonadExcept ε m] (x : m α) : m (Except ε α) :=
|
||||
tryCatch (do let a ← x; pure (Except.ok a)) (fun ex => pure (Except.error ex))
|
||||
|
||||
|
|
@ -182,19 +182,19 @@ class MonadFinally (m : Type u → Type v) where
|
|||
export MonadFinally (tryFinally')
|
||||
|
||||
/-- Execute `x` and then execute `finalizer` even if `x` threw an exception -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def tryFinally {m : Type u → Type v} {α β : Type u} [MonadFinally m] [Functor m] (x : m α) (finalizer : m β) : m α :=
|
||||
let y := tryFinally' x (fun _ => finalizer)
|
||||
(·.1) <$> y
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance Id.finally : MonadFinally Id where
|
||||
tryFinally' := fun x h =>
|
||||
let a := x
|
||||
let b := h (some x)
|
||||
pure (a, b)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance ExceptT.finally {m : Type u → Type v} {ε : Type u} [MonadFinally m] [Monad m] : MonadFinally (ExceptT ε m) where
|
||||
tryFinally' := fun x h => ExceptT.mk do
|
||||
let r ← tryFinally' x fun e? => match e? with
|
||||
|
|
|
|||
|
|
@ -14,19 +14,19 @@ def ExceptCpsT (ε : Type u) (m : Type u → Type v) (α : Type u) := (β : Type
|
|||
|
||||
namespace ExceptCpsT
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def run {ε α : Type u} [Monad m] (x : ExceptCpsT ε m α) : m (Except ε α) :=
|
||||
x _ (fun a => pure (Except.ok a)) (fun e => pure (Except.error e))
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def runK {ε α : Type u} (x : ExceptCpsT ε m α) (s : ε) (ok : α → m β) (error : ε → m β) : m β :=
|
||||
x _ ok error
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def runCatch [Monad m] (x : ExceptCpsT α m α) : m α :=
|
||||
x α pure pure
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad (ExceptCpsT ε m) where
|
||||
map f x := fun _ k₁ k₂ => x _ (fun a => k₁ (f a)) k₂
|
||||
pure a := fun _ k _ => k a
|
||||
|
|
@ -39,7 +39,7 @@ instance : MonadExceptOf ε (ExceptCpsT ε m) where
|
|||
throw e := fun _ _ k => k e
|
||||
tryCatch x handle := fun _ k₁ k₂ => x _ k₁ (fun e => handle e _ k₁ k₂)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def lift [Monad m] (x : m α) : ExceptCpsT ε m α :=
|
||||
fun _ k _ => x >>= k
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ def Id (type : Type u) : Type u := type
|
|||
|
||||
namespace Id
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad Id where
|
||||
pure x := x
|
||||
bind x f := f x
|
||||
|
|
@ -23,7 +23,7 @@ instance : Monad Id where
|
|||
def hasBind : Bind Id :=
|
||||
inferInstance
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def run (x : Id α) : α := x
|
||||
|
||||
instance [OfNat α n] : OfNat (Id α) n :=
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ instance : ToBool (Option α) := ⟨Option.toBool⟩
|
|||
def OptionT (m : Type u → Type v) (α : Type u) : Type v :=
|
||||
m (Option α)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def OptionT.run {m : Type u → Type v} {α : Type u} (x : OptionT m α) : m (Option α) :=
|
||||
x
|
||||
|
||||
|
|
@ -25,41 +25,41 @@ variable {m : Type u → Type v} [Monad m] {α β : Type u}
|
|||
protected def mk (x : m (Option α)) : OptionT m α :=
|
||||
x
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def bind (x : OptionT m α) (f : α → OptionT m β) : OptionT m β := OptionT.mk do
|
||||
match (← x) with
|
||||
| some a => f a
|
||||
| none => pure none
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def pure (a : α) : OptionT m α := OptionT.mk do
|
||||
pure (some a)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad (OptionT m) where
|
||||
pure := OptionT.pure
|
||||
bind := OptionT.bind
|
||||
|
||||
@[alwaysInline, inline] protected def orElse (x : OptionT m α) (y : Unit → OptionT m α) : OptionT m α := OptionT.mk do
|
||||
@[always_inline, inline] protected def orElse (x : OptionT m α) (y : Unit → OptionT m α) : OptionT m α := OptionT.mk do
|
||||
match (← x) with
|
||||
| some a => pure (some a)
|
||||
| _ => y ()
|
||||
|
||||
@[alwaysInline, inline] protected def fail : OptionT m α := OptionT.mk do
|
||||
@[always_inline, inline] protected def fail : OptionT m α := OptionT.mk do
|
||||
pure none
|
||||
|
||||
instance : Alternative (OptionT m) where
|
||||
failure := OptionT.fail
|
||||
orElse := OptionT.orElse
|
||||
|
||||
@[alwaysInline, inline] protected def lift (x : m α) : OptionT m α := OptionT.mk do
|
||||
@[always_inline, inline] protected def lift (x : m α) : OptionT m α := OptionT.mk do
|
||||
return some (← x)
|
||||
|
||||
instance : MonadLift m (OptionT m) := ⟨OptionT.lift⟩
|
||||
|
||||
instance : MonadFunctor m (OptionT m) := ⟨fun f x => f x⟩
|
||||
|
||||
@[alwaysInline, inline] protected def tryCatch (x : OptionT m α) (handle : Unit → OptionT m α) : OptionT m α := OptionT.mk do
|
||||
@[always_inline, inline] protected def tryCatch (x : OptionT m α) (handle : Unit → OptionT m α) : OptionT m α := OptionT.mk do
|
||||
let some a ← x | handle ()
|
||||
pure a
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ import Init.Control.Except
|
|||
|
||||
namespace ReaderT
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def orElse [Alternative m] (x₁ : ReaderT ρ m α) (x₂ : Unit → ReaderT ρ m α) : ReaderT ρ m α :=
|
||||
fun s => x₁ s <|> x₂ () s
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def failure [Alternative m] : ReaderT ρ m α :=
|
||||
fun _ => failure
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ instance : MonadControl m (ReaderT ρ m) where
|
|||
liftWith f ctx := f fun x => x ctx
|
||||
restoreM x _ := x
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance ReaderT.tryFinally [MonadFinally m] [Monad m] : MonadFinally (ReaderT ρ m) where
|
||||
tryFinally' x h ctx := tryFinally' (x ctx) (fun a? => h a? ctx)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ universe u v w
|
|||
def StateT (σ : Type u) (m : Type u → Type v) (α : Type u) : Type (max u v) :=
|
||||
σ → m (α × σ)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def StateT.run {σ : Type u} {m : Type u → Type v} {α : Type u} (x : StateT σ m α) (s : σ) : m (α × σ) :=
|
||||
x s
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def StateT.run' {σ : Type u} {m : Type u → Type v} [Functor m] {α : Type u} (x : StateT σ m α) (s : σ) : m α :=
|
||||
(·.1) <$> x s
|
||||
|
||||
|
|
@ -38,29 +38,29 @@ section
|
|||
variable {σ : Type u} {m : Type u → Type v}
|
||||
variable [Monad m] {α β : Type u}
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def pure (a : α) : StateT σ m α :=
|
||||
fun s => pure (a, s)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def bind (x : StateT σ m α) (f : α → StateT σ m β) : StateT σ m β :=
|
||||
fun s => do let (a, s) ← x s; f a s
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def map (f : α → β) (x : StateT σ m α) : StateT σ m β :=
|
||||
fun s => do let (a, s) ← x s; pure (f a, s)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad (StateT σ m) where
|
||||
pure := StateT.pure
|
||||
bind := StateT.bind
|
||||
map := StateT.map
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def orElse [Alternative m] {α : Type u} (x₁ : StateT σ m α) (x₂ : Unit → StateT σ m α) : StateT σ m α :=
|
||||
fun s => x₁ s <|> x₂ () s
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def failure [Alternative m] {α : Type u} : StateT σ m α :=
|
||||
fun _ => failure
|
||||
|
||||
|
|
@ -68,28 +68,28 @@ instance [Alternative m] : Alternative (StateT σ m) where
|
|||
failure := StateT.failure
|
||||
orElse := StateT.orElse
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def get : StateT σ m σ :=
|
||||
fun s => pure (s, s)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def set : σ → StateT σ m PUnit :=
|
||||
fun s' _ => pure (⟨⟩, s')
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def modifyGet (f : σ → α × σ) : StateT σ m α :=
|
||||
fun s => pure (f s)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def lift {α : Type u} (t : m α) : StateT σ m α :=
|
||||
fun s => do let a ← t; pure (a, s)
|
||||
|
||||
instance : MonadLift m (StateT σ m) := ⟨StateT.lift⟩
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (σ m) [Monad m] : MonadFunctor m (StateT σ m) := ⟨fun f x s => f (x s)⟩
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (StateT σ m) := {
|
||||
throw := StateT.lift ∘ throwThe ε
|
||||
tryCatch := fun x c s => tryCatchThe ε (x s) (fun e => c e s)
|
||||
|
|
@ -99,7 +99,7 @@ end
|
|||
end StateT
|
||||
|
||||
/-- Adapter to create a ForIn instance from a ForM instance -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def ForM.forIn [Monad m] [ForM (StateT β (ExceptT β m)) ρ α]
|
||||
(x : ρ) (b : β) (f : α → β → m (ForInStep β)) : m β := do
|
||||
let g a b := .mk do
|
||||
|
|
@ -120,13 +120,13 @@ instance [Monad m] : MonadStateOf σ (StateT σ m) where
|
|||
|
||||
end
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance StateT.monadControl (σ : Type u) (m : Type u → Type v) [Monad m] : MonadControl m (StateT σ m) where
|
||||
stM := fun α => α × σ
|
||||
liftWith := fun f => do let s ← get; liftM (f (fun x => x.run s))
|
||||
restoreM := fun x => do let (a, s) ← liftM x; set s; pure a
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance StateT.tryFinally {m : Type u → Type v} {σ : Type u} [MonadFinally m] [Monad m] : MonadFinally (StateT σ m) where
|
||||
tryFinally' := fun x h s => do
|
||||
let ((a, _), (b, s'')) ← tryFinally' (x s) fun
|
||||
|
|
|
|||
|
|
@ -14,19 +14,19 @@ def StateCpsT (σ : Type u) (m : Type u → Type v) (α : Type u) := (δ : Type
|
|||
|
||||
namespace StateCpsT
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def runK {α σ : Type u} {m : Type u → Type v} (x : StateCpsT σ m α) (s : σ) (k : α → σ → m β) : m β :=
|
||||
x _ s k
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def run {α σ : Type u} {m : Type u → Type v} [Monad m] (x : StateCpsT σ m α) (s : σ) : m (α × σ) :=
|
||||
runK x s (fun a s => pure (a, s))
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def run' {α σ : Type u} {m : Type u → Type v} [Monad m] (x : StateCpsT σ m α) (s : σ) : m α :=
|
||||
runK x s (fun a _ => pure a)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad (StateCpsT σ m) where
|
||||
map f x := fun δ s k => x δ s fun a s => k (f a) s
|
||||
pure a := fun _ s k => k a s
|
||||
|
|
@ -35,13 +35,13 @@ instance : Monad (StateCpsT σ m) where
|
|||
instance : LawfulMonad (StateCpsT σ m) := by
|
||||
refine' { .. } <;> intros <;> rfl
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : MonadStateOf σ (StateCpsT σ m) where
|
||||
get := fun _ s k => k s s
|
||||
set s := fun _ _ k => k ⟨⟩ s
|
||||
modifyGet f := fun _ s k => let (a, s) := f s; k a s
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def lift [Monad m] (x : m α) : StateCpsT σ m α :=
|
||||
fun _ s k => x >>= (k . s)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ def StateRefT' (ω : Type) (σ : Type) (m : Type → Type) (α : Type) : Type :=
|
|||
|
||||
/-! Recall that `StateRefT` is a macro that infers `ω` from the `m`. -/
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def StateRefT'.run {ω σ : Type} {m : Type → Type} [Monad m] [MonadLiftT (ST ω) m] {α : Type} (x : StateRefT' ω σ m α) (s : σ) : m (α × σ) := do
|
||||
let ref ← ST.mkRef s
|
||||
let a ← x ref
|
||||
let s ← ref.get
|
||||
pure (a, s)
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def StateRefT'.run' {ω σ : Type} {m : Type → Type} [Monad m] [MonadLiftT (ST ω) m] {α : Type} (x : StateRefT' ω σ m α) (s : σ) : m α := do
|
||||
let (a, _) ← x.run s
|
||||
pure a
|
||||
|
|
@ -28,7 +28,7 @@ def StateRefT'.run' {ω σ : Type} {m : Type → Type} [Monad m] [MonadLiftT (ST
|
|||
namespace StateRefT'
|
||||
variable {ω σ : Type} {m : Type → Type} {α : Type}
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def lift (x : m α) : StateRefT' ω σ m α :=
|
||||
fun _ => x
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ instance [MonadLiftT (ST ω) m] [Monad m] : MonadStateOf σ (StateRefT' ω σ m)
|
|||
set := StateRefT'.set
|
||||
modifyGet := StateRefT'.modifyGet
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (StateRefT' ω σ m) where
|
||||
throw := StateRefT'.lift ∘ throwThe ε
|
||||
tryCatch := fun x c s => tryCatchThe ε (x s) (fun e => c e s)
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ structure Iff (a b : Prop) : Prop where
|
|||
/-- Modus ponens for if and only if, reversed. If `a ↔ b` and `b`, then `a`. -/
|
||||
mpr : b → a
|
||||
|
||||
@[inheritDoc] infix:20 " <-> " => Iff
|
||||
@[inheritDoc] infix:20 " ↔ " => Iff
|
||||
@[inherit_doc] infix:20 " <-> " => Iff
|
||||
@[inherit_doc] infix:20 " ↔ " => Iff
|
||||
|
||||
/--
|
||||
`Sum α β`, or `α ⊕ β`, is the disjoint union of types `α` and `β`.
|
||||
|
|
@ -105,7 +105,7 @@ inductive Sum (α : Type u) (β : Type v) where
|
|||
/-- Right injection into the sum type `α ⊕ β`. If `b : β` then `.inr b : α ⊕ β`. -/
|
||||
| inr (val : β) : Sum α β
|
||||
|
||||
@[inheritDoc] infixr:30 " ⊕ " => Sum
|
||||
@[inherit_doc] infixr:30 " ⊕ " => Sum
|
||||
|
||||
/--
|
||||
`PSum α β`, or `α ⊕' β`, is the disjoint union of types `α` and `β`.
|
||||
|
|
@ -124,7 +124,7 @@ inductive PSum (α : Sort u) (β : Sort v) where
|
|||
/-- Right injection into the sum type `α ⊕' β`. If `b : β` then `.inr b : α ⊕' β`. -/
|
||||
| inr (val : β) : PSum α β
|
||||
|
||||
@[inheritDoc] infixr:30 " ⊕' " => PSum
|
||||
@[inherit_doc] infixr:30 " ⊕' " => PSum
|
||||
|
||||
/--
|
||||
`Sigma β`, also denoted `Σ a : α, β a` or `(a : α) × β a`, is the type of dependent pairs
|
||||
|
|
@ -340,7 +340,7 @@ class HasEquiv (α : Sort u) where
|
|||
the notion of equivalence is type-dependent. -/
|
||||
Equiv : α → α → Sort v
|
||||
|
||||
@[inheritDoc] infix:50 " ≈ " => HasEquiv.Equiv
|
||||
@[inherit_doc] infix:50 " ≈ " => HasEquiv.Equiv
|
||||
|
||||
/-- `EmptyCollection α` is the typeclass which supports the notation `∅`, also written as `{}`. -/
|
||||
class EmptyCollection (α : Type u) where
|
||||
|
|
@ -348,8 +348,8 @@ class EmptyCollection (α : Type u) where
|
|||
It is supported by the `EmptyCollection` typeclass. -/
|
||||
emptyCollection : α
|
||||
|
||||
@[inheritDoc] notation "{" "}" => EmptyCollection.emptyCollection
|
||||
@[inheritDoc] notation "∅" => EmptyCollection.emptyCollection
|
||||
@[inherit_doc] notation "{" "}" => EmptyCollection.emptyCollection
|
||||
@[inherit_doc] notation "∅" => EmptyCollection.emptyCollection
|
||||
|
||||
/--
|
||||
`Task α` is a primitive for asynchronous computation.
|
||||
|
|
@ -485,7 +485,7 @@ Unlike `x ≠ y` (which is notation for `Ne x y`), this is `Bool` valued instead
|
|||
@[inline] def bne {α : Type u} [BEq α] (a b : α) : Bool :=
|
||||
!(a == b)
|
||||
|
||||
@[inheritDoc] infix:50 " != " => bne
|
||||
@[inherit_doc] infix:50 " != " => bne
|
||||
|
||||
/--
|
||||
`LawfulBEq α` is a typeclass which asserts that the `BEq α` implementation
|
||||
|
|
@ -514,7 +514,7 @@ instance : LawfulBEq String := inferInstance
|
|||
|
||||
/-! # Logical connectives and equality -/
|
||||
|
||||
@[inheritDoc True.intro] def trivial : True := ⟨⟩
|
||||
@[inherit_doc True.intro] def trivial : True := ⟨⟩
|
||||
|
||||
theorem mt {a b : Prop} (h₁ : a → b) (h₂ : ¬b) : ¬a :=
|
||||
fun ha => h₂ (h₁ ha)
|
||||
|
|
@ -536,7 +536,7 @@ If `h : α = β` is a proof of type equality, then `h.mp : α → β` is the ind
|
|||
You can prove theorems about the resulting element by induction on `h`, since
|
||||
`rfl.mp` is definitionally the identity function.
|
||||
-/
|
||||
@[macroInline] def Eq.mp {α β : Sort u} (h : α = β) (a : α) : β :=
|
||||
@[macro_inline] def Eq.mp {α β : Sort u} (h : α = β) (a : α) : β :=
|
||||
h ▸ a
|
||||
|
||||
/--
|
||||
|
|
@ -546,7 +546,7 @@ If `h : α = β` is a proof of type equality, then `h.mpr : β → α` is the in
|
|||
You can prove theorems about the resulting element by induction on `h`, since
|
||||
`rfl.mpr` is definitionally the identity function.
|
||||
-/
|
||||
@[macroInline] def Eq.mpr {α β : Sort u} (h : α = β) (b : β) : α :=
|
||||
@[macro_inline] def Eq.mpr {α β : Sort u} (h : α = β) (b : β) : α :=
|
||||
h ▸ b
|
||||
|
||||
theorem Eq.substr {α : Sort u} {p : α → Prop} {a b : α} (h₁ : b = a) (h₂ : p a) : p b :=
|
||||
|
|
@ -562,7 +562,7 @@ and asserts that `a` and `b` are not equal.
|
|||
@[reducible] def Ne {α : Sort u} (a b : α) :=
|
||||
¬(a = b)
|
||||
|
||||
@[inheritDoc] infix:50 " ≠ " => Ne
|
||||
@[inherit_doc] infix:50 " ≠ " => Ne
|
||||
|
||||
section Ne
|
||||
variable {α : Sort u}
|
||||
|
|
@ -725,7 +725,7 @@ Synonym for `dite` (dependent if-then-else). We can construct an element `q`
|
|||
(of any sort, not just a proposition) by cases on whether `p` is true or false,
|
||||
provided `p` is decidable.
|
||||
-/
|
||||
@[macroInline] def byCases {q : Sort u} [dec : Decidable p] (h1 : p → q) (h2 : ¬p → q) : q :=
|
||||
@[macro_inline] def byCases {q : Sort u} [dec : Decidable p] (h1 : p → q) (h2 : ¬p → q) : q :=
|
||||
match dec with
|
||||
| isTrue h => h1 h
|
||||
| isFalse h => h2 h
|
||||
|
|
@ -766,7 +766,7 @@ variable {p q : Prop}
|
|||
decidable_of_decidable_of_iff (p := p) (h ▸ Iff.rfl)
|
||||
end
|
||||
|
||||
@[macroInline] instance {p q} [Decidable p] [Decidable q] : Decidable (p → q) :=
|
||||
@[macro_inline] instance {p q} [Decidable p] [Decidable q] : Decidable (p → q) :=
|
||||
if hp : p then
|
||||
if hq : q then isTrue (fun _ => hq)
|
||||
else isFalse (fun h => absurd (h hp) hq)
|
||||
|
|
@ -1222,7 +1222,7 @@ protected abbrev liftOn {α : Sort u} {β : Sort v} {r : α → α → Prop}
|
|||
(q : Quot r) (f : α → β) (c : (a b : α) → r a b → f a = f b) : β :=
|
||||
lift f c q
|
||||
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected theorem inductionOn {α : Sort u} {r : α → α → Prop} {motive : Quot r → Prop}
|
||||
(q : Quot r)
|
||||
(h : (a : α) → motive (Quot.mk r a))
|
||||
|
|
@ -1238,7 +1238,7 @@ variable {r : α → α → Prop}
|
|||
variable {motive : Quot r → Sort v}
|
||||
|
||||
/-- Auxiliary definition for `Quot.rec`. -/
|
||||
@[reducible, macroInline]
|
||||
@[reducible, macro_inline]
|
||||
protected def indep (f : (a : α) → motive (Quot.mk r a)) (a : α) : PSigma motive :=
|
||||
⟨Quot.mk r a, f a⟩
|
||||
|
||||
|
|
@ -1270,7 +1270,7 @@ protected abbrev rec
|
|||
(q : Quot r) : motive q :=
|
||||
Eq.ndrecOn (Quot.liftIndepPr1 f h q) ((lift (Quot.indep f) (Quot.indepCoherent f h) q).2)
|
||||
|
||||
@[inheritDoc Quot.rec] protected abbrev recOn
|
||||
@[inherit_doc Quot.rec] protected abbrev recOn
|
||||
(q : Quot r)
|
||||
(f : (a : α) → motive (Quot.mk r a))
|
||||
(h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (sound p) = f b)
|
||||
|
|
@ -1354,7 +1354,7 @@ then it lifts to a function on `Quotient s` such that `lift (mk a) f h = f a`.
|
|||
protected abbrev liftOn {α : Sort u} {β : Sort v} {s : Setoid α} (q : Quotient s) (f : α → β) (c : (a b : α) → a ≈ b → f a = f b) : β :=
|
||||
Quot.liftOn q f c
|
||||
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected theorem inductionOn {α : Sort u} {s : Setoid α} {motive : Quotient s → Prop}
|
||||
(q : Quotient s)
|
||||
(h : (a : α) → motive (Quotient.mk s a))
|
||||
|
|
@ -1370,7 +1370,7 @@ variable {s : Setoid α}
|
|||
variable {motive : Quotient s → Sort v}
|
||||
|
||||
/-- The analogue of `Quot.rec` for `Quotient`. See `Quot.rec`. -/
|
||||
@[inline, elabAsElim]
|
||||
@[inline, elab_as_elim]
|
||||
protected def rec
|
||||
(f : (a : α) → motive (Quotient.mk s a))
|
||||
(h : (a b : α) → (p : a ≈ b) → Eq.ndrec (f a) (Quotient.sound p) = f b)
|
||||
|
|
@ -1379,7 +1379,7 @@ protected def rec
|
|||
Quot.rec f h q
|
||||
|
||||
/-- The analogue of `Quot.recOn` for `Quotient`. See `Quot.recOn`. -/
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected abbrev recOn
|
||||
(q : Quotient s)
|
||||
(f : (a : α) → motive (Quotient.mk s a))
|
||||
|
|
@ -1388,7 +1388,7 @@ protected abbrev recOn
|
|||
Quot.recOn q f h
|
||||
|
||||
/-- The analogue of `Quot.recOnSubsingleton` for `Quotient`. See `Quot.recOnSubsingleton`. -/
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected abbrev recOnSubsingleton
|
||||
[h : (a : α) → Subsingleton (motive (Quotient.mk s a))]
|
||||
(q : Quotient s)
|
||||
|
|
@ -1397,7 +1397,7 @@ protected abbrev recOnSubsingleton
|
|||
Quot.recOnSubsingleton (h := h) q f
|
||||
|
||||
/-- The analogue of `Quot.hrecOn` for `Quotient`. See `Quot.hrecOn`. -/
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected abbrev hrecOn
|
||||
(q : Quotient s)
|
||||
(f : (a : α) → motive (Quotient.mk s a))
|
||||
|
|
@ -1431,7 +1431,7 @@ protected abbrev liftOn₂
|
|||
: φ :=
|
||||
Quotient.lift₂ f c q₁ q₂
|
||||
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected theorem ind₂
|
||||
{motive : Quotient s₁ → Quotient s₂ → Prop}
|
||||
(h : (a : α) → (b : β) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))
|
||||
|
|
@ -1442,7 +1442,7 @@ protected theorem ind₂
|
|||
induction q₂ using Quotient.ind
|
||||
apply h
|
||||
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected theorem inductionOn₂
|
||||
{motive : Quotient s₁ → Quotient s₂ → Prop}
|
||||
(q₁ : Quotient s₁)
|
||||
|
|
@ -1453,7 +1453,7 @@ protected theorem inductionOn₂
|
|||
induction q₂ using Quotient.ind
|
||||
apply h
|
||||
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected theorem inductionOn₃
|
||||
{s₃ : Setoid φ}
|
||||
{motive : Quotient s₁ → Quotient s₂ → Quotient s₃ → Prop}
|
||||
|
|
@ -1498,7 +1498,7 @@ variable {α : Sort uA} {β : Sort uB}
|
|||
variable {s₁ : Setoid α} {s₂ : Setoid β}
|
||||
|
||||
/-- Lift a binary function to a quotient on both arguments. -/
|
||||
@[elabAsElim]
|
||||
@[elab_as_elim]
|
||||
protected abbrev recOnSubsingleton₂
|
||||
{motive : Quotient s₁ → Quotient s₂ → Sort uC}
|
||||
[s : (a : α) → (b : β) → Subsingleton (motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))]
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ unsafe def modifyMUnsafe [Monad m] (a : Array α) (i : Nat) (f : α → m α) :
|
|||
else
|
||||
pure a
|
||||
|
||||
@[implementedBy modifyMUnsafe]
|
||||
@[implemented_by modifyMUnsafe]
|
||||
def modifyM [Monad m] (a : Array α) (i : Nat) (f : α → m α) : m (Array α) := do
|
||||
if h : i < a.size then
|
||||
let idx := ⟨i, h⟩
|
||||
|
|
@ -158,7 +158,7 @@ def modifyOp (self : Array α) (idx : Nat) (f : α → α) : Array α :=
|
|||
loop 0 b
|
||||
|
||||
/-- Reference implementation for `forIn` -/
|
||||
@[implementedBy Array.forInUnsafe]
|
||||
@[implemented_by Array.forInUnsafe]
|
||||
protected def forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : Array α) (b : β) (f : α → β → m (ForInStep β)) : m β :=
|
||||
let rec loop (i : Nat) (h : i ≤ as.size) (b : β) : m β := do
|
||||
match i, h with
|
||||
|
|
@ -192,7 +192,7 @@ unsafe def foldlMUnsafe {α : Type u} {β : Type v} {m : Type v → Type w} [Mon
|
|||
pure init
|
||||
|
||||
/-- Reference implementation for `foldlM` -/
|
||||
@[implementedBy foldlMUnsafe]
|
||||
@[implemented_by foldlMUnsafe]
|
||||
def foldlM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : β → α → m β) (init : β) (as : Array α) (start := 0) (stop := as.size) : m β :=
|
||||
let fold (stop : Nat) (h : stop ≤ as.size) :=
|
||||
let rec loop (i : Nat) (j : Nat) (b : β) : m β := do
|
||||
|
|
@ -229,7 +229,7 @@ unsafe def foldrMUnsafe {α : Type u} {β : Type v} {m : Type v → Type w} [Mon
|
|||
pure init
|
||||
|
||||
/-- Reference implementation for `foldrM` -/
|
||||
@[implementedBy foldrMUnsafe]
|
||||
@[implemented_by foldrMUnsafe]
|
||||
def foldrM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : α → β → m β) (init : β) (as : Array α) (start := as.size) (stop := 0) : m β :=
|
||||
let rec fold (i : Nat) (h : i ≤ as.size) (b : β) : m β := do
|
||||
if i == stop then
|
||||
|
|
@ -267,7 +267,7 @@ unsafe def mapMUnsafe {α : Type u} {β : Type v} {m : Type v → Type w} [Monad
|
|||
unsafeCast <| map 0 (unsafeCast as)
|
||||
|
||||
/-- Reference implementation for `mapM` -/
|
||||
@[implementedBy mapMUnsafe]
|
||||
@[implemented_by mapMUnsafe]
|
||||
def mapM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : α → m β) (as : Array α) : m (Array β) :=
|
||||
as.foldlM (fun bs a => do let b ← f a; pure (bs.push b)) (mkEmpty as.size)
|
||||
|
||||
|
|
@ -327,7 +327,7 @@ unsafe def anyMUnsafe {α : Type u} {m : Type → Type w} [Monad m] (p : α →
|
|||
else
|
||||
pure false
|
||||
|
||||
@[implementedBy anyMUnsafe]
|
||||
@[implemented_by anyMUnsafe]
|
||||
def anyM {α : Type u} {m : Type → Type w} [Monad m] (p : α → m Bool) (as : Array α) (start := 0) (stop := as.size) : m Bool :=
|
||||
let any (stop : Nat) (h : stop ≤ as.size) :=
|
||||
let rec loop (j : Nat) : m Bool := do
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ where
|
|||
Monomorphic `Array.mapM`. The internal implementation uses pointer equality, and does not allocate a new array
|
||||
if the result of each `f a` is a pointer equal value `a`.
|
||||
-/
|
||||
@[implementedBy mapMonoMImp] def Array.mapMonoM [Monad m] (as : Array α) (f : α → m α) : m (Array α) :=
|
||||
@[implemented_by mapMonoMImp] def Array.mapMonoM [Monad m] (as : Array α) (f : α → m α) : m (Array α) :=
|
||||
as.mapM f
|
||||
|
||||
@[inline] def Array.mapMono (as : Array α) (f : α → α) : Array α :=
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ def popFront (s : Subarray α) : Subarray α :=
|
|||
loop (USize.ofNat s.start) b
|
||||
|
||||
-- TODO: provide reference implementation
|
||||
@[implementedBy Subarray.forInUnsafe]
|
||||
@[implemented_by Subarray.forInUnsafe]
|
||||
protected opaque forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (s : Subarray α) (b : β) (f : α → β → m (ForInStep β)) : m β :=
|
||||
pure b
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ partial def toList (bs : ByteArray) : List UInt8 :=
|
|||
loop 0 b
|
||||
|
||||
/-- Reference implementation for `forIn` -/
|
||||
@[implementedBy ByteArray.forInUnsafe]
|
||||
@[implemented_by ByteArray.forInUnsafe]
|
||||
protected def forIn {β : Type v} {m : Type v → Type w} [Monad m] (as : ByteArray) (b : β) (f : UInt8 → β → m (ForInStep β)) : m β :=
|
||||
let rec loop (i : Nat) (h : i ≤ as.size) (b : β) : m β := do
|
||||
match i, h with
|
||||
|
|
@ -156,7 +156,7 @@ unsafe def foldlMUnsafe {β : Type v} {m : Type v → Type w} [Monad m] (f : β
|
|||
pure init
|
||||
|
||||
/-- Reference implementation for `foldlM` -/
|
||||
@[implementedBy foldlMUnsafe]
|
||||
@[implemented_by foldlMUnsafe]
|
||||
def foldlM {β : Type v} {m : Type v → Type w} [Monad m] (f : β → UInt8 → m β) (init : β) (as : ByteArray) (start := 0) (stop := as.size) : m β :=
|
||||
let fold (stop : Nat) (h : stop ≤ as.size) :=
|
||||
let rec loop (i : Nat) (j : Nat) (b : β) : m β := do
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ partial def toList (ds : FloatArray) : List Float :=
|
|||
loop 0 b
|
||||
|
||||
/-- Reference implementation for `forIn` -/
|
||||
@[implementedBy FloatArray.forInUnsafe]
|
||||
@[implemented_by FloatArray.forInUnsafe]
|
||||
protected def forIn {β : Type v} {m : Type v → Type w} [Monad m] (as : FloatArray) (b : β) (f : Float → β → m (ForInStep β)) : m β :=
|
||||
let rec loop (i : Nat) (h : i ≤ as.size) (b : β) : m β := do
|
||||
match i, h with
|
||||
|
|
@ -137,7 +137,7 @@ unsafe def foldlMUnsafe {β : Type v} {m : Type v → Type w} [Monad m] (f : β
|
|||
pure init
|
||||
|
||||
/-- Reference implementation for `foldlM` -/
|
||||
@[implementedBy foldlMUnsafe]
|
||||
@[implemented_by foldlMUnsafe]
|
||||
def foldlM {β : Type v} {m : Type v → Type w} [Monad m] (f : β → Float → m β) (init : β) (as : FloatArray) (start := 0) (stop := as.size) : m β :=
|
||||
let fold (stop : Nat) (h : stop ≤ as.size) :=
|
||||
let rec loop (i : Nat) (j : Nat) (b : β) : m β := do
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ protected def mul (m n : @& Int) : Int :=
|
|||
#check -42
|
||||
```
|
||||
-/
|
||||
@[defaultInstance mid]
|
||||
@[default_instance mid]
|
||||
instance : Neg Int where
|
||||
neg := Int.neg
|
||||
instance : Add Int where
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ protected opaque Float.ofScientific (m : Nat) (s : Bool) (e : Nat) : Float :=
|
|||
#check -42.0 -- must be Float
|
||||
```
|
||||
-/
|
||||
@[defaultInstance mid+1]
|
||||
@[default_instance mid+1]
|
||||
instance : OfScientific Float where
|
||||
ofScientific := Float.ofScientific
|
||||
|
||||
|
|
|
|||
|
|
@ -43,19 +43,19 @@ def toMonad [Monad m] [Alternative m] : Option α → m α
|
|||
theorem map_id : (Option.map id : Option α → Option α) = id :=
|
||||
funext (fun o => match o with | none => rfl | some _ => rfl)
|
||||
|
||||
@[alwaysInline, inline] protected def filter (p : α → Bool) : Option α → Option α
|
||||
@[always_inline, inline] protected def filter (p : α → Bool) : Option α → Option α
|
||||
| some a => if p a then some a else none
|
||||
| none => none
|
||||
|
||||
@[alwaysInline, inline] protected def all (p : α → Bool) : Option α → Bool
|
||||
@[always_inline, inline] protected def all (p : α → Bool) : Option α → Bool
|
||||
| some a => p a
|
||||
| none => true
|
||||
|
||||
@[alwaysInline, inline] protected def any (p : α → Bool) : Option α → Bool
|
||||
@[always_inline, inline] protected def any (p : α → Bool) : Option α → Bool
|
||||
| some a => p a
|
||||
| none => false
|
||||
|
||||
@[alwaysInline, macroInline] protected def orElse : Option α → (Unit → Option α) → Option α
|
||||
@[always_inline, macro_inline] protected def orElse : Option α → (Unit → Option α) → Option α
|
||||
| some a, _ => some a
|
||||
| none, b => b ()
|
||||
|
||||
|
|
@ -89,16 +89,16 @@ deriving instance BEq for Option
|
|||
instance [LT α] : LT (Option α) where
|
||||
lt := Option.lt (· < ·)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Functor Option where
|
||||
map := Option.map
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad Option where
|
||||
pure := Option.some
|
||||
bind := Option.bind
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Alternative Option where
|
||||
failure := Option.none
|
||||
orElse := Option.orElse
|
||||
|
|
@ -107,7 +107,7 @@ def liftOption [Alternative m] : Option α → m α
|
|||
| some a => pure a
|
||||
| none => failure
|
||||
|
||||
@[alwaysInline, inline] protected def Option.tryCatch (x : Option α) (handle : Unit → Option α) : Option α :=
|
||||
@[always_inline, inline] protected def Option.tryCatch (x : Option α) (handle : Unit → Option α) : Option α :=
|
||||
match x with
|
||||
| some _ => x
|
||||
| none => handle ()
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ private unsafe def TypeName.typeNameImpl (α) [TypeName α] : Name :=
|
|||
/--
|
||||
Returns a declaration name of the type.
|
||||
-/
|
||||
@[implementedBy TypeName.typeNameImpl]
|
||||
@[implemented_by TypeName.typeNameImpl]
|
||||
opaque TypeName.typeName (α) [TypeName α] : Name
|
||||
|
||||
private opaque DynamicPointed : NonemptyType.{0} :=
|
||||
|
|
@ -72,7 +72,7 @@ private unsafe def Dynamic.typeNameImpl (any : Dynamic) : Name :=
|
|||
/--
|
||||
The name of the type of the value stored in the `Dynamic`.
|
||||
-/
|
||||
@[implementedBy Dynamic.typeNameImpl]
|
||||
@[implemented_by Dynamic.typeNameImpl]
|
||||
opaque Dynamic.typeName (any : Dynamic) : Name
|
||||
|
||||
private unsafe def Dynamic.get?Impl (α) (any : Dynamic) [TypeName α] : Option α :=
|
||||
|
|
@ -86,11 +86,11 @@ private unsafe def Dynamic.get?Impl (α) (any : Dynamic) [TypeName α] : Option
|
|||
Retrieves the value stored in the `Dynamic`.
|
||||
Returns `some a` if the value has the right type, and `none` otherwise.
|
||||
-/
|
||||
@[implementedBy Dynamic.get?Impl]
|
||||
@[implemented_by Dynamic.get?Impl]
|
||||
opaque Dynamic.get? (α) (any : Dynamic) [TypeName α] : Option α
|
||||
|
||||
private unsafe def Dynamic.mkImpl [TypeName α] (obj : α) : Dynamic :=
|
||||
unsafeCast (TypeName.typeName α, (unsafeCast obj : NonScalar))
|
||||
|
||||
@[implementedBy Dynamic.mkImpl]
|
||||
@[implemented_by Dynamic.mkImpl]
|
||||
opaque Dynamic.mk [TypeName α] (obj : α) : Dynamic
|
||||
|
|
|
|||
|
|
@ -248,23 +248,23 @@ especially when proving properties about the `ofNat` function itself.
|
|||
-/
|
||||
syntax (name := rawNatLit) "nat_lit " num : term
|
||||
|
||||
@[inheritDoc] infixr:90 " ∘ " => Function.comp
|
||||
@[inheritDoc] infixr:35 " × " => Prod
|
||||
@[inherit_doc] infixr:90 " ∘ " => Function.comp
|
||||
@[inherit_doc] infixr:35 " × " => Prod
|
||||
|
||||
@[inheritDoc] infixl:55 " ||| " => HOr.hOr
|
||||
@[inheritDoc] infixl:58 " ^^^ " => HXor.hXor
|
||||
@[inheritDoc] infixl:60 " &&& " => HAnd.hAnd
|
||||
@[inheritDoc] infixl:65 " + " => HAdd.hAdd
|
||||
@[inheritDoc] infixl:65 " - " => HSub.hSub
|
||||
@[inheritDoc] infixl:70 " * " => HMul.hMul
|
||||
@[inheritDoc] infixl:70 " / " => HDiv.hDiv
|
||||
@[inheritDoc] infixl:70 " % " => HMod.hMod
|
||||
@[inheritDoc] infixl:75 " <<< " => HShiftLeft.hShiftLeft
|
||||
@[inheritDoc] infixl:75 " >>> " => HShiftRight.hShiftRight
|
||||
@[inheritDoc] infixr:80 " ^ " => HPow.hPow
|
||||
@[inheritDoc] infixl:65 " ++ " => HAppend.hAppend
|
||||
@[inheritDoc] prefix:100 "-" => Neg.neg
|
||||
@[inheritDoc] prefix:100 "~~~" => Complement.complement
|
||||
@[inherit_doc] infixl:55 " ||| " => HOr.hOr
|
||||
@[inherit_doc] infixl:58 " ^^^ " => HXor.hXor
|
||||
@[inherit_doc] infixl:60 " &&& " => HAnd.hAnd
|
||||
@[inherit_doc] infixl:65 " + " => HAdd.hAdd
|
||||
@[inherit_doc] infixl:65 " - " => HSub.hSub
|
||||
@[inherit_doc] infixl:70 " * " => HMul.hMul
|
||||
@[inherit_doc] infixl:70 " / " => HDiv.hDiv
|
||||
@[inherit_doc] infixl:70 " % " => HMod.hMod
|
||||
@[inherit_doc] infixl:75 " <<< " => HShiftLeft.hShiftLeft
|
||||
@[inherit_doc] infixl:75 " >>> " => HShiftRight.hShiftRight
|
||||
@[inherit_doc] infixr:80 " ^ " => HPow.hPow
|
||||
@[inherit_doc] infixl:65 " ++ " => HAppend.hAppend
|
||||
@[inherit_doc] prefix:100 "-" => Neg.neg
|
||||
@[inherit_doc] prefix:100 "~~~" => Complement.complement
|
||||
|
||||
/-!
|
||||
Remark: the infix commands above ensure a delaborator is generated for each relations.
|
||||
|
|
@ -282,14 +282,14 @@ macro_rules | `($x ^ $y) => `(binop% HPow.hPow $x $y)
|
|||
macro_rules | `($x ++ $y) => `(binop% HAppend.hAppend $x $y)
|
||||
|
||||
-- declare ASCII alternatives first so that the latter Unicode unexpander wins
|
||||
@[inheritDoc] infix:50 " <= " => LE.le
|
||||
@[inheritDoc] infix:50 " ≤ " => LE.le
|
||||
@[inheritDoc] infix:50 " < " => LT.lt
|
||||
@[inheritDoc] infix:50 " >= " => GE.ge
|
||||
@[inheritDoc] infix:50 " ≥ " => GE.ge
|
||||
@[inheritDoc] infix:50 " > " => GT.gt
|
||||
@[inheritDoc] infix:50 " = " => Eq
|
||||
@[inheritDoc] infix:50 " == " => BEq.beq
|
||||
@[inherit_doc] infix:50 " <= " => LE.le
|
||||
@[inherit_doc] infix:50 " ≤ " => LE.le
|
||||
@[inherit_doc] infix:50 " < " => LT.lt
|
||||
@[inherit_doc] infix:50 " >= " => GE.ge
|
||||
@[inherit_doc] infix:50 " ≥ " => GE.ge
|
||||
@[inherit_doc] infix:50 " > " => GT.gt
|
||||
@[inherit_doc] infix:50 " = " => Eq
|
||||
@[inherit_doc] infix:50 " == " => BEq.beq
|
||||
/-!
|
||||
Remark: the infix commands above ensure a delaborator is generated for each relations.
|
||||
We redefine the macros below to be able to use the auxiliary `binrel%` elaboration helper for binary relations.
|
||||
|
|
@ -305,28 +305,28 @@ macro_rules | `($x ≥ $y) => `(binrel% GE.ge $x $y)
|
|||
macro_rules | `($x = $y) => `(binrel% Eq $x $y)
|
||||
macro_rules | `($x == $y) => `(binrel_no_prop% BEq.beq $x $y)
|
||||
|
||||
@[inheritDoc] infixr:35 " /\\ " => And
|
||||
@[inheritDoc] infixr:35 " ∧ " => And
|
||||
@[inheritDoc] infixr:30 " \\/ " => Or
|
||||
@[inheritDoc] infixr:30 " ∨ " => Or
|
||||
@[inheritDoc] notation:max "¬" p:40 => Not p
|
||||
@[inherit_doc] infixr:35 " /\\ " => And
|
||||
@[inherit_doc] infixr:35 " ∧ " => And
|
||||
@[inherit_doc] infixr:30 " \\/ " => Or
|
||||
@[inherit_doc] infixr:30 " ∨ " => Or
|
||||
@[inherit_doc] notation:max "¬" p:40 => Not p
|
||||
|
||||
@[inheritDoc] infixl:35 " && " => and
|
||||
@[inheritDoc] infixl:30 " || " => or
|
||||
@[inheritDoc] notation:max "!" b:40 => not b
|
||||
@[inherit_doc] infixl:35 " && " => and
|
||||
@[inherit_doc] infixl:30 " || " => or
|
||||
@[inherit_doc] notation:max "!" b:40 => not b
|
||||
|
||||
@[inheritDoc] infix:50 " ∈ " => Membership.mem
|
||||
@[inherit_doc] infix:50 " ∈ " => Membership.mem
|
||||
/-- `a ∉ b` is negated elementhood. It is notation for `¬ (a ∈ b)`. -/
|
||||
notation:50 a:50 " ∉ " b:50 => ¬ (a ∈ b)
|
||||
|
||||
@[inheritDoc] infixr:67 " :: " => List.cons
|
||||
@[inheritDoc HOrElse.hOrElse] syntax:20 term:21 " <|> " term:20 : term
|
||||
@[inheritDoc HAndThen.hAndThen] syntax:60 term:61 " >> " term:60 : term
|
||||
@[inheritDoc] infixl:55 " >>= " => Bind.bind
|
||||
@[inheritDoc] notation:60 a:60 " <*> " b:61 => Seq.seq a fun _ : Unit => b
|
||||
@[inheritDoc] notation:60 a:60 " <* " b:61 => SeqLeft.seqLeft a fun _ : Unit => b
|
||||
@[inheritDoc] notation:60 a:60 " *> " b:61 => SeqRight.seqRight a fun _ : Unit => b
|
||||
@[inheritDoc] infixr:100 " <$> " => Functor.map
|
||||
@[inherit_doc] infixr:67 " :: " => List.cons
|
||||
@[inherit_doc HOrElse.hOrElse] syntax:20 term:21 " <|> " term:20 : term
|
||||
@[inherit_doc HAndThen.hAndThen] syntax:60 term:61 " >> " term:60 : term
|
||||
@[inherit_doc] infixl:55 " >>= " => Bind.bind
|
||||
@[inherit_doc] notation:60 a:60 " <*> " b:61 => Seq.seq a fun _ : Unit => b
|
||||
@[inherit_doc] notation:60 a:60 " <* " b:61 => SeqLeft.seqLeft a fun _ : Unit => b
|
||||
@[inherit_doc] notation:60 a:60 " *> " b:61 => SeqRight.seqRight a fun _ : Unit => b
|
||||
@[inherit_doc] infixr:100 " <$> " => Functor.map
|
||||
|
||||
macro_rules | `($x <|> $y) => `(binop_lazy% HOrElse.hOrElse $x $y)
|
||||
macro_rules | `($x >> $y) => `(binop_lazy% HAndThen.hAndThen $x $y)
|
||||
|
|
@ -350,7 +350,7 @@ syntax caseArg := binderIdent binderIdent*
|
|||
end Parser.Tactic
|
||||
end Lean
|
||||
|
||||
@[inheritDoc dite] syntax (name := termDepIfThenElse)
|
||||
@[inherit_doc dite] syntax (name := termDepIfThenElse)
|
||||
ppRealGroup(ppRealFill(ppIndent("if " Lean.binderIdent " : " term " then") ppSpace term)
|
||||
ppDedent(ppSpace) ppRealFill("else " term)) : term
|
||||
|
||||
|
|
@ -362,7 +362,7 @@ macro_rules
|
|||
let mvar ← Lean.withRef c `(?m)
|
||||
`(let_mvar% ?m := $c; wait_if_type_mvar% ?m; dite $mvar (fun _%$h => $t) (fun _%$h => $e))
|
||||
|
||||
@[inheritDoc ite] syntax (name := termIfThenElse)
|
||||
@[inherit_doc ite] syntax (name := termIfThenElse)
|
||||
ppRealGroup(ppRealFill(ppIndent("if " term " then") ppSpace term)
|
||||
ppDedent(ppSpace) ppRealFill("else " term)) : term
|
||||
|
||||
|
|
@ -384,7 +384,7 @@ If the pattern does not match, it returns `e` instead.
|
|||
macro "if " "let " pat:term " := " d:term " then " t:term " else " e:term : term =>
|
||||
`(match $d:term with | $pat => $t | _ => $e)
|
||||
|
||||
@[inheritDoc cond] syntax (name := boolIfThenElse)
|
||||
@[inherit_doc cond] syntax (name := boolIfThenElse)
|
||||
ppRealGroup(ppRealFill(ppIndent("bif " term " then") ppSpace term)
|
||||
ppDedent(ppSpace) ppRealFill("else " term)) : term
|
||||
|
||||
|
|
@ -424,7 +424,7 @@ macro_rules
|
|||
| `($f $args* $ $a) => `($f $args* $a)
|
||||
| `($f $ $a) => `($f $a)
|
||||
|
||||
@[inheritDoc Subtype] syntax "{ " ident (" : " term)? " // " term " }" : term
|
||||
@[inherit_doc Subtype] syntax "{ " ident (" : " term)? " // " term " }" : term
|
||||
|
||||
macro_rules
|
||||
| `({ $x : $type // $p }) => ``(Subtype (fun ($x:ident : $type) => $p))
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ macro_rules
|
|||
for (c₁, c₂) in cs₁.zip cs₂ |>.reverse do
|
||||
body ← `($c₁ = $c₂ → $body)
|
||||
let hint : Ident ← `(hint)
|
||||
`($[$doc?:docComment]? @[$kind unificationHint] def $(n.getD hint) $bs* : Sort _ := $body)
|
||||
`($[$doc?:docComment]? @[$kind unification_hint] def $(n.getD hint) $bs* : Sort _ := $body)
|
||||
end Lean
|
||||
|
||||
open Lean
|
||||
|
|
@ -133,153 +133,153 @@ See [Theorem Proving in Lean 4][tpil4] for more information.
|
|||
-/
|
||||
syntax (name := calcTactic) "calc" ppLine withPosition(calcStep) ppLine withPosition((calcStep ppLine)*) : tactic
|
||||
|
||||
@[appUnexpander Unit.unit] def unexpandUnit : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Unit.unit] def unexpandUnit : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_)) => `(())
|
||||
|
||||
@[appUnexpander List.nil] def unexpandListNil : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander List.nil] def unexpandListNil : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_)) => `([])
|
||||
|
||||
@[appUnexpander List.cons] def unexpandListCons : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander List.cons] def unexpandListCons : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $x []) => `([$x])
|
||||
| `($(_) $x [$xs,*]) => `([$x, $xs,*])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander List.toArray] def unexpandListToArray : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander List.toArray] def unexpandListToArray : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) [$xs,*]) => `(#[$xs,*])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Prod.mk] def unexpandProdMk : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Prod.mk] def unexpandProdMk : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $x ($y, $ys,*)) => `(($x, $y, $ys,*))
|
||||
| `($(_) $x $y) => `(($x, $y))
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander ite] def unexpandIte : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander ite] def unexpandIte : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $c $t $e) => `(if $c then $t else $e)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander sorryAx] def unexpandSorryAx : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander sorryAx] def unexpandSorryAx : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) _) => `(sorry)
|
||||
| `($(_) _ _) => `(sorry)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Eq.ndrec] def unexpandEqNDRec : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Eq.ndrec] def unexpandEqNDRec : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $m $h) => `($h ▸ $m)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Eq.rec] def unexpandEqRec : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Eq.rec] def unexpandEqRec : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $m $h) => `($h ▸ $m)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Exists] def unexpandExists : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Exists] def unexpandExists : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) fun $x:ident => ∃ $xs:binderIdent*, $b) => `(∃ $x:ident $xs:binderIdent*, $b)
|
||||
| `($(_) fun $x:ident => $b) => `(∃ $x:ident, $b)
|
||||
| `($(_) fun ($x:ident : $t) => $b) => `(∃ ($x:ident : $t), $b)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Sigma] def unexpandSigma : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Sigma] def unexpandSigma : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) fun ($x:ident : $t) => $b) => `(($x:ident : $t) × $b)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander PSigma] def unexpandPSigma : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander PSigma] def unexpandPSigma : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) fun ($x:ident : $t) => $b) => `(($x:ident : $t) ×' $b)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Subtype] def unexpandSubtype : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Subtype] def unexpandSubtype : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) fun ($x:ident : $type) => $p) => `({ $x : $type // $p })
|
||||
| `($(_) fun $x:ident => $p) => `({ $x // $p })
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander TSyntax] def unexpandTSyntax : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander TSyntax] def unexpandTSyntax : Lean.PrettyPrinter.Unexpander
|
||||
| `($f [$k]) => `($f $k)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander TSyntaxArray] def unexpandTSyntaxArray : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander TSyntaxArray] def unexpandTSyntaxArray : Lean.PrettyPrinter.Unexpander
|
||||
| `($f [$k]) => `($f $k)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Syntax.TSepArray] def unexpandTSepArray : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Syntax.TSepArray] def unexpandTSepArray : Lean.PrettyPrinter.Unexpander
|
||||
| `($f [$k] $sep) => `($f $k $sep)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander GetElem.getElem] def unexpandGetElem : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander GetElem.getElem] def unexpandGetElem : Lean.PrettyPrinter.Unexpander
|
||||
| `($_ $array $index $_) => `($array[$index])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander getElem!] def unexpandGetElem! : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander getElem!] def unexpandGetElem! : Lean.PrettyPrinter.Unexpander
|
||||
| `($_ $array $index) => `($array[$index]!)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander getElem?] def unexpandGetElem? : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander getElem?] def unexpandGetElem? : Lean.PrettyPrinter.Unexpander
|
||||
| `($_ $array $index) => `($array[$index]?)
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr1] def unexpandMkStr1 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr1] def unexpandMkStr1 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr2] def unexpandMkStr2 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr2] def unexpandMkStr2 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1:str $a2:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a1.getString}.{a2.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr3] def unexpandMkStr3 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr3] def unexpandMkStr3 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1:str $a2:str $a3:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a1.getString}.{a2.getString}.{a3.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr4] def unexpandMkStr4 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr4] def unexpandMkStr4 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1:str $a2:str $a3:str $a4:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a1.getString}.{a2.getString}.{a3.getString}.{a4.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr5] def unexpandMkStr5 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr5] def unexpandMkStr5 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1:str $a2:str $a3:str $a4:str $a5:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a1.getString}.{a2.getString}.{a3.getString}.{a4.getString}.{a5.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr6] def unexpandMkStr6 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr6] def unexpandMkStr6 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1:str $a2:str $a3:str $a4:str $a5:str $a6:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a1.getString}.{a2.getString}.{a3.getString}.{a4.getString}.{a5.getString}.{a6.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr7] def unexpandMkStr7 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr7] def unexpandMkStr7 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1:str $a2:str $a3:str $a4:str $a5:str $a6:str $a7:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a1.getString}.{a2.getString}.{a3.getString}.{a4.getString}.{a5.getString}.{a6.getString}.{a7.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Name.mkStr8] def unexpandMkStr8 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Name.mkStr8] def unexpandMkStr8 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1:str $a2:str $a3:str $a4:str $a5:str $a6:str $a7:str $a8:str) => return mkNode `Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{a1.getString}.{a2.getString}.{a3.getString}.{a4.getString}.{a5.getString}.{a6.getString}.{a7.getString}.{a8.getString}"]
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.empty] def unexpandArrayEmpty : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.empty] def unexpandArrayEmpty : Lean.PrettyPrinter.Unexpander
|
||||
| _ => `(#[])
|
||||
|
||||
@[appUnexpander Array.mkArray0] def unexpandMkArray0 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray0] def unexpandMkArray0 : Lean.PrettyPrinter.Unexpander
|
||||
| _ => `(#[])
|
||||
|
||||
@[appUnexpander Array.mkArray1] def unexpandMkArray1 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray1] def unexpandMkArray1 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1) => `(#[$a1])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.mkArray2] def unexpandMkArray2 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray2] def unexpandMkArray2 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1 $a2) => `(#[$a1, $a2])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.mkArray3] def unexpandMkArray3 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray3] def unexpandMkArray3 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1 $a2 $a3) => `(#[$a1, $a2, $a3])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.mkArray4] def unexpandMkArray4 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray4] def unexpandMkArray4 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1 $a2 $a3 $a4) => `(#[$a1, $a2, $a3, $a4])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.mkArray5] def unexpandMkArray5 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray5] def unexpandMkArray5 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1 $a2 $a3 $a4 $a5) => `(#[$a1, $a2, $a3, $a4, $a5])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.mkArray6] def unexpandMkArray6 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray6] def unexpandMkArray6 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1 $a2 $a3 $a4 $a5 $a6) => `(#[$a1, $a2, $a3, $a4, $a5, $a6])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.mkArray7] def unexpandMkArray7 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray7] def unexpandMkArray7 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1 $a2 $a3 $a4 $a5 $a6 $a7) => `(#[$a1, $a2, $a3, $a4, $a5, $a6, $a7])
|
||||
| _ => throw ()
|
||||
|
||||
@[appUnexpander Array.mkArray8] def unexpandMkArray8 : Lean.PrettyPrinter.Unexpander
|
||||
@[app_unexpander Array.mkArray8] def unexpandMkArray8 : Lean.PrettyPrinter.Unexpander
|
||||
| `($(_) $a1 $a2 $a3 $a4 $a5 $a6 $a7 $a8) => `(#[$a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8])
|
||||
| _ => throw ()
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ abbrev Unit : Type := PUnit
|
|||
`Unit.unit : Unit` is the canonical element of the unit type.
|
||||
It can also be written as `()`.
|
||||
-/
|
||||
@[matchPattern] abbrev Unit.unit : Unit := PUnit.unit
|
||||
@[match_pattern] abbrev Unit.unit : Unit := PUnit.unit
|
||||
|
||||
/-- Marker for information that has been erased by the code generator. -/
|
||||
unsafe axiom lcErased : Type
|
||||
|
|
@ -220,7 +220,7 @@ instruction: it is **undefined behavior** to run, but it will probably print
|
|||
"unreachable code". (You would need to construct a proof of false to run it
|
||||
anyway, which you can only do using `sorry` or unsound axioms.)
|
||||
-/
|
||||
@[macroInline] def False.elim {C : Sort u} (h : False) : C :=
|
||||
@[macro_inline] def False.elim {C : Sort u} (h : False) : C :=
|
||||
h.rec
|
||||
|
||||
/--
|
||||
|
|
@ -230,7 +230,7 @@ example (hp : p) (hnp : ¬p) : q := absurd hp hnp
|
|||
```
|
||||
For more information: [Propositional Logic](https://leanprover.github.io/theorem_proving_in_lean4/propositions_and_proofs.html#propositional-logic)
|
||||
-/
|
||||
@[macroInline] def absurd {a : Prop} {b : Sort v} (h₁ : a) (h₂ : Not a) : b :=
|
||||
@[macro_inline] def absurd {a : Prop} {b : Sort v} (h₁ : a) (h₂ : Not a) : b :=
|
||||
(h₂ h₁).rec
|
||||
|
||||
/--
|
||||
|
|
@ -278,7 +278,7 @@ the statement of the theorem is `a = a`, lean will allow anything that is
|
|||
definitionally equal to that type. So, for instance, `2 + 2 = 4` is proven in
|
||||
lean by `rfl`, because both sides are the same up to definitional equality.
|
||||
-/
|
||||
@[matchPattern] def rfl {α : Sort u} {a : α} : Eq a a := Eq.refl a
|
||||
@[match_pattern] def rfl {α : Sort u} {a : α} : Eq a a := Eq.refl a
|
||||
|
||||
/-- `id x = x`, as a `@[simp]` lemma. -/
|
||||
@[simp] theorem id_eq (a : α) : Eq (id a) a := rfl
|
||||
|
|
@ -333,7 +333,7 @@ definitionally sometimes there isn't anything better you can do.
|
|||
|
||||
For more information: [Equality](https://leanprover.github.io/theorem_proving_in_lean4/quantifiers_and_equality.html#equality)
|
||||
-/
|
||||
@[macroInline] def cast {α β : Sort u} (h : Eq α β) (a : α) : β :=
|
||||
@[macro_inline] def cast {α β : Sort u} (h : Eq α β) (a : α) : β :=
|
||||
h.rec a
|
||||
|
||||
/--
|
||||
|
|
@ -445,7 +445,7 @@ inductive HEq : {α : Sort u} → α → {β : Sort u} → β → Prop where
|
|||
| refl (a : α) : HEq a a
|
||||
|
||||
/-- A version of `HEq.refl` with an implicit argument. -/
|
||||
@[matchPattern] protected def HEq.rfl {α : Sort u} {a : α} : HEq a a :=
|
||||
@[match_pattern] protected def HEq.rfl {α : Sort u} {a : α} : HEq a a :=
|
||||
HEq.refl a
|
||||
|
||||
theorem eq_of_heq {α : Sort u} {a a' : α} (h : HEq a a') : Eq a a' :=
|
||||
|
|
@ -614,7 +614,7 @@ in the expression. A synthetic `sorry` acts like a regular one, except that it
|
|||
suppresses follow-up errors in order to prevent one error from causing a cascade
|
||||
of other errors because the desired term was not constructed.
|
||||
-/
|
||||
@[extern "lean_sorry", neverExtract]
|
||||
@[extern "lean_sorry", never_extract]
|
||||
axiom sorryAx (α : Sort u) (synthetic := false) : α
|
||||
|
||||
theorem eq_false_of_ne_true : {b : Bool} → Not (Eq b true) → Eq b false
|
||||
|
|
@ -796,7 +796,7 @@ Convert a decidable proposition into a boolean value.
|
|||
If `p : Prop` is decidable, then `decide p : Bool` is the boolean value
|
||||
which is `true` if `p` is true and `false` if `p` is false.
|
||||
-/
|
||||
@[inlineIfReduce, nospecialize] def Decidable.decide (p : Prop) [h : Decidable p] : Bool :=
|
||||
@[inline_if_reduce, nospecialize] def Decidable.decide (p : Prop) [h : Decidable p] : Bool :=
|
||||
h.casesOn (fun _ => false) (fun _ => true)
|
||||
|
||||
export Decidable (isTrue isFalse decide)
|
||||
|
|
@ -887,7 +887,7 @@ to avoid the bounds check inside the if branch. (Of course in this case we have
|
|||
lifted the check into an explicit `if`, but we could also use this proof multiple times
|
||||
or derive `i < arr.size` from some other proposition that we are checking in the `if`.)
|
||||
-/
|
||||
@[macroInline] def dite {α : Sort u} (c : Prop) [h : Decidable c] (t : c → α) (e : Not c → α) : α :=
|
||||
@[macro_inline] def dite {α : Sort u} (c : Prop) [h : Decidable c] (t : c → α) (e : Not c → α) : α :=
|
||||
h.casesOn e t
|
||||
|
||||
/-! # if-then-else -/
|
||||
|
|
@ -904,15 +904,15 @@ function is problematic in that it would require `t` and `e` to be evaluated bef
|
|||
calling the `ite` function, which would cause both sides of the `if` to be evaluated.
|
||||
Even if the result is discarded, this would be a big performance problem,
|
||||
and is undesirable for users in any case. To resolve this, `ite` is marked as
|
||||
`@[macroInline]`, which means that it is unfolded during code generation, and
|
||||
`@[macro_inline]`, which means that it is unfolded during code generation, and
|
||||
the definition of the function uses `fun _ => t` and `fun _ => e` so this recovers
|
||||
the expected "lazy" behavior of `if`: the `t` and `e` arguments delay evaluation
|
||||
until `c` is known.
|
||||
-/
|
||||
@[macroInline] def ite {α : Sort u} (c : Prop) [h : Decidable c] (t e : α) : α :=
|
||||
@[macro_inline] def ite {α : Sort u} (c : Prop) [h : Decidable c] (t e : α) : α :=
|
||||
h.casesOn (fun _ => e) (fun _ => t)
|
||||
|
||||
@[macroInline] instance {p q} [dp : Decidable p] [dq : Decidable q] : Decidable (And p q) :=
|
||||
@[macro_inline] instance {p q} [dp : Decidable p] [dq : Decidable q] : Decidable (And p q) :=
|
||||
match dp with
|
||||
| isTrue hp =>
|
||||
match dq with
|
||||
|
|
@ -921,7 +921,7 @@ until `c` is known.
|
|||
| isFalse hp =>
|
||||
isFalse (fun h => hp (And.left h))
|
||||
|
||||
@[macroInline] instance [dp : Decidable p] [dq : Decidable q] : Decidable (Or p q) :=
|
||||
@[macro_inline] instance [dp : Decidable p] [dq : Decidable q] : Decidable (Or p q) :=
|
||||
match dp with
|
||||
| isTrue hp => isTrue (Or.inl hp)
|
||||
| isFalse hp =>
|
||||
|
|
@ -942,10 +942,10 @@ instance [dp : Decidable p] : Decidable (Not p) :=
|
|||
/--
|
||||
`cond b x y` is the same as `if b then x else y`, but optimized for a
|
||||
boolean condition. It can also be written as `bif b then x else y`.
|
||||
This is `@[macroInline]` because `x` and `y` should not
|
||||
This is `@[macro_inline]` because `x` and `y` should not
|
||||
be eagerly evaluated (see `ite`).
|
||||
-/
|
||||
@[macroInline] def cond {α : Type u} (c : Bool) (x y : α) : α :=
|
||||
@[macro_inline] def cond {α : Type u} (c : Bool) (x y : α) : α :=
|
||||
match c with
|
||||
| true => x
|
||||
| false => y
|
||||
|
|
@ -953,10 +953,10 @@ be eagerly evaluated (see `ite`).
|
|||
/--
|
||||
`or x y`, or `x || y`, is the boolean "or" operation (not to be confused
|
||||
with `Or : Prop → Prop → Prop`, which is the propositional connective).
|
||||
It is `@[macroInline]` because it has C-like short-circuiting behavior:
|
||||
It is `@[macro_inline]` because it has C-like short-circuiting behavior:
|
||||
if `x` is true then `y` is not evaluated.
|
||||
-/
|
||||
@[macroInline] def or (x y : Bool) : Bool :=
|
||||
@[macro_inline] def or (x y : Bool) : Bool :=
|
||||
match x with
|
||||
| true => true
|
||||
| false => y
|
||||
|
|
@ -964,10 +964,10 @@ if `x` is true then `y` is not evaluated.
|
|||
/--
|
||||
`and x y`, or `x && y`, is the boolean "and" operation (not to be confused
|
||||
with `And : Prop → Prop → Prop`, which is the propositional connective).
|
||||
It is `@[macroInline]` because it has C-like short-circuiting behavior:
|
||||
It is `@[macro_inline]` because it has C-like short-circuiting behavior:
|
||||
if `x` is false then `y` is not evaluated.
|
||||
-/
|
||||
@[macroInline] def and (x y : Bool) : Bool :=
|
||||
@[macro_inline] def and (x y : Bool) : Bool :=
|
||||
match x with
|
||||
| false => false
|
||||
| true => y
|
||||
|
|
@ -1042,7 +1042,7 @@ class OfNat (α : Type u) (_ : Nat) where
|
|||
`α`. -/
|
||||
ofNat : α
|
||||
|
||||
@[defaultInstance 100] /- low prio -/
|
||||
@[default_instance 100] /- low prio -/
|
||||
instance (n : Nat) : OfNat Nat n where
|
||||
ofNat := n
|
||||
|
||||
|
|
@ -1326,59 +1326,59 @@ class ShiftRight (α : Type u) where
|
|||
/-- The implementation of `a >>> b : α`. See `HShiftRight`. -/
|
||||
shiftRight : α → α → α
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Add α] : HAdd α α α where
|
||||
hAdd a b := Add.add a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Sub α] : HSub α α α where
|
||||
hSub a b := Sub.sub a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Mul α] : HMul α α α where
|
||||
hMul a b := Mul.mul a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Div α] : HDiv α α α where
|
||||
hDiv a b := Div.div a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Mod α] : HMod α α α where
|
||||
hMod a b := Mod.mod a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Pow α β] : HPow α β α where
|
||||
hPow a b := Pow.pow a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Append α] : HAppend α α α where
|
||||
hAppend a b := Append.append a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [OrElse α] : HOrElse α α α where
|
||||
hOrElse a b := OrElse.orElse a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [AndThen α] : HAndThen α α α where
|
||||
hAndThen a b := AndThen.andThen a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [AndOp α] : HAnd α α α where
|
||||
hAnd a b := AndOp.and a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [Xor α] : HXor α α α where
|
||||
hXor a b := Xor.xor a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [OrOp α] : HOr α α α where
|
||||
hOr a b := OrOp.or a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [ShiftLeft α] : HShiftLeft α α α where
|
||||
hShiftLeft a b := ShiftLeft.shiftLeft a b
|
||||
|
||||
@[defaultInstance]
|
||||
@[default_instance]
|
||||
instance [ShiftRight α] : HShiftRight α α α where
|
||||
hShiftRight a b := ShiftRight.shiftRight a b
|
||||
|
||||
|
|
@ -1414,7 +1414,7 @@ instance : Add Nat where
|
|||
|
||||
/- We mark the following definitions as pattern to make sure they can be used in recursive equations,
|
||||
and reduced by the equation Compiler. -/
|
||||
attribute [matchPattern] Nat.add Add.add HAdd.hAdd Neg.neg
|
||||
attribute [match_pattern] Nat.add Add.add HAdd.hAdd Neg.neg
|
||||
|
||||
set_option bootstrap.genMatcherCode false in
|
||||
/--
|
||||
|
|
@ -2034,7 +2034,7 @@ def Char.ofNatAux (n : @& Nat) (h : n.isValidChar) : Char :=
|
|||
Convert a `Nat` into a `Char`. If the `Nat` does not encode a valid unicode scalar value,
|
||||
`'\0'` is returned instead.
|
||||
-/
|
||||
@[noinline, matchPattern]
|
||||
@[noinline, match_pattern]
|
||||
def Char.ofNat (n : Nat) : Char :=
|
||||
dite (n.isValidChar)
|
||||
(fun h => Char.ofNatAux n h)
|
||||
|
|
@ -2114,10 +2114,10 @@ instance {α} : Inhabited (Option α) where
|
|||
Get with default. If `opt : Option α` and `dflt : α`, then `opt.getD dflt`
|
||||
returns `a` if `opt = some a` and `dflt` otherwise.
|
||||
|
||||
This function is `@[macroInline]`, so `dflt` will not be evaluated unless
|
||||
This function is `@[macro_inline]`, so `dflt` will not be evaluated unless
|
||||
`opt` turns out to be `none`.
|
||||
-/
|
||||
@[macroInline] def Option.getD : Option α → α → α
|
||||
@[macro_inline] def Option.getD : Option α → α → α
|
||||
| some x, _ => x
|
||||
| none, e => e
|
||||
|
||||
|
|
@ -2385,7 +2385,7 @@ will prevent the the actual monad from being "copied" to the code being speciali
|
|||
When we reimplement the specializer, we may consider copying `inst` if it also
|
||||
occurs outside binders or if it is an instance.
|
||||
-/
|
||||
@[neverExtract, extern "lean_panic_fn"]
|
||||
@[never_extract, extern "lean_panic_fn"]
|
||||
def panicCore {α : Type u} [Inhabited α] (msg : String) : α := default
|
||||
|
||||
/--
|
||||
|
|
@ -2399,7 +2399,7 @@ Because this is a pure function with side effects, it is marked as
|
|||
`@[never_extract]` so that the compiler will not perform common sub-expression
|
||||
elimination and other optimizations that assume that the expression is pure.
|
||||
-/
|
||||
@[noinline, neverExtract]
|
||||
@[noinline, never_extract]
|
||||
def panic {α : Type u} [Inhabited α] (msg : String) : α :=
|
||||
panicCore msg
|
||||
|
||||
|
|
@ -2579,13 +2579,13 @@ protected def Array.appendCore {α : Type u} (as : Array α) (bs : Array α) :
|
|||
loop bs.size 0 as
|
||||
|
||||
/-- Auxiliary definition for `List.toArray`. -/
|
||||
@[inlineIfReduce]
|
||||
@[inline_if_reduce]
|
||||
def List.toArrayAux : List α → Array α → Array α
|
||||
| nil, r => r
|
||||
| cons a as, r => toArrayAux as (r.push a)
|
||||
|
||||
/-- A non-tail-recursive version of `List.length`, used for `List.toArray`. -/
|
||||
@[inlineIfReduce]
|
||||
@[inline_if_reduce]
|
||||
def List.redLength : List α → Nat
|
||||
| nil => 0
|
||||
| cons _ as => as.redLength.succ
|
||||
|
|
@ -2596,7 +2596,7 @@ Convert a `List α` into an `Array α`. This is O(n) in the length of the list.
|
|||
This function is exported to C, where it is called by `Array.mk`
|
||||
(the constructor) to implement this functionality.
|
||||
-/
|
||||
@[inline, matchPattern, export lean_list_to_array]
|
||||
@[inline, match_pattern, export lean_list_to_array]
|
||||
def List.toArray (as : List α) : Array α :=
|
||||
as.toArrayAux (Array.mkEmpty as.redLength)
|
||||
|
||||
|
|
@ -2746,7 +2746,7 @@ export MonadLiftT (monadLift)
|
|||
/-- Lifts a value from monad `m` into monad `n`. -/
|
||||
abbrev liftM := @monadLift
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (m n o) [MonadLift n o] [MonadLiftT m n] : MonadLiftT m o where
|
||||
monadLift x := MonadLift.monadLift (m := n) (monadLift x)
|
||||
|
||||
|
|
@ -2775,7 +2775,7 @@ class MonadFunctorT (m : Type u → Type v) (n : Type u → Type w) where
|
|||
|
||||
export MonadFunctorT (monadMap)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (m n o) [MonadFunctor n o] [MonadFunctorT m n] : MonadFunctorT m o where
|
||||
monadMap f := MonadFunctor.monadMap (m := n) (monadMap (m := m) f)
|
||||
|
||||
|
|
@ -2886,7 +2886,7 @@ instance (ρ : Type u) (m : Type u → Type v) (α : Type u) [Inhabited (m α)]
|
|||
If `x : ReaderT ρ m α` and `r : ρ`, then `x.run r : ρ` runs the monad with the
|
||||
given reader state.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def ReaderT.run {ρ : Type u} {m : Type u → Type v} {α : Type u} (x : ReaderT ρ m α) (r : ρ) : m α :=
|
||||
x r
|
||||
|
||||
|
|
@ -2898,7 +2898,7 @@ variable {ρ : Type u} {m : Type u → Type v} {α : Type u}
|
|||
instance : MonadLift m (ReaderT ρ m) where
|
||||
monadLift x := fun _ => x
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (ReaderT ρ m) where
|
||||
throw e := liftM (m := m) (throw e)
|
||||
tryCatch := fun x c r => tryCatchThe ε (x r) (fun e => (c e) r)
|
||||
|
|
@ -2909,26 +2909,26 @@ section
|
|||
variable {ρ : Type u} {m : Type u → Type v}
|
||||
|
||||
/-- `(← read) : ρ` gets the read-only state of a `ReaderT ρ`. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def read [Monad m] : ReaderT ρ m ρ :=
|
||||
pure
|
||||
|
||||
/-- The `pure` operation of the `ReaderT` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def pure [Monad m] {α} (a : α) : ReaderT ρ m α :=
|
||||
fun _ => pure a
|
||||
|
||||
/-- The `bind` operation of the `ReaderT` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def bind [Monad m] {α β} (x : ReaderT ρ m α) (f : α → ReaderT ρ m β) : ReaderT ρ m β :=
|
||||
fun r => bind (x r) fun a => f a r
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance [Monad m] : Functor (ReaderT ρ m) where
|
||||
map f x r := Functor.map f (x r)
|
||||
mapConst a x r := Functor.mapConst a (x r)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance [Monad m] : Applicative (ReaderT ρ m) where
|
||||
pure := ReaderT.pure
|
||||
seq f x r := Seq.seq (f r) fun _ => x () r
|
||||
|
|
@ -2945,7 +2945,7 @@ instance (ρ m) : MonadFunctor m (ReaderT ρ m) where
|
|||
`adapt (f : ρ' → ρ)` precomposes function `f` on the reader state of a
|
||||
`ReaderT ρ`, yielding a `ReaderT ρ'`.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def adapt {ρ' α : Type u} (f : ρ' → ρ) : ReaderT ρ m α → ReaderT ρ' m α :=
|
||||
fun x r => x (f r)
|
||||
|
||||
|
|
@ -2973,7 +2973,7 @@ class MonadReaderOf (ρ : Type u) (m : Type u → Type v) where
|
|||
Like `read`, but with `ρ` explicit. This is useful if a monad supports
|
||||
`MonadReaderOf` for multiple different types `ρ`.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def readThe (ρ : Type u) {m : Type u → Type v} [MonadReaderOf ρ m] : m ρ :=
|
||||
MonadReaderOf.read
|
||||
|
||||
|
|
@ -3009,7 +3009,7 @@ class MonadWithReaderOf (ρ : Type u) (m : Type u → Type v) where
|
|||
Like `withReader`, but with `ρ` explicit. This is useful if a monad supports
|
||||
`MonadWithReaderOf` for multiple different types `ρ`.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def withTheReader (ρ : Type u) {m : Type u → Type v} [MonadWithReaderOf ρ m] {α : Type u} (f : ρ → ρ) (x : m α) : m α :=
|
||||
MonadWithReaderOf.withReader f x
|
||||
|
||||
|
|
@ -3062,7 +3062,7 @@ abbrev getThe (σ : Type u) {m : Type u → Type v} [MonadStateOf σ m] : m σ :
|
|||
Like `modify`, but with `σ` explicit. This is useful if a monad supports
|
||||
`MonadStateOf` for multiple different types `σ`.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
abbrev modifyThe (σ : Type u) {m : Type u → Type v} [MonadStateOf σ m] (f : σ → σ) : m PUnit :=
|
||||
MonadStateOf.modifyGet fun s => (PUnit.unit, f s)
|
||||
|
||||
|
|
@ -3070,7 +3070,7 @@ abbrev modifyThe (σ : Type u) {m : Type u → Type v} [MonadStateOf σ m] (f :
|
|||
Like `modifyGet`, but with `σ` explicit. This is useful if a monad supports
|
||||
`MonadStateOf` for multiple different types `σ`.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
abbrev modifyGetThe {α : Type u} (σ : Type u) {m : Type u → Type v} [MonadStateOf σ m] (f : σ → Prod α σ) : m α :=
|
||||
MonadStateOf.modifyGet f
|
||||
|
||||
|
|
@ -3101,7 +3101,7 @@ instance (σ : Type u) (m : Type u → Type v) [MonadStateOf σ m] : MonadState
|
|||
It is equivalent to `do put (f (← get))`, but `modify f` may be preferable
|
||||
because the former does not use the state linearly (without sufficient inlining).
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def modify {σ : Type u} {m : Type u → Type v} [MonadState σ m] (f : σ → σ) : m PUnit :=
|
||||
modifyGet fun s => (PUnit.unit, f s)
|
||||
|
||||
|
|
@ -3109,13 +3109,13 @@ def modify {σ : Type u} {m : Type u → Type v} [MonadState σ m] (f : σ →
|
|||
`getModify f` gets the state, applies function `f`, and returns the old value
|
||||
of the state. It is equivalent to `get <* modify f` but may be more efficient.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def getModify {σ : Type u} {m : Type u → Type v} [MonadState σ m] [Monad m] (f : σ → σ) : m σ :=
|
||||
modifyGet fun s => (s, f s)
|
||||
|
||||
-- NOTE: The Ordering of the following two instances determines that the top-most `StateT` Monad layer
|
||||
-- will be picked first
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance {σ : Type u} {m : Type u → Type v} {n : Type u → Type w} [MonadLift m n] [MonadStateOf σ m] : MonadStateOf σ n where
|
||||
get := liftM (m := m) MonadStateOf.get
|
||||
set s := liftM (m := m) (MonadStateOf.set s)
|
||||
|
|
@ -3155,28 +3155,28 @@ instance [Inhabited ε] : Inhabited (EStateM ε σ α) where
|
|||
default := fun s => Result.error default s
|
||||
|
||||
/-- The `pure` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def pure (a : α) : EStateM ε σ α := fun s =>
|
||||
Result.ok a s
|
||||
|
||||
/-- The `set` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def set (s : σ) : EStateM ε σ PUnit := fun _ =>
|
||||
Result.ok ⟨⟩ s
|
||||
|
||||
/-- The `get` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def get : EStateM ε σ σ := fun s =>
|
||||
Result.ok s s
|
||||
|
||||
/-- The `modifyGet` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def modifyGet (f : σ → Prod α σ) : EStateM ε σ α := fun s =>
|
||||
match f s with
|
||||
| (a, s) => Result.ok a s
|
||||
|
||||
/-- The `throw` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def throw (e : ε) : EStateM ε σ α := fun s =>
|
||||
Result.error e s
|
||||
|
||||
|
|
@ -3193,7 +3193,7 @@ class Backtrackable (δ : outParam (Type u)) (σ : Type u) where
|
|||
restore : σ → δ → σ
|
||||
|
||||
/-- Implementation of `tryCatch` for `EStateM` where the state is `Backtrackable`. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def tryCatch {δ} [Backtrackable δ σ] {α} (x : EStateM ε σ α) (handle : ε → EStateM ε σ α) : EStateM ε σ α := fun s =>
|
||||
let d := Backtrackable.save s
|
||||
match x s with
|
||||
|
|
@ -3201,7 +3201,7 @@ protected def tryCatch {δ} [Backtrackable δ σ] {α} (x : EStateM ε σ α) (h
|
|||
| ok => ok
|
||||
|
||||
/-- Implementation of `orElse` for `EStateM` where the state is `Backtrackable`. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def orElse {δ} [Backtrackable δ σ] (x₁ : EStateM ε σ α) (x₂ : Unit → EStateM ε σ α) : EStateM ε σ α := fun s =>
|
||||
let d := Backtrackable.save s;
|
||||
match x₁ s with
|
||||
|
|
@ -3209,34 +3209,34 @@ protected def orElse {δ} [Backtrackable δ σ] (x₁ : EStateM ε σ α) (x₂
|
|||
| ok => ok
|
||||
|
||||
/-- Map the exception type of a `EStateM ε σ α` by a function `f : ε → ε'`. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def adaptExcept {ε' : Type u} (f : ε → ε') (x : EStateM ε σ α) : EStateM ε' σ α := fun s =>
|
||||
match x s with
|
||||
| Result.error e s => Result.error (f e) s
|
||||
| Result.ok a s => Result.ok a s
|
||||
|
||||
/-- The `bind` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def bind (x : EStateM ε σ α) (f : α → EStateM ε σ β) : EStateM ε σ β := fun s =>
|
||||
match x s with
|
||||
| Result.ok a s => f a s
|
||||
| Result.error e s => Result.error e s
|
||||
|
||||
/-- The `map` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def map (f : α → β) (x : EStateM ε σ α) : EStateM ε σ β := fun s =>
|
||||
match x s with
|
||||
| Result.ok a s => Result.ok (f a) s
|
||||
| Result.error e s => Result.error e s
|
||||
|
||||
/-- The `seqRight` operation of the `EStateM` monad. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
protected def seqRight (x : EStateM ε σ α) (y : Unit → EStateM ε σ β) : EStateM ε σ β := fun s =>
|
||||
match x s with
|
||||
| Result.ok _ s => y () s
|
||||
| Result.error e s => Result.error e s
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad (EStateM ε σ) where
|
||||
bind := EStateM.bind
|
||||
pure := EStateM.pure
|
||||
|
|
@ -3256,14 +3256,14 @@ instance {δ} [Backtrackable δ σ] : MonadExceptOf ε (EStateM ε σ) where
|
|||
tryCatch := EStateM.tryCatch
|
||||
|
||||
/-- Execute an `EStateM` on initial state `s` to get a `Result`. -/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def run (x : EStateM ε σ α) (s : σ) : Result ε σ α := x s
|
||||
|
||||
/--
|
||||
Execute an `EStateM` on initial state `s` for the returned value `α`.
|
||||
If the monadic action throws an exception, returns `none` instead.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def run' (x : EStateM ε σ α) (s : σ) : Option α :=
|
||||
match run x s with
|
||||
| Result.ok v _ => some v
|
||||
|
|
@ -3368,7 +3368,7 @@ inductive Name where
|
|||
with
|
||||
/-- A hash function for names, which is stored inside the name itself as a
|
||||
computed field. -/
|
||||
@[computedField] hash : Name → UInt64
|
||||
@[computed_field] hash : Name → UInt64
|
||||
| .anonymous => .ofNatCore 1723 (by decide)
|
||||
| .str p s => mixHash p.hash s.hash
|
||||
| .num p v => mixHash p.hash (dite (LT.lt v UInt64.size) (fun h => UInt64.ofNatCore v h) (fun _ => UInt64.ofNatCore 17 (by decide)))
|
||||
|
|
@ -3864,14 +3864,14 @@ abbrev TSyntaxArray (ks : SyntaxNodeKinds) := Array (TSyntax ks)
|
|||
unsafe def TSyntaxArray.rawImpl : TSyntaxArray ks → Array Syntax := unsafeCast
|
||||
|
||||
/-- Converts a `TSyntaxArray` to an `Array Syntax`, without reallocation. -/
|
||||
@[implementedBy TSyntaxArray.rawImpl]
|
||||
@[implemented_by TSyntaxArray.rawImpl]
|
||||
opaque TSyntaxArray.raw (as : TSyntaxArray ks) : Array Syntax := Array.empty
|
||||
|
||||
/-- Implementation of `TSyntaxArray.mk`. -/
|
||||
unsafe def TSyntaxArray.mkImpl : Array Syntax → TSyntaxArray ks := unsafeCast
|
||||
|
||||
/-- Converts an `Array Syntax` to a `TSyntaxArray`, without reallocation. -/
|
||||
@[implementedBy TSyntaxArray.mkImpl]
|
||||
@[implemented_by TSyntaxArray.mkImpl]
|
||||
opaque TSyntaxArray.mk (as : Array Syntax) : TSyntaxArray ks := Array.empty
|
||||
|
||||
/-- Constructs a synthetic `SourceInfo` using a `ref : Syntax` for the span. -/
|
||||
|
|
@ -4006,7 +4006,7 @@ Run `x : m α` with a modified value for the `ref`. This is not exactly
|
|||
the same as `MonadRef.withRef`, because it uses `replaceRef` to avoid putting
|
||||
syntax with bad spans in the state.
|
||||
-/
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def withRef [Monad m] [MonadRef m] {α} (ref : Syntax) (x : m α) : m α :=
|
||||
bind getRef fun oldRef =>
|
||||
let ref := replaceRef ref oldRef
|
||||
|
|
@ -4363,7 +4363,7 @@ unsafe def mkMethodsImp (methods : Methods) : MethodsRef :=
|
|||
unsafeCast methods
|
||||
|
||||
/-- Make an opaque reference to a `Methods`. -/
|
||||
@[implementedBy mkMethodsImp]
|
||||
@[implemented_by mkMethodsImp]
|
||||
opaque mkMethods (methods : Methods) : MethodsRef
|
||||
|
||||
instance : Inhabited MethodsRef where
|
||||
|
|
@ -4374,7 +4374,7 @@ unsafe def getMethodsImp : MacroM Methods :=
|
|||
bind read fun ctx => pure (unsafeCast (ctx.methods))
|
||||
|
||||
/-- Extract the methods list from the `MacroM` state. -/
|
||||
@[implementedBy getMethodsImp] opaque getMethods : MacroM Methods
|
||||
@[implemented_by getMethodsImp] opaque getMethods : MacroM Methods
|
||||
|
||||
/--
|
||||
`expandMacro? stx` returns `some stxNew` if `stx` is a macro,
|
||||
|
|
@ -4422,7 +4422,7 @@ abbrev UnexpandM := ReaderT Syntax (EStateM Unit Unit)
|
|||
/--
|
||||
Function that tries to reverse macro expansions as a post-processing step of delaboration.
|
||||
While less general than an arbitrary delaborator, it can be declared without importing `Lean`.
|
||||
Used by the `[appUnexpander]` attribute.
|
||||
Used by the `[app_unexpander]` attribute.
|
||||
-/
|
||||
-- a `kindUnexpander` could reasonably be added later
|
||||
abbrev Unexpander := Syntax → UnexpandM Syntax
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ unsafe def StateFactory.mkImpl : StateFactoryBuilder → StateFactory
|
|||
setInsert := @setInsert Object ⟨Object.eq⟩ ⟨Object.hash⟩
|
||||
: StateFactoryImpl }
|
||||
|
||||
@[implementedBy StateFactory.mkImpl]
|
||||
@[implemented_by StateFactory.mkImpl]
|
||||
opaque StateFactory.mk : StateFactoryBuilder → StateFactory
|
||||
|
||||
unsafe def StateFactory.get : StateFactory → StateFactoryImpl := unsafeCast
|
||||
|
|
@ -75,7 +75,7 @@ abbrev State (σ : StateFactory) : Type u := (StatePointed σ).type
|
|||
instance : Nonempty (State σ) := (StatePointed σ).property
|
||||
|
||||
unsafe def mkStateImpl (σ : StateFactory) : State σ := unsafeCast (σ.get.mkState ())
|
||||
@[implementedBy mkStateImpl] opaque State.mk (σ : StateFactory) : State σ
|
||||
@[implemented_by mkStateImpl] opaque State.mk (σ : StateFactory) : State σ
|
||||
instance : Inhabited (State σ) := ⟨.mk σ⟩
|
||||
|
||||
@[extern "lean_state_sharecommon"]
|
||||
|
|
|
|||
|
|
@ -43,20 +43,20 @@ def BaseIO := EIO Empty
|
|||
instance : Monad BaseIO := inferInstanceAs (Monad (EIO Empty))
|
||||
instance : MonadFinally BaseIO := inferInstanceAs (MonadFinally (EIO Empty))
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def BaseIO.toEIO (act : BaseIO α) : EIO ε α :=
|
||||
fun s => match act s with
|
||||
| EStateM.Result.ok a s => EStateM.Result.ok a s
|
||||
|
||||
instance : MonadLift BaseIO (EIO ε) := ⟨BaseIO.toEIO⟩
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def EIO.toBaseIO (act : EIO ε α) : BaseIO (Except ε α) :=
|
||||
fun s => match act s with
|
||||
| EStateM.Result.ok a s => EStateM.Result.ok (Except.ok a) s
|
||||
| EStateM.Result.error ex s => EStateM.Result.ok (Except.error ex) s
|
||||
|
||||
@[alwaysInline, inline]
|
||||
@[always_inline, inline]
|
||||
def EIO.catchExceptions (act : EIO ε α) (h : ε → BaseIO α) : BaseIO α :=
|
||||
fun s => match act s with
|
||||
| EStateM.Result.ok a s => EStateM.Result.ok a s
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ The result task of a `Promise`.
|
|||
|
||||
The task blocks until `Promise.resolve` is called.
|
||||
-/
|
||||
@[implementedBy Promise.resultImpl]
|
||||
@[implemented_by Promise.resultImpl]
|
||||
opaque Promise.result (promise : Promise α) : Task α :=
|
||||
have : Nonempty α := (PromiseImpl α).2.2 ⟨promise⟩
|
||||
Classical.choice inferInstance
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ def runST {α : Type} (x : (σ : Type) → ST σ α) : α :=
|
|||
| EStateM.Result.ok a _ => a
|
||||
| EStateM.Result.error ex _ => nomatch ex
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance {ε σ} : MonadLift (ST σ) (EST ε σ) := ⟨fun x s =>
|
||||
match x s with
|
||||
| EStateM.Result.ok a s => EStateM.Result.ok a s
|
||||
|
|
@ -82,12 +82,12 @@ opaque Ref.ptrEq {σ α} (r1 r2 : @& Ref σ α) : ST σ Bool
|
|||
Ref.set r a
|
||||
pure b
|
||||
|
||||
@[implementedBy Ref.modifyUnsafe]
|
||||
@[implemented_by Ref.modifyUnsafe]
|
||||
def Ref.modify {σ α : Type} (r : Ref σ α) (f : α → α) : ST σ Unit := do
|
||||
let v ← Ref.get r
|
||||
Ref.set r (f v)
|
||||
|
||||
@[implementedBy Ref.modifyGetUnsafe]
|
||||
@[implemented_by Ref.modifyGetUnsafe]
|
||||
def Ref.modifyGet {σ α β : Type} (r : Ref σ α) (f : α → β × α) : ST σ β := do
|
||||
let v ← Ref.get r
|
||||
let (b, a) := f v
|
||||
|
|
|
|||
|
|
@ -821,8 +821,8 @@ macro "get_elem_tactic" : tactic =>
|
|||
- Use `a[i]'h` notation instead, where `h` is a proof that index is valid"
|
||||
)
|
||||
|
||||
@[inheritDoc getElem]
|
||||
@[inherit_doc getElem]
|
||||
macro:max x:term noWs "[" i:term "]" : term => `(getElem $x $i (by get_elem_tactic))
|
||||
|
||||
@[inheritDoc getElem]
|
||||
@[inherit_doc getElem]
|
||||
macro x:term noWs "[" i:term "]'" h:term:max : term => `(getElem $x $i $h)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ universe u v
|
|||
/-! # Debugging helper functions -/
|
||||
|
||||
set_option linter.unusedVariables.funArgs false in
|
||||
@[neverExtract, extern "lean_dbg_trace"]
|
||||
@[never_extract, extern "lean_dbg_trace"]
|
||||
def dbgTrace {α : Type u} (s : String) (f : Unit → α) : α := f ()
|
||||
|
||||
def dbgTraceVal {α : Type u} [ToString α] (a : α) : α :=
|
||||
|
|
@ -20,11 +20,11 @@ def dbgTraceVal {α : Type u} [ToString α] (a : α) : α :=
|
|||
|
||||
set_option linter.unusedVariables.funArgs false in
|
||||
/-- Display the given message if `a` is shared, that is, RC(a) > 1 -/
|
||||
@[neverExtract, extern "lean_dbg_trace_if_shared"]
|
||||
@[never_extract, extern "lean_dbg_trace_if_shared"]
|
||||
def dbgTraceIfShared {α : Type u} (s : String) (a : α) : α := a
|
||||
|
||||
/-- Print stack trace to stderr before evaluating given closure. Currently supported on Linux only. -/
|
||||
@[neverExtract, extern "lean_dbg_stack_trace"]
|
||||
@[never_extract, extern "lean_dbg_stack_trace"]
|
||||
def dbgStackTrace {α : Type u} (f : Unit → α) : α := f ()
|
||||
|
||||
@[extern "lean_dbg_sleep"]
|
||||
|
|
@ -33,13 +33,13 @@ def dbgSleep {α : Type u} (ms : UInt32) (f : Unit → α) : α := f ()
|
|||
@[noinline] private def mkPanicMessage (modName : String) (line col : Nat) (msg : String) : String :=
|
||||
"PANIC at " ++ modName ++ ":" ++ toString line ++ ":" ++ toString col ++ ": " ++ msg
|
||||
|
||||
@[neverExtract, inline] def panicWithPos {α : Type u} [Inhabited α] (modName : String) (line col : Nat) (msg : String) : α :=
|
||||
@[never_extract, inline] def panicWithPos {α : Type u} [Inhabited α] (modName : String) (line col : Nat) (msg : String) : α :=
|
||||
panic (mkPanicMessage modName line col msg)
|
||||
|
||||
@[noinline] private def mkPanicMessageWithDecl (modName : String) (declName : String) (line col : Nat) (msg : String) : String :=
|
||||
"PANIC at " ++ declName ++ " " ++ modName ++ ":" ++ toString line ++ ":" ++ toString col ++ ": " ++ msg
|
||||
|
||||
@[neverExtract, inline] def panicWithPosWithDecl {α : Type u} [Inhabited α] (modName : String) (declName : String) (line col : Nat) (msg : String) : α :=
|
||||
@[never_extract, inline] def panicWithPosWithDecl {α : Type u} [Inhabited α] (modName : String) (declName : String) (line col : Nat) (msg : String) : α :=
|
||||
panic (mkPanicMessageWithDecl modName declName line col msg)
|
||||
|
||||
@[extern "lean_ptr_addr"]
|
||||
|
|
@ -60,7 +60,7 @@ set_option linter.unusedVariables.funArgs false in
|
|||
@[inline] unsafe def withPtrEqUnsafe {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool :=
|
||||
if ptrEq a b then true else k ()
|
||||
|
||||
@[implementedBy withPtrEqUnsafe]
|
||||
@[implemented_by withPtrEqUnsafe]
|
||||
def withPtrEq {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () = true) : Bool := k ()
|
||||
|
||||
/-- `withPtrEq` for `DecidableEq` -/
|
||||
|
|
@ -70,10 +70,10 @@ def withPtrEq {α : Type u} (a b : α) (k : Unit → Bool) (h : a = b → k () =
|
|||
| true => isTrue (ofBoolUsing_eq_true h)
|
||||
| false => isFalse (ofBoolUsing_eq_false h)
|
||||
|
||||
@[implementedBy withPtrAddrUnsafe]
|
||||
@[implemented_by withPtrAddrUnsafe]
|
||||
def withPtrAddr {α : Type u} {β : Type v} (a : α) (k : USize → β) (h : ∀ u₁ u₂, k u₁ = k u₂) : β := k 0
|
||||
|
||||
@[neverExtract]
|
||||
@[never_extract]
|
||||
private def outOfBounds [Inhabited α] : α :=
|
||||
panic! "index out of bounds"
|
||||
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ def registerBuiltinAttribute (attr : AttributeImpl) : IO Unit := do
|
|||
Helper methods for decoding the parameters of builtin attributes that are defined before `Lean.Parser`.
|
||||
We have the following ones:
|
||||
```
|
||||
@[builtinAttrParser] def simple := leading_parser ident >> optional ident >> optional priorityParser
|
||||
@[builtin_attr_parser] def simple := leading_parser ident >> optional ident >> optional priorityParser
|
||||
/- We can't use `simple` for `class`, `instance`, `export` and `macro` because they are keywords. -/
|
||||
@[builtinAttrParser] def «class» := leading_parser "class"
|
||||
@[builtinAttrParser] def «instance» := leading_parser "instance" >> optional priorityParser
|
||||
@[builtinAttrParser] def «macro» := leading_parser "macro " >> ident
|
||||
@[builtin_attr_parser] def «class» := leading_parser "class"
|
||||
@[builtin_attr_parser] def «instance» := leading_parser "instance" >> optional priorityParser
|
||||
@[builtin_attr_parser] def «macro» := leading_parser "macro " >> ident
|
||||
```
|
||||
Note that we need the parsers for `class`, `instance`, and `macros` because they are keywords.
|
||||
-/
|
||||
|
|
@ -340,7 +340,7 @@ unsafe def mkAttributeImplOfConstantUnsafe (env : Environment) (opts : Options)
|
|||
| Expr.const `Lean.AttributeImpl _ => env.evalConst AttributeImpl opts declName
|
||||
| _ => throw ("unexpected attribute implementation type at '" ++ toString declName ++ "' (`AttributeImpl` expected")
|
||||
|
||||
@[implementedBy mkAttributeImplOfConstantUnsafe]
|
||||
@[implemented_by mkAttributeImplOfConstantUnsafe]
|
||||
opaque mkAttributeImplOfConstant (env : Environment) (opts : Options) (declName : Name) : Except String AttributeImpl
|
||||
|
||||
def mkAttributeImplOfEntry (env : Environment) (opts : Options) (e : AttributeExtensionOLeanEntry) : IO AttributeImpl :=
|
||||
|
|
|
|||
|
|
@ -290,8 +290,8 @@ abbrev FnBody.nil := FnBody.unreachable
|
|||
@[export lean_ir_mk_unreachable] def mkUnreachable : Unit → FnBody := fun _ => FnBody.unreachable
|
||||
|
||||
abbrev Alt := AltCore FnBody
|
||||
@[matchPattern] abbrev Alt.ctor := @AltCore.ctor FnBody
|
||||
@[matchPattern] abbrev Alt.default := @AltCore.default FnBody
|
||||
@[match_pattern] abbrev Alt.ctor := @AltCore.ctor FnBody
|
||||
@[match_pattern] abbrev Alt.default := @AltCore.default FnBody
|
||||
|
||||
instance : Inhabited Alt := ⟨Alt.default default⟩
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ unsafe def registerInitAttrUnsafe (attrName : Name) (runAfterImport : Bool) (ref
|
|||
runInit ctx.env ctx.opts decl initDecl
|
||||
}
|
||||
|
||||
@[implementedBy registerInitAttrUnsafe]
|
||||
@[implemented_by registerInitAttrUnsafe]
|
||||
private opaque registerInitAttrInner (attrName : Name) (runAfterImport : Bool) (ref : Name) : IO (ParametricAttribute Name)
|
||||
|
||||
@[inline]
|
||||
|
|
|
|||
|
|
@ -136,12 +136,12 @@ mutual
|
|||
| _, _ => false
|
||||
end
|
||||
|
||||
@[implementedBy eqImp] protected opaque Code.beq : Code → Code → Bool
|
||||
@[implemented_by eqImp] protected opaque Code.beq : Code → Code → Bool
|
||||
|
||||
instance : BEq Code where
|
||||
beq := Code.beq
|
||||
|
||||
@[implementedBy eqFunDecl] protected opaque FunDecl.beq : FunDecl → FunDecl → Bool
|
||||
@[implemented_by eqFunDecl] protected opaque FunDecl.beq : FunDecl → FunDecl → Bool
|
||||
|
||||
instance : BEq FunDecl where
|
||||
beq := FunDecl.beq
|
||||
|
|
@ -164,35 +164,35 @@ private unsafe def updateAltCodeImp (alt : Alt) (k' : Code) : Alt :=
|
|||
| .default k => if ptrEq k k' then alt else .default k'
|
||||
| .alt ctorName ps k => if ptrEq k k' then alt else .alt ctorName ps k'
|
||||
|
||||
@[implementedBy updateAltCodeImp] opaque AltCore.updateCode (alt : Alt) (c : Code) : Alt
|
||||
@[implemented_by updateAltCodeImp] opaque AltCore.updateCode (alt : Alt) (c : Code) : Alt
|
||||
|
||||
private unsafe def updateAltImp (alt : Alt) (ps' : Array Param) (k' : Code) : Alt :=
|
||||
match alt with
|
||||
| .alt ctorName ps k => if ptrEq k k' && ptrEq ps ps' then alt else .alt ctorName ps' k'
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateAltImp] opaque AltCore.updateAlt! (alt : Alt) (ps' : Array Param) (k' : Code) : Alt
|
||||
@[implemented_by updateAltImp] opaque AltCore.updateAlt! (alt : Alt) (ps' : Array Param) (k' : Code) : Alt
|
||||
|
||||
@[inline] private unsafe def updateAltsImp (c : Code) (alts : Array Alt) : Code :=
|
||||
match c with
|
||||
| .cases cs => if ptrEq cs.alts alts then c else .cases { cs with alts }
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateAltsImp] opaque Code.updateAlts! (c : Code) (alts : Array Alt) : Code
|
||||
@[implemented_by updateAltsImp] opaque Code.updateAlts! (c : Code) (alts : Array Alt) : Code
|
||||
|
||||
@[inline] private unsafe def updateCasesImp (c : Code) (resultType : Expr) (discr : FVarId) (alts : Array Alt) : Code :=
|
||||
match c with
|
||||
| .cases cs => if ptrEq cs.alts alts && ptrEq cs.resultType resultType && cs.discr == discr then c else .cases { cs with discr, resultType, alts }
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateCasesImp] opaque Code.updateCases! (c : Code) (resultType : Expr) (discr : FVarId) (alts : Array Alt) : Code
|
||||
@[implemented_by updateCasesImp] opaque Code.updateCases! (c : Code) (resultType : Expr) (discr : FVarId) (alts : Array Alt) : Code
|
||||
|
||||
@[inline] private unsafe def updateLetImp (c : Code) (decl' : LetDecl) (k' : Code) : Code :=
|
||||
match c with
|
||||
| .let decl k => if ptrEq k k' && ptrEq decl decl' then c else .let decl' k'
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateLetImp] opaque Code.updateLet! (c : Code) (decl' : LetDecl) (k' : Code) : Code
|
||||
@[implemented_by updateLetImp] opaque Code.updateLet! (c : Code) (decl' : LetDecl) (k' : Code) : Code
|
||||
|
||||
@[inline] private unsafe def updateContImp (c : Code) (k' : Code) : Code :=
|
||||
match c with
|
||||
|
|
@ -201,7 +201,7 @@ private unsafe def updateAltImp (alt : Alt) (ps' : Array Param) (k' : Code) : Al
|
|||
| .jp decl k => if ptrEq k k' then c else .jp decl k'
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateContImp] opaque Code.updateCont! (c : Code) (k' : Code) : Code
|
||||
@[implemented_by updateContImp] opaque Code.updateCont! (c : Code) (k' : Code) : Code
|
||||
|
||||
@[inline] private unsafe def updateFunImp (c : Code) (decl' : FunDecl) (k' : Code) : Code :=
|
||||
match c with
|
||||
|
|
@ -209,28 +209,28 @@ private unsafe def updateAltImp (alt : Alt) (ps' : Array Param) (k' : Code) : Al
|
|||
| .jp decl k => if ptrEq k k' && ptrEq decl decl' then c else .jp decl' k'
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateFunImp] opaque Code.updateFun! (c : Code) (decl' : FunDecl) (k' : Code) : Code
|
||||
@[implemented_by updateFunImp] opaque Code.updateFun! (c : Code) (decl' : FunDecl) (k' : Code) : Code
|
||||
|
||||
@[inline] private unsafe def updateReturnImp (c : Code) (fvarId' : FVarId) : Code :=
|
||||
match c with
|
||||
| .return fvarId => if fvarId == fvarId' then c else .return fvarId'
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateReturnImp] opaque Code.updateReturn! (c : Code) (fvarId' : FVarId) : Code
|
||||
@[implemented_by updateReturnImp] opaque Code.updateReturn! (c : Code) (fvarId' : FVarId) : Code
|
||||
|
||||
@[inline] private unsafe def updateJmpImp (c : Code) (fvarId' : FVarId) (args' : Array Expr) : Code :=
|
||||
match c with
|
||||
| .jmp fvarId args => if fvarId == fvarId' && ptrEq args args' then c else .jmp fvarId' args'
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateJmpImp] opaque Code.updateJmp! (c : Code) (fvarId' : FVarId) (args' : Array Expr) : Code
|
||||
@[implemented_by updateJmpImp] opaque Code.updateJmp! (c : Code) (fvarId' : FVarId) (args' : Array Expr) : Code
|
||||
|
||||
@[inline] private unsafe def updateUnreachImp (c : Code) (type' : Expr) : Code :=
|
||||
match c with
|
||||
| .unreach type => if ptrEq type type' then c else .unreach type'
|
||||
| _ => unreachable!
|
||||
|
||||
@[implementedBy updateUnreachImp] opaque Code.updateUnreach! (c : Code) (type' : Expr) : Code
|
||||
@[implemented_by updateUnreachImp] opaque Code.updateUnreach! (c : Code) (type' : Expr) : Code
|
||||
|
||||
private unsafe def updateParamCoreImp (p : Param) (type : Expr) : Param :=
|
||||
if ptrEq type p.type then
|
||||
|
|
@ -243,7 +243,7 @@ Low-level update `Param` function. It does not update the local context.
|
|||
Consider using `Param.update : Param → Expr → CompilerM Param` if you want the local context
|
||||
to be updated.
|
||||
-/
|
||||
@[implementedBy updateParamCoreImp] opaque Param.updateCore (p : Param) (type : Expr) : Param
|
||||
@[implemented_by updateParamCoreImp] opaque Param.updateCore (p : Param) (type : Expr) : Param
|
||||
|
||||
private unsafe def updateLetDeclCoreImp (decl : LetDecl) (type : Expr) (value : Expr) : LetDecl :=
|
||||
if ptrEq type decl.type && ptrEq value decl.value then
|
||||
|
|
@ -256,7 +256,7 @@ Low-level update `LetDecl` function. It does not update the local context.
|
|||
Consider using `LetDecl.update : LetDecl → Expr → Expr → CompilerM LetDecl` if you want the local context
|
||||
to be updated.
|
||||
-/
|
||||
@[implementedBy updateLetDeclCoreImp] opaque LetDecl.updateCore (decl : LetDecl) (type : Expr) (value : Expr) : LetDecl
|
||||
@[implemented_by updateLetDeclCoreImp] opaque LetDecl.updateCore (decl : LetDecl) (type : Expr) (value : Expr) : LetDecl
|
||||
|
||||
private unsafe def updateFunDeclCoreImp (decl: FunDecl) (type : Expr) (params : Array Param) (value : Code) : FunDecl :=
|
||||
if ptrEq type decl.type && ptrEq params decl.params && ptrEq value decl.value then
|
||||
|
|
@ -269,7 +269,7 @@ Low-level update `FunDecl` function. It does not update the local context.
|
|||
Consider using `FunDecl.update : LetDecl → Expr → Array Param → Code → CompilerM FunDecl` if you want the local context
|
||||
to be updated.
|
||||
-/
|
||||
@[implementedBy updateFunDeclCoreImp] opaque FunDeclCore.updateCore (decl: FunDecl) (type : Expr) (params : Array Param) (value : Code) : FunDecl
|
||||
@[implemented_by updateFunDeclCoreImp] opaque FunDeclCore.updateCore (decl: FunDecl) (type : Expr) (params : Array Param) (value : Code) : FunDecl
|
||||
|
||||
def CasesCore.extractAlt! (cases : Cases) (ctorName : Name) : Alt × Cases :=
|
||||
let found (i : Nat) := (cases.alts[i]!, { cases with alts := cases.alts.eraseIdx i })
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ structure CompilerM.Context where
|
|||
|
||||
abbrev CompilerM := ReaderT CompilerM.Context $ StateRefT CompilerM.State CoreM
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad CompilerM := let i := inferInstanceAs (Monad CompilerM); { pure := i.pure, bind := i.bind }
|
||||
|
||||
@[inline] def withPhase (phase : Phase) (x : CompilerM α) : CompilerM α :=
|
||||
|
|
@ -242,13 +242,13 @@ See `Check.lean` for the free variable substitution checker.
|
|||
@[inline] def addSubst [MonadFVarSubstState m] (fvarId : FVarId) (e : Expr) : m Unit :=
|
||||
modifySubst fun s => s.insert fvarId e
|
||||
|
||||
@[inline, inheritDoc normFVarImp] def normFVar [MonadFVarSubst m t] [Monad m] (fvarId : FVarId) : m FVarId :=
|
||||
@[inline, inherit_doc normFVarImp] def normFVar [MonadFVarSubst m t] [Monad m] (fvarId : FVarId) : m FVarId :=
|
||||
return normFVarImp (← getSubst) fvarId t
|
||||
|
||||
@[inline, inheritDoc normExprImp] def normExpr [MonadFVarSubst m t] [Monad m] (e : Expr) : m Expr :=
|
||||
@[inline, inherit_doc normExprImp] def normExpr [MonadFVarSubst m t] [Monad m] (e : Expr) : m Expr :=
|
||||
return normExprImp (← getSubst) e t
|
||||
|
||||
@[inheritDoc normExprImp]
|
||||
@[inherit_doc normExprImp]
|
||||
abbrev normExprCore (s : FVarSubst) (e : Expr) (translator : Bool) : Expr :=
|
||||
normExprImp s e translator
|
||||
|
||||
|
|
@ -302,7 +302,7 @@ private unsafe def updateParamImp (p : Param) (type : Expr) : CompilerM Param :=
|
|||
modifyLCtx fun lctx => lctx.addParam p
|
||||
return p
|
||||
|
||||
@[implementedBy updateParamImp] opaque Param.update (p : Param) (type : Expr) : CompilerM Param
|
||||
@[implemented_by updateParamImp] opaque Param.update (p : Param) (type : Expr) : CompilerM Param
|
||||
|
||||
private unsafe def updateLetDeclImp (decl : LetDecl) (type : Expr) (value : Expr) : CompilerM LetDecl := do
|
||||
if ptrEq type decl.type && ptrEq value decl.value then
|
||||
|
|
@ -312,7 +312,7 @@ private unsafe def updateLetDeclImp (decl : LetDecl) (type : Expr) (value : Expr
|
|||
modifyLCtx fun lctx => lctx.addLetDecl decl
|
||||
return decl
|
||||
|
||||
@[implementedBy updateLetDeclImp] opaque LetDecl.update (decl : LetDecl) (type : Expr) (value : Expr) : CompilerM LetDecl
|
||||
@[implemented_by updateLetDeclImp] opaque LetDecl.update (decl : LetDecl) (type : Expr) (value : Expr) : CompilerM LetDecl
|
||||
|
||||
def LetDecl.updateValue (decl : LetDecl) (value : Expr) : CompilerM LetDecl :=
|
||||
decl.update decl.type value
|
||||
|
|
@ -325,7 +325,7 @@ private unsafe def updateFunDeclImp (decl: FunDecl) (type : Expr) (params : Arra
|
|||
modifyLCtx fun lctx => lctx.addFunDecl decl
|
||||
return decl
|
||||
|
||||
@[implementedBy updateFunDeclImp] opaque FunDeclCore.update (decl: FunDecl) (type : Expr) (params : Array Param) (value : Code) : CompilerM FunDecl
|
||||
@[implemented_by updateFunDeclImp] opaque FunDeclCore.update (decl: FunDecl) (type : Expr) (params : Array Param) (value : Code) : CompilerM FunDecl
|
||||
|
||||
abbrev FunDeclCore.update' (decl : FunDecl) (type : Expr) (value : Code) : CompilerM FunDecl :=
|
||||
decl.update type decl.params value
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ structure Context where
|
|||
mainDecl : Decl
|
||||
/--
|
||||
If true, the lambda-lifted functions inherit the inline attribute from `mainDecl`.
|
||||
We use this feature to implement `@[inline] instance ...` and `@[alwaysInline] instance ...`
|
||||
We use this feature to implement `@[inline] instance ...` and `@[always_inline] instance ...`
|
||||
-/
|
||||
inheritInlineAttrs := false
|
||||
/--
|
||||
Only local functions with `size > minSize` are lambda lifted.
|
||||
We use this feature to implement `@[inline] instance ...` and `@[alwaysInline] instance ...`
|
||||
We use this feature to implement `@[inline] instance ...` and `@[always_inline] instance ...`
|
||||
-/
|
||||
minSize : Nat := 0
|
||||
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ def run (manager : PassManager) (installer : PassInstaller) : CoreM PassManager
|
|||
private unsafe def getPassInstallerUnsafe (declName : Name) : CoreM PassInstaller := do
|
||||
ofExcept <| (← getEnv).evalConstCheck PassInstaller (← getOptions) ``PassInstaller declName
|
||||
|
||||
@[implementedBy getPassInstallerUnsafe]
|
||||
@[implemented_by getPassInstallerUnsafe]
|
||||
private opaque getPassInstaller (declName : Name) : CoreM PassInstaller
|
||||
|
||||
def runFromDecl (manager : PassManager) (declName : Name) : CoreM PassManager := do
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ partial def Decl.simp (decl : Decl) (config : Config) : CompilerM Decl := do
|
|||
|
||||
There is an exception: inlineable instances. This is important for auxiliary instances such as
|
||||
```
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad TermElabM := let i := inferInstanceAs (Monad TermElabM); { pure := i.pure, bind := i.bind }
|
||||
```
|
||||
by keeping `inlineDefs := true`, we can pre-compute the `pure` and `bind` methods for `TermElabM`.
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ def applyFolders (decl : LetDecl) (folders : SMap Name Folder) : CompilerM (Opti
|
|||
private unsafe def getFolderCoreUnsafe (env : Environment) (opts : Options) (declName : Name) : ExceptT String Id Folder :=
|
||||
env.evalConstCheck Folder opts ``Folder declName
|
||||
|
||||
@[implementedBy getFolderCoreUnsafe]
|
||||
@[implemented_by getFolderCoreUnsafe]
|
||||
private opaque getFolderCore (env : Environment) (opts : Options) (declName : Name) : ExceptT String Id Folder
|
||||
|
||||
private def getFolder (declName : Name) : CoreM Folder := do
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ where
|
|||
let ctor := mkAppN (mkAppN (mkConst ctorName) (mkArray ctorInfo.numParams erasedExpr)) fieldArgs
|
||||
return { ctx with discrCtorMap := ctx.discrCtorMap.insert discr ctor }
|
||||
|
||||
@[inline, inheritDoc withDiscrCtorImp] def withDiscrCtor [MonadFunctorT DiscrM m] (discr : FVarId) (ctorName : Name) (ctorFields : Array Param) : m α → m α :=
|
||||
@[inline, inherit_doc withDiscrCtorImp] def withDiscrCtor [MonadFunctorT DiscrM m] (discr : FVarId) (ctorName : Name) (ctorFields : Array Param) : m α → m α :=
|
||||
monadMap (m := DiscrM) <| withDiscrCtorImp discr ctorName ctorFields
|
||||
|
||||
def simpCtorDiscrCore? (e : Expr) : DiscrM (Option Expr) := do
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ structure State where
|
|||
|
||||
abbrev SimpM := ReaderT Context $ StateRefT State DiscrM
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad SimpM := let i := inferInstanceAs (Monad SimpM); { pure := i.pure, bind := i.bind }
|
||||
|
||||
instance : MonadFVarSubst SimpM false where
|
||||
|
|
@ -112,7 +112,7 @@ def addFunOcc (fvarId : FVarId) : SimpM Unit :=
|
|||
def addFunHoOcc (fvarId : FVarId) : SimpM Unit :=
|
||||
modify fun s => { s with funDeclInfoMap := s.funDeclInfoMap.addHo fvarId }
|
||||
|
||||
@[inheritDoc FunDeclInfoMap.update]
|
||||
@[inherit_doc FunDeclInfoMap.update]
|
||||
partial def updateFunDeclInfo (code : Code) (mustInline := false) : SimpM Unit := do
|
||||
let map ← modifyGet fun s => (s.funDeclInfoMap, { s with funDeclInfoMap := {} })
|
||||
let map ← map.update code mustInline
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ abbrev CoreM := ReaderT Context <| StateRefT State (EIO Exception)
|
|||
|
||||
-- Make the compiler generate specialized `pure`/`bind` so we do not have to optimize through the
|
||||
-- whole monad stack at every use site. May eventually be covered by `deriving`.
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad CoreM := let i := inferInstanceAs (Monad CoreM); { pure := i.pure, bind := i.bind }
|
||||
|
||||
instance : Inhabited (CoreM α) where
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ private def shouldPropagateExpectedTypeFor (nextArg : Arg) : Bool :=
|
|||
|
||||
These two conditions would restrict the method to simple functions that are "morally" in
|
||||
the Hindley&Milner fragment.
|
||||
If users need to disable expected type propagation, we can add an attribute `[elabWithoutExpectedType]`.
|
||||
If users need to disable expected type propagation, we can add an attribute `[elab_without_expected_type]`.
|
||||
-/
|
||||
private def propagateExpectedType (arg : Arg) : M Unit := do
|
||||
if shouldPropagateExpectedTypeFor arg then
|
||||
|
|
@ -644,18 +644,18 @@ builtin_initialize elabAsElim : TagAttribute ←
|
|||
discard <| getElimInfo declName
|
||||
let info ← getConstInfo declName
|
||||
if (← hasOptAutoParams info.type) then
|
||||
throwError "[elabAsElim] attribute cannot be used in declarations containing optional and auto parameters"
|
||||
throwError "[elab_as_elim] attribute cannot be used in declarations containing optional and auto parameters"
|
||||
go.run' {} {}
|
||||
|
||||
/-! # Eliminator-like function application elaborator -/
|
||||
namespace ElabElim
|
||||
|
||||
/-- Context of the `elabAsElim` elaboration procedure. -/
|
||||
/-- Context of the `elab_as_elim` elaboration procedure. -/
|
||||
structure Context where
|
||||
elimInfo : ElimInfo
|
||||
expectedType : Expr
|
||||
|
||||
/-- State of the `elabAsElim` elaboration procedure. -/
|
||||
/-- State of the `elab_as_elim` elaboration procedure. -/
|
||||
structure State where
|
||||
/-- The resultant expression being built. -/
|
||||
f : Expr
|
||||
|
|
@ -1367,7 +1367,7 @@ private def annotateIfRec (stx : Syntax) (e : Expr) : TermElabM Expr := do
|
|||
return mkRecAppWithSyntax e stx
|
||||
return e
|
||||
|
||||
@[builtinTermElab app] def elabApp : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab app] def elabApp : TermElab := fun stx expectedType? =>
|
||||
universeConstraintsCheckpoint do
|
||||
let (f, namedArgs, args, ellipsis) ← expandApp stx
|
||||
annotateIfRec stx (← elabAppAux f namedArgs args (ellipsis := ellipsis) expectedType?)
|
||||
|
|
@ -1375,18 +1375,18 @@ private def annotateIfRec (stx : Syntax) (e : Expr) : TermElabM Expr := do
|
|||
private def elabAtom : TermElab := fun stx expectedType? => do
|
||||
annotateIfRec stx (← elabAppAux stx #[] #[] (ellipsis := false) expectedType?)
|
||||
|
||||
@[builtinTermElab ident] def elabIdent : TermElab := elabAtom
|
||||
@[builtinTermElab namedPattern] def elabNamedPattern : TermElab := elabAtom
|
||||
@[builtinTermElab dotIdent] def elabDotIdent : TermElab := elabAtom
|
||||
@[builtinTermElab explicitUniv] def elabExplicitUniv : TermElab := elabAtom
|
||||
@[builtinTermElab pipeProj] def elabPipeProj : TermElab
|
||||
@[builtin_term_elab ident] def elabIdent : TermElab := elabAtom
|
||||
@[builtin_term_elab namedPattern] def elabNamedPattern : TermElab := elabAtom
|
||||
@[builtin_term_elab dotIdent] def elabDotIdent : TermElab := elabAtom
|
||||
@[builtin_term_elab explicitUniv] def elabExplicitUniv : TermElab := elabAtom
|
||||
@[builtin_term_elab pipeProj] def elabPipeProj : TermElab
|
||||
| `($e |>.$f $args*), expectedType? =>
|
||||
universeConstraintsCheckpoint do
|
||||
let (namedArgs, args, ellipsis) ← expandArgs args
|
||||
elabAppAux (← `($e |>.$f)) namedArgs args (ellipsis := ellipsis) expectedType?
|
||||
| _, _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab explicit] def elabExplicit : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab explicit] def elabExplicit : TermElab := fun stx expectedType? =>
|
||||
match stx with
|
||||
| `(@$_:ident) => elabAtom stx expectedType? -- Recall that `elabApp` also has support for `@`
|
||||
| `(@$_:ident.{$_us,*}) => elabAtom stx expectedType?
|
||||
|
|
@ -1394,8 +1394,8 @@ private def elabAtom : TermElab := fun stx expectedType? => do
|
|||
| `(@$t) => elabTerm t expectedType? (implicitLambda := false) -- `@` is being used just to disable implicit lambdas
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab choice] def elabChoice : TermElab := elabAtom
|
||||
@[builtinTermElab proj] def elabProj : TermElab := elabAtom
|
||||
@[builtin_term_elab choice] def elabChoice : TermElab := elabAtom
|
||||
@[builtin_term_elab proj] def elabProj : TermElab := elabAtom
|
||||
|
||||
builtin_initialize
|
||||
registerTraceClass `Elab.app
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ with an internal, unused name based on the suggestion `foo`.
|
|||
-/
|
||||
scoped syntax (name := aux_def) docComment ? attributes ? "aux_def" ident+ ":" term ":=" term : command
|
||||
|
||||
@[builtinCommandElab «aux_def»]
|
||||
@[builtin_command_elab «aux_def»]
|
||||
def elabAuxDef : CommandElab
|
||||
| `($[$doc?:docComment]? $[$attrs?:attributes]? aux_def $suggestion* : $ty := $body) => do
|
||||
let id := suggestion.map (·.getId.eraseMacroScopes) |>.foldl (· ++ ·) Name.anonymous
|
||||
|
|
|
|||
|
|
@ -251,13 +251,13 @@ def expandSimpleBinderWithType (type : Term) (binder : Syntax) : MacroM Syntax :
|
|||
else
|
||||
Macro.throwErrorAt type "unexpected type ascription"
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.forall] def expandForall : Macro
|
||||
@[builtin_macro Lean.Parser.Term.forall] def expandForall : Macro
|
||||
| `(forall $binders* : $ty, $term) => do
|
||||
let binders ← binders.mapM (expandSimpleBinderWithType ty)
|
||||
`(forall $binders*, $term)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
@[builtinTermElab «forall»] def elabForall : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab «forall»] def elabForall : TermElab := fun stx _ =>
|
||||
match stx with
|
||||
| `(forall $binders*, $term) =>
|
||||
elabBinders binders fun xs => do
|
||||
|
|
@ -266,13 +266,13 @@ def expandSimpleBinderWithType (type : Term) (binder : Syntax) : MacroM Syntax :
|
|||
| _ => throwUnsupportedSyntax
|
||||
|
||||
open Lean.Elab.Term.Quotation in
|
||||
@[builtinQuotPrecheck Lean.Parser.Term.arrow] def precheckArrow : Precheck
|
||||
@[builtin_quot_precheck Lean.Parser.Term.arrow] def precheckArrow : Precheck
|
||||
| `($dom:term -> $rng) => do
|
||||
precheck dom
|
||||
precheck rng
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab arrow] def elabArrow : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab arrow] def elabArrow : TermElab := fun stx _ =>
|
||||
match stx with
|
||||
| `($dom:term -> $rng) => do
|
||||
-- elaborate independently from each other
|
||||
|
|
@ -285,7 +285,7 @@ open Lean.Elab.Term.Quotation in
|
|||
The dependent arrow. `(x : α) → β` is equivalent to `∀ x : α, β`, but we usually
|
||||
reserve the latter for propositions. Also written as `Π x : α, β` (the "Pi-type")
|
||||
in the literature. -/
|
||||
@[builtinTermElab depArrow] def elabDepArrow : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab depArrow] def elabDepArrow : TermElab := fun stx _ =>
|
||||
-- bracketedBinder `->` term
|
||||
let binder := stx[0]
|
||||
let term := stx[2]
|
||||
|
|
@ -593,7 +593,7 @@ def expandMatchAltsWhereDecls (matchAltsWhereDecls : Syntax) : MacroM Syntax :=
|
|||
`(@fun x => $body)
|
||||
loop (getMatchAltsNumPatterns matchAlts) #[]
|
||||
|
||||
@[builtinMacro Parser.Term.fun] partial def expandFun : Macro
|
||||
@[builtin_macro Parser.Term.fun] partial def expandFun : Macro
|
||||
| `(fun $binders* : $ty => $body) => do
|
||||
let binders ← binders.mapM (expandSimpleBinderWithType ty)
|
||||
`(fun $binders* => $body)
|
||||
|
|
@ -606,13 +606,13 @@ def expandMatchAltsWhereDecls (matchAltsWhereDecls : Syntax) : MacroM Syntax :=
|
|||
| stx@`(fun $m:matchAlts) => expandMatchAltsIntoMatch stx m (useExplicit := false)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
@[builtinMacro Parser.Term.explicit] partial def expandExplicitFun : Macro := fun stx =>
|
||||
@[builtin_macro Parser.Term.explicit] partial def expandExplicitFun : Macro := fun stx =>
|
||||
match stx with
|
||||
| `(@fun $m:matchAlts) => expandMatchAltsIntoMatch stx[1] m (useExplicit := true)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
open Lean.Elab.Term.Quotation in
|
||||
@[builtinQuotPrecheck Lean.Parser.Term.fun] def precheckFun : Precheck
|
||||
@[builtin_quot_precheck Lean.Parser.Term.fun] def precheckFun : Precheck
|
||||
| `(fun $binders* $[: $ty?]? => $body) => do
|
||||
let (binders, body, _) ← liftMacroM <| expandFunBinders binders body
|
||||
let mut ids := #[]
|
||||
|
|
@ -623,7 +623,7 @@ open Lean.Elab.Term.Quotation in
|
|||
Quotation.withNewLocals ids <| precheck body
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab «fun»] partial def elabFun : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab «fun»] partial def elabFun : TermElab := fun stx expectedType? =>
|
||||
match stx with
|
||||
| `(fun $binders* => $body) => do
|
||||
-- We can assume all `match` binders have been iteratively expanded by the above macro here, though
|
||||
|
|
@ -748,16 +748,16 @@ def elabLetDeclCore (stx : Syntax) (expectedType? : Option Expr) (useLetExpr : B
|
|||
else
|
||||
throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab «let»] def elabLetDecl : TermElab :=
|
||||
@[builtin_term_elab «let»] def elabLetDecl : TermElab :=
|
||||
fun stx expectedType? => elabLetDeclCore stx expectedType? (useLetExpr := true) (elabBodyFirst := false) (usedLetOnly := false)
|
||||
|
||||
@[builtinTermElab «let_fun»] def elabLetFunDecl : TermElab :=
|
||||
@[builtin_term_elab «let_fun»] def elabLetFunDecl : TermElab :=
|
||||
fun stx expectedType? => elabLetDeclCore stx expectedType? (useLetExpr := false) (elabBodyFirst := false) (usedLetOnly := false)
|
||||
|
||||
@[builtinTermElab «let_delayed»] def elabLetDelayedDecl : TermElab :=
|
||||
@[builtin_term_elab «let_delayed»] def elabLetDelayedDecl : TermElab :=
|
||||
fun stx expectedType? => elabLetDeclCore stx expectedType? (useLetExpr := true) (elabBodyFirst := true) (usedLetOnly := false)
|
||||
|
||||
@[builtinTermElab «let_tmp»] def elabLetTmpDecl : TermElab :=
|
||||
@[builtin_term_elab «let_tmp»] def elabLetTmpDecl : TermElab :=
|
||||
fun stx expectedType? => elabLetDeclCore stx expectedType? (useLetExpr := true) (elabBodyFirst := false) (usedLetOnly := true)
|
||||
|
||||
builtin_initialize registerTraceClass `Elab.let
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import Lean.Elab.SetOption
|
|||
|
||||
namespace Lean.Elab.Command
|
||||
|
||||
@[builtinCommandElab moduleDoc] def elabModuleDoc : CommandElab := fun stx => do
|
||||
@[builtin_command_elab moduleDoc] def elabModuleDoc : CommandElab := fun stx => do
|
||||
match stx[1] with
|
||||
| Syntax.atom _ val =>
|
||||
let doc := val.extract 0 (val.endPos - ⟨2⟩)
|
||||
|
|
@ -60,24 +60,24 @@ private def checkEndHeader : Name → List Scope → Bool
|
|||
| .str p s, { header := h, .. } :: scopes => h == s && checkEndHeader p scopes
|
||||
| _, _ => false
|
||||
|
||||
@[builtinCommandElab «namespace»] def elabNamespace : CommandElab := fun stx =>
|
||||
@[builtin_command_elab «namespace»] def elabNamespace : CommandElab := fun stx =>
|
||||
match stx with
|
||||
| `(namespace $n) => addNamespace n.getId
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab «section»] def elabSection : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «section»] def elabSection : CommandElab := fun stx => do
|
||||
match stx with
|
||||
| `(section $header:ident) => addScopes (isNewNamespace := false) (isNoncomputable := false) header.getId
|
||||
| `(section) => addScope (isNewNamespace := false) (isNoncomputable := false) "" (← getCurrNamespace)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab noncomputableSection] def elabNonComputableSection : CommandElab := fun stx => do
|
||||
@[builtin_command_elab noncomputableSection] def elabNonComputableSection : CommandElab := fun stx => do
|
||||
match stx with
|
||||
| `(noncomputable section $header:ident) => addScopes (isNewNamespace := false) (isNoncomputable := true) header.getId
|
||||
| `(noncomputable section) => addScope (isNewNamespace := false) (isNoncomputable := true) "" (← getCurrNamespace)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab «end»] def elabEnd : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «end»] def elabEnd : CommandElab := fun stx => do
|
||||
let header? := (stx.getArg 1).getOptionalIdent?;
|
||||
let endSize := match header? with
|
||||
| none => 1
|
||||
|
|
@ -109,18 +109,18 @@ private partial def elabChoiceAux (cmds : Array Syntax) (i : Nat) : CommandElabM
|
|||
else
|
||||
throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab choice] def elabChoice : CommandElab := fun stx =>
|
||||
@[builtin_command_elab choice] def elabChoice : CommandElab := fun stx =>
|
||||
elabChoiceAux stx.getArgs 0
|
||||
|
||||
@[builtinCommandElab «universe»] def elabUniverse : CommandElab := fun n => do
|
||||
@[builtin_command_elab «universe»] def elabUniverse : CommandElab := fun n => do
|
||||
n[1].forArgsM addUnivLevel
|
||||
|
||||
@[builtinCommandElab «init_quot»] def elabInitQuot : CommandElab := fun _ => do
|
||||
@[builtin_command_elab «init_quot»] def elabInitQuot : CommandElab := fun _ => do
|
||||
match (← getEnv).addDecl Declaration.quotDecl with
|
||||
| Except.ok env => setEnv env
|
||||
| Except.error ex => throwError (ex.toMessageData (← getOptions))
|
||||
|
||||
@[builtinCommandElab «export»] def elabExport : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «export»] def elabExport : CommandElab := fun stx => do
|
||||
let `(export $ns ($ids*)) := stx | throwUnsupportedSyntax
|
||||
let nss ← resolveNamespace ns
|
||||
let currNamespace ← getCurrNamespace
|
||||
|
|
@ -132,7 +132,7 @@ private partial def elabChoiceAux (cmds : Array Syntax) (i : Nat) : CommandElabM
|
|||
aliases := aliases.push (currNamespace ++ id, declName)
|
||||
modify fun s => { s with env := aliases.foldl (init := s.env) fun env p => addAlias env p.1 p.2 }
|
||||
|
||||
@[builtinCommandElab «open»] def elabOpen : CommandElab
|
||||
@[builtin_command_elab «open»] def elabOpen : CommandElab
|
||||
| `(open $decl:openDecl) => do
|
||||
let openDecls ← elabOpenDecl decl
|
||||
modifyScope fun scope => { scope with openDecls := openDecls }
|
||||
|
|
@ -217,7 +217,7 @@ private def replaceBinderAnnotation (binder : TSyntax ``Parser.Term.bracketedBin
|
|||
else
|
||||
return #[binder]
|
||||
|
||||
@[builtinCommandElab «variable»] def elabVariable : CommandElab
|
||||
@[builtin_command_elab «variable»] def elabVariable : CommandElab
|
||||
| `(variable $binders*) => do
|
||||
-- Try to elaborate `binders` for sanity checking
|
||||
runTermElabM fun _ => Term.withAutoBoundImplicit <|
|
||||
|
|
@ -242,9 +242,9 @@ def elabCheckCore (ignoreStuckTC : Bool) : CommandElab
|
|||
logInfoAt tk m!"{e} : {type}"
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab Lean.Parser.Command.check] def elabCheck : CommandElab := elabCheckCore (ignoreStuckTC := true)
|
||||
@[builtin_command_elab Lean.Parser.Command.check] def elabCheck : CommandElab := elabCheckCore (ignoreStuckTC := true)
|
||||
|
||||
@[builtinCommandElab Lean.Parser.Command.reduce] def elabReduce : CommandElab
|
||||
@[builtin_command_elab Lean.Parser.Command.reduce] def elabReduce : CommandElab
|
||||
| `(#reduce%$tk $term) => withoutModifyingEnv <| runTermElabM fun _ => Term.withDeclName `_reduce do
|
||||
let e ← Term.elabTerm term none
|
||||
Term.synthesizeSyntheticMVarsNoPostponing
|
||||
|
|
@ -278,7 +278,7 @@ def failIfSucceeds (x : CommandElabM Unit) : CommandElabM Unit := do
|
|||
if succeeded then
|
||||
throwError "unexpected success"
|
||||
|
||||
@[builtinCommandElab «check_failure»] def elabCheckFailure : CommandElab
|
||||
@[builtin_command_elab «check_failure»] def elabCheckFailure : CommandElab
|
||||
| `(#check_failure $term) => do
|
||||
failIfSucceeds <| elabCheckCore (ignoreStuckTC := false) (← `(#check $term))
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
|
@ -386,10 +386,10 @@ unsafe def elabEvalUnsafe : CommandElab
|
|||
elabEval
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab «eval», implementedBy elabEvalUnsafe]
|
||||
@[builtin_command_elab «eval», implemented_by elabEvalUnsafe]
|
||||
opaque elabEval : CommandElab
|
||||
|
||||
@[builtinCommandElab «synth»] def elabSynth : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «synth»] def elabSynth : CommandElab := fun stx => do
|
||||
let term := stx[1]
|
||||
withoutModifyingEnv <| runTermElabM fun _ => Term.withDeclName `_synth_cmd do
|
||||
let inst ← Term.elabTerm term none
|
||||
|
|
@ -399,26 +399,26 @@ opaque elabEval : CommandElab
|
|||
logInfo val
|
||||
pure ()
|
||||
|
||||
@[builtinCommandElab «set_option»] def elabSetOption : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «set_option»] def elabSetOption : CommandElab := fun stx => do
|
||||
let options ← Elab.elabSetOption stx[1] stx[2]
|
||||
modify fun s => { s with maxRecDepth := maxRecDepth.get options }
|
||||
modifyScope fun scope => { scope with opts := options }
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.«in»] def expandInCmd : Macro
|
||||
@[builtin_macro Lean.Parser.Command.«in»] def expandInCmd : Macro
|
||||
| `($cmd₁ in $cmd₂) => `(section $cmd₁:command $cmd₂ end)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
@[builtinCommandElab Parser.Command.addDocString] def elabAddDeclDoc : CommandElab := fun stx => do
|
||||
@[builtin_command_elab Parser.Command.addDocString] def elabAddDeclDoc : CommandElab := fun stx => do
|
||||
match stx with
|
||||
| `($doc:docComment add_decl_doc $id) =>
|
||||
let declName ← resolveGlobalConstNoOverloadWithInfo id
|
||||
addDocString declName (← getDocStringText doc)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab Parser.Command.exit] def elabExit : CommandElab := fun _ =>
|
||||
@[builtin_command_elab Parser.Command.exit] def elabExit : CommandElab := fun _ =>
|
||||
logWarning "using 'exit' to interrupt Lean"
|
||||
|
||||
@[builtinCommandElab Parser.Command.import] def elabImport : CommandElab := fun _ =>
|
||||
@[builtin_command_elab Parser.Command.import] def elabImport : CommandElab := fun _ =>
|
||||
throwError "invalid 'import' command, it must be used in the beginning of the file"
|
||||
|
||||
end Lean.Elab.Command
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import Lean.Elab.SyntheticMVars
|
|||
namespace Lean.Elab.Term
|
||||
open Meta
|
||||
|
||||
@[builtinTermElab coeNotation] def elabCoe : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab coeNotation] def elabCoe : TermElab := fun stx expectedType? => do
|
||||
let stx := stx[1]
|
||||
tryPostponeIfNoneOrMVar expectedType?
|
||||
let e ← elabTerm stx none
|
||||
|
|
@ -19,7 +19,7 @@ open Meta
|
|||
throwError "invalid coercion notation, expected type is not known"
|
||||
ensureHasType expectedType? e
|
||||
|
||||
@[builtinTermElab anonymousCtor] def elabAnonymousCtor : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab anonymousCtor] def elabAnonymousCtor : TermElab := fun stx expectedType? =>
|
||||
match stx with
|
||||
| `(⟨$args,*⟩) => do
|
||||
tryPostponeIfNoneOrMVar expectedType?
|
||||
|
|
@ -57,18 +57,18 @@ open Meta
|
|||
| none => throwError "invalid constructor ⟨...⟩, expected type must be known"
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab borrowed] def elabBorrowed : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab borrowed] def elabBorrowed : TermElab := fun stx expectedType? =>
|
||||
match stx with
|
||||
| `(@& $e) => return markBorrowed (← elabTerm e expectedType?)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.show] def expandShow : Macro := fun stx =>
|
||||
@[builtin_macro Lean.Parser.Term.show] def expandShow : Macro := fun stx =>
|
||||
match stx with
|
||||
| `(show $type from $val) => let thisId := mkIdentFrom stx `this; `(let_fun $thisId : $type := $val; $thisId)
|
||||
| `(show $type by%$b $tac) => `(show $type from by%$b $tac)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.have] def expandHave : Macro := fun stx =>
|
||||
@[builtin_macro Lean.Parser.Term.have] def expandHave : Macro := fun stx =>
|
||||
match stx with
|
||||
| `(have $x $bs* $[: $type]? := $val; $body) => `(let_fun $x $bs* $[: $type]? := $val; $body)
|
||||
| `(have%$tk $[: $type]? := $val; $body) => `(have $(mkIdentFrom tk `this (canonical := true)) $[: $type]? := $val; $body)
|
||||
|
|
@ -77,7 +77,7 @@ open Meta
|
|||
| `(have $pattern:term $[: $type]? := $val:term; $body) => `(let_fun $pattern:term $[: $type]? := $val:term ; $body)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.suffices] def expandSuffices : Macro
|
||||
@[builtin_macro Lean.Parser.Term.suffices] def expandSuffices : Macro
|
||||
| `(suffices%$tk $[$x :]? $type from $val; $body) => `(have%$tk $[$x]? : $type := $body; $val)
|
||||
| `(suffices%$tk $[$x :]? $type by%$b $tac:tacticSeq; $body) => `(have%$tk $[$x]? : $type := $body; by%$b $tac)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
|
@ -93,7 +93,7 @@ private def elabParserMacroAux (prec e : Term) (withAnonymousAntiquot : Bool) :
|
|||
``(withAntiquot (mkAntiquot $s $kind $(quote withAnonymousAntiquot)) (leadingNode $kind $prec $e))
|
||||
| _ => throwError "invalid `leading_parser` macro, unexpected declaration name"
|
||||
|
||||
@[builtinTermElab «leading_parser»] def elabLeadingParserMacro : TermElab :=
|
||||
@[builtin_term_elab «leading_parser»] def elabLeadingParserMacro : TermElab :=
|
||||
adaptExpander fun stx => match stx with
|
||||
| `(leading_parser $[: $prec?]? $[(withAnonymousAntiquot := $anon?)]? $e) =>
|
||||
elabParserMacroAux (prec?.getD (quote Parser.maxPrec)) e (anon?.all (·.raw.isOfKind ``Parser.Term.trueVal))
|
||||
|
|
@ -105,13 +105,13 @@ private def elabTParserMacroAux (prec lhsPrec e : Term) : TermElabM Syntax := do
|
|||
| some declName => let kind := quote declName; ``(Lean.Parser.trailingNode $kind $prec $lhsPrec $e)
|
||||
| none => throwError "invalid `trailing_parser` macro, it must be used in definitions"
|
||||
|
||||
@[builtinTermElab «trailing_parser»] def elabTrailingParserMacro : TermElab :=
|
||||
@[builtin_term_elab «trailing_parser»] def elabTrailingParserMacro : TermElab :=
|
||||
adaptExpander fun stx => match stx with
|
||||
| `(trailing_parser$[:$prec?]?$[:$lhsPrec?]? $e) =>
|
||||
elabTParserMacroAux (prec?.getD <| quote Parser.maxPrec) (lhsPrec?.getD <| quote 0) e
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab Lean.Parser.Term.panic] def elabPanic : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab Lean.Parser.Term.panic] def elabPanic : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(panic! $arg) =>
|
||||
let pos ← getRefPosition
|
||||
|
|
@ -122,10 +122,10 @@ private def elabTParserMacroAux (prec lhsPrec e : Term) : TermElabM Syntax := do
|
|||
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.unreachable] def expandUnreachable : Macro := fun _ =>
|
||||
@[builtin_macro Lean.Parser.Term.unreachable] def expandUnreachable : Macro := fun _ =>
|
||||
`(panic! "unreachable code has been reached")
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.assert] def expandAssert : Macro
|
||||
@[builtin_macro Lean.Parser.Term.assert] def expandAssert : Macro
|
||||
| `(assert! $cond; $body) =>
|
||||
-- TODO: support for disabling runtime assertions
|
||||
match cond.raw.reprint with
|
||||
|
|
@ -133,12 +133,12 @@ private def elabTParserMacroAux (prec lhsPrec e : Term) : TermElabM Syntax := do
|
|||
| none => `(if $cond then $body else panic! ("assertion violation"))
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.dbgTrace] def expandDbgTrace : Macro
|
||||
@[builtin_macro Lean.Parser.Term.dbgTrace] def expandDbgTrace : Macro
|
||||
| `(dbg_trace $arg:interpolatedStr; $body) => `(dbgTrace (s! $arg) fun _ => $body)
|
||||
| `(dbg_trace $arg:term; $body) => `(dbgTrace (toString $arg) fun _ => $body)
|
||||
| _ => Macro.throwUnsupported
|
||||
|
||||
@[builtinTermElab «sorry»] def elabSorry : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «sorry»] def elabSorry : TermElab := fun stx expectedType? => do
|
||||
let stxNew ← `(sorryAx _ false)
|
||||
withMacroExpansion stx stxNew <| elabTerm stxNew expectedType?
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ where
|
|||
| `(($e)) => Term.expandCDot? e
|
||||
| _ => Term.expandCDot? stx
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.paren] def expandParen : Macro
|
||||
@[builtin_macro Lean.Parser.Term.paren] def expandParen : Macro
|
||||
| `(()) => `(Unit.unit)
|
||||
| `(($e : $type)) => do
|
||||
match (← expandCDot? e) with
|
||||
|
|
@ -233,7 +233,7 @@ where
|
|||
else
|
||||
throw <| Macro.Exception.error stx "unexpected parentheses notation"
|
||||
|
||||
@[builtinTermElab paren] def elabParen : TermElab := fun stx _ => do
|
||||
@[builtin_term_elab paren] def elabParen : TermElab := fun stx _ => do
|
||||
match stx with
|
||||
| `(($e : $type)) =>
|
||||
let type ← withSynthesize (mayPostpone := true) <| elabType type
|
||||
|
|
@ -260,7 +260,7 @@ private def withLocalIdentFor (stx : Term) (e : Expr) (k : Term → TermElabM Ex
|
|||
let aux ← withLocalDeclD id (← inferType e) fun x => do mkLambdaFVars #[x] (← k (mkIdentFrom stx id))
|
||||
return mkApp aux e
|
||||
|
||||
@[builtinTermElab subst] def elabSubst : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab subst] def elabSubst : TermElab := fun stx expectedType? => do
|
||||
let expectedType? ← tryPostponeIfHasMVars? expectedType?
|
||||
match stx with
|
||||
| `($heqStx ▸ $hStx) => do
|
||||
|
|
@ -334,7 +334,7 @@ private def withLocalIdentFor (stx : Term) (e : Expr) (k : Term → TermElabM Ex
|
|||
mkEqRec motive h heq
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab stateRefT] def elabStateRefT : TermElab := fun stx _ => do
|
||||
@[builtin_term_elab stateRefT] def elabStateRefT : TermElab := fun stx _ => do
|
||||
let σ ← elabType stx[1]
|
||||
let mut mStx := stx[2]
|
||||
if mStx.getKind == ``Lean.Parser.Term.macroDollarArg then
|
||||
|
|
@ -345,7 +345,7 @@ private def withLocalIdentFor (stx : Term) (e : Expr) (k : Term → TermElabM Ex
|
|||
discard <| mkInstMVar stWorld
|
||||
mkAppM ``StateRefT' #[ω, σ, m]
|
||||
|
||||
@[builtinTermElab noindex] def elabNoindex : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab noindex] def elabNoindex : TermElab := fun stx expectedType? => do
|
||||
let e ← elabTerm stx[1] expectedType?
|
||||
return DiscrTree.mkNoindexAnnotation e
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Lean.Elab.Eval
|
|||
namespace Lean.Elab.Term
|
||||
open Meta
|
||||
|
||||
@[builtinTermElab «prop»] def elabProp : TermElab := fun _ _ =>
|
||||
@[builtin_term_elab «prop»] def elabProp : TermElab := fun _ _ =>
|
||||
return mkSort levelZero
|
||||
|
||||
private def elabOptLevel (stx : Syntax) : TermElabM Level :=
|
||||
|
|
@ -19,10 +19,10 @@ private def elabOptLevel (stx : Syntax) : TermElabM Level :=
|
|||
else
|
||||
elabLevel stx[0]
|
||||
|
||||
@[builtinTermElab «sort»] def elabSort : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab «sort»] def elabSort : TermElab := fun stx _ =>
|
||||
return mkSort (← elabOptLevel stx[1])
|
||||
|
||||
@[builtinTermElab «type»] def elabTypeStx : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab «type»] def elabTypeStx : TermElab := fun stx _ =>
|
||||
return mkSort (mkLevelSucc (← elabOptLevel stx[1]))
|
||||
|
||||
/-!
|
||||
|
|
@ -31,13 +31,13 @@ private def elabOptLevel (stx : Syntax) : TermElabM Level :=
|
|||
It doesn't "hurt" if the identifier can be resolved because the expected type is not used in this case.
|
||||
Recall that if the name resolution fails a synthetic sorry is returned.-/
|
||||
|
||||
@[builtinTermElab «pipeCompletion»] def elabPipeCompletion : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «pipeCompletion»] def elabPipeCompletion : TermElab := fun stx expectedType? => do
|
||||
let e ← elabTerm stx[0] none
|
||||
unless e.isSorry do
|
||||
addDotCompletionInfo stx e expectedType?
|
||||
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
|
||||
|
||||
@[builtinTermElab «completion»] def elabCompletion : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «completion»] def elabCompletion : TermElab := fun stx expectedType? => do
|
||||
/- `ident.` is ambiguous in Lean, we may try to be completing a declaration name or access a "field". -/
|
||||
if stx[0].isIdent then
|
||||
/- If we can elaborate the identifier successfully, we assume it is a dot-completion. Otherwise, we treat it as
|
||||
|
|
@ -54,13 +54,13 @@ private def elabOptLevel (stx : Syntax) : TermElabM Level :=
|
|||
else
|
||||
elabPipeCompletion stx expectedType?
|
||||
|
||||
@[builtinTermElab «hole»] def elabHole : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «hole»] def elabHole : TermElab := fun stx expectedType? => do
|
||||
let kind := if (← read).inPattern || !(← read).holesAsSyntheticOpaque then MetavarKind.natural else MetavarKind.syntheticOpaque
|
||||
let mvar ← mkFreshExprMVar expectedType? kind
|
||||
registerMVarErrorHoleInfo mvar.mvarId! stx
|
||||
pure mvar
|
||||
|
||||
@[builtinTermElab «syntheticHole»] def elabSyntheticHole : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «syntheticHole»] def elabSyntheticHole : TermElab := fun stx expectedType? => do
|
||||
let arg := stx[1]
|
||||
let userName := if arg.isIdent then arg.getId else Name.anonymous
|
||||
let mkNewHole : Unit → TermElabM Expr := fun _ => do
|
||||
|
|
@ -98,7 +98,7 @@ private def elabOptLevel (stx : Syntax) : TermElabM Level :=
|
|||
else
|
||||
throwError "synthetic hole has already been defined with an incompatible local context"
|
||||
|
||||
@[builtinTermElab «letMVar»] def elabLetMVar : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «letMVar»] def elabLetMVar : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(let_mvar% ? $n := $e; $b) =>
|
||||
match (← getMCtx).findUserName? n.getId with
|
||||
|
|
@ -117,14 +117,14 @@ private def getMVarFromUserName (ident : Syntax) : MetaM Expr := do
|
|||
| some mvarId => instantiateMVars (mkMVar mvarId)
|
||||
|
||||
|
||||
@[builtinTermElab «waitIfTypeMVar»] def elabWaitIfTypeMVar : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «waitIfTypeMVar»] def elabWaitIfTypeMVar : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(wait_if_type_mvar% ? $n; $b) =>
|
||||
tryPostponeIfMVar (← inferType (← getMVarFromUserName n))
|
||||
elabTerm b expectedType?
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab «waitIfTypeContainsMVar»] def elabWaitIfTypeContainsMVar : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «waitIfTypeContainsMVar»] def elabWaitIfTypeContainsMVar : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(wait_if_type_contains_mvar% ? $n; $b) =>
|
||||
if (← instantiateMVars (← inferType (← getMVarFromUserName n))).hasExprMVar then
|
||||
|
|
@ -132,7 +132,7 @@ private def getMVarFromUserName (ident : Syntax) : MetaM Expr := do
|
|||
elabTerm b expectedType?
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab «waitIfContainsMVar»] def elabWaitIfContainsMVar : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «waitIfContainsMVar»] def elabWaitIfContainsMVar : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(wait_if_contains_mvar% ? $n; $b) =>
|
||||
if (← getMVarFromUserName n).hasExprMVar then
|
||||
|
|
@ -147,20 +147,20 @@ private def mkTacticMVar (type : Expr) (tacticCode : Syntax) : TermElabM Expr :=
|
|||
registerSyntheticMVar ref mvarId <| SyntheticMVarKind.tactic tacticCode (← saveContext)
|
||||
return mvar
|
||||
|
||||
@[builtinTermElab byTactic] def elabByTactic : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab byTactic] def elabByTactic : TermElab := fun stx expectedType? => do
|
||||
match expectedType? with
|
||||
| some expectedType => mkTacticMVar expectedType stx
|
||||
| none =>
|
||||
tryPostpone
|
||||
throwError ("invalid 'by' tactic, expected type has not been provided")
|
||||
|
||||
@[builtinTermElab noImplicitLambda] def elabNoImplicitLambda : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab noImplicitLambda] def elabNoImplicitLambda : TermElab := fun stx expectedType? =>
|
||||
elabTerm stx[1] (mkNoImplicitLambdaAnnotation <$> expectedType?)
|
||||
|
||||
@[builtinTermElab cdot] def elabBadCDot : TermElab := fun _ _ =>
|
||||
@[builtin_term_elab cdot] def elabBadCDot : TermElab := fun _ _ =>
|
||||
throwError "invalid occurrence of `·` notation, it must be surrounded by parentheses (e.g. `(· + 1)`)"
|
||||
|
||||
@[builtinTermElab str] def elabStrLit : TermElab := fun stx _ => do
|
||||
@[builtin_term_elab str] def elabStrLit : TermElab := fun stx _ => do
|
||||
match stx.isStrLit? with
|
||||
| some val => pure $ mkStrLit val
|
||||
| none => throwIllFormedSyntax
|
||||
|
|
@ -172,7 +172,7 @@ private def mkFreshTypeMVarFor (expectedType? : Option Expr) : TermElabM Expr :=
|
|||
| _ => pure ()
|
||||
return typeMVar
|
||||
|
||||
@[builtinTermElab num] def elabNumLit : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab num] def elabNumLit : TermElab := fun stx expectedType? => do
|
||||
let val ← match stx.isNatLit? with
|
||||
| some val => pure val
|
||||
| none => throwIllFormedSyntax
|
||||
|
|
@ -183,12 +183,12 @@ private def mkFreshTypeMVarFor (expectedType? : Option Expr) : TermElabM Expr :=
|
|||
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
|
||||
return r
|
||||
|
||||
@[builtinTermElab rawNatLit] def elabRawNatLit : TermElab := fun stx _ => do
|
||||
@[builtin_term_elab rawNatLit] def elabRawNatLit : TermElab := fun stx _ => do
|
||||
match stx[1].isNatLit? with
|
||||
| some val => return mkRawNatLit val
|
||||
| none => throwIllFormedSyntax
|
||||
|
||||
@[builtinTermElab scientific]
|
||||
@[builtin_term_elab scientific]
|
||||
def elabScientificLit : TermElab := fun stx expectedType? => do
|
||||
match stx.isScientificLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
|
|
@ -200,31 +200,31 @@ def elabScientificLit : TermElab := fun stx expectedType? => do
|
|||
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
|
||||
return r
|
||||
|
||||
@[builtinTermElab char] def elabCharLit : TermElab := fun stx _ => do
|
||||
@[builtin_term_elab char] def elabCharLit : TermElab := fun stx _ => do
|
||||
match stx.isCharLit? with
|
||||
| some val => return mkApp (Lean.mkConst ``Char.ofNat) (mkRawNatLit val.toNat)
|
||||
| none => throwIllFormedSyntax
|
||||
|
||||
@[builtinTermElab quotedName] def elabQuotedName : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab quotedName] def elabQuotedName : TermElab := fun stx _ =>
|
||||
match stx[0].isNameLit? with
|
||||
| some val => pure $ toExpr val
|
||||
| none => throwIllFormedSyntax
|
||||
|
||||
@[builtinTermElab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ =>
|
||||
return toExpr (← resolveGlobalConstNoOverloadWithInfo stx[2])
|
||||
|
||||
@[builtinTermElab declName] def elabDeclName : TermElab := adaptExpander fun _ => do
|
||||
@[builtin_term_elab declName] def elabDeclName : TermElab := adaptExpander fun _ => do
|
||||
let some declName ← getDeclName?
|
||||
| throwError "invalid `decl_name%` macro, the declaration name is not available"
|
||||
return (quote declName : Term)
|
||||
|
||||
@[builtinTermElab Parser.Term.withDeclName] def elabWithDeclName : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab Parser.Term.withDeclName] def elabWithDeclName : TermElab := fun stx expectedType? => do
|
||||
let id := stx[2].getId
|
||||
let id := if stx[1].isNone then id else (← getCurrNamespace) ++ id
|
||||
let e := stx[3]
|
||||
withMacroExpansion stx e <| withDeclName id <| elabTerm e expectedType?
|
||||
|
||||
@[builtinTermElab typeOf] def elabTypeOf : TermElab := fun stx _ => do
|
||||
@[builtin_term_elab typeOf] def elabTypeOf : TermElab := fun stx _ => do
|
||||
inferType (← elabTerm stx[1] none)
|
||||
|
||||
/--
|
||||
|
|
@ -255,7 +255,7 @@ private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
|
|||
else
|
||||
return e
|
||||
|
||||
@[builtinTermElab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx _ =>
|
||||
match stx[2].isStrLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
| some msg => do
|
||||
|
|
@ -264,12 +264,12 @@ private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
|
|||
-- See comment at `mkSilentAnnotationIfHole`
|
||||
mkSilentAnnotationIfHole (← elabTermEnsuringType stx[3] refTermType (errorMsgHeader? := msg))
|
||||
|
||||
@[builtinTermElab ensureExpectedType] def elabEnsureExpectedType : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab ensureExpectedType] def elabEnsureExpectedType : TermElab := fun stx expectedType? =>
|
||||
match stx[1].isStrLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
| some msg => elabTermEnsuringType stx[2] expectedType? (errorMsgHeader? := msg)
|
||||
|
||||
@[builtinTermElab clear] def elabClear : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab clear] def elabClear : TermElab := fun stx expectedType? => do
|
||||
let some (.fvar fvarId) ← isLocalIdent? stx[1]
|
||||
| throwErrorAt stx[1] "not in scope"
|
||||
let body := stx[3]
|
||||
|
|
@ -289,7 +289,7 @@ private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
|
|||
else
|
||||
elabTerm body expectedType?
|
||||
|
||||
@[builtinTermElab «open»] def elabOpen : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «open»] def elabOpen : TermElab := fun stx expectedType? => do
|
||||
let `(open $decl in $e) := stx | throwUnsupportedSyntax
|
||||
try
|
||||
pushScope
|
||||
|
|
@ -299,12 +299,12 @@ private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
|
|||
finally
|
||||
popScope
|
||||
|
||||
@[builtinTermElab «set_option»] def elabSetOption : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «set_option»] def elabSetOption : TermElab := fun stx expectedType? => do
|
||||
let options ← Elab.elabSetOption stx[1] stx[2]
|
||||
withTheReader Core.Context (fun ctx => { ctx with maxRecDepth := maxRecDepth.get options, options := options }) do
|
||||
elabTerm stx[4] expectedType?
|
||||
|
||||
@[builtinTermElab withAnnotateTerm] def elabWithAnnotateTerm : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab withAnnotateTerm] def elabWithAnnotateTerm : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(with_annotate_term $stx $e) =>
|
||||
withInfoContext' stx (elabTerm e expectedType?) (mkTermInfo .anonymous (expectedType? := expectedType?) stx)
|
||||
|
|
@ -313,10 +313,10 @@ private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
|
|||
private unsafe def evalFilePathUnsafe (stx : Syntax) : TermElabM System.FilePath :=
|
||||
evalTerm System.FilePath (Lean.mkConst ``System.FilePath) stx
|
||||
|
||||
@[implementedBy evalFilePathUnsafe]
|
||||
@[implemented_by evalFilePathUnsafe]
|
||||
private opaque evalFilePath (stx : Syntax) : TermElabM System.FilePath
|
||||
|
||||
@[builtinTermElab includeStr] def elabIncludeStr : TermElab
|
||||
@[builtin_term_elab includeStr] def elabIncludeStr : TermElab
|
||||
| `(include_str $path:term), _ => do
|
||||
let path ← evalFilePath path
|
||||
let ctx ← readThe Lean.Core.Context
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ def elabCalcSteps (steps : Array Syntax) : TermElabM Expr := do
|
|||
return result
|
||||
|
||||
/-- Elaborator for the `calc` term mode variant. -/
|
||||
@[builtinTermElab «calc»]
|
||||
@[builtin_term_elab «calc»]
|
||||
def elabCalc : TermElab := fun stx expectedType? => do
|
||||
let steps := #[stx[1]] ++ stx[2].getArgs
|
||||
let result ← elabCalcSteps steps
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ whole monad stack at every use site. May eventually be covered by `deriving`.
|
|||
|
||||
Remark: see comment at TermElabM
|
||||
-/
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad CommandElabM := let i := inferInstanceAs (Monad CommandElabM); { pure := i.pure, bind := i.bind }
|
||||
|
||||
def mkState (env : Environment) (messages : MessageLog := {}) (opts : Options := {}) : State := {
|
||||
|
|
@ -81,7 +81,7 @@ instance : MonadEnv CommandElabM where
|
|||
getEnv := do pure (← get).env
|
||||
modifyEnv f := modify fun s => { s with env := f s.env }
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : MonadOptions CommandElabM where
|
||||
getOptions := do pure (← get).scopes.head!.opts
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ instance : MonadQuotation CommandElabM where
|
|||
unsafe def mkCommandElabAttributeUnsafe (ref : Name) : IO (KeyedDeclsAttribute CommandElab) :=
|
||||
mkElabAttribute CommandElab `builtin_command_elab `command_elab `Lean.Parser.Command `Lean.Elab.Command.CommandElab "command" ref
|
||||
|
||||
@[implementedBy mkCommandElabAttributeUnsafe]
|
||||
@[implemented_by mkCommandElabAttributeUnsafe]
|
||||
opaque mkCommandElabAttribute (ref : Name) : IO (KeyedDeclsAttribute CommandElab)
|
||||
|
||||
builtin_initialize commandElabAttribute : KeyedDeclsAttribute CommandElab ← mkCommandElabAttribute decl_name%
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ def setComputedFields (computedFields : Array (Name × Array Name)) : MetaM Unit
|
|||
for (indName, computedFieldNames) in computedFields do
|
||||
for computedFieldName in computedFieldNames do
|
||||
unless computedFieldAttr.hasTag (← getEnv) computedFieldName do
|
||||
logError m!"'{computedFieldName}' must be tagged with @[computedField]"
|
||||
logError m!"'{computedFieldName}' must be tagged with @[computed_field]"
|
||||
mkComputedFieldOverrides indName computedFieldNames
|
||||
|
||||
-- Once all the implemented_by infrastructure is set up, compile everything.
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ def getTerminationHints (stx : Syntax) : TerminationHints :=
|
|||
else
|
||||
{}
|
||||
|
||||
@[builtinCommandElab declaration]
|
||||
@[builtin_command_elab declaration]
|
||||
def elabDeclaration : CommandElab := fun stx => do
|
||||
match (← liftMacroM <| expandDeclNamespace? stx) with
|
||||
| some (ns, newStx) => do
|
||||
|
|
@ -289,7 +289,7 @@ where
|
|||
| _, _ => .anonymous
|
||||
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.mutual]
|
||||
@[builtin_macro Lean.Parser.Command.mutual]
|
||||
def expandMutualNamespace : Macro := fun stx => do
|
||||
let mut nss := #[]
|
||||
for elem in stx[1].getArgs do
|
||||
|
|
@ -307,7 +307,7 @@ def expandMutualNamespace : Macro := fun stx => do
|
|||
let stxNew := stx.setArg 1 (mkNullNode elemsNew)
|
||||
`(namespace $ns $(⟨stxNew⟩) end $ns)
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.mutual]
|
||||
@[builtin_macro Lean.Parser.Command.mutual]
|
||||
def expandMutualElement : Macro := fun stx => do
|
||||
let mut elemsNew := #[]
|
||||
let mut modified := false
|
||||
|
|
@ -320,7 +320,7 @@ def expandMutualElement : Macro := fun stx => do
|
|||
else
|
||||
Macro.throwUnsupported
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.mutual]
|
||||
@[builtin_macro Lean.Parser.Command.mutual]
|
||||
def expandMutualPreamble : Macro := fun stx =>
|
||||
match splitMutualPreamble stx[1].getArgs with
|
||||
| none => Macro.throwUnsupported
|
||||
|
|
@ -330,7 +330,7 @@ def expandMutualPreamble : Macro := fun stx =>
|
|||
let endCmd ← `(end)
|
||||
return mkNullNode (#[secCmd] ++ preamble ++ #[newMutual] ++ #[endCmd])
|
||||
|
||||
@[builtinCommandElab «mutual»]
|
||||
@[builtin_command_elab «mutual»]
|
||||
def elabMutual : CommandElab := fun stx => do
|
||||
let hints := { terminationBy? := stx[3].getOptional?, decreasingBy? := stx[4].getOptional? }
|
||||
if isMutualInductive stx then
|
||||
|
|
@ -351,7 +351,7 @@ def elabMutual : CommandElab := fun stx => do
|
|||
throwError "invalid mutual block"
|
||||
|
||||
/- leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "]" >> many1 ident -/
|
||||
@[builtinCommandElab «attribute»] def elabAttr : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «attribute»] def elabAttr : CommandElab := fun stx => do
|
||||
let mut attrInsts := #[]
|
||||
let mut toErase := #[]
|
||||
for attrKindStx in stx[2].getSepArgs do
|
||||
|
|
@ -371,7 +371,7 @@ def elabMutual : CommandElab := fun stx => do
|
|||
for attrName in toErase do
|
||||
Attribute.erase declName attrName
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.«initialize»] def expandInitialize : Macro
|
||||
@[builtin_macro Lean.Parser.Command.«initialize»] def expandInitialize : Macro
|
||||
| stx@`($declModifiers:declModifiers $kw:initializeKeyword $[$id? : $type? ←]? $doSeq) => do
|
||||
let attrId := mkIdentFrom stx <| if kw.raw[0].isToken "initialize" then `init else `builtin_init
|
||||
if let (some id, some type) := (id?, type?) then
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ private def tryApplyDefHandler (className : Name) (declName : Name) : CommandEla
|
|||
liftTermElabM do
|
||||
Term.processDefDeriving className declName
|
||||
|
||||
@[builtinCommandElab «deriving»] def elabDeriving : CommandElab
|
||||
@[builtin_command_elab «deriving»] def elabDeriving : CommandElab
|
||||
| `(deriving instance $[$classes $[with $argss?]?],* for $[$declNames],*) => do
|
||||
let declNames ← declNames.mapM resolveGlobalConstNoOverloadWithInfo
|
||||
for cls in classes, args? in argss? do
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ private def getDoSeqElems (doSeq : Syntax) : List Syntax :=
|
|||
private def getDoSeq (doStx : Syntax) : Syntax :=
|
||||
doStx[1]
|
||||
|
||||
@[builtinTermElab liftMethod] def elabLiftMethod : TermElab := fun stx _ =>
|
||||
@[builtin_term_elab liftMethod] def elabLiftMethod : TermElab := fun stx _ =>
|
||||
throwErrorAt stx "invalid use of `(<- ...)`, must be nested inside a 'do' expression"
|
||||
|
||||
/-- Return true if we should not lift `(<- ...)` actions nested in the syntax nodes with the given kind. -/
|
||||
|
|
@ -1658,7 +1658,7 @@ def run (doStx : Syntax) (m : Syntax) (returnType : Syntax) : TermElabM CodeBloc
|
|||
|
||||
end ToCodeBlock
|
||||
|
||||
@[builtinTermElab «do»] def elabDo : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «do»] def elabDo : TermElab := fun stx expectedType? => do
|
||||
tryPostponeIfNoneOrMVar expectedType?
|
||||
let bindInfo ← extractBind expectedType?
|
||||
let m ← Term.exprToSyntax bindInfo.m
|
||||
|
|
@ -1676,16 +1676,16 @@ private def toDoElem (newKind : SyntaxNodeKind) : Macro := fun stx => do
|
|||
let stx := stx.setKind newKind
|
||||
withRef stx `(do $stx:doElem)
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.termFor]
|
||||
@[builtin_macro Lean.Parser.Term.termFor]
|
||||
def expandTermFor : Macro := toDoElem ``Parser.Term.doFor
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.termTry]
|
||||
@[builtin_macro Lean.Parser.Term.termTry]
|
||||
def expandTermTry : Macro := toDoElem ``Parser.Term.doTry
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.termUnless]
|
||||
@[builtin_macro Lean.Parser.Term.termUnless]
|
||||
def expandTermUnless : Macro := toDoElem ``Parser.Term.doUnless
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.termReturn]
|
||||
@[builtin_macro Lean.Parser.Term.termReturn]
|
||||
def expandTermReturn : Macro := toDoElem ``Parser.Term.doReturn
|
||||
|
||||
end Lean.Elab.Term
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ def elabElabRulesAux (doc? : Option (TSyntax ``docComment))
|
|||
-- If users want this feature, they add their own `elab_rules` macro that uses this one as a fallback.
|
||||
throwError "unsupported syntax category '{catName}'"
|
||||
|
||||
@[builtinCommandElab «elab_rules»] def elabElabRules : CommandElab :=
|
||||
@[builtin_command_elab «elab_rules»] def elabElabRules : CommandElab :=
|
||||
adaptExpander fun stx => match stx with
|
||||
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind elab_rules $[: $cat?]? $[<= $expty?]? $alts:matchAlt*) =>
|
||||
expandNoKindMacroRulesAux alts "elab_rules" fun kind? alts =>
|
||||
|
|
@ -85,7 +85,7 @@ def elabElabRulesAux (doc? : Option (TSyntax ``docComment))
|
|||
do elabElabRulesAux doc? attrs? attrKind (← resolveSyntaxKind kind.getId) cat? expty? alts
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinCommandElab Lean.Parser.Command.elab]
|
||||
@[builtin_command_elab Lean.Parser.Command.elab]
|
||||
def elabElab : CommandElab
|
||||
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind
|
||||
elab%$tk$[:$prec?]? $[(name := $name?)]? $[(priority := $prio?)]? $args:macroArg* :
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ private def getMonadForIn (expectedType? : Option Expr) : TermElabM Expr := do
|
|||
private def throwForInFailure (forInInstance : Expr) : TermElabM Expr :=
|
||||
throwError "failed to synthesize instance for 'for_in%' notation{indentExpr forInInstance}"
|
||||
|
||||
@[builtinTermElab forInMacro] def elabForIn : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab forInMacro] def elabForIn : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(for_in% $col $init $body) =>
|
||||
match (← isLocalIdent? col) with
|
||||
|
|
@ -48,7 +48,7 @@ private def throwForInFailure (forInInstance : Expr) : TermElabM Expr :=
|
|||
| .none => throwForInFailure forInInstance
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab forInMacro'] def elabForIn' : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab forInMacro'] def elabForIn' : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(for_in'% $col $init $body) =>
|
||||
match (← isLocalIdent? col) with
|
||||
|
|
@ -261,7 +261,7 @@ private def toExprCore (t : Tree) : TermElabM Expr := do
|
|||
|
||||
The motivation is to support default instances such as
|
||||
```
|
||||
@[defaultInstance high]
|
||||
@[default_instance high]
|
||||
instance [Mul α] : HMul α (Array α) (Array α) where
|
||||
hMul a as := as.map (a * ·)
|
||||
|
||||
|
|
@ -364,11 +364,11 @@ mutual
|
|||
|
||||
end
|
||||
|
||||
@[builtinTermElab binop]
|
||||
@[builtin_term_elab binop]
|
||||
def elabBinOp : TermElab := fun stx expectedType? => do
|
||||
toExpr (← toTree stx) expectedType?
|
||||
|
||||
@[builtinTermElab binop_lazy]
|
||||
@[builtin_term_elab binop_lazy]
|
||||
def elabBinOpLazy : TermElab := elabBinOp
|
||||
|
||||
/--
|
||||
|
|
@ -445,11 +445,11 @@ where
|
|||
return (← ensureHasType (Lean.mkConst ``Bool) e)
|
||||
return e
|
||||
|
||||
@[builtinTermElab binrel] def elabBinRel : TermElab := elabBinRelCore false
|
||||
@[builtin_term_elab binrel] def elabBinRel : TermElab := elabBinRelCore false
|
||||
|
||||
@[builtinTermElab binrel_no_prop] def elabBinRelNoProp : TermElab := elabBinRelCore true
|
||||
@[builtin_term_elab binrel_no_prop] def elabBinRelNoProp : TermElab := elabBinRelCore true
|
||||
|
||||
@[builtinTermElab defaultOrOfNonempty]
|
||||
@[builtin_term_elab defaultOrOfNonempty]
|
||||
def elabDefaultOrNonempty : TermElab := fun stx expectedType? => do
|
||||
tryPostponeIfNoneOrMVar expectedType?
|
||||
match expectedType? with
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import Lean.Meta.Injective
|
|||
|
||||
namespace Lean.Elab.Command
|
||||
|
||||
@[builtinCommandElab genInjectiveTheorems] def elabGenInjectiveTheorems : CommandElab := fun stx => do
|
||||
@[builtin_command_elab genInjectiveTheorems] def elabGenInjectiveTheorems : CommandElab := fun stx => do
|
||||
let declName ← resolveGlobalConstNoOverloadWithInfo stx[1]
|
||||
liftTermElabM do
|
||||
Meta.mkInjectiveTheorems declName
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ private def registerLetRecsToLift (views : Array LetRecDeclView) (fvars : Array
|
|||
: LetRecToLift }
|
||||
modify fun s => { s with letRecsToLift := toLift.toList ++ s.letRecsToLift }
|
||||
|
||||
@[builtinTermElab «letrec»] def elabLetRec : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «letrec»] def elabLetRec : TermElab := fun stx expectedType? => do
|
||||
let view ← mkLetRecDeclView stx
|
||||
withAuxLocalDecls view.decls fun fvars => do
|
||||
for decl in view.decls, fvar in fvars do
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ abbrev LevelElabM := ReaderT Context (EStateM Exception State)
|
|||
instance : MonadOptions LevelElabM where
|
||||
getOptions := return (← read).options
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : MonadRef LevelElabM where
|
||||
getRef := return (← read).ref
|
||||
withRef ref x := withReader (fun ctx => { ctx with ref := ref }) x
|
||||
|
|
@ -33,7 +33,7 @@ instance : MonadRef LevelElabM where
|
|||
instance : AddMessageContext LevelElabM where
|
||||
addMessageContext msg := pure msg
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : MonadNameGenerator LevelElabM where
|
||||
getNGen := return (← get).ngen
|
||||
setNGen ngen := modify fun s => { s with ngen := ngen }
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ open Lean.Syntax
|
|||
open Lean.Parser.Term hiding macroArg
|
||||
open Lean.Parser.Command
|
||||
|
||||
@[builtinCommandElab Lean.Parser.Command.macro] def elabMacro : CommandElab
|
||||
@[builtin_command_elab Lean.Parser.Command.macro] def elabMacro : CommandElab
|
||||
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind
|
||||
macro%$tk$[:$prec?]? $[(name := $name?)]? $[(priority := $prio?)]? $args:macroArg* : $cat => $rhs) =>
|
||||
-- exclude command prefix from synthetic position used for e.g. jumping to the macro definition
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ def elabMacroRulesAux (doc? : Option (TSyntax ``docComment))
|
|||
aux_def macroRules $(mkIdentFrom tk k (canonical := true)) : Macro :=
|
||||
fun $alts:matchAlt* | _ => no_error_if_unused% throw Lean.Macro.Exception.unsupportedSyntax)
|
||||
|
||||
@[builtinCommandElab «macro_rules»] def elabMacroRules : CommandElab :=
|
||||
@[builtin_command_elab «macro_rules»] def elabMacroRules : CommandElab :=
|
||||
adaptExpander fun stx => match stx with
|
||||
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind macro_rules%$tk $alts:matchAlt*) =>
|
||||
-- exclude command prefix from synthetic position used for e.g. jumping to the macro definition
|
||||
|
|
|
|||
|
|
@ -151,12 +151,12 @@ private def getMatchAlts : Syntax → Array MatchAltView
|
|||
| _ => none
|
||||
| _ => #[]
|
||||
|
||||
@[builtinTermElab inaccessible] def elabInaccessible : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab inaccessible] def elabInaccessible : TermElab := fun stx expectedType? => do
|
||||
let e ← elabTerm stx[1] expectedType?
|
||||
return mkInaccessible e
|
||||
|
||||
open Lean.Elab.Term.Quotation in
|
||||
@[builtinQuotPrecheck Lean.Parser.Term.match] def precheckMatch : Precheck
|
||||
@[builtin_quot_precheck Lean.Parser.Term.match] def precheckMatch : Precheck
|
||||
| `(match $[$discrs:term],* with $[| $[$patss],* => $rhss]*) => do
|
||||
discrs.forM precheck
|
||||
for (pats, rhs) in patss.zip rhss do
|
||||
|
|
@ -1214,7 +1214,7 @@ where
|
|||
isAtomicIdent (stx : Syntax) : Bool :=
|
||||
stx.isIdent && stx.getId.eraseMacroScopes.isAtomic
|
||||
|
||||
@[builtinTermElab «match»] def elabMatch : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «match»] def elabMatch : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(match $discr:term with | $y:ident => $rhs) =>
|
||||
if (← isPatternVar y) then expandSimpleMatch stx discr y rhs expectedType? else elabMatchDefault stx expectedType?
|
||||
|
|
@ -1237,7 +1237,7 @@ builtin_initialize
|
|||
registerTraceClass `Elab.match
|
||||
|
||||
-- leading_parser:leadPrec "nomatch " >> termParser
|
||||
@[builtinTermElab «nomatch»] def elabNoMatch : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab «nomatch»] def elabNoMatch : TermElab := fun stx expectedType? => do
|
||||
match stx with
|
||||
| `(nomatch $discrExpr) =>
|
||||
if (← isAtomicDiscr discrExpr) then
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import Lean.Elab.Attributes
|
|||
|
||||
namespace Lean.Elab.Command
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.mixfix] def expandMixfix : Macro := fun stx =>
|
||||
@[builtin_macro Lean.Parser.Command.mixfix] def expandMixfix : Macro := fun stx =>
|
||||
withAttrKindGlobal stx fun stx => do
|
||||
match stx with
|
||||
| `($[$doc?:docComment]? $[@[$attrs?,*]]? infixl:$prec $[(name := $name)]? $[(priority := $prio)]? $op => $f) =>
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ private def expandNotationAux (ref : Syntax) (currNamespace : Name)
|
|||
| some delabDecl => return mkNullNode #[stxDecl, macroDecls, delabDecl]
|
||||
| none => return mkNullNode #[stxDecl, macroDecls]
|
||||
|
||||
@[builtinMacro Lean.Parser.Command.notation] def expandNotation : Macro
|
||||
@[builtin_macro Lean.Parser.Command.notation] def expandNotation : Macro
|
||||
| stx@`($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind
|
||||
notation $[: $prec?]? $[(name := $name?)]? $[(priority := $prio?)]? $items* => $rhs) => do
|
||||
-- trigger scoped checks early and only once
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ private def printId (id : Syntax) : CommandElabM Unit := do
|
|||
let cs ← resolveGlobalConstWithInfos id
|
||||
cs.forM printIdCore
|
||||
|
||||
@[builtinCommandElab «print»] def elabPrint : CommandElab
|
||||
@[builtin_command_elab «print»] def elabPrint : CommandElab
|
||||
| `(#print%$tk $id:ident) => withRef tk <| printId id
|
||||
| `(#print%$tk $s:str) => logInfoAt tk s.getString
|
||||
| _ => throwError "invalid #print command"
|
||||
|
|
@ -121,7 +121,7 @@ private def printAxiomsOf (constName : Name) : CommandElabM Unit := do
|
|||
else
|
||||
logInfo m!"'{constName}' depends on axioms: {s.axioms.toList}"
|
||||
|
||||
@[builtinCommandElab «printAxioms»] def elabPrintAxioms : CommandElab
|
||||
@[builtin_command_elab «printAxioms»] def elabPrintAxioms : CommandElab
|
||||
| `(#print%$tk axioms $id) => withRef tk do
|
||||
let cs ← resolveGlobalConstWithInfos id
|
||||
cs.forM printAxiomsOf
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ def stxQuot.expand (stx : Syntax) : TermElabM Syntax := do
|
|||
mkSyntaxQuotation stx kind
|
||||
|
||||
macro "elab_stx_quot" kind:ident : command =>
|
||||
`(@[builtinTermElab $kind:ident] def elabQuot : TermElab := adaptExpander stxQuot.expand)
|
||||
`(@[builtin_term_elab $kind:ident] def elabQuot : TermElab := adaptExpander stxQuot.expand)
|
||||
|
||||
elab_stx_quot Parser.Term.quot
|
||||
elab_stx_quot Parser.Tactic.quot
|
||||
|
|
@ -663,10 +663,10 @@ def match_syntax.expand (stx : Syntax) : TermElabM Syntax := do
|
|||
return stx
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab «match»] def elabMatchSyntax : TermElab :=
|
||||
@[builtin_term_elab «match»] def elabMatchSyntax : TermElab :=
|
||||
adaptExpander match_syntax.expand
|
||||
|
||||
@[builtinTermElab noErrorIfUnused] def elabNoErrorIfUnused : TermElab := fun stx expectedType? =>
|
||||
@[builtin_term_elab noErrorIfUnused] def elabNoErrorIfUnused : TermElab := fun stx expectedType? =>
|
||||
match stx with
|
||||
| `(no_error_if_unused% $term) => elabTerm term expectedType?
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ and calling `precheck` recursively on nested terms, potentially with an extended
|
|||
Macros without registered precheck hook are unfolded, and identifier-less syntax is ultimately assumed to be well-formed.",
|
||||
valueTypeName := ``Precheck
|
||||
} `Lean.Elab.Term.Quotation.precheckAttribute
|
||||
@[builtinInit mkPrecheckAttribute] opaque precheckAttribute : KeyedDeclsAttribute Precheck
|
||||
@[builtin_init mkPrecheckAttribute] opaque precheckAttribute : KeyedDeclsAttribute Precheck
|
||||
|
||||
partial def precheck : Precheck := fun stx => do
|
||||
if let p::_ := precheckAttribute.getValues (← getEnv) stx.getKind then
|
||||
|
|
@ -80,7 +80,7 @@ def runPrecheck (stx : Syntax) : TermElabM Unit := do
|
|||
private def isSectionVariable (e : Expr) : TermElabM Bool := do
|
||||
return (← read).sectionFVars.any fun _ v => e == v
|
||||
|
||||
@[builtinQuotPrecheck ident] def precheckIdent : Precheck := fun stx =>
|
||||
@[builtin_quot_precheck ident] def precheckIdent : Precheck := fun stx =>
|
||||
match stx with
|
||||
| Syntax.ident _ _ val preresolved => do
|
||||
if !preresolved.isEmpty then
|
||||
|
|
@ -106,7 +106,7 @@ private def isSectionVariable (e : Expr) : TermElabM Bool := do
|
|||
throwError "unknown identifier '{val}' at quotation precheck; you can use `set_option quotPrecheck false` to disable this check."
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinQuotPrecheck Lean.Parser.Term.app] def precheckApp : Precheck
|
||||
@[builtin_quot_precheck Lean.Parser.Term.app] def precheckApp : Precheck
|
||||
| `($f $args*) => do
|
||||
precheck f
|
||||
for arg in args.raw do
|
||||
|
|
@ -116,7 +116,7 @@ private def isSectionVariable (e : Expr) : TermElabM Bool := do
|
|||
| `(argument| $e:term) => precheck e
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinQuotPrecheck Lean.Parser.Term.paren] def precheckParen : Precheck
|
||||
@[builtin_quot_precheck Lean.Parser.Term.paren] def precheckParen : Precheck
|
||||
| `(()) => pure ()
|
||||
| `(($e : $type)) => do
|
||||
precheck e
|
||||
|
|
@ -127,7 +127,7 @@ private def isSectionVariable (e : Expr) : TermElabM Bool := do
|
|||
es.getElems.raw.forM precheck
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinQuotPrecheck choice] def precheckChoice : Precheck := fun stx => do
|
||||
@[builtin_quot_precheck choice] def precheckChoice : Precheck := fun stx => do
|
||||
let checks ← stx.getArgs.mapM (_root_.observing ∘ precheck)
|
||||
let fails := checks.zip stx.getArgs |>.filterMap fun
|
||||
| (.error e, stx) => some m!"{stx}\n{e.toMessageData}"
|
||||
|
|
@ -135,7 +135,7 @@ private def isSectionVariable (e : Expr) : TermElabM Bool := do
|
|||
unless fails.isEmpty do
|
||||
throwErrorAt stx "ambiguous notation with at least one interpretation that failed quotation precheck, possible interpretations {indentD (MessageData.joinSep fails.toList m!"\n\n")}"
|
||||
|
||||
@[builtinTermElab precheckedQuot] def elabPrecheckedQuot : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab precheckedQuot] def elabPrecheckedQuot : TermElab := fun stx expectedType? => do
|
||||
let singleQuot := stx[1]
|
||||
runPrecheck singleQuot.getQuotContent
|
||||
adaptExpander (fun _ => pure singleQuot) stx expectedType?
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ open TSyntax.Compat
|
|||
>> " }"
|
||||
-/
|
||||
|
||||
@[builtinMacro Lean.Parser.Term.structInst] def expandStructInstExpectedType : Macro := fun stx =>
|
||||
@[builtin_macro Lean.Parser.Term.structInst] def expandStructInstExpectedType : Macro := fun stx =>
|
||||
let expectedArg := stx[4]
|
||||
if expectedArg.isNone then
|
||||
Macro.throwUnsupported
|
||||
|
|
@ -34,7 +34,7 @@ open TSyntax.Compat
|
|||
`(($stxNew : $expected))
|
||||
|
||||
/-- Expand field abbreviations. Example: `{ x, y := 0 }` expands to `{ x := x, y := 0 }` -/
|
||||
@[builtinMacro Lean.Parser.Term.structInst] def expandStructInstFieldAbbrev : Macro
|
||||
@[builtin_macro Lean.Parser.Term.structInst] def expandStructInstFieldAbbrev : Macro
|
||||
| `({ $[$srcs,* with]? $fields,* $[..%$ell]? $[: $ty]? }) =>
|
||||
if fields.getElems.raw.any (·.getKind == ``Lean.Parser.Term.structInstFieldAbbrev) then do
|
||||
let fieldsNew ← fields.getElems.mapM fun
|
||||
|
|
@ -900,7 +900,7 @@ private def elabStructInstAux (stx : Syntax) (expectedType? : Option Expr) (sour
|
|||
synthesizeAppInstMVars instMVars r
|
||||
return r
|
||||
|
||||
@[builtinTermElab structInst] def elabStructInst : TermElab := fun stx expectedType? => do
|
||||
@[builtin_term_elab structInst] def elabStructInst : TermElab := fun stx expectedType? => do
|
||||
match (← expandNonAtomicExplicitSources stx) with
|
||||
| some stxNew => withMacroExpansion stx stxNew <| elabTerm stxNew expectedType?
|
||||
| none =>
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ private def declareSyntaxCatQuotParser (catName : Name) : CommandElabM Unit := d
|
|||
(Lean.ParserDescr.symbol ")")))))
|
||||
elabCommand cmd
|
||||
|
||||
@[builtinCommandElab syntaxCat] def elabDeclareSyntaxCat : CommandElab := fun stx => do
|
||||
@[builtin_command_elab syntaxCat] def elabDeclareSyntaxCat : CommandElab := fun stx => do
|
||||
let docString? := stx[0].getOptional?.map fun stx => ⟨stx⟩
|
||||
let catName := stx[2].getId
|
||||
let catBehavior :=
|
||||
|
|
@ -333,7 +333,7 @@ def resolveSyntaxKind (k : Name) : CommandElabM Name := do
|
|||
<|>
|
||||
throwError "invalid syntax node kind '{k}'"
|
||||
|
||||
@[builtinCommandElab «syntax»] def elabSyntax : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «syntax»] def elabSyntax : CommandElab := fun stx => do
|
||||
let `($[$doc?:docComment]? $[ @[ $attrInstances:attrInstance,* ] ]? $attrKind:attrKind
|
||||
syntax%$tk $[: $prec? ]? $[(name := $name?)]? $[(priority := $prio?)]? $[$ps:stx]* : $catStx) := stx
|
||||
| throwUnsupportedSyntax
|
||||
|
|
@ -368,7 +368,7 @@ def resolveSyntaxKind (k : Name) : CommandElabM Name := do
|
|||
trace `Elab fun _ => d
|
||||
withMacroExpansion stx d <| elabCommand d
|
||||
|
||||
@[builtinCommandElab «syntaxAbbrev»] def elabSyntaxAbbrev : CommandElab := fun stx => do
|
||||
@[builtin_command_elab «syntaxAbbrev»] def elabSyntaxAbbrev : CommandElab := fun stx => do
|
||||
let `($[$doc?:docComment]? syntax $declName:ident := $[$ps:stx]*) ← pure stx | throwUnsupportedSyntax
|
||||
-- TODO: nonatomic names
|
||||
let (val, _) ← runTermElabM fun _ => Term.toParserDescr (mkNullNode ps) Name.anonymous
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ whole monad stack at every use site. May eventually be covered by `deriving`.
|
|||
|
||||
See comment at `Monad TermElabM`
|
||||
-/
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad TacticM :=
|
||||
let i := inferInstanceAs (Monad TacticM);
|
||||
{ pure := i.pure, bind := i.bind }
|
||||
|
|
@ -105,7 +105,7 @@ protected def getMainModule : TacticM Name := do pure (← getEnv).mai
|
|||
unsafe def mkTacticAttribute : IO (KeyedDeclsAttribute Tactic) :=
|
||||
mkElabAttribute Tactic `builtin_tactic `tactic `Lean.Parser.Tactic `Lean.Elab.Tactic.Tactic "tactic" `Lean.Elab.Tactic.tacticElabAttribute
|
||||
|
||||
@[builtinInit mkTacticAttribute] opaque tacticElabAttribute : KeyedDeclsAttribute Tactic
|
||||
@[builtin_init mkTacticAttribute] opaque tacticElabAttribute : KeyedDeclsAttribute Tactic
|
||||
|
||||
def mkTacticInfo (mctxBefore : MetavarContext) (goalsBefore : List MVarId) (stx : Syntax) : TacticM Info :=
|
||||
return Info.ofTacticInfo {
|
||||
|
|
|
|||
|
|
@ -16,15 +16,15 @@ namespace Lean.Elab.Tactic
|
|||
open Meta
|
||||
open Parser.Tactic
|
||||
|
||||
@[builtinTactic withAnnotateState] def evalWithAnnotateState : Tactic
|
||||
@[builtin_tactic withAnnotateState] def evalWithAnnotateState : Tactic
|
||||
| `(tactic| with_annotate_state $stx $t) =>
|
||||
withTacticInfoContext stx (evalTactic t)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.«done»] def evalDone : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.«done»] def evalDone : Tactic := fun _ =>
|
||||
done
|
||||
|
||||
@[builtinTactic seq1] def evalSeq1 : Tactic := fun stx => do
|
||||
@[builtin_tactic seq1] def evalSeq1 : Tactic := fun stx => do
|
||||
let args := stx[0].getArgs
|
||||
for i in [:args.size] do
|
||||
if i % 2 == 0 then
|
||||
|
|
@ -32,7 +32,7 @@ open Parser.Tactic
|
|||
else
|
||||
saveTacticInfoForToken args[i]! -- add `TacticInfo` node for `;`
|
||||
|
||||
@[builtinTactic paren] def evalParen : Tactic := fun stx =>
|
||||
@[builtin_tactic paren] def evalParen : Tactic := fun stx =>
|
||||
evalTactic stx[1]
|
||||
|
||||
def isCheckpointableTactic (arg : Syntax) : TacticM Bool := do
|
||||
|
|
@ -105,17 +105,17 @@ def evalSepByIndentTactic (stx : Syntax) : TacticM Unit := do
|
|||
else
|
||||
saveTacticInfoForToken arg
|
||||
|
||||
@[builtinTactic tacticSeq1Indented] def evalTacticSeq1Indented : Tactic := fun stx =>
|
||||
@[builtin_tactic tacticSeq1Indented] def evalTacticSeq1Indented : Tactic := fun stx =>
|
||||
evalSepByIndentTactic stx[0]
|
||||
|
||||
@[builtinTactic tacticSeqBracketed] def evalTacticSeqBracketed : Tactic := fun stx => do
|
||||
@[builtin_tactic tacticSeqBracketed] def evalTacticSeqBracketed : Tactic := fun stx => do
|
||||
let initInfo ← mkInitialTacticInfo stx[0]
|
||||
withRef stx[2] <| closeUsingOrAdmit do
|
||||
-- save state before/after entering focus on `{`
|
||||
withInfoContext (pure ()) initInfo
|
||||
evalSepByIndentTactic stx[1]
|
||||
|
||||
@[builtinTactic Parser.Tactic.focus] def evalFocus : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.focus] def evalFocus : Tactic := fun stx => do
|
||||
let mkInfo ← mkInitialTacticInfo stx[0]
|
||||
focus do
|
||||
-- show focused state on `focus`
|
||||
|
|
@ -125,15 +125,15 @@ def evalSepByIndentTactic (stx : Syntax) : TacticM Unit := do
|
|||
private def getOptRotation (stx : Syntax) : Nat :=
|
||||
if stx.isNone then 1 else stx[0].toNat
|
||||
|
||||
@[builtinTactic Parser.Tactic.rotateLeft] def evalRotateLeft : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.rotateLeft] def evalRotateLeft : Tactic := fun stx => do
|
||||
let n := getOptRotation stx[1]
|
||||
setGoals <| (← getGoals).rotateLeft n
|
||||
|
||||
@[builtinTactic Parser.Tactic.rotateRight] def evalRotateRight : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.rotateRight] def evalRotateRight : Tactic := fun stx => do
|
||||
let n := getOptRotation stx[1]
|
||||
setGoals <| (← getGoals).rotateRight n
|
||||
|
||||
@[builtinTactic Parser.Tactic.open] def evalOpen : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.open] def evalOpen : Tactic := fun stx => do
|
||||
let `(tactic| open $decl in $tac) := stx | throwUnsupportedSyntax
|
||||
try
|
||||
pushScope
|
||||
|
|
@ -143,12 +143,12 @@ private def getOptRotation (stx : Syntax) : Nat :=
|
|||
finally
|
||||
popScope
|
||||
|
||||
@[builtinTactic Parser.Tactic.set_option] def elabSetOption : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.set_option] def elabSetOption : Tactic := fun stx => do
|
||||
let options ← Elab.elabSetOption stx[1] stx[2]
|
||||
withTheReader Core.Context (fun ctx => { ctx with maxRecDepth := maxRecDepth.get options, options := options }) do
|
||||
evalTactic stx[4]
|
||||
|
||||
@[builtinTactic Parser.Tactic.allGoals] def evalAllGoals : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.allGoals] def evalAllGoals : Tactic := fun stx => do
|
||||
let mvarIds ← getGoals
|
||||
let mut mvarIdsNew := #[]
|
||||
for mvarId in mvarIds do
|
||||
|
|
@ -165,7 +165,7 @@ private def getOptRotation (stx : Syntax) : Nat :=
|
|||
throw ex
|
||||
setGoals mvarIdsNew.toList
|
||||
|
||||
@[builtinTactic Parser.Tactic.anyGoals] def evalAnyGoals : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.anyGoals] def evalAnyGoals : Tactic := fun stx => do
|
||||
let mvarIds ← getGoals
|
||||
let mut mvarIdsNew := #[]
|
||||
let mut succeeded := false
|
||||
|
|
@ -182,7 +182,7 @@ private def getOptRotation (stx : Syntax) : Nat :=
|
|||
throwError "failed on all goals"
|
||||
setGoals mvarIdsNew.toList
|
||||
|
||||
@[builtinTactic tacticSeq] def evalTacticSeq : Tactic := fun stx =>
|
||||
@[builtin_tactic tacticSeq] def evalTacticSeq : Tactic := fun stx =>
|
||||
evalTactic stx[0]
|
||||
|
||||
partial def evalChoiceAux (tactics : Array Syntax) (i : Nat) : TacticM Unit :=
|
||||
|
|
@ -194,39 +194,39 @@ partial def evalChoiceAux (tactics : Array Syntax) (i : Nat) : TacticM Unit :=
|
|||
else
|
||||
throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic choice] def evalChoice : Tactic := fun stx =>
|
||||
@[builtin_tactic choice] def evalChoice : Tactic := fun stx =>
|
||||
evalChoiceAux stx.getArgs 0
|
||||
|
||||
@[builtinTactic skip] def evalSkip : Tactic := fun _ => pure ()
|
||||
@[builtin_tactic skip] def evalSkip : Tactic := fun _ => pure ()
|
||||
|
||||
@[builtinTactic unknown] def evalUnknown : Tactic := fun stx => do
|
||||
@[builtin_tactic unknown] def evalUnknown : Tactic := fun stx => do
|
||||
addCompletionInfo <| CompletionInfo.tactic stx (← getGoals)
|
||||
|
||||
@[builtinTactic failIfSuccess] def evalFailIfSuccess : Tactic := fun stx =>
|
||||
@[builtin_tactic failIfSuccess] def evalFailIfSuccess : Tactic := fun stx =>
|
||||
Term.withoutErrToSorry <| withoutRecover do
|
||||
let tactic := stx[1]
|
||||
if (← try evalTactic tactic; pure true catch _ => pure false) then
|
||||
throwError "tactic succeeded"
|
||||
|
||||
@[builtinTactic traceState] def evalTraceState : Tactic := fun _ => do
|
||||
@[builtin_tactic traceState] def evalTraceState : Tactic := fun _ => do
|
||||
let gs ← getUnsolvedGoals
|
||||
addRawTrace (goalsToMessageData gs)
|
||||
|
||||
@[builtinTactic traceMessage] def evalTraceMessage : Tactic := fun stx => do
|
||||
@[builtin_tactic traceMessage] def evalTraceMessage : Tactic := fun stx => do
|
||||
match stx[1].isStrLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
| some msg => withRef stx[0] <| addRawTrace msg
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.assumption] def evalAssumption : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.assumption] def evalAssumption : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => do mvarId.assumption; pure []
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.contradiction] def evalContradiction : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.contradiction] def evalContradiction : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => do mvarId.contradiction; pure []
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.refl] def evalRefl : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.refl] def evalRefl : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => do mvarId.refl; pure []
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.intro] def evalIntro : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.intro] def evalIntro : Tactic := fun stx => do
|
||||
match stx with
|
||||
| `(tactic| intro) => introStep none `_
|
||||
| `(tactic| intro $h:ident) => introStep h h.getId
|
||||
|
|
@ -243,12 +243,12 @@ where
|
|||
withMainContext do
|
||||
Term.addLocalVarInfo stx (mkFVar fvar)
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.introMatch] def evalIntroMatch : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.introMatch] def evalIntroMatch : Tactic := fun stx => do
|
||||
let matchAlts := stx[1]
|
||||
let stxNew ← liftMacroM <| Term.expandMatchAltsIntoMatchTactic stx matchAlts
|
||||
withMacroExpansion stx stxNew <| evalTactic stxNew
|
||||
|
||||
@[builtinTactic «intros»] def evalIntros : Tactic := fun stx =>
|
||||
@[builtin_tactic «intros»] def evalIntros : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| intros) => liftMetaTactic fun mvarId => do
|
||||
let (_, mvarId) ← mvarId.intros
|
||||
|
|
@ -262,14 +262,14 @@ where
|
|||
Term.addLocalVarInfo stx (mkFVar fvar)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.revert] def evalRevert : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.revert] def evalRevert : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| revert $hs*) => do
|
||||
let (_, mvarId) ← (← getMainGoal).revert (← getFVarIds hs)
|
||||
replaceMainGoal [mvarId]
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.clear] def evalClear : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.clear] def evalClear : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| clear $hs*) => do
|
||||
let fvarIds ← getFVarIds hs
|
||||
|
|
@ -287,12 +287,12 @@ def forEachVar (hs : Array Syntax) (tac : MVarId → FVarId → MetaM MVarId) :
|
|||
let mvarId ← tac (← getMainGoal) fvarId
|
||||
replaceMainGoal [mvarId]
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.subst] def evalSubst : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.subst] def evalSubst : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| subst $hs*) => forEachVar hs Meta.subst
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.substVars] def evalSubstVars : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.substVars] def evalSubstVars : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => return [← substVars mvarId]
|
||||
|
||||
/--
|
||||
|
|
@ -350,7 +350,7 @@ private def getCaseGoals (tag : TSyntax ``binderIdent) : TacticM (MVarId × List
|
|||
getMainGoal
|
||||
return (g, gs.erase g)
|
||||
|
||||
@[builtinTactic «case»] def evalCase : Tactic
|
||||
@[builtin_tactic «case»] def evalCase : Tactic
|
||||
| stx@`(tactic| case $[$tag $hs*]|* =>%$arr $tac:tacticSeq) =>
|
||||
for tag in tag, hs in hs do
|
||||
let (g, gs) ← getCaseGoals tag
|
||||
|
|
@ -362,7 +362,7 @@ private def getCaseGoals (tag : TSyntax ``binderIdent) : TacticM (MVarId × List
|
|||
setGoals gs
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «case'»] def evalCase' : Tactic
|
||||
@[builtin_tactic «case'»] def evalCase' : Tactic
|
||||
| `(tactic| case' $[$tag $hs*]|* =>%$arr $tac:tacticSeq) => do
|
||||
let mut acc := #[]
|
||||
for tag in tag, hs in hs do
|
||||
|
|
@ -379,11 +379,11 @@ private def getCaseGoals (tag : TSyntax ``binderIdent) : TacticM (MVarId × List
|
|||
setGoals (acc.toList ++ (← getGoals))
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «renameI»] def evalRenameInaccessibles : Tactic
|
||||
@[builtin_tactic «renameI»] def evalRenameInaccessibles : Tactic
|
||||
| `(tactic| rename_i $hs*) => do replaceMainGoal [← renameInaccessibles (← getMainGoal) hs]
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «first»] partial def evalFirst : Tactic := fun stx => do
|
||||
@[builtin_tactic «first»] partial def evalFirst : Tactic := fun stx => do
|
||||
let tacs := stx[1].getArgs
|
||||
if tacs.isEmpty then throwUnsupportedSyntax
|
||||
loop tacs 0
|
||||
|
|
@ -394,7 +394,7 @@ where
|
|||
else
|
||||
evalTactic tacs[i]![1] <|> loop tacs (i+1)
|
||||
|
||||
@[builtinTactic «fail»] def evalFail : Tactic := fun stx => do
|
||||
@[builtin_tactic «fail»] def evalFail : Tactic := fun stx => do
|
||||
let goals ← getGoals
|
||||
let goalsMsg := MessageData.joinSep (goals.map MessageData.ofGoal) m!"\n\n"
|
||||
match stx with
|
||||
|
|
@ -402,12 +402,12 @@ where
|
|||
| `(tactic| fail $msg:str) => throwError "{msg.getString}\n{goalsMsg}"
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Parser.Tactic.dbgTrace] def evalDbgTrace : Tactic := fun stx => do
|
||||
@[builtin_tactic Parser.Tactic.dbgTrace] def evalDbgTrace : Tactic := fun stx => do
|
||||
match stx[1].isStrLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
| some msg => dbg_trace msg
|
||||
|
||||
@[builtinTactic sleep] def evalSleep : Tactic := fun stx => do
|
||||
@[builtin_tactic sleep] def evalSleep : Tactic := fun stx => do
|
||||
match stx[1].isNatLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
| some ms => IO.sleep ms.toUInt32
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ private def findCache? (cacheRef : IO.Ref Cache) (mvarId : MVarId) (stx : Syntax
|
|||
dbg_cache "cached state is not compatible"
|
||||
return none
|
||||
|
||||
@[builtinTactic checkpoint] def evalCheckpoint : Tactic := fun stx =>
|
||||
@[builtin_tactic checkpoint] def evalCheckpoint : Tactic := fun stx =>
|
||||
focus do
|
||||
let mvarId ← getMainGoal
|
||||
let some cacheRef := (← readThe Term.Context).tacticCache? | evalTactic stx[1]
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ where
|
|||
instantiateMVars e
|
||||
|
||||
/-- Elaborator for the `calc` tactic mode variant. -/
|
||||
@[builtinTactic calcTactic]
|
||||
@[builtin_tactic calcTactic]
|
||||
def evalCalc : Tactic := fun stx => do
|
||||
withMainContext do
|
||||
let steps := #[stx[1]] ++ stx[2].getArgs
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ open Meta
|
|||
macro (name := configElab) doc?:(docComment)? "declare_config_elab" elabName:ident type:ident : command =>
|
||||
`(unsafe def evalUnsafe (e : Expr) : TermElabM $type :=
|
||||
Meta.evalExpr' (safety := .unsafe) $type ``$type e
|
||||
@[implementedBy evalUnsafe] opaque eval (e : Expr) : TermElabM $type
|
||||
@[implemented_by evalUnsafe] opaque eval (e : Expr) : TermElabM $type
|
||||
$[$doc?:docComment]?
|
||||
def $elabName (optConfig : Syntax) : TermElabM $type := do
|
||||
if optConfig.isNone then
|
||||
|
|
@ -27,7 +27,7 @@ macro (name := configElab) doc?:(docComment)? "declare_config_elab" elabName:ide
|
|||
)
|
||||
|
||||
open Linter.MissingDocs in
|
||||
@[builtinMissingDocsHandler Elab.Tactic.configElab]
|
||||
@[builtin_missing_docs_handler Elab.Tactic.configElab]
|
||||
def checkConfigElab : SimpleHandler := mkSimpleHandler "config elab"
|
||||
|
||||
end Lean.Elab.Tactic
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import Lean.Elab.Tactic.Basic
|
|||
namespace Lean.Elab.Tactic
|
||||
|
||||
namespace Lean.Elab.Tactic
|
||||
@[builtinTactic Parser.Tactic.congr] def evalCongr : Tactic := fun stx =>
|
||||
@[builtin_tactic Parser.Tactic.congr] def evalCongr : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| congr $[$n?]?) =>
|
||||
let hugeDepth := 1000000
|
||||
|
|
|
|||
|
|
@ -85,15 +85,15 @@ def changeLhs (lhs' : Expr) : TacticM Unit := do
|
|||
liftMetaTactic1 fun mvarId => do
|
||||
mvarId.replaceTargetDefEq (mkLHSGoalRaw (← mkEq lhs' rhs))
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.whnf] def evalWhnf : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.whnf] def evalWhnf : Tactic := fun _ =>
|
||||
withMainContext do
|
||||
changeLhs (← whnf (← getLhs))
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.reduce] def evalReduce : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.reduce] def evalReduce : Tactic := fun _ =>
|
||||
withMainContext do
|
||||
changeLhs (← reduce (← getLhs))
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.zeta] def evalZeta : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.zeta] def evalZeta : Tactic := fun _ =>
|
||||
withMainContext do
|
||||
changeLhs (← zetaReduce (← getLhs))
|
||||
|
||||
|
|
@ -105,10 +105,10 @@ def evalSepByIndentConv (stx : Syntax) : TacticM Unit := do
|
|||
else
|
||||
saveTacticInfoForToken arg
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.convSeq1Indented] def evalConvSeq1Indented : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.convSeq1Indented] def evalConvSeq1Indented : Tactic := fun stx => do
|
||||
evalSepByIndentConv stx[0]
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.convSeqBracketed] def evalConvSeqBracketed : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.convSeqBracketed] def evalConvSeqBracketed : Tactic := fun stx => do
|
||||
let initInfo ← mkInitialTacticInfo stx[0]
|
||||
withRef stx[2] <| closeUsingOrAdmit do
|
||||
-- save state before/after entering focus on `{`
|
||||
|
|
@ -116,18 +116,18 @@ def evalSepByIndentConv (stx : Syntax) : TacticM Unit := do
|
|||
evalSepByIndentConv stx[1]
|
||||
evalTactic (← `(tactic| all_goals (try rfl)))
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.nestedConv] def evalNestedConv : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.nestedConv] def evalNestedConv : Tactic := fun stx => do
|
||||
evalConvSeqBracketed stx[0]
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.convSeq] def evalConvSeq : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.convSeq] def evalConvSeq : Tactic := fun stx => do
|
||||
evalTactic stx[0]
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.convConvSeq] def evalConvConvSeq : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.convConvSeq] def evalConvConvSeq : Tactic := fun stx =>
|
||||
withMainContext do
|
||||
let (lhsNew, proof) ← convert (← getLhs) (evalTactic stx[2][0])
|
||||
updateLhs lhsNew proof
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.paren] def evalParen : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.paren] def evalParen : Tactic := fun stx =>
|
||||
evalTactic stx[1]
|
||||
|
||||
/-- Mark goals of the form `⊢ a = ?m ..` with the conv goal annotation -/
|
||||
|
|
@ -143,11 +143,11 @@ def remarkAsConvGoal : TacticM Unit := do
|
|||
return mvarId
|
||||
setGoals newGoals
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.nestedTacticCore] def evalNestedTacticCore : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.nestedTacticCore] def evalNestedTacticCore : Tactic := fun stx => do
|
||||
let seq := stx[2]
|
||||
evalTactic seq; remarkAsConvGoal
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.nestedTactic] def evalNestedTactic : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.nestedTactic] def evalNestedTactic : Tactic := fun stx => do
|
||||
let seq := stx[2]
|
||||
let target ← getMainTarget
|
||||
if let some _ := isLHSGoal? target then
|
||||
|
|
@ -155,7 +155,7 @@ def remarkAsConvGoal : TacticM Unit := do
|
|||
mvarId.replaceTargetDefEq target.mdataExpr!
|
||||
focus do evalTactic seq; remarkAsConvGoal
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.convTactic] def evalConvTactic : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.convTactic] def evalConvTactic : Tactic := fun stx =>
|
||||
evalTactic stx[2]
|
||||
|
||||
private def convTarget (conv : Syntax) : TacticM Unit := withMainContext do
|
||||
|
|
@ -170,7 +170,7 @@ private def convLocalDecl (conv : Syntax) (hUserName : Name) : TacticM Unit := w
|
|||
liftMetaTactic1 fun mvarId =>
|
||||
return some (← mvarId.replaceLocalDecl localDecl.fvarId typeNew proof).mvarId
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.conv] def evalConv : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.conv] def evalConv : Tactic := fun stx => do
|
||||
match stx with
|
||||
| `(tactic| conv%$tk $[at $loc?]? in $(occs)? $p =>%$arr $code) =>
|
||||
evalTactic (← `(tactic| conv%$tk $[at $loc?]? =>%$arr pattern $(occs)? $p; ($code:convSeq)))
|
||||
|
|
@ -183,7 +183,7 @@ private def convLocalDecl (conv : Syntax) (hUserName : Name) : TacticM Unit := w
|
|||
convTarget code
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.first] partial def evalFirst : Tactic :=
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.first] partial def evalFirst : Tactic :=
|
||||
Tactic.evalFirst
|
||||
|
||||
end Lean.Elab.Tactic.Conv
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import Lean.Elab.Tactic.Conv.Basic
|
|||
namespace Lean.Elab.Tactic.Conv
|
||||
open Meta
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.change] def evalChange : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.change] def evalChange : Tactic := fun stx => do
|
||||
match stx with
|
||||
| `(conv| change $e) => withMainContext do
|
||||
let lhs ← getLhs
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ def congr (mvarId : MVarId) (addImplicitArgs := false) (nameSubgoals := true) :
|
|||
else
|
||||
throwError "invalid 'congr' conv tactic, application or implication expected{indentExpr lhs}"
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.congr] def evalCongr : Tactic := fun _ => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.congr] def evalCongr : Tactic := fun _ => do
|
||||
replaceMainGoal <| List.filterMap id (← congr (← getMainGoal))
|
||||
|
||||
private def selectIdx (tacticName : String) (mvarIds : List (Option MVarId)) (i : Int) :
|
||||
|
|
@ -91,17 +91,17 @@ private def selectIdx (tacticName : String) (mvarIds : List (Option MVarId)) (i
|
|||
return ()
|
||||
throwError "invalid '{tacticName}' conv tactic, application has only {mvarIds.length} (nondependent) argument(s)"
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.skip] def evalSkip : Tactic := fun _ => pure ()
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.skip] def evalSkip : Tactic := fun _ => pure ()
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.lhs] def evalLhs : Tactic := fun _ => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.lhs] def evalLhs : Tactic := fun _ => do
|
||||
let mvarIds ← congr (← getMainGoal) (nameSubgoals := false)
|
||||
selectIdx "lhs" mvarIds ((mvarIds.length : Int) - 2)
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.rhs] def evalRhs : Tactic := fun _ => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.rhs] def evalRhs : Tactic := fun _ => do
|
||||
let mvarIds ← congr (← getMainGoal) (nameSubgoals := false)
|
||||
selectIdx "rhs" mvarIds ((mvarIds.length : Int) - 1)
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.arg] def evalArg : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.arg] def evalArg : Tactic := fun stx => do
|
||||
match stx with
|
||||
| `(conv| arg $[@%$tk?]? $i:num) =>
|
||||
let i := i.getNat
|
||||
|
|
@ -174,7 +174,7 @@ private def extCore (mvarId : MVarId) (userName? : Option Name) : MetaM MVarId :
|
|||
private def ext (userName? : Option Name) : TacticM Unit := do
|
||||
replaceMainGoal [← extCore (← getMainGoal) userName?]
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.ext] def evalExt : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.ext] def evalExt : Tactic := fun stx => do
|
||||
let ids := stx[1].getArgs
|
||||
if ids.isEmpty then
|
||||
ext none
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import Lean.Elab.Tactic.Conv.Basic
|
|||
namespace Lean.Elab.Tactic.Conv
|
||||
open Meta
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.delta] def evalDelta : Tactic := fun stx => withMainContext do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.delta] def evalDelta : Tactic := fun stx => withMainContext do
|
||||
let declNames ← stx[1].getArgs.mapM resolveGlobalConstNoOverloadWithInfo
|
||||
let lhsNew ← deltaExpand (← instantiateMVars (← getLhs)) declNames.contains
|
||||
changeLhs lhsNew
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ private def pre (pattern : AbstractMVarsResult) (state : IO.Ref PatternMatchStat
|
|||
else
|
||||
return Simp.Step.visit { expr := e }
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.pattern] def evalPattern : Tactic := fun stx => withMainContext do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.pattern] def evalPattern : Tactic := fun stx => withMainContext do
|
||||
match stx with
|
||||
| `(conv| pattern $[(occs := $occs)]? $p) =>
|
||||
let patternA ←
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Lean.Elab.Tactic.Conv.Basic
|
|||
namespace Lean.Elab.Tactic.Conv
|
||||
open Meta
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.rewrite] def evalRewrite : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.rewrite] def evalRewrite : Tactic := fun stx => do
|
||||
let config ← Tactic.elabRewriteConfig stx[1]
|
||||
withRWRulesSeq stx[0] stx[2] fun symm term => do
|
||||
Term.withSynthesize <| withMainContext do
|
||||
|
|
|
|||
|
|
@ -16,16 +16,16 @@ def applySimpResult (result : Simp.Result) : TacticM Unit := do
|
|||
else
|
||||
updateLhs result.expr (← result.getProof)
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.simp] def evalSimp : Tactic := fun stx => withMainContext do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.simp] def evalSimp : Tactic := fun stx => withMainContext do
|
||||
let { ctx, dischargeWrapper, .. } ← mkSimpContext stx (eraseLocal := false)
|
||||
let lhs ← getLhs
|
||||
let (result, _) ← dischargeWrapper.with fun d? => simp lhs ctx (discharge? := d?)
|
||||
applySimpResult result
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.simpMatch] def evalSimpMatch : Tactic := fun _ => withMainContext do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.simpMatch] def evalSimpMatch : Tactic := fun _ => withMainContext do
|
||||
applySimpResult (← Split.simpMatch (← getLhs))
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.dsimp] def evalDSimp : Tactic := fun stx => withMainContext do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.dsimp] def evalDSimp : Tactic := fun stx => withMainContext do
|
||||
let { ctx, .. } ← mkSimpContext stx (eraseLocal := false) (kind := .dsimp)
|
||||
changeLhs (← Lean.Meta.dsimp (← getLhs) ctx).1
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import Lean.Elab.Tactic.Conv.Simp
|
|||
namespace Lean.Elab.Tactic.Conv
|
||||
open Meta
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.unfold] def evalUnfold : Tactic := fun stx => withMainContext do
|
||||
@[builtin_tactic Lean.Parser.Tactic.Conv.unfold] def evalUnfold : Tactic := fun stx => withMainContext do
|
||||
for declNameId in stx[1].getArgs do
|
||||
let declName ← resolveGlobalConstNoOverloadWithInfo declNameId
|
||||
applySimpResult (← unfold (← getLhs) declName)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ def deltaTarget (declNames : Array Name) : TacticM Unit := do
|
|||
replaceMainGoal [← mvarId.replaceTargetDefEq targetNew]
|
||||
|
||||
/-- "delta " ident+ (location)? -/
|
||||
@[builtinTactic Lean.Parser.Tactic.delta] def evalDelta : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.delta] def evalDelta : Tactic := fun stx => do
|
||||
let declNames ← stx[1].getArgs.mapM resolveGlobalConstNoOverloadWithInfo
|
||||
let loc := expandOptLocation stx[2]
|
||||
withLocation loc (deltaLocalDecl declNames) (deltaTarget declNames)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def filterOldMVars (mvarIds : Array MVarId) (mvarCounterSaved : Nat) : MetaM (Ar
|
|||
let mctx ← getMCtx
|
||||
return mvarIds.filter fun mvarId => (mctx.getDecl mvarId |>.index) >= mvarCounterSaved
|
||||
|
||||
@[builtinTactic «exact»] def evalExact : Tactic := fun stx =>
|
||||
@[builtin_tactic «exact»] def evalExact : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| exact $e) => closeMainGoalUsing (checkUnassigned := false) fun type => do
|
||||
let mvarCounterSaved := (← getMCtx).mvarCounter
|
||||
|
|
@ -154,17 +154,17 @@ def refineCore (stx : Syntax) (tagSuffix : Name) (allowNaturalHoles : Bool) : Ta
|
|||
mvarId.assign val
|
||||
replaceMainGoal mvarIds'
|
||||
|
||||
@[builtinTactic «refine»] def evalRefine : Tactic := fun stx =>
|
||||
@[builtin_tactic «refine»] def evalRefine : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| refine $e) => refineCore e `refine (allowNaturalHoles := false)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «refine'»] def evalRefine' : Tactic := fun stx =>
|
||||
@[builtin_tactic «refine'»] def evalRefine' : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| refine' $e) => refineCore e `refine' (allowNaturalHoles := true)
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «specialize»] def evalSpecialize : Tactic := fun stx => withMainContext do
|
||||
@[builtin_tactic «specialize»] def evalSpecialize : Tactic := fun stx => withMainContext do
|
||||
match stx with
|
||||
| `(tactic| specialize $e:term) =>
|
||||
let (e, mvarIds') ← elabTermWithHoles e none `specialize (allowNaturalHoles := true)
|
||||
|
|
@ -255,24 +255,24 @@ def getFVarId (id : Syntax) : TacticM FVarId := withRef id do
|
|||
def getFVarIds (ids : Array Syntax) : TacticM (Array FVarId) := do
|
||||
withMainContext do ids.mapM getFVarId
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.apply] def evalApply : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.apply] def evalApply : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| apply $e) => evalApplyLikeTactic (·.apply) e
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.constructor] def evalConstructor : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.constructor] def evalConstructor : Tactic := fun _ =>
|
||||
withMainContext do
|
||||
let mvarIds' ← (← getMainGoal).constructor
|
||||
Term.synthesizeSyntheticMVarsNoPostponing
|
||||
replaceMainGoal mvarIds'
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.withReducible] def evalWithReducible : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.withReducible] def evalWithReducible : Tactic := fun stx =>
|
||||
withReducible <| evalTactic stx[1]
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.withReducibleAndInstances] def evalWithReducibleAndInstances : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.withReducibleAndInstances] def evalWithReducibleAndInstances : Tactic := fun stx =>
|
||||
withReducibleAndInstances <| evalTactic stx[1]
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.withUnfoldingAll] def evalWithUnfoldingAll : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.withUnfoldingAll] def evalWithUnfoldingAll : Tactic := fun stx =>
|
||||
withTransparency TransparencyMode.all <| evalTactic stx[1]
|
||||
|
||||
/--
|
||||
|
|
@ -296,7 +296,7 @@ def elabAsFVar (stx : Syntax) (userName? : Option Name := none) : TacticM FVarId
|
|||
| none => intro `h false
|
||||
| some userName => intro userName true
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.rename] def evalRename : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.rename] def evalRename : Tactic := fun stx =>
|
||||
match stx with
|
||||
| `(tactic| rename $typeStx:term => $h:ident) => do
|
||||
withMainContext do
|
||||
|
|
@ -325,7 +325,7 @@ private def preprocessPropToDecide (expectedType : Expr) : TermElabM Expr := do
|
|||
throwError "expected type must not contain free or meta variables{indentExpr expectedType}"
|
||||
return expectedType
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.decide] def evalDecide : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.decide] def evalDecide : Tactic := fun _ =>
|
||||
closeMainGoalUsing fun expectedType => do
|
||||
let expectedType ← preprocessPropToDecide expectedType
|
||||
let d ← mkDecide expectedType
|
||||
|
|
@ -348,7 +348,7 @@ private def mkNativeAuxDecl (baseName : Name) (type value : Expr) : TermElabM Na
|
|||
compileDecl decl
|
||||
pure auxName
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.nativeDecide] def evalNativeDecide : Tactic := fun _ =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.nativeDecide] def evalNativeDecide : Tactic := fun _ =>
|
||||
closeMainGoalUsing fun expectedType => do
|
||||
let expectedType ← preprocessPropToDecide expectedType
|
||||
let d ← mkDecide expectedType
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import Lean.Elab.Tactic.Location
|
|||
namespace Lean.Elab.Tactic
|
||||
open Meta
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.generalize] def evalGeneralize : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.generalize] def evalGeneralize : Tactic := fun stx =>
|
||||
withMainContext do
|
||||
let args ← stx[1].getSepArgs.mapM fun arg => do
|
||||
let hName? := if arg[0].isNone then none else some arg[0][0].getId
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ private def generalizeTargets (exprs : Array Expr) : TacticM (Array Expr) := do
|
|||
else
|
||||
return exprs
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.induction] def evalInduction : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.induction] def evalInduction : Tactic := fun stx =>
|
||||
match expandInduction? stx with
|
||||
| some stxNew => withMacroExpansion stx stxNew <| evalTactic stxNew
|
||||
| _ => focus do
|
||||
|
|
@ -587,7 +587,7 @@ def elabCasesTargets (targets : Array Syntax) : TacticM (Array Expr) :=
|
|||
else
|
||||
return args.map (·.expr)
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.cases] def evalCases : Tactic := fun stx =>
|
||||
@[builtin_tactic Lean.Parser.Tactic.cases] def evalCases : Tactic := fun stx =>
|
||||
match expandCases? stx with
|
||||
| some stxNew => withMacroExpansion stx stxNew <| evalTactic stxNew
|
||||
| _ => focus do
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ private def checkUnusedIds (tacticName : Name) (mvarId : MVarId) (unusedIds : Li
|
|||
unless unusedIds.isEmpty do
|
||||
Meta.throwTacticEx tacticName mvarId m!"too many identifiers provided, unused: {unusedIds}"
|
||||
|
||||
@[builtinTactic «injection»] def evalInjection : Tactic := fun stx => do
|
||||
@[builtin_tactic «injection»] def evalInjection : Tactic := fun stx => do
|
||||
-- leading_parser nonReservedSymbol "injection " >> termParser >> withIds
|
||||
let fvarId ← elabAsFVar stx[1]
|
||||
let ids := getInjectionNewIds stx[2]
|
||||
|
|
@ -27,7 +27,7 @@ private def checkUnusedIds (tacticName : Name) (mvarId : MVarId) (unusedIds : Li
|
|||
| .solved => checkUnusedIds `injection mvarId ids; return []
|
||||
| .subgoal mvarId' _ unusedIds => checkUnusedIds `injection mvarId unusedIds; return [mvarId']
|
||||
|
||||
@[builtinTactic «injections»] def evalInjections : Tactic := fun stx => do
|
||||
@[builtin_tactic «injections»] def evalInjections : Tactic := fun stx => do
|
||||
let ids := stx[1].getArgs.toList.map getNameOfIdent'
|
||||
liftMetaTactic fun mvarId => do
|
||||
match (← Meta.injections mvarId ids) with
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ private def mkAuxiliaryMatchTerm (parentTag : Name) (matchTac : Syntax) : MacroM
|
|||
let result := result.setArg 5 (mkNode ``Parser.Term.matchAlts #[mkNullNode newAlts])
|
||||
return (result, newCases)
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.match]
|
||||
@[builtin_tactic Lean.Parser.Tactic.match]
|
||||
def evalMatch : Tactic := fun stx => do
|
||||
let tag ← getMainTag
|
||||
let (matchTerm, casesStx) ← liftMacroM <| mkAuxiliaryMatchTerm tag stx
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def withRWRulesSeq (token : Syntax) (rwRulesSeqStx : Syntax) (x : (symm : Bool)
|
|||
|
||||
declare_config_elab elabRewriteConfig Rewrite.Config
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.rewriteSeq] def evalRewriteSeq : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.rewriteSeq] def evalRewriteSeq : Tactic := fun stx => do
|
||||
let cfg ← elabRewriteConfig stx[1]
|
||||
let loc := expandOptLocation stx[3]
|
||||
withRWRulesSeq stx[0] stx[2] fun symm term => do
|
||||
|
|
|
|||
|
|
@ -319,14 +319,14 @@ where
|
|||
/-
|
||||
"simp " (config)? (discharger)? ("only ")? ("[" simpLemma,* "]")? (location)?
|
||||
-/
|
||||
@[builtinTactic Lean.Parser.Tactic.simp] def evalSimp : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.simp] def evalSimp : Tactic := fun stx => do
|
||||
let { ctx, dischargeWrapper } ← withMainContext <| mkSimpContext stx (eraseLocal := false)
|
||||
let usedSimps ← dischargeWrapper.with fun discharge? =>
|
||||
simpLocation ctx discharge? (expandOptLocation stx[5])
|
||||
if tactic.simp.trace.get (← getOptions) then
|
||||
traceSimpCall stx usedSimps
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.simpAll] def evalSimpAll : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.simpAll] def evalSimpAll : Tactic := fun stx => do
|
||||
let { ctx, .. } ← mkSimpContext stx (eraseLocal := true) (kind := .simpAll) (ignoreStarArg := true)
|
||||
let (result?, usedSimps) ← simpAll (← getMainGoal) ctx
|
||||
match result? with
|
||||
|
|
@ -354,7 +354,7 @@ where
|
|||
if tactic.simp.trace.get (← getOptions) then
|
||||
traceSimpCall (← getRef) usedSimps
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.dsimp] def evalDSimp : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.dsimp] def evalDSimp : Tactic := fun stx => do
|
||||
let { ctx, .. } ← withMainContext <| mkSimpContext stx (eraseLocal := false) (kind := .dsimp)
|
||||
dsimpLocation ctx (expandOptLocation stx[5])
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Lean.Elab.Tactic.Location
|
|||
namespace Lean.Elab.Tactic
|
||||
open Meta
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.split] def evalSplit : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.split] def evalSplit : Tactic := fun stx => do
|
||||
unless stx[1].isNone do
|
||||
throwError "'split' tactic, term to split is not supported yet"
|
||||
let loc := expandOptLocation stx[2]
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ def unfoldTarget (declName : Name) : TacticM Unit := do
|
|||
replaceMainGoal [← Meta.unfoldTarget (← getMainGoal) declName]
|
||||
|
||||
/-- "unfold " ident+ (location)? -/
|
||||
@[builtinTactic Lean.Parser.Tactic.unfold] def evalUnfold : Tactic := fun stx => do
|
||||
@[builtin_tactic Lean.Parser.Tactic.unfold] def evalUnfold : Tactic := fun stx => do
|
||||
let loc := expandOptLocation stx[2]
|
||||
for declNameId in stx[1].getArgs do
|
||||
go declNameId loc
|
||||
|
|
|
|||
|
|
@ -230,9 +230,9 @@ whole monad stack at every use site. May eventually be covered by `deriving`.
|
|||
TODO: this trick does not work in the old/new code generators anymore.
|
||||
TODO: figure out a way to instruct the compiler to optimize this code once,
|
||||
and then lambda lift all methods once. Perhaps, we should do it whenever the
|
||||
instance is marked as alwaysInline.
|
||||
instance is marked as always_inline.
|
||||
-/
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance : Monad TermElabM :=
|
||||
let i := inferInstanceAs (Monad TermElabM)
|
||||
{ pure := i.pure, bind := i.bind }
|
||||
|
|
@ -371,7 +371,7 @@ def withoutSavingRecAppSyntax (x : TermElabM α) : TermElabM α :=
|
|||
unsafe def mkTermElabAttributeUnsafe (ref : Name) : IO (KeyedDeclsAttribute TermElab) :=
|
||||
mkElabAttribute TermElab `builtin_term_elab `term_elab `Lean.Parser.Term `Lean.Elab.Term.TermElab "term" ref
|
||||
|
||||
@[implementedBy mkTermElabAttributeUnsafe]
|
||||
@[implemented_by mkTermElabAttributeUnsafe]
|
||||
opaque mkTermElabAttribute (ref : Name) : IO (KeyedDeclsAttribute TermElab)
|
||||
|
||||
builtin_initialize termElabAttribute : KeyedDeclsAttribute TermElab ← mkTermElabAttribute decl_name%
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ def syntaxNodeKindOfAttrParam (defaultParserNamespace : Name) (stx : Syntax) : A
|
|||
private unsafe def evalSyntaxConstantUnsafe (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax :=
|
||||
env.evalConstCheck Syntax opts `Lean.Syntax constName
|
||||
|
||||
@[implementedBy evalSyntaxConstantUnsafe]
|
||||
@[implemented_by evalSyntaxConstantUnsafe]
|
||||
opaque evalSyntaxConstant (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax := throw ""
|
||||
|
||||
unsafe def mkElabAttribute (γ) (attrBuiltinName attrName : Name) (parserNamespace : Name) (typeName : Name) (kind : String)
|
||||
|
|
@ -121,7 +121,7 @@ unsafe def mkElabAttribute (γ) (attrBuiltinName attrName : Name) (parserNamespa
|
|||
unsafe def mkMacroAttributeUnsafe (ref : Name) : IO (KeyedDeclsAttribute Macro) :=
|
||||
mkElabAttribute Macro `builtin_macro `macro Name.anonymous `Lean.Macro "macro" ref
|
||||
|
||||
@[implementedBy mkMacroAttributeUnsafe]
|
||||
@[implemented_by mkMacroAttributeUnsafe]
|
||||
opaque mkMacroAttribute (ref : Name) : IO (KeyedDeclsAttribute Macro)
|
||||
|
||||
builtin_initialize macroAttribute : KeyedDeclsAttribute Macro ← mkMacroAttribute decl_name%
|
||||
|
|
@ -145,7 +145,7 @@ class MonadMacroAdapter (m : Type → Type) where
|
|||
getNextMacroScope : m MacroScope
|
||||
setNextMacroScope : MacroScope → m Unit
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (m n) [MonadLift m n] [MonadMacroAdapter m] : MonadMacroAdapter n := {
|
||||
getCurrMacroScope := liftM (MonadMacroAdapter.getCurrMacroScope : m _)
|
||||
getNextMacroScope := liftM (MonadMacroAdapter.getNextMacroScope : m _)
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ unsafe def imp : EnvExtensionInterface := {
|
|||
|
||||
end EnvExtensionInterfaceUnsafe
|
||||
|
||||
@[implementedBy EnvExtensionInterfaceUnsafe.imp]
|
||||
@[implemented_by EnvExtensionInterfaceUnsafe.imp]
|
||||
opaque EnvExtensionInterfaceImp : EnvExtensionInterface
|
||||
|
||||
def EnvExtension (σ : Type) : Type := EnvExtensionInterfaceImp.ext σ
|
||||
|
|
@ -468,7 +468,7 @@ unsafe def registerPersistentEnvExtensionUnsafe {α β σ : Type} [Inhabited σ]
|
|||
persistentEnvExtensionsRef.modify fun pExts => pExts.push (unsafeCast pExt)
|
||||
return pExt
|
||||
|
||||
@[implementedBy registerPersistentEnvExtensionUnsafe]
|
||||
@[implemented_by registerPersistentEnvExtensionUnsafe]
|
||||
opaque registerPersistentEnvExtension {α β σ : Type} [Inhabited σ] (descr : PersistentEnvExtensionDescr α β σ) : IO (PersistentEnvExtension α β σ)
|
||||
|
||||
/-- Simple `PersistentEnvExtension` that implements `exportEntriesFn` using a list of entries. -/
|
||||
|
|
@ -869,7 +869,7 @@ class MonadEnv (m : Type → Type) where
|
|||
|
||||
export MonadEnv (getEnv modifyEnv)
|
||||
|
||||
@[alwaysInline]
|
||||
@[always_inline]
|
||||
instance (m n) [MonadLift m n] [MonadEnv m] : MonadEnv n where
|
||||
getEnv := liftM (getEnv : m Environment)
|
||||
modifyEnv := fun f => liftM (modifyEnv f : m Unit)
|
||||
|
|
|
|||
|
|
@ -459,7 +459,7 @@ inductive Expr where
|
|||
-/
|
||||
| proj (typeName : Name) (idx : Nat) (struct : Expr)
|
||||
with
|
||||
@[computedField, extern c inline "lean_ctor_get_uint64(#1, lean_ctor_num_objs(#1)*sizeof(void*))"]
|
||||
@[computed_field, extern c inline "lean_ctor_get_uint64(#1, lean_ctor_num_objs(#1)*sizeof(void*))"]
|
||||
data : @& Expr → Data
|
||||
| .const n lvls => mkData (mixHash 5 <| mixHash (hash n) (hash lvls)) 0 0 false false (lvls.any Level.hasMVar) (lvls.any Level.hasParam)
|
||||
| .bvar idx => mkData (mixHash 7 <| hash idx) (idx+1)
|
||||
|
|
@ -1464,7 +1464,7 @@ the compiler will eliminate the double-match.
|
|||
| app fn arg => if ptrEq fn newFn && ptrEq arg newArg then e else mkApp newFn newArg
|
||||
| _ => panic! "application expected"
|
||||
|
||||
@[implementedBy updateApp!Impl]
|
||||
@[implemented_by updateApp!Impl]
|
||||
def updateApp! (e : Expr) (newFn : Expr) (newArg : Expr) : Expr :=
|
||||
match e with
|
||||
| app _ _ => mkApp newFn newArg
|
||||
|
|
@ -1475,7 +1475,7 @@ def updateApp! (e : Expr) (newFn : Expr) (newArg : Expr) : Expr :=
|
|||
| const n ls => if ptrEqList ls newLevels then e else mkConst n newLevels
|
||||
| _ => panic! "constant expected"
|
||||
|
||||
@[implementedBy updateConst!Impl]
|
||||
@[implemented_by updateConst!Impl]
|
||||
def updateConst! (e : Expr) (newLevels : List Level) : Expr :=
|
||||
match e with
|
||||
| const n _ => mkConst n newLevels
|
||||
|
|
@ -1486,7 +1486,7 @@ def updateConst! (e : Expr) (newLevels : List Level) : Expr :=
|
|||
| sort u => if ptrEq u u' then e else mkSort u'
|
||||
| _ => panic! "level expected"
|
||||
|
||||
@[implementedBy updateSort!Impl]
|
||||
@[implemented_by updateSort!Impl]
|
||||
def updateSort! (e : Expr) (newLevel : Level) : Expr :=
|
||||
match e with
|
||||
| sort _ => mkSort newLevel
|
||||
|
|
@ -1497,7 +1497,7 @@ def updateSort! (e : Expr) (newLevel : Level) : Expr :=
|
|||
| mdata d a => if ptrEq a newExpr then e else mkMData d newExpr
|
||||
| _ => panic! "mdata expected"
|
||||
|
||||
@[implementedBy updateMData!Impl]
|
||||
@[implemented_by updateMData!Impl]
|
||||
def updateMData! (e : Expr) (newExpr : Expr) : Expr :=
|
||||
match e with
|
||||
| mdata d _ => mkMData d newExpr
|
||||
|
|
@ -1508,7 +1508,7 @@ def updateMData! (e : Expr) (newExpr : Expr) : Expr :=
|
|||
| proj s i a => if ptrEq a newExpr then e else mkProj s i newExpr
|
||||
| _ => panic! "proj expected"
|
||||
|
||||
@[implementedBy updateProj!Impl]
|
||||
@[implemented_by updateProj!Impl]
|
||||
def updateProj! (e : Expr) (newExpr : Expr) : Expr :=
|
||||
match e with
|
||||
| proj s i _ => mkProj s i newExpr
|
||||
|
|
@ -1523,7 +1523,7 @@ def updateProj! (e : Expr) (newExpr : Expr) : Expr :=
|
|||
mkForall n newBinfo newDomain newBody
|
||||
| _ => panic! "forall expected"
|
||||
|
||||
@[implementedBy updateForall!Impl]
|
||||
@[implemented_by updateForall!Impl]
|
||||
def updateForall! (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody : Expr) : Expr :=
|
||||
match e with
|
||||
| forallE n _ _ _ => mkForall n newBinfo newDomain newBody
|
||||
|
|
@ -1543,7 +1543,7 @@ def updateForall! (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody
|
|||
mkLambda n newBinfo newDomain newBody
|
||||
| _ => panic! "lambda expected"
|
||||
|
||||
@[implementedBy updateLambda!Impl]
|
||||
@[implemented_by updateLambda!Impl]
|
||||
def updateLambda! (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody : Expr) : Expr :=
|
||||
match e with
|
||||
| lam n _ _ _ => mkLambda n newBinfo newDomain newBody
|
||||
|
|
@ -1563,7 +1563,7 @@ def updateLambda! (e : Expr) (newBinfo : BinderInfo) (newDomain : Expr) (newBody
|
|||
letE n newType newVal newBody nonDep
|
||||
| _ => panic! "let expression expected"
|
||||
|
||||
@[implementedBy updateLet!Impl]
|
||||
@[implemented_by updateLet!Impl]
|
||||
def updateLet! (e : Expr) (newType : Expr) (newVal : Expr) (newBody : Expr) : Expr :=
|
||||
match e with
|
||||
| letE n _ _ _ c => letE n newType newVal newBody c
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ inductive Level where
|
|||
| param : Name → Level
|
||||
| mvar : LMVarId → Level
|
||||
with
|
||||
@[computedField] data : Level → Data
|
||||
@[computed_field] data : Level → Data
|
||||
| .zero => mkData 2221 0 false false
|
||||
| .mvar mvarId => mkData (mixHash 2237 <| hash mvarId) 0 true false
|
||||
| .param name => mkData (mixHash 2239 <| hash name) 0 false true
|
||||
|
|
@ -533,7 +533,7 @@ the compiler will eliminate the double-match.
|
|||
| succ l => if ptrEq l newLvl then lvl else mkLevelSucc newLvl
|
||||
| _ => panic! "succ level expected"
|
||||
|
||||
@[implementedBy updateSucc!Impl]
|
||||
@[implemented_by updateSucc!Impl]
|
||||
def updateSucc! (lvl : Level) (newLvl : Level) : Level :=
|
||||
match lvl with
|
||||
| succ _ => mkLevelSucc newLvl
|
||||
|
|
@ -544,7 +544,7 @@ def updateSucc! (lvl : Level) (newLvl : Level) : Level :=
|
|||
| max lhs rhs => if ptrEq lhs newLhs && ptrEq rhs newRhs then simpLevelMax' newLhs newRhs lvl else mkLevelMax' newLhs newRhs
|
||||
| _ => panic! "max level expected"
|
||||
|
||||
@[implementedBy updateMax!Impl]
|
||||
@[implemented_by updateMax!Impl]
|
||||
def updateMax! (lvl : Level) (newLhs : Level) (newRhs : Level) : Level :=
|
||||
match lvl with
|
||||
| max _ _ => mkLevelMax' newLhs newRhs
|
||||
|
|
@ -555,7 +555,7 @@ def updateMax! (lvl : Level) (newLhs : Level) (newRhs : Level) : Level :=
|
|||
| imax lhs rhs => if ptrEq lhs newLhs && ptrEq rhs newRhs then simpLevelIMax' newLhs newRhs lvl else mkLevelIMax' newLhs newRhs
|
||||
| _ => panic! "imax level expected"
|
||||
|
||||
@[implementedBy updateIMax!Impl]
|
||||
@[implemented_by updateIMax!Impl]
|
||||
def updateIMax! (lvl : Level) (newLhs : Level) (newRhs : Level) : Level :=
|
||||
match lvl with
|
||||
| imax _ _ => mkLevelIMax' newLhs newRhs
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ unsafe def mkHandlerUnsafe (constName : Name) : ImportM Handler := do
|
|||
IO.ofExcept $ env.evalConst Handler opts constName
|
||||
| _ => throw ↑s!"unexpected missing docs handler at '{constName}', `MissingDocs.Handler` or `MissingDocs.SimpleHandler` expected"
|
||||
|
||||
@[implementedBy mkHandlerUnsafe]
|
||||
@[implemented_by mkHandlerUnsafe]
|
||||
opaque mkHandler (constName : Name) : ImportM Handler
|
||||
|
||||
builtin_initialize builtinHandlersRef : IO.Ref (NameMap Handler) ← IO.mkRef {}
|
||||
|
|
@ -128,7 +128,7 @@ def lintDeclHead (k : SyntaxNodeKind) (id : Syntax) : CommandElabM Unit := do
|
|||
else if k == ``classInductive then lintNamed id "public inductive"
|
||||
else if k == ``«structure» then lintNamed id "public structure"
|
||||
|
||||
@[builtinMissingDocsHandler declaration]
|
||||
@[builtin_missing_docs_handler declaration]
|
||||
def checkDecl : SimpleHandler := fun stx => do
|
||||
let head := stx[0]; let rest := stx[1]
|
||||
if head[2][0].getKind == ``«private» then return -- not private
|
||||
|
|
@ -169,24 +169,24 @@ def checkDecl : SimpleHandler := fun stx => do
|
|||
for stx in stx[2].getArgs do
|
||||
lint1 stx
|
||||
|
||||
@[builtinMissingDocsHandler «initialize»]
|
||||
@[builtin_missing_docs_handler «initialize»]
|
||||
def checkInit : SimpleHandler := fun stx => do
|
||||
if !stx[2].isNone && declModifiersPubNoDoc stx[0] then
|
||||
lintNamed stx[2][0] "initializer"
|
||||
|
||||
@[builtinMissingDocsHandler «notation»]
|
||||
@[builtin_missing_docs_handler «notation»]
|
||||
def checkNotation : SimpleHandler := fun stx => do
|
||||
if stx[0].isNone && stx[2][0][0].getKind != ``«local» && !hasInheritDoc stx[1] then
|
||||
if stx[5].isNone then lint stx[3] "notation"
|
||||
else lintNamed stx[5][0][3] "notation"
|
||||
|
||||
@[builtinMissingDocsHandler «mixfix»]
|
||||
@[builtin_missing_docs_handler «mixfix»]
|
||||
def checkMixfix : SimpleHandler := fun stx => do
|
||||
if stx[0].isNone && stx[2][0][0].getKind != ``«local» && !hasInheritDoc stx[1] then
|
||||
if stx[5].isNone then lint stx[3] stx[3][0].getAtomVal
|
||||
else lintNamed stx[5][0][3] stx[3][0].getAtomVal
|
||||
|
||||
@[builtinMissingDocsHandler «syntax»]
|
||||
@[builtin_missing_docs_handler «syntax»]
|
||||
def checkSyntax : SimpleHandler := fun stx => do
|
||||
if stx[0].isNone && stx[2][0][0].getKind != ``«local» && !hasInheritDoc stx[1] then
|
||||
if stx[5].isNone then lint stx[3] "syntax"
|
||||
|
|
@ -196,42 +196,42 @@ def mkSimpleHandler (name : String) : SimpleHandler := fun stx => do
|
|||
if stx[0].isNone then
|
||||
lintNamed stx[2] name
|
||||
|
||||
@[builtinMissingDocsHandler syntaxAbbrev]
|
||||
@[builtin_missing_docs_handler syntaxAbbrev]
|
||||
def checkSyntaxAbbrev : SimpleHandler := mkSimpleHandler "syntax"
|
||||
|
||||
@[builtinMissingDocsHandler syntaxCat]
|
||||
@[builtin_missing_docs_handler syntaxCat]
|
||||
def checkSyntaxCat : SimpleHandler := mkSimpleHandler "syntax category"
|
||||
|
||||
@[builtinMissingDocsHandler «macro»]
|
||||
@[builtin_missing_docs_handler «macro»]
|
||||
def checkMacro : SimpleHandler := fun stx => do
|
||||
if stx[0].isNone && stx[2][0][0].getKind != ``«local» && !hasInheritDoc stx[1] then
|
||||
if stx[5].isNone then lint stx[3] "macro"
|
||||
else lintNamed stx[5][0][3] "macro"
|
||||
|
||||
@[builtinMissingDocsHandler «elab»]
|
||||
@[builtin_missing_docs_handler «elab»]
|
||||
def checkElab : SimpleHandler := fun stx => do
|
||||
if stx[0].isNone && stx[2][0][0].getKind != ``«local» && !hasInheritDoc stx[1] then
|
||||
if stx[5].isNone then lint stx[3] "elab"
|
||||
else lintNamed stx[5][0][3] "elab"
|
||||
|
||||
@[builtinMissingDocsHandler classAbbrev]
|
||||
@[builtin_missing_docs_handler classAbbrev]
|
||||
def checkClassAbbrev : SimpleHandler := fun stx => do
|
||||
if declModifiersPubNoDoc stx[0] then
|
||||
lintNamed stx[3] "class abbrev"
|
||||
|
||||
@[builtinMissingDocsHandler Parser.Tactic.declareSimpLikeTactic]
|
||||
@[builtin_missing_docs_handler Parser.Tactic.declareSimpLikeTactic]
|
||||
def checkSimpLike : SimpleHandler := mkSimpleHandler "simp-like tactic"
|
||||
|
||||
@[builtinMissingDocsHandler Option.registerBuiltinOption]
|
||||
@[builtin_missing_docs_handler Option.registerBuiltinOption]
|
||||
def checkRegisterBuiltinOption : SimpleHandler := mkSimpleHandler "option"
|
||||
|
||||
@[builtinMissingDocsHandler Option.registerOption]
|
||||
@[builtin_missing_docs_handler Option.registerOption]
|
||||
def checkRegisterOption : SimpleHandler := mkSimpleHandler "option"
|
||||
|
||||
@[builtinMissingDocsHandler registerSimpAttr]
|
||||
@[builtin_missing_docs_handler registerSimpAttr]
|
||||
def checkRegisterSimpAttr : SimpleHandler := mkSimpleHandler "simp attr"
|
||||
|
||||
@[builtinMissingDocsHandler «in»]
|
||||
@[builtin_missing_docs_handler «in»]
|
||||
def handleIn : Handler := fun _ stx => do
|
||||
if stx[0].getKind == ``«set_option» then
|
||||
let opts ← Elab.elabSetOption stx[0][1] stx[0][2]
|
||||
|
|
@ -240,6 +240,6 @@ def handleIn : Handler := fun _ stx => do
|
|||
else
|
||||
missingDocs stx[2]
|
||||
|
||||
@[builtinMissingDocsHandler «mutual»]
|
||||
@[builtin_missing_docs_handler «mutual»]
|
||||
def handleMutual : Handler := fun _ stx => do
|
||||
stx[1].getArgs.forM missingDocs
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ unsafe def getUnusedVariablesIgnoreFnsImpl : CommandElabM (Array IgnoreFunction)
|
|||
let ents ← ents.mapM (evalConstCheck IgnoreFunction ``IgnoreFunction)
|
||||
return (← builtinUnusedVariablesIgnoreFnsRef.get) ++ ents
|
||||
|
||||
@[implementedBy getUnusedVariablesIgnoreFnsImpl]
|
||||
@[implemented_by getUnusedVariablesIgnoreFnsImpl]
|
||||
opaque getUnusedVariablesIgnoreFns : CommandElabM (Array IgnoreFunction)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ end
|
|||
|
||||
end ACLt
|
||||
|
||||
@[implementedBy ACLt.lt]
|
||||
@[implemented_by ACLt.lt]
|
||||
opaque Expr.acLt : Expr → Expr → MetaM Bool
|
||||
|
||||
end Lean.Meta
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue