Move OS-dependent parts of std::io to alloc#152918
Conversation
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
319bd3c to
0989265
Compare
This comment has been minimized.
This comment has been minimized.
|
I have a idea, that move iovec into struct iovec {
iov_base: *mut c_void,
iov_len: usize,
}for windows/UEFI, use struct iovec {
iov_len: c_ulong,
iov_base: *mut c_void,
}and for RawOsError, it's can also defined in core:ffi as
|
|
It would possible indeed. I think that what we'll do will depend on T-libs team preference. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
To make rustdoc happy, I had to remove a bunch a links in |
|
@rustbot reroll |
A specific plan should be proposed as an ACP before starting too much work, there are tradeoffs and alternatives that need to be discussed and accepted by the libs-api team. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
This is a separated commit to be easy to reverse later.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Up on this! Also friendly ping @jhpratt, when do you think that you will have time to review this? |
|
I can take a look later, but note that I did reassign reviewers a bit ago :) For perf, I'll start a run if I don't see anything obvious. |
Oh sorry, I missed that. Ping @joboet then! |
|
☔ The latest upstream changes (presumably #155837) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@bushrat011899 can you file a new issue or place a comment somewhere (that is kept up to date) on which PRs should be reviewed in what order? I see you have several parallel PRs in flight and it would help to have an overview. E.g., it looks like #155849 pulls out one of the commits from this PR (seems good -- smaller is easier to review, generally), it seems like I should review that first? |
|
@Mark-Simulacrum Yes that is correct, I've opened up: Which both take up most of the most of the controversial changes of this PR, but they do go further by going straight to EDIT: I've made a more detailed summary of the current state of this effort here. |
|
I'll mark this as blocked, since it overlaps with the other PRs. Feel free to flip the labels once this PR is ready. @rustbot label +S-blocked -S-waiting-on-review |
Move `IoSlice` and `IoSliceMut` to `core::io` ACP: rust-lang/libs-team#755 Tracking issue: #154046 Related: #152918 Related: #155625 ## Description Moves `std::io::IoSlice` and `std::io::IoSliceMut` into `core::io`. This is required for the `Read` and `Write` traits to be moved into `alloc` and/or `core`, as they contain stable methods which work with IO slices. Similar to #155574, this PR inlines the `std::sys` types required to create an ABI compatible type for the platforms where such compatibility is guaranteed. Additionally, I've moved the relevant tests out of `std::io::tests` into `coretests::io::io_slice`. --- ## Notes * This PR overlaps with #152918, but goes further than moving the IO slice types to `alloc` and instead moves them straight to `core`. Since these types have no interaction with allocation, and doing so will allow `Write` to move to `core::io`, I consider this a better home for these types. * Some discussion around the decision to not use a `core::sys` module can be found [here](#155574 (comment)). * I've renamed `unsupported` to `generic` to better reflect that `IoSlice(Mut)` _is_ supported by all platforms, it just doesn't have a special ABI-compatible type. I don't want to imply that parts of `core` "don't work" depending on the target; `IoSlice(Mut)` works exactly as expected on all targets. * I've made `pub` items within each platform-specific representation `pub(super)` to highlight that everything within `core::io::io_slice` is an internal implementation detail not meant for any other part of the crate to be aware of. * No AI tooling of any kind was used during the creation of this PR.
Move `IoSlice` and `IoSliceMut` to `core::io` ACP: rust-lang/libs-team#755 Tracking issue: #154046 Related: #152918 Related: #155625 ## Description Moves `std::io::IoSlice` and `std::io::IoSliceMut` into `core::io`. This is required for the `Read` and `Write` traits to be moved into `alloc` and/or `core`, as they contain stable methods which work with IO slices. Similar to #155574, this PR inlines the `std::sys` types required to create an ABI compatible type for the platforms where such compatibility is guaranteed. Additionally, I've moved the relevant tests out of `std::io::tests` into `coretests::io::io_slice`. --- ## Notes * This PR overlaps with #152918, but goes further than moving the IO slice types to `alloc` and instead moves them straight to `core`. Since these types have no interaction with allocation, and doing so will allow `Write` to move to `core::io`, I consider this a better home for these types. * Some discussion around the decision to not use a `core::sys` module can be found [here](#155574 (comment)). * I've renamed `unsupported` to `generic` to better reflect that `IoSlice(Mut)` _is_ supported by all platforms, it just doesn't have a special ABI-compatible type. I don't want to imply that parts of `core` "don't work" depending on the target; `IoSlice(Mut)` works exactly as expected on all targets. * I've made `pub` items within each platform-specific representation `pub(super)` to highlight that everything within `core::io::io_slice` is an internal implementation detail not meant for any other part of the crate to be aware of. * No AI tooling of any kind was used during the creation of this PR.
Move `IoSlice` and `IoSliceMut` to `core::io` ACP: rust-lang/libs-team#755 Tracking issue: #154046 Related: #152918 Related: #155625 ## Description Moves `std::io::IoSlice` and `std::io::IoSliceMut` into `core::io`. This is required for the `Read` and `Write` traits to be moved into `alloc` and/or `core`, as they contain stable methods which work with IO slices. Similar to #155574, this PR inlines the `std::sys` types required to create an ABI compatible type for the platforms where such compatibility is guaranteed. Additionally, I've moved the relevant tests out of `std::io::tests` into `coretests::io::io_slice`. --- ## Notes * This PR overlaps with #152918, but goes further than moving the IO slice types to `alloc` and instead moves them straight to `core`. Since these types have no interaction with allocation, and doing so will allow `Write` to move to `core::io`, I consider this a better home for these types. * Some discussion around the decision to not use a `core::sys` module can be found [here](#155574 (comment)). * I've renamed `unsupported` to `generic` to better reflect that `IoSlice(Mut)` _is_ supported by all platforms, it just doesn't have a special ABI-compatible type. I don't want to imply that parts of `core` "don't work" depending on the target; `IoSlice(Mut)` works exactly as expected on all targets. * I've made `pub` items within each platform-specific representation `pub(super)` to highlight that everything within `core::io::io_slice` is an internal implementation detail not meant for any other part of the crate to be aware of. * No AI tooling of any kind was used during the creation of this PR.
Move `IoSlice` and `IoSliceMut` to `core::io` ACP: rust-lang/libs-team#755 Tracking issue: #154046 Related: #152918 Related: #155625 ## Description Moves `std::io::IoSlice` and `std::io::IoSliceMut` into `core::io`. This is required for the `Read` and `Write` traits to be moved into `alloc` and/or `core`, as they contain stable methods which work with IO slices. Similar to #155574, this PR inlines the `std::sys` types required to create an ABI compatible type for the platforms where such compatibility is guaranteed. Additionally, I've moved the relevant tests out of `std::io::tests` into `coretests::io::io_slice`. --- ## Notes * This PR overlaps with #152918, but goes further than moving the IO slice types to `alloc` and instead moves them straight to `core`. Since these types have no interaction with allocation, and doing so will allow `Write` to move to `core::io`, I consider this a better home for these types. * Some discussion around the decision to not use a `core::sys` module can be found [here](#155574 (comment)). * I've renamed `unsupported` to `generic` to better reflect that `IoSlice(Mut)` _is_ supported by all platforms, it just doesn't have a special ABI-compatible type. I don't want to imply that parts of `core` "don't work" depending on the target; `IoSlice(Mut)` works exactly as expected on all targets. * I've made `pub` items within each platform-specific representation `pub(super)` to highlight that everything within `core::io::io_slice` is an internal implementation detail not meant for any other part of the crate to be aware of. * No AI tooling of any kind was used during the creation of this PR.
Move `IoSlice` and `IoSliceMut` to `core::io` ACP: rust-lang/libs-team#755 Tracking issue: rust-lang/rust#154046 Related: rust-lang/rust#152918 Related: rust-lang/rust#155625 ## Description Moves `std::io::IoSlice` and `std::io::IoSliceMut` into `core::io`. This is required for the `Read` and `Write` traits to be moved into `alloc` and/or `core`, as they contain stable methods which work with IO slices. Similar to rust-lang/rust#155574, this PR inlines the `std::sys` types required to create an ABI compatible type for the platforms where such compatibility is guaranteed. Additionally, I've moved the relevant tests out of `std::io::tests` into `coretests::io::io_slice`. --- ## Notes * This PR overlaps with rust-lang/rust#152918, but goes further than moving the IO slice types to `alloc` and instead moves them straight to `core`. Since these types have no interaction with allocation, and doing so will allow `Write` to move to `core::io`, I consider this a better home for these types. * Some discussion around the decision to not use a `core::sys` module can be found [here](rust-lang/rust#155574 (comment)). * I've renamed `unsupported` to `generic` to better reflect that `IoSlice(Mut)` _is_ supported by all platforms, it just doesn't have a special ABI-compatible type. I don't want to imply that parts of `core` "don't work" depending on the target; `IoSlice(Mut)` works exactly as expected on all targets. * I've made `pub` items within each platform-specific representation `pub(super)` to highlight that everything within `core::io::io_slice` is an internal implementation detail not meant for any other part of the crate to be aware of. * No AI tooling of any kind was used during the creation of this PR.
Move `std::io::Error` into `core` ACP: rust-lang/libs-team#755 Tracking issue: #154046 Related: #155574 Related: #152918 ## Description Moves `std::io::Error` into `core`, deferring `Box`-adjacent methods to incoherent implementations in `alloc`, and `RawOsError` methods to `std`. This requires some substantial changes to the internals of `Error`, but none of them are breaking changes or externally visible. Notably, I've replaced usage of `Box` with a wrapper around a pointer and an appropriate drop function. This requires the addition of quite a few lines of unsafe, but is required to work around `Box` only being accessible from `alloc`. Additionally, an atomic pointer to a VTable is used for working with `RawOsError` in `core`, since we cannot know the required implementations without `std`. As mention in [this comment](#155625 (comment)), there may be concern around having a static `AtomicPtr` in `core` for certain users. I've added a configuration option `no_io_statics` which (similar to `no_sync`/etc. in `alloc`) can be used to prevent their inclusion in `core`. When active, the fallback default implementation will always be used. --- ## Notes * This PR adopts the VTable technique from #152918 * This PR builds on my previous PR #155574 * No AI tooling of any kind was used during the creation of this PR.
Move `std::io::Error` into `core` ACP: rust-lang/libs-team#755 Tracking issue: #154046 Related: #155574 Related: #152918 ## Description Moves `std::io::Error` into `core`, deferring `Box`-adjacent methods to incoherent implementations in `alloc`, and `RawOsError` methods to `std`. This requires some substantial changes to the internals of `Error`, but none of them are breaking changes or externally visible. Notably, I've replaced usage of `Box` with a wrapper around a pointer and an appropriate drop function. This requires the addition of quite a few lines of unsafe, but is required to work around `Box` only being accessible from `alloc`. Additionally, an atomic pointer to a VTable is used for working with `RawOsError` in `core`, since we cannot know the required implementations without `std`. As mention in [this comment](#155625 (comment)), there may be concern around having a static `AtomicPtr` in `core` for certain users. I've added a configuration option `no_io_statics` which (similar to `no_sync`/etc. in `alloc`) can be used to prevent their inclusion in `core`. When active, the fallback default implementation will always be used. --- ## Notes * This PR adopts the VTable technique from #152918 * This PR builds on my previous PR #155574 * No AI tooling of any kind was used during the creation of this PR.
Move `std::io::Error` into `core` ACP: rust-lang/libs-team#755 Tracking issue: rust-lang/rust#154046 Related: rust-lang/rust#155574 Related: rust-lang/rust#152918 ## Description Moves `std::io::Error` into `core`, deferring `Box`-adjacent methods to incoherent implementations in `alloc`, and `RawOsError` methods to `std`. This requires some substantial changes to the internals of `Error`, but none of them are breaking changes or externally visible. Notably, I've replaced usage of `Box` with a wrapper around a pointer and an appropriate drop function. This requires the addition of quite a few lines of unsafe, but is required to work around `Box` only being accessible from `alloc`. Additionally, an atomic pointer to a VTable is used for working with `RawOsError` in `core`, since we cannot know the required implementations without `std`. As mention in [this comment](rust-lang/rust#155625 (comment)), there may be concern around having a static `AtomicPtr` in `core` for certain users. I've added a configuration option `no_io_statics` which (similar to `no_sync`/etc. in `alloc`) can be used to prevent their inclusion in `core`. When active, the fallback default implementation will always be used. --- ## Notes * This PR adopts the VTable technique from rust-lang/rust#152918 * This PR builds on my previous PR rust-lang/rust#155574 * No AI tooling of any kind was used during the creation of this PR.
Move `std::io::Error` into `core` ACP: rust-lang/libs-team#755 Tracking issue: rust-lang/rust#154046 Related: rust-lang/rust#155574 Related: rust-lang/rust#152918 ## Description Moves `std::io::Error` into `core`, deferring `Box`-adjacent methods to incoherent implementations in `alloc`, and `RawOsError` methods to `std`. This requires some substantial changes to the internals of `Error`, but none of them are breaking changes or externally visible. Notably, I've replaced usage of `Box` with a wrapper around a pointer and an appropriate drop function. This requires the addition of quite a few lines of unsafe, but is required to work around `Box` only being accessible from `alloc`. Additionally, an atomic pointer to a VTable is used for working with `RawOsError` in `core`, since we cannot know the required implementations without `std`. As mention in [this comment](rust-lang/rust#155625 (comment)), there may be concern around having a static `AtomicPtr` in `core` for certain users. I've added a configuration option `no_io_statics` which (similar to `no_sync`/etc. in `alloc`) can be used to prevent their inclusion in `core`. When active, the fallback default implementation will always be used. --- ## Notes * This PR adopts the VTable technique from rust-lang/rust#152918 * This PR builds on my previous PR rust-lang/rust#155574 * No AI tooling of any kind was used during the creation of this PR.
View all comments
ACP: rust-lang/libs-team#755
Tracking issue: #154046
This is the first (and the hardest) part of a plan to move most of
std::iotoalloc.This PR has three commits:
alloc::ffiwithno_rcandno_syncbecause they where annoying me.io::Errortoalloc.Errorfrom raw OS errors is restricted tostdvia incoherent impls.allocis set at runtime bystdwhen creatingErrorfrom raw OS errors (so no linking required, and not dependent of how Rust code is started). Can be moved to externally implementable one day.IoSliceandIoSliceMutto alloc (required byReadandWrite, exact layout depend on the OS).alloc, but do not link to anything either.I expect the introduction of OS-dependent code to
allocquite controversial, but please note that this PR does not expose anything OS-dependent toallocusers.Also this PR abuses the fact that
tidydoes not warn oncfg_select!inalloclike it does for#[cfg()]😈The rest of
std::iothat can move should do so easily (obviously not things like stdio,IsTerminal, pipes, etc), except maybe forio::copywhich has OS-dependent specialization. If this get merged, I will make a follup-up PR with all all this. In the meantime, a PR containing only the hard parts will avoid perpetual conflicts and rebases.Some questions
Why not
core?Well this could be tried in the future. The main issue is that
Readdirectly usesVec.Why not new
Read/Writetraits?Why about not having them and make the existing one work for everyone?
Previous discussion (far larger than these few links)
Cc #48331
Prior try to move
Errortocore(notalloc): #116685Prior discussion on this specific plan: https://internals.rust-lang.org/t/a-plan-to-move-most-of-std-io-to-alloc/23678/9
Many
#![no_std]crates reimplementingstd::io:embedded-iocore2and its forksciborium-io.