[🍒 5.9] Fix main executor check in startOnMainActor #65272
Merged
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.
Cherry-picking #65271
Explanation: Some API's don't set the current executor resulting in the current executor containing a
nullptr
identity. This caused the MainExecutor check inswift_task_startOnMainActorImpl
to fail, when we were running on the main thread and executing off of the main dispatch queue.swift_task_isCurrentExecutor
contains additional logic to properly handle this case, checking that we're running off of the main dispatch queue and that we're running on the main thread. Also adding @discardableResult since we can discard the results from this SPI, like withTask.detached
.Scope: The
swift_task_startOnMainActorImpl
is only used by theTask.startOnMainActor
SPI, so this change only impacts the one SPI function. It's replacing a piece of logic with a function that has been in the runtime for two years now, and is in use in other places in the concurrency runtime for this purpose.Risk: Low. The SPI was added earlier this release so changing this shouldn't break existing code. Additionally, it's SPI.
rdar://108221645
rdar://108222007