Skip to content

Commit f9695bf

Browse files
committed
Move the rustc_no_mir_inline down a level
1 parent 04938dd commit f9695bf

3 files changed

Lines changed: 72 additions & 53 deletions

File tree

library/core/src/slice/cmp.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ impl<T, U> const PartialEq<[U]> for [T]
1313
where
1414
T: [const] PartialEq<U>,
1515
{
16-
// It's not worth trying to inline the loops underneath here *in MIR*,
17-
// and preventing it encourages more useful inlining upstream,
18-
// such as in `<str as PartialEq>::eq`.
19-
// The codegen backend can still inline it later if needed.
20-
#[rustc_no_mir_inline]
16+
#[inline]
2117
fn eq(&self, other: &[U]) -> bool {
2218
SlicePartialEq::equal(self, other)
2319
}
@@ -108,6 +104,11 @@ impl<A, B> const SlicePartialEq<B> for [A]
108104
where
109105
A: [const] PartialEq<B>,
110106
{
107+
// It's not worth trying to inline the loops underneath here *in MIR*,
108+
// and preventing it encourages more useful inlining upstream,
109+
// such as in `<str as PartialEq>::eq`.
110+
// The codegen backend can still inline it later if needed.
111+
#[rustc_no_mir_inline]
111112
default fn equal(&self, other: &[B]) -> bool {
112113
if self.len() != other.len() {
113114
return false;
@@ -137,6 +138,16 @@ impl<A, B> const SlicePartialEq<B> for [A]
137138
where
138139
A: [const] BytewiseEq<B>,
139140
{
141+
// This is usually a pretty good backend inlining candidate because the
142+
// intrinsic tends to just be `memcmp`. However, as of 2025-12 letting
143+
// MIR inline this makes reuse worse because it means that, for example,
144+
// `String::eq` doesn't inline, whereas by keeping this from inling all
145+
// the wrappers until the call to this disappear. If the heuristics have
146+
// changed and this is no longer fruitful, though, please do remove it.
147+
// In the mean time, it's fine to not inline it in MIR because the backend
148+
// will still inline it if it things it's important to do so.
149+
#[rustc_no_mir_inline]
150+
#[inline]
140151
fn equal(&self, other: &[B]) -> bool {
141152
if self.len() != other.len() {
142153
return false;

tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-abort.diff

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,62 +92,66 @@
9292
scope 24 (inlined core::str::<impl str>::as_bytes) {
9393
}
9494
scope 25 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
95+
scope 26 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
96+
}
9597
}
9698
}
9799
}
98100
}
99-
scope 26 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
101+
scope 27 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
100102
let mut _39: &std::string::String;
101103
let mut _40: &str;
102-
scope 27 (inlined <String as PartialEq<str>>::eq) {
103-
scope 28 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
104+
scope 28 (inlined <String as PartialEq<str>>::eq) {
105+
scope 29 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
104106
let _41: &str;
105-
scope 29 (inlined String::as_str) {
107+
scope 30 (inlined String::as_str) {
106108
let _42: &[u8];
107-
scope 30 (inlined Vec::<u8>::as_slice) {
109+
scope 31 (inlined Vec::<u8>::as_slice) {
108110
let _43: *const [u8];
109111
let mut _44: *const u8;
110112
let mut _45: usize;
111-
scope 31 (inlined Vec::<u8>::as_ptr) {
112-
scope 32 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
113-
scope 33 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
114-
scope 34 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
113+
scope 32 (inlined Vec::<u8>::as_ptr) {
114+
scope 33 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
115+
scope 34 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
116+
scope 35 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
115117
let mut _46: std::ptr::NonNull<u8>;
116-
scope 35 (inlined Unique::<u8>::cast::<u8>) {
117-
scope 36 (inlined NonNull::<u8>::cast::<u8>) {
118-
scope 37 (inlined NonNull::<u8>::as_ptr) {
118+
scope 36 (inlined Unique::<u8>::cast::<u8>) {
119+
scope 37 (inlined NonNull::<u8>::cast::<u8>) {
120+
scope 38 (inlined NonNull::<u8>::as_ptr) {
119121
}
120122
}
121123
}
122-
scope 38 (inlined Unique::<u8>::as_non_null_ptr) {
124+
scope 39 (inlined Unique::<u8>::as_non_null_ptr) {
123125
}
124126
}
125-
scope 39 (inlined NonNull::<u8>::as_ptr) {
127+
scope 40 (inlined NonNull::<u8>::as_ptr) {
126128
}
127129
}
128130
}
129131
}
130132
}
131-
scope 40 (inlined from_utf8_unchecked) {
133+
scope 41 (inlined from_utf8_unchecked) {
132134
}
133135
}
134-
scope 41 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
136+
scope 42 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
135137
}
136138
}
137-
scope 42 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
138-
scope 43 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
139+
scope 43 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
140+
scope 44 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
139141
}
140142
}
141-
scope 44 (inlined core::str::traits::<impl PartialEq for str>::eq) {
143+
scope 45 (inlined core::str::traits::<impl PartialEq for str>::eq) {
142144
let mut _47: &&[u8];
143145
let _48: &[u8];
144146
let mut _49: &&[u8];
145147
let _50: &[u8];
146-
scope 45 (inlined core::str::<impl str>::as_bytes) {
147-
}
148148
scope 46 (inlined core::str::<impl str>::as_bytes) {
149149
}
150-
scope 47 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
150+
scope 47 (inlined core::str::<impl str>::as_bytes) {
151+
}
152+
scope 48 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
153+
scope 49 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
154+
}
151155
}
152156
}
153157
}
@@ -214,7 +218,7 @@
214218
StorageLive(_38);
215219
_36 = copy _29 as &[u8] (Transmute);
216220
_38 = copy _28 as &[u8] (Transmute);
217-
_7 = <[u8] as PartialEq>::eq(move _36, move _38) -> [return: bb19, unwind unreachable];
221+
_7 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _36, move _38) -> [return: bb19, unwind unreachable];
218222
}
219223

220224
bb5: {
@@ -270,7 +274,7 @@
270274
StorageLive(_50);
271275
_48 = copy _41 as &[u8] (Transmute);
272276
_50 = copy _40 as &[u8] (Transmute);
273-
_14 = <[u8] as PartialEq>::eq(move _48, move _50) -> [return: bb20, unwind unreachable];
277+
_14 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _48, move _50) -> [return: bb20, unwind unreachable];
274278
}
275279

276280
bb7: {

tests/mir-opt/jump_threading.chained_conditions.JumpThreading.panic-unwind.diff

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,62 +92,66 @@
9292
scope 24 (inlined core::str::<impl str>::as_bytes) {
9393
}
9494
scope 25 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
95+
scope 26 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
96+
}
9597
}
9698
}
9799
}
98100
}
99-
scope 26 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
101+
scope 27 (inlined std::cmp::impls::<impl PartialEq<&str> for &String>::eq) {
100102
let mut _39: &std::string::String;
101103
let mut _40: &str;
102-
scope 27 (inlined <String as PartialEq<str>>::eq) {
103-
scope 28 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
104+
scope 28 (inlined <String as PartialEq<str>>::eq) {
105+
scope 29 (inlined #[track_caller] <String as Index<RangeFull>>::index) {
104106
let _41: &str;
105-
scope 29 (inlined String::as_str) {
107+
scope 30 (inlined String::as_str) {
106108
let _42: &[u8];
107-
scope 30 (inlined Vec::<u8>::as_slice) {
109+
scope 31 (inlined Vec::<u8>::as_slice) {
108110
let _43: *const [u8];
109111
let mut _44: *const u8;
110112
let mut _45: usize;
111-
scope 31 (inlined Vec::<u8>::as_ptr) {
112-
scope 32 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
113-
scope 33 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
114-
scope 34 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
113+
scope 32 (inlined Vec::<u8>::as_ptr) {
114+
scope 33 (inlined alloc::raw_vec::RawVec::<u8>::ptr) {
115+
scope 34 (inlined alloc::raw_vec::RawVecInner::ptr::<u8>) {
116+
scope 35 (inlined alloc::raw_vec::RawVecInner::non_null::<u8>) {
115117
let mut _46: std::ptr::NonNull<u8>;
116-
scope 35 (inlined Unique::<u8>::cast::<u8>) {
117-
scope 36 (inlined NonNull::<u8>::cast::<u8>) {
118-
scope 37 (inlined NonNull::<u8>::as_ptr) {
118+
scope 36 (inlined Unique::<u8>::cast::<u8>) {
119+
scope 37 (inlined NonNull::<u8>::cast::<u8>) {
120+
scope 38 (inlined NonNull::<u8>::as_ptr) {
119121
}
120122
}
121123
}
122-
scope 38 (inlined Unique::<u8>::as_non_null_ptr) {
124+
scope 39 (inlined Unique::<u8>::as_non_null_ptr) {
123125
}
124126
}
125-
scope 39 (inlined NonNull::<u8>::as_ptr) {
127+
scope 40 (inlined NonNull::<u8>::as_ptr) {
126128
}
127129
}
128130
}
129131
}
130132
}
131-
scope 40 (inlined from_utf8_unchecked) {
133+
scope 41 (inlined from_utf8_unchecked) {
132134
}
133135
}
134-
scope 41 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
136+
scope 42 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
135137
}
136138
}
137-
scope 42 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
138-
scope 43 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
139+
scope 43 (inlined #[track_caller] core::str::traits::<impl Index<RangeFull> for str>::index) {
140+
scope 44 (inlined #[track_caller] core::str::traits::<impl SliceIndex<str> for RangeFull>::index) {
139141
}
140142
}
141-
scope 44 (inlined core::str::traits::<impl PartialEq for str>::eq) {
143+
scope 45 (inlined core::str::traits::<impl PartialEq for str>::eq) {
142144
let mut _47: &&[u8];
143145
let _48: &[u8];
144146
let mut _49: &&[u8];
145147
let _50: &[u8];
146-
scope 45 (inlined core::str::<impl str>::as_bytes) {
147-
}
148148
scope 46 (inlined core::str::<impl str>::as_bytes) {
149149
}
150-
scope 47 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
150+
scope 47 (inlined core::str::<impl str>::as_bytes) {
151+
}
152+
scope 48 (inlined std::cmp::impls::<impl PartialEq for &[u8]>::eq) {
153+
scope 49 (inlined core::slice::cmp::<impl PartialEq for [u8]>::eq) {
154+
}
151155
}
152156
}
153157
}
@@ -214,7 +218,7 @@
214218
StorageLive(_38);
215219
_36 = copy _29 as &[u8] (Transmute);
216220
_38 = copy _28 as &[u8] (Transmute);
217-
_7 = <[u8] as PartialEq>::eq(move _36, move _38) -> [return: bb23, unwind: bb22];
221+
_7 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _36, move _38) -> [return: bb23, unwind: bb22];
218222
}
219223

220224
bb5: {
@@ -270,7 +274,7 @@
270274
StorageLive(_50);
271275
_48 = copy _41 as &[u8] (Transmute);
272276
_50 = copy _40 as &[u8] (Transmute);
273-
_14 = <[u8] as PartialEq>::eq(move _48, move _50) -> [return: bb24, unwind: bb22];
277+
_14 = <[u8] as core::slice::cmp::SlicePartialEq<u8>>::equal(move _48, move _50) -> [return: bb24, unwind: bb22];
274278
}
275279

276280
bb7: {

0 commit comments

Comments
 (0)