Skip to content

Commit fd04918

Browse files
committed
Revert "[create-pull-request] automated change"
This reverts commit 577d275.
1 parent a480b93 commit fd04918

1 file changed

Lines changed: 39 additions & 93 deletions

File tree

  • verifast-proofs/alloc/raw_vec/mod.rs/verified

verifast-proofs/alloc/raw_vec/mod.rs/verified/raw_vec.rs

Lines changed: 39 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ lem mul_zero(x: i32, y: i32)
4848
// ensure that the code generation related to these panics is minimal as there's
4949
// only one location which panics rather than a bunch throughout the module.
5050
#[cfg(not(no_global_oom_handling))]
51-
#[cfg_attr(not(panic = "immediate-abort"), inline(never))]
51+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
52+
#[track_caller]
5253
fn capacity_overflow() -> !
5354
//@ req true;
5455
//@ ens false;
@@ -432,6 +433,7 @@ impl<T> RawVec<T, Global> {
432433
#[cfg(not(any(no_global_oom_handling, test)))]
433434
#[must_use]
434435
#[inline]
436+
#[track_caller]
435437
pub(crate) fn with_capacity(capacity: usize) -> Self {
436438
Self { inner: RawVecInner::with_capacity(capacity, T::LAYOUT), _marker: PhantomData }
437439
}
@@ -440,6 +442,7 @@ impl<T> RawVec<T, Global> {
440442
#[cfg(not(any(no_global_oom_handling, test)))]
441443
#[must_use]
442444
#[inline]
445+
#[track_caller]
443446
pub(crate) fn with_capacity_zeroed(capacity: usize) -> Self {
444447
Self {
445448
inner: RawVecInner::with_capacity_zeroed_in(capacity, Global, T::LAYOUT),
@@ -452,6 +455,7 @@ impl RawVecInner<Global> {
452455
#[cfg(not(any(no_global_oom_handling, test)))]
453456
#[must_use]
454457
#[inline]
458+
#[track_caller]
455459
fn with_capacity(capacity: usize, elem_layout: Layout) -> Self {
456460
match Self::try_allocate_in(capacity, AllocInit::Uninitialized, Global, elem_layout) {
457461
Ok(res) => res,
@@ -483,8 +487,6 @@ impl<T, A: Allocator> RawVec<T, A> {
483487
#[cfg(not(no_global_oom_handling))]
484488
pub(crate) const MIN_NON_ZERO_CAP: usize = min_non_zero_cap(size_of::<T>());
485489

486-
// Check assumption made in `current_memory`
487-
const { assert!(T::LAYOUT.size() % T::LAYOUT.align() == 0) };
488490
/// Like `new`, but parameterized over the choice of allocator for
489491
/// the returned `RawVec`.
490492
#[inline]
@@ -514,6 +516,7 @@ impl<T, A: Allocator> RawVec<T, A> {
514516
/// allocator for the returned `RawVec`.
515517
#[cfg(not(no_global_oom_handling))]
516518
#[inline]
519+
#[track_caller]
517520
pub(crate) fn with_capacity_in(capacity: usize, alloc: A) -> Self
518521
//@ req thread_token(?t) &*& Allocator(t, alloc, ?alloc_id) &*& t == currentThread;
519522
//@ ens thread_token(t) &*& RawVec(t, result, alloc_id, ?ptr, ?capacity_) &*& array_at_lft_(alloc_id.lft, ptr, capacity_, _) &*& capacity <= capacity_;
@@ -550,6 +553,7 @@ impl<T, A: Allocator> RawVec<T, A> {
550553
/// of allocator for the returned `RawVec`.
551554
#[cfg(not(no_global_oom_handling))]
552555
#[inline]
556+
#[track_caller]
553557
pub(crate) fn with_capacity_zeroed_in(capacity: usize, alloc: A) -> Self {
554558
Self {
555559
inner: RawVecInner::with_capacity_zeroed_in(capacity, alloc, T::LAYOUT),
@@ -787,18 +791,18 @@ impl<T, A: Allocator> RawVec<T, A> {
787791
/// Aborts on OOM.
788792
#[cfg(not(no_global_oom_handling))]
789793
#[inline]
794+
#[track_caller]
790795
pub(crate) fn reserve(&mut self, len: usize, additional: usize) {
791-
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
792-
unsafe { self.inner.reserve(len, additional, T::LAYOUT) }
796+
self.inner.reserve(len, additional, T::LAYOUT)
793797
}
794798

795799
/// A specialized version of `self.reserve(len, 1)` which requires the
796800
/// caller to ensure `len == self.capacity()`.
797801
#[cfg(not(no_global_oom_handling))]
798802
#[inline(never)]
803+
#[track_caller]
799804
pub(crate) fn grow_one(&mut self) {
800-
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
801-
unsafe { self.inner.grow_one(T::LAYOUT) }
805+
self.inner.grow_one(T::LAYOUT)
802806
}
803807

804808
/// The same as `reserve`, but returns on errors instead of panicking or aborting.
@@ -884,9 +888,9 @@ impl<T, A: Allocator> RawVec<T, A> {
884888
///
885889
/// Aborts on OOM.
886890
#[cfg(not(no_global_oom_handling))]
891+
#[track_caller]
887892
pub(crate) fn reserve_exact(&mut self, len: usize, additional: usize) {
888-
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
889-
unsafe { self.inner.reserve_exact(len, additional, T::LAYOUT) }
893+
self.inner.reserve_exact(len, additional, T::LAYOUT)
890894
}
891895

892896
/// The same as `reserve_exact`, but returns on errors instead of panicking or aborting.
@@ -965,10 +969,10 @@ impl<T, A: Allocator> RawVec<T, A> {
965969
///
966970
/// Aborts on OOM.
967971
#[cfg(not(no_global_oom_handling))]
972+
#[track_caller]
968973
#[inline]
969974
pub(crate) fn shrink_to_fit(&mut self, cap: usize) {
970-
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
971-
unsafe { self.inner.shrink_to_fit(cap, T::LAYOUT) }
975+
self.inner.shrink_to_fit(cap, T::LAYOUT)
972976
}
973977
}
974978

@@ -1011,6 +1015,7 @@ impl<A: Allocator> RawVecInner<A> {
10111015

10121016
#[cfg(not(no_global_oom_handling))]
10131017
#[inline]
1018+
#[track_caller]
10141019
fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self
10151020
//@ req thread_token(?t) &*& Allocator(t, alloc, ?alloc_id) &*& t == currentThread &*& Layout::size_(elem_layout) % Layout::align_(elem_layout) == 0;
10161021
//@ ens thread_token(t) &*& RawVecInner(t, result, elem_layout, alloc_id, ?ptr, ?capacity_) &*& array_at_lft_(alloc_id.lft, ptr, Layout::size_(elem_layout) * capacity_, _) &*& capacity <= capacity_;
@@ -1066,6 +1071,7 @@ impl<A: Allocator> RawVecInner<A> {
10661071

10671072
#[cfg(not(no_global_oom_handling))]
10681073
#[inline]
1074+
#[track_caller]
10691075
fn with_capacity_zeroed_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self {
10701076
match Self::try_allocate_in(capacity, AllocInit::Zeroed, alloc, elem_layout) {
10711077
Ok(res) => res,
@@ -1141,10 +1147,6 @@ impl<A: Allocator> RawVecInner<A> {
11411147
}
11421148
//@ end_lifetime(k);
11431149
//@ std::alloc::end_ref_Allocator_at_lifetime::<A>();
1144-
/// # Safety
1145-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1146-
/// initially construct `self`
1147-
/// - `elem_layout`'s size must be a multiple of its alignment
11481150
r
11491151
}
11501152
#[cfg(not(no_global_oom_handling))]
@@ -1162,10 +1164,6 @@ impl<A: Allocator> RawVecInner<A> {
11621164
//@ std::alloc::end_ref_Allocator_at_lifetime::<A>();
11631165
r
11641166
}
1165-
/// # Safety
1166-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1167-
/// initially construct `self`
1168-
/// - `elem_layout`'s size must be a multiple of its alignment
11691167
};
11701168
let ptr = match result {
11711169
Ok(ptr) => ptr,
@@ -1350,49 +1348,39 @@ impl<A: Allocator> RawVecInner<A> {
13501348

13511349
#[cfg(not(no_global_oom_handling))]
13521350
#[inline]
1353-
unsafe fn reserve(&mut self, len: usize, additional: usize, elem_layout: Layout) {
1351+
#[track_caller]
1352+
fn reserve(&mut self, len: usize, additional: usize, elem_layout: Layout) {
13541353
// Callers expect this function to be very cheap when there is already sufficient capacity.
13551354
// Therefore, we move all the resizing and error-handling logic from grow_amortized and
13561355
// handle_reserve behind a call, while making sure that this function is likely to be
13571356
// inlined as just a comparison and a call if the comparison fails.
13581357
#[cold]
1359-
unsafe fn do_reserve_and_handle<A: Allocator>(
1358+
fn do_reserve_and_handle<A: Allocator>(
13601359
slf: &mut RawVecInner<A>,
13611360
len: usize,
13621361
additional: usize,
13631362
elem_layout: Layout,
13641363
) {
1365-
// SAFETY: Precondition passed to caller
1366-
if let Err(err) = unsafe { slf.grow_amortized(len, additional, elem_layout) } {
1364+
if let Err(err) = slf.grow_amortized(len, additional, elem_layout) {
13671365
handle_error(err);
13681366
}
13691367
}
13701368

13711369
if self.needs_to_grow(len, additional, elem_layout) {
1372-
unsafe {
1373-
do_reserve_and_handle(self, len, additional, elem_layout);
1374-
}
1370+
do_reserve_and_handle(self, len, additional, elem_layout);
13751371
}
13761372
}
13771373

1378-
/// # Safety
1379-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1380-
/// initially construct `self`
1381-
/// - `elem_layout`'s size must be a multiple of its alignment
13821374
#[cfg(not(no_global_oom_handling))]
13831375
#[inline]
1384-
unsafe fn grow_one(&mut self, elem_layout: Layout) {
1385-
// SAFETY: Precondition passed to caller
1386-
if let Err(err) = unsafe { self.grow_amortized(self.cap.as_inner(), 1, elem_layout) } {
1376+
#[track_caller]
1377+
fn grow_one(&mut self, elem_layout: Layout) {
1378+
if let Err(err) = self.grow_amortized(self.cap.as_inner(), 1, elem_layout) {
13871379
handle_error(err);
13881380
}
13891381
}
13901382

1391-
/// # Safety
1392-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1393-
/// initially construct `self`
1394-
/// - `elem_layout`'s size must be a multiple of its alignment
1395-
unsafe fn try_reserve(
1383+
fn try_reserve(
13961384
&mut self,
13971385
len: usize,
13981386
additional: usize,
@@ -1431,10 +1419,7 @@ impl<A: Allocator> RawVecInner<A> {
14311419
//@ end_share_RawVecInner(self);
14321420

14331421
if needs_to_grow {
1434-
// SAFETY: Precondition passed to caller
1435-
unsafe {
1436-
self.grow_amortized(len, additional, elem_layout)?;
1437-
}
1422+
self.grow_amortized(len, additional, elem_layout)?;
14381423
}
14391424
unsafe {
14401425
//@ let k2 = begin_lifetime();
@@ -1456,23 +1441,15 @@ impl<A: Allocator> RawVecInner<A> {
14561441
Ok(())
14571442
}
14581443

1459-
/// # Safety
1460-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1461-
/// initially construct `self`
1462-
/// - `elem_layout`'s size must be a multiple of its alignment
14631444
#[cfg(not(no_global_oom_handling))]
1464-
unsafe fn reserve_exact(&mut self, len: usize, additional: usize, elem_layout: Layout) {
1465-
// SAFETY: Precondition passed to caller
1466-
if let Err(err) = unsafe { self.try_reserve_exact(len, additional, elem_layout) } {
1445+
#[track_caller]
1446+
fn reserve_exact(&mut self, len: usize, additional: usize, elem_layout: Layout) {
1447+
if let Err(err) = self.try_reserve_exact(len, additional, elem_layout) {
14671448
handle_error(err);
14681449
}
14691450
}
14701451

1471-
/// # Safety
1472-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1473-
/// initially construct `self`
1474-
/// - `elem_layout`'s size must be a multiple of its alignment
1475-
unsafe fn try_reserve_exact(
1452+
fn try_reserve_exact(
14761453
&mut self,
14771454
len: usize,
14781455
additional: usize,
@@ -1511,10 +1488,7 @@ impl<A: Allocator> RawVecInner<A> {
15111488
//@ end_share_RawVecInner(self);
15121489

15131490
if needs_to_grow {
1514-
// SAFETY: Precondition passed to caller
1515-
unsafe {
1516-
self.grow_exact(len, additional, elem_layout)?;
1517-
}
1491+
self.grow_exact(len, additional, elem_layout)?;
15181492
}
15191493
unsafe {
15201494
//@ let k2 = begin_lifetime();
@@ -1523,11 +1497,6 @@ impl<A: Allocator> RawVecInner<A> {
15231497
//@ init_ref_RawVecInner(self_ref2);
15241498
//@ open_frac_borrow(k2, ref_initialized_(self_ref2), 1/2);
15251499
//@ open [?f2]ref_initialized_::<RawVecInner<A>>(self_ref2)();
1526-
/// # Safety
1527-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1528-
/// initially construct `self`
1529-
/// - `elem_layout`'s size must be a multiple of its alignment
1530-
/// - `cap` must be less than or equal to `self.capacity(elem_layout.size())`
15311500
let needs_to_grow2 = self.needs_to_grow(len, additional, elem_layout);
15321501
//@ close [f2]ref_initialized_::<RawVecInner<A>>(self_ref2)();
15331502
//@ close_frac_borrow(f2, ref_initialized_(self_ref2));
@@ -1543,8 +1512,9 @@ impl<A: Allocator> RawVecInner<A> {
15431512

15441513
#[cfg(not(no_global_oom_handling))]
15451514
#[inline]
1546-
unsafe fn shrink_to_fit(&mut self, cap: usize, elem_layout: Layout) {
1547-
if let Err(err) = unsafe { self.shrink(cap, elem_layout) } {
1515+
#[track_caller]
1516+
fn shrink_to_fit(&mut self, cap: usize, elem_layout: Layout) {
1517+
if let Err(err) = self.shrink(cap, elem_layout) {
15481518
handle_error(err);
15491519
}
15501520
}
@@ -1571,13 +1541,7 @@ impl<A: Allocator> RawVecInner<A> {
15711541
self.cap = unsafe { Cap::new_unchecked(cap) };
15721542
}
15731543

1574-
/// # Safety
1575-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1576-
/// initially construct `self`
1577-
/// - `elem_layout`'s size must be a multiple of its alignment
1578-
/// - The sum of `len` and `additional` must be greater than or equal to
1579-
/// `self.capacity(elem_layout.size())`
1580-
unsafe fn grow_amortized(
1544+
fn grow_amortized(
15811545
&mut self,
15821546
len: usize,
15831547
additional: usize,
@@ -1605,7 +1569,6 @@ impl<A: Allocator> RawVecInner<A> {
16051569
//@ safety_proof { assume(false); }
16061570
{
16071571
// This is ensured by the calling contexts.
1608-
// SAFETY: layout_array would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
16091572
if cfg!(debug_assertions) { //~allow_dead_code // FIXME: The source location associated with a dead `else` branch is the entire `if` statement :-(
16101573
assert!(additional > 0);
16111574
}
@@ -1690,13 +1653,7 @@ impl<A: Allocator> RawVecInner<A> {
16901653
}
16911654
}
16921655

1693-
/// # Safety
1694-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1695-
/// initially construct `self`
1696-
/// - `elem_layout`'s size must be a multiple of its alignment
1697-
/// - The sum of `len` and `additional` must be greater than or equal to
1698-
/// `self.capacity(elem_layout.size())`
1699-
unsafe fn grow_exact(
1656+
fn grow_exact(
17001657
&mut self,
17011658
len: usize,
17021659
additional: usize,
@@ -1719,11 +1676,6 @@ impl<A: Allocator> RawVecInner<A> {
17191676
Result::Err(e) =>
17201677
RawVecInner(t, self1, elem_layout, alloc_id, ptr0, capacity0) &*& array_at_lft_(alloc_id.lft, ptr0, capacity0 * Layout::size_(elem_layout), _) &*&
17211678
<std::collections::TryReserveError>.own(t, e)
1722-
/// # Safety
1723-
/// - `elem_layout` must be valid for `self`, i.e. it must be the same `elem_layout` used to
1724-
/// initially construct `self`
1725-
/// - `elem_layout`'s size must be a multiple of its alignment
1726-
/// - `cap` must be less than or equal to `self.capacity(elem_layout.size())`
17271679
};
17281680
@*/
17291681
//@ safety_proof { assume(false); }
@@ -1793,13 +1745,6 @@ impl<A: Allocator> RawVecInner<A> {
17931745
//@ assert 0 <= Cap_as_inner_(self0.cap);
17941746
//@ assert 0 <= logical_capacity(self0.cap, Layout::size_(elem_layout));
17951747
//@ assert cap != 0;
1796-
/// # Safety
1797-
/// If `current_memory` matches `Some((ptr, old_layout))`:
1798-
/// - `ptr` must denote a block of memory *currently allocated* via `alloc`
1799-
/// - `old_layout` must *fit* that block of memory
1800-
/// - `new_layout` must have the same alignment as `old_layout`
1801-
/// - `new_layout.size()` must be greater than or equal to `old_layout.size()`
1802-
/// If `current_memory` is `None`, this function is safe.
18031748
//@ std::alloc::Layout_inv(new_layout);
18041749
//@ close RawVecInner0(alloc_id, Unique::from_non_null_(ptr.ptr), UsizeNoHighBit::new_(cap), elem_layout, NonNull_ptr(ptr.ptr), _);
18051750
//@ close RawVecInner::<A>(t, self1, elem_layout, alloc_id, _, _);
@@ -2030,7 +1975,7 @@ impl<A: Allocator> RawVecInner<A> {
20301975
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
20311976
// function, see tests/codegen-llvm/vec-reserve-extend.rs.
20321977
#[cold]
2033-
unsafe fn finish_grow<A>(
1978+
fn finish_grow<A>(
20341979
new_layout: Layout,
20351980
current_memory: Option<(NonNull<u8>, Layout)>,
20361981
alloc: &mut A,
@@ -2125,6 +2070,7 @@ ens thread_token(t) &*& *alloc |-> ?alloc1 &*& Allocator(t, alloc1, alloc_id) &*
21252070
#[cfg(not(no_global_oom_handling))]
21262071
#[cold]
21272072
#[optimize(size)]
2073+
#[track_caller]
21282074
fn handle_error(e: TryReserveError) -> !
21292075
//@ req true;
21302076
//@ ens false;

0 commit comments

Comments
 (0)