-
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
WIP: use trait object for io::Error representation #82343
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I doubt that a perf run would be particularly revealing - it both is unlikely to see many errors, but also doesn't really use I/O all that much. I'm not sure how to best evaluate these changes, and unfortunately don't have a lot of time myself to investigate here - let me try switching to r? @KodrAus, maybe Ashley has some more time :) |
Thanks for the PR @Plecra! So the thing you're trying to avoid here is the double box needed to stash a custom error type? Have you looked at how I think in a scheme like that we'd break the |
I'm actually more interested in avoiding allocations altogether (right now, fn main() -> io::Result<()> {
if bad {
// creates a single use type that implements `IoError` with these values
// As a ZST, no allocations have to be made to return it.
return io::err!(Other; "*crickets*");
// Naturally, there are many variations to this - any `repr(int)` enum could be packed
// into the data half of the pointer. One could declare a `NotFound` type that
// held a `&'static ThinStr` and always returned `ErrorKind::NotFound`, etc...
}
Ok(())
} We'd need a new API to do this, something similar to
|
Can I create a ZST |
Oh... not sure how I managed to do that. Can anybody reopen this? |
@Plecra Ping from triage, what's the current status of this? |
An actual implementation of this is waiting on a few questions around the state of I'm tempted to simply close this and revisit it when the position of |
☔ The latest upstream changes (presumably #84310) made this pull request unmergeable. Please resolve the merge conflicts. |
triage:
@Plecra I'm closing this for as inactive, please feel free to reopen when things get cleared up. |
This is a little experiment in the hopes that
io::Error
could box some user types without allocating.I want to do a perf run on these changes, but there are a couple things to fix up first:
i32::MIN
as a sentinel value for os errors at the moment, which is a bit of a shame. This shouldn't ever be returned from libc or windows APIs, but there was nothing stopping users from passing it to the API before.(ptr::NonNull<VTable>, *mut ())
to allow zero.as_error_*
calls be much of a performance hit?repr(u8)
ErrorKind
without a stability problem?