From 4a216a25d143e88eefac2655c1fce042571e1f6e Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 23 Nov 2024 13:19:17 -0500 Subject: 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. --- library/std/src/lib.rs | 1 + library/std/src/panicking.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'library/std/src') 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 -- cgit 1.4.1-3-g733a5