Skip to content

Commit 906c360

Browse files
committed
Adjust inlining attributes around panic_immediate_abort
1 parent b833ad5 commit 906c360

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

library/core/src/panicking.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ use crate::panic::{Location, PanicInfo};
3838
/// site as much as possible (so that `panic!()` has as low an impact
3939
/// on (e.g.) the inlining of other functions as possible), by moving
4040
/// the actual formatting into this shared place.
41-
#[cold]
4241
// If panic_immediate_abort, inline the abort call,
4342
// otherwise avoid inlining because of it is cold path.
44-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
43+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
4544
#[cfg_attr(feature = "panic_immediate_abort", inline)]
4645
#[track_caller]
4746
#[lang = "panic_fmt"] // needed for const-evaluated panics
@@ -67,8 +66,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
6766

6867
/// Like panic_fmt, but without unwinding and track_caller to reduce the impact on codesize.
6968
/// Also just works on `str`, as a `fmt::Arguments` needs more space to be passed.
70-
#[cold]
71-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
69+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
7270
#[cfg_attr(feature = "panic_immediate_abort", inline)]
7371
#[rustc_nounwind]
7472
pub fn panic_str_nounwind(msg: &'static str) -> ! {
@@ -96,10 +94,9 @@ pub fn panic_str_nounwind(msg: &'static str) -> ! {
9694
// above.
9795

9896
/// The underlying implementation of libcore's `panic!` macro when no formatting is used.
99-
#[cold]
10097
// never inline unless panic_immediate_abort to avoid code
10198
// bloat at the call sites as much as possible
102-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
99+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
103100
#[cfg_attr(feature = "panic_immediate_abort", inline)]
104101
#[track_caller]
105102
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
@@ -138,8 +135,8 @@ pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
138135
panic_fmt(format_args!("{}", *x));
139136
}
140137

141-
#[cold]
142-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
138+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
139+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
143140
#[track_caller]
144141
#[lang = "panic_bounds_check"] // needed by codegen for panic on OOB array/slice access
145142
fn panic_bounds_check(index: usize, len: usize) -> ! {
@@ -154,8 +151,8 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
154151
///
155152
/// This function is called directly by the codegen backend, and must not have
156153
/// any extra arguments (including those synthesized by track_caller).
157-
#[cold]
158-
#[inline(never)]
154+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
155+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
159156
#[lang = "panic_no_unwind"] // needed by codegen for panic in nounwind function
160157
#[rustc_nounwind]
161158
fn panic_no_unwind() -> ! {
@@ -185,7 +182,8 @@ pub enum AssertKind {
185182
}
186183

187184
/// Internal function for `assert_eq!` and `assert_ne!` macros
188-
#[cold]
185+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
186+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
189187
#[track_caller]
190188
#[doc(hidden)]
191189
pub fn assert_failed<T, U>(
@@ -202,7 +200,8 @@ where
202200
}
203201

204202
/// Internal function for `assert_match!`
205-
#[cold]
203+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
204+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
206205
#[track_caller]
207206
#[doc(hidden)]
208207
pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
@@ -221,6 +220,8 @@ pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
221220
}
222221

223222
/// Non-generic version of the above functions, to avoid code bloat.
223+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
224+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
224225
#[track_caller]
225226
fn assert_failed_inner(
226227
kind: AssertKind,

library/core/src/slice/index.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ where
3131
}
3232
}
3333

34-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
34+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
3535
#[cfg_attr(feature = "panic_immediate_abort", inline)]
36-
#[cold]
3736
#[track_caller]
3837
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
3938
const fn slice_start_index_len_fail(index: usize, len: usize) -> ! {
@@ -48,19 +47,20 @@ const fn slice_start_index_len_fail(index: usize, len: usize) -> ! {
4847
}
4948

5049
// FIXME const-hack
50+
#[inline]
5151
#[track_caller]
5252
fn slice_start_index_len_fail_rt(index: usize, len: usize) -> ! {
5353
panic!("range start index {index} out of range for slice of length {len}");
5454
}
5555

56+
#[inline]
5657
#[track_caller]
5758
const fn slice_start_index_len_fail_ct(_: usize, _: usize) -> ! {
5859
panic!("slice start index is out of range for slice");
5960
}
6061

61-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
62+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
6263
#[cfg_attr(feature = "panic_immediate_abort", inline)]
63-
#[cold]
6464
#[track_caller]
6565
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
6666
const fn slice_end_index_len_fail(index: usize, len: usize) -> ! {
@@ -71,19 +71,20 @@ const fn slice_end_index_len_fail(index: usize, len: usize) -> ! {
7171
}
7272

7373
// FIXME const-hack
74+
#[inline]
7475
#[track_caller]
7576
fn slice_end_index_len_fail_rt(index: usize, len: usize) -> ! {
7677
panic!("range end index {index} out of range for slice of length {len}");
7778
}
7879

80+
#[inline]
7981
#[track_caller]
8082
const fn slice_end_index_len_fail_ct(_: usize, _: usize) -> ! {
8183
panic!("slice end index is out of range for slice");
8284
}
8385

84-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
86+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
8587
#[cfg_attr(feature = "panic_immediate_abort", inline)]
86-
#[cold]
8788
#[track_caller]
8889
#[rustc_const_unstable(feature = "const_slice_index", issue = "none")]
8990
const fn slice_index_order_fail(index: usize, end: usize) -> ! {
@@ -92,27 +93,27 @@ const fn slice_index_order_fail(index: usize, end: usize) -> ! {
9293
}
9394

9495
// FIXME const-hack
96+
#[inline]
9597
#[track_caller]
9698
fn slice_index_order_fail_rt(index: usize, end: usize) -> ! {
9799
panic!("slice index starts at {index} but ends at {end}");
98100
}
99101

102+
#[inline]
100103
#[track_caller]
101104
const fn slice_index_order_fail_ct(_: usize, _: usize) -> ! {
102105
panic!("slice index start is larger than end");
103106
}
104107

105-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
108+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
106109
#[cfg_attr(feature = "panic_immediate_abort", inline)]
107-
#[cold]
108110
#[track_caller]
109111
const fn slice_start_index_overflow_fail() -> ! {
110112
panic!("attempted to index slice from after maximum usize");
111113
}
112114

113-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
115+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
114116
#[cfg_attr(feature = "panic_immediate_abort", inline)]
115-
#[cold]
116117
#[track_caller]
117118
const fn slice_end_index_overflow_fail() -> ! {
118119
panic!("attempted to index slice up to maximum usize");

library/std/src/panicking.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
594594
// lang item for CTFE panic support
595595
// never inline unless panic_immediate_abort to avoid code
596596
// bloat at the call sites as much as possible
597-
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
598-
#[cold]
597+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)]
598+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
599599
#[track_caller]
600600
#[rustc_do_not_const_check] // hooked by const-eval
601601
pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {

0 commit comments

Comments
 (0)