Skip to content

Commit 92114b2

Browse files
committed
Only replace async functions with _unsafeInheritExecutor_ versions
1 parent d80cdb9 commit 92114b2

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
@@ -2105,7 +2105,8 @@ void swift::introduceUnsafeInheritExecutorReplacements(
21052105

21062106
auto isReplaceable = [&](ValueDecl *decl) {
21072107
return isa<FuncDecl>(decl) && inConcurrencyModule(decl->getDeclContext()) &&
2108-
decl->getDeclContext()->isModuleScopeContext();
2108+
decl->getDeclContext()->isModuleScopeContext() &&
2109+
cast<FuncDecl>(decl)->hasAsync();
21092110
};
21102111

21112112
// Make sure at least some of the entries are functions in the _Concurrency
@@ -2160,7 +2161,8 @@ void swift::introduceUnsafeInheritExecutorReplacements(
21602161
return;
21612162

21622163
auto isReplaceable = [&](ValueDecl *decl) {
2163-
return isa<FuncDecl>(decl) && inConcurrencyModule(decl->getDeclContext());
2164+
return isa<FuncDecl>(decl) && inConcurrencyModule(decl->getDeclContext()) &&
2165+
cast<FuncDecl>(decl)->hasAsync();
21642166
};
21652167

21662168
// 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)