hir: remove parent_node from NodeCollector

This commit is contained in:
ljedrz 2019-02-15 12:14:36 +01:00
parent 56bf2c6316
commit 36fffa8196

View file

@ -27,8 +27,6 @@ pub(super) struct NodeCollector<'a, 'hir> {
/// The node map
map: Vec<Option<Entry<'hir>>>,
/// The parent of this node
parent_node: NodeId,
parent_hir: hir::HirId,
// These fields keep track of the currently relevant DepNodes during
@ -149,7 +147,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
krate,
source_map: sess.source_map(),
map: repeat(None).take(sess.current_node_id_count()).collect(),
parent_node: CRATE_NODE_ID,
parent_hir: hir::CRATE_HIR_ID,
current_signature_dep_index: root_mod_sig_dep_index,
current_full_dep_index: root_mod_full_dep_index,
@ -233,7 +230,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
let entry = Entry {
parent: self.parent_node,
parent: self.hir_to_node_id[&self.parent_hir],
parent_hir: self.parent_hir,
dep_node: if self.currently_in_body {
self.current_full_dep_index
@ -286,17 +283,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
fn with_parent<F: FnOnce(&mut Self)>(
&mut self,
parent_node_id: NodeId,
parent_hir_id: HirId,
f: F,
) {
let parent_node = self.parent_node;
self.parent_node = parent_node_id;
let parent_hir = self.parent_hir;
self.parent_hir = parent_hir_id;
f(self);
self.parent_hir = parent_hir;
self.parent_node = parent_node;
}
fn with_dep_node_owner<T: for<'b> HashStable<StableHashingContext<'b>>,
@ -366,7 +359,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.definitions.opt_def_index(i.id).unwrap());
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
this.insert(i.span, i.hir_id, Node::Item(i));
this.with_parent(i.id, i.hir_id, |this| {
this.with_parent(i.hir_id, |this| {
if let ItemKind::Struct(ref struct_def, _) = i.node {
// If this is a tuple-like struct, register the constructor.
if !struct_def.is_struct() {
@ -381,7 +374,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) {
self.insert(foreign_item.span, foreign_item.hir_id, Node::ForeignItem(foreign_item));
self.with_parent(foreign_item.id, foreign_item.hir_id, |this| {
self.with_parent(foreign_item.hir_id, |this| {
intravisit::walk_foreign_item(this, foreign_item);
});
}
@ -397,7 +390,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.with_dep_node_owner(ti.hir_id.owner, ti, |this| {
this.insert(ti.span, ti.hir_id, Node::TraitItem(ti));
this.with_parent(ti.id, ti.hir_id, |this| {
this.with_parent(ti.hir_id, |this| {
intravisit::walk_trait_item(this, ti);
});
});
@ -409,7 +402,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
this.insert(ii.span, ii.hir_id, Node::ImplItem(ii));
this.with_parent(ii.id, ii.hir_id, |this| {
this.with_parent(ii.hir_id, |this| {
intravisit::walk_impl_item(this, ii);
});
});
@ -423,7 +416,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
};
self.insert(pat.span, pat.hir_id, node);
self.with_parent(pat.id, pat.hir_id, |this| {
self.with_parent(pat.hir_id, |this| {
intravisit::walk_pat(this, pat);
});
}
@ -431,7 +424,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
self.insert(DUMMY_SP, constant.hir_id, Node::AnonConst(constant));
self.with_parent(constant.id, constant.hir_id, |this| {
self.with_parent(constant.hir_id, |this| {
intravisit::walk_anon_const(this, constant);
});
}
@ -439,7 +432,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_expr(&mut self, expr: &'hir Expr) {
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
self.with_parent(expr.id, expr.hir_id, |this| {
self.with_parent(expr.hir_id, |this| {
intravisit::walk_expr(this, expr);
});
}
@ -447,7 +440,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_stmt(&mut self, stmt: &'hir Stmt) {
self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
self.with_parent(stmt.id, stmt.hir_id, |this| {
self.with_parent(stmt.hir_id, |this| {
intravisit::walk_stmt(this, stmt);
});
}
@ -463,7 +456,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_ty(&mut self, ty: &'hir Ty) {
self.insert(ty.span, ty.hir_id, Node::Ty(ty));
self.with_parent(ty.id, ty.hir_id, |this| {
self.with_parent(ty.hir_id, |this| {
intravisit::walk_ty(this, ty);
});
}
@ -471,7 +464,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_trait_ref(&mut self, tr: &'hir TraitRef) {
self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr));
self.with_parent(tr.ref_id, tr.hir_ref_id, |this| {
self.with_parent(tr.hir_ref_id, |this| {
intravisit::walk_trait_ref(this, tr);
});
}
@ -484,14 +477,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_block(&mut self, block: &'hir Block) {
self.insert(block.span, block.hir_id, Node::Block(block));
self.with_parent(block.id, block.hir_id, |this| {
self.with_parent(block.hir_id, |this| {
intravisit::walk_block(this, block);
});
}
fn visit_local(&mut self, l: &'hir Local) {
self.insert(l.span, l.hir_id, Node::Local(l));
self.with_parent(l.id, l.hir_id, |this| {
self.with_parent(l.hir_id, |this| {
intravisit::walk_local(this, l)
})
}
@ -505,9 +498,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
VisibilityKind::Public |
VisibilityKind::Crate(_) |
VisibilityKind::Inherited => {}
VisibilityKind::Restricted { id, hir_id, .. } => {
VisibilityKind::Restricted { hir_id, .. } => {
self.insert(visibility.span, hir_id, Node::Visibility(visibility));
self.with_parent(id, hir_id, |this| {
self.with_parent(hir_id, |this| {
intravisit::walk_vis(this, visibility);
});
}
@ -524,14 +517,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: HirId) {
self.insert(v.span, v.node.data.hir_id(), Node::Variant(v));
self.with_parent(v.node.data.id(), v.node.data.hir_id(), |this| {
self.with_parent(v.node.data.hir_id(), |this| {
intravisit::walk_variant(this, v, g, item_id);
});
}
fn visit_struct_field(&mut self, field: &'hir StructField) {
self.insert(field.span, field.hir_id, Node::Field(field));
self.with_parent(field.id, field.hir_id, |this| {
self.with_parent(field.hir_id, |this| {
intravisit::walk_struct_field(this, field);
});
}