Skip to content

Commit c0cfa04

Browse files
author
The Miri Conjob Bot
committed
Merge from rustc
2 parents 67fb0bc + d8a1def commit c0cfa04

File tree

26 files changed

+248
-124
lines changed

26 files changed

+248
-124
lines changed

alloc/src/raw_vec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ fn handle_reserve(result: Result<(), TryReserveError>) {
552552
// `> isize::MAX` bytes will surely fail. On 32-bit and 16-bit we need to add
553553
// an extra guard for this in case we're running on a platform which can use
554554
// all 4GB in user-space, e.g., PAE or x32.
555-
556555
#[inline]
557556
fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> {
558557
if usize::BITS < 64 && alloc_size > isize::MAX as usize {

alloc/tests/autotraits.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ fn test_btree_map() {
5555

5656
require_send_sync(async {
5757
let _v = None::<
58-
alloc::collections::btree_map::ExtractIf<
59-
'_,
60-
&u32,
61-
&u32,
62-
fn(&&u32, &mut &u32) -> bool,
63-
>,
58+
alloc::collections::btree_map::ExtractIf<'_, &u32, &u32, fn(&&u32, &mut &u32) -> bool>,
6459
>;
6560
async {}.await;
6661
});

alloc/tests/vec.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::alloc::{Allocator, Layout};
2-
use core::{assert_eq, assert_ne};
32
use core::num::NonZeroUsize;
43
use core::ptr::NonNull;
4+
use core::{assert_eq, assert_ne};
55
use std::alloc::System;
66
use std::assert_matches::assert_matches;
77
use std::borrow::Cow;
@@ -1212,7 +1212,7 @@ fn test_in_place_specialization_step_up_down() {
12121212
assert_eq!(sink.len(), 2);
12131213

12141214
let mut src: Vec<[u8; 3]> = Vec::with_capacity(17);
1215-
src.resize( 8, [0; 3]);
1215+
src.resize(8, [0; 3]);
12161216
let iter = src.into_iter().map(|[a, b, _]| [a, b]);
12171217
assert_in_place_trait(&iter);
12181218
let sink: Vec<[u8; 2]> = iter.collect();
@@ -1221,11 +1221,7 @@ fn test_in_place_specialization_step_up_down() {
12211221

12221222
let src = vec![[0u8; 4]; 256];
12231223
let srcptr = src.as_ptr();
1224-
let iter = src
1225-
.into_iter()
1226-
.flat_map(|a| {
1227-
a.into_iter().map(|b| b.wrapping_add(1))
1228-
});
1224+
let iter = src.into_iter().flat_map(|a| a.into_iter().map(|b| b.wrapping_add(1)));
12291225
assert_in_place_trait(&iter);
12301226
let sink = iter.collect::<Vec<_>>();
12311227
assert_eq!(srcptr as *const u8, sink.as_ptr());

core/benches/num/int_pow/mod.rs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
use rand::Rng;
2+
use test::{black_box, Bencher};
3+
4+
const ITERATIONS: usize = 128; // Uses an ITERATIONS * 20 Byte stack allocation
5+
type IntType = i128; // Hardest native type to multiply
6+
const EXPONENT_MAX: u32 = 31;
7+
const MAX_BASE: IntType = 17; // +-17 ** 31 <= IntType::MAX
8+
9+
macro_rules! pow_bench_template {
10+
($name:ident, $inner_macro:ident, $base_macro:ident) => {
11+
#[bench]
12+
fn $name(bench: &mut Bencher) {
13+
// Frequent black_box calls can add latency and prevent optimizations, so for
14+
// variable parameters we premake an array and pass the
15+
// reference through black_box outside of the loop.
16+
let mut rng = crate::bench_rng();
17+
let base_array: [IntType; ITERATIONS] =
18+
core::array::from_fn(|_| rng.gen_range((-MAX_BASE..=MAX_BASE)));
19+
let exp_array: [u32; ITERATIONS] =
20+
core::array::from_fn(|_| rng.gen_range((0..=EXPONENT_MAX)));
21+
22+
bench.iter(|| {
23+
#[allow(unused, unused_mut)]
24+
let mut base_iter = black_box(&base_array).into_iter();
25+
let mut exp_iter = black_box(&exp_array).into_iter();
26+
27+
(0..ITERATIONS).fold((0 as IntType, false), |acc, _| {
28+
// Sometimes constants don't propogate all the way to the
29+
// inside of the loop, so we call a custom expression every cycle
30+
// rather than iter::repeat(CONST)
31+
let base: IntType = $base_macro!(base_iter);
32+
let exp: u32 = *exp_iter.next().unwrap();
33+
34+
let r: (IntType, bool) = $inner_macro!(base, exp);
35+
(acc.0 ^ r.0, acc.1 ^ r.1)
36+
})
37+
});
38+
}
39+
};
40+
}
41+
42+
// This may panic if it overflows.
43+
macro_rules! inner_pow {
44+
($base:ident, $exp:ident) => {
45+
($base.pow($exp), false)
46+
};
47+
}
48+
49+
macro_rules! inner_wrapping {
50+
($base:ident, $exp:ident) => {
51+
($base.wrapping_pow($exp), false)
52+
};
53+
}
54+
55+
macro_rules! inner_overflowing {
56+
($base:ident, $exp:ident) => {
57+
$base.overflowing_pow($exp)
58+
};
59+
}
60+
61+
// This will panic if it overflows.
62+
macro_rules! inner_checked_unwrapped {
63+
($base:ident, $exp:ident) => {
64+
($base.checked_pow($exp).unwrap(), false)
65+
};
66+
}
67+
68+
macro_rules! inner_saturating {
69+
($base:ident, $exp:ident) => {
70+
($base.saturating_pow($exp), false)
71+
};
72+
}
73+
74+
macro_rules! make_const_base {
75+
($name:ident, $x:literal) => {
76+
macro_rules! $name {
77+
($iter:ident) => {
78+
$x
79+
};
80+
}
81+
};
82+
}
83+
84+
make_const_base!(const_base_m7, -7);
85+
make_const_base!(const_base_m8, -8);
86+
87+
macro_rules! variable_base {
88+
($iter:ident) => {
89+
*$iter.next().unwrap()
90+
};
91+
}
92+
93+
pow_bench_template!(pow_variable, inner_pow, variable_base);
94+
pow_bench_template!(wrapping_pow_variable, inner_wrapping, variable_base);
95+
pow_bench_template!(overflowing_pow_variable, inner_overflowing, variable_base);
96+
pow_bench_template!(checked_pow_variable, inner_checked_unwrapped, variable_base);
97+
pow_bench_template!(saturating_pow_variable, inner_saturating, variable_base);
98+
pow_bench_template!(pow_m7, inner_pow, const_base_m7);
99+
pow_bench_template!(pow_m8, inner_pow, const_base_m8);

core/benches/num/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod dec2flt;
22
mod flt2dec;
33
mod int_log;
4+
mod int_pow;
45

56
use std::str::FromStr;
67
use test::{black_box, Bencher};

core/src/intrinsics.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,8 +1787,9 @@ extern "rust-intrinsic" {
17871787
/// so this rounds half-way cases to the number with an even least significant digit.
17881788
///
17891789
/// May raise an inexact floating-point exception if the argument is not an integer.
1790-
/// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that
1791-
/// can actually be used from Rust code.
1790+
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
1791+
/// cannot actually be utilized from Rust code.
1792+
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf32` and `roundevenf32`.
17921793
///
17931794
/// The stabilized version of this intrinsic is
17941795
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
@@ -1798,8 +1799,9 @@ extern "rust-intrinsic" {
17981799
/// so this rounds half-way cases to the number with an even least significant digit.
17991800
///
18001801
/// May raise an inexact floating-point exception if the argument is not an integer.
1801-
/// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that
1802-
/// can actually be used from Rust code.
1802+
/// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions
1803+
/// cannot actually be utilized from Rust code.
1804+
/// In other words, this intrinsic is equivalent in behavior to `nearbyintf64` and `roundevenf64`.
18031805
///
18041806
/// The stabilized version of this intrinsic is
18051807
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)

core/src/num/nonzero.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ macro_rules! nonzero_integers {
104104
#[inline]
105105
#[rustc_const_stable(feature = "const_nonzero_get", since = "1.34.0")]
106106
pub const fn get(self) -> $Int {
107+
// FIXME: Remove this after LLVM supports `!range` metadata for function
108+
// arguments https://github.com/llvm/llvm-project/issues/76628
109+
//
110+
// Rustc can set range metadata only if it loads `self` from
111+
// memory somewhere. If the value of `self` was from by-value argument
112+
// of some not-inlined function, LLVM don't have range metadata
113+
// to understand that the value cannot be zero.
114+
115+
// SAFETY: It is an invariant of this type.
116+
unsafe {
117+
intrinsics::assume(self.0 != 0);
118+
}
107119
self.0
108120
}
109121

@@ -114,7 +126,9 @@ macro_rules! nonzero_integers {
114126
#[doc = concat!("Converts a `", stringify!($Ty), "` into an `", stringify!($Int), "`")]
115127
#[inline]
116128
fn from(nonzero: $Ty) -> Self {
117-
nonzero.0
129+
// Call nonzero to keep information range information
130+
// from get method.
131+
nonzero.get()
118132
}
119133
}
120134

@@ -233,7 +247,7 @@ macro_rules! nonzero_leading_trailing_zeros {
233247
#[inline]
234248
pub const fn leading_zeros(self) -> u32 {
235249
// SAFETY: since `self` cannot be zero, it is safe to call `ctlz_nonzero`.
236-
unsafe { intrinsics::ctlz_nonzero(self.0 as $Uint) as u32 }
250+
unsafe { intrinsics::ctlz_nonzero(self.get() as $Uint) as u32 }
237251
}
238252

239253
/// Returns the number of trailing zeros in the binary representation
@@ -257,7 +271,7 @@ macro_rules! nonzero_leading_trailing_zeros {
257271
#[inline]
258272
pub const fn trailing_zeros(self) -> u32 {
259273
// SAFETY: since `self` cannot be zero, it is safe to call `cttz_nonzero`.
260-
unsafe { intrinsics::cttz_nonzero(self.0 as $Uint) as u32 }
274+
unsafe { intrinsics::cttz_nonzero(self.get() as $Uint) as u32 }
261275
}
262276

263277
}
@@ -515,7 +529,7 @@ macro_rules! nonzero_unsigned_operations {
515529
without modifying the original"]
516530
#[inline]
517531
pub const fn ilog10(self) -> u32 {
518-
super::int_log10::$Int(self.0)
532+
super::int_log10::$Int(self.get())
519533
}
520534

521535
/// Calculates the middle point of `self` and `rhs`.

core/tests/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use core::{array, assert_eq};
21
use core::num::NonZeroUsize;
32
use core::sync::atomic::{AtomicUsize, Ordering};
3+
use core::{array, assert_eq};
44

55
#[test]
66
fn array_from_ref() {

core/tests/cell.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,14 @@ fn const_cells() {
466466
const CELL: Cell<i32> = Cell::new(3);
467467
const _: i32 = CELL.into_inner();
468468

469-
/* FIXME(#110395)
470-
const UNSAFE_CELL_FROM: UnsafeCell<i32> = UnsafeCell::from(3);
471-
const _: i32 = UNSAFE_CELL.into_inner();
469+
/* FIXME(#110395)
470+
const UNSAFE_CELL_FROM: UnsafeCell<i32> = UnsafeCell::from(3);
471+
const _: i32 = UNSAFE_CELL.into_inner();
472472
473-
const REF_CELL_FROM: RefCell<i32> = RefCell::from(3);
474-
const _: i32 = REF_CELL.into_inner();
473+
const REF_CELL_FROM: RefCell<i32> = RefCell::from(3);
474+
const _: i32 = REF_CELL.into_inner();
475475
476-
const CELL_FROM: Cell<i32> = Cell::from(3);
477-
const _: i32 = CELL.into_inner();
478-
*/
476+
const CELL_FROM: Cell<i32> = Cell::from(3);
477+
const _: i32 = CELL.into_inner();
478+
*/
479479
}

core/tests/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::error::{request_value, request_ref, Request};
1+
use core::error::{request_ref, request_value, Request};
22

33
// Test the `Request` API.
44
#[derive(Debug)]

0 commit comments

Comments
 (0)