Skip to content

Commit e3e78ad

Browse files
committed
[sending] Change the internals of sending to be based around 'sending' instead of 'transferring'.
We still only parse transferring... but this sets us up for adding the new 'sending' syntax by first validating that this internal change does not mess up the current transferring impl since we want both to keep working for now. rdar://128216574
1 parent 764ba94 commit e3e78ad

Some content is hidden

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

45 files changed

+284
-304
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/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/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/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/Types.h

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ class ParameterTypeFlags {
22242224
Isolated = 1 << 7,
22252225
CompileTimeConst = 1 << 8,
22262226
ResultDependsOn = 1 << 9,
2227-
Transferring = 1 << 10,
2227+
Sending = 1 << 10,
22282228
NumBits = 11
22292229
};
22302230
OptionSet<ParameterFlags> value;
@@ -2241,21 +2241,21 @@ class ParameterTypeFlags {
22412241
ParameterTypeFlags(bool variadic, bool autoclosure, bool nonEphemeral,
22422242
ParamSpecifier specifier, bool isolated, bool noDerivative,
22432243
bool compileTimeConst, bool hasResultDependsOn,
2244-
bool isTransferring)
2244+
bool isSending)
22452245
: value((variadic ? Variadic : 0) | (autoclosure ? AutoClosure : 0) |
22462246
(nonEphemeral ? NonEphemeral : 0) |
22472247
uint8_t(specifier) << SpecifierShift | (isolated ? Isolated : 0) |
22482248
(noDerivative ? NoDerivative : 0) |
22492249
(compileTimeConst ? CompileTimeConst : 0) |
22502250
(hasResultDependsOn ? ResultDependsOn : 0) |
2251-
(isTransferring ? Transferring : 0)) {}
2251+
(isSending ? Sending : 0)) {}
22522252

22532253
/// Create one from what's present in the parameter type
22542254
inline static ParameterTypeFlags
22552255
fromParameterType(Type paramTy, bool isVariadic, bool isAutoClosure,
22562256
bool isNonEphemeral, ParamSpecifier ownership,
22572257
bool isolated, bool isNoDerivative, bool compileTimeConst,
2258-
bool hasResultDependsOn, bool isTransferring);
2258+
bool hasResultDependsOn, bool isSending);
22592259

