From 6e955c39e8ab6c21930e6620a35cc136cea68dba Mon Sep 17 00:00:00 2001 From: Caleb Robson <94545082+Spartan2909@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:01:23 +0100 Subject: [PATCH 1/5] Reexport std::hint::black_box --- src/lib.rs | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 855c68ff2..dcf32e7ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,7 @@ use std::cell::RefCell; use std::collections::HashSet; use std::default::Default; use std::env; +pub use std::hint::black_box; use std::io::stdout; use std::net::TcpStream; use std::path::{Path, PathBuf}; @@ -149,29 +150,6 @@ fn debug_enabled() -> bool { *DEBUG_ENABLED } -/// A function that is opaque to the optimizer, used to prevent the compiler from -/// optimizing away computations in a benchmark. -/// -/// This variant is backed by the (unstable) test::black_box function. -#[cfg(feature = "real_blackbox")] -pub fn black_box(dummy: T) -> T { - test::black_box(dummy) -} - -/// A function that is opaque to the optimizer, used to prevent the compiler from -/// optimizing away computations in a benchmark. -/// -/// This variant is stable-compatible, but it may cause some performance overhead -/// or fail to prevent code from being eliminated. -#[cfg(not(feature = "real_blackbox"))] -pub fn black_box(dummy: T) -> T { - unsafe { - let ret = std::ptr::read_volatile(&dummy); - std::mem::forget(dummy); - ret - } -} - /// Argument to [`Bencher::iter_batched`](struct.Bencher.html#method.iter_batched) and /// [`Bencher::iter_batched_ref`](struct.Bencher.html#method.iter_batched_ref) which controls the /// batch size. From d3d62ef38bec7eaaf96abb189bc3b3bf8162b56a Mon Sep 17 00:00:00 2001 From: Caleb Robson <94545082+Spartan2909@users.noreply.github.com> Date: Wed, 19 Jul 2023 16:41:28 +0100 Subject: [PATCH 2/5] Add deprecated black_box function --- src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index dcf32e7ad..82c24d45f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ use std::cell::RefCell; use std::collections::HashSet; use std::default::Default; use std::env; -pub use std::hint::black_box; +use std::hint; use std::io::stdout; use std::net::TcpStream; use std::path::{Path, PathBuf}; @@ -150,6 +150,15 @@ fn debug_enabled() -> bool { *DEBUG_ENABLED } +/// A function that is opaque to the optimizer, used to prevent the compiler from +/// optimizing away computations in a benchmark. +/// +/// This function is deprecated in favour of `std::hint::black_box`. +#[deprecated(note = "use `std::hint::black_box` instead")] +pub fn black_box(dummy: T) -> T { + hint::black_box(dummy) +} + /// Argument to [`Bencher::iter_batched`](struct.Bencher.html#method.iter_batched) and /// [`Bencher::iter_batched_ref`](struct.Bencher.html#method.iter_batched_ref) which controls the /// batch size. From 18b209617b4f4e00be04a68de38ade0c6336b810 Mon Sep 17 00:00:00 2001 From: Caleb Robson <94545082+Spartan2909@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:05:59 +0100 Subject: [PATCH 3/5] Bump MSRV and remove unused nightly feature --- .github/workflows/ci.yaml | 2 +- Cargo.toml | 3 ++- src/lib.rs | 4 ---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 44a5fffe1..985aea4de 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: matrix: rust: - stable - - 1.64.0 # MSRV + - 1.66.0 # MSRV - nightly steps: diff --git a/Cargo.toml b/Cargo.toml index b73124173..3fde89c35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ keywords = ["criterion", "benchmark"] categories = ["development-tools::profiling"] license = "Apache-2.0 OR MIT" exclude = ["book/*"] +rust-version = "1.66" [dependencies] anes = "0.1.4" @@ -69,7 +70,7 @@ stable = [ "async_tokio", "async_std", ] -default = ["rayon", "plotters", "cargo_bench_support"] +default = ["rayon", "plotters", "cargo_bench_support", "real_blackbox"] # Enable use of the nightly-only test::black_box function to discourage compiler optimizations. real_blackbox = [] diff --git a/src/lib.rs b/src/lib.rs index 82c24d45f..46af1b615 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ #![warn(missing_docs)] #![warn(bare_trait_objects)] -#![cfg_attr(feature = "real_blackbox", feature(test))] #![cfg_attr( feature = "cargo-clippy", allow( @@ -39,9 +38,6 @@ extern crate quickcheck; use is_terminal::IsTerminal; use regex::Regex; -#[cfg(feature = "real_blackbox")] -extern crate test; - #[macro_use] extern crate serde_derive; From fc6a63542ce6283fa66424972d0ced1d8478a533 Mon Sep 17 00:00:00 2001 From: Caleb Robson <94545082+Spartan2909@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:14:54 +0100 Subject: [PATCH 4/5] Fix formatting --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 46af1b615..9f997f9c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,7 +148,7 @@ fn debug_enabled() -> bool { /// A function that is opaque to the optimizer, used to prevent the compiler from /// optimizing away computations in a benchmark. -/// +/// /// This function is deprecated in favour of `std::hint::black_box`. #[deprecated(note = "use `std::hint::black_box` instead")] pub fn black_box(dummy: T) -> T { From 4b6c0780dbea62273a72edfaa92a8f7c1c364a1a Mon Sep 17 00:00:00 2001 From: Caleb Robson <94545082+Spartan2909@users.noreply.github.com> Date: Sat, 25 May 2024 15:28:05 +0100 Subject: [PATCH 5/5] Fix missing import --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 66ea3c356..5aa9b1de1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,7 @@ mod stats; use std::cell::RefCell; use std::collections::HashSet; use std::env; +use std::hint; use std::io::{stdout, IsTerminal}; use std::net::TcpStream; use std::path::{Path, PathBuf};