-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec_treiber_composition_diaframe.v
216 lines (192 loc) · 7.7 KB
/
spec_treiber_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
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 Σ) :=
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 Σ) :=
try_push_dspec'' :> ∀ (V : view) N γg (s : loc) M (v : Z), SPEC ⟨ ⊤ , ↑N , ↑histN⟩ E γs 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 *)
∃ omo' stlist' st M',
let E' := (E ++ [mkOmoEvent (Push v) V' M']) in
▷ StackInv γg γs s E' omo' stlist' ∗
⌜ omo' = omo_append_w omo (length E) [] ∧ stlist' = stlist ++ [st] ⌝ ∗
@{V'} StackLocal N γg s M' ∗ ⌜ V ⊑ V' ∧ M ⊆ M' ⌝ ∗
OmoUB γg M (length E) ∗
OmoTokenW γg (length E)
) 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 Σ) :=
push_dspec'' :> ∀ (V : view) N γg s M v,
SPEC ⟨ ⊤ , ↑N , ↑histN⟩ E γs omo stlist, <<
(* PRIVATE PRE *)
⊒V ∗
StackLocal N γg s M ∗
⌜ (0 < v)%Z ⌝ ∗
⌜ N ## histN ⌝
¦
(* PUBLIC PRE *)
▷ StackInv γg γs s E omo stlist > >
push [ #s ; #v]
<< RET #☠;
emp
¦
(* PUBLIC POST *)
(∃ V', ⊒V' ∗
∃ omo' stlist' st M',
let E' := (E ++ [mkOmoEvent (Push v) V' M']) in
▷ StackInv γg γs s E' omo' stlist' ∗
⌜ omo' = omo_append_w omo (length E) [] ∧ stlist' = stlist ++ [st] ⌝ ∗
@{V'} StackLocal N γg s M' ∗ ⌜ V ⊑ V' ∧ M ⊆ M' ⌝ ∗
OmoUB γg M (length E) ∗
OmoTokenW γg (length E)
)
> >.
Class try_pop_dspec' {Σ} `{!noprolG Σ, !omoGeneralG Σ}
(try_pop : val) (StackLocal : StackLocalNT Σ) (StackInv : StackInvT Σ) :=
try_pop_dspec'' :> ∀ (V : view) N γg (s : loc) M,
SPEC ⟨ ⊤ , ↑N , ↑histN⟩ E γs 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 (
∃ omo' stlist' M', ⌜ V ⊑ V' ⌝ ∗
(if (decide (v = EMPTY)) then (
∃ gen,
let E' := E ++ [mkOmoEvent EmpPop V' M'] in
▷ StackInv γg γs s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ (gen < length omo)%nat ∧ stlist' = stlist ∧ omo' = omo_insert_r omo gen (length E) ⌝ ∗
OmoTokenR γg (length E)
) else ( (* successful case *)
∃ st,
let E' := E ++ [mkOmoEvent (Pop v) V' M'] in
▷ StackInv γg γs s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_append_w omo (length E) [] ∧ stlist' = stlist ++ [st] ⌝ ∗
OmoTokenW γg (length E)
)) ∗
OmoUB γg M (length E) ∗ ⌜ M ⊆ M' ⌝
)
)
> >.
Class pop_dspec' {Σ} `{!noprolG Σ, !omoGeneralG Σ}
(pop : val) (StackLocal : StackLocalNT Σ) (StackInv : StackInvT Σ) :=
pop_dspec'' :> ∀ (V : view) N γg (s : loc) M, SPEC ⟨ ⊤ , ↑N , ↑histN⟩ E γs 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' ∗
OmoUB γg M (length E) ∗
∃ omo' stlist' M',
⌜ V ⊑ V' ⌝ ∗
(if (decide (v = EMPTY)) then (
∃ gen,
let E' := E ++ [mkOmoEvent EmpPop V' M'] in
▷ StackInv γg γs s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ (gen < length omo)%nat ∧ stlist' = stlist ∧ omo' = omo_insert_r omo gen (length E) ⌝
) else ( (* successful case *)
∃ st,
let E' := E ++ [mkOmoEvent (Pop v) V' M'] in
▷ StackInv γg γs s E' omo' stlist' ∗ @{V'} StackLocal N γg s M' ∗
⌜ omo' = omo_append_w omo (length E) [] ∧ stlist' = stlist ++ [st] ⌝ ∗
OmoTokenW γg (length E)
)) ∗ ⌜ M ⊆ M' ⌝
)
> >.
Record stack_dspec {Σ} `{!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 E omo stlist _ ∗ (OmoAuth γg γs 1 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_dspec _ {_ _ _}.
Global Existing Instances StackInv_Objective StackInv_Timeless StackLocal_Persistent
new_stack_dspec try_push_dspec push_dspec try_pop_dspec pop_dspec.