Skip to content

Commit 4f800b5

Browse files
committed
Clarify follow_inlining.
I found this confusing because it includes the root item, plus the inlined items reachable from the root item. The new formulation separates the two parts more clearly.
1 parent 3806bad commit 4f800b5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

compiler/rustc_monomorphize/src/partitioning.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,10 @@ fn place_inlined_mono_items<'tcx>(
426426
// Collect all items that need to be available in this codegen unit.
427427
let mut reachable = FxHashSet::default();
428428
for root in cgu.items().keys() {
429-
follow_inlining(cx.tcx, *root, cx.usage_map, &mut reachable);
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);
430433
}
431434

432435
// Add all monomorphizations that are not already there.
@@ -462,18 +465,17 @@ fn place_inlined_mono_items<'tcx>(
462465

463466
return mono_item_placements;
464467

465-
fn follow_inlining<'tcx>(
468+
fn get_reachable_inlined_items<'tcx>(
466469
tcx: TyCtxt<'tcx>,
467470
item: MonoItem<'tcx>,
468471
usage_map: &UsageMap<'tcx>,
469472
visited: &mut FxHashSet<MonoItem<'tcx>>,
470473
) {
471-
if !visited.insert(item) {
472-
return;
473-
}
474-
475474
usage_map.for_each_inlined_used_item(tcx, item, |inlined_item| {
476-
follow_inlining(tcx, inlined_item, usage_map, visited);
475+
let is_new = visited.insert(inlined_item);
476+
if is_new {
477+
get_reachable_inlined_items(tcx, inlined_item, usage_map, visited);
478+
}
477479
});
478480
}
479481
}

0 commit comments

Comments
 (0)