-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Generalize get_nullable_type
to allow types where null is all-ones.
#94586
Merged
bors
merged 1 commit into
rust-lang:master
from
sunfishcode:sunfishcode/io-lifetimes-tests
Mar 8, 2022
Merged
Generalize get_nullable_type
to allow types where null is all-ones.
#94586
bors
merged 1 commit into
rust-lang:master
from
sunfishcode:sunfishcode/io-lifetimes-tests
Mar 8, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generalize get_nullable_type to accept types that have an all-ones bit pattern as their sentry "null" value. This will allow [`OwnedFd`], [`BorrowedFd`], [`OwnedSocket`], and [`BorrowedSocket`] to be marked with `#[rustc_nonnull_optimization_guaranteed]`, which will allow `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. For example, it will allow a function like `open` on Unix and `WSASocketW` on Windows to be declared using `Option<OwnedFd>` and `Option<OwnedSocket>` return types, respectively. The actual change to add `#[rustc_nonnull_optimization_guaranteed]` to the abovementioned types will be a separate PR, as it'll depend on having this patch in the stage0 compiler. Also, update the diagnostics to mention that "niche optimizations" are used in libstd as well as libcore, as `rustc_layout_scalar_valid_range_start` and `rustc_layout_scalar_valid_range_end` are already in use in libstd. [`OwnedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L49 [`BorrowedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L29 [`OwnedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L51 [`BorrowedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L29 [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
rustbot
added
the
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
label
Mar 4, 2022
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
Mar 4, 2022
This was referenced Mar 4, 2022
davidtwco
approved these changes
Mar 8, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay in reviewing, this looks good to me.
@bors r+ |
📌 Commit 86b4658 has been approved by |
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-review
Status: Awaiting review from the assignee but also interested parties.
labels
Mar 8, 2022
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Mar 8, 2022
…askrgr Rollup of 8 pull requests Successful merges: - rust-lang#91993 (Tweak output for non-exhaustive `match` expression) - rust-lang#92385 (Add Result::{ok, err, and, or, unwrap_or} as const) - rust-lang#94559 (Remove argument from closure in thread::Scope::spawn.) - rust-lang#94580 (Emit `unused_attributes` if a level attr only has a reason) - rust-lang#94586 (Generalize `get_nullable_type` to allow types where null is all-ones.) - rust-lang#94708 (diagnostics: only talk about `Cargo.toml` if running under Cargo) - rust-lang#94712 (promot debug_assert to assert) - rust-lang#94726 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
sunfishcode
added a commit
to sunfishcode/rust
that referenced
this pull request
May 11, 2022
PR rust-lang#94586 added support for using `rustc_nonnull_optimization_guaranteed` on values where the "null" value is the all-ones bitpattern. Now that rust-lang#94586 has made it to the stage0 compiler, add `rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`, `OwnedSocket`, and `BorrowedSocket`, since these types all exclude all-ones bitpatterns. This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
Dylan-DPC
added a commit
to Dylan-DPC/rust
that referenced
this pull request
May 15, 2022
…ll-optimization-guaranteed, r=joshtriplett Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket PR rust-lang#94586 added support for using `rustc_nonnull_optimization_guaranteed` on values where the "null" value is the all-ones bitpattern. Now that rust-lang#94586 has made it to the stage0 compiler, add `rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`, `OwnedSocket`, and `BorrowedSocket`, since these types all exclude all-ones bitpatterns. This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
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-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Generalize get_nullable_type to accept types that have an all-ones bit
pattern as their sentry "null" value.
This will allow
OwnedFd
,BorrowedFd
,OwnedSocket
, andBorrowedSocket
to be marked with#[rustc_nonnull_optimization_guaranteed]
, which will allowOption<OwnedFd>
,Option<BorrowedFd>
,Option<OwnedSocket>
, andOption<BorrowedSocket>
to be used in FFI declarations, as describedin the I/O safety RFC.
For example, it will allow a function like
open
on Unix andWSASocketW
on Windows to be declared using
Option<OwnedFd>
andOption<OwnedSocket>
return types, respectively.
The actual change to add
#[rustc_nonnull_optimization_guaranteed]
to the abovementioned types will be a separate PR, as it'll depend on
having this patch in the stage0 compiler.
Also, update the diagnostics to mention that "niche optimizations" are
used in libstd as well as libcore, as
rustc_layout_scalar_valid_range_start
and
rustc_layout_scalar_valid_range_end
are already in use in libstd.