Skip to content

Commit 010068f

Browse files
authored
Merge pull request swiftlang#36596 from DougGregor/banish-async-handler
Banish @asyncHandler to a hidden flag.
2 parents 29f3e34 + c76dac7 commit 010068f

24 files changed

+40
-20
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,6 +4314,8 @@ ERROR(asynchandler_noescape_closure_parameter,none,
43144314
ERROR(asynchandler_mutating,none,
43154315
"'@asyncHandler' function cannot be 'mutating'",
43164316
())
4317+
ERROR(asynchandler_removed,none,
4318+
"'@asyncHandler' has been removed from the language", ())
43174319

43184320
ERROR(objc_ambiguous_async_convention,none,
43194321
"%0 overrides or implements protocol requirements for Objective-C "

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ namespace swift {
250250
/// Enable experimental concurrency model.
251251
bool EnableExperimentalConcurrency = false;
252252

253+
/// Enable experimental asyncHandler support.
254+
bool EnableExperimentalAsyncHandler = false;
255+
253256
/// Enable experimental flow-sensitive concurrent captures.
254257
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;
255258

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ def enable_experimental_concurrency :
229229
Flag<["-"], "enable-experimental-concurrency">,
230230
HelpText<"Enable experimental concurrency model">;
231231

232+
def enable_experimental_async_handler :
233+
Flag<["-"], "enable-experimental-async-handler">,
234+
HelpText<"Enable experimental @asyncHandler feature">;
235+
232236
def enable_experimental_flow_sensitive_concurrent_captures :
233237
Flag<["-"], "enable-experimental-flow-sensitive-concurrent-captures">,
234238
HelpText<"Enable flow-sensitive concurrent captures">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
389389
Args.hasFlag(OPT_enable_infer_public_concurrent_value,
390390
OPT_disable_infer_public_concurrent_value,
391391
false);
392+
Opts.EnableExperimentalAsyncHandler |=
393+
Args.hasArg(OPT_enable_experimental_async_handler);
392394
Opts.EnableExperimentalFlowSensitiveConcurrentCaptures |=
393395
Args.hasArg(OPT_enable_experimental_flow_sensitive_concurrent_captures);
394396

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5389,6 +5389,11 @@ void AttributeChecker::visitTransposeAttr(TransposeAttr *attr) {
53895389
}
53905390

53915391
void AttributeChecker::visitAsyncHandlerAttr(AsyncHandlerAttr *attr) {
5392+
if (!Ctx.LangOpts.EnableExperimentalAsyncHandler) {
5393+
diagnoseAndRemoveAttr(attr, diag::asynchandler_removed);
5394+
return;
5395+
}
5396+
53925397
auto func = dyn_cast<FuncDecl>(D);
53935398
if (!func) {
53945399
diagnoseAndRemoveAttr(attr, diag::asynchandler_non_func);

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ void swift::addAsyncNotes(AbstractFunctionDecl const* func) {
158158

159159
bool IsAsyncHandlerRequest::evaluate(
160160
Evaluator &evaluator, FuncDecl *func) const {
161+
// Turn off @asyncHandler when not specifically enabled.
162+
if (!func->getASTContext().LangOpts.EnableExperimentalAsyncHandler) {
163+
return false;
164+
}
165+
161166
// Check whether the attribute was explicitly specified.
162167
if (auto attr = func->getAttrs().getAttribute<AsyncHandlerAttr>()) {
163168
// Check for well-formedness.
@@ -231,6 +236,11 @@ bool IsAsyncHandlerRequest::evaluate(
231236

232237
bool CanBeAsyncHandlerRequest::evaluate(
233238
Evaluator &evaluator, FuncDecl *func) const {
239+
// Turn off @asyncHandler when not specifically enabled.
240+
if (!func->getASTContext().LangOpts.EnableExperimentalAsyncHandler) {
241+
return false;
242+
}
243+
234244
return !checkAsyncHandler(func, /*diagnose=*/false);
235245
}
236246

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules -enable-experimental-concurrency %s -verify
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules -enable-experimental-concurrency -enable-experimental-async-handler %s -verify
22

33
// REQUIRES: objc_interop
44
// REQUIRES: concurrency

test/Concurrency/actor_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -warn-concurrency
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -enable-experimental-async-handler -warn-concurrency
22
// REQUIRES: concurrency
33

44
let immutableGlobal: String = "hello"

test/Concurrency/actor_isolation_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -enable-experimental-async-handler
22
// REQUIRES: concurrency
33
// REQUIRES: objc_interop
44

test/Concurrency/async_throwing.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func throwingTask() async throws -> String {
4444
return "ok!"
4545
}
4646

47-
// expected-note@+2 7 {{add '@asyncHandler' to function 'syncTest()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
4847
// expected-note@+1 7 {{add 'async' to function 'syncTest()' to make it asynchronous}} {{16-16= async}}
4948
func syncTest() {
5049
let _ = invoke(fn: normalTask) // expected-error{{'async' call in a function that does not support concurrency}}

0 commit comments

Comments
 (0)