-
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
impl Try for ExitStatus #93565
impl Try for ExitStatus #93565
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
(Marked this needs-fcp because |
☔ The latest upstream changes (presumably #94514) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #94546) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #96904) made this pull request unmergeable. Please resolve the merge conflicts. |
Currently just sys/unix is implemented.
Signed-off-by: matt rice <ratmice@gmail.com>
We added I'm going to r? @yaahc since you maybe felt otherwise in #84908 (comment) -- it seems like that would've been an unresolved question rather than a Step in my mind. Maybe that's what you meant :) |
It's been quite a while so I don't remember exactly what I was thinking at the time but your instinct to prefer only having one form over having both seems valid. Out of the two I think I'd prefer the version more closely integrated with |
FWIW, this is merely marked as draft, because I hadn't intiially implemented windows support, But that is I think the only reason it is still a draft, so I could mark it as ready for review if that helps, |
FWIW, I think I feel differently -- I don't think implementing Try on types that aren't in the return type is a good idea; a magic conversion from ExitStatus to Result feels iffy to me. This is particularly true since e.g. https://doc.rust-lang.org/nightly/std/process/struct.Command.html#method.status already returns
I think it's worth settling the question of whether we want to pursue this path before you do a bunch of work over time updating this PR (rebasing, implementing Windows, etc.). |
It is an interesting example, I suppose it strikes me the myriad of ways that the It at the very least makes me consider what (if any) the equivalent of Edit: I tried messing around with hacks to see if I could get anything flattenesque, best I could come up with 🤷 |
Hmmm. I don't have the same experience of finding it confusing or magical. ExitStatus is a well established analog to That said I do see some advantages to forcing it to go into a |
FWIW, if my method has a signature like But if the Try conversion would involve converting from |
What I meant by this is that it is representing the equivalent constructs from os process error reporting. Status codes and signals are the error reporting mechanism for processes and represent both the control flow (success / fail) and the explanation of the failure. I feel like it's fairly intuitive to imagine |
I think we sort of agree on that point -- ExitStatus does resemble a Result in some ways at the process level. ExitStatusError is a pretty poor error in terms of being able to interpret it (really wants some amount of context attached), but the same is true of io::Error, if to a slightly lesser extent. I'm somewhat ambivalent now on which I prefer -- in general, I think I still lean towards exit_ok, but without any meaningful justification. There's a slight feeling in my mind that some explicit declaration of 0 = Ok, other = Err is valuable, since not all programs respect that convention -- for example, if running I was going to nominate this for libs-api to make a decision here but I'll leave whether to do that in your hands as the assigned reviewer - the alternative being to fcp merge this, presumably, implicitly closing/removing exit_ok + ExitStatusError? |
self.0.try_branch() | ||
} | ||
|
||
fn from_output((): ()) -> Self { |
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.
If I follow the docs on Try correctly, I think this isn't quite right.
Try::from_output(x).branch() --> ControlFlow::Continue(x)
to me implies that type Output = ExitStatus
would be correct here.
I think the current implementation is forcing a synthesis of ExitStatus from (), whereas you actually "want" to just pass along the ExitStatus you're taking in branch
.
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.
This is definitely the least straightforward part of this patch, and definitely deserves scrutiny.
I believed though that it does meet the Try
laws, because branch() --> ControlFlow::Continue(x) iff self.code() == 0
.
And I think type Output = ExitStatus
seems weird to me, because ExitStatusError
is a subset of ExitStatus
such that the values intersect, so I felt it was weird in the way that a Result<ExitStatus, ExitStatusError>
would be strange, since it has values which would be valid in both the Ok
, and the Err
branches.
Anyhow, that is the justification for why I did it this way at least.
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.
I also noticed this in the documentation for the Residual
associated type:
This represents the possible values of the Self type which are not represented by the Output type.
https://doc.rust-lang.org/stable/std/ops/trait.Try.html#associatedtype.Residual
Which type Output = ExitStatus
would run afoul of.
Edit: I think if we want to change the type Output
here away from unit, we should try and introduce a new type to complement ExitStatusError
. Such as ExitStatusSuccess
or some bikeshed to that extent.
Edit 2: This would also would allow exit_status????
because success would be identity which implements Try
.
I may be misunderstanding things, but |
Whether And it seemed like defining a new type specifically for this, that it would end up being an ad-hoc implementation of |
☔ The latest upstream changes (presumably #101077) made this pull request unmergeable. Please resolve the merge conflicts. |
Reassigning yaahc's reviews as she has stepped down from the review rotation. r? rust-lang/libs-api |
The libs-api-nominated label seems to have not been properly applied, so this was never discussed in a meeting. FWIW I agree with @Mark-Simulacrum here: I'm hesitant to add more |
Alright, well I figure I should summarize the open questions probably:
|
I have just proposed this RFC rust-lang/rfcs#3362 for new methods on |
We discussed this in last week's libs-api meeting. We agreed with the comments above, that it doesn't seem like a great idea to implement Try for this type. The end result can get confusing, in part because of types like We prefer something more explicit, like the currently unstable ExitStatus::exit_ok(). We should find a better name for that method, though. (It starts with |
Alright, I'm going to close this then and leave a comment in #54889 that it should be closed too |
I figured I could take a stab at issue #54889,
Currently just sys/unix is implemented,
More work needs to be done with testing and platforms which I don't have access to.
But given that i've not done much coding in libstd, and this is a bit roundabout with
imp::process
callingcrate::process
,in a call from
crate::process
callingimp::
...Along with the
from_output
where we need to materialize an imp::ExitStatus out of()
, I figured it'd be good to get some feedback early if possible.Thanks