Skip to content

Commit cb893a9

Browse files
committed
TEMP Revert "Share inline(never) generics across crates"
This reverts commit 4a216a2. To see if the regression test works. Changed tests are removed so I don't have to resolve conflicts.
1 parent 7d9d7e5 commit cb893a9

File tree

25 files changed

+14
-715
lines changed

25 files changed

+14
-715
lines changed

compiler/rustc_codegen_llvm/src/callee.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
101101

102102
let is_hidden = if is_generic {
103103
// This is a monomorphization of a generic function.
104-
if !(cx.tcx.sess.opts.share_generics()
105-
|| tcx.codegen_fn_attrs(instance_def_id).inline
106-
== rustc_attr_data_structures::InlineAttr::Never)
107-
{
104+
if !cx.tcx.sess.opts.share_generics() {
108105
// When not sharing generics, all instances are in the same
109106
// crate and have hidden visibility.
110107
true

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ fn exported_symbols_provider_local<'tcx>(
308308
));
309309
}
310310

311-
if tcx.local_crate_exports_generics() {
311+
if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() {
312312
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
313313
use rustc_middle::ty::InstanceKind;
314314

@@ -368,17 +368,6 @@ fn exported_symbols_provider_local<'tcx>(
368368
continue;
369369
}
370370

371-
if !tcx.sess.opts.share_generics() {
372-
if tcx.codegen_fn_attrs(mono_item.def_id()).inline
373-
== rustc_attr_data_structures::InlineAttr::Never
374-
{
375-
// this is OK, we explicitly allow sharing inline(never) across crates even
376-
// without share-generics.
377-
} else {
378-
continue;
379-
}
380-
}
381-
382371
match *mono_item {
383372
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
384373
let has_generics = args.non_erasable_generics().next().is_some();

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fmt;
33
use std::hash::Hash;
44

55
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
6-
use rustc_attr_data_structures::InlineAttr;
76
use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN};
87
use rustc_data_structures::fingerprint::Fingerprint;
98
use rustc_data_structures::fx::FxIndexMap;
@@ -211,20 +210,6 @@ impl<'tcx> MonoItem<'tcx> {
211210
return InstantiationMode::LocalCopy;
212211
}
213212

214-
// #[inline(never)] functions in general are poor candidates for inlining and thus since
215-
// LocalCopy generally increases code size for the benefit of optimizations from inlining,
216-
// we want to give them GloballyShared codegen.
217-
// The slight problem is that generic functions need to always support cross-crate
218-
// compilation, so all previous stages of the compiler are obligated to treat generic
219-
// functions the same as those that unconditionally get LocalCopy codegen. It's only when
220-
// we get here that we can at least not codegen a #[inline(never)] generic function in all
221-
// of our CGUs.
222-
if let InlineAttr::Never = tcx.codegen_fn_attrs(instance.def_id()).inline
223-
&& self.is_generic_fn()
224-
{
225-
return InstantiationMode::GloballyShared { may_conflict: true };
226-
}
227-
228213
// The fallthrough case is to generate LocalCopy for all optimized builds, and
229214
// GloballyShared with conflict prevention when optimizations are disabled.
230215
match tcx.sess.opts.optimize {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,8 @@ impl<'tcx> TyCtxt<'tcx> {
21512151

21522152
#[inline]
21532153
pub fn local_crate_exports_generics(self) -> bool {
2154+
debug_assert!(self.sess.opts.share_generics());
2155+
21542156
self.crate_types().iter().any(|crate_type| {
21552157
match crate_type {
21562158
CrateType::Executable

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,7 @@ impl<'tcx> Instance<'tcx> {
209209
// If we are not in share generics mode, we don't link to upstream
210210
// monomorphizations but always instantiate our own internal versions
211211
// instead.
212-
if !tcx.sess.opts.share_generics()
213-
// However, if the def_id is marked inline(never), then it's fine to just reuse the
214-
// upstream monomorphization.
215-
&& tcx.codegen_fn_attrs(self.def_id()).inline != rustc_attr_data_structures::InlineAttr::Never
216-
{
212+
if !tcx.sess.opts.share_generics() {
217213
return None;
218214
}
219215

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ use std::fs::{self, File};
100100
use std::io::Write;
101101
use std::path::{Path, PathBuf};
102102

103-
use rustc_attr_data_structures::InlineAttr;
104103
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
105104
use rustc_data_structures::sync;
106105
use rustc_data_structures::unord::{UnordMap, UnordSet};
@@ -210,8 +209,8 @@ where
210209
// available to downstream crates. This depends on whether we are in
211210
// share-generics mode and whether the current crate can even have
212211
// downstream crates.
213-
let can_export_generics = cx.tcx.local_crate_exports_generics();
214-
let always_export_generics = can_export_generics && cx.tcx.sess.opts.share_generics();
212+
let export_generics =
213+
cx.tcx.sess.opts.share_generics() && cx.tcx.local_crate_exports_generics();
215214

216215
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
217216
let cgu_name_cache = &mut UnordMap::default();
@@ -251,8 +250,7 @@ where
251250
cx.tcx,
252251
&mono_item,
253252
&mut can_be_internalized,
254-
can_export_generics,
255-
always_export_generics,
253+
export_generics,
256254
);
257255

258256
// We can't differentiate a function that got inlined.
@@ -747,19 +745,12 @@ fn mono_item_linkage_and_visibility<'tcx>(
747745
tcx: TyCtxt<'tcx>,
748746
mono_item: &MonoItem<'tcx>,
749747
can_be_internalized: &mut bool,
750-
can_export_generics: bool,
751-
always_export_generics: bool,
748+
export_generics: bool,
752749
) -> (Linkage, Visibility) {
753750
if let Some(explicit_linkage) = mono_item.explicit_linkage(tcx) {
754751
return (explicit_linkage, Visibility::Default);
755752
}
756-
let vis = mono_item_visibility(
757-
tcx,
758-
mono_item,
759-
can_be_internalized,
760-
can_export_generics,
761-
always_export_generics,
762-
);
753+
let vis = mono_item_visibility(tcx, mono_item, can_be_internalized, export_generics);
763754
(Linkage::External, vis)
764755
}
765756

@@ -782,8 +773,7 @@ fn mono_item_visibility<'tcx>(
782773
tcx: TyCtxt<'tcx>,
783774
mono_item: &MonoItem<'tcx>,
784775
can_be_internalized: &mut bool,
785-
can_export_generics: bool,
786-
always_export_generics: bool,
776+
export_generics: bool,
787777
) -> Visibility {
788778
let instance = match mono_item {
789779
// This is pretty complicated; see below.
@@ -843,11 +833,7 @@ fn mono_item_visibility<'tcx>(
843833

844834
// Upstream `DefId` instances get different handling than local ones.
845835
let Some(def_id) = def_id.as_local() else {
846-
return if is_generic
847-
&& (always_export_generics
848-
|| (can_export_generics
849-
&& tcx.codegen_fn_attrs(def_id).inline == InlineAttr::Never))
850-
{
836+
return if export_generics && is_generic {
851837
// If it is an upstream monomorphization and we export generics, we must make
852838
// it available to downstream crates.
853839
*can_be_internalized = false;
@@ -858,9 +844,7 @@ fn mono_item_visibility<'tcx>(
858844
};
859845

860846
if is_generic {
861-
if always_export_generics
862-
|| (can_export_generics && tcx.codegen_fn_attrs(def_id).inline == InlineAttr::Never)
863-
{
847+
if export_generics {
864848
if tcx.is_unreachable_local_definition(def_id) {
865849
// This instance cannot be used from another crate.
866850
Visibility::Hidden

library/alloc/src/raw_vec/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,7 @@ impl<A: Allocator> RawVecInner<A> {
760760
}
761761
}
762762

763-
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
764-
// function, see tests/codegen/vec-reserve-extend.rs.
765-
#[cold]
763+
#[inline(never)]
766764
fn finish_grow<A>(
767765
new_layout: Layout,
768766
current_memory: Option<(NonNull<u8>, Layout)>,

library/std/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@
368368
#![feature(sync_unsafe_cell)]
369369
#![feature(temporary_niche_types)]
370370
#![feature(ub_checks)]
371-
#![feature(used_with_arg)]
372371
// tidy-alphabetical-end
373372
//
374373
// Library features (alloc):

library/std/src/panicking.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,6 @@ 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-
4630
// Binary interface to the panic runtime that the standard library depends on.
4731
//
4832
// The standard library is tagged with `#![needs_panic_runtime]` (introduced in

src/tools/tidy/src/issues.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3132,7 +3132,6 @@ ui/packed/issue-118537-field-offset.rs
31323132
ui/packed/issue-27060-2.rs
31333133
ui/packed/issue-27060.rs
31343134
ui/packed/issue-46152.rs
3135-
ui/panics/issue-47429-short-backtraces.rs
31363135
ui/parser/issue-116781.rs
31373136
ui/parser/issue-12187-1.rs
31383137
ui/parser/issue-12187-2.rs

tests/codegen-units/item-collection/cross-crate-generic-functions.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/codegen-units/partitioning/extern-generic.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)