Skip to content

Commit 3c48cdd

Browse files
committed
Only replace async functions with _unsafeInheritExecutor_ versions
1 parent f37b0a4 commit 3c48cdd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,8 @@ void swift::introduceUnsafeInheritExecutorReplacements(
21082108

21092109
auto isReplaceable = [&](ValueDecl *decl) {
21102110
return isa<FuncDecl>(decl) && inConcurrencyModule(decl->getDeclContext()) &&
2111-
decl->getDeclContext()->isModuleScopeContext();
2111+
decl->getDeclContext()->isModuleScopeContext() &&
2112+
cast<FuncDecl>(decl)->hasAsync();
21122113
};
21132114

21142115
// Make sure at least some of the entries are functions in the _Concurrency
@@ -2163,7 +2164,8 @@ void swift::introduceUnsafeInheritExecutorReplacements(
21632164
return;
21642165

21652166
auto isReplaceable = [&](ValueDecl *decl) {
2166-
return isa<FuncDecl>(decl) && inConcurrencyModule(decl->getDeclContext());
2167+
return isa<FuncDecl>(decl) && inConcurrencyModule(decl->getDeclContext()) &&
2168+
cast<FuncDecl>(decl)->hasAsync();
21672169
};
21682170

21692171
// Make sure at least some of the entries are functions in the _Concurrency

test/Concurrency/unsafe_inherit_executor.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ func unsafeCallerAvoidsNewLoop(clock: some Clock) async throws {
117117
} onCancel: {
118118
}
119119

120-
await TL.$string.withValue("hello") {
120+
TL.$string.withValue("hello") {
121+
print(TL.string)
122+
}
123+
124+
try await TL.$string.withValue("hello") {
125+
try await Task.sleep(nanoseconds: 500)
121126
print(TL.string)
122127
}
123128

0 commit comments

Comments
 (0)