Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
(* NOTE: This file is expected to be deleted when the `rr_frontend` will be done. *)
From refinedrust Require Import automation.
From refinedrust Require Import existentials_na.
From refinedrust Require Import typing.
Section UnsafeCell_sls.
Context `{!refinedrustGS Σ}.
Definition UnsafeCell_sls : struct_layout_spec := mk_sls "UnsafeCell" [
("value", IntSynType I32)] StructReprTransparent.
Definition UnsafeCell_st : syn_type := UnsafeCell_sls.
End UnsafeCell_sls.
Section Cell_sls.
Context `{!refinedrustGS Σ}.
Definition Cell_sls : struct_layout_spec := mk_sls "Cell" [
("value", UnsafeCell_st)] StructReprRust.
Definition Cell_st : syn_type := Cell_sls .
End Cell_sls.
Section code.
Context `{!refinedrustGS Σ}.
Open Scope printing_sugar.
Definition UnsafeCell_new_def : function := {|
f_args := [
("value", (it_layout I32) : layout)
];
f_local_vars := [
("__0", (use_layout_alg' (UnsafeCell_st)) : layout);
("__2", (it_layout I32) : layout)
];
f_code :=
<[
"_bb0" :=
"__2" <-{ IntOp I32 } use{ IntOp I32 } ("value");
"__0" <-{ (use_op_alg' (UnsafeCell_st)) } StructInit UnsafeCell_sls [("value", use{ IntOp I32 } ("__2") : expr)];
return (use{ (use_op_alg' (UnsafeCell_st)) } ("__0"))
]>%E $
∅;
f_init := "_bb0";
|}.
Definition UnsafeCell_into_inner_def : function := {|
f_args := [
("self", (use_layout_alg' (UnsafeCell_st)) : layout)
];
f_local_vars := [
("__0", (it_layout I32) : layout)
];
f_code :=
<[
"_bb0" :=
"__0" <-{ IntOp I32 } use{ IntOp I32 } (("self") at{ UnsafeCell_sls } "value");
return (use{ IntOp I32 } ("__0"))
]>%E $
∅;
f_init := "_bb0";
|}.
Definition UnsafeCell_get_old_def : function := {|
f_args := [
("self", void* : layout)
];
f_local_vars := [
("__0", (it_layout I32) : layout)
];
f_code :=
<[
"_bb0" :=
annot: CopyLftNameAnnot "plft3" "ulft__";
"__0" <-{ IntOp I32 } use{ IntOp I32 } ((!{ PtrOp } ( "self" )) at{ (UnsafeCell_sls) } "value");
return (use{ IntOp I32 } ("__0"))
]>%E $
∅;
f_init := "_bb0";
|}.
Definition UnsafeCell_get_def : function := {|
f_args := [
("self", void* : layout)
];
f_local_vars := [
("__0", void* : layout);
("__2", void* : layout);
("__3", void* : layout)
];
f_code :=
<[
"_bb0" :=
annot: CopyLftNameAnnot "plft3" "ulft_1";
"__3" <-{ PtrOp } &raw{ Shr } (!{ PtrOp } ( "self" ));
"__2" <-{ PtrOp } use{ PtrOp } ("__3");
"__0" <-{ PtrOp } use{ PtrOp } ("__2");
return (use{ PtrOp } ("__0"))
]>%E $
∅;
f_init := "_bb0";
|}.
Definition Cell_new_def (UnsafeCell_new_loc : loc) : function := {|
f_args := [
("value", (it_layout I32) : layout)
];
f_local_vars := [
("__0", (use_layout_alg' (Cell_st)) : layout);
("__2", (use_layout_alg' (UnsafeCell_st)) : layout);
("__3", (it_layout I32) : layout)
];
f_code :=
<[
"_bb0" :=
"__3" <-{ IntOp I32 } use{ IntOp I32 } ("value");
"__2" <-{ (use_op_alg' (UnsafeCell_st)) } CallE UnsafeCell_new_loc [] [] [@{expr} use{ IntOp I32 } ("__3")];
Goto "_bb1"
]>%E $
<[
"_bb1" :=
"__0" <-{ (use_op_alg' (Cell_st)) } StructInit Cell_sls [("value", use{ (use_op_alg' (UnsafeCell_st)) } ("__2") : expr)];
return (use{ (use_op_alg' (Cell_st)) } ("__0"))
]>%E $
∅;
f_init := "_bb0";
|}.
Definition Cell_into_inner_def (UnsafeCell_into_inner_loc : loc) : function := {|
f_args := [
("self", (use_layout_alg' (Cell_st)) : layout)
];
f_local_vars := [
("__0", (it_layout I32) : layout);
("__2", (use_layout_alg' (UnsafeCell_st)) : layout)
];
f_code :=
<[
"_bb0" :=
"__2" <-{ (use_op_alg' (UnsafeCell_st)) } use{ (use_op_alg' (UnsafeCell_st)) } (("self") at{ Cell_sls } "value");
"__0" <-{ IntOp I32 } CallE UnsafeCell_into_inner_loc [] [] [@{expr} use{ (use_op_alg' (UnsafeCell_st)) } ("__2")];
Goto "_bb1"
]>%E $
<[
"_bb1" :=
return (use{ IntOp I32 } ("__0"))
]>%E $
∅;
f_init := "_bb0";
|}.
End code.
Section UnsafeCell_ty.
Context `{!refinedrustGS Σ}.
Definition UnsafeCell_ty : type (plist place_rfn [Z : Type]).
Proof using Type*. exact (struct_t UnsafeCell_sls +[(int I32)]). Defined.
Definition UnsafeCell_rt : Type.
Proof using . let __a := eval hnf in (rt_of UnsafeCell_ty) in exact __a. Defined.
Global Typeclasses Transparent UnsafeCell_ty.
Global Typeclasses Transparent UnsafeCell_rt.
End UnsafeCell_ty.
Global Arguments UnsafeCell_rt : clear implicits.
Section UnsafeCell_inv_t.
Context `{!refinedrustGS Σ}.
Program Definition UnsafeCell_inv_t_inv_spec : na_ex_inv_def (UnsafeCell_rt) (Z) :=
na_mk_ex_inv_def
((Z)%type)
(xmap)
(λ π inner_rfn 'x, ⌜inner_rfn = -[#(x)]⌝ ∗ ⌜Zeven x⌝ ∗ True)%I
[] [].
Definition UnsafeCell_inv_t : type (Z) :=
na_ex_plain_t _ _ UnsafeCell_inv_t_inv_spec UnsafeCell_ty.
Definition UnsafeCell_inv_t_rt : Type.
Proof using. let __a := eval hnf in (rt_of UnsafeCell_inv_t) in exact __a. Defined.
Global Typeclasses Transparent UnsafeCell_inv_t.
Global Typeclasses Transparent UnsafeCell_inv_t_rt.
End UnsafeCell_inv_t.
Global Arguments UnsafeCell_inv_t_rt : clear implicits.
Section Cell_ty.
Context `{!refinedrustGS Σ}.
Definition Cell_ty : type (plist place_rfn [UnsafeCell_inv_t_rt : Type]).
Proof using Type*. exact (struct_t Cell_sls +[UnsafeCell_inv_t]). Defined.
Definition Cell_rt : Type.
Proof using . let __a := eval hnf in (rt_of Cell_ty) in exact __a. Defined.
Global Typeclasses Transparent Cell_ty.
Global Typeclasses Transparent Cell_rt.
End Cell_ty.
Global Arguments Cell_rt : clear implicits.
Section Cell_inv_t.
Context `{!refinedrustGS Σ}.
Program Definition Cell_inv_t_inv_spec : na_ex_inv_def (Cell_rt) (Z) :=
na_mk_ex_inv_def
((Z)%type)
(xmap)
(λ π inner_rfn 'x, ⌜inner_rfn = -[#(x)]⌝ ∗ ⌜Zeven x⌝ ∗ True)%I
[] [].
Definition Cell_inv_t : type (Z) :=
na_ex_plain_t _ _ Cell_inv_t_inv_spec Cell_ty.
Definition Cell_inv_t_rt : Type.
Proof using . let __a := eval hnf in (rt_of Cell_inv_t) in exact __a. Defined.
Global Typeclasses Transparent Cell_inv_t.
Global Typeclasses Transparent Cell_inv_t_rt.
End Cell_inv_t.
Global Arguments Cell_inv_t_rt : clear implicits.
Section specs.
Context `{RRGS: !refinedrustGS Σ}.
Definition type_of_UnsafeCell_new :=
fn(∀ ( *[]) : 0 | ( *[]): ([]) | (x) : (Z), (λ ϝ, []); x :@: (int I32); (λ π : thread_id, (⌜Zeven x⌝)))
→ ∃ _ : unit, x @ UnsafeCell_inv_t; (λ π : thread_id, True).
Definition type_of_UnsafeCell_into_inner :=
fn(∀ ( *[]) : 0 | ( *[]): ([]) | (x) : (Z), (λ ϝ, []); x :@: UnsafeCell_inv_t; (λ π : thread_id, True))
→ ∃ _ : unit, x @ (int I32); (λ π : thread_id, (⌜Zeven x⌝)).
Definition type_of_UnsafeCell_get_old :=
fn(∀ ( *[ulft_1]) : 1 | ( *[]) : ([]) | (x) : (_), (λ ϝ, []); x :@: (shr_ref ulft_1 UnsafeCell_inv_t); (λ π : thread_id, True))
→ ∃ _ : unit, x @ (int I32); (λ π : thread_id, (⌜Zeven x⌝)).
Definition type_of_Cell_new :=
fn(∀ ( *[]) : 0 | ( *[]) : [] | (x) : (Z), (λ ϝ, []); x :@: (int I32); (λ π : thread_id, (⌜Zeven x⌝)))
→ ∃ _ : unit, x @ Cell_inv_t; (λ π : thread_id, True).
Definition type_of_Cell_into_inner :=
fn(∀ ( *[]) : 0 | ( *[]) : [] | (x) : (_), (λ ϝ, []); x :@: Cell_inv_t; (λ π : thread_id, True))
→ ∃ _ : unit, x @ (int I32); (λ π : thread_id, (⌜Zeven x⌝)).
End specs.
Section proof.
Context `{RRGS: !refinedrustGS Σ}.
Definition UnsafeCell_new_lemma (π : thread_id) : Prop :=
syn_type_is_layoutable ((UnsafeCell_sls : syn_type)) →
⊢ typed_function π (UnsafeCell_new_def ) [UnsafeCell_st; IntSynType I32] (<tag_type> type_of_UnsafeCell_new ).
Definition UnsafeCell_into_inner_lemma (π : thread_id) : Prop :=
syn_type_is_layoutable ((UnsafeCell_sls : syn_type)) →
⊢ typed_function π (UnsafeCell_into_inner_def ) [IntSynType I32] (<tag_type> type_of_UnsafeCell_into_inner ).
Definition UnsafeCell_get_old_lemma (π : thread_id) : Prop :=
syn_type_is_layoutable (Cell_st) →
⊢ typed_function π (UnsafeCell_get_old_def ) [IntSynType I32] (<tag_type> type_of_UnsafeCell_get_old ).
Definition Cell_new_lemma (π : thread_id) : Prop :=
∀ (UnsafeCell_new_loc : loc) ,
syn_type_is_layoutable ((UnsafeCell_sls : syn_type)) →
syn_type_is_layoutable ((Cell_sls : syn_type)) →
UnsafeCell_new_loc ◁ᵥ{π} UnsafeCell_new_loc @ function_ptr [IntSynType I32] (<tag_type> spec! ( *[]) : 0 | ( *[]) : ([]), type_of_UnsafeCell_new (RRGS := RRGS) <MERGE!>) -∗
typed_function π (Cell_new_def UnsafeCell_new_loc ) [Cell_st; UnsafeCell_st; IntSynType I32] (<tag_type> type_of_Cell_new ).
End proof.
Ltac UnsafeCell_new_prelude :=
unfold UnsafeCell_new_lemma;
set (FN_NAME := FUNCTION_NAME "UnsafeCell_new");
intros;
iStartProof;
let ϝ := fresh "ϝ" in
start_function "UnsafeCell_new" ϝ ( [] ) ( [] ) ( x ) ( x );
set (loop_map := BB_INV_MAP (PolyNil));
intros arg_value local___0 local___2;
init_lfts (named_lft_update "_flft" ϝ $ ∅ );
init_tyvars ( ∅ ).
Ltac UnsafeCell_into_inner_prelude :=
unfold UnsafeCell_into_inner_lemma;
set (FN_NAME := FUNCTION_NAME "UnsafeCell_into_inner");
intros;
iStartProof;
let ϝ := fresh "ϝ" in
start_function "UnsafeCell_into_inner" ϝ ( [] ) ( [] ) ( x ) ( x );
set (loop_map := BB_INV_MAP (PolyNil));
intros arg_self local___0;
init_lfts (named_lft_update "_flft" ϝ $ ∅ );
init_tyvars ( ∅ ).
Ltac UnsafeCell_get_old_prelude :=
unfold UnsafeCell_get_old_lemma;
set (FN_NAME := FUNCTION_NAME "Cell_get");
intros;
iStartProof;
let ϝ := fresh "ϝ" in
let ulft__ := fresh "ulft__" in
start_function "UnsafeCell_get_old" ϝ ( [ ulft__ [] ] ) ( [] ) ( x ) ( x );
set (loop_map := BB_INV_MAP (PolyNil));
intros arg_self local___0;
init_lfts (named_lft_update "ulft__" ulft__ $ named_lft_update "_flft" ϝ $ ∅ );
init_tyvars ( ∅ ).
Ltac Cell_new_prelude :=
unfold Cell_new_lemma;
set (FN_NAME := FUNCTION_NAME "Cell_new");
intros;
iStartProof;
let ϝ := fresh "ϝ" in
start_function "Cell_T_new" ϝ ( [] ) ( [] ) ( x ) ( x );
set (loop_map := BB_INV_MAP (PolyNil));
intros arg_value local___0 local___2 local___3;
init_lfts (named_lft_update "_flft" ϝ $ ∅ );
init_tyvars ( ∅ ).
Section proof.
Context `{!refinedrustGS Σ}.
Lemma UnsafeCell_new_proof (π : thread_id) :
UnsafeCell_new_lemma π.
Proof.
UnsafeCell_new_prelude.
repeat liRStep; liShow.
all: print_remaining_goal.
Unshelve. all: sidecond_solver.
Unshelve. all: sidecond_hammer.
Unshelve. all: print_remaining_sidecond.
Qed.
Lemma UnsafeCell_into_inner_proof (π : thread_id) :
UnsafeCell_into_inner_lemma π.
Proof.
UnsafeCell_into_inner_prelude.
repeat liRStep; liShow.
all: print_remaining_goal.
Unshelve. all: sidecond_solver.
Unshelve. all: sidecond_hammer.
Unshelve. all: print_remaining_sidecond.
Qed.
Lemma Cell_new_proof (π : thread_id) :
Cell_new_lemma π.
Proof.
Cell_new_prelude.
repeat liRStep; liShow.
all: print_remaining_goal.
Unshelve. all: sidecond_solver.
Unshelve. all: sidecond_hammer.
Unshelve. all: print_remaining_sidecond.
Qed.
Lemma UnsafeCell_get_old_proof (π : thread_id) :
UnsafeCell_get_old_lemma π.
Proof.
UnsafeCell_get_old_prelude.
do 324 liRStep; liShow.
(* TODO: This instance isn't properly found *)
iApply stratify_ltype_shadowed_shared.
repeat liRStep; liShow.
Unshelve. all: sidecond_solver.
Unshelve. all: sidecond_hammer.
Unshelve. all: print_remaining_sidecond.
Qed.
End proof.