| 1 |
Require Export Crypto.Util.FixCoqMistakes. |
| 2 |
|
| 3 |
(** given a [matcher] that succeeds on some hypotheses and fails on |
| 4 |
others, destruct any matching hypotheses, and then execute [tac] |
| 5 |
after each [destruct]. |
| 6 |
|
| 7 |
The [tac] part exists so that you can, e.g., [simpl in *], to |
| 8 |
speed things up. *) |
| 9 |
Ltac do_one_match_then matcher do_tac tac := |
| 10 |
idtac; |
| 11 |
match goal with |
| 12 |
| [ H : ?T |- _ ] |
| 13 |
=> matcher T; do_tac H; |
| 14 |
try match type of H with |
| 15 |
| T => clear H |
| 16 |
end; |
| 17 |
tac |
| 18 |
end. |
| 19 |
|
| 20 |
Ltac do_all_matches_then matcher do_tac tac := |
| 21 |
repeat do_one_match_then matcher do_tac tac. |
| 22 |
|
| 23 |
Ltac destruct_all_matches_then matcher tac := |
| 24 |
do_all_matches_then matcher ltac:(fun H => destruct H) tac. |
| 25 |
Ltac destruct_one_match_then matcher tac := |
| 26 |
do_one_match_then matcher ltac:(fun H => destruct H) tac. |
| 27 |
|
| 28 |
Ltac inversion_all_matches_then matcher tac := |
| 29 |
do_all_matches_then matcher ltac:(fun H => inversion H; subst) tac. |
| 30 |
Ltac inversion_one_match_then matcher tac := |
| 31 |
do_one_match_then matcher ltac:(fun H => inversion H; subst) tac. |
| 32 |
|
| 33 |
Ltac destruct_all_matches matcher := |
| 34 |
destruct_all_matches_then matcher ltac:( simpl in * ). |
| 35 |
Ltac destruct_one_match matcher := destruct_one_match_then matcher ltac:( simpl in * ). |
| 36 |
Ltac destruct_all_matches' matcher := destruct_all_matches_then matcher idtac. |
| 37 |
Ltac destruct_one_match' matcher := destruct_one_match_then matcher idtac. |
| 38 |
|
| 39 |
Ltac inversion_all_matches matcher := inversion_all_matches_then matcher ltac:( simpl in * ). |
| 40 |
Ltac inversion_one_match matcher := inversion_one_match_then matcher ltac:( simpl in * ). |
| 41 |
Ltac inversion_all_matches' matcher := inversion_all_matches_then matcher idtac. |
| 42 |
Ltac inversion_one_match' matcher := inversion_one_match_then matcher idtac. |
| 43 |
|
| 44 |
(* matches anything whose type has a [T] in it *) |
| 45 |
Ltac destruct_type_matcher T HT := |
| 46 |
match HT with |
| 47 |
| context[T] => idtac |
| 48 |
end. |
| 49 |
Ltac destruct_type T := destruct_all_matches ltac:(destruct_type_matcher T). |
| 50 |
Ltac destruct_type' T := destruct_all_matches' ltac:(destruct_type_matcher T). |