Skip to content

Commit d759ec9

Browse files
authored
Merge pull request #73696 from gottesmm/rdar128216574
[sending] Add support for 'sending'
2 parents 011c46e + 20a3589 commit d759ec9

File tree

102 files changed

+1484
-631
lines changed

Some content is hidden

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

102 files changed

+1484
-631
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ class TargetExtendedFunctionTypeFlags {
11981198
IsolatedAny = 0x00000002U,
11991199

12001200
// Values if we have a transferring result.
1201-
HasTransferringResult = 0x00000010U,
1201+
HasSendingResult = 0x00000010U,
12021202

12031203
/// A InvertibleProtocolSet in the high bits.
12041204
InvertedProtocolshift = 16,
@@ -1228,10 +1228,10 @@ class TargetExtendedFunctionTypeFlags {
12281228
}
12291229

12301230
const TargetExtendedFunctionTypeFlags<int_type>
1231-
withTransferringResult(bool newValue = true) const {
1231+
withSendingResult(bool newValue = true) const {
12321232
return TargetExtendedFunctionTypeFlags<int_type>(
1233-
(Data & ~HasTransferringResult) |
1234-
(newValue ? HasTransferringResult : 0));
1233+
(Data & ~HasSendingResult) |
1234+
(newValue ? HasSendingResult : 0));
12351235
}
12361236

12371237
const TargetExtendedFunctionTypeFlags<int_type>
@@ -1247,8 +1247,8 @@ class TargetExtendedFunctionTypeFlags {
12471247
return (Data & IsolationMask) == IsolatedAny;
12481248
}
12491249

1250-
bool hasTransferringResult() const {
1251-
return bool(Data & HasTransferringResult);
1250+
bool hasSendingResult() const {
1251+
return bool(Data & HasSendingResult);
12521252
}
12531253

12541254
int_type getIntValue() const {
@@ -1295,7 +1295,7 @@ class TargetParameterTypeFlags {
12951295
AutoClosureMask = 0x100,
12961296
NoDerivativeMask = 0x200,
12971297
IsolatedMask = 0x400,
1298-
TransferringMask = 0x800,
1298+
SendingMask = 0x800,
12991299
};
13001300
int_type Data;
13011301

@@ -1335,17 +1335,17 @@ class TargetParameterTypeFlags {
13351335
}
13361336

13371337
constexpr TargetParameterTypeFlags<int_type>
1338-
withTransferring(bool isTransferring) const {
1338+
withSending(bool isSending) const {
13391339
return TargetParameterTypeFlags<int_type>(
1340-
(Data & ~TransferringMask) | (isTransferring ? TransferringMask : 0));
1340+
(Data & ~SendingMask) | (isSending ? SendingMask : 0));
13411341
}
13421342

13431343
bool isNone() const { return Data == 0; }
13441344
bool isVariadic() const { return Data & VariadicMask; }
13451345
bool isAutoClosure() const { return Data & AutoClosureMask; }
13461346
bool isNoDerivative() const { return Data & NoDerivativeMask; }
13471347
bool isIsolated() const { return Data & IsolatedMask; }
1348-
bool isTransferring() const { return Data & TransferringMask; }
1348+
bool isSending() const { return Data & SendingMask; }
13491349

13501350
ParameterOwnership getOwnership() const {
13511351
return (ParameterOwnership)(Data & OwnershipMask);

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/Decl.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
532532
/// analysis.
533533
HasTopLevelLocalContextCaptures : 1,
534534

535-
/// Set to true if this FuncDecl has a transferring result.
536-
HasTransferringResult : 1
535+
/// Set to true if this FuncDecl has a 'sending' result.
536+
HasSendingResult : 1
537537
);
538538

539539
SWIFT_INLINE_BITFIELD(AccessorDecl, FuncDecl, 4 + 1 + 1,
@@ -6639,8 +6639,8 @@ class ParamDecl : public VarDecl {
66396639
/// Whether or not this paramater is '_resultDependsOn'
66406640
IsResultDependsOn = 1 << 3,
66416641

6642-
/// Whether or not this parameter is 'transferring'.
6643-
IsTransferring = 1 << 4,
6642+
/// Whether or not this parameter is 'sending'.
6643+
IsSending = 1 << 4,
66446644
};
66456645

66466646
/// The type repr and 3 bits used for flags.
@@ -6918,16 +6918,14 @@ class ParamDecl : public VarDecl {
69186918
removeFlag(Flag::IsIsolated);
69196919
}
69206920

6921-
/// Whether or not this parameter is marked with 'transferring'.
6922-
bool isTransferring() const {
6923-
return getOptions().contains(Flag::IsTransferring);
6924-
}
6921+
/// Whether or not this parameter is marked with 'sending'.
6922+
bool isSending() const { return getOptions().contains(Flag::IsSending); }
69256923

6926-
void setTransferring(bool value = true) {
6924+
void setSending(bool value = true) {
69276925
if (value)
6928-
addFlag(Flag::IsTransferring);
6926+
addFlag(Flag::IsSending);
69296927
else
6930-
removeFlag(Flag::IsTransferring);
6928+
removeFlag(Flag::IsSending);
69316929
}
69326930

69336931
/// Whether or not this parameter is marked with '_const'.
@@ -7966,7 +7964,7 @@ class FuncDecl : public AbstractFunctionDecl {
79667964
Bits.FuncDecl.IsStaticComputed = false;
79677965
Bits.FuncDecl.IsStatic = false;
79687966
Bits.FuncDecl.HasTopLevelLocalContextCaptures = false;
7969-
Bits.FuncDecl.HasTransferringResult = false;
7967+
Bits.FuncDecl.HasSendingResult = false;
79707968
}
79717969

79727970
void setResultInterfaceType(Type type);
@@ -8119,14 +8117,12 @@ class FuncDecl : public AbstractFunctionDecl {
81198117
Bits.FuncDecl.ForcedStaticDispatch = flag;
81208118
}
81218119

8122-
/// Returns true if this FuncDecl has a transferring result... returns false
8120+
/// Returns true if this FuncDecl has a sending result... returns false
81238121
/// otherwise.
8124-
bool hasTransferringResult() const {
8125-
return Bits.FuncDecl.HasTransferringResult;
8126-
}
8122+
bool hasSendingResult() const { return Bits.FuncDecl.HasSendingResult; }
81278123

8128-
void setTransferringResult(bool newValue = true) {
8129-
Bits.FuncDecl.HasTransferringResult = newValue;
8124+
void setSendingResult(bool newValue = true) {
8125+
Bits.FuncDecl.HasSendingResult = newValue;
81308126
}
81318127

81328128
static bool classof(const Decl *D) {

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/DiagnosticsSIL.def

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,14 +992,14 @@ NOTE(regionbasedisolation_named_transfer_non_transferrable, none,
992992
NOTE(regionbasedisolation_named_transfer_non_transferrable_callee, none,
993993
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and %5 uses",
994994
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, StringRef))
995-
NOTE(regionbasedisolation_named_transfer_into_transferring_param, none,
996-
"%0%1 is passed as a transferring parameter; Uses in callee may race with later %0uses",
995+
NOTE(regionbasedisolation_named_transfer_into_sending_param, none,
996+
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with later %0uses",
997997
(StringRef, Identifier))
998998
NOTE(regionbasedisolation_named_notransfer_transfer_into_result, none,
999-
"%0%1 cannot be a transferring result. %2 uses may race with caller uses",
999+
"%0%1 cannot be a 'sending' result. %2 uses may race with caller uses",
10001000
(StringRef, Identifier, StringRef))
1001-
NOTE(regionbasedisolation_named_stronglytransferred_binding, none,
1002-
"%0 used after being passed as a transferring parameter; Later uses could race",
1001+
NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
1002+
"%0 used after being passed as a 'sending' parameter; Later uses could race",
10031003
(Identifier))
10041004
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
10051005
"%0%1 is captured by a %2 closure. %2 uses in closure may race against later %3 uses",

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7976,17 +7976,23 @@ ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
79767976
"Escapable",
79777977
())
79787978

7979-
//===----------------------------------------------------------------------===//
7980-
// MARK: Transferring
7981-
//===----------------------------------------------------------------------===//
7982-
7983-
ERROR(transferring_unsupported_param_specifier, none,
7984-
"'%0' cannot be applied to a 'transferring' parameter", (StringRef))
7979+
//===----------------------------------------------------------------------===//
7980+
// MARK: Transferring
7981+
//===----------------------------------------------------------------------===//
79857982

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

79917997
#define UNDEFINE_DIAGNOSTIC_MACROS
79927998
#include "DefineDiagnosticMacros.h"

include/swift/AST/ExtInfo.h

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ class ASTExtInfoBuilder {
438438
// If bits are added or removed, then TypeBase::NumAFTExtInfoBits
439439
// and NumMaskBits must be updated, and they must match.
440440
//
441-
// |representation|noEscape|concurrent|async|throws|isolation|differentiability| TransferringResult |
442-
// | 0 .. 3 | 4 | 5 | 6 | 7 | 8 .. 10 | 11 .. 13 | 14 |
441+
// |representation|noEscape|concurrent|async|throws|isolation|differentiability| SendingResult |
442+
// | 0 .. 3 | 4 | 5 | 6 | 7 | 8 .. 10 | 11 .. 13 | 14 |
443443
//
444444
enum : unsigned {
445445
RepresentationMask = 0xF << 0,
@@ -451,7 +451,7 @@ class ASTExtInfoBuilder {
451451
IsolationMask = 0x7 << IsolationMaskOffset,
452452
DifferentiabilityMaskOffset = 11,
453453
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
454-
TransferringResultMask = 1 << 14,
454+
SendingResultMask = 1 << 14,
455455
NumMaskBits = 15
456456
};
457457

@@ -501,14 +501,14 @@ class ASTExtInfoBuilder {
501501
Type thrownError, DifferentiabilityKind diffKind,
502502
const clang::Type *type, FunctionTypeIsolation isolation,
503503
LifetimeDependenceInfo lifetimeDependenceInfo,
504-
bool transferringResult)
504+
bool sendingResult)
505505
: ASTExtInfoBuilder(
506506
((unsigned)rep) | (isNoEscape ? NoEscapeMask : 0) |
507507
(throws ? ThrowsMask : 0) |
508508
(((unsigned)diffKind << DifferentiabilityMaskOffset) &
509509
DifferentiabilityMask) |
510510
(unsigned(isolation.getKind()) << IsolationMaskOffset) |
511-
(transferringResult ? TransferringResultMask : 0),
511+
(sendingResult ? SendingResultMask : 0),
512512
ClangTypeInfo(type), isolation.getOpaqueType(), thrownError,
513513
lifetimeDependenceInfo) {}
514514

@@ -530,9 +530,7 @@ class ASTExtInfoBuilder {
530530

531531
constexpr bool isThrowing() const { return bits & ThrowsMask; }
532532

533-
constexpr bool hasTransferringResult() const {
534-
return bits & TransferringResultMask;
535-
}
533+
constexpr bool hasSendingResult() const { return bits & SendingResultMask; }
536534

537535
constexpr DifferentiabilityKind getDifferentiabilityKind() const {
538536
return DifferentiabilityKind((bits & DifferentiabilityMask) >>
@@ -644,12 +642,10 @@ class ASTExtInfoBuilder {
644642
return withThrows(true, Type());
645643
}
646644

647-
[[nodiscard]] ASTExtInfoBuilder
648-
withTransferringResult(bool transferring = true) const {
649-
return ASTExtInfoBuilder(transferring ? (bits | TransferringResultMask)
650-
: (bits & ~TransferringResultMask),
651-
clangTypeInfo, globalActor, thrownError,
652-
lifetimeDependenceInfo);
645+
[[nodiscard]] ASTExtInfoBuilder withSendingResult(bool sending = true) const {
646+
return ASTExtInfoBuilder(
647+
sending ? (bits | SendingResultMask) : (bits & ~SendingResultMask),
648+
clangTypeInfo, globalActor, thrownError, lifetimeDependenceInfo);
653649
}
654650

655651
[[nodiscard]]
@@ -765,9 +761,7 @@ class ASTExtInfo {
765761

766762
constexpr bool isThrowing() const { return builder.isThrowing(); }
767763

768-
constexpr bool hasTransferringResult() const {
769-
return builder.hasTransferringResult();
770-
}
764+
constexpr bool hasSendingResult() const { return builder.hasSendingResult(); }
771765

772766
constexpr DifferentiabilityKind getDifferentiabilityKind() const {
773767
return builder.getDifferentiabilityKind();
@@ -838,9 +832,8 @@ class ASTExtInfo {
838832
return builder.withAsync(async).build();
839833
}
840834

841-
[[nodiscard]] ASTExtInfo
842-
withTransferringResult(bool transferring = true) const {
843-
return builder.withTransferringResult(transferring).build();
835+
[[nodiscard]] ASTExtInfo withSendingResult(bool sending = true) const {
836+
return builder.withSendingResult(sending).build();
844837
}
845838

846839
[[nodiscard]]

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/TypeAttr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ SIMPLE_SIL_TYPE_ATTR(captures_generics, CapturesGenerics)
105105
// Used at the SIL level to mark a type as moveOnly.
106106
SIMPLE_SIL_TYPE_ATTR(moveOnly, MoveOnly)
107107
SIMPLE_SIL_TYPE_ATTR(sil_isolated, SILIsolated)
108-
SIMPLE_SIL_TYPE_ATTR(sil_transferring, SILTransferring)
108+
SIMPLE_SIL_TYPE_ATTR(sil_sending, SILSending)
109109

110110
// SIL metatype attributes.
111111
SIMPLE_SIL_TYPE_ATTR(thin, Thin)

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)

0 commit comments

Comments
 (0)