@@ -9,6 +9,10 @@ use hir_def::{
99 LocalEnumVariantId , LocalFieldId , StructId ,
1010} ;
1111use la_arena:: { Idx , RawIdx } ;
12+ use rustc_dependencies:: {
13+ abi:: AddressSpace ,
14+ index:: { IndexSlice , IndexVec } ,
15+ } ;
1216use stdx:: never;
1317use triomphe:: Arc ;
1418
@@ -34,7 +38,7 @@ mod target;
3438#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
3539pub struct RustcEnumVariantIdx ( pub LocalEnumVariantId ) ;
3640
37- impl rustc_dependencies:: index:: vec :: Idx for RustcEnumVariantIdx {
41+ impl rustc_dependencies:: index:: Idx for RustcEnumVariantIdx {
3842 fn new ( idx : usize ) -> Self {
3943 RustcEnumVariantIdx ( Idx :: from_raw ( RawIdx :: from ( idx as u32 ) ) )
4044 }
@@ -44,9 +48,28 @@ impl rustc_dependencies::index::vec::Idx for RustcEnumVariantIdx {
4448 }
4549}
4650
47- pub type Layout = LayoutS < RustcEnumVariantIdx > ;
51+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
52+ pub struct RustcFieldIdx ( pub LocalFieldId ) ;
53+
54+ impl RustcFieldIdx {
55+ pub fn new ( idx : usize ) -> Self {
56+ RustcFieldIdx ( Idx :: from_raw ( RawIdx :: from ( idx as u32 ) ) )
57+ }
58+ }
59+
60+ impl rustc_dependencies:: index:: Idx for RustcFieldIdx {
61+ fn new ( idx : usize ) -> Self {
62+ RustcFieldIdx ( Idx :: from_raw ( RawIdx :: from ( idx as u32 ) ) )
63+ }
64+
65+ fn index ( self ) -> usize {
66+ u32:: from ( self . 0 . into_raw ( ) ) as usize
67+ }
68+ }
69+
70+ pub type Layout = LayoutS < RustcFieldIdx , RustcEnumVariantIdx > ;
4871pub type TagEncoding = hir_def:: layout:: TagEncoding < RustcEnumVariantIdx > ;
49- pub type Variants = hir_def:: layout:: Variants < RustcEnumVariantIdx > ;
72+ pub type Variants = hir_def:: layout:: Variants < RustcFieldIdx , RustcEnumVariantIdx > ;
5073
5174#[ derive( Debug , PartialEq , Eq , Clone ) ]
5275pub enum LayoutError {
@@ -66,7 +89,7 @@ struct LayoutCx<'a> {
6689impl < ' a > LayoutCalculator for LayoutCx < ' a > {
6790 type TargetDataLayoutRef = & ' a TargetDataLayout ;
6891
69- fn delay_bug ( & self , txt : & str ) {
92+ fn delay_bug ( & self , txt : String ) {
7093 never ! ( "{}" , txt) ;
7194 }
7295
@@ -145,6 +168,8 @@ fn layout_of_simd_ty(
145168 largest_niche : e_ly. largest_niche ,
146169 size,
147170 align,
171+ max_repr_align : None ,
172+ unadjusted_abi_align : align. abi ,
148173 } ) )
149174}
150175
@@ -230,7 +255,7 @@ pub fn layout_of_ty_query(
230255 . map ( |k| db. layout_of_ty ( k. assert_ty_ref ( Interner ) . clone ( ) , trait_env. clone ( ) ) )
231256 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
232257 let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
233- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
258+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
234259 cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , kind) . ok_or ( LayoutError :: Unknown ) ?
235260 }
236261 TyKind :: Array ( element, count) => {
@@ -255,6 +280,8 @@ pub fn layout_of_ty_query(
255280 largest_niche,
256281 align : element. align ,
257282 size,
283+ max_repr_align : None ,
284+ unadjusted_abi_align : element. align . abi ,
258285 }
259286 }
260287 TyKind :: Slice ( element) => {
@@ -266,11 +293,23 @@ pub fn layout_of_ty_query(
266293 largest_niche : None ,
267294 align : element. align ,
268295 size : Size :: ZERO ,
296+ max_repr_align : None ,
297+ unadjusted_abi_align : element. align . abi ,
269298 }
270299 }
300+ TyKind :: Str => Layout {
301+ variants : Variants :: Single { index : struct_variant_idx ( ) } ,
302+ fields : FieldsShape :: Array { stride : Size :: from_bytes ( 1 ) , count : 0 } ,
303+ abi : Abi :: Aggregate { sized : false } ,
304+ largest_niche : None ,
305+ align : dl. i8_align ,
306+ size : Size :: ZERO ,
307+ max_repr_align : None ,
308+ unadjusted_abi_align : dl. i8_align . abi ,
309+ } ,
271310 // Potentially-wide pointers.
272311 TyKind :: Ref ( _, _, pointee) | TyKind :: Raw ( _, pointee) => {
273- let mut data_ptr = scalar_unit ( dl, Primitive :: Pointer ) ;
312+ let mut data_ptr = scalar_unit ( dl, Primitive :: Pointer ( AddressSpace :: DATA ) ) ;
274313 if matches ! ( ty. kind( Interner ) , TyKind :: Ref ( ..) ) {
275314 data_ptr. valid_range_mut ( ) . start = 1 ;
276315 }
@@ -294,7 +333,7 @@ pub fn layout_of_ty_query(
294333 scalar_unit ( dl, Primitive :: Int ( dl. ptr_sized_integer ( ) , false ) )
295334 }
296335 TyKind :: Dyn ( ..) => {
297- let mut vtable = scalar_unit ( dl, Primitive :: Pointer ) ;
336+ let mut vtable = scalar_unit ( dl, Primitive :: Pointer ( AddressSpace :: DATA ) ) ;
298337 vtable. valid_range_mut ( ) . start = 1 ;
299338 vtable
300339 }
@@ -308,22 +347,7 @@ pub fn layout_of_ty_query(
308347 cx. scalar_pair ( data_ptr, metadata)
309348 }
310349 TyKind :: FnDef ( _, _) => layout_of_unit ( & cx, dl) ?,
311- TyKind :: Str => Layout {
312- variants : Variants :: Single { index : struct_variant_idx ( ) } ,
313- fields : FieldsShape :: Array { stride : Size :: from_bytes ( 1 ) , count : 0 } ,
314- abi : Abi :: Aggregate { sized : false } ,
315- largest_niche : None ,
316- align : dl. i8_align ,
317- size : Size :: ZERO ,
318- } ,
319- TyKind :: Never => Layout {
320- variants : Variants :: Single { index : struct_variant_idx ( ) } ,
321- fields : FieldsShape :: Primitive ,
322- abi : Abi :: Uninhabited ,
323- largest_niche : None ,
324- align : dl. i8_align ,
325- size : Size :: ZERO ,
326- } ,
350+ TyKind :: Never => cx. layout_of_never_type ( ) ,
327351 TyKind :: Dyn ( _) | TyKind :: Foreign ( _) => {
328352 let mut unit = layout_of_unit ( & cx, dl) ?;
329353 match unit. abi {
@@ -333,7 +357,7 @@ pub fn layout_of_ty_query(
333357 unit
334358 }
335359 TyKind :: Function ( _) => {
336- let mut ptr = scalar_unit ( dl, Primitive :: Pointer ) ;
360+ let mut ptr = scalar_unit ( dl, Primitive :: Pointer ( dl . instruction_address_space ) ) ;
337361 ptr. valid_range_mut ( ) . start = 1 ;
338362 Layout :: scalar ( dl, ptr)
339363 }
@@ -363,7 +387,7 @@ pub fn layout_of_ty_query(
363387 } )
364388 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
365389 let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
366- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
390+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
367391 cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , StructKind :: AlwaysSized )
368392 . ok_or ( LayoutError :: Unknown ) ?
369393 }
@@ -398,9 +422,9 @@ pub fn layout_of_ty_recover(
398422}
399423
400424fn layout_of_unit ( cx : & LayoutCx < ' _ > , dl : & TargetDataLayout ) -> Result < Layout , LayoutError > {
401- cx. univariant :: < RustcEnumVariantIdx , & & Layout > (
425+ cx. univariant :: < RustcFieldIdx , RustcEnumVariantIdx , & & Layout > (
402426 dl,
403- & [ ] ,
427+ IndexSlice :: empty ( ) ,
404428 & ReprOptions :: default ( ) ,
405429 StructKind :: AlwaysSized ,
406430 )
0 commit comments