21
21
#define SWIFT_EXTINFO_H
22
22
23
23
#include " swift/AST/AutoDiff.h"
24
+ #include " swift/AST/LifetimeDependence.h"
24
25
25
26
#include " llvm/ADT/None.h"
26
27
#include " llvm/ADT/Optional.h"
@@ -157,27 +158,6 @@ class ClangTypeInfo {
157
158
void dump (llvm::raw_ostream &os, const clang::ASTContext &ctx) const ;
158
159
};
159
160
160
- class LifetimeDependenceInfo {
161
- IndexSubset *copyLifetimeParamIndices;
162
- IndexSubset *borrowLifetimeParamIndices;
163
-
164
- public:
165
- LifetimeDependenceInfo ()
166
- : copyLifetimeParamIndices(nullptr ), borrowLifetimeParamIndices(nullptr ) {
167
- }
168
- LifetimeDependenceInfo (IndexSubset *copyLifetimeParamIndices,
169
- IndexSubset *borrowLifetimeParamIndices)
170
- : copyLifetimeParamIndices(copyLifetimeParamIndices),
171
- borrowLifetimeParamIndices (borrowLifetimeParamIndices) {}
172
-
173
- operator bool () const { return empty (); }
174
-
175
- bool empty () const {
176
- return copyLifetimeParamIndices == nullptr &&
177
- borrowLifetimeParamIndices == nullptr ;
178
- }
179
- };
180
-
181
161
// MARK: - UnexpectedClangTypeError
182
162
// / Potential errors when trying to store a Clang type in an ExtInfo.
183
163
struct UnexpectedClangTypeError {
@@ -684,20 +664,21 @@ class ASTExtInfoBuilder {
684
664
lifetimeDependenceInfo);
685
665
}
686
666
667
+ void Profile (llvm::FoldingSetNodeID &ID) const {
668
+ ID.AddInteger (bits);
669
+ ID.AddPointer (clangTypeInfo.getType ());
670
+ ID.AddPointer (globalActor.getPointer ());
671
+ ID.AddPointer (thrownError.getPointer ());
672
+ lifetimeDependenceInfo.Profile (ID);
673
+ }
674
+
687
675
bool isEqualTo (ASTExtInfoBuilder other, bool useClangTypes) const {
688
676
return bits == other.bits &&
689
677
(useClangTypes ? (clangTypeInfo == other.clangTypeInfo ) : true ) &&
690
678
globalActor.getPointer () == other.globalActor .getPointer () &&
691
679
thrownError.getPointer () == other.thrownError .getPointer () &&
692
680
lifetimeDependenceInfo == other.lifetimeDependenceInfo ;
693
681
}
694
-
695
- constexpr std::tuple<unsigned , const void *, const void *, const void *>
696
- getFuncAttrKey () const {
697
- return std::make_tuple (
698
- bits, clangTypeInfo.getType (), globalActor.getPointer (),
699
- thrownError.getPointer ());
700
- }
701
682
}; // end ASTExtInfoBuilder
702
683
703
684
// MARK: - ASTExtInfo
@@ -844,14 +825,11 @@ class ASTExtInfo {
844
825
return builder.withLifetimeDependenceInfo (lifetimeDependenceInfo).build ();
845
826
}
846
827
828
+ void Profile (llvm::FoldingSetNodeID &ID) const { builder.Profile (ID); }
829
+
847
830
bool isEqualTo (ASTExtInfo other, bool useClangTypes) const {
848
831
return builder.isEqualTo (other.builder , useClangTypes);
849
832
}
850
-
851
- constexpr std::tuple<unsigned , const void *, const void *, const void *>
852
- getFuncAttrKey () const {
853
- return builder.getFuncAttrKey ();
854
- }
855
833
}; // end ASTExtInfo
856
834
857
835
// MARK: - SILFunctionLanguage
@@ -922,11 +900,15 @@ class SILExtInfoBuilder {
922
900
923
901
ClangTypeInfo clangTypeInfo;
924
902
903
+ LifetimeDependenceInfo lifetimeDependenceInfo;
904
+
925
905
using Language = SILFunctionLanguage;
926
906
using Representation = SILFunctionTypeRepresentation;
927
907
928
- SILExtInfoBuilder (unsigned bits, ClangTypeInfo clangTypeInfo)
929
- : bits(bits), clangTypeInfo(clangTypeInfo.getCanonical()) {}
908
+ SILExtInfoBuilder (unsigned bits, ClangTypeInfo clangTypeInfo,
909
+ LifetimeDependenceInfo lifetimeDependenceInfo)
910
+ : bits(bits), clangTypeInfo(clangTypeInfo.getCanonical()),
911
+ lifetimeDependenceInfo (lifetimeDependenceInfo) {}
930
912
931
913
static constexpr unsigned makeBits (Representation rep, bool isPseudogeneric,
932
914
bool isNoEscape, bool isSendable,
@@ -948,23 +930,24 @@ class SILExtInfoBuilder {
948
930
: SILExtInfoBuilder(makeBits(SILFunctionTypeRepresentation::Thick, false ,
949
931
false , false , false , false ,
950
932
DifferentiabilityKind::NonDifferentiable),
951
- ClangTypeInfo (nullptr )) {}
933
+ ClangTypeInfo(nullptr ), LifetimeDependenceInfo() ) {}
952
934
953
935
SILExtInfoBuilder (Representation rep, bool isPseudogeneric, bool isNoEscape,
954
936
bool isSendable, bool isAsync, bool isUnimplementable,
955
- DifferentiabilityKind diffKind, const clang::Type *type)
956
- : SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape,
957
- isSendable, isAsync, isUnimplementable ,
958
- diffKind),
959
- ClangTypeInfo(type)) {}
937
+ DifferentiabilityKind diffKind, const clang::Type *type,
938
+ LifetimeDependenceInfo lifetimeDependenceInfo)
939
+ : SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape, isSendable ,
940
+ isAsync, isUnimplementable, diffKind),
941
+ ClangTypeInfo(type), lifetimeDependenceInfo ) {}
960
942
961
943
// Constructor for polymorphic type.
962
944
SILExtInfoBuilder (ASTExtInfoBuilder info, bool isPseudogeneric)
963
945
: SILExtInfoBuilder(makeBits(info.getSILRepresentation(), isPseudogeneric,
964
946
info.isNoEscape(), info.isSendable(),
965
947
info.isAsync(), /* unimplementable*/ false,
966
948
info.getDifferentiabilityKind()),
967
- info.getClangTypeInfo()) {}
949
+ info.getClangTypeInfo(),
950
+ info.getLifetimeDependenceInfo()) {}
968
951
969
952
void checkInvariants () const ;
970
953
@@ -1008,6 +991,10 @@ class SILExtInfoBuilder {
1008
991
// / Get the underlying ClangTypeInfo value.
1009
992
ClangTypeInfo getClangTypeInfo () const { return clangTypeInfo; }
1010
993
994
+ LifetimeDependenceInfo getLifetimeDependenceInfo () const {
995
+ return lifetimeDependenceInfo;
996
+ }
997
+
1011
998
constexpr bool hasSelfParam () const {
1012
999
switch (getRepresentation ()) {
1013
1000
case Representation::Thick:
@@ -1057,59 +1044,66 @@ class SILExtInfoBuilder {
1057
1044
SILExtInfoBuilder withRepresentation (Representation rep) const {
1058
1045
return SILExtInfoBuilder ((bits & ~RepresentationMask) | (unsigned )rep,
1059
1046
shouldStoreClangType (rep) ? clangTypeInfo
1060
- : ClangTypeInfo ());
1047
+ : ClangTypeInfo (),
1048
+ lifetimeDependenceInfo);
1061
1049
}
1062
1050
[[nodiscard]]
1063
1051
SILExtInfoBuilder withIsPseudogeneric (bool isPseudogeneric = true ) const {
1064
1052
return SILExtInfoBuilder (isPseudogeneric ? (bits | PseudogenericMask)
1065
1053
: (bits & ~PseudogenericMask),
1066
- clangTypeInfo);
1054
+ clangTypeInfo, lifetimeDependenceInfo );
1067
1055
}
1068
1056
[[nodiscard]]
1069
1057
SILExtInfoBuilder withNoEscape (bool noEscape = true ) const {
1070
1058
return SILExtInfoBuilder (noEscape ? (bits | NoEscapeMask)
1071
1059
: (bits & ~NoEscapeMask),
1072
- clangTypeInfo);
1060
+ clangTypeInfo, lifetimeDependenceInfo );
1073
1061
}
1074
1062
[[nodiscard]]
1075
1063
SILExtInfoBuilder withConcurrent (bool isSendable = true ) const {
1076
1064
return SILExtInfoBuilder (isSendable ? (bits | SendableMask)
1077
- : (bits & ~SendableMask),
1078
- clangTypeInfo);
1065
+ : (bits & ~SendableMask),
1066
+ clangTypeInfo, lifetimeDependenceInfo );
1079
1067
}
1080
1068
[[nodiscard]]
1081
1069
SILExtInfoBuilder withAsync (bool isAsync = true ) const {
1082
1070
return SILExtInfoBuilder (isAsync ? (bits | AsyncMask) : (bits & ~AsyncMask),
1083
- clangTypeInfo);
1071
+ clangTypeInfo, lifetimeDependenceInfo );
1084
1072
}
1085
1073
[[nodiscard]]
1086
1074
SILExtInfoBuilder withUnimplementable (bool isUnimplementable = true ) const {
1087
1075
return SILExtInfoBuilder (isUnimplementable ? (bits | UnimplementableMask)
1088
1076
: (bits & ~UnimplementableMask),
1089
- clangTypeInfo);
1077
+ clangTypeInfo, lifetimeDependenceInfo );
1090
1078
}
1091
1079
[[nodiscard]]
1092
1080
SILExtInfoBuilder
1093
1081
withDifferentiabilityKind (DifferentiabilityKind differentiability) const {
1094
1082
return SILExtInfoBuilder (
1095
1083
(bits & ~DifferentiabilityMask) |
1096
1084
((unsigned )differentiability << DifferentiabilityMaskOffset),
1097
- clangTypeInfo);
1085
+ clangTypeInfo, lifetimeDependenceInfo );
1098
1086
}
1099
1087
[[nodiscard]]
1100
1088
SILExtInfoBuilder withClangFunctionType (const clang::Type *type) const {
1101
- return SILExtInfoBuilder (bits, ClangTypeInfo (type).getCanonical ());
1089
+ return SILExtInfoBuilder (bits, ClangTypeInfo (type).getCanonical (),
1090
+ lifetimeDependenceInfo);
1091
+ }
1092
+ [[nodiscard]] SILExtInfoBuilder withLifetimeDependenceInfo (
1093
+ LifetimeDependenceInfo lifetimeDependenceInfo) const {
1094
+ return SILExtInfoBuilder (bits, clangTypeInfo, lifetimeDependenceInfo);
1102
1095
}
1103
1096
1097
+ void Profile (llvm::FoldingSetNodeID &ID) const {
1098
+ ID.AddInteger (bits);
1099
+ ID.AddPointer (clangTypeInfo.getType ());
1100
+ lifetimeDependenceInfo.Profile (ID);
1101
+ }
1104
1102
1105
1103
bool isEqualTo (SILExtInfoBuilder other, bool useClangTypes) const {
1106
1104
return bits == other.bits &&
1107
1105
(useClangTypes ? (clangTypeInfo == other.clangTypeInfo ) : true );
1108
1106
}
1109
-
1110
- constexpr std::pair<unsigned , const void *> getFuncAttrKey () const {
1111
- return std::make_pair (bits, clangTypeInfo.getType ());
1112
- }
1113
1107
}; // end SILExtInfoBuilder
1114
1108
1115
1109
// MARK: - SILExtInfo
@@ -1129,8 +1123,9 @@ class SILExtInfo {
1129
1123
// Only for use by SILExtInfoBuilder::build. Don't use it elsewhere!
1130
1124
SILExtInfo (SILExtInfoBuilder builder) : builder(builder) {}
1131
1125
1132
- SILExtInfo (unsigned bits, ClangTypeInfo clangTypeInfo)
1133
- : builder(bits, clangTypeInfo) {
1126
+ SILExtInfo (unsigned bits, ClangTypeInfo clangTypeInfo,
1127
+ LifetimeDependenceInfo lifetimeDependenceInfo)
1128
+ : builder(bits, clangTypeInfo, lifetimeDependenceInfo) {
1134
1129
builder.checkInvariants ();
1135
1130
};
1136
1131
@@ -1148,7 +1143,8 @@ class SILExtInfo {
1148
1143
static SILExtInfo getThin () {
1149
1144
return SILExtInfoBuilder (SILExtInfoBuilder::Representation::Thin, false ,
1150
1145
false , false , false , false ,
1151
- DifferentiabilityKind::NonDifferentiable, nullptr )
1146
+ DifferentiabilityKind::NonDifferentiable, nullptr ,
1147
+ LifetimeDependenceInfo ())
1152
1148
.build ();
1153
1149
}
1154
1150
@@ -1187,6 +1183,10 @@ class SILExtInfo {
1187
1183
1188
1184
ClangTypeInfo getClangTypeInfo () const { return builder.getClangTypeInfo (); }
1189
1185
1186
+ LifetimeDependenceInfo getLifetimeDependenceInfo () const {
1187
+ return builder.getLifetimeDependenceInfo ();
1188
+ }
1189
+
1190
1190
constexpr bool hasSelfParam () const { return builder.hasSelfParam (); }
1191
1191
1192
1192
constexpr bool hasContext () const { return builder.hasContext (); }
@@ -1217,14 +1217,12 @@ class SILExtInfo {
1217
1217
return builder.withUnimplementable (isUnimplementable).build ();
1218
1218
}
1219
1219
1220
+ void Profile (llvm::FoldingSetNodeID &ID) const { builder.Profile (ID); }
1221
+
1220
1222
bool isEqualTo (SILExtInfo other, bool useClangTypes) const {
1221
1223
return builder.isEqualTo (other.builder , useClangTypes);
1222
1224
}
1223
1225
1224
- constexpr std::pair<unsigned , const void *> getFuncAttrKey () const {
1225
- return builder.getFuncAttrKey ();
1226
- }
1227
-
1228
1226
llvm::Optional<UnexpectedClangTypeError> checkClangType () const ;
1229
1227
};
1230
1228
0 commit comments