Skip to content

Commit 5c391d7

Browse files
committed
add visit_all_bodies_in_krate helper
1 parent 22f91ca commit 5c391d7

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/librustc/dep_graph/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ pub use self::dep_node::WorkProductId;
2525
pub use self::graph::DepGraph;
2626
pub use self::graph::WorkProduct;
2727
pub use self::query::DepGraphQuery;
28+
pub use self::visit::visit_all_bodies_in_krate;
2829
pub use self::visit::visit_all_item_likes_in_krate;
2930
pub use self::raii::DepTask;

src/librustc/dep_graph/visit.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ pub fn visit_all_item_likes_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>
7474
};
7575
krate.visit_all_item_likes(&mut tracking_visitor)
7676
}
77+
78+
pub fn visit_all_bodies_in_krate<'a, 'tcx, C>(tcx: TyCtxt<'a, 'tcx, 'tcx>, callback: C)
79+
where C: Fn(/* body_owner */ DefId, /* body id */ hir::BodyId),
80+
{
81+
let krate = tcx.hir.krate();
82+
for body_id in krate.bodies.keys().cloned() {
83+
let body_owner_def_id = tcx.hir.body_owner_def_id(body_id);
84+
callback(body_owner_def_id, body_id);
85+
}
86+
}

src/librustc/ty/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26742674
dep_graph::visit_all_item_likes_in_krate(self.global_tcx(), dep_node_fn, visitor);
26752675
}
26762676

2677+
/// Invokes `callback` for each body in the krate. This will
2678+
/// create a read edge from `DepNode::Krate` to the current task;
2679+
/// it is meant to be run in the context of some global task like
2680+
/// `BorrowckCrate`. The callback would then create a task like
2681+
/// `BorrowckBody(DefId)` to process each individual item.
2682+
pub fn visit_all_bodies_in_krate<C>(self, callback: C)
2683+
where C: Fn(/* body_owner */ DefId, /* body id */ hir::BodyId),
2684+
{
2685+
dep_graph::visit_all_bodies_in_krate(self.global_tcx(), callback)
2686+
}
2687+
26772688
/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`
26782689
/// with the name of the crate containing the impl.
26792690
pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {

0 commit comments

Comments
 (0)