Skip to content

Commit d885e4c

Browse files
committed
add visit_all_bodies_in_krate helper
1 parent b3a482c commit d885e4c

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
@@ -2613,6 +2613,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26132613
dep_graph::visit_all_item_likes_in_krate(self.global_tcx(), dep_node_fn, visitor);
26142614
}
26152615

2616+
/// Invokes `callback` for each body in the krate. This will
2617+
/// create a read edge from `DepNode::Krate` to the current task;
2618+
/// it is meant to be run in the context of some global task like
2619+
/// `BorrowckCrate`. The callback would then create a task like
2620+
/// `BorrowckBody(DefId)` to process each individual item.
2621+
pub fn visit_all_bodies_in_krate<C>(self, callback: C)
2622+
where C: Fn(/* body_owner */ DefId, /* body id */ hir::BodyId),
2623+
{
2624+
dep_graph::visit_all_bodies_in_krate(self.global_tcx(), callback)
2625+
}
2626+
26162627
/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`
26172628
/// with the name of the crate containing the impl.
26182629
pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {

0 commit comments

Comments
 (0)