Skip to content

Commit d6f0642

Browse files
committed
Auto merge of rust-lang#107206 - cjgillot:no-h2l-map, r=WaffleLapkin
Remove HirId -> LocalDefId map from HIR. Having this map in HIR prevents the creating of new definitions after HIR has been built. Thankfully, we do not need it. Based on rust-lang#103902
2 parents bca8b4d + 1aab86e commit d6f0642

File tree

91 files changed

+557
-592
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+557
-592
lines changed

compiler/rustc_ast_lowering/src/index.rs

-13
Original file line numberDiff line numberDiff line change
@@ -275,19 +275,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
275275
});
276276
}
277277

278-
fn visit_fn(
279-
&mut self,
280-
fk: intravisit::FnKind<'hir>,
281-
fd: &'hir FnDecl<'hir>,
282-
b: BodyId,
283-
_: Span,
284-
id: HirId,
285-
) {
286-
assert_eq!(self.owner, id.owner);
287-
assert_eq!(self.parent_node, id.local_id);
288-
intravisit::walk_fn(self, fk, fd, b, id);
289-
}
290-
291278
fn visit_block(&mut self, block: &'hir Block<'hir>) {
292279
self.insert(block.span, block.hir_id, Node::Block(block));
293280
self.with_parent(block.hir_id, |this| {

compiler/rustc_ast_lowering/src/item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6767
current_hir_id_owner: hir::CRATE_OWNER_ID,
6868
item_local_id_counter: hir::ItemLocalId::new(0),
6969
node_id_to_local_id: Default::default(),
70-
local_id_to_def_id: SortedMap::new(),
7170
trait_map: Default::default(),
7271

7372
// Lowering state.

compiler/rustc_ast_lowering/src/lib.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ struct LoweringContext<'a, 'hir> {
119119

120120
current_hir_id_owner: hir::OwnerId,
121121
item_local_id_counter: hir::ItemLocalId,
122-
local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>,
123122
trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
124123

125124
impl_trait_defs: Vec<hir::GenericParam<'hir>>,
@@ -567,7 +566,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
567566
let current_attrs = std::mem::take(&mut self.attrs);
568567
let current_bodies = std::mem::take(&mut self.bodies);
569568
let current_node_ids = std::mem::take(&mut self.node_id_to_local_id);
570-
let current_id_to_def_id = std::mem::take(&mut self.local_id_to_def_id);
571569
let current_trait_map = std::mem::take(&mut self.trait_map);
572570
let current_owner =
573571
std::mem::replace(&mut self.current_hir_id_owner, hir::OwnerId { def_id });
@@ -594,7 +592,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
594592
self.attrs = current_attrs;
595593
self.bodies = current_bodies;
596594
self.node_id_to_local_id = current_node_ids;
597-
self.local_id_to_def_id = current_id_to_def_id;
598595
self.trait_map = current_trait_map;
599596
self.current_hir_id_owner = current_owner;
600597
self.item_local_id_counter = current_local_counter;
@@ -629,7 +626,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
629626
fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
630627
let attrs = std::mem::take(&mut self.attrs);
631628
let mut bodies = std::mem::take(&mut self.bodies);
632-
let local_id_to_def_id = std::mem::take(&mut self.local_id_to_def_id);
633629
let trait_map = std::mem::take(&mut self.trait_map);
634630

635631
#[cfg(debug_assertions)]
@@ -645,13 +641,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
645641
let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies);
646642
let (nodes, parenting) =
647643
index::index_hir(self.tcx.sess, &*self.tcx.definitions_untracked(), node, &bodies);
648-
let nodes = hir::OwnerNodes {
649-
hash_including_bodies,
650-
hash_without_bodies,
651-
nodes,
652-
bodies,
653-
local_id_to_def_id,
654-
};
644+
let nodes = hir::OwnerNodes { hash_including_bodies, hash_without_bodies, nodes, bodies };
655645
let attrs = {
656646
let hash = self.tcx.with_stable_hashing_context(|mut hcx| {
657647
let mut stable_hasher = StableHasher::new();
@@ -710,7 +700,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
710700
assert_ne!(local_id, hir::ItemLocalId::new(0));
711701
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
712702
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
713-
self.local_id_to_def_id.insert(local_id, def_id);
714703
}
715704

716705
if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {

compiler/rustc_hir/src/hir.rs

-3
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,6 @@ pub struct OwnerNodes<'tcx> {
831831
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
832832
/// Content of local bodies.
833833
pub bodies: SortedMap<ItemLocalId, &'tcx Body<'tcx>>,
834-
/// Non-owning definitions contained in this owner.
835-
pub local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>,
836834
}
837835

838836
impl<'tcx> OwnerNodes<'tcx> {
@@ -862,7 +860,6 @@ impl fmt::Debug for OwnerNodes<'_> {
862860
.collect::<Vec<_>>(),
863861
)
864862
.field("bodies", &self.bodies)
865-
.field("local_id_to_def_id", &self.local_id_to_def_id)
866863
.field("hash_without_bodies", &self.hash_without_bodies)
867864
.field("hash_including_bodies", &self.hash_including_bodies)
868865
.finish()

compiler/rustc_hir/src/intravisit.rs

+27-21
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use crate::hir::*;
6868
use rustc_ast::walk_list;
6969
use rustc_ast::{Attribute, Label};
70+
use rustc_span::def_id::LocalDefId;
7071
use rustc_span::symbol::{Ident, Symbol};
7172
use rustc_span::Span;
7273

@@ -364,7 +365,7 @@ pub trait Visitor<'v>: Sized {
364365
fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) {
365366
walk_fn_decl(self, fd)
366367
}
367-
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, _: Span, id: HirId) {
368+
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, _: Span, id: LocalDefId) {
368369
walk_fn(self, fk, fd, b, id)
369370
}
370371
fn visit_use(&mut self, path: &'v UsePath<'v>, hir_id: HirId) {
@@ -468,13 +469,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
468469
visitor.visit_ty(typ);
469470
visitor.visit_nested_body(body);
470471
}
471-
ItemKind::Fn(ref sig, ref generics, body_id) => visitor.visit_fn(
472-
FnKind::ItemFn(item.ident, generics, sig.header),
473-
sig.decl,
474-
body_id,
475-
item.span,
476-
item.hir_id(),
477-
),
472+
ItemKind::Fn(ref sig, ref generics, body_id) => {
473+
visitor.visit_id(item.hir_id());
474+
visitor.visit_fn(
475+
FnKind::ItemFn(item.ident, generics, sig.header),
476+
sig.decl,
477+
body_id,
478+
item.span,
479+
item.owner_id.def_id,
480+
)
481+
}
478482
ItemKind::Macro(..) => {
479483
visitor.visit_id(item.hir_id());
480484
}
@@ -733,7 +737,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
733737
walk_list!(visitor, visit_arm, arms);
734738
}
735739
ExprKind::Closure(&Closure {
736-
def_id: _,
740+
def_id,
737741
binder: _,
738742
bound_generic_params,
739743
fn_decl,
@@ -745,7 +749,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
745749
constness: _,
746750
}) => {
747751
walk_list!(visitor, visit_generic_param, bound_generic_params);
748-
visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, expression.hir_id)
752+
visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, def_id)
749753
}
750754
ExprKind::Block(ref block, ref opt_label) => {
751755
walk_list!(visitor, visit_label, opt_label);
@@ -923,9 +927,8 @@ pub fn walk_fn<'v, V: Visitor<'v>>(
923927
function_kind: FnKind<'v>,
924928
function_declaration: &'v FnDecl<'v>,
925929
body_id: BodyId,
926-
id: HirId,
930+
_: LocalDefId,
927931
) {
928-
visitor.visit_id(id);
929932
visitor.visit_fn_decl(function_declaration);
930933
walk_fn_kind(visitor, function_kind);
931934
visitor.visit_nested_body(body_id)
@@ -953,26 +956,30 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
953956
let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item;
954957
let hir_id = trait_item.hir_id();
955958
visitor.visit_ident(ident);
956-
visitor.visit_generics(generics);
957-
visitor.visit_defaultness(defaultness);
959+
visitor.visit_generics(&generics);
960+
visitor.visit_defaultness(&defaultness);
961+
visitor.visit_id(hir_id);
958962
match *kind {
959963
TraitItemKind::Const(ref ty, default) => {
960-
visitor.visit_id(hir_id);
961964
visitor.visit_ty(ty);
962965
walk_list!(visitor, visit_nested_body, default);
963966
}
964967
TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
965-
visitor.visit_id(hir_id);
966968
visitor.visit_fn_decl(sig.decl);
967969
for &param_name in param_names {
968970
visitor.visit_ident(param_name);
969971
}
970972
}
971973
TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
972-
visitor.visit_fn(FnKind::Method(ident, sig), sig.decl, body_id, span, hir_id);
974+
visitor.visit_fn(
975+
FnKind::Method(ident, sig),
976+
sig.decl,
977+
body_id,
978+
span,
979+
trait_item.owner_id.def_id,
980+
);
973981
}
974982
TraitItemKind::Type(bounds, ref default) => {
975-
visitor.visit_id(hir_id);
976983
walk_list!(visitor, visit_param_bound, bounds);
977984
walk_list!(visitor, visit_ty, default);
978985
}
@@ -1002,9 +1009,9 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
10021009
visitor.visit_ident(ident);
10031010
visitor.visit_generics(generics);
10041011
visitor.visit_defaultness(defaultness);
1012+
visitor.visit_id(impl_item.hir_id());
10051013
match *kind {
10061014
ImplItemKind::Const(ref ty, body) => {
1007-
visitor.visit_id(impl_item.hir_id());
10081015
visitor.visit_ty(ty);
10091016
visitor.visit_nested_body(body);
10101017
}
@@ -1014,11 +1021,10 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
10141021
sig.decl,
10151022
body_id,
10161023
impl_item.span,
1017-
impl_item.hir_id(),
1024+
impl_item.owner_id.def_id,
10181025
);
10191026
}
10201027
ImplItemKind::Type(ref ty) => {
1021-
visitor.visit_id(impl_item.hir_id());
10221028
visitor.visit_ty(ty);
10231029
}
10241030
}

compiler/rustc_hir/src/stable_hash_impls.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,8 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'
100100
// `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
101101
// the body satisfies the condition of two nodes being different have different
102102
// `hash_stable` results.
103-
let OwnerNodes {
104-
hash_including_bodies,
105-
hash_without_bodies: _,
106-
nodes: _,
107-
bodies: _,
108-
local_id_to_def_id: _,
109-
} = *self;
103+
let OwnerNodes { hash_including_bodies, hash_without_bodies: _, nodes: _, bodies: _ } =
104+
*self;
110105
hash_including_bodies.hash_stable(hcx, hasher);
111106
}
112107
}

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
665665
DefKind::GlobalAsm => {
666666
let it = tcx.hir().item(id);
667667
let hir::ItemKind::GlobalAsm(asm) = it.kind else { span_bug!(it.span, "DefKind::GlobalAsm but got {:#?}", it) };
668-
InlineAsmCtxt::new_global_asm(tcx).check_asm(asm, id.hir_id());
668+
InlineAsmCtxt::new_global_asm(tcx).check_asm(asm, id.owner_id.def_id);
669669
}
670670
_ => {}
671671
}

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_data_structures::fx::FxHashSet;
33
use rustc_hir as hir;
44
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitable, UintTy};
55
use rustc_session::lint;
6+
use rustc_span::def_id::LocalDefId;
67
use rustc_span::{Symbol, DUMMY_SP};
78
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};
89

