-
Notifications
You must be signed in to change notification settings - Fork 648
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
Fix EventLoopFuture
and EventLoopPromise
under strict concurrency checking
#2654
Open
FranzBusch
wants to merge
15
commits into
apple:main
Choose a base branch
from
FranzBusch:fb-event-loop-future-sendable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Commits on Feb 19, 2024
-
Fix
EventLoopFuture
andEventLoopPromise
under strict concurrency…… checking # Motivation We need to tackle the remaining strict concurrency checking related `Sendable` warnings in NIO. The first place to start is making sure that `EventLoopFuture` and `EventLoopPromise` are properly annotated. # Modification In a previous apple#2496, @weissi changed the `@unchecked Sendable` conformances of `EventLoopFuture/Promise` to be conditional on the sendability of the generic `Value` type. After having looked at all the APIs on the future and promise types as well as reading the latest Concurrency evolution proposals, specifically the [Region based Isolation](https://github.com/apple/swift-evolution/blob/main/proposals/0414-region-based-isolation.md), I came to the conclusion that the previous `@unchecked Sendable` annotations were correct. The reasoning for this is: 1. An `EventLoopPromise` and `EventLoopFuture` pair are tied to a specific `EventLoop` 2. An `EventLoop` represents an isolation region and values tied to its isolation are not allowed to be shared outside of it unless they are disconnected from the region 3. The `value` used to succeed a promise often come from outside the isolation domain of the `EventLoop` hence they must be transferred into the promise. 4. The isolation region of the event loop is enforced through `@Sendable` annotations on all closures that receive the value in some kind of transformation e.g. `map()` 5. Any method on `EventLoopFuture` that combines itself with another future must require `Sendable` of the other futures `Value` since we cannot statically enforce that futures are bound to the same event loop i.e. to the same isolation domain Due to the above rules, this PR adds back the `@unchecked Sendable` conformances to both types. Furthermore, this PR revisits every single method on `EventLoopPromise/Future` and adds missing `Sendable` and `@Sendable` annotation where necessary to uphold the above rules. A few important things to call out: - Since `transferring` is currently not available this PR requires a `Sendable` conformance for some methods on `EventLoopPromise/Future` that should rather take a `transffering` argument - To enable the common case where a value from the same event loop is used to succeed a promise I added two additional methods that take a `eventLoopBoundResult` and enforce dynamic isolation checking. We might have to do this for more methods once we adopt those changes in other targets/packages. # Result After this PR has landed our lowest level building block should be inline with what the rest of the language enforces in Concurrency. The `EventLoopFuture.swift` produces no more warnings under strict concurrency checking on the latest 5.10 snapshots.
Configuration menu - View commit details
-
Copy full SHA for e0a87fc - Browse repository at this point
Copy the full SHA e0a87fcView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5d20621 - Browse repository at this point
Copy the full SHA 5d20621View commit details
Commits on Mar 4, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 3ae701c - Browse repository at this point
Copy the full SHA 3ae701cView commit details
Commits on Oct 9, 2024
-
Configuration menu - View commit details
-
Copy full SHA for aeb2634 - Browse repository at this point
Copy the full SHA aeb2634View commit details -
Configuration menu - View commit details
-
Copy full SHA for 469e475 - Browse repository at this point
Copy the full SHA 469e475View commit details -
Configuration menu - View commit details
-
Copy full SHA for 426e453 - Browse repository at this point
Copy the full SHA 426e453View commit details
Commits on Oct 16, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 7f83110 - Browse repository at this point
Copy the full SHA 7f83110View commit details -
Configuration menu - View commit details
-
Copy full SHA for b191621 - Browse repository at this point
Copy the full SHA b191621View commit details -
Configuration menu - View commit details
-
Copy full SHA for b9b9ea6 - Browse repository at this point
Copy the full SHA b9b9ea6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 77da82c - Browse repository at this point
Copy the full SHA 77da82cView commit details
Commits on Oct 17, 2024
-
Configuration menu - View commit details
-
Copy full SHA for bfe84d2 - Browse repository at this point
Copy the full SHA bfe84d2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 75ad4d7 - Browse repository at this point
Copy the full SHA 75ad4d7View commit details -
Configuration menu - View commit details
-
Copy full SHA for 28029bf - Browse repository at this point
Copy the full SHA 28029bfView commit details -
Configuration menu - View commit details
-
Copy full SHA for dacc452 - Browse repository at this point
Copy the full SHA dacc452View commit details -
Configuration menu - View commit details
-
Copy full SHA for c41d45d - Browse repository at this point
Copy the full SHA c41d45dView commit details
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.