@@ -6,11 +6,37 @@ Authors: Leonardo de Moura
66module
77prelude
88public import Lean.Elab.Tactic.Grind.Basic
9+ import Init.Grind.Interactive
10+ import Lean.Meta.Tactic.TryThis
911import Lean.Meta.Tactic.Grind.Action
12+ import Lean.Meta.Tactic.Grind.EMatchAction
13+ import Lean.Meta.Tactic.Grind.Split
1014namespace Lean.Elab.Tactic.Grind
1115open Meta
1216open 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
1642end Lean.Elab.Tactic.Grind
0 commit comments