@@ -9,12 +9,11 @@ use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
9
9
use rustc_data_structures:: fx:: FxHashMap ;
10
10
use rustc_errors:: ErrorGuaranteed ;
11
11
use rustc_index:: Idx ;
12
- use rustc_middle:: mir:: interpret:: ErrorHandled ;
13
12
use rustc_middle:: query:: Providers ;
14
13
use rustc_middle:: ty:: layout:: { FnAbiOf , LayoutOf , TyAndLayout } ;
15
14
use rustc_middle:: ty:: {
16
- self , Const , CoroutineArgs , CoroutineArgsExt as _, FloatTy , IntTy , ParamEnv , PolyFnSig , Ty ,
17
- TyCtxt , TyKind , UintTy ,
15
+ self , Const , CoroutineArgs , CoroutineArgsExt as _, FloatTy , IntTy , PolyFnSig , Ty , TyCtxt ,
16
+ TyKind , UintTy ,
18
17
} ;
19
18
use rustc_middle:: ty:: { GenericArgsRef , ScalarInt } ;
20
19
use rustc_middle:: { bug, span_bug} ;
@@ -23,10 +22,10 @@ use rustc_span::def_id::DefId;
23
22
use rustc_span:: { Span , Symbol } ;
24
23
use rustc_target:: abi:: call:: { ArgAbi , ArgAttributes , FnAbi , PassMode } ;
25
24
use rustc_target:: abi:: {
26
- Abi , Align , FieldsShape , LayoutS , Primitive , ReprFlags , ReprOptions , Scalar , Size , TagEncoding ,
27
- VariantIdx , Variants ,
25
+ Align , BackendRepr , FieldsShape , LayoutData , Primitive , ReprFlags , ReprOptions , Scalar , Size ,
26
+ TagEncoding , VariantIdx , Variants ,
28
27
} ;
29
- use rustc_target:: spec:: abi:: Abi as SpecAbi ;
28
+ use rustc_target:: spec:: abi:: Abi ;
30
29
use std:: cell:: RefCell ;
31
30
use std:: collections:: hash_map:: Entry ;
32
31
use std:: fmt;
@@ -47,8 +46,8 @@ pub(crate) fn provide(providers: &mut Providers) {
47
46
let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS . fn_sig ) ( tcx, def_id) ;
48
47
result. map_bound ( |outer| {
49
48
outer. map_bound ( |mut inner| {
50
- if let SpecAbi :: C { .. } = inner. abi {
51
- inner. abi = SpecAbi :: Unadjusted ;
49
+ if let Abi :: C { .. } = inner. abi {
50
+ inner. abi = Abi :: Unadjusted ;
52
51
}
53
52
inner
54
53
} )
@@ -98,22 +97,21 @@ pub(crate) fn provide(providers: &mut Providers) {
98
97
Ok ( readjust_fn_abi ( tcx, result?) )
99
98
} ;
100
99
101
- // FIXME(eddyb) remove this by deriving `Clone` for `LayoutS` upstream.
102
- // FIXME(eddyb) the `S` suffix is a naming antipattern, rename upstream.
100
+ // FIXME(eddyb) remove this by deriving `Clone` for `LayoutData` upstream.
103
101
fn clone_layout < FieldIdx : Idx , VariantIdx : Idx > (
104
- layout : & LayoutS < FieldIdx , VariantIdx > ,
105
- ) -> LayoutS < FieldIdx , VariantIdx > {
106
- let LayoutS {
102
+ layout : & LayoutData < FieldIdx , VariantIdx > ,
103
+ ) -> LayoutData < FieldIdx , VariantIdx > {
104
+ let LayoutData {
107
105
ref fields,
108
106
ref variants,
109
- abi ,
107
+ backend_repr ,
110
108
largest_niche,
111
109
align,
112
110
size,
113
111
max_repr_align,
114
112
unadjusted_abi_align,
115
113
} = * layout;
116
- LayoutS {
114
+ LayoutData {
117
115
fields : match * fields {
118
116
FieldsShape :: Primitive => FieldsShape :: Primitive ,
119
117
FieldsShape :: Union ( count) => FieldsShape :: Union ( count) ,
@@ -151,7 +149,7 @@ pub(crate) fn provide(providers: &mut Providers) {
151
149
variants : variants. clone ( ) ,
152
150
} ,
153
151
} ,
154
- abi ,
152
+ backend_repr ,
155
153
largest_niche,
156
154
align,
157
155
size,
@@ -171,7 +169,7 @@ pub(crate) fn provide(providers: &mut Providers) {
171
169
} ;
172
170
173
171
if hide_niche {
174
- layout = tcx. mk_layout ( LayoutS {
172
+ layout = tcx. mk_layout ( LayoutData {
175
173
largest_niche : None ,
176
174
..clone_layout ( layout. 0 . 0 )
177
175
} ) ;
@@ -192,6 +190,10 @@ pub(crate) fn provide(providers: &mut Providers) {
192
190
// an option (may require Rust-GPU distinguishing between "SPIR-V interface"
193
191
// and "Rust-facing" types, which is even worse when the `OpTypeVector`s
194
192
// may be e.g. nested in `struct`s/arrays/etc. - at least buffers are easy).
193
+ //
194
+ // FIXME(eddyb) maybe using `#[spirv(vector)]` and `BackendRepr::Memory`,
195
+ // no claims at `rustc`-understood SIMD whatsoever, would be enough?
196
+ // (i.e. only SPIR-V caring about such a type vs a struct/array)
195
197
providers. check_well_formed = |tcx, def_id| {
196
198
let trivial_struct = match tcx. hir_node_by_def_id ( def_id) {
197
199
rustc_hir:: Node :: Item ( item) => match item. kind {
@@ -263,6 +265,14 @@ pub(crate) fn provide(providers: &mut Providers) {
263
265
264
266
( rustc_interface:: DEFAULT_QUERY_PROVIDERS . check_well_formed ) ( tcx, def_id)
265
267
} ;
268
+
269
+ // HACK(eddyb) work around https://github.com/rust-lang/rust/pull/132173
270
+ // (and further changes from https://github.com/rust-lang/rust/pull/132843)
271
+ // starting to ban SIMD ABI misuse (or at least starting to warn about it).
272
+ //
273
+ // FIXME(eddyb) same as the FIXME comment on `check_well_formed`:
274
+ // need to migrate away from `#[repr(simd)]` ASAP.
275
+ providers. check_mono_item = |_, _| { } ;
266
276
}
267
277
268
278
/// If a struct contains a pointer to itself, even indirectly, then doing a naiive recursive walk
@@ -450,9 +460,9 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
450
460
451
461
// Note: ty.layout is orthogonal to ty.ty, e.g. `ManuallyDrop<Result<isize, isize>>` has abi
452
462
// `ScalarPair`.
453
- // There's a few layers that we go through here. First we inspect layout.abi , then if relevant, layout.fields, etc.
454
- match self . abi {
455
- Abi :: Uninhabited => SpirvType :: Adt {
463
+ // There's a few layers that we go through here. First we inspect layout.backend_repr , then if relevant, layout.fields, etc.
464
+ match self . backend_repr {
465
+ BackendRepr :: Uninhabited => SpirvType :: Adt {
456
466
def_id : def_id_for_spirv_type_adt ( * self ) ,
457
467
size : Some ( Size :: ZERO ) ,
458
468
align : Align :: from_bytes ( 0 ) . unwrap ( ) ,
@@ -461,13 +471,13 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
461
471
field_names : None ,
462
472
}
463
473
. def_with_name ( cx, span, TyLayoutNameKey :: from ( * self ) ) ,
464
- Abi :: Scalar ( scalar) => trans_scalar ( cx, span, * self , scalar, Size :: ZERO ) ,
465
- Abi :: ScalarPair ( a, b) => {
466
- // NOTE(eddyb) unlike `Abi ::Scalar`'s simpler newtype-unpacking
467
- // behavior, `Abi ::ScalarPair` can be composed in two ways:
468
- // * two `Abi ::Scalar` fields (and any number of ZST fields),
474
+ BackendRepr :: Scalar ( scalar) => trans_scalar ( cx, span, * self , scalar, Size :: ZERO ) ,
475
+ BackendRepr :: ScalarPair ( a, b) => {
476
+ // NOTE(eddyb) unlike `BackendRepr ::Scalar`'s simpler newtype-unpacking
477
+ // behavior, `BackendRepr ::ScalarPair` can be composed in two ways:
478
+ // * two `BackendRepr ::Scalar` fields (and any number of ZST fields),
469
479
// gets handled the same as a `struct { a, b }`, further below
470
- // * an `Abi ::ScalarPair` field (and any number of ZST fields),
480
+ // * an `BackendRepr ::ScalarPair` field (and any number of ZST fields),
471
481
// which requires more work to allow taking a reference to
472
482
// that field, and there are two potential approaches:
473
483
// 1. wrapping that field's SPIR-V type in a single-field
@@ -477,7 +487,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
477
487
// 2. reusing that field's SPIR-V type, instead of defining
478
488
// a new one, offering the `(a, b)` shape `rustc_codegen_ssa`
479
489
// expects, while letting noop pointercasts access the sole
480
- // `Abi ::ScalarPair` field - this is the approach taken here
490
+ // `BackendRepr ::ScalarPair` field - this is the approach taken here
481
491
let mut non_zst_fields = ( 0 ..self . fields . count ( ) )
482
492
. map ( |i| ( i, self . field ( cx, i) ) )
483
493
. filter ( |( _, field) | !field. is_zst ( ) ) ;
@@ -491,7 +501,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
491
501
if self . fields . offset ( i) == Size :: ZERO
492
502
&& field. size == self . size
493
503
&& field. align == self . align
494
- && field. abi == self . abi
504
+ && field. backend_repr == self . backend_repr
495
505
{
496
506
return field. spirv_type ( span, cx) ;
497
507
}
@@ -532,15 +542,15 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
532
542
}
533
543
. def_with_name ( cx, span, TyLayoutNameKey :: from ( * self ) )
534
544
}
535
- Abi :: Vector { element, count } => {
545
+ BackendRepr :: Vector { element, count } => {
536
546
let elem_spirv = trans_scalar ( cx, span, * self , element, Size :: ZERO ) ;
537
547
SpirvType :: Vector {
538
548
element : elem_spirv,
539
549
count : count as u32 ,
540
550
}
541
551
. def ( span, cx)
542
552
}
543
- Abi :: Aggregate { sized : _ } => trans_aggregate ( cx, span, * self ) ,
553
+ BackendRepr :: Memory { sized : _ } => trans_aggregate ( cx, span, * self ) ,
544
554
}
545
555
}
546
556
}
@@ -553,8 +563,8 @@ pub fn scalar_pair_element_backend_type<'tcx>(
553
563
ty : TyAndLayout < ' tcx > ,
554
564
index : usize ,
555
565
) -> Word {
556
- let [ a, b] = match ty. layout . abi ( ) {
557
- Abi :: ScalarPair ( a, b) => [ a, b] ,
566
+ let [ a, b] = match ty. layout . backend_repr ( ) {
567
+ BackendRepr :: ScalarPair ( a, b) => [ a, b] ,
558
568
other => span_bug ! (
559
569
span,
560
570
"scalar_pair_element_backend_type invalid abi: {:?}" ,
@@ -901,7 +911,7 @@ fn trans_intrinsic_type<'tcx>(
901
911
// ) -> P {
902
912
// let adt_def = const_.ty.ty_adt_def().unwrap();
903
913
// assert!(adt_def.is_enum());
904
- // let destructured = cx.tcx.destructure_const(ParamEnv::reveal_all ().and(const_));
914
+ // let destructured = cx.tcx.destructure_const(TypingEnv::fully_monomorphized ().and(const_));
905
915
// let idx = destructured.variant.unwrap();
906
916
// let value = const_.ty.discriminant_for_variant(cx.tcx, idx).unwrap().val as u64;
907
917
// <_>::from_u64(value).unwrap()
@@ -974,24 +984,17 @@ fn trans_intrinsic_type<'tcx>(
974
984
cx : & CodegenCx < ' tcx > ,
975
985
const_ : Const < ' tcx > ,
976
986
) -> Result < P , ErrorGuaranteed > {
977
- const_
978
- . eval ( cx. tcx , ParamEnv :: reveal_all ( ) , DUMMY_SP )
979
- . map_err ( |e| match e {
980
- ErrorHandled :: Reported ( reported_error_info, _) => {
981
- Some ( reported_error_info. into ( ) )
982
- }
983
- ErrorHandled :: TooGeneric ( _) => None ,
984
- } )
985
- . and_then ( |( const_ty, const_val) | {
986
- assert ! ( const_ty. is_integral( ) ) ;
987
- P :: from_scalar_int ( const_val. try_to_scalar_int ( ) . ok_or ( None ) ?) . ok_or ( None )
988
- } )
989
- . map_err ( |already_reported| {
990
- already_reported. unwrap_or_else ( || {
991
- cx. tcx
992
- . dcx ( )
993
- . err ( format ! ( "invalid value for Image const generic: {const_}" ) )
994
- } )
987
+ let ( const_val, const_ty) = const_
988
+ . try_to_valtree ( )
989
+ . expect ( "expected monomorphic const in codegen" ) ;
990
+ assert ! ( const_ty. is_integral( ) ) ;
991
+ const_val
992
+ . try_to_scalar_int ( )
993
+ . and_then ( P :: from_scalar_int)
994
+ . ok_or_else ( || {
995
+ cx. tcx
996
+ . dcx ( )
997
+ . err ( format ! ( "invalid value for Image const generic: {const_}" ) )
995
998
} )
996
999
}
997
1000
0 commit comments