Skip to content

Commit

Permalink
Clarify follow_inlining.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnethercote committed Jun 2, 2023
1 parent 3806bad commit 4f800b5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ fn place_inlined_mono_items<'tcx>(
// Collect all items that need to be available in this codegen unit.
let mut reachable = FxHashSet::default();
for root in cgu.items().keys() {
follow_inlining(cx.tcx, *root, cx.usage_map, &mut reachable);
// Insert the root item itself, plus all inlined items that are
// reachable from it without going via another root item.
reachable.insert(*root);
get_reachable_inlined_items(cx.tcx, *root, cx.usage_map, &mut reachable);
}

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

return mono_item_placements;

fn follow_inlining<'tcx>(
fn get_reachable_inlined_items<'tcx>(
tcx: TyCtxt<'tcx>,
item: MonoItem<'tcx>,
usage_map: &UsageMap<'tcx>,
visited: &mut FxHashSet<MonoItem<'tcx>>,
) {
if !visited.insert(item) {
return;
}

usage_map.for_each_inlined_used_item(tcx, item, |inlined_item| {
follow_inlining(tcx, inlined_item, usage_map, visited);
let is_new = visited.insert(inlined_item);
if is_new {
get_reachable_inlined_items(tcx, inlined_item, usage_map, visited);
}
});
}
}
Expand Down

0 comments on commit 4f800b5

Please sign in to comment.