mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
get rid of the internal unlikely macro
This commit is contained in:
parent
3854e16fa2
commit
16b9bb744d
@ -986,7 +986,10 @@ pub const unsafe fn assume(b: bool) {
|
|||||||
/// any safety invariants.
|
/// any safety invariants.
|
||||||
///
|
///
|
||||||
/// This intrinsic does not have a stable counterpart.
|
/// This intrinsic does not have a stable counterpart.
|
||||||
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_likely", issue = "none"))]
|
#[cfg_attr(
|
||||||
|
bootstrap,
|
||||||
|
rustc_const_stable(feature = "const_likely", since = "CURRENT_RUSTC_VERSION")
|
||||||
|
)]
|
||||||
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
|
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
|
||||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||||
#[rustc_intrinsic]
|
#[rustc_intrinsic]
|
||||||
@ -1007,7 +1010,10 @@ pub const fn likely(b: bool) -> bool {
|
|||||||
/// any safety invariants.
|
/// any safety invariants.
|
||||||
///
|
///
|
||||||
/// This intrinsic does not have a stable counterpart.
|
/// This intrinsic does not have a stable counterpart.
|
||||||
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_likely", issue = "none"))]
|
#[cfg_attr(
|
||||||
|
bootstrap,
|
||||||
|
rustc_const_stable(feature = "const_likely", since = "CURRENT_RUSTC_VERSION")
|
||||||
|
)]
|
||||||
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
|
#[cfg_attr(not(bootstrap), rustc_const_stable_indirect)]
|
||||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||||
#[rustc_intrinsic]
|
#[rustc_intrinsic]
|
||||||
|
@ -449,7 +449,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_add(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_add(self, rhs: Self) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_add(rhs);
|
let (a, b) = self.overflowing_add(rhs);
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict integer addition. Computes `self + rhs`, panicking
|
/// Strict integer addition. Computes `self + rhs`, panicking
|
||||||
@ -545,7 +545,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_add_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
|
pub const fn checked_add_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_add_unsigned(rhs);
|
let (a, b) = self.overflowing_add_unsigned(rhs);
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict addition with an unsigned integer. Computes `self + rhs`,
|
/// Strict addition with an unsigned integer. Computes `self + rhs`,
|
||||||
@ -601,7 +601,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_sub(rhs);
|
let (a, b) = self.overflowing_sub(rhs);
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict integer subtraction. Computes `self - rhs`, panicking if
|
/// Strict integer subtraction. Computes `self - rhs`, panicking if
|
||||||
@ -697,7 +697,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_sub_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
|
pub const fn checked_sub_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_sub_unsigned(rhs);
|
let (a, b) = self.overflowing_sub_unsigned(rhs);
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict subtraction with an unsigned integer. Computes `self - rhs`,
|
/// Strict subtraction with an unsigned integer. Computes `self - rhs`,
|
||||||
@ -753,7 +753,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_mul(rhs);
|
let (a, b) = self.overflowing_mul(rhs);
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict integer multiplication. Computes `self * rhs`, panicking if
|
/// Strict integer multiplication. Computes `self * rhs`, panicking if
|
||||||
@ -849,7 +849,7 @@ macro_rules! int_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
|
||||||
if unlikely!(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
|
if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// SAFETY: div by zero and by INT_MIN have been checked above
|
// SAFETY: div by zero and by INT_MIN have been checked above
|
||||||
@ -924,7 +924,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
|
||||||
// Using `&` helps LLVM see that it is the same check made in division.
|
// Using `&` helps LLVM see that it is the same check made in division.
|
||||||
if unlikely!(rhs == 0 || ((self == Self::MIN) & (rhs == -1))) {
|
if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) & (rhs == -1))) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.div_euclid(rhs))
|
Some(self.div_euclid(rhs))
|
||||||
@ -997,7 +997,7 @@ macro_rules! int_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
|
||||||
if unlikely!(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
|
if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// SAFETY: div by zero and by INT_MIN have been checked above
|
// SAFETY: div by zero and by INT_MIN have been checked above
|
||||||
@ -1071,7 +1071,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
|
||||||
// Using `&` helps LLVM see that it is the same check made in division.
|
// Using `&` helps LLVM see that it is the same check made in division.
|
||||||
if unlikely!(rhs == 0 || ((self == Self::MIN) & (rhs == -1))) {
|
if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) & (rhs == -1))) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.rem_euclid(rhs))
|
Some(self.rem_euclid(rhs))
|
||||||
@ -1142,7 +1142,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_neg(self) -> Option<Self> {
|
pub const fn checked_neg(self) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_neg();
|
let (a, b) = self.overflowing_neg();
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unchecked negation. Computes `-self`, assuming overflow cannot occur.
|
/// Unchecked negation. Computes `-self`, assuming overflow cannot occur.
|
||||||
@ -2564,7 +2564,7 @@ macro_rules! int_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
|
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
|
||||||
// Using `&` helps LLVM see that it is the same check made in division.
|
// Using `&` helps LLVM see that it is the same check made in division.
|
||||||
if unlikely!((self == Self::MIN) & (rhs == -1)) {
|
if intrinsics::unlikely((self == Self::MIN) & (rhs == -1)) {
|
||||||
(self, true)
|
(self, true)
|
||||||
} else {
|
} else {
|
||||||
(self / rhs, false)
|
(self / rhs, false)
|
||||||
@ -2595,7 +2595,7 @@ macro_rules! int_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
|
pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
|
||||||
// Using `&` helps LLVM see that it is the same check made in division.
|
// Using `&` helps LLVM see that it is the same check made in division.
|
||||||
if unlikely!((self == Self::MIN) & (rhs == -1)) {
|
if intrinsics::unlikely((self == Self::MIN) & (rhs == -1)) {
|
||||||
(self, true)
|
(self, true)
|
||||||
} else {
|
} else {
|
||||||
(self.div_euclid(rhs), false)
|
(self.div_euclid(rhs), false)
|
||||||
@ -2625,7 +2625,7 @@ macro_rules! int_impl {
|
|||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
|
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
|
||||||
if unlikely!(rhs == -1) {
|
if intrinsics::unlikely(rhs == -1) {
|
||||||
(0, self == Self::MIN)
|
(0, self == Self::MIN)
|
||||||
} else {
|
} else {
|
||||||
(self % rhs, false)
|
(self % rhs, false)
|
||||||
@ -2657,7 +2657,7 @@ macro_rules! int_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
|
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
|
||||||
if unlikely!(rhs == -1) {
|
if intrinsics::unlikely(rhs == -1) {
|
||||||
(0, self == Self::MIN)
|
(0, self == Self::MIN)
|
||||||
} else {
|
} else {
|
||||||
(self.rem_euclid(rhs), false)
|
(self.rem_euclid(rhs), false)
|
||||||
@ -2686,7 +2686,7 @@ macro_rules! int_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[allow(unused_attributes)]
|
#[allow(unused_attributes)]
|
||||||
pub const fn overflowing_neg(self) -> (Self, bool) {
|
pub const fn overflowing_neg(self) -> (Self, bool) {
|
||||||
if unlikely!(self == Self::MIN) {
|
if intrinsics::unlikely(self == Self::MIN) {
|
||||||
(Self::MIN, true)
|
(Self::MIN, true)
|
||||||
} else {
|
} else {
|
||||||
(-self, false)
|
(-self, false)
|
||||||
|
@ -16,13 +16,6 @@ macro_rules! try_opt {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(bootstrap, allow_internal_unstable(const_likely))]
|
|
||||||
macro_rules! unlikely {
|
|
||||||
($e: expr) => {
|
|
||||||
intrinsics::unlikely($e)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use this when the generated code should differ between signed and unsigned types.
|
// Use this when the generated code should differ between signed and unsigned types.
|
||||||
macro_rules! sign_dependent_expr {
|
macro_rules! sign_dependent_expr {
|
||||||
(signed ? if signed { $signed_case:expr } if unsigned { $unsigned_case:expr } ) => {
|
(signed ? if signed { $signed_case:expr } if unsigned { $unsigned_case:expr } ) => {
|
||||||
|
@ -491,7 +491,7 @@ macro_rules! uint_impl {
|
|||||||
// Per <https://github.com/rust-lang/rust/pull/124114#issuecomment-2066173305>,
|
// Per <https://github.com/rust-lang/rust/pull/124114#issuecomment-2066173305>,
|
||||||
// LLVM is happy to re-form the intrinsic later if useful.
|
// LLVM is happy to re-form the intrinsic later if useful.
|
||||||
|
|
||||||
if unlikely!(intrinsics::add_with_overflow(self, rhs).1) {
|
if intrinsics::unlikely(intrinsics::add_with_overflow(self, rhs).1) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// SAFETY: Just checked it doesn't overflow
|
// SAFETY: Just checked it doesn't overflow
|
||||||
@ -593,7 +593,7 @@ macro_rules! uint_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_add_signed(self, rhs: $SignedT) -> Option<Self> {
|
pub const fn checked_add_signed(self, rhs: $SignedT) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_add_signed(rhs);
|
let (a, b) = self.overflowing_add_signed(rhs);
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict addition with a signed integer. Computes `self + rhs`,
|
/// Strict addition with a signed integer. Computes `self + rhs`,
|
||||||
@ -845,7 +845,7 @@ macro_rules! uint_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_mul(rhs);
|
let (a, b) = self.overflowing_mul(rhs);
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict integer multiplication. Computes `self * rhs`, panicking if
|
/// Strict integer multiplication. Computes `self * rhs`, panicking if
|
||||||
@ -940,7 +940,7 @@ macro_rules! uint_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_div(self, rhs: Self) -> Option<Self> {
|
||||||
if unlikely!(rhs == 0) {
|
if intrinsics::unlikely(rhs == 0) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// SAFETY: div by zero has been checked above and unsigned types have no other
|
// SAFETY: div by zero has been checked above and unsigned types have no other
|
||||||
@ -1001,7 +1001,7 @@ macro_rules! uint_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
|
||||||
if unlikely!(rhs == 0) {
|
if intrinsics::unlikely(rhs == 0) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.div_euclid(rhs))
|
Some(self.div_euclid(rhs))
|
||||||
@ -1061,7 +1061,7 @@ macro_rules! uint_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
|
||||||
if unlikely!(rhs == 0) {
|
if intrinsics::unlikely(rhs == 0) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
// SAFETY: div by zero has been checked above and unsigned types have no other
|
// SAFETY: div by zero has been checked above and unsigned types have no other
|
||||||
@ -1123,7 +1123,7 @@ macro_rules! uint_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
|
pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
|
||||||
if unlikely!(rhs == 0) {
|
if intrinsics::unlikely(rhs == 0) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.rem_euclid(rhs))
|
Some(self.rem_euclid(rhs))
|
||||||
@ -1362,7 +1362,7 @@ macro_rules! uint_impl {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub const fn checked_neg(self) -> Option<Self> {
|
pub const fn checked_neg(self) -> Option<Self> {
|
||||||
let (a, b) = self.overflowing_neg();
|
let (a, b) = self.overflowing_neg();
|
||||||
if unlikely!(b) { None } else { Some(a) }
|
if intrinsics::unlikely(b) { None } else { Some(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Strict negation. Computes `-self`, panicking unless `self ==
|
/// Strict negation. Computes `-self`, panicking unless `self ==
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
#![cfg_attr(bootstrap, feature(const_likely))]
|
|
||||||
#![cfg_attr(bootstrap, feature(strict_provenance))]
|
#![cfg_attr(bootstrap, feature(strict_provenance))]
|
||||||
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
|
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
|
||||||
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
|
#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
|
||||||
|
Loading…
Reference in New Issue
Block a user