-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Concurrency] Correct enqueue behavior in with... functions by adopting nonisolated(nonsending) #80753
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
base: main
Are you sure you want to change the base?
Conversation
de601db to
1303d99
Compare
|
This is blocked by incorrect behavior of the caller execution on a closure rdar://149107104 |
a583630 to
9ea3293
Compare
|
Now blocked on rdar://150017382 |
|
@swift-ci please smoke test |
|
@swift-ci smoke test |
1 similar comment
|
@swift-ci smoke test |
|
Good news, this was now unblocked by #82858 |
25a963e to
be2b2ad
Compare
|
@swift-ci please smoke test |
|
This is almost unblocked, we need to fix throwing nonisolated nonsending (caller isolated) closures to not lose isolation -- rdar://155313349 And there seems to be a problem with noncopyable types and nonisolated nonsending (caller isolated) closures as well; It shows up in Giving it a run to see if anything else |
|
@swift-ci please smoke test |
|
By now this is unlikely to make it into 6.2.0 |
9f1e063 to
0e5a262
Compare
|
@swift-ci please smoke test |
|
Fixing all the ABI tests to follow. |
fcdc60b to
01e0397
Compare
9a2d287 to
3ceae73
Compare
|
@swift-ci please smoke test |
jamieQ
left a comment
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.
some further unsolicited feedback/questions for your consideration :)
| func globalTestFunc(isolation: isolated (any Actor)? = #isolation) async { | ||
| isolation!.assertIsolated("wat in \(#function)!") | ||
| await withTaskCancellationHandler { | ||
| isolation!.assertIsolated("wat in \(#function)!") |
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.
might be good to test that this works without a capture of the isolated parameter too, to ensure it's relying on the nonisolated(nonsending)-ness of the closure, and not the isolated capture logic.
aa0fb44 to
13e6b40
Compare
|
@swift-ci please smoke test |
| #endif | ||
| public func withTaskCancellationHandler<T>( | ||
| @export(implementation) | ||
| public nonisolated(nonsending) func withTaskCancellationHandler<T>( |
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.
another case that occurred to me recently that probably should get the same treatment (though probably is quite a bit less commonly used): withTaskPriorityEscalationHandler
13e6b40 to
6a221b5
Compare
|
@swift-ci please smoke test |
|
Builds timed out heh |
|
A bunch of real failures to follow up on: 17:00:49 Failed Tests (19): Though at least we're past not compiling into runtime issues now, that's progress. |
This drastically lessens the number of unexpected task enqueues and hops that these APIs cause, and therefore improves performance and even correctness in a few cases (like the withContinuation APIs)
76e13aa to
72ac89e
Compare
|
rebased |
|
@swift-ci please smoke test |
|
@ktoso there is a linux failure about attributes: |
|
@swift-ci please smoke test |
|
Need to figure out how to resolve this in swift-testing: |
|
swiftlang/swift-testing#1493 |
|
More new compat issues uncovered |
|
swiftlang/swift-tools-protocols#35 |
The problem is that even with the #isolation parameter the non-Sendable
async closure operation still would potentially hop off the caller
isolation. We introduced this change because the plan was the
non-Sendable closure would run on the isolated parameter's isolation,
but that's not actually the case: an "re-enqueue" can still happens in those cases.
Instead, we can use the nonisolated(nonsending) on the function and closure,
in order to guarantee there is no hop between those at all, and
developers can trust that adding this cancellation handler will not
cause any unexpected isolation changes and hops.
The API was always documented to not hop as we execute the operation,
so this brings the correct and expected behavior.
This corrects the following APIs:
as well as task group's next() and related ones...
This gets down the "re-enqueue" count of those methods by far, and makes all these more reliable and predictable.
resolves rdar://140110775
resolves rdar://162192512