@@ -48,6 +48,7 @@ namespace Mathlib.Tactic
4848open Lean Meta Elab.Tactic
4949
5050/-- Use the procedure `m` to rewrite the provided goal. -/
51+ -- Assumes `proc` is not surrounded by backticks itself.
5152def transformAtTarget (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (proc : String)
5253 (failIfUnchanged : Bool) (goal : MVarId) :
5354 ReaderT Simp.Context MetaM (Option MVarId) := do
@@ -56,7 +57,7 @@ def transformAtTarget (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (pro
5657 -- we use expression equality here (rather than defeq) to be consistent with, e.g.,
5758 -- `applySimpResultToTarget`
5859 let unchanged := tgt.cleanupAnnotations == r.expr.cleanupAnnotations
59- if failIfUnchanged && unchanged then throwError "{proc} made no progress on the goal"
60+ if failIfUnchanged && unchanged then throwError "` {proc}` made no progress on the goal"
6061 if r.expr.isTrue then
6162 goal.assign (← mkOfEqTrue (← r.getProof))
6263 pure none
@@ -71,23 +72,25 @@ def transformAtTarget (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (pro
7172The `simpTheorems` of the simp-context carried with `m` will be modified to remove `fvarId`;
7273this ensures that if the procedure `m` involves rewriting by this `SimpTheoremsArray`, then, e.g.,
7374`h : x = y` is not transformed (by rewriting `h`) to `True`. -/
75+ -- Assumes `proc` is not surrounded by backticks itself.
7476def transformAtLocalDecl (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (proc : String)
7577 (failIfUnchanged : Bool) (mayCloseGoal : Bool) (fvarId : FVarId) (goal : MVarId) :
7678 ReaderT Simp.Context MetaM (Option MVarId) := do
7779 let ldecl ← fvarId.getDecl
7880 if ldecl.isImplementationDetail then
79- throwError "Cannot run {proc} at {ldecl.userName}, it is an implementation detail"
81+ throwError "Cannot run ` {proc}` at ` {ldecl.userName}` , it is an implementation detail"
8082 let tgt ← instantiateMVars (← fvarId.getType)
8183 let eraseFVarId (ctx : Simp.Context) :=
8284 ctx.setSimpTheorems <| ctx.simpTheorems.eraseTheorem (.fvar fvarId)
8385 let r ← withReader eraseFVarId <| m tgt
8486 -- we use expression equality here (rather than defeq) to be consistent with, e.g.,
8587 -- `applySimpResultToLocalDeclCore`
8688 if failIfUnchanged && tgt.cleanupAnnotations == r.expr.cleanupAnnotations then
87- throwError "{proc} made no progress at {ldecl.userName}"
89+ throwError "` {proc}` made no progress at ` {ldecl.userName}` "
8890 return (← applySimpResultToLocalDecl goal fvarId r mayCloseGoal).map Prod.snd
8991
9092/-- Use the procedure `m` to transform at specified locations (hypotheses and/or goal). -/
93+ -- Assumes `proc` is not surrounded by backticks itself.
9194def transformAtLocation (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (proc : String)
9295 (loc : Location) (failIfUnchanged : Bool := true ) (mayCloseGoalFromHyp : Bool := false )
9396 -- streamline the most common use case, in which the procedure `m`'s implementation is not
@@ -97,11 +100,12 @@ def transformAtLocation (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (p
97100 withLocation loc
98101 (liftMetaTactic1 ∘ (transformAtLocalDecl m proc failIfUnchanged mayCloseGoalFromHyp · · ctx))
99102 (liftMetaTactic1 (transformAtTarget m proc failIfUnchanged · ctx))
100- fun _ ↦ throwError "{proc} made no progress anywhere"
103+ fun _ ↦ throwError "` {proc}` made no progress anywhere"
101104
102105/-- Use the procedure `m` to transform at specified locations (hypotheses and/or goal).
103106
104107In the wildcard case (`*`), filter out all dependent and/or non-Prop hypotheses. -/
108+ -- Assumes `proc` is not surrounded by backticks itself.
105109def transformAtNondepPropLocation (m : Expr → ReaderT Simp.Context MetaM Simp.Result)
106110 (proc : String) (loc : Location) (failIfUnchanged : Bool := true )
107111 (mayCloseGoalFromHyp : Bool := false )
@@ -112,6 +116,6 @@ def transformAtNondepPropLocation (m : Expr → ReaderT Simp.Context MetaM Simp.
112116 withNondepPropLocation loc
113117 (liftMetaTactic1 ∘ (transformAtLocalDecl m proc failIfUnchanged mayCloseGoalFromHyp · · ctx))
114118 (liftMetaTactic1 (transformAtTarget m proc failIfUnchanged · ctx))
115- fun _ ↦ throwError "{proc} made no progress anywhere"
119+ fun _ ↦ throwError "` {proc}` made no progress anywhere"
116120
117121end Mathlib.Tactic
0 commit comments