Skip to content

Commit

Permalink
Basic specs for Rc and Arc (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgolfouse authored Jan 17, 2025
2 parents 4c2c870 + 4f0f655 commit 9645e8a
Show file tree
Hide file tree
Showing 71 changed files with 616 additions and 421 deletions.
38 changes: 0 additions & 38 deletions creusot-contracts/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use ::std::{rc::Rc, sync::Arc};

use crate::*;

/// The view of a type is its logical model as typically used to specify a data
Expand Down Expand Up @@ -29,24 +27,6 @@ pub trait DeepModel {
fn deep_model(self) -> Self::DeepModelTy;
}

impl<T: DeepModel> DeepModel for Rc<T> {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { self.view().deep_model() }
}
}

impl<T> View for Rc<T> {
type ViewTy = T;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}

impl View for str {
type ViewTy = Seq<char>;

Expand All @@ -57,24 +37,6 @@ impl View for str {
}
}

impl<T: DeepModel> DeepModel for Arc<T> {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { self@.deep_model() }
}
}

impl<T> View for Arc<T> {
type ViewTy = T;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}

impl<T: DeepModel + ?Sized> DeepModel for &T {
type DeepModelTy = T::DeepModelTy;
#[logic]
Expand Down
2 changes: 2 additions & 0 deletions creusot-contracts/src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ pub mod ops;
pub mod option;
pub mod panicking;
pub mod ptr;
pub mod rc;
pub mod result;
pub mod slice;
pub mod string;
pub mod sync;
pub mod time;
mod tuples;
pub mod vec;
36 changes: 36 additions & 0 deletions creusot-contracts/src/std/rc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::*;
use ::std::{alloc::Allocator, rc::Rc};

impl<T: DeepModel, A: Allocator> DeepModel for Rc<T, A> {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { self.view().deep_model() }
}
}

impl<T, A: Allocator> View for Rc<T, A> {
type ViewTy = T;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}

extern_spec! {
mod std {
mod rc {
impl<T> Rc<T> {
#[ensures(result@ == value)]
fn new(value: T) -> Self;
}

impl<T, A: Allocator> AsRef for Rc<T, A> {
#[ensures(*result == (*self)@)]
fn as_ref(&self) -> &T;
}
}
}
}
36 changes: 36 additions & 0 deletions creusot-contracts/src/std/sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::*;
use ::std::{alloc::Allocator, sync::Arc};

impl<T: DeepModel, A: Allocator> DeepModel for Arc<T, A> {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { self.view().deep_model() }
}
}

impl<T, A: Allocator> View for Arc<T, A> {
type ViewTy = T;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}

extern_spec! {
mod std {
mod sync {
impl<T> Arc<T> {
#[ensures(result@ == value)]
fn new(value: T) -> Self;
}

impl<T, A: Allocator> AsRef for Arc<T, A> {
#[ensures(*result == (*self)@)]
fn as_ref(&self) -> &T;
}
}
}
}
Loading

0 comments on commit 9645e8a

Please sign in to comment.