Skip to content

Commit 06ade5c

Browse files
author
The Miri Conjob Bot
committed
Merge from rustc
2 parents 578a23c + 820ec42 commit 06ade5c

File tree

38 files changed

+759
-108
lines changed

38 files changed

+759
-108
lines changed

alloc/src/alloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![stable(feature = "alloc_module", since = "1.28.0")]
44

55
#[cfg(not(test))]
6-
use core::intrinsics;
6+
use core::hint;
77

88
#[cfg(not(test))]
99
use core::ptr::{self, NonNull};
@@ -208,7 +208,7 @@ impl Global {
208208
let new_size = new_layout.size();
209209

210210
// `realloc` probably checks for `new_size >= old_layout.size()` or something similar.
211-
intrinsics::assume(new_size >= old_layout.size());
211+
hint::assert_unchecked(new_size >= old_layout.size());
212212

213213
let raw_ptr = realloc(ptr.as_ptr(), old_layout, new_size);
214214
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
@@ -299,7 +299,7 @@ unsafe impl Allocator for Global {
299299
// SAFETY: `new_size` is non-zero. Other conditions must be upheld by the caller
300300
new_size if old_layout.align() == new_layout.align() => unsafe {
301301
// `realloc` probably checks for `new_size <= old_layout.size()` or something similar.
302-
intrinsics::assume(new_size <= old_layout.size());
302+
hint::assert_unchecked(new_size <= old_layout.size());
303303

304304
let raw_ptr = realloc(ptr.as_ptr(), old_layout, new_size);
305305
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;

alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
#![feature(fmt_internals)]
130130
#![feature(fn_traits)]
131131
#![feature(hasher_prefixfree_extras)]
132+
#![feature(hint_assert_unchecked)]
132133
#![feature(inline_const)]
133134
#![feature(inplace_iteration)]
134135
#![feature(iter_advance_by)]

alloc/src/raw_vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use core::alloc::LayoutError;
44
use core::cmp;
5-
use core::intrinsics;
5+
use core::hint;
66
use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties};
77
use core::ptr::{self, NonNull, Unique};
88
use core::slice;
@@ -325,7 +325,7 @@ impl<T, A: Allocator> RawVec<T, A> {
325325
}
326326
unsafe {
327327
// Inform the optimizer that the reservation has succeeded or wasn't needed
328-
core::intrinsics::assume(!self.needs_to_grow(len, additional));
328+
hint::assert_unchecked(!self.needs_to_grow(len, additional));
329329
}
330330
Ok(())
331331
}
@@ -363,7 +363,7 @@ impl<T, A: Allocator> RawVec<T, A> {
363363
}
364364
unsafe {
365365
// Inform the optimizer that the reservation has succeeded or wasn't needed
366-
core::intrinsics::assume(!self.needs_to_grow(len, additional));
366+
hint::assert_unchecked(!self.needs_to_grow(len, additional));
367367
}
368368
Ok(())
369369
}
@@ -514,7 +514,7 @@ where
514514
debug_assert_eq!(old_layout.align(), new_layout.align());
515515
unsafe {
516516
// The allocator checks for alignment equality
517-
intrinsics::assume(old_layout.align() == new_layout.align());
517+
hint::assert_unchecked(old_layout.align() == new_layout.align());
518518
alloc.grow(ptr, old_layout, new_layout)
519519
}
520520
} else {

alloc/src/rc.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ use core::cell::Cell;
252252
use core::cmp::Ordering;
253253
use core::fmt;
254254
use core::hash::{Hash, Hasher};
255+
use core::hint;
255256
use core::intrinsics::abort;
256257
#[cfg(not(no_global_oom_handling))]
257258
use core::iter;
@@ -1885,10 +1886,10 @@ impl<T: ?Sized> Rc<T> {
18851886
// Initialize the RcBox
18861887
let inner = mem_to_rcbox(ptr.as_non_null_ptr().as_ptr());
18871888
unsafe {
1888-
debug_assert_eq!(Layout::for_value(&*inner), layout);
1889+
debug_assert_eq!(Layout::for_value_raw(inner), layout);
18891890

1890-
ptr::write(&mut (*inner).strong, Cell::new(1));
1891-
ptr::write(&mut (*inner).weak, Cell::new(1));
1891+
ptr::addr_of_mut!((*inner).strong).write(Cell::new(1));
1892+
ptr::addr_of_mut!((*inner).weak).write(Cell::new(1));
18921893
}
18931894

18941895
Ok(inner)
@@ -1902,7 +1903,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
19021903
// Allocate for the `RcBox<T>` using the given value.
19031904
unsafe {
19041905
Rc::<T>::allocate_for_layout(
1905-
Layout::for_value(&*ptr),
1906+
Layout::for_value_raw(ptr),
19061907
|layout| alloc.allocate(layout),
19071908
|mem| mem.with_metadata_of(ptr as *const RcBox<T>),
19081909
)
@@ -1918,7 +1919,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
19181919
// Copy value as bytes
19191920
ptr::copy_nonoverlapping(
19201921
&*src as *const T as *const u8,
1921-
&mut (*ptr).value as *mut _ as *mut u8,
1922+
ptr::addr_of_mut!((*ptr).value) as *mut u8,
19221923
value_size,
19231924
);
19241925

@@ -1952,7 +1953,11 @@ impl<T> Rc<[T]> {
19521953
unsafe fn copy_from_slice(v: &[T]) -> Rc<[T]> {
19531954
unsafe {
19541955
let ptr = Self::allocate_for_slice(v.len());
1955-
ptr::copy_nonoverlapping(v.as_ptr(), &mut (*ptr).value as *mut [T] as *mut T, v.len());
1956+
ptr::copy_nonoverlapping(
1957+
v.as_ptr(),
1958+
ptr::addr_of_mut!((*ptr).value) as *mut T,
1959+
v.len(),
1960+
);
19561961
Self::from_ptr(ptr)
19571962
}
19581963
}
@@ -1987,10 +1992,10 @@ impl<T> Rc<[T]> {
19871992
let ptr = Self::allocate_for_slice(len);
19881993

19891994
let mem = ptr as *mut _ as *mut u8;
1990-
let layout = Layout::for_value(&*ptr);
1995+
let layout = Layout::for_value_raw(ptr);
19911996

19921997
// Pointer to first element
1993-
let elems = &mut (*ptr).value as *mut [T] as *mut T;
1998+
let elems = ptr::addr_of_mut!((*ptr).value) as *mut T;
19941999

19952000
let mut guard = Guard { mem: NonNull::new_unchecked(mem), elems, layout, n_elems: 0 };
19962001

@@ -2096,7 +2101,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> {
20962101
self.inner().dec_weak();
20972102

20982103
if self.inner().weak() == 0 {
2099-
self.alloc.deallocate(self.ptr.cast(), Layout::for_value(self.ptr.as_ref()));
2104+
self.alloc
2105+
.deallocate(self.ptr.cast(), Layout::for_value_raw(self.ptr.as_ptr()));
21002106
}
21012107
}
21022108
}
@@ -2524,7 +2530,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
25242530
let (vec_ptr, len, cap, alloc) = v.into_raw_parts_with_alloc();
25252531

25262532
let rc_ptr = Self::allocate_for_slice_in(len, &alloc);
2527-
ptr::copy_nonoverlapping(vec_ptr, &mut (*rc_ptr).value as *mut [T] as *mut T, len);
2533+
ptr::copy_nonoverlapping(vec_ptr, ptr::addr_of_mut!((*rc_ptr).value) as *mut T, len);
25282534

25292535
// Create a `Vec<T, &A>` with length 0, to deallocate the buffer
25302536
// without dropping its contents or the allocator
@@ -3268,7 +3274,7 @@ trait RcInnerPtr {
32683274
// SAFETY: The reference count will never be zero when this is
32693275
// called.
32703276
unsafe {
3271-
core::intrinsics::assume(strong != 0);
3277+
hint::assert_unchecked(strong != 0);
32723278
}
32733279

32743280
let strong = strong.wrapping_add(1);
@@ -3301,7 +3307,7 @@ trait RcInnerPtr {
33013307
// SAFETY: The reference count will never be zero when this is
33023308
// called.
33033309
unsafe {
3304-
core::intrinsics::assume(weak != 0);
3310+
hint::assert_unchecked(weak != 0);
33053311
}
33063312

33073313
let weak = weak.wrapping_add(1);
@@ -3514,7 +3520,7 @@ unsafe impl<#[may_dangle] T> Drop for UniqueRc<T> {
35143520
self.ptr.as_ref().dec_weak();
35153521

35163522
if self.ptr.as_ref().weak() == 0 {
3517-
Global.deallocate(self.ptr.cast(), Layout::for_value(self.ptr.as_ref()));
3523+
Global.deallocate(self.ptr.cast(), Layout::for_value_raw(self.ptr.as_ptr()));
35183524
}
35193525
}
35203526
}

alloc/src/sync.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,11 +1828,11 @@ impl<T: ?Sized> Arc<T> {
18281828
mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T>,
18291829
) -> *mut ArcInner<T> {
18301830
let inner = mem_to_arcinner(ptr.as_non_null_ptr().as_ptr());
1831-
debug_assert_eq!(unsafe { Layout::for_value(&*inner) }, layout);
1831+
debug_assert_eq!(unsafe { Layout::for_value_raw(inner) }, layout);
18321832

18331833
unsafe {
1834-
ptr::write(&mut (*inner).strong, atomic::AtomicUsize::new(1));
1835-
ptr::write(&mut (*inner).weak, atomic::AtomicUsize::new(1));
1834+
ptr::addr_of_mut!((*inner).strong).write(atomic::AtomicUsize::new(1));
1835+
ptr::addr_of_mut!((*inner).weak).write(atomic::AtomicUsize::new(1));
18361836
}
18371837

18381838
inner
@@ -1847,7 +1847,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
18471847
// Allocate for the `ArcInner<T>` using the given value.
18481848
unsafe {
18491849
Arc::allocate_for_layout(
1850-
Layout::for_value(&*ptr),
1850+
Layout::for_value_raw(ptr),
18511851
|layout| alloc.allocate(layout),
18521852
|mem| mem.with_metadata_of(ptr as *const ArcInner<T>),
18531853
)
@@ -1863,7 +1863,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
18631863
// Copy value as bytes
18641864
ptr::copy_nonoverlapping(
18651865
&*src as *const T as *const u8,
1866-
&mut (*ptr).data as *mut _ as *mut u8,
1866+
ptr::addr_of_mut!((*ptr).data) as *mut u8,
18671867
value_size,
18681868
);
18691869

@@ -1898,7 +1898,7 @@ impl<T> Arc<[T]> {
18981898
unsafe {
18991899
let ptr = Self::allocate_for_slice(v.len());
19001900

1901-
ptr::copy_nonoverlapping(v.as_ptr(), &mut (*ptr).data as *mut [T] as *mut T, v.len());
1901+
ptr::copy_nonoverlapping(v.as_ptr(), ptr::addr_of_mut!((*ptr).data) as *mut T, v.len());
19021902

19031903
Self::from_ptr(ptr)
19041904
}
@@ -1934,10 +1934,10 @@ impl<T> Arc<[T]> {
19341934
let ptr = Self::allocate_for_slice(len);
19351935

19361936
let mem = ptr as *mut _ as *mut u8;
1937-
let layout = Layout::for_value(&*ptr);
1937+
let layout = Layout::for_value_raw(ptr);
19381938

19391939
// Pointer to first element
1940-
let elems = &mut (*ptr).data as *mut [T] as *mut T;
1940+
let elems = ptr::addr_of_mut!((*ptr).data) as *mut T;
19411941

19421942
let mut guard = Guard { mem: NonNull::new_unchecked(mem), elems, layout, n_elems: 0 };
19431943

@@ -3380,7 +3380,7 @@ impl<T, A: Allocator + Clone> From<Vec<T, A>> for Arc<[T], A> {
33803380
let (vec_ptr, len, cap, alloc) = v.into_raw_parts_with_alloc();
33813381

33823382
let rc_ptr = Self::allocate_for_slice_in(len, &alloc);
3383-
ptr::copy_nonoverlapping(vec_ptr, &mut (*rc_ptr).data as *mut [T] as *mut T, len);
3383+
ptr::copy_nonoverlapping(vec_ptr, ptr::addr_of_mut!((*rc_ptr).data) as *mut T, len);
33843384

33853385
// Create a `Vec<T, &A>` with length 0, to deallocate the buffer
33863386
// without dropping its contents or the allocator

alloc/src/vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ impl<T, A: Allocator> Vec<T, A> {
19961996
} else {
19971997
unsafe {
19981998
self.len -= 1;
1999-
core::intrinsics::assume(self.len < self.capacity());
1999+
core::hint::assert_unchecked(self.len < self.capacity());
20002000
Some(ptr::read(self.as_ptr().add(self.len())))
20012001
}
20022002
}

core/src/alloc/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use crate::ptr;
110110
/// ```rust,ignore (unsound and has placeholders)
111111
/// drop(Box::new(42));
112112
/// let number_of_heap_allocs = /* call private allocator API */;
113-
/// unsafe { std::intrinsics::assume(number_of_heap_allocs > 0); }
113+
/// unsafe { std::hint::assert_unchecked(number_of_heap_allocs > 0); }
114114
/// ```
115115
///
116116
/// Note that the optimizations mentioned above are not the only

core/src/intrinsics/mir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ define!("mir_unwind_resume",
357357

358358
define!("mir_storage_live", fn StorageLive<T>(local: T));
359359
define!("mir_storage_dead", fn StorageDead<T>(local: T));
360+
#[cfg(not(bootstrap))]
361+
define!("mir_assume", fn Assume(operand: bool));
360362
define!("mir_deinit", fn Deinit<T>(place: T));
361363
define!("mir_checked", fn Checked<T>(binop: T) -> (T, bool));
362364
define!("mir_len", fn Len<T>(place: T) -> usize);

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
#![feature(const_fmt_arguments_new)]
133133
#![feature(const_hash)]
134134
#![feature(const_heap)]
135+
#![feature(const_hint_assert_unchecked)]
135136
#![feature(const_index_range_slice_index)]
136137
#![feature(const_int_unchecked_arith)]
137138
#![feature(const_intrinsic_forget)]

core/src/num/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![stable(feature = "rust1", since = "1.0.0")]
44

55
use crate::ascii;
6+
use crate::hint;
67
use crate::intrinsics;
78
use crate::mem;
89
use crate::ops::{Add, Mul, Sub};

0 commit comments

Comments
 (0)