@@ -22,15 +22,6 @@ Import mbox.
22
22
Import SAWCorePrelude.
23
23
24
24
25
- Lemma Mbox_rect_id (m : Mbox) :
26
- Mbox_rect (fun _ => Mbox) Mbox_nil
27
- (fun strt len _ rec vec => Mbox_cons strt len rec vec) m = m.
28
- Proof .
29
- induction m; simpl; eauto.
30
- rewrite IHm; reflexivity.
31
- Qed .
32
-
33
-
34
25
Definition unfoldMbox_nil :
35
26
unfoldMbox Mbox_nil = Left _ _ tt :=
36
27
reflexivity _.
@@ -79,7 +70,44 @@ Proof.
79
70
simpl; f_equal; eauto.
80
71
Qed .
81
72
82
- Hint Rewrite transMbox_Mbox_nil_r : refinesM.
73
+ Lemma transMbox_assoc m1 m2 m3 :
74
+ transMbox (transMbox m1 m2) m3 = transMbox m1 (transMbox m2 m3).
75
+ Proof .
76
+ induction m1; eauto.
77
+ simpl; f_equal; eauto.
78
+ Qed .
79
+
80
+ Hint Rewrite transMbox_Mbox_nil_r transMbox_assoc : refinesM.
81
+
82
+
83
+ (* ========================================================================== *)
84
+
85
+
86
+ Lemma no_errors_mbox_drop
87
+ : refinesFun mbox_drop (fun _ _ => noErrorsSpec).
88
+ Proof .
89
+ unfold mbox_drop, mbox_drop__tuple_fun, noErrorsSpec.
90
+ (* Set Ltac Profiling. *)
91
+ time "no_errors_mbox_drop" prove_refinement.
92
+ (* Show Ltac Profile. Reset Ltac Profile. *)
93
+ Time Qed .
94
+
95
+ Definition mbox_drop_spec : Mbox -> BV64 -> Mbox :=
96
+ Mbox__rec _ (fun _ => Mbox_nil) (fun strt len next rec d ix =>
97
+ if bvuge 64 (projT1 ix) (projT1 len)
98
+ then Mbox_cons (existT _ (intToBv 64 0) tt) (existT _ (intToBv 64 0) tt)
99
+ (rec (existT _ (bvSub 64 (projT1 ix) (projT1 len)) tt)) d
100
+ else Mbox_cons (existT _ (bvAdd 64 (projT1 ix) (projT1 strt)) tt)
101
+ (existT _ (bvSub 64 (projT1 len) (projT1 ix)) tt) next d).
102
+
103
+ Lemma mbox_drop_spec_ref
104
+ : refinesFun mbox_drop (fun x ix => returnM (mbox_drop_spec x ix)).
105
+ Proof .
106
+ unfold mbox_drop, mbox_drop__tuple_fun, mbox_drop_spec.
107
+ (* Set Ltac Profiling. *)
108
+ time "mbox_drop_spec_ref" prove_refinement.
109
+ (* Show Ltac Profile. Reset Ltac Profile. *)
110
+ Time Qed .
83
111
84
112
85
113
Lemma mbox_free_chain_spec_ref
@@ -89,7 +117,9 @@ Proof.
89
117
prove_refinement_match_letRecM_l.
90
118
- exact (fun _ => returnM (mkBV32 (intToBv 32 0))).
91
119
unfold mkBV32.
120
+ (* Set Ltac Profiling. *)
92
121
time "mbox_free_chain_spec_ref" prove_refinement.
122
+ (* Show Ltac Profile. Reset Ltac Profile. *)
93
123
Time Qed .
94
124
95
125
Lemma no_errors_mbox_free_chain
@@ -105,7 +135,9 @@ Lemma no_errors_mbox_concat
105
135
: refinesFun mbox_concat (fun _ _ => noErrorsSpec).
106
136
Proof .
107
137
unfold mbox_concat, mbox_concat__tuple_fun, noErrorsSpec.
138
+ (* Set Ltac Profiling. *)
108
139
time "no_errors_mbox_concat" prove_refinement.
140
+ (* Show Ltac Profile. Reset Ltac Profile. *)
109
141
Time Qed .
110
142
111
143
Definition mbox_concat_spec (x y : Mbox) : Mbox :=
@@ -115,15 +147,56 @@ Lemma mbox_concat_spec_ref
115
147
: refinesFun mbox_concat (fun x y => returnM (mbox_concat_spec x y)).
116
148
Proof .
117
149
unfold mbox_concat, mbox_concat__tuple_fun, mbox_concat_spec.
150
+ (* Set Ltac Profiling. *)
151
+ time "mbox_concat_spec_ref" prove_refinement.
152
+ (* Show Ltac Profile. Reset Ltac Profile. *)
153
+ Time Qed .
154
+
155
+ (* Add `mbox_concat_spec_ref` to the hint database. Unfortunately, Coq will not unfold refinesFun
156
+ and mbox_concat_spec when rewriting, and the only workaround I know right now is this :/ *)
157
+ Definition mbox_concat_spec_ref' : ltac:(let tp := type of mbox_concat_spec_ref in
158
+ let tp' := eval unfold refinesFun, mbox_concat_spec in tp
159
+ in exact tp') := mbox_concat_spec_ref.
160
+ Hint Rewrite mbox_concat_spec_ref' : refinement_proofs.
161
+
162
+
163
+ Lemma no_errors_mbox_concat_chains
164
+ : refinesFun mbox_concat_chains (fun _ _ => noErrorsSpec).
165
+ Proof .
166
+ unfold mbox_concat_chains, mbox_concat_chains__tuple_fun.
167
+ prove_refinement_match_letRecM_l.
168
+ - exact (fun _ _ _ _ _ _ => noErrorsSpec).
169
+ unfold noErrorsSpec.
170
+ (* Set Ltac Profiling. *)
171
+ time "no_errors_mbox_concat_chains" prove_refinement with NoRewrite.
172
+ (* Show Ltac Profile. Reset Ltac Profile. *)
173
+ Time Qed .
174
+
175
+ Definition mbox_concat_chains_spec (x y : Mbox) : Mbox :=
176
+ Mbox__rec (fun _ => Mbox) Mbox_nil (fun _ _ _ _ _ =>
177
+ Mbox__rec (fun _ => Mbox) x (fun _ _ _ _ _ =>
178
+ transMbox x y) y) x.
179
+
180
+ Lemma mbox_concat_chains_spec_ref
181
+ : refinesFun mbox_concat_chains (fun x y => returnM (mbox_concat_chains_spec x y)).
182
+ Proof .
183
+ unfold mbox_concat_chains, mbox_concat_chains__tuple_fun.
184
+ prove_refinement_match_letRecM_l.
185
+ - intros x y strt len next d.
186
+ exact (returnM (transMbox x (Mbox_cons strt len (transMbox next y) d))).
187
+ unfold mbox_concat_chains_spec.
118
188
time "mbox_concat_spec_ref" prove_refinement.
189
+ simpl; repeat rewrite transMbox_Mbox_nil_r; reflexivity.
119
190
Time Qed .
120
191
121
192
122
193
Lemma no_errors_mbox_detach
123
194
: refinesFun mbox_detach (fun _ => noErrorsSpec).
124
195
Proof .
125
196
unfold mbox_detach, mbox_detach__tuple_fun, noErrorsSpec.
197
+ (* Set Ltac Profiling. *)
126
198
time "no_errors_mbox_detach" prove_refinement.
199
+ (* Show Ltac Profile. Reset Ltac Profile. *)
127
200
Time Qed .
128
201
129
202
Definition mbox_detach_spec : Mbox -> Mbox * (Mbox * unit) :=
@@ -134,7 +207,52 @@ Lemma mbox_detach_spec_ref
134
207
: refinesFun mbox_detach (fun x => returnM (mbox_detach_spec x)).
135
208
Proof .
136
209
unfold mbox_detach, mbox_detach__tuple_fun, mbox_detach, mbox_detach_spec.
210
+ (* Set Ltac Profiling. *)
137
211
time "mbox_detach_spec_ref" prove_refinement.
212
+ (* Show Ltac Profile. Reset Ltac Profile. *)
213
+ Time Qed .
214
+
215
+ (* Add `mbox_detach_spec_ref` to the hint database. Unfortunately, Coq will not unfold refinesFun
216
+ and mbox_detach_spec when rewriting, and the only workaround I know right now is this :/ *)
217
+ Definition mbox_detach_spec_ref' : ltac:(let tp := type of mbox_detach_spec_ref in
218
+ let tp' := eval unfold refinesFun, mbox_detach_spec in tp
219
+ in exact tp') := mbox_detach_spec_ref.
220
+ Hint Rewrite mbox_detach_spec_ref' : refinement_proofs.
221
+
222
+
223
+ Lemma no_errors_mbox_len
224
+ : refinesFun mbox_len (fun _ => noErrorsSpec).
225
+ Proof .
226
+ unfold mbox_len, mbox_len__tuple_fun.
227
+ prove_refinement_match_letRecM_l.
228
+ - exact (fun _ _ _ => noErrorsSpec).
229
+ unfold noErrorsSpec.
230
+ (* Set Ltac Profiling. *)
231
+ time "no_errors_mbox_len" prove_refinement.
232
+ (* Show Ltac Profile. Reset Ltac Profile. *)
233
+ Time Qed .
234
+
235
+ Definition mbox_len_spec : Mbox -> bitvector 64 :=
236
+ Mbox__rec (fun _ => bitvector 64) (intToBv 64 0)
237
+ (fun strt len m rec d => bvAdd 64 rec (projT1 len)).
238
+
239
+ Lemma mbox_len_spec_ref
240
+ : refinesFun mbox_len (fun m => returnM (m, (existT _ (mbox_len_spec m) tt, tt))).
241
+ Proof .
242
+ unfold mbox_len, mbox_len__tuple_fun.
243
+ prove_refinement_match_letRecM_l.
244
+ - exact (fun m1 rec m2 => returnM (transMbox m1 m2, (existT _ (bvAdd 64 (projT1 rec) (mbox_len_spec m2)) tt, tt))).
245
+ unfold mbox_len_spec.
246
+ (* Set Ltac Profiling. *)
247
+ time "mbox_len_spec_ref" prove_refinement.
248
+ (* Show Ltac Profile. Reset Ltac Profile. *)
249
+ (* Most of the remaining cases are taken care of with just bvAdd_id_l and bvAdd_id_r *)
250
+ all: try rewrite bvAdd_id_r; try rewrite bvAdd_id_l; try reflexivity.
251
+ (* The remaining case just needs a few more rewrites *)
252
+ - do 3 f_equal.
253
+ rewrite bvAdd_assoc; f_equal.
254
+ rewrite bvAdd_comm; reflexivity.
255
+ - cbn; rewrite transMbox_Mbox_nil_r; reflexivity.
138
256
Time Qed .
139
257
140
258
@@ -207,9 +325,11 @@ Proof.
207
325
try unfold llvm__x2ememcpy__x2ep0i8__x2ep0i8__x2ei64.
208
326
try unfold llvm__x2eobjectsize__x2ei64__x2ep0i8, __memcpy_chk.
209
327
Set Printing Depth 1000.
210
- (* Expect this to take on the order of 25 seconds, removing the `NoRewrite`
328
+ (* Expect this to take on the order of 15 seconds, removing the `NoRewrite`
211
329
adds another 5 seconds and only simplifies the proof in the one noted spot *)
330
+ (* Set Ltac Profiling. *)
212
331
time "mbox_copy_spec_ref" prove_refinement with NoRewrite.
332
+ (* Show Ltac Profile. Reset Ltac Profile. *)
213
333
all: try discriminate e_either.
214
334
- rewrite e_forall in e_maybe.
215
335
discriminate e_maybe.
@@ -220,19 +340,13 @@ Proof.
220
340
discriminate e_maybe1.
221
341
- rewrite a1 in e_maybe2.
222
342
discriminate e_maybe2.
223
- - replace a2 with e_forall; [ replace a3 with e_forall0 | ].
343
+ - rewrite transMbox_Mbox_nil_r. (* <- this would go away if we removed "NoRewrite" *)
344
+ replace a2 with e_forall; [ replace a3 with e_forall0 | ].
224
345
destruct strt, len, u, u0; cbn.
225
346
unfold conjSliceBVVec; simpl projT1.
226
347
reflexivity.
227
348
- apply BoolDecidableEqDepSet.UIP.
228
349
- apply BoolDecidableEqDepSet.UIP.
229
- - replace a2 with e_forall; [ replace a3 with e_forall0 | ].
230
- destruct strt, len, u, u0; cbn.
231
- unfold conjSliceBVVec; simpl projT1.
232
- (* Without the `NoRewrite` this next line is just `reflexivity` *)
233
- rewrite Mbox_rect_id; reflexivity.
234
- - apply BoolDecidableEqDepSet.UIP.
235
- - apply BoolDecidableEqDepSet.UIP.
236
350
- rewrite <- e_assuming in e_if.
237
351
vm_compute in e_if; discriminate e_if.
238
352
- rewrite <- isBvult_to_isBvslt_pos in e_if.
@@ -252,3 +366,10 @@ Proof.
252
366
induction a; simpl in *.
253
367
all: repeat prove_refinement.
254
368
Qed .
369
+
370
+ (* Add `mbox_copy_spec_ref` to the hint database. Unfortunately, Coq will not unfold refinesFun
371
+ and mbox_copy_spec when rewriting, and the only workaround I know right now is this :/ *)
372
+ Definition mbox_copy_spec_ref' : ltac:(let tp := type of mbox_copy_spec_ref in
373
+ let tp' := eval unfold refinesFun, mbox_copy_spec, mbox_copy_spec_cons, empty_mbox_d in tp
374
+ in exact tp') := mbox_copy_spec_ref.
375
+ Hint Rewrite mbox_copy_spec_ref' : refinement_proofs.
0 commit comments