-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
YieldSafe auto trait #2890
YieldSafe auto trait #2890
Conversation
I think there are several problems that are not addressed in the RFC. Firstly, the example given "don't lock a mutex in an async function" is different from the prior art in C# "don't await whilst a mutex is held/in a critical section" and C# has got it more correct. Locking a mutex is fine in async context as long as you don't yield whilst it's held, and there is a lot of existing code which does this. Secondly, the RFC doesn't explain how this attribute would be propagated across function calls. Async code often calls non-async code, and that non-async code may call a function with the I believe a better option would be to talk about what types of value should be allowed to exist on the stack in an async function. We could imagine a new default marker trait |
You are right - C# got it more correct, although I thought a more defensive approach was acceptable. A marker trait might be a better solution - then the compiler should emit a warning/error when encountering |
async fn foo<T>(value: T) {
// potentially valid code, since value doesn't need to cross .await if it doesn't implement Drop (recursively)
bar().await
} I don’t know if it’s just a lack of creativity on my side but I can’t think of a setting that provides a non-YieldSafe type (that is non-YieldSafe for a reason) that doesn’t implement Drop (recursively). |
This reminds me of |
Me neither, but it still would be possible to create one in practice.
That seems like a good idea (assuming understanding the consequences, that is). I will add it to the RFC. |
Potentially silly question, but is there really no relationship between |
Not really, since you can have a single-threaded runtime, which doesn't require futures to be neither |
Okay, after thinking about it it makes a bit more sense, so, I'll share the way I thought about it in case it helps anyone else:
Taking this in mind, I think a better name might be |
@clarfon you’re not quite there yet with your intuition. What you might have missed is the strong relationship between continuation of rather long and somewhat off-topic answerHence in particular it would not make sense to evaluate for `Sync` and `Send` separately whether they have something to do with `async`.
But the real meaning of these traits is (admittedly from a quite formalist point of view): They are Soundness of an API in rust means that without using Back to the topic of For I’m with you on the point that this could be even more explicit that TLDR (and a conclusion): Also now I’m wondering, @krojew, what do you think about a |
At the moment, I'm not sure |
Are there any more questions about this RFC? |
Thanks for this RFC. The async foundations working group is working on a We'd like to consolidate work on this area into a single proposal, so we're inclined to close this in favor of the proposal from the WG. If there are important differences between the two proposals, it would be great for people to hash that out on the async foundations WG's proposal and possibly modify that proposal as needed. @rfcbot fcp close |
Team member @withoutboats has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@withoutboats I do not understand how to interact in a WG discussion, and given my experience trying to do so I won't have enough energy to try again. Would it be possible for you (or anyone else) to raise at the new right place the fact that auto traits as suggested here, which have no arguments listed against on the WG document, also would naturally solve the question that is currently marked as “unresolved” there? I wouldn't have to add beyond this one point. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Co-authored-by: Chan Kwan Yin <[email protected]>
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC is now closed. |
Rendered