fix: backtrack Term.State at TacticM

It contains references to metavariables that are declared in the
backtracked `MCtx`
This commit is contained in:
Leonardo de Moura 2020-11-03 15:38:53 -08:00
parent 27c495c198
commit 51e7aa8b75

View file

@ -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