Skip to content

Commit 7dc29a7

Browse files
committed
[Concurrency] Apply @MainActor to main dispatch queue operations without
considering `Sendable`.
1 parent 6ff708e commit 7dc29a7

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
@@ -6050,6 +6050,7 @@ swift::isDispatchQueueOperationName(StringRef name) {
60506050
.Case("sync", DispatchQueueOperation::Normal)
60516051
.Case("async", DispatchQueueOperation::Sendable)
60526052
.Case("asyncAndWait", DispatchQueueOperation::Normal)
6053+
.Case("asyncUnsafe", DispatchQueueOperation::Normal)
60536054
.Case("asyncAfter", DispatchQueueOperation::Sendable)
60546055
.Case("concurrentPerform", DispatchQueueOperation::Sendable)
60556056
.Default(std::nullopt);
@@ -6147,8 +6148,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
61476148
// @MainActor occurs in concurrency contexts or those where we have an
61486149
// application.
61496150
bool addSendable = knownUnsafeParams && inConcurrencyContext;
6150-
bool addMainActor =
6151-
(isMainDispatchQueue && knownUnsafeParams) &&
6151+
bool addMainActor = isMainDispatchQueue &&
61526152
(inConcurrencyContext || numApplies >= 1);
61536153
Type newParamType = param.getPlainType();
61546154
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)