Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm authored and gitbot committed Feb 20, 2025
1 parent 953a621 commit b4d438a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
12 changes: 5 additions & 7 deletions core/src/intrinsics/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,8 @@ impl const CarryingMulAdd for i128 {
#[const_trait]
#[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
pub trait DisjointBitOr: Copy + 'static {
/// This is always just `assume((self & other) == 0); self | other`.
///
/// It's essential that the assume is there so that this is sufficient to
/// specify the UB for MIRI, rather than it needing to re-implement it.
///
/// # Safety
/// See [`super::disjoint_bitor`].
/// See [`super::disjoint_bitor`]; we just need the trait indirection to handle
/// different types since calling intrinsics with generics doesn't work.
unsafe fn disjoint_bitor(self, other: Self) -> Self;
}
macro_rules! zero {
Expand All @@ -135,8 +130,11 @@ macro_rules! impl_disjoint_bitor {
($($t:ident,)+) => {$(
#[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
impl const DisjointBitOr for $t {
#[cfg_attr(miri, track_caller)]
#[inline]
unsafe fn disjoint_bitor(self, other: Self) -> Self {
// Note that the assume here is required for UB detection in Miri!

// SAFETY: our precondition is that there are no bits in common,
// so this is just telling that to the backend.
unsafe { super::assume((self & other) == zero!($t)) };
Expand Down
3 changes: 2 additions & 1 deletion core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3261,7 +3261,8 @@ pub const fn three_way_compare<T: Copy>(_lhs: T, _rhss: T) -> crate::cmp::Orderi
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell MIRI
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
pub const unsafe fn disjoint_bitor<T: ~const fallback::DisjointBitOr>(a: T, b: T) -> T {
// SAFETY: same preconditions as this function.
unsafe { fallback::DisjointBitOr::disjoint_bitor(a, b) }
Expand Down
2 changes: 1 addition & 1 deletion core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ macro_rules! uint_impl {
///
/// # Safety
///
/// Requires that `(self | other) == 0`, otherwise it's immediate UB.
/// Requires that `(self & other) == 0`, otherwise it's immediate UB.
///
/// Equivalently, requires that `(self | other) == (self + other)`.
#[unstable(feature = "disjoint_bitor", issue = "135758")]
Expand Down

0 comments on commit b4d438a

Please sign in to comment.