Skip to content

Commit efb0e1e

Browse files
authored
Merge pull request #72507 from hborla/dispatch-main-actor
[Concurrency] Apply `@MainActor` to main dispatch queue operations without considering `Sendable`.
2 parents 89cd626 + 7dc29a7 commit efb0e1e

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
@@ -6072,6 +6072,7 @@ swift::isDispatchQueueOperationName(StringRef name) {
60726072
.Case("sync", DispatchQueueOperation::Normal)
60736073
.Case("async", DispatchQueueOperation::Sendable)
60746074
.Case("asyncAndWait", DispatchQueueOperation::Normal)
6075+
.Case("asyncUnsafe", DispatchQueueOperation::Normal)
60756076
.Case("asyncAfter", DispatchQueueOperation::Sendable)
60766077
.Case("concurrentPerform", DispatchQueueOperation::Sendable)
60776078
.Default(std::nullopt);
@@ -6169,8 +6170,7 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
61696170
// @MainActor occurs in concurrency contexts or those where we have an
61706171
// application.
61716172
bool addSendable = knownUnsafeParams && inConcurrencyContext;
6172-
bool addMainActor =
6173-
(isMainDispatchQueue && knownUnsafeParams) &&
6173+
bool addMainActor = isMainDispatchQueue &&
61746174
(inConcurrencyContext || numApplies >= 1);
61756175
Type newParamType = param.getPlainType();
61766176
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)