Skip to content

Commit 6ed8462

Browse files
authored
Rollup merge of rust-lang#84216 - RalfJung:black-box, r=Mark-Simulacrum
move core::hint::black_box under its own feature gate The `black_box` function had its own RFC and is tracked separately from the `test` feature at rust-lang#64102. Let's reflect this in the feature gate. To avoid breaking all the benchmarks, libtest's `test::black_box` is a wrapping definition, not a reexport -- this means it is still under the `test` feature gate.
2 parents 18523ee + 03900e4 commit 6ed8462

File tree

8 files changed

+19
-9
lines changed

8 files changed

+19
-9
lines changed

compiler/rustc_index/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(allow_internal_unstable)]
2+
#![feature(bench_black_box)]
23
#![feature(const_fn)]
34
#![feature(const_panic)]
45
#![feature(extend_one)]

library/core/benches/fmt.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,28 @@ fn write_str_macro_debug(bh: &mut Bencher) {
112112
#[bench]
113113
fn write_u128_max(bh: &mut Bencher) {
114114
bh.iter(|| {
115-
std::hint::black_box(format!("{}", u128::MAX));
115+
test::black_box(format!("{}", u128::MAX));
116116
});
117117
}
118118

119119
#[bench]
120120
fn write_u128_min(bh: &mut Bencher) {
121121
bh.iter(|| {
122122
let s = format!("{}", 0u128);
123-
std::hint::black_box(s);
123+
test::black_box(s);
124124
});
125125
}
126126

127127
#[bench]
128128
fn write_u64_max(bh: &mut Bencher) {
129129
bh.iter(|| {
130-
std::hint::black_box(format!("{}", u64::MAX));
130+
test::black_box(format!("{}", u64::MAX));
131131
});
132132
}
133133

134134
#[bench]
135135
fn write_u64_min(bh: &mut Bencher) {
136136
bh.iter(|| {
137-
std::hint::black_box(format!("{}", 0u64));
137+
test::black_box(format!("{}", 0u64));
138138
});
139139
}

library/core/src/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn spin_loop() {
154154
/// [`std::convert::identity`]: crate::convert::identity
155155
#[cfg_attr(not(miri), inline)]
156156
#[cfg_attr(miri, inline(never))]
157-
#[unstable(feature = "test", issue = "50297")]
157+
#[unstable(feature = "bench_black_box", issue = "64102")]
158158
#[cfg_attr(miri, allow(unused_mut))]
159159
pub fn black_box<T>(mut dummy: T) -> T {
160160
// We need to "use" the argument in some way LLVM can't introspect, and on

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
#![feature(assert_matches)]
234234
#![feature(associated_type_bounds)]
235235
#![feature(atomic_mut_ptr)]
236+
#![feature(bench_black_box)]
236237
#![feature(box_syntax)]
237238
#![feature(c_variadic)]
238239
#![feature(cfg_accessible)]

library/test/src/bench.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//! Benchmarking module.
2-
pub use std::hint::black_box;
3-
42
use super::{
53
event::CompletedTest,
64
options::BenchMode,
@@ -16,6 +14,15 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
1614
use std::sync::{Arc, Mutex};
1715
use std::time::{Duration, Instant};
1816

17+
/// An identity function that *__hints__* to the compiler to be maximally pessimistic about what
18+
/// `black_box` could do.
19+
///
20+
/// See [`std::hint::black_box`] for details.
21+
#[inline(always)]
22+
pub fn black_box<T>(dummy: T) -> T {
23+
std::hint::black_box(dummy)
24+
}
25+
1926
/// Manager of the benchmarking runs.
2027
///
2128
/// This is fed into functions marked with `#[bench]` to allow for

library/test/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#![feature(rustc_private)]
2525
#![feature(nll)]
2626
#![feature(available_concurrency)]
27+
#![feature(bench_black_box)]
2728
#![feature(internal_output_capture)]
2829
#![feature(panic_unwind)]
2930
#![feature(staged_api)]

src/test/ui/consts/cast-discriminant-zst-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22
// Test a ZST enum whose dicriminant is ~0i128. This caused an ICE when casting to a i32.
3-
#![feature(test)]
3+
#![feature(bench_black_box)]
44
use std::hint::black_box;
55

66
#[derive(Copy, Clone)]

src/test/ui/consts/const_discriminant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22
#![feature(const_discriminant)]
3-
#![feature(test)]
3+
#![feature(bench_black_box)]
44
#![allow(dead_code)]
55

66
use std::mem::{discriminant, Discriminant};

0 commit comments

Comments
 (0)