Skip to content

Commit b518ee1

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 (cherry picked from commit e3e78ad)
1 parent b4792a5 commit b518ee1

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,
@@ -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/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
@@ -2218,7 +2218,7 @@ class ParameterTypeFlags {
22182218
Isolated = 1 << 7,
22192219
CompileTimeConst = 1 << 8,
22202220
ResultDependsOn = 1 << 9,
2221-
Transferring = 1 << 10,
2221+
Sending = 1 << 10,
22222222
NumBits = 11
22232223
};
22242224
OptionSet<ParameterFlags> value;
@@ -2235,21 +2235,21 @@ class ParameterTypeFlags {
22352235
ParameterTypeFlags(bool variadic, bool autoclosure, bool nonEphemeral,
22362236
ParamSpecifier specifier, bool isolated, bool noDerivative,
22372237
bool compileTimeConst, bool hasResultDependsOn,
2238-
bool isTransferring)
2238+
bool isSending)
22392239
: value((variadic ? Variadic : 0) | (autoclosure ? AutoClosure : 0) |
22402240
(nonEphemeral ? NonEphemeral : 0) |
22412241
uint8_t(specifier) << SpecifierShift | (isolated ? Isolated : 0) |
22422242
(noDerivative ? NoDerivative : 0) |
22432243
(compileTimeConst ? CompileTimeConst : 0) |
22442244
(hasResultDependsOn ? ResultDependsOn : 0) |
2245-
(isTransferring ? Transferring : 0)) {}
2245+
(isSending ? Sending : 0)) {}
22462246

22472247
/// Create one from what's present in the parameter type
22482248
inline static ParameterTypeFlags
22492249
fromParameterType(Type paramTy, bool isVariadic, bool isAutoClosure,
22502250
bool isNonEphemeral, ParamSpecifier ownership,
22512251
bool isolated, bool isNoDerivative, bool compileTimeConst,
2252-
bool hasResultDependsOn, bool isTransferring);
2252+
bool hasResultDependsOn, bool isSending);
22532253

22542254
bool isNone() const { return !value; }
22552255
bool isVariadic() const { return value.contains(Variadic); }
@@ -2262,7 +2262,7 @@ class ParameterTypeFlags {
22622262
bool isCompileTimeConst() const { return value.contains(CompileTimeConst); }
22632263
bool isNoDerivative() const { return value.contains(NoDerivative); }
22642264
bool hasResultDependsOn() const { return value.contains(ResultDependsOn); }
2265-
bool isTransferring() const { return value.contains(Transferring); }
2265+
bool isSending() const { return value.contains(Sending); }
22662266

22672267
/// Get the spelling of the parameter specifier used on the parameter.
22682268
ParamSpecifier getOwnershipSpecifier() const {
@@ -2325,10 +2325,10 @@ class ParameterTypeFlags {
23252325
: value - ParameterTypeFlags::NoDerivative);
23262326
}
23272327

2328-
ParameterTypeFlags withTransferring(bool withTransferring) const {
2329-
return ParameterTypeFlags(withTransferring
2330-
? value | ParameterTypeFlags::Transferring
2331-
: value - ParameterTypeFlags::Transferring);
2328+
ParameterTypeFlags withSending(bool withSending) const {
2329+
return ParameterTypeFlags(withSending
2330+
? value | ParameterTypeFlags::Sending
2331+
: value - ParameterTypeFlags::Sending);
23322332
}
23332333

23342334
bool operator ==(const ParameterTypeFlags &other) const {
@@ -3640,9 +3640,7 @@ class AnyFunctionType : public TypeBase {
36403640

36413641
bool isThrowing() const { return getExtInfo().isThrowing(); }
36423642

3643-
bool hasTransferringResult() const {
3644-
return getExtInfo().hasTransferringResult();
3645-
}
3643+
bool hasSendingResult() const { return getExtInfo().hasSendingResult(); }
36463644

36473645
bool hasEffect(EffectKind kind) const;
36483646

@@ -4212,8 +4210,8 @@ class SILParameterInfo {
42124210
/// differentiable with respect to this parameter.
42134211
NotDifferentiable = 0x1,
42144212

4215-
/// Set if the given parameter is transferring.
4216-
Transferring = 0x2,
4213+
/// Set if the given parameter is sending.
4214+
Sending = 0x2,
42174215

42184216
/// Set if the given parameter is isolated.
42194217
Isolated = 0x4,
@@ -4482,10 +4480,10 @@ class SILResultInfo {
44824480
/// differentiable with respect to this result.
44834481
NotDifferentiable = 0x1,
44844482

4485-
/// Set if a return type is transferring. This means that the returned value
4483+
/// Set if a return type is sending. This means that the returned value
44864484
/// must be disconnected and not in any strongly structured regions like an
44874485
/// actor or a task isolated variable.
4488-
IsTransferring = 0x2,
4486+
IsSending = 0x2,
44894487
};
44904488

44914489
using Options = OptionSet<Flag>;
@@ -4931,12 +4929,12 @@ class SILFunctionType final
49314929
return getExtInfo().getIsolation();
49324930
}
49334931

4934-
/// Return true if all
4935-
bool hasTransferringResult() const {
4936-
// For now all functions either have all transferring results or no
4937-
// transferring results. This is validated with a SILVerifier check.
4932+
/// Return true if all results are 'sending'.
4933+
bool hasSendingResult() const {
4934+
// For now all functions either have all sending results or no
4935+
// sending results. This is validated with a SILVerifier check.
49384936
return getNumResults() &&
4939-
getResults().front().hasOption(SILResultInfo::IsTransferring);
4937+
getResults().front().hasOption(SILResultInfo::IsSending);
49404938
}
49414939

49424940
/// Return the array of all the yields.
@@ -7756,7 +7754,7 @@ inline TupleTypeElt TupleTypeElt::getWithType(Type T) const {
77567754
inline ParameterTypeFlags ParameterTypeFlags::fromParameterType(
77577755
Type paramTy, bool isVariadic, bool isAutoClosure, bool isNonEphemeral,
77587756
ParamSpecifier ownership, bool isolated, bool isNoDerivative,
7759-
bool compileTimeConst, bool hasResultDependsOn, bool isTransferring) {
7757+
bool compileTimeConst, bool hasResultDependsOn, bool isSending) {
77607758
// FIXME(Remove InOut): The last caller that needs this is argument
77617759
// decomposition. Start by enabling the assertion there and fixing up those
77627760
// callers, then remove this, then remove
@@ -7768,7 +7766,7 @@ inline ParameterTypeFlags ParameterTypeFlags::fromParameterType(
77687766
}
77697767
return {isVariadic, isAutoClosure, isNonEphemeral,
77707768
ownership, isolated, isNoDerivative,
7771-
compileTimeConst, hasResultDependsOn, isTransferring};
7769+
compileTimeConst, hasResultDependsOn, isSending};
77727770
}
77737771

77747772
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
@@ -601,7 +601,7 @@ struct [[nodiscard]] ManglingError {
601601
InvalidImplDifferentiability,
602602
InvalidImplFunctionAttribute,
603603
InvalidImplParameterConvention,
604-
InvalidImplParameterTransferring,
604+
InvalidImplParameterSending,
605605
InvalidMetatypeRepresentation,
606606
MultiByteRelatedEntity,
607607
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)
@@ -152,9 +152,9 @@ NODE(InfixOperator)
152152
CONTEXT_NODE(Initializer)
153153
CONTEXT_NODE(InitAccessor)
154154
NODE(Isolated)
155-
NODE(Transferring)
155+
NODE(Sending)
156156
NODE(IsolatedAnyFunctionType)
157-
NODE(TransferringResultFunctionType)
157+
NODE(SendingResultFunctionType)
158158
NODE(KeyPathGetterThunkHelper)
159159
NODE(KeyPathSetterThunkHelper)
160160
NODE(KeyPathEqualsThunkHelper)

0 commit comments

Comments
 (0)