Skip to content

Commit 91452e1

Browse files
committed
feat: make grind +premises more robust to bad suggestions
1 parent 808d123 commit 91452e1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Lean/Elab/Tactic/Grind/Main.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ def elabGrindParams
120120
| none => pure <| .ematch (.default false)
121121
match attr with
122122
| .ematch kind =>
123-
params ← addEMatchTheorem params (mkIdent p.name) p.name kind false
123+
try
124+
params ← addEMatchTheorem params (mkIdent p.name) p.name kind false (warn := false)
125+
catch _ => pure () -- Don't worry if premise suggestion gave bad suggetions.
124126
| _ =>
125127
-- We could actually support arbitrary grind modifiers,
126128
-- and call `processParam` rather than `addEMatchTheorem`,

tests/lean/run/grind_premises.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,19 @@ set_premise_selector (fun _ _ => pure #[{ name := `p, score := 1.0 }])
3838

3939
example : P 7 := by
4040
grind +premises
41+
42+
set_premise_selector (fun _ _ => pure #[{ name := `List.append_assoc, score := 1.0 }])
43+
44+
-- Make sure there is no warning about the redundant theorem.
45+
#guard_msgs in
46+
example (x y z : List Nat) : x ++ (y ++ z) = (x ++ y) ++ z := by
47+
grind +premises
48+
49+
theorem f : True := trivial
50+
51+
set_premise_selector (fun _ _ => pure #[{ name := `f, score := 1.0 }])
52+
53+
-- Make sure that bad suggestions (e.g. not patterns) from premise selection are dropped silently.
54+
#guard_msgs in
55+
example (x y z : List Nat) : x ++ (y ++ z) = (x ++ y) ++ z := by
56+
grind +premises

0 commit comments

Comments
 (0)