aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib/future.ml5
-rw-r--r--lib/future.mli2
-rw-r--r--library/states.ml2
-rw-r--r--library/states.mli7
-rw-r--r--plugins/funind/invfun.ml2
-rw-r--r--plugins/funind/recdef.ml3
6 files changed, 18 insertions, 3 deletions
diff --git a/lib/future.ml b/lib/future.ml
index 1e9cada51..d8f7b3a94 100644
--- a/lib/future.ml
+++ b/lib/future.ml
@@ -111,6 +111,11 @@ let purify f x =
v
with e -> let e = Errors.push e in !unfreeze state; raise e
+let transactify f x =
+ let state = !freeze () in
+ try f x
+ with e -> let e = Errors.push e in !unfreeze state; raise e
+
let purify_future f x =
match !x with
| Val _ | Exn _ | Delegated | Dropped -> f x
diff --git a/lib/future.mli b/lib/future.mli
index 39be0c180..f07d325e0 100644
--- a/lib/future.mli
+++ b/lib/future.mli
@@ -59,4 +59,6 @@ val set_freeze : (unit -> Dyn.t) -> (Dyn.t -> unit) -> unit
(* Once set_freeze is called we can purify a computation *)
val purify : ('a -> 'b) -> 'a -> 'b
+(* And also let a function alter the state but backtrack if it raises exn *)
+val transactify : ('a -> 'b) -> 'a -> 'b
diff --git a/library/states.ml b/library/states.ml
index a06e7ce80..ea4e7d43c 100644
--- a/library/states.ml
+++ b/library/states.ml
@@ -39,4 +39,4 @@ let with_state_protection f x =
with reraise ->
(unfreeze st; raise reraise)
-
+let with_state_protection_on_exception = Future.transactify
diff --git a/library/states.mli b/library/states.mli
index 0babae6af..fae1bfc02 100644
--- a/library/states.mli
+++ b/library/states.mli
@@ -27,3 +27,10 @@ val unfreeze : state -> unit
val with_state_protection : ('a -> 'b) -> 'a -> 'b
+(** [with_state_protection_on_exception f x] applies [f] to [x] and restores the
+ state of the whole system as it was before applying [f] only if an
+ exception is raised. Unlike [with_state_protection] it also takes into
+ account the proof state *)
+
+val with_state_protection_on_exception : ('a -> 'b) -> 'a -> 'b
+
diff --git a/plugins/funind/invfun.ml b/plugins/funind/invfun.ml
index bac3ad45f..00a44888f 100644
--- a/plugins/funind/invfun.ml
+++ b/plugins/funind/invfun.ml
@@ -1015,7 +1015,7 @@ let do_save () = Lemmas.save_named false
let derive_correctness make_scheme functional_induction (funs: constant list) (graphs:inductive list) =
let funs = Array.of_list funs and graphs = Array.of_list graphs in
let funs_constr = Array.map mkConst funs in
- States.with_state_protection (fun () ->
+ States.with_state_protection_on_exception (fun () ->
let graphs_constr = Array.map mkInd graphs in
let lemmas_types_infos =
Util.Array.map2_i
diff --git a/plugins/funind/recdef.ml b/plugins/funind/recdef.ml
index 7fbc1b981..831fab633 100644
--- a/plugins/funind/recdef.ml
+++ b/plugins/funind/recdef.ml
@@ -1262,6 +1262,7 @@ let open_new_goal (build_proof:tactic -> tactic -> unit) using_lemmas ref_ goal_
ref_ := Some lemma ;
let lid = ref [] in
let h_num = ref (-1) in
+ Proof_global.discard_all ();
build_proof
( fun gls ->
let hid = next_ident_away_in_goal h_id (pf_ids_of_hyps gls) in
@@ -1512,7 +1513,7 @@ let recursive_definition is_mes function_name rec_impls type_of_f r rec_arg_num
spc () ++ str"is defined" )
)
in
- States.with_state_protection (fun () ->
+ States.with_state_protection_on_exception (fun () ->
com_terminate
tcc_lemma_name
tcc_lemma_constr