@@ -133,40 +133,22 @@ fn layout_of_simd_ty(
133133 env : Arc < TraitEnvironment > ,
134134 dl : & TargetDataLayout ,
135135) -> Result < Arc < Layout > , LayoutError > {
136- let fields = db. field_types ( id. into ( ) ) ;
137-
138- // Supported SIMD vectors are homogeneous ADTs with at least one field:
136+ // Supported SIMD vectors are homogeneous ADTs with exactly one array field:
139137 //
140- // * #[repr(simd)] struct S(T, T, T, T);
141- // * #[repr(simd)] struct S { it: T, y: T, z: T, w: T }
142138 // * #[repr(simd)] struct S([T; 4])
143139 //
144140 // where T is a primitive scalar (integer/float/pointer).
145-
146- let f0_ty = match fields. iter ( ) . next ( ) {
147- Some ( it) => it. 1 . clone ( ) . substitute ( Interner , subst) ,
148- None => return Err ( LayoutError :: InvalidSimdType ) ,
141+ let fields = db. field_types ( id. into ( ) ) ;
142+ let mut fields = fields. iter ( ) ;
143+ let Some ( TyKind :: Array ( e_ty, e_len) ) = fields
144+ . next ( )
145+ . filter ( |_| fields. next ( ) . is_none ( ) )
146+ . map ( |f| f. 1 . clone ( ) . substitute ( Interner , subst) . kind ( Interner ) . clone ( ) )
147+ else {
148+ return Err ( LayoutError :: InvalidSimdType ) ;
149149 } ;
150150
151- // The element type and number of elements of the SIMD vector
152- // are obtained from:
153- //
154- // * the element type and length of the single array field, if
155- // the first field is of array type, or
156- //
157- // * the homogeneous field type and the number of fields.
158- let ( e_ty, e_len, is_array) = if let TyKind :: Array ( e_ty, _) = f0_ty. kind ( Interner ) {
159- // Extract the number of elements from the layout of the array field:
160- let FieldsShape :: Array { count, .. } = db. layout_of_ty ( f0_ty. clone ( ) , env. clone ( ) ) ?. fields
161- else {
162- return Err ( LayoutError :: Unknown ) ;
163- } ;
164-
165- ( e_ty. clone ( ) , count, true )
166- } else {
167- // First ADT field is not an array:
168- ( f0_ty, fields. iter ( ) . count ( ) as u64 , false )
169- } ;
151+ let e_len = try_const_usize ( db, & e_len) . ok_or ( LayoutError :: HasErrorConst ) ? as u64 ;
170152
171153 // Compute the ABI of the element type:
172154 let e_ly = db. layout_of_ty ( e_ty, env) ?;
@@ -182,16 +164,9 @@ fn layout_of_simd_ty(
182164 let align = dl. llvmlike_vector_align ( size) ;
183165 let size = size. align_to ( align. abi ) ;
184166
185- // Compute the placement of the vector fields:
186- let fields = if is_array {
187- FieldsShape :: Arbitrary { offsets : [ Size :: ZERO ] . into ( ) , memory_index : [ 0 ] . into ( ) }
188- } else {
189- FieldsShape :: Array { stride : e_ly. size , count : e_len }
190- } ;
191-
192167 Ok ( Arc :: new ( Layout {
193168 variants : Variants :: Single { index : struct_variant_idx ( ) } ,
194- fields,
169+ fields : FieldsShape :: Arbitrary { offsets : [ Size :: ZERO ] . into ( ) , memory_index : [ 0 ] . into ( ) } ,
195170 backend_repr : BackendRepr :: SimdVector { element : e_abi, count : e_len } ,
196171 largest_niche : e_ly. largest_niche ,
197172 uninhabited : false ,
0 commit comments