Skip to content

Commit 1ec8c43

Browse files
committed
[sending] Begin parsing 'sending' while still accepting 'transferring'.
A few things: 1. Internally except for in the parser and the clang importer, we only represent 'sending'. This means that it will be easy to remove 'transferring' once enough time has passed. 2. I included a warning that suggested to the user to change 'transferring' -> 'sending'. 3. I duplicated the parsing diagnostics for 'sending' so both will still get different sets of diagnostics for parsing issues... but anywhere below parsing, I have just changed 'transferring' to 'sending' since transferring isn't represented at those lower levels. 4. Since SendingArgsAndResults is always enabled when TransferringArgsAndResults is enabled (NOTE not vis-a-versa), we know that we can always parse sending. So we import "transferring" as "sending". This means that even if one marks a function with "transferring", the compiler will guard it behind a SendingArgsAndResults -D flag and in the imported header print out sending. rdar://128216574 (cherry picked from commit b780ff6)
1 parent 5678526 commit 1ec8c43

File tree

58 files changed

+947
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+947
-237
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,7 @@ enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : size_t {
15521552
BridgedAttributedTypeSpecifierIsolated,
15531553
BridgedAttributedTypeSpecifierResultDependsOn,
15541554
BridgedAttributedTypeSpecifierTransferring,
1555+
BridgedAttributedTypeSpecifierSending,
15551556
};
15561557

15571558
SWIFT_NAME("BridgedUnqualifiedIdentTypeRepr.createParsed(_:loc:name:)")

