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

@ -336,7 +336,7 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> {
ProjectionElem::Field(..) => {
let ty = place_base.ty(&self.body.local_decls, self.tcx).ty;
if let ty::Adt(def, _) = ty.kind() {
if self.tcx.layout_scalar_valid_range(def.did)
if self.tcx.layout_scalar_valid_range(def.did())
!= (Bound::Unbounded, Bound::Unbounded)
{
let details = if is_mut_use {

View file

@ -210,7 +210,7 @@ struct SuspensionPoint<'tcx> {
struct TransformVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
state_adt_ref: &'tcx AdtDef,
state_adt_ref: AdtDef<'tcx>,
state_substs: SubstsRef<'tcx>,
// The type of the discriminant in the generator struct
@ -243,11 +243,11 @@ impl<'tcx> TransformVisitor<'tcx> {
val: Operand<'tcx>,
source_info: SourceInfo,
) -> impl Iterator<Item = Statement<'tcx>> {
let kind = AggregateKind::Adt(self.state_adt_ref.did, idx, self.state_substs, None, None);
assert_eq!(self.state_adt_ref.variants[idx].fields.len(), 1);
let kind = AggregateKind::Adt(self.state_adt_ref.did(), idx, self.state_substs, None, None);
assert_eq!(self.state_adt_ref.variant(idx).fields.len(), 1);
let ty = self
.tcx
.type_of(self.state_adt_ref.variants[idx].fields[0].did)
.type_of(self.state_adt_ref.variant(idx).fields[0].did)
.subst(self.tcx, self.state_substs);
expand_aggregate(
Place::return_place(),

View file

@ -124,7 +124,7 @@ fn is_needs_drop_and_init<'tcx>(
//
// If its projection *is* present in `MoveData`, then the field may have been moved
// from separate from its parent. Recurse.
adt.variants.iter_enumerated().any(|(vid, variant)| {
adt.variants().iter_enumerated().any(|(vid, variant)| {
// Enums have multiple variants, which are discriminated with a `Downcast` projection.
// Structs have a single variant, and don't use a `Downcast` projection.
let mpi = if adt.is_enum() {

View file

@ -760,10 +760,10 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
let statements = expand_aggregate(
Place::return_place(),
adt_def.variants[variant_index].fields.iter().enumerate().map(|(idx, field_def)| {
adt_def.variant(variant_index).fields.iter().enumerate().map(|(idx, field_def)| {
(Operand::Move(Place::from(Local::new(idx + 1))), field_def.ty(tcx, substs))
}),
AggregateKind::Adt(adt_def.did, variant_index, substs, None, None),
AggregateKind::Adt(adt_def.did(), variant_index, substs, None, None),
source_info,
tcx,
)

View file

@ -726,7 +726,7 @@ impl<'tcx> SimplifyBranchSameOptimizationFinder<'_, 'tcx> {
);
return StatementEquality::NotEqual;
}
let variant_is_fieldless = adt.variants[variant_index].fields.is_empty();
let variant_is_fieldless = adt.variant(variant_index).fields.is_empty();
if !variant_is_fieldless {
trace!("NO: variant {:?} was not fieldless", variant_index);
return StatementEquality::NotEqual;