Skip to content

Commit

Permalink
Add old helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbolliger committed Jul 21, 2021
1 parent fd85321 commit 67e4839
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libstainless/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ pub use set::*;
mod map;
pub use map::*;

pub fn old<T>(t: T) -> T {
t
}

pub trait Implies {
fn implies(self, b: Self) -> bool;
}
Expand Down
5 changes: 5 additions & 0 deletions stainless_extraction/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl<'a, 'l, 'tcx> BodyExtractor<'a, 'l, 'tcx> {
}

StdItem::CrateItem(CrateItem::ImpliesFn) => self.extract_implies(args),
StdItem::CrateItem(CrateItem::OldFn) => Some(self.extract_old(args.first().unwrap())),

// Box::new, erase it and return the argument directly.
StdItem::CrateItem(BoxNewFn) => Some(self.extract_expr(args.first().unwrap())),
Expand All @@ -141,6 +142,10 @@ impl<'a, 'l, 'tcx> BodyExtractor<'a, 'l, 'tcx> {
}
}

fn extract_old(&mut self, arg: &'a Expr<'a, 'tcx>) -> st::Expr<'l> {
self.factory().Old(self.extract_expr(arg)).into()
}

fn extract_call(
&mut self,
def_id: DefId,
Expand Down
4 changes: 3 additions & 1 deletion stainless_extraction/src/std_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub enum CrateItem {
MapInsertFn,
MapRemoveFn,
OptionType,
OldFn,
}

use CrateItem::*;
Expand All @@ -81,6 +82,7 @@ impl CrateItem {
CloneFn => "std::clone::Clone::clone",
CloneTrait => "std::clone::Clone",
ImpliesFn => "stainless::Implies::implies",
OldFn => "stainless::old",
MapType => "stainless::Map",
MapNewFn => "stainless::Map::<K, V>::new",
MapIndexFn => "stainless::Map::<K, V>::index",
Expand All @@ -106,7 +108,7 @@ impl CrateItem {

pub fn def_kind(&self) -> DefKind {
match self {
BeginPanicFmtFn => DefKind::Fn,
BeginPanicFmtFn | OldFn => DefKind::Fn,
SetType | MapType | StringType | PhantomData => DefKind::Struct,
CloneTrait => DefKind::Trait,
OptionType => DefKind::Enum,
Expand Down

0 comments on commit 67e4839

Please sign in to comment.