@@ -8,6 +8,7 @@ use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
88use std:: str:: FromStr ;
99
1010use bitflags:: bitflags;
11+ use rustc_data_structures:: intern:: Interned ;
1112#[ cfg( feature = "nightly" ) ]
1213use rustc_data_structures:: stable_hasher:: StableOrd ;
1314use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -1257,9 +1258,9 @@ impl Abi {
12571258
12581259#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
12591260#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1260- pub enum Variants < V : Idx > {
1261+ pub enum Variants {
12611262 /// Single enum variants, structs/tuples, unions, and all non-ADTs.
1262- Single { index : V } ,
1263+ Single { index : VariantIdx } ,
12631264
12641265 /// Enum-likes with more than one inhabited variant: each variant comes with
12651266 /// a *discriminant* (usually the same as the variant index but the user can
@@ -1269,15 +1270,15 @@ pub enum Variants<V: Idx> {
12691270 /// For enums, the tag is the sole field of the layout.
12701271 Multiple {
12711272 tag : Scalar ,
1272- tag_encoding : TagEncoding < V > ,
1273+ tag_encoding : TagEncoding ,
12731274 tag_field : usize ,
1274- variants : IndexVec < V , LayoutS < V > > ,
1275+ variants : IndexVec < VariantIdx , LayoutS > ,
12751276 } ,
12761277}
12771278
12781279#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
12791280#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1280- pub enum TagEncoding < V : Idx > {
1281+ pub enum TagEncoding {
12811282 /// The tag directly stores the discriminant, but possibly with a smaller layout
12821283 /// (so converting the tag to the discriminant can require sign extension).
12831284 Direct ,
@@ -1292,7 +1293,11 @@ pub enum TagEncoding<V: Idx> {
12921293 /// For example, `Option<(usize, &T)>` is represented such that
12931294 /// `None` has a null pointer for the second tuple field, and
12941295 /// `Some` is the identity function (with a non-null reference).
1295- Niche { untagged_variant : V , niche_variants : RangeInclusive < V > , niche_start : u128 } ,
1296+ Niche {
1297+ untagged_variant : VariantIdx ,
1298+ niche_variants : RangeInclusive < VariantIdx > ,
1299+ niche_start : u128 ,
1300+ } ,
12961301}
12971302
12981303#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
@@ -1379,9 +1384,14 @@ impl Niche {
13791384 }
13801385}
13811386
1387+ rustc_index:: newtype_index! {
1388+ #[ derive( HashStable_Generic ) ]
1389+ pub struct VariantIdx { }
1390+ }
1391+
13821392#[ derive( PartialEq , Eq , Hash , Clone ) ]
13831393#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1384- pub struct LayoutS < V : Idx > {
1394+ pub struct LayoutS {
13851395 /// Says where the fields are located within the layout.
13861396 pub fields : FieldsShape ,
13871397
@@ -1392,7 +1402,7 @@ pub struct LayoutS<V: Idx> {
13921402 ///
13931403 /// To access all fields of this layout, both `fields` and the fields of the active variant
13941404 /// must be taken into account.
1395- pub variants : Variants < V > ,
1405+ pub variants : Variants ,
13961406
13971407 /// The `abi` defines how this data is passed between functions, and it defines
13981408 /// value restrictions via `valid_range`.
@@ -1411,13 +1421,13 @@ pub struct LayoutS<V: Idx> {
14111421 pub size : Size ,
14121422}
14131423
1414- impl < V : Idx > LayoutS < V > {
1424+ impl LayoutS {
14151425 pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
14161426 let largest_niche = Niche :: from_scalar ( cx, Size :: ZERO , scalar) ;
14171427 let size = scalar. size ( cx) ;
14181428 let align = scalar. align ( cx) ;
14191429 LayoutS {
1420- variants : Variants :: Single { index : V :: new ( 0 ) } ,
1430+ variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
14211431 fields : FieldsShape :: Primitive ,
14221432 abi : Abi :: Scalar ( scalar) ,
14231433 largest_niche,
@@ -1427,7 +1437,7 @@ impl<V: Idx> LayoutS<V> {
14271437 }
14281438}
14291439
1430- impl < V : Idx > fmt:: Debug for LayoutS < V > {
1440+ impl fmt:: Debug for LayoutS {
14311441 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
14321442 // This is how `Layout` used to print before it become
14331443 // `Interned<LayoutS>`. We print it like this to avoid having to update
@@ -1444,6 +1454,43 @@ impl<V: Idx> fmt::Debug for LayoutS<V> {
14441454 }
14451455}
14461456
1457+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , HashStable_Generic ) ]
1458+ #[ rustc_pass_by_value]
1459+ pub struct Layout < ' a > ( pub Interned < ' a , LayoutS > ) ;
1460+
1461+ impl < ' a > fmt:: Debug for Layout < ' a > {
1462+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1463+ // See comment on `<LayoutS as Debug>::fmt` above.
1464+ self . 0 . 0 . fmt ( f)
1465+ }
1466+ }
1467+
1468+ impl < ' a > Layout < ' a > {
1469+ pub fn fields ( self ) -> & ' a FieldsShape {
1470+ & self . 0 . 0 . fields
1471+ }
1472+
1473+ pub fn variants ( self ) -> & ' a Variants {
1474+ & self . 0 . 0 . variants
1475+ }
1476+
1477+ pub fn abi ( self ) -> Abi {
1478+ self . 0 . 0 . abi
1479+ }
1480+
1481+ pub fn largest_niche ( self ) -> Option < Niche > {
1482+ self . 0 . 0 . largest_niche
1483+ }
1484+
1485+ pub fn align ( self ) -> AbiAndPrefAlign {
1486+ self . 0 . 0 . align
1487+ }
1488+
1489+ pub fn size ( self ) -> Size {
1490+ self . 0 . 0 . size
1491+ }
1492+ }
1493+
14471494#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
14481495pub enum PointerKind {
14491496 /// Most general case, we know no restrictions to tell LLVM.
@@ -1479,7 +1526,7 @@ pub enum InitKind {
14791526 UninitMitigated0x01Fill ,
14801527}
14811528
1482- impl < V : Idx > LayoutS < V > {
1529+ impl LayoutS {
14831530 /// Returns `true` if the layout corresponds to an unsized type.
14841531 pub fn is_unsized ( & self ) -> bool {
14851532 self . abi . is_unsized ( )
0 commit comments