Skip to content

Commit fc8304d

Browse files
committed
feat: finishTrace
1 parent 215a4e5 commit fc8304d

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,37 @@ Authors: Leonardo de Moura
66
module
77
prelude
88
public import Lean.Elab.Tactic.Grind.Basic
9+
import Init.Grind.Interactive
10+
import Lean.Meta.Tactic.TryThis
911
import Lean.Meta.Tactic.Grind.Action
12+
import Lean.Meta.Tactic.Grind.EMatchAction
13+
import Lean.Meta.Tactic.Grind.Split
1014
namespace Lean.Elab.Tactic.Grind
1115
open Meta
1216
open Meta.Grind
1317

18+
def withTracing (x : GrindTacticM α) : GrindTacticM α := do
19+
withReader (fun ctx => { ctx with ctx.config.trace := true }) x
1420

21+
def mkFinish (maxIterations : Nat) : IO Action := do
22+
let solvers ← Solvers.mkAction
23+
return Action.checkTactic >> (Action.done <|> solvers <|> Action.instantiate <|> Action.splitNext).loop maxIterations
24+
25+
def maxIterations := 1000 -- **TODO**: Add option
26+
27+
@[builtin_grind_tactic finishTrace] def evalFinishTrace : GrindTactic := fun stx => do
28+
let a ← mkFinish maxIterations
29+
let goal ← getMainGoal
30+
withTracing do
31+
match (← liftGrindM <| a.run goal) with
32+
| .closed seq =>
33+
replaceMainGoal []
34+
let seq := Action.mkGrindSeq seq
35+
Tactic.TryThis.addSuggestion stx { suggestion := .tsyntax seq }
36+
| .stuck gs =>
37+
let goal :: _ := gs | throwError "`finish?` failed, but resulting goal is not available"
38+
let params := (← read).params
39+
let result ← liftGrindM do mkResult params (some goal)
40+
throwError "`finish?` failed\n{← result.toMessageData}"
1541

1642
end Lean.Elab.Tactic.Grind

src/Lean/Meta/Tactic/Grind.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public import Lean.Meta.Tactic.Grind.Ctor
2424
public import Lean.Meta.Tactic.Grind.Parser
2525
public import Lean.Meta.Tactic.Grind.EMatchTheorem
2626
public import Lean.Meta.Tactic.Grind.EMatch
27-
public import Lean.Meta.Tactic.Grind.EMatchAction
2827
public import Lean.Meta.Tactic.Grind.Main
2928
public import Lean.Meta.Tactic.Grind.CasesMatch
3029
public import Lean.Meta.Tactic.Grind.Arith
@@ -44,9 +43,8 @@ public import Lean.Meta.Tactic.Grind.PropagateInj
4443
public import Lean.Meta.Tactic.Grind.Order
4544
public import Lean.Meta.Tactic.Grind.Anchor
4645
public import Lean.Meta.Tactic.Grind.Action
47-
46+
public import Lean.Meta.Tactic.Grind.EMatchAction
4847
public section
49-
5048
namespace Lean
5149

5250
/-! Trace options for `grind` users -/

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ Authors: Leonardo de Moura
66
module
77
prelude
88
public import Lean.Meta.Tactic.Grind.Action
9+
public import Lean.Meta.Tactic.Grind.Intro
910
import Lean.Meta.Tactic.Grind.EMatch
11+
public section
1012
namespace Lean.Meta.Grind.Action
1113

12-
def Action.instantiate : Action := fun goal kna kp => do
14+
def instantiate' : Action := fun goal kna kp => do
1315
let (progress, goal') ← GoalM.run goal ematch
1416
-- **TODO**: filter relevant instances
1517
if progress then
1618
concatTactic (← kp goal') `(grind| instantiate)
1719
else
1820
kna goal
1921

22+
def instantiate : Action :=
23+
instantiate' >> assertAll
24+
2025
end Lean.Meta.Grind.Action

0 commit comments

Comments
 (0)