From e439761b8fe67f39c1a987fae10433b9a29c045a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 5 Mar 2022 07:28:41 +1100 Subject: [PATCH] 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`. --- src/common.rs | 2 +- src/unsize.rs | 4 ++-- src/value_and_place.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common.rs b/src/common.rs index d3e36be3244..89fd0bfa8bb 100644 --- a/src/common.rs +++ b/src/common.rs @@ -67,7 +67,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option { + ty::Adt(adt_def, _) if adt_def.repr().simd() => { let (element, count) = match &tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().abi { Abi::Vector { element, count } => (element.clone(), *count), diff --git a/src/unsize.rs b/src/unsize.rs index 8cae506e0cb..fd63c3ecddb 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -127,7 +127,7 @@ pub(crate) fn coerce_unsized_into<'tcx>( (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => { assert_eq!(def_a, def_b); - for i in 0..def_a.variants[VariantIdx::new(0)].fields.len() { + for i in 0..def_a.variant(VariantIdx::new(0)).fields.len() { let src_f = src.value_field(fx, mir::Field::new(i)); let dst_f = dst.place_field(fx, mir::Field::new(i)); @@ -200,7 +200,7 @@ pub(crate) fn size_and_align_of_dst<'tcx>( // Packed types ignore the alignment of their fields. if let ty::Adt(def, _) = layout.ty.kind() { - if def.repr.packed() { + if def.repr().packed() { unsized_align = sized_align; } } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index b016af5174e..afe8797a030 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -24,7 +24,7 @@ fn codegen_field<'tcx>( } match field_layout.ty.kind() { ty::Slice(..) | ty::Str | ty::Foreign(..) => simple(fx), - ty::Adt(def, _) if def.repr.packed() => { + ty::Adt(def, _) if def.repr().packed() => { assert_eq!(layout.align.abi.bytes(), 1); simple(fx) } @@ -816,7 +816,7 @@ pub(crate) fn assert_assignable<'tcx>( // dyn for<'r> Trait<'r> -> dyn Trait<'_> is allowed } (&ty::Adt(adt_def_a, substs_a), &ty::Adt(adt_def_b, substs_b)) - if adt_def_a.did == adt_def_b.did => + if adt_def_a.did() == adt_def_b.did() => { let mut types_a = substs_a.types(); let mut types_b = substs_b.types();