Skip to content

Commit e4f568e

Browse files
Make incremental compilation respect the -Ccodegen-units flag.
1 parent 2f688ac commit e4f568e

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/librustc_mir/monomorphize/partitioning.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ use rustc_span::symbol::Symbol;
112112
use crate::monomorphize::collector::InliningMap;
113113
use crate::monomorphize::collector::{self, MonoItemCollectionMode};
114114

115-
pub enum PartitioningStrategy {
116-
/// Generates one codegen unit per source-level module.
117-
PerModule,
118-
119-
/// Partition the whole crate into a fixed number of codegen units.
120-
FixedUnitCount(usize),
121-
}
122-
123115
// Anything we can't find a proper codegen unit for goes into this.
124116
fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> Symbol {
125117
name_builder.build_cgu_name(LOCAL_CRATE, &["fallback"], Some("cgu"))
@@ -128,7 +120,7 @@ fn fallback_cgu_name(name_builder: &mut CodegenUnitNameBuilder<'_>) -> Symbol {
128120
pub fn partition<'tcx, I>(
129121
tcx: TyCtxt<'tcx>,
130122
mono_items: I,
131-
strategy: PartitioningStrategy,
123+
max_cgu_count: usize,
132124
inlining_map: &InliningMap<'tcx>,
133125
) -> Vec<CodegenUnit<'tcx>>
134126
where
@@ -148,11 +140,10 @@ where
148140

149141
debug_dump(tcx, "INITIAL PARTITIONING:", initial_partitioning.codegen_units.iter());
150142

151-
// If the partitioning should produce a fixed count of codegen units, merge
152-
// until that count is reached.
153-
if let PartitioningStrategy::FixedUnitCount(count) = strategy {
143+
// Merge until we have at most `max_cgu_count` codegen units.
144+
{
154145
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
155-
merge_codegen_units(tcx, &mut initial_partitioning, count);
146+
merge_codegen_units(tcx, &mut initial_partitioning, max_cgu_count);
156147
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
157148
}
158149

@@ -875,13 +866,7 @@ fn collect_and_partition_mono_items(
875866
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {
876867
sync::join(
877868
|| {
878-
let strategy = if tcx.sess.opts.incremental.is_some() {
879-
PartitioningStrategy::PerModule
880-
} else {
881-
PartitioningStrategy::FixedUnitCount(tcx.sess.codegen_units())
882-
};
883-
884-
partition(tcx, items.iter().cloned(), strategy, &inlining_map)
869+
partition(tcx, items.iter().cloned(), tcx.sess.codegen_units(), &inlining_map)
885870
.into_iter()
886871
.map(Arc::new)
887872
.collect::<Vec<_>>()

src/librustc_session/session.rs

+7
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,13 @@ impl Session {
741741
return n as usize;
742742
}
743743

744+
// If incremental compilation is turned on, we default to a high number
745+
// codegen units in order to reduce the "collatoral damage" small
746+
// changes cause.
747+
if self.opts.incremental.is_some() {
748+
return 256;
749+
}
750+
744751
// Why is 16 codegen units the default all the time?
745752
//
746753
// The main reason for enabling multiple codegen units by default is to

0 commit comments

Comments
 (0)