@@ -9,12 +9,11 @@ use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
99use rustc_data_structures:: fx:: FxHashMap ;
1010use rustc_errors:: ErrorGuaranteed ;
1111use rustc_index:: Idx ;
12- use rustc_middle:: mir:: interpret:: ErrorHandled ;
1312use rustc_middle:: query:: Providers ;
1413use rustc_middle:: ty:: layout:: { FnAbiOf , LayoutOf , TyAndLayout } ;
1514use 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 ,
1817} ;
1918use rustc_middle:: ty:: { GenericArgsRef , ScalarInt } ;
2019use rustc_middle:: { bug, span_bug} ;
@@ -23,10 +22,10 @@ use rustc_span::def_id::DefId;
2322use rustc_span:: { Span , Symbol } ;
2423use rustc_target:: abi:: call:: { ArgAbi , ArgAttributes , FnAbi , PassMode } ;
2524use 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 ,
2827} ;
29- use rustc_target:: spec:: abi:: Abi as SpecAbi ;
28+ use rustc_target:: spec:: abi:: Abi ;
3029use std:: cell:: RefCell ;
3130use std:: collections:: hash_map:: Entry ;
3231use std:: fmt;
@@ -47,8 +46,8 @@ pub(crate) fn provide(providers: &mut Providers) {
4746 let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS . fn_sig ) ( tcx, def_id) ;
4847 result. map_bound ( |outer| {
4948 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 ;
5251 }
5352 inner
5453 } )
@@ -98,22 +97,21 @@ pub(crate) fn provide(providers: &mut Providers) {
9897 Ok ( readjust_fn_abi ( tcx, result?) )
9998 } ;
10099
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.
103101 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 {
107105 ref fields,
108106 ref variants,
109- abi ,
107+ backend_repr ,
110108 largest_niche,
111109 align,
112110 size,
113111 max_repr_align,
114112 unadjusted_abi_align,
115113 } = * layout;
116- LayoutS {
114+ LayoutData {
117115 fields : match * fields {
118116 FieldsShape :: Primitive => FieldsShape :: Primitive ,
119117 FieldsShape :: Union ( count) => FieldsShape :: Union ( count) ,
@@ -151,7 +149,7 @@ pub(crate) fn provide(providers: &mut Providers) {
151149 variants : variants. clone ( ) ,
152150 } ,
153151 } ,
154- abi ,
152+ backend_repr ,
155153 largest_niche,
156154 align,
157155 size,
@@ -171,7 +169,7 @@ pub(crate) fn provide(providers: &mut Providers) {
171169 } ;
172170
173171 if hide_niche {
174- layout = tcx. mk_layout ( LayoutS {
172+ layout = tcx. mk_layout ( LayoutData {
175173 largest_niche : None ,
176174 ..clone_layout ( layout. 0 . 0 )
177175 } ) ;
@@ -192,6 +190,10 @@ pub(crate) fn provide(providers: &mut Providers) {
192190 // an option (may require Rust-GPU distinguishing between "SPIR-V interface"
193191 // and "Rust-facing" types, which is even worse when the `OpTypeVector`s
194192 // 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)
195197 providers. check_well_formed = |tcx, def_id| {
196198 let trivial_struct = match tcx. hir_node_by_def_id ( def_id) {
197199 rustc_hir:: Node :: Item ( item) => match item. kind {
@@ -263,6 +265,14 @@ pub(crate) fn provide(providers: &mut Providers) {
263265
264266 ( rustc_interface:: DEFAULT_QUERY_PROVIDERS . check_well_formed ) ( tcx, def_id)
265267 } ;
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 = |_, _| { } ;
266276}
267277
268278/// 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> {
450460
451461 // Note: ty.layout is orthogonal to ty.ty, e.g. `ManuallyDrop<Result<isize, isize>>` has abi
452462 // `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 {
456466 def_id : def_id_for_spirv_type_adt ( * self ) ,
457467 size : Some ( Size :: ZERO ) ,
458468 align : Align :: from_bytes ( 0 ) . unwrap ( ) ,
@@ -461,13 +471,13 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
461471 field_names : None ,
462472 }
463473 . 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),
469479 // 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),
471481 // which requires more work to allow taking a reference to
472482 // that field, and there are two potential approaches:
473483 // 1. wrapping that field's SPIR-V type in a single-field
@@ -477,7 +487,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
477487 // 2. reusing that field's SPIR-V type, instead of defining
478488 // a new one, offering the `(a, b)` shape `rustc_codegen_ssa`
479489 // 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
481491 let mut non_zst_fields = ( 0 ..self . fields . count ( ) )
482492 . map ( |i| ( i, self . field ( cx, i) ) )
483493 . filter ( |( _, field) | !field. is_zst ( ) ) ;
@@ -491,7 +501,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
491501 if self . fields . offset ( i) == Size :: ZERO
492502 && field. size == self . size
493503 && field. align == self . align
494- && field. abi == self . abi
504+ && field. backend_repr == self . backend_repr
495505 {
496506 return field. spirv_type ( span, cx) ;
497507 }
@@ -532,15 +542,15 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
532542 }
533543 . def_with_name ( cx, span, TyLayoutNameKey :: from ( * self ) )
534544 }
535- Abi :: Vector { element, count } => {
545+ BackendRepr :: Vector { element, count } => {
536546 let elem_spirv = trans_scalar ( cx, span, * self , element, Size :: ZERO ) ;
537547 SpirvType :: Vector {
538548 element : elem_spirv,
539549 count : count as u32 ,
540550 }
541551 . def ( span, cx)
542552 }
543- Abi :: Aggregate { sized : _ } => trans_aggregate ( cx, span, * self ) ,
553+ BackendRepr :: Memory { sized : _ } => trans_aggregate ( cx, span, * self ) ,
544554 }
545555 }
546556}
@@ -553,8 +563,8 @@ pub fn scalar_pair_element_backend_type<'tcx>(
553563 ty : TyAndLayout < ' tcx > ,
554564 index : usize ,
555565) -> 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] ,
558568 other => span_bug ! (
559569 span,
560570 "scalar_pair_element_backend_type invalid abi: {:?}" ,
@@ -901,7 +911,7 @@ fn trans_intrinsic_type<'tcx>(
901911 // ) -> P {
902912 // let adt_def = const_.ty.ty_adt_def().unwrap();
903913 // 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_));
905915 // let idx = destructured.variant.unwrap();
906916 // let value = const_.ty.discriminant_for_variant(cx.tcx, idx).unwrap().val as u64;
907917 // <_>::from_u64(value).unwrap()
@@ -974,24 +984,17 @@ fn trans_intrinsic_type<'tcx>(
974984 cx : & CodegenCx < ' tcx > ,
975985 const_ : Const < ' tcx > ,
976986 ) -> 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_}" ) )
995998 } )
996999 }
9971000
0 commit comments