Skip to content

Commit b780ff6

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
1 parent 71e95b9 commit b780ff6

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
@@ -868,7 +868,7 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(GetCurrentAsyncTask, "getCurrentAsyncTask", "
868868
BUILTIN_MISC_OPERATION_WITH_SILGEN(CancelAsyncTask, "cancelAsyncTask", "", Special)
869869

870870
/// startAsyncLet()<T>: (
871-
/// __owned @escaping () async throws -> transferring T
871+
/// __owned @escaping () async throws -> sending T
872872
/// ) -> Builtin.RawPointer
873873
///
874874
/// DEPRECATED. startAsyncLetWithLocalBuffer is used instead.
@@ -878,7 +878,7 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(CancelAsyncTask, "cancelAsyncTask", "", Speci
878878
BUILTIN_MISC_OPERATION(StartAsyncLet, "startAsyncLet", "", Special)
879879

880880
/// startAsyncLetWithLocalBuffer()<T>: (
881-
/// __owned @escaping () async throws -> transferring T,
881+
/// __owned @escaping () async throws -> sending T,
882882
/// _ resultBuf: Builtin.RawPointer
883883
/// ) -> Builtin.RawPointer
884884
///

include/swift/AST/DiagnosticsParse.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,16 @@ ERROR(transferring_after_parameter_specifier,none,
22002200
"'transferring' must be placed before specifier '%0'", (StringRef))
22012201
ERROR(transferring_repeated,none,
22022202
"parameter may have at most one 'transferring' specifier", ())
2203+
ERROR(sending_before_parameter_specifier,none,
2204+
"'sending' must be placed after specifier '%0'", (StringRef))
2205+
ERROR(sending_repeated,none,
2206+
"parameter may have at most one 'sending' specifier", ())
2207+
ERROR(sending_and_transferring_used_together,none,
2208+
"'transferring' and 'sending' may not be used together", ())
2209+
WARNING(transferring_is_now_sendable,none,
2210+
"'transferring' has been renamed to 'sending' and the 'transferring' spelling will be removed shortly",
2211+
())
2212+
22032213

22042214
#define UNDEFINE_DIAGNOSTIC_MACROS
22052215
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7972,17 +7972,23 @@ ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
79727972
"Escapable",
79737973
())
79747974

7975-
//===----------------------------------------------------------------------===//
7976-
// MARK: Transferring
7977-
//===----------------------------------------------------------------------===//
7978-
7979-
ERROR(transferring_unsupported_param_specifier, none,
7980-
"'%0' cannot be applied to a 'transferring' parameter", (StringRef))
7975+
//===----------------------------------------------------------------------===//
7976+
// MARK: Transferring
7977+
//===----------------------------------------------------------------------===//
79817978

7982-
ERROR(transferring_only_on_parameters_and_results, none,
7983-
"'transferring' may only be used on parameters and results", ())
7984-
ERROR(transferring_cannot_be_applied_to_tuple_elt, none,
7985-
"'transferring' cannot be applied to tuple elements", ())
7979+
ERROR(transferring_unsupported_param_specifier, none,
7980+
"'%0' cannot be applied to a 'transferring' parameter", (StringRef))
7981+
7982+
ERROR(transferring_only_on_parameters_and_results, none,
7983+
"'transferring' may only be used on parameters and results", ())
7984+
ERROR(transferring_cannot_be_applied_to_tuple_elt, none,
7985+
"'transferring' cannot be applied to tuple elements", ())
7986+
ERROR(sending_unsupported_param_specifier, none,
7987+
"'%0' cannot be applied to a 'sending' parameter", (StringRef))
7988+
ERROR(sending_only_on_parameters_and_results, none,
7989+
"'sending' may only be used on parameters and results", ())
7990+
ERROR(sending_cannot_be_applied_to_tuple_elt, none,
7991+
"'sending' cannot be applied to tuple elements", ())
79867992

79877993
#define UNDEFINE_DIAGNOSTIC_MACROS
79887994
#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
@@ -353,7 +353,14 @@ EXPERIMENTAL_FEATURE(FixedArrays, true)
353353
EXPERIMENTAL_FEATURE(GroupActorErrors, true)
354354

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

358365
// Enable explicit isolation of closures.
359366
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
@@ -878,6 +878,8 @@ BridgedParamDecl BridgedParamDecl_createParsed(
878878
paramDecl->setCompileTimeConst(true);
879879
else if (isa<TransferringTypeRepr>(STR))
880880
paramDecl->setSending(true);
881+
else if (isa<SendingTypeRepr>(STR))
882+
paramDecl->setSending(true);
881883

882884
unwrappedType = STR->getBase();
883885
continue;
@@ -2225,6 +2227,9 @@ BridgedSpecifierTypeRepr BridgedSpecifierTypeRepr_createParsed(
22252227
case BridgedAttributedTypeSpecifierTransferring: {
22262228
return new (context) TransferringTypeRepr(baseType, loc);
22272229
}
2230+
case BridgedAttributedTypeSpecifierSending: {
2231+
return new (context) SendingTypeRepr(baseType, loc);
2232+
}
22282233
case BridgedAttributedTypeSpecifierConst: {
22292234
return new (context) CompileTimeConstTypeRepr(baseType, loc);
22302235
}

0 commit comments

Comments
 (0)