File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
src/Lean/Meta/Tactic/Grind Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,9 @@ structure State where
219219 -/
220220 anchors : PHashMap ExprPtr UInt64 := {}
221221
222+ instance : Nonempty State :=
223+ .intro {}
224+
222225private opaque MethodsRefPointed : NonemptyType.{0 }
223226def MethodsRef : Type := MethodsRefPointed.type
224227instance : Nonempty MethodsRef := by exact MethodsRefPointed.property
@@ -228,6 +231,26 @@ abbrev GrindM := ReaderT MethodsRef $ ReaderT Context $ StateRefT State MetaM
228231@[inline] def mapGrindM [MonadControlT GrindM m] [Monad m] (f : {α : Type } → GrindM α → GrindM α) {α} (x : m α) : m α :=
229232 controlAt GrindM fun runInBase => f <| runInBase x
230233
234+ /--
235+ Backtrackable state for the `GrindM` monad.
236+ -/
237+ structure SavedState where
238+ «meta » : Meta.SavedState
239+ grind : State
240+ deriving Nonempty
241+
242+ protected def saveState : GrindM SavedState :=
243+ return { «meta » := (← Meta.saveState), grind := (← get) }
244+
245+ /-- Restore backtrackable parts of the state. -/
246+ def SavedState.restore (b : SavedState) : GrindM Unit := do
247+ b.meta.restore
248+ set b.grind
249+
250+ instance : MonadBacktrack SavedState GrindM where
251+ saveState := Grind.saveState
252+ restoreState s := s.restore
253+
231254/--
232255`withoutReportingMVarIssues x` executes `x` without reporting metavariables found during internalization.
233256See comment at `Grind.Context.reportMVarIssue` for additional details.
You can’t perform that action at this time.
0 commit comments