-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve core::task::TaskObj #51532
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
Merged
Merged
Improve core::task::TaskObj #51532
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why remove this? We don't particularly need it, but it's totally sound AFAICT, and it will give the correct behavior were we to add more non-mutating methods in the future (in addition to the current
Debug::fmt
).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 can put it in again, but is it safe?
trait UnsafeTask: Send + 'static
<-- noSync
Uh oh!
There was an error while loading. Please reload this page.
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.
According to the comment above
TaskObj
is supposed to be approximately equivalent toBox<Future<Output = ()> + Send>
which has also noSync
bound.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.
UnsafeTask
only has&mut
methods-- those are only used for mutating the inner task. Since no&self
methods are called, it's triviallySync
.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.
TaskObj
is just a workaround forBox<Future<Output = ()> + Send + 'static>
which throws an error, but if it worked, it wouldn't be beSync
. I think the workaround should match what we really want but can't get as much as possible. IMO it feels wrong to implementSync
. I agree with your reasoning why it can be considered safe, though.Here's the error for
Box<Future<Output = ()> + Send + 'static>
:Also a playground example that shows
Box<Future<Output = ()> + Send + 'static>
is notSync
I believe the more conservative approach would be to leave it out.
Uh oh!
There was an error while loading. Please reload this page.
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.
That is certainly the more conservative approach :).
I'm fine with leaving it out if you feel strongly about it-- I don't think it really matters significantly either way. Currently the only
&self
method isDebug::fmt
, which is thread-safe, but if we someday decide to add a thread-locked&self
method you're right that we wouldn't be able to do so.Uh oh!
There was an error while loading. Please reload this page.
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.
No strong feelings, because, as you say, it's safe. My recommendation is, however, to leave it out.
For adding
impl Sync
: We can because it's safe.Against adding
impl Sync
: More conservative, we don't need it, and it approximatesBox<Future...>
which is!Sync
more closely=> My conclusion: Don't add it