From ca5525d5643f4eb7de5c5e69d0691fc8f1cacfca Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 5 Mar 2022 07:28:41 +1100 Subject: 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`. --- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 14 +++++++------- compiler/rustc_codegen_llvm/src/debuginfo/mod.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src/debuginfo') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 89fc8980037..6dfa752dee5 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -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)| { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 1b4a193dbf1..34013b5f737 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -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, -- cgit 1.4.1-3-g733a5