1#[cfg(feature = "sc-drf")]
2use crate::std::sync::atomic_sc::ordering::SeqCst;
3use crate::{
4 ghost::{Perm, perm::PermTarget},
5 logic::FMap,
6 prelude::*,
7 std::sync::{
8 atomic::ordering::{Acquire, Relaxed, Release},
9 view::{AcquireSyncView, HasTimestamp, ReleaseSyncView, SyncView, Timestamp},
10 },
11};
12use core::marker::PhantomData;
13
14#[opaque]
21pub struct Committer<C: PermTarget, T, Load, Store>(PhantomData<(C, T, Load, Store)>);
22
23impl<C: PermTarget, T, Load, Store> Committer<C, T, Load, Store> {
24 #[logic(opaque)]
28 pub fn ward(self) -> C {
29 dead
30 }
31
32 #[logic(opaque)]
36 pub fn timestamp(self) -> Timestamp {
37 dead
38 }
39
40 #[logic(opaque)]
42 pub fn val_load(self) -> T {
43 dead
44 }
45
46 #[logic(opaque)]
48 pub fn val_store(self) -> T {
49 dead
50 }
51
52 #[logic(opaque)]
54 pub fn shot_store(self) -> bool {
55 dead
56 }
57
58 #[logic(open, inline)]
59 pub fn hist_inv(self, other: Self) -> bool {
60 self.ward() == other.ward()
61 && self.val_load() == other.val_load()
62 && self.val_store() == other.val_store()
63 && self.timestamp() == other.timestamp()
64 }
65}
66
67impl<C, T, Store> Committer<C, T, Relaxed, Store>
68where
69 C: PermTarget<Value = FMap<Timestamp, (T, SyncView)>> + HasTimestamp,
70{
71 #[requires(!self.shot_store())]
75 #[requires(self.ward() == *(*own).ward())]
76 #[ensures(*sync_view <= ^sync_view)]
77 #[ensures(self.ward().get_timestamp(*sync_view) <= self.timestamp())]
78 #[ensures(self.timestamp() <= self.ward().get_timestamp(^sync_view))]
79 #[ensures(own.val().get(self.timestamp()) == Some((self.val_load(), result@)))]
80 #[check(ghost)]
81 #[trusted]
82 #[allow(unused_variables)]
83 pub fn shoot_load(&self, own: &Perm<C>, sync_view: &mut SyncView) -> AcquireSyncView {
84 panic!("Should not be called outside ghost code")
85 }
86}
87
88impl<C, T, Store> Committer<C, T, Acquire, Store>
89where
90 C: PermTarget<Value = FMap<Timestamp, (T, SyncView)>> + HasTimestamp,
91{
92 #[requires(!self.shot_store())]
96 #[requires(self.ward() == *(*own).ward())]
97 #[ensures(*sync_view <= ^sync_view)]
98 #[ensures(self.ward().get_timestamp(*sync_view) <= self.timestamp())]
99 #[ensures(self.timestamp() <= self.ward().get_timestamp(^sync_view))]
100 #[ensures(match own.val().get(self.timestamp()) {
101 Some((v, v_view)) => v == self.val_load() && v_view <= ^sync_view,
102 None => false
103 })]
104 #[check(ghost)]
105 #[trusted]
106 #[allow(unused_variables)]
107 pub fn shoot_load(&self, own: &Perm<C>, sync_view: &mut SyncView) {
108 panic!("Should not be called outside ghost code")
109 }
110}
111
112#[cfg(feature = "sc-drf")]
113impl<C, Store> Committer<C, C::Value, SeqCst, Store>
114where
115 C: PermTarget,
116 C::Value: Sized,
117{
118 #[requires(!self.shot_store())]
122 #[requires(self.ward() == *(*own).ward())]
123 #[ensures(self.val_load() == own.val())]
124 #[check(ghost)]
125 #[trusted]
126 #[allow(unused_variables)]
127 pub fn shoot_load(&self, own: &Perm<C>) {
128 panic!("Should not be called outside ghost code")
129 }
130}
131
132impl<C, T, Load> Committer<C, T, Load, Relaxed>
133where
134 C: PermTarget<Value = FMap<Timestamp, (T, SyncView)>> + HasTimestamp,
135{
136 #[requires(!(*self).shot_store())]
140 #[requires(self.ward() == *(*own).ward())]
141 #[ensures((*self).hist_inv(^self))]
142 #[ensures((^self).shot_store())]
143 #[ensures((*own).ward() == (^own).ward())]
144 #[ensures(*sync_view <= ^sync_view)]
145 #[ensures((*self).ward().get_timestamp(*sync_view) <= self.timestamp())]
146 #[ensures(self.timestamp() < (*self).ward().get_timestamp(^sync_view))]
147 #[ensures((*own).val().get(self.timestamp() + 1) == None)]
148 #[ensures((^own).val() == (*own).val().insert(self.timestamp() + 1, ((*self).val_store(), rel_view@)))]
149 #[check(ghost)]
150 #[trusted]
151 #[allow(unused_variables)]
152 pub fn shoot_store(
153 &mut self,
154 own: &mut Perm<C>,
155 sync_view: &mut SyncView,
156 rel_view: ReleaseSyncView,
157 ) {
158 panic!("Should not be called outside ghost code")
159 }
160}
161
162impl<C, T, Load> Committer<C, T, Load, Release>
163where
164 C: PermTarget<Value = FMap<Timestamp, (T, SyncView)>> + HasTimestamp,
165{
166 #[requires(!(*self).shot_store())]
170 #[requires(self.ward() == *(*own).ward())]
171 #[ensures((*self).hist_inv(^self))]
172 #[ensures((^self).shot_store())]
173 #[ensures((*own).ward() == (^own).ward())]
174 #[ensures(*sync_view <= ^sync_view)]
175 #[ensures((*self).ward().get_timestamp(*sync_view) <= self.timestamp())]
176 #[ensures(self.timestamp() < (*self).ward().get_timestamp(^sync_view))]
177 #[ensures((*own).val().get(self.timestamp() + 1) == None)]
178 #[ensures((^own).val() == (*own).val().insert(self.timestamp() + 1, ((*self).val_store(), ^sync_view)))]
179 #[check(ghost)]
180 #[trusted]
181 #[allow(unused_variables)]
182 pub fn shoot_store(&mut self, own: &mut Perm<C>, sync_view: &mut SyncView) {
183 panic!("Should not be called outside ghost code")
184 }
185}
186
187#[cfg(feature = "sc-drf")]
188impl<C, Load> Committer<C, C::Value, Load, SeqCst>
189where
190 C: PermTarget,
191 C::Value: Sized,
192{
193 #[requires(!(*self).shot_store())]
197 #[requires(self.ward() == *(*own).ward())]
198 #[ensures((*self).hist_inv(^self))]
199 #[ensures((^self).shot_store())]
200 #[ensures((*own).ward() == (^own).ward())]
201 #[ensures((^own).val() == (*self).val_store())]
202 #[check(ghost)]
203 #[trusted]
204 #[allow(unused_variables)]
205 pub fn shoot_store(&mut self, own: &mut Perm<C>) {
206 panic!("Should not be called outside ghost code")
207 }
208}