Skip to content

[experimental] Don't partition generic and non-generic code into different CGUs during incr. comp. #53963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/librustc_mir/monomorphize/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
{
let mut roots = FxHashSet();
let mut codegen_units = FxHashMap();
let is_incremental_build = tcx.sess.opts.incremental.is_some();
let mut internalization_candidates = FxHashSet();

// Determine if monomorphizations instantiated in this crate will be made
Expand All @@ -323,14 +322,11 @@ fn place_root_mono_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

let characteristic_def_id = characteristic_def_id_of_mono_item(tcx, mono_item);
let is_volatile = is_incremental_build &&
mono_item.is_generic_fn();

let codegen_unit_name = match characteristic_def_id {
Some(def_id) => compute_codegen_unit_name(tcx,
cgu_name_builder,
def_id,
is_volatile,
cgu_name_cache),
None => fallback_cgu_name(cgu_name_builder),
};
Expand Down Expand Up @@ -794,12 +790,11 @@ fn characteristic_def_id_of_mono_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}

type CguNameCache = FxHashMap<(DefId, bool), InternedString>;
type CguNameCache = FxHashMap<DefId, InternedString>;

fn compute_codegen_unit_name(tcx: TyCtxt,
name_builder: &mut CodegenUnitNameBuilder,
def_id: DefId,
volatile: bool,
cache: &mut CguNameCache)
-> InternedString {
// Find the innermost module that is not nested within a function
Expand Down Expand Up @@ -838,21 +833,16 @@ fn compute_codegen_unit_name(tcx: TyCtxt,

let cgu_def_id = cgu_def_id.unwrap();

cache.entry((cgu_def_id, volatile)).or_insert_with(|| {
cache.entry(cgu_def_id).or_insert_with(|| {
let def_path = tcx.def_path(cgu_def_id);

let components = def_path
.data
.iter()
.map(|part| part.data.as_interned_str());

let volatile_suffix = if volatile {
Some("volatile")
} else {
None
};

name_builder.build_cgu_name(def_path.krate, components, volatile_suffix)
let suffix: Option<&str> = None;
name_builder.build_cgu_name(def_path.krate, components, suffix)
}).clone()
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/codegen-units/partitioning/extern-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ mod mod3 {

// Make sure the two generic functions from the extern crate get instantiated
// once for the current crate
//~ MONO_ITEM fn cgu_generic_function::foo[0]<&str> @@ cgu_generic_function.volatile[External]
//~ MONO_ITEM fn cgu_generic_function::bar[0]<&str> @@ cgu_generic_function.volatile[External]
//~ MONO_ITEM fn cgu_generic_function::foo[0]<&str> @@ cgu_generic_function[External]
//~ MONO_ITEM fn cgu_generic_function::bar[0]<&str> @@ cgu_generic_function[External]
8 changes: 4 additions & 4 deletions src/test/codegen-units/partitioning/local-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#![allow(dead_code)]
#![crate_type="lib"]

//~ MONO_ITEM fn local_generic::generic[0]<u32> @@ local_generic.volatile[External]
//~ MONO_ITEM fn local_generic::generic[0]<u64> @@ local_generic.volatile[External]
//~ MONO_ITEM fn local_generic::generic[0]<char> @@ local_generic.volatile[External]
//~ MONO_ITEM fn local_generic::generic[0]<&str> @@ local_generic.volatile[External]
//~ MONO_ITEM fn local_generic::generic[0]<u32> @@ local_generic[External]
//~ MONO_ITEM fn local_generic::generic[0]<u64> @@ local_generic[External]
//~ MONO_ITEM fn local_generic::generic[0]<char> @@ local_generic[External]
//~ MONO_ITEM fn local_generic::generic[0]<&str> @@ local_generic[External]
pub fn generic<T>(x: T) -> T { x }

//~ MONO_ITEM fn local_generic::user[0] @@ local_generic[Internal]
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen-units/partitioning/shared-generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern crate shared_generics_aux;
//~ MONO_ITEM fn shared_generics::foo[0]
pub fn foo() {

//~ MONO_ITEM fn shared_generics_aux::generic_fn[0]<u16> @@ shared_generics_aux.volatile[External]
//~ MONO_ITEM fn shared_generics_aux::generic_fn[0]<u16> @@ shared_generics_aux[External]
let _ = shared_generics_aux::generic_fn(0u16, 1u16);

// This should not generate a monomorphization because it's already
Expand Down
10 changes: 5 additions & 5 deletions src/test/codegen-units/partitioning/vtable-through-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ fn start(_: isize, _: *const *const u8) -> isize {
// Since Trait1::do_something() is instantiated via its default implementation,
// it is considered a generic and is instantiated here only because it is
// referenced in this module.
//~ MONO_ITEM fn vtable_through_const::mod1[0]::Trait1[0]::do_something_else[0]<u32> @@ vtable_through_const-mod1.volatile[External]
//~ MONO_ITEM fn vtable_through_const::mod1[0]::Trait1[0]::do_something_else[0]<u32> @@ vtable_through_const-mod1[External]

// Although it is never used, Trait1::do_something_else() has to be
// instantiated locally here too, otherwise the <&u32 as &Trait1> vtable
// could not be fully constructed.
//~ MONO_ITEM fn vtable_through_const::mod1[0]::Trait1[0]::do_something[0]<u32> @@ vtable_through_const-mod1.volatile[External]
//~ MONO_ITEM fn vtable_through_const::mod1[0]::Trait1[0]::do_something[0]<u32> @@ vtable_through_const-mod1[External]
mod1::TRAIT1_REF.do_something();

// Same as above
//~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something[0]<u8> @@ vtable_through_const-mod1.volatile[External]
//~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something_else[0]<u8> @@ vtable_through_const-mod1.volatile[External]
//~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something[0]<u8> @@ vtable_through_const-mod1[External]
//~ MONO_ITEM fn vtable_through_const::mod1[0]::{{impl}}[1]::do_something_else[0]<u8> @@ vtable_through_const-mod1[External]
mod1::TRAIT1_GEN_REF.do_something(0u8);

//~ MONO_ITEM fn vtable_through_const::mod1[0]::id[0]<char> @@ vtable_through_const-mod1.volatile[External]
//~ MONO_ITEM fn vtable_through_const::mod1[0]::id[0]<char> @@ vtable_through_const-mod1[External]
mod1::ID_CHAR('x');

0
Expand Down