diff --git a/src/Init/Control/Basic.lean b/src/Init/Control/Basic.lean index 0ee7148863..3314218e46 100644 --- a/src/Init/Control/Basic.lean +++ b/src/Init/Control/Basic.lean @@ -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 diff --git a/src/Init/Control/EState.lean b/src/Init/Control/EState.lean index 2f5bae1e96..030f10b142 100644 --- a/src/Init/Control/EState.lean +++ b/src/Init/Control/EState.lean @@ -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' diff --git a/src/Init/Control/Except.lean b/src/Init/Control/Except.lean index df92df8383..3e1efa5ed7 100644 --- a/src/Init/Control/Except.lean +++ b/src/Init/Control/Except.lean @@ -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 diff --git a/src/Init/Control/ExceptCps.lean b/src/Init/Control/ExceptCps.lean index 48a587fb56..7adc504f9a 100644 --- a/src/Init/Control/ExceptCps.lean +++ b/src/Init/Control/ExceptCps.lean @@ -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 diff --git a/src/Init/Control/Id.lean b/src/Init/Control/Id.lean index 3290101043..ab1b4a1a15 100644 --- a/src/Init/Control/Id.lean +++ b/src/Init/Control/Id.lean @@ -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 := diff --git a/src/Init/Control/Option.lean b/src/Init/Control/Option.lean index 0d777a62f2..ebdcb40e97 100644 --- a/src/Init/Control/Option.lean +++ b/src/Init/Control/Option.lean @@ -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 diff --git a/src/Init/Control/Reader.lean b/src/Init/Control/Reader.lean index 4a3fa71437..b0e24e9aa4 100644 --- a/src/Init/Control/Reader.lean +++ b/src/Init/Control/Reader.lean @@ -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) diff --git a/src/Init/Control/State.lean b/src/Init/Control/State.lean index bbcc6ee119..ade42f7c0e 100644 --- a/src/Init/Control/State.lean +++ b/src/Init/Control/State.lean @@ -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 diff --git a/src/Init/Control/StateCps.lean b/src/Init/Control/StateCps.lean index 028c9b31d7..bb49ce5ea2 100644 --- a/src/Init/Control/StateCps.lean +++ b/src/Init/Control/StateCps.lean @@ -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) diff --git a/src/Init/Control/StateRef.lean b/src/Init/Control/StateRef.lean index 37cca543de..7bbdd8c341 100644 --- a/src/Init/Control/StateRef.lean +++ b/src/Init/Control/StateRef.lean @@ -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) diff --git a/src/Init/Core.lean b/src/Init/Core.lean index fd21f37ba8..bade81ce07 100644 --- a/src/Init/Core.lean +++ b/src/Init/Core.lean @@ -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))] diff --git a/src/Init/Data/Array/Basic.lean b/src/Init/Data/Array/Basic.lean index 6a3d1da0a6..fc9002312d 100644 --- a/src/Init/Data/Array/Basic.lean +++ b/src/Init/Data/Array/Basic.lean @@ -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 diff --git a/src/Init/Data/Array/BasicAux.lean b/src/Init/Data/Array/BasicAux.lean index 848f025cae..1f8285b499 100644 --- a/src/Init/Data/Array/BasicAux.lean +++ b/src/Init/Data/Array/BasicAux.lean @@ -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 α := diff --git a/src/Init/Data/Array/Subarray.lean b/src/Init/Data/Array/Subarray.lean index 343706cd49..0143263bd3 100644 --- a/src/Init/Data/Array/Subarray.lean +++ b/src/Init/Data/Array/Subarray.lean @@ -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 diff --git a/src/Init/Data/ByteArray/Basic.lean b/src/Init/Data/ByteArray/Basic.lean index 52b22c535f..46f5c4411c 100644 --- a/src/Init/Data/ByteArray/Basic.lean +++ b/src/Init/Data/ByteArray/Basic.lean @@ -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 diff --git a/src/Init/Data/FloatArray/Basic.lean b/src/Init/Data/FloatArray/Basic.lean index eef9c53b49..0c47834383 100644 --- a/src/Init/Data/FloatArray/Basic.lean +++ b/src/Init/Data/FloatArray/Basic.lean @@ -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 diff --git a/src/Init/Data/Int/Basic.lean b/src/Init/Data/Int/Basic.lean index b06174ea6a..0a12ff799e 100644 --- a/src/Init/Data/Int/Basic.lean +++ b/src/Init/Data/Int/Basic.lean @@ -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 diff --git a/src/Init/Data/OfScientific.lean b/src/Init/Data/OfScientific.lean index 584bec1c3c..772ce0b0f9 100644 --- a/src/Init/Data/OfScientific.lean +++ b/src/Init/Data/OfScientific.lean @@ -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 diff --git a/src/Init/Data/Option/Basic.lean b/src/Init/Data/Option/Basic.lean index 4a7cbc51bc..21359e6dfa 100644 --- a/src/Init/Data/Option/Basic.lean +++ b/src/Init/Data/Option/Basic.lean @@ -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 () diff --git a/src/Init/Dynamic.lean b/src/Init/Dynamic.lean index ec1cc5b8f4..a784b7dc2c 100644 --- a/src/Init/Dynamic.lean +++ b/src/Init/Dynamic.lean @@ -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 diff --git a/src/Init/Notation.lean b/src/Init/Notation.lean index 3b52d13f15..e337638a22 100644 --- a/src/Init/Notation.lean +++ b/src/Init/Notation.lean @@ -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)) diff --git a/src/Init/NotationExtra.lean b/src/Init/NotationExtra.lean index 6a927e77bc..a2b22f716b 100644 --- a/src/Init/NotationExtra.lean +++ b/src/Init/NotationExtra.lean @@ -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 () diff --git a/src/Init/Prelude.lean b/src/Init/Prelude.lean index 76d1f5d6d1..9f73068659 100644 --- a/src/Init/Prelude.lean +++ b/src/Init/Prelude.lean @@ -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 diff --git a/src/Init/ShareCommon.lean b/src/Init/ShareCommon.lean index 2fa5dbff29..7754d07f87 100644 --- a/src/Init/ShareCommon.lean +++ b/src/Init/ShareCommon.lean @@ -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"] diff --git a/src/Init/System/IO.lean b/src/Init/System/IO.lean index f4d9e4be4b..db70311513 100644 --- a/src/Init/System/IO.lean +++ b/src/Init/System/IO.lean @@ -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 diff --git a/src/Init/System/Promise.lean b/src/Init/System/Promise.lean index 83be4056ef..dcbbe302a5 100644 --- a/src/Init/System/Promise.lean +++ b/src/Init/System/Promise.lean @@ -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 diff --git a/src/Init/System/ST.lean b/src/Init/System/ST.lean index 0e247eca08..8ff6ba89ff 100644 --- a/src/Init/System/ST.lean +++ b/src/Init/System/ST.lean @@ -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 diff --git a/src/Init/Tactics.lean b/src/Init/Tactics.lean index 3f0a3fc8d7..3dc30b43c9 100644 --- a/src/Init/Tactics.lean +++ b/src/Init/Tactics.lean @@ -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) diff --git a/src/Init/Util.lean b/src/Init/Util.lean index 9ee6cdb218..55a4f64e2b 100644 --- a/src/Init/Util.lean +++ b/src/Init/Util.lean @@ -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" diff --git a/src/Lean/Attributes.lean b/src/Lean/Attributes.lean index 405953f282..44ffdd9f6d 100644 --- a/src/Lean/Attributes.lean +++ b/src/Lean/Attributes.lean @@ -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 := diff --git a/src/Lean/Compiler/IR/Basic.lean b/src/Lean/Compiler/IR/Basic.lean index 237434c7a3..a99ec82891 100644 --- a/src/Lean/Compiler/IR/Basic.lean +++ b/src/Lean/Compiler/IR/Basic.lean @@ -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⟩ diff --git a/src/Lean/Compiler/InitAttr.lean b/src/Lean/Compiler/InitAttr.lean index 16d7a5c859..6bdd5d1611 100644 --- a/src/Lean/Compiler/InitAttr.lean +++ b/src/Lean/Compiler/InitAttr.lean @@ -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] diff --git a/src/Lean/Compiler/LCNF/Basic.lean b/src/Lean/Compiler/LCNF/Basic.lean index 3dfb6aa42b..c78d585587 100644 --- a/src/Lean/Compiler/LCNF/Basic.lean +++ b/src/Lean/Compiler/LCNF/Basic.lean @@ -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 }) diff --git a/src/Lean/Compiler/LCNF/CompilerM.lean b/src/Lean/Compiler/LCNF/CompilerM.lean index fde53ebfc7..877f310c34 100644 --- a/src/Lean/Compiler/LCNF/CompilerM.lean +++ b/src/Lean/Compiler/LCNF/CompilerM.lean @@ -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 diff --git a/src/Lean/Compiler/LCNF/LambdaLifting.lean b/src/Lean/Compiler/LCNF/LambdaLifting.lean index 0585d12140..e2a7413171 100644 --- a/src/Lean/Compiler/LCNF/LambdaLifting.lean +++ b/src/Lean/Compiler/LCNF/LambdaLifting.lean @@ -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 diff --git a/src/Lean/Compiler/LCNF/PassManager.lean b/src/Lean/Compiler/LCNF/PassManager.lean index 79774019a9..7347e3792a 100644 --- a/src/Lean/Compiler/LCNF/PassManager.lean +++ b/src/Lean/Compiler/LCNF/PassManager.lean @@ -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 diff --git a/src/Lean/Compiler/LCNF/Simp.lean b/src/Lean/Compiler/LCNF/Simp.lean index 212c6ec371..9679e29548 100644 --- a/src/Lean/Compiler/LCNF/Simp.lean +++ b/src/Lean/Compiler/LCNF/Simp.lean @@ -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`. diff --git a/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean b/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean index 7a4c71759e..9fefd02e74 100644 --- a/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean +++ b/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean @@ -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 diff --git a/src/Lean/Compiler/LCNF/Simp/DiscrM.lean b/src/Lean/Compiler/LCNF/Simp/DiscrM.lean index 8276faf25c..ea523c32ad 100644 --- a/src/Lean/Compiler/LCNF/Simp/DiscrM.lean +++ b/src/Lean/Compiler/LCNF/Simp/DiscrM.lean @@ -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 diff --git a/src/Lean/Compiler/LCNF/Simp/SimpM.lean b/src/Lean/Compiler/LCNF/Simp/SimpM.lean index 2b6ae4d157..14ae6d0562 100644 --- a/src/Lean/Compiler/LCNF/Simp/SimpM.lean +++ b/src/Lean/Compiler/LCNF/Simp/SimpM.lean @@ -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 diff --git a/src/Lean/CoreM.lean b/src/Lean/CoreM.lean index 735095ea80..a01f10113b 100644 --- a/src/Lean/CoreM.lean +++ b/src/Lean/CoreM.lean @@ -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 diff --git a/src/Lean/Elab/App.lean b/src/Lean/Elab/App.lean index 142491c2fc..82021923eb 100644 --- a/src/Lean/Elab/App.lean +++ b/src/Lean/Elab/App.lean @@ -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 diff --git a/src/Lean/Elab/AuxDef.lean b/src/Lean/Elab/AuxDef.lean index e0661c5ab7..bb8984e523 100644 --- a/src/Lean/Elab/AuxDef.lean +++ b/src/Lean/Elab/AuxDef.lean @@ -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 diff --git a/src/Lean/Elab/Binders.lean b/src/Lean/Elab/Binders.lean index c18acbb2f8..6e03d6712e 100644 --- a/src/Lean/Elab/Binders.lean +++ b/src/Lean/Elab/Binders.lean @@ -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 diff --git a/src/Lean/Elab/BuiltinCommand.lean b/src/Lean/Elab/BuiltinCommand.lean index 663b5e3c00..b46ebb4863 100644 --- a/src/Lean/Elab/BuiltinCommand.lean +++ b/src/Lean/Elab/BuiltinCommand.lean @@ -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 diff --git a/src/Lean/Elab/BuiltinNotation.lean b/src/Lean/Elab/BuiltinNotation.lean index 8569353bc4..054e4a6f4b 100644 --- a/src/Lean/Elab/BuiltinNotation.lean +++ b/src/Lean/Elab/BuiltinNotation.lean @@ -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 diff --git a/src/Lean/Elab/BuiltinTerm.lean b/src/Lean/Elab/BuiltinTerm.lean index 7a19f02183..cd9cebafa7 100644 --- a/src/Lean/Elab/BuiltinTerm.lean +++ b/src/Lean/Elab/BuiltinTerm.lean @@ -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 diff --git a/src/Lean/Elab/Calc.lean b/src/Lean/Elab/Calc.lean index a7b8458012..4f6da6e7b8 100644 --- a/src/Lean/Elab/Calc.lean +++ b/src/Lean/Elab/Calc.lean @@ -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 diff --git a/src/Lean/Elab/Command.lean b/src/Lean/Elab/Command.lean index c06fe78f8b..14754ed5a9 100644 --- a/src/Lean/Elab/Command.lean +++ b/src/Lean/Elab/Command.lean @@ -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% diff --git a/src/Lean/Elab/ComputedFields.lean b/src/Lean/Elab/ComputedFields.lean index 552145c4a8..2019d83ee1 100644 --- a/src/Lean/Elab/ComputedFields.lean +++ b/src/Lean/Elab/ComputedFields.lean @@ -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. diff --git a/src/Lean/Elab/Declaration.lean b/src/Lean/Elab/Declaration.lean index 1b471f9e93..b8073722b9 100644 --- a/src/Lean/Elab/Declaration.lean +++ b/src/Lean/Elab/Declaration.lean @@ -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 diff --git a/src/Lean/Elab/Deriving/Basic.lean b/src/Lean/Elab/Deriving/Basic.lean index 2c934665f1..6fd387d5df 100644 --- a/src/Lean/Elab/Deriving/Basic.lean +++ b/src/Lean/Elab/Deriving/Basic.lean @@ -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 diff --git a/src/Lean/Elab/Do.lean b/src/Lean/Elab/Do.lean index bc49ece918..a4a23b3dd5 100644 --- a/src/Lean/Elab/Do.lean +++ b/src/Lean/Elab/Do.lean @@ -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 diff --git a/src/Lean/Elab/ElabRules.lean b/src/Lean/Elab/ElabRules.lean index 87582e3172..c51c7bcf96 100644 --- a/src/Lean/Elab/ElabRules.lean +++ b/src/Lean/Elab/ElabRules.lean @@ -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* : diff --git a/src/Lean/Elab/Extra.lean b/src/Lean/Elab/Extra.lean index 994eb74962..f8dfd05766 100644 --- a/src/Lean/Elab/Extra.lean +++ b/src/Lean/Elab/Extra.lean @@ -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 diff --git a/src/Lean/Elab/GenInjective.lean b/src/Lean/Elab/GenInjective.lean index 8a97530f6a..becc897bb6 100644 --- a/src/Lean/Elab/GenInjective.lean +++ b/src/Lean/Elab/GenInjective.lean @@ -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 diff --git a/src/Lean/Elab/LetRec.lean b/src/Lean/Elab/LetRec.lean index 8367fa68a2..41a5153137 100644 --- a/src/Lean/Elab/LetRec.lean +++ b/src/Lean/Elab/LetRec.lean @@ -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 diff --git a/src/Lean/Elab/Level.lean b/src/Lean/Elab/Level.lean index f3fd95d165..610d44a141 100644 --- a/src/Lean/Elab/Level.lean +++ b/src/Lean/Elab/Level.lean @@ -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 } diff --git a/src/Lean/Elab/Macro.lean b/src/Lean/Elab/Macro.lean index 59c7fec754..890db271f6 100644 --- a/src/Lean/Elab/Macro.lean +++ b/src/Lean/Elab/Macro.lean @@ -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 diff --git a/src/Lean/Elab/MacroRules.lean b/src/Lean/Elab/MacroRules.lean index 30110f74d6..8384c81fc0 100644 --- a/src/Lean/Elab/MacroRules.lean +++ b/src/Lean/Elab/MacroRules.lean @@ -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 diff --git a/src/Lean/Elab/Match.lean b/src/Lean/Elab/Match.lean index 4d4d1ac749..b4d9883d85 100644 --- a/src/Lean/Elab/Match.lean +++ b/src/Lean/Elab/Match.lean @@ -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 diff --git a/src/Lean/Elab/Mixfix.lean b/src/Lean/Elab/Mixfix.lean index e74ef2a9be..c50100acaa 100644 --- a/src/Lean/Elab/Mixfix.lean +++ b/src/Lean/Elab/Mixfix.lean @@ -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) => diff --git a/src/Lean/Elab/Notation.lean b/src/Lean/Elab/Notation.lean index a25fe92e54..710f6d728c 100644 --- a/src/Lean/Elab/Notation.lean +++ b/src/Lean/Elab/Notation.lean @@ -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 diff --git a/src/Lean/Elab/Print.lean b/src/Lean/Elab/Print.lean index addcb93559..8e22327e1d 100644 --- a/src/Lean/Elab/Print.lean +++ b/src/Lean/Elab/Print.lean @@ -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 diff --git a/src/Lean/Elab/Quotation.lean b/src/Lean/Elab/Quotation.lean index d5d455e7fc..04c6190e9a 100644 --- a/src/Lean/Elab/Quotation.lean +++ b/src/Lean/Elab/Quotation.lean @@ -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 diff --git a/src/Lean/Elab/Quotation/Precheck.lean b/src/Lean/Elab/Quotation/Precheck.lean index aeaecd46a6..16442d929f 100644 --- a/src/Lean/Elab/Quotation/Precheck.lean +++ b/src/Lean/Elab/Quotation/Precheck.lean @@ -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? diff --git a/src/Lean/Elab/StructInst.lean b/src/Lean/Elab/StructInst.lean index 1bd55efe61..868c818f66 100644 --- a/src/Lean/Elab/StructInst.lean +++ b/src/Lean/Elab/StructInst.lean @@ -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 => diff --git a/src/Lean/Elab/Syntax.lean b/src/Lean/Elab/Syntax.lean index 40fc670a6f..d2b0500033 100644 --- a/src/Lean/Elab/Syntax.lean +++ b/src/Lean/Elab/Syntax.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Basic.lean b/src/Lean/Elab/Tactic/Basic.lean index e71788181e..f786d6fc7e 100644 --- a/src/Lean/Elab/Tactic/Basic.lean +++ b/src/Lean/Elab/Tactic/Basic.lean @@ -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 { diff --git a/src/Lean/Elab/Tactic/BuiltinTactic.lean b/src/Lean/Elab/Tactic/BuiltinTactic.lean index c6d4faa8c4..d5fee377fe 100644 --- a/src/Lean/Elab/Tactic/BuiltinTactic.lean +++ b/src/Lean/Elab/Tactic/BuiltinTactic.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Cache.lean b/src/Lean/Elab/Tactic/Cache.lean index 9555ca5ea0..dea4b86fb8 100644 --- a/src/Lean/Elab/Tactic/Cache.lean +++ b/src/Lean/Elab/Tactic/Cache.lean @@ -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] diff --git a/src/Lean/Elab/Tactic/Calc.lean b/src/Lean/Elab/Tactic/Calc.lean index ace04ce2ca..245984a905 100644 --- a/src/Lean/Elab/Tactic/Calc.lean +++ b/src/Lean/Elab/Tactic/Calc.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Config.lean b/src/Lean/Elab/Tactic/Config.lean index b2f30d517c..9f8fa220a1 100644 --- a/src/Lean/Elab/Tactic/Config.lean +++ b/src/Lean/Elab/Tactic/Config.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Congr.lean b/src/Lean/Elab/Tactic/Congr.lean index 72ed18527a..4d45e7977a 100644 --- a/src/Lean/Elab/Tactic/Congr.lean +++ b/src/Lean/Elab/Tactic/Congr.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Conv/Basic.lean b/src/Lean/Elab/Tactic/Conv/Basic.lean index 42ca3eb343..bc4bb3ce76 100644 --- a/src/Lean/Elab/Tactic/Conv/Basic.lean +++ b/src/Lean/Elab/Tactic/Conv/Basic.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Conv/Change.lean b/src/Lean/Elab/Tactic/Conv/Change.lean index 3930f7a997..385cbf0c63 100644 --- a/src/Lean/Elab/Tactic/Conv/Change.lean +++ b/src/Lean/Elab/Tactic/Conv/Change.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Conv/Congr.lean b/src/Lean/Elab/Tactic/Conv/Congr.lean index 0c78c1e167..4b9dae5359 100644 --- a/src/Lean/Elab/Tactic/Conv/Congr.lean +++ b/src/Lean/Elab/Tactic/Conv/Congr.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Conv/Delta.lean b/src/Lean/Elab/Tactic/Conv/Delta.lean index 60202eb003..55b0a5e9d7 100644 --- a/src/Lean/Elab/Tactic/Conv/Delta.lean +++ b/src/Lean/Elab/Tactic/Conv/Delta.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Conv/Pattern.lean b/src/Lean/Elab/Tactic/Conv/Pattern.lean index 6278c3a4a1..7f149d6016 100644 --- a/src/Lean/Elab/Tactic/Conv/Pattern.lean +++ b/src/Lean/Elab/Tactic/Conv/Pattern.lean @@ -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 ← diff --git a/src/Lean/Elab/Tactic/Conv/Rewrite.lean b/src/Lean/Elab/Tactic/Conv/Rewrite.lean index 39861871c2..a6d3ed840b 100644 --- a/src/Lean/Elab/Tactic/Conv/Rewrite.lean +++ b/src/Lean/Elab/Tactic/Conv/Rewrite.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Conv/Simp.lean b/src/Lean/Elab/Tactic/Conv/Simp.lean index 2321e7caae..f71a349b35 100644 --- a/src/Lean/Elab/Tactic/Conv/Simp.lean +++ b/src/Lean/Elab/Tactic/Conv/Simp.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Conv/Unfold.lean b/src/Lean/Elab/Tactic/Conv/Unfold.lean index fd2c60c8e4..9c12e9991d 100644 --- a/src/Lean/Elab/Tactic/Conv/Unfold.lean +++ b/src/Lean/Elab/Tactic/Conv/Unfold.lean @@ -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) diff --git a/src/Lean/Elab/Tactic/Delta.lean b/src/Lean/Elab/Tactic/Delta.lean index 3e9b7fae76..7171b785a4 100644 --- a/src/Lean/Elab/Tactic/Delta.lean +++ b/src/Lean/Elab/Tactic/Delta.lean @@ -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) diff --git a/src/Lean/Elab/Tactic/ElabTerm.lean b/src/Lean/Elab/Tactic/ElabTerm.lean index 93152dc2b5..623ff77a64 100644 --- a/src/Lean/Elab/Tactic/ElabTerm.lean +++ b/src/Lean/Elab/Tactic/ElabTerm.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Generalize.lean b/src/Lean/Elab/Tactic/Generalize.lean index f3f3da8ea8..2f915b9202 100644 --- a/src/Lean/Elab/Tactic/Generalize.lean +++ b/src/Lean/Elab/Tactic/Generalize.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Induction.lean b/src/Lean/Elab/Tactic/Induction.lean index 622f95d72c..bbdcdb84fa 100644 --- a/src/Lean/Elab/Tactic/Induction.lean +++ b/src/Lean/Elab/Tactic/Induction.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Injection.lean b/src/Lean/Elab/Tactic/Injection.lean index e27ac15364..eaaf69bd21 100644 --- a/src/Lean/Elab/Tactic/Injection.lean +++ b/src/Lean/Elab/Tactic/Injection.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Match.lean b/src/Lean/Elab/Tactic/Match.lean index 7157741023..a2eb3c86f7 100644 --- a/src/Lean/Elab/Tactic/Match.lean +++ b/src/Lean/Elab/Tactic/Match.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Rewrite.lean b/src/Lean/Elab/Tactic/Rewrite.lean index 0b9b668eb4..55de56b798 100644 --- a/src/Lean/Elab/Tactic/Rewrite.lean +++ b/src/Lean/Elab/Tactic/Rewrite.lean @@ -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 diff --git a/src/Lean/Elab/Tactic/Simp.lean b/src/Lean/Elab/Tactic/Simp.lean index 86e1c56c88..df13416168 100644 --- a/src/Lean/Elab/Tactic/Simp.lean +++ b/src/Lean/Elab/Tactic/Simp.lean @@ -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]) diff --git a/src/Lean/Elab/Tactic/Split.lean b/src/Lean/Elab/Tactic/Split.lean index 5615c48a0a..b44eff6fd0 100644 --- a/src/Lean/Elab/Tactic/Split.lean +++ b/src/Lean/Elab/Tactic/Split.lean @@ -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] diff --git a/src/Lean/Elab/Tactic/Unfold.lean b/src/Lean/Elab/Tactic/Unfold.lean index 69ea96a588..fc0936d154 100644 --- a/src/Lean/Elab/Tactic/Unfold.lean +++ b/src/Lean/Elab/Tactic/Unfold.lean @@ -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 diff --git a/src/Lean/Elab/Term.lean b/src/Lean/Elab/Term.lean index 503a342b86..64cde873eb 100644 --- a/src/Lean/Elab/Term.lean +++ b/src/Lean/Elab/Term.lean @@ -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% diff --git a/src/Lean/Elab/Util.lean b/src/Lean/Elab/Util.lean index 0ca9269cd5..a096e8bb74 100644 --- a/src/Lean/Elab/Util.lean +++ b/src/Lean/Elab/Util.lean @@ -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 _) diff --git a/src/Lean/Environment.lean b/src/Lean/Environment.lean index 93690de4d3..19eb078190 100644 --- a/src/Lean/Environment.lean +++ b/src/Lean/Environment.lean @@ -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) diff --git a/src/Lean/Expr.lean b/src/Lean/Expr.lean index 4e6c8dc964..fd6a8c8a80 100644 --- a/src/Lean/Expr.lean +++ b/src/Lean/Expr.lean @@ -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 diff --git a/src/Lean/Level.lean b/src/Lean/Level.lean index c90dd68ec0..c4782a6d58 100644 --- a/src/Lean/Level.lean +++ b/src/Lean/Level.lean @@ -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 diff --git a/src/Lean/Linter/MissingDocs.lean b/src/Lean/Linter/MissingDocs.lean index 0c151d8ecf..7c3f5f6977 100644 --- a/src/Lean/Linter/MissingDocs.lean +++ b/src/Lean/Linter/MissingDocs.lean @@ -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 diff --git a/src/Lean/Linter/UnusedVariables.lean b/src/Lean/Linter/UnusedVariables.lean index c287efa153..9ee71bed4b 100644 --- a/src/Lean/Linter/UnusedVariables.lean +++ b/src/Lean/Linter/UnusedVariables.lean @@ -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) diff --git a/src/Lean/Meta/ACLt.lean b/src/Lean/Meta/ACLt.lean index d7dd4d3808..5583968097 100644 --- a/src/Lean/Meta/ACLt.lean +++ b/src/Lean/Meta/ACLt.lean @@ -154,7 +154,7 @@ end end ACLt -@[implementedBy ACLt.lt] +@[implemented_by ACLt.lt] opaque Expr.acLt : Expr → Expr → MetaM Bool end Lean.Meta diff --git a/src/Lean/Meta/AbstractMVars.lean b/src/Lean/Meta/AbstractMVars.lean index 8af495c481..a362566d56 100644 --- a/src/Lean/Meta/AbstractMVars.lean +++ b/src/Lean/Meta/AbstractMVars.lean @@ -27,7 +27,7 @@ structure State where abbrev M := StateM State -@[alwaysInline] +@[always_inline] instance : MonadMCtx M where getMCtx := return (← get).mctx modifyMCtx f := modify fun s => { s with mctx := f s.mctx } diff --git a/src/Lean/Meta/Basic.lean b/src/Lean/Meta/Basic.lean index 690b7324cb..34bb562e22 100644 --- a/src/Lean/Meta/Basic.lean +++ b/src/Lean/Meta/Basic.lean @@ -300,7 +300,7 @@ abbrev MetaM := ReaderT Context $ StateRefT State CoreM -- 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 MetaM := let i := inferInstanceAs (Monad MetaM); { pure := i.pure, bind := i.bind } instance : Inhabited (MetaM α) where diff --git a/src/Lean/Meta/RecursorInfo.lean b/src/Lean/Meta/RecursorInfo.lean index b543ff795f..824d069673 100644 --- a/src/Lean/Meta/RecursorInfo.lean +++ b/src/Lean/Meta/RecursorInfo.lean @@ -238,7 +238,7 @@ private def mkRecursorInfoAux (cinfo : ConstantInfo) (majorPos? : Option Nat) : | _ => throwError "invalid user defined recursor '{declName}', type of the major premise must be of the form (I ...), where I is a constant" /- -@[builtinAttrParser] def «recursor» := leading_parser "recursor " >> numLit +@[builtin_attr_parser] def «recursor» := leading_parser "recursor " >> numLit -/ def Attribute.Recursor.getMajorPos (stx : Syntax) : AttrM Nat := do if stx.getKind == `Lean.Parser.Attr.recursor then diff --git a/src/Lean/Meta/SynthInstance.lean b/src/Lean/Meta/SynthInstance.lean index 19d37e2a5f..6c914976cd 100644 --- a/src/Lean/Meta/SynthInstance.lean +++ b/src/Lean/Meta/SynthInstance.lean @@ -89,7 +89,7 @@ structure State where abbrev M := StateM State -@[alwaysInline] +@[always_inline] instance : MonadMCtx M where getMCtx := return (← get).mctx modifyMCtx f := modify fun s => { s with mctx := f s.mctx } diff --git a/src/Lean/Meta/Tactic/AC/Main.lean b/src/Lean/Meta/Tactic/AC/Main.lean index 3a5fe8cc1b..297565c113 100644 --- a/src/Lean/Meta/Tactic/AC/Main.lean +++ b/src/Lean/Meta/Tactic/AC/Main.lean @@ -57,7 +57,7 @@ inductive PreExpr | op (lhs rhs : PreExpr) | var (e : Expr) -@[matchPattern] def bin (op l r : Expr) := +@[match_pattern] def bin (op l r : Expr) := Expr.app (Expr.app op l) r def toACExpr (op l r : Expr) : MetaM (Array Expr × ACExpr) := do @@ -168,7 +168,7 @@ where | none => return Simp.Step.done { expr := e } | e, _ => return Simp.Step.done { expr := e } -@[builtinTactic acRfl] def acRflTactic : Lean.Elab.Tactic.Tactic := fun _ => do +@[builtin_tactic acRfl] def acRflTactic : Lean.Elab.Tactic.Tactic := fun _ => do let goal ← getMainGoal goal.withContext <| rewriteUnnormalized goal diff --git a/src/Lean/Meta/Tactic/Generalize.lean b/src/Lean/Meta/Tactic/Generalize.lean index 462fe2faea..ff3993ba39 100644 --- a/src/Lean/Meta/Tactic/Generalize.lean +++ b/src/Lean/Meta/Tactic/Generalize.lean @@ -70,11 +70,11 @@ private partial def generalizeCore (mvarId : MVarId) (args : Array GeneralizeArg mvarId.assign (mkAppN (mkAppN mvarNew es) rfls.toArray) mvarNew.mvarId!.introNP (args.size + rfls.length) -@[inheritDoc generalizeCore] +@[inherit_doc generalizeCore] def _root_.Lean.MVarId.generalize (mvarId : MVarId) (args : Array GeneralizeArg) : MetaM (Array FVarId × MVarId) := generalizeCore mvarId args -@[inheritDoc generalizeCore, deprecated MVarId.generalize] +@[inherit_doc generalizeCore, deprecated MVarId.generalize] def generalize (mvarId : MVarId) (args : Array GeneralizeArg) : MetaM (Array FVarId × MVarId) := generalizeCore mvarId args diff --git a/src/Lean/Meta/WHNF.lean b/src/Lean/Meta/WHNF.lean index 288d32a59c..d991870986 100644 --- a/src/Lean/Meta/WHNF.lean +++ b/src/Lean/Meta/WHNF.lean @@ -747,8 +747,8 @@ def reduceRecMatcher? (e : Expr) : MetaM (Option Expr) := do unsafe def reduceBoolNativeUnsafe (constName : Name) : MetaM Bool := evalConstCheck Bool `Bool constName unsafe def reduceNatNativeUnsafe (constName : Name) : MetaM Nat := evalConstCheck Nat `Nat constName -@[implementedBy reduceBoolNativeUnsafe] opaque reduceBoolNative (constName : Name) : MetaM Bool -@[implementedBy reduceNatNativeUnsafe] opaque reduceNatNative (constName : Name) : MetaM Nat +@[implemented_by reduceBoolNativeUnsafe] opaque reduceBoolNative (constName : Name) : MetaM Bool +@[implemented_by reduceNatNativeUnsafe] opaque reduceNatNative (constName : Name) : MetaM Nat def reduceNative? (e : Expr) : MetaM (Option Expr) := match e with diff --git a/src/Lean/MetavarContext.lean b/src/Lean/MetavarContext.lean index b15fafae8d..37ad643c03 100644 --- a/src/Lean/MetavarContext.lean +++ b/src/Lean/MetavarContext.lean @@ -330,7 +330,7 @@ class MonadMCtx (m : Type → Type) where export MonadMCtx (getMCtx modifyMCtx) -@[alwaysInline] +@[always_inline] instance (m n) [MonadLift m n] [MonadMCtx m] : MonadMCtx n where getMCtx := liftM (getMCtx : m _) modifyMCtx := fun f => liftM (modifyMCtx f : m _) diff --git a/src/Lean/Parser.lean b/src/Lean/Parser.lean index d4aef2b861..ea4bb99162 100644 --- a/src/Lean/Parser.lean +++ b/src/Lean/Parser.lean @@ -60,11 +60,11 @@ def mkAntiquot.parenthesizer (name : String) (kind : SyntaxNodeKind) (anonymous -- The parenthesizer auto-generated these instances correctly, but tagged them with the wrong kind, since the actual kind -- (e.g. `ident`) is not equal to the parser name `Lean.Parser.Term.ident`. -@[builtinParenthesizer ident] def ident.parenthesizer : Parenthesizer := Parser.Term.ident.parenthesizer -@[builtinParenthesizer num] def numLit.parenthesizer : Parenthesizer := Parser.Term.num.parenthesizer -@[builtinParenthesizer scientific] def scientificLit.parenthesizer : Parenthesizer := Parser.Term.scientific.parenthesizer -@[builtinParenthesizer char] def charLit.parenthesizer : Parenthesizer := Parser.Term.char.parenthesizer -@[builtinParenthesizer str] def strLit.parenthesizer : Parenthesizer := Parser.Term.str.parenthesizer +@[builtin_parenthesizer ident] def ident.parenthesizer : Parenthesizer := Parser.Term.ident.parenthesizer +@[builtin_parenthesizer num] def numLit.parenthesizer : Parenthesizer := Parser.Term.num.parenthesizer +@[builtin_parenthesizer scientific] def scientificLit.parenthesizer : Parenthesizer := Parser.Term.scientific.parenthesizer +@[builtin_parenthesizer char] def charLit.parenthesizer : Parenthesizer := Parser.Term.char.parenthesizer +@[builtin_parenthesizer str] def strLit.parenthesizer : Parenthesizer := Parser.Term.str.parenthesizer open Lean.Parser @@ -91,11 +91,11 @@ namespace Formatter def mkAntiquot.formatter (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPseudoKind := true) : Formatter := Parser.mkAntiquot.formatter name kind anonymous isPseudoKind -@[builtinFormatter ident] def ident.formatter : Formatter := Parser.Term.ident.formatter -@[builtinFormatter num] def numLit.formatter : Formatter := Parser.Term.num.formatter -@[builtinFormatter scientific] def scientificLit.formatter : Formatter := Parser.Term.scientific.formatter -@[builtinFormatter char] def charLit.formatter : Formatter := Parser.Term.char.formatter -@[builtinFormatter str] def strLit.formatter : Formatter := Parser.Term.str.formatter +@[builtin_formatter ident] def ident.formatter : Formatter := Parser.Term.ident.formatter +@[builtin_formatter num] def numLit.formatter : Formatter := Parser.Term.num.formatter +@[builtin_formatter scientific] def scientificLit.formatter : Formatter := Parser.Term.scientific.formatter +@[builtin_formatter char] def charLit.formatter : Formatter := Parser.Term.char.formatter +@[builtin_formatter str] def strLit.formatter : Formatter := Parser.Term.str.formatter open Lean.Parser diff --git a/src/Lean/Parser/Attr.lean b/src/Lean/Parser/Attr.lean index 6a1044a4e5..bd3042d488 100644 --- a/src/Lean/Parser/Attr.lean +++ b/src/Lean/Parser/Attr.lean @@ -22,30 +22,30 @@ builtin_initialize @[inline] def attrParser (rbp : Nat := 0) : Parser := categoryParser `attr rbp -attribute [runBuiltinParserAttributeHooks] +attribute [run_builtin_parser_attribute_hooks] priorityParser attrParser namespace Priority -@[builtinPrioParser] def numPrio := checkPrec maxPrec >> numLit -attribute [runBuiltinParserAttributeHooks] numPrio +@[builtin_prio_parser] def numPrio := checkPrec maxPrec >> numLit +attribute [run_builtin_parser_attribute_hooks] numPrio end Priority namespace Attr -@[builtinAttrParser] def simple := leading_parser ident >> optional (priorityParser <|> ident) +@[builtin_attr_parser] def simple := leading_parser ident >> optional (priorityParser <|> ident) /- Remark, We can't use `simple` for `class`, `instance`, `export`, and `macro` because they are keywords. -/ -@[builtinAttrParser] def «macro» := leading_parser "macro " >> ident -@[builtinAttrParser] def «export» := leading_parser "export " >> ident +@[builtin_attr_parser] def «macro» := leading_parser "macro " >> ident +@[builtin_attr_parser] def «export» := leading_parser "export " >> ident /- We don't use `simple` for recursor because the argument is not a priority -/ -@[builtinAttrParser] def recursor := leading_parser nonReservedSymbol "recursor " >> numLit -@[builtinAttrParser] def «class» := leading_parser "class" -@[builtinAttrParser] def «instance» := leading_parser "instance" >> optional priorityParser -@[builtinAttrParser] def default_instance := leading_parser nonReservedSymbol "default_instance " >> optional priorityParser -@[builtinAttrParser] def «specialize» := leading_parser (nonReservedSymbol "specialize") >> many (ident <|> numLit) +@[builtin_attr_parser] def recursor := leading_parser nonReservedSymbol "recursor " >> numLit +@[builtin_attr_parser] def «class» := leading_parser "class" +@[builtin_attr_parser] def «instance» := leading_parser "instance" >> optional priorityParser +@[builtin_attr_parser] def default_instance := leading_parser nonReservedSymbol "default_instance " >> optional priorityParser +@[builtin_attr_parser] def «specialize» := leading_parser (nonReservedSymbol "specialize") >> many (ident <|> numLit) def externEntry := leading_parser optional ident >> optional (nonReservedSymbol "inline ") >> strLit -@[builtinAttrParser] def extern := leading_parser nonReservedSymbol "extern " >> optional numLit >> many externEntry +@[builtin_attr_parser] def extern := leading_parser nonReservedSymbol "extern " >> optional numLit >> many externEntry end Attr diff --git a/src/Lean/Parser/Command.lean b/src/Lean/Parser/Command.lean index 79443f6e9f..bc65b3cd03 100644 --- a/src/Lean/Parser/Command.lean +++ b/src/Lean/Parser/Command.lean @@ -10,8 +10,8 @@ namespace Lean namespace Parser /-- Syntax quotation for terms. -/ -@[builtinTermParser] def Term.quot := leading_parser "`(" >> incQuotDepth termParser >> ")" -@[builtinTermParser] def Term.precheckedQuot := leading_parser "`" >> Term.quot +@[builtin_term_parser] def Term.quot := leading_parser "`(" >> incQuotDepth termParser >> ")" +@[builtin_term_parser] def Term.precheckedQuot := leading_parser "`" >> Term.quot namespace Command @@ -20,7 +20,7 @@ namespace Command `` `($x $y) `` will be parsed as an application, not two commands. Use `` `($x:command $y:command) `` instead. Multiple commands will be put in a `` `null `` node, but a single command will not (so that you can directly match against a quotation in a command kind's elaborator). -/ -@[builtinTermParser low] def quot := leading_parser "`(" >> incQuotDepth (many1Unbox commandParser) >> ")" +@[builtin_term_parser low] def quot := leading_parser "`(" >> incQuotDepth (many1Unbox commandParser) >> ")" /- A mutual block may be broken in different cliques, we identify them using an `ident` (an element of the clique) @@ -40,7 +40,7 @@ def terminationBy := leading_parser ppLine >> "termination_by " >> many def terminationSuffix := optional (terminationBy <|> terminationByCore) >> optional decreasingBy -@[builtinCommandParser] +@[builtin_command_parser] def moduleDoc := leading_parser ppDedent $ "/-!" >> commentBody >> ppLine def namedPrio := leading_parser (atomic ("(" >> nonReservedSymbol "priority") >> " := " >> priorityParser >> ")") @@ -113,30 +113,30 @@ def «structure» := leading_parser (structureTk <|> classTk) >> declId >> many (ppSpace >> Term.bracketedBinder) >> optional «extends» >> Term.optType >> optional ((symbol " := " <|> " where ") >> optional structCtor >> structFields) >> optDeriving -@[builtinCommandParser] def declaration := leading_parser +@[builtin_command_parser] def declaration := leading_parser declModifiers false >> («abbrev» <|> «def» <|> «theorem» <|> «opaque» <|> «instance» <|> «axiom» <|> «example» <|> «inductive» <|> classInductive <|> «structure») -@[builtinCommandParser] def «deriving» := leading_parser "deriving " >> "instance " >> derivingClasses >> " for " >> sepBy1 ident ", " -@[builtinCommandParser] def noncomputableSection := leading_parser "noncomputable " >> "section " >> optional ident -@[builtinCommandParser] def «section» := leading_parser "section " >> optional ident -@[builtinCommandParser] def «namespace» := leading_parser "namespace " >> ident -@[builtinCommandParser] def «end» := leading_parser "end " >> optional ident -@[builtinCommandParser] def «variable» := leading_parser "variable" >> many1 (ppSpace >> Term.bracketedBinder) -@[builtinCommandParser] def «universe» := leading_parser "universe " >> many1 ident -@[builtinCommandParser] def check := leading_parser "#check " >> termParser -@[builtinCommandParser] def check_failure := leading_parser "#check_failure " >> termParser -- Like `#check`, but succeeds only if term does not type check -@[builtinCommandParser] def reduce := leading_parser "#reduce " >> termParser -@[builtinCommandParser] def eval := leading_parser "#eval " >> termParser -@[builtinCommandParser] def synth := leading_parser "#synth " >> termParser -@[builtinCommandParser] def exit := leading_parser "#exit" -@[builtinCommandParser] def print := leading_parser "#print " >> (ident <|> strLit) -@[builtinCommandParser] def printAxioms := leading_parser "#print " >> nonReservedSymbol "axioms " >> ident -@[builtinCommandParser] def «init_quot» := leading_parser "init_quot" +@[builtin_command_parser] def «deriving» := leading_parser "deriving " >> "instance " >> derivingClasses >> " for " >> sepBy1 ident ", " +@[builtin_command_parser] def noncomputableSection := leading_parser "noncomputable " >> "section " >> optional ident +@[builtin_command_parser] def «section» := leading_parser "section " >> optional ident +@[builtin_command_parser] def «namespace» := leading_parser "namespace " >> ident +@[builtin_command_parser] def «end» := leading_parser "end " >> optional ident +@[builtin_command_parser] def «variable» := leading_parser "variable" >> many1 (ppSpace >> Term.bracketedBinder) +@[builtin_command_parser] def «universe» := leading_parser "universe " >> many1 ident +@[builtin_command_parser] def check := leading_parser "#check " >> termParser +@[builtin_command_parser] def check_failure := leading_parser "#check_failure " >> termParser -- Like `#check`, but succeeds only if term does not type check +@[builtin_command_parser] def reduce := leading_parser "#reduce " >> termParser +@[builtin_command_parser] def eval := leading_parser "#eval " >> termParser +@[builtin_command_parser] def synth := leading_parser "#synth " >> termParser +@[builtin_command_parser] def exit := leading_parser "#exit" +@[builtin_command_parser] def print := leading_parser "#print " >> (ident <|> strLit) +@[builtin_command_parser] def printAxioms := leading_parser "#print " >> nonReservedSymbol "axioms " >> ident +@[builtin_command_parser] def «init_quot» := leading_parser "init_quot" def optionValue := nonReservedSymbol "true" <|> nonReservedSymbol "false" <|> strLit <|> numLit -@[builtinCommandParser] def «set_option» := leading_parser "set_option " >> ident >> ppSpace >> optionValue +@[builtin_command_parser] def «set_option» := leading_parser "set_option " >> ident >> ppSpace >> optionValue def eraseAttr := leading_parser "-" >> rawIdent -@[builtinCommandParser] def «attribute» := leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "] " >> many1 ident -@[builtinCommandParser] def «export» := leading_parser "export " >> ident >> " (" >> many1 ident >> ")" -@[builtinCommandParser] def «import» := leading_parser "import" -- not a real command, only for error messages +@[builtin_command_parser] def «attribute» := leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "] " >> many1 ident +@[builtin_command_parser] def «export» := leading_parser "export " >> ident >> " (" >> many1 ident >> ")" +@[builtin_command_parser] def «import» := leading_parser "import" -- not a real command, only for error messages def openHiding := leading_parser atomic (ident >> "hiding") >> many1 (checkColGt >> ident) def openRenamingItem := leading_parser ident >> unicodeSymbol " → " " -> " >> checkColGt >> ident def openRenaming := leading_parser atomic (ident >> "renaming") >> sepBy1 openRenamingItem ", " @@ -145,23 +145,23 @@ def openSimple := leading_parser many1 (checkColGt >> ident) def openScoped := leading_parser "scoped " >> many1 (checkColGt >> ident) def openDecl := withAntiquot (mkAntiquot "openDecl" `Lean.Parser.Command.openDecl (isPseudoKind := true)) <| openHiding <|> openRenaming <|> openOnly <|> openSimple <|> openScoped -@[builtinCommandParser] def «open» := leading_parser withPosition ("open " >> openDecl) +@[builtin_command_parser] def «open» := leading_parser withPosition ("open " >> openDecl) -@[builtinCommandParser] def «mutual» := leading_parser "mutual " >> many1 (ppLine >> notSymbol "end" >> commandParser) >> ppDedent (ppLine >> "end") >> terminationSuffix +@[builtin_command_parser] def «mutual» := leading_parser "mutual " >> many1 (ppLine >> notSymbol "end" >> commandParser) >> ppDedent (ppLine >> "end") >> terminationSuffix def initializeKeyword := leading_parser "initialize " <|> "builtin_initialize " -@[builtinCommandParser] def «initialize» := leading_parser declModifiers false >> initializeKeyword >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq +@[builtin_command_parser] def «initialize» := leading_parser declModifiers false >> initializeKeyword >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq -@[builtinCommandParser] def «in» := trailing_parser withOpen (" in " >> commandParser) +@[builtin_command_parser] def «in» := trailing_parser withOpen (" in " >> commandParser) -@[builtinCommandParser] def addDocString := leading_parser docComment >> "add_decl_doc" >> ident +@[builtin_command_parser] def addDocString := leading_parser docComment >> "add_decl_doc" >> ident /-- This is an auxiliary command for generation constructor injectivity theorems for inductive types defined at `Prelude.lean`. It is meant for bootstrapping purposes only. -/ -@[builtinCommandParser] def genInjectiveTheorems := leading_parser "gen_injective_theorems% " >> ident +@[builtin_command_parser] def genInjectiveTheorems := leading_parser "gen_injective_theorems% " >> ident -@[runBuiltinParserAttributeHooks] abbrev declModifiersF := declModifiers false -@[runBuiltinParserAttributeHooks] abbrev declModifiersT := declModifiers true +@[run_builtin_parser_attribute_hooks] abbrev declModifiersF := declModifiers false +@[run_builtin_parser_attribute_hooks] abbrev declModifiersT := declModifiers true builtin_initialize register_parser_alias (kind := ``declModifiers) "declModifiers" declModifiersF @@ -180,26 +180,26 @@ namespace Term `open Foo in e` is like `open Foo` but scoped to a single term. It makes the given namespaces available in the term `e`. -/ -@[builtinTermParser] def «open» := leading_parser:leadPrec +@[builtin_term_parser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> withOpenDecl (" in " >> termParser) /-- `set_option opt val in e` is like `set_option opt val` but scoped to a single term. It sets the option `opt` to the value `val` in the term `e`. -/ -@[builtinTermParser] def «set_option» := leading_parser:leadPrec +@[builtin_term_parser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> termParser end Term namespace Tactic /-- `open Foo in tacs` (the tactic) acts like `open Foo` at command level, but it opens a namespace only within the tactics `tacs`. -/ -@[builtinTacticParser] def «open» := leading_parser:leadPrec +@[builtin_tactic_parser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> withOpenDecl (" in " >> tacticSeq) /-- `set_option opt val in tacs` (the tactic) acts like `set_option opt val` at the command level, but it sets the option only within the tactics `tacs`. -/ -@[builtinTacticParser] def «set_option» := leading_parser:leadPrec +@[builtin_tactic_parser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> tacticSeq end Tactic diff --git a/src/Lean/Parser/Do.lean b/src/Lean/Parser/Do.lean index 202124b462..3badcd950c 100644 --- a/src/Lean/Parser/Do.lean +++ b/src/Lean/Parser/Do.lean @@ -16,7 +16,7 @@ builtin_initialize registerBuiltinDynamicParserAttribute `doElem_parser `doElem namespace Term def leftArrow : Parser := unicodeSymbol "← " "<- " -@[builtinTermParser] def liftMethod := leading_parser:minPrec leftArrow >> termParser +@[builtin_term_parser] def liftMethod := leading_parser:minPrec leftArrow >> termParser def doSeqItem := leading_parser ppLine >> doElemParser >> optional "; " def doSeqIndent := leading_parser many1Indent doSeqItem @@ -24,7 +24,7 @@ def doSeqBracketed := leading_parser "{" >> withoutPosition (many1 doSeqItem) >> def doSeq := withAntiquot (mkAntiquot "doSeq" `Lean.Parser.Term.doSeq (isPseudoKind := true)) <| doSeqBracketed <|> doSeqIndent def termBeforeDo := withForbidden "do" termParser -attribute [runBuiltinParserAttributeHooks] doSeq termBeforeDo +attribute [run_builtin_parser_attribute_hooks] doSeq termBeforeDo builtin_initialize register_parser_alias doSeq @@ -35,21 +35,21 @@ def notFollowedByRedefinedTermToken := -- "open" command following `do`-block. If we don't add `do`, then users would have to indent `do` blocks or use `{ ... }`. notFollowedBy ("set_option" <|> "open" <|> "if" <|> "match" <|> "let" <|> "have" <|> "do" <|> "dbg_trace" <|> "assert!" <|> "for" <|> "unless" <|> "return" <|> symbol "try") "token at 'do' element" -@[builtinDoElemParser] def doLet := leading_parser "let " >> optional "mut " >> letDecl -@[builtinDoElemParser] def doLetElse := leading_parser "let " >> optional "mut " >> termParser >> " := " >> termParser >> checkColGt >> " | " >> doElemParser +@[builtin_doElem_parser] def doLet := leading_parser "let " >> optional "mut " >> letDecl +@[builtin_doElem_parser] def doLetElse := leading_parser "let " >> optional "mut " >> termParser >> " := " >> termParser >> checkColGt >> " | " >> doElemParser -@[builtinDoElemParser] def doLetRec := leading_parser group ("let " >> nonReservedSymbol "rec ") >> letRecDecls +@[builtin_doElem_parser] def doLetRec := leading_parser group ("let " >> nonReservedSymbol "rec ") >> letRecDecls def doIdDecl := leading_parser atomic (ident >> optType >> ppSpace >> leftArrow) >> doElemParser def doPatDecl := leading_parser atomic (termParser >> ppSpace >> leftArrow) >> doElemParser >> optional (checkColGt >> " | " >> doElemParser) -@[builtinDoElemParser] def doLetArrow := leading_parser withPosition ("let " >> optional "mut " >> (doIdDecl <|> doPatDecl)) +@[builtin_doElem_parser] def doLetArrow := leading_parser withPosition ("let " >> optional "mut " >> (doIdDecl <|> doPatDecl)) -- We use `letIdDeclNoBinders` to define `doReassign`. -- Motivation: we do not reassign functions, and avoid parser conflict def letIdDeclNoBinders := node `Lean.Parser.Term.letIdDecl $ atomic (ident >> pushNone >> optType >> " := ") >> termParser -@[builtinDoElemParser] def doReassign := leading_parser notFollowedByRedefinedTermToken >> (letIdDeclNoBinders <|> letPatDecl) -@[builtinDoElemParser] def doReassignArrow := leading_parser notFollowedByRedefinedTermToken >> withPosition (doIdDecl <|> doPatDecl) -@[builtinDoElemParser] def doHave := leading_parser "have " >> Term.haveDecl +@[builtin_doElem_parser] def doReassign := leading_parser notFollowedByRedefinedTermToken >> (letIdDeclNoBinders <|> letPatDecl) +@[builtin_doElem_parser] def doReassignArrow := leading_parser notFollowedByRedefinedTermToken >> withPosition (doIdDecl <|> doPatDecl) +@[builtin_doElem_parser] def doHave := leading_parser "have " >> Term.haveDecl /- In `do` blocks, we support `if` without an `else`. Thus, we use indentation to prevent examples such as ``` @@ -86,11 +86,11 @@ def doIfLetBind := leading_parser " ← " >> termParser def doIfLet := leading_parser (withAnonymousAntiquot := false) "let " >> termParser >> (doIfLetPure <|> doIfLetBind) def doIfProp := leading_parser (withAnonymousAntiquot := false) optIdent >> termParser def doIfCond := withAntiquot (mkAntiquot "doIfCond" `Lean.Parser.Term.doIfCond (anonymous := false) (isPseudoKind := true)) <| doIfLet <|> doIfProp -@[builtinDoElemParser] def doIf := leading_parser withPositionAfterLinebreak $ +@[builtin_doElem_parser] def doIf := leading_parser withPositionAfterLinebreak $ "if " >> doIfCond >> " then " >> doSeq >> many (checkColGe "'else if' in 'do' must be indented" >> group (elseIf >> doIfCond >> " then " >> doSeq)) >> optional (checkColGe "'else' in 'do' must be indented" >> " else " >> doSeq) -@[builtinDoElemParser] def doUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq +@[builtin_doElem_parser] def doUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq def doForDecl := leading_parser optional (atomic (ident >> " : ")) >> termParser >> " in " >> withForbidden "do" termParser /-- `for x in e do s` iterates over `e` assuming `e`'s type has an instance of the `ForIn` typeclass. @@ -98,20 +98,20 @@ def doForDecl := leading_parser optional (atomic (ident >> " : ")) >> termParser `for x in e, x2 in e2, ... do s` iterates of the given collections in parallel, until at least one of them is exhausted. The types of `e2` etc. must implement the `ToStream` typeclass. -/ -@[builtinDoElemParser] def doFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq +@[builtin_doElem_parser] def doFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq def doMatchAlts := ppDedent <| matchAlts (rhsParser := doSeq) -@[builtinDoElemParser] def doMatch := leading_parser:leadPrec "match " >> optional Term.generalizingParam >> optional Term.motive >> sepBy1 matchDiscr ", " >> " with " >> doMatchAlts +@[builtin_doElem_parser] def doMatch := leading_parser:leadPrec "match " >> optional Term.generalizingParam >> optional Term.motive >> sepBy1 matchDiscr ", " >> " with " >> doMatchAlts def doCatch := leading_parser atomic ("catch " >> binderIdent) >> optional (" : " >> termParser) >> darrow >> doSeq def doCatchMatch := leading_parser "catch " >> doMatchAlts def doFinally := leading_parser "finally " >> doSeq -@[builtinDoElemParser] def doTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally +@[builtin_doElem_parser] def doTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally /-- `break` exits the surrounding `for` loop. -/ -@[builtinDoElemParser] def doBreak := leading_parser "break" +@[builtin_doElem_parser] def doBreak := leading_parser "break" /-- `continue` skips to the next iteration of the surrounding `for` loop. -/ -@[builtinDoElemParser] def doContinue := leading_parser "continue" +@[builtin_doElem_parser] def doContinue := leading_parser "continue" /-- `return e` inside of a `do` block makes the surrounding block evaluate to `pure e`, skipping any further statements. Note that uses of the `do` keyword in other syntax like in `for _ in _ do` do not constitute a surrounding block in this sense; @@ -119,9 +119,9 @@ in supported editors, the corresponding `do` keyword of the surrounding block is `return` not followed by a term starting on the same line is equivalent to `return ()`. -/ -@[builtinDoElemParser] def doReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser)) -@[builtinDoElemParser] def doDbgTrace := leading_parser:leadPrec "dbg_trace " >> ((interpolatedStr termParser) <|> termParser) -@[builtinDoElemParser] def doAssert := leading_parser:leadPrec "assert! " >> termParser +@[builtin_doElem_parser] def doReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser)) +@[builtin_doElem_parser] def doDbgTrace := leading_parser:leadPrec "dbg_trace " >> ((interpolatedStr termParser) <|> termParser) +@[builtin_doElem_parser] def doAssert := leading_parser:leadPrec "assert! " >> termParser /- We use `notFollowedBy` to avoid counterintuitive behavior. @@ -135,21 +135,21 @@ Consider the `doElem` `x := (a, b⟩` it contains an error since we are using ` However, `doExpr` would succeed consuming just `x`, and cryptic error message is generated after that. The second `notFollowedBy` prevents this problem. -/ -@[builtinDoElemParser] def doExpr := leading_parser notFollowedByRedefinedTermToken >> termParser >> notFollowedBy (symbol ":=" <|> symbol "←" <|> symbol "<-") "unexpected token after 'expr' in 'do' block" -@[builtinDoElemParser] def doNested := leading_parser "do " >> doSeq +@[builtin_doElem_parser] def doExpr := leading_parser notFollowedByRedefinedTermToken >> termParser >> notFollowedBy (symbol ":=" <|> symbol "←" <|> symbol "<-") "unexpected token after 'expr' in 'do' block" +@[builtin_doElem_parser] def doNested := leading_parser "do " >> doSeq -@[builtinTermParser] def «do» := leading_parser:argPrec ppAllowUngrouped >> "do " >> doSeq +@[builtin_term_parser] def «do» := leading_parser:argPrec ppAllowUngrouped >> "do " >> doSeq /- macros for using `unless`, `for`, `try`, `return` as terms. They expand into `do unless ...`, `do for ...`, `do try ...`, and `do return ...` -/ /-- `unless e do s` is a nicer way to write `if !e do s`. -/ -@[builtinTermParser] def termUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq -@[builtinTermParser] def termFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq -@[builtinTermParser] def termTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally +@[builtin_term_parser] def termUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq +@[builtin_term_parser] def termFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq +@[builtin_term_parser] def termTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally /-- `return` used outside of `do` blocks creates an implicit block around it and thus is equivalent to `pure e`, but helps with avoiding parentheses. -/ -@[builtinTermParser] def termReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser)) +@[builtin_term_parser] def termReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser)) end Term end Parser diff --git a/src/Lean/Parser/Extension.lean b/src/Lean/Parser/Extension.lean index 6d5611281e..a39aacb152 100644 --- a/src/Lean/Parser/Extension.lean +++ b/src/Lean/Parser/Extension.lean @@ -271,7 +271,7 @@ unsafe def mkParserOfConstantUnsafe (constName : Name) (compileParserDescr : Par pure ⟨false, p⟩ | _ => throw ↑s!"unexpected parser type at '{constName}' (`ParserDescr`, `TrailingParserDescr`, `Parser` or `TrailingParser` expected)" -@[implementedBy mkParserOfConstantUnsafe] +@[implemented_by mkParserOfConstantUnsafe] opaque mkParserOfConstantAux (constName : Name) (compileParserDescr : ParserDescr → ImportM Parser) : ImportM (Bool × Parser) partial def compileParserDescr (categories : ParserCategories) (d : ParserDescr) : ImportM Parser := @@ -368,7 +368,7 @@ unsafe def evalParserConstUnsafe (declName : Name) : ParserFn := fun ctx s => un return p.fn ctx s | .error e => return s.mkUnexpectedError e.toString -@[implementedBy evalParserConstUnsafe] +@[implemented_by evalParserConstUnsafe] opaque evalParserConst (declName : Name) : ParserFn register_builtin_option internal.parseQuotWithCurrentStage : Bool := { diff --git a/src/Lean/Parser/Extra.lean b/src/Lean/Parser/Extra.lean index 48efe40aa5..73a7805943 100644 --- a/src/Lean/Parser/Extra.lean +++ b/src/Lean/Parser/Extra.lean @@ -13,48 +13,48 @@ namespace Parser -- synthesize pretty printers for parsers declared prior to `Lean.PrettyPrinter` -- (because `Parser.Extension` depends on them) -attribute [runBuiltinParserAttributeHooks] +attribute [run_builtin_parser_attribute_hooks] leadingNode termParser commandParser mkAntiquot nodeWithAntiquot sepBy sepBy1 unicodeSymbol nonReservedSymbol -@[runBuiltinParserAttributeHooks] def optional (p : Parser) : Parser := +@[run_builtin_parser_attribute_hooks] def optional (p : Parser) : Parser := optionalNoAntiquot (withAntiquotSpliceAndSuffix `optional p (symbol "?")) -@[runBuiltinParserAttributeHooks] def many (p : Parser) : Parser := +@[run_builtin_parser_attribute_hooks] def many (p : Parser) : Parser := manyNoAntiquot (withAntiquotSpliceAndSuffix `many p (symbol "*")) -@[runBuiltinParserAttributeHooks] def many1 (p : Parser) : Parser := +@[run_builtin_parser_attribute_hooks] def many1 (p : Parser) : Parser := many1NoAntiquot (withAntiquotSpliceAndSuffix `many p (symbol "*")) -@[runBuiltinParserAttributeHooks] def ident : Parser := +@[run_builtin_parser_attribute_hooks] def ident : Parser := withAntiquot (mkAntiquot "ident" identKind) identNoAntiquot -- `ident` and `rawIdent` produce the same syntax tree, so we reuse the antiquotation kind name -@[runBuiltinParserAttributeHooks] def rawIdent : Parser := +@[run_builtin_parser_attribute_hooks] def rawIdent : Parser := withAntiquot (mkAntiquot "ident" identKind) rawIdentNoAntiquot -@[runBuiltinParserAttributeHooks] def numLit : Parser := +@[run_builtin_parser_attribute_hooks] def numLit : Parser := withAntiquot (mkAntiquot "num" numLitKind) numLitNoAntiquot -@[runBuiltinParserAttributeHooks] def scientificLit : Parser := +@[run_builtin_parser_attribute_hooks] def scientificLit : Parser := withAntiquot (mkAntiquot "scientific" scientificLitKind) scientificLitNoAntiquot -@[runBuiltinParserAttributeHooks] def strLit : Parser := +@[run_builtin_parser_attribute_hooks] def strLit : Parser := withAntiquot (mkAntiquot "str" strLitKind) strLitNoAntiquot -@[runBuiltinParserAttributeHooks] def charLit : Parser := +@[run_builtin_parser_attribute_hooks] def charLit : Parser := withAntiquot (mkAntiquot "char" charLitKind) charLitNoAntiquot -@[runBuiltinParserAttributeHooks] def nameLit : Parser := +@[run_builtin_parser_attribute_hooks] def nameLit : Parser := withAntiquot (mkAntiquot "name" nameLitKind) nameLitNoAntiquot -@[runBuiltinParserAttributeHooks, inline] def group (p : Parser) : Parser := +@[run_builtin_parser_attribute_hooks, inline] def group (p : Parser) : Parser := node groupKind p -@[runBuiltinParserAttributeHooks, inline] def many1Indent (p : Parser) : Parser := +@[run_builtin_parser_attribute_hooks, inline] def many1Indent (p : Parser) : Parser := withPosition $ many1 (checkColGe "irrelevant" >> p) -@[runBuiltinParserAttributeHooks, inline] def manyIndent (p : Parser) : Parser := +@[run_builtin_parser_attribute_hooks, inline] def manyIndent (p : Parser) : Parser := withPosition $ many (checkColGe "irrelevant" >> p) @[inline] def sepByIndent (p : Parser) (sep : String) (psep : Parser := symbol sep) (allowTrailingSep : Bool := false) : Parser := @@ -66,7 +66,7 @@ attribute [runBuiltinParserAttributeHooks] withPosition $ sepBy1 (checkColGe "irrelevant" >> p) sep (psep <|> checkColEq "irrelevant" >> checkLinebreakBefore >> pushNone) allowTrailingSep open PrettyPrinter Syntax.MonadTraverser Formatter in -@[combinatorFormatter Lean.Parser.sepByIndent] +@[combinator_formatter Lean.Parser.sepByIndent] def sepByIndent.formatter (p : Formatter) (_sep : String) (pSep : Formatter) : Formatter := do let stx ← getCur let hasNewlineSep := stx.getArgs.mapIdx (fun ⟨i, _⟩ n => i % 2 == 1 && n.matchesNull 0) |>.any id @@ -82,11 +82,11 @@ def sepByIndent.formatter (p : Formatter) (_sep : String) (pSep : Formatter) : F -- HACK: allow formatter to put initial brace on previous line in structure instances modify ({ · with mustBeGrouped := false }) -@[combinatorFormatter Lean.Parser.sepBy1Indent] def sepBy1Indent.formatter := sepByIndent.formatter +@[combinator_formatter Lean.Parser.sepBy1Indent] def sepBy1Indent.formatter := sepByIndent.formatter -attribute [runBuiltinParserAttributeHooks] sepByIndent sepBy1Indent +attribute [run_builtin_parser_attribute_hooks] sepByIndent sepBy1Indent -@[runBuiltinParserAttributeHooks] abbrev notSymbol (s : String) : Parser := +@[run_builtin_parser_attribute_hooks] abbrev notSymbol (s : String) : Parser := notFollowedBy (symbol s) s /-- No-op parser that advises the pretty printer to emit a non-breaking space. -/ @@ -139,24 +139,24 @@ end Parser section open PrettyPrinter -@[combinatorFormatter Lean.Parser.ppHardSpace] def ppHardSpace.formatter : Formatter := Formatter.pushWhitespace " " -@[combinatorFormatter Lean.Parser.ppSpace] def ppSpace.formatter : Formatter := Formatter.pushLine -@[combinatorFormatter Lean.Parser.ppLine] def ppLine.formatter : Formatter := Formatter.pushWhitespace "\n" -@[combinatorFormatter Lean.Parser.ppRealFill] def ppRealFill.formatter (p : Formatter) : Formatter := Formatter.fill p -@[combinatorFormatter Lean.Parser.ppRealGroup] def ppRealGroup.formatter (p : Formatter) : Formatter := Formatter.group p -@[combinatorFormatter Lean.Parser.ppIndent] def ppIndent.formatter (p : Formatter) : Formatter := Formatter.indent p -@[combinatorFormatter Lean.Parser.ppDedent] def ppDedent.formatter (p : Formatter) : Formatter := do +@[combinator_formatter Lean.Parser.ppHardSpace] def ppHardSpace.formatter : Formatter := Formatter.pushWhitespace " " +@[combinator_formatter Lean.Parser.ppSpace] def ppSpace.formatter : Formatter := Formatter.pushLine +@[combinator_formatter Lean.Parser.ppLine] def ppLine.formatter : Formatter := Formatter.pushWhitespace "\n" +@[combinator_formatter Lean.Parser.ppRealFill] def ppRealFill.formatter (p : Formatter) : Formatter := Formatter.fill p +@[combinator_formatter Lean.Parser.ppRealGroup] def ppRealGroup.formatter (p : Formatter) : Formatter := Formatter.group p +@[combinator_formatter Lean.Parser.ppIndent] def ppIndent.formatter (p : Formatter) : Formatter := Formatter.indent p +@[combinator_formatter Lean.Parser.ppDedent] def ppDedent.formatter (p : Formatter) : Formatter := do let opts ← getOptions Formatter.indent p (some ((0:Int) - Std.Format.getIndent opts)) -@[combinatorFormatter Lean.Parser.ppAllowUngrouped] def ppAllowUngrouped.formatter : Formatter := do +@[combinator_formatter Lean.Parser.ppAllowUngrouped] def ppAllowUngrouped.formatter : Formatter := do modify ({ · with mustBeGrouped := false }) -@[combinatorFormatter Lean.Parser.ppDedentIfGrouped] def ppDedentIfGrouped.formatter (p : Formatter) : Formatter := do +@[combinator_formatter Lean.Parser.ppDedentIfGrouped] def ppDedentIfGrouped.formatter (p : Formatter) : Formatter := do Formatter.concat p let indent := Std.Format.getIndent (← getOptions) unless (← get).isUngrouped do modify fun st => { st with stack := st.stack.modify (st.stack.size - 1) (·.nest (0 - indent)) } -@[combinatorFormatter Lean.Parser.ppHardLineUnlessUngrouped] def ppHardLineUnlessUngrouped.formatter : Formatter := do +@[combinator_formatter Lean.Parser.ppHardLineUnlessUngrouped] def ppHardLineUnlessUngrouped.formatter : Formatter := do if (← get).isUngrouped then Formatter.pushLine else @@ -167,7 +167,7 @@ end namespace Parser -- now synthesize parenthesizers -attribute [runBuiltinParserAttributeHooks] +attribute [run_builtin_parser_attribute_hooks] ppHardSpace ppSpace ppLine ppGroup ppRealGroup ppRealFill ppIndent ppDedent ppAllowUngrouped ppDedentIfGrouped ppHardLineUnlessUngrouped diff --git a/src/Lean/Parser/Level.lean b/src/Lean/Parser/Level.lean index f2e93bc836..5a407c9d7c 100644 --- a/src/Lean/Parser/Level.lean +++ b/src/Lean/Parser/Level.lean @@ -16,13 +16,13 @@ builtin_initialize namespace Level -@[builtinLevelParser] def paren := leading_parser "(" >> levelParser >> ")" -@[builtinLevelParser] def max := leading_parser nonReservedSymbol "max" true >> many1 (ppSpace >> levelParser maxPrec) -@[builtinLevelParser] def imax := leading_parser nonReservedSymbol "imax" true >> many1 (ppSpace >> levelParser maxPrec) -@[builtinLevelParser] def hole := leading_parser "_" -@[builtinLevelParser] def num := checkPrec maxPrec >> numLit -@[builtinLevelParser] def ident := checkPrec maxPrec >> Parser.ident -@[builtinLevelParser] def addLit := trailing_parser:65 " + " >> numLit +@[builtin_level_parser] def paren := leading_parser "(" >> levelParser >> ")" +@[builtin_level_parser] def max := leading_parser nonReservedSymbol "max" true >> many1 (ppSpace >> levelParser maxPrec) +@[builtin_level_parser] def imax := leading_parser nonReservedSymbol "imax" true >> many1 (ppSpace >> levelParser maxPrec) +@[builtin_level_parser] def hole := leading_parser "_" +@[builtin_level_parser] def num := checkPrec maxPrec >> numLit +@[builtin_level_parser] def ident := checkPrec maxPrec >> Parser.ident +@[builtin_level_parser] def addLit := trailing_parser:65 " + " >> numLit end Level diff --git a/src/Lean/Parser/Module.lean b/src/Lean/Parser/Module.lean index c9cfdd2c4d..c02219d85b 100644 --- a/src/Lean/Parser/Module.lean +++ b/src/Lean/Parser/Module.lean @@ -17,7 +17,7 @@ def header := leading_parser optional («prelude» >> ppLine) >> many («imp Parser for a Lean module. We never actually run this parser but instead use the imperative definitions below that return the same syntax tree structure, but add error recovery. Still, it is helpful to have a `Parser` definition for it in order to auto-generate helpers such as the pretty printer. -/ -@[runBuiltinParserAttributeHooks] +@[run_builtin_parser_attribute_hooks] def module := leading_parser header >> many (commandParser >> ppLine >> ppLine) def updateTokens (c : ParserContext) : ParserContext := diff --git a/src/Lean/Parser/Syntax.lean b/src/Lean/Parser/Syntax.lean index e5a96fc3f5..298decf4ef 100644 --- a/src/Lean/Parser/Syntax.lean +++ b/src/Lean/Parser/Syntax.lean @@ -26,16 +26,16 @@ def «precedence» := leading_parser ":" >> precedenceParser maxPrec def optPrecedence := optional (atomic «precedence») namespace Syntax -@[builtinPrecParser] def numPrec := checkPrec maxPrec >> numLit +@[builtin_prec_parser] def numPrec := checkPrec maxPrec >> numLit -@[builtinSyntaxParser] def paren := leading_parser "(" >> many1 syntaxParser >> ")" -@[builtinSyntaxParser] def cat := leading_parser ident >> optPrecedence -@[builtinSyntaxParser] def unary := leading_parser ident >> checkNoWsBefore >> "(" >> many1 syntaxParser >> ")" -@[builtinSyntaxParser] def binary := leading_parser ident >> checkNoWsBefore >> "(" >> many1 syntaxParser >> ", " >> many1 syntaxParser >> ")" -@[builtinSyntaxParser] def sepBy := leading_parser "sepBy(" >> many1 syntaxParser >> ", " >> strLit >> optional (", " >> many1 syntaxParser) >> optional (", " >> nonReservedSymbol "allowTrailingSep") >> ")" -@[builtinSyntaxParser] def sepBy1 := leading_parser "sepBy1(" >> many1 syntaxParser >> ", " >> strLit >> optional (", " >> many1 syntaxParser) >> optional (", " >> nonReservedSymbol "allowTrailingSep") >> ")" -@[builtinSyntaxParser] def atom := leading_parser strLit -@[builtinSyntaxParser] def nonReserved := leading_parser "&" >> strLit +@[builtin_syntax_parser] def paren := leading_parser "(" >> many1 syntaxParser >> ")" +@[builtin_syntax_parser] def cat := leading_parser ident >> optPrecedence +@[builtin_syntax_parser] def unary := leading_parser ident >> checkNoWsBefore >> "(" >> many1 syntaxParser >> ")" +@[builtin_syntax_parser] def binary := leading_parser ident >> checkNoWsBefore >> "(" >> many1 syntaxParser >> ", " >> many1 syntaxParser >> ")" +@[builtin_syntax_parser] def sepBy := leading_parser "sepBy(" >> many1 syntaxParser >> ", " >> strLit >> optional (", " >> many1 syntaxParser) >> optional (", " >> nonReservedSymbol "allowTrailingSep") >> ")" +@[builtin_syntax_parser] def sepBy1 := leading_parser "sepBy1(" >> many1 syntaxParser >> ", " >> strLit >> optional (", " >> many1 syntaxParser) >> optional (", " >> nonReservedSymbol "allowTrailingSep") >> ")" +@[builtin_syntax_parser] def atom := leading_parser strLit +@[builtin_syntax_parser] def nonReserved := leading_parser "&" >> strLit end Syntax @@ -50,7 +50,7 @@ def «infixl» := leading_parser "infixl" def «infixr» := leading_parser "infixr" def «postfix» := leading_parser "postfix" def mixfixKind := «prefix» <|> «infix» <|> «infixl» <|> «infixr» <|> «postfix» -@[builtinCommandParser] def «mixfix» := leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> mixfixKind >> precedence >> optNamedName >> optNamedPrio >> ppSpace >> strLit >> darrow >> termParser +@[builtin_command_parser] def «mixfix» := leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> mixfixKind >> precedence >> optNamedName >> optNamedPrio >> ppSpace >> strLit >> darrow >> termParser -- NOTE: We use `suppressInsideQuot` in the following parsers because quotations inside them are evaluated in the same stage and -- thus should be ignored when we use `checkInsideQuot` to prepare the next stage for a builtin syntax change def identPrec := leading_parser ident >> optPrecedence @@ -58,23 +58,23 @@ def identPrec := leading_parser ident >> optPrecedence def optKind : Parser := optional ("(" >> nonReservedSymbol "kind" >> ":=" >> ident >> ")") def notationItem := ppSpace >> withAntiquot (mkAntiquot "notationItem" `Lean.Parser.Command.notationItem) (strLit <|> identPrec) -@[builtinCommandParser] def «notation» := leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> "notation" >> optPrecedence >> optNamedName >> optNamedPrio >> many notationItem >> darrow >> termParser -@[builtinCommandParser] def «macro_rules» := suppressInsideQuot (leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> "macro_rules" >> optKind >> Term.matchAlts) -@[builtinCommandParser] def «syntax» := leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> "syntax " >> optPrecedence >> optNamedName >> optNamedPrio >> many1 (syntaxParser argPrec) >> " : " >> ident -@[builtinCommandParser] def syntaxAbbrev := leading_parser optional docComment >> "syntax " >> ident >> " := " >> many1 syntaxParser +@[builtin_command_parser] def «notation» := leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> "notation" >> optPrecedence >> optNamedName >> optNamedPrio >> many notationItem >> darrow >> termParser +@[builtin_command_parser] def «macro_rules» := suppressInsideQuot (leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> "macro_rules" >> optKind >> Term.matchAlts) +@[builtin_command_parser] def «syntax» := leading_parser optional docComment >> optional Term.«attributes» >> Term.attrKind >> "syntax " >> optPrecedence >> optNamedName >> optNamedPrio >> many1 (syntaxParser argPrec) >> " : " >> ident +@[builtin_command_parser] def syntaxAbbrev := leading_parser optional docComment >> "syntax " >> ident >> " := " >> many1 syntaxParser def catBehaviorBoth := leading_parser nonReservedSymbol "both" def catBehaviorSymbol := leading_parser nonReservedSymbol "symbol" def catBehavior := optional ("(" >> nonReservedSymbol "behavior" >> " := " >> (catBehaviorBoth <|> catBehaviorSymbol) >> ")") -@[builtinCommandParser] def syntaxCat := leading_parser optional docComment >> "declare_syntax_cat " >> ident >> catBehavior +@[builtin_command_parser] def syntaxCat := leading_parser optional docComment >> "declare_syntax_cat " >> ident >> catBehavior def macroArg := leading_parser optional (atomic (ident >> checkNoWsBefore "no space before ':'" >> ":")) >> syntaxParser argPrec def macroRhs : Parser := leading_parser withPosition termParser def macroTail := leading_parser atomic (" : " >> ident) >> darrow >> macroRhs -@[builtinCommandParser] def «macro» := leading_parser suppressInsideQuot (optional docComment >> optional Term.«attributes» >> Term.attrKind >> "macro " >> optPrecedence >> optNamedName >> optNamedPrio >> many1 macroArg >> macroTail) +@[builtin_command_parser] def «macro» := leading_parser suppressInsideQuot (optional docComment >> optional Term.«attributes» >> Term.attrKind >> "macro " >> optPrecedence >> optNamedName >> optNamedPrio >> many1 macroArg >> macroTail) -@[builtinCommandParser] def «elab_rules» := leading_parser suppressInsideQuot (optional docComment >> optional Term.«attributes» >> Term.attrKind >> "elab_rules" >> optKind >> optional (" : " >> ident) >> optional (" <= " >> ident) >> Term.matchAlts) +@[builtin_command_parser] def «elab_rules» := leading_parser suppressInsideQuot (optional docComment >> optional Term.«attributes» >> Term.attrKind >> "elab_rules" >> optKind >> optional (" : " >> ident) >> optional (" <= " >> ident) >> Term.matchAlts) def elabArg := macroArg def elabTail := leading_parser atomic (" : " >> ident >> optional (" <= " >> ident)) >> darrow >> withPosition termParser -@[builtinCommandParser] def «elab» := leading_parser suppressInsideQuot (optional docComment >> optional Term.«attributes» >> Term.attrKind >> "elab " >> optPrecedence >> optNamedName >> optNamedPrio >> many1 elabArg >> elabTail) +@[builtin_command_parser] def «elab» := leading_parser suppressInsideQuot (optional docComment >> optional Term.«attributes» >> Term.attrKind >> "elab " >> optPrecedence >> optNamedName >> optNamedPrio >> many1 elabArg >> elabTail) end Command diff --git a/src/Lean/Parser/Tactic.lean b/src/Lean/Parser/Tactic.lean index 12f023a47e..5caec48375 100644 --- a/src/Lean/Parser/Tactic.lean +++ b/src/Lean/Parser/Tactic.lean @@ -18,9 +18,9 @@ to improve syntax error messages. example : True := by foo -- unknown tactic ``` -/ -@[builtinTacticParser] def «unknown» := leading_parser withPosition (ident >> errorAtSavedPos "unknown tactic" true) +@[builtin_tactic_parser] def «unknown» := leading_parser withPosition (ident >> errorAtSavedPos "unknown tactic" true) -@[builtinTacticParser] def nestedTactic := tacticSeqBracketed +@[builtin_tactic_parser] def nestedTactic := tacticSeqBracketed def matchRhs := Term.hole <|> Term.syntheticHole <|> tacticSeq def matchAlts := Term.matchAlts (rhsParser := matchRhs) @@ -38,7 +38,7 @@ example (n : Nat) : n = n := by [tpil4]: https://leanprover.github.io/theorem_proving_in_lean4/induction_and_recursion.html -/ -@[builtinTacticParser] def «match» := leading_parser:leadPrec "match " >> optional Term.generalizingParam >> optional Term.motive >> sepBy1 Term.matchDiscr ", " >> " with " >> ppDedent matchAlts +@[builtin_tactic_parser] def «match» := leading_parser:leadPrec "match " >> optional Term.generalizingParam >> optional Term.motive >> sepBy1 Term.matchDiscr ", " >> " with " >> ppDedent matchAlts /-- The tactic @@ -57,7 +57,7 @@ match x with That is, `intro` can be followed by match arms and it introduces the values while doing a pattern match. This is equivalent to `fun` with match arms in term mode. -/ -@[builtinTacticParser] def introMatch := leading_parser nonReservedSymbol "intro " >> matchAlts +@[builtin_tactic_parser] def introMatch := leading_parser nonReservedSymbol "intro " >> matchAlts /-- `decide` will attempt to prove a goal of type `p` by synthesizing an instance of `Decidable p` and then evaluating it to `isTrue ..`. Because this uses kernel @@ -67,7 +67,7 @@ by well founded recursion, since this requires reducing proofs. example : 2 + 2 ≠ 5 := by decide ``` -/ -@[builtinTacticParser] def decide := leading_parser nonReservedSymbol "decide" +@[builtin_tactic_parser] def decide := leading_parser nonReservedSymbol "decide" /-- `native_decide` will attempt to prove a goal of type `p` by synthesizing an instance of `Decidable p` and then evaluating it to `isTrue ..`. Unlike `decide`, this @@ -82,7 +82,7 @@ large computations this is one way to run external programs and trust the result example : (List.range 1000).length = 1000 := by native_decide ``` -/ -@[builtinTacticParser] def nativeDecide := leading_parser nonReservedSymbol "native_decide" +@[builtin_tactic_parser] def nativeDecide := leading_parser nonReservedSymbol "native_decide" end Tactic end Parser diff --git a/src/Lean/Parser/Term.lean b/src/Lean/Parser/Term.lean index 8e138893c4..a097c0d6e3 100644 --- a/src/Lean/Parser/Term.lean +++ b/src/Lean/Parser/Term.lean @@ -13,8 +13,8 @@ namespace Command def commentBody : Parser := { fn := rawFn (finishCommentBlock 1) (trailingWs := true) } -@[combinatorParenthesizer Lean.Parser.Command.commentBody] def commentBody.parenthesizer := PrettyPrinter.Parenthesizer.visitToken -@[combinatorFormatter Lean.Parser.Command.commentBody] def commentBody.formatter := PrettyPrinter.Formatter.visitAtom Name.anonymous +@[combinator_parenthesizer Lean.Parser.Command.commentBody] def commentBody.parenthesizer := PrettyPrinter.Parenthesizer.visitToken +@[combinator_formatter Lean.Parser.Command.commentBody] def commentBody.formatter := PrettyPrinter.Formatter.visitAtom Name.anonymous def docComment := leading_parser ppDedent $ "/--" >> ppSpace >> commentBody >> ppLine end Command @@ -31,11 +31,11 @@ builtin_initialize namespace Tactic -@[runBuiltinParserAttributeHooks] +@[run_builtin_parser_attribute_hooks] def sepByIndentSemicolon (p : Parser) : Parser := sepByIndent p "; " (allowTrailingSep := true) -@[runBuiltinParserAttributeHooks] +@[run_builtin_parser_attribute_hooks] def sepBy1IndentSemicolon (p : Parser) : Parser := sepBy1Indent p "; " (allowTrailingSep := true) @@ -66,7 +66,7 @@ namespace Term /-! # Built-in parsers -/ /-- `by tac` constructs a term of the expected type by running the tactic(s) `tac`. -/ -@[builtinTermParser] def byTactic := leading_parser:leadPrec ppAllowUngrouped >> "by " >> Tactic.tacticSeq +@[builtin_term_parser] def byTactic := leading_parser:leadPrec ppAllowUngrouped >> "by " >> Tactic.tacticSeq /- This is the same as `byTactic`, but it uses a different syntax kind. This is @@ -80,27 +80,27 @@ def byTactic' := leading_parser "by " >> Tactic.tacticSeq def optSemicolon (p : Parser) : Parser := ppDedent $ semicolonOrLinebreak >> ppLine >> p -- `checkPrec` necessary for the pretty printer -@[builtinTermParser] def ident := checkPrec maxPrec >> Parser.ident -@[builtinTermParser] def num : Parser := checkPrec maxPrec >> numLit -@[builtinTermParser] def scientific : Parser := checkPrec maxPrec >> scientificLit -@[builtinTermParser] def str : Parser := checkPrec maxPrec >> strLit -@[builtinTermParser] def char : Parser := checkPrec maxPrec >> charLit +@[builtin_term_parser] def ident := checkPrec maxPrec >> Parser.ident +@[builtin_term_parser] def num : Parser := checkPrec maxPrec >> numLit +@[builtin_term_parser] def scientific : Parser := checkPrec maxPrec >> scientificLit +@[builtin_term_parser] def str : Parser := checkPrec maxPrec >> strLit +@[builtin_term_parser] def char : Parser := checkPrec maxPrec >> charLit /-- A type universe. `Type ≡ Type 0`, `Type u ≡ Sort (u + 1)`. -/ -@[builtinTermParser] def type := leading_parser "Type" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) +@[builtin_term_parser] def type := leading_parser "Type" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) /-- A specific universe in Lean's infinite hierarchy of universes. -/ -@[builtinTermParser] def sort := leading_parser "Sort" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) +@[builtin_term_parser] def sort := leading_parser "Sort" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) /-- The universe of propositions. `Prop ≡ Sort 0`. -/ -@[builtinTermParser] def prop := leading_parser "Prop" +@[builtin_term_parser] def prop := leading_parser "Prop" /-- A placeholder term, to be synthesized by unification. -/ -@[builtinTermParser] def hole := leading_parser "_" -@[builtinTermParser] def syntheticHole := leading_parser "?" >> (ident <|> hole) +@[builtin_term_parser] def hole := leading_parser "_" +@[builtin_term_parser] def syntheticHole := leading_parser "?" >> (ident <|> hole) /-- A temporary placeholder for a missing proof or value. -/ -@[builtinTermParser] def «sorry» := leading_parser "sorry" +@[builtin_term_parser] def «sorry» := leading_parser "sorry" /-- A placeholder for an implicit lambda abstraction's variable. The lambda abstraction is scoped to the surrounding parentheses. For example, `(· + ·)` is equivalent to `fun x y => x + y`. -/ -@[builtinTermParser] def cdot := leading_parser symbol "·" <|> "." +@[builtin_term_parser] def cdot := leading_parser symbol "·" <|> "." def typeAscription := leading_parser " : " >> termParser def tupleTail := leading_parser ", " >> sepBy1 termParser ", " def parenSpecial : Parser := optional (tupleTail <|> typeAscription) @@ -116,7 +116,7 @@ Parentheses, used for - `(f · a b)` is shorthand for `fun x => f x a b` - `(h (· + 1) ·)` is shorthand for `fun x => h (fun y => y + 1) x` -/ -@[builtinTermParser] def paren := leading_parser "(" >> (withoutPosition (withoutForbidden (optional (ppDedentIfGrouped termParser >> parenSpecial)))) >> ")" +@[builtin_term_parser] def paren := leading_parser "(" >> (withoutPosition (withoutForbidden (optional (ppDedentIfGrouped termParser >> parenSpecial)))) >> ")" /-- The *anonymous constructor* `⟨e, ...⟩` is equivalent to `c e ...` if the expected type is an inductive type with a single constructor `c`. @@ -124,13 +124,13 @@ If more terms are given than `c` has parameters, the remaining arguments are turned into a new anonymous constructor application. For example, `⟨a, b, c⟩ : α × (β × γ)` is equivalent to `⟨a, ⟨b, c⟩⟩`. -/ -@[builtinTermParser] def anonymousCtor := leading_parser "⟨" >> sepBy termParser ", " >> "⟩" +@[builtin_term_parser] def anonymousCtor := leading_parser "⟨" >> sepBy termParser ", " >> "⟩" def optIdent : Parser := optional (atomic (ident >> " : ")) def fromTerm := leading_parser "from " >> termParser def showRhs := fromTerm <|> byTactic' def sufficesDecl := leading_parser optIdent >> termParser >> ppSpace >> showRhs -@[builtinTermParser] def «suffices» := leading_parser:leadPrec withPosition ("suffices " >> sufficesDecl) >> optSemicolon termParser -@[builtinTermParser] def «show» := leading_parser:leadPrec "show " >> termParser >> ppSpace >> showRhs +@[builtin_term_parser] def «suffices» := leading_parser:leadPrec withPosition ("suffices " >> sufficesDecl) >> optSemicolon termParser +@[builtin_term_parser] def «show» := leading_parser:leadPrec "show " >> termParser >> ppSpace >> showRhs def structInstArrayRef := leading_parser "[" >> termParser >>"]" def structInstLVal := leading_parser (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef) def structInstField := ppGroup $ leading_parser structInstLVal >> " := " >> termParser @@ -145,7 +145,7 @@ A *structure update* of an existing value can be given via `with`: The structure type can be specified if not inferable: `{ x := 1, y := 2 : Point }`. -/ -@[builtinTermParser] def structInst := leading_parser "{" >> ppHardSpace >> optional (atomic (sepBy1 termParser ", " >> " with ")) +@[builtin_term_parser] def structInst := leading_parser "{" >> ppHardSpace >> optional (atomic (sepBy1 termParser ", " >> " with ")) >> sepByIndent (structInstFieldAbbrev <|> structInstField) ", " (allowTrailingSep := true) >> optEllipsis >> optional (" : " >> termParser) >> " }" @@ -155,12 +155,12 @@ def optType : Parser := optional typeSpec `@x` disables automatic insertion of implicit parameters of the constant `x`. `@e` for any term `e` also disables the insertion of implicit lambdas at this position. -/ -@[builtinTermParser] def explicit := leading_parser "@" >> termParser maxPrec +@[builtin_term_parser] def explicit := leading_parser "@" >> termParser maxPrec /-- `.(e)` marks an "inaccessible pattern", which does not influence evaluation of the pattern match, but may be necessary for type-checking. In contrast to regular patterns, `e` may be an arbitrary term of the appropriate type. -/ -@[builtinTermParser] def inaccessible := leading_parser ".(" >> termParser >> ")" +@[builtin_term_parser] def inaccessible := leading_parser ".(" >> termParser >> ")" def binderIdent : Parser := ident <|> hole def binderType (requireType := false) : Parser := if requireType then node nullKind (" : " >> termParser) else optional (" : " >> termParser) def binderTactic := leading_parser atomic (symbol " := " >> " by ") >> Tactic.tacticSeq @@ -186,15 +186,15 @@ def implicitShortBinder := node `Lean.Parser.Term.implicitBinder $ "{" >> many1 def depArrowShortPrefix := try (implicitShortBinder >> unicodeSymbol " → " " -> ") def depArrowLongPrefix := bracketedBinder true >> unicodeSymbol " → " " -> " def depArrowPrefix := depArrowShortPrefix <|> depArrowLongPrefix -@[builtinTermParser] def depArrow := leading_parser depArrowPrefix >> termParser +@[builtin_term_parser] def depArrow := leading_parser depArrowPrefix >> termParser ``` Note that no changes in the elaborator are needed. We decided to not use it because terms such as `{α} → α → α` may look too cryptic. Note that we did not add a `explicitShortBinder` parser since `(α) → α → α` is really cryptic as a short for `(α : Type) → α → α`. -/ -@[builtinTermParser] def depArrow := leading_parser:25 bracketedBinder true >> unicodeSymbol " → " " -> " >> termParser +@[builtin_term_parser] def depArrow := leading_parser:25 bracketedBinder true >> unicodeSymbol " → " " -> " >> termParser -@[builtinTermParser] +@[builtin_term_parser] def «forall» := leading_parser:leadPrec unicodeSymbol "∀" "forall" >> many1 (ppSpace >> (binderIdent <|> bracketedBinder)) >> optType >> ", " >> termParser def matchAlt (rhsParser : Parser := termParser) : Parser := @@ -249,36 +249,36 @@ syntax "c" (foo <|> "bar") ... ``` they are not. -/ -@[builtinTermParser] def «match» := leading_parser:leadPrec "match " >> optional generalizingParam >> optional motive >> sepBy1 matchDiscr ", " >> " with " >> ppDedent matchAlts +@[builtin_term_parser] def «match» := leading_parser:leadPrec "match " >> optional generalizingParam >> optional motive >> sepBy1 matchDiscr ", " >> " with " >> ppDedent matchAlts /-- Empty match/ex falso. `nomatch e` is of arbitrary type `α : Sort u` if Lean can show that an empty set of patterns is exhaustive given `e`'s type, e.g. because it has no constructors. -/ -@[builtinTermParser] def «nomatch» := leading_parser:leadPrec "nomatch " >> termParser +@[builtin_term_parser] def «nomatch» := leading_parser:leadPrec "nomatch " >> termParser def funImplicitBinder := withAntiquot (mkAntiquot "implicitBinder" ``implicitBinder) <| atomic (lookahead ("{" >> many1 binderIdent >> (symbol " : " <|> "}"))) >> implicitBinder def funStrictImplicitBinder := atomic (lookahead (strictImplicitLeftBracket >> many1 binderIdent >> (symbol " : " <|> strictImplicitRightBracket))) >> strictImplicitBinder def funBinder : Parser := withAntiquot (mkAntiquot "funBinder" `Lean.Parser.Term.funBinder (isPseudoKind := true)) (funStrictImplicitBinder <|> funImplicitBinder <|> instBinder <|> termParser maxPrec) -- NOTE: we disable anonymous antiquotations to ensure that `fun $b => ...` remains a `term` antiquotation def basicFun : Parser := leading_parser (withAnonymousAntiquot := false) ppGroup (many1 (ppSpace >> funBinder) >> optType >> " =>") >> ppSpace >> termParser -@[builtinTermParser] def «fun» := leading_parser:maxPrec ppAllowUngrouped >> unicodeSymbol "λ" "fun" >> (basicFun <|> matchAlts) +@[builtin_term_parser] def «fun» := leading_parser:maxPrec ppAllowUngrouped >> unicodeSymbol "λ" "fun" >> (basicFun <|> matchAlts) def optExprPrecedence := optional (atomic ":" >> termParser maxPrec) def withAnonymousAntiquot := leading_parser atomic ("(" >> nonReservedSymbol "withAnonymousAntiquot" >> " := ") >> (trueVal <|> falseVal) >> ")" >> ppSpace -@[builtinTermParser] def «leading_parser» := leading_parser:leadPrec "leading_parser " >> optExprPrecedence >> optional withAnonymousAntiquot >> termParser -@[builtinTermParser] def «trailing_parser» := leading_parser:leadPrec "trailing_parser " >> optExprPrecedence >> optExprPrecedence >> termParser +@[builtin_term_parser] def «leading_parser» := leading_parser:leadPrec "leading_parser " >> optExprPrecedence >> optional withAnonymousAntiquot >> termParser +@[builtin_term_parser] def «trailing_parser» := leading_parser:leadPrec "trailing_parser " >> optExprPrecedence >> optExprPrecedence >> termParser -@[builtinTermParser] def borrowed := leading_parser "@& " >> termParser leadPrec +@[builtin_term_parser] def borrowed := leading_parser "@& " >> termParser leadPrec /-- A literal of type `Name`. -/ -@[builtinTermParser] def quotedName := leading_parser nameLit +@[builtin_term_parser] def quotedName := leading_parser nameLit /-- A resolved name literal. Evaluates to the full name of the given constant if existent in the current context, or else fails. -/ -- use `rawCh` because ``"`" >> ident`` overlaps with `nameLit`, with the latter being preferred by the tokenizer -- note that we cannot use ```"``"``` as a new token either because it would break `precheckedQuot` -@[builtinTermParser] def doubleQuotedName := leading_parser "`" >> checkNoWsBefore >> rawCh '`' (trailingWs := false) >> ident +@[builtin_term_parser] def doubleQuotedName := leading_parser "`" >> checkNoWsBefore >> rawCh '`' (trailingWs := false) >> ident def letIdBinder := withAntiquot (mkAntiquot "letIdBinder" `Lean.Parser.Term.letIdBinder (isPseudoKind := true)) (binderIdent <|> bracketedBinder) /- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/ @@ -319,28 +319,28 @@ let (x, y) := p x + y ``` -/ -@[builtinTermParser] def «let» := leading_parser:leadPrec withPosition ("let " >> letDecl) >> optSemicolon termParser +@[builtin_term_parser] def «let» := leading_parser:leadPrec withPosition ("let " >> letDecl) >> optSemicolon termParser /-- `let_fun x := v; b` is syntax sugar for `(fun x => b) v`. It is very similar to `let x := v; b`, but they are not equivalent. In `let_fun`, the value `v` has been abstracted away and cannot be accessed in `b`. -/ -@[builtinTermParser] def «let_fun» := leading_parser:leadPrec withPosition ((symbol "let_fun " <|> "let_λ") >> letDecl) >> optSemicolon termParser +@[builtin_term_parser] def «let_fun» := leading_parser:leadPrec withPosition ((symbol "let_fun " <|> "let_λ") >> letDecl) >> optSemicolon termParser /-- `let_delayed x := v; b` is similar to `let x := v; b`, but `b` is elaborated before `v`. -/ -@[builtinTermParser] def «let_delayed» := leading_parser:leadPrec withPosition ("let_delayed " >> letDecl) >> optSemicolon termParser +@[builtin_term_parser] def «let_delayed» := leading_parser:leadPrec withPosition ("let_delayed " >> letDecl) >> optSemicolon termParser /-- `let`-declaration that is only included in the elaborated term if variable is still there. It is often used when building macros. -/ -@[builtinTermParser] def «let_tmp» := leading_parser:leadPrec withPosition ("let_tmp " >> letDecl) >> optSemicolon termParser +@[builtin_term_parser] def «let_tmp» := leading_parser:leadPrec withPosition ("let_tmp " >> letDecl) >> optSemicolon termParser /- like `let_fun` but with optional name -/ def haveIdLhs := optional (ident >> many (ppSpace >> letIdBinder)) >> optType def haveIdDecl := leading_parser (withAnonymousAntiquot := false) atomic (haveIdLhs >> " := ") >> termParser def haveEqnsDecl := leading_parser (withAnonymousAntiquot := false) haveIdLhs >> matchAlts def haveDecl := leading_parser (withAnonymousAntiquot := false) haveIdDecl <|> letPatDecl <|> haveEqnsDecl -@[builtinTermParser] def «have» := leading_parser:leadPrec withPosition ("have " >> haveDecl) >> optSemicolon termParser +@[builtin_term_parser] def «have» := leading_parser:leadPrec withPosition ("have " >> haveDecl) >> optSemicolon termParser def «scoped» := leading_parser "scoped " def «local» := leading_parser "local " @@ -350,58 +350,58 @@ def attrInstance := ppGroup $ leading_parser attrKind >> attrParser def attributes := leading_parser "@[" >> sepBy1 attrInstance ", " >> "]" def letRecDecl := leading_parser optional Command.docComment >> optional «attributes» >> letDecl def letRecDecls := leading_parser sepBy1 letRecDecl ", " -@[builtinTermParser] +@[builtin_term_parser] def «letrec» := leading_parser:leadPrec withPosition (group ("let " >> nonReservedSymbol "rec ") >> letRecDecls) >> optSemicolon termParser -@[runBuiltinParserAttributeHooks] +@[run_builtin_parser_attribute_hooks] def whereDecls := leading_parser " where" >> sepBy1Indent (ppGroup letRecDecl) "; " (allowTrailingSep := true) -@[runBuiltinParserAttributeHooks] +@[run_builtin_parser_attribute_hooks] def matchAltsWhereDecls := leading_parser matchAlts >> optional whereDecls -@[builtinTermParser] def noindex := leading_parser "no_index " >> termParser maxPrec +@[builtin_term_parser] def noindex := leading_parser "no_index " >> termParser maxPrec -@[builtinTermParser] def binrel := leading_parser "binrel% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec +@[builtin_term_parser] def binrel := leading_parser "binrel% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec /-- Similar to `binrel`, but coerce `Prop` arguments into `Bool`. -/ -@[builtinTermParser] def binrel_no_prop := leading_parser "binrel_no_prop% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec -@[builtinTermParser] def binop := leading_parser "binop% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec -@[builtinTermParser] def binop_lazy := leading_parser "binop_lazy% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec +@[builtin_term_parser] def binrel_no_prop := leading_parser "binrel_no_prop% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec +@[builtin_term_parser] def binop := leading_parser "binop% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec +@[builtin_term_parser] def binop_lazy := leading_parser "binop_lazy% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec -@[builtinTermParser] def forInMacro := leading_parser "for_in% " >> termParser maxPrec >> termParser maxPrec >> termParser maxPrec -@[builtinTermParser] def forInMacro' := leading_parser "for_in'% " >> termParser maxPrec >> termParser maxPrec >> termParser maxPrec +@[builtin_term_parser] def forInMacro := leading_parser "for_in% " >> termParser maxPrec >> termParser maxPrec >> termParser maxPrec +@[builtin_term_parser] def forInMacro' := leading_parser "for_in'% " >> termParser maxPrec >> termParser maxPrec >> termParser maxPrec /-- A macro which evaluates to the name of the currently elaborating declaration. -/ -@[builtinTermParser] def declName := leading_parser "decl_name%" +@[builtin_term_parser] def declName := leading_parser "decl_name%" /-- * `with_decl_name% id e` elaborates `e` in a context while changing the effective declaration name to `id`. * `with_decl_name% ?id e` does the same, but resolves `id` as a new definition name (appending the current namespaces). -/ -@[builtinTermParser] def withDeclName := leading_parser "with_decl_name% " >> optional "?" >> ident >> termParser -@[builtinTermParser] def typeOf := leading_parser "type_of% " >> termParser maxPrec -@[builtinTermParser] def ensureTypeOf := leading_parser "ensure_type_of% " >> termParser maxPrec >> strLit >> termParser -@[builtinTermParser] def ensureExpectedType := leading_parser "ensure_expected_type% " >> strLit >> termParser maxPrec -@[builtinTermParser] def noImplicitLambda := leading_parser "no_implicit_lambda% " >> termParser maxPrec +@[builtin_term_parser] def withDeclName := leading_parser "with_decl_name% " >> optional "?" >> ident >> termParser +@[builtin_term_parser] def typeOf := leading_parser "type_of% " >> termParser maxPrec +@[builtin_term_parser] def ensureTypeOf := leading_parser "ensure_type_of% " >> termParser maxPrec >> strLit >> termParser +@[builtin_term_parser] def ensureExpectedType := leading_parser "ensure_expected_type% " >> strLit >> termParser maxPrec +@[builtin_term_parser] def noImplicitLambda := leading_parser "no_implicit_lambda% " >> termParser maxPrec /-- `clear% x; e` elaborates `x` after clearing the free variable `x` from the local context. If `x` cannot be cleared (due to dependencies), it will keep `x` without failing. -/ -@[builtinTermParser] def clear := leading_parser "clear% " >> ident >> semicolonOrLinebreak >> termParser +@[builtin_term_parser] def clear := leading_parser "clear% " >> ident >> semicolonOrLinebreak >> termParser -@[builtinTermParser] def letMVar := leading_parser "let_mvar% " >> "?" >> ident >> " := " >> termParser >> "; " >> termParser -@[builtinTermParser] def waitIfTypeMVar := leading_parser "wait_if_type_mvar% " >> "?" >> ident >> "; " >> termParser -@[builtinTermParser] def waitIfTypeContainsMVar := leading_parser "wait_if_type_contains_mvar% " >> "?" >> ident >> "; " >> termParser -@[builtinTermParser] def waitIfContainsMVar := leading_parser "wait_if_contains_mvar% " >> "?" >> ident >> "; " >> termParser +@[builtin_term_parser] def letMVar := leading_parser "let_mvar% " >> "?" >> ident >> " := " >> termParser >> "; " >> termParser +@[builtin_term_parser] def waitIfTypeMVar := leading_parser "wait_if_type_mvar% " >> "?" >> ident >> "; " >> termParser +@[builtin_term_parser] def waitIfTypeContainsMVar := leading_parser "wait_if_type_contains_mvar% " >> "?" >> ident >> "; " >> termParser +@[builtin_term_parser] def waitIfContainsMVar := leading_parser "wait_if_contains_mvar% " >> "?" >> ident >> "; " >> termParser -@[builtinTermParser] def defaultOrOfNonempty := leading_parser "default_or_ofNonempty% " >> optional "unsafe" +@[builtin_term_parser] def defaultOrOfNonempty := leading_parser "default_or_ofNonempty% " >> optional "unsafe" /-- Helper parser for marking `match`-alternatives that should not trigger errors if unused. We use them to implement `macro_rules` and `elab_rules` -/ -@[builtinTermParser] def noErrorIfUnused := leading_parser "no_error_if_unused%" >> termParser +@[builtin_term_parser] def noErrorIfUnused := leading_parser "no_error_if_unused%" >> termParser def namedArgument := leading_parser (withAnonymousAntiquot := false) atomic ("(" >> ident >> " := ") >> termParser >> ")" def ellipsis := leading_parser (withAnonymousAntiquot := false) ".." @@ -412,7 +412,7 @@ def argument := -- `app` precedence is `lead` (cannot be used as argument) -- `lhs` precedence is `max` (i.e. does not accept `arg` precedence) -- argument precedence is `arg` (i.e. does not accept `lead` precedence) -@[builtinTermParser] def app := trailing_parser:leadPrec:maxPrec many1 argument +@[builtin_term_parser] def app := trailing_parser:leadPrec:maxPrec many1 argument /-- The *extended field notation* `e.f` is roughly short for `T.f e` where `T` is the type of `e`. @@ -423,22 +423,22 @@ More precisely, * otherwise, if `e` is of a structure type, the above is repeated for every base type of the structure. The field index notation `e.i`, where `i` is a positive number, is short for accessing the `i`-th field (1-indexed) of `e` if it is of a structure type. -/ -@[builtinTermParser] def proj := trailing_parser checkNoWsBefore >> "." >> checkNoWsBefore >> (fieldIdx <|> rawIdent) -@[builtinTermParser] def completion := trailing_parser checkNoWsBefore >> "." -@[builtinTermParser] def arrow := trailing_parser checkPrec 25 >> unicodeSymbol " → " " -> " >> termParser 25 +@[builtin_term_parser] def proj := trailing_parser checkNoWsBefore >> "." >> checkNoWsBefore >> (fieldIdx <|> rawIdent) +@[builtin_term_parser] def completion := trailing_parser checkNoWsBefore >> "." +@[builtin_term_parser] def arrow := trailing_parser checkPrec 25 >> unicodeSymbol " → " " -> " >> termParser 25 def isIdent (stx : Syntax) : Bool := -- antiquotations should also be allowed where an identifier is expected stx.isAntiquot || stx.isIdent /-- `x.{u, ...}` explicitly specifies the universes `u, ...` of the constant `x`. -/ -@[builtinTermParser] def explicitUniv : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '.{'" >> ".{" >> sepBy1 levelParser ", " >> "}" +@[builtin_term_parser] def explicitUniv : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '.{'" >> ".{" >> sepBy1 levelParser ", " >> "}" /-- `x@e` matches the pattern `e` and binds its value to the identifier `x`. -/ -@[builtinTermParser] def namedPattern : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '@'" >> "@" >> optional (atomic (ident >> ":")) >> termParser maxPrec +@[builtin_term_parser] def namedPattern : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '@'" >> "@" >> optional (atomic (ident >> ":")) >> termParser maxPrec /-- `e |>.x` is a shorthand for `(e).x`. It is especially useful for avoiding parentheses with repeated applications. -/ -@[builtinTermParser] def pipeProj := trailing_parser:minPrec " |>." >> checkNoWsBefore >> (fieldIdx <|> rawIdent) >> many argument -@[builtinTermParser] def pipeCompletion := trailing_parser:minPrec " |>." +@[builtin_term_parser] def pipeProj := trailing_parser:minPrec " |>." >> checkNoWsBefore >> (fieldIdx <|> rawIdent) >> many argument +@[builtin_term_parser] def pipeCompletion := trailing_parser:minPrec " |>." /-- `h ▸ e` is a macro built on top of `Eq.rec` and `Eq.symm` definitions. @@ -446,7 +446,7 @@ Given `h : a = b` and `e : p a`, the term `h ▸ e` has type `p b`. You can also view `h ▸ e` as a "type casting" operation where you change the type of `e` by using `h`. See the Chapter "Quantifiers and Equality" in the manual "Theorem Proving in Lean" for additional information. -/ -@[builtinTermParser] def subst := trailing_parser:75 " ▸ " >> sepBy1 (termParser 75) " ▸ " +@[builtin_term_parser] def subst := trailing_parser:75 " ▸ " >> sepBy1 (termParser 75) " ▸ " def bracketedBinderF := bracketedBinder -- no default arg instance : Coe (TSyntax ``bracketedBinderF) (TSyntax ``bracketedBinder) where coe s := ⟨s⟩ @@ -459,16 +459,16 @@ function `lean_set_panic_messages(false)` has been executed before. If the C function `lean_set_exit_on_panic(true)` has been executed before, the process is then aborted. -/ -@[builtinTermParser] def panic := leading_parser:leadPrec "panic! " >> termParser +@[builtin_term_parser] def panic := leading_parser:leadPrec "panic! " >> termParser /-- A shorthand for `panic! "unreachable code has been reached"`. -/ -@[builtinTermParser] def unreachable := leading_parser:leadPrec "unreachable!" +@[builtin_term_parser] def unreachable := leading_parser:leadPrec "unreachable!" /-- `dbg_trace e; body` evaluates to `body` and prints `e` (which can be an interpolated string literal) to stderr. It should only be used for debugging. -/ -@[builtinTermParser] def dbgTrace := leading_parser:leadPrec withPosition ("dbg_trace" >> ((interpolatedStr termParser) <|> termParser)) >> optSemicolon termParser +@[builtin_term_parser] def dbgTrace := leading_parser:leadPrec withPosition ("dbg_trace" >> ((interpolatedStr termParser) <|> termParser)) >> optSemicolon termParser /-- `assert! cond` panics if `cond` evaluates to `false`. -/ -@[builtinTermParser] def assert := leading_parser:leadPrec withPosition ("assert! " >> termParser) >> optSemicolon termParser +@[builtin_term_parser] def assert := leading_parser:leadPrec withPosition ("assert! " >> termParser) >> optSemicolon termParser def macroArg := termParser maxPrec @@ -476,16 +476,16 @@ def macroDollarArg := leading_parser "$" >> termParser 10 def macroLastArg := macroDollarArg <|> macroArg -- Macro for avoiding exponentially big terms when using `STWorld` -@[builtinTermParser] def stateRefT := leading_parser "StateRefT" >> macroArg >> macroLastArg +@[builtin_term_parser] def stateRefT := leading_parser "StateRefT" >> macroArg >> macroLastArg -@[builtinTermParser] def dynamicQuot := leading_parser "`(" >> ident >> "|" >> incQuotDepth (parserOfStack 1) >> ")" +@[builtin_term_parser] def dynamicQuot := leading_parser "`(" >> ident >> "|" >> incQuotDepth (parserOfStack 1) >> ")" -@[builtinTermParser] def dotIdent := leading_parser "." >> checkNoWsBefore >> rawIdent +@[builtin_term_parser] def dotIdent := leading_parser "." >> checkNoWsBefore >> rawIdent end Term -@[builtinTermParser default+1] def Tactic.quot : Parser := leading_parser "`(tactic|" >> incQuotDepth tacticParser >> ")" -@[builtinTermParser] def Tactic.quotSeq : Parser := leading_parser "`(tactic|" >> incQuotDepth Tactic.seq1 >> ")" +@[builtin_term_parser default+1] def Tactic.quot : Parser := leading_parser "`(tactic|" >> incQuotDepth tacticParser >> ")" +@[builtin_term_parser] def Tactic.quotSeq : Parser := leading_parser "`(tactic|" >> incQuotDepth Tactic.seq1 >> ")" open Term in builtin_initialize diff --git a/src/Lean/PrettyPrinter.lean b/src/Lean/PrettyPrinter.lean index 5b8682616c..f64e75c180 100644 --- a/src/Lean/PrettyPrinter.lean +++ b/src/Lean/PrettyPrinter.lean @@ -86,7 +86,7 @@ builtin_initialize builtin_initialize registerTraceClass `PrettyPrinter -@[builtinInit] +@[builtin_init] unsafe def registerParserCompilers : IO Unit := do ParserCompiler.registerParserCompiler ⟨`parenthesizer, parenthesizerAttribute, combinatorParenthesizerAttribute⟩ ParserCompiler.registerParserCompiler ⟨`formatter, formatterAttribute, combinatorFormatterAttribute⟩ diff --git a/src/Lean/PrettyPrinter/Delaborator/Basic.lean b/src/Lean/PrettyPrinter/Delaborator/Basic.lean index f1f9a0ef46..57d1be6dde 100644 --- a/src/Lean/PrettyPrinter/Delaborator/Basic.lean +++ b/src/Lean/PrettyPrinter/Delaborator/Basic.lean @@ -107,7 +107,7 @@ unsafe def mkDelabAttribute : IO (KeyedDeclsAttribute Delab) := is tried first.", valueTypeName := `Lean.PrettyPrinter.Delaborator.Delab } `Lean.PrettyPrinter.Delaborator.delabAttribute -@[builtinInit mkDelabAttribute] opaque delabAttribute : KeyedDeclsAttribute Delab +@[builtin_init mkDelabAttribute] opaque delabAttribute : KeyedDeclsAttribute Delab def getExprKind : DelabM Name := do let e ← getExpr @@ -263,7 +263,7 @@ to true or `pp.notation` is set to false, it will not be called at all.", evalKey := fun _ stx => do Elab.resolveGlobalConstNoOverloadWithInfo (← Attribute.Builtin.getIdent stx) } `Lean.PrettyPrinter.Delaborator.appUnexpanderAttribute -@[builtinInit mkAppUnexpanderAttribute] opaque appUnexpanderAttribute : KeyedDeclsAttribute Unexpander +@[builtin_init mkAppUnexpanderAttribute] opaque appUnexpanderAttribute : KeyedDeclsAttribute Unexpander end Delaborator diff --git a/src/Lean/PrettyPrinter/Delaborator/Builtins.lean b/src/Lean/PrettyPrinter/Delaborator/Builtins.lean index 683d02dca9..3af33e8372 100644 --- a/src/Lean/PrettyPrinter/Delaborator/Builtins.lean +++ b/src/Lean/PrettyPrinter/Delaborator/Builtins.lean @@ -22,7 +22,7 @@ def unfoldMDatas : Expr → Expr | Expr.mdata _ e => unfoldMDatas e | e => e -@[builtinDelab fvar] +@[builtin_delab fvar] def delabFVar : Delab := do let Expr.fvar fvarId ← getExpr | unreachable! try @@ -33,12 +33,12 @@ catch _ => maybeAddBlockImplicit <| mkIdent fvarId.name -- loose bound variable, use pseudo syntax -@[builtinDelab bvar] +@[builtin_delab bvar] def delabBVar : Delab := do let Expr.bvar idx ← getExpr | unreachable! pure $ mkIdent $ Name.mkSimple $ "#" ++ toString idx -@[builtinDelab mvar] +@[builtin_delab mvar] def delabMVar : Delab := do let Expr.mvar n ← getExpr | unreachable! let mvarDecl ← n.getDecl @@ -48,7 +48,7 @@ def delabMVar : Delab := do | n => n `(?$(mkIdent n)) -@[builtinDelab sort] +@[builtin_delab sort] def delabSort : Delab := do let Expr.sort l ← getExpr | unreachable! match l with @@ -133,7 +133,7 @@ where forallTelescopeArgs (mkAppN f $ args.shrink xs.size) (args.extract xs.size args.size) fun ys b => k (xs ++ ys) b -@[builtinDelab app] +@[builtin_delab app] def delabAppExplicit : Delab := do let paramKinds ← getParamKinds let tagAppFn ← getPPOption getPPTagAppFns @@ -204,7 +204,7 @@ def unexpandStructureInstance (stx : Syntax) : Delab := whenPPOption getPPStruct if (← getPPOption getPPStructureInstanceType) then delab >>= pure ∘ some else pure none `({ $fields,* $[: $tyStx]? }) -@[builtinDelab app] +@[builtin_delab app] def delabAppImplicit : Delab := do -- TODO: always call the unexpanders, make them guard on the right # args? let paramKinds ← getParamKinds @@ -333,7 +333,7 @@ where (x : List α) → (Unit → motive List.nil) → ((a : α) → (as : List α) → motive (a :: as)) → motive x ``` -/ -@[builtinDelab app] +@[builtin_delab app] def delabAppMatch : Delab := whenPPOption getPPNotation <| whenPPOption getPPMatch do -- incrementally fill `AppMatchState` from arguments let st ← withAppFnArgs @@ -408,7 +408,7 @@ def delabLetFun : Delab := do else `(let_fun $(mkIdent n) := $stxV; $stxB) -@[builtinDelab mdata] +@[builtin_delab mdata] def delabMData : Delab := do if let some _ := inaccessible? (← getExpr) then let s ← withMDataExpr delab @@ -472,7 +472,7 @@ private partial def delabBinders (delabGroup : Array Syntax → Syntax → Delab let (stx, stxN) ← withBindingBodyUnusedName fun stxN => return (← delab, stxN) delabGroup (curNames.push stxN) stx -@[builtinDelab lam] +@[builtin_delab lam] def delabLam : Delab := delabBinders fun curNames stxBody => do let e ← getExpr @@ -543,7 +543,7 @@ private partial def delabForallBinders (delabGroup : Array Syntax → Bool → S let (stx, stxN) ← withBindingBodyUnusedName fun stxN => return (← delab, stxN) delabGroup (curNames.push stxN) curDep stx -@[builtinDelab forallE] +@[builtin_delab forallE] def delabForall : Delab := do delabForallBinders fun curNames dependent stxBody => do let e ← getExpr @@ -570,7 +570,7 @@ def delabForall : Delab := do else `($group:bracketedBinder → $stxBody) -@[builtinDelab letE] +@[builtin_delab letE] def delabLetE : Delab := do let Expr.letE n t v b _ ← getExpr | unreachable! let n ← getUnusedName n b @@ -583,7 +583,7 @@ def delabLetE : Delab := do `(let $(mkIdent n) : $stxT := $stxV; $stxB) else `(let $(mkIdent n) := $stxV; $stxB) -@[builtinDelab lit] +@[builtin_delab lit] def delabLit : Delab := do let Expr.lit l ← getExpr | unreachable! match l with @@ -591,13 +591,13 @@ def delabLit : Delab := do | Literal.strVal s => pure $ quote s -- `@OfNat.ofNat _ n _` ~> `n` -@[builtinDelab app.OfNat.ofNat] +@[builtin_delab app.OfNat.ofNat] def delabOfNat : Delab := whenPPOption getPPCoercions do let .app (.app _ (.lit (.natVal n))) _ ← getExpr | failure return quote n -- `@OfDecimal.ofDecimal _ _ m s e` ~> `m*10^(sign * e)` where `sign == 1` if `s = false` and `sign = -1` if `s = true` -@[builtinDelab app.OfScientific.ofScientific] +@[builtin_delab app.OfScientific.ofScientific] def delabOfScientific : Delab := whenPPOption getPPCoercions do let expr ← getExpr guard <| expr.getAppNumArgs == 5 @@ -622,7 +622,7 @@ Delaborate a projection primitive. These do not usually occur in user code, but are pretty-printed when e.g. `#print`ing a projection function. -/ -@[builtinDelab proj] +@[builtin_delab proj] def delabProj : Delab := do let Expr.proj _ idx _ ← getExpr | unreachable! let e ← withProj delab @@ -633,7 +633,7 @@ def delabProj : Delab := do `($(e).$idx:fieldIdx) /-- Delaborate a call to a projection function such as `Prod.fst`. -/ -@[builtinDelab app] +@[builtin_delab app] def delabProjectionApp : Delab := whenPPOption getPPStructureProjections $ do let e@(Expr.app fn _) ← getExpr | failure let .const c@(.str _ f) _ ← pure fn.getAppFn | failure @@ -651,7 +651,7 @@ def delabProjectionApp : Delab := whenPPOption getPPStructureProjections $ do let appStx ← withAppArg delab `($(appStx).$(mkIdent f):ident) -@[builtinDelab app.dite] +@[builtin_delab app.dite] def delabDIte : Delab := whenPPOption getPPNotation do -- Note: we keep this as a delaborator for now because it actually accesses the expression. guard $ (← getExpr).getAppNumArgs == 5 @@ -668,7 +668,7 @@ where | none => withBindingBodyUnusedName fun h => do return (← delab, h.getId) -@[builtinDelab app.cond] +@[builtin_delab app.cond] def delabCond : Delab := whenPPOption getPPNotation do guard $ (← getExpr).getAppNumArgs == 4 let c ← withAppFn $ withAppFn $ withAppArg delab @@ -676,7 +676,7 @@ def delabCond : Delab := whenPPOption getPPNotation do let e ← withAppArg delab `(bif $c then $t else $e) -@[builtinDelab app.namedPattern] +@[builtin_delab app.namedPattern] def delabNamedPattern : Delab := do -- Note: we keep this as a delaborator because it accesses the DelabM context guard (← read).inPattern @@ -702,10 +702,10 @@ def delabSigmaCore (sigma : Bool) : Delab := whenPPOption getPPNotation do else if sigma then `((_ : $α) × $b) else `((_ : $α) ×' $b) -@[builtinDelab app.Sigma] +@[builtin_delab app.Sigma] def delabSigma : Delab := delabSigmaCore (sigma := true) -@[builtinDelab app.PSigma] +@[builtin_delab app.PSigma] def delabPSigma : Delab := delabSigmaCore (sigma := false) partial def delabDoElems : DelabM (List Syntax) := do @@ -740,7 +740,7 @@ partial def delabDoElems : DelabM (List Syntax) := do where prependAndRec x : DelabM _ := List.cons <$> x <*> delabDoElems -@[builtinDelab app.Bind.bind] +@[builtin_delab app.Bind.bind] def delabDo : Delab := whenPPOption getPPNotation do guard <| (← getExpr).isAppOfArity ``Bind.bind 6 let elems ← delabDoElems @@ -753,13 +753,13 @@ def reifyName : Expr → DelabM Name | .app (.app (.const ``Lean.Name.num ..) n) (.lit (.natVal i)) => return (← reifyName n).mkNum i | _ => failure -@[builtinDelab app.Lean.Name.str] +@[builtin_delab app.Lean.Name.str] def delabNameMkStr : Delab := whenPPOption getPPNotation do let n ← reifyName (← getExpr) -- not guaranteed to be a syntactically valid name, but usually more helpful than the explicit version return mkNode ``Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!"`{n}"] -@[builtinDelab app.Lean.Name.num] +@[builtin_delab app.Lean.Name.num] def delabNameMkNum : Delab := delabNameMkStr end Lean.PrettyPrinter.Delaborator diff --git a/src/Lean/PrettyPrinter/Formatter.lean b/src/Lean/PrettyPrinter/Formatter.lean index 284d52b02d..59b08cd723 100644 --- a/src/Lean/PrettyPrinter/Formatter.lean +++ b/src/Lean/PrettyPrinter/Formatter.lean @@ -71,7 +71,7 @@ unsafe def mkFormatterAttribute : IO (KeyedDeclsAttribute Formatter) := if (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id then pure id else throwError "invalid [formatter] argument, unknown syntax kind '{id}'" } `Lean.PrettyPrinter.formatterAttribute -@[builtinInit mkFormatterAttribute] opaque formatterAttribute : KeyedDeclsAttribute Formatter +@[builtin_init mkFormatterAttribute] opaque formatterAttribute : KeyedDeclsAttribute Formatter unsafe def mkCombinatorFormatterAttribute : IO ParserCompiler.CombinatorAttribute := ParserCompiler.registerCombinatorAttribute @@ -82,7 +82,7 @@ unsafe def mkCombinatorFormatterAttribute : IO ParserCompiler.CombinatorAttribut Note that, unlike with [formatter], this is not a node kind since combinators usually do not introduce their own node kinds. The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced with `Formatter` in the parameter types." -@[builtinInit mkCombinatorFormatterAttribute] opaque combinatorFormatterAttribute : ParserCompiler.CombinatorAttribute +@[builtin_init mkCombinatorFormatterAttribute] opaque combinatorFormatterAttribute : ParserCompiler.CombinatorAttribute namespace Formatter @@ -173,7 +173,7 @@ def withMaybeTag (pos? : Option String.Pos) (x : FormatterM Unit) : Formatter := else x -@[combinatorFormatter Lean.Parser.orelse] def orelse.formatter (p1 p2 : Formatter) : Formatter := +@[combinator_formatter Lean.Parser.orelse] def orelse.formatter (p1 p2 : Formatter) : Formatter := -- HACK: We have no (immediate) information on which side of the orelse could have produced the current node, so try -- them in turn. Uses the syntax traverser non-linearly! p1 <|> p2 @@ -208,23 +208,23 @@ unsafe def formatterForKindUnsafe (k : SyntaxNodeKind) : Formatter := do let f ← runForNodeKind formatterAttribute k interpretParserDescr' withMaybeTag (getExprPos? stx) f -@[implementedBy formatterForKindUnsafe] +@[implemented_by formatterForKindUnsafe] opaque formatterForKind (k : SyntaxNodeKind) : Formatter -@[combinatorFormatter Lean.Parser.withAntiquot] +@[combinator_formatter Lean.Parser.withAntiquot] def withAntiquot.formatter (antiP p : Formatter) : Formatter := -- TODO: could be optimized using `isAntiquot` (which would have to be moved), but I'd rather -- fix the backtracking hack outright. orelse.formatter antiP p -@[combinatorFormatter Lean.Parser.withAntiquotSuffixSplice] +@[combinator_formatter Lean.Parser.withAntiquotSuffixSplice] def withAntiquotSuffixSplice.formatter (_ : SyntaxNodeKind) (p suffix : Formatter) : Formatter := do if (← getCur).isAntiquotSuffixSplice then visitArgs <| suffix *> p else p -@[combinatorFormatter Lean.Parser.tokenWithAntiquot] +@[combinator_formatter Lean.Parser.tokenWithAntiquot] def tokenWithAntiquot.formatter (p : Formatter) : Formatter := do if (← getCur).isTokenAntiquot then visitArgs p @@ -246,7 +246,7 @@ def categoryFormatterCore (cat : Name) : Formatter := do withAntiquot.formatter (mkAntiquot.formatter' cat.toString cat (isPseudoKind := true)) (formatterForKind stx.getKind) modify fun st => { st with mustBeGrouped := true, isUngrouped := !st.mustBeGrouped } -@[combinatorFormatter Lean.Parser.categoryParser] +@[combinator_formatter Lean.Parser.categoryParser] def categoryParser.formatter (cat : Name) : Formatter := do concat <| categoryFormatterCore cat unless (← get).isUngrouped do @@ -259,31 +259,31 @@ def categoryParser.formatter (cat : Name) : Formatter := do def categoryFormatter (cat : Name) : Formatter := fill <| indent <| categoryFormatterCore cat -@[combinatorFormatter Lean.Parser.categoryParserOfStack] +@[combinator_formatter Lean.Parser.categoryParserOfStack] def categoryParserOfStack.formatter (offset : Nat) : Formatter := do let st ← get let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset) categoryParser.formatter stx.getId -@[combinatorFormatter Lean.Parser.parserOfStack] +@[combinator_formatter Lean.Parser.parserOfStack] def parserOfStack.formatter (offset : Nat) (_prec : Nat := 0) : Formatter := do let st ← get let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset) formatterForKind stx.getKind -@[combinatorFormatter Lean.Parser.error] +@[combinator_formatter Lean.Parser.error] def error.formatter (_msg : String) : Formatter := pure () -@[combinatorFormatter Lean.Parser.errorAtSavedPos] +@[combinator_formatter Lean.Parser.errorAtSavedPos] def errorAtSavedPos.formatter (_msg : String) (_delta : Bool) : Formatter := pure () -@[combinatorFormatter Lean.Parser.atomic] +@[combinator_formatter Lean.Parser.atomic] def atomic.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.lookahead] +@[combinator_formatter Lean.Parser.lookahead] def lookahead.formatter (_ : Formatter) : Formatter := pure () -@[combinatorFormatter Lean.Parser.notFollowedBy] +@[combinator_formatter Lean.Parser.notFollowedBy] def notFollowedBy.formatter (_ : Formatter) : Formatter := pure () -@[combinatorFormatter Lean.Parser.andthen] +@[combinator_formatter Lean.Parser.andthen] def andthen.formatter (p1 p2 : Formatter) : Formatter := p2 *> p1 def checkKind (k : SyntaxNodeKind) : FormatterM Unit := do @@ -292,12 +292,12 @@ def checkKind (k : SyntaxNodeKind) : FormatterM Unit := do trace[PrettyPrinter.format.backtrack] "unexpected node kind '{stx.getKind}', expected '{k}'" throwBacktrack -@[combinatorFormatter Lean.Parser.node] +@[combinator_formatter Lean.Parser.node] def node.formatter (k : SyntaxNodeKind) (p : Formatter) : Formatter := do checkKind k; visitArgs p -@[combinatorFormatter Lean.Parser.trailingNode] +@[combinator_formatter Lean.Parser.trailingNode] def trailingNode.formatter (k : SyntaxNodeKind) (_ _ : Nat) (p : Formatter) : Formatter := do checkKind k visitArgs do @@ -370,7 +370,7 @@ def pushToken (info : SourceInfo) (tk : String) : FormatterM Unit := do modify fun st => { st with leadWord := "" } | _ => pure () -@[combinatorFormatter Lean.Parser.symbolNoAntiquot] +@[combinator_formatter Lean.Parser.symbolNoAntiquot] def symbolNoAntiquot.formatter (sym : String) : Formatter := do let stx ← getCur if stx.isToken sym then do @@ -381,11 +381,11 @@ def symbolNoAntiquot.formatter (sym : String) : Formatter := do trace[PrettyPrinter.format.backtrack] "unexpected syntax '{format stx}', expected symbol '{sym}'" throwBacktrack -@[combinatorFormatter Lean.Parser.nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.formatter := symbolNoAntiquot.formatter +@[combinator_formatter Lean.Parser.nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.formatter := symbolNoAntiquot.formatter -@[combinatorFormatter Lean.Parser.rawCh] def rawCh.formatter (ch : Char) := symbolNoAntiquot.formatter ch.toString +@[combinator_formatter Lean.Parser.rawCh] def rawCh.formatter (ch : Char) := symbolNoAntiquot.formatter ch.toString -@[combinatorFormatter Lean.Parser.unicodeSymbolNoAntiquot] +@[combinator_formatter Lean.Parser.unicodeSymbolNoAntiquot] def unicodeSymbolNoAntiquot.formatter (sym asciiSym : String) : Formatter := do let Syntax.atom info val ← getCur | throwError m!"not an atom: {← getCur}" @@ -395,7 +395,7 @@ def unicodeSymbolNoAntiquot.formatter (sym asciiSym : String) : Formatter := do pushToken info asciiSym; goLeft -@[combinatorFormatter Lean.Parser.identNoAntiquot] +@[combinator_formatter Lean.Parser.identNoAntiquot] def identNoAntiquot.formatter : Formatter := do checkKind identKind let stx@(Syntax.ident info _ id _) ← getCur @@ -404,14 +404,14 @@ def identNoAntiquot.formatter : Formatter := do withMaybeTag (getExprPos? stx) (pushToken info id.toString) goLeft -@[combinatorFormatter Lean.Parser.rawIdentNoAntiquot] def rawIdentNoAntiquot.formatter : Formatter := do +@[combinator_formatter Lean.Parser.rawIdentNoAntiquot] def rawIdentNoAntiquot.formatter : Formatter := do checkKind identKind let Syntax.ident info _ id _ ← getCur | throwError m!"not an ident: {← getCur}" pushToken info id.toString goLeft -@[combinatorFormatter Lean.Parser.identEq] def identEq.formatter (_id : Name) := rawIdentNoAntiquot.formatter +@[combinator_formatter Lean.Parser.identEq] def identEq.formatter (_id : Name) := rawIdentNoAntiquot.formatter def visitAtom (k : SyntaxNodeKind) : Formatter := do let stx ← getCur @@ -422,24 +422,24 @@ def visitAtom (k : SyntaxNodeKind) : Formatter := do pushToken info val goLeft -@[combinatorFormatter Lean.Parser.charLitNoAntiquot] def charLitNoAntiquot.formatter := visitAtom charLitKind -@[combinatorFormatter Lean.Parser.strLitNoAntiquot] def strLitNoAntiquot.formatter := visitAtom strLitKind -@[combinatorFormatter Lean.Parser.nameLitNoAntiquot] def nameLitNoAntiquot.formatter := visitAtom nameLitKind -@[combinatorFormatter Lean.Parser.numLitNoAntiquot] def numLitNoAntiquot.formatter := visitAtom numLitKind -@[combinatorFormatter Lean.Parser.scientificLitNoAntiquot] def scientificLitNoAntiquot.formatter := visitAtom scientificLitKind -@[combinatorFormatter Lean.Parser.fieldIdx] def fieldIdx.formatter := visitAtom fieldIdxKind +@[combinator_formatter Lean.Parser.charLitNoAntiquot] def charLitNoAntiquot.formatter := visitAtom charLitKind +@[combinator_formatter Lean.Parser.strLitNoAntiquot] def strLitNoAntiquot.formatter := visitAtom strLitKind +@[combinator_formatter Lean.Parser.nameLitNoAntiquot] def nameLitNoAntiquot.formatter := visitAtom nameLitKind +@[combinator_formatter Lean.Parser.numLitNoAntiquot] def numLitNoAntiquot.formatter := visitAtom numLitKind +@[combinator_formatter Lean.Parser.scientificLitNoAntiquot] def scientificLitNoAntiquot.formatter := visitAtom scientificLitKind +@[combinator_formatter Lean.Parser.fieldIdx] def fieldIdx.formatter := visitAtom fieldIdxKind -@[combinatorFormatter Lean.Parser.manyNoAntiquot] +@[combinator_formatter Lean.Parser.manyNoAntiquot] def manyNoAntiquot.formatter (p : Formatter) : Formatter := do let stx ← getCur visitArgs $ stx.getArgs.size.forM fun _ => p -@[combinatorFormatter Lean.Parser.many1NoAntiquot] def many1NoAntiquot.formatter (p : Formatter) : Formatter := manyNoAntiquot.formatter p +@[combinator_formatter Lean.Parser.many1NoAntiquot] def many1NoAntiquot.formatter (p : Formatter) : Formatter := manyNoAntiquot.formatter p -@[combinatorFormatter Lean.Parser.optionalNoAntiquot] +@[combinator_formatter Lean.Parser.optionalNoAntiquot] def optionalNoAntiquot.formatter (p : Formatter) : Formatter := visitArgs p -@[combinatorFormatter Lean.Parser.many1Unbox] +@[combinator_formatter Lean.Parser.many1Unbox] def many1Unbox.formatter (p : Formatter) : Formatter := do let stx ← getCur if stx.getKind == nullKind then do @@ -447,65 +447,65 @@ def many1Unbox.formatter (p : Formatter) : Formatter := do else p -@[combinatorFormatter Lean.Parser.sepByNoAntiquot] +@[combinator_formatter Lean.Parser.sepByNoAntiquot] def sepByNoAntiquot.formatter (p pSep : Formatter) : Formatter := do let stx ← getCur visitArgs <| (List.range stx.getArgs.size).reverse.forM fun i => if i % 2 == 0 then p else pSep -@[combinatorFormatter Lean.Parser.sepBy1NoAntiquot] def sepBy1NoAntiquot.formatter := sepByNoAntiquot.formatter +@[combinator_formatter Lean.Parser.sepBy1NoAntiquot] def sepBy1NoAntiquot.formatter := sepByNoAntiquot.formatter -@[combinatorFormatter Lean.Parser.withPosition] def withPosition.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.withPositionAfterLinebreak] def withPositionAfterLinebreak.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.withoutPosition] def withoutPosition.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.withForbidden] def withForbidden.formatter (_tk : Token) (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.withoutForbidden] def withoutForbidden.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.withoutInfo] def withoutInfo.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.setExpected] +@[combinator_formatter Lean.Parser.withPosition] def withPosition.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.withPositionAfterLinebreak] def withPositionAfterLinebreak.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.withoutPosition] def withoutPosition.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.withForbidden] def withForbidden.formatter (_tk : Token) (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.withoutForbidden] def withoutForbidden.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.withoutInfo] def withoutInfo.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.setExpected] def setExpected.formatter (_expected : List String) (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.incQuotDepth] def incQuotDepth.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.decQuotDepth] def decQuotDepth.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.suppressInsideQuot] def suppressInsideQuot.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.evalInsideQuot] def evalInsideQuot.formatter (_declName : Name) (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.incQuotDepth] def incQuotDepth.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.decQuotDepth] def decQuotDepth.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.suppressInsideQuot] def suppressInsideQuot.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.evalInsideQuot] def evalInsideQuot.formatter (_declName : Name) (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.checkWsBefore] def checkWsBefore.formatter : Formatter := do +@[combinator_formatter Lean.Parser.checkWsBefore] def checkWsBefore.formatter : Formatter := do let st ← get if st.leadWord != "" then pushLine -@[combinatorFormatter Lean.Parser.checkPrec] def checkPrec.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkLhsPrec] def checkLhsPrec.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.setLhsPrec] def setLhsPrec.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkStackTop] def checkStackTop.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkNoWsBefore] def checkNoWsBefore.formatter : Formatter := +@[combinator_formatter Lean.Parser.checkPrec] def checkPrec.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkLhsPrec] def checkLhsPrec.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.setLhsPrec] def setLhsPrec.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkStackTop] def checkStackTop.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkNoWsBefore] def checkNoWsBefore.formatter : Formatter := -- prevent automatic whitespace insertion modify fun st => { st with leadWord := "" } -@[combinatorFormatter Lean.Parser.checkLinebreakBefore] def checkLinebreakBefore.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkTailWs] def checkTailWs.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkColEq] def checkColEq.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkColGe] def checkColGe.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkColGt] def checkColGt.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkLineEq] def checkLineEq.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkLinebreakBefore] def checkLinebreakBefore.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkTailWs] def checkTailWs.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkColEq] def checkColEq.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkColGe] def checkColGe.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkColGt] def checkColGt.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkLineEq] def checkLineEq.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.eoi] def eoi.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.checkNoImmediateColon] def checkNoImmediateColon.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.skip] def skip.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.eoi] def eoi.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.checkNoImmediateColon] def checkNoImmediateColon.formatter : Formatter := pure () +@[combinator_formatter Lean.Parser.skip] def skip.formatter : Formatter := pure () -@[combinatorFormatter Lean.Parser.pushNone] def pushNone.formatter : Formatter := goLeft +@[combinator_formatter Lean.Parser.pushNone] def pushNone.formatter : Formatter := goLeft -@[combinatorFormatter Lean.Parser.withOpenDecl] def withOpenDecl.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.withOpen] def withOpen.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.withOpenDecl] def withOpenDecl.formatter (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.withOpen] def withOpen.formatter (p : Formatter) : Formatter := p -@[combinatorFormatter Lean.Parser.interpolatedStr] +@[combinator_formatter Lean.Parser.interpolatedStr] def interpolatedStr.formatter (p : Formatter) : Formatter := do visitArgs $ (← getCur).getArgs.reverse.forM fun chunk => match chunk.isLit? interpolatedStrLitKind with | some str => push str *> goLeft | none => p -@[combinatorFormatter Lean.Parser.dbgTraceState] def dbgTraceState.formatter (_label : String) (p : Formatter) : Formatter := p +@[combinator_formatter Lean.Parser.dbgTraceState] def dbgTraceState.formatter (_label : String) (p : Formatter) : Formatter := p -@[combinatorFormatter ite, macroInline] def ite {_ : Type} (c : Prop) [Decidable c] (t e : Formatter) : Formatter := +@[combinator_formatter ite, macro_inline] def ite {_ : Type} (c : Prop) [Decidable c] (t e : Formatter) : Formatter := if c then t else e abbrev FormatterAliasValue := AliasValue Formatter diff --git a/src/Lean/PrettyPrinter/Parenthesizer.lean b/src/Lean/PrettyPrinter/Parenthesizer.lean index 2e284b9051..1b388ab8f3 100644 --- a/src/Lean/PrettyPrinter/Parenthesizer.lean +++ b/src/Lean/PrettyPrinter/Parenthesizer.lean @@ -54,7 +54,7 @@ parenthesize if `prec > stP.minPrec` (case 1) or if `stP.trailPrec <= st.contPre The traversal can be customized for each `[*Parser]` parser declaration `c` (more specifically, each `SyntaxNodeKind` `c`) using the `[parenthesizer c]` attribute. Otherwise, a default parenthesizer will be synthesized from the used -parser combinators by recursively replacing them with declarations tagged as `[combinatorParenthesizer]` for the +parser combinators by recursively replacing them with declarations tagged as `[combinator_parenthesizer]` for the respective combinator. If a called function does not have a registered combinator parenthesizer and is not reducible, the synthesizer fails. This happens mostly at the `Parser.mk` decl, which is irreducible, when some parser primitive has not been handled yet. @@ -126,7 +126,7 @@ unsafe def mkParenthesizerAttribute : IO (KeyedDeclsAttribute Parenthesizer) := if (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id then pure id else throwError "invalid [parenthesizer] argument, unknown syntax kind '{id}'" } `Lean.PrettyPrinter.parenthesizerAttribute -@[builtinInit mkParenthesizerAttribute] opaque parenthesizerAttribute : KeyedDeclsAttribute Parenthesizer +@[builtin_init mkParenthesizerAttribute] opaque parenthesizerAttribute : KeyedDeclsAttribute Parenthesizer abbrev CategoryParenthesizer := (prec : Nat) → Parenthesizer @@ -147,7 +147,7 @@ unsafe def mkCategoryParenthesizerAttribute : IO (KeyedDeclsAttribute CategoryPa if Parser.isParserCategory env id then pure id else throwError "invalid [category_parenthesizer] argument, unknown parser category '{toString id}'" } `Lean.PrettyPrinter.categoryParenthesizerAttribute -@[builtinInit mkCategoryParenthesizerAttribute] opaque categoryParenthesizerAttribute : KeyedDeclsAttribute CategoryParenthesizer +@[builtin_init mkCategoryParenthesizerAttribute] opaque categoryParenthesizerAttribute : KeyedDeclsAttribute CategoryParenthesizer unsafe def mkCombinatorParenthesizerAttribute : IO ParserCompiler.CombinatorAttribute := ParserCompiler.registerCombinatorAttribute @@ -158,7 +158,7 @@ unsafe def mkCombinatorParenthesizerAttribute : IO ParserCompiler.CombinatorAttr Note that, unlike with [parenthesizer], this is not a node kind since combinators usually do not introduce their own node kinds. The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced with `Parenthesizer` in the parameter types." -@[builtinInit mkCombinatorParenthesizerAttribute] opaque combinatorParenthesizerAttribute : ParserCompiler.CombinatorAttribute +@[builtin_init mkCombinatorParenthesizerAttribute] opaque combinatorParenthesizerAttribute : ParserCompiler.CombinatorAttribute namespace Parenthesizer @@ -247,7 +247,7 @@ def visitToken : Parenthesizer := do modify fun st => { st with contPrec := none, contCat := Name.anonymous, visitedToken := true } goLeft -@[combinatorParenthesizer Lean.Parser.orelse] def orelse.parenthesizer (p1 p2 : Parenthesizer) : Parenthesizer := do +@[combinator_parenthesizer Lean.Parser.orelse] def orelse.parenthesizer (p1 p2 : Parenthesizer) : Parenthesizer := do -- HACK: We have no (immediate) information on which side of the orelse could have produced the current node, so try -- them in turn. Uses the syntax traverser non-linearly! p1 <|> p2 @@ -273,10 +273,10 @@ unsafe def parenthesizerForKindUnsafe (k : SyntaxNodeKind) : Parenthesizer := do let p ← runForNodeKind parenthesizerAttribute k interpretParserDescr' p -@[implementedBy parenthesizerForKindUnsafe] +@[implemented_by parenthesizerForKindUnsafe] opaque parenthesizerForKind (k : SyntaxNodeKind) : Parenthesizer -@[combinatorParenthesizer Lean.Parser.withAntiquot] +@[combinator_parenthesizer Lean.Parser.withAntiquot] def withAntiquot.parenthesizer (antiP p : Parenthesizer) : Parenthesizer := do let stx ← getCur -- early check as minor optimization that also cleans up the backtrack traces @@ -285,14 +285,14 @@ def withAntiquot.parenthesizer (antiP p : Parenthesizer) : Parenthesizer := do else p -@[combinatorParenthesizer Lean.Parser.withAntiquotSuffixSplice] +@[combinator_parenthesizer Lean.Parser.withAntiquotSuffixSplice] def withAntiquotSuffixSplice.parenthesizer (_ : SyntaxNodeKind) (p suffix : Parenthesizer) : Parenthesizer := do if (← getCur).isAntiquotSuffixSplice then visitArgs <| suffix *> p else p -@[combinatorParenthesizer Lean.Parser.tokenWithAntiquot] +@[combinator_parenthesizer Lean.Parser.tokenWithAntiquot] def tokenWithAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do if (← getCur).isTokenAntiquot then visitArgs p @@ -310,7 +310,7 @@ def parenthesizeCategoryCore (cat : Name) (_prec : Nat) : Parenthesizer := withAntiquot.parenthesizer (mkAntiquot.parenthesizer' cat.toString cat (isPseudoKind := true)) (parenthesizerForKind stx.getKind) modify fun st => { st with contCat := cat } -@[combinatorParenthesizer Lean.Parser.categoryParser] +@[combinator_parenthesizer Lean.Parser.categoryParser] def categoryParser.parenthesizer (cat : Name) (prec : Nat) : Parenthesizer := do let env ← getEnv match categoryParenthesizerAttribute.getValues env cat with @@ -319,58 +319,58 @@ def categoryParser.parenthesizer (cat : Name) (prec : Nat) : Parenthesizer := do -- In this case this node will never be parenthesized since we don't know which parentheses to use. | _ => parenthesizeCategoryCore cat prec -@[combinatorParenthesizer Lean.Parser.categoryParserOfStack] +@[combinator_parenthesizer Lean.Parser.categoryParserOfStack] def categoryParserOfStack.parenthesizer (offset : Nat) (prec : Nat) : Parenthesizer := do let st ← get let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset) categoryParser.parenthesizer stx.getId prec -@[combinatorParenthesizer Lean.Parser.parserOfStack] +@[combinator_parenthesizer Lean.Parser.parserOfStack] def parserOfStack.parenthesizer (offset : Nat) (_prec : Nat := 0) : Parenthesizer := do let st ← get let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset) parenthesizerForKind stx.getKind -@[builtinCategoryParenthesizer term] +@[builtin_category_parenthesizer term] def term.parenthesizer : CategoryParenthesizer | prec => do maybeParenthesize `term true (fun stx => Unhygienic.run `(($(⟨stx⟩)))) prec $ parenthesizeCategoryCore `term prec -@[builtinCategoryParenthesizer tactic] +@[builtin_category_parenthesizer tactic] def tactic.parenthesizer : CategoryParenthesizer | prec => do maybeParenthesize `tactic false (fun stx => Unhygienic.run `(tactic|($(⟨stx⟩)))) prec $ parenthesizeCategoryCore `tactic prec -@[builtinCategoryParenthesizer level] +@[builtin_category_parenthesizer level] def level.parenthesizer : CategoryParenthesizer | prec => do maybeParenthesize `level false (fun stx => Unhygienic.run `(level|($(⟨stx⟩)))) prec $ parenthesizeCategoryCore `level prec -@[builtinCategoryParenthesizer rawStx] +@[builtin_category_parenthesizer rawStx] def rawStx.parenthesizer : CategoryParenthesizer | _ => do goLeft -@[combinatorParenthesizer Lean.Parser.error] +@[combinator_parenthesizer Lean.Parser.error] def error.parenthesizer (_msg : String) : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.errorAtSavedPos] +@[combinator_parenthesizer Lean.Parser.errorAtSavedPos] def errorAtSavedPos.parenthesizer (_msg : String) (_delta : Bool) : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.atomic] +@[combinator_parenthesizer Lean.Parser.atomic] def atomic.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.lookahead] +@[combinator_parenthesizer Lean.Parser.lookahead] def lookahead.parenthesizer (_ : Parenthesizer) : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.notFollowedBy] +@[combinator_parenthesizer Lean.Parser.notFollowedBy] def notFollowedBy.parenthesizer (_ : Parenthesizer) : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.andthen] +@[combinator_parenthesizer Lean.Parser.andthen] def andthen.parenthesizer (p1 p2 : Parenthesizer) : Parenthesizer := p2 *> p1 @@ -381,16 +381,16 @@ def checkKind (k : SyntaxNodeKind) : Parenthesizer := do -- HACK; see `orelse.parenthesizer` throwBacktrack -@[combinatorParenthesizer Lean.Parser.node] +@[combinator_parenthesizer Lean.Parser.node] def node.parenthesizer (k : SyntaxNodeKind) (p : Parenthesizer) : Parenthesizer := do checkKind k visitArgs p -@[combinatorParenthesizer Lean.Parser.checkPrec] +@[combinator_parenthesizer Lean.Parser.checkPrec] def checkPrec.parenthesizer (prec : Nat) : Parenthesizer := addPrecCheck prec -@[combinatorParenthesizer Lean.Parser.leadingNode] +@[combinator_parenthesizer Lean.Parser.leadingNode] def leadingNode.parenthesizer (k : SyntaxNodeKind) (prec : Nat) (p : Parenthesizer) : Parenthesizer := do node.parenthesizer k p addPrecCheck prec @@ -399,7 +399,7 @@ def leadingNode.parenthesizer (k : SyntaxNodeKind) (prec : Nat) (p : Parenthesiz -- into a trailing one. modify fun st => { st with contPrec := Nat.min (Parser.maxPrec-1) prec } -@[combinatorParenthesizer Lean.Parser.trailingNode] +@[combinator_parenthesizer Lean.Parser.trailingNode] def trailingNode.parenthesizer (k : SyntaxNodeKind) (prec lhsPrec : Nat) (p : Parenthesizer) : Parenthesizer := do checkKind k visitArgs do @@ -413,33 +413,33 @@ def trailingNode.parenthesizer (k : SyntaxNodeKind) (prec lhsPrec : Nat) (p : Pa -- parser is calling us. categoryParser.parenthesizer ctx.cat lhsPrec -@[combinatorParenthesizer Lean.Parser.rawCh] def rawCh.parenthesizer (_ch : Char) := visitToken +@[combinator_parenthesizer Lean.Parser.rawCh] def rawCh.parenthesizer (_ch : Char) := visitToken -@[combinatorParenthesizer Lean.Parser.symbolNoAntiquot] def symbolNoAntiquot.parenthesizer (_sym : String) := visitToken -@[combinatorParenthesizer Lean.Parser.unicodeSymbolNoAntiquot] def unicodeSymbolNoAntiquot.parenthesizer (_sym _asciiSym : String) := visitToken +@[combinator_parenthesizer Lean.Parser.symbolNoAntiquot] def symbolNoAntiquot.parenthesizer (_sym : String) := visitToken +@[combinator_parenthesizer Lean.Parser.unicodeSymbolNoAntiquot] def unicodeSymbolNoAntiquot.parenthesizer (_sym _asciiSym : String) := visitToken -@[combinatorParenthesizer Lean.Parser.identNoAntiquot] def identNoAntiquot.parenthesizer := do checkKind identKind; visitToken -@[combinatorParenthesizer Lean.Parser.rawIdentNoAntiquot] def rawIdentNoAntiquot.parenthesizer := visitToken -@[combinatorParenthesizer Lean.Parser.identEq] def identEq.parenthesizer (_id : Name) := visitToken -@[combinatorParenthesizer Lean.Parser.nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.parenthesizer (_sym : String) (_includeIdent : Bool) := visitToken +@[combinator_parenthesizer Lean.Parser.identNoAntiquot] def identNoAntiquot.parenthesizer := do checkKind identKind; visitToken +@[combinator_parenthesizer Lean.Parser.rawIdentNoAntiquot] def rawIdentNoAntiquot.parenthesizer := visitToken +@[combinator_parenthesizer Lean.Parser.identEq] def identEq.parenthesizer (_id : Name) := visitToken +@[combinator_parenthesizer Lean.Parser.nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.parenthesizer (_sym : String) (_includeIdent : Bool) := visitToken -@[combinatorParenthesizer Lean.Parser.charLitNoAntiquot] def charLitNoAntiquot.parenthesizer := visitToken -@[combinatorParenthesizer Lean.Parser.strLitNoAntiquot] def strLitNoAntiquot.parenthesizer := visitToken -@[combinatorParenthesizer Lean.Parser.nameLitNoAntiquot] def nameLitNoAntiquot.parenthesizer := visitToken -@[combinatorParenthesizer Lean.Parser.numLitNoAntiquot] def numLitNoAntiquot.parenthesizer := visitToken -@[combinatorParenthesizer Lean.Parser.scientificLitNoAntiquot] def scientificLitNoAntiquot.parenthesizer := visitToken -@[combinatorParenthesizer Lean.Parser.fieldIdx] def fieldIdx.parenthesizer := visitToken +@[combinator_parenthesizer Lean.Parser.charLitNoAntiquot] def charLitNoAntiquot.parenthesizer := visitToken +@[combinator_parenthesizer Lean.Parser.strLitNoAntiquot] def strLitNoAntiquot.parenthesizer := visitToken +@[combinator_parenthesizer Lean.Parser.nameLitNoAntiquot] def nameLitNoAntiquot.parenthesizer := visitToken +@[combinator_parenthesizer Lean.Parser.numLitNoAntiquot] def numLitNoAntiquot.parenthesizer := visitToken +@[combinator_parenthesizer Lean.Parser.scientificLitNoAntiquot] def scientificLitNoAntiquot.parenthesizer := visitToken +@[combinator_parenthesizer Lean.Parser.fieldIdx] def fieldIdx.parenthesizer := visitToken -@[combinatorParenthesizer Lean.Parser.manyNoAntiquot] +@[combinator_parenthesizer Lean.Parser.manyNoAntiquot] def manyNoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do let stx ← getCur visitArgs $ stx.getArgs.size.forM fun _ => p -@[combinatorParenthesizer Lean.Parser.many1NoAntiquot] +@[combinator_parenthesizer Lean.Parser.many1NoAntiquot] def many1NoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do manyNoAntiquot.parenthesizer p -@[combinatorParenthesizer Lean.Parser.many1Unbox] +@[combinator_parenthesizer Lean.Parser.many1Unbox] def many1Unbox.parenthesizer (p : Parenthesizer) : Parenthesizer := do let stx ← getCur if stx.getKind == nullKind then @@ -447,55 +447,55 @@ def many1Unbox.parenthesizer (p : Parenthesizer) : Parenthesizer := do else p -@[combinatorParenthesizer Lean.Parser.optionalNoAntiquot] +@[combinator_parenthesizer Lean.Parser.optionalNoAntiquot] def optionalNoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do visitArgs p -@[combinatorParenthesizer Lean.Parser.sepByNoAntiquot] +@[combinator_parenthesizer Lean.Parser.sepByNoAntiquot] def sepByNoAntiquot.parenthesizer (p pSep : Parenthesizer) : Parenthesizer := do let stx ← getCur visitArgs <| (List.range stx.getArgs.size).reverse.forM fun i => if i % 2 == 0 then p else pSep -@[combinatorParenthesizer Lean.Parser.sepBy1NoAntiquot] def sepBy1NoAntiquot.parenthesizer := sepByNoAntiquot.parenthesizer +@[combinator_parenthesizer Lean.Parser.sepBy1NoAntiquot] def sepBy1NoAntiquot.parenthesizer := sepByNoAntiquot.parenthesizer -@[combinatorParenthesizer Lean.Parser.withPosition] def withPosition.parenthesizer (p : Parenthesizer) : Parenthesizer := do +@[combinator_parenthesizer Lean.Parser.withPosition] def withPosition.parenthesizer (p : Parenthesizer) : Parenthesizer := do -- We assume the formatter will indent syntax sufficiently such that parenthesizing a `withPosition` node is never necessary modify fun st => { st with contPrec := none } p -@[combinatorParenthesizer Lean.Parser.withPositionAfterLinebreak] def withPositionAfterLinebreak.parenthesizer (p : Parenthesizer) : Parenthesizer := +@[combinator_parenthesizer Lean.Parser.withPositionAfterLinebreak] def withPositionAfterLinebreak.parenthesizer (p : Parenthesizer) : Parenthesizer := -- TODO: improve? withPosition.parenthesizer p -@[combinatorParenthesizer Lean.Parser.withoutPosition] def withoutPosition.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.withForbidden] def withForbidden.parenthesizer (_tk : Parser.Token) (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.withoutForbidden] def withoutForbidden.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.withoutInfo] def withoutInfo.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.setExpected] +@[combinator_parenthesizer Lean.Parser.withoutPosition] def withoutPosition.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.withForbidden] def withForbidden.parenthesizer (_tk : Parser.Token) (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.withoutForbidden] def withoutForbidden.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.withoutInfo] def withoutInfo.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.setExpected] def setExpected.parenthesizer (_expected : List String) (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.incQuotDepth] def incQuotDepth.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.decQuotDepth] def decQuotDepth.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.suppressInsideQuot] def suppressInsideQuot.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.evalInsideQuot] def evalInsideQuot.parenthesizer (_declName : Name) (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.incQuotDepth] def incQuotDepth.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.decQuotDepth] def decQuotDepth.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.suppressInsideQuot] def suppressInsideQuot.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.evalInsideQuot] def evalInsideQuot.parenthesizer (_declName : Name) (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.checkStackTop] def checkStackTop.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkWsBefore] def checkWsBefore.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkNoWsBefore] def checkNoWsBefore.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkLinebreakBefore] def checkLinebreakBefore.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkTailWs] def checkTailWs.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkColEq] def checkColEq.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkColGe] def checkColGe.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkColGt] def checkColGt.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkLineEq] def checkLineEq.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.eoi] def eoi.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.checkNoImmediateColon] def checkNoImmediateColon.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.skip] def skip.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkStackTop] def checkStackTop.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkWsBefore] def checkWsBefore.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkNoWsBefore] def checkNoWsBefore.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkLinebreakBefore] def checkLinebreakBefore.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkTailWs] def checkTailWs.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkColEq] def checkColEq.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkColGe] def checkColGe.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkColGt] def checkColGt.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkLineEq] def checkLineEq.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.eoi] def eoi.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.checkNoImmediateColon] def checkNoImmediateColon.parenthesizer : Parenthesizer := pure () +@[combinator_parenthesizer Lean.Parser.skip] def skip.parenthesizer : Parenthesizer := pure () -@[combinatorParenthesizer Lean.Parser.pushNone] def pushNone.parenthesizer : Parenthesizer := goLeft +@[combinator_parenthesizer Lean.Parser.pushNone] def pushNone.parenthesizer : Parenthesizer := goLeft -@[combinatorParenthesizer Lean.Parser.withOpenDecl] def withOpenDecl.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.withOpen] def withOpen.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.withOpenDecl] def withOpenDecl.parenthesizer (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.withOpen] def withOpen.parenthesizer (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer Lean.Parser.interpolatedStr] +@[combinator_parenthesizer Lean.Parser.interpolatedStr] def interpolatedStr.parenthesizer (p : Parenthesizer) : Parenthesizer := do visitArgs $ (← getCur).getArgs.reverse.forM fun chunk => if chunk.isOfKind interpolatedStrLitKind then @@ -503,9 +503,9 @@ def interpolatedStr.parenthesizer (p : Parenthesizer) : Parenthesizer := do else p -@[combinatorParenthesizer Lean.Parser.dbgTraceState] def dbgTraceState.parenthesizer (_label : String) (p : Parenthesizer) : Parenthesizer := p +@[combinator_parenthesizer Lean.Parser.dbgTraceState] def dbgTraceState.parenthesizer (_label : String) (p : Parenthesizer) : Parenthesizer := p -@[combinatorParenthesizer ite, macroInline] def ite {_ : Type} (c : Prop) [Decidable c] (t e : Parenthesizer) : Parenthesizer := +@[combinator_parenthesizer ite, macro_inline] def ite {_ : Type} (c : Prop) [Decidable c] (t e : Parenthesizer) : Parenthesizer := if c then t else e open Parser diff --git a/src/Lean/ScopedEnvExtension.lean b/src/Lean/ScopedEnvExtension.lean index 9feaaeafeb..e74fecfc1e 100644 --- a/src/Lean/ScopedEnvExtension.lean +++ b/src/Lean/ScopedEnvExtension.lean @@ -116,7 +116,7 @@ unsafe def registerScopedEnvExtensionUnsafe (descr : Descr α β σ) : IO (Scope scopedEnvExtensionsRef.modify fun exts => exts.push (unsafeCast ext) return ext -@[implementedBy registerScopedEnvExtensionUnsafe] +@[implemented_by registerScopedEnvExtensionUnsafe] opaque registerScopedEnvExtension (descr : Descr α β σ) : IO (ScopedEnvExtension α β σ) def ScopedEnvExtension.pushScope (ext : ScopedEnvExtension α β σ) (env : Environment) : Environment := diff --git a/src/Lean/Server/Rpc/RequestHandling.lean b/src/Lean/Server/Rpc/RequestHandling.lean index 01d7649435..75614e7e3c 100644 --- a/src/Lean/Server/Rpc/RequestHandling.lean +++ b/src/Lean/Server/Rpc/RequestHandling.lean @@ -27,7 +27,7 @@ private unsafe def evalRpcProcedureUnsafe (env : Environment) (opts : Options) ( Except String RpcProcedure := env.evalConstCheck RpcProcedure opts ``RpcProcedure procName -@[implementedBy evalRpcProcedureUnsafe] +@[implemented_by evalRpcProcedureUnsafe] opaque evalRpcProcedure (env : Environment) (opts : Options) (procName : Name) : Except String RpcProcedure diff --git a/src/Lean/Util/FindExpr.lean b/src/Lean/Util/FindExpr.lean index ef36cd64c9..ecc4e924c3 100644 --- a/src/Lean/Util/FindExpr.lean +++ b/src/Lean/Util/FindExpr.lean @@ -53,7 +53,7 @@ unsafe def findUnsafe? (p : Expr → Bool) (e : Expr) : Option Expr := end FindImpl -@[implementedBy FindImpl.findUnsafe?] +@[implemented_by FindImpl.findUnsafe?] def find? (p : Expr → Bool) (e : Expr) : Option Expr := /- This is a reference implementation for the unsafe one above -/ if p e then @@ -113,7 +113,7 @@ end FindExtImpl /-- Similar to `find?`, but `p` can return `FindStep.done` to interrupt the search on subterms. Remark: Differently from `find?`, we do not invoke `p` for partial applications of an application. -/ -@[implementedBy FindExtImpl.findUnsafe?] +@[implemented_by FindExtImpl.findUnsafe?] opaque findExt? (p : Expr → FindStep) (e : Expr) : Option Expr end Expr diff --git a/src/Lean/Util/FoldConsts.lean b/src/Lean/Util/FoldConsts.lean index 4a00f0a3a1..4ef9038f05 100644 --- a/src/Lean/Util/FoldConsts.lean +++ b/src/Lean/Util/FoldConsts.lean @@ -60,7 +60,7 @@ unsafe def initCache : State := end FoldConstsImpl /-- Apply `f` to every constant occurring in `e` once. -/ -@[implementedBy FoldConstsImpl.foldUnsafe] +@[implemented_by FoldConstsImpl.foldUnsafe] opaque foldConsts {α : Type} (e : Expr) (init : α) (f : Name → α → α) : α := init def getUsedConstants (e : Expr) : Array Name := diff --git a/src/Lean/Util/HasConstCache.lean b/src/Lean/Util/HasConstCache.lean index 9972fb70a2..744079153b 100644 --- a/src/Lean/Util/HasConstCache.lean +++ b/src/Lean/Util/HasConstCache.lean @@ -31,7 +31,7 @@ where /-- Return true iff `e` contains the constant `declName`. Remark: the results for visited expressions are stored in the state cache. -/ -@[implementedBy HasConstCache.containsUnsafe] +@[implemented_by HasConstCache.containsUnsafe] opaque HasConstCache.contains (e : Expr) : StateM (HasConstCache declName) Bool end Lean diff --git a/src/Lean/Util/MonadCache.lean b/src/Lean/Util/MonadCache.lean index 1b9c935a5a..b11bb11a31 100644 --- a/src/Lean/Util/MonadCache.lean +++ b/src/Lean/Util/MonadCache.lean @@ -13,7 +13,7 @@ class MonadCache (α β : Type) (m : Type → Type) where /-- If entry `a := b` is already in the cache, then return `b`. Otherwise, execute `b ← f ()`, store `a := b` in the cache and return `b`. -/ -@[alwaysInline, inline] +@[always_inline, inline] def checkCache {α β : Type} {m : Type → Type} [MonadCache α β m] [Monad m] (a : α) (f : Unit → m β) : m β := do match (← MonadCache.findCached? a) with | some b => pure b @@ -26,7 +26,7 @@ instance {α β ρ : Type} {m : Type → Type} [MonadCache α β m] : MonadCache findCached? a _ := MonadCache.findCached? a cache a b _ := MonadCache.cache a b -@[alwaysInline] +@[always_inline] instance {α β ε : Type} {m : Type → Type} [MonadCache α β m] [Monad m] : MonadCache α β (ExceptT ε m) where findCached? a := ExceptT.lift $ MonadCache.findCached? a cache a b := ExceptT.lift $ MonadCache.cache a b @@ -39,12 +39,12 @@ class MonadHashMapCacheAdapter (α β : Type) (m : Type → Type) [BEq α] [Hash namespace MonadHashMapCacheAdapter -@[alwaysInline, inline] +@[always_inline, inline] def findCached? {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [Monad m] [MonadHashMapCacheAdapter α β m] (a : α) : m (Option β) := do let c ← getCache pure (c.find? a) -@[alwaysInline, inline] +@[always_inline, inline] def cache {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [MonadHashMapCacheAdapter α β m] (a : α) (b : β) : m Unit := modifyCache fun s => s.insert a b @@ -88,7 +88,7 @@ instance : MonadHashMapCacheAdapter α β (MonadStateCacheT α β m) where getCache := (get : StateT ..) modifyCache f := (modify f : StateT ..) -@[alwaysInline, inline] def run {σ} (x : MonadStateCacheT α β m σ) : m σ := +@[always_inline, inline] def run {σ} (x : MonadStateCacheT α β m σ) : m σ := x.run' mkHashMap instance : Monad (MonadStateCacheT α β m) := inferInstanceAs (Monad (StateT _ _)) diff --git a/src/Lean/Util/Profile.lean b/src/Lean/Util/Profile.lean index 6abccffda3..3dd82c86d5 100644 --- a/src/Lean/Util/Profile.lean +++ b/src/Lean/Util/Profile.lean @@ -16,7 +16,7 @@ unsafe def profileitIOUnsafe {ε α : Type} (category : String) (opts : Options) | Except.ok a => pure a | Except.error e => throw e -@[implementedBy profileitIOUnsafe] +@[implemented_by profileitIOUnsafe] def profileitIO {ε α : Type} (category : String) (opts : Options) (act : EIO ε α) : EIO ε α := act -- impossible to infer `ε` diff --git a/src/Lean/Util/ReplaceExpr.lean b/src/Lean/Util/ReplaceExpr.lean index bf503aa2cb..bd2ba7a7e1 100644 --- a/src/Lean/Util/ReplaceExpr.lean +++ b/src/Lean/Util/ReplaceExpr.lean @@ -53,7 +53,7 @@ end ReplaceImpl /- TODO: use withPtrAddr, withPtrEq to avoid unsafe tricks above. We also need an invariant at `State` and proofs for the `uget` operations. -/ -@[implementedBy ReplaceImpl.replaceUnsafe] +@[implemented_by ReplaceImpl.replaceUnsafe] partial def replace (f? : Expr → Option Expr) (e : Expr) : Expr := /- This is a reference implementation for the unsafe one above -/ match f? e with diff --git a/src/Lean/Util/ReplaceLevel.lean b/src/Lean/Util/ReplaceLevel.lean index 119aedb690..1185838ad6 100644 --- a/src/Lean/Util/ReplaceLevel.lean +++ b/src/Lean/Util/ReplaceLevel.lean @@ -63,7 +63,7 @@ unsafe def replaceUnsafe (f? : Level → Option Level) (e : Expr) : Expr := end ReplaceLevelImpl -@[implementedBy ReplaceLevelImpl.replaceUnsafe] +@[implemented_by ReplaceLevelImpl.replaceUnsafe] partial def replaceLevel (f? : Level → Option Level) : Expr → Expr | e@(Expr.forallE _ d b _) => let d := replaceLevel f? d; let b := replaceLevel f? b; e.updateForallE! d b | e@(Expr.lam _ d b _) => let d := replaceLevel f? d; let b := replaceLevel f? b; e.updateLambdaE! d b diff --git a/src/Lean/Widget/UserWidget.lean b/src/Lean/Widget/UserWidget.lean index d338dfcf99..f574fe746d 100644 --- a/src/Lean/Widget/UserWidget.lean +++ b/src/Lean/Widget/UserWidget.lean @@ -66,7 +66,7 @@ private unsafe def getUserWidgetDefinitionUnsafe (decl : Name) : CoreM UserWidgetDefinition := evalConstCheck UserWidgetDefinition ``UserWidgetDefinition decl -@[implementedBy getUserWidgetDefinitionUnsafe] +@[implemented_by getUserWidgetDefinitionUnsafe] private opaque getUserWidgetDefinition (decl : Name) : CoreM UserWidgetDefinition @@ -92,7 +92,7 @@ structure GetWidgetSourceParams where deriving ToJson, FromJson open Server RequestM in -@[serverRpcMethod] +@[server_rpc_method] def getWidgetSource (args : GetWidgetSourceParams) : RequestM (RequestTask WidgetSource) := do let doc ← readDoc let pos := doc.meta.text.lspPosToUtf8Pos args.pos @@ -139,7 +139,7 @@ structure GetWidgetsResponse where open Lean Server RequestM in /-- Get the `UserWidget`s present at a particular position. -/ -@[serverRpcMethod] +@[server_rpc_method] def getWidgets (args : Lean.Lsp.Position) : RequestM (RequestTask (GetWidgetsResponse)) := do let doc ← readDoc let filemap := doc.meta.text @@ -176,12 +176,12 @@ open Lean Lean.Meta Lean.Elab Lean.Elab.Term in private unsafe def evalJsonUnsafe (stx : Syntax) : TermElabM Json := Lean.Elab.Term.evalTerm Json (mkConst ``Json) stx -@[implementedBy evalJsonUnsafe] +@[implemented_by evalJsonUnsafe] private opaque evalJson (stx : Syntax) : TermElabM Json open Elab Command in -@[commandElab widgetCmd] def elabWidgetCmd : CommandElab := fun +@[command_elab widgetCmd] def elabWidgetCmd : CommandElab := fun | stx@`(#widget $id:ident $props) => do let props : Json ← runTermElabM fun _ => evalJson props saveWidgetInfo id.getId props stx diff --git a/src/lake b/src/lake index 8546900b81..c4a1e54353 160000 --- a/src/lake +++ b/src/lake @@ -1 +1 @@ -Subproject commit 8546900b81abb8df291d95bd615819a28b4fdc15 +Subproject commit c4a1e543537d293c35b9a4604f6285ed5fad4bf5 diff --git a/tests/pkg/builtin_attr/lakefile.lean b/tests/pkg/builtin_attr/lakefile.lean index 3b0c46f973..89e82affdf 100644 --- a/tests/pkg/builtin_attr/lakefile.lean +++ b/tests/pkg/builtin_attr/lakefile.lean @@ -2,4 +2,4 @@ import Lake open System Lake DSL package user_attr -@[defaultTarget] lean_lib UserAttr +@[default_target] lean_lib UserAttr diff --git a/tests/pkg/deriving/lakefile.lean b/tests/pkg/deriving/lakefile.lean index 521fb262f1..2567ab7566 100644 --- a/tests/pkg/deriving/lakefile.lean +++ b/tests/pkg/deriving/lakefile.lean @@ -2,4 +2,4 @@ import Lake open System Lake DSL package user_deriving -@[defaultTarget] lean_lib UserDeriving +@[default_target] lean_lib UserDeriving diff --git a/tests/pkg/misc/lakefile.lean b/tests/pkg/misc/lakefile.lean index dfd791ca28..c4010eb6bb 100644 --- a/tests/pkg/misc/lakefile.lean +++ b/tests/pkg/misc/lakefile.lean @@ -2,4 +2,4 @@ import Lake open System Lake DSL package misc -@[defaultTarget] lean_lib Misc +@[default_target] lean_lib Misc diff --git a/tests/pkg/prv/lakefile.lean b/tests/pkg/prv/lakefile.lean index d22d58719d..b43c239bc3 100644 --- a/tests/pkg/prv/lakefile.lean +++ b/tests/pkg/prv/lakefile.lean @@ -2,4 +2,4 @@ import Lake open System Lake DSL package prv -@[defaultTarget] lean_lib Prv +@[default_target] lean_lib Prv diff --git a/tests/pkg/user_attr/lakefile.lean b/tests/pkg/user_attr/lakefile.lean index 3b0c46f973..89e82affdf 100644 --- a/tests/pkg/user_attr/lakefile.lean +++ b/tests/pkg/user_attr/lakefile.lean @@ -2,4 +2,4 @@ import Lake open System Lake DSL package user_attr -@[defaultTarget] lean_lib UserAttr +@[default_target] lean_lib UserAttr diff --git a/tests/pkg/user_attr_app/lakefile.lean b/tests/pkg/user_attr_app/lakefile.lean index 6d9917f31b..0196ebab36 100644 --- a/tests/pkg/user_attr_app/lakefile.lean +++ b/tests/pkg/user_attr_app/lakefile.lean @@ -5,7 +5,7 @@ package user_attr lean_lib UserAttr -@[defaultTarget] +@[default_target] lean_exe user_attr where root := `Main supportInterpreter := true diff --git a/tests/pkg/user_ext/UserExt/BlaExt.lean b/tests/pkg/user_ext/UserExt/BlaExt.lean index 2645b01cec..318692f11e 100644 --- a/tests/pkg/user_ext/UserExt/BlaExt.lean +++ b/tests/pkg/user_ext/UserExt/BlaExt.lean @@ -14,9 +14,9 @@ syntax (name := showBla) "show_bla_set" : command open Lean.Elab open Lean.Elab.Command -@[commandElab insertBla] def elabInsertBla : CommandElab := fun stx => do +@[command_elab insertBla] def elabInsertBla : CommandElab := fun stx => do IO.println s!"inserting {stx[1].getId}" modifyEnv fun env => blaExtension.addEntry env stx[1].getId -@[commandElab showBla] def elabShowBla : CommandElab := fun stx => do +@[command_elab showBla] def elabShowBla : CommandElab := fun stx => do IO.println s!"bla set: {blaExtension.getState (← getEnv) |>.toList}" diff --git a/tests/pkg/user_ext/UserExt/FooExt.lean b/tests/pkg/user_ext/UserExt/FooExt.lean index 252a3958f4..1476f06c3f 100644 --- a/tests/pkg/user_ext/UserExt/FooExt.lean +++ b/tests/pkg/user_ext/UserExt/FooExt.lean @@ -16,10 +16,10 @@ syntax (name := showFoo) "show_foo_set" : command open Lean.Elab open Lean.Elab.Command -@[commandElab insertFoo] def elabInsertFoo : CommandElab := fun stx => do +@[command_elab insertFoo] def elabInsertFoo : CommandElab := fun stx => do trace[myDebug] "testing trace message at insert foo '{stx}'" IO.println s!"inserting {stx[1].getId}" modifyEnv fun env => fooExtension.addEntry env stx[1].getId -@[commandElab showFoo] def elabShowFoo : CommandElab := fun stx => do +@[command_elab showFoo] def elabShowFoo : CommandElab := fun stx => do IO.println s!"foo set: {fooExtension.getState (← getEnv) |>.toList}" diff --git a/tests/pkg/user_ext/lakefile.lean b/tests/pkg/user_ext/lakefile.lean index 370b5b551c..2588ea8e19 100644 --- a/tests/pkg/user_ext/lakefile.lean +++ b/tests/pkg/user_ext/lakefile.lean @@ -2,4 +2,4 @@ import Lake open System Lake DSL package user_ext -@[defaultTarget] lean_lib UserExt +@[default_target] lean_lib UserExt diff --git a/tests/pkg/user_opt/lakefile.lean b/tests/pkg/user_opt/lakefile.lean index f409768a79..5657d60ed1 100644 --- a/tests/pkg/user_opt/lakefile.lean +++ b/tests/pkg/user_opt/lakefile.lean @@ -2,4 +2,4 @@ import Lake open System Lake DSL package user_opt -@[defaultTarget] lean_lib UserOpt +@[default_target] lean_lib UserOpt