@@ -6,15 +6,14 @@ use base_db::ra_salsa::Cycle;
66use chalk_ir:: { AdtId , FloatTy , IntTy , TyKind , UintTy } ;
77use hir_def:: {
88 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 ,
1111 WrappingRange ,
1212 } ,
1313 LocalFieldId , StructId ,
1414} ;
1515use la_arena:: { Idx , RawIdx } ;
1616use rustc_abi:: AddressSpace ;
17- use rustc_hashes:: Hash64 ;
1817use rustc_index:: IndexVec ;
1918
2019use triomphe:: Arc ;
@@ -23,7 +22,6 @@ use crate::{
2322 consteval:: try_const_usize,
2423 db:: { HirDatabase , InternedClosure } ,
2524 infer:: normalize,
26- layout:: adt:: struct_variant_idx,
2725 utils:: ClosureSubst ,
2826 Interner , ProjectionTy , Substitution , TraitEnvironment , Ty ,
2927} ;
@@ -125,10 +123,10 @@ impl<'a> LayoutCx<'a> {
125123 }
126124}
127125
128- // FIXME: move this to the `rustc_abi`.
129126fn layout_of_simd_ty (
130127 db : & dyn HirDatabase ,
131128 id : StructId ,
129+ repr_packed : bool ,
132130 subst : & Substitution ,
133131 env : Arc < TraitEnvironment > ,
134132 dl : & TargetDataLayout ,
@@ -149,33 +147,10 @@ fn layout_of_simd_ty(
149147 } ;
150148
151149 let e_len = try_const_usize ( db, & e_len) . ok_or ( LayoutError :: HasErrorConst ) ? as u64 ;
152-
153- // Compute the ABI of the element type:
154150 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- } ;
158151
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) ?) )
179154}
180155
181156pub fn layout_of_ty_query (
@@ -197,7 +172,7 @@ pub fn layout_of_ty_query(
197172 let data = db. struct_data ( * s) ;
198173 let repr = data. repr . unwrap_or_default ( ) ;
199174 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) ;
201176 }
202177 } ;
203178 return db. layout_of_adt ( * def, subst. clone ( ) , trait_env) ;
0 commit comments