Skip to content

Commit ab4c584

Browse files
committed
[Concurrency] Centralize rejection of concurrency-only attributes.
Reject concurrency-only attributes in the parser if the experimental concurrency mode is not enabled.
1 parent cb64295 commit ab4c584

File tree

8 files changed

+17
-21
lines changed

8 files changed

+17
-21
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ SIMPLE_DECL_ATTR(noDerivative, NoDerivative,
562562
100)
563563

564564
SIMPLE_DECL_ATTR(asyncHandler, AsyncHandler,
565-
OnFunc | UserInaccessible |
565+
OnFunc | ConcurrencyOnly |
566566
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
567567
101)
568568

include/swift/AST/DiagnosticsParse.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,11 @@ ERROR(pound_available_package_description_not_allowed, none,
17481748
ERROR(availability_query_repeated_platform, none,
17491749
"version for '%0' already specified", (StringRef))
17501750

1751+
ERROR(attr_requires_concurrency,none,
1752+
"'%0' %select{attribute|modifier}1 is only valid when experimental "
1753+
"concurrency is enabled",
1754+
(StringRef, bool))
1755+
17511756
//------------------------------------------------------------------------------
17521757
// MARK: syntax parsing diagnostics
17531758
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4107,9 +4107,6 @@ NOTE(protocol_witness_async_conflict,none,
41074107
ERROR(async_autoclosure_nonasync_function,none,
41084108
"'async' autoclosure parameter in a non-'async' function", ())
41094109

4110-
ERROR(asynchandler_attr_requires_concurrency,none,
4111-
"'@asyncHandler' is only valid when experimental concurrency is enabled",
4112-
())
41134110
ERROR(asynchandler_non_func,none,
41144111
"'@asyncHandler' can only be applied to functions",
41154112
())
@@ -4142,8 +4139,6 @@ ERROR(satisfy_async_objc,none,
41424139
ERROR(async_objc_dynamic_self,none,
41434140
"asynchronous method returning 'Self' cannot be '@objc'", ())
41444141

4145-
ERROR(actor_without_concurrency,none,
4146-
"'actor' classes require experimental concurrency support", ())
41474142
ERROR(actor_with_nonactor_superclass,none,
41484143
"actor class cannot inherit from non-actor class %0", (DeclName))
41494144

lib/Parse/ParseDecl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,15 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
13941394
DiscardAttribute = true;
13951395
}
13961396

1397+
// If this attribute is only permitted when concurrency is enabled, reject it.
1398+
if (DeclAttribute::isConcurrencyOnly(DK) &&
1399+
!shouldParseExperimentalConcurrency()) {
1400+
diagnose(
1401+
Loc, diag::attr_requires_concurrency, AttrName,
1402+
DeclAttribute::isDeclModifier(DK));
1403+
DiscardAttribute = true;
1404+
}
1405+
13971406
if (Context.LangOpts.Target.isOSBinFormatCOFF()) {
13981407
if (DK == DAK_WeakLinked) {
13991408
diagnose(Loc, diag::attr_unsupported_on_target, AttrName,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
259259
void visitTransposeAttr(TransposeAttr *attr);
260260

261261
void visitAsyncHandlerAttr(AsyncHandlerAttr *attr) {
262-
if (!Ctx.LangOpts.EnableExperimentalConcurrency) {
263-
diagnoseAndRemoveAttr(attr, diag::asynchandler_attr_requires_concurrency);
264-
return;
265-
}
266-
267262
auto func = dyn_cast<FuncDecl>(D);
268263
if (!func) {
269264
diagnoseAndRemoveAttr(attr, diag::asynchandler_non_func);

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ bool IsActorRequest::evaluate(
161161
Evaluator &evaluator, ClassDecl *classDecl) const {
162162
// If concurrency is not enabled, we don't have actors.
163163
auto actorAttr = classDecl->getAttrs().getAttribute<ActorAttr>();
164-
if (!classDecl->getASTContext().LangOpts.EnableExperimentalConcurrency) {
165-
if (actorAttr) {
166-
classDecl->diagnose(diag::actor_without_concurrency)
167-
.highlight(actorAttr->getRange());
168-
}
169-
170-
return false;
171-
}
172164

173165
// If there is a superclass, we can infer actor-ness from it.
174166
if (auto superclassDecl = classDecl->getSuperclassDecl()) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// RUN: %target-swift-frontend -typecheck -verify %s
22

33
@asyncHandler func asyncHandler1() { }
4-
// expected-error@-1{{'@asyncHandler' is only valid when experimental concurrency is enabled}}
4+
// expected-error@-1{{'asyncHandler' attribute is only valid when experimental concurrency is enabled}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
actor class C { } // expected-error{{'actor' classes require experimental concurrency support}}
3+
actor class C { } // expected-error{{'actor' attribute is only valid when experimental concurrency is enabled}}
44

0 commit comments

Comments
 (0)