Auto merge of #81611 - cjgillot:meowner, r=estebank
Only store a LocalDefId in some HIR nodes Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef. As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`. This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
This commit is contained in:
commit
8fe989dd76
117 changed files with 1127 additions and 1191 deletions
|
@ -767,7 +767,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||
let hir = self.infcx.tcx.hir();
|
||||
|
||||
if let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind {
|
||||
let opaque_ty = hir.item(id.id);
|
||||
let opaque_ty = hir.item(id);
|
||||
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
bounds:
|
||||
[hir::GenericBound::LangItemTrait(
|
||||
|
|
|
@ -1013,13 +1013,12 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
|
|||
| hir::ItemKind::Union(_, ref generics) => {
|
||||
if generics.params.is_empty() {
|
||||
if self.mode == MonoItemCollectionMode::Eager {
|
||||
let def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
debug!(
|
||||
"RootCollector: ADT drop-glue for {}",
|
||||
self.tcx.def_path_str(def_id.to_def_id())
|
||||
self.tcx.def_path_str(item.def_id.to_def_id())
|
||||
);
|
||||
|
||||
let ty = Instance::new(def_id.to_def_id(), InternalSubsts::empty())
|
||||
let ty = Instance::new(item.def_id.to_def_id(), InternalSubsts::empty())
|
||||
.ty(self.tcx, ty::ParamEnv::reveal_all());
|
||||
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
|
||||
}
|
||||
|
@ -1028,29 +1027,28 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
|
|||
hir::ItemKind::GlobalAsm(..) => {
|
||||
debug!(
|
||||
"RootCollector: ItemKind::GlobalAsm({})",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
|
||||
self.tcx.def_path_str(item.def_id.to_def_id())
|
||||
);
|
||||
self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.hir_id)));
|
||||
self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.item_id())));
|
||||
}
|
||||
hir::ItemKind::Static(..) => {
|
||||
let def_id = self.tcx.hir().local_def_id(item.hir_id).to_def_id();
|
||||
debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id));
|
||||
self.output.push(dummy_spanned(MonoItem::Static(def_id)));
|
||||
debug!(
|
||||
"RootCollector: ItemKind::Static({})",
|
||||
self.tcx.def_path_str(item.def_id.to_def_id())
|
||||
);
|
||||
self.output.push(dummy_spanned(MonoItem::Static(item.def_id.to_def_id())));
|
||||
}
|
||||
hir::ItemKind::Const(..) => {
|
||||
// const items only generate mono items if they are
|
||||
// actually used somewhere. Just declaring them is insufficient.
|
||||
|
||||
// but even just declaring them must collect the items they refer to
|
||||
let def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
|
||||
if let Ok(val) = self.tcx.const_eval_poly(def_id.to_def_id()) {
|
||||
if let Ok(val) = self.tcx.const_eval_poly(item.def_id.to_def_id()) {
|
||||
collect_const_value(self.tcx, val, &mut self.output);
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Fn(..) => {
|
||||
let def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
self.push_if_root(def_id);
|
||||
self.push_if_root(item.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1062,8 +1060,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
|
|||
|
||||
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem<'v>) {
|
||||
if let hir::ImplItemKind::Fn(hir::FnSig { .. }, _) = ii.kind {
|
||||
let def_id = self.tcx.hir().local_def_id(ii.hir_id);
|
||||
self.push_if_root(def_id);
|
||||
self.push_if_root(ii.def_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1156,14 +1153,12 @@ fn create_mono_items_for_default_impls<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
let impl_def_id = tcx.hir().local_def_id(item.hir_id);
|
||||
|
||||
debug!(
|
||||
"create_mono_items_for_default_impls(item={})",
|
||||
tcx.def_path_str(impl_def_id.to_def_id())
|
||||
tcx.def_path_str(item.def_id.to_def_id())
|
||||
);
|
||||
|
||||
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) {
|
||||
if let Some(trait_ref) = tcx.impl_trait_ref(item.def_id) {
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
|
||||
let overridden_methods: FxHashSet<_> =
|
||||
|
|
|
@ -314,7 +314,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
|
|||
Some(def_id)
|
||||
}
|
||||
MonoItem::Static(def_id) => Some(def_id),
|
||||
MonoItem::GlobalAsm(hir_id) => Some(tcx.hir().local_def_id(hir_id).to_def_id()),
|
||||
MonoItem::GlobalAsm(item_id) => Some(item_id.def_id.to_def_id()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -405,11 +405,10 @@ fn mono_item_visibility(
|
|||
Visibility::Hidden
|
||||
};
|
||||
}
|
||||
MonoItem::GlobalAsm(hir_id) => {
|
||||
let def_id = tcx.hir().local_def_id(*hir_id);
|
||||
return if tcx.is_reachable_non_generic(def_id) {
|
||||
MonoItem::GlobalAsm(item_id) => {
|
||||
return if tcx.is_reachable_non_generic(item_id.def_id) {
|
||||
*can_be_internalized = false;
|
||||
default_visibility(tcx, def_id.to_def_id(), false)
|
||||
default_visibility(tcx, item_id.def_id.to_def_id(), false)
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue