Skip to content

Commit 3806bad

Browse files
committed
Simplify place_inlined_mono_items.
Currently it overwrites all the CGUs with new CGUs. But those new CGUs are just copies of the old CGUs, possibly with some things added. This commit changes things so that each CGU just gets added to in place, which makes things simpler and clearer.
1 parent f1fe797 commit 3806bad

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

compiler/rustc_monomorphize/src/partitioning.rs

+7-24
Original file line numberDiff line numberDiff line change
@@ -422,33 +422,22 @@ fn place_inlined_mono_items<'tcx>(
422422

423423
let single_codegen_unit = codegen_units.len() == 1;
424424

425-
for old_codegen_unit in codegen_units.iter_mut() {
425+
for cgu in codegen_units.iter_mut() {
426426
// Collect all items that need to be available in this codegen unit.
427427
let mut reachable = FxHashSet::default();
428-
for root in old_codegen_unit.items().keys() {
428+
for root in cgu.items().keys() {
429429
follow_inlining(cx.tcx, *root, cx.usage_map, &mut reachable);
430430
}
431431

432-
let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name());
433-
434432
// Add all monomorphizations that are not already there.
435433
for mono_item in reachable {
436-
if let Some(linkage) = old_codegen_unit.items().get(&mono_item) {
437-
// This is a root, just copy it over.
438-
new_codegen_unit.items_mut().insert(mono_item, *linkage);
439-
} else {
434+
if !cgu.items().contains_key(&mono_item) {
440435
if roots.contains(&mono_item) {
441-
bug!(
442-
"GloballyShared mono-item inlined into other CGU: \
443-
{:?}",
444-
mono_item
445-
);
436+
bug!("GloballyShared mono-item inlined into other CGU: {:?}", mono_item);
446437
}
447438

448439
// This is a CGU-private copy.
449-
new_codegen_unit
450-
.items_mut()
451-
.insert(mono_item, (Linkage::Internal, Visibility::Default));
440+
cgu.items_mut().insert(mono_item, (Linkage::Internal, Visibility::Default));
452441
}
453442

454443
if !single_codegen_unit {
@@ -458,23 +447,17 @@ fn place_inlined_mono_items<'tcx>(
458447
Entry::Occupied(e) => {
459448
let placement = e.into_mut();
460449
debug_assert!(match *placement {
461-
MonoItemPlacement::SingleCgu { cgu_name } => {
462-
cgu_name != new_codegen_unit.name()
463-
}
450+
MonoItemPlacement::SingleCgu { cgu_name } => cgu_name != cgu.name(),
464451
MonoItemPlacement::MultipleCgus => true,
465452
});
466453
*placement = MonoItemPlacement::MultipleCgus;
467454
}
468455
Entry::Vacant(e) => {
469-
e.insert(MonoItemPlacement::SingleCgu {
470-
cgu_name: new_codegen_unit.name(),
471-
});
456+
e.insert(MonoItemPlacement::SingleCgu { cgu_name: cgu.name() });
472457
}
473458
}
474459
}
475460
}
476-
477-
*old_codegen_unit = new_codegen_unit;
478461
}
479462

480463
return mono_item_placements;

0 commit comments

Comments
 (0)