Skip to content

Commit 88729b9

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
1 parent a890c60 commit 88729b9

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
@@ -196,6 +196,8 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(NoncopyableGenerics, 427, "Noncopyable generics")
196196
SUPPRESSIBLE_LANGUAGE_FEATURE(ConformanceSuppression, 426, "Suppressible inferred conformances")
197197
SUPPRESSIBLE_LANGUAGE_FEATURE(BitwiseCopyable2, 426, "BitwiseCopyable feature")
198198
LANGUAGE_FEATURE(BodyMacros, 415, "Function body macros")
199+
LANGUAGE_FEATURE(TransferringArgsAndResults, 430, "Transferring args and results")
200+
SUPPRESSIBLE_LANGUAGE_FEATURE(SendingArgsAndResults, 430, "Sending arg and results")
199201

200202
// Swift 6
201203
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -214,8 +216,6 @@ UPCOMING_FEATURE(DynamicActorIsolation, 423, 6)
214216
UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
215217
UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
216218
UPCOMING_FEATURE(BorrowingSwitch, 432, 6)
217-
UPCOMING_FEATURE(TransferringArgsAndResults, 430, 6)
218-
SUPPRESSIBLE_UPCOMING_FEATURE(SendingArgsAndResults, 430, 6)
219219

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

lib/AST/Builtins.cpp

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

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

lib/DriverTool/sil_opt_main.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -576,17 +576,6 @@ struct SILOptOptions {
576576
"disable-region-based-isolation-with-strict-concurrency",
577577
llvm::cl::init(false));
578578

579-
llvm::cl::opt<bool>
580-
DisableTransferringArgsAndResultsWithRegionBasedIsolation = llvm::cl::opt<
581-
bool>(
582-
"disable-transferring-args-and-results-with-region-based-isolation",
583-
llvm::cl::init(false));
584-
585-
llvm::cl::opt<bool> DisableSendingArgsAndResultsWithRegionBasedIsolation =
586-
llvm::cl::opt<bool>(
587-
"disable-sending-args-and-results-with-region-based-isolation",
588-
llvm::cl::init(false));
589-
590579
llvm::cl::opt<std::string> SwiftVersionString = llvm::cl::opt<std::string>(
591580
"swift-version",
592581
llvm::cl::desc(
@@ -805,19 +794,6 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
805794
Invocation.getLangOptions().enableFeature(Feature::RegionBasedIsolation);
806795
}
807796

808-
if (Invocation.getLangOptions().hasFeature(Feature::RegionBasedIsolation)) {
809-
if (!options.DisableTransferringArgsAndResultsWithRegionBasedIsolation)
810-
Invocation.getLangOptions().enableFeature(
811-
Feature::TransferringArgsAndResults);
812-
if (!options.DisableSendingArgsAndResultsWithRegionBasedIsolation)
813-
Invocation.getLangOptions().enableFeature(Feature::SendingArgsAndResults);
814-
}
815-
816-
if (Invocation.getLangOptions().hasFeature(
817-
Feature::TransferringArgsAndResults)) {
818-
Invocation.getLangOptions().enableFeature(Feature::SendingArgsAndResults);
819-
}
820-
821797
Invocation.getDiagnosticOptions().VerifyMode =
822798
options.VerifyMode ? DiagnosticOptions::Verify
823799
: DiagnosticOptions::NoVerify;

lib/Frontend/CompilerInvocation.cpp

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

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

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5464,14 +5464,9 @@ ParserStatus Parser::ParsedTypeAttributeList::slowParse(Parser &P) {
54645464
// Perform an extra check for transferring. Since it is a specifier, we use
54655465
// the actual parsing logic below.
54665466
if (Tok.isContextualKeyword("transferring")) {
5467-
if (!P.Context.LangOpts.hasFeature(Feature::TransferringArgsAndResults)) {
5468-
P.diagnose(Tok, diag::requires_experimental_feature, Tok.getRawText(),
5469-
false, getFeatureName(Feature::TransferringArgsAndResults));
5470-
} else {
5471-
// Now that we have sending, warn users to convert 'transferring' to
5472-
// 'sendable'.
5473-
P.diagnose(Tok, diag::transferring_is_now_sendable);
5474-
}
5467+
// Now that we have sending, warn users to convert 'transferring' to
5468+
// 'sendable'.
5469+
P.diagnose(Tok, diag::transferring_is_now_sendable);
54755470

54765471
// Do not allow for transferring to be parsed after a specifier has been
54775472
// parsed.

lib/Parse/ParsePattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
263263
continue;
264264
}
265265

266-
if (Context.LangOpts.hasFeature(Feature::TransferringArgsAndResults) &&
266+
if (Context.LangOpts.hasFeature(Feature::SendingArgsAndResults) &&
267267
Tok.isContextualKeyword("transferring")) {
268268
diagnose(Tok, diag::parameter_specifier_as_attr_disallowed, Tok.getText())
269269
.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
@@ -9043,8 +9043,11 @@ static Expr *wrapAsyncLetInitializer(
90439043
bool throws = TypeChecker::canThrow(cs.getASTContext(), initializer)
90449044
.has_value();
90459045
bool hasSendingeResult = isSendingInitializer(initializer);
9046-
bool isSendable = !cs.getASTContext().LangOpts.hasFeature(
9047-
Feature::TransferringArgsAndResults);
9046+
bool isSendable =
9047+
!cs.getASTContext().LangOpts.hasFeature(Feature::RegionBasedIsolation);
9048+
assert((isSendable || cs.getASTContext().LangOpts.hasFeature(
9049+
Feature::SendingArgsAndResults)) &&
9050+
"Region Isolation should imply SendingArgsAndResults");
90489051
auto extInfo = ASTExtInfoBuilder()
90499052
.withAsync()
90509053
.withThrows(throws, /*FIXME:*/ Type())

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,9 +2541,13 @@ namespace {
25412541
if (patternBindingDecl && patternBindingDecl->isAsyncLet()) {
25422542
// Defer diagnosing checking of non-Sendable types that are passed
25432543
// into async let to SIL level region based isolation if we have
2544-
// transferring and region based isolation enabled.
2545-
if (!ctx.LangOpts.hasFeature(Feature::RegionBasedIsolation) ||
2546-
!ctx.LangOpts.hasFeature(Feature::TransferringArgsAndResults)) {
2544+
// region based isolation enabled.
2545+
//
2546+
// We purposely do not do this for SendingArgsAndResults since that
2547+
// just triggers the actual ability to represent
2548+
// 'sending'. RegionBasedIsolation is what determines if we get the
2549+
// differing semantics.
2550+
if (!ctx.LangOpts.hasFeature(Feature::RegionBasedIsolation)) {
25472551
diagnoseNonSendableTypes(
25482552
type, getDeclContext(),
25492553
/*inDerivedConformance*/Type(), capture.getLoc(),
@@ -3606,8 +3610,11 @@ namespace {
36063610

36073611
// Check for sendability of the result type if we do not have a
36083612
// transferring result.
3609-
if ((!ctx.LangOpts.hasFeature(Feature::TransferringArgsAndResults) ||
3613+
if ((!ctx.LangOpts.hasFeature(Feature::RegionBasedIsolation) ||
36103614
!fnType->hasSendingResult())) {
3615+
assert(ctx.LangOpts.hasFeature(Feature::SendingArgsAndResults) &&
3616+
"SendingArgsAndResults should be enabled if RegionIsolation is "
3617+
"enabled");
36113618
// See if we are a autoclosure that has a direct callee that has the
36123619
// same non-transferred type value returned. If so, do not emit an
36133620
// 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)