Move some Map
methods onto TyCtxt
.
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
This commit is contained in:
parent
cd1d84cdf7
commit
f86f7ad5f2
197 changed files with 465 additions and 476 deletions
|
@ -93,7 +93,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let parent_id = self.map.def_key(self.current_id.owner.def_id).parent;
|
||||
let parent_id = self.map.tcx.hir_def_key(self.current_id.owner.def_id).parent;
|
||||
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
|
||||
let def_id = LocalDefId { local_def_index };
|
||||
self.map.tcx.local_def_id_to_hir_id(def_id).owner
|
||||
|
@ -164,76 +164,80 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
pub fn parent_hir_node(self, hir_id: HirId) -> Node<'tcx> {
|
||||
self.hir_node(self.parent_hir_id(hir_id))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Map<'hir> {
|
||||
/// Best avoided in favour of more targeted methods. See the comment on the `hir_crate` query.
|
||||
#[inline]
|
||||
pub fn krate(self) -> &'hir Crate<'hir> {
|
||||
self.tcx.hir_crate(())
|
||||
pub fn hir_krate(self) -> &'tcx Crate<'tcx> {
|
||||
self.hir_crate(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn root_module(self) -> &'hir Mod<'hir> {
|
||||
match self.tcx.hir_owner_node(CRATE_OWNER_ID) {
|
||||
pub fn hir_root_module(self) -> &'tcx Mod<'tcx> {
|
||||
match self.hir_owner_node(CRATE_OWNER_ID) {
|
||||
OwnerNode::Crate(item) => item,
|
||||
_ => bug!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn items(self) -> impl Iterator<Item = ItemId> + 'hir {
|
||||
self.tcx.hir_crate_items(()).free_items.iter().copied()
|
||||
pub fn hir_free_items(self) -> impl Iterator<Item = ItemId> + 'tcx {
|
||||
self.hir_crate_items(()).free_items.iter().copied()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn module_items(self, module: LocalModDefId) -> impl Iterator<Item = ItemId> + 'hir {
|
||||
self.tcx.hir_module_items(module).free_items()
|
||||
pub fn hir_module_free_items(
|
||||
self,
|
||||
module: LocalModDefId,
|
||||
) -> impl Iterator<Item = ItemId> + 'tcx {
|
||||
self.hir_module_items(module).free_items()
|
||||
}
|
||||
|
||||
pub fn def_key(self, def_id: LocalDefId) -> DefKey {
|
||||
pub fn hir_def_key(self, def_id: LocalDefId) -> DefKey {
|
||||
// Accessing the DefKey is ok, since it is part of DefPathHash.
|
||||
self.tcx.definitions_untracked().def_key(def_id)
|
||||
self.definitions_untracked().def_key(def_id)
|
||||
}
|
||||
|
||||
pub fn def_path(self, def_id: LocalDefId) -> DefPath {
|
||||
pub fn hir_def_path(self, def_id: LocalDefId) -> DefPath {
|
||||
// Accessing the DefPath is ok, since it is part of DefPathHash.
|
||||
self.tcx.definitions_untracked().def_path(def_id)
|
||||
self.definitions_untracked().def_path(def_id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
|
||||
pub fn hir_def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
|
||||
// Accessing the DefPathHash is ok, it is incr. comp. stable.
|
||||
self.tcx.definitions_untracked().def_path_hash(def_id)
|
||||
self.definitions_untracked().def_path_hash(def_id)
|
||||
}
|
||||
|
||||
pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> {
|
||||
id.as_local().map(|id| self.tcx.hir_node_by_def_id(id))
|
||||
pub fn hir_get_if_local(self, id: DefId) -> Option<Node<'tcx>> {
|
||||
id.as_local().map(|id| self.hir_node_by_def_id(id))
|
||||
}
|
||||
|
||||
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {
|
||||
self.tcx.opt_hir_owner_node(id)?.generics()
|
||||
pub fn hir_get_generics(self, id: LocalDefId) -> Option<&'tcx Generics<'tcx>> {
|
||||
self.opt_hir_owner_node(id)?.generics()
|
||||
}
|
||||
|
||||
pub fn item(self, id: ItemId) -> &'hir Item<'hir> {
|
||||
self.tcx.hir_owner_node(id.owner_id).expect_item()
|
||||
pub fn hir_item(self, id: ItemId) -> &'tcx Item<'tcx> {
|
||||
self.hir_owner_node(id.owner_id).expect_item()
|
||||
}
|
||||
|
||||
pub fn trait_item(self, id: TraitItemId) -> &'hir TraitItem<'hir> {
|
||||
self.tcx.hir_owner_node(id.owner_id).expect_trait_item()
|
||||
pub fn hir_trait_item(self, id: TraitItemId) -> &'tcx TraitItem<'tcx> {
|
||||
self.hir_owner_node(id.owner_id).expect_trait_item()
|
||||
}
|
||||
|
||||
pub fn impl_item(self, id: ImplItemId) -> &'hir ImplItem<'hir> {
|
||||
self.tcx.hir_owner_node(id.owner_id).expect_impl_item()
|
||||
pub fn hir_impl_item(self, id: ImplItemId) -> &'tcx ImplItem<'tcx> {
|
||||
self.hir_owner_node(id.owner_id).expect_impl_item()
|
||||
}
|
||||
|
||||
pub fn foreign_item(self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
|
||||
self.tcx.hir_owner_node(id.owner_id).expect_foreign_item()
|
||||
pub fn hir_foreign_item(self, id: ForeignItemId) -> &'tcx ForeignItem<'tcx> {
|
||||
self.hir_owner_node(id.owner_id).expect_foreign_item()
|
||||
}
|
||||
|
||||
pub fn body(self, id: BodyId) -> &'hir Body<'hir> {
|
||||
self.tcx.hir_owner_nodes(id.hir_id.owner).bodies[&id.hir_id.local_id]
|
||||
pub fn hir_body(self, id: BodyId) -> &'tcx Body<'tcx> {
|
||||
self.hir_owner_nodes(id.hir_id.owner).bodies[&id.hir_id.local_id]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Map<'hir> {
|
||||
#[track_caller]
|
||||
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
||||
self.tcx.hir_node(hir_id).fn_decl()
|
||||
|
@ -271,7 +275,7 @@ impl<'hir> Map<'hir> {
|
|||
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
|
||||
/// if the node is a body owner, otherwise returns `None`.
|
||||
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<&'hir Body<'hir>> {
|
||||
Some(self.body(self.tcx.hir_node_by_def_id(id).body_id()?))
|
||||
Some(self.tcx.hir_body(self.tcx.hir_node_by_def_id(id).body_id()?))
|
||||
}
|
||||
|
||||
/// Given a body owner's id, returns the `BodyId` associated with it.
|
||||
|
@ -288,7 +292,7 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
|
||||
pub fn body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir {
|
||||
self.body(id).params.iter().map(|arg| match arg.pat.kind {
|
||||
self.tcx.hir_body(id).params.iter().map(|arg| match arg.pat.kind {
|
||||
PatKind::Binding(_, _, ident, _) => ident,
|
||||
_ => Ident::empty(),
|
||||
})
|
||||
|
@ -410,7 +414,7 @@ impl<'hir> Map<'hir> {
|
|||
where
|
||||
V: Visitor<'hir>,
|
||||
{
|
||||
let krate = self.krate();
|
||||
let krate = self.tcx.hir_krate();
|
||||
for info in krate.owners.iter() {
|
||||
if let MaybeOwner::Owner(info) = info {
|
||||
for attrs in info.attrs.map.values() {
|
||||
|
@ -436,13 +440,21 @@ impl<'hir> Map<'hir> {
|
|||
V: Visitor<'hir>,
|
||||
{
|
||||
let krate = self.tcx.hir_crate_items(());
|
||||
walk_list!(visitor, visit_item, krate.free_items().map(|id| self.item(id)));
|
||||
walk_list!(visitor, visit_trait_item, krate.trait_items().map(|id| self.trait_item(id)));
|
||||
walk_list!(visitor, visit_impl_item, krate.impl_items().map(|id| self.impl_item(id)));
|
||||
walk_list!(visitor, visit_item, krate.free_items().map(|id| self.tcx.hir_item(id)));
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_trait_item,
|
||||
krate.trait_items().map(|id| self.tcx.hir_trait_item(id))
|
||||
);
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_impl_item,
|
||||
krate.impl_items().map(|id| self.tcx.hir_impl_item(id))
|
||||
);
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_foreign_item,
|
||||
krate.foreign_items().map(|id| self.foreign_item(id))
|
||||
krate.foreign_items().map(|id| self.tcx.hir_foreign_item(id))
|
||||
);
|
||||
V::Result::output()
|
||||
}
|
||||
|
@ -454,13 +466,21 @@ impl<'hir> Map<'hir> {
|
|||
V: Visitor<'hir>,
|
||||
{
|
||||
let module = self.tcx.hir_module_items(module);
|
||||
walk_list!(visitor, visit_item, module.free_items().map(|id| self.item(id)));
|
||||
walk_list!(visitor, visit_trait_item, module.trait_items().map(|id| self.trait_item(id)));
|
||||
walk_list!(visitor, visit_impl_item, module.impl_items().map(|id| self.impl_item(id)));
|
||||
walk_list!(visitor, visit_item, module.free_items().map(|id| self.tcx.hir_item(id)));
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_trait_item,
|
||||
module.trait_items().map(|id| self.tcx.hir_trait_item(id))
|
||||
);
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_impl_item,
|
||||
module.impl_items().map(|id| self.tcx.hir_impl_item(id))
|
||||
);
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_foreign_item,
|
||||
module.foreign_items().map(|id| self.foreign_item(id))
|
||||
module.foreign_items().map(|id| self.tcx.hir_foreign_item(id))
|
||||
);
|
||||
V::Result::output()
|
||||
}
|
||||
|
@ -921,7 +941,7 @@ impl<'hir> Map<'hir> {
|
|||
Node::Variant(variant) => variant.span,
|
||||
Node::Field(field) => field.span,
|
||||
Node::AnonConst(constant) => constant.span,
|
||||
Node::ConstBlock(constant) => self.body(constant.body).value.span,
|
||||
Node::ConstBlock(constant) => self.tcx.hir_body(constant.body).value.span,
|
||||
Node::ConstArg(const_arg) => const_arg.span(),
|
||||
Node::Expr(expr) => expr.span,
|
||||
Node::ExprField(field) => field.span,
|
||||
|
@ -1020,23 +1040,23 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
|
|||
}
|
||||
|
||||
fn body(&self, id: BodyId) -> &'hir Body<'hir> {
|
||||
(*self).body(id)
|
||||
self.tcx.hir_body(id)
|
||||
}
|
||||
|
||||
fn item(&self, id: ItemId) -> &'hir Item<'hir> {
|
||||
(*self).item(id)
|
||||
self.tcx.hir_item(id)
|
||||
}
|
||||
|
||||
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> {
|
||||
(*self).trait_item(id)
|
||||
self.tcx.hir_trait_item(id)
|
||||
}
|
||||
|
||||
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
|
||||
(*self).impl_item(id)
|
||||
self.tcx.hir_impl_item(id)
|
||||
}
|
||||
|
||||
fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
|
||||
(*self).foreign_item(id)
|
||||
self.tcx.hir_foreign_item(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3299,13 +3299,12 @@ define_print_and_forward_display! {
|
|||
|
||||
fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, Namespace, DefId)) {
|
||||
// Iterate all local crate items no matter where they are defined.
|
||||
let hir = tcx.hir();
|
||||
for id in hir.items() {
|
||||
for id in tcx.hir_free_items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Use) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let item = hir.item(id);
|
||||
let item = tcx.hir_item(id);
|
||||
if item.ident.name == kw::Empty {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ pub(super) fn incoherent_impls_provider(tcx: TyCtxt<'_>, simp: SimplifiedType) -
|
|||
|
||||
pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
|
||||
let mut traits = Vec::new();
|
||||
for id in tcx.hir().items() {
|
||||
for id in tcx.hir_free_items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
|
||||
traits.push(id.owner_id.to_def_id())
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
|
|||
|
||||
pub(super) fn trait_impls_in_crate_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
|
||||
let mut trait_impls = Vec::new();
|
||||
for id in tcx.hir().items() {
|
||||
for id in tcx.hir_free_items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
|
||||
&& tcx.impl_trait_ref(id.owner_id).is_some()
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
|
|||
let arity = if let Some(frame) = cycle_error.cycle.get(0)
|
||||
&& frame.query.dep_kind == dep_kinds::fn_sig
|
||||
&& let Some(def_id) = frame.query.def_id
|
||||
&& let Some(node) = tcx.hir().get_if_local(def_id)
|
||||
&& let Some(node) = tcx.hir_get_if_local(def_id)
|
||||
&& let Some(sig) = node.fn_sig()
|
||||
{
|
||||
sig.decl.inputs.len()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue