Skip to content
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

Tracking Issue for core_ffi_c #94501

Closed
1 of 3 tasks
joshtriplett opened this issue Mar 1, 2022 · 13 comments
Closed
1 of 3 tasks

Tracking Issue for core_ffi_c #94501

joshtriplett opened this issue Mar 1, 2022 · 13 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@joshtriplett
Copy link
Member

joshtriplett commented Mar 1, 2022

Feature gate: #![feature(core_ffi_c)]

This is a tracking issue for providing the aliases for C types (c_int, c_char, etc) via core::ffi, not just via std::os::raw. The ability to interoperate with C code via FFI is not limited to crates using std; this allows using these types without std.

Public API

// core::ffi

pub type c_char = ...;
pub type c_short = ...;
pub type c_ushort = ...;
pub type c_int = ...;
pub type c_uint = ...;
// ...

The existing types in std::os::raw will become type aliases for the ones in core::ffi. This will use type aliases rather than re-exports, to allow the std types to remain stable while the core types are unstable.

This also moves the currently unstable NonZero variants and c_size_t/c_ssize_t/c_ptrdiff_t types to core::ffi, while leaving them unstable.

Steps / History

@joshtriplett joshtriplett added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Mar 1, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 2, 2022
Provide C FFI types via core::ffi, not just in std

Tracking issue: rust-lang#94501

The ability to interoperate with C code via FFI is not limited to crates
using std; this allows using these types without std.

The existing types in `std::os::raw` become type aliases for the ones in
`core::ffi`. This uses type aliases rather than re-exports, to allow the
std types to remain stable while the core types are unstable.

This also moves the currently unstable `NonZero_` variants and
`c_size_t`/`c_ssize_t`/`c_ptrdiff_t` types to `core::ffi`, while leaving
them unstable.

Historically, we didn't do this because these types are target-dependent.
However, `core` itself is also target-dependent. `core` should not call
any OS services, but it knows the target and the target's ABI.
@bstrie
Copy link
Contributor

bstrie commented Mar 2, 2022

To clarify, was #94503 able to avoid insta-stability of the new items? There seems to be some confusion as to whether or not type aliases respect stability markers.

@joshtriplett
Copy link
Member Author

joshtriplett commented Mar 3, 2022

@bstrie It appears so: core::ffi::c_ulong shows up as unstable, while std::os::raw::c_ulong shows up as stable.

@madsmtm
Copy link
Contributor

madsmtm commented Jun 7, 2022

The introductory docs for core currently says:

this library is platform-agnostic

So that should probably be modified slightly if we go with this change? (Which I am greatly in favour of btw)

@SimonSapin
Copy link
Contributor

Should these items also be available in std::ffi, in order to keep std a superset of core? (Though in this case it’s redundant with std::os::raw)

@joshtriplett
Copy link
Member Author

@SimonSapin They were, but that was reverted in 07ea143 because it caused breakage; we can re-add it as re-exports when we stabilize this.

@joshtriplett
Copy link
Member Author

The introductory docs for core currently says:

this library is platform-agnostic

So that should probably be modified slightly if we go with this change? (Which I am greatly in favour of btw)

core is platform-agnostic: it's skeptical about platforms but doesn't deny their existence

More seriously: I think the key detail here is that core doesn't offer any interfaces to platform functionality; it doesn't call into the platform. I think offering portable types whose layout is platform-specific doesn't invalidate that. core also has interfaces which use usize, whose size varies by platform.

@joshtriplett
Copy link
Member Author

Following up from Zulip:

@rust-lang/libs-api, shall we stabilize the core::ffi::c_* types?

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Jun 12, 2022

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jun 12, 2022
@BurntSushi
Copy link
Member

To be clear, this also includes adding these types to std::ffi too?

@joshtriplett
Copy link
Member Author

@BurntSushi Yes.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jun 21, 2022
@rfcbot
Copy link

rfcbot commented Jun 21, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot
Copy link

rfcbot commented Jul 1, 2022

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jul 1, 2022
@joshtriplett
Copy link
Member Author

Stabilized in #98315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants