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

Make std::os::fd public. #98368

Merged
merged 5 commits into from
Sep 29, 2022
Merged

Conversation

sunfishcode
Copy link
Member

std::os::fd defines types like OwnedFd and RawFd and is common
between Unix and non-Unix platforms that share a basic file-descriptor
concept. Rust currently uses this internally to simplify its own code,
but it would be useful for external users in the same way, so make it
public.

This means that OwnedFd etc. will all appear in three places, for
example on unix platforms:

  • std::os::fd::OwnedFd
  • std::os::unix::io::OwnedFd
  • std::os::unix::prelude::OwnedFd

r? @joshtriplett

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 22, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2022
@joshtriplett joshtriplett added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 22, 2022
@joshtriplett
Copy link
Member

@rfcbot merge

@rfcbot

This comment was marked as outdated.

@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 23, 2022
@dtolnay
Copy link
Member

dtolnay commented Jun 29, 2022

Would it be possible to get a listing of everything that is being proposed to be stabilized at a path inside std::os::fd (and on what platforms) by this PR? Currently the summary just says "types like OwnedFd and RawFd" which isn't specific enough for me to approve the stabilization.

@rfcbot concern what are the contents

@sunfishcode
Copy link
Member Author

@dtolnay The contents of the fd module in this PR are:

  • types: OwnedFd, BorrowedFd, RawFd
  • traits: AsFd, AsRawFd, IntoRawFd, FromRawFd

The platforms this PR adds the fd module to are Unix-family platforms (cfg(unix)) and WASI (cfg(target_os = "wasi")).

In the future, it's possible that fortanix_sgx and/or solid may want to add this module as well, as they also have similar types and traits.

@dtolnay
Copy link
Member

dtolnay commented Jun 29, 2022

Great!

@rfcbot resolve what are the contents
@rfcbot reviewed

@BurntSushi
Copy link
Member

Is this insta-stable?

The other thing I'm confused about here is why things like RawFd are going in a platform independent module? They aren't used on Windows, for example, right?

@dtolnay
Copy link
Member

dtolnay commented Jun 29, 2022

I think the idea is that we already have std::os::unix, and std::os::wasi, and in the future perhaps std::os::fortanix_sgx or std::os::solid, all of which contain identical fd-related wrappers and traits. If someone is writing code for "anything with an fd", they can't easily do it. So std::os::fd serves as std::os::[anything with an fd].

@BurntSushi
Copy link
Member

@dtolnay Ah I see thanks, I think that makes sense.

@sunfishcode Can we add that guidance to the docs of std::os::fd? That is, call out that RawFd (and company) aren't purely platform independent, but that they are used on so many platforms that it can be convenient to just import it from std::os::fd.

I do admit though that this feels a little strange to me to be honest. I like the practicality behind this, but I think you still have to gate std::os::fd imports with conditional compilation in order for it to be correct, right? If so, I'd expect that to be in the docs too, because the import doesn't really hint that you need any conditional compilation.

@rustbot
Copy link
Collaborator

rustbot commented Jun 30, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@sunfishcode
Copy link
Member Author

Is this insta-stable?

Yes, I guess it currently is. Would it be better here to use #[unstable(...)]? And I guess open a tracking issue?

@sunfishcode Can we add that guidance to the docs of std::os::fd? That is, call out that RawFd (and company) aren't purely platform independent, but that they are used on so many platforms that it can be convenient to just import it from std::os::fd.

I've clarified the comment to explicitly mention both Unix and WASI.

I do admit though that this feels a little strange to me to be honest. I like the practicality behind this, but I think you still have to gate std::os::fd imports with conditional compilation in order for it to be correct, right? If so, I'd expect that to be in the docs too, because the import doesn't really hint that you need any conditional compilation.

It does already have conditional compilation; the pub mod fd is gated on #[cfg(any(unix, target_os = "wasi", doc))]. Is that what you're referring to?

@BurntSushi
Copy link
Member

It does already have conditional compilation; the pub mod fd is gated on #[cfg(any(unix, target_os = "wasi", doc))]. Is that what you're referring to?

Hmmm, I suppose, yes. I was more referring to consumers of this API. The import path doesn't really make it clear (like other import paths do) that conditional compilation is needed. It's just a departure from what we've done, I think.

The fact that pub mod fd is gated on any(unix, target_os = "wasi", doc) does make it better. But still overall feels a little weird to me.

@BurntSushi
Copy link
Member

Yes, I guess it currently is. Would it be better here to use #[unstable(...)]? And I guess open a tracking issue?

I'm not sure of the underlying mechanism, but basically, if we don't have to do this as insta-stable, then we probably shouldn't. The typical insta-stable things are trait impls, and I believe that's because there just isn't any alternative.

@sunfishcode sunfishcode mentioned this pull request Jun 30, 2022
3 tasks
@sunfishcode
Copy link
Member Author

Yes, I guess it currently is. Would it be better here to use #[unstable(...)]? And I guess open a tracking issue?

I'm not sure of the underlying mechanism, but basically, if we don't have to do this as insta-stable, then we probably shouldn't. The typical insta-stable things are trait impls, and I believe that's because there just isn't any alternative.

I've now filed a tracking issue #98699, and updated the PR to use a #[unstable(...)] attribute. This was a little tricky, because the fd module is already used internally in a way that doesn't want it to be #[unstable(...)], so it appears this requires having two separate modules.

@dtolnay
Copy link
Member

dtolnay commented Jun 30, 2022

@rfcbot fcp cancel

@rfcbot
Copy link

rfcbot commented Jun 30, 2022

@dtolnay proposal cancelled.

@rfcbot rfcbot removed 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 30, 2022
@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 1, 2022
@sunfishcode
Copy link
Member Author

Fixed the WIndows build issue.

r? @joshtriplett

@joshtriplett
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 28, 2022

📌 Commit a7f3ba9 has been approved by joshtriplett

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 28, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 28, 2022
…r=joshtriplett

Make `std::os::fd` public.

`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common
between Unix and non-Unix platforms that share a basic file-descriptor
concept. Rust currently uses this internally to simplify its own code,
but it would be useful for external users in the same way, so make it
public.

This means that `OwnedFd` etc. will all appear in three places, for
example on unix platforms:
 - `std::os::fd::OwnedFd`
 - `std::os::unix::io::OwnedFd`
 - `std::os::unix::prelude::OwnedFd`

r? `@joshtriplett`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 28, 2022
…r=joshtriplett

Make `std::os::fd` public.

`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common
between Unix and non-Unix platforms that share a basic file-descriptor
concept. Rust currently uses this internally to simplify its own code,
but it would be useful for external users in the same way, so make it
public.

This means that `OwnedFd` etc. will all appear in three places, for
example on unix platforms:
 - `std::os::fd::OwnedFd`
 - `std::os::unix::io::OwnedFd`
 - `std::os::unix::prelude::OwnedFd`

r? ``@joshtriplett``
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Sep 29, 2022
…r=joshtriplett

Make `std::os::fd` public.

`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common
between Unix and non-Unix platforms that share a basic file-descriptor
concept. Rust currently uses this internally to simplify its own code,
but it would be useful for external users in the same way, so make it
public.

This means that `OwnedFd` etc. will all appear in three places, for
example on unix platforms:
 - `std::os::fd::OwnedFd`
 - `std::os::unix::io::OwnedFd`
 - `std::os::unix::prelude::OwnedFd`

r? ```@joshtriplett```
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Sep 29, 2022
…r=joshtriplett

Make `std::os::fd` public.

`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common
between Unix and non-Unix platforms that share a basic file-descriptor
concept. Rust currently uses this internally to simplify its own code,
but it would be useful for external users in the same way, so make it
public.

This means that `OwnedFd` etc. will all appear in three places, for
example on unix platforms:
 - `std::os::fd::OwnedFd`
 - `std::os::unix::io::OwnedFd`
 - `std::os::unix::prelude::OwnedFd`

r? ````@joshtriplett````
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 29, 2022
Rollup of 8 pull requests

Successful merges:

 - rust-lang#98368 (Make `std::os::fd` public.)
 - rust-lang#102085 (Code refactoring smart_resolve_report_errors)
 - rust-lang#102351 (Improve E0585 help)
 - rust-lang#102368 (Add a niche to `Duration`, unix `SystemTime`, and non-apple `Instant`)
 - rust-lang#102393 (Add regression test for issue 94923)
 - rust-lang#102399 (Account for use of index-based lifetime names in print of binder)
 - rust-lang#102416 (remove FIXME, improve documentation)
 - rust-lang#102433 (env::temp_dir: fix a typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7cd4780 into rust-lang:master Sep 29, 2022
@rustbot rustbot added this to the 1.66.0 milestone Sep 29, 2022
@sunfishcode sunfishcode deleted the sunfishcode/std-os-fd branch January 13, 2023 00:48
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Jan 15, 2023
As @bjorn3 pointed out [here], I used the wrong stability attribute in rust-lang#98368
when making `std::os::fd` public. I set it to Rust 1.63, which was when
io-safety was stabilized, but it should be Rust 1.66, which was when
`std::os::fd` was stabilized.

[here]: rust-lang#98368 (comment)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 15, 2023
…stable-version, r=m-ou-se

Fix the stability attributes for `std::os::fd`.

As `@bjorn3` pointed out [here], I used the wrong stability attribute in rust-lang#98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized.

[here]: rust-lang#98368 (comment)
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request May 31, 2023
As @bjorn3 pointed out [here], I used the wrong stability attribute in #98368
when making `std::os::fd` public. I set it to Rust 1.63, which was when
io-safety was stabilized, but it should be Rust 1.66, which was when
`std::os::fd` was stabilized.

[here]: rust-lang/rust#98368 (comment)
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request May 31, 2023
…rsion, r=m-ou-se

Fix the stability attributes for `std::os::fd`.

As `@bjorn3` pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized.

[here]: rust-lang/rust#98368 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.