Skip to content

Commit 91faf10

Browse files
committed
feat: rename show_splits and show_thms
1 parent 904b3e7 commit 91faf10

File tree

3 files changed

+43
-53
lines changed

3 files changed

+43
-53
lines changed

src/Init/Grind/Interactive.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ syntax (name := showFalse) "show_false" ppSpace grindFilter : grind
7878
/-- Shows equivalence classes of terms. -/
7979
syntax (name := showEqcs) "show_eqcs" ppSpace grindFilter : grind
8080
/-- Show case-split candidates. -/
81-
syntax (name := showSplits) "show_splits" ppSpace grindFilter : grind
81+
syntax (name := showCases) "show_cases" ppSpace grindFilter : grind
8282
/-- Show `grind` state. -/
8383
syntax (name := «showState») "show_state" ppSpace grindFilter : grind
8484
/-- Show active local theorems and their anchors for heuristic instantiation. -/
85-
syntax (name := showThms) "show_thms" : grind
85+
syntax (name := showLocalThms) "show_local_thms" : grind
8686

8787
declare_syntax_cat grind_ref (behavior := both)
8888

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

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ def ppAsserted? (filter : Filter) (collapsed := false) : GrindTacticM (Option Me
2121
return some <| Grind.ppExprArray `facts "Asserted facts" facts (collapsed := collapsed)
2222

2323
@[builtin_grind_tactic showAsserted] def evalShowAsserted : GrindTactic := fun stx => withMainContext do
24-
match stx with
25-
| `(grind| show_asserted $[$filter?]?) =>
26-
let filter ← elabFilter filter?
27-
let some msg ← ppAsserted? filter | throwError "no facts"
28-
logInfo msg
29-
| _ => throwUnsupportedSyntax
24+
let `(grind| show_asserted $[$filter?]?) := stx | throwUnsupportedSyntax
25+
let filter ← elabFilter filter?
26+
let some msg ← ppAsserted? filter | throwError "no facts"
27+
logInfo msg
3028

3129
def ppProps? (filter : Filter) (isTrue : Bool) (collapsed := false) : GrindTacticM (Option MessageData) := do
3230
let props ← liftGoalM do
@@ -43,14 +41,12 @@ def showProps (filter? : Option (TSyntax `grind_filter)) (isTrue : Bool) : Grind
4341
logInfo msg
4442

4543
@[builtin_grind_tactic showTrue] def evalShowTrue : GrindTactic := fun stx => do
46-
match stx with
47-
| `(grind| show_true $[$filter?]?) => showProps filter? true
48-
| _ => throwUnsupportedSyntax
44+
let `(grind| show_true $[$filter?]?) := stx | throwUnsupportedSyntax
45+
showProps filter? true
4946

5047
@[builtin_grind_tactic showFalse] def evalShowFalse : GrindTactic := fun stx => do
51-
match stx with
52-
| `(grind| show_false $[$filter?]?) => showProps filter? false
53-
| _ => throwUnsupportedSyntax
48+
let `(grind| show_false $[$filter?]?) := stx | throwUnsupportedSyntax
49+
showProps filter? false
5450

