Skip to content

Commit a531a74

Browse files
committed
feat: add checkTactic action
1 parent 2a2a3d8 commit a531a74

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ def liftSearchM (k : SearchM α) : GrindTacticM α := do
344344
def GrindTacticM.run (x : GrindTacticM α) (ctx : Context) (s : State) : TermElabM (α × State) :=
345345
x ctx |>.run s
346346

347-
def mkEvalTactic (params : Params) : TacticM (Goal → TSyntax `grind → GrindM (List Goal)) := do
348-
let elaborator := (← read).elaborator
347+
def mkEvalTactic' (elaborator : Name) (params : Params) : TermElabM (Goal → TSyntax `grind → GrindM (List Goal)) := do
349348
let termState ← getThe Term.State
350349
let termCtx ← readThe Term.Context
351350
let eval (goal : Goal) (stx : TSyntax `grind) : GrindM (List Goal) := do
@@ -364,6 +363,9 @@ def mkEvalTactic (params : Params) : TacticM (Goal → TSyntax `grind → GrindM
364363
return subgoals
365364
return eval
366365

366+
def mkEvalTactic (params : Params) : TacticM (Goal → TSyntax `grind → GrindM (List Goal)) := do
367+
mkEvalTactic' (← read).elaborator params
368+
367369
def GrindTacticM.runAtGoal (mvarId : MVarId) (params : Params) (k : GrindTacticM α) : TacticM (α × State) := do
368370
let evalTactic ← mkEvalTactic params
369371
let (methods, ctx, state) ← liftMetaM <| GrindM.runAtGoal mvarId params (evalTactic? := some evalTactic) fun goal => do

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ A terminal action which closes the goal or not.
247247
This kind of action may make progress, but we only include `mkTac` into the resulting tactic sequence
248248
if it closed the goal.
249249
-/
250-
public def terminalAction (check : GoalM Bool) (mkTac : GrindM (TSyntax `grind)) : Action := fun goal kna kp => do
250+
def terminalAction (check : GoalM Bool) (mkTac : GrindM (TSyntax `grind)) : Action := fun goal kna kp => do
251251
let (progress, goal') ← GoalM.run goal check
252252
if progress then
253253
if goal'.inconsistent then
@@ -257,6 +257,24 @@ public def terminalAction (check : GoalM Bool) (mkTac : GrindM (TSyntax `grind))
257257
else
258258
kna goal'
259259

260+
/--
261+
Helper action that checks whether the resulting tactic script produced by its continuation
262+
can close the original goal.
263+
-/
264+
def checkTactic : Action := fun goal _ kp => do
265+
let s ← saveState
266+
let r ← kp goal
267+
match r with
268+
| .closed seq =>
269+
let tac ← mkGrindNext seq
270+
Lean.withoutModifyingState do
271+
s.restore
272+
let subgoals ← evalTactic goal tac
273+
unless subgoals.isEmpty do
274+
throwError "generated tactic cannot close the goal{indentD tac}\nInitial goal\n{goal.mvarId}\nPending subgoals\n{subgoals.map (·.mvarId)}"
275+
return r
276+
| _ => return r
277+
260278
section
261279
/-!
262280
Some sanity check properties.

0 commit comments

Comments
 (0)