use crate::hir::{HirItem, HirOwner, HirOwnerItems};
use crate::ich::StableHashingContext;
use crate::middle::cstore::CrateStore;
-use rustc_ast::ast::NodeId;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
current_dep_node_owner: DefIndex,
definitions: &'a definitions::Definitions,
- hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
hcx: StableHashingContext<'a>,
arena: &'hir Arena<'hir>,
krate: &'hir Crate<'hir>,
definitions: &'a definitions::Definitions,
- hir_to_node_id: &'a FxHashMap<HirId, NodeId>,
mut hcx: StableHashingContext<'a>,
) -> NodeCollector<'a, 'hir> {
let root_mod_def_path_hash = definitions.def_path_hash(CRATE_DEF_INDEX);
parent_node: hir::CRATE_HIR_ID,
current_dep_node_owner: CRATE_DEF_INDEX,
definitions,
- hir_to_node_id,
hcx,
hir_body_nodes,
map: (0..definitions.def_index_count())
// Make sure that the DepNode of some node coincides with the HirId
// owner of that node.
if cfg!(debug_assertions) {
- let node_id = self.hir_to_node_id[&hir_id];
+ let node_id = self.definitions.hir_to_node_id(hir_id);
assert_eq!(self.definitions.node_to_hir_id(node_id), hir_id);
if hir_id.owner != self.current_dep_node_owner {
debug!("visit_item: {:?}", i);
debug_assert_eq!(
i.hir_id.owner,
- self.definitions.opt_def_index(self.hir_to_node_id[&i.hir_id]).unwrap()
+ self.definitions.opt_def_index(self.definitions.hir_to_node_id(i.hir_id)).unwrap()
);
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
this.insert_with_hash(i.span, i.hir_id, Node::Item(i), hash);
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
debug_assert_eq!(
ti.hir_id.owner,
- self.definitions.opt_def_index(self.hir_to_node_id[&ti.hir_id]).unwrap()
+ self.definitions.opt_def_index(self.definitions.hir_to_node_id(ti.hir_id)).unwrap()
);
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
this.insert_with_hash(ti.span, ti.hir_id, Node::TraitItem(ti), hash);
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
debug_assert_eq!(
ii.hir_id.owner,
- self.definitions.opt_def_index(self.hir_to_node_id[&ii.hir_id]).unwrap()
+ self.definitions.opt_def_index(self.definitions.hir_to_node_id(ii.hir_id)).unwrap()
);
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);
}
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) {
- let node_id = self.hir_to_node_id[¯o_def.hir_id];
+ let node_id = self.definitions.hir_to_node_id(macro_def.hir_id);
let def_index = self.definitions.opt_def_index(node_id).unwrap();
self.with_dep_node_owner(def_index, macro_def, |this, hash| {
table: DefPathTable,
node_to_def_index: NodeMap<DefIndex>,
def_index_to_node: IndexVec<DefIndex, ast::NodeId>,
+
pub(super) node_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
+ /// The reverse mapping of `node_to_hir_id`.
+ pub(super) hir_to_node_id: FxHashMap<hir::HirId, ast::NodeId>,
+
/// If `ExpnId` is an ID of some macro expansion,
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
parent_modules_of_macro_defs: FxHashMap<ExpnId, DefId>,
}
}
+ #[inline]
+ pub fn hir_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
+ self.hir_to_node_id[&hir_id]
+ }
+
#[inline]
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
self.node_to_hir_id[node_id]
"trying to initialize `NodeId` -> `HirId` mapping twice"
);
self.node_to_hir_id = mapping;
+
+ // Build the reverse mapping of `node_to_hir_id`.
+ self.hir_to_node_id = self
+ .node_to_hir_id
+ .iter_enumerated()
+ .map(|(node_id, &hir_id)| (hir_id, node_id))
+ .collect();
}
pub fn expansion_that_defined(&self, index: DefIndex) -> ExpnId {
use crate::ty::query::Providers;
use crate::ty::TyCtxt;
use rustc_ast::ast::{self, Name, NodeId};
-use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::svh::Svh;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE};
pub crate_hash: Svh,
pub(super) map: IndexVec<DefIndex, HirOwnerData<'hir>>,
-
- /// The reverse mapping of `node_to_hir_id`.
- pub(super) hir_to_node_id: FxHashMap<HirId, NodeId>,
}
#[derive(Copy, Clone)]
#[inline]
pub fn hir_to_node_id(&self, hir_id: HirId) -> NodeId {
- self.tcx.index_hir(LOCAL_CRATE).hir_to_node_id[&hir_id]
+ self.tcx.definitions.hir_to_node_id(hir_id)
}
#[inline]
let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map");
- // Build the reverse mapping of `node_to_hir_id`.
- let hir_to_node_id = tcx
- .definitions
- .node_to_hir_id
- .iter_enumerated()
- .map(|(node_id, &hir_id)| (hir_id, node_id))
- .collect();
-
let (map, crate_hash) = {
let hcx = tcx.create_stable_hashing_context();
- let mut collector = NodeCollector::root(
- tcx.sess,
- &**tcx.arena,
- tcx.untracked_crate,
- &tcx.definitions,
- &hir_to_node_id,
- hcx,
- );
+ let mut collector =
+ NodeCollector::root(tcx.sess, &**tcx.arena, tcx.untracked_crate, &tcx.definitions, hcx);
intravisit::walk_crate(&mut collector, tcx.untracked_crate);
let crate_disambiguator = tcx.sess.local_crate_disambiguator();
collector.finalize_and_compute_crate_hash(crate_disambiguator, &*tcx.cstore, cmdline_args)
};
- let map = tcx.arena.alloc(IndexedHir { crate_hash, map, hir_to_node_id });
+ let map = tcx.arena.alloc(IndexedHir { crate_hash, map });
map
}