@@ -8,6 +8,7 @@ use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
8
8
use std:: str:: FromStr ;
9
9
10
10
use bitflags:: bitflags;
11
+ use rustc_data_structures:: intern:: Interned ;
11
12
#[ cfg( feature = "nightly" ) ]
12
13
use rustc_data_structures:: stable_hasher:: StableOrd ;
13
14
use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -1257,9 +1258,9 @@ impl Abi {
1257
1258
1258
1259
#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
1259
1260
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1260
- pub enum Variants < V : Idx > {
1261
+ pub enum Variants {
1261
1262
/// Single enum variants, structs/tuples, unions, and all non-ADTs.
1262
- Single { index : V } ,
1263
+ Single { index : VariantIdx } ,
1263
1264
1264
1265
/// Enum-likes with more than one inhabited variant: each variant comes with
1265
1266
/// a *discriminant* (usually the same as the variant index but the user can
@@ -1269,15 +1270,15 @@ pub enum Variants<V: Idx> {
1269
1270
/// For enums, the tag is the sole field of the layout.
1270
1271
Multiple {
1271
1272
tag : Scalar ,
1272
- tag_encoding : TagEncoding < V > ,
1273
+ tag_encoding : TagEncoding ,
1273
1274
tag_field : usize ,
1274
- variants : IndexVec < V , LayoutS < V > > ,
1275
+ variants : IndexVec < VariantIdx , LayoutS > ,
1275
1276
} ,
1276
1277
}
1277
1278
1278
1279
#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
1279
1280
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1280
- pub enum TagEncoding < V : Idx > {
1281
+ pub enum TagEncoding {
1281
1282
/// The tag directly stores the discriminant, but possibly with a smaller layout
1282
1283
/// (so converting the tag to the discriminant can require sign extension).
1283
1284
Direct ,
@@ -1292,7 +1293,11 @@ pub enum TagEncoding<V: Idx> {
1292
1293
/// For example, `Option<(usize, &T)>` is represented such that
1293
1294
/// `None` has a null pointer for the second tuple field, and
1294
1295
/// `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
+ } ,
1296
1301
}
1297
1302
1298
1303
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
@@ -1379,9 +1384,14 @@ impl Niche {
1379
1384
}
1380
1385
}
1381
1386
1387
+ rustc_index:: newtype_index! {
1388
+ #[ derive( HashStable_Generic ) ]
1389
+ pub struct VariantIdx { }
1390
+ }
1391
+
1382
1392
#[ derive( PartialEq , Eq , Hash , Clone ) ]
1383
1393
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1384
- pub struct LayoutS < V : Idx > {
1394
+ pub struct LayoutS {
1385
1395
/// Says where the fields are located within the layout.
1386
1396
pub fields : FieldsShape ,
1387
1397
@@ -1392,7 +1402,7 @@ pub struct LayoutS<V: Idx> {
1392
1402
///
1393
1403
/// To access all fields of this layout, both `fields` and the fields of the active variant
1394
1404
/// must be taken into account.
1395
- pub variants : Variants < V > ,
1405
+ pub variants : Variants ,
1396
1406
1397
1407
/// The `abi` defines how this data is passed between functions, and it defines
1398
1408
/// value restrictions via `valid_range`.
@@ -1411,13 +1421,13 @@ pub struct LayoutS<V: Idx> {
1411
1421
pub size : Size ,
1412
1422
}
1413
1423
1414
- impl < V : Idx > LayoutS < V > {
1424
+ impl LayoutS {
1415
1425
pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
1416
1426
let largest_niche = Niche :: from_scalar ( cx, Size :: ZERO , scalar) ;
1417
1427
let size = scalar. size ( cx) ;
1418
1428
let align = scalar. align ( cx) ;
1419
1429
LayoutS {
1420
- variants : Variants :: Single { index : V :: new ( 0 ) } ,
1430
+ variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
1421
1431
fields : FieldsShape :: Primitive ,
1422
1432
abi : Abi :: Scalar ( scalar) ,
1423
1433
largest_niche,
@@ -1427,7 +1437,7 @@ impl<V: Idx> LayoutS<V> {
1427
1437
}
1428
1438
}
1429
1439
1430
- impl < V : Idx > fmt:: Debug for LayoutS < V > {
1440
+ impl fmt:: Debug for LayoutS {
1431
1441
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1432
1442
// This is how `Layout` used to print before it become
1433
1443
// `Interned<LayoutS>`. We print it like this to avoid having to update
@@ -1444,6 +1454,43 @@ impl<V: Idx> fmt::Debug for LayoutS<V> {
1444
1454
}
1445
1455
}
1446
1456
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
+
1447
1494
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
1448
1495
pub enum PointerKind {
1449
1496
/// Most general case, we know no restrictions to tell LLVM.
@@ -1479,7 +1526,7 @@ pub enum InitKind {
1479
1526
UninitMitigated0x01Fill ,
1480
1527
}
1481
1528
1482
- impl < V : Idx > LayoutS < V > {
1529
+ impl LayoutS {
1483
1530
/// Returns `true` if the layout corresponds to an unsized type.
1484
1531
pub fn is_unsized ( & self ) -> bool {
1485
1532
self . abi . is_unsized ( )
0 commit comments