Skip to content

Commit e8375e1

Browse files
committed
Define a feature for @Concurrent functions.
1 parent 4eae2ed commit e8375e1

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ LANGUAGE_FEATURE(StaticAssert, 0, "#assert", langOpts.EnableExperimentalStaticAs
3838
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
3939
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
4040
LANGUAGE_FEATURE(Actors, 0, "actors", langOpts.EnableExperimentalConcurrency)
41+
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)
4142

4243
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,32 @@ static bool usesFeatureActors(Decl *decl) {
25092509
return false;
25102510
}
25112511

2512+
static bool usesFeatureConcurrentFunctions(Decl *decl) {
2513+
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2514+
if (func->isConcurrent())
2515+
return true;
2516+
}
2517+
2518+
// Check for concurrent functions in the types of declarations.
2519+
if (auto value = dyn_cast<ValueDecl>(decl)) {
2520+
if (Type type = value->getInterfaceType()) {
2521+
bool hasConcurrent = type.findIf([](Type type) {
2522+
if (auto fnType = type->getAs<AnyFunctionType>()) {
2523+
if (fnType->isConcurrent())
2524+
return true;
2525+
}
2526+
2527+
return false;
2528+
});
2529+
2530+
if (hasConcurrent)
2531+
return true;
2532+
}
2533+
}
2534+
2535+
return false;
2536+
}
2537+
25122538
/// Determine the set of "new" features used on a given declaration.
25132539
///
25142540
/// Note: right now, all features we check for are "new". At some point, we'll

test/ModuleInterface/features.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ extension OldSchool: UnsafeConcurrentValue { }
7272
// CHECK-NEXT: #endif
7373
public func runSomethingSomewhere(body: () async -> Void) { }
7474

75+
// CHECK: #if compiler(>=5.3) && $ConcurrentFunctions
76+
// CHECK-NEXT: func runSomethingConcurrently(body: @concurrent () ->
77+
// CHECK-NEXT: #endif
78+
public func runSomethingConcurrently(body: @concurrent () -> Void) { }
79+
7580
// CHECK: #if compiler(>=5.3) && $Actors
7681
// CHECK-NEXT: func stage
7782
// CHECK-NEXT: #endif

0 commit comments

Comments
 (0)