rust icon indicating copy to clipboard operation
rust copied to clipboard

Tracking Issue for result_ffi_guarantees (RFC 3391)

Open tmandry opened this issue 2 years ago • 6 comments

This is a tracking issue for the RFC "result_ffi_guarantees" (rust-lang/rfcs#3391).

About tracking issues

Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

None

Implementation history

tmandry avatar Apr 18 '23 19:04 tmandry

I did a bunch of work on ABI tests for repr(transparent) that could also be useful for testing this RFC:

  • Miri now has this test: https://github.com/rust-lang/miri/blob/master/tests/pass/function_calls/abi_compat.rs
  • and rustct will hopefully soon have this: https://github.com/rust-lang/rust/pull/115372

RalfJung avatar Aug 31 '23 16:08 RalfJung

Is anyone still working on this? If not, I'd love to try my shot at it.

MasterAwesome avatar Mar 09 '24 00:03 MasterAwesome

I have not heard word of anyone working on this in a very long time. It's probably a safe bet to begin a PR.

Lokathor avatar Mar 09 '24 00:03 Lokathor

Besides adjusting the improper-ctypes lint (which is happening in https://github.com/rust-lang/rust/pull/122253), some other things that should be done:

  • For Option we have this documentation. I assume we want the same for Result? Is there some way to not repeat the table?
  • Miri has a test here that currently only checks Option, not Result.

RalfJung avatar Mar 12 '24 16:03 RalfJung

Should the documentation change be a separate PR?

MasterAwesome avatar Mar 12 '24 16:03 MasterAwesome

Yes, that probably makes review easier.

RalfJung avatar Mar 12 '24 16:03 RalfJung

The lint update PR has merged.

Lokathor avatar May 06 '24 05:05 Lokathor

I hope docs are next, then. :) We shouldn't go too long with such a gap between what we document and what we implement.

The Result type itself should get suitable documentation. And probably there's somewhere in the reference as well that needs updating?

RalfJung avatar May 06 '24 05:05 RalfJung

philosophically speaking I'm not sure how much the reference needs to say in addition to what the standard library type docs say, but yeah docs on Option and Result are the next step. I will likely have time for a docs PR very soon if no one else does it first

Lokathor avatar May 06 '24 06:05 Lokathor

The docs are merged.

@tmandry Is there more to do or can we officially call this done?

Lokathor avatar May 28 '24 08:05 Lokathor

I think Miri still needs tests. Those would go around here.

RalfJung avatar May 28 '24 08:05 RalfJung

Followup: The MIRI test cases have been merged.

I believe we're done? Should we put this into the release notes two releases from now?

Lokathor avatar Jun 12 '24 19:06 Lokathor

Yeah sounds right! I have added the relnotes label to https://github.com/rust-lang/rust/pull/124870. But with that PR being "closed" rather than "merged" I don't know if that will work properly...

RalfJung avatar Jun 12 '24 21:06 RalfJung

This is still unstable, right? What exactly are we wanting to promise in relnotes?

e.g. This still warns if the feature gate is not enabled: playground

//#![feature(result_ffi_guarantees)]

extern "C" {
    pub fn foo() -> Result<(), std::num::NonZeroU32>;
}
warning: `extern` block uses type `Result<(), NonZero<u32>>`, which is not FFI-safe
 --> src/lib.rs:4:21
  |
4 |     pub fn foo() -> Result<(), std::num::NonZeroU32>;
  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
  |
  = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
  = note: enum has no representation hint
  = note: `#[warn(improper_ctypes)]` on by default

cuviper avatar Jul 09 '24 20:07 cuviper

I guess there needs to be a final stabilization PR for the feature, but it doesn't need T-lang signoff?

Lokathor avatar Jul 09 '24 21:07 Lokathor

Why would it not need t-lang signoff?

RalfJung avatar Jul 10 '24 06:07 RalfJung

that's just what @tmandry wrote in the start of the thread next to the checked box.

Lokathor avatar Jul 10 '24 06:07 Lokathor

Where is the reference PR they are mentioning there?

RalfJung avatar Jul 10 '24 06:07 RalfJung

I don't know, actually. I just saw a checked box and assumed the box wouldn't be checked if it wasn't completed yet.

Lokathor avatar Jul 11 '24 02:07 Lokathor

I must have been under the impression that this was only a documentation change. It probably needs a lang team signoff since it's more than that.

tmandry avatar Jul 11 '24 02:07 tmandry