Skip to content

Commit 19ae2b9

Browse files
committed
Shrink some internal enums
1 parent 6fc8779 commit 19ae2b9

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/librustc/mir/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ pub enum ProjectionElem<'tcx, V, T> {
19391939
/// "Downcast" to a variant of an ADT. Currently, we only introduce
19401940
/// this for ADTs with more than one variant. It may be better to
19411941
/// just introduce it always, or always for enums.
1942-
Downcast(&'tcx AdtDef, usize),
1942+
Downcast(&'tcx AdtDef, u32),
19431943
}
19441944

19451945
/// Alias for projections as they appear in places, where the base is a place
@@ -1950,6 +1950,11 @@ pub type PlaceProjection<'tcx> = Projection<'tcx, Place<'tcx>, Local, Ty<'tcx>>;
19501950
/// and the index is a local.
19511951
pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
19521952

1953+
// at least on 64 bit systems, `PlaceElem` should not be larger than two pointers
1954+
static_assert!(PROJECTION_ELEM_IS_2_PTRS_LARGE:
1955+
mem::size_of::<PlaceElem<'_>>() <= 16
1956+
);
1957+
19531958
/// Alias for projections as they appear in `UserTypeProjection`, where we
19541959
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
19551960
pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>;
@@ -1970,7 +1975,7 @@ impl<'tcx> Place<'tcx> {
19701975
}
19711976

19721977
pub fn downcast(self, adt_def: &'tcx AdtDef, variant_index: usize) -> Place<'tcx> {
1973-
self.elem(ProjectionElem::Downcast(adt_def, variant_index))
1978+
self.elem(ProjectionElem::Downcast(adt_def, variant_index as u32))
19741979
}
19751980

19761981
pub fn index(self, index: Local) -> Place<'tcx> {
@@ -2021,7 +2026,7 @@ impl<'tcx> Debug for Place<'tcx> {
20212026
Promoted(ref promoted) => write!(fmt, "({:?}: {:?})", promoted.0, promoted.1),
20222027
Projection(ref data) => match data.elem {
20232028
ProjectionElem::Downcast(ref adt_def, index) => {
2024-
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].name)
2029+
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index as usize].name)
20252030
}
20262031
ProjectionElem::Deref => write!(fmt, "(*{:?})", data.base),
20272032
ProjectionElem::Field(field, ty) => {

src/librustc/mir/tcx.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ pub enum PlaceTy<'tcx> {
2727
/// Downcast to a particular variant of an enum.
2828
Downcast { adt_def: &'tcx AdtDef,
2929
substs: &'tcx Substs<'tcx>,
30-
variant_index: usize },
30+
variant_index: u32 },
3131
}
3232

33+
static_assert!(PLACE_TY_IS_3_PTRS_LARGE:
34+
mem::size_of::<PlaceTy<'_>>() <= 24
35+
);
36+
3337
impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
3438
pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
3539
PlaceTy::Ty { ty }
@@ -58,7 +62,7 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
5862
(PlaceTy::Ty {
5963
ty: &ty::TyS { sty: ty::TyKind::Adt(adt_def, substs), .. } }, variant_index) |
6064
(PlaceTy::Downcast { adt_def, substs, variant_index }, _) => {
61-
let variant_def = &adt_def.variants[variant_index];
65+
let variant_def = &adt_def.variants[variant_index as usize];
6266
let field_def = &variant_def.fields[f.index()];
6367
field_def.ty(tcx, substs)
6468
}
@@ -134,7 +138,7 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
134138
match self.to_ty(tcx).sty {
135139
ty::Adt(adt_def, substs) => {
136140
assert!(adt_def.is_enum());
137-
assert!(index < adt_def.variants.len());
141+
assert!(index < adt_def.variants.len() as u32);
138142
assert_eq!(adt_def, adt_def1);
139143
PlaceTy::Downcast { adt_def,
140144
substs,

src/librustc/ty/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,7 @@ pub struct FieldDef {
18011801
/// table.
18021802
pub struct AdtDef {
18031803
pub did: DefId,
1804+
// TODO: make this an IndexVec
18041805
pub variants: Vec<VariantDef>,
18051806
flags: AdtFlags,
18061807
pub repr: ReprOptions,

src/librustc/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CloneTypeFoldableAndLiftImpls! {
3333
(),
3434
bool,
3535
usize,
36+
u32,
3637
u64,
3738
::middle::region::Scope,
3839
::syntax::ast::FloatTy,

0 commit comments

Comments
 (0)