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:
Nicholas Nethercote 2022-03-05 07:28:41 +11:00
parent 5f4e067719
commit ca5525d564
169 changed files with 702 additions and 687 deletions

View file

@ -639,7 +639,7 @@ pub fn type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll
AdtKind::Struct => prepare_struct_metadata(cx, t, unique_type_id).finalize(cx),
AdtKind::Union => prepare_union_metadata(cx, t, unique_type_id).finalize(cx),
AdtKind::Enum => {
prepare_enum_metadata(cx, t, def.did, unique_type_id, vec![]).finalize(cx)
prepare_enum_metadata(cx, t, def.did(), unique_type_id, vec![]).finalize(cx)
}
},
ty::Tuple(tys) => {
@ -1207,7 +1207,7 @@ fn prepare_struct_metadata<'ll, 'tcx>(
let struct_name = compute_debuginfo_type_name(cx.tcx, struct_type, false);
let (struct_def_id, variant) = match struct_type.kind() {
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
ty::Adt(def, _) => (def.did(), def.non_enum_variant()),
_ => bug!("prepare_struct_metadata on a non-ADT"),
};
@ -1384,7 +1384,7 @@ fn prepare_union_metadata<'ll, 'tcx>(
let union_name = compute_debuginfo_type_name(cx.tcx, union_type, false);
let (union_def_id, variant) = match union_type.kind() {
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
ty::Adt(def, _) => (def.did(), def.non_enum_variant()),
_ => bug!("prepare_union_metadata on a non-ADT"),
};
@ -1466,7 +1466,7 @@ impl<'ll, 'tcx> EnumMemberDescriptionFactory<'ll, 'tcx> {
};
let variant_info_for = |index: VariantIdx| match *self.enum_type.kind() {
ty::Adt(adt, _) => VariantInfo::Adt(&adt.variants[index], index),
ty::Adt(adt, _) => VariantInfo::Adt(&adt.variant(index), index),
ty::Generator(def_id, _, _) => {
let (generator_layout, generator_saved_local_names) =
generator_variant_info_data.as_ref().unwrap();
@ -1490,7 +1490,7 @@ impl<'ll, 'tcx> EnumMemberDescriptionFactory<'ll, 'tcx> {
match self.layout.variants {
Variants::Single { index } => {
if let ty::Adt(adt, _) = self.enum_type.kind() {
if adt.variants.is_empty() {
if adt.variants().is_empty() {
return vec![];
}
}
@ -1940,7 +1940,7 @@ fn prepare_enum_metadata<'ll, 'tcx>(
let discriminant_type_metadata = |discr: Primitive| {
let enumerators_metadata: Vec<_> = match enum_type.kind() {
ty::Adt(def, _) => iter::zip(def.discriminants(tcx), &def.variants)
ty::Adt(def, _) => iter::zip(def.discriminants(tcx), def.variants())
.map(|((_, discr), v)| {
let name = v.name.as_str();
let is_unsigned = match discr.ty.kind() {
@ -2311,7 +2311,7 @@ fn set_members_of_composite_type<'ll, 'tcx>(
fn compute_type_parameters<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIArray {
if let ty::Adt(def, substs) = *ty.kind() {
if substs.types().next().is_some() {
let generics = cx.tcx.generics_of(def.did);
let generics = cx.tcx.generics_of(def.did());
let names = get_parameter_names(cx, generics);
let template_params: Vec<_> = iter::zip(substs, names)
.filter_map(|(kind, name)| {

View file

@ -524,7 +524,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
{
Some(type_metadata(cx, impl_self_ty))
} else {
Some(namespace::item_namespace(cx, def.did))
Some(namespace::item_namespace(cx, def.did()))
}
}
_ => None,

View file

@ -53,8 +53,8 @@ fn uncached_llvm_type<'a, 'tcx>(
if let (&ty::Adt(def, _), &Variants::Single { index }) =
(layout.ty.kind(), &layout.variants)
{
if def.is_enum() && !def.variants.is_empty() {
write!(&mut name, "::{}", def.variants[index].name).unwrap();
if def.is_enum() && !def.variants().is_empty() {
write!(&mut name, "::{}", def.variant(index).name).unwrap();
}
}
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =