]> git.lizzy.rs Git - rust.git/commitdiff
add `visit_all_bodies_in_krate` helper
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 15 Feb 2017 10:17:30 +0000 (05:17 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Tue, 28 Feb 2017 13:43:47 +0000 (08:43 -0500)
src/librustc/dep_graph/mod.rs
src/librustc/dep_graph/visit.rs
src/librustc/ty/mod.rs

index e365cea6d0e5ea8e553fbff25c72efff2bfb1333..7331756f35b8e95da63c8e6667f02de9a7b0caf1 100644 (file)
@@ -25,5 +25,6 @@
 pub use self::graph::DepGraph;
 pub use self::graph::WorkProduct;
 pub use self::query::DepGraphQuery;
+pub use self::visit::visit_all_bodies_in_krate;
 pub use self::visit::visit_all_item_likes_in_krate;
 pub use self::raii::DepTask;
index f0a81fd1cfd334f061686970ed6a8a69d9b58201..f807437750d0119c70880ce090c0d92c36102c08 100644 (file)
@@ -74,3 +74,13 @@ fn visit_impl_item(&mut self, i: &'tcx hir::ImplItem) {
     };
     krate.visit_all_item_likes(&mut tracking_visitor)
 }
+
+pub fn visit_all_bodies_in_krate<'a, 'tcx, C>(tcx: TyCtxt<'a, 'tcx, 'tcx>, callback: C)
+    where C: Fn(/* body_owner */ DefId, /* body id */ hir::BodyId),
+{
+    let krate = tcx.hir.krate();
+    for body_id in krate.bodies.keys().cloned() {
+        let body_owner_def_id = tcx.hir.body_owner_def_id(body_id);
+        callback(body_owner_def_id, body_id);
+    }
+}
index 55b6f61148d7715b947e7665d25942536f4b82f0..328d5c234e17efb115a98d6e7c72a78c81e8358a 100644 (file)
@@ -2613,6 +2613,17 @@ pub fn visit_all_item_likes_in_krate<V,F>(self,
         dep_graph::visit_all_item_likes_in_krate(self.global_tcx(), dep_node_fn, visitor);
     }
 
+    /// Invokes `callback` for each body in the krate. This will
+    /// create a read edge from `DepNode::Krate` to the current task;
+    /// it is meant to be run in the context of some global task like
+    /// `BorrowckCrate`. The callback would then create a task like
+    /// `BorrowckBody(DefId)` to process each individual item.
+    pub fn visit_all_bodies_in_krate<C>(self, callback: C)
+        where C: Fn(/* body_owner */ DefId, /* body id */ hir::BodyId),
+    {
+        dep_graph::visit_all_bodies_in_krate(self.global_tcx(), callback)
+    }
+
     /// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`
     /// with the name of the crate containing the impl.
     pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {