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};
|
2018-02-12 10:21:01 -06:00
|
|
|
use hir::def_id::{LOCAL_CRATE, CrateNum};
|
2016-11-28 13:00:26 -06:00
|
|
|
use hir::intravisit::{Visitor, NestedVisitorMap};
|
2018-08-03 13:22:22 -05:00
|
|
|
use rustc_data_structures::svh::Svh;
|
2018-02-23 13:18:38 -06:00
|
|
|
use ich::Fingerprint;
|
2017-12-01 08:56:37 -06:00
|
|
|
use middle::cstore::CrateStore;
|
2017-10-24 10:49:58 -05:00
|
|
|
use session::CrateDisambiguator;
|
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};
|
2018-08-18 05:14:03 -05:00
|
|
|
use syntax::source_map::SourceMap;
|
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
|
2018-08-25 09:48:42 -05:00
|
|
|
map: Vec<Option<Entry<'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-12-19 11:01:19 -06:00
|
|
|
hir_body_nodes: Vec<(DefPathHash, DepNodeIndex)>,
|
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: _,
|
2017-10-09 11:59:20 -05:00
|
|
|
trait_auto_impl: _,
|
2017-09-14 10:43:03 -05:00
|
|
|
body_ids: _,
|
|
|
|
} = *krate;
|
|
|
|
|
2018-04-06 07:52:36 -05:00
|
|
|
root_mod_sig_dep_index = dep_graph.input_task(
|
2017-09-14 10:43:03 -05:00
|
|
|
root_mod_def_path_hash.to_dep_node(DepKind::Hir),
|
|
|
|
&hcx,
|
|
|
|
HirItemLike { item_like: (module, attrs, span), hash_bodies: false },
|
|
|
|
).1;
|
2018-04-06 07:52:36 -05:00
|
|
|
root_mod_full_dep_index = dep_graph.input_task(
|
2017-09-14 10:43:03 -05:00
|
|
|
root_mod_def_path_hash.to_dep_node(DepKind::HirBody),
|
|
|
|
&hcx,
|
|
|
|
HirItemLike { item_like: (module, attrs, span), hash_bodies: true },
|
|
|
|
).1;
|
|
|
|
}
|
|
|
|
|
2017-08-21 09:44:05 -05:00
|
|
|
{
|
2018-04-06 07:52:36 -05:00
|
|
|
dep_graph.input_task(
|
2017-08-21 09:44:05 -05:00
|
|
|
DepNode::new_no_params(DepKind::AllLocalTraitImpls),
|
|
|
|
&hcx,
|
|
|
|
&krate.trait_impls,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:01:19 -06:00
|
|
|
let hir_body_nodes = vec![(root_mod_def_path_hash, root_mod_full_dep_index)];
|
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
|
|
|
};
|
2018-08-25 09:48:42 -05:00
|
|
|
collector.insert_entry(CRATE_NODE_ID, Entry {
|
2018-08-25 17:10:01 -05:00
|
|
|
parent: CRATE_NODE_ID,
|
2018-08-25 09:48:42 -05:00
|
|
|
dep_node: root_mod_sig_dep_index,
|
2018-08-25 09:56:16 -05:00
|
|
|
node: Node::Crate,
|
2018-08-25 09:48:42 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
|
|
|
|
collector
|
|
|
|
}
|
|
|
|
|
2018-02-23 13:18:38 -06:00
|
|
|
pub(super) fn finalize_and_compute_crate_hash(mut self,
|
2017-12-01 08:56:37 -06:00
|
|
|
crate_disambiguator: CrateDisambiguator,
|
2018-02-23 11:53:00 -06:00
|
|
|
cstore: &dyn CrateStore,
|
2018-08-18 05:14:14 -05:00
|
|
|
source_map: &SourceMap,
|
2017-12-01 08:56:37 -06:00
|
|
|
commandline_args_hash: u64)
|
2018-08-25 09:48:42 -05:00
|
|
|
-> (Vec<Option<Entry<'hir>>>, Svh) {
|
|
|
|
self.hir_body_nodes
|
2018-02-23 13:18:38 -06:00
|
|
|
.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
|
2017-09-14 10:43:03 -05:00
|
|
|
|
2018-02-23 13:18:38 -06:00
|
|
|
let node_hashes = self
|
|
|
|
.hir_body_nodes
|
|
|
|
.iter()
|
|
|
|
.fold(Fingerprint::ZERO, |fingerprint , &(def_path_hash, dep_node_index)| {
|
|
|
|
fingerprint.combine(
|
|
|
|
def_path_hash.0.combine(self.dep_graph.fingerprint_of(dep_node_index))
|
|
|
|
)
|
|
|
|
});
|
2017-09-14 10:43:03 -05:00
|
|
|
|
2017-12-01 08:56:37 -06:00
|
|
|
let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
|
|
|
|
let name = cstore.crate_name_untracked(cnum).as_str();
|
|
|
|
let disambiguator = cstore.crate_disambiguator_untracked(cnum)
|
|
|
|
.to_fingerprint();
|
|
|
|
let hash = cstore.crate_hash_untracked(cnum);
|
|
|
|
(name, disambiguator, hash)
|
|
|
|
}).collect();
|
|
|
|
|
|
|
|
upstream_crates.sort_unstable_by(|&(name1, dis1, _), &(name2, dis2, _)| {
|
|
|
|
(name1, dis1).cmp(&(name2, dis2))
|
|
|
|
});
|
|
|
|
|
2018-02-12 10:21:01 -06:00
|
|
|
// We hash the final, remapped names of all local source files so we
|
|
|
|
// don't have to include the path prefix remapping commandline args.
|
|
|
|
// If we included the full mapping in the SVH, we could only have
|
|
|
|
// reproducible builds by compiling from the same directory. So we just
|
|
|
|
// hash the result of the mapping instead of the mapping itself.
|
2018-08-18 05:14:14 -05:00
|
|
|
let mut source_file_names: Vec<_> = source_map
|
2018-02-12 10:21:01 -06:00
|
|
|
.files()
|
|
|
|
.iter()
|
2018-08-18 05:13:56 -05:00
|
|
|
.filter(|source_file| CrateNum::from_u32(source_file.crate_of_origin) == LOCAL_CRATE)
|
|
|
|
.map(|source_file| source_file.name_hash)
|
2018-02-12 10:21:01 -06:00
|
|
|
.collect();
|
|
|
|
|
|
|
|
source_file_names.sort_unstable();
|
|
|
|
|
2017-12-19 11:01:19 -06:00
|
|
|
let (_, crate_dep_node_index) = self
|
|
|
|
.dep_graph
|
2018-04-06 07:52:36 -05:00
|
|
|
.input_task(DepNode::new_no_params(DepKind::Krate),
|
2017-12-19 11:01:19 -06:00
|
|
|
&self.hcx,
|
2018-02-12 10:21:01 -06:00
|
|
|
(((node_hashes, upstream_crates), source_file_names),
|
2017-12-19 11:01:19 -06:00
|
|
|
(commandline_args_hash,
|
2018-04-06 07:52:36 -05:00
|
|
|
crate_disambiguator.to_fingerprint())));
|
2017-12-19 11:01:19 -06:00
|
|
|
|
|
|
|
let svh = Svh::new(self.dep_graph
|
|
|
|
.fingerprint_of(crate_dep_node_index)
|
|
|
|
.to_smaller_hash());
|
|
|
|
(self.map, svh)
|
2017-08-18 13:24:19 -05:00
|
|
|
}
|
|
|
|
|
2018-08-25 09:48:42 -05:00
|
|
|
fn insert_entry(&mut self, id: NodeId, entry: Entry<'hir>) {
|
2017-01-25 19:21:50 -06:00
|
|
|
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 {
|
2018-08-25 09:48:42 -05:00
|
|
|
self.map.extend(repeat(None).take(id.as_usize() - len + 1));
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
2018-08-25 09:48:42 -05:00
|
|
|
self.map[id.as_usize()] = Some(entry);
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2018-08-25 09:56:16 -05:00
|
|
|
fn insert(&mut self, id: NodeId, node: Node<'hir>) {
|
2018-08-25 09:48:42 -05:00
|
|
|
let entry = Entry {
|
|
|
|
parent: self.parent_node,
|
|
|
|
dep_node: if self.currently_in_body {
|
|
|
|
self.current_full_dep_index
|
|
|
|
} else {
|
|
|
|
self.current_signature_dep_index
|
|
|
|
},
|
|
|
|
node,
|
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) {
|
2018-06-20 03:44:31 -05:00
|
|
|
let hir_id = self.definitions.node_to_hir_id(id);
|
2017-08-18 13:24:19 -05:00
|
|
|
|
2018-06-20 03:44:31 -05:00
|
|
|
if hir_id.owner != self.current_dep_node_owner {
|
2017-08-18 13:24:19 -05:00
|
|
|
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)
|
|
|
|
};
|
|
|
|
|
2018-06-20 03:44:31 -05:00
|
|
|
if hir_id == ::hir::DUMMY_HIR_ID {
|
2018-06-26 07:39:37 -05:00
|
|
|
debug!("Maybe you forgot to lower the node id {:?}?", id);
|
2018-06-20 03:44:31 -05:00
|
|
|
}
|
|
|
|
|
2017-08-18 13:24:19 -05:00
|
|
|
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(),
|
2018-06-20 03:44:31 -05:00
|
|
|
self.definitions.def_path(hir_id.owner).to_string_no_crate())
|
2017-08-18 13:24:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2017-10-26 08:50:29 -05:00
|
|
|
let prev_full_dep_index = self.current_full_dep_index;
|
2017-09-14 10:43:03 -05:00
|
|
|
let prev_in_body = self.currently_in_body;
|
|
|
|
|
|
|
|
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
|
|
|
|
|
2018-04-06 07:52:36 -05:00
|
|
|
self.current_signature_dep_index = self.dep_graph.input_task(
|
2017-09-14 10:43:03 -05:00
|
|
|
def_path_hash.to_dep_node(DepKind::Hir),
|
|
|
|
&self.hcx,
|
|
|
|
HirItemLike { item_like, hash_bodies: false },
|
|
|
|
).1;
|
|
|
|
|
2018-04-06 07:52:36 -05:00
|
|
|
self.current_full_dep_index = self.dep_graph.input_task(
|
2017-09-14 10:43:03 -05:00
|
|
|
def_path_hash.to_dep_node(DepKind::HirBody),
|
|
|
|
&self.hcx,
|
|
|
|
HirItemLike { item_like, hash_bodies: true },
|
|
|
|
).1;
|
|
|
|
|
2017-12-19 11:01:19 -06:00
|
|
|
self.hir_body_nodes.push((def_path_hash, self.current_full_dep_index));
|
2017-09-14 10:43:03 -05:00
|
|
|
|
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| {
|
2018-08-25 09:56:16 -05:00
|
|
|
this.insert(i.id, Node::Item(i));
|
2017-08-18 13:24:19 -05:00
|
|
|
this.with_parent(i.id, |this| {
|
|
|
|
match i.node {
|
2018-07-11 10:36:06 -05:00
|
|
|
ItemKind::Struct(ref struct_def, _) => {
|
2017-08-18 13:24:19 -05:00
|
|
|
// If this is a tuple-like struct, register the constructor.
|
|
|
|
if !struct_def.is_struct() {
|
2018-08-25 09:56:16 -05:00
|
|
|
this.insert(struct_def.id(), Node::StructCtor(struct_def));
|
2017-08-18 13:24:19 -05:00
|
|
|
}
|
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) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(foreign_item.id, Node::ForeignItem(foreign_item));
|
2016-04-13 18:55:34 -05:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-30 06:36:53 -05:00
|
|
|
fn visit_generic_param(&mut self, param: &'hir GenericParam) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(param.id, Node::GenericParam(param));
|
2018-05-30 06:36:53 -05:00
|
|
|
intravisit::walk_generic_param(self, param);
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
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| {
|
2018-08-25 09:56:16 -05:00
|
|
|
this.insert(ti.id, Node::TraitItem(ti));
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
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| {
|
2018-08-25 09:56:16 -05:00
|
|
|
this.insert(ii.id, Node::ImplItem(ii));
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
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 {
|
2018-08-25 09:56:16 -05:00
|
|
|
Node::Binding(pat)
|
2016-04-17 17:30:55 -05:00
|
|
|
} else {
|
2018-08-25 09:56:16 -05:00
|
|
|
Node::Pat(pat)
|
2016-04-17 17:30:55 -05:00
|
|
|
};
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-17 13:28:50 -05:00
|
|
|
fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(constant.id, Node::AnonConst(constant));
|
2018-05-17 13:28:50 -05:00
|
|
|
|
|
|
|
self.with_parent(constant.id, |this| {
|
|
|
|
intravisit::walk_anon_const(this, constant);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_expr(&mut self, expr: &'hir Expr) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(expr.id, Node::Expr(expr));
|
2015-09-10 14:53:08 -05:00
|
|
|
|
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();
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(id, Node::Stmt(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) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(ty.id, Node::Ty(ty));
|
2016-08-05 19:12:20 -05:00
|
|
|
|
|
|
|
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) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(tr.ref_id, Node::TraitRef(tr));
|
2016-10-30 01:04:52 -05:00
|
|
|
|
|
|
|
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) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(block.id, Node::Block(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) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(l.id, Node::Local(l));
|
2017-08-18 01:56:11 -05:00
|
|
|
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) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(lifetime.id, Node::Lifetime(lifetime));
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
2016-10-28 01:52:45 -05:00
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_vis(&mut self, visibility: &'hir Visibility) {
|
2018-06-30 22:34:18 -05:00
|
|
|
match visibility.node {
|
2018-07-01 13:05:10 -05:00
|
|
|
VisibilityKind::Public |
|
|
|
|
VisibilityKind::Crate(_) |
|
|
|
|
VisibilityKind::Inherited => {}
|
|
|
|
VisibilityKind::Restricted { id, .. } => {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(id, Node::Visibility(visibility));
|
2016-10-30 01:04:52 -05:00
|
|
|
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| {
|
2018-08-25 09:56:16 -05:00
|
|
|
this.insert(macro_def.id, Node::MacroDef(macro_def));
|
2017-09-14 10:43:03 -05:00
|
|
|
});
|
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();
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(id, Node::Variant(v));
|
2016-12-21 04:32:59 -06:00
|
|
|
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) {
|
2018-08-25 09:56:16 -05:00
|
|
|
self.insert(field.id, Node::Field(field));
|
2016-11-09 12:57:48 -06:00
|
|
|
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,
|
2018-06-10 14:24:24 -05:00
|
|
|
ident: _,
|
2017-08-18 13:24:19 -05:00
|
|
|
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,
|
2018-06-10 14:24:24 -05:00
|
|
|
ident: _,
|
2017-08-18 13:24:19 -05:00
|
|
|
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
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
|
2018-01-16 03:16:38 -06:00
|
|
|
impl<'a, 'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
|
2017-09-14 10:43:03 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|