-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[draft] Store the path in io::Error without extra allocations. #86826
Conversation
cc @yaahc |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@CryZe Since you reacted with a 👎, I'd be curious to hear your thoughts on this. |
This comment has been minimized.
This comment has been minimized.
We need to allocate for doing a syscall on a path anyway, so this just keeps that allocation around in the io::Error if the syscall fails.
This comment has been minimized.
This comment has been minimized.
@CryZe I will note that mara has only added the path info to the |
Yeah I guess that may be fine then. |
☔ The latest upstream changes (presumably #87329) made this pull request unmergeable. Please resolve the merge conflicts. |
It's possible that in the future, std could be optimized to avoid |
Since it was brought up to me, #87869 and this aren't really incompatible beyond it needing to allocate in the 64 bit case (on 32 bit targets it would be almost identical). (IMO that's probably fine, since this is in the error case, and that having a smaller io::Error optimizes the success path more than allocating in the error case would pessimize anything) |
When making the OsPathBuf allocation, can't you just leave some room for the error kind field in there, even if it's not needed in the success case? (With 64 bit, maybe half of the string length usize unless we assume path names can be too long for u32 length field?) |
Can we store both of them, like, allocated contiguously? |
@sunfishcode The link in your comment above is now broken, at a guess because it wasn't a permalink that included the git commit. Did you mean this: https://github.com/bytecodealliance/rustix/blob/e1ec8abf106e976bc05ce45d308602728e84ccf3/src/path/arg.rs#L933-L953 |
Closing this as inactive and was still a draft. |
This stores the path of the file/directory in io::Error, without doing any allocations and without increasing the size of io::Error.
We need to allocate for doing a syscall on a path anyway, so this just keeps that allocation around in the io::Error if the syscall fails.
This implements it only on unix. But it can work similarly on other platforms as well.
It does not store the path for the rename and (sym)link operations, as they involve two paths, and you can't really tell which of the two paths caused the error.
This only shows the path in the Debug implementation of io::Error. It's not clear what else we should do with it. Putting it in Display will make many programs show the path twice, and have less control over the output format. Adding a .path() accessor to io::Error is also not great, because it'll have to be a Option, and won't be accessible through the Error triat.