diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2024-11-23 13:19:17 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2024-11-28 13:43:05 -0500 |
| commit | 4a216a25d143e88eefac2655c1fce042571e1f6e (patch) | |
| tree | dd8b394804ef4dcee527cfa8e31f3b2ebded7612 /library | |
| parent | 39cb3386ddc6c71657418be28dbb3987eea4aa4b (diff) | |
| download | rust-4a216a25d143e88eefac2655c1fce042571e1f6e.tar.gz rust-4a216a25d143e88eefac2655c1fce042571e1f6e.zip | |
Share inline(never) generics across crates
This reduces code sizes and better respects programmer intent when marking inline(never). Previously such a marking was essentially ignored for generic functions, as we'd still inline them in remote crates.
Diffstat (limited to 'library')
| -rw-r--r-- | library/alloc/src/raw_vec.rs | 4 | ||||
| -rw-r--r-- | library/std/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/std/src/panicking.rs | 16 |
3 files changed, 20 insertions, 1 deletions
diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 85a9120c7e2..51b2a0570d9 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -757,7 +757,9 @@ impl<A: Allocator> RawVecInner<A> { } } -#[inline(never)] +// not marked inline(never) since we want optimizers to be able to observe the specifics of this +// function, see tests/codegen/vec-reserve-extend.rs. +#[cold] fn finish_grow<A>( new_layout: Layout, current_memory: Option<(NonNull<u8>, Layout)>, diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index cf99a618e55..314d9203ca1 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -362,6 +362,7 @@ #![feature(strict_provenance_atomic_ptr)] #![feature(sync_unsafe_cell)] #![feature(ub_checks)] +#![feature(used_with_arg)] // tidy-alphabetical-end // // Library features (alloc): diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index ac1f547c914..97f800dddaa 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -27,6 +27,22 @@ use crate::sys::backtrace; use crate::sys::stdio::panic_output; use crate::{fmt, intrinsics, process, thread}; +// This forces codegen of the function called by panic!() inside the std crate, rather than in +// downstream crates. Primarily this is useful for rustc's codegen tests, which rely on noticing +// complete removal of panic from generated IR. Since begin_panic is inline(never), it's only +// codegen'd once per crate-graph so this pushes that to std rather than our codegen test crates. +// +// (See https://github.com/rust-lang/rust/pull/123244 for more info on why). +// +// If this is causing problems we can also modify those codegen tests to use a crate type like +// cdylib which doesn't export "Rust" symbols to downstream linkage units. +#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")] +#[doc(hidden)] +#[allow(dead_code)] +#[used(compiler)] +pub static EMPTY_PANIC: fn(&'static str) -> ! = + begin_panic::<&'static str> as fn(&'static str) -> !; + // Binary interface to the panic runtime that the standard library depends on. // // The standard library is tagged with `#![needs_panic_runtime]` (introduced in |
