| 1 |
(* Code by Jason Gross for COQBUG 4637: vm_compute in _ makes Defined slow *) |
| 2 |
|
| 3 |
(** First, work around COQBUG 4494, https://coq.inria.fr/bugs/show_bug.cgi?id=4494 (replace is slow and broken under binders *) |
| 4 |
Ltac replace_with_at_by x y set_tac tac := |
| 5 |
let H := fresh in |
| 6 |
let x' := fresh in |
| 7 |
set_tac x' x; |
| 8 |
assert (H : y = x') by (subst x'; tac); |
| 9 |
clearbody x'; induction H. |
| 10 |
|
| 11 |
Ltac replace_with_at x y set_tac := |
| 12 |
let H := fresh in |
| 13 |
let x' := fresh in |
| 14 |
set_tac x' x; |
| 15 |
cut (y = x'); |
| 16 |
[ intro H; induction H |
| 17 |
| subst x' ]. |
| 18 |
|
| 19 |
Ltac replace_with_vm_compute c := |
| 20 |
let c' := (eval vm_compute in c) in |
| 21 |
(* we'd like to just do: *) |
| 22 |
(* replace c with c' by (clear; abstract (vm_compute; reflexivity)) *) |
| 23 |
(* but [set] is too slow in 8.4, so we write our own version (see COQBUG https://coq.inria.fr/bugs/show_bug.cgi?id=3280#c13 *) |
| 24 |
let set_tac := (fun x' x |
| 25 |
=> pose x as x'; |
| 26 |
change x with x') in |
| 27 |
replace_with_at_by c c' set_tac ltac:(clear; vm_cast_no_check (eq_refl c')). |
| 28 |
|
| 29 |
Ltac replace_with_vm_compute_in c H := |
| 30 |
let c' := (eval vm_compute in c) in |
| 31 |
(* By constrast [set ... in ...] seems faster than [change .. with ... in ...] in 8.4?! *) |
| 32 |
replace_with_at_by c c' ltac:(fun x' x => set (x' := x) in H ) ltac:(clear; vm_cast_no_check (eq_refl c')). |