5551
def ppEqcs? (filter : Filter) (collapsed := false) : GrindTacticM (Option MessageData) := liftGoalM do
5652
let mut regularEqcs : Array MessageData := #[]
@@ -88,42 +84,36 @@ def ppEqcs? (filter : Filter) (collapsed := false) : GrindTacticM (Option Messag
8884
return MessageData.trace { cls := `eqc, collapsed } "Equivalence classes" regularEqcs
8985

9086
@[builtin_grind_tactic showEqcs] def evalShowEqcs : GrindTactic := fun stx => withMainContext do
91-
match stx with
92-
| `(grind| show_eqcs $[$filter?]?) =>
93-
let filter ← elabFilter filter?
94-
let some msg ← ppEqcs? filter | throwError "no equivalence classes"
95-
logInfo msg
96-
| _ => throwUnsupportedSyntax
87+
let `(grind| show_eqcs $[$filter?]?) := stx | throwUnsupportedSyntax
88+
let filter ← elabFilter filter?
89+
let some msg ← ppEqcs? filter | throwError "no equivalence classes"
90+
logInfo msg
9791

9892
def pushIfSome (msgs : Array MessageData) (msg? : Option MessageData) : Array MessageData :=
9993
if let some msg := msg? then msgs.push msg else msgs
10094

10195
@[builtin_grind_tactic showState] def evalShowState : GrindTactic := fun stx => withMainContext do
102-
match stx with
103-
| `(grind| show_state $[$filter?]?) =>
104-
let filter ← elabFilter filter?
105-
let msgs := #[]
106-
let msgs := pushIfSome msgs (← ppAsserted? filter (collapsed := true))
107-
let msgs := pushIfSome msgs (← ppProps? filter true (collapsed := false))
108-
let msgs := pushIfSome msgs (← ppProps? filter false (collapsed := false))
109-
let msgs := pushIfSome msgs (← ppEqcs? filter (collapsed := false))
110-
logInfo <| MessageData.trace { cls := `grind, collapsed := false } "Grind state" msgs
111-
| _ => throwUnsupportedSyntax
96+
let `(grind| show_state $[$filter?]?) := stx | throwUnsupportedSyntax
97+
let filter ← elabFilter filter?
98+
let msgs := #[]
99+
let msgs := pushIfSome msgs (← ppAsserted? filter (collapsed := true))
100+
let msgs := pushIfSome msgs (← ppProps? filter true (collapsed := false))
101+
let msgs := pushIfSome msgs (← ppProps? filter false (collapsed := false))
102+
let msgs := pushIfSome msgs (← ppEqcs? filter (collapsed := false))
103+
logInfo <| MessageData.trace { cls := `grind, collapsed := false } "Grind state" msgs
112104

113-
@[builtin_grind_tactic showSplits] def evalShowSplits : GrindTactic := fun stx => withMainContext do
114-
match stx with
115-
| `(grind| show_splits $[$filter?]?) =>
116-
let filter ← elabFilter filter?
117-
let { candidates, numDigits } ← liftGoalM <| getSplitCandidateAnchors filter.eval
118-
if candidates.isEmpty then
119-
throwError "no case splits"
120-
let msgs := candidates.map fun { anchor, e, .. } =>
121-
.trace { cls := `split } m!"#{anchorToString numDigits anchor} := {e}" #[]
122-
let msg := MessageData.trace { cls := `splits, collapsed := false } "Case split candidates" msgs
123-
logInfo msg
124-
| _ => throwUnsupportedSyntax
105+
@[builtin_grind_tactic showCases] def evalShowCases : GrindTactic := fun stx => withMainContext do
106+
let `(grind| show_cases $[$filter?]?) := stx | throwUnsupportedSyntax
107+
let filter ← elabFilter filter?
108+
let { candidates, numDigits } ← liftGoalM <| getSplitCandidateAnchors filter.eval
109+
if candidates.isEmpty then
110+
throwError "no case splits"
111+
let msgs := candidates.map fun { anchor, e, .. } =>
112+
.trace { cls := `split } m!"#{anchorToString numDigits anchor} := {e}" #[]
113+
let msg := MessageData.trace { cls := `splits, collapsed := false } "Case split candidates" msgs
114+
logInfo msg
125115

126-
@[builtin_grind_tactic showThms] def evalShowThms : GrindTactic := fun _ => withMainContext do
116+
@[builtin_grind_tactic showLocalThms] def evalShowLocalThms : GrindTactic := fun _ => withMainContext do
127117
let goal ← getMainGoal
128118
let entries ← liftGrindM do
129119
let (found, entries) ← go {} {} goal.ematch.thms

tests/lean/run/grind_interactive.lean

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ trace: [splits] Case split candidates
179179
#guard_msgs (trace) in
180180
example (r p q : Prop) : p ∨ r → p ∨ q → p ∨ ¬q → ¬p ∨ q → ¬p ∨ ¬q → False := by
181181
grind =>
182-
show_splits
182+
show_cases
183183
sorry
184184

185185
/--
@@ -189,7 +189,7 @@ trace: [splits] Case split candidates
189189
-/
190190
example (r p q p₁ p₂ : Prop) : (p₁ → q) → p ∨ (q ∧ r) → p ∨ (p₁ ↔ p₂) → False := by
191191
grind =>
192-
show_splits
192+
show_cases
193193
sorry
194194

195195
def h (as : List Nat) :=
@@ -213,13 +213,13 @@ trace: [splits] Case split candidates
213213
example : h bs = 1 → h as ≠ 0 := by
214214
grind [h.eq_def] =>
215215
instantiate
216-
show_splits
216+
show_cases
217217
sorry
218218

219219
example : h bs = 1 → h as ≠ 0 := by
220220
grind [h.eq_def] =>
221221
instantiate
222-
show_splits
222+
show_cases
223223
cases #ec88
224224
instantiate
225225
focus instantiate
@@ -445,12 +445,12 @@ trace: [thms] Local theorems
445445
#guard_msgs in
446446
example : (∀ x, q x) → (∀ x, p x → p (f x)) → p x → p (f (f x)) := by
447447
grind =>
448-
show_thms
448+
show_local_thms
449449
instantiate #bfb8
450450

451451
example : (∀ x, q x) → (∀ x, p x → p (f x)) → p x → p (f (f x)) := by
452452
grind =>
453-
show_thms
453+
show_local_thms
454454
instantiate #bfb8
455455

456456
/-- error: no local theorems -/
@@ -495,9 +495,9 @@ example : (a : Point Nat) → p a → x ≠ y → False := by
495495
grind =>
496496
cases #6ccb
497497
instantiate pax
498-
show_splits
498+
show_cases
499499
rename_i y w _ -- Must reset cached anchors
500-
show_splits
500+
show_cases
501501
cases #e2a6
502502
all_goals sorry
503503

@@ -506,9 +506,9 @@ example : (a : Point Nat) → p a → x ≠ y → False := by
506506
grind =>
507507
cases #6ccb
508508
instantiate pax
509-
show_splits
509+
show_cases
510510
next y w _ =>
511-
show_splits
511+
show_cases
512512
cases #e2a6
513513
all_goals sorry
514514

0 commit comments

Comments
 (0)