include/swift/AST/Builtins.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(GetCurrentAsyncTask, "getCurrentAsyncTask", "
884884
BUILTIN_MISC_OPERATION_WITH_SILGEN(CancelAsyncTask, "cancelAsyncTask", "", Special)
885885

886886
/// startAsyncLet()<T>: (
887-
/// __owned @escaping () async throws -> transferring T
887+
/// __owned @escaping () async throws -> sending T
888888
/// ) -> Builtin.RawPointer
889889
///
890890
/// DEPRECATED. startAsyncLetWithLocalBuffer is used instead.
@@ -894,7 +894,7 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(CancelAsyncTask, "cancelAsyncTask", "", Speci
894894
BUILTIN_MISC_OPERATION(StartAsyncLet, "startAsyncLet", "", Special)
895895

896896
/// startAsyncLetWithLocalBuffer()<T>: (
897-
/// __owned @escaping () async throws -> transferring T,
897+
/// __owned @escaping () async throws -> sending T,
898898
/// _ resultBuf: Builtin.RawPointer
899899
/// ) -> Builtin.RawPointer
900900
///

include/swift/AST/DiagnosticsParse.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,16 @@ ERROR(transferring_after_parameter_specifier,none,
22072207
"'transferring' must be placed before specifier '%0'", (StringRef))
22082208
ERROR(transferring_repeated,none,
22092209
"parameter may have at most one 'transferring' specifier", ())
2210+
ERROR(sending_before_parameter_specifier,none,
2211+
"'sending' must be placed after specifier '%0'", (StringRef))
2212+
ERROR(sending_repeated,none,
2213+
"parameter may have at most one 'sending' specifier", ())
2214+
ERROR(sending_and_transferring_used_together,none,
2215+
"'transferring' and 'sending' may not be used together", ())
2216+
WARNING(transferring_is_now_sendable,none,
2217+
"'transferring' has been renamed to 'sending' and the 'transferring' spelling will be removed shortly",
2218+
())
2219+
22102220

22112221
#define UNDEFINE_DIAGNOSTIC_MACROS
22122222
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7933,17 +7933,23 @@ ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
79337933
"Escapable",
79347934
())
79357935

7936-
//===----------------------------------------------------------------------===//
7937-
// MARK: Transferring
7938-
//===----------------------------------------------------------------------===//
7939-
7940-
ERROR(transferring_unsupported_param_specifier, none,
7941-
"'%0' cannot be applied to a 'transferring' parameter", (StringRef))
7936+
//===----------------------------------------------------------------------===//
7937+
// MARK: Transferring
7938+
//===----------------------------------------------------------------------===//
79427939

7943-
ERROR(transferring_only_on_parameters_and_results, none,
7944-
"'transferring' may only be used on parameters and results", ())
7945-
ERROR(transferring_cannot_be_applied_to_tuple_elt, none,
7946-
"'transferring' cannot be applied to tuple elements", ())
7940+
ERROR(transferring_unsupported_param_specifier, none,
7941+
"'%0' cannot be applied to a 'transferring' parameter", (StringRef))
7942+
7943+
ERROR(transferring_only_on_parameters_and_results, none,
7944+
"'transferring' may only be used on parameters and results", ())
7945+
ERROR(transferring_cannot_be_applied_to_tuple_elt, none,
7946+
"'transferring' cannot be applied to tuple elements", ())
7947+
ERROR(sending_unsupported_param_specifier, none,
7948+
"'%0' cannot be applied to a 'sending' parameter", (StringRef))
7949+
ERROR(sending_only_on_parameters_and_results, none,
7950+
"'sending' may only be used on parameters and results", ())
7951+
ERROR(sending_cannot_be_applied_to_tuple_elt, none,
7952+
"'sending' cannot be applied to tuple elements", ())
79477953

79487954
#define UNDEFINE_DIAGNOSTIC_MACROS
79497955
#include "DefineDiagnosticMacros.h"

include/swift/AST/PrintOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ struct PrintOptions {
382382
/// Suppress 'isolated' and '#isolation' on isolated parameters with optional type.
383383
bool SuppressOptionalIsolatedParams = false;
384384

385-
/// Suppress 'transferring' on arguments and results.
386-
bool SuppressTransferringArgsAndResults = false;
385+
/// Suppress 'sending' on arguments and results.
386+
bool SuppressSendingArgsAndResults = false;
387387

388388
/// Suppress Noncopyable generics.
389389
bool SuppressNoncopyableGenerics = false;

include/swift/AST/TypeRepr.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,8 @@ class SpecifierTypeRepr : public TypeRepr {
11161116
T->getKind() == TypeReprKind::CompileTimeConst ||
11171117
T->getKind() == TypeReprKind::ResultDependsOn ||
11181118
T->getKind() == TypeReprKind::LifetimeDependentReturn ||
1119-
T->getKind() == TypeReprKind::Transferring;
1119+
T->getKind() == TypeReprKind::Transferring ||
1120+
T->getKind() == TypeReprKind::Sending;
11201121
}
11211122
static bool classof(const SpecifierTypeRepr *T) { return true; }
11221123

@@ -1217,6 +1218,21 @@ class TransferringTypeRepr : public SpecifierTypeRepr {
12171218
static bool classof(const TransferringTypeRepr *T) { return true; }
12181219
};
12191220

1221+
/// A sending type.
1222+
/// \code
1223+
/// x : sending Int
1224+
/// \endcode
1225+
class SendingTypeRepr : public SpecifierTypeRepr {
1226+
public:
1227+
SendingTypeRepr(TypeRepr *Base, SourceLoc Loc)
1228+
: SpecifierTypeRepr(TypeReprKind::Sending, Base, Loc) {}
1229+
1230+
static bool classof(const TypeRepr *T) {
1231+
return T->getKind() == TypeReprKind::Sending;
1232+
}
1233+
static bool classof(const SendingTypeRepr *T) { return true; }
1234+
};
1235+
12201236
/// A TypeRepr for a known, fixed type.
12211237
///
12221238
/// Fixed type representations should be used sparingly, in places
@@ -1618,6 +1634,7 @@ inline bool TypeRepr::isSimple() const {
16181634
case TypeReprKind::SILBox:
16191635
case TypeReprKind::Isolated:
16201636
case TypeReprKind::Transferring:
1637+
case TypeReprKind::Sending:
16211638
case TypeReprKind::Placeholder:
16221639
case TypeReprKind::CompileTimeConst:
16231640
case TypeReprKind::ResultDependsOn:

include/swift/AST/TypeReprNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ABSTRACT_TYPEREPR(Specifier, TypeRepr)
7272
SPECIFIER_TYPEREPR(CompileTimeConst, SpecifierTypeRepr)
7373
SPECIFIER_TYPEREPR(ResultDependsOn, SpecifierTypeRepr)
7474
SPECIFIER_TYPEREPR(Transferring, SpecifierTypeRepr)
75+
SPECIFIER_TYPEREPR(Sending, SpecifierTypeRepr)
7576
TYPEREPR(Fixed, TypeRepr)
7677
TYPEREPR(SILBox, TypeRepr)
7778
TYPEREPR(Self, TypeRepr)

include/swift/Basic/Features.def

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,14 @@ EXPERIMENTAL_FEATURE(FixedArrays, true)
350350
EXPERIMENTAL_FEATURE(GroupActorErrors, true)
351351

352352
// Allow for the 'transferring' keyword to be applied to arguments and results.
353-
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)
353+
//
354+
// Enables SendingArgsAndResults as well. After parsing, we just represent this
355+
// as 'sendable' implying that since both are always enabled together, this
356+
// doesn't need to be suppressed.
357+
EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)
358+
359+
// Allow for the 'sending' keyword to be applied to arguments and results.
360+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(SendingArgsAndResults, true)
354361

355362
// Enable explicit isolation of closures.
356363
EXPERIMENTAL_FEATURE(ClosureIsolation, true)

include/swift/Parse/Parser.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,9 @@ class Parser {
12061206
if (Context.LangOpts.hasFeature(Feature::TransferringArgsAndResults) &&
12071207
Tok.isContextualKeyword("transferring"))
12081208
return true;
1209+
if (Context.LangOpts.hasFeature(Feature::SendingArgsAndResults) &&
1210+
Tok.isContextualKeyword("sending"))
1211+
return true;
12091212
if (Context.LangOpts.hasFeature(Feature::NonescapableTypes) &&
12101213
(Tok.isContextualKeyword("_resultDependsOn") ||
12111214
isLifetimeDependenceToken()))
@@ -1256,6 +1259,7 @@ class Parser {
12561259
SourceLoc ConstLoc;
12571260
SourceLoc ResultDependsOnLoc;
12581261
SourceLoc TransferringLoc;
1262+
SourceLoc SendingLoc;
12591263
SmallVector<TypeOrCustomAttr> Attributes;
12601264
SmallVector<LifetimeDependenceSpecifier> lifetimeDependenceSpecifiers;
12611265

@@ -1573,6 +1577,9 @@ class Parser {
15731577
/// The location of the 'transferring' keyword if present.
15741578
SourceLoc TransferringLoc;
15751579

1580+
/// The location of the 'sending' keyword if present.
1581+
SourceLoc SendingLoc;
1582+
15761583
/// The type following the ':'.
15771584
TypeRepr *Type = nullptr;
15781585

lib/AST/ASTBridging.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ BridgedParamDecl BridgedParamDecl_createParsed(
890890
paramDecl->setCompileTimeConst(true);
891891
else if (isa<TransferringTypeRepr>(STR))
892892
paramDecl->setSending(true);
893+
else if (isa<SendingTypeRepr>(STR))
894+
paramDecl->setSending(true);
893895

894896
unwrappedType = STR->getBase();
895897
continue;
@@ -2240,6 +2242,9 @@ BridgedSpecifierTypeRepr BridgedSpecifierTypeRepr_createParsed(
22402242
case BridgedAttributedTypeSpecifierTransferring: {
22412243
return new (context) TransferringTypeRepr(baseType, loc);
22422244
}
2245+
case BridgedAttributedTypeSpecifierSending: {
2246+
return new (context) SendingTypeRepr(baseType, loc);
2247+
}
22432248
case BridgedAttributedTypeSpecifierConst: {
22442249
return new (context) CompileTimeConstTypeRepr(baseType, loc);
22452250
}

0 commit comments

Comments
 (0)