Skip to content

Commit 86adc7b

Browse files
committed
feat: cdot tactic in grind iteractive mode
1 parent fc10fc3 commit 86adc7b

File tree

5 files changed

+53
-69
lines changed

5 files changed

+53
-69
lines changed

src/Init/Grind/Interactive.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ inaccessible names to the given names.
162162
-/
163163
syntax (name := next) "next " binderIdent* " => " grindSeq : grind
164164

165+
/--
166+
`· grindSeq` focuses on the main `grind` goal and tries to solve it using the given
167+
sequence of `grind` tactics.
168+
-/
169+
macro dot:patternIgnore("· " <|> ". ") s:grindSeq : grind => `(grind| next%$dot =>%$dot $s:grindSeq )
170+
165171
/--
166172
`any_goals tac` applies the tactic `tac` to every goal,
167173
concatenating the resulting goals for successful tactic applications.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,16 @@ def mkGrindSeq (s : List TGrind) : TSyntax ``Parser.Tactic.Grind.grindSeq :=
159159
/--
160160
Given `[t₁, ..., tₙ]`, returns
161161
```
162-
next =>
163-
t₁
162+
· t₁
164163
...
165164
tₙ
166165
```
167-
If the list is empty, it returns `next => done`.
166+
If the list is empty, it returns `· done`.
168167
-/
169168
def mkGrindNext (s : List TGrind) : CoreM TGrind := do
170169
let s ← if s == [] then pure [← `(grind| done)] else pure s
171170
let s := mkGrindSeq s
172-
`(grind| next => $s:grindSeq)
171+
`(grind| · $s:grindSeq)
173172

174173
/--
175174
Given `[t₁, ..., tₙ]`, returns
@@ -189,8 +188,7 @@ private def mkGrindParen (s : List TGrind) : CoreM TGrind := do
189188
If tracing is enabled and continuation produced `.closed [t₁, ..., tₙ]`,
190189
returns the singleton sequence `[t]` where `t` is
191190
```
192-
next =>
193-
t₁
191+
· t₁
194192
...
195193
tₙ
196194
```
@@ -205,7 +203,7 @@ def group : Action := fun goal _ kp => do
205203
return r
206204

207205
/--
208-
If tracing is enabled and continuation produced `.closed [(next => t₁; ...; tₙ)]`,
206+
If tracing is enabled and continuation produced `.closed [(next => t₁; ...; tₙ)]` or its variant using `·`
209207
returns `.close [t₁, ... tₙ]`
210208
-/
211209
def ungroup : Action := fun goal _ kp => do
@@ -214,7 +212,9 @@ def ungroup : Action := fun goal _ kp => do
214212
match r with
215213
| .closed [tac] =>
216214
match tac with
217-
| `(grind| next => $seq;*) => return .closed <| seq.getElems.toList.map TGrindStep.getTactic
215+
| `(grind| next => $seq;*)
216+
| `(grind| · $seq;*) =>
217+
return .closed <| seq.getElems.toList.map TGrindStep.getTactic
218218
| _ => return r
219219
| _ => return r
220220
else

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ where
322322
private def isCompressibleSeq (seq : List (TSyntax `grind)) : Bool :=
323323
seq.all fun tac => match tac with
324324
| `(grind| next $_* => $_:grindSeq) => false
325+
| `(grind| · $_:grindSeq) => false
325326
| _ => true
326327

327328
/--

tests/lean/run/grind_finish_trace.lean

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ example {α : Type} [CommRing α] (a b c d e : α) :
1717
info: Try this:
1818
[apply]
1919
cases #b0f4
20-
next => cases #50fc
21-
next => cases #50fc <;> lia
20+
· cases #50fc
21+
· cases #50fc <;> lia
2222
-/
2323
#guard_msgs in
2424
example (p : Nat → Prop) (x y z w : Int) :
@@ -65,14 +65,12 @@ set_option warn.sorry false
6565
info: Try this:
6666
[apply]
6767
cases #c4b6
68-
next =>
69-
cases #8c9f
70-
next => ring
71-
next => sorry
72-
next =>
73-
cases #8c9f
74-
next => ring
75-
next => sorry
68+
· cases #8c9f
69+
· ring
70+
· sorry
71+
· cases #8c9f
72+
· ring
73+
· sorry
7674
-/
7775
#guard_msgs in
7876
example {α : Type} [CommRing α] (a b c d e : α) :
@@ -86,8 +84,8 @@ info: Try this:
8684
[apply]
8785
instantiate only [= Nat.min_def]
8886
cases #7640
89-
next => sorry
90-
next => lia
87+
· sorry
88+
· lia
9189
-/
9290
#guard_msgs in
9391
example (as : Array α) (lo hi i j : Nat) (h₁ : lo ≤ i) (_ : i < j) (_ : j ≤ hi) (_ : j < as.size)

tests/lean/run/grind_indexmap_trace.lean

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,18 @@ info: Try this:
149149
instantiate only [= mem_indices_of_mem, insert]
150150
instantiate only [=_ HashMap.contains_iff_mem, = getElem?_neg, = getElem?_pos]
151151
cases #4ed2
152-
next =>
153-
cases #ffdf
154-
next => instantiate only
155-
next =>
156-
instantiate only
152+
· cases #ffdf
153+
· instantiate only
154+
· instantiate only
157155
instantiate only [= HashMap.contains_insert]
158-
next =>
159-
cases #95a0
160-
next =>
161-
cases #2688
162-
next => instantiate only
163-
next =>
164-
instantiate only
156+
· cases #95a0
157+
· cases #2688
158+
· instantiate only
159+
· instantiate only
165160
instantiate only [= HashMap.contains_insert]
166-
next =>
167-
cases #ffdf
168-
next => instantiate only
169-
next =>
170-
instantiate only
161+
· cases #ffdf
162+
· instantiate only
163+
· instantiate only
171164
instantiate only [= HashMap.contains_insert]
172165
-/
173166
#guard_msgs in
@@ -181,25 +174,18 @@ info: Try this:
181174
instantiate only [= mem_indices_of_mem, insert]
182175
instantiate only [=_ HashMap.contains_iff_mem, = getElem?_neg, = getElem?_pos]
183176
cases #4ed2
184-
next =>
185-
cases #ffdf
186-
next => instantiate only
187-
next =>
188-
instantiate only
177+
· cases #ffdf
178+
· instantiate only
179+
· instantiate only
189180
instantiate only [= HashMap.contains_insert]
190-
next =>
191-
cases #95a0
192-
next =>
193-
cases #2688
194-
next => instantiate only
195-
next =>
196-
instantiate only
181+
· cases #95a0
182+
· cases #2688
183+
· instantiate only
184+
· instantiate only
197185
instantiate only [= HashMap.contains_insert]
198-
next =>
199-
cases #ffdf
200-
next => instantiate only
201-
next =>
202-
instantiate only
186+
· cases #ffdf
187+
· instantiate only
188+
· instantiate only
203189
instantiate only [= HashMap.contains_insert]
204190
-/
205191
#guard_msgs in
@@ -240,25 +226,19 @@ info: Try this:
240226
instantiate only [= mem_indices_of_mem, insert, = getElem_def]
241227
instantiate only [= getElem?_neg, = getElem?_pos]
242228
cases #f590
243-
next =>
244-
cases #ffdf
245-
next =>
246-
instantiate only
229+
· cases #ffdf
230+
· instantiate only
247231
instantiate only [= Array.getElem_set]
248-
next =>
249-
instantiate only
232+
· instantiate only
250233
instantiate only [size, = HashMap.mem_insert, = HashMap.getElem_insert, = Array.getElem_push]
251-
next =>
252-
instantiate only [= mem_indices_of_mem, = getElem_def]
234+
· instantiate only [= mem_indices_of_mem, = getElem_def]
253235
instantiate only [usr getElem_indices_lt]
254236
instantiate only [size]
255237
cases #ffdf
256-
next =>
257-
instantiate only [=_ WF]
238+
· instantiate only [=_ WF]
258239
instantiate only [= getElem?_neg, = getElem?_pos, = Array.getElem_set]
259240
instantiate only [WF']
260-
next =>
261-
instantiate only
241+
· instantiate only
262242
instantiate only [= HashMap.mem_insert, = HashMap.getElem_insert, = Array.getElem_push]
263243
-/
264244
#guard_msgs in
@@ -300,9 +280,8 @@ info: Try this:
300280
instantiate only [findIdx, insert, = mem_indices_of_mem]
301281
instantiate only [= getElem?_neg, = getElem?_pos]
302282
cases #1bba
303-
next => instantiate only [findIdx]
304-
next =>
305-
instantiate only
283+
· instantiate only [findIdx]
284+
· instantiate only
306285
instantiate only [= HashMap.mem_insert, = HashMap.getElem_insert]
307286
-/
308287
#guard_msgs in

0 commit comments

Comments
 (0)