@@ -439,8 +439,8 @@ class ASTExtInfoBuilder {
439
439
// If bits are added or removed, then TypeBase::NumAFTExtInfoBits
440
440
// and NumMaskBits must be updated, and they must match.
441
441
//
442
- // |representation|noEscape|concurrent|async|throws|isolation|differentiability|
443
- // | 0 .. 3 | 4 | 5 | 6 | 7 | 8 .. 10 | 11 .. 13 |
442
+ // |representation|noEscape|concurrent|async|throws|isolation|differentiability| TransferringResult |
443
+ // | 0 .. 3 | 4 | 5 | 6 | 7 | 8 .. 10 | 11 .. 13 | 14 |
444
444
//
445
445
enum : unsigned {
446
446
RepresentationMask = 0xF << 0 ,
@@ -452,7 +452,8 @@ class ASTExtInfoBuilder {
452
452
IsolationMask = 0x7 << IsolationMaskOffset,
453
453
DifferentiabilityMaskOffset = 11 ,
454
454
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
455
- NumMaskBits = 14
455
+ TransferringResultMask = 1 << 14 ,
456
+ NumMaskBits = 15
456
457
};
457
458
458
459
static_assert (FunctionTypeIsolation::Mask == 0x7 , " update mask manually" );
@@ -485,26 +486,30 @@ class ASTExtInfoBuilder {
485
486
: ASTExtInfoBuilder(Representation::Swift, false , false , Type(),
486
487
DifferentiabilityKind::NonDifferentiable, nullptr,
487
488
FunctionTypeIsolation::forNonIsolated(),
488
- LifetimeDependenceInfo()) {}
489
+ LifetimeDependenceInfo(),
490
+ false /* transferringResult*/ ) {}
489
491
490
492
// Constructor for polymorphic type.
491
493
ASTExtInfoBuilder (Representation rep, bool throws, Type thrownError)
492
494
: ASTExtInfoBuilder(rep, false , throws, thrownError,
493
495
DifferentiabilityKind::NonDifferentiable, nullptr ,
494
496
FunctionTypeIsolation::forNonIsolated (),
495
- LifetimeDependenceInfo()) {}
497
+ LifetimeDependenceInfo(),
498
+ false /* transferringResult*/ ) {}
496
499
497
500
// Constructor with no defaults.
498
501
ASTExtInfoBuilder (Representation rep, bool isNoEscape, bool throws,
499
502
Type thrownError, DifferentiabilityKind diffKind,
500
503
const clang::Type *type, FunctionTypeIsolation isolation,
501
- LifetimeDependenceInfo lifetimeDependenceInfo)
504
+ LifetimeDependenceInfo lifetimeDependenceInfo,
505
+ bool transferringResult)
502
506
: ASTExtInfoBuilder(
503
507
((unsigned )rep) | (isNoEscape ? NoEscapeMask : 0 ) |
504
508
(throws ? ThrowsMask : 0 ) |
505
509
(((unsigned )diffKind << DifferentiabilityMaskOffset) &
506
510
DifferentiabilityMask) |
507
- (unsigned (isolation.getKind()) << IsolationMaskOffset),
511
+ (unsigned (isolation.getKind()) << IsolationMaskOffset) |
512
+ (transferringResult ? TransferringResultMask : 0 ),
508
513
ClangTypeInfo(type), isolation.getOpaqueType(), thrownError,
509
514
lifetimeDependenceInfo) {}
510
515
@@ -526,6 +531,10 @@ class ASTExtInfoBuilder {
526
531
527
532
constexpr bool isThrowing () const { return bits & ThrowsMask; }
528
533
534
+ constexpr bool hasTransferringResult () const {
535
+ return bits & TransferringResultMask;
536
+ }
537
+
529
538
constexpr DifferentiabilityKind getDifferentiabilityKind () const {
530
539
return DifferentiabilityKind ((bits & DifferentiabilityMask) >>
531
540
DifferentiabilityMaskOffset);
@@ -630,10 +639,20 @@ class ASTExtInfoBuilder {
630
639
throws ? (bits | ThrowsMask) : (bits & ~ThrowsMask), clangTypeInfo,
631
640
globalActor, thrownError, lifetimeDependenceInfo);
632
641
}
642
+
633
643
[[nodiscard]]
634
644
ASTExtInfoBuilder withThrows () const {
635
645
return withThrows (true , Type ());
636
646
}
647
+
648
+ [[nodiscard]] ASTExtInfoBuilder
649
+ withTransferringResult (bool transferring = true ) const {
650
+ return ASTExtInfoBuilder (transferring ? (bits | TransferringResultMask)
651
+ : (bits & ~TransferringResultMask),
652
+ clangTypeInfo, globalActor, thrownError,
653
+ lifetimeDependenceInfo);
654
+ }
655
+
637
656
[[nodiscard]]
638
657
ASTExtInfoBuilder
639
658
withDifferentiabilityKind (DifferentiabilityKind differentiability) const {
@@ -747,6 +766,10 @@ class ASTExtInfo {
747
766
748
767
constexpr bool isThrowing () const { return builder.isThrowing (); }
749
768
769
+ constexpr bool hasTransferringResult () const {
770
+ return builder.hasTransferringResult ();
771
+ }
772
+
750
773
constexpr DifferentiabilityKind getDifferentiabilityKind () const {
751
774
return builder.getDifferentiabilityKind ();
752
775
}
@@ -816,6 +839,11 @@ class ASTExtInfo {
816
839
return builder.withAsync (async).build ();
817
840
}
818
841
842
+ [[nodiscard]] ASTExtInfo
843
+ withTransferringResult (bool transferring = true ) const {
844
+ return builder.withTransferringResult (transferring).build ();
845
+ }
846
+
819
847
[[nodiscard]]
820
848
ASTExtInfo withIsolation (FunctionTypeIsolation isolation) const {
821
849
return builder.withIsolation (isolation).build ();
@@ -908,7 +936,8 @@ class SILExtInfoBuilder {
908
936
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
909
937
UnimplementableMask = 1 << 12 ,
910
938
ErasedIsolationMask = 1 << 13 ,
911
- NumMaskBits = 14
939
+ TransferringResultMask = 1 << 14 ,
940
+ NumMaskBits = 15
912
941
};
913
942
914
943
unsigned bits; // Naturally sized for speed.
@@ -929,16 +958,17 @@ class SILExtInfoBuilder {
929
958
bool isNoEscape, bool isSendable,
930
959
bool isAsync, bool isUnimplementable,
931
960
SILFunctionTypeIsolation isolation,
961
+ bool hasTransferringResult,
932
962
DifferentiabilityKind diffKind) {
933
963
return ((unsigned )rep) | (isPseudogeneric ? PseudogenericMask : 0 ) |
934
- (isNoEscape ? NoEscapeMask : 0 ) |
935
- (isSendable ? SendableMask : 0 ) |
964
+ (isNoEscape ? NoEscapeMask : 0 ) | (isSendable ? SendableMask : 0 ) |
936
965
(isAsync ? AsyncMask : 0 ) |
937
966
(isUnimplementable ? UnimplementableMask : 0 ) |
938
967
(isolation == SILFunctionTypeIsolation::Erased
939
968
? ErasedIsolationMask : 0 ) |
940
969
(((unsigned )diffKind << DifferentiabilityMaskOffset) &
941
- DifferentiabilityMask);
970
+ DifferentiabilityMask) |
971
+ (hasTransferringResult ? TransferringResultMask : 0 );
942
972
}
943
973
944
974
public:
@@ -947,18 +977,19 @@ class SILExtInfoBuilder {
947
977
SILExtInfoBuilder ()
948
978
: SILExtInfoBuilder(makeBits(SILFunctionTypeRepresentation::Thick, false ,
949
979
false , false , false , false ,
950
- SILFunctionTypeIsolation::Unknown,
980
+ SILFunctionTypeIsolation::Unknown, false ,
951
981
DifferentiabilityKind::NonDifferentiable),
952
982
ClangTypeInfo(nullptr ), LifetimeDependenceInfo()) {}
953
983
954
984
SILExtInfoBuilder (Representation rep, bool isPseudogeneric, bool isNoEscape,
955
985
bool isSendable, bool isAsync, bool isUnimplementable,
956
986
SILFunctionTypeIsolation isolation,
957
987
DifferentiabilityKind diffKind, const clang::Type *type,
958
- LifetimeDependenceInfo lifetimeDependenceInfo)
988
+ LifetimeDependenceInfo lifetimeDependenceInfo,
989
+ bool hasTransferringResult)
959
990
: SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape, isSendable,
960
- isAsync, isUnimplementable,
961
- isolation , diffKind),
991
+ isAsync, isUnimplementable, isolation,
992
+ hasTransferringResult , diffKind),
962
993
ClangTypeInfo(type), lifetimeDependenceInfo) {}
963
994
964
995
// Constructor for polymorphic type.
@@ -967,8 +998,9 @@ class SILExtInfoBuilder {
967
998
info.isNoEscape(), info.isSendable(),
968
999
info.isAsync(), /* unimplementable*/ false,
969
1000
info.getIsolation().isErased()
970
- ? SILFunctionTypeIsolation::Erased
971
- : SILFunctionTypeIsolation::Unknown,
1001
+ ? SILFunctionTypeIsolation::Erased
1002
+ : SILFunctionTypeIsolation::Unknown,
1003
+ /* has transferring result*/ false,
972
1004
info.getDifferentiabilityKind()),
973
1005
info.getClangTypeInfo(),
974
1006
info.getLifetimeDependenceInfo()) {}
@@ -998,6 +1030,10 @@ class SILExtInfoBuilder {
998
1030
999
1031
constexpr bool isAsync () const { return bits & AsyncMask; }
1000
1032
1033
+ constexpr bool hasTransferringResult () const {
1034
+ return bits & TransferringResultMask;
1035
+ }
1036
+
1001
1037
constexpr DifferentiabilityKind getDifferentiabilityKind () const {
1002
1038
return DifferentiabilityKind ((bits & DifferentiabilityMask) >>
1003
1039
DifferentiabilityMaskOffset);
@@ -1101,11 +1137,13 @@ class SILExtInfoBuilder {
1101
1137
: (bits & ~SendableMask),
1102
1138
clangTypeInfo, lifetimeDependenceInfo);
1103
1139
}
1140
+
1104
1141
[[nodiscard]]
1105
1142
SILExtInfoBuilder withAsync (bool isAsync = true ) const {
1106
1143
return SILExtInfoBuilder (isAsync ? (bits | AsyncMask) : (bits & ~AsyncMask),
1107
1144
clangTypeInfo, lifetimeDependenceInfo);
1108
1145
}
1146
+
1109
1147
[[nodiscard]]
1110
1148
SILExtInfoBuilder withErasedIsolation (bool erased = true ) const {
1111
1149
return SILExtInfoBuilder (erased ? (bits | ErasedIsolationMask)
@@ -1128,6 +1166,15 @@ class SILExtInfoBuilder {
1128
1166
: (bits & ~UnimplementableMask),
1129
1167
clangTypeInfo, lifetimeDependenceInfo);
1130
1168
}
1169
+
1170
+ [[nodiscard]] SILExtInfoBuilder
1171
+ withTransferringResult (bool hasTransferringResult = true ) const {
1172
+ return SILExtInfoBuilder (hasTransferringResult
1173
+ ? (bits | TransferringResultMask)
1174
+ : (bits & ~TransferringResultMask),
1175
+ clangTypeInfo, lifetimeDependenceInfo);
1176
+ }
1177
+
1131
1178
[[nodiscard]]
1132
1179
SILExtInfoBuilder
1133
1180
withDifferentiabilityKind (DifferentiabilityKind differentiability) const {
@@ -1193,11 +1240,11 @@ class SILExtInfo {
1193
1240
1194
1241
// / A default ExtInfo but with a Thin convention.
1195
1242
static SILExtInfo getThin () {
1196
- return SILExtInfoBuilder (SILExtInfoBuilder::Representation::Thin, false ,
1197
- false , false , false , false ,
1198
- SILFunctionTypeIsolation::Unknown,
1199
- DifferentiabilityKind::NonDifferentiable, nullptr ,
1200
- LifetimeDependenceInfo ())
1243
+ return SILExtInfoBuilder (
1244
+ SILExtInfoBuilder::Representation::Thin , false , false , false ,
1245
+ false , false , SILFunctionTypeIsolation::Unknown,
1246
+ DifferentiabilityKind::NonDifferentiable, nullptr ,
1247
+ LifetimeDependenceInfo (), false /* transferring result */ )
1201
1248
.build ();
1202
1249
}
1203
1250
@@ -1235,6 +1282,10 @@ class SILExtInfo {
1235
1282
return builder.getIsolation ();
1236
1283
}
1237
1284
1285
+ constexpr bool hasTransferringResult () const {
1286
+ return builder.hasTransferringResult ();
1287
+ }
1288
+
1238
1289
constexpr DifferentiabilityKind getDifferentiabilityKind () const {
1239
1290
return builder.getDifferentiabilityKind ();
1240
1291
}
@@ -1281,6 +1332,10 @@ class SILExtInfo {
1281
1332
return builder.withUnimplementable (isUnimplementable).build ();
1282
1333
}
1283
1334
1335
+ SILExtInfo withTransferringResult (bool hasTransferringResult = true ) const {
1336
+ return builder.withTransferringResult (hasTransferringResult).build ();
1337
+ }
1338
+
1284
1339
void Profile (llvm::FoldingSetNodeID &ID) const { builder.Profile (ID); }
1285
1340
1286
1341
bool isEqualTo (SILExtInfo other, bool useClangTypes) const {
0 commit comments