Skip to content

Commit 87e76bc

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#123244 - Mark-Simulacrum:share-inline-never-generics, r=saethlin
Enable -Zshare-generics for inline(never) functions This avoids inlining cross-crate generic items when possible that are already marked inline(never), implying that the author is not intending for the function to be inlined by callers. As such, having a local copy may make it easier for LLVM to optimize but mostly just adds to binary bloat and codegen time. In practice our benchmarks indicate this is indeed a win for larger compilations, where the extra cost in dynamic linking to these symbols is diminished compared to the advantages in fewer copies that need optimizing in each binary. It might also make sense it expand this with other heuristics (e.g., `#[cold]`) in the future, but this seems like a good starting point. FWIW, I expect that doing cleanup in where we make the decision what should/shouldn't be shared is also a good idea. Way too much code needed to be tweaked to check this. But I'm hoping to leave that for a follow-up PR rather than blocking this on it.
2 parents 15825f6 + a2354a8 commit 87e76bc

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

alloc/src/raw_vec.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,9 @@ impl<A: Allocator> RawVecInner<A> {
757757
}
758758
}
759759

760-
#[inline(never)]
760+
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
761+
// function, see tests/codegen/vec-reserve-extend.rs.
762+
#[cold]
761763
fn finish_grow<A>(
762764
new_layout: Layout,
763765
current_memory: Option<(NonNull<u8>, Layout)>,

std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@
362362
#![feature(strict_provenance_atomic_ptr)]
363363
#![feature(sync_unsafe_cell)]
364364
#![feature(ub_checks)]
365+
#![feature(used_with_arg)]
365366
// tidy-alphabetical-end
366367
//
367368
// Library features (alloc):

std/src/panicking.rs

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ use crate::sys::backtrace;
2727
use crate::sys::stdio::panic_output;
2828
use crate::{fmt, intrinsics, process, thread};
2929

30+
// This forces codegen of the function called by panic!() inside the std crate, rather than in
31+
// downstream crates. Primarily this is useful for rustc's codegen tests, which rely on noticing
32+
// complete removal of panic from generated IR. Since begin_panic is inline(never), it's only
33+
// codegen'd once per crate-graph so this pushes that to std rather than our codegen test crates.
34+
//
35+
// (See https://github.com/rust-lang/rust/pull/123244 for more info on why).
36+
//
37+
// If this is causing problems we can also modify those codegen tests to use a crate type like
38+
// cdylib which doesn't export "Rust" symbols to downstream linkage units.
39+
#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")]
40+
#[doc(hidden)]
41+
#[allow(dead_code)]
42+
#[used(compiler)]
43+
pub static EMPTY_PANIC: fn(&'static str) -> ! =
44+
begin_panic::<&'static str> as fn(&'static str) -> !;
45+
3046
// Binary interface to the panic runtime that the standard library depends on.
3147
//
3248
// The standard library is tagged with `#![needs_panic_runtime]` (introduced in

0 commit comments

Comments
 (0)