Improve AdtDef
interning.
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
This commit is contained in:
parent
5f4e067719
commit
ca5525d564
169 changed files with 702 additions and 687 deletions
|
@ -259,7 +259,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
if self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) {
|
||||
let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap();
|
||||
if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind() {
|
||||
if let Some(adt_def_id) = adt_def.did.as_local() {
|
||||
if let Some(adt_def_id) = adt_def.did().as_local() {
|
||||
self.ignored_derived_traits
|
||||
.entry(adt_def_id)
|
||||
.or_default()
|
||||
|
@ -297,7 +297,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
match item.kind {
|
||||
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) => {
|
||||
let def = self.tcx.adt_def(item.def_id);
|
||||
self.repr_has_repr_c = def.repr.c();
|
||||
self.repr_has_repr_c = def.repr().c();
|
||||
|
||||
intravisit::walk_item(self, &item);
|
||||
}
|
||||
|
@ -328,8 +328,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
self.repr_has_repr_c = had_repr_c;
|
||||
}
|
||||
|
||||
fn mark_as_used_if_union(&mut self, adt: &ty::AdtDef, fields: &[hir::ExprField<'_>]) {
|
||||
if adt.is_union() && adt.non_enum_variant().fields.len() > 1 && adt.did.is_local() {
|
||||
fn mark_as_used_if_union(&mut self, adt: ty::AdtDef<'tcx>, fields: &[hir::ExprField<'_>]) {
|
||||
if adt.is_union() && adt.non_enum_variant().fields.len() > 1 && adt.did().is_local() {
|
||||
for field in fields {
|
||||
let index = self.tcx.field_index(field.hir_id, self.typeck_results());
|
||||
self.insert_def_id(adt.non_enum_variant().fields[index].did);
|
||||
|
@ -382,8 +382,8 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
|||
hir::ExprKind::Struct(ref qpath, ref fields, _) => {
|
||||
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
|
||||
self.handle_res(res);
|
||||
if let ty::Adt(ref adt, _) = self.typeck_results().expr_ty(expr).kind() {
|
||||
self.mark_as_used_if_union(adt, fields);
|
||||
if let ty::Adt(adt, _) = self.typeck_results().expr_ty(expr).kind() {
|
||||
self.mark_as_used_if_union(*adt, fields);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
@ -38,22 +38,22 @@ struct ExprVisitor<'tcx> {
|
|||
fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
let ty::Adt(def, substs) = *ty.kind() else { return ty };
|
||||
|
||||
if def.variants.len() == 2 && !def.repr.c() && def.repr.int.is_none() {
|
||||
if def.variants().len() == 2 && !def.repr().c() && def.repr().int.is_none() {
|
||||
let data_idx;
|
||||
|
||||
let one = VariantIdx::new(1);
|
||||
let zero = VariantIdx::new(0);
|
||||
|
||||
if def.variants[zero].fields.is_empty() {
|
||||
if def.variant(zero).fields.is_empty() {
|
||||
data_idx = one;
|
||||
} else if def.variants[one].fields.is_empty() {
|
||||
} else if def.variant(one).fields.is_empty() {
|
||||
data_idx = zero;
|
||||
} else {
|
||||
return ty;
|
||||
}
|
||||
|
||||
if def.variants[data_idx].fields.len() == 1 {
|
||||
return def.variants[data_idx].fields[0].ty(tcx, substs);
|
||||
if def.variant(data_idx).fields.len() == 1 {
|
||||
return def.variant(data_idx).fields[0].ty(tcx, substs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ impl<'tcx> ExprVisitor<'tcx> {
|
|||
ty::RawPtr(ty::TypeAndMut { ty, mutbl: _ }) if self.is_thin_ptr_ty(ty) => {
|
||||
Some(asm_ty_isize)
|
||||
}
|
||||
ty::Adt(adt, substs) if adt.repr.simd() => {
|
||||
ty::Adt(adt, substs) if adt.repr().simd() => {
|
||||
let fields = &adt.non_enum_variant().fields;
|
||||
let elem_ty = fields[0].ty(self.tcx, substs);
|
||||
match elem_ty.kind() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue