diff --git a/Cargo.toml b/Cargo.toml index 1ce4a83bec..39858fd43c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,9 @@ harness = false [features] default = [] +# Enable this feature if you want to use nightly features and compiler +nightly = [] + # This feature is only supported on x86-64 for now # It's manually added to CI scripts perf_counter = ["pfm"] diff --git a/src/lib.rs b/src/lib.rs index def57e4756..44bd5a123c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,8 @@ // to me - considering it will break our API and all the efforts for all the developers to make the change, it may // not worth it. #![allow(clippy::upper_case_acronyms)] +// Use the `{likely, unlikely}` provided by compiler when using nightly +#![cfg_attr(feature = "nightly", feature(core_intrinsics))] //! Memory Management ToolKit (MMTk) is a portable and high performance memory manager //! that includes various garbage collection algorithms and provides clean and efficient diff --git a/src/util/rust_util/mod.rs b/src/util/rust_util/mod.rs index 193cfe8e68..a5f8da73db 100644 --- a/src/util/rust_util/mod.rs +++ b/src/util/rust_util/mod.rs @@ -14,24 +14,27 @@ pub const fn min_of_usize(a: usize, b: usize) -> usize { } } -#[rustversion::nightly] +#[cfg(feature = "nightly")] pub use core::intrinsics::{likely, unlikely}; // likely() and unlikely() compiler hints in stable Rust // [1]: https://github.com/rust-lang/hashbrown/blob/a41bd76de0a53838725b997c6085e024c47a0455/src/raw/mod.rs#L48-L70 // [2]: https://users.rust-lang.org/t/compiler-hint-for-unlikely-likely-for-if-branches/62102/3 -#[rustversion::not(nightly)] +#[cfg(not(feature = "nightly"))] +#[inline] #[cold] fn cold() {} -#[rustversion::not(nightly)] +#[cfg(not(feature = "nightly"))] +#[inline] pub fn likely(b: bool) -> bool { if !b { cold(); } b } -#[rustversion::not(nightly)] +#[cfg(not(feature = "nightly"))] +#[inline] pub fn unlikely(b: bool) -> bool { if b { cold();