@@ -253,10 +254,8 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
253254
Some(asm_ty)
254255
}
255256

256-
pub fn check_asm(&self, asm: &hir::InlineAsm<'tcx>, enclosing_id: hir::HirId) {
257-
let hir = self.tcx.hir();
258-
let enclosing_def_id = hir.local_def_id(enclosing_id).to_def_id();
259-
let target_features = self.tcx.asm_target_features(enclosing_def_id);
257+
pub fn check_asm(&self, asm: &hir::InlineAsm<'tcx>, enclosing_id: LocalDefId) {
258+
let target_features = self.tcx.asm_target_features(enclosing_id.to_def_id());
260259
let Some(asm_arch) = self.tcx.sess.asm_arch else {
261260
self.tcx.sess.delay_span_bug(DUMMY_SP, "target architecture does not support asm");
262261
return;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
391391
gather_gat_bounds(
392392
tcx,
393393
param_env,
394-
item_def_id.def_id,
394+
item_def_id,
395395
sig.inputs_and_output,
396396
// We also assume that all of the function signature's parameter types
397397
// are well formed.
@@ -413,7 +413,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
413413
gather_gat_bounds(
414414
tcx,
415415
param_env,
416-
item_def_id.def_id,
416+
item_def_id,
417417
tcx.explicit_item_bounds(item_def_id).to_vec(),
418418
&FxIndexSet::default(),
419419
gat_def_id.def_id,
@@ -563,7 +563,7 @@ fn augment_param_env<'tcx>(
563563
fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
564564
tcx: TyCtxt<'tcx>,
565565
param_env: ty::ParamEnv<'tcx>,
566-
item_def_id: LocalDefId,
566+
item_def_id: hir::OwnerId,
567567
to_check: T,
568568
wf_tys: &FxIndexSet<Ty<'tcx>>,
569569
gat_def_id: LocalDefId,
@@ -596,7 +596,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
596596
// reflected in a where clause on the GAT itself.
597597
for (ty, ty_idx) in &types {
598598
// In our example, requires that `Self: 'a`
599-
if ty_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *ty, *region_a) {
599+
if ty_known_to_outlive(tcx, item_def_id.def_id, param_env, &wf_tys, *ty, *region_a) {
600600
debug!(?ty_idx, ?region_a_idx);
601601
debug!("required clause: {ty} must outlive {region_a}");
602602
// Translate into the generic parameters of the GAT. In
@@ -634,7 +634,14 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
634634
if ty::ReStatic == **region_b || region_a == region_b {
635635
continue;
636636
}
637-
if region_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *region_a, *region_b) {
637+
if region_known_to_outlive(
638+
tcx,
639+
item_def_id.def_id,
640+
param_env,
641+
&wf_tys,
642+
*region_a,
643+
*region_b,
644+
) {
638645
debug!(?region_a_idx, ?region_b_idx);
639646
debug!("required clause: {region_a} must outlive {region_b}");
640647
// Translate into the generic parameters of the GAT.

0 commit comments

Comments
 (0)