fix: backtrack Term.State at TacticM
It contains references to metavariables that are declared in the backtracked `MCtx`
This commit is contained in:
parent
27c495c198
commit
51e7aa8b75
1 changed files with 5 additions and 1 deletions
|
|
@ -34,17 +34,21 @@ instance : Inhabited State := ⟨{ goals := [] }⟩
|
|||
structure BacktrackableState :=
|
||||
(env : Environment)
|
||||
(mctx : MetavarContext)
|
||||
(term : Term.State)
|
||||
(goals : List MVarId)
|
||||
|
||||
abbrev TacticM := ReaderT Context $ StateRefT State TermElabM
|
||||
abbrev Tactic := Syntax → TacticM Unit
|
||||
|
||||
def saveBacktrackableState : TacticM BacktrackableState := do
|
||||
pure { env := (← getEnv), mctx := (← getMCtx), goals := (← get).goals }
|
||||
pure { env := (← getEnv), mctx := (← getMCtx), term := (← getThe Term.State), goals := (← get).goals }
|
||||
|
||||
def BacktrackableState.restore (b : BacktrackableState) : TacticM Unit := do
|
||||
setEnv b.env
|
||||
setMCtx b.mctx
|
||||
let msgLog ← Term.getMessageLog -- we do not backtrack the message log
|
||||
set b.term
|
||||
Term.setMessageLog msgLog
|
||||
modify fun s => { s with goals := b.goals }
|
||||
|
||||
@[inline] protected def tryCatch {α} (x : TacticM α) (h : Exception → TacticM α) : TacticM α := do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue