Skip to content

Commit 6881eed

Browse files
committed
Don't hold the definitions' lock across index_hir
1 parent 0c96a92 commit 6881eed

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ use rustc_data_structures::fx::FxHashMap;
22
use rustc_data_structures::sorted_map::SortedMap;
33
use rustc_hir as hir;
44
use rustc_hir::def_id::LocalDefId;
5-
use rustc_hir::definitions;
65
use rustc_hir::intravisit::{self, Visitor};
76
use rustc_hir::*;
87
use rustc_index::{Idx, IndexVec};
98
use rustc_middle::span_bug;
10-
use rustc_session::Session;
11-
use rustc_span::source_map::SourceMap;
9+
use rustc_middle::ty::TyCtxt;
1210
use rustc_span::{Span, DUMMY_SP};
1311

1412
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
1513
pub(super) struct NodeCollector<'a, 'hir> {
16-
/// Source map
17-
source_map: &'a SourceMap,
14+
tcx: TyCtxt<'hir>,
15+
1816
bodies: &'a SortedMap<ItemLocalId, &'hir Body<'hir>>,
1917

2018
/// Outputs
@@ -25,14 +23,11 @@ pub(super) struct NodeCollector<'a, 'hir> {
2523
parent_node: hir::ItemLocalId,
2624

2725
owner: OwnerId,
28-
29-
definitions: &'a definitions::Definitions,
3026
}
3127

32-
#[instrument(level = "debug", skip(sess, definitions, bodies))]
28+
#[instrument(level = "debug", skip(tcx, bodies))]
3329
pub(super) fn index_hir<'hir>(
34-
sess: &Session,
35-
definitions: &definitions::Definitions,
30+
tcx: TyCtxt<'hir>,
3631
item: hir::OwnerNode<'hir>,
3732
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
3833
) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, FxHashMap<LocalDefId, ItemLocalId>) {
@@ -42,8 +37,7 @@ pub(super) fn index_hir<'hir>(
4237
// used.
4338
nodes.push(Some(ParentedNode { parent: ItemLocalId::INVALID, node: item.into() }));
4439
let mut collector = NodeCollector {
45-
source_map: sess.source_map(),
46-
definitions,
40+
tcx,
4741
owner: item.def_id(),
4842
parent_node: ItemLocalId::new(0),
4943
nodes,
@@ -79,11 +73,17 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
7973
span,
8074
"inconsistent HirId at `{:?}` for `{:?}`: \
8175
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
82-
self.source_map.span_to_diagnostic_string(span),
76+
self.tcx.sess.source_map().span_to_diagnostic_string(span),
8377
node,
84-
self.definitions.def_path(self.owner.def_id).to_string_no_crate_verbose(),
78+
self.tcx
79+
.definitions_untracked()
80+
.def_path(self.owner.def_id)
81+
.to_string_no_crate_verbose(),
8582
self.owner,
86-
self.definitions.def_path(hir_id.owner.def_id).to_string_no_crate_verbose(),
83+
self.tcx
84+
.definitions_untracked()
85+
.def_path(hir_id.owner.def_id)
86+
.to_string_no_crate_verbose(),
8787
hir_id.owner,
8888
)
8989
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
671671
} else {
672672
(None, None)
673673
};
674-
let (nodes, parenting) =
675-
index::index_hir(self.tcx.sess, &*self.tcx.definitions_untracked(), node, &bodies);
674+
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies);
676675
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
677676
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash };
678677

0 commit comments

Comments
 (0)