Skip to content

Commit d23ef33

Browse files
committed
Fix nightly build and add inline attributes to {un,}likely
1 parent 3830168 commit d23ef33

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ harness = false
6868
[features]
6969
default = []
7070

71+
# Enable this feature if you want to use nightly features and compiler
72+
nightly = []
73+
7174
# This feature is only supported on x86-64 for now
7275
# It's manually added to CI scripts
7376
perf_counter = ["pfm"]

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// not worth it.
99
#![allow(clippy::upper_case_acronyms)]
1010

11+
// Use the `{likely, unlikely}` provided by compiler when using nightly
12+
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
13+
1114
//! Memory Management ToolKit (MMTk) is a portable and high performance memory manager
1215
//! that includes various garbage collection algorithms and provides clean and efficient
1316
//! interfaces to cooperate with language implementations. MMTk features highly modular

src/util/rust_util/mod.rs

+7-4
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)