@@ -21,6 +21,7 @@ use rustc_middle::ty::{
2121use rustc_middle:: ty:: { GenericArgsRef , ScalarInt } ;
2222use rustc_middle:: util:: Providers ;
2323use rustc_middle:: { bug, span_bug} ;
24+ use rustc_session:: config:: OptLevel ;
2425use rustc_span:: DUMMY_SP ;
2526use rustc_span:: def_id:: DefId ;
2627use rustc_span:: { Span , Symbol } ;
@@ -131,7 +132,15 @@ pub(crate) fn provide(providers: &mut Providers) {
131132 let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS
132133 . queries
133134 . fn_abi_of_instance_no_deduced_attrs ) ( tcx, key) ;
134- Ok ( readjust_fn_abi ( tcx, result?) )
135+ // Keep this query in its original shape while `fn_abi_of_instance_raw`
136+ // is being computed: rustc validates strict invariants there.
137+ // Otherwise, if `fn_abi_of_instance` would route through this query
138+ // directly (e.g. incremental or opt-level=0), apply SPIR-V readjustment.
139+ if tcx. sess . opts . optimize != OptLevel :: No && tcx. sess . opts . incremental . is_none ( ) {
140+ result
141+ } else {
142+ Ok ( readjust_fn_abi ( tcx, result?) )
143+ }
135144 } ;
136145 providers. queries . fn_abi_of_instance_raw = |tcx, key| {
137146 let result = ( rustc_interface:: DEFAULT_QUERY_PROVIDERS
0 commit comments