Move the rustc_no_mir_inline down a level

This commit is contained in:
Scott McMurray 2025-12-23 22:42:03 -08:00
parent 5932078c79
commit c48df5dcf1
3 changed files with 72 additions and 53 deletions

View file

@ -13,11 +13,7 @@ impl<T, U> const PartialEq<[U]> for [T]
where
T: [const] PartialEq<U>,
{
// It's not worth trying to inline the loops underneath here *in MIR*,
// and preventing it encourages more useful inlining upstream,
// such as in `<str as PartialEq>::eq`.
// The codegen backend can still inline it later if needed.
#[rustc_no_mir_inline]
#[inline]
fn eq(&self, other: &[U]) -> bool {
SlicePartialEq::equal(self, other)
}
@ -108,6 +104,11 @@ impl<A, B> const SlicePartialEq<B> for [A]
where
A: [const] PartialEq<B>,
{
// It's not worth trying to inline the loops underneath here *in MIR*,
// and preventing it encourages more useful inlining upstream,
// such as in `<str as PartialEq>::eq`.
// The codegen backend can still inline it later if needed.
#[rustc_no_mir_inline]
default fn equal(&self, other: &[B]) -> bool {
if self.len() != other.len() {
return false;
@ -137,6 +138,16 @@ impl<A, B> const SlicePartialEq<B> for [A]
where
A: [const] BytewiseEq<B>,
{
// This is usually a pretty good backend inlining candidate because the
// intrinsic tends to just be `memcmp`. However, as of 2025-12 letting
// MIR inline this makes reuse worse because it means that, for example,
// `String::eq` doesn't inline, whereas by keeping this from inling all
// the wrappers until the call to this disappear. If the heuristics have
// changed and this is no longer fruitful, though, please do remove it.
// In the mean time, it's fine to not inline it in MIR because the backend
// will still inline it if it things it's important to do so.
#[rustc_no_mir_inline]
#[inline]
fn equal(&self, other: &[B]) -> bool {
if self.len() != other.len() {
return false;

View file

@ -92,62 +92,66 @@
scope 24 (inlined core::str::<impl str>::as_bytes) {
}
scope 25 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
scope 26 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
}
}
}
}
}
scope 26 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
scope 27 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
let mut _39: &std::string::String;
let mut _40: &str;
scope 27 (inlined <String as PartialEq<str>>::eq) {
scope 28 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
scope 28 (inlined <String as PartialEq<str>>::eq) {
scope 29 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
let _41: &str;
scope 29 (inlined String::as_str) {
scope 30 (inlined String::as_str) {
let _42: &[u8];
scope 30 (inlined Vec::<u8>::as_slice) {
scope 31 (inlined Vec::<u8>::as_slice) {
let _43: *const [u8];
let mut _44: *const u8;
let mut _45: usize;
scope 31 (inlined Vec::<u8>::as_ptr) {
scope 32 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
scope 33 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
scope 34 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
scope 32 (inlined Vec::<u8>::as_ptr) {
scope 33 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
scope 34 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
scope 35 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
let mut _46: std::ptr::NonNull<u8>;
scope 35 (inlined Unique::<u8>::cast::<u8>) {
scope 36 (inlined NonNull::<u8>::cast::<u8>) {
scope 37 (inlined NonNull::<u8>::as_ptr) {
scope 36 (inlined Unique::<u8>::cast::<u8>) {
scope 37 (inlined NonNull::<u8>::cast::<u8>) {
scope 38 (inlined NonNull::<u8>::as_ptr) {
}
}
}
scope 38 (inlined Unique::<u8>::as_non_null_ptr) {
scope 39 (inlined Unique::<u8>::as_non_null_ptr) {
}
}
scope 39 (inlined NonNull::<u8>::as_ptr) {
scope 40 (inlined NonNull::<u8>::as_ptr) {
}
}
}
}
}
scope 40 (inlined from_utf8_unchecked) {
scope 41 (inlined from_utf8_unchecked) {
}
}
scope 41 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
scope 42 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
}
}
scope 42 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
scope 43 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
scope 43 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
scope 44 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
}
}
scope 44 (inlined core::str::traits::<impl PartialEq for str>::eq) {
scope 45 (inlined core::str::traits::<impl PartialEq for str>::eq) {
let mut _47: &&[u8];
let _48: &[u8];
let mut _49: &&[u8];
let _50: &[u8];
scope 45 (inlined core::str::<impl str>::as_bytes) {
}
scope 46 (inlined core::str::<impl str>::as_bytes) {
}
scope 47 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
scope 47 (inlined core::str::<impl str>::as_bytes) {
}
scope 48 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
scope 49 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
}
}
}
}
@ -214,7 +218,7 @@
StorageLive(_38);
_36 = copy _29 as &[u8] (Transmute);
_38 = copy _28 as &[u8] (Transmute);
_7 = <[u8] as PartialEq>::eq(move _36, move _38) -> [return: bb19, unwind unreachable];
_7 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _36, move _38) -> [return: bb19, unwind unreachable];
}
bb5: {
@ -270,7 +274,7 @@
StorageLive(_50);
_48 = copy _41 as &[u8] (Transmute);
_50 = copy _40 as &[u8] (Transmute);
_14 = <[u8] as PartialEq>::eq(move _48, move _50) -> [return: bb20, unwind unreachable];
_14 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _48, move _50) -> [return: bb20, unwind unreachable];
}
bb7: {

View file

@ -92,62 +92,66 @@
scope 24 (inlined core::str::<impl str>::as_bytes) {
}
scope 25 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
scope 26 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
}
}
}
}
}
scope 26 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
scope 27 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
let mut _39: &std::string::String;
let mut _40: &str;
scope 27 (inlined <String as PartialEq<str>>::eq) {
scope 28 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
scope 28 (inlined <String as PartialEq<str>>::eq) {
scope 29 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
let _41: &str;
scope 29 (inlined String::as_str) {
scope 30 (inlined String::as_str) {
let _42: &[u8];
scope 30 (inlined Vec::<u8>::as_slice) {
scope 31 (inlined Vec::<u8>::as_slice) {
let _43: *const [u8];
let mut _44: *const u8;
let mut _45: usize;
scope 31 (inlined Vec::<u8>::as_ptr) {
scope 32 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
scope 33 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
scope 34 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
scope 32 (inlined Vec::<u8>::as_ptr) {
scope 33 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
scope 34 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
scope 35 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
let mut _46: std::ptr::NonNull<u8>;
scope 35 (inlined Unique::<u8>::cast::<u8>) {
scope 36 (inlined NonNull::<u8>::cast::<u8>) {
scope 37 (inlined NonNull::<u8>::as_ptr) {
scope 36 (inlined Unique::<u8>::cast::<u8>) {
scope 37 (inlined NonNull::<u8>::cast::<u8>) {
scope 38 (inlined NonNull::<u8>::as_ptr) {
}
}
}
scope 38 (inlined Unique::<u8>::as_non_null_ptr) {
scope 39 (inlined Unique::<u8>::as_non_null_ptr) {
}
}
scope 39 (inlined NonNull::<u8>::as_ptr) {
scope 40 (inlined NonNull::<u8>::as_ptr) {
}
}
}
}
}
scope 40 (inlined from_utf8_unchecked) {
scope 41 (inlined from_utf8_unchecked) {
}
}
scope 41 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
scope 42 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
}
}
scope 42 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
scope 43 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
scope 43 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
scope 44 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
}
}
scope 44 (inlined core::str::traits::<impl PartialEq for str>::eq) {
scope 45 (inlined core::str::traits::<impl PartialEq for str>::eq) {
let mut _47: &&[u8];
let _48: &[u8];
let mut _49: &&[u8];
let _50: &[u8];
scope 45 (inlined core::str::<impl str>::as_bytes) {
}
scope 46 (inlined core::str::<impl str>::as_bytes) {
}
scope 47 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
scope 47 (inlined core::str::<impl str>::as_bytes) {
}
scope 48 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
scope 49 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
}
}
}
}
@ -214,7 +218,7 @@
StorageLive(_38);
_36 = copy _29 as &[u8] (Transmute);
_38 = copy _28 as &[u8] (Transmute);
_7 = <[u8] as PartialEq>::eq(move _36, move _38) -> [return: bb23, unwind: bb22];
_7 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _36, move _38) -> [return: bb23, unwind: bb22];
}
bb5: {
@ -270,7 +274,7 @@
StorageLive(_50);
_48 = copy _41 as &[u8] (Transmute);
_50 = copy _40 as &[u8] (Transmute);
_14 = <[u8] as PartialEq>::eq(move _48, move _50) -> [return: bb24, unwind: bb22];
_14 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _48, move _50) -> [return: bb24, unwind: bb22];
}
bb7: {