Skip to content

Commit 43eb31e

Browse files
[Concurrency] Guard use of async calling convention.
Certain targets don't support the async calling convention, so we first add the feature check to avoid breaking the codegen/runtime while doing gradual rollout for different targets.
1 parent e6aee25 commit 43eb31e

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ if(SWIFT_PROFDATA_FILE AND EXISTS ${SWIFT_PROFDATA_FILE})
196196
add_definitions("-fprofile-instr-use=${SWIFT_PROFDATA_FILE}")
197197
endif()
198198

199+
option(USE_SWIFT_ASYNC_LOWERING
200+
"Indicates if Swiftc should use async-specific lowering for async
201+
functions if it is supported for the target. The runtime also checks
202+
this setting before using async-specific attributes. This only applies
203+
to the async calling convention and not to the async context attribute."
204+
FALSE)
205+
199206
#
200207
# User-configurable Swift Standard Library specific options.
201208
#

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/Basic/Sanitizers.h"
2424
#include "swift/Basic/OptionSet.h"
2525
#include "swift/Basic/OptimizationMode.h"
26+
#include "swift/Config.h"
2627
#include "clang/Basic/PointerAuthOptions.h"
2728
// FIXME: This include is just for llvm::SanitizerCoverageOptions. We should
2829
// split the header upstream so we don't include so much.
@@ -337,6 +338,10 @@ class IRGenOptions {
337338
/// Pointer authentication.
338339
PointerAuthOptions PointerAuth;
339340

341+
/// Use async-specific lowering for async functions if it is supported for
342+
/// the target.
343+
bool UseAsyncLowering = USE_SWIFT_ASYNC_LOWERING;
344+
340345
/// The different modes for dumping IRGen type info.
341346
enum class TypeInfoDumpFilter {
342347
All,

include/swift/Config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88

99
#cmakedefine HAVE_PROC_PID_RUSAGE 1
1010

11+
#cmakedefine01 USE_SWIFT_ASYNC_LOWERING
12+
1113
#endif // SWIFT_CONFIG_H

include/swift/Runtime/CMakeConfig.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
#cmakedefine01 SWIFT_BNI_OS_BUILD
88
#cmakedefine01 SWIFT_BNI_XCODE_BUILD
99

10+
#cmakedefine01 USE_SWIFT_ASYNC_LOWERING
11+
1012
#endif

include/swift/Runtime/Config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL
184184

185185
// SWIFT_CC(swiftasync) is the Swift async calling convention.
186186
// We assume that it supports mandatory tail call elimination.
187-
#if __has_attribute(swiftasynccall)
187+
#if __has_feature(swiftasynccc) && USE_SWIFT_ASYNC_LOWERING && \
188+
__has_attribute(swiftasynccall)
188189
#define SWIFT_CC_swiftasync __attribute__((swiftasynccall))
189190
#else
190191
#define SWIFT_CC_swiftasync SWIFT_CC_swift

0 commit comments

Comments
 (0)