@@ -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,10 @@ fn layout_of_simd_ty(
145168 largest_niche : e_ly. largest_niche ,
146169 size,
147170 align,
171+ // FIXME might be wrong
172+ max_repr_align : e_ly. max_repr_align ,
173+ // FIXME might be wrong
174+ unadjusted_abi_align : e_ly. unadjusted_abi_align ,
148175 } ) )
149176}
150177
@@ -230,7 +257,7 @@ pub fn layout_of_ty_query(
230257 . map ( |k| db. layout_of_ty ( k. assert_ty_ref ( Interner ) . clone ( ) , trait_env. clone ( ) ) )
231258 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
232259 let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
233- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
260+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
234261 cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , kind) . ok_or ( LayoutError :: Unknown ) ?
235262 }
236263 TyKind :: Array ( element, count) => {
@@ -255,6 +282,8 @@ pub fn layout_of_ty_query(
255282 largest_niche,
256283 align : element. align ,
257284 size,
285+ max_repr_align : element. max_repr_align ,
286+ unadjusted_abi_align : element. unadjusted_abi_align ,
258287 }
259288 }
260289 TyKind :: Slice ( element) => {
@@ -266,11 +295,14 @@ pub fn layout_of_ty_query(
266295 largest_niche : None ,
267296 align : element. align ,
268297 size : Size :: ZERO ,
298+ max_repr_align : element. max_repr_align ,
299+ unadjusted_abi_align : element. unadjusted_abi_align ,
269300 }
270301 }
271302 // Potentially-wide pointers.
272303 TyKind :: Ref ( _, _, pointee) | TyKind :: Raw ( _, pointee) => {
273- let mut data_ptr = scalar_unit ( dl, Primitive :: Pointer ) ;
304+ // FIXME: fill out AddressSpace
305+ let mut data_ptr = scalar_unit ( dl, Primitive :: Pointer ( AddressSpace ( 0 ) ) ) ;
274306 if matches ! ( ty. kind( Interner ) , TyKind :: Ref ( ..) ) {
275307 data_ptr. valid_range_mut ( ) . start = 1 ;
276308 }
@@ -294,7 +326,8 @@ pub fn layout_of_ty_query(
294326 scalar_unit ( dl, Primitive :: Int ( dl. ptr_sized_integer ( ) , false ) )
295327 }
296328 TyKind :: Dyn ( ..) => {
297- let mut vtable = scalar_unit ( dl, Primitive :: Pointer ) ;
329+ // FIXME: fill out AddressSpace
330+ let mut vtable = scalar_unit ( dl, Primitive :: Pointer ( AddressSpace ( 0 ) ) ) ;
298331 vtable. valid_range_mut ( ) . start = 1 ;
299332 vtable
300333 }
@@ -315,6 +348,10 @@ pub fn layout_of_ty_query(
315348 largest_niche : None ,
316349 align : dl. i8_align ,
317350 size : Size :: ZERO ,
351+ // FIXME
352+ max_repr_align : None ,
353+ // FIXME
354+ unadjusted_abi_align : dl. i8_align . abi ,
318355 } ,
319356 TyKind :: Never => Layout {
320357 variants : Variants :: Single { index : struct_variant_idx ( ) } ,
@@ -323,6 +360,11 @@ pub fn layout_of_ty_query(
323360 largest_niche : None ,
324361 align : dl. i8_align ,
325362 size : Size :: ZERO ,
363+
364+ // FIXME
365+ max_repr_align : None ,
366+ // FIXME
367+ unadjusted_abi_align : dl. i8_align . abi ,
326368 } ,
327369 TyKind :: Dyn ( _) | TyKind :: Foreign ( _) => {
328370 let mut unit = layout_of_unit ( & cx, dl) ?;
@@ -333,7 +375,8 @@ pub fn layout_of_ty_query(
333375 unit
334376 }
335377 TyKind :: Function ( _) => {
336- let mut ptr = scalar_unit ( dl, Primitive :: Pointer ) ;
378+ // FOXME: fill out AddressSpace
379+ let mut ptr = scalar_unit ( dl, Primitive :: Pointer ( AddressSpace ( 0 ) ) ) ;
337380 ptr. valid_range_mut ( ) . start = 1 ;
338381 Layout :: scalar ( dl, ptr)
339382 }
@@ -363,7 +406,7 @@ pub fn layout_of_ty_query(
363406 } )
364407 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
365408 let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
366- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
409+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
367410 cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , StructKind :: AlwaysSized )
368411 . ok_or ( LayoutError :: Unknown ) ?
369412 }
@@ -398,9 +441,9 @@ pub fn layout_of_ty_recover(
398441}
399442
400443fn layout_of_unit ( cx : & LayoutCx < ' _ > , dl : & TargetDataLayout ) -> Result < Layout , LayoutError > {
401- cx. univariant :: < RustcEnumVariantIdx , & & Layout > (
444+ cx. univariant :: < RustcFieldIdx , RustcEnumVariantIdx , & & Layout > (
402445 dl,
403- & [ ] ,
446+ IndexSlice :: empty ( ) ,
404447 & ReprOptions :: default ( ) ,
405448 StructKind :: AlwaysSized ,
406449 )
0 commit comments