Skip to content

Commit

Permalink
TEMP: Basic specs for Rc
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgolfouse committed Jan 16, 2025
1 parent b9ec265 commit e14fba1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
21 changes: 1 addition & 20 deletions creusot-contracts/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ::std::{rc::Rc, sync::Arc};

use crate::*;
use ::std::sync::Arc;

/// The view of a type is its logical model as typically used to specify a data
/// structure. It is typically "shallow", and does not involve the model of
Expand Down Expand Up @@ -29,24 +28,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 Down
1 change: 1 addition & 0 deletions creusot-contracts/src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod ops;
pub mod option;
pub mod panicking;
pub mod ptr;
pub mod rc;
pub mod result;
pub mod slice;
pub mod string;
Expand Down
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;
}
}
}
}

0 comments on commit e14fba1

Please sign in to comment.