Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::ich::Fingerprint;
use crate::middle::cstore::CrateStore;
use crate::session::CrateDisambiguator;
use crate::session::Session;
use std::iter::repeat;
use syntax::ast::{NodeId, CRATE_NODE_ID};
use crate::util::nodemap::FxHashMap;
use syntax::ast::NodeId;
use syntax::source_map::SourceMap;
use syntax_pos::Span;

Expand All @@ -25,7 +25,7 @@ pub(super) struct NodeCollector<'a, 'hir> {
source_map: &'a SourceMap,

/// The node map
map: Vec<Option<Entry<'hir>>>,
map: FxHashMap<HirId, Entry<'hir>>,
/// The parent of this node
parent_node: hir::HirId,

Expand Down Expand Up @@ -145,7 +145,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
let mut collector = NodeCollector {
krate,
source_map: sess.source_map(),
map: repeat(None).take(sess.current_node_id_count()).collect(),
map: FxHashMap::with_capacity_and_hasher(sess.current_node_id_count(),
Default::default()),
parent_node: hir::CRATE_HIR_ID,
current_signature_dep_index: root_mod_sig_dep_index,
current_full_dep_index: root_mod_full_dep_index,
Expand All @@ -157,9 +158,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
hcx,
hir_body_nodes,
};
collector.insert_entry(CRATE_NODE_ID, Entry {
parent: CRATE_NODE_ID,
parent_hir: hir::CRATE_HIR_ID,
collector.insert_entry(hir::CRATE_HIR_ID, Entry {
parent: hir::CRATE_HIR_ID,
dep_node: root_mod_sig_dep_index,
node: Node::Crate,
});
Expand All @@ -171,7 +171,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
crate_disambiguator: CrateDisambiguator,
cstore: &dyn CrateStore,
commandline_args_hash: u64)
-> (Vec<Option<Entry<'hir>>>, Svh)
-> (FxHashMap<HirId, Entry<'hir>>, Svh)
{
self.hir_body_nodes.sort_unstable_by_key(|bn| bn.0);

Expand Down Expand Up @@ -222,15 +222,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
(self.map, svh)
}

fn insert_entry(&mut self, id: NodeId, entry: Entry<'hir>) {
fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
debug!("hir_map: {:?} => {:?}", id, entry);
self.map[id.as_usize()] = Some(entry);
self.map.insert(id, entry);
}

fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
let entry = Entry {
parent: self.hir_to_node_id[&self.parent_node],
parent_hir: self.parent_node,
parent: self.parent_node,
dep_node: if self.currently_in_body {
self.current_full_dep_index
} else {
Expand All @@ -239,12 +238,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
node,
};

let node_id = self.hir_to_node_id[&hir_id];

// Make sure that the DepNode of some node coincides with the HirId
// owner of that node.
if cfg!(debug_assertions) {
assert_eq!(self.definitions.node_to_hir_id(node_id), hir_id);
let node_id = self.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 {
let node_str = match self.definitions.opt_def_index(node_id) {
Expand Down Expand Up @@ -277,7 +275,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
}
}

self.insert_entry(node_id, entry);
self.insert_entry(hir_id, entry);
}

fn with_parent<F: FnOnce(&mut Self)>(
Expand Down
Loading