| 1 |
(** * Various variants on [reflexivity] and [abstract reflexivity] for evars *) |
| 2 |
Require Import Crypto.Util.Tactics.ClearAll. |
| 3 |
(** This file defines a number of different ways to solve goals of the |
| 4 |
form [LHS = RHS] where [LHS] may contain evars and [RHS] must not |
| 5 |
contain evars. Most tactics use [abstract] to reduce the load on |
| 6 |
[Defined] and to catch looping behavior early. *) |
| 7 |
|
| 8 |
(** This is the generic tactic; from a goal [LHS = RHS], it transforms |
| 9 |
the RHS with a passed transformer, unifies the output with LHS |
| 10 |
using the passed [unify] tactic, and then uses the passed variant |
| 11 |
of [exact_no_check] to [abstract] a subproof of the form [eq_refl |
| 12 |
new_rhs]. If there is no evar in the [LHS], don't run |
| 13 |
transformation nor unification. *) |
| 14 |
Ltac unify_transformed_rhs_abstract_tac transform_rhs unify exact_no_check := |
| 15 |
intros; clear_all; |
| 16 |
lazymatch goal with |
| 17 |
| [ |- ?LHS = ?RHS ] |
| 18 |
=> tryif has_evar LHS |
| 19 |
then (let RHS' := transform_rhs RHS in |
| 20 |
unify LHS RHS'; clear; |
| 21 |
abstract exact_no_check (eq_refl RHS')) |
| 22 |
else (abstract exact_no_check (eq_refl RHS)) |
| 23 |
end. |
| 24 |
|
| 25 |
Ltac idterm x := x. |
| 26 |
Ltac noop2 x y := idtac. |
| 27 |
Ltac eval_vm_compute_in x := eval vm_compute in x. |
| 28 |
Ltac eval_compute_in x := eval vm_compute in x. |
| 29 |
Ltac unify_tac x y := unify x y. |
| 30 |
|
| 31 |
(** The tactic [abstract_vm_compute_rhs_reflexivity] unifies [LHS] |
| 32 |
with the result of [vm_compute]ing [RHS], and costs two |
| 33 |
[vm_compute]s, unless there is no evar in the [LHS], in which case |
| 34 |
it costs only one [vm_compute]. *) |
| 35 |
Ltac unify_abstract_vm_compute_rhs_reflexivity := |
| 36 |
unify_transformed_rhs_abstract_tac |
| 37 |
eval_vm_compute_in |
| 38 |
unify_tac |
| 39 |
vm_cast_no_check. |
| 40 |
(** The tactic [abstract_compute_rhs_reflexivity] unfies [LHS] with |
| 41 |
the result of running [compute] in [RHS], and costs a [compute] |
| 42 |
and a [vm_compute]. Use this if you don't want to lose binder |
| 43 |
names or otherwise can't use [vm_compute]. *) |
| 44 |
Ltac unify_abstract_compute_rhs_reflexivity := |
| 45 |
unify_transformed_rhs_abstract_tac |
| 46 |
eval_compute_in |
| 47 |
unify_tac |
| 48 |
vm_cast_no_check. |
| 49 |
(** The tactic [abstract_rhs_reflexivity] unifies [LHS] with [RHS]. *) |
| 50 |
Ltac unify_abstract_rhs_reflexivity := |
| 51 |
unify_transformed_rhs_abstract_tac |
| 52 |
idterm |
| 53 |
unify_tac |
| 54 |
exact_no_check. |