@@ -6,15 +6,14 @@ use base_db::ra_salsa::Cycle;
6
6
use chalk_ir:: { AdtId , FloatTy , IntTy , TyKind , UintTy } ;
7
7
use hir_def:: {
8
8
layout:: {
9
- BackendRepr , FieldsShape , Float , Integer , LayoutCalculator , LayoutCalculatorError ,
10
- LayoutData , Primitive , ReprOptions , Scalar , Size , StructKind , TargetDataLayout ,
9
+ Float , Integer , LayoutCalculator , LayoutCalculatorError ,
10
+ LayoutData , Primitive , ReprOptions , Scalar , StructKind , TargetDataLayout ,
11
11
WrappingRange ,
12
12
} ,
13
13
LocalFieldId , StructId ,
14
14
} ;
15
15
use la_arena:: { Idx , RawIdx } ;
16
16
use rustc_abi:: AddressSpace ;
17
- use rustc_hashes:: Hash64 ;
18
17
use rustc_index:: IndexVec ;
19
18
20
19
use triomphe:: Arc ;
@@ -23,7 +22,6 @@ use crate::{
23
22
consteval:: try_const_usize,
24
23
db:: { HirDatabase , InternedClosure } ,
25
24
infer:: normalize,
26
- layout:: adt:: struct_variant_idx,
27
25
utils:: ClosureSubst ,
28
26
Interner , ProjectionTy , Substitution , TraitEnvironment , Ty ,
29
27
} ;
@@ -125,10 +123,10 @@ impl<'a> LayoutCx<'a> {
125
123
}
126
124
}
127
125
128
- // FIXME: move this to the `rustc_abi`.
129
126
fn layout_of_simd_ty (
130
127
db : & dyn HirDatabase ,
131
128
id : StructId ,
129
+ repr_packed : bool ,
132
130
subst : & Substitution ,
133
131
env : Arc < TraitEnvironment > ,
134
132
dl : & TargetDataLayout ,
@@ -149,33 +147,10 @@ fn layout_of_simd_ty(
149
147
} ;
150
148
151
149
let e_len = try_const_usize ( db, & e_len) . ok_or ( LayoutError :: HasErrorConst ) ? as u64 ;
152
-
153
- // Compute the ABI of the element type:
154
150
let e_ly = db. layout_of_ty ( e_ty, env) ?;
155
- let BackendRepr :: Scalar ( e_abi) = e_ly. backend_repr else {
156
- return Err ( LayoutError :: Unknown ) ;
157
- } ;
158
151
159
- // Compute the size and alignment of the vector:
160
- let size = e_ly
161
- . size
162
- . checked_mul ( e_len, dl)
163
- . ok_or ( LayoutError :: BadCalc ( LayoutCalculatorError :: SizeOverflow ) ) ?;
164
- let align = dl. llvmlike_vector_align ( size) ;
165
- let size = size. align_to ( align. abi ) ;
166
-
167
- Ok ( Arc :: new ( Layout {
168
- variants : Variants :: Single { index : struct_variant_idx ( ) } ,
169
- fields : FieldsShape :: Arbitrary { offsets : [ Size :: ZERO ] . into ( ) , memory_index : [ 0 ] . into ( ) } ,
170
- backend_repr : BackendRepr :: SimdVector { element : e_abi, count : e_len } ,
171
- largest_niche : e_ly. largest_niche ,
172
- uninhabited : false ,
173
- size,
174
- align,
175
- max_repr_align : None ,
176
- unadjusted_abi_align : align. abi ,
177
- randomization_seed : Hash64 :: ZERO ,
178
- } ) )
152
+ let cx = LayoutCx :: new ( dl) ;
153
+ Ok ( Arc :: new ( cx. calc . simd_type ( e_ly, e_len, repr_packed) ?) )
179
154
}
180
155
181
156
pub fn layout_of_ty_query (
@@ -197,7 +172,7 @@ pub fn layout_of_ty_query(
197
172
let data = db. struct_data ( * s) ;
198
173
let repr = data. repr . unwrap_or_default ( ) ;
199
174
if repr. simd ( ) {
200
- return layout_of_simd_ty ( db, * s, subst, trait_env, & target) ;
175
+ return layout_of_simd_ty ( db, * s, repr . packed ( ) , subst, trait_env, & target) ;
201
176
}
202
177
} ;
203
178
return db. layout_of_adt ( * def, subst. clone ( ) , trait_env) ;
0 commit comments