Skip to content

Commit 03cbc54

Browse files
Mark-Simulacrumgitbot
authored and
gitbot
committed
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.
1 parent ccc3087 commit 03cbc54

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)