Skip to content

Commit 24d5e2d

Browse files
committed
chore(AtLocation): clean up backtick handling (#37999)
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 #37899.
1 parent 0446312 commit 24d5e2d

File tree

8 files changed

+27
-24
lines changed

8 files changed

+27
-24
lines changed

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: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def Lean.Elab.Tactic.withNondepPropLocation (loc : Location) (atLocal : FVarId
4747
namespace Mathlib.Tactic
4848
open Lean Meta Elab.Tactic
4949

50-
/-- Use the procedure `m` to rewrite the provided goal. -/
50+
/-- Use the procedure `m` to rewrite the provided goal.
51+
52+
Assumes `proc` is not surrounded by backticks. -/
5153
def transformAtTarget (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (proc : String)
5254
(failIfUnchanged : Bool) (goal : MVarId) :
5355
ReaderT Simp.Context MetaM (Option MVarId) := do
@@ -56,7 +58,7 @@ def transformAtTarget (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (pro
5658
-- we use expression equality here (rather than defeq) to be consistent with, e.g.,
5759
-- `applySimpResultToTarget`
5860
let unchanged := tgt.cleanupAnnotations == r.expr.cleanupAnnotations
59-
if failIfUnchanged && unchanged then throwError "{proc} made no progress on the goal"
61+
if failIfUnchanged && unchanged then throwError "`{proc}` made no progress on the goal"
6062
if r.expr.isTrue then
6163
goal.assign (← mkOfEqTrue (← r.getProof))
6264
pure none
@@ -70,24 +72,28 @@ def transformAtTarget (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (pro
7072
7173
The `simpTheorems` of the simp-context carried with `m` will be modified to remove `fvarId`;
7274
this ensures that if the procedure `m` involves rewriting by this `SimpTheoremsArray`, then, e.g.,
73-
`h : x = y` is not transformed (by rewriting `h`) to `True`. -/
75+
`h : x = y` is not transformed (by rewriting `h`) to `True`.
76+
77+
Assumes `proc` is not surrounded by backticks. -/
7478
def transformAtLocalDecl (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (proc : String)
7579
(failIfUnchanged : Bool) (mayCloseGoal : Bool) (fvarId : FVarId) (goal : MVarId) :
7680
ReaderT Simp.Context MetaM (Option MVarId) := do
7781
let ldecl ← fvarId.getDecl
7882
if ldecl.isImplementationDetail then
79-
throwError "Cannot run {proc} at {ldecl.userName}, it is an implementation detail"
83+
throwError "Cannot run `{proc}` at `{ldecl.userName}`, it is an implementation detail"
8084
let tgt ← instantiateMVars (← fvarId.getType)
8185
let eraseFVarId (ctx : Simp.Context) :=
8286
ctx.setSimpTheorems <| ctx.simpTheorems.eraseTheorem (.fvar fvarId)
8387
let r ← withReader eraseFVarId <| m tgt
8488
-- we use expression equality here (rather than defeq) to be consistent with, e.g.,
8589
-- `applySimpResultToLocalDeclCore`
8690
if failIfUnchanged && tgt.cleanupAnnotations == r.expr.cleanupAnnotations then
87-
throwError "{proc} made no progress at {ldecl.userName}"
91+
throwError "`{proc}` made no progress at `{ldecl.userName}`"
8892
return (← applySimpResultToLocalDecl goal fvarId r mayCloseGoal).map Prod.snd
8993

90-
/-- Use the procedure `m` to transform at specified locations (hypotheses and/or goal). -/
94+
/-- Use the procedure `m` to transform at specified locations (hypotheses and/or goal).
95+
96+
Assumes `proc` is not surrounded by backticks. -/
9197
def transformAtLocation (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (proc : String)
9298
(loc : Location) (failIfUnchanged : Bool := true) (mayCloseGoalFromHyp : Bool := false)
9399
-- streamline the most common use case, in which the procedure `m`'s implementation is not
@@ -97,11 +103,13 @@ def transformAtLocation (m : Expr → ReaderT Simp.Context MetaM Simp.Result) (p
97103
withLocation loc
98104
(liftMetaTactic1 ∘ (transformAtLocalDecl m proc failIfUnchanged mayCloseGoalFromHyp · · ctx))
99105
(liftMetaTactic1 (transformAtTarget m proc failIfUnchanged · ctx))
100-
fun _ ↦ throwError "{proc} made no progress anywhere"
106+
fun _ ↦ throwError "`{proc}` made no progress anywhere"
101107

102108
/-- Use the procedure `m` to transform at specified locations (hypotheses and/or goal).
103109
104-
In the wildcard case (`*`), filter out all dependent and/or non-Prop hypotheses. -/
110+
In the wildcard case (`*`), filter out all dependent and/or non-`Prop` hypotheses.
111+
112+
Assumes `proc` is not surrounded by backticks. -/
105113
def transformAtNondepPropLocation (m : Expr → ReaderT Simp.Context MetaM Simp.Result)
106114
(proc : String) (loc : Location) (failIfUnchanged : Bool := true)
107115
(mayCloseGoalFromHyp : Bool := false)
@@ -112,6 +120,6 @@ def transformAtNondepPropLocation (m : Expr → ReaderT Simp.Context MetaM Simp.
112120
withNondepPropLocation loc
113121
(liftMetaTactic1 ∘ (transformAtLocalDecl m proc failIfUnchanged mayCloseGoalFromHyp · · ctx))
114122
(liftMetaTactic1 (transformAtTarget m proc failIfUnchanged · ctx))
115-
fun _ ↦ throwError "{proc} made no progress anywhere"
123+
fun _ ↦ throwError "`{proc}` made no progress anywhere"
116124

117125
end Mathlib.Tactic

MathlibTest/abel.lean

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ error: `abel_nf` made no progress on the goal
9999
#guard_msgs in
100100
example : False := by abel_nf
101101

102-
/--
103-
error: `abel_nf` made no progress at w
104-
-/
102+
/-- error: `abel_nf` made no progress at `w` -/
105103
#guard_msgs in
106104
example [AddCommGroup α] (x y z : α) (w : x = y + z) : False := by
107105
abel_nf at w
@@ -141,9 +139,7 @@ example [AddCommGroup α] (x y z : α) (_w : x = y + z) : False := by
141139
example [AddCommGroup α] (x y z : α) (_w : x = y + z) : x - x = 0 := by
142140
abel_nf at *
143141

144-
/--
145-
error: `abel_nf` made no progress at w
146-
-/
142+
/-- error: `abel_nf` made no progress at `w` -/
147143
#guard_msgs in
148144
example [AddCommGroup α] (x y z : α) (w : x = y + z) : x - x = 0 := by
149145
abel_nf at w ⊢

MathlibTest/push_neg.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ example {P : Prop} (h : P) : P := by push Not at *
151151

152152
-- new behaviour as of https://github.com/leanprover-community/mathlib4/issues/27562
153153
-- (Previously, because of a metavariable instantiation issue, the tactic succeeded as a no-op.)
154-
/-- error: `push` made no progress at h -/
154+
/-- error: `push` made no progress at `h` -/
155155
#guard_msgs in
156156
example {x y : ℕ} : True := by
157157
have h : x ≤ y := test_sorry
158158
push Not at h
159159

160160
-- new behaviour as of https://github.com/leanprover-community/mathlib4/issues/27562 (previously the tactic succeeded as a no-op)
161-
/-- error: Cannot run `push` at inductive_proof, it is an implementation detail -/
161+
/-- error: Cannot run `push` at `inductive_proof`, it is an implementation detail -/
162162
#guard_msgs in
163163
def inductive_proof : True := by
164164
push Not at inductive_proof

MathlibTest/ring.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ example (n : ℤ) (r : ℝ) : n • r = n * r := by
243243

244244
-- new behaviour as of https://github.com/leanprover-community/mathlib4/issues/27562
245245
-- (Previously, because of a metavariable instantiation issue, the tactic succeeded as a no-op.)
246-
/-- error: `ring_nf` made no progress at h -/
246+
/-- error: `ring_nf` made no progress at `h` -/
247247
#guard_msgs in
248248
example {R : Type*} [CommSemiring R] {x y : R} : True := by
249249
have h : x + y = 3 := test_sorry

0 commit comments

Comments
 (0)