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
Instances For
If the goal is already inconsistent, returns .closed []. Otherwise, executes
then not applicable continuation.
Equations
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
Instances For
Choice: tries x, if not applicable, tries y.
Equations
Instances For
Repeats x up to n times while it remains applicable.
Equations
Instances For
Runs action a on the given goal.
Equations
Instances For
TSyntax `grind => TSyntax `Lean.Parser.Tactic.Grind.grindStep
Equations
Instances For
Equations
Instances For
If tracing is enabled and continuation produced .closed [t₁, ..., tₙ],
returns the singleton sequence [t] where t is
· t₁
...
tₙ
Equations
Instances For
If tracing is enabled and continuation produced .closed [(next => t₁; ...; tₙ)] or its variant using ·
returns .close [t₁, ... tₙ]
Equations
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
Instances For
Equations
Instances For
Returns true if the tactic sequence seq closes goal starting at saved state s?.
If s? is none just returns true.
Equations
Instances For
Helper action that checks whether the resulting tactic script produced by its continuation
can close the original goal.
If warnOnly = true, just generates a warning message instead of an error
Equations
Instances For
Helper action for satellite solvers that use CheckResult.
Equations
Instances For
Some sanity check properties.