Skip to content

Commit 3c94dd1

Browse files
committed
Revert "Pre-compute hir_id_to_def_id mapping"
This reverts commit 94817e3.
1 parent 8b3fb35 commit 3c94dd1

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/librustc_hir/definitions.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ pub struct Definitions {
8787
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
8888

8989
pub(super) node_id_to_hir_id: IndexVec<ast::NodeId, Option<hir::HirId>>,
90-
/// The pre-computed mapping of `hir_id_to_node_id` -> `node_id_to_def_id`.
91-
pub(super) hir_id_to_def_id: FxHashMap<hir::HirId, LocalDefId>,
90+
/// The reverse mapping of `node_id_to_hir_id`.
91+
pub(super) hir_id_to_node_id: FxHashMap<hir::HirId, ast::NodeId>,
9292

9393
/// If `ExpnId` is an ID of some macro expansion,
9494
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
@@ -351,7 +351,8 @@ impl Definitions {
351351

352352
#[inline]
353353
pub fn opt_hir_id_to_local_def_id(&self, hir_id: hir::HirId) -> Option<LocalDefId> {
354-
self.hir_id_to_def_id.get(&hir_id).copied()
354+
let node_id = self.hir_id_to_node_id[&hir_id];
355+
self.opt_local_def_id(node_id)
355356
}
356357

357358
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
@@ -466,15 +467,11 @@ impl Definitions {
466467
);
467468
self.node_id_to_hir_id = mapping;
468469

469-
// Build the pre-computed mapping of `hir_id_to_node_id` -> `node_id_to_def_id`.
470-
self.hir_id_to_def_id = self
470+
// Build the reverse mapping of `node_id_to_hir_id`.
471+
self.hir_id_to_node_id = self
471472
.node_id_to_hir_id
472473
.iter_enumerated()
473-
.filter_map(|(node_id, &hir_id)| {
474-
hir_id.and_then(|hir_id| {
475-
self.node_id_to_def_id.get(&node_id).map(|&def_id| (hir_id, def_id))
476-
})
477-
})
474+
.filter_map(|(node_id, &hir_id)| hir_id.map(|hir_id| (hir_id, node_id)))
478475
.collect();
479476
}
480477

0 commit comments

Comments
 (0)