@@ -17,6 +17,9 @@ use rustc_target::abi::*;
17
17
use std:: fmt:: Debug ;
18
18
use std:: iter;
19
19
20
+ use crate :: errors:: {
21
+ MultipleArrayFieldsSimdType , NonPrimitiveSimdType , OversizedSimdType , ZeroLengthSimdType ,
22
+ } ;
20
23
use crate :: layout_sanity_check:: sanity_check_layout;
21
24
22
25
pub fn provide ( providers : & mut ty:: query:: Providers ) {
@@ -294,6 +297,8 @@ fn layout_of_uncached<'tcx>(
294
297
return Err ( LayoutError :: Unknown ( ty) ) ;
295
298
}
296
299
300
+ let fields = & def. non_enum_variant ( ) . fields ;
301
+
297
302
// Supported SIMD vectors are homogeneous ADTs with at least one field:
298
303
//
299
304
// * #[repr(simd)] struct S(T, T, T, T);
@@ -304,18 +309,22 @@ fn layout_of_uncached<'tcx>(
304
309
305
310
// SIMD vectors with zero fields are not supported.
306
311
// (should be caught by typeck)
307
- if def . non_enum_variant ( ) . fields . is_empty ( ) {
308
- tcx. sess . fatal ( & format ! ( "monomorphising SIMD type `{}` of zero length" , ty ) ) ;
312
+ if fields. is_empty ( ) {
313
+ tcx. sess . emit_fatal ( ZeroLengthSimdType { ty } )
309
314
}
310
315
311
316
// Type of the first ADT field:
312
- let f0_ty = def . non_enum_variant ( ) . fields [ FieldIdx :: from_u32 ( 0 ) ] . ty ( tcx, substs) ;
317
+ let f0_ty = fields[ FieldIdx :: from_u32 ( 0 ) ] . ty ( tcx, substs) ;
313
318
314
319
// Heterogeneous SIMD vectors are not supported:
315
320
// (should be caught by typeck)
316
- for fi in & def . non_enum_variant ( ) . fields {
321
+ for fi in fields {
317
322
if fi. ty ( tcx, substs) != f0_ty {
318
- tcx. sess . fatal ( & format ! ( "monomorphising heterogeneous SIMD type `{}`" , ty) ) ;
323
+ tcx. sess . delay_span_bug (
324
+ DUMMY_SP ,
325
+ "#[repr(simd)] was applied to an ADT with hetrogeneous field type" ,
326
+ ) ;
327
+ return Err ( LayoutError :: Unknown ( ty) ) ;
319
328
}
320
329
}
321
330
@@ -330,12 +339,9 @@ fn layout_of_uncached<'tcx>(
330
339
// First ADT field is an array:
331
340
332
341
// SIMD vectors with multiple array fields are not supported:
333
- // (should be caught by typeck)
342
+ // Can't be caught by typeck with a generic simd type.
334
343
if def. non_enum_variant ( ) . fields . len ( ) != 1 {
335
- tcx. sess . fatal ( & format ! (
336
- "monomorphising SIMD type `{}` with more than one array field" ,
337
- ty
338
- ) ) ;
344
+ tcx. sess . emit_fatal ( MultipleArrayFieldsSimdType { ty } ) ;
339
345
}
340
346
341
347
// Extract the number of elements from the layout of the array field:
@@ -355,24 +361,17 @@ fn layout_of_uncached<'tcx>(
355
361
//
356
362
// Can't be caught in typeck if the array length is generic.
357
363
if e_len == 0 {
358
- tcx. sess . fatal ( & format ! ( "monomorphising SIMD type `{}` of zero length" , ty ) ) ;
364
+ tcx. sess . emit_fatal ( ZeroLengthSimdType { ty } ) ;
359
365
} else if e_len > MAX_SIMD_LANES {
360
- tcx. sess . fatal ( & format ! (
361
- "monomorphising SIMD type `{}` of length greater than {}" ,
362
- ty, MAX_SIMD_LANES ,
363
- ) ) ;
366
+ tcx. sess . emit_fatal ( OversizedSimdType { ty, max_lanes : MAX_SIMD_LANES } ) ;
364
367
}
365
368
366
369
// Compute the ABI of the element type:
367
370
let e_ly = cx. layout_of ( e_ty) ?;
368
371
let Abi :: Scalar ( e_abi) = e_ly. abi else {
369
372
// This error isn't caught in typeck, e.g., if
370
373
// the element type of the vector is generic.
371
- tcx. sess . fatal ( & format ! (
372
- "monomorphising SIMD type `{}` with a non-primitive-scalar \
373
- (integer/float/pointer) element type `{}`",
374
- ty, e_ty
375
- ) )
374
+ tcx. sess . emit_fatal ( NonPrimitiveSimdType { ty, e_ty } ) ;
376
375
} ;
377
376
378
377
// Compute the size and alignment of the vector:
0 commit comments