From 77e659a6d324bd6f096832899f5f77ae5c5d734e Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 16 Dec 2016 20:11:59 -0500 Subject: [PATCH] Remove some more things that were only needed for inlined-HIR DefIds --- src/librustc/dep_graph/README.md | 6 +- src/librustc/dep_graph/visit.rs | 2 - src/librustc/hir/map/def_collector.rs | 192 ----------------------- src/librustc/hir/map/mod.rs | 12 -- src/librustc_incremental/persist/hash.rs | 5 - 5 files changed, 2 insertions(+), 215 deletions(-) diff --git a/src/librustc/dep_graph/README.md b/src/librustc/dep_graph/README.md index 48f5b7ea259..d2b94db689b 100644 --- a/src/librustc/dep_graph/README.md +++ b/src/librustc/dep_graph/README.md @@ -418,7 +418,7 @@ to see something like: Hir(foo) -> Collect(bar) Collect(bar) -> TypeckItemBody(bar) - + That first edge looks suspicious to you. So you set `RUST_FORBID_DEP_GRAPH_EDGE` to `Hir&foo -> Collect&bar`, re-run, and then observe the backtrace. Voila, bug fixed! @@ -440,6 +440,4 @@ To achieve this, the HIR map will detect if the def-id originates in an inlined node and add a dependency to a suitable `MetaData` node instead. If you are reading a HIR node and are not sure if it may be inlined or not, you can use `tcx.map.read(node_id)` and it will detect -whether the node is inlined or not and do the right thing. You can -also use `tcx.map.is_inlined_def_id()` and -`tcx.map.is_inlined_node_id()` to test. +whether the node is inlined or not and do the right thing. diff --git a/src/librustc/dep_graph/visit.rs b/src/librustc/dep_graph/visit.rs index 600732fc6f7..f6a22e47cf2 100644 --- a/src/librustc/dep_graph/visit.rs +++ b/src/librustc/dep_graph/visit.rs @@ -40,7 +40,6 @@ fn visit_item(&mut self, i: &'tcx hir::Item) { let task_id = (self.dep_node_fn)(item_def_id); let _task = self.tcx.dep_graph.in_task(task_id.clone()); debug!("Started task {:?}", task_id); - assert!(!self.tcx.map.is_inlined_def_id(item_def_id)); self.tcx.dep_graph.read(DepNode::Hir(item_def_id)); self.visitor.visit_item(i); debug!("Ended task {:?}", task_id); @@ -51,7 +50,6 @@ fn visit_impl_item(&mut self, i: &'tcx hir::ImplItem) { let task_id = (self.dep_node_fn)(impl_item_def_id); let _task = self.tcx.dep_graph.in_task(task_id.clone()); debug!("Started task {:?}", task_id); - assert!(!self.tcx.map.is_inlined_def_id(impl_item_def_id)); self.tcx.dep_graph.read(DepNode::Hir(impl_item_def_id)); self.visitor.visit_impl_item(i); debug!("Ended task {:?}", task_id); diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index 8c303a96b0c..256aee342a3 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -9,13 +9,8 @@ // except according to those terms. use hir::map::definitions::*; - -use hir; -use hir::intravisit::{self, Visitor, NestedVisitorMap}; use hir::def_id::{CRATE_DEF_INDEX, DefIndex}; -use middle::cstore::InlinedItem; - use syntax::ast::*; use syntax::ext::hygiene::Mark; use syntax::visit; @@ -23,9 +18,6 @@ /// Creates def ids for nodes in the HIR. pub struct DefCollector<'a> { - // If we are walking HIR (c.f., AST), we need to keep a reference to the - // crate. - hir_crate: Option<&'a hir::Crate>, definitions: &'a mut Definitions, parent_def: Option, pub visit_macro_invoc: Option<&'a mut FnMut(MacroInvocationData)>, @@ -40,7 +32,6 @@ pub struct MacroInvocationData { impl<'a> DefCollector<'a> { pub fn new(definitions: &'a mut Definitions) -> Self { DefCollector { - hir_crate: None, definitions: definitions, parent_def: None, visit_macro_invoc: None, @@ -51,13 +42,6 @@ pub fn collect_root(&mut self) { let root = self.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot); assert_eq!(root, CRATE_DEF_INDEX); self.parent_def = Some(root); - - self.create_def_with_parent(Some(CRATE_DEF_INDEX), DUMMY_NODE_ID, DefPathData::Misc); - } - - pub fn walk_item(&mut self, ii: &'a InlinedItem, krate: &'a hir::Crate) { - self.hir_crate = Some(krate); - ii.visit(self); } fn create_def(&mut self, node_id: NodeId, data: DefPathData) -> DefIndex { @@ -95,16 +79,6 @@ pub fn visit_ast_const_integer(&mut self, expr: &Expr) { self.create_def(expr.id, DefPathData::Initializer); } - fn visit_hir_const_integer(&mut self, expr: &hir::Expr) { - // FIXME(eddyb) Closures should have separate - // function definition IDs and expression IDs. - if let hir::ExprClosure(..) = expr.node { - return; - } - - self.create_def(expr.id, DefPathData::Initializer); - } - fn visit_macro_invoc(&mut self, id: NodeId, const_integer: bool) { if let Some(ref mut visit) = self.visit_macro_invoc { visit(MacroInvocationData { @@ -305,169 +279,3 @@ fn visit_stmt(&mut self, stmt: &'a Stmt) { } } } - -// We walk the HIR rather than the AST when reading items from metadata. -impl<'ast> Visitor<'ast> for DefCollector<'ast> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> { - // note however that we override `visit_body` below - NestedVisitorMap::None - } - - fn visit_body(&mut self, id: hir::ExprId) { - if let Some(krate) = self.hir_crate { - self.visit_expr(krate.expr(id)); - } - } - - fn visit_item(&mut self, i: &'ast hir::Item) { - debug!("visit_item: {:?}", i); - - // Pick the def data. This need not be unique, but the more - // information we encapsulate into - let def_data = match i.node { - hir::ItemDefaultImpl(..) | hir::ItemImpl(..) => - DefPathData::Impl, - hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) | - hir::ItemTrait(..) | hir::ItemExternCrate(..) | hir::ItemMod(..) | - hir::ItemForeignMod(..) | hir::ItemTy(..) => - DefPathData::TypeNs(i.name.as_str()), - hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) => - DefPathData::ValueNs(i.name.as_str()), - hir::ItemUse(..) => DefPathData::Misc, - }; - let def = self.create_def(i.id, def_data); - - self.with_parent(def, |this| { - match i.node { - hir::ItemEnum(ref enum_definition, _) => { - for v in &enum_definition.variants { - let variant_def_index = - this.create_def(v.node.data.id(), - DefPathData::EnumVariant(v.node.name.as_str())); - - this.with_parent(variant_def_index, |this| { - for field in v.node.data.fields() { - this.create_def(field.id, - DefPathData::Field(field.name.as_str())); - } - if let Some(ref expr) = v.node.disr_expr { - this.visit_hir_const_integer(expr); - } - }); - } - } - hir::ItemStruct(ref struct_def, _) | - hir::ItemUnion(ref struct_def, _) => { - // If this is a tuple-like struct, register the constructor. - if !struct_def.is_struct() { - this.create_def(struct_def.id(), - DefPathData::StructCtor); - } - - for field in struct_def.fields() { - this.create_def(field.id, DefPathData::Field(field.name.as_str())); - } - } - _ => {} - } - intravisit::walk_item(this, i); - }); - } - - fn visit_foreign_item(&mut self, foreign_item: &'ast hir::ForeignItem) { - let def = self.create_def(foreign_item.id, - DefPathData::ValueNs(foreign_item.name.as_str())); - - self.with_parent(def, |this| { - intravisit::walk_foreign_item(this, foreign_item); - }); - } - - fn visit_generics(&mut self, generics: &'ast hir::Generics) { - for ty_param in generics.ty_params.iter() { - self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.name.as_str())); - } - - intravisit::walk_generics(self, generics); - } - - fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) { - let def_data = match ti.node { - hir::MethodTraitItem(..) | hir::ConstTraitItem(..) => - DefPathData::ValueNs(ti.name.as_str()), - hir::TypeTraitItem(..) => DefPathData::TypeNs(ti.name.as_str()), - }; - - let def = self.create_def(ti.id, def_data); - self.with_parent(def, |this| { - if let hir::ConstTraitItem(_, Some(ref expr)) = ti.node { - this.create_def(expr.id, DefPathData::Initializer); - } - - intravisit::walk_trait_item(this, ti); - }); - } - - fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) { - let def_data = match ii.node { - hir::ImplItemKind::Method(..) | hir::ImplItemKind::Const(..) => - DefPathData::ValueNs(ii.name.as_str()), - hir::ImplItemKind::Type(..) => DefPathData::TypeNs(ii.name.as_str()), - }; - - let def = self.create_def(ii.id, def_data); - self.with_parent(def, |this| { - if let hir::ImplItemKind::Const(_, ref expr) = ii.node { - this.create_def(expr.id, DefPathData::Initializer); - } - - intravisit::walk_impl_item(this, ii); - }); - } - - fn visit_pat(&mut self, pat: &'ast hir::Pat) { - let parent_def = self.parent_def; - - if let hir::PatKind::Binding(_, _, name, _) = pat.node { - let def = self.create_def(pat.id, DefPathData::Binding(name.node.as_str())); - self.parent_def = Some(def); - } - - intravisit::walk_pat(self, pat); - self.parent_def = parent_def; - } - - fn visit_expr(&mut self, expr: &'ast hir::Expr) { - let parent_def = self.parent_def; - - if let hir::ExprRepeat(_, ref count) = expr.node { - self.visit_hir_const_integer(count); - } - - if let hir::ExprClosure(..) = expr.node { - let def = self.create_def(expr.id, DefPathData::ClosureExpr); - self.parent_def = Some(def); - } - - intravisit::walk_expr(self, expr); - self.parent_def = parent_def; - } - - fn visit_ty(&mut self, ty: &'ast hir::Ty) { - if let hir::TyArray(_, ref length) = ty.node { - self.visit_hir_const_integer(length); - } - if let hir::TyImplTrait(..) = ty.node { - self.create_def(ty.id, DefPathData::ImplTrait); - } - intravisit::walk_ty(self, ty); - } - - fn visit_lifetime_def(&mut self, def: &'ast hir::LifetimeDef) { - self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str())); - } - - fn visit_macro_def(&mut self, macro_def: &'ast hir::MacroDef) { - self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.name.as_str())); - } -} diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 7b827b0a7e5..4546f6d8c27 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -226,17 +226,9 @@ pub struct Map<'ast> { /// All NodeIds that are numerically greater or equal to this value come /// from inlined items. local_node_id_watermark: NodeId, - - /// All def-indices that are numerically greater or equal to this value come - /// from inlined items. - local_def_id_watermark: usize, } impl<'ast> Map<'ast> { - pub fn is_inlined_def_id(&self, id: DefId) -> bool { - id.is_local() && id.index.as_usize() >= self.local_def_id_watermark - } - pub fn is_inlined_node_id(&self, id: NodeId) -> bool { id >= self.local_node_id_watermark } @@ -262,7 +254,6 @@ fn dep_node(&self, id0: NodeId) -> DepNode { EntryItem(_, item) => { assert_eq!(id, item.id); let def_id = self.local_def_id(id); - assert!(!self.is_inlined_def_id(def_id)); if let Some(last_id) = last_expr { // The body of the item may have a separate dep node @@ -278,7 +269,6 @@ fn dep_node(&self, id0: NodeId) -> DepNode { EntryImplItem(_, item) => { let def_id = self.local_def_id(id); - assert!(!self.is_inlined_def_id(def_id)); if let Some(last_id) = last_expr { // The body of the item may have a separate dep node @@ -934,7 +924,6 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest, } let local_node_id_watermark = NodeId::new(map.len()); - let local_def_id_watermark = definitions.len(); Map { forest: forest, @@ -942,7 +931,6 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest, map: RefCell::new(map), definitions: definitions, local_node_id_watermark: local_node_id_watermark, - local_def_id_watermark: local_def_id_watermark, } } diff --git a/src/librustc_incremental/persist/hash.rs b/src/librustc_incremental/persist/hash.rs index e5203ea02b4..799cb6c5e3d 100644 --- a/src/librustc_incremental/persist/hash.rs +++ b/src/librustc_incremental/persist/hash.rs @@ -66,11 +66,6 @@ pub fn hash(&mut self, dep_node: &DepNode) -> Option { def_id, self.tcx.item_path_str(def_id)); - assert!(!self.tcx.map.is_inlined_def_id(def_id), - "cannot hash HIR for inlined def-id {:?} => {:?}", - def_id, - self.tcx.item_path_str(def_id)); - Some(self.incremental_hashes_map[dep_node]) } -- 2.44.0