]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/reachable.rs
Rollup merge of #31055 - steveklabnik:alt-tags, r=alexcrichton
[rust.git] / src / librustc / middle / reachable.rs
index e5bc9030fc97db96d008aa9811b967d3bfd4f060..6373bfbc55ee65c70e8276916c76d9ad50e6a057 100644 (file)
@@ -15,8 +15,9 @@
 // makes all other generics or inline functions that it references
 // reachable as well.
 
+use dep_graph::DepNode;
 use front::map as ast_map;
-use middle::def;
+use middle::def::Def;
 use middle::def_id::DefId;
 use middle::ty;
 use middle::privacy;
@@ -28,8 +29,8 @@
 use syntax::ast;
 use syntax::attr;
 use rustc_front::hir;
-use rustc_front::visit::Visitor;
-use rustc_front::visit;
+use rustc_front::intravisit::Visitor;
+use rustc_front::intravisit;
 
 // Returns true if the given set of generics implies that the item it's
 // associated with must be inlined.
@@ -87,9 +88,7 @@ struct ReachableContext<'a, 'tcx: 'a> {
 }
 
 impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
-
     fn visit_expr(&mut self, expr: &hir::Expr) {
-
         match expr.node {
             hir::ExprPath(..) => {
                 let def = match self.tcx.def_map.borrow().get(&expr.id) {
@@ -109,7 +108,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
                             // If this path leads to a constant, then we need to
                             // recurse into the constant to continue finding
                             // items that are reachable.
-                            def::DefConst(..) | def::DefAssociatedConst(..) => {
+                            Def::Const(..) | Def::AssociatedConst(..) => {
                                 self.worklist.push(node_id);
                             }
 
@@ -138,12 +137,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
             _ => {}
         }
 
-        visit::walk_expr(self, expr)
-    }
-
-    fn visit_item(&mut self, _item: &hir::Item) {
-        // Do not recurse into items. These items will be added to the worklist
-        // and recursed into manually if necessary.
+        intravisit::walk_expr(self, expr)
     }
 }
 
@@ -260,7 +254,7 @@ fn propagate_node(&mut self, node: &ast_map::Node,
                 match item.node {
                     hir::ItemFn(_, _, _, _, _, ref search_block) => {
                         if item_might_be_inlined(&*item) {
-                            visit::walk_block(self, &**search_block)
+                            intravisit::walk_block(self, &**search_block)
                         }
                     }
 
@@ -292,7 +286,7 @@ fn propagate_node(&mut self, node: &ast_map::Node,
                         self.visit_expr(&*expr);
                     }
                     hir::MethodTraitItem(_, Some(ref body)) => {
-                        visit::walk_block(self, body);
+                        intravisit::walk_block(self, body);
                     }
                     hir::TypeTraitItem(..) => {}
                 }
@@ -305,7 +299,7 @@ fn propagate_node(&mut self, node: &ast_map::Node,
                     hir::ImplItemKind::Method(ref sig, ref body) => {
                         let did = self.tcx.map.get_parent_did(search_item);
                         if method_might_be_inlined(self.tcx, sig, impl_item, did) {
-                            visit::walk_block(self, body)
+                            intravisit::walk_block(self, body)
                         }
                     }
                     hir::ImplItemKind::Type(_) => {}
@@ -336,7 +330,7 @@ fn propagate_node(&mut self, node: &ast_map::Node,
 // trait items are used from inlinable code through method call syntax or UFCS, or their
 // trait is a lang item.
 struct CollectPrivateImplItemsVisitor<'a> {
-    exported_items: &'a privacy::ExportedItems,
+    access_levels: &'a privacy::AccessLevels,
     worklist: &'a mut Vec<ast::NodeId>,
 }
 
@@ -344,20 +338,19 @@ impl<'a, 'v> Visitor<'v> for CollectPrivateImplItemsVisitor<'a> {
     fn visit_item(&mut self, item: &hir::Item) {
         // We need only trait impls here, not inherent impls, and only non-exported ones
         if let hir::ItemImpl(_, _, _, Some(_), _, ref impl_items) = item.node {
-            if !self.exported_items.contains(&item.id) {
+            if !self.access_levels.is_reachable(item.id) {
                 for impl_item in impl_items {
                     self.worklist.push(impl_item.id);
                 }
             }
         }
-
-        visit::walk_item(self, item);
     }
 }
 
 pub fn find_reachable(tcx: &ty::ctxt,
-                      exported_items: &privacy::ExportedItems)
+                      access_levels: &privacy::AccessLevels)
                       -> NodeSet {
+    let _task = tcx.dep_graph.in_task(DepNode::Reachability);
 
     let mut reachable_context = ReachableContext::new(tcx);
 
@@ -366,7 +359,7 @@ pub fn find_reachable(tcx: &ty::ctxt,
     //         If other crates link to us, they're going to expect to be able to
     //         use the lang items, so we need to be sure to mark them as
     //         exported.
-    for id in exported_items {
+    for (id, _) in &access_levels.map {
         reachable_context.worklist.push(*id);
     }
     for (_, item) in tcx.lang_items.items() {
@@ -378,11 +371,10 @@ pub fn find_reachable(tcx: &ty::ctxt,
     }
     {
         let mut collect_private_impl_items = CollectPrivateImplItemsVisitor {
-            exported_items: exported_items,
+            access_levels: access_levels,
             worklist: &mut reachable_context.worklist,
         };
-
-        visit::walk_crate(&mut collect_private_impl_items, tcx.map.krate());
+        tcx.map.krate().visit_all_items(&mut collect_private_impl_items);
     }
 
     // Step 2: Mark all symbols that the symbols on the worklist touch.