Skip to content

Commit 75433a3

Browse files
committed
[sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes the semantic language effects to be keyed on RegionBasedIsolation instead. ---- The key thing that makes this all work is that I changed all of the "special" semantic changes originally triggered on *ArgsAndResults to now be triggered based on RegionBasedIsolation being enabled. This makes a lot of sense since we want these semantic changes specifically to be combined with the checkers that RegionBasedIsolation turns on. As a result, even though this causes these two features to always be enabled, we just parse it but we do not use it for anything semantically. rdar://128961672 (cherry picked from commit 88729b9) Conflicts: include/swift/Basic/Features.def lib/DriverTool/sil_opt_main.cpp
1 parent cab61e8 commit 75433a3

36 files changed

+69
-119
lines changed

include/swift/Basic/Features.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(ConformanceSuppression, 426, "Suppressible inferre
197197
SUPPRESSIBLE_LANGUAGE_FEATURE(BitwiseCopyable2, 426, "BitwiseCopyable feature")
198198
LANGUAGE_FEATURE(BodyMacros, 415, "Function body macros")
199199
LANGUAGE_FEATURE(BuiltinAddressOfRawLayout, 0, "Builtin.addressOfRawLayout")
200+
LANGUAGE_FEATURE(TransferringArgsAndResults, 430, "Transferring args and results")
201+
SUPPRESSIBLE_LANGUAGE_FEATURE(SendingArgsAndResults, 430, "Sending arg and results")
200202

201203
// Swift 6
202204
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -215,8 +217,6 @@ UPCOMING_FEATURE(DynamicActorIsolation, 423, 6)
215217
UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
216218
UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
217219
UPCOMING_FEATURE(BorrowingSwitch, 432, 6)
218-
UPCOMING_FEATURE(TransferringArgsAndResults, 430, 6)
219-
SUPPRESSIBLE_UPCOMING_FEATURE(SendingArgsAndResults, 430, 6)
220220

221221
// Swift 7
222222
UPCOMING_FEATURE(ExistentialAny, 335, 7)

lib/AST/Builtins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ static ValueDecl *getStartAsyncLet(ASTContext &ctx, Identifier id) {
16541654
// a case want to thunk and not emit an error. So in such a case, we always
16551655
// make this builtin take a sending result.
16561656
bool hasSendingResult =
1657-
ctx.LangOpts.hasFeature(Feature::TransferringArgsAndResults);
1657+
ctx.LangOpts.hasFeature(Feature::RegionBasedIsolation);
16581658

16591659
// operation async function pointer: () async throws -> transferring T
16601660
auto extInfo = ASTExtInfoBuilder()

lib/DriverTool/sil_opt_main.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -539,17 +539,6 @@ struct SILOptOptions {
539539
llvm::cl::opt<bool>(
540540
"disable-region-based-isolation-with-strict-concurrency",
541541
llvm::cl::init(false));
542-
543-
llvm::cl::opt<bool>
544-
DisableTransferringArgsAndResultsWithRegionBasedIsolation = llvm::cl::opt<
545-
bool>(
546-
"disable-transferring-args-and-results-with-region-based-isolation",
547-
llvm::cl::init(false));
548-
549-
llvm::cl::opt<bool> DisableSendingArgsAndResultsWithRegionBasedIsolation =
550-
llvm::cl::opt<bool>(
551-
"disable-sending-args-and-results-with-region-based-isolation",
552-
llvm::cl::init(false));
553542
};
554543

555544
/// Regular expression corresponding to the value given in one of the
@@ -723,19 +712,6 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
723712
}
724713
}
725714

726-
if (Invocation.getLangOptions().hasFeature(Feature::RegionBasedIsolation)) {
727-
if (!options.DisableTransferringArgsAndResultsWithRegionBasedIsolation)
728-
Invocation.getLangOptions().enableFeature(
729-
Feature::TransferringArgsAndResults);
730-
if (!options.DisableSendingArgsAndResultsWithRegionBasedIsolation)
731-
Invocation.getLangOptions().enableFeature(Feature::SendingArgsAndResults);
732-
}
733-
734-
if (Invocation.getLangOptions().hasFeature(
735-
Feature::TransferringArgsAndResults)) {
736-
Invocation.getLangOptions().enableFeature(Feature::SendingArgsAndResults);
737-
}
738-
739715
Invocation.getDiagnosticOptions().VerifyMode =
740716
options.VerifyMode ? DiagnosticOptions::Verify : DiagnosticOptions::NoVerify;
741717

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,34 +1109,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11091109
Opts.enableFeature(Feature::RegionBasedIsolation);
11101110
}
11111111

1112-
// Enable TransferringArgsAndResults/SendingArgsAndResults whenever
1113-
// RegionIsolation is enabled.
1114-
if (Opts.hasFeature(Feature::RegionBasedIsolation)) {
1115-
bool enableTransferringArgsAndResults = true;
1116-
bool enableSendingArgsAndResults = true;
1117-
#ifndef NDEBUG
1118-
enableTransferringArgsAndResults = !Args.hasArg(
1119-
OPT_disable_transferring_args_and_results_with_region_isolation);
1120-
enableSendingArgsAndResults = !Args.hasArg(
1121-
OPT_disable_sending_args_and_results_with_region_isolation);
1122-
#endif
1123-
if (enableTransferringArgsAndResults)
1124-
Opts.enableFeature(Feature::TransferringArgsAndResults);
1125-
if (enableSendingArgsAndResults)
1126-
Opts.enableFeature(Feature::SendingArgsAndResults);
1127-
}
1128-
1129-
// Enable SendingArgsAndResults whenever TransferringArgsAndResults is
1130-
// enabled.
1131-
//
1132-
// The reason that we are doing this is we want to phase out transferring in
1133-
// favor of sending and this ensures that if we output 'sending' instead of
1134-
// 'transferring' (for instance when emitting suppressed APIs), we know that
1135-
// the compiler will be able to handle sending as well.
1136-
if (Opts.hasFeature(Feature::TransferringArgsAndResults)) {
1137-
Opts.enableFeature(Feature::SendingArgsAndResults);
1138-
}
1139-
11401112
Opts.WarnImplicitOverrides =
11411113
Args.hasArg(OPT_warn_implicit_overrides);
11421114

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5454,14 +5454,9 @@ ParserStatus Parser::ParsedTypeAttributeList::slowParse(Parser &P) {
54545454
// Perform an extra check for transferring. Since it is a specifier, we use
54555455
// the actual parsing logic below.
54565456
if (Tok.isContextualKeyword("transferring")) {
5457-
if (!P.Context.LangOpts.hasFeature(Feature::TransferringArgsAndResults)) {
5458-
P.diagnose(Tok, diag::requires_experimental_feature, Tok.getRawText(),
5459-
false, getFeatureName(Feature::TransferringArgsAndResults));
5460-
} else {
5461-
// Now that we have sending, warn users to convert 'transferring' to
5462-
// 'sendable'.
5463-
P.diagnose(Tok, diag::transferring_is_now_sendable);
5464-
}
5457+
// Now that we have sending, warn users to convert 'transferring' to
5458+
// 'sendable'.
5459+
P.diagnose(Tok, diag::transferring_is_now_sendable);
54655460

54665461
// Do not allow for transferring to be parsed after a specifier has been
54675462
// parsed.

lib/Parse/ParsePattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
280280
continue;
281281
}
282282

283-
if (Context.LangOpts.hasFeature(Feature::TransferringArgsAndResults) &&
283+
if (Context.LangOpts.hasFeature(Feature::SendingArgsAndResults) &&
284284
Tok.isContextualKeyword("transferring")) {
285285
diagnose(Tok, diag::parameter_specifier_as_attr_disallowed, Tok.getText())
286286
.warnUntilSwiftVersion(6);

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ SILDeclRef::SILDeclRef(SILDeclRef::Loc baseLoc, bool asForeign,
171171
loc = ACE;
172172
kind = Kind::Func;
173173
if (ACE->getASTContext().LangOpts.hasFeature(
174-
Feature::TransferringArgsAndResults)) {
174+
Feature::RegionBasedIsolation)) {
175+
assert(ACE->getASTContext().LangOpts.hasFeature(
176+
Feature::SendingArgsAndResults) &&
177+
"Sending args and results should always be enabled");
175178
if (auto *autoClosure = dyn_cast<AutoClosureExpr>(ACE)) {
176179
isAsyncLetClosure =
177180
autoClosure->getThunkKind() == AutoClosureExpr::Kind::AsyncLet;

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9002,8 +9002,11 @@ static Expr *wrapAsyncLetInitializer(
90029002
bool throws = TypeChecker::canThrow(cs.getASTContext(), initializer)
90039003
.has_value();
90049004
bool hasSendingeResult = isSendingInitializer(initializer);
9005-
bool isSendable = !cs.getASTContext().LangOpts.hasFeature(
9006-
Feature::TransferringArgsAndResults);
9005+
bool isSendable =
9006+
!cs.getASTContext().LangOpts.hasFeature(Feature::RegionBasedIsolation);
9007+
assert((isSendable || cs.getASTContext().LangOpts.hasFeature(
9008+
Feature::SendingArgsAndResults)) &&
9009+
"Region Isolation should imply SendingArgsAndResults");
90079010
auto extInfo = ASTExtInfoBuilder()
90089011
.withAsync()
90099012
.withThrows(throws, /*FIXME:*/ Type())

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,9 +2537,13 @@ namespace {
25372537
if (patternBindingDecl && patternBindingDecl->isAsyncLet()) {
25382538
// Defer diagnosing checking of non-Sendable types that are passed
25392539
// into async let to SIL level region based isolation if we have
2540-
// transferring and region based isolation enabled.
2541-
if (!ctx.LangOpts.hasFeature(Feature::RegionBasedIsolation) ||
2542-
!ctx.LangOpts.hasFeature(Feature::TransferringArgsAndResults)) {
2540+
// region based isolation enabled.
2541+
//
2542+
// We purposely do not do this for SendingArgsAndResults since that
2543+
// just triggers the actual ability to represent
2544+
// 'sending'. RegionBasedIsolation is what determines if we get the
2545+
// differing semantics.
2546+
if (!ctx.LangOpts.hasFeature(Feature::RegionBasedIsolation)) {
25432547
diagnoseNonSendableTypes(
25442548
type, getDeclContext(),
25452549
/*inDerivedConformance*/Type(), capture.getLoc(),
@@ -3600,8 +3604,11 @@ namespace {
36003604

36013605
// Check for sendability of the result type if we do not have a
36023606
// transferring result.
3603-
if ((!ctx.LangOpts.hasFeature(Feature::TransferringArgsAndResults) ||
3607+
if ((!ctx.LangOpts.hasFeature(Feature::RegionBasedIsolation) ||
36043608
!fnType->hasSendingResult())) {
3609+
assert(ctx.LangOpts.hasFeature(Feature::SendingArgsAndResults) &&
3610+
"SendingArgsAndResults should be enabled if RegionIsolation is "
3611+
"enabled");
36053612
// See if we are a autoclosure that has a direct callee that has the
36063613
// same non-transferred type value returned. If so, do not emit an
36073614
// error... we are going to emit an error on the call expr and do not

test/ClangImporter/sending_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -swift-version 6 -disable-availability-checking -emit-sil -o /dev/null %s -parse-as-library -enable-experimental-feature TransferringArgsAndResults -verify -import-objc-header %S/Inputs/transferring.h
1+
// RUN: %target-swift-frontend -swift-version 6 -disable-availability-checking -emit-sil -o /dev/null %s -parse-as-library -verify -import-objc-header %S/Inputs/transferring.h
22

33
// REQUIRES: concurrency
44
// REQUIRES: asserts

0 commit comments

Comments
 (0)