-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Nullable-pointer Option
s aren't FFI-compatible with the base pointer types.
#11303
Comments
I am a bit worried about what promises we can make regarding Option's compatibility with C. Option's representation is so dependent upon it's contents, and I'm seeing FFI user's want to deal with various other different Option types from C. Personally, I do not think it's a best practice to use Rust pointers in the FFI and always convert to unsafe pointers. I would not be opposed to keeping Option a struct and telling people to leave it out of the FFI. |
One problem is that the |
I have a patch that almost works, but there's this, from enum UniqueList {
ULNil, ULCons(~UniqueList)
} That's a nullable pointer to itself, which sends |
Nominating. Although we aren't trying to make any promises about Rust's ABI, this is still pretty important to get right. |
@brson this seems to have more to do with the treatment of non-C types in |
This is an important issue. We need to be a little concerned about over-committing too many guarantees about our FFI and the ABI and data representations / compatibility in 1.0. In any case, right now we are not going to guarantee that we will solve this particular problem for 1.0. P-high, but not 1.0. |
Questions about whether this is valid today or whether we want to support this in the future may be better directed at #12608 now. |
This slightly adjusts the NullablePointer representation for some enums in the case where the non-nullable variant has a single field (the ptr field) to be just that, the pointer. This is in contrast to the current behaviour where we'd wrap that single pointer in a LLVM struct. Fixes #11040 & #11303.
Fixed by #14121. |
Works on x86_64; crashes on i686. The Rust
struct
orenum
gets an LLVM struct wrapped around it, which changes the ABI on 32-bit x86 if the type is used as a return type. This is an unpleasant surprise for projects using the FFI to represent nullable pointers from C, and there isn't an immediately obvious workaround.But also:
Same thing. But we probably don't want one-field structs to deviate from the ABI for the equivalent C struct, and the newtype case can (I think?) just use a wrapper to do the conversion instead. This yields the slightly counterintuitive result that adjoining a value to a type makes its representation slightly more efficient (option returned in register vs. newtype returned on stack), but we might be willing to live with that.
See also #10570; cc @bjz @rlane
The text was updated successfully, but these errors were encountered: