Skip to content

Commit aafb7ce

Browse files
committed
Auto merge of rust-lang#139742 - ChrisDenton:rollup-rd0vj53, r=ChrisDenton
Rollup of 11 pull requests Successful merges: - rust-lang#138972 (std: Fix build for NuttX targets) - rust-lang#139177 (Use -C target-cpu=z13 on s390x vector test) - rust-lang#139511 (libtest: Pass the test's panic payload as Option instead of Result) - rust-lang#139605 (update ```miniz_oxide``` to 0.8.8) - rust-lang#139618 (compiletest: Make `SUGGESTION` annotations viral) - rust-lang#139677 (Fix profiler_builtins build script to handle full path to profiler lib) - rust-lang#139683 (Use `with_native_path` for Windows) - rust-lang#139695 (compiletest: consistently use `camino::{Utf8Path,Utf8PathBuf}` throughout) - rust-lang#139710 (Move `args` into `std::sys`) - rust-lang#139721 (End all lines in src/stage0 with trailing newline) - rust-lang#139726 (Move `select_unpredictable` to the `hint` module) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 65fa0ab + c2c8ffa commit aafb7ce

File tree

92 files changed

+905
-998
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+905
-998
lines changed

Cargo.lock

+5-3
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ version = "0.0.0"
719719
dependencies = [
720720
"anstyle-svg",
721721
"build_helper",
722+
"camino",
722723
"colored",
723724
"diff",
724725
"getopts",
@@ -1212,7 +1213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
12121213
checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece"
12131214
dependencies = [
12141215
"crc32fast",
1215-
"miniz_oxide 0.8.7",
1216+
"miniz_oxide 0.8.8",
12161217
]
12171218

12181219
[[package]]
@@ -2282,9 +2283,9 @@ dependencies = [
22822283

22832284
[[package]]
22842285
name = "miniz_oxide"
2285-
version = "0.8.7"
2286+
version = "0.8.8"
22862287
source = "registry+https://github.com/rust-lang/crates.io-index"
2287-
checksum = "ff70ce3e48ae43fa075863cef62e8b43b71a4f2382229920e0df362592919430"
2288+
checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
22882289
dependencies = [
22892290
"adler2",
22902291
]
@@ -4671,6 +4672,7 @@ name = "rustdoc-gui-test"
46714672
version = "0.1.0"
46724673
dependencies = [
46734674
"build_helper",
4675+
"camino",
46744676
"compiletest",
46754677
"getopts",
46764678
"walkdir",

library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ dependencies = [
176176

177177
[[package]]
178178
name = "miniz_oxide"
179-
version = "0.8.7"
179+
version = "0.8.8"
180180
source = "registry+https://github.com/rust-lang/crates.io-index"
181-
checksum = "ff70ce3e48ae43fa075863cef62e8b43b71a4f2382229920e0df362592919430"
181+
checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
182182
dependencies = [
183183
"adler2",
184184
"compiler_builtins",

library/core/src/bool.rs

-48
Original file line numberDiff line numberDiff line change
@@ -61,52 +61,4 @@ impl bool {
6161
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
6262
if self { Some(f()) } else { None }
6363
}
64-
65-
/// Returns either `true_val` or `false_val` depending on the value of
66-
/// `self`, with a hint to the compiler that `self` is unlikely
67-
/// to be correctly predicted by a CPU’s branch predictor.
68-
///
69-
/// This method is functionally equivalent to
70-
/// ```ignore (this is just for illustrative purposes)
71-
/// fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T {
72-
/// if b { true_val } else { false_val }
73-
/// }
74-
/// ```
75-
/// but might generate different assembly. In particular, on platforms with
76-
/// a conditional move or select instruction (like `cmov` on x86 or `csel`
77-
/// on ARM) the optimizer might use these instructions to avoid branches,
78-
/// which can benefit performance if the branch predictor is struggling
79-
/// with predicting `condition`, such as in an implementation of binary
80-
/// search.
81-
///
82-
/// Note however that this lowering is not guaranteed (on any platform) and
83-
/// should not be relied upon when trying to write constant-time code. Also
84-
/// be aware that this lowering might *decrease* performance if `condition`
85-
/// is well-predictable. It is advisable to perform benchmarks to tell if
86-
/// this function is useful.
87-
///
88-
/// # Examples
89-
///
90-
/// Distribute values evenly between two buckets:
91-
/// ```
92-
/// #![feature(select_unpredictable)]
93-
///
94-
/// use std::hash::BuildHasher;
95-
///
96-
/// fn append<H: BuildHasher>(hasher: &H, v: i32, bucket_one: &mut Vec<i32>, bucket_two: &mut Vec<i32>) {
97-
/// let hash = hasher.hash_one(&v);
98-
/// let bucket = (hash % 2 == 0).select_unpredictable(bucket_one, bucket_two);
99-
/// bucket.push(v);
100-
/// }
101-
/// # let hasher = std::collections::hash_map::RandomState::new();
102-
/// # let mut bucket_one = Vec::new();
103-
/// # let mut bucket_two = Vec::new();
104-
/// # append(&hasher, 42, &mut bucket_one, &mut bucket_two);
105-
/// # assert_eq!(bucket_one.len() + bucket_two.len(), 1);
106-
/// ```
107-
#[inline(always)]
108-
#[unstable(feature = "select_unpredictable", issue = "133962")]
109-
pub fn select_unpredictable<T>(self, true_val: T, false_val: T) -> T {
110-
crate::intrinsics::select_unpredictable(self, true_val, false_val)
111-
}
11264
}

library/core/src/hint.rs

+49
Original file line numberDiff line numberDiff line change
@@ -734,3 +734,52 @@ pub const fn unlikely(b: bool) -> bool {
734734
pub const fn cold_path() {
735735
crate::intrinsics::cold_path()
736736
}
737+
738+
/// Returns either `true_val` or `false_val` depending on the value of `b`,
739+
/// with a hint to the compiler that `b` is unlikely to be correctly
740+
/// predicted by a CPU’s branch predictor.
741+
///
742+
/// This method is functionally equivalent to
743+
/// ```ignore (this is just for illustrative purposes)
744+
/// fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T {
745+
/// if b { true_val } else { false_val }
746+
/// }
747+
/// ```
748+
/// but might generate different assembly. In particular, on platforms with
749+
/// a conditional move or select instruction (like `cmov` on x86 or `csel`
750+
/// on ARM) the optimizer might use these instructions to avoid branches,
751+
/// which can benefit performance if the branch predictor is struggling
752+
/// with predicting `condition`, such as in an implementation of binary
753+
/// search.
754+
///
755+
/// Note however that this lowering is not guaranteed (on any platform) and
756+
/// should not be relied upon when trying to write constant-time code. Also
757+
/// be aware that this lowering might *decrease* performance if `condition`
758+
/// is well-predictable. It is advisable to perform benchmarks to tell if
759+
/// this function is useful.
760+
///
761+
/// # Examples
762+
///
763+
/// Distribute values evenly between two buckets:
764+
/// ```
765+
/// #![feature(select_unpredictable)]
766+
///
767+
/// use std::hash::BuildHasher;
768+
/// use std::hint;
769+
///
770+
/// fn append<H: BuildHasher>(hasher: &H, v: i32, bucket_one: &mut Vec<i32>, bucket_two: &mut Vec<i32>) {
771+
/// let hash = hasher.hash_one(&v);
772+
/// let bucket = hint::select_unpredictable(hash % 2 == 0, bucket_one, bucket_two);
773+
/// bucket.push(v);
774+
/// }
775+
/// # let hasher = std::collections::hash_map::RandomState::new();
776+
/// # let mut bucket_one = Vec::new();
777+
/// # let mut bucket_two = Vec::new();
778+
/// # append(&hasher, 42, &mut bucket_one, &mut bucket_two);
779+
/// # assert_eq!(bucket_one.len() + bucket_two.len(), 1);
780+
/// ```
781+
#[inline(always)]
782+
#[unstable(feature = "select_unpredictable", issue = "133962")]
783+
pub fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T {
784+
crate::intrinsics::select_unpredictable(b, true_val, false_val)
785+
}

library/core/src/intrinsics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ pub const fn unlikely(b: bool) -> bool {
13261326
/// Therefore, implementations must not require the user to uphold
13271327
/// any safety invariants.
13281328
///
1329-
/// The public form of this instrinsic is [`bool::select_unpredictable`].
1329+
/// The public form of this instrinsic is [`core::hint::select_unpredictable`].
13301330
#[unstable(feature = "core_intrinsics", issue = "none")]
13311331
#[rustc_intrinsic]
13321332
#[rustc_nounwind]

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ impl<T> [T] {
28222822
// Binary search interacts poorly with branch prediction, so force
28232823
// the compiler to use conditional moves if supported by the target
28242824
// architecture.
2825-
base = (cmp == Greater).select_unpredictable(base, mid);
2825+
base = hint::select_unpredictable(cmp == Greater, base, mid);
28262826

28272827
// This is imprecise in the case where `size` is odd and the
28282828
// comparison returns Greater: the mid element still gets included

library/core/src/slice/sort/shared/smallsort.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::mem::{self, ManuallyDrop, MaybeUninit};
44
use crate::slice::sort::shared::FreezeMarker;
5-
use crate::{intrinsics, ptr, slice};
5+
use crate::{hint, intrinsics, ptr, slice};
66

77
// It's important to differentiate between SMALL_SORT_THRESHOLD performance for
88
// small slices and small-sort performance sorting small sub-slices as part of
@@ -408,8 +408,8 @@ where
408408
// }
409409

410410
// The goal is to generate cmov instructions here.
411-
let v_a_swap = should_swap.select_unpredictable(v_b, v_a);
412-
let v_b_swap = should_swap.select_unpredictable(v_a, v_b);
411+
let v_a_swap = hint::select_unpredictable(should_swap, v_b, v_a);
412+
let v_b_swap = hint::select_unpredictable(should_swap, v_a, v_b);
413413

414414
let v_b_swap_tmp = ManuallyDrop::new(ptr::read(v_b_swap));
415415
ptr::copy(v_a_swap, v_a, 1);
@@ -640,15 +640,15 @@ pub unsafe fn sort4_stable<T, F: FnMut(&T, &T) -> bool>(
640640
// 1, 1 | c b a d
641641
let c3 = is_less(&*c, &*a);
642642
let c4 = is_less(&*d, &*b);
643-
let min = c3.select_unpredictable(c, a);
644-
let max = c4.select_unpredictable(b, d);
645-
let unknown_left = c3.select_unpredictable(a, c4.select_unpredictable(c, b));
646-
let unknown_right = c4.select_unpredictable(d, c3.select_unpredictable(b, c));
643+
let min = hint::select_unpredictable(c3, c, a);
644+
let max = hint::select_unpredictable(c4, b, d);
645+
let unknown_left = hint::select_unpredictable(c3, a, hint::select_unpredictable(c4, c, b));
646+
let unknown_right = hint::select_unpredictable(c4, d, hint::select_unpredictable(c3, b, c));
647647

648648
// Sort the last two unknown elements.
649649
let c5 = is_less(&*unknown_right, &*unknown_left);
650-
let lo = c5.select_unpredictable(unknown_right, unknown_left);
651-
let hi = c5.select_unpredictable(unknown_left, unknown_right);
650+
let lo = hint::select_unpredictable(c5, unknown_right, unknown_left);
651+
let hi = hint::select_unpredictable(c5, unknown_left, unknown_right);
652652

653653
ptr::copy_nonoverlapping(min, dst, 1);
654654
ptr::copy_nonoverlapping(lo, dst.add(1), 1);

library/profiler_builtins/build.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ use std::path::PathBuf;
99

1010
fn main() {
1111
if let Ok(rt) = tracked_env_var("LLVM_PROFILER_RT_LIB") {
12-
println!("cargo::rustc-link-lib=static:+verbatim={rt}");
13-
return;
12+
let rt = PathBuf::from(rt);
13+
if let Some(lib) = rt.file_name() {
14+
if let Some(dir) = rt.parent() {
15+
println!("cargo::rustc-link-search=native={}", dir.display());
16+
}
17+
println!("cargo::rustc-link-lib=static:+verbatim={}", lib.to_str().unwrap());
18+
return;
19+
}
1420
}
1521

1622
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set");

library/std/src/sys/args/common.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::ffi::OsString;
2+
use crate::{fmt, vec};
3+
4+
pub struct Args {
5+
iter: vec::IntoIter<OsString>,
6+
}
7+
8+
impl !Send for Args {}
9+
impl !Sync for Args {}
10+
11+
impl Args {
12+
pub(super) fn new(args: Vec<OsString>) -> Self {
13+
Args { iter: args.into_iter() }
14+
}
15+
}
16+
17+
impl fmt::Debug for Args {
18+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19+
self.iter.as_slice().fmt(f)
20+
}
21+
}
22+
23+
impl Iterator for Args {
24+
type Item = OsString;
25+
fn next(&mut self) -> Option<OsString> {
26+
self.iter.next()
27+
}
28+
fn size_hint(&self) -> (usize, Option<usize>) {
29+
self.iter.size_hint()
30+
}
31+
}
32+
33+
impl ExactSizeIterator for Args {
34+
fn len(&self) -> usize {
35+
self.iter.len()
36+
}
37+
}
38+
39+
impl DoubleEndedIterator for Args {
40+
fn next_back(&mut self) -> Option<OsString> {
41+
self.iter.next_back()
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use crate::ffi::{CStr, OsString, c_char};
22
use crate::os::hermit::ffi::OsStringExt;
3+
use crate::ptr;
34
use crate::sync::atomic::Ordering::{Acquire, Relaxed, Release};
45
use crate::sync::atomic::{AtomicIsize, AtomicPtr};
5-
use crate::{fmt, ptr, vec};
6+
7+
#[path = "common.rs"]
8+
mod common;
9+
pub use common::Args;
610

711
static ARGC: AtomicIsize = AtomicIsize::new(0);
812
static ARGV: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut());
@@ -27,40 +31,5 @@ pub fn args() -> Args {
2731
})
2832
.collect();
2933

30-
Args { iter: args.into_iter() }
31-
}
32-
33-
pub struct Args {
34-
iter: vec::IntoIter<OsString>,
35-
}
36-
37-
impl fmt::Debug for Args {
38-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39-
self.iter.as_slice().fmt(f)
40-
}
41-
}
42-
43-
impl !Send for Args {}
44-
impl !Sync for Args {}
45-
46-
impl Iterator for Args {
47-
type Item = OsString;
48-
fn next(&mut self) -> Option<OsString> {
49-
self.iter.next()
50-
}
51-
fn size_hint(&self) -> (usize, Option<usize>) {
52-
self.iter.size_hint()
53-
}
54-
}
55-
56-
impl ExactSizeIterator for Args {
57-
fn len(&self) -> usize {
58-
self.iter.len()
59-
}
60-
}
61-
62-
impl DoubleEndedIterator for Args {
63-
fn next_back(&mut self) -> Option<OsString> {
64-
self.iter.next_back()
65-
}
34+
Args::new(args)
6635
}

library/std/src/sys/args/mod.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Platform-dependent command line arguments abstraction.
2+
3+
#![forbid(unsafe_op_in_unsafe_fn)]
4+
5+
cfg_if::cfg_if! {
6+
if #[cfg(all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))))] {
7+
mod unix;
8+
pub use unix::*;
9+
} else if #[cfg(target_family = "windows")] {
10+
mod windows;
11+
pub use windows::*;
12+
} else if #[cfg(target_os = "hermit")] {
13+
mod hermit;
14+
pub use hermit::*;
15+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
16+
mod sgx;
17+
pub use sgx::*;
18+
} else if #[cfg(target_os = "uefi")] {
19+
mod uefi;
20+
pub use uefi::*;
21+
} else if #[cfg(target_os = "wasi")] {
22+
mod wasi;
23+
pub use wasi::*;
24+
} else if #[cfg(target_os = "xous")] {
25+
mod xous;
26+
pub use xous::*;
27+
} else if #[cfg(target_os = "zkvm")] {
28+
mod zkvm;
29+
pub use zkvm::*;
30+
} else {
31+
mod unsupported;
32+
pub use unsupported::*;
33+
}
34+
}

library/std/src/sys/pal/sgx/args.rs renamed to library/std/src/sys/args/sgx.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use super::abi::usercalls::alloc;
2-
use super::abi::usercalls::raw::ByteBuffer;
1+
#![allow(fuzzy_provenance_casts)] // FIXME: this module systematically confuses pointers and integers
2+
33
use crate::ffi::OsString;
44
use crate::sync::atomic::{AtomicUsize, Ordering};
55
use crate::sys::os_str::Buf;
6+
use crate::sys::pal::abi::usercalls::alloc;
7+
use crate::sys::pal::abi::usercalls::raw::ByteBuffer;
68
use crate::sys_common::FromInner;
79
use crate::{fmt, slice};
810

0 commit comments

Comments
 (0)