Skip to content

Commit 41501a5

Browse files
authored
Fix nightly build and add inline attributes to {un,}likely (#1228)
1 parent 753f71c commit 41501a5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ default = ["builtin_env_logger"]
7373
# See `crate::util::logger` for more details.
7474
builtin_env_logger = ["dep:env_logger"]
7575

76+
# Enable this feature if you want to use nightly features and compiler
77+
nightly = []
78+
7679
# This feature is only supported on x86-64 for now
7780
# It's manually added to CI scripts
7881
perf_counter = ["dep:pfm"]

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// to me - considering it will break our API and all the efforts for all the developers to make the change, it may
88
// not worth it.
99
#![allow(clippy::upper_case_acronyms)]
10+
// Use the `{likely, unlikely}` provided by compiler when using nightly
11+
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
1012

1113
//! Memory Management ToolKit (MMTk) is a portable and high performance memory manager
1214
//! that includes various garbage collection algorithms and provides clean and efficient

src/util/rust_util/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,27 @@ pub const fn min_of_usize(a: usize, b: usize) -> usize {
1414
}
1515
}
1616

17-
#[rustversion::nightly]
17+
#[cfg(feature = "nightly")]
1818
pub use core::intrinsics::{likely, unlikely};
1919

2020
// likely() and unlikely() compiler hints in stable Rust
2121
// [1]: https://github.com/rust-lang/hashbrown/blob/a41bd76de0a53838725b997c6085e024c47a0455/src/raw/mod.rs#L48-L70
2222
// [2]: https://users.rust-lang.org/t/compiler-hint-for-unlikely-likely-for-if-branches/62102/3
23-
#[rustversion::not(nightly)]
23+
#[cfg(not(feature = "nightly"))]
24+
#[inline]
2425
#[cold]
2526
fn cold() {}
2627

27-
#[rustversion::not(nightly)]
28+
#[cfg(not(feature = "nightly"))]
29+
#[inline]
2830
pub fn likely(b: bool) -> bool {
2931
if !b {
3032
cold();
3133
}
3234
b
3335
}
34-
#[rustversion::not(nightly)]
36+
#[cfg(not(feature = "nightly"))]
37+
#[inline]
3538
pub fn unlikely(b: bool) -> bool {
3639
if b {
3740
cold();

0 commit comments

Comments
 (0)