-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.v
202 lines (178 loc) · 6.61 KB
/
client.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
From iris.base_logic.lib Require Import invariants.
From smr.program_logic Require Import atomic.
From smr.lang Require Import adequacy notation proofmode.
From smr.no_recl Require Import closed_proofs.
From iris.prelude Require Import options.
Section code.
Definition counter_code := counter_code_impl.
Definition treiber_code := treiber_code_impl.
Definition elimstack_code := elimstack_code_impl.
Definition ms_code := ms_code_impl.
Definition dglm_code := dglm_code_impl.
Definition rdcss_code := rdcss_code_impl.
Definition cldeque_code := cldeque_code_impl.
Definition client1 : val := λ: <>,
let: "c" := counter_code.(spec_counter.counter_new) #() in
counter_code.(spec_counter.counter_inc) "c";;
let: "s" := treiber_code.(spec_stack.stack_new) #() in
let: "q" := ms_code.(spec_queue.queue_new) #() in
treiber_code.(spec_stack.stack_push) "s" #1%Z;;
ms_code.(spec_queue.queue_push) "q" #2%Z;;
let: "oa" := treiber_code.(spec_stack.stack_pop) "s" in
let: "ob" := ms_code.(spec_queue.queue_pop) "q" in
let: "a" :=
match: "oa" with
NONE => #()
| SOME "a" => "a"
end
in
let: "b" :=
match: "ob" with
NONE => #()
| SOME "b" => "b"
end
in
"a" + "b".
Definition client2 : val := λ: <>,
let: "s" := treiber_code.(spec_stack.stack_new) #() in
Fork(
treiber_code.(spec_stack.stack_push) "s" #10%Z;;
treiber_code.(spec_stack.stack_pop) "s"
);;
treiber_code.(spec_stack.stack_push) "s" #10%Z;;
treiber_code.(spec_stack.stack_pop) "s";;
#().
Definition client3 : val := λ: <>,
let: "s1" := elimstack_code.(spec_stack.stack_new) #() in
let: "s2" := elimstack_code.(spec_stack.stack_new) #() in
elimstack_code.(spec_stack.stack_push) "s1" #10%Z;;
let: "oa" := elimstack_code.(spec_stack.stack_pop) "s1" in
let: "a" :=
match: "oa" with
NONE => #()
| SOME "a" => "a"
end
in
elimstack_code.(spec_stack.stack_push) "s2" "a";;
let: "ob" := elimstack_code.(spec_stack.stack_pop) "s2" in
match: "ob" with
NONE => #()
| SOME "b" => "b"
end
.
End code.
Section proof.
Context `{!heapGS Σ, !counterG Σ, !treiberG Σ, !elimstackG Σ, msG Σ}.
Definition counter := counter_impl Σ.
Definition treiber := treiber_impl Σ.
Definition elimstack := elimstack_impl Σ.
Definition ms := ms_impl Σ.
Definition clientN := nroot .@ "client".
Lemma client1_spec :
{{{ True }}}
client1 #()
{{{ RET #3; True }}}.
Proof using All.
iIntros (Φ) "_ HΦ".
wp_lam.
(* counters *)
wp_apply (counter.(spec_counter.counter_new_spec) with "[//]") as (??) "[#IC C]".
wp_let.
awp_apply (counter.(spec_counter.counter_inc_spec) with "IC") without "HΦ".
iAaccIntro with "C"; first by eauto with iFrame.
iIntros "C !> _ HΦ". wp_seq.
(* stack, queue *)
wp_apply (treiber.(spec_stack.stack_new_spec) with "[//]") as (??) "[#IS S]".
wp_let.
wp_apply (ms.(spec_queue.queue_new_spec) with "[//]") as (??) "[#IQ Q]".
wp_let.
(* NOTE: we need to explictly give the values for push
because Coq will otherwise not be able to do unification.
Suspected reason is simplification due to [of_val] *)
awp_apply (treiber.(spec_stack.stack_push_spec) $! _ _ #1 with "IS") without "HΦ".
iAaccIntro with "S"; first by eauto with iFrame.
iIntros "S !> _ HΦ". wp_seq.
awp_apply (ms.(spec_queue.queue_push_spec) $! _ _ #2 with "IQ") without "HΦ".
iAaccIntro with "Q"; first by eauto with iFrame.
iIntros "Q !> _ HΦ". wp_seq.
awp_apply (treiber.(spec_stack.stack_pop_spec) with "IS") without "HΦ"; eauto.
iAaccIntro with "S"; first by eauto with iFrame.
iIntros "S !> _ HΦ". wp_pures.
awp_apply (ms.(spec_queue.queue_pop_spec) with "IQ") without "HΦ"; eauto.
iAaccIntro with "Q"; first by eauto with iFrame.
iIntros "Q !> _ HΦ". wp_pures.
by iApply "HΦ".
Qed.
Lemma client2_spec :
{{{ True }}}
client2 #()
{{{ RET #(); True }}}.
Proof using All.
iIntros (Φ) "_ HΦ".
wp_lam.
wp_apply (treiber.(spec_stack.stack_new_spec) with "[//]") as (??) "[#IS S]".
wp_let.
iMod (inv_alloc clientN _ (∃ xs, TStack γ xs) with "[S]") as "#SInv". { eauto. }
wp_apply wp_fork.
{ awp_apply (treiber.(spec_stack.stack_push_spec) $! _ _ #10 with "IS").
iInv "SInv" as (xs) ">S". iAaccIntro with "S".
{ iIntros "S !>". iFrame. eauto. }
iIntros "S !>". iSplitL "S"; eauto.
iIntros "_". wp_seq.
awp_apply (treiber.(spec_stack.stack_pop_spec) with "IS"); auto.
iInv "SInv" as (xs') ">S". iAaccIntro with "S".
{ iIntros "S". eauto with iFrame. }
iIntros "S !>". iSplitL "S"; eauto with iFrame.
}
iIntros. wp_seq.
awp_apply (treiber.(spec_stack.stack_push_spec) $! _ _ #10 with "IS").
iInv "SInv" as (xs) ">S". iAaccIntro with "S".
{ iIntros "S !>". iFrame. eauto. }
iIntros "S !>". iSplitL "S"; eauto.
iIntros "_". wp_seq.
awp_apply (treiber.(spec_stack.stack_pop_spec) with "IS") without "HΦ"; auto.
iInv "SInv" as (xs') ">S". iAaccIntro with "S".
{ iIntros "S". eauto with iFrame. }
iIntros "S !>". iSplitL "S"; eauto with iFrame.
iIntros "_ HΦ". wp_pures. by iApply "HΦ".
Qed.
Lemma client3_spec :
{{{ True }}}
client3 #()
{{{ RET #10; True }}}.
Proof using All.
iIntros (Φ) "_ HΦ".
wp_lam. wp_apply (elimstack.(spec_stack.stack_new_spec) with "[//]") as (γ1 ?) "[#IS1 S1]".
wp_let.
wp_apply (elimstack.(spec_stack.stack_new_spec) with "[//]") as (γ2 ?) "[#IS2 S2]".
wp_let.
awp_apply (elimstack.(spec_stack.stack_push_spec) $! _ _ #10 with "IS1") without "HΦ".
iAaccIntro with "S1"; first by eauto with iFrame.
iIntros "S1 !> _ HΦ". wp_seq.
awp_apply (elimstack.(spec_stack.stack_pop_spec) with "IS1") without "HΦ"; eauto.
iAaccIntro with "S1"; first by eauto with iFrame.
iIntros "S1 !> _ HΦ". wp_pures.
awp_apply (elimstack.(spec_stack.stack_push_spec) $! _ _ #10 with "IS2") without "HΦ".
iAaccIntro with "S2"; first by eauto with iFrame.
iIntros "S2 !> _ HΦ". wp_pures.
awp_apply (elimstack.(spec_stack.stack_pop_spec) with "IS2") without "HΦ"; eauto.
iAaccIntro with "S2"; first by eauto with iFrame.
iIntros "S2 !> _ HΦ". wp_pures. by iApply "HΦ".
Qed.
End proof.
Definition clientΣ : gFunctors := #[heapΣ; counterΣ; treiberΣ; elimstackΣ; msΣ].
Lemma client1_adequate σ : adequate NotStuck (client1 #()) σ (λ v _, v = #3).
Proof.
apply (heap_adequacy clientΣ)=> ?.
iIntros "_". iApply client1_spec; done.
Qed.
Lemma client2_adequate σ : adequate NotStuck (client2 #()) σ (λ v _, v = #()).
Proof.
apply (heap_adequacy clientΣ)=> ?.
iIntros "_". iApply client2_spec; done.
Qed.
Lemma client3_adequate σ : adequate NotStuck (client3 #()) σ (λ v _, v = #10).
Proof.
apply (heap_adequacy clientΣ)=> ?.
iIntros "_". iApply client3_spec; done.
Qed.