Skip to content

Commit 6cc7c33

Browse files
committed
chore(AtLocation): clean up backtick handling
Make errors in AtLocation surround the tactic name with backticks by default. This fixes a few error messages to comply with mathlib's style guide. Extracted from leanprover-community#37899.
1 parent 0b45e16 commit 6cc7c33

5 files changed

Lines changed: 14 additions & 11 deletions

File tree

Mathlib/Tactic/Abel.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ elab (name := abelNF) "abel_nf" tk:"!"? cfg:optConfig loc:(location)? : tactic =
506506
let loc := (loc.map expandLocation).getD (.targets #[] true)
507507
let s ← IO.mkRef {}
508508
let m := AtomM.recurse s cfg.toConfig (wellBehavedDischarge := true) evalExpr (cleanup cfg)
509-
transformAtLocation (m ·) "`abel_nf`" loc (failIfUnchanged := true) false
509+
transformAtLocation (m ·) "abel_nf" loc (failIfUnchanged := true) false
510510

511511
@[tactic_alt abel]
512512
macro "abel_nf!" cfg:optConfig loc:(location)? : tactic =>

Mathlib/Tactic/FieldSimp.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,7 @@ elab (name := fieldSimp) "field_simp" d:(discharger)? args:(simpArgs)? loc:(loca
711711
let m := AtomM.recurse s { contextual := true } (wellBehavedDischarge := false)
712712
(fun e ↦ reduceProp disch e <|> reduceExpr disch e) cleanup
713713
let loc := (loc.map expandLocation).getD (.targets #[] true)
714-
transformAtLocation
715-
(m ·) "`field_simp`" (failIfUnchanged := true) (mayCloseGoalFromHyp := true) loc
714+
transformAtLocation (m ·) "field_simp" (failIfUnchanged := true) (mayCloseGoalFromHyp := true) loc
716715

717716
/--
718717
`field_simp` normalizes an expression in a (semi-)field by rewriting it to a common denominator,

Mathlib/Tactic/Push.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def elabDischarger (stx : TSyntax ``discharger) : TacticM Simp.Discharge :=
211211
def push (cfg : Config) (disch? : Option Simp.Discharge) (head : Head) (loc : Location)
212212
(failIfUnchanged : Bool := true) : TacticM Unit := do
213213
let cfg := { distrib := cfg.distrib || (← getBoolOption `push_neg.use_distrib) }
214-
transformAtLocation (pushCore head cfg disch? ·) "`push`" loc failIfUnchanged
214+
transformAtLocation (pushCore head cfg disch? ·) "push" loc failIfUnchanged
215215

216216
/--
217217
`push c` rewrites the goal by pushing the constant `c` deeper into an expression.
@@ -318,7 +318,7 @@ elab (name := pull) "pull" disch?:(discharger)? head:(ppSpace colGt term) loc:(l
318318
let disch? ← disch?.mapM elabDischarger
319319
let head ← elabHead head
320320
let loc := (loc.map expandLocation).getD (.targets #[] true)
321-
transformAtLocation (pullCore head · disch?) "`pull`" loc (failIfUnchanged := true) false
321+
transformAtLocation (pullCore head · disch?) "pull" loc (failIfUnchanged := true) false
322322

323323
/-- A simproc variant of `push fun _ ↦ _`, to be used as `simp [↓pushFun]`. -/
324324
simproc_decl _root_.pushFun (fun _ ↦ ?_) := pushStep .lambda {}

Mathlib/Tactic/Ring/RingNF.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ elab (name := ringNF) "ring_nf" tk:"!"? cfg:optConfig loc:(location)? : tactic =
138138
let loc := (loc.map expandLocation).getD (.targets #[] true)
139139
let s ← IO.mkRef {}
140140
let m := AtomM.recurse s cfg.toConfig (wellBehavedDischarge := true) evalExpr (cleanup cfg)
141-
transformAtLocation (m ·) "`ring_nf`" loc cfg.failIfUnchanged false
141+
transformAtLocation (m ·) "ring_nf" loc cfg.failIfUnchanged false
142142

143143
@[tactic_alt ringNF] macro "ring_nf!" cfg:optConfig loc:(location)? : tactic =>
144144
`(tactic| ring_nf ! $cfg:optConfig $(loc)?)

Mathlib/Util/AtLocation.lean

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace Mathlib.Tactic
4848
open Lean Meta Elab.Tactic
4949

5050
/-- Use the procedure `m` to rewrite the provided goal. -/
51+
-- Assumes `proc` is not surrounded by backticks itself.
5152
def 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
7172
The `simpTheorems` of the simp-context carried with `m` will be modified to remove `fvarId`;
7273
this 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.
7476
def 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.
9194
def 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
104107
In the wildcard case (`*`), filter out all dependent and/or non-Prop hypotheses. -/
108+
-- Assumes `proc` is not surrounded by backticks itself.
105109
def 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

117121
end Mathlib.Tactic

0 commit comments

Comments
 (0)