Skip to content

Commit 8dbb347

Browse files
committed
Split loop in place_inlined_mono_item.
This loop is doing two different things. For inlined items, it's adding them to the CGU. For all items, it's recording them in `mono_item_placements`. This commit splits it into two separate loops. This avoids putting root mono items into `reachable`, and removes the low-value check that `roots` doesn't contain inlined mono items.
1 parent fe3b646 commit 8dbb347

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -416,37 +416,35 @@ enum MonoItemPlacement {
416416
fn place_inlined_mono_items<'tcx>(
417417
cx: &PartitioningCx<'_, 'tcx>,
418418
codegen_units: &mut [CodegenUnit<'tcx>],
419-
roots: FxHashSet<MonoItem<'tcx>>,
419+
_roots: FxHashSet<MonoItem<'tcx>>,
420420
) -> FxHashMap<MonoItem<'tcx>, MonoItemPlacement> {
421-
let mut mono_item_placements = FxHashMap::default();
422-
423-
let single_codegen_unit = codegen_units.len() == 1;
424-
425421
for cgu in codegen_units.iter_mut() {
426-
// Collect all items that need to be available in this codegen unit.
427-
let mut reachable = FxHashSet::default();
422+
// Collect all inlined items that need to be available in this codegen unit.
423+
let mut reachable_inlined_items = FxHashSet::default();
428424
for root in cgu.items().keys() {
429-
// Insert the root item itself, plus all inlined items that are
430-
// reachable from it without going via another root item.
431-
reachable.insert(*root);
432-
get_reachable_inlined_items(cx.tcx, *root, cx.usage_map, &mut reachable);
425+
// Get all inlined items that are reachable from it without going
426+
// via another root item.
427+
get_reachable_inlined_items(cx.tcx, *root, cx.usage_map, &mut reachable_inlined_items);
433428
}
434429

435430
// Add all monomorphizations that are not already there.
436-
for mono_item in reachable {
437-
if !cgu.items().contains_key(&mono_item) {
438-
if roots.contains(&mono_item) {
439-
bug!("GloballyShared mono-item inlined into other CGU: {:?}", mono_item);
440-
}
431+
for inlined_item in reachable_inlined_items {
432+
assert!(!cgu.items().contains_key(&inlined_item));
441433

442-
// This is a CGU-private copy.
443-
cgu.items_mut().insert(mono_item, (Linkage::Internal, Visibility::Default));
444-
}
434+
// This is a CGU-private copy.
435+
cgu.items_mut().insert(inlined_item, (Linkage::Internal, Visibility::Default));
436+
}
437+
}
438+
439+
let mut mono_item_placements = FxHashMap::default();
440+
let single_codegen_unit = codegen_units.len() == 1;
445441

442+
for cgu in codegen_units.iter_mut() {
443+
for item in cgu.items().keys() {
446444
if !single_codegen_unit {
447445
// If there is more than one codegen unit, we need to keep track
448446
// in which codegen units each monomorphization is placed.
449-
match mono_item_placements.entry(mono_item) {
447+
match mono_item_placements.entry(*item) {
450448
Entry::Occupied(e) => {
451449
let placement = e.into_mut();
452450
debug_assert!(match *placement {

0 commit comments

Comments
 (0)