Action #
Action is the control interface for grind’s search steps. It is defined in
Continuation-Passing Style (CPS):
abbrev Action :=
Goal → (kna : Goal → GrindM ActionResult) → (kp : Goal → GrindM ActionResult) → GrindM ActionResult
An Action receives: the current Goal, a continuation kna to run when the action is not applicable,
and a continuation kp to run when it makes progress.
It returns an ActionResult:
.closed seq: the goal was fully solved, andseqis the sequence of tactics that, if replayed, closes the goal..stuck gs: search ran and got stuck at goalsgs. Remark: actions such assplitNextcan decide whether they stop at the first failure or not.
Why CPS? #
Two core requirements motivated CPS:
Non-chronological backtracking (NCB) for branching steps like
splitNext. A branching action must be able to run the full continuation on each subgoal and decide—based on the entire downstream proof whether the case split is actually needed or not. CPS gives the action visibility and control overkp.Tactic script generation. Some leaves (e.g.
ematch) should log only the facts/instantiations actually used by the final proof. Running the continuation first and then post-processing what happened lets an action commit exactly the steps that mattered.
Contract (what every Action must guarantee) #
Return exactly once. An action may call
kpzero or more times internally (e.g. once per branch), but it must eventually return a singleActionResult..stuck gand.closed seqreflect the final choice the action made after any internal calls tokp. Combinators reason only about this final result.When an action is not applicable, it must invoke
knaand perform no observable effects.
Why Action is not a Monad #
Although it looks like “a computation that can call a continuation”, Action
is a control operator, not a lawful monad:
Multi-shot continuations.
splitNextlegitimately callskpmultiple times (once per subgoal). Standardbindassumes a linear continuation. Duplicating the continuation breaks associativity (agreed?)Future inspection. Many actions decide what to keep/commit after seeing the entire result of
kp(e.g., the generated proof term). That is delimited control (callCC/handlers) rather than plain monadic sequencing. It seems overkill to usecallCChere.
Equations
- Lean.Meta.Grind.TGrindStep = Lean.TSyntax `Lean.Parser.Tactic.Grind.grindStep
Instances For
Equations
- (Lean.Meta.Grind.ActionResult.closed seq).toMessageData = Lean.toMessageData "closed " ++ Lean.toMessageData seq
- (Lean.Meta.Grind.ActionResult.stuck goals).toMessageData = Lean.toMessageData "stuck " ++ Lean.toMessageData (List.map (fun (x : Lean.Meta.Grind.Goal) => x.mvarId) goals)
Instances For
Equations
Equations
- Lean.Meta.Grind.Action.skip goal x✝ kp = kp goal
Instances For
If the goal is already inconsistent, returns .closed []. Otherwise, executes
then not applicable continuation.
Equations
- Lean.Meta.Grind.Action.done goal kna x✝ = if goal.inconsistent = true then pure (Lean.Meta.Grind.ActionResult.closed []) else kna goal
Instances For
x >> y, executes x and then y
- If
xis not applicable, thenx >> yis not applicable. - If
yis not applicable, it behaves like a skip.
Equations
- x.andThen y goal kna kp = x goal kna fun (goal' : Lean.Meta.Grind.Goal) => y goal' kp kp
Instances For
Equations
- Lean.Meta.Grind.Action.instAndThen = { andThen := fun (x : Lean.Meta.Grind.Action) (y : Unit → Lean.Meta.Grind.Action) => x.andThen (y ()) }
Choice: tries x, if not applicable, tries y.
Equations
- x.orElse y goal kna kp = x goal (fun (goal : Lean.Meta.Grind.Goal) => y goal kna kp) kp
Instances For
Equations
- Lean.Meta.Grind.Action.instOrElse = { orElse := fun (x : Lean.Meta.Grind.Action) (y : Unit → Lean.Meta.Grind.Action) => x.orElse (y ()) }
Repeats x up to n times while it remains applicable.
Equations
- Lean.Meta.Grind.Action.loop 0 x goal x✝ kp = kp goal
- Lean.Meta.Grind.Action.loop n_2.succ x goal x✝ kp = x goal kp fun (goal' : Lean.Meta.Grind.Goal) => Lean.Meta.Grind.Action.loop n_2 x goal' kp kp
Instances For
Runs action a on the given goal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
TSyntax `grind => TSyntax `Lean.Parser.Tactic.Grind.grindStep
Equations
- Lean.Meta.Grind.Action.mkGrindStep t = Lean.mkNode `Lean.Parser.Tactic.Grind.grindStep #[t.raw, Lean.mkNullNode]
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
If tracing is enabled and continuation produced .closed [t₁, ..., tₙ],
returns the singleton sequence [t] where t is
next =>
t₁
...
tₙ
Equations
- One or more equations did not get rendered due to their size.
Instances For
If tracing is enabled and continuation produced .closed [(next => t₁; ...; tₙ)],
returns .close [t₁, ... tₙ]
Equations
- One or more equations did not get rendered due to their size.
Instances For
Appends a new tactic syntax to a successful result.
Used by leaf actions to record the tactic that produced progress.
If (← getConfig).trace is false, it just returns r.
Equations
Instances For
Returns .closed [← mk] if tracing is enabled, and .closed [] otherwise.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A terminal action which closes the goal or not.
This kind of action may make progress, but we only include mkTac into the resulting tactic sequence
if it closed the goal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Helper action for satellite solvers that use CheckResult.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns true if the tactic sequence seq closes goal starting at saved state s?.
If s? is none just returns true.
Equations
- One or more equations did not get rendered due to their size.
- Lean.Meta.Grind.Action.checkSeqAt s? goal seq = pure true
Instances For
Helper action that checks whether the resulting tactic script produced by its continuation can close the original goal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Some sanity check properties.