Skip to content

Commit a90ce0a

Browse files
Make FixedCount partitioning handle case where codegen units have to be added.
1 parent 29e3977 commit a90ce0a

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/librustc_trans/partitioning.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,7 @@ pub fn partition<'tcx, I>(tcx: &TyCtxt<'tcx>,
182182
// easily determine which declarations need to be placed within each one.
183183
let post_declarations = place_declarations(post_inlining, reference_map);
184184

185-
let mut final_partitioning = post_declarations.0;
186-
187-
if final_partitioning.len() == 0 {
188-
// Some crates don't contain anything that will result in a translation
189-
// item. We still want to have at least one (empty) codegen unit in that
190-
// case.
191-
final_partitioning.push(CodegenUnit {
192-
name: token::intern_and_get_ident(&format!("{}.0", tcx.crate_name)[..]),
193-
items: FnvHashMap()
194-
});
195-
}
196-
197-
final_partitioning
185+
post_declarations.0
198186
}
199187

200188
struct PreInliningPartitioning<'tcx> {
@@ -268,10 +256,6 @@ fn place_root_translation_items<'tcx, I>(tcx: &TyCtxt<'tcx>,
268256
fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<'tcx>,
269257
target_cgu_count: usize,
270258
crate_name: &str) {
271-
if target_cgu_count >= initial_partitioning.codegen_units.len() {
272-
return;
273-
}
274-
275259
assert!(target_cgu_count >= 1);
276260
let codegen_units = &mut initial_partitioning.codegen_units;
277261

@@ -290,7 +274,22 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
290274
}
291275

292276
for (index, cgu) in codegen_units.iter_mut().enumerate() {
293-
cgu.name = token::intern_and_get_ident(&format!("{}.{}", crate_name, index)[..]);
277+
cgu.name = numbered_codegen_unit_name(crate_name, index);
278+
}
279+
280+
// If the initial partitioning contained less than target_cgu_count to begin
281+
// with, we won't have enough codegen units here, so add a empty units until
282+
// we reach the target count
283+
while codegen_units.len() < target_cgu_count {
284+
let index = codegen_units.len();
285+
codegen_units.push(CodegenUnit {
286+
name: numbered_codegen_unit_name(crate_name, index),
287+
items: FnvHashMap()
288+
});
289+
}
290+
291+
fn numbered_codegen_unit_name(crate_name: &str, index: usize) -> InternedString {
292+
token::intern_and_get_ident(&format!("{}.{}", crate_name, index)[..])
294293
}
295294
}
296295

0 commit comments

Comments
 (0)