@@ -5,9 +5,9 @@ use hir::def_id::DefId;
55use rustc_abi:: Integer :: { I8 , I32 } ;
66use rustc_abi:: Primitive :: { self , Float , Int , Pointer } ;
77use rustc_abi:: {
8- AbiAndPrefAlign , AddressSpace , Align , BackendRepr , FIRST_VARIANT , FieldIdx , FieldsShape ,
9- HasDataLayout , Layout , LayoutCalculatorError , LayoutData , Niche , ReprOptions , Scalar , Size ,
10- StructKind , TagEncoding , VariantIdx , Variants , WrappingRange ,
8+ AddressSpace , BackendRepr , FIRST_VARIANT , FieldIdx , FieldsShape , HasDataLayout , Layout ,
9+ LayoutCalculatorError , LayoutData , Niche , ReprOptions , Scalar , Size , StructKind , TagEncoding ,
10+ VariantIdx , Variants , WrappingRange ,
1111} ;
1212use rustc_hashes:: Hash64 ;
1313use rustc_index:: bit_set:: DenseBitSet ;
@@ -16,7 +16,7 @@ use rustc_middle::bug;
1616use rustc_middle:: mir:: { CoroutineLayout , CoroutineSavedLocal } ;
1717use rustc_middle:: query:: Providers ;
1818use rustc_middle:: ty:: layout:: {
19- FloatExt , HasTyCtxt , IntegerExt , LayoutCx , LayoutError , LayoutOf , MAX_SIMD_LANES , TyAndLayout ,
19+ FloatExt , HasTyCtxt , IntegerExt , LayoutCx , LayoutError , LayoutOf , TyAndLayout ,
2020} ;
2121use rustc_middle:: ty:: print:: with_no_trimmed_paths;
2222use rustc_middle:: ty:: {
@@ -124,6 +124,19 @@ fn map_error<'tcx>(
124124 . delayed_bug ( format ! ( "computed impossible repr (packed enum?): {ty:?}" ) ) ;
125125 LayoutError :: ReferencesError ( guar)
126126 }
127+ LayoutCalculatorError :: ZeroLengthSimdType => {
128+ // Can't be caught in typeck if the array length is generic.
129+ cx. tcx ( ) . dcx ( ) . emit_fatal ( ZeroLengthSimdType { ty } )
130+ }
131+ LayoutCalculatorError :: OversizedSimdType { max_lanes } => {
132+ // Can't be caught in typeck if the array length is generic.
133+ cx. tcx ( ) . dcx ( ) . emit_fatal ( OversizedSimdType { ty, max_lanes } )
134+ }
135+ LayoutCalculatorError :: NonPrimitiveSimdType ( field) => {
136+ // This error isn't caught in typeck, e.g., if
137+ // the element type of the vector is generic.
138+ cx. tcx ( ) . dcx ( ) . emit_fatal ( NonPrimitiveSimdType { ty, e_ty : field. ty } )
139+ }
127140 } ;
128141 error ( cx, err)
129142}
@@ -423,65 +436,9 @@ fn layout_of_uncached<'tcx>(
423436 . try_to_target_usize ( tcx)
424437 . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
425438
426- // SIMD vectors of zero length are not supported.
427- // Additionally, lengths are capped at 2^16 as a fixed maximum backends must
428- // support.
429- //
430- // Can't be caught in typeck if the array length is generic.
431- if e_len == 0 {
432- tcx. dcx ( ) . emit_fatal ( ZeroLengthSimdType { ty } ) ;
433- } else if e_len > MAX_SIMD_LANES {
434- tcx. dcx ( ) . emit_fatal ( OversizedSimdType { ty, max_lanes : MAX_SIMD_LANES } ) ;
435- }
436-
437- // Compute the ABI of the element type:
438439 let e_ly = cx. layout_of ( e_ty) ?;
439- let BackendRepr :: Scalar ( e_abi) = e_ly. backend_repr else {
440- // This error isn't caught in typeck, e.g., if
441- // the element type of the vector is generic.
442- tcx. dcx ( ) . emit_fatal ( NonPrimitiveSimdType { ty, e_ty } ) ;
443- } ;
444-
445- // Compute the size and alignment of the vector:
446- let size = e_ly
447- . size
448- . checked_mul ( e_len, dl)
449- . ok_or_else ( || error ( cx, LayoutError :: SizeOverflow ( ty) ) ) ?;
450-
451- let ( abi, align) = if def. repr ( ) . packed ( ) && !e_len. is_power_of_two ( ) {
452- // Non-power-of-two vectors have padding up to the next power-of-two.
453- // If we're a packed repr, remove the padding while keeping the alignment as close
454- // to a vector as possible.
455- (
456- BackendRepr :: Memory { sized : true } ,
457- AbiAndPrefAlign {
458- abi : Align :: max_aligned_factor ( size) ,
459- pref : dl. llvmlike_vector_align ( size) . pref ,
460- } ,
461- )
462- } else {
463- (
464- BackendRepr :: SimdVector { element : e_abi, count : e_len } ,
465- dl. llvmlike_vector_align ( size) ,
466- )
467- } ;
468- let size = size. align_to ( align. abi ) ;
469440
470- tcx. mk_layout ( LayoutData {
471- variants : Variants :: Single { index : FIRST_VARIANT } ,
472- fields : FieldsShape :: Arbitrary {
473- offsets : [ Size :: ZERO ] . into ( ) ,
474- memory_index : [ 0 ] . into ( ) ,
475- } ,
476- backend_repr : abi,
477- largest_niche : e_ly. largest_niche ,
478- uninhabited : false ,
479- size,
480- align,
481- max_repr_align : None ,
482- unadjusted_abi_align : align. abi ,
483- randomization_seed : e_ly. randomization_seed . wrapping_add ( Hash64 :: new ( e_len) ) ,
484- } )
441+ map_layout ( cx. calc . simd_type ( e_ly, e_len, def. repr ( ) . packed ( ) ) ) ?
485442 }
486443
487444 // ADTs.
0 commit comments