@@ -120,6 +120,20 @@ class FunctionTypeIsolation {
120
120
}
121
121
};
122
122
123
+ // / For now, the kinds of isolation we carry on SIL function types
124
+ // / are significantly reduced compared to AST function types.
125
+ // / Isolation is not part of the SIL function model after the
126
+ // / early portion of the pipeline.
127
+ enum class SILFunctionTypeIsolation {
128
+ // / We don't normally record isolation in SIL function types,
129
+ // / so the empty case here is "unknown".
130
+ Unknown,
131
+
132
+ // / The isolation of the function has been statically erased.
133
+ // / This corresponds to @isolated(any).
134
+ Erased,
135
+ };
136
+
123
137
// MARK: - ClangTypeInfo
124
138
// / Wrapper class for storing a clang::Type in an (AST|SIL)ExtInfo.
125
139
class ClangTypeInfo {
@@ -893,7 +907,8 @@ class SILExtInfoBuilder {
893
907
DifferentiabilityMaskOffset = 9 ,
894
908
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
895
909
UnimplementableMask = 1 << 12 ,
896
- NumMaskBits = 13
910
+ ErasedIsolationMask = 1 << 13 ,
911
+ NumMaskBits = 14
897
912
};
898
913
899
914
unsigned bits; // Naturally sized for speed.
@@ -913,12 +928,15 @@ class SILExtInfoBuilder {
913
928
static constexpr unsigned makeBits (Representation rep, bool isPseudogeneric,
914
929
bool isNoEscape, bool isSendable,
915
930
bool isAsync, bool isUnimplementable,
931
+ SILFunctionTypeIsolation isolation,
916
932
DifferentiabilityKind diffKind) {
917
933
return ((unsigned )rep) | (isPseudogeneric ? PseudogenericMask : 0 ) |
918
934
(isNoEscape ? NoEscapeMask : 0 ) |
919
935
(isSendable ? SendableMask : 0 ) |
920
936
(isAsync ? AsyncMask : 0 ) |
921
937
(isUnimplementable ? UnimplementableMask : 0 ) |
938
+ (isolation == SILFunctionTypeIsolation::Erased
939
+ ? ErasedIsolationMask : 0 ) |
922
940
(((unsigned )diffKind << DifferentiabilityMaskOffset) &
923
941
DifferentiabilityMask);
924
942
}
@@ -929,22 +947,28 @@ class SILExtInfoBuilder {
929
947
SILExtInfoBuilder ()
930
948
: SILExtInfoBuilder(makeBits(SILFunctionTypeRepresentation::Thick, false ,
931
949
false , false , false , false ,
950
+ SILFunctionTypeIsolation::Unknown,
932
951
DifferentiabilityKind::NonDifferentiable),
933
952
ClangTypeInfo(nullptr ), LifetimeDependenceInfo()) {}
934
953
935
954
SILExtInfoBuilder (Representation rep, bool isPseudogeneric, bool isNoEscape,
936
955
bool isSendable, bool isAsync, bool isUnimplementable,
956
+ SILFunctionTypeIsolation isolation,
937
957
DifferentiabilityKind diffKind, const clang::Type *type,
938
958
LifetimeDependenceInfo lifetimeDependenceInfo)
939
959
: SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape, isSendable,
940
- isAsync, isUnimplementable, diffKind),
960
+ isAsync, isUnimplementable,
961
+ isolation, diffKind),
941
962
ClangTypeInfo(type), lifetimeDependenceInfo) {}
942
963
943
964
// Constructor for polymorphic type.
944
965
SILExtInfoBuilder (ASTExtInfoBuilder info, bool isPseudogeneric)
945
966
: SILExtInfoBuilder(makeBits(info.getSILRepresentation(), isPseudogeneric,
946
967
info.isNoEscape(), info.isSendable(),
947
968
info.isAsync(), /* unimplementable*/ false,
969
+ info.getIsolation().isErased()
970
+ ? SILFunctionTypeIsolation::Erased
971
+ : SILFunctionTypeIsolation::Unknown,
948
972
info.getDifferentiabilityKind()),
949
973
info.getClangTypeInfo(),
950
974
info.getLifetimeDependenceInfo()) {}
@@ -988,6 +1012,18 @@ class SILExtInfoBuilder {
988
1012
return bits & UnimplementableMask;
989
1013
}
990
1014
1015
+ // / Does this function type have erased isolation (i.e. is it the
1016
+ // / lowering of an @isolated(any) function type)?
1017
+ constexpr bool hasErasedIsolation () const {
1018
+ return bits & ErasedIsolationMask;
1019
+ }
1020
+
1021
+ constexpr SILFunctionTypeIsolation getIsolation () const {
1022
+ return hasErasedIsolation ()
1023
+ ? SILFunctionTypeIsolation::Erased
1024
+ : SILFunctionTypeIsolation::Unknown;
1025
+ }
1026
+
991
1027
// / Get the underlying ClangTypeInfo value.
992
1028
ClangTypeInfo getClangTypeInfo () const { return clangTypeInfo; }
993
1029
@@ -1071,6 +1107,22 @@ class SILExtInfoBuilder {
1071
1107
clangTypeInfo, lifetimeDependenceInfo);
1072
1108
}
1073
1109
[[nodiscard]]
1110
+ SILExtInfoBuilder withErasedIsolation (bool erased = true ) const {
1111
+ return SILExtInfoBuilder (erased ? (bits | ErasedIsolationMask)
1112
+ : (bits & ~ErasedIsolationMask),
1113
+ clangTypeInfo, lifetimeDependenceInfo);
1114
+ }
1115
+ [[nodiscard]]
1116
+ SILExtInfoBuilder withIsolation (SILFunctionTypeIsolation isolation) const {
1117
+ switch (isolation) {
1118
+ case SILFunctionTypeIsolation::Unknown:
1119
+ return *this ;
1120
+ case SILFunctionTypeIsolation::Erased:
1121
+ return withErasedIsolation (true );
1122
+ }
1123
+ llvm_unreachable (" bad kind" );
1124
+ }
1125
+ [[nodiscard]]
1074
1126
SILExtInfoBuilder withUnimplementable (bool isUnimplementable = true ) const {
1075
1127
return SILExtInfoBuilder (isUnimplementable ? (bits | UnimplementableMask)
1076
1128
: (bits & ~UnimplementableMask),
@@ -1143,6 +1195,7 @@ class SILExtInfo {
1143
1195
static SILExtInfo getThin () {
1144
1196
return SILExtInfoBuilder (SILExtInfoBuilder::Representation::Thin, false ,
1145
1197
false , false , false , false ,
1198
+ SILFunctionTypeIsolation::Unknown,
1146
1199
DifferentiabilityKind::NonDifferentiable, nullptr ,
1147
1200
LifetimeDependenceInfo ())
1148
1201
.build ();
@@ -1175,6 +1228,13 @@ class SILExtInfo {
1175
1228
return builder.isUnimplementable ();
1176
1229
}
1177
1230
1231
+ constexpr bool hasErasedIsolation () const {
1232
+ return builder.hasErasedIsolation ();
1233
+ }
1234
+ constexpr SILFunctionTypeIsolation getIsolation () const {
1235
+ return builder.getIsolation ();
1236
+ }
1237
+
1178
1238
constexpr DifferentiabilityKind getDifferentiabilityKind () const {
1179
1239
return builder.getDifferentiabilityKind ();
1180
1240
}
@@ -1213,6 +1273,10 @@ class SILExtInfo {
1213
1273
return builder.withAsync (isAsync).build ();
1214
1274
}
1215
1275
1276
+ SILExtInfo withErasedIsolation (bool erased = true ) const {
1277
+ return builder.withErasedIsolation (erased).build ();
1278
+ }
1279
+
1216
1280
SILExtInfo withUnimplementable (bool isUnimplementable = true ) const {
1217
1281
return builder.withUnimplementable (isUnimplementable).build ();
1218
1282
}
0 commit comments