Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move core::hint::black_box under its own feature gate #84216

Merged
merged 2 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_index/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(allow_internal_unstable)]
#![feature(bench_black_box)]
#![feature(const_panic)]
#![feature(extend_one)]
#![feature(iter_zip)]
Expand Down
8 changes: 4 additions & 4 deletions library/core/benches/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,28 @@ fn write_str_macro_debug(bh: &mut Bencher) {
#[bench]
fn write_u128_max(bh: &mut Bencher) {
bh.iter(|| {
std::hint::black_box(format!("{}", u128::MAX));
test::black_box(format!("{}", u128::MAX));
});
}

#[bench]
fn write_u128_min(bh: &mut Bencher) {
bh.iter(|| {
let s = format!("{}", 0u128);
std::hint::black_box(s);
test::black_box(s);
});
}

#[bench]
fn write_u64_max(bh: &mut Bencher) {
bh.iter(|| {
std::hint::black_box(format!("{}", u64::MAX));
test::black_box(format!("{}", u64::MAX));
});
}

#[bench]
fn write_u64_min(bh: &mut Bencher) {
bh.iter(|| {
std::hint::black_box(format!("{}", 0u64));
test::black_box(format!("{}", 0u64));
});
}
2 changes: 1 addition & 1 deletion library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn spin_loop() {
/// [`std::convert::identity`]: crate::convert::identity
#[cfg_attr(not(miri), inline)]
#[cfg_attr(miri, inline(never))]
#[unstable(feature = "test", issue = "50297")]
#[unstable(feature = "bench_black_box", issue = "64102")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, shouldn't this not use bench in the name? Is black_box taken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the name of the RFC.

#[cfg_attr(miri, allow(unused_mut))]
pub fn black_box<T>(mut dummy: T) -> T {
// We need to "use" the argument in some way LLVM can't introspect, and on
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
#![feature(assert_matches)]
#![feature(associated_type_bounds)]
#![feature(atomic_mut_ptr)]
#![feature(bench_black_box)]
#![feature(box_syntax)]
#![feature(c_variadic)]
#![feature(cfg_accessible)]
Expand Down
11 changes: 9 additions & 2 deletions library/test/src/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Benchmarking module.
pub use std::hint::black_box;

use super::{
event::CompletedTest,
options::BenchMode,
Expand All @@ -16,6 +14,15 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};

/// An identity function that *__hints__* to the compiler to be maximally pessimistic about what
/// `black_box` could do.
///
/// See [`std::hint::black_box`] for details.
#[inline(always)]
pub fn black_box<T>(dummy: T) -> T {
std::hint::black_box(dummy)
}

/// Manager of the benchmarking runs.
///
/// This is fed into functions marked with `#[bench]` to allow for
Expand Down
1 change: 1 addition & 0 deletions library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#![feature(rustc_private)]
#![feature(nll)]
#![feature(available_concurrency)]
#![feature(bench_black_box)]
#![feature(internal_output_capture)]
#![feature(panic_unwind)]
#![feature(staged_api)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/cast-discriminant-zst-enum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// run-pass
// Test a ZST enum whose dicriminant is ~0i128. This caused an ICE when casting to a i32.
#![feature(test)]
#![feature(bench_black_box)]
use std::hint::black_box;

#[derive(Copy, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const_discriminant.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// run-pass
#![feature(const_discriminant)]
#![feature(test)]
#![feature(bench_black_box)]
#![allow(dead_code)]

use std::mem::{discriminant, Discriminant};
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/sanitize/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// error-pattern: AddressSanitizer: stack-buffer-overflow
// error-pattern: 'xs' (line 15) <== Memory access at offset

#![feature(test)]
#![feature(bench_black_box)]

use std::hint::black_box;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/sanitize/hwaddress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// run-fail
// error-pattern: HWAddressSanitizer: tag-mismatch

#![feature(test)]
#![feature(bench_black_box)]

use std::hint::black_box;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/sanitize/leak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// run-fail
// error-pattern: LeakSanitizer: detected memory leaks

#![feature(test)]
#![feature(bench_black_box)]

use std::hint::black_box;
use std::mem;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/sanitize/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#![feature(core_intrinsics)]
#![feature(start)]
#![feature(test)]
#![feature(bench_black_box)]

use std::hint::black_box;
use std::mem::MaybeUninit;
Expand Down