-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Custom main and global executors #2654
Open
al45tair
wants to merge
6
commits into
swiftlang:main
Choose a base branch
from
al45tair:custom-executors
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.
Open
Conversation
This file contains 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
Use `any TaskExecutor` instead of `any Executor` for `Task.defaultExecutor`. Rename `ExecutorJobKind` to `ExecutorJob.Kind`. Add `EventableExecutor`; replace `SerialRunLoopExecutor` with `MainExecutor`, then make `MainActor` and `PlatformMainExecutor` use the new protocol.
08df4e3
to
d176b25
Compare
The previous iteration would have required us to make calling the allocation methods a fatal error, and would have meant executors had to check explicitly for the `.task` job kind before using them. Instead, if we add a new `LocalAllocator` type, we can have an `allocator` property that is `nil` if the job doesn't support allocation, and a valid `LocalAllocator` otherwise.
Since the previous pitch, I've added `Clock`-based `enqueue` methods and made a few other changes, notably to the way you actually set custome executors for your program.
Remove `EventableExecutor`; we can come back to that later. Update documentation for `currentExecutor` and add `preferredExecutor` and `currentSchedulableExecutor`. Move the clock-based enqueuing to a separate `SchedulableExecutor` protocol, and provide an efficient way to get it. This means we don't need the `supportsScheduling` property. Back `ClockTraits` with `UInt32`.
We should use typed throws, which will make this work better for Embedded Swift.
FranzBusch
reviewed
Mar 24, 2025
/// 1. The custom executor associated with an `Actor` on which we are | ||
/// currently running, or | ||
/// 2. The preferred executor for the currently executing `Task`, or | ||
/// 3. The task executor for the current thread |
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 think this should be "for the current task" instead of "current thread"
/// Executors can implement this method explicitly to avoid the use of | ||
/// a potentially expensive runtime cast. | ||
@available(SwiftStdlib 6.2, *) | ||
var asSchedulable: AsSchedulable? { get } |
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.
Suggested change
var asSchedulable: AsSchedulable? { get } | |
var asSchedulableExecutor: SchedulableExecutor? { get } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add write up of custom executor proposals. There are still some concerns surrounding integration with Dispatch that need working through.