-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add infrastructure to "compute the ABI of a Rust type, described as a C type" #672
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. cc @rust-lang/compiler @rust-lang/compiler-contributors |
I think the entire ABI/ |
@rustbot second |
Which of the various variants we discussed does this second? In particular we discussed that (a variant of) Or do we leave that to experimentation during the implementation? |
Incremental progress towards (and including) replacing |
@eddyb mentions that another shape this could take is to have a method on ABI adjustments could then even be given a wrapper around |
After more discussion with @eddyb we came to no final conclusion but exchanged some promising ideas:
|
When we are refactoring the ABI adjustments anyway, it might make sense to make the entire thing properly declarative: currently we are setting a "default" |
@rustbot label -final-comment-period +major-change-accepted |
Opened an issue to track this: rust-lang/rust#119183 |
Proposal
Platform ABIs are typically defined in terms of C types. When adding support for a platform in Rust, the ABI adjustment code needs to figure out how to map Rust types into such a description. For many ABIs this is fairly simple, but some ABIs do complicated type-directed traversals, and that easily leads to issues:
extern "C" fn
on sparc64 targets does not respect repr(transparent) rust#115336extern "C" fn
on mips64 targets does not respect repr(transparent) rust#115404extern "C"
ABI violates repr(transparent) on unions rust#115481extern "C"
ABI violates repr(transparent) on unions rust#115509extern "C" fn
ABIs are all wrong when aligned/packed structs are involved rust#115609extern "C" fn
ABI on aarch64 violates repr(transparent) rust#115664Literally every single ABI that we have implemented and that does something non-trivial got it wrong! This is clearly a systematic issue. I don't have high confidence that after fixing the above bugs, those targets are "good" -- these ABIs tend to special-case specific arcane conditions and it is really hard to be sure that tests like rust-lang/rust#115372 cover all of them.
So I propose that we systematically attack this issue, by introducing a type for "C ABI descriptions" that roughly looks like this (this is a first draft, this will almost certainly need to be extended/adjusted):
We could then have a single shared function that computes the
CAbiType
for a RustTyAndLayout
, and all targets that need to make subtle adjustments should be ported to use that shared function instead of traversing the type/layout themselves. This shared function would, in particular, know to skiprepr(transparent)
wrappers.Alternative
Instead of making this a completely new type that is derived from
TyAndLayout
, we could also alter the existingAbi
type to be able to represent C structs, unions, and arrays. The intent of thatAbi
type was to capture everything relevant for the ABI, but unfortunately it turns out that the currentAbi::Aggregate
case just loses too much information.Mentors or Reviewers
I won't have time to implement this or to serve as the sole mentor, but I'd be happy to co-mentor with someone else.
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: