#[cfg(feature = "sc-drf")]
use crate::std::sync::atomic_sc::ordering::SeqCst;
use crate::{
ghost::{Perm, perm::PermTarget},
logic::FMap,
prelude::*,
std::sync::{
atomic::ordering::{Acquire, Relaxed, Release},
view::{AcquireSyncView, HasTimestamp, ReleaseSyncView, SyncView, Timestamp},
},
};
use core::marker::PhantomData;
#[opaque]
pub struct Committer<C: PermTarget, T, Load, Store>(PhantomData<(C, T, Load, Store)>);
impl<C: PermTarget, T, Load, Store> Committer<C, T, Load, Store> {
#[logic(opaque)]
pub fn ward(self) -> C {
dead
}
#[logic(opaque)]
pub fn timestamp(self) -> Timestamp {
dead
}
#[logic(opaque)]
pub fn val_load(self) -> T {
dead
}
#[logic(opaque)]
pub fn val_store(self) -> T {
dead
}
#[logic(opaque)]
pub fn shot_store(self) -> bool {
dead
}
#[logic(open, inline)]
pub fn hist_inv(self, other: Self) -> bool {
self.ward() == other.ward()
&& self.val_load() == other.val_load()
&& self.val_store() == other.val_store()
&& self.timestamp() == other.timestamp()
}
}
impl<'a, C, T, Store> Committer<C, T, Relaxed, Store>
where
C: PermTarget<Value<'a> = FMap<Timestamp, (T, SyncView)>> + HasTimestamp + 'a,
{
#[requires(!self.shot_store())]
#[requires(self.ward() == *(*own).ward())]
#[ensures(*sync_view <= ^sync_view)]
#[ensures(self.ward().get_timestamp(*sync_view) <= self.timestamp())]
#[ensures(self.timestamp() <= self.ward().get_timestamp(^sync_view))]
#[ensures(own.val().get(self.timestamp()) == Some((self.val_load(), result@)))]
#[check(ghost)]
#[trusted]
#[allow(unused_variables)]
pub fn shoot_load(&self, own: &Perm<C>, sync_view: &mut SyncView) -> AcquireSyncView {
panic!("Should not be called outside ghost code")
}
}
impl<'a, C, T, Store> Committer<C, T, Acquire, Store>
where
C: PermTarget<Value<'a> = FMap<Timestamp, (T, SyncView)>> + HasTimestamp + 'a,
{
#[requires(!self.shot_store())]
#[requires(self.ward() == *(*own).ward())]
#[ensures(*sync_view <= ^sync_view)]
#[ensures(self.ward().get_timestamp(*sync_view) <= self.timestamp())]
#[ensures(self.timestamp() <= self.ward().get_timestamp(^sync_view))]
#[ensures(match own.val().get(self.timestamp()) {
Some((v, v_view)) => v == self.val_load() && v_view <= ^sync_view,
None => false
})]
#[check(ghost)]
#[trusted]
#[allow(unused_variables)]
pub fn shoot_load(&self, own: &Perm<C>, sync_view: &mut SyncView) {
panic!("Should not be called outside ghost code")
}
}
#[cfg(feature = "sc-drf")]
impl<'a, C, Store> Committer<C, C::Value<'a>, SeqCst, Store>
where
C: PermTarget,
{
#[requires(!self.shot_store())]
#[requires(self.ward() == *(*own).ward())]
#[ensures(self.val_load() == own.val())]
#[check(ghost)]
#[trusted]
#[allow(unused_variables)]
pub fn shoot_load(&self, own: &Perm<C>) {
panic!("Should not be called outside ghost code")
}
}
impl<'a, C, T, Load> Committer<C, T, Load, Relaxed>
where
C: PermTarget<Value<'a> = FMap<Timestamp, (T, SyncView)>> + HasTimestamp + 'a,
{
#[requires(!(*self).shot_store())]
#[requires(self.ward() == *(*own).ward())]
#[ensures((*self).hist_inv(^self))]
#[ensures((^self).shot_store())]
#[ensures((*own).ward() == (^own).ward())]
#[ensures(*sync_view <= ^sync_view)]
#[ensures((*self).ward().get_timestamp(*sync_view) <= self.timestamp())]
#[ensures(self.timestamp() < (*self).ward().get_timestamp(^sync_view))]
#[ensures((*own).val().get(self.timestamp() + 1) == None)]
#[ensures((^own).val() == (*own).val().insert(self.timestamp() + 1, ((*self).val_store(), rel_view@)))]
#[check(ghost)]
#[trusted]
#[allow(unused_variables)]
pub fn shoot_store(
&mut self,
own: &mut Perm<C>,
sync_view: &mut SyncView,
rel_view: ReleaseSyncView,
) {
panic!("Should not be called outside ghost code")
}
}
impl<'a, C, T, Load> Committer<C, T, Load, Release>
where
C: PermTarget<Value<'a> = FMap<Timestamp, (T, SyncView)>> + HasTimestamp + 'a,
{
#[requires(!(*self).shot_store())]
#[requires(self.ward() == *(*own).ward())]
#[ensures((*self).hist_inv(^self))]
#[ensures((^self).shot_store())]
#[ensures((*own).ward() == (^own).ward())]
#[ensures(*sync_view <= ^sync_view)]
#[ensures((*self).ward().get_timestamp(*sync_view) <= self.timestamp())]
#[ensures(self.timestamp() < (*self).ward().get_timestamp(^sync_view))]
#[ensures((*own).val().get(self.timestamp() + 1) == None)]
#[ensures((^own).val() == (*own).val().insert(self.timestamp() + 1, ((*self).val_store(), ^sync_view)))]
#[check(ghost)]
#[trusted]
#[allow(unused_variables)]
pub fn shoot_store(&mut self, own: &mut Perm<C>, sync_view: &mut SyncView) {
panic!("Should not be called outside ghost code")
}
}
#[cfg(feature = "sc-drf")]
impl<'a, C, Load> Committer<C, C::Value<'a>, Load, SeqCst>
where
C: PermTarget,
{
#[requires(!(*self).shot_store())]
#[requires(self.ward() == *(*own).ward())]
#[ensures((*self).hist_inv(^self))]
#[ensures((^self).shot_store())]
#[ensures((*own).ward() == (^own).ward())]
#[ensures((^own).val() == (*self).val_store())]
#[check(ghost)]
#[trusted]
#[allow(unused_variables)]
pub fn shoot_store(&mut self, own: &mut Perm<C>) {
panic!("Should not be called outside ghost code")
}
}