abi: readjust FnAbi
s to remove unsupported PassMode
s, via query hooks.
#766
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
The
rustc
"call ABI" computation tries to find efficient ways to pass arguments (into functions) and return values (out of functions), and this can result in situations where e.g.PassMode::Cast
is used to indicate that a[u8; 4]
is actually being passed using a single 32-bit (CPU) register.While useful at the machine ABI level, SPIR-V is too high-level and doesn't support the necessary raw manipulation to implement that kind of trick, so for a while now we've had to work around the situations in which
rustc
would decide for us on aPassMode
that is incompatible with SPIR-V, with no room for the backend to override this behavior at all.To a lesser extent,
PassMode::Indirect
is also not great for SPIR-V, as MIR allows more by-ref argument/return value passing than SPIR-V considers valid, and extra work was required to remove that after the fact (or bugs like #731 crept in because extra copies would've had to be used to remain correct).Solution
We can now hook
FnAbi
computation, thanks to these upstream PRs:layout_raw
query intolayout_of
. rust-lang/rust#88308TyAndLayout::field
should never error. rust-lang/rust#88337layout_of
automatically (given tcx + param_env + error handling). rust-lang/rust#88499FnAbi::of_{fn_ptr,instance}
asfn_abi_of_{fn_ptr,instance}
. rust-lang/rust#88575fn_abi_of_*
queries wouldn't have been consistent withlayout_of
, without the other refactorsThe
Layout
/FnAbi
interface refactors have already been accounted inrustup
PRs (e.g. #759), so the main change in this PR is taking advantage of query hooking, to overridefn_abi_of_*
queries' behavior.Both
PassMode::Cast
and (for good measure)PassMode::Ignore
are now impossible, and if we wanted to we could also get rid ofPassMode::Pair
(like e.g. many C ABIs do), but that could introduce its own problems (so I would leave it for a different PR, if we even want it).Fixes #373.
Fixes #731 (unrelated to
PassMode::Cast
, but becausePassMode::Indirect
is no longer used).Note: opened as draft because I would like to add more tests before merging.