lean4-htt/tests/elab/grind_unused_lemmas.lean
Kim Morrison ada53633dc
feat: add grind.unusedLemmaThreshold option to report unused E-matching activations (#12805)
This PR adds a `set_option grind.unusedLemmaThreshold` that, when set to
N > 0
and `grind` succeeds, reports E-matching lemmas that were activated at
least N
times but do not appear in the final proof term. This helps identify
`@[grind]`
annotations that fire frequently without contributing to proofs.

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:57:37 +00:00

24 lines
741 B
Text

-- Test that grind.unusedLemmaThreshold reports activated but unused E-matching lemmas
def foo : Nat → Nat
| 0 => 1
| n + 1 => foo n + 1
@[grind =] theorem foo_zero : foo 0 = 1 := rfl
@[grind =] theorem foo_succ (n : Nat) : foo (n + 1) = foo n + 1 := rfl
@[grind =] theorem bar (n : Nat) : foo n + 0 = foo n := Nat.add_zero _
-- `bar` is activated but not used in the proof. With threshold=1, we get a warning.
/--
trace: [grind] grind: activated but unused E-matching lemmas
[thm] bar ↦ 1
-/
#guard_msgs in
set_option grind.unusedLemmaThreshold 1 in
example (n : Nat) (h : n = 0) : foo n = 1 := by
grind
-- Without the option (threshold=0), no warning.
#guard_msgs in
example (n : Nat) (h : n = 0) : foo n = 1 := by
grind