Debian Codegraph @

src/Bedrock/Field/Common/Tactics.v

raw
1 Require Import bedrock2.WeakestPreconditionProperties.
2 Require Import bedrock2.Map.Separation bedrock2.Map.SeparationLogic.
3 Require Import coqutil.Map.Interface.
4 Require Import Crypto.Bedrock.Field.Common.Util.
5 Require Import Crypto.Language.API.
6 Require Import Crypto.Util.Tactics.DestructHead.
7 Require Import Crypto.Util.Tactics.BreakMatch.
8
9 Import API.Compilers.
10
11 (** Tactics ***)
12 Ltac cleanup :=
13 repeat first [ progress cbn [fst snd eq_rect] in *
14 | progress destruct_head'_and
15 | match goal with H : exists _, _ |- _ => destruct H end
16 | match goal with H : ?x = ?x |- _ => clear H end ].
17
18 (* call after inversion or induction on a wf hypothesis *)
19 Ltac cleanup_wf :=
20 repeat (first
21 [ progress subst
22 | progress Inversion.Compilers.expr.inversion_expr
23 | match goal with
24 | H:existT _ _ _ = existT _ _ _
25 |- _ =>
26 apply Eqdep_dec.inj_pair2_eq_dec in H;
27 [ | solve [ apply Inversion.Compilers.type.type_eq_Decidable ] ]
28 | H:existT _ _ _ = existT _ _ _
29 |- _ =>
30 apply Eqdep_dec.inj_pair2_eq_dec in H;
31 [ | apply base.type.type_eq_dec with (eq_base_type:=Compilers.base_beq);
32 intros *; apply Bool.reflect_iff;
33 solve [auto using Compilers.reflect_base_beq] ]
34 end ]); cleanup.
35
36 Ltac sepsimpl_step' :=
37 match goal with
38 | |- sep (emp _) _ _ => apply sep_emp_l
39 | |- sep _ (emp _) _ => apply sep_emp_r
40 | |- sep (fun m => emp _ m) _ _ => apply sep_emp_l
41 | |- sep _ (fun m => emp _ m) _ => apply sep_emp_r
42 | |- sep (Lift1Prop.ex1 _) _ _ => apply sep_ex1_l
43 | |- sep _ (Lift1Prop.ex1 _) _ => apply sep_ex1_r
44 | |- sep (fun m => Lift1Prop.ex1 _ m) _ _ => apply sep_ex1_l
45 | |- sep _ (fun m => Lift1Prop.ex1 _ m) _ => apply sep_ex1_r
46 | |- emp _ _ => split; [ congruence | ]
47 end.
48
49 Ltac sepsimpl_step_no_comm :=
50 match goal with
51 | _ => sepsimpl_step'
52 | |- sep (sep _ _) _ _ => apply sep_assoc; sepsimpl_step'
53 | |- sep (sep (sep _ _) _) _ _ =>
54 apply sep_assoc; apply sep_assoc; sepsimpl_step'
55 end.
56
57 Ltac sepsimpl_step :=
58 match goal with
59 | _ => sepsimpl_step_no_comm
60 | |- sep _ (sep _ _) _ =>
61 apply sep_comm, sep_assoc; sepsimpl_step_no_comm
62 | |- sep _ _ _ => apply sep_comm; sepsimpl_step_no_comm
63 end.
64
65 Ltac sepsimpl_in H :=
66 match type of H with
67 | sep (emp _) _ _ =>
68 eapply sep_emp_l in H
69 | sep _ (emp _) _ =>
70 eapply sep_emp_r in H
71 | sep (fun m => emp _ m) _ _ =>
72 eapply sep_emp_l in H
73 | sep _ (fun m => emp _ m) _ =>
74 eapply sep_emp_r in H
75 | sep (Lift1Prop.ex1 _) _ _ =>
76 eapply sep_ex1_l in H; destruct H
77 | sep _ (Lift1Prop.ex1 _) _ =>
78 eapply sep_ex1_r in H; destruct H
79 | sep (fun m => Lift1Prop.ex1 _ m) _ _ =>
80 eapply sep_ex1_l in H; destruct H
81 | sep _ (fun m => Lift1Prop.ex1 _ m) _ =>
82 eapply sep_ex1_r in H; destruct H
83 | sep _ _ map.empty =>
84 apply sep_empty_iff in H
85 end.
86
87 Ltac sepsimpl_hyps_step_no_comm :=
88 match goal with
89 | H : False |- _ => tauto
90 | H : emp _ _ |- _ => cbv [emp] in H; destruct H
91 | H : Lift1Prop.ex1 _ _ |- _ => destruct H
92 | H : sep (sep ?p ?q) _ _ |- _ =>
93 eapply (sep_assoc p q) in H; sepsimpl_in H
94 | H : sep (sep (sep ?p ?q) ?r) _ _ |- _ =>
95 eapply (sep_assoc (sep p q) r) in H;
96 eapply (sep_assoc p q) in H;
97 sepsimpl_in H
98 | H : sep _ _ _ |- _ => sepsimpl_in H
99 end.
100
101 Ltac sepsimpl_hyps_step :=
102 match goal with
103 | _ => sepsimpl_hyps_step_no_comm
104 | H : sep _ (sep ?p ?q) _ |- _ =>
105 (* reverse order and try simplifying again *)
106 eapply sep_comm, (sep_assoc p q) in H;
107 sepsimpl_hyps_step_no_comm
108 end.
109
110 Ltac sepsimpl_hyps :=
111 repeat first [ progress cleanup
112 | progress sepsimpl_hyps_step ].
113
114 Ltac sepsimpl :=
115 repeat first [ progress cleanup
116 | match goal with |- _ /\ _ => split end
117 | progress sepsimpl_step
118 | progress sepsimpl_hyps_step ].