@@ -120,6 +120,20 @@ class FunctionTypeIsolation {
120120 }
121121};
122122
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+
123137// MARK: - ClangTypeInfo
124138// / Wrapper class for storing a clang::Type in an (AST|SIL)ExtInfo.
125139class ClangTypeInfo {
@@ -893,7 +907,8 @@ class SILExtInfoBuilder {
893907 DifferentiabilityMaskOffset = 9 ,
894908 DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
895909 UnimplementableMask = 1 << 12 ,
896- NumMaskBits = 13
910+ ErasedIsolationMask = 1 << 13 ,
911+ NumMaskBits = 14
897912 };
898913
899914 unsigned bits; // Naturally sized for speed.
@@ -913,12 +928,15 @@ class SILExtInfoBuilder {
913928 static constexpr unsigned makeBits (Representation rep, bool isPseudogeneric,
914929 bool isNoEscape, bool isSendable,
915930 bool isAsync, bool isUnimplementable,
931+ SILFunctionTypeIsolation isolation,
916932 DifferentiabilityKind diffKind) {
917933 return ((unsigned )rep) | (isPseudogeneric ? PseudogenericMask : 0 ) |
918934 (isNoEscape ? NoEscapeMask : 0 ) |
919935 (isSendable ? SendableMask : 0 ) |
920936 (isAsync ? AsyncMask : 0 ) |
921937 (isUnimplementable ? UnimplementableMask : 0 ) |
938+ (isolation == SILFunctionTypeIsolation::Erased
939+ ? ErasedIsolationMask : 0 ) |
922940 (((unsigned )diffKind << DifferentiabilityMaskOffset) &
923941 DifferentiabilityMask);
924942 }
@@ -929,22 +947,28 @@ class SILExtInfoBuilder {
929947 SILExtInfoBuilder ()
930948 : SILExtInfoBuilder(makeBits(SILFunctionTypeRepresentation::Thick, false ,
931949 false , false , false , false ,
950+ SILFunctionTypeIsolation::Unknown,
932951 DifferentiabilityKind::NonDifferentiable),
933952 ClangTypeInfo(nullptr ), LifetimeDependenceInfo()) {}
934953
935954 SILExtInfoBuilder (Representation rep, bool isPseudogeneric, bool isNoEscape,
936955 bool isSendable, bool isAsync, bool isUnimplementable,
956+ SILFunctionTypeIsolation isolation,
937957 DifferentiabilityKind diffKind, const clang::Type *type,
938958 LifetimeDependenceInfo lifetimeDependenceInfo)
939959 : SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape, isSendable,
940- isAsync, isUnimplementable, diffKind),
960+ isAsync, isUnimplementable,
961+ isolation, diffKind),
941962 ClangTypeInfo(type), lifetimeDependenceInfo) {}
942963
943964 // Constructor for polymorphic type.
944965 SILExtInfoBuilder (ASTExtInfoBuilder info, bool isPseudogeneric)
945966 : SILExtInfoBuilder(makeBits(info.getSILRepresentation(), isPseudogeneric,
946967 info.isNoEscape(), info.isSendable(),
947968 info.isAsync(), /* unimplementable*/ false,
969+ info.getIsolation().isErased()
970+ ? SILFunctionTypeIsolation::Erased
971+ : SILFunctionTypeIsolation::Unknown,
948972 info.getDifferentiabilityKind()),
949973 info.getClangTypeInfo(),
950974 info.getLifetimeDependenceInfo()) {}
@@ -988,6 +1012,18 @@ class SILExtInfoBuilder {
9881012 return bits & UnimplementableMask;
9891013 }
9901014
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+
9911027 // / Get the underlying ClangTypeInfo value.
9921028 ClangTypeInfo getClangTypeInfo () const { return clangTypeInfo; }
9931029
@@ -1071,6 +1107,22 @@ class SILExtInfoBuilder {
10711107 clangTypeInfo, lifetimeDependenceInfo);
10721108 }
10731109 [[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]]
10741126 SILExtInfoBuilder withUnimplementable (bool isUnimplementable = true ) const {
10751127 return SILExtInfoBuilder (isUnimplementable ? (bits | UnimplementableMask)
10761128 : (bits & ~UnimplementableMask),
@@ -1143,6 +1195,7 @@ class SILExtInfo {
11431195 static SILExtInfo getThin () {
11441196 return SILExtInfoBuilder (SILExtInfoBuilder::Representation::Thin, false ,
11451197 false , false , false , false ,
1198+ SILFunctionTypeIsolation::Unknown,
11461199 DifferentiabilityKind::NonDifferentiable, nullptr ,
11471200 LifetimeDependenceInfo ())
11481201 .build ();
@@ -1175,6 +1228,13 @@ class SILExtInfo {
11751228 return builder.isUnimplementable ();
11761229 }
11771230
1231+ constexpr bool hasErasedIsolation () const {
1232+ return builder.hasErasedIsolation ();
1233+ }
1234+ constexpr SILFunctionTypeIsolation getIsolation () const {
1235+ return builder.getIsolation ();
1236+ }
1237+
11781238 constexpr DifferentiabilityKind getDifferentiabilityKind () const {
11791239 return builder.getDifferentiabilityKind ();
11801240 }
@@ -1213,6 +1273,10 @@ class SILExtInfo {
12131273 return builder.withAsync (isAsync).build ();
12141274 }
12151275
1276+ SILExtInfo withErasedIsolation (bool erased = true ) const {
1277+ return builder.withErasedIsolation (erased).build ();
1278+ }
1279+
12161280 SILExtInfo withUnimplementable (bool isUnimplementable = true ) const {
12171281 return builder.withUnimplementable (isUnimplementable).build ();
12181282 }
0 commit comments