-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_slot_bag_oloc.v
189 lines (159 loc) · 6.85 KB
/
spec_slot_bag_oloc.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
From smr.program_logic Require Import atomic.
From iris.base_logic.lib Require Import invariants.
From smr.lang Require Import proofmode notation.
From smr Require Import code_slot_bag_oloc.
From iris.prelude Require Import options.
(* NOTE: Sync with spec_slot_bag_onat *)
Definition SlotT Σ : Type :=
∀ (γsb : gname) (slot : loc) (idx : nat) (v : option blk), iProp Σ.
Definition SlotBagT Σ : Type :=
∀ (γsb : gname) (slotBag : loc)
(sbvmap : gmap loc (bool * option blk)) (slist : list loc), iProp Σ.
Definition SlotListT Σ : Type :=
∀ (γsb : gname) (slist : list loc), iProp Σ.
Definition SeqBagT Σ : Type :=
∀ (seqBag : loc) (vs : list (option blk)), iProp Σ.
Section spec.
Context {Σ} `{!heapGS Σ}.
Context
(Slot : SlotT Σ)
(SlotBag : SlotBagT Σ)
(SlotList : SlotListT Σ)
(SeqBag : SeqBagT Σ).
Definition slot_bag_acquire_slot_spec' : Prop :=
⊢ ∀ γsb (slotBag : loc) E,
<<< ∀∀ sbvmap slist, ▷ SlotBag γsb slotBag sbvmap slist >>>
slot_bag_acquire_slot #slotBag @ E,∅,∅
<<< ∃∃ slist' (slot : loc) (idx : nat),
let sbvmap' := <[slot := (true, None)]> sbvmap in
SlotBag γsb slotBag sbvmap' slist' ∗
Slot γsb slot idx None ∗
⌜ (slist' = slist ++ [slot] ∧
sbvmap !! slot = None ∧
idx = length slist) ∨
(slist' = slist ∧
sbvmap !! slot = Some (false, None) ∧
slist !! idx = Some slot) ⌝,
RET #slot >>>.
Definition slot_bag_read_head_spec' : Prop :=
∀ γsb slotBag sbvmap slist E,
{{{ SlotBag γsb slotBag sbvmap slist }}}
! #(slotBag +ₗ 0) @ E
{{{ RET #(oloc_to_lit (last slist));
SlotBag γsb slotBag sbvmap slist ∗
SlotList γsb slist }}}.
Definition slot_set_spec' : Prop :=
⊢ ∀ γsb (slotBag slot : loc) (idx : nat) (v' v : option blk) E,
▷ Slot γsb slot idx v' -∗
<<< ∀∀ sbvmap slist, ▷ SlotBag γsb slotBag sbvmap slist >>>
slot_set #slot #(oblk_to_lit v) @ E,∅,∅
<<< ⌜slist !! idx = Some slot ∧ sbvmap !! slot = Some (true, v')⌝ ∗
SlotBag γsb slotBag (<[slot := (true, v)]> sbvmap) slist ∗
Slot γsb slot idx v,
RET #() >>>.
Definition slot_unset_spec' : Prop :=
⊢ ∀ γsb (slotBag slot : loc) (idx : nat) (v : option blk) E,
▷ Slot γsb slot idx v -∗
<<< ∀∀ sbvmap slist, ▷ SlotBag γsb slotBag sbvmap slist >>>
slot_unset #slot @ E,∅,∅
<<< ⌜slist !! idx = Some slot ∧ sbvmap !! slot = Some (true, v)⌝ ∗
SlotBag γsb slotBag (<[slot := (true, None)]> sbvmap) slist ∗
Slot γsb slot idx None,
RET #() >>>.
Definition slot_bag_new_spec' : Prop :=
⊢ ∀ E,
{{{ True }}}
slot_bag_new #() @ E
{{{ γsb (slotbag : loc), RET #slotbag; SlotBag γsb slotbag ∅ [] }}}.
Definition slot_drop_spec' : Prop :=
⊢ ∀ γsb (slotBag slot : loc) (idx : nat) E,
▷ Slot γsb slot idx None -∗
<<< ∀∀ sbvmap slist, ▷ SlotBag γsb slotBag sbvmap slist >>>
slot_drop #slot @ E,∅,∅
<<< ⌜slist !! idx = Some slot ∧ sbvmap !! slot = Some (true, None)⌝ ∗
let sbvmap' := <[slot := (false, None)]> sbvmap in
SlotBag γsb slotBag sbvmap' slist, RET #() >>>.
Definition slot_read_active_spec' : Prop :=
⊢ ∀ γsb sbvmap (slist : list loc) slotBag (slot : loc) idx E
(_ : slist !! idx = Some slot),
{{{ SlotBag γsb slotBag sbvmap slist }}}
! #(slot +ₗ slotActive) @ E
{{{ (b : bool) v, RET #b;
⌜sbvmap !! slot = Some (b, v)⌝ ∗
SlotBag γsb slotBag sbvmap slist }}}.
Definition slot_read_value_spec' : Prop :=
⊢ ∀ γsb sbvmap (slist : list loc) slotBag (slot : loc) idx E
(_ : slist !! idx = Some slot),
{{{ SlotBag γsb slotBag sbvmap slist }}}
! #(slot +ₗ slotValue) @ E
{{{ b v, RET #(oblk_to_lit v);
⌜sbvmap !! slot = Some (b, v)⌝ ∗
SlotBag γsb slotBag sbvmap slist }}}.
Definition slot_read_next_spec' : Prop :=
⊢ ∀ γsb sbvmap (slist : list loc) slotBag (slot : loc) idx E
(_ : slist !! idx = Some slot),
{{{ SlotBag γsb slotBag sbvmap slist }}}
! #(slot +ₗ slotNext) @ E
{{{ RET #(oloc_to_lit (last (take idx slist)));
SlotBag γsb slotBag sbvmap slist }}}.
Definition SlotBag_lookup' : Prop :=
⊢ ∀ slotBag γsb slot sbvmap slist idx v,
SlotBag γsb slotBag sbvmap slist -∗ Slot γsb slot idx v -∗
⌜slist !! idx = Some slot ∧ sbvmap !! slot = Some (true, v)⌝.
Definition SlotBag_prefix' : Prop :=
⊢ ∀ slotBag γsb sbvmap slist1 slist2,
SlotBag γsb slotBag sbvmap slist1 -∗ SlotList γsb slist2 -∗
⌜slist2 `prefix_of` slist1⌝.
Definition SlotBag_NoDup' : Prop :=
⊢ ∀ slotBag γsb sbvmap slist,
SlotBag γsb slotBag sbvmap slist -∗ ⌜NoDup slist⌝.
Definition seq_bag_new_spec' : Prop :=
∀ E,
{{{ True }}}
seq_bag_new #() @ E
{{{ seqBag, RET #seqBag; SeqBag seqBag [] }}}.
Definition seq_bag_add_spec' : Prop :=
∀ E seqBag vs v,
{{{ SeqBag seqBag vs }}}
seq_bag_add #seqBag #(oblk_to_lit v) @ E
{{{ RET #(); SeqBag seqBag (v :: vs) }}}.
Definition seq_bag_contains_spec' : Prop :=
∀ seqBag vs (v : option blk) E,
{{{ SeqBag seqBag vs }}}
seq_bag_contains #seqBag #(oblk_to_lit v) @ E
{{{ RET #(bool_decide (v ∈ vs));
SeqBag seqBag vs }}}.
Definition seq_bag_contains_other_spec' : Prop :=
∀ seqBag vs (v : option blk) E,
{{{ SeqBag seqBag vs }}}
seq_bag_contains_other #seqBag #(oblk_to_lit v) @ E
{{{ v', RET #(bool_decide (v' ∈ vs ∧ v' ≠ v));
SeqBag seqBag vs }}}.
End spec.
Record slot_bag_spec {Σ} `{!heapGS Σ} : Type := SlotBagSpec {
Slot : SlotT Σ;
SlotBag : SlotBagT Σ;
SlotList : SlotListT Σ;
SeqBag : SeqBagT Σ;
Slot_Timeless : ∀ γsb slot idx v, Timeless (Slot γsb slot idx v);
SlotBag_Timeless : ∀ γsb slotBag sbvmap slist, Timeless (SlotBag γsb slotBag sbvmap slist);
SlotList_Persistent : ∀ γsb slist, Persistent (SlotList γsb slist);
slot_bag_new_spec : slot_bag_new_spec' SlotBag;
slot_bag_acquire_slot_spec : slot_bag_acquire_slot_spec' Slot SlotBag;
slot_bag_read_head_spec : slot_bag_read_head_spec' SlotBag SlotList;
slot_set_spec : slot_set_spec' Slot SlotBag;
slot_unset_spec : slot_unset_spec' Slot SlotBag;
slot_drop_spec : slot_drop_spec' Slot SlotBag;
slot_read_active_spec : slot_read_active_spec' SlotBag;
slot_read_value_spec : slot_read_value_spec' SlotBag;
slot_read_next_spec : slot_read_next_spec' SlotBag;
SlotBag_lookup : SlotBag_lookup' Slot SlotBag;
SlotBag_prefix : SlotBag_prefix' SlotBag SlotList;
SlotBag_NoDup : SlotBag_NoDup' SlotBag;
seq_bag_new_spec : seq_bag_new_spec' SeqBag;
seq_bag_add_spec : seq_bag_add_spec' SeqBag;
seq_bag_contains_spec : seq_bag_contains_spec' SeqBag;
seq_bag_contains_other_spec : seq_bag_contains_other_spec' SeqBag;
}.
Global Arguments slot_bag_spec _ {_}.
Global Existing Instances Slot_Timeless SlotBag_Timeless SlotList_Persistent.