Skip to content

Commit

Permalink
avoid the allocator feature to keep vstd compiling on stable rust
Browse files Browse the repository at this point in the history
  • Loading branch information
utaal committed Nov 13, 2023
1 parent 8fbbc3c commit 146fe0b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
11 changes: 5 additions & 6 deletions source/pervasive/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use alloc::alloc::Layout;
use core::{marker, mem, mem::MaybeUninit};
use alloc::alloc::Allocator;

use builtin::*;
use builtin_macros::*;
Expand All @@ -11,6 +10,8 @@ use crate::pervasive::*;
use crate::modes::*;
use crate::prelude::*;
use crate::layout::*;

#[cfg(verus_keep_ghost)]
use crate::set_lib::set_int_range;

verus!{
Expand Down Expand Up @@ -519,7 +520,7 @@ impl<V> PPtr<V> {
// The 'add' can't overflow, since we already know (size, align) is a valid layout.
let layout = Layout::from_size_align(size + align, align).unwrap();
let p = PPtr {
uptr: alloc::alloc::Global.allocate(layout).unwrap().as_ptr() as *mut V,
uptr: unsafe { std::alloc::alloc(layout) as *mut V },
};

// See explanation about exposing pointers, above
Expand Down Expand Up @@ -645,13 +646,12 @@ impl<V> PPtr<V> {
opens_invariants none
{
unsafe {
let nn = core::ptr::NonNull::new_unchecked(self.uptr as *mut u8);
let layout = alloc::alloc::Layout::for_value(&*self.uptr);
let size = layout.size();
let align = layout.align();
// Add the padding to match what we did in 'alloc'
let layout = Layout::from_size_align_unchecked(size + align, align);
alloc::alloc::Global.deallocate(nn, alloc::alloc::Layout::for_value(&*self.uptr));
std::alloc::dealloc(self.uptr as *mut u8, alloc::alloc::Layout::for_value(&*self.uptr));
}
}

Expand All @@ -675,8 +675,7 @@ impl<V> PPtr<V> {
// and that it's safe to call 'deallocate'
// Remember to add the padding, like in `alloc`
let layout = Layout::from_size_align_unchecked(size + align, align);
let nn = core::ptr::NonNull::new_unchecked(self.uptr as *mut u8);
alloc::alloc::Global.deallocate(nn, alloc::alloc::Layout::for_value(&*self.uptr));
std::alloc::dealloc(self.uptr as *mut u8, alloc::alloc::Layout::for_value(&*self.uptr));
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/pervasive/vstd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#![allow(unused_attributes)]
#![allow(rustdoc::invalid_rust_codeblocks)]

#![feature(allocator_api)]
#![cfg_attr(verus_keep_ghost, feature(core_intrinsics))]
#![cfg_attr(verus_keep_ghost, feature(allocator_api))]

#[cfg(feature = "alloc")]
extern crate alloc;
Expand Down
1 change: 0 additions & 1 deletion source/tools/docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ RUSTC_BOOTSTRAP=1 eval ""VERUSDOC=1 VERUS_Z3_PATH="$(pwd)/z3" rustdoc \
-Zcrate-attr=feature\\\(register_tool\\\) \
-Zcrate-attr=feature\\\(rustc_attrs\\\) \
-Zcrate-attr=feature\\\(unboxed_closures\\\) \
-Zcrate-attr=feature\\\(allocator_api\\\) \
-Zcrate-attr=register_tool\\\(verus\\\) \
-Zcrate-attr=register_tool\\\(verifier\\\) \
pervasive/vstd.rs""
Expand Down

0 comments on commit 146fe0b

Please sign in to comment.