use crate::{logic::ops::DerefLogic, prelude::*};
use std::sync::Arc;
#[cfg(creusot)]
use crate::std::ptr::PointerExt as _;
#[cfg(creusot)]
use std::ops::Deref;
#[cfg(feature = "nightly")]
use std::alloc::Allocator;
pub trait ArcExt {
type Pointee: ?Sized;
#[logic]
fn as_ptr_logic(self) -> *const Self::Pointee;
}
#[cfg(feature = "nightly")]
impl<T: ?Sized, A: Allocator> ArcExt for Arc<T, A> {
type Pointee = T;
#[logic(opaque)]
fn as_ptr_logic(self) -> *const T {
dead
}
}
#[cfg(feature = "nightly")]
impl<T: DeepModel + ?Sized, A: Allocator> DeepModel for Arc<T, A> {
type DeepModelTy = T::DeepModelTy;
#[logic(open, inline)]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { (*self).deep_model() }
}
}
#[cfg(feature = "nightly")]
impl<T: ?Sized, A: Allocator> DerefLogic for Arc<T, A> {
#[logic(opaque)]
fn deref_logic(&self) -> &T {
dead
}
}
extern_spec! {
impl<T> Arc<T> {
#[check(ghost)]
#[ensures(*result == value)]
fn new(value: T) -> Self;
}
impl<T, A: Allocator> Arc<T, A> {
#[check(ghost)]
#[logic_alias(Arc::<T, A>::as_ptr_logic(*this))]
#[ensures(!result.is_null_logic())]
fn as_ptr(this: &Arc<T, A>) -> *const T;
#[check(terminates)] #[ensures(result == (this.as_ptr_logic().deep_model() == other.as_ptr_logic().deep_model()))]
#[ensures(result ==> this == other)]
fn ptr_eq(this: &Arc<T, A>, other: &Arc<T, A>) -> bool;
}
impl<T, A: Allocator> AsRef<T> for Arc<T, A> {
#[check(ghost)]
#[ensures(*result == **self)]
fn as_ref(&self) -> &T;
}
impl<T: ?Sized, A: Allocator + Clone> Clone for Arc<T, A> {
#[check(ghost)]
#[ensures(result == *self)]
fn clone(&self) -> Arc<T, A>;
}
impl<T: ?Sized, A: Allocator> Deref for Arc<T, A> {
#[check(ghost)]
#[logic_alias(self.deref_logic())]
fn deref(&self) -> &T { self.as_ref() }
}
}
#[cfg(not(feature = "nightly"))]
impl<T: DeepModel + ?Sized> DeepModel for Arc<T> {
type DeepModelTy = T::DeepModelTy;
}
#[cfg(not(feature = "nightly"))]
impl<T: ?Sized> DerefLogic for Arc<T> {}