Skip to content

Commit 87b71ed

Browse files
committed
Auto merge of rust-lang#77771 - nagisa:revert-77023, r=Mark-Simulacrum
Revert "Assume slice len is bounded by allocation size" rust-lang#77023 (comment) suggests that the original PR introduced a significant perf regression. This reverts commit e44784b / rust-lang#77023. cc `@HeroicKatora`
2 parents cae8bc1 + 54a5608 commit 87b71ed

File tree

3 files changed

+2
-46
lines changed

3 files changed

+2
-46
lines changed

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
#![feature(const_pin)]
8383
#![feature(const_fn)]
8484
#![feature(const_fn_union)]
85-
#![feature(const_assume)]
8685
#![cfg_attr(not(bootstrap), feature(const_impl_trait))]
8786
#![feature(const_fn_floating_point_arithmetic)]
8887
#![feature(const_fn_fn_ptr_basics)]

library/core/src/slice/mod.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ pub use index::check_range;
7979
#[lang = "slice"]
8080
#[cfg(not(test))]
8181
impl<T> [T] {
82-
/// The maximum, inclusive, length such that the slice is no larger than `isize::MAX` bytes.
83-
/// This constant is used in `len` below.
84-
const MAX_LEN_BOUND: usize = {
85-
if mem::size_of::<T>() == 0 {
86-
usize::MAX
87-
} else {
88-
isize::MAX as usize / mem::size_of::<T>()
89-
}
90-
};
91-
9282
/// Returns the number of elements in the slice.
9383
///
9484
/// # Examples
@@ -101,20 +91,11 @@ impl<T> [T] {
10191
#[rustc_const_stable(feature = "const_slice_len", since = "1.32.0")]
10292
#[inline]
10393
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
104-
#[allow_internal_unstable(const_fn_union, const_assume)]
94+
#[allow_internal_unstable(const_fn_union)]
10595
pub const fn len(&self) -> usize {
10696
// SAFETY: this is safe because `&[T]` and `FatPtr<T>` have the same layout.
10797
// Only `std` can make this guarantee.
108-
let raw_len = unsafe { crate::ptr::Repr { rust: self }.raw.len };
109-
110-
// SAFETY: this assume asserts that `raw_len * size_of::<T>() <= isize::MAX`. All
111-
// references must point to one allocation with size at most isize::MAX. Note that we the
112-
// multiplication could appear to overflow until we have assumed the bound. This overflow
113-
// would make additional values appear 'valid' and then `n > 1` the range of permissible
114-
// length would no longer be the full or even a single range.
115-
unsafe { crate::intrinsics::assume(raw_len <= Self::MAX_LEN_BOUND) };
116-
117-
raw_len
98+
unsafe { crate::ptr::Repr { rust: self }.raw.len }
11899
}
119100

120101
/// Returns `true` if the slice has a length of 0.

src/test/codegen/len-is-bounded.rs

-24
This file was deleted.

0 commit comments

Comments
 (0)