use crate::arena::Arena;
-use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex};
use crate::hir::map::definitions::{self, DefPathHash};
-use crate::hir::map::{Entry, HirEntryMap, Map};
+use crate::hir::map::{Entry, Map};
use crate::hir::{HirItem, HirOwner, HirOwnerItems};
use crate::ich::StableHashingContext;
use crate::middle::cstore::CrateStore;
owner_map: FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
owner_items_map: FxHashMap<DefIndex, &'hir mut HirOwnerItems<'hir>>,
- /// The node map
- map: HirEntryMap<'hir>,
/// The parent of this node
parent_node: hir::HirId,
- // These fields keep track of the currently relevant DepNodes during
- // the visitor's traversal.
current_dep_node_owner: DefIndex,
- current_signature_dep_index: DepNodeIndex,
- current_full_dep_index: DepNodeIndex,
- currently_in_body: bool,
- dep_graph: &'a DepGraph,
definitions: &'a definitions::Definitions,
hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
hcx: StableHashingContext<'a>,
// We are collecting `DepNode::HirBody` hashes here so we can compute the
- // crate hash from then later on.
+ // crate hash from them later on.
hir_body_nodes: Vec<(DefPathHash, Fingerprint)>,
}
-fn input_dep_node_and_hash(
- dep_graph: &DepGraph,
+fn hash(
hcx: &mut StableHashingContext<'_>,
- dep_node: DepNode,
input: impl for<'a> HashStable<StableHashingContext<'a>>,
-) -> (DepNodeIndex, Fingerprint) {
- let dep_node_index = dep_graph.input_task(dep_node, &mut *hcx, &input).1;
-
- let hash = if dep_graph.is_fully_enabled() {
- dep_graph.fingerprint_of(dep_node_index)
- } else {
- let mut stable_hasher = StableHasher::new();
- input.hash_stable(hcx, &mut stable_hasher);
- stable_hasher.finish()
- };
-
- (dep_node_index, hash)
+) -> Fingerprint {
+ let mut stable_hasher = StableHasher::new();
+ input.hash_stable(hcx, &mut stable_hasher);
+ stable_hasher.finish()
}
-fn alloc_hir_dep_nodes(
- dep_graph: &DepGraph,
+fn hash_body(
hcx: &mut StableHashingContext<'_>,
def_path_hash: DefPathHash,
item_like: impl for<'a> HashStable<StableHashingContext<'a>>,
hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>,
-) -> (DepNodeIndex, DepNodeIndex) {
- let sig = dep_graph
- .input_task(
- DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
- &mut *hcx,
- HirItemLike { item_like: &item_like, hash_bodies: false },
- )
- .1;
- let (full, hash) = input_dep_node_and_hash(
- dep_graph,
- hcx,
- DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody),
- HirItemLike { item_like: &item_like, hash_bodies: true },
- );
+) {
+ let hash = hash(hcx, HirItemLike { item_like: &item_like });
hir_body_nodes.push((def_path_hash, hash));
- (sig, full)
}
fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(Symbol, Fingerprint, Svh)> {
sess: &'a Session,
arena: &'hir Arena<'hir>,
krate: &'hir Crate<'hir>,
- dep_graph: &'a DepGraph,
definitions: &'a definitions::Definitions,
hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
mut hcx: StableHashingContext<'a>,
let mut hir_body_nodes = Vec::new();
- // Allocate `DepNode`s for the root module.
- let (root_mod_sig_dep_index, root_mod_full_dep_index) = {
+ {
let Crate {
ref item,
// These fields are handled separately:
proc_macros: _,
} = *krate;
- alloc_hir_dep_nodes(
- dep_graph,
- &mut hcx,
- root_mod_def_path_hash,
- item,
- &mut hir_body_nodes,
- )
+ hash_body(&mut hcx, root_mod_def_path_hash, item, &mut hir_body_nodes)
};
let mut collector = NodeCollector {
arena,
krate,
source_map: sess.source_map(),
- map: IndexVec::from_elem_n(IndexVec::new(), definitions.def_index_count()),
parent_node: hir::CRATE_HIR_ID,
- current_signature_dep_index: root_mod_sig_dep_index,
- current_full_dep_index: root_mod_full_dep_index,
current_dep_node_owner: CRATE_DEF_INDEX,
- currently_in_body: false,
- dep_graph,
definitions,
hir_to_node_id,
hcx,
hir_body_nodes,
- owner_map: FxHashMap::default(),
- owner_items_map: FxHashMap::default(),
+ owner_map: FxHashMap::with_capacity_and_hasher(
+ definitions.def_index_count(),
+ Default::default(),
+ ),
+ owner_items_map: FxHashMap::with_capacity_and_hasher(
+ definitions.def_index_count(),
+ Default::default(),
+ ),
};
collector.insert_entry(
hir::CRATE_HIR_ID,
- Entry {
- parent: hir::CRATE_HIR_ID,
- dep_node: root_mod_sig_dep_index,
- node: Node::Crate(&krate.item),
- },
+ Entry { parent: hir::CRATE_HIR_ID, node: Node::Crate(&krate.item) },
);
collector
cstore: &dyn CrateStore,
commandline_args_hash: u64,
) -> (
- HirEntryMap<'hir>,
FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
FxHashMap<DefIndex, &'hir mut HirOwnerItems<'hir>>,
Svh,
let crate_hash: Fingerprint = stable_hasher.finish();
let svh = Svh::new(crate_hash.to_smaller_hash());
- (self.map, self.owner_map, self.owner_items_map, svh)
+ (self.owner_map, self.owner_items_map, svh)
}
fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
items.items[id.local_id] =
Some(HirItem { parent: entry.parent.local_id, node: entry.node });
}
-
- debug!("hir_map: {:?} => {:?}", id, entry);
- let local_map = &mut self.map[id.owner];
- let len = local_map.len();
- if i >= len {
- local_map.extend(repeat(None).take(i - len + 1));
- }
- local_map[id.local_id] = Some(entry);
}
fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
- 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,
- };
+ let entry = Entry { parent: self.parent_node, node };
// Make sure that the DepNode of some node coincides with the HirId
// owner of that node.
f: F,
) {
let prev_owner = self.current_dep_node_owner;
- let prev_signature_dep_index = self.current_signature_dep_index;
- let prev_full_dep_index = self.current_full_dep_index;
- let prev_in_body = self.currently_in_body;
let def_path_hash = self.definitions.def_path_hash(dep_node_owner);
- let (signature_dep_index, full_dep_index) = alloc_hir_dep_nodes(
- self.dep_graph,
- &mut self.hcx,
- def_path_hash,
- item_like,
- &mut self.hir_body_nodes,
- );
- self.current_signature_dep_index = signature_dep_index;
- self.current_full_dep_index = full_dep_index;
+ hash_body(&mut self.hcx, def_path_hash, item_like, &mut self.hir_body_nodes);
self.current_dep_node_owner = dep_node_owner;
- self.currently_in_body = false;
f(self);
- self.currently_in_body = prev_in_body;
self.current_dep_node_owner = prev_owner;
- self.current_full_dep_index = prev_full_dep_index;
- self.current_signature_dep_index = prev_signature_dep_index;
}
}
}
fn visit_nested_body(&mut self, id: BodyId) {
- let prev_in_body = self.currently_in_body;
- self.currently_in_body = true;
self.visit_body(self.krate.body(id));
- self.currently_in_body = prev_in_body;
}
fn visit_param(&mut self, param: &'hir Param<'hir>) {
}
}
-// This is a wrapper structure that allows determining if span values within
-// the wrapped item should be hashed or not.
struct HirItemLike<T> {
item_like: T,
- hash_bodies: bool,
}
impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
T: HashStable<StableHashingContext<'hir>>,
{
fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) {
- hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| {
+ hcx.while_hashing_hir_bodies(true, |hcx| {
self.item_like.hash_stable(hcx, hasher);
});
}
};
use crate::arena::Arena;
-use crate::dep_graph::{DepGraph, DepNodeIndex};
use crate::hir::{HirOwner, HirOwnerItems};
use crate::middle::cstore::CrateStoreDyn;
use crate::ty::query::Providers;
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::print::Nested;
use rustc_hir::*;
-use rustc_index::vec::IndexVec;
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::kw;
#[derive(Copy, Clone, Debug)]
pub struct Entry<'hir> {
parent: HirId,
- dep_node: DepNodeIndex,
node: Node<'hir>,
}
}
}
-/// This type is effectively a `HashMap<HirId, Entry<'hir>>`,
-/// but it is implemented as 2 layers of arrays.
-/// - first we have `A = IndexVec<DefIndex, B>` mapping `DefIndex`s to an inner value
-/// - which is `B = IndexVec<ItemLocalId, Option<Entry<'hir>>` which gives you the `Entry`.
-pub(super) type HirEntryMap<'hir> = IndexVec<DefIndex, IndexVec<ItemLocalId, Option<Entry<'hir>>>>;
-
/// Represents a mapping from `NodeId`s to AST elements and their parent `NodeId`s.
pub struct EarlyMap<'hir> {
pub krate: &'hir Crate<'hir>,
- pub dep_graph: DepGraph,
-
/// The SVH of the local crate.
pub crate_hash: Svh,
pub(super) owner_map: FxHashMap<DefIndex, &'hir HirOwner<'hir>>,
pub(super) owner_items_map: FxHashMap<DefIndex, &'hir HirOwnerItems<'hir>>,
- pub(super) map: HirEntryMap<'hir>,
-
pub(crate) definitions: &'hir Definitions,
/// The reverse mapping of `node_to_hir_id`.
pub(super) krate: &'hir Crate<'hir>,
- pub dep_graph: DepGraph,
-
/// The SVH of the local crate.
pub crate_hash: Svh,
fn get_entry(&self, id: HirId) -> Entry<'hir> {
if id.local_id == ItemLocalId::from_u32_const(0) {
let owner = self.tcx.hir_owner(id.owner_def_id());
- Entry { parent: owner.parent, node: owner.node, dep_node: DepNodeIndex::INVALID }
+ Entry { parent: owner.parent, node: owner.node }
} else {
let owner = self.tcx.hir_owner_items(id.owner_def_id());
let item = owner.items[id.local_id].as_ref().unwrap();
- Entry {
- parent: HirId { owner: id.owner, local_id: item.parent },
- node: item.node,
- dep_node: DepNodeIndex::INVALID,
- }
+ Entry { parent: HirId { owner: id.owner, local_id: item.parent }, node: item.node }
}
}
arena: &'hir Arena<'hir>,
cstore: &CrateStoreDyn,
krate: &'hir Crate<'hir>,
- dep_graph: DepGraph,
definitions: Definitions,
) -> EarlyMap<'hir> {
let _prof_timer = sess.prof.generic_activity("build_hir_map");
.map(|(node_id, &hir_id)| (hir_id, node_id))
.collect();
- let (map, owner_map, owner_items_map, crate_hash) = {
+ let (owner_map, owner_items_map, crate_hash) = {
let hcx = crate::ich::StableHashingContext::new(sess, krate, &definitions, cstore);
let mut collector =
- NodeCollector::root(sess, arena, krate, &dep_graph, &definitions, &hir_to_node_id, hcx);
+ NodeCollector::root(sess, arena, krate, &definitions, &hir_to_node_id, hcx);
intravisit::walk_crate(&mut collector, krate);
let crate_disambiguator = sess.local_crate_disambiguator();
let map = EarlyMap {
krate,
- dep_graph,
crate_hash,
- map,
owner_map,
owner_items_map: owner_items_map.into_iter().map(|(k, v)| (k, &*v)).collect(),
hir_to_node_id,