@@ -13,13 +13,13 @@ use rustc_abi::{
1313use rustc_data_structures:: fx:: FxHashMap ;
1414use rustc_errors:: ErrorGuaranteed ;
1515use rustc_index:: Idx ;
16- use rustc_middle:: query:: Providers ;
1716use rustc_middle:: ty:: layout:: { FnAbiOf , LayoutOf , TyAndLayout } ;
1817use rustc_middle:: ty:: {
1918 self , Const , CoroutineArgs , CoroutineArgsExt as _, FloatTy , IntTy , PolyFnSig , Ty , TyCtxt ,
20- TyKind , UintTy ,
19+ TyKind , UintTy , ValTreeKindExt ,
2120} ;
2221use rustc_middle:: ty:: { GenericArgsRef , ScalarInt } ;
22+ use rustc_middle:: util:: Providers ;
2323use rustc_middle:: { bug, span_bug} ;
2424use rustc_span:: DUMMY_SP ;
2525use rustc_span:: def_id:: DefId ;
@@ -29,6 +29,19 @@ use std::cell::RefCell;
2929use std:: collections:: hash_map:: Entry ;
3030use std:: fmt;
3131
32+ fn rewrite_c_abi_to_rust < ' tcx > (
33+ fn_sig : ty:: EarlyBinder < ' tcx , ty:: PolyFnSig < ' tcx > > ,
34+ ) -> ty:: EarlyBinder < ' tcx , ty:: PolyFnSig < ' tcx > > {
35+ fn_sig. map_bound ( |outer| {
36+ outer. map_bound ( |mut inner| {
37+ if let Abi :: C { .. } = inner. abi {
38+ inner. abi = Abi :: Rust ;
39+ }
40+ inner
41+ } )
42+ } )
43+ }
44+
3245pub ( crate ) fn provide ( providers : & mut Providers ) {
3346 // This is a lil weird: so, we obviously don't support C ABIs at all. However, libcore does declare some extern
3447 // C functions:
@@ -44,18 +57,19 @@ pub(crate) fn provide(providers: &mut Providers) {
4457 // NOTE: this used to rewrite to `extern "unadjusted"`, but rustc now
4558 // validates `#[rustc_pass_indirectly_in_non_rustic_abis]` for non-Rust ABIs,
4659 // and `Unadjusted` does not satisfy that requirement.
47- providers. fn_sig = |tcx, def_id| {
60+ providers. queries . fn_sig = |tcx, def_id| {
4861 // We can't capture the old fn_sig and just call that, because fn_sig is a `fn`, not a `Fn`, i.e. it can't
4962 // capture variables. Fortunately, the defaults are exposed (thanks rustdoc), so use that instead.
50- let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS . fn_sig ) ( tcx, def_id) ;
51- result. map_bound ( |outer| {
52- outer. map_bound ( |mut inner| {
53- if let Abi :: C { .. } = inner. abi {
54- inner. abi = Abi :: Rust ;
55- }
56- inner
57- } )
58- } )
63+ let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS . queries . fn_sig ) ( tcx, def_id) ;
64+ rewrite_c_abi_to_rust ( result)
65+ } ;
66+ providers. extern_queries . fn_sig = |tcx, def_id| {
67+ // We can't capture the old fn_sig and just call that, because fn_sig is a `fn`, not a `Fn`, i.e. it can't
68+ // capture variables. Fortunately, the defaults are exposed (thanks rustdoc), so use that instead.
69+ let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS
70+ . extern_queries
71+ . fn_sig ) ( tcx, def_id) ;
72+ rewrite_c_abi_to_rust ( result)
5973 } ;
6074
6175 // For the Rust ABI, `FnAbi` adjustments are backend-agnostic, but they will
@@ -67,7 +81,7 @@ pub(crate) fn provide(providers: &mut Providers) {
6781 fn_abi : & ' tcx FnAbi < ' tcx , Ty < ' tcx > > ,
6882 ) -> & ' tcx FnAbi < ' tcx , Ty < ' tcx > > {
6983 let readjust_arg_abi = |arg : & ArgAbi < ' tcx , Ty < ' tcx > > | {
70- let mut arg = ArgAbi :: new ( & tcx, arg. layout , |_, _, _ | ArgAttributes :: new ( ) ) ;
84+ let mut arg = ArgAbi :: new ( & tcx, arg. layout , |_, _| ArgAttributes :: new ( ) ) ;
7185 // FIXME: this is bad! https://github.com/rust-lang/rust/issues/115666
7286 // <https://github.com/rust-lang/rust/commit/eaaa03faf77b157907894a4207d8378ecaec7b45>
7387 arg. make_direct_deprecated ( ) ;
@@ -86,6 +100,12 @@ pub(crate) fn provide(providers: &mut Providers) {
86100 arg. mode = PassMode :: Ignore ;
87101 }
88102
103+ // SPIR-V backend lowers arguments by-value and cannot handle
104+ // backend-specific indirection/casts at this layer.
105+ if matches ! ( arg. mode, PassMode :: Cast { .. } | PassMode :: Indirect { .. } ) {
106+ arg. mode = PassMode :: Direct ( ArgAttributes :: new ( ) ) ;
107+ }
108+
89109 arg
90110 } ;
91111 tcx. arena . alloc ( FnAbi {
@@ -101,12 +121,22 @@ pub(crate) fn provide(providers: &mut Providers) {
101121 can_unwind : fn_abi. can_unwind ,
102122 } )
103123 }
104- providers. fn_abi_of_fn_ptr = |tcx, key| {
105- let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS . fn_abi_of_fn_ptr ) ( tcx, key) ;
124+ providers. queries . fn_abi_of_fn_ptr = |tcx, key| {
125+ let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS
126+ . queries
127+ . fn_abi_of_fn_ptr ) ( tcx, key) ;
128+ Ok ( readjust_fn_abi ( tcx, result?) )
129+ } ;
130+ providers. queries . fn_abi_of_instance_no_deduced_attrs = |tcx, key| {
131+ let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS
132+ . queries
133+ . fn_abi_of_instance_no_deduced_attrs ) ( tcx, key) ;
106134 Ok ( readjust_fn_abi ( tcx, result?) )
107135 } ;
108- providers. fn_abi_of_instance = |tcx, key| {
109- let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS . fn_abi_of_instance ) ( tcx, key) ;
136+ providers. queries . fn_abi_of_instance_raw = |tcx, key| {
137+ let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS
138+ . queries
139+ . fn_abi_of_instance_raw ) ( tcx, key) ;
110140 Ok ( readjust_fn_abi ( tcx, result?) )
111141 } ;
112142
@@ -116,7 +146,7 @@ pub(crate) fn provide(providers: &mut Providers) {
116146 //
117147 // FIXME(eddyb) same as the FIXME comment on `check_well_formed`:
118148 // need to migrate away from `#[repr(simd)]` ASAP.
119- providers. check_mono_item = |_, _| { } ;
149+ providers. queries . check_mono_item = |_, _| { } ;
120150}
121151
122152/// If a struct contains a pointer to itself, even indirectly, then doing a naiive recursive walk
@@ -291,6 +321,7 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
291321 span = cx. tcx . def_span ( adt. did ( ) ) ;
292322 }
293323
324+ #[ allow( deprecated) ]
294325 let attrs = AggregatedSpirvAttributes :: parse ( cx, cx. tcx . get_all_attrs ( adt. did ( ) ) ) ;
295326
296327 if let Some ( intrinsic_type_attr) = attrs. intrinsic_type . map ( |attr| attr. value )
@@ -395,6 +426,10 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
395426 }
396427 . def ( span, cx)
397428 }
429+ BackendRepr :: ScalableVector { .. } => cx
430+ . tcx
431+ . dcx ( )
432+ . fatal ( "scalable vectors are not supported in SPIR-V backend" ) ,
398433 BackendRepr :: Memory { sized : _ } => trans_aggregate ( cx, span, * self ) ,
399434 }
400435 }
@@ -614,22 +649,11 @@ fn trans_aggregate<'tcx>(cx: &CodegenCx<'tcx>, span: Span, ty: TyAndLayout<'tcx>
614649 . def ( span, cx)
615650 }
616651 }
617- FieldsShape :: Arbitrary {
618- offsets : _,
619- memory_index : _,
620- } => trans_struct_or_union ( cx, span, ty, None ) ,
652+ FieldsShape :: Arbitrary { .. } => trans_struct_or_union ( cx, span, ty, None ) ,
621653 }
622654}
623655
624- #[ cfg_attr(
625- not( rustc_codegen_spirv_disable_pqp_cg_ssa) ,
626- expect(
627- unused,
628- reason = "actually used from \
629- `<rustc_codegen_ssa::traits::ConstCodegenMethods for CodegenCx<'_>>::const_struct`, \
630- but `rustc_codegen_ssa` being `pqp_cg_ssa` makes that trait unexported"
631- )
632- ) ]
656+ #[ cfg_attr( not( rustc_codegen_spirv_disable_pqp_cg_ssa) , allow( unused) ) ]
633657// returns (field_offsets, size, align)
634658pub fn auto_struct_layout (
635659 cx : & CodegenCx < ' _ > ,
@@ -866,7 +890,8 @@ fn trans_intrinsic_type<'tcx>(
866890 } = const_. to_value ( ) ;
867891 assert ! ( const_ty. is_integral( ) ) ;
868892 const_val
869- . try_to_scalar_int ( )
893+ . try_to_scalar ( )
894+ . and_then ( |scalar| scalar. try_to_scalar_int ( ) . ok ( ) )
870895 . and_then ( P :: from_scalar_int)
871896 . ok_or_else ( || {
872897 cx. tcx
0 commit comments