@@ -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 } ;
@@ -1250,9 +1251,9 @@ impl Abi {
1250
1251
1251
1252
#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
1252
1253
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1253
- pub enum Variants < V : Idx > {
1254
+ pub enum Variants {
1254
1255
/// Single enum variants, structs/tuples, unions, and all non-ADTs.
1255
- Single { index : V } ,
1256
+ Single { index : VariantIdx } ,
1256
1257
1257
1258
/// Enum-likes with more than one inhabited variant: each variant comes with
1258
1259
/// a *discriminant* (usually the same as the variant index but the user can
@@ -1262,15 +1263,15 @@ pub enum Variants<V: Idx> {
1262
1263
/// For enums, the tag is the sole field of the layout.
1263
1264
Multiple {
1264
1265
tag : Scalar ,
1265
- tag_encoding : TagEncoding < V > ,
1266
+ tag_encoding : TagEncoding ,
1266
1267
tag_field : usize ,
1267
- variants : IndexVec < V , LayoutS < V > > ,
1268
+ variants : IndexVec < VariantIdx , LayoutS > ,
1268
1269
} ,
1269
1270
}
1270
1271
1271
1272
#[ derive( PartialEq , Eq , Hash , Clone , Debug ) ]
1272
1273
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1273
- pub enum TagEncoding < V : Idx > {
1274
+ pub enum TagEncoding {
1274
1275
/// The tag directly stores the discriminant, but possibly with a smaller layout
1275
1276
/// (so converting the tag to the discriminant can require sign extension).
1276
1277
Direct ,
@@ -1285,7 +1286,11 @@ pub enum TagEncoding<V: Idx> {
1285
1286
/// For example, `Option<(usize, &T)>` is represented such that
1286
1287
/// `None` has a null pointer for the second tuple field, and
1287
1288
/// `Some` is the identity function (with a non-null reference).
1288
- Niche { untagged_variant : V , niche_variants : RangeInclusive < V > , niche_start : u128 } ,
1289
+ Niche {
1290
+ untagged_variant : VariantIdx ,
1291
+ niche_variants : RangeInclusive < VariantIdx > ,
1292
+ niche_start : u128 ,
1293
+ } ,
1289
1294
}
1290
1295
1291
1296
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
@@ -1372,9 +1377,14 @@ impl Niche {
1372
1377
}
1373
1378
}
1374
1379
1380
+ rustc_index:: newtype_index! {
1381
+ #[ derive( HashStable_Generic ) ]
1382
+ pub struct VariantIdx { }
1383
+ }
1384
+
1375
1385
#[ derive( PartialEq , Eq , Hash , Clone ) ]
1376
1386
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1377
- pub struct LayoutS < V : Idx > {
1387
+ pub struct LayoutS {
1378
1388
/// Says where the fields are located within the layout.
1379
1389
pub fields : FieldsShape ,
1380
1390
@@ -1385,7 +1395,7 @@ pub struct LayoutS<V: Idx> {
1385
1395
///
1386
1396
/// To access all fields of this layout, both `fields` and the fields of the active variant
1387
1397
/// must be taken into account.
1388
- pub variants : Variants < V > ,
1398
+ pub variants : Variants ,
1389
1399
1390
1400
/// The `abi` defines how this data is passed between functions, and it defines
1391
1401
/// value restrictions via `valid_range`.
@@ -1404,13 +1414,13 @@ pub struct LayoutS<V: Idx> {
1404
1414
pub size : Size ,
1405
1415
}
1406
1416
1407
- impl < V : Idx > LayoutS < V > {
1417
+ impl LayoutS {
1408
1418
pub fn scalar < C : HasDataLayout > ( cx : & C , scalar : Scalar ) -> Self {
1409
1419
let largest_niche = Niche :: from_scalar ( cx, Size :: ZERO , scalar) ;
1410
1420
let size = scalar. size ( cx) ;
1411
1421
let align = scalar. align ( cx) ;
1412
1422
LayoutS {
1413
- variants : Variants :: Single { index : V :: new ( 0 ) } ,
1423
+ variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
1414
1424
fields : FieldsShape :: Primitive ,
1415
1425
abi : Abi :: Scalar ( scalar) ,
1416
1426
largest_niche,
@@ -1420,7 +1430,7 @@ impl<V: Idx> LayoutS<V> {
1420
1430
}
1421
1431
}
1422
1432
1423
- impl < V : Idx > fmt:: Debug for LayoutS < V > {
1433
+ impl fmt:: Debug for LayoutS {
1424
1434
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1425
1435
// This is how `Layout` used to print before it become
1426
1436
// `Interned<LayoutS>`. We print it like this to avoid having to update
@@ -1437,6 +1447,43 @@ impl<V: Idx> fmt::Debug for LayoutS<V> {
1437
1447
}
1438
1448
}
1439
1449
1450
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , HashStable_Generic ) ]
1451
+ #[ rustc_pass_by_value]
1452
+ pub struct Layout < ' a > ( pub Interned < ' a , LayoutS > ) ;
1453
+
1454
+ impl < ' a > fmt:: Debug for Layout < ' a > {
1455
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1456
+ // See comment on `<LayoutS as Debug>::fmt` above.
1457
+ self . 0 . 0 . fmt ( f)
1458
+ }
1459
+ }
1460
+
1461
+ impl < ' a > Layout < ' a > {
1462
+ pub fn fields ( self ) -> & ' a FieldsShape {
1463
+ & self . 0 . 0 . fields
1464
+ }
1465
+
1466
+ pub fn variants ( self ) -> & ' a Variants {
1467
+ & self . 0 . 0 . variants
1468
+ }
1469
+
1470
+ pub fn abi ( self ) -> Abi {
1471
+ self . 0 . 0 . abi
1472
+ }
1473
+
1474
+ pub fn largest_niche ( self ) -> Option < Niche > {
1475
+ self . 0 . 0 . largest_niche
1476
+ }
1477
+
1478
+ pub fn align ( self ) -> AbiAndPrefAlign {
1479
+ self . 0 . 0 . align
1480
+ }
1481
+
1482
+ pub fn size ( self ) -> Size {
1483
+ self . 0 . 0 . size
1484
+ }
1485
+ }
1486
+
1440
1487
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
1441
1488
pub enum PointerKind {
1442
1489
/// Shared reference. `frozen` indicates the absence of any `UnsafeCell`.
@@ -1464,7 +1511,7 @@ pub enum InitKind {
1464
1511
UninitMitigated0x01Fill ,
1465
1512
}
1466
1513
1467
- impl < V : Idx > LayoutS < V > {
1514
+ impl LayoutS {
1468
1515
/// Returns `true` if the layout corresponds to an unsized type.
1469
1516
pub fn is_unsized ( & self ) -> bool {
1470
1517
self . abi . is_unsized ( )
0 commit comments