Skip to content

Commit fe80a87

Browse files
authored
Merge pull request #73743 from gottesmm/release/6.0-sending-rename
[6.0] Add support for sending
2 parents cb8d19b + 63bd41d commit fe80a87

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
@@ -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/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,
@@ -6647,8 +6647,8 @@ class ParamDecl : public VarDecl {
66476647
/// Whether or not this paramater is '_resultDependsOn'
66486648
IsResultDependsOn = 1 << 3,
66496649

6650-
/// Whether or not this parameter is 'transferring'.
6651-
IsTransferring = 1 << 4,
6650+
/// Whether or not this parameter is 'sending'.
6651+
IsSending = 1 << 4,
66526652
};
66536653

66546654
/// The type repr and 3 bits used for flags.
@@ -6902,16 +6902,14 @@ class ParamDecl : public VarDecl {
69026902
removeFlag(Flag::IsIsolated);
69036903
}
69046904

6905-
/// Whether or not this parameter is marked with 'transferring'.
6906-
bool isTransferring() const {
6907-
return getOptions().contains(Flag::IsTransferring);
6908-
}
6905+
/// Whether or not this parameter is marked with 'sending'.
6906+
bool isSending() const { return getOptions().contains(Flag::IsSending); }
69096907

6910-
void setTransferring(bool value = true) {
6908+
void setSending(bool value = true) {
69116909
if (value)
6912-
addFlag(Flag::IsTransferring);
6910+
addFlag(Flag::IsSending);
69136911
else
6914-
removeFlag(Flag::IsTransferring);
6912+
removeFlag(Flag::IsSending);
69156913
}
69166914

69176915
/// Whether or not this parameter is marked with '_const'.
@@ -7940,7 +7938,7 @@ class FuncDecl : public AbstractFunctionDecl {
79407938
Bits.FuncDecl.IsStaticComputed = false;
79417939
Bits.FuncDecl.IsStatic = false;
79427940
Bits.FuncDecl.HasTopLevelLocalContextCaptures = false;
7943-
Bits.FuncDecl.HasTransferringResult = false;
7941+
Bits.FuncDecl.HasSendingResult = false;
79447942
}
79457943

79467944
void setResultInterfaceType(Type type);
@@ -8097,14 +8095,12 @@ class FuncDecl : public AbstractFunctionDecl {
80978095
Bits.FuncDecl.ForcedStaticDispatch = flag;
80988096
}
80998097

8100-
/// Returns true if this FuncDecl has a transferring result... returns false
8098+
/// Returns true if this FuncDecl has a sending result... returns false
81018099
/// otherwise.
8102-
bool hasTransferringResult() const {
8103-
return Bits.FuncDecl.HasTransferringResult;
8104-
}
8100+
bool hasSendingResult() const { return Bits.FuncDecl.HasSendingResult; }
81058101

8106-
void setTransferringResult(bool newValue = true) {
8107-
Bits.FuncDecl.HasTransferringResult = newValue;
8102+
void setSendingResult(bool newValue = true) {
8103+
Bits.FuncDecl.HasSendingResult = newValue;
81088104
}
81098105

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,14 +990,14 @@ NOTE(regionbasedisolation_named_transfer_non_transferrable, none,
990990
NOTE(regionbasedisolation_named_transfer_non_transferrable_callee, none,
991991
"sending %1%0 to %2 %3 %4 risks causing data races between %2 and %5 uses",
992992
(Identifier, StringRef, ActorIsolation, DescriptiveDeclKind, DeclName, StringRef))
993-
NOTE(regionbasedisolation_named_transfer_into_transferring_param, none,
994-
"%0%1 is passed as a transferring parameter; Uses in callee may race with later %0uses",
993+
NOTE(regionbasedisolation_named_transfer_into_sending_param, none,
994+
"%0%1 is passed as a 'sending' parameter; Uses in callee may race with later %0uses",
995995
(StringRef, Identifier))
996996
NOTE(regionbasedisolation_named_notransfer_transfer_into_result, none,
997-
"%0%1 cannot be a transferring result. %2 uses may race with caller uses",
997+
"%0%1 cannot be a 'sending' result. %2 uses may race with caller uses",
998998
(StringRef, Identifier, StringRef))
999-
NOTE(regionbasedisolation_named_stronglytransferred_binding, none,
1000-
"%0 used after being passed as a transferring parameter; Later uses could race",
999+
NOTE(regionbasedisolation_named_value_used_after_explicit_sending, none,
1000+
"%0 used after being passed as a 'sending' parameter; Later uses could race",
10011001
(Identifier))
10021002
NOTE(regionbasedisolation_named_isolated_closure_yields_race, none,
10031003
"%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
@@ -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/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)