Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7a639bf

Browse files
committedMar 20, 2025
Auto merge of rust-lang#138705 - oli-obk:hir-split, r=<try>
[perf] Decouple directly accessing a HIR owner from ast lowering r? `@ghost` cc rust-lang#95004
2 parents d8e44b7 + f9c8be9 commit 7a639bf

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed
 

‎compiler/rustc_middle/src/hir/mod.rs

+9-10
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);
@@ -235,7 +235,6 @@ pub fn provide(providers: &mut Providers) {
235235
providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
236236
providers.expn_that_defined =
237237
|tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root());
238-
providers.in_scope_traits_map = |tcx, id| {
239-
tcx.hir_crate(()).owners[id.def_id].as_owner().map(|owner_info| &owner_info.trait_map)
240-
};
238+
providers.in_scope_traits_map =
239+
|tcx, id| tcx.hir_owner(id.def_id).as_owner().map(|owner_info| &owner_info.trait_map);
241240
}

‎compiler/rustc_middle/src/query/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ rustc_queries! {
154154
desc { "getting the crate HIR" }
155155
}
156156

157+
/// A query decoupling the `hir_crate` query from everything else
158+
query hir_owner(key: LocalDefId) -> rustc_hir::MaybeOwner<'tcx> {
159+
no_hash
160+
desc { |tcx| "getting HIR of `{}`", tcx.def_path_str(key) }
161+
}
162+
157163
/// All items in the crate.
158164
query hir_crate_items(_: ()) -> &'tcx rustc_middle::hir::ModuleItems {
159165
arena_cache

0 commit comments

Comments
 (0)
Failed to load comments.