diff options
| author | The 8472 <git@infinite-source.de> | 2024-08-13 23:54:54 +0200 |
|---|---|---|
| committer | The 8472 <git@infinite-source.de> | 2024-08-14 20:50:04 +0200 |
| commit | 6d8f0bd930dc0ab9c72fc89583e74500a665e2ba (patch) | |
| tree | 662ba025725a0ef377a7e22388fb8527f2311e03 /library/std | |
| parent | 80eb5a8e910e5185d47cdefe3732d839c78a5e7e (diff) | |
| download | rust-6d8f0bd930dc0ab9c72fc89583e74500a665e2ba.tar.gz rust-6d8f0bd930dc0ab9c72fc89583e74500a665e2ba.zip | |
apply #[optimize(size)] to #[cold] ones and part of the panick machinery
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/lib.rs | 2 | ||||
| -rw-r--r-- | library/std/src/panicking.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sync/once_lock.rs | 1 |
3 files changed, 9 insertions, 2 deletions
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 93a74ef739b..cae84fa88ac 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -306,10 +306,12 @@ #![feature(negative_impls)] #![feature(never_type)] #![feature(no_sanitize)] +#![feature(optimize_attribute)] #![feature(prelude_import)] #![feature(rustc_attrs)] #![feature(rustdoc_internals)] #![feature(staged_api)] +#![feature(stmt_expr_attributes)] #![feature(thread_local)] #![feature(try_blocks)] #![feature(type_alias_impl_trait)] diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index e818b448270..b420445807f 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -231,6 +231,7 @@ where } /// The default panic handler. +#[optimize(size)] fn default_hook(info: &PanicHookInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. @@ -249,7 +250,8 @@ fn default_hook(info: &PanicHookInfo<'_>) { let thread = thread::try_current(); let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>"); - let write = |err: &mut dyn crate::io::Write| { + let write = #[optimize(size)] + |err: &mut dyn crate::io::Write| { // Use a lock to prevent mixed output in multithreading context. // Some platforms also require it when printing a backtrace, like `SymFromAddr` on Windows. let mut lock = backtrace::lock(); @@ -527,6 +529,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> // optimizer (in most cases this function is not inlined even as a normal, // non-cold function, though, as of the writing of this comment). #[cold] + #[optimize(size)] unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send + 'static> { // SAFETY: The whole unsafe block hinges on a correct implementation of // the panic handler `__rust_panic_cleanup`. As such we can only @@ -686,7 +689,7 @@ pub fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! { // lang item for CTFE panic support // never inline unless panic_immediate_abort to avoid code // bloat at the call sites as much as possible -#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold, optimize(size))] #[cfg_attr(feature = "panic_immediate_abort", inline)] #[track_caller] #[rustc_do_not_const_check] // hooked by const-eval @@ -756,6 +759,7 @@ fn payload_as_str(payload: &dyn Any) -> &str { /// Executes the primary logic for a panic, including checking for recursive /// panics, panic hooks, and finally dispatching to the panic runtime to either /// abort or unwind. +#[optimize(size)] fn rust_panic_with_hook( payload: &mut dyn PanicPayload, location: &Location<'_>, diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index 56cf877ddc6..a51e5c1b76b 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -498,6 +498,7 @@ impl<T> OnceLock<T> { } #[cold] + #[optimize(size)] fn initialize<F, E>(&self, f: F) -> Result<(), E> where F: FnOnce() -> Result<T, E>, |
