Skip to content

Commit 260f477

Browse files
authored
Merge pull request #72565 from hborla/6.0-dispatch-main-actor
[6.0][Concurrency] Apply `@MainActor` to main dispatch queue operations without considering `Sendable`.
2 parents ac47357 + ec5acfc commit 260f477

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6058,6 +6058,7 @@ swift::isDispatchQueueOperationName(StringRef name) {
60586058
.Case("sync", DispatchQueueOperation::Normal)
60596059
.Case("async", DispatchQueueOperation::Sendable)
60606060
.Case("asyncAndWait", DispatchQueueOperation::Normal)
6061+
.Case("asyncUnsafe", DispatchQueueOperation::Normal)
60616062
.Case("asyncAfter", DispatchQueueOperation::Sendable)
60626063
.Case("concurrentPerform", DispatchQueueOperation::Sendable)
60636064
.Default(std::nullopt);
@@ -6155,8 +6156,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
61556156
// @MainActor occurs in concurrency contexts or those where we have an
61566157
// application.
61576158
bool addSendable = knownUnsafeParams && inConcurrencyContext;
6158-
bool addMainActor =
6159-
(isMainDispatchQueue && knownUnsafeParams) &&
6159+
bool addMainActor = isMainDispatchQueue &&
61606160
(inConcurrencyContext || numApplies >= 1);
61616161
Type newParamType = param.getPlainType();
61626162
if (addSendable || addMainActor) {

test/Concurrency/dispatch_inference.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ func testMe() {
1717
DispatchQueue.main.async {
1818
onlyOnMainActor() // okay, due to inference of @MainActor-ness
1919
}
20+
21+
DispatchQueue.main.sync {
22+
onlyOnMainActor()
23+
}
2024
}
2125

2226
func testUnsafeSendableInMainAsync() async {

0 commit comments

Comments
 (0)