Skip to content

Commit 1ef0803

Browse files
Rollup merge of rust-lang#152322 - Zalathar:core-intrinsics, r=fmease
Replace some `feature(core_intrinsics)` with stable hints I noticed that some compiler crates use `feature(core_intrinsics)` for optimization hints, when they could potentially be using stable `std::hint` functions instead. This PR replaces the occurrences in `rustc_arena` and `rustc_data_structures`.
2 parents 355bdb7 + 118372e commit 1ef0803

5 files changed

Lines changed: 16 additions & 14 deletions

File tree

compiler/rustc_arena/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![cfg_attr(test, feature(test))]
1414
#![deny(unsafe_op_in_unsafe_fn)]
1515
#![doc(test(no_crate_inject, attr(deny(warnings), allow(internal_features))))]
16-
#![feature(core_intrinsics)]
1716
#![feature(decl_macro)]
1817
#![feature(dropck_eyepatch)]
1918
#![feature(never_type)]
@@ -26,7 +25,7 @@ use std::cell::{Cell, RefCell};
2625
use std::marker::PhantomData;
2726
use std::mem::{self, MaybeUninit};
2827
use std::ptr::{self, NonNull};
29-
use std::{cmp, intrinsics, slice};
28+
use std::{cmp, hint, slice};
3029

3130
use smallvec::SmallVec;
3231

@@ -452,7 +451,7 @@ impl DroplessArena {
452451
let bytes = align_up(layout.size(), DROPLESS_ALIGNMENT);
453452

454453
// Tell LLVM that `end` is aligned to DROPLESS_ALIGNMENT.
455-
unsafe { intrinsics::assume(end == align_down(end, DROPLESS_ALIGNMENT)) };
454+
unsafe { hint::assert_unchecked(end == align_down(end, DROPLESS_ALIGNMENT)) };
456455

457456
if let Some(sub) = end.checked_sub(bytes) {
458457
let new_end = align_down(sub, layout.align());

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![allow(internal_features)]
1111
#![allow(rustc::default_hash_types)]
1212
#![allow(rustc::potential_query_instability)]
13+
#![cfg_attr(bootstrap, feature(cold_path))]
1314
#![deny(unsafe_op_in_unsafe_fn)]
1415
#![feature(allocator_api)]
1516
#![feature(ascii_char)]
@@ -19,7 +20,6 @@
1920
#![feature(cfg_select)]
2021
#![feature(const_default)]
2122
#![feature(const_trait_impl)]
22-
#![feature(core_intrinsics)]
2323
#![feature(dropck_eyepatch)]
2424
#![feature(extend_one)]
2525
#![feature(file_buffered)]

compiler/rustc_data_structures/src/profiling.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ use std::borrow::Borrow;
8585
use std::collections::hash_map::Entry;
8686
use std::error::Error;
8787
use std::fmt::Display;
88-
use std::intrinsics::unlikely;
8988
use std::path::Path;
9089
use std::sync::Arc;
9190
use std::sync::atomic::Ordering;
9291
use std::time::{Duration, Instant};
93-
use std::{fs, process};
92+
use std::{fs, hint, process};
9493

9594
pub use measureme::EventId;
9695
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
@@ -427,7 +426,8 @@ impl SelfProfilerRef {
427426
.unwrap()
428427
.increment_query_cache_hit_counters(QueryInvocationId(query_invocation_id.0));
429428
}
430-
if unlikely(profiler_ref.event_filter_mask.contains(EventFilter::QUERY_CACHE_HITS)) {
429+
if profiler_ref.event_filter_mask.contains(EventFilter::QUERY_CACHE_HITS) {
430+
hint::cold_path();
431431
profiler_ref.instant_query_event(
432432
|profiler| profiler.query_cache_hit_event_kind,
433433
query_invocation_id,
@@ -437,7 +437,8 @@ impl SelfProfilerRef {
437437

438438
// We check both kinds of query cache hit events at once, to reduce overhead in the
439439
// common case (with self-profile disabled).
440-
if unlikely(self.event_filter_mask.intersects(EventFilter::QUERY_CACHE_HIT_COMBINED)) {
440+
if self.event_filter_mask.intersects(EventFilter::QUERY_CACHE_HIT_COMBINED) {
441+
hint::cold_path();
441442
cold_call(self, query_invocation_id);
442443
}
443444
}

compiler/rustc_data_structures/src/sync/freeze.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::cell::UnsafeCell;
2-
use std::intrinsics::likely;
2+
use std::hint;
33
use std::marker::PhantomData;
44
use std::ops::{Deref, DerefMut};
55
use std::ptr::NonNull;
@@ -60,10 +60,11 @@ impl<T> FreezeLock<T> {
6060
/// Get the inner value if frozen.
6161
#[inline]
6262
pub fn get(&self) -> Option<&T> {
63-
if likely(self.frozen.load(Ordering::Acquire)) {
63+
if self.frozen.load(Ordering::Acquire) {
6464
// SAFETY: This is frozen so the data cannot be modified.
6565
unsafe { Some(&*self.data.get()) }
6666
} else {
67+
hint::cold_path();
6768
None
6869
}
6970
}

compiler/rustc_data_structures/src/sync/lock.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module implements a lock which only uses synchronization if `might_be_dyn_thread_safe` is true.
22
//! It implements `DynSend` and `DynSync` instead of the typical `Send` and `Sync` traits.
33
4-
use std::fmt;
4+
use std::{fmt, hint};
55

66
#[derive(Clone, Copy, PartialEq)]
77
pub enum Mode {
@@ -10,7 +10,6 @@ pub enum Mode {
1010
}
1111

1212
use std::cell::{Cell, UnsafeCell};
13-
use std::intrinsics::unlikely;
1413
use std::marker::PhantomData;
1514
use std::mem::ManuallyDrop;
1615
use std::ops::{Deref, DerefMut};
@@ -92,7 +91,8 @@ pub struct Lock<T> {
9291
impl<T> Lock<T> {
9392
#[inline(always)]
9493
pub fn new(inner: T) -> Self {
95-
let (mode, mode_union) = if unlikely(mode::might_be_dyn_thread_safe()) {
94+
let (mode, mode_union) = if mode::might_be_dyn_thread_safe() {
95+
hint::cold_path();
9696
// Create the lock with synchronization enabled using the `RawMutex` type.
9797
(Mode::Sync, ModeUnion { sync: ManuallyDrop::new(RawMutex::INIT) })
9898
} else {
@@ -150,7 +150,8 @@ impl<T> Lock<T> {
150150
unsafe {
151151
match mode {
152152
Mode::NoSync => {
153-
if unlikely(self.mode_union.no_sync.replace(LOCKED) == LOCKED) {
153+
if self.mode_union.no_sync.replace(LOCKED) == LOCKED {
154+
hint::cold_path();
154155
lock_held()
155156
}
156157
}

0 commit comments

Comments
 (0)