#[cfg(creusot)]
use crate::resolve::structural_resolve;
use crate::{invariant::GuardRef, prelude::*};
pub trait PermTarget {
type Value: ?Sized;
type Objectiveness;
#[logic(open, inline)]
fn is_disjoint(&self, _self_val: &Self::Value, other: &Self, _other_val: &Self::Value) -> bool {
self != other
}
}
#[opaque]
pub struct Perm<C: ?Sized + PermTarget> {
#[allow(unused)]
value: Snapshot<C::Value>,
#[allow(unused)]
objective: C::Objectiveness,
}
impl<C: ?Sized + PermTarget> Perm<C> {
#[logic(opaque)]
pub fn ward<'a>(self) -> &'a C {
dead
}
#[logic(open, inline)]
pub fn val(self) -> C::Value
where
C::Value: Sized,
{
*self.val_unsized()
}
#[logic(opaque)]
pub fn val_unsized<'a>(self) -> &'a C::Value {
dead
}
#[trusted]
#[check(ghost)]
#[ensures(self.val_unsized() != other.val_unsized() ==> self.ward().is_disjoint(self.val_unsized(), other.ward(), other.val_unsized()))]
#[allow(unused_variables)]
pub fn disjoint_lemma_shared(&self, other: &Self) {}
#[trusted]
#[check(ghost)]
#[ensures(self.ward().is_disjoint(self.val_unsized(), other.ward(), other.val_unsized()))]
#[ensures(*self == ^self)]
#[allow(unused_variables)]
pub fn disjoint_lemma(&mut self, other: &Self) {}
}
impl<C: ?Sized + PermTarget> Resolve for Perm<C> {
#[logic(open, prophetic, inline)]
#[creusot::trusted_trivial_if_param_trivial]
fn resolve(self) -> bool {
resolve(self.val_unsized())
}
#[trusted]
#[logic(prophetic)]
#[requires(inv(self))]
#[requires(structural_resolve(self))]
#[ensures(self.resolve())]
fn resolve_coherence(self) {}
}
impl<C: ?Sized + PermTarget> GuardRef<Perm<C>> for C {
#[logic(open, inline)]
fn guards_ref(self, c: Perm<C>) -> bool {
pearlite! { *c.ward() == self }
}
}