Skip to content

Commit 861ad0c

Browse files
committed
feat: improve error messages of tauto (#5965)
Modify `tauto` to throw an error message "tauto failed to solve some goals" if it fails.
1 parent a3b98ba commit 861ad0c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Mathlib/Lean/Elab/Tactic/Basic.lean

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/-
22
Copyright (c) 2023 Floris van Doorn. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Floris van Doorn
4+
Authors: Floris van Doorn, Jon Eugster
55
-/
66
import Mathlib.Lean.Meta
77
/-!
@@ -18,4 +18,27 @@ Remark: note that `MVarId.getType'` uses `whnf` instead of `cleanupAnnotations`,
1818
def getMainTarget'' : TacticM Expr := do
1919
(← getMainGoal).getType''
2020

21+
/--
22+
Like `done` but takes a scope (e.g. a tactic name) as an argument
23+
to produce more detailed error messages.
24+
-/
25+
def doneWithScope (scope : MessageData) : TacticM Unit := do
26+
let gs ← getUnsolvedGoals
27+
unless gs.isEmpty do
28+
logError m!"{scope} failed to solve some goals.\n"
29+
Term.reportUnsolvedGoals gs
30+
throwAbortTactic
31+
32+
/--
33+
Like `focusAndDone` but takes a scope (e.g. tactic name) as an argument to
34+
produce more detailed error messages.
35+
-/
36+
def focusAndDoneWithScope (scope : MessageData) (tactic : TacticM α) : TacticM α :=
37+
focus do
38+
let a ← try tactic catch e =>
39+
if isAbortTacticException e then throw e
40+
else throwError "{scope} failed.\n{← nestedExceptionToMessageData e}"
41+
doneWithScope scope
42+
pure a
43+
2144
end Lean.Elab.Tactic

Mathlib/Tactic/Tauto.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,13 @@ def finishingConstructorMatcher (e : Q(Prop)) : MetaM Bool :=
190190
| _ => pure false
191191

192192
/-- Implementation of the `tauto` tactic. -/
193-
def tautology : TacticM Unit := focus do
193+
def tautology : TacticM Unit := focusAndDoneWithScope "tauto" do
194194
evalTactic (← `(tactic| classical!))
195195
tautoCore
196196
allGoals (iterateUntilFailure
197197
(evalTactic (← `(tactic| rfl)) <|>
198198
evalTactic (← `(tactic| solve_by_elim)) <|>
199199
liftMetaTactic (constructorMatching · finishingConstructorMatcher)))
200-
done
201200

202201
/--
203202
`tauto` breaks down assumptions of the form `_ ∧ _`, `_ ∨ _`, `_ ↔ _` and `∃ _, _`

0 commit comments

Comments
 (0)