Skip to content

Commit 6f356df

Browse files
committed
Fix bugs
1 parent 840bdc3 commit 6f356df

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/librustc/hir/map/collector.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ fn alloc_hir_dep_nodes(
7474
dep_graph: &DepGraph,
7575
hcx: &mut StableHashingContext<'_>,
7676
def_path_hash: DefPathHash,
77+
parent: HirId,
7778
item_like: impl for<'a> HashStable<StableHashingContext<'a>>,
7879
hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>,
7980
) -> (DepNodeIndex, DepNodeIndex) {
8081
let sig = dep_graph
8182
.input_task(
8283
def_path_hash.to_dep_node(DepKind::Hir),
8384
&mut *hcx,
84-
HirItemLike { item_like: &item_like, hash_bodies: false },
85+
HirItemLike { item_like: &(parent, &item_like), hash_bodies: false },
8586
)
8687
.1;
8788
let (full, hash) = input_dep_node_and_hash(
@@ -146,6 +147,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
146147
dep_graph,
147148
&mut hcx,
148149
root_mod_def_path_hash,
150+
CRATE_HIR_ID,
149151
(module, attrs, span),
150152
&mut hir_body_nodes,
151153
)
@@ -316,6 +318,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
316318
self.dep_graph,
317319
&mut self.hcx,
318320
def_path_hash,
321+
self.parent_node,
319322
item_like,
320323
&mut self.hir_body_nodes,
321324
);

src/librustc/hir/map/mod.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'hir> Iterator for ParentHirIterator<'_, 'hir> {
181181
}
182182

183183
self.current_id = parent_id;
184-
if let Some(entry) = self.map.find_entry(parent_id) {
184+
if let Some(entry) = self.map.find_and_read_entry(parent_id) {
185185
return Some((parent_id, entry.node));
186186
}
187187
// If this `HirId` doesn't have an `Entry`, skip it and look for its `parent_id`.
@@ -381,6 +381,12 @@ impl<'hir> Map<'hir> {
381381
self.lookup(id).cloned()
382382
}
383383

384+
fn find_and_read_entry(&self, id: HirId) -> Option<Entry<'hir>> {
385+
let entry = self.find_entry(id);
386+
entry.map(|e| self.dep_graph.read_index(e.dep_node));
387+
entry
388+
}
389+
384390
pub fn item(&self, id: HirId) -> &'hir Item<'hir> {
385391
self.read(id);
386392

@@ -414,15 +420,15 @@ impl<'hir> Map<'hir> {
414420
}
415421

416422
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
417-
if let Some(entry) = self.find_entry(hir_id) {
423+
if let Some(entry) = self.find_and_read_entry(hir_id) {
418424
entry.fn_decl()
419425
} else {
420426
bug!("no entry for hir_id `{}`", hir_id)
421427
}
422428
}
423429

424430
pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
425-
if let Some(entry) = self.find_entry(hir_id) {
431+
if let Some(entry) = self.find_and_read_entry(hir_id) {
426432
entry.fn_sig()
427433
} else {
428434
bug!("no entry for hir_id `{}`", hir_id)
@@ -612,7 +618,12 @@ impl<'hir> Map<'hir> {
612618
if self.dep_graph.is_fully_enabled() {
613619
let hir_id_owner = hir_id.owner;
614620
let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
615-
self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody));
621+
let kind = if hir_id.local_id == ItemLocalId::from_u32_const(0) {
622+
DepKind::Hir
623+
} else {
624+
DepKind::HirBody
625+
};
626+
self.dep_graph.read(def_path_hash.to_dep_node(kind));
616627
}
617628

618629
self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id)
@@ -654,7 +665,7 @@ impl<'hir> Map<'hir> {
654665

655666
/// Wether `hir_id` corresponds to a `mod` or a crate.
656667
pub fn is_hir_id_module(&self, hir_id: HirId) -> bool {
657-
match self.lookup(hir_id) {
668+
match self.find_and_read_entry(hir_id) {
658669
Some(Entry { node: Node::Item(Item { kind: ItemKind::Mod(_), .. }), .. })
659670
| Some(Entry { node: Node::Crate, .. }) => true,
660671
_ => false,
@@ -1150,7 +1161,7 @@ impl<'a> NodesMatchingSuffix<'a> {
11501161
}
11511162

11521163
fn matches_suffix(&self, hir: HirId) -> bool {
1153-
let name = match self.map.find_entry(hir).map(|entry| entry.node) {
1164+
let name = match self.map.find_and_read_entry(hir).map(|entry| entry.node) {
11541165
Some(Node::Item(n)) => n.name(),
11551166
Some(Node::ForeignItem(n)) => n.name(),
11561167
Some(Node::TraitItem(n)) => n.name(),

0 commit comments

Comments
 (0)