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:
commit
7c75fe4c85
63 changed files with 449 additions and 549 deletions
|
@ -219,18 +219,6 @@ impl CheckAttrVisitor<'_> {
|
|||
return;
|
||||
}
|
||||
|
||||
// FIXME(@lcnr): this doesn't belong here.
|
||||
if matches!(
|
||||
target,
|
||||
Target::Closure
|
||||
| Target::Fn
|
||||
| Target::Method(_)
|
||||
| Target::ForeignFn
|
||||
| Target::ForeignStatic
|
||||
) {
|
||||
self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
|
||||
}
|
||||
|
||||
self.check_repr(attrs, span, target, item, hir_id);
|
||||
self.check_used(attrs, target);
|
||||
}
|
||||
|
@ -423,8 +411,7 @@ impl CheckAttrVisitor<'_> {
|
|||
if let Some(generics) = tcx.hir().get_generics(tcx.hir().local_def_id(hir_id)) {
|
||||
for p in generics.params {
|
||||
let hir::GenericParamKind::Type { .. } = p.kind else { continue };
|
||||
let param_id = tcx.hir().local_def_id(p.hir_id);
|
||||
let default = tcx.object_lifetime_default(param_id);
|
||||
let default = tcx.object_lifetime_default(p.def_id);
|
||||
let repr = match default {
|
||||
ObjectLifetimeDefault::Empty => "BaseDefault".to_owned(),
|
||||
ObjectLifetimeDefault::Static => "'static".to_owned(),
|
||||
|
@ -2150,7 +2137,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_variant(&mut self, variant: &'tcx hir::Variant<'tcx>) {
|
||||
self.check_attributes(variant.id, variant.span, Target::Variant, None);
|
||||
self.check_attributes(variant.hir_id, variant.span, Target::Variant, None);
|
||||
intravisit::walk_variant(self, variant)
|
||||
}
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
|||
let has_repr_c = self.repr_has_repr_c;
|
||||
let has_repr_simd = self.repr_has_repr_simd;
|
||||
let live_fields = def.fields().iter().filter_map(|f| {
|
||||
let def_id = tcx.hir().local_def_id(f.hir_id);
|
||||
let def_id = f.def_id;
|
||||
if has_repr_c || (f.is_positional() && has_repr_simd) {
|
||||
return Some(def_id);
|
||||
}
|
||||
|
@ -522,17 +522,13 @@ fn check_item<'tcx>(
|
|||
DefKind::Enum => {
|
||||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
|
||||
let hir = tcx.hir();
|
||||
if allow_dead_code {
|
||||
worklist.extend(
|
||||
enum_def.variants.iter().map(|variant| hir.local_def_id(variant.id)),
|
||||
);
|
||||
worklist.extend(enum_def.variants.iter().map(|variant| variant.def_id));
|
||||
}
|
||||
|
||||
for variant in enum_def.variants {
|
||||
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
|
||||
struct_constructors
|
||||
.insert(hir.local_def_id(ctor_hir_id), hir.local_def_id(variant.id));
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
struct_constructors.insert(ctor_def_id, variant.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
|||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
||||
for variant in def.variants {
|
||||
collector.check_for_lang(Target::Variant, variant.id);
|
||||
collector.check_for_lang(Target::Variant, variant.hir_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
|||
}
|
||||
intravisit::walk_expr(self, expr);
|
||||
}
|
||||
hir::ExprKind::Closure { .. } => {
|
||||
hir::ExprKind::Closure(closure) => {
|
||||
// Interesting control flow (for loops can contain labeled
|
||||
// breaks or continues)
|
||||
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
|
||||
|
@ -423,8 +423,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
|||
// in better error messages than just pointing at the closure
|
||||
// construction site.
|
||||
let mut call_caps = Vec::new();
|
||||
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
||||
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
|
||||
if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
|
||||
call_caps.extend(upvars.keys().map(|var_id| {
|
||||
let upvar = upvars[var_id];
|
||||
let upvar_ln = self.add_live_node(UpvarNode(upvar.span));
|
||||
|
|
|
@ -358,9 +358,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
const_stab_inherit = InheritConstStability::Yes;
|
||||
}
|
||||
hir::ItemKind::Struct(ref sd, _) => {
|
||||
if let Some(ctor_hir_id) = sd.ctor_hir_id() {
|
||||
if let Some(ctor_def_id) = sd.ctor_def_id() {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(ctor_hir_id),
|
||||
ctor_def_id,
|
||||
i.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
|
@ -435,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
|
||||
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(var.id),
|
||||
var.def_id,
|
||||
var.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
|
@ -443,9 +443,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
InheritConstStability::No,
|
||||
InheritStability::Yes,
|
||||
|v| {
|
||||
if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
|
||||
if let Some(ctor_def_id) = var.data.ctor_def_id() {
|
||||
v.annotate(
|
||||
v.tcx.hir().local_def_id(ctor_hir_id),
|
||||
ctor_def_id,
|
||||
var.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
|
@ -463,7 +463,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
|
||||
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(s.hir_id),
|
||||
s.def_id,
|
||||
s.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
|
@ -500,7 +500,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
};
|
||||
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(p.hir_id),
|
||||
p.def_id,
|
||||
p.span,
|
||||
None,
|
||||
kind,
|
||||
|
@ -601,15 +601,15 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(var.id), var.span);
|
||||
if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(ctor_hir_id), var.span);
|
||||
self.check_missing_stability(var.def_id, var.span);
|
||||
if let Some(ctor_def_id) = var.data.ctor_def_id() {
|
||||
self.check_missing_stability(ctor_def_id, var.span);
|
||||
}
|
||||
intravisit::walk_variant(self, var);
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(s.hir_id), s.span);
|
||||
self.check_missing_stability(s.def_id, s.span);
|
||||
intravisit::walk_field_def(self, s);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,9 +75,8 @@ impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||
if let hir::ExprKind::Closure { .. } = expr.kind {
|
||||
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
||||
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
|
||||
if let hir::ExprKind::Closure(closure) = expr.kind {
|
||||
if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
|
||||
// Every capture of a closure expression is a local in scope,
|
||||
// that is moved/copied/borrowed into the closure value, and
|
||||
// for this analysis they are like any other access to a local.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue