Skip to content

Commit 7f61336

Browse files
committed
Feed the hir_owner query instead of the other queries based off it
1 parent e7184d6 commit 7f61336

File tree

6 files changed

+31
-22
lines changed

6 files changed

+31
-22
lines changed

compiler/rustc_hir/src/definitions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ impl DefPathTable {
8888
DefPathHash::new(self.stable_crate_id, hash)
8989
}
9090

91+
pub fn def_keys(&self) -> impl Iterator<Item = DefIndex> + ExactSizeIterator {
92+
self.index_to_key.iter_enumerated().map(|(index, _)| index)
93+
}
94+
9195
pub fn enumerated_keys_and_path_hashes(
9296
&self,
9397
) -> impl Iterator<Item = (DefIndex, &DefKey, DefPathHash)> + ExactSizeIterator {

compiler/rustc_hir/src/hir.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,11 +1462,15 @@ pub struct AttributeMap<'tcx> {
14621462
}
14631463

14641464
impl<'tcx> AttributeMap<'tcx> {
1465-
pub const EMPTY: &'static AttributeMap<'static> = &AttributeMap {
1466-
map: SortedMap::new(),
1467-
opt_hash: Some(Fingerprint::ZERO),
1468-
define_opaque: None,
1469-
};
1465+
pub const EMPTY: &'static AttributeMap<'static> = &Self::empty();
1466+
1467+
pub const fn empty() -> AttributeMap<'static> {
1468+
AttributeMap {
1469+
map: SortedMap::new(),
1470+
opt_hash: Some(Fingerprint::ZERO),
1471+
define_opaque: None,
1472+
}
1473+
}
14701474

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

compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ macro_rules! arena_types {
118118
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
119119
[] crate_inherent_impls: rustc_middle::ty::CrateInherentImpls,
120120
[] hir_owner_nodes: rustc_hir::OwnerNodes<'tcx>,
121+
[] owner_info: rustc_hir::OwnerInfo<'tcx>,
121122
]);
122123
)
123124
}

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ rustc_queries! {
176176
query hir_owner(key: LocalDefId) -> rustc_hir::MaybeOwner<'tcx> {
177177
no_hash
178178
desc { |tcx| "getting HIR of `{}`", tcx.def_path_str(key) }
179+
feedable
179180
}
180181

181182
/// All items in the crate.
@@ -198,7 +199,6 @@ rustc_queries! {
198199
/// Returns HIR ID for the given `LocalDefId`.
199200
query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
200201
desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key) }
201-
feedable
202202
}
203203

204204
/// Gives access to the HIR node's parent for the HIR owner `key`.
@@ -215,7 +215,6 @@ rustc_queries! {
215215
/// Avoid calling this query directly.
216216
query opt_hir_owner_nodes(key: LocalDefId) -> Option<&'tcx hir::OwnerNodes<'tcx>> {
217217
desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key) }
218-
feedable
219218
}
220219

221220
/// Gives access to the HIR attributes inside the HIR owner `key`.
@@ -224,7 +223,6 @@ rustc_queries! {
224223
/// Avoid calling this query directly.
225224
query hir_attr_map(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
226225
desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key) }
227-
feedable
228226
}
229227

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

compiler/rustc_middle/src/ty/context.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
3737
use rustc_hir::definitions::{DefPathData, Definitions, DisambiguatorState};
3838
use rustc_hir::intravisit::VisitorExt;
3939
use rustc_hir::lang_items::LangItem;
40-
use rustc_hir::{self as hir, Attribute, HirId, Node, TraitCandidate};
40+
use rustc_hir::{self as hir, Attribute, HirId, MaybeOwner, Node, OwnerInfo, TraitCandidate};
4141
use rustc_index::IndexVec;
4242
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
4343
use rustc_query_system::cache::WithDepNode;
@@ -1326,24 +1326,25 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
13261326

13271327
// Fills in all the important parts needed by HIR queries
13281328
pub fn feed_hir(&self) {
1329-
self.local_def_id_to_hir_id(HirId::make_owner(self.def_id()));
1330-
13311329
let node = hir::OwnerNode::Synthetic;
13321330
let bodies = Default::default();
1333-
let attrs = hir::AttributeMap::EMPTY;
1334-
1331+
let attrs = hir::AttributeMap::empty();
13351332
let (opt_hash_including_bodies, _) =
13361333
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque);
13371334
let node = node.into();
1338-
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
1339-
opt_hash_including_bodies,
1340-
nodes: IndexVec::from_elem_n(
1341-
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
1342-
1,
1343-
),
1344-
bodies,
1335+
self.hir_owner(MaybeOwner::Owner(self.tcx.arena.alloc(OwnerInfo {
1336+
nodes: hir::OwnerNodes {
1337+
opt_hash_including_bodies,
1338+
nodes: IndexVec::from_elem_n(
1339+
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
1340+
1,
1341+
),
1342+
bodies,
1343+
},
1344+
parenting: Default::default(),
1345+
attrs,
1346+
trait_map: Default::default(),
13451347
})));
1346-
self.feed_owner_id().hir_attr_map(attrs);
13471348
}
13481349
}
13491350

0 commit comments

Comments
 (0)