Skip to content

Commit 881c910

Browse files
leodemouraluisacicolini
authored andcommitted
feat: add %reset_grind_attrs (leanprover#6824)
This PR introduces the auxiliary command `%reset_grind_attrs` for debugging purposes. It is particularly useful for writing self-contained tests.
1 parent 5285bc7 commit 881c910

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

src/Init/Grind/Tactics.lean

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ Authors: Leonardo de Moura
66
prelude
77
import Init.Tactics
88

9-
namespace Lean.Parser.Attr
9+
namespace Lean.Parser
10+
/--
11+
Reset all `grind` attributes. This command is intended for testing purposes only and should not be used in applications.
12+
-/
13+
syntax (name := resetGrindAttrs) "%reset_grind_attrs" : command
1014

15+
namespace Attr
1116
syntax grindEq := "= "
1217
syntax grindEqBoth := atomic("_" "=" "_ ")
1318
syntax grindEqRhs := atomic("=" "_ ")
@@ -17,12 +22,10 @@ syntax grindFwd := "→ "
1722
syntax grindUsr := &"usr "
1823
syntax grindCases := &"cases "
1924
syntax grindCasesEager := atomic(&"cases" &"eager ")
20-
2125
syntax grindMod := grindEqBoth <|> grindEqRhs <|> grindEq <|> grindEqBwd <|> grindBwd <|> grindFwd <|> grindUsr <|> grindCasesEager <|> grindCases
22-
2326
syntax (name := grind) "grind" (grindMod)? : attr
24-
25-
end Lean.Parser.Attr
27+
end Attr
28+
end Lean.Parser
2629

2730
namespace Lean.Grind
2831
/--

src/Lean/Elab/Tactic/Grind.lean

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def elabGrindPattern : CommandElab := fun stx => do
3535
Grind.addEMatchTheorem declName xs.size patterns.toList .user
3636
| _ => throwUnsupportedSyntax
3737

38+
open Command in
39+
@[builtin_command_elab Lean.Parser.resetGrindAttrs]
40+
def elabResetGrindAttrs : CommandElab := fun _ => liftTermElabM do
41+
Grind.resetCasesExt
42+
Grind.resetEMatchTheoremsExt
43+
3844
open Command Term in
3945
@[builtin_command_elab Lean.Parser.Command.initGrindNorm]
4046
def elabInitGrindNorm : CommandElab := fun stx =>

src/Lean/Meta/Tactic/Grind/Cases.lean

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ builtin_initialize casesExt : SimpleScopedEnvExtension CasesEntry CasesTypes ←
6060
addEntry := fun s {declName, eager} => s.insert declName eager
6161
}
6262

63+
def resetCasesExt : CoreM Unit := do
64+
modifyEnv fun env => casesExt.modifyState env fun _ => {}
65+
6366
def getCasesTypes : CoreM CasesTypes :=
6467
return casesExt.getState (← getEnv)
6568

src/Lean/Meta/Tactic/Grind/EMatchTheorem.lean

+3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ private builtin_initialize ematchTheoremsExt : SimpleScopedEnvExtension EMatchTh
224224
initial := {}
225225
}
226226

227+
def resetEMatchTheoremsExt : CoreM Unit := do
228+
modifyEnv fun env => ematchTheoremsExt.modifyState env fun _ => {}
229+
227230
/--
228231
Symbols with built-in support in `grind` are unsuitable as pattern candidates for E-matching.
229232
This is because `grind` performs normalization operations and uses specialized data structures

tests/lean/run/grind_trace.lean

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
%reset_grind_attrs
2+
13
attribute [grind =] List.length_cons
24
attribute [grind →] List.getElem?_eq_getElem
35
attribute [grind =] List.length_replicate
@@ -92,3 +94,12 @@ error: `And` is marked as a built-in case-split for `grind` and cannot be erased
9294
#guard_msgs (error) in
9395
example : p ∧ q → p := by
9496
grind [-And]
97+
98+
example : (List.replicate n a)[m]? = if m < n then some a else none := by
99+
grind?
100+
101+
%reset_grind_attrs
102+
103+
example : (List.replicate n a)[m]? = if m < n then some a else none := by
104+
fail_if_success grind?
105+
sorry

0 commit comments

Comments
 (0)