1
Fork 0

Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead

Record `LocalDefId` in HIR nodes instead of a side table

This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed.

This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.
This commit is contained in:
bors 2022-11-17 07:42:27 +00:00
commit 7c75fe4c85
63 changed files with 449 additions and 549 deletions

View file

@ -608,24 +608,22 @@ impl<'tcx> Cx<'tcx> {
out_expr: out_expr.as_ref().map(|expr| self.mirror_expr(expr)),
},
hir::InlineAsmOperand::Const { ref anon_const } => {
let anon_const_def_id = tcx.hir().local_def_id(anon_const.hir_id);
let value = mir::ConstantKind::from_anon_const(
tcx,
anon_const_def_id,
anon_const.def_id,
self.param_env,
);
let span = tcx.hir().span(anon_const.hir_id);
let span = tcx.def_span(anon_const.def_id);
InlineAsmOperand::Const { value, span }
}
hir::InlineAsmOperand::SymFn { ref anon_const } => {
let anon_const_def_id = tcx.hir().local_def_id(anon_const.hir_id);
let value = mir::ConstantKind::from_anon_const(
tcx,
anon_const_def_id,
anon_const.def_id,
self.param_env,
);
let span = tcx.hir().span(anon_const.hir_id);
let span = tcx.def_span(anon_const.def_id);
InlineAsmOperand::SymFn { value, span }
}
@ -640,7 +638,7 @@ impl<'tcx> Cx<'tcx> {
hir::ExprKind::ConstBlock(ref anon_const) => {
let ty = self.typeck_results().node_type(anon_const.hir_id);
let did = tcx.hir().local_def_id(anon_const.hir_id).to_def_id();
let did = anon_const.def_id.to_def_id();
let typeck_root_def_id = tcx.typeck_root_def_id(did);
let parent_substs =
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, typeck_root_def_id));
@ -859,9 +857,7 @@ impl<'tcx> Cx<'tcx> {
Res::Def(DefKind::ConstParam, def_id) => {
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let item_id = self.tcx.hir().get_parent_node(hir_id);
let item_def_id = self.tcx.hir().local_def_id(item_id);
let generics = self.tcx.generics_of(item_def_id);
let generics = self.tcx.generics_of(hir_id.owner);
let index = generics.param_def_id_to_index[&def_id];
let name = self.tcx.hir().name(hir_id);
let param = ty::ParamConst::new(index, name);

View file

@ -565,8 +565,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
id: hir::HirId,
span: Span,
) -> PatKind<'tcx> {
let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id);
let value = mir::ConstantKind::from_inline_const(self.tcx, anon_const_def_id);
let value = mir::ConstantKind::from_inline_const(self.tcx, anon_const.def_id);
// Evaluate early like we do in `lower_path`.
let value = value.eval(self.tcx, self.param_env);