Skip to content

Commit 360569a

Browse files
committed
Feed the hir_owner query instead of the other queries based off it
1 parent 1d919a2 commit 360569a

File tree

6 files changed

+31
-22
lines changed

6 files changed

+31
-22
lines changed

compiler/rustc_hir/src/definitions.rs

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ impl DefPathTable {
9191
DefPathHash::new(self.stable_crate_id, hash)
9292
}
9393

94+
pub fn def_keys(&self) -> impl Iterator<Item = DefIndex> + ExactSizeIterator {
95+
self.index_to_key.iter_enumerated().map(|(index, _)| index)
96+
}
97+
9498
pub fn enumerated_keys_and_path_hashes(
9599
&self,
96100
) -> impl Iterator<Item = (DefIndex, &DefKey, DefPathHash)> + ExactSizeIterator {

compiler/rustc_hir/src/hir.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1314,11 +1314,15 @@ pub struct AttributeMap<'tcx> {
13141314
}
13151315

13161316
impl<'tcx> AttributeMap<'tcx> {
1317-
pub const EMPTY: &'static AttributeMap<'static> = &AttributeMap {
1318-
map: SortedMap::new(),
1319-
opt_hash: Some(Fingerprint::ZERO),
1320-
define_opaque: None,
1321-
};
1317+
pub const EMPTY: &'static AttributeMap<'static> = &Self::empty();
1318+
1319+
pub const fn empty() -> AttributeMap<'static> {
1320+
AttributeMap {
1321+
map: SortedMap::new(),
1322+
opt_hash: Some(Fingerprint::ZERO),
1323+
define_opaque: None,
1324+
}
1325+
}
13221326

13231327
#[inline]
13241328
pub fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] {

compiler/rustc_middle/src/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ macro_rules! arena_types {
116116
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
117117
[] crate_inherent_impls: rustc_middle::ty::CrateInherentImpls,
118118
[] hir_owner_nodes: rustc_hir::OwnerNodes<'tcx>,
119+
[] owner_info: rustc_hir::OwnerInfo<'tcx>,
119120
]);
120121
)
121122
}

compiler/rustc_middle/src/hir/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ 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.hir_owner = |tcx, def_id| tcx.hir_crate(()).owners[def_id];
184+
providers.hir_owner =
185+
|tcx, def_id| tcx.hir_crate(()).owners.get(def_id).copied().unwrap_or(MaybeOwner::Phantom);
185186
providers.local_def_id_to_hir_id = |tcx, def_id| match tcx.hir_owner(def_id) {
186187
MaybeOwner::Owner(_) => HirId::make_owner(def_id),
187188
MaybeOwner::NonOwner(hir_id) => hir_id,

compiler/rustc_middle/src/query/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ rustc_queries! {
157157
/// A query decoupling the `hir_crate` query from everything else
158158
query hir_owner(key: LocalDefId) -> rustc_hir::MaybeOwner<'tcx> {
159159
desc { |tcx| "getting HIR of `{}`", tcx.def_path_str(key) }
160+
feedable
160161
}
161162

162163
/// All items in the crate.
@@ -179,7 +180,6 @@ rustc_queries! {
179180
/// Returns HIR ID for the given `LocalDefId`.
180181
query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
181182
desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key) }
182-
feedable
183183
}
184184

185185
/// Gives access to the HIR node's parent for the HIR owner `key`.
@@ -196,7 +196,6 @@ rustc_queries! {
196196
/// Avoid calling this query directly.
197197
query opt_hir_owner_nodes(key: LocalDefId) -> Option<&'tcx hir::OwnerNodes<'tcx>> {
198198
desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key) }
199-
feedable
200199
}
201200

202201
/// Gives access to the HIR attributes inside the HIR owner `key`.
@@ -205,7 +204,6 @@ rustc_queries! {
205204
/// Avoid calling this query directly.
206205
query hir_attr_map(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
207206
desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key) }
208-
feedable
209207
}
210208

211209
/// Returns the *default* of the const pararameter given by `DefId`.

compiler/rustc_middle/src/ty/context.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
3535
use rustc_hir::definitions::Definitions;
3636
use rustc_hir::intravisit::VisitorExt;
3737
use rustc_hir::lang_items::LangItem;
38-
use rustc_hir::{self as hir, Attribute, HirId, Node, TraitCandidate};
38+
use rustc_hir::{self as hir, Attribute, HirId, MaybeOwner, Node, OwnerInfo, TraitCandidate};
3939
use rustc_index::IndexVec;
4040
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
4141
use rustc_query_system::cache::WithDepNode;
@@ -1282,23 +1282,24 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
12821282

12831283
// Fills in all the important parts needed by HIR queries
12841284
pub fn feed_hir(&self) {
1285-
self.local_def_id_to_hir_id(HirId::make_owner(self.def_id()));
1286-
12871285
let node = hir::OwnerNode::Synthetic;
12881286
let bodies = Default::default();
1289-
let attrs = hir::AttributeMap::EMPTY;
1290-
1287+
let attrs = hir::AttributeMap::empty();
12911288
let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
12921289
let node = node.into();
1293-
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
1294-
opt_hash_including_bodies,
1295-
nodes: IndexVec::from_elem_n(
1296-
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
1297-
1,
1298-
),
1299-
bodies,
1290+
self.hir_owner(MaybeOwner::Owner(self.tcx.arena.alloc(OwnerInfo {
1291+
nodes: hir::OwnerNodes {
1292+
opt_hash_including_bodies,
1293+
nodes: IndexVec::from_elem_n(
1294+
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
1295+
1,
1296+
),
1297+
bodies,
1298+
},
1299+
parenting: Default::default(),
1300+
attrs,
1301+
trait_map: Default::default(),
13001302
})));
1301-
self.feed_owner_id().hir_attr_map(attrs);
13021303
}
13031304
}
13041305

0 commit comments

Comments
 (0)