Auto merge of #118770 - saethlin:fix-inline-never-uses, r=nnethercote
Fix cases where std accidentally relied on inline(never) This PR increases the power of `-Zcross-crate-inline-threshold=always` so that it applies through `#[inline(never)]`. Note that though this is called "cross-crate-inlining" in this case especially it is _just_ lazy per-CGU codegen. The MIR inliner and LLVM still respect the attribute as much as they ever have. Trying to bootstrap with the new `-Zcross-crate-inline-threshold=always` change revealed two bugs: We have special intrinsics `assert_inhabited`, `assert_zero_valid`, and `assert_mem_uniniitalized_valid` which codegen backends will lower to nothing or a call to `panic_nounwind`. Since we may not have any call to `panic_nounwind` in MIR but emit one anyway, we need to specially tell `MirUsedCollector` about this situation. `#[lang = "start"]` is special-cased already so that `MirUsedCollector` will collect it, but then when we make it cross-crate-inlinable it is only assigned to a CGU based on whether `MirUsedCollector` saw a call to it, which of course we didn't. --- I started looking into this because https://github.com/rust-lang/rust/pull/118683 revealed a case where we were accidentally relying on a function being `#[inline(never)]`, and cranking up cross-crate-inlinability seems like a way to find other situations like that. r? `@nnethercote` because I don't like what I'm doing to the CGU partitioning code here but I can't come up with something much better
This commit is contained in:
commit
1559dd2dbf
4 changed files with 37 additions and 11 deletions
|
@ -212,11 +212,17 @@ where
|
|||
let cgu_name_cache = &mut FxHashMap::default();
|
||||
|
||||
for mono_item in mono_items {
|
||||
// Handle only root items directly here. Inlined items are handled at
|
||||
// the bottom of the loop based on reachability.
|
||||
// Handle only root (GloballyShared) items directly here. Inlined (LocalCopy) items
|
||||
// are handled at the bottom of the loop based on reachability, with one exception.
|
||||
// The #[lang = "start"] item is the program entrypoint, so there are no calls to it in MIR.
|
||||
// So even if its mode is LocalCopy, we need to treat it like a root.
|
||||
match mono_item.instantiation_mode(cx.tcx) {
|
||||
InstantiationMode::GloballyShared { .. } => {}
|
||||
InstantiationMode::LocalCopy => continue,
|
||||
InstantiationMode::LocalCopy => {
|
||||
if Some(mono_item.def_id()) != cx.tcx.lang_items().start_fn() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let characteristic_def_id = characteristic_def_id_of_mono_item(cx.tcx, mono_item);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue