-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec_elim_composition_diaframe.v
221 lines (201 loc) · 7.94 KB
/
spec_elim_composition_diaframe.v
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
From gpfsl.examples Require Import sflib.
From stdpp Require Import namespaces.
From gpfsl.logic Require Import logatom.
From gpfsl.examples.stack Require Export stack_event_omo.
From gpfsl.examples.omo Require Export omo omo_preds append_only_loc.
From gpfsl.diaframe Require Import spec_notation atom_spec_notation.
Require Import iris.prelude.options.
Local Open Scope Z_scope.
Local Notation history := (history sevent_hist).
Implicit Types (E : history) (stk : stack_state).
Local Notation EMPTY := 0 (only parsing).
Local Notation FAIL_RACE := (-1) (only parsing).
Definition StackLocalT Σ : Type :=
∀ (γg : gname) (s : loc) (M : eView), vProp Σ.
Definition StackLocalNT Σ : Type :=
∀ (N : namespace), StackLocalT Σ.
Definition StackInvT Σ : Type :=
∀ (γg γs : gname) (s : loc) (E : history) (omo : omoT) (stlist : list stack_state), vProp Σ.
Class new_stack_dspec' {Σ} `{!noprolG Σ, !omoGeneralG Σ}
(new_stack : val) (StackLocal : StackLocalNT Σ) (StackInv : StackInvT Σ) : Prop :=
new_stack_dspec'' :>
SPEC N V, {{ ⊒V }}
new_stack []
{{ (s: loc) , RET #s;
∃ γg γs M V',
let eVinit := mkOmoEvent Init V' M in
let E := [eVinit] in
let stinit : stack_state := [] in
StackInv γg γs s E (omo_append_w [] 0%nat []) [stinit] ∗ ⊒V' ∗ @{V'} StackLocal N γg s M ∗
OmoTokenW γg 0%nat ∗ ⌜ V ⊑ V' ⌝} }.
Class try_push_dspec' {Σ} `{!noprolG Σ, !omoGeneralG Σ}
(try_push : val) (StackLocal : StackLocalNT Σ) (StackInv : StackInvT Σ) : Prop :=
try_push_dspec'' :> ∀ N (s : loc) γg M (V : view) (v : Z),
SPEC ⟨ ⊤ , ↑N , ↑histN⟩ γs E omo stlist, <<
(* PRIVATE PRE *)
⊒V ∗
StackLocal N γg s M ∗
⌜ 0 < v ∧ N ## histN ⌝
¦
(* PUBLIC PRE *)
▷ StackInv γg γs s E omo stlist
> >
try_push [ #s ; #v]
<< (b : bool), RET #b;
emp
¦
( (* PUBLIC POST *)
∃ V', ⊒V' ∗
if b then (
(* successful case *)
∃ γs' M' omo' stlist' gen,
let E' := E ++ [mkOmoEvent (Push v) V' M'] in
▷ StackInv γg γs' s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_insert_w omo gen (length E) [] ⌝ ∗
OmoTokenW γg (length E) ∗
OmoUB γg M (length E) ∗
⌜ V ⊑ V' ∧ M ⊆ M' ⌝
) else (
(* FAIL_RACE case *)
▷ StackInv γg γs s E omo stlist ∗ @{V'} StackLocal N γg s M
))
> >.
Class push_dspec' {Σ} `{!noprolG Σ, !omoGeneralG Σ}
(push : val) (StackLocal : StackLocalNT Σ) (StackInv : StackInvT Σ) : Prop :=
push_dspec'' :>
∀ N (s: loc) γg M (V : view) (v : Z) ,
SPEC ⟨ ⊤ , ↑N , ↑histN⟩ γs E omo stlist, <<
(* PRIVATE PRE *)
⊒V ∗
StackLocal N γg s M ∗
⌜ 0 < v ∧ N ## histN ⌝
¦
(* PUBLIC PRE *)
▷ StackInv γg γs s E omo stlist
> >
push [ #s ; #v]
<< RET #☠;
emp
¦
( (* PUBLIC POST *)
∃ V' γs' M' omo' stlist' gen,
⊒V' ∗
let E' := E ++ [mkOmoEvent (Push v) V' M'] in
▷ StackInv γg γs' s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_insert_w omo gen (length E) [] ⌝ ∗
OmoTokenW γg (length E) ∗
OmoUB γg M (length E) ∗
⌜ V ⊑ V' ∧ M ⊆ M' ⌝
)
> >.
Class try_pop_dspec' {Σ} `{!noprolG Σ, !omoGeneralG Σ}
(try_pop : val) (StackLocal : StackLocalNT Σ) (StackInv : StackInvT Σ) : Prop :=
try_pop_dspec'' :>
∀ N (s: loc) γg M V,
SPEC ⟨ ⊤ , ↑N , ↑histN⟩ γs E omo stlist, <<
(* PRIVATE PRE *)
⊒V ∗
StackLocal N γg s M ∗
⌜ N ## histN ⌝
¦
(* PUBLIC PRE *)
▷ StackInv γg γs s E omo stlist
> >
try_pop [ #s ]
<< (v : Z), RET #v;
emp
¦
( (* PUBLIC POST *)
∃ V', ⊒V' ∗
if (decide (v = FAIL_RACE)) then (
(* FAIL_RACE case *)
▷ StackInv γg γs s E omo stlist ∗ @{V'} StackLocal N γg s M
)
else (
∃ γs' M',
⌜ V ⊑ V' ⌝ ∗
(if (decide (v = EMPTY)) then ( (* EMPTY case *)
∃ gen omo' stlist',
let E' := E ++ [mkOmoEvent EmpPop V' M'] in
▷ StackInv γg γs' s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_insert_r omo gen (length E) ∧ (gen < length omo)%nat ∧ stlist' = stlist ∧ γs' = γs ⌝ ∗
OmoTokenR γg (length E)
) else ( (* successful case *)
∃ gen omo' stlist',
let E' := E ++ [mkOmoEvent (Pop v) V' M'] in
▷ StackInv γg γs' s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_insert_w omo gen (length E) [] ⌝ ∗
OmoTokenW γg (length E)
)) ∗
OmoUB γg M (length E) ∗ ⌜ M ⊆ M' ⌝
))
> >.
Class pop_dspec' {Σ} `{!noprolG Σ, !omoGeneralG Σ}
(pop : val) (StackLocal : StackLocalNT Σ) (StackInv : StackInvT Σ) : Prop :=
pop_dspec'' :>
∀ N (s: loc) γg M V,
SPEC ⟨ ⊤ , ↑N , ↑histN⟩ γs E omo stlist, <<
(* PRIVATE PRE *)
⊒V ∗
StackLocal N γg s M ∗
⌜ N ## histN ⌝
¦
(* PUBLIC PRE *)
▷ StackInv γg γs s E omo stlist
> >
pop [ #s ]
<< (v : Z), RET #v;
emp
¦
( (* PUBLIC POST *)
∃ V', ⊒V' ∗
∃ γs' M',
OmoUB γg M (length E) ∗ ⌜ V ⊑ V' ⌝ ∗
if (decide (v = EMPTY)) then ( (* EMPTY case *)
∃ gen omo' stlist',
let E' := E ++ [mkOmoEvent EmpPop V' M'] in
▷ StackInv γg γs' s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_insert_r omo gen (length E) ∧ (gen < length omo)%nat ∧ stlist' = stlist ∧ γs' = γs ⌝ ∗
OmoTokenR γg (length E)
) else ( (* successful case *)
∃ gen omo' stlist',
let E' := E ++ [mkOmoEvent (Pop v) V' M'] in
▷ StackInv γg γs' s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_insert_w omo gen (length E) [] ⌝ ∗
OmoTokenW γg (length E)
) ∗
⌜ M ⊆ M' ⌝
)
> >.
Record stack_spec {Σ} `{!noprolG Σ, !omoGeneralG Σ, !omoSpecificG Σ sevent_hist stack_state} := StackSpec {
(** operations *)
new_stack : val;
try_push : val;
push : val;
try_pop : val;
pop : val;
(** These are common elements in arbitrary history-style spec *)
(** predicates *)
StackLocal : StackLocalNT Σ;
StackInv : StackInvT Σ;
(** predicates properties *)
StackInv_Objective : ∀ γg γs s E omo stlist, Objective (StackInv γg γs s E omo stlist);
StackInv_Timeless : ∀ γg γs s E omo stlist, Timeless (StackInv γg γs s E omo stlist);
StackInv_Linearizable : ∀ γg γs s E omo stlist, StackInv γg γs s E omo stlist ⊢ ⌜ Linearizability_omo E omo stlist ⌝;
StackInv_OmoAuth_acc : ∀ γg γs s E omo stlist,
StackInv γg γs s E omo stlist ⊢ OmoAuth γg γs (1/2)%Qp E omo stlist _ ∗ (OmoAuth γg γs (1/2)%Qp E omo stlist _ -∗ StackInv γg γs s E omo stlist);
StackLocal_OmoEview : ∀ N γg s M, StackLocal N γg s M ⊢ OmoEview γg M;
StackLocal_Eview_update : ∀ N γg s M1 M2, StackLocal N γg s M1 -∗ OmoEview γg M2 -∗ StackLocal N γg s (M1 ∪ M2);
StackLocal_Persistent :
∀ N γg s M, Persistent (StackLocal N γg s M);
(**************************************************************)
(* operations specs *)
new_stack_dspec : new_stack_dspec' new_stack StackLocal StackInv;
try_push_dspec : try_push_dspec' try_push StackLocal StackInv;
push_dspec : push_dspec' push StackLocal StackInv;
try_pop_dspec : try_pop_dspec' try_pop StackLocal StackInv;
pop_dspec : pop_dspec' pop StackLocal StackInv;
}.
Arguments stack_spec _ {_ _ _}.
Global Existing Instances StackInv_Objective StackInv_Timeless StackLocal_Persistent
new_stack_dspec try_push_dspec push_dspec try_pop_dspec pop_dspec.