22602260
bool isNone() const { return !value; }
22612261
bool isVariadic() const { return value.contains(Variadic); }
@@ -2268,7 +2268,7 @@ class ParameterTypeFlags {
22682268
bool isCompileTimeConst() const { return value.contains(CompileTimeConst); }
22692269
bool isNoDerivative() const { return value.contains(NoDerivative); }
22702270
bool hasResultDependsOn() const { return value.contains(ResultDependsOn); }
2271-
bool isTransferring() const { return value.contains(Transferring); }
2271+
bool isSending() const { return value.contains(Sending); }
22722272

22732273
/// Get the spelling of the parameter specifier used on the parameter.
22742274
ParamSpecifier getOwnershipSpecifier() const {
@@ -2331,10 +2331,10 @@ class ParameterTypeFlags {
23312331
: value - ParameterTypeFlags::NoDerivative);
23322332
}
23332333

2334-
ParameterTypeFlags withTransferring(bool withTransferring) const {
2335-
return ParameterTypeFlags(withTransferring
2336-
? value | ParameterTypeFlags::Transferring
2337-
: value - ParameterTypeFlags::Transferring);
2334+
ParameterTypeFlags withSending(bool withSending) const {
2335+
return ParameterTypeFlags(withSending
2336+
? value | ParameterTypeFlags::Sending
2337+
: value - ParameterTypeFlags::Sending);
23382338
}
23392339

23402340
bool operator ==(const ParameterTypeFlags &other) const {
@@ -3646,9 +3646,7 @@ class AnyFunctionType : public TypeBase {
36463646

36473647
bool isThrowing() const { return getExtInfo().isThrowing(); }
36483648

3649-
bool hasTransferringResult() const {
3650-
return getExtInfo().hasTransferringResult();
3651-
}
3649+
bool hasSendingResult() const { return getExtInfo().hasSendingResult(); }
36523650

36533651
bool hasEffect(EffectKind kind) const;
36543652

@@ -4218,8 +4216,8 @@ class SILParameterInfo {
42184216
/// differentiable with respect to this parameter.
42194217
NotDifferentiable = 0x1,
42204218

4221-
/// Set if the given parameter is transferring.
4222-
Transferring = 0x2,
4219+
/// Set if the given parameter is sending.
4220+
Sending = 0x2,
42234221

42244222
/// Set if the given parameter is isolated.
42254223
Isolated = 0x4,
@@ -4488,10 +4486,10 @@ class SILResultInfo {
44884486
/// differentiable with respect to this result.
44894487
NotDifferentiable = 0x1,
44904488

4491-
/// Set if a return type is transferring. This means that the returned value
4489+
/// Set if a return type is sending. This means that the returned value
44924490
/// must be disconnected and not in any strongly structured regions like an
44934491
/// actor or a task isolated variable.
4494-
IsTransferring = 0x2,
4492+
IsSending = 0x2,
44954493
};
44964494

44974495
using Options = OptionSet<Flag>;
@@ -4940,12 +4938,12 @@ class SILFunctionType final
49404938
return getExtInfo().getIsolation();
49414939
}
49424940

4943-
/// Return true if all
4944-
bool hasTransferringResult() const {
4945-
// For now all functions either have all transferring results or no
4946-
// transferring results. This is validated with a SILVerifier check.
4941+
/// Return true if all results are 'sending'.
4942+
bool hasSendingResult() const {
4943+
// For now all functions either have all sending results or no
4944+
// sending results. This is validated with a SILVerifier check.
49474945
return getNumResults() &&
4948-
getResults().front().hasOption(SILResultInfo::IsTransferring);
4946+
getResults().front().hasOption(SILResultInfo::IsSending);
49494947
}
49504948

49514949
/// Return the array of all the yields.
@@ -7768,7 +7766,7 @@ inline TupleTypeElt TupleTypeElt::getWithType(Type T) const {
77687766
inline ParameterTypeFlags ParameterTypeFlags::fromParameterType(
77697767
Type paramTy, bool isVariadic, bool isAutoClosure, bool isNonEphemeral,
77707768
ParamSpecifier ownership, bool isolated, bool isNoDerivative,
7771-
bool compileTimeConst, bool hasResultDependsOn, bool isTransferring) {
7769+
bool compileTimeConst, bool hasResultDependsOn, bool isSending) {
77727770
// FIXME(Remove InOut): The last caller that needs this is argument
77737771
// decomposition. Start by enabling the assertion there and fixing up those
77747772
// callers, then remove this, then remove
@@ -7780,7 +7778,7 @@ inline ParameterTypeFlags ParameterTypeFlags::fromParameterType(
77807778
}
77817779
return {isVariadic, isAutoClosure, isNonEphemeral,
77827780
ownership, isolated, isNoDerivative,
7783-
compileTimeConst, hasResultDependsOn, isTransferring};
7781+
compileTimeConst, hasResultDependsOn, isSending};
77847782
}
77857783

77867784
inline const Type *BoundGenericType::getTrailingObjectsPointer() const {

include/swift/Demangling/Demangle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ struct [[nodiscard]] ManglingError {
602602
InvalidImplCoroutineKind,
603603
InvalidImplFunctionAttribute,
604604
InvalidImplParameterConvention,
605-
InvalidImplParameterTransferring,
605+
InvalidImplParameterSending,
606606
InvalidMetatypeRepresentation,
607607
MultiByteRelatedEntity,
608608
BadValueWitnessKind,

include/swift/Demangling/DemangleNodes.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ NODE(ImplEscaping)
133133
NODE(ImplConvention)
134134
NODE(ImplDifferentiabilityKind)
135135
NODE(ImplErasedIsolation)
136-
NODE(ImplTransferringResult)
136+
NODE(ImplSendingResult)
137137
NODE(ImplParameterResultDifferentiability)
138-
NODE(ImplParameterTransferring)
138+
NODE(ImplParameterSending)
139139
NODE(ImplFunctionAttribute)
140140
NODE(ImplFunctionConvention)
141141
NODE(ImplFunctionConventionName)
@@ -153,9 +153,9 @@ NODE(InfixOperator)
153153
CONTEXT_NODE(Initializer)
154154
CONTEXT_NODE(InitAccessor)
155155
NODE(Isolated)
156-
NODE(Transferring)
156+
NODE(Sending)
157157
NODE(IsolatedAnyFunctionType)
158-
NODE(TransferringResultFunctionType)
158+
NODE(SendingResultFunctionType)
159159
NODE(KeyPathGetterThunkHelper)
160160
NODE(KeyPathSetterThunkHelper)
161161
NODE(KeyPathEqualsThunkHelper)

0 commit comments

Comments
 (0)