2016-04-13 19:14:03 -05:00
|
|
|
// Copyright 2015-2016 The Rust Project Developers. See the COPYRIGHT
|
2015-09-10 14:53:08 -05:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
2017-08-18 13:24:19 -05:00
|
|
|
use dep_graph::{DepGraph, DepKind, DepNodeIndex};
|
2017-10-23 11:44:58 -05:00
|
|
|
use ich::Fingerprint;
|
2016-11-28 13:00:26 -06:00
|
|
|
use hir::intravisit::{Visitor, NestedVisitorMap};
|
2015-09-10 14:53:08 -05:00
|
|
|
use std::iter::repeat;
|
2016-04-13 19:14:03 -05:00
|
|
|
use syntax::ast::{NodeId, CRATE_NODE_ID};
|
2016-06-21 17:08:13 -05:00
|
|
|
use syntax_pos::Span;
|
2015-09-10 14:53:08 -05:00
|
|
|
|
2017-09-14 10:43:03 -05:00
|
|
|
use ich::StableHashingContext;
|
|
|
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
|
|
|
|
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A Visitor that walks over the HIR and collects Nodes into a HIR map
|
2017-08-18 13:24:19 -05:00
|
|
|
pub(super) struct NodeCollector<'a, 'hir> {
|
2015-12-21 15:24:15 -06:00
|
|
|
/// The crate
|
2017-08-18 13:24:19 -05:00
|
|
|
krate: &'hir Crate,
|
2015-12-21 15:24:15 -06:00
|
|
|
/// The node map
|
2017-08-18 13:24:19 -05:00
|
|
|
map: Vec<MapEntry<'hir>>,
|
2015-12-21 15:24:15 -06:00
|
|
|
/// The parent of this node
|
2017-08-18 13:24:19 -05:00
|
|
|
parent_node: NodeId,
|
|
|
|
|
2017-09-19 05:13:09 -05:00
|
|
|
// These fields keep track of the currently relevant DepNodes during
|
|
|
|
// the visitor's traversal.
|
2017-08-18 13:24:19 -05:00
|
|
|
current_dep_node_owner: DefIndex,
|
2017-09-14 10:43:03 -05:00
|
|
|
current_signature_dep_index: DepNodeIndex,
|
|
|
|
current_full_dep_index: DepNodeIndex,
|
|
|
|
currently_in_body: bool,
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
dep_graph: &'a DepGraph,
|
|
|
|
definitions: &'a definitions::Definitions,
|
2017-09-14 10:43:03 -05:00
|
|
|
|
|
|
|
hcx: StableHashingContext<'a>,
|
|
|
|
|
2017-09-19 05:13:09 -05:00
|
|
|
// We are collecting DepNode::HirBody hashes here so we can compute the
|
|
|
|
// crate hash from then later on.
|
2017-09-14 10:43:03 -05:00
|
|
|
hir_body_nodes: Vec<DefPathHash>,
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2017-08-18 13:24:19 -05:00
|
|
|
impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
|
|
|
pub(super) fn root(krate: &'hir Crate,
|
2017-09-14 10:43:03 -05:00
|
|
|
dep_graph: &'a DepGraph,
|
|
|
|
definitions: &'a definitions::Definitions,
|
|
|
|
hcx: StableHashingContext<'a>)
|
2017-08-18 13:24:19 -05:00
|
|
|
-> NodeCollector<'a, 'hir> {
|
|
|
|
let root_mod_def_path_hash = definitions.def_path_hash(CRATE_DEF_INDEX);
|
2017-09-14 10:43:03 -05:00
|
|
|
|
|
|
|
// Allocate DepNodes for the root module
|
|
|
|
let (root_mod_sig_dep_index, root_mod_full_dep_index);
|
|
|
|
{
|
|
|
|
let Crate {
|
|
|
|
ref module,
|
|
|
|
// Crate attributes are not copied over to the root `Mod`, so hash
|
|
|
|
// them explicitly here.
|
|
|
|
ref attrs,
|
|
|
|
span,
|
|
|
|
|
|
|
|
// These fields are handled separately:
|
|
|
|
exported_macros: _,
|
|
|
|
items: _,
|
|
|
|
trait_items: _,
|
|
|
|
impl_items: _,
|
|
|
|
bodies: _,
|
|
|
|
trait_impls: _,
|
|
|
|
trait_default_impl: _,
|
|
|
|
body_ids: _,
|
|
|
|
} = *krate;
|
|
|
|
|
|
|
|
root_mod_sig_dep_index = dep_graph.with_task(
|
|
|
|
root_mod_def_path_hash.to_dep_node(DepKind::Hir),
|
|
|
|
&hcx,
|
|
|
|
HirItemLike { item_like: (module, attrs, span), hash_bodies: false },
|
|
|
|
identity_fn
|
|
|
|
).1;
|
|
|
|
root_mod_full_dep_index = dep_graph.with_task(
|
|
|
|
root_mod_def_path_hash.to_dep_node(DepKind::HirBody),
|
|
|
|
&hcx,
|
|
|
|
HirItemLike { item_like: (module, attrs, span), hash_bodies: true },
|
|
|
|
identity_fn
|
|
|
|
).1;
|
|
|
|
}
|
|
|
|
|
2017-08-21 09:44:05 -05:00
|
|
|
{
|
|
|
|
dep_graph.with_task(
|
|
|
|
DepNode::new_no_params(DepKind::AllLocalTraitImpls),
|
|
|
|
&hcx,
|
|
|
|
&krate.trait_impls,
|
|
|
|
identity_fn
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-09-14 10:43:03 -05:00
|
|
|
let hir_body_nodes = vec![root_mod_def_path_hash];
|
2017-08-18 13:24:19 -05:00
|
|
|
|
2016-04-13 18:55:34 -05:00
|
|
|
let mut collector = NodeCollector {
|
2017-07-03 13:19:51 -05:00
|
|
|
krate,
|
2016-04-13 18:55:34 -05:00
|
|
|
map: vec![],
|
|
|
|
parent_node: CRATE_NODE_ID,
|
2017-09-14 10:43:03 -05:00
|
|
|
current_signature_dep_index: root_mod_sig_dep_index,
|
|
|
|
current_full_dep_index: root_mod_full_dep_index,
|
2017-08-18 13:24:19 -05:00
|
|
|
current_dep_node_owner: CRATE_DEF_INDEX,
|
2017-09-14 10:43:03 -05:00
|
|
|
currently_in_body: false,
|
2017-08-18 13:24:19 -05:00
|
|
|
dep_graph,
|
|
|
|
definitions,
|
2017-09-14 10:43:03 -05:00
|
|
|
hcx,
|
|
|
|
hir_body_nodes,
|
2016-04-13 18:55:34 -05:00
|
|
|
};
|
2017-09-14 10:43:03 -05:00
|
|
|
collector.insert_entry(CRATE_NODE_ID, RootCrate(root_mod_sig_dep_index));
|
2016-04-13 18:55:34 -05:00
|
|
|
|
|
|
|
collector
|
|
|
|
}
|
|
|
|
|
2017-09-14 10:43:03 -05:00
|
|
|
pub(super) fn finalize_and_compute_crate_hash(self,
|
2017-10-23 11:44:58 -05:00
|
|
|
crate_disambiguator: &Fingerprint)
|
2017-09-14 10:43:03 -05:00
|
|
|
-> Vec<MapEntry<'hir>> {
|
|
|
|
let mut node_hashes: Vec<_> = self
|
|
|
|
.hir_body_nodes
|
|
|
|
.iter()
|
|
|
|
.map(|&def_path_hash| {
|
|
|
|
let dep_node = def_path_hash.to_dep_node(DepKind::HirBody);
|
|
|
|
(def_path_hash, self.dep_graph.fingerprint_of(&dep_node))
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
node_hashes.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
|
|
|
|
|
|
|
|
self.dep_graph.with_task(DepNode::new_no_params(DepKind::Krate),
|
|
|
|
&self.hcx,
|
|
|
|
(node_hashes, crate_disambiguator),
|
|
|
|
identity_fn);
|
2017-08-18 13:24:19 -05:00
|
|
|
self.map
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'hir>) {
|
|
|
|
debug!("hir_map: {:?} => {:?}", id, entry);
|
2016-04-13 18:55:34 -05:00
|
|
|
let len = self.map.len();
|
2016-08-31 06:00:29 -05:00
|
|
|
if id.as_usize() >= len {
|
|
|
|
self.map.extend(repeat(NotPresent).take(id.as_usize() - len + 1));
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
2016-08-31 06:00:29 -05:00
|
|
|
self.map[id.as_usize()] = entry;
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn insert(&mut self, id: NodeId, node: Node<'hir>) {
|
2017-08-18 13:24:19 -05:00
|
|
|
let parent = self.parent_node;
|
2017-09-14 10:43:03 -05:00
|
|
|
let dep_node_index = if self.currently_in_body {
|
|
|
|
self.current_full_dep_index
|
|
|
|
} else {
|
|
|
|
self.current_signature_dep_index
|
|
|
|
};
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
let entry = match node {
|
|
|
|
NodeItem(n) => EntryItem(parent, dep_node_index, n),
|
|
|
|
NodeForeignItem(n) => EntryForeignItem(parent, dep_node_index, n),
|
|
|
|
NodeTraitItem(n) => EntryTraitItem(parent, dep_node_index, n),
|
|
|
|
NodeImplItem(n) => EntryImplItem(parent, dep_node_index, n),
|
|
|
|
NodeVariant(n) => EntryVariant(parent, dep_node_index, n),
|
|
|
|
NodeField(n) => EntryField(parent, dep_node_index, n),
|
|
|
|
NodeExpr(n) => EntryExpr(parent, dep_node_index, n),
|
|
|
|
NodeStmt(n) => EntryStmt(parent, dep_node_index, n),
|
|
|
|
NodeTy(n) => EntryTy(parent, dep_node_index, n),
|
|
|
|
NodeTraitRef(n) => EntryTraitRef(parent, dep_node_index, n),
|
|
|
|
NodeBinding(n) => EntryBinding(parent, dep_node_index, n),
|
|
|
|
NodePat(n) => EntryPat(parent, dep_node_index, n),
|
|
|
|
NodeBlock(n) => EntryBlock(parent, dep_node_index, n),
|
|
|
|
NodeStructCtor(n) => EntryStructCtor(parent, dep_node_index, n),
|
|
|
|
NodeLifetime(n) => EntryLifetime(parent, dep_node_index, n),
|
|
|
|
NodeTyParam(n) => EntryTyParam(parent, dep_node_index, n),
|
|
|
|
NodeVisibility(n) => EntryVisibility(parent, dep_node_index, n),
|
|
|
|
NodeLocal(n) => EntryLocal(parent, dep_node_index, n),
|
2017-09-14 10:43:03 -05:00
|
|
|
NodeMacroDef(n) => EntryMacroDef(dep_node_index, n),
|
2017-08-18 13:24:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure that the DepNode of some node coincides with the HirId
|
|
|
|
// owner of that node.
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
let hir_id_owner = self.definitions.node_to_hir_id(id).owner;
|
|
|
|
|
|
|
|
if hir_id_owner != self.current_dep_node_owner {
|
|
|
|
let node_str = match self.definitions.opt_def_index(id) {
|
|
|
|
Some(def_index) => {
|
|
|
|
self.definitions.def_path(def_index).to_string_no_crate()
|
|
|
|
}
|
|
|
|
None => format!("{:?}", node)
|
|
|
|
};
|
|
|
|
|
|
|
|
bug!("inconsistent DepNode for `{}`: \
|
|
|
|
current_dep_node_owner={}, hir_id.owner={}",
|
|
|
|
node_str,
|
|
|
|
self.definitions
|
|
|
|
.def_path(self.current_dep_node_owner)
|
|
|
|
.to_string_no_crate(),
|
|
|
|
self.definitions.def_path(hir_id_owner).to_string_no_crate())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:55:34 -05:00
|
|
|
self.insert_entry(id, entry);
|
2017-08-18 13:24:19 -05:00
|
|
|
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
2016-04-14 00:24:30 -05:00
|
|
|
|
|
|
|
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_id: NodeId, f: F) {
|
|
|
|
let parent_node = self.parent_node;
|
|
|
|
self.parent_node = parent_id;
|
|
|
|
f(self);
|
|
|
|
self.parent_node = parent_node;
|
|
|
|
}
|
2017-08-18 13:24:19 -05:00
|
|
|
|
2017-09-14 10:43:03 -05:00
|
|
|
fn with_dep_node_owner<T: HashStable<StableHashingContext<'a>>,
|
|
|
|
F: FnOnce(&mut Self)>(&mut self,
|
2017-08-18 13:24:19 -05:00
|
|
|
dep_node_owner: DefIndex,
|
2017-09-14 10:43:03 -05:00
|
|
|
item_like: &T,
|
2017-08-18 13:24:19 -05:00
|
|
|
f: F) {
|
|
|
|
let prev_owner = self.current_dep_node_owner;
|
2017-09-14 10:43:03 -05:00
|
|
|
let prev_signature_dep_index = self.current_signature_dep_index;
|
|
|
|
let prev_full_dep_index = self.current_signature_dep_index;
|
|
|
|
let prev_in_body = self.currently_in_body;
|
|
|
|
|
|
|
|
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
|
|
|
|
|
|
|
|
self.current_signature_dep_index = self.dep_graph.with_task(
|
|
|
|
def_path_hash.to_dep_node(DepKind::Hir),
|
|
|
|
&self.hcx,
|
|
|
|
HirItemLike { item_like, hash_bodies: false },
|
|
|
|
identity_fn
|
|
|
|
).1;
|
|
|
|
|
|
|
|
self.current_full_dep_index = self.dep_graph.with_task(
|
|
|
|
def_path_hash.to_dep_node(DepKind::HirBody),
|
|
|
|
&self.hcx,
|
|
|
|
HirItemLike { item_like, hash_bodies: true },
|
|
|
|
identity_fn
|
|
|
|
).1;
|
|
|
|
|
|
|
|
self.hir_body_nodes.push(def_path_hash);
|
|
|
|
|
2017-08-18 13:24:19 -05:00
|
|
|
self.current_dep_node_owner = dep_node_owner;
|
2017-09-14 10:43:03 -05:00
|
|
|
self.currently_in_body = false;
|
2017-08-18 13:24:19 -05:00
|
|
|
f(self);
|
2017-09-14 10:43:03 -05:00
|
|
|
self.currently_in_body = prev_in_body;
|
2017-08-18 13:24:19 -05:00
|
|
|
self.current_dep_node_owner = prev_owner;
|
2017-09-14 10:43:03 -05:00
|
|
|
self.current_full_dep_index = prev_full_dep_index;
|
|
|
|
self.current_signature_dep_index = prev_signature_dep_index;
|
2017-08-18 13:24:19 -05:00
|
|
|
}
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2017-08-18 13:24:19 -05:00
|
|
|
impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
2016-04-13 18:55:34 -05:00
|
|
|
/// Because we want to track parent items and so forth, enable
|
|
|
|
/// deep walking so that we walk nested items in the context of
|
|
|
|
/// their outer items.
|
2016-11-09 15:45:26 -06:00
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
|
2016-11-09 15:45:26 -06:00
|
|
|
panic!("visit_nested_xxx must be manually implemented in this visitor")
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:55:34 -05:00
|
|
|
fn visit_nested_item(&mut self, item: ItemId) {
|
|
|
|
debug!("visit_nested_item: {:?}", item);
|
2017-01-03 20:01:58 -06:00
|
|
|
self.visit_item(self.krate.item(item.id));
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2016-12-03 20:21:06 -06:00
|
|
|
fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
|
2017-01-03 20:01:58 -06:00
|
|
|
self.visit_trait_item(self.krate.trait_item(item_id));
|
2016-12-03 20:21:06 -06:00
|
|
|
}
|
|
|
|
|
2016-11-04 17:20:15 -05:00
|
|
|
fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
|
2017-01-03 20:01:58 -06:00
|
|
|
self.visit_impl_item(self.krate.impl_item(item_id));
|
2016-11-04 17:20:15 -05:00
|
|
|
}
|
|
|
|
|
2016-12-21 04:32:59 -06:00
|
|
|
fn visit_nested_body(&mut self, id: BodyId) {
|
2017-09-14 10:43:03 -05:00
|
|
|
let prev_in_body = self.currently_in_body;
|
|
|
|
self.currently_in_body = true;
|
2017-01-03 20:01:58 -06:00
|
|
|
self.visit_body(self.krate.body(id));
|
2017-09-14 10:43:03 -05:00
|
|
|
self.currently_in_body = prev_in_body;
|
2016-10-28 15:58:32 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_item(&mut self, i: &'hir Item) {
|
2016-04-13 18:55:34 -05:00
|
|
|
debug!("visit_item: {:?}", i);
|
2017-08-18 13:24:19 -05:00
|
|
|
debug_assert_eq!(i.hir_id.owner,
|
|
|
|
self.definitions.opt_def_index(i.id).unwrap());
|
2017-09-14 10:43:03 -05:00
|
|
|
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
|
2017-08-18 13:24:19 -05:00
|
|
|
this.insert(i.id, NodeItem(i));
|
|
|
|
this.with_parent(i.id, |this| {
|
|
|
|
match i.node {
|
|
|
|
ItemStruct(ref struct_def, _) => {
|
|
|
|
// If this is a tuple-like struct, register the constructor.
|
|
|
|
if !struct_def.is_struct() {
|
|
|
|
this.insert(struct_def.id(), NodeStructCtor(struct_def));
|
|
|
|
}
|
2016-04-14 00:24:30 -05:00
|
|
|
}
|
2017-08-18 13:24:19 -05:00
|
|
|
_ => {}
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
2017-08-18 13:24:19 -05:00
|
|
|
intravisit::walk_item(this, i);
|
|
|
|
});
|
2016-04-14 00:24:30 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) {
|
2016-04-13 18:55:34 -05:00
|
|
|
self.insert(foreign_item.id, NodeForeignItem(foreign_item));
|
|
|
|
|
2016-04-14 00:24:30 -05:00
|
|
|
self.with_parent(foreign_item.id, |this| {
|
|
|
|
intravisit::walk_foreign_item(this, foreign_item);
|
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_generics(&mut self, generics: &'hir Generics) {
|
2016-04-13 18:55:34 -05:00
|
|
|
for ty_param in generics.ty_params.iter() {
|
|
|
|
self.insert(ty_param.id, NodeTyParam(ty_param));
|
|
|
|
}
|
|
|
|
|
|
|
|
intravisit::walk_generics(self, generics);
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_trait_item(&mut self, ti: &'hir TraitItem) {
|
2017-08-18 13:24:19 -05:00
|
|
|
debug_assert_eq!(ti.hir_id.owner,
|
|
|
|
self.definitions.opt_def_index(ti.id).unwrap());
|
2017-09-14 10:43:03 -05:00
|
|
|
self.with_dep_node_owner(ti.hir_id.owner, ti, |this| {
|
2017-08-18 13:24:19 -05:00
|
|
|
this.insert(ti.id, NodeTraitItem(ti));
|
|
|
|
|
|
|
|
this.with_parent(ti.id, |this| {
|
|
|
|
intravisit::walk_trait_item(this, ti);
|
|
|
|
});
|
2016-04-14 00:24:30 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_impl_item(&mut self, ii: &'hir ImplItem) {
|
2017-08-18 13:24:19 -05:00
|
|
|
debug_assert_eq!(ii.hir_id.owner,
|
|
|
|
self.definitions.opt_def_index(ii.id).unwrap());
|
2017-09-14 10:43:03 -05:00
|
|
|
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
|
2017-08-18 13:24:19 -05:00
|
|
|
this.insert(ii.id, NodeImplItem(ii));
|
|
|
|
|
|
|
|
this.with_parent(ii.id, |this| {
|
|
|
|
intravisit::walk_impl_item(this, ii);
|
|
|
|
});
|
2016-04-14 00:24:30 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_pat(&mut self, pat: &'hir Pat) {
|
2016-03-06 06:54:44 -06:00
|
|
|
let node = if let PatKind::Binding(..) = pat.node {
|
2017-08-18 01:00:57 -05:00
|
|
|
NodeBinding(pat)
|
2016-04-17 17:30:55 -05:00
|
|
|
} else {
|
|
|
|
NodePat(pat)
|
|
|
|
};
|
|
|
|
self.insert(pat.id, node);
|
2015-09-10 14:53:08 -05:00
|
|
|
|
2016-04-14 00:24:30 -05:00
|
|
|
self.with_parent(pat.id, |this| {
|
|
|
|
intravisit::walk_pat(this, pat);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_expr(&mut self, expr: &'hir Expr) {
|
2015-09-10 14:53:08 -05:00
|
|
|
self.insert(expr.id, NodeExpr(expr));
|
|
|
|
|
2016-04-14 00:24:30 -05:00
|
|
|
self.with_parent(expr.id, |this| {
|
|
|
|
intravisit::walk_expr(this, expr);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_stmt(&mut self, stmt: &'hir Stmt) {
|
2016-03-29 01:32:58 -05:00
|
|
|
let id = stmt.node.id();
|
2015-09-10 14:53:08 -05:00
|
|
|
self.insert(id, NodeStmt(stmt));
|
2016-04-14 00:24:30 -05:00
|
|
|
|
|
|
|
self.with_parent(id, |this| {
|
|
|
|
intravisit::walk_stmt(this, stmt);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_ty(&mut self, ty: &'hir Ty) {
|
2016-08-05 19:12:20 -05:00
|
|
|
self.insert(ty.id, NodeTy(ty));
|
|
|
|
|
|
|
|
self.with_parent(ty.id, |this| {
|
|
|
|
intravisit::walk_ty(this, ty);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_trait_ref(&mut self, tr: &'hir TraitRef) {
|
2016-10-30 01:04:52 -05:00
|
|
|
self.insert(tr.ref_id, NodeTraitRef(tr));
|
|
|
|
|
|
|
|
self.with_parent(tr.ref_id, |this| {
|
|
|
|
intravisit::walk_trait_ref(this, tr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_fn(&mut self, fk: intravisit::FnKind<'hir>, fd: &'hir FnDecl,
|
2016-12-21 04:32:59 -06:00
|
|
|
b: BodyId, s: Span, id: NodeId) {
|
2015-09-29 05:47:33 -05:00
|
|
|
assert_eq!(self.parent_node, id);
|
2016-07-28 04:58:45 -05:00
|
|
|
intravisit::walk_fn(self, fk, fd, b, s, id);
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_block(&mut self, block: &'hir Block) {
|
2015-09-10 14:53:08 -05:00
|
|
|
self.insert(block.id, NodeBlock(block));
|
2016-04-14 00:24:30 -05:00
|
|
|
self.with_parent(block.id, |this| {
|
|
|
|
intravisit::walk_block(this, block);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2017-08-18 01:56:11 -05:00
|
|
|
fn visit_local(&mut self, l: &'hir Local) {
|
|
|
|
self.insert(l.id, NodeLocal(l));
|
|
|
|
self.with_parent(l.id, |this| {
|
|
|
|
intravisit::walk_local(this, l)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
|
2015-09-10 14:53:08 -05:00
|
|
|
self.insert(lifetime.id, NodeLifetime(lifetime));
|
|
|
|
}
|
2016-10-28 01:52:45 -05:00
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_vis(&mut self, visibility: &'hir Visibility) {
|
2016-10-30 01:04:52 -05:00
|
|
|
match *visibility {
|
|
|
|
Visibility::Public |
|
|
|
|
Visibility::Crate |
|
|
|
|
Visibility::Inherited => {}
|
|
|
|
Visibility::Restricted { id, .. } => {
|
|
|
|
self.insert(id, NodeVisibility(visibility));
|
|
|
|
self.with_parent(id, |this| {
|
|
|
|
intravisit::walk_vis(this, visibility);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) {
|
2017-09-14 10:43:03 -05:00
|
|
|
let def_index = self.definitions.opt_def_index(macro_def.id).unwrap();
|
|
|
|
|
|
|
|
self.with_dep_node_owner(def_index, macro_def, |this| {
|
|
|
|
this.insert(macro_def.id, NodeMacroDef(macro_def));
|
|
|
|
});
|
2016-10-28 01:52:45 -05:00
|
|
|
}
|
2016-11-09 12:57:48 -06:00
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: NodeId) {
|
2016-12-21 04:32:59 -06:00
|
|
|
let id = v.node.data.id();
|
|
|
|
self.insert(id, NodeVariant(v));
|
|
|
|
self.with_parent(id, |this| {
|
|
|
|
intravisit::walk_variant(this, v, g, item_id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_struct_field(&mut self, field: &'hir StructField) {
|
2016-11-09 12:57:48 -06:00
|
|
|
self.insert(field.id, NodeField(field));
|
|
|
|
self.with_parent(field.id, |this| {
|
|
|
|
intravisit::walk_struct_field(this, field);
|
|
|
|
});
|
|
|
|
}
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
fn visit_trait_item_ref(&mut self, ii: &'hir TraitItemRef) {
|
|
|
|
// Do not visit the duplicate information in TraitItemRef. We want to
|
|
|
|
// map the actual nodes, not the duplicate ones in the *Ref.
|
|
|
|
let TraitItemRef {
|
|
|
|
id,
|
|
|
|
name: _,
|
|
|
|
kind: _,
|
|
|
|
span: _,
|
|
|
|
defaultness: _,
|
|
|
|
} = *ii;
|
|
|
|
|
|
|
|
self.visit_nested_trait_item(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef) {
|
|
|
|
// Do not visit the duplicate information in ImplItemRef. We want to
|
|
|
|
// map the actual nodes, not the duplicate ones in the *Ref.
|
|
|
|
let ImplItemRef {
|
|
|
|
id,
|
|
|
|
name: _,
|
|
|
|
kind: _,
|
|
|
|
span: _,
|
|
|
|
vis: _,
|
|
|
|
defaultness: _,
|
|
|
|
} = *ii;
|
|
|
|
|
|
|
|
self.visit_nested_impl_item(id);
|
|
|
|
}
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
2017-09-14 10:43:03 -05:00
|
|
|
|
2017-09-19 05:13:09 -05:00
|
|
|
// We use this with DepGraph::with_task(). Since we are handling only input
|
|
|
|
// values here, the "task" computing them just passes them through.
|
2017-09-14 10:43:03 -05:00
|
|
|
fn identity_fn<T>(_: &StableHashingContext, item_like: T) -> T {
|
|
|
|
item_like
|
|
|
|
}
|
|
|
|
|
2017-09-19 05:13:09 -05:00
|
|
|
// This is a wrapper structure that allows determining if span values within
|
|
|
|
// the wrapped item should be hashed or not.
|
2017-09-14 10:43:03 -05:00
|
|
|
struct HirItemLike<T> {
|
|
|
|
item_like: T,
|
|
|
|
hash_bodies: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
|
|
|
|
where T: HashStable<StableHashingContext<'hir>>
|
|
|
|
{
|
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
|
|
|
hcx: &mut StableHashingContext<'hir>,
|
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| {
|
|
|
|
self.item_like.hash_stable(hcx, hasher);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|