Skip to content

Commit 7740fad

Browse files
committed
Enforce compiler-builtins CGU partitioning in the compiler
1 parent d45fd5e commit 7740fad

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

compiler/rustc_mir_transform/src/cross_crate_inline.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
3434
return true;
3535
}
3636

37+
// compiler-builtins only defines intrinsics (which are handled above by checking
38+
// contains_extern_indicator) and helper functions used by those intrinsics. The helper
39+
// functions should always be inlined into intrinsics that use them. This check does not
40+
// guarantee that we get the optimizations we want, but it makes them *much* easier.
41+
// See https://github.com/rust-lang/rust/issues/73135
42+
if tcx.is_compiler_builtins(rustc_span::def_id::LOCAL_CRATE) {
43+
return true;
44+
}
45+
3746
if tcx.has_attr(def_id, sym::rustc_intrinsic) {
3847
// Intrinsic fallback bodies are always cross-crate inlineable.
3948
// To ensure that the MIR inliner doesn't cluelessly try to inline fallback

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ fn merge_codegen_units<'tcx>(
319319
let mut cgu_contents: UnordMap<Symbol, Vec<Symbol>> =
320320
codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name()])).collect();
321321

322+
if cx.tcx.is_compiler_builtins(LOCAL_CRATE) {
323+
return cgu_contents;
324+
}
325+
322326
// If N is the maximum number of CGUs, and the CGUs are sorted from largest
323327
// to smallest, we repeatedly find which CGU in codegen_units[N..] has the
324328
// greatest overlap of inlined items with codegen_units[N-1], merge that
@@ -680,6 +684,11 @@ fn compute_codegen_unit_name<'tcx>(
680684
mono_item: MonoItem<'tcx>,
681685
cache: &mut CguNameCache,
682686
) -> Symbol {
687+
if tcx.is_compiler_builtins(LOCAL_CRATE) {
688+
let name = mono_item.symbol_name(tcx);
689+
return Symbol::intern(name.name);
690+
}
691+
683692
let Some(def_id) = characteristic_def_id_of_mono_item(tcx, mono_item) else {
684693
return fallback_cgu_name(name_builder);
685694
};

library/Cargo.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ exclude = [
1111
"windows_targets"
1212
]
1313

14-
[profile.release.package.compiler_builtins]
15-
# For compiler-builtins we always use a high number of codegen units.
16-
# The goal here is to place every single intrinsic into its own object
17-
# file to avoid symbol clashes with the system libgcc if possible. Note
18-
# that this number doesn't actually produce this many object files, we
19-
# just don't create more than this number of object files.
20-
#
21-
# It's a bit of a bummer that we have to pass this here, unfortunately.
22-
# Ideally this would be specified through an env var to Cargo so Cargo
23-
# knows how many CGUs are for this specific crate, but for now
24-
# per-crate configuration isn't specifiable in the environment.
25-
codegen-units = 10000
26-
2714
# These dependencies of the standard library implement symbolication for
2815
# backtraces on most platforms. Their debuginfo causes both linking to be slower
2916
# (more data to chew through) and binaries to be larger without really all that

0 commit comments

Comments
 (0)