Skip to content

Commit ee0e69b

Browse files
authored
Merge pull request #35959 from DougGregor/enable-concurrent-functions
2 parents f5e32aa + 184b150 commit ee0e69b

File tree

7 files changed

+40
-14
lines changed

7 files changed

+40
-14
lines changed

include/swift/AST/Attr.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(async, Async,
602602
106)
603603

604604
SIMPLE_DECL_ATTR(concurrent, Concurrent,
605-
OnFunc | OnConstructor | OnAccessor | ConcurrencyOnly |
606-
ABIStableToAdd | ABIStableToRemove |
605+
OnFunc | OnConstructor | OnAccessor |
606+
ABIBreakingToAdd | ABIBreakingToRemove |
607607
APIBreakingToAdd | APIBreakingToRemove,
608608
107)
609609

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

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,17 +2339,7 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
23392339
}
23402340
}
23412341

2342-
bool concurrent = false;
2343-
if (attrs.has(TAK_concurrent)) {
2344-
if (getASTContext().LangOpts.EnableExperimentalConcurrency) {
2345-
concurrent = true;
2346-
} else {
2347-
diagnoseInvalid(repr, attrs.getLoc(TAK_concurrent),
2348-
diag::attr_requires_concurrency,
2349-
TypeAttributes::getAttrName(TAK_concurrent),
2350-
false);
2351-
}
2352-
}
2342+
bool concurrent = attrs.has(TAK_concurrent);
23532343

23542344
ty = resolveASTFunctionType(fnRepr, options, rep, /*noescape=*/false,
23552345
concurrent, parsedClangFunctionType,

test/IDE/complete_decl_attribute.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct MyStruct {}
7171
// KEYWORD2-NEXT: Keyword/None: derivative[#Func Attribute#]; name=derivative
7272
// KEYWORD2-NEXT: Keyword/None: transpose[#Func Attribute#]; name=transpose
7373
// KEYWORD2-NEXT: Keyword/None: noDerivative[#Func Attribute#]; name=noDerivative
74+
// KEYWORD2-NEXT: Keyword/None: concurrent[#Func Attribute#]; name=concurrent
7475
// KEYWORD2-NOT: Keyword
7576
// KEYWORD2: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
7677
// KEYWORD2: End completions
@@ -190,6 +191,7 @@ struct _S {
190191
// ON_METHOD-DAG: Keyword/None: differentiable[#Func Attribute#]; name=differentiable
191192
// ON_METHOD-DAG: Keyword/None: derivative[#Func Attribute#]; name=derivative
192193
// ON_METHOD-DAG: Keyword/None: transpose[#Func Attribute#]; name=transpose
194+
// ON_METHOD-DAG: Keyword/None: concurrent[#Func Attribute#]; name=concurrent
193195
// ON_METHOD-DAG: Keyword/None: noDerivative[#Func Attribute#]; name=noDerivative
194196
// ON_METHOD-NOT: Keyword
195197
// ON_METHOD: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
@@ -251,6 +253,7 @@ struct _S {
251253
// ON_MEMBER_LAST-DAG: Keyword/None: derivative[#Declaration Attribute#]; name=derivative
252254
// ON_MEMBER_LAST-DAG: Keyword/None: transpose[#Declaration Attribute#]; name=transpose
253255
// ON_MEMBER_LAST-DAG: Keyword/None: noDerivative[#Declaration Attribute#]; name=noDerivative
256+
// ON_MEMBER_LAST-DAG: Keyword/None: concurrent[#Declaration Attribute#]; name=concurrent
254257
// ON_MEMBER_LAST-NOT: Keyword
255258
// ON_MEMBER_LAST: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
256259
// ON_MEMBER_LAST-NOT: Decl[PrecedenceGroup]
@@ -300,6 +303,7 @@ func dummy2() {}
300303
// KEYWORD_LAST-NEXT: Keyword/None: derivative[#Declaration Attribute#]; name=derivative
301304
// KEYWORD_LAST-NEXT: Keyword/None: transpose[#Declaration Attribute#]; name=transpose
302305
// KEYWORD_LAST-NEXT: Keyword/None: noDerivative[#Declaration Attribute#]; name=noDerivative
306+
// KEYWORD_LAST-NEXT: Keyword/None: concurrent[#Declaration Attribute#]; name=concurrent
303307
// KEYWORD_LAST-NOT: Keyword
304308
// KEYWORD_LAST: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
305309
// KEYWORD_LAST: End completions

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

test/attr/attr_concurrent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck -verify %s -enable-experimental-concurrency -enable-experimental-flow-sensitive-concurrent-captures
1+
// RUN: %target-swift-frontend -typecheck -verify %s -enable-experimental-flow-sensitive-concurrent-captures
22
// REQUIRES: concurrency
33

44
// Concurrent attribute on a function type.

0 commit comments

Comments
 (0)