@@ -9,6 +9,10 @@ use hir_def::{
9
9
LocalEnumVariantId , LocalFieldId , StructId ,
10
10
} ;
11
11
use la_arena:: { Idx , RawIdx } ;
12
+ use rustc_dependencies:: {
13
+ abi:: AddressSpace ,
14
+ index:: { IndexSlice , IndexVec } ,
15
+ } ;
12
16
use stdx:: never;
13
17
use triomphe:: Arc ;
14
18
@@ -34,7 +38,7 @@ mod target;
34
38
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
35
39
pub struct RustcEnumVariantIdx ( pub LocalEnumVariantId ) ;
36
40
37
- impl rustc_dependencies:: index:: vec :: Idx for RustcEnumVariantIdx {
41
+ impl rustc_dependencies:: index:: Idx for RustcEnumVariantIdx {
38
42
fn new ( idx : usize ) -> Self {
39
43
RustcEnumVariantIdx ( Idx :: from_raw ( RawIdx :: from ( idx as u32 ) ) )
40
44
}
@@ -44,9 +48,28 @@ impl rustc_dependencies::index::vec::Idx for RustcEnumVariantIdx {
44
48
}
45
49
}
46
50
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 > ;
48
71
pub 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 > ;
50
73
51
74
#[ derive( Debug , PartialEq , Eq , Clone ) ]
52
75
pub enum LayoutError {
@@ -66,7 +89,7 @@ struct LayoutCx<'a> {
66
89
impl < ' a > LayoutCalculator for LayoutCx < ' a > {
67
90
type TargetDataLayoutRef = & ' a TargetDataLayout ;
68
91
69
- fn delay_bug ( & self , txt : & str ) {
92
+ fn delay_bug ( & self , txt : String ) {
70
93
never ! ( "{}" , txt) ;
71
94
}
72
95
@@ -145,6 +168,8 @@ fn layout_of_simd_ty(
145
168
largest_niche : e_ly. largest_niche ,
146
169
size,
147
170
align,
171
+ max_repr_align : None ,
172
+ unadjusted_abi_align : align. abi ,
148
173
} ) )
149
174
}
150
175
@@ -230,7 +255,7 @@ pub fn layout_of_ty_query(
230
255
. map ( |k| db. layout_of_ty ( k. assert_ty_ref ( Interner ) . clone ( ) , trait_env. clone ( ) ) )
231
256
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
232
257
let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
233
- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
258
+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
234
259
cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , kind) . ok_or ( LayoutError :: Unknown ) ?
235
260
}
236
261
TyKind :: Array ( element, count) => {
@@ -255,6 +280,8 @@ pub fn layout_of_ty_query(
255
280
largest_niche,
256
281
align : element. align ,
257
282
size,
283
+ max_repr_align : None ,
284
+ unadjusted_abi_align : element. align . abi ,
258
285
}
259
286
}
260
287
TyKind :: Slice ( element) => {
@@ -266,11 +293,23 @@ pub fn layout_of_ty_query(
266
293
largest_niche : None ,
267
294
align : element. align ,
268
295
size : Size :: ZERO ,
296
+ max_repr_align : None ,
297
+ unadjusted_abi_align : element. align . abi ,
269
298
}
270
299
}
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
+ } ,
271
310
// Potentially-wide pointers.
272
311
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 ) ) ;
274
313
if matches ! ( ty. kind( Interner ) , TyKind :: Ref ( ..) ) {
275
314
data_ptr. valid_range_mut ( ) . start = 1 ;
276
315
}
@@ -294,7 +333,7 @@ pub fn layout_of_ty_query(
294
333
scalar_unit ( dl, Primitive :: Int ( dl. ptr_sized_integer ( ) , false ) )
295
334
}
296
335
TyKind :: Dyn ( ..) => {
297
- let mut vtable = scalar_unit ( dl, Primitive :: Pointer ) ;
336
+ let mut vtable = scalar_unit ( dl, Primitive :: Pointer ( AddressSpace :: DATA ) ) ;
298
337
vtable. valid_range_mut ( ) . start = 1 ;
299
338
vtable
300
339
}
@@ -308,22 +347,7 @@ pub fn layout_of_ty_query(
308
347
cx. scalar_pair ( data_ptr, metadata)
309
348
}
310
349
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 ( ) ,
327
351
TyKind :: Dyn ( _) | TyKind :: Foreign ( _) => {
328
352
let mut unit = layout_of_unit ( & cx, dl) ?;
329
353
match unit. abi {
@@ -333,7 +357,7 @@ pub fn layout_of_ty_query(
333
357
unit
334
358
}
335
359
TyKind :: Function ( _) => {
336
- let mut ptr = scalar_unit ( dl, Primitive :: Pointer ) ;
360
+ let mut ptr = scalar_unit ( dl, Primitive :: Pointer ( dl . instruction_address_space ) ) ;
337
361
ptr. valid_range_mut ( ) . start = 1 ;
338
362
Layout :: scalar ( dl, ptr)
339
363
}
@@ -363,7 +387,7 @@ pub fn layout_of_ty_query(
363
387
} )
364
388
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
365
389
let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
366
- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
390
+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
367
391
cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , StructKind :: AlwaysSized )
368
392
. ok_or ( LayoutError :: Unknown ) ?
369
393
}
@@ -398,9 +422,9 @@ pub fn layout_of_ty_recover(
398
422
}
399
423
400
424
fn layout_of_unit ( cx : & LayoutCx < ' _ > , dl : & TargetDataLayout ) -> Result < Layout , LayoutError > {
401
- cx. univariant :: < RustcEnumVariantIdx , & & Layout > (
425
+ cx. univariant :: < RustcFieldIdx , RustcEnumVariantIdx , & & Layout > (
402
426
dl,
403
- & [ ] ,
427
+ IndexSlice :: empty ( ) ,
404
428
& ReprOptions :: default ( ) ,
405
429
StructKind :: AlwaysSized ,
406
430
)
0 commit comments