Skip to content

Commit 947090d

Browse files
committed
Decouple directly accessing a HIR owner from ast lowering
1 parent 7068c8b commit 947090d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,20 @@ pub fn provide(providers: &mut Providers) {
181181
providers.hir_crate_items = map::hir_crate_items;
182182
providers.crate_hash = map::crate_hash;
183183
providers.hir_module_items = map::hir_module_items;
184-
providers.local_def_id_to_hir_id = |tcx, def_id| match tcx.hir_crate(()).owners[def_id] {
184+
providers.hir_owner = |tcx, def_id| tcx.hir_crate(()).owners[def_id];
185+
providers.local_def_id_to_hir_id = |tcx, def_id| match tcx.hir_owner(def_id) {
185186
MaybeOwner::Owner(_) => HirId::make_owner(def_id),
186187
MaybeOwner::NonOwner(hir_id) => hir_id,
187188
MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
188189
};
189-
providers.opt_hir_owner_nodes =
190-
|tcx, id| tcx.hir_crate(()).owners.get(id)?.as_owner().map(|i| &i.nodes);
190+
providers.opt_hir_owner_nodes = |tcx, id| tcx.hir_owner(id).as_owner().map(|i| &i.nodes);
191191
providers.hir_owner_parent = |tcx, owner_id| {
192192
tcx.opt_local_parent(owner_id.def_id).map_or(CRATE_HIR_ID, |parent_def_id| {
193193
let parent_owner_id = tcx.local_def_id_to_hir_id(parent_def_id).owner;
194194
HirId {
195195
owner: parent_owner_id,
196-
local_id: tcx.hir_crate(()).owners[parent_owner_id.def_id]
196+
local_id: tcx
197+
.hir_owner(parent_owner_id.def_id)
197198
.unwrap()
198199
.parenting
199200
.get(&owner_id.def_id)
@@ -202,9 +203,8 @@ pub fn provide(providers: &mut Providers) {
202203
}
203204
})
204205
};
205-
providers.hir_attr_map = |tcx, id| {
206-
tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
207-
};
206+
providers.hir_attr_map =
207+
|tcx, id| tcx.hir_owner(id.def_id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
208208
providers.def_span = |tcx, def_id| tcx.hir_span(tcx.local_def_id_to_hir_id(def_id));
209209
providers.def_ident_span = |tcx, def_id| {
210210
let hir_id = tcx.local_def_id_to_hir_id(def_id);
@@ -236,7 +236,6 @@ pub fn provide(providers: &mut Providers) {
236236
|tcx, trait_id| tcx.resolutions(()).trait_impls.get(&trait_id).map_or(&[], |xs| &xs[..]);
237237
providers.expn_that_defined =
238238
|tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root());
239-
providers.in_scope_traits_map = |tcx, id| {
240-
tcx.hir_crate(()).owners[id.def_id].as_owner().map(|owner_info| &owner_info.trait_map)
241-
};
239+
providers.in_scope_traits_map =
240+
|tcx, id| tcx.hir_owner(id.def_id).as_owner().map(|owner_info| &owner_info.trait_map);
242241
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ rustc_queries! {
172172
desc { "getting the crate HIR" }
173173
}
174174

175+
/// A query decoupling the `hir_crate` query from everything else
176+
query hir_owner(key: LocalDefId) -> rustc_hir::MaybeOwner<'tcx> {
177+
no_hash
178+
desc { |tcx| "getting HIR of `{}`", tcx.def_path_str(key) }
179+
}
180+
175181
/// All items in the crate.
176182
query hir_crate_items(_: ()) -> &'tcx rustc_middle::hir::ModuleItems {
177183
arena_cache

0 commit comments

Comments
 (0)