@@ -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,10 @@ fn layout_of_simd_ty(
145
168
largest_niche : e_ly. largest_niche ,
146
169
size,
147
170
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 ,
148
175
} ) )
149
176
}
150
177
@@ -230,7 +257,7 @@ pub fn layout_of_ty_query(
230
257
. map ( |k| db. layout_of_ty ( k. assert_ty_ref ( Interner ) . clone ( ) , trait_env. clone ( ) ) )
231
258
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
232
259
let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
233
- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
260
+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
234
261
cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , kind) . ok_or ( LayoutError :: Unknown ) ?
235
262
}
236
263
TyKind :: Array ( element, count) => {
@@ -255,6 +282,8 @@ pub fn layout_of_ty_query(
255
282
largest_niche,
256
283
align : element. align ,
257
284
size,
285
+ max_repr_align : element. max_repr_align ,
286
+ unadjusted_abi_align : element. unadjusted_abi_align ,
258
287
}
259
288
}
260
289
TyKind :: Slice ( element) => {
@@ -266,11 +295,14 @@ pub fn layout_of_ty_query(
266
295
largest_niche : None ,
267
296
align : element. align ,
268
297
size : Size :: ZERO ,
298
+ max_repr_align : element. max_repr_align ,
299
+ unadjusted_abi_align : element. unadjusted_abi_align ,
269
300
}
270
301
}
271
302
// Potentially-wide pointers.
272
303
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 ) ) ) ;
274
306
if matches ! ( ty. kind( Interner ) , TyKind :: Ref ( ..) ) {
275
307
data_ptr. valid_range_mut ( ) . start = 1 ;
276
308
}
@@ -294,7 +326,8 @@ pub fn layout_of_ty_query(
294
326
scalar_unit ( dl, Primitive :: Int ( dl. ptr_sized_integer ( ) , false ) )
295
327
}
296
328
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 ) ) ) ;
298
331
vtable. valid_range_mut ( ) . start = 1 ;
299
332
vtable
300
333
}
@@ -315,6 +348,10 @@ pub fn layout_of_ty_query(
315
348
largest_niche : None ,
316
349
align : dl. i8_align ,
317
350
size : Size :: ZERO ,
351
+ // FIXME
352
+ max_repr_align : None ,
353
+ // FIXME
354
+ unadjusted_abi_align : dl. i8_align . abi ,
318
355
} ,
319
356
TyKind :: Never => Layout {
320
357
variants : Variants :: Single { index : struct_variant_idx ( ) } ,
@@ -323,6 +360,11 @@ pub fn layout_of_ty_query(
323
360
largest_niche : None ,
324
361
align : dl. i8_align ,
325
362
size : Size :: ZERO ,
363
+
364
+ // FIXME
365
+ max_repr_align : None ,
366
+ // FIXME
367
+ unadjusted_abi_align : dl. i8_align . abi ,
326
368
} ,
327
369
TyKind :: Dyn ( _) | TyKind :: Foreign ( _) => {
328
370
let mut unit = layout_of_unit ( & cx, dl) ?;
@@ -333,7 +375,8 @@ pub fn layout_of_ty_query(
333
375
unit
334
376
}
335
377
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 ) ) ) ;
337
380
ptr. valid_range_mut ( ) . start = 1 ;
338
381
Layout :: scalar ( dl, ptr)
339
382
}
@@ -363,7 +406,7 @@ pub fn layout_of_ty_query(
363
406
} )
364
407
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
365
408
let fields = fields. iter ( ) . map ( |it| & * * it) . collect :: < Vec < _ > > ( ) ;
366
- let fields = fields. iter ( ) . collect :: < Vec < _ > > ( ) ;
409
+ let fields = fields. iter ( ) . collect :: < IndexVec < _ , _ > > ( ) ;
367
410
cx. univariant ( dl, & fields, & ReprOptions :: default ( ) , StructKind :: AlwaysSized )
368
411
. ok_or ( LayoutError :: Unknown ) ?
369
412
}
@@ -398,9 +441,9 @@ pub fn layout_of_ty_recover(
398
441
}
399
442
400
443
fn layout_of_unit ( cx : & LayoutCx < ' _ > , dl : & TargetDataLayout ) -> Result < Layout , LayoutError > {
401
- cx. univariant :: < RustcEnumVariantIdx , & & Layout > (
444
+ cx. univariant :: < RustcFieldIdx , RustcEnumVariantIdx , & & Layout > (
402
445
dl,
403
- & [ ] ,
446
+ IndexSlice :: empty ( ) ,
404
447
& ReprOptions :: default ( ) ,
405
448
StructKind :: AlwaysSized ,
406
449
)
0 commit comments