-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec_abs_graph.v
272 lines (250 loc) · 11 KB
/
spec_abs_graph.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
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
From stdpp Require Import namespaces.
From gpfsl.logic Require Import logatom.
From gpfsl.examples.graph Require Export spec.
From gpfsl.examples.queue Require Export event spec_graph.
Require Import iris.prelude.options.
Local Open Scope Z_scope.
Local Notation graph := (graph qevent).
Implicit Type (Q : queue) (G : graph) (M : logView).
(** * Hybrid Specs with both Abstract State and Partial Orders (Event Graph) *)
(** Queue predicate with abstract state *)
Definition QueueInvT Σ : Type :=
gname → loc → queue → graph → vProp Σ.
(** Operation specs *)
Definition new_queue_spec' {Σ} `{!noprolG Σ, !inG Σ (graphR qevent)}
(new_queue : val) (QueueLocal : QueueLocalT Σ) (QueueInv : QueueInvT Σ) : Prop :=
∀ N tid,
{{{ True }}}
new_queue [] @ tid; ⊤
{{{ γg (q: loc), RET #q; QueueLocal N γg q ∅ ∅ ∗ QueueInv γg q [] ∅ }}}.
Definition enqueue_spec' {Σ} `{!noprolG Σ, !inG Σ (graphR qevent)}
(enqueue : val) (QueueLocal : QueueLocalT Σ) (QueueInv : QueueInvT Σ) : Prop :=
∀ N (DISJ: N ## histN) (q : loc) tid γg G1 M (V : view) (v : Z) (Posx: 0 < v),
(* PRIVATE PRE *)
⊒V -∗ QueueLocal N γg q G1 M -∗ (* G1 is a snapshot of the graph, locally observed by M *)
(* PUBLIC PRE *)
<<< ∀ Q G, ▷ QueueInv γg q Q G >>>
enqueue [ #q ; #v] @ tid; ↑N
<<< ∃ V' Q' G' (enqId : event_id) enq Venq M',
(* PUBLIC POST *)
▷ QueueInv γg q Q' G' ∗
⊒V' ∗ @{V'} QueueLocal N γg q G' M' ∗
⌜ G ⊑ G' ∧ M ⊑ M' ∧
V ⊑ Venq.(dv_in) ∧ Venq.(dv_wrt) = V' ∧
Q' = Q ++ [(v, Venq.(dv_comm))] ∧
(* enq is a new enqueue event with which G' strictly extends G *)
is_enqueue enq v ∧
enqId = length G.(Es) ∧
G'.(Es) = G.(Es) ++ [mkGraphEvent enq Venq M'] ∧
G'.(so) = G.(so) ∧ G'.(com) = G.(com) ∧
enqId ∈ M' (* << M' may also acquire more events that
come with the Enqueue (acquired by reading the Head pointer). *) ∧
enqId ∉ M ⌝,
(* RETURN VALUE AT COMMITTING POINT *)
RET #☠, emp >>>
.
Definition dequeue_spec' {Σ} `{!noprolG Σ, !inG Σ (graphR qevent)}
(dequeue : val) (QueueLocal : QueueLocalT Σ) (QueueInv : QueueInvT Σ) : Prop :=
∀ N (DISJ: N ## histN) (q : loc) tid γg G1 M V,
(* PRIVATE PRE *)
⊒V -∗ QueueLocal N γg q G1 M -∗
(* PUBLIC PRE *)
<<< ∀ Q G, ▷ QueueInv γg q Q G >>>
dequeue [ #q] @ tid; ↑N
<<< ∃ (v: Z) V' Q' G' enqId deqId enq deq Venq Vdeq M',
(* PUBLIC POST *)
▷ QueueInv γg q Q' G' ∗
⊒V' ∗ @{V'} QueueLocal N γg q G' M' ∗
⌜ G ⊑ G' ∧ M ⊑ M' ∧
V ⊑ Vdeq.(dv_in) ∧ Vdeq.(dv_comm) = V' ∧
( (* EMPTY case *)
( Q' = Q ∧
v = 0 ∧ deq = EmpDeq ∧
deqId = length G.(Es) ∧
G'.(Es) = G.(Es) ++ [mkGraphEvent deq Vdeq M'] ∧
G'.(so) = G.(so) ∧ G'.(com) = G.(com) ∧
{[deqId]} ∪ M ⊆ M' ∧ deqId ∉ M)
∨ (* successful case *)
(Q = (v, Venq.(dv_comm)) :: Q' ∧
0 < v ∧ is_enqueue enq v ∧ is_dequeue deq v ∧
deqId = length G.(Es) ∧
(∀ id, (enqId, id) ∉ G.(so)) ∧
G'.(Es) = G.(Es) ++ [mkGraphEvent deq Vdeq M'] ∧
G'.(so) = {[(enqId, deqId)]} ∪ G.(so) ∧
G'.(com) = {[(enqId, deqId)]} ∪ G.(com) ∧
enqId ∈ M' ∧ deqId ∈ M' ∧ deqId ∉ M ∧
∃ eV, G.(Es) !! enqId = Some eV ∧ eV.(ge_event) = enq ∧
eV.(ge_view) = Venq ∧ eV.(ge_lview) ⊆ M') ) ⌝,
(* RETURN VALUE AT COMMITTING POINT *)
RET #v, emp >>>
.
Definition try_enq_spec' {Σ} `{!noprolG Σ, !inG Σ (graphR qevent)}
(try_enq : val) (QueueLocal : QueueLocalT Σ) (QueueInv : QueueInvT Σ) : Prop :=
∀ N (DISJ: N ## histN) (q : loc) tid γg G1 M (V : view) (v : Z) (Posx: 0 < v),
(* PRIVATE PRE *)
⊒V -∗ QueueLocal N γg q G1 M -∗
(* PUBLIC PRE *)
<<< ∀ Q G, ▷ QueueInv γg q Q G >>>
try_enq [ #q ; #v] @ tid; ↑N
<<< ∃ (b: bool) V' Q' G' (enqId : event_id) enq Venq M',
(* PUBLIC POST *)
▷ (QueueInv γg q Q' G') ∗
⊒V' ∗ @{V'} QueueLocal N γg q G' M' ∗
⌜ G ⊑ G' ∧ M ⊑ M' ∧
V ⊑ Venq.(dv_in) ∧ Venq.(dv_wrt) = V' ∧
if b is false then
Q' = Q ∧ G' = G
else
(* enq is a new enqueue event with which G' strictly extends G *)
Q' = Q ++ [(v, Venq.(dv_comm))] ∧
is_enqueue enq v ∧
enqId = length G.(Es) ∧
G'.(Es) = G.(Es) ++ [mkGraphEvent enq Venq M'] ∧
G'.(so) = G.(so) ∧ G'.(com) = G.(com) ∧
enqId ∈ M' ∧ enqId ∉ M ⌝,
(* RETURN VALUE AT COMMITTING POINT *)
RET #b, emp >>>
.
Definition try_deq_spec' {Σ} `{!noprolG Σ, !inG Σ (graphR qevent)}
(try_deq : val) (QueueLocal : QueueLocalT Σ) (QueueInv : QueueInvT Σ) : Prop :=
∀ N (DISJ: N ## histN) (q : loc) tid γg G1 M V,
(* PRIVATE PRE *)
⊒V -∗ QueueLocal N γg q G1 M -∗
<<< (* PUBLIC PRE *)
∀ Q G, ▷ (QueueInv γg q Q G) >>>
try_deq [ #q] @ tid; ↑N
<<< ∃ (v: Z) V' Q' G' enqId deqId enq deq Venq Vdeq M',
(* PUBLIC POST *)
▷ (QueueInv γg q Q' G') ∗
⊒V' ∗ @{V'} QueueLocal N γg q G' M' ∗
⌜ G ⊑ G' ∧ M ⊑ M' ∧
V ⊑ Vdeq.(dv_in) ∧ Vdeq.(dv_comm) = V' ∧
(* FAIL case *)
((Q' = Q ∧ v < 0 ∧ G' = G)
∨ (* EMPTY case *)
( Q' = Q ∧
v = 0 ∧ deq = EmpDeq ∧
deqId = length G.(Es) ∧
G'.(Es) = G.(Es) ++ [mkGraphEvent deq Vdeq M'] ∧
G'.(so) = G.(so) ∧ G'.(com) = G.(com) ∧
{[deqId]} ∪ M ⊆ M' ∧ deqId ∉ M)
∨ (* successful case *)
(Q = (v, Venq.(dv_comm)) :: Q' ∧
0 < v ∧ is_enqueue enq v ∧ is_dequeue deq v ∧
deqId = length G.(Es) ∧
(∀ id, (enqId, id) ∉ G.(so)) ∧
G'.(Es) = G.(Es) ++ [mkGraphEvent deq Vdeq M'] ∧
G'.(so) = {[(enqId, deqId)]} ∪ G.(so) ∧
G'.(com) = {[(enqId, deqId)]} ∪ G.(com) ∧
enqId ∈ M' ∧ deqId ∈ M' ∧ deqId ∉ M ∧
∃ eV, G.(Es) !! enqId = Some eV ∧ eV.(ge_event) = enq ∧
eV.(ge_view) = Venq ∧ eV.(ge_lview) ⊆ M') ) ⌝,
(* RETURN VALUE AT COMMITTING POINT *)
RET #v, emp >>>
.
(** Bundling of specs *)
Record core_queue_spec {Σ} `{!noprolG Σ, !inG Σ (graphR qevent)}
{QueueConsistent : graph → Prop} := QueueSpec {
(* operations *)
new_queue : val;
enqueue : val;
dequeue : val;
(* predicates *)
QueueLocal : QueueLocalT Σ;
QueueInv : QueueInvT Σ;
(** predicates properties *)
QueueInv_Timeless : ∀ γg q Q G, Timeless (QueueInv γg q Q G);
QueueInv_Objective : ∀ γg q Q G, Objective (QueueInv γg q Q G);
QueueInv_QueueConsistent : ∀ γg q Q G, QueueInv γg q Q G ⊢ ⌜ QueueConsistent G ⌝;
QueueInv_graph_master_acc :
∀ γg q Q G, QueueInv γg q Q G ⊢ graph_master γg (1/2) G ∗
(graph_master γg (1/2) G -∗ QueueInv γg q Q G);
QueueLocal_graph_snap :
∀ N γg q G M, QueueLocal N γg q G M ⊢ graph_snap γg G M;
QueueLocal_Persistent :
∀ N γg q G M, Persistent (QueueLocal N γg q G M);
(* operations specs *)
new_queue_spec : new_queue_spec' new_queue QueueLocal QueueInv;
enqueue_spec : enqueue_spec' enqueue QueueLocal QueueInv;
dequeue_spec : dequeue_spec' dequeue QueueLocal QueueInv;
}.
Arguments core_queue_spec _ {_ _} _.
Record extended_queue_spec {Σ} `{!noprolG Σ, !inG Σ (graphR qevent)}
{QueueConsistent : graph → Prop} := ExtendedQueueSpec {
extended_core_spec :> core_queue_spec Σ QueueConsistent ;
(* extra operations *)
try_enq : val;
try_deq : val;
(* operations specs *)
try_enq_spec :
try_enq_spec' try_enq extended_core_spec.(QueueLocal) extended_core_spec.(QueueInv);
try_deq_spec :
try_deq_spec' try_deq extended_core_spec.(QueueLocal) extended_core_spec.(QueueInv);
}.
Arguments extended_queue_spec _ {_ _} _.
(** A Strong queue spec, with 5 operations with Strong Consistency *)
Definition strong_queue_spec Σ `{!noprolG Σ, !inG Σ (graphR qevent)}
:= extended_queue_spec Σ StrongQueueConsistent.
(** A Weak queue spec, with 3 operations and Weak Consistency *)
Definition weak_queue_spec Σ `{!noprolG Σ, !inG Σ (graphR qevent)}
:= core_queue_spec Σ WeakQueueConsistent.
(** Basic queue spec, with 3 operations and Basic Consistency *)
Definition basic_queue_spec Σ `{!noprolG Σ, !inG Σ (graphR qevent)}
:= core_queue_spec Σ BasicQueueConsistent.
(** Strong implies Weak *)
Program Definition extended_strong_weak_queue_spec
Σ `{!noprolG Σ, !inG Σ (graphR qevent)}
(sq : strong_queue_spec Σ) : extended_queue_spec Σ WeakQueueConsistent :=
{|
extended_core_spec := {|
QueueInv_Timeless := sq.(QueueInv_Timeless);
QueueInv_Objective := sq.(QueueInv_Objective);
QueueInv_graph_master_acc := sq.(QueueInv_graph_master_acc);
QueueLocal_graph_snap := sq.(QueueLocal_graph_snap) ;
QueueLocal_Persistent := sq.(QueueLocal_Persistent) ;
new_queue_spec := sq.(new_queue_spec) ;
enqueue_spec := sq.(enqueue_spec) ;
dequeue_spec := sq.(dequeue_spec);
|} ;
try_enq_spec := sq.(try_enq_spec) ;
try_deq_spec := sq.(try_deq_spec) ;
|}.
Next Obligation.
iIntros "* QI".
by iDestruct (sq.(QueueInv_QueueConsistent) with "QI") as %SC%strq_wkq_cons.
Qed.
Program Definition strong_weak_queue_spec
Σ `{!noprolG Σ, !inG Σ (graphR qevent)}
(sq : strong_queue_spec Σ) : weak_queue_spec Σ :=
{|
QueueInv_Timeless := sq.(QueueInv_Timeless);
QueueInv_Objective := sq.(QueueInv_Objective);
QueueInv_graph_master_acc := sq.(QueueInv_graph_master_acc);
QueueLocal_graph_snap := sq.(QueueLocal_graph_snap) ;
QueueLocal_Persistent := sq.(QueueLocal_Persistent) ;
new_queue_spec := sq.(new_queue_spec) ;
enqueue_spec := sq.(enqueue_spec) ;
dequeue_spec := sq.(dequeue_spec) ;
|}.
Next Obligation.
iIntros "* QI".
by iDestruct (sq.(QueueInv_QueueConsistent) with "QI") as %SC%strq_wkq_cons.
Qed.
(** Weak implies Basic *)
Program Definition weak_basic_queue_spec
Σ `{!noprolG Σ, !inG Σ (graphR qevent)}
(wq : weak_queue_spec Σ) : basic_queue_spec Σ :=
{|
QueueInv_Timeless := wq.(QueueInv_Timeless);
QueueInv_Objective := wq.(QueueInv_Objective);
QueueInv_graph_master_acc := wq.(QueueInv_graph_master_acc);
QueueLocal_graph_snap := wq.(QueueLocal_graph_snap) ;
QueueLocal_Persistent := wq.(QueueLocal_Persistent) ;
new_queue_spec := wq.(new_queue_spec) ;
enqueue_spec := wq.(enqueue_spec) ;
dequeue_spec := wq.(dequeue_spec) ;
|}.
Next Obligation.
iIntros "* QI".
by iDestruct (wq.(QueueInv_QueueConsistent) with "QI") as %SC%wkq_bsq_cons.
Qed.