File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -344,8 +344,7 @@ def liftSearchM (k : SearchM α) : GrindTacticM α := do
344344def 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+
367369def 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
Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ A terminal action which closes the goal or not.
247247This kind of action may make progress, but we only include `mkTac` into the resulting tactic sequence
248248if 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}\n Initial goal\n {goal.mvarId}\n Pending subgoals\n {subgoals.map (·.mvarId)}"
275+ return r
276+ | _ => return r
277+
260278section
261279/-!
262280Some sanity check properties.
You can’t perform that action at this time.
0 commit comments