File tree Expand file tree Collapse file tree 3 files changed +37
-7
lines changed Expand file tree Collapse file tree 3 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -1121,6 +1121,32 @@ class SILFunction
1121
1121
return false ;
1122
1122
}
1123
1123
1124
+ // / Returns true if this function belongs to a declaration that
1125
+ // / has `@_alwaysEmitIntoClient` attribute.
1126
+ bool markedAsAlwaysEmitIntoClient () const {
1127
+ if (!hasLocation ())
1128
+ return false ;
1129
+
1130
+ auto *V = getLocation ().getAsASTNode <ValueDecl>();
1131
+ return V && V->getAttrs ().hasAttribute <AlwaysEmitIntoClientAttr>();
1132
+ }
1133
+
1134
+ // / Returns true if this function belongs to a declaration that returns
1135
+ // / an opaque result type with one or more availability conditions that are
1136
+ // / allowed to produce a different underlying type at runtime.
1137
+ bool hasOpaqueResultTypeWithAvailabilityConditions () const {
1138
+ if (!hasLocation ())
1139
+ return false ;
1140
+
1141
+ if (auto *V = getLocation ().getAsASTNode <ValueDecl>()) {
1142
+ auto *opaqueResult = V->getOpaqueResultTypeDecl ();
1143
+ return opaqueResult &&
1144
+ opaqueResult->hasConditionallyAvailableSubstitutions ();
1145
+ }
1146
+
1147
+ return false ;
1148
+ }
1149
+
1124
1150
// ===--------------------------------------------------------------------===//
1125
1151
// Block List Access
1126
1152
// ===--------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -2232,18 +2232,15 @@ void IRGenSILFunction::emitSILFunction() {
2232
2232
IGM.IRGen .addDynamicReplacement (CurSILFn);
2233
2233
2234
2234
if (CurSILFn->getLinkage () == SILLinkage::Shared) {
2235
- if (auto *V = CurSILFn->getLocation (). getAsASTNode <ValueDecl>()) {
2236
- bool alwaysEmitIntoClient =
2237
- V-> getAttrs ().hasAttribute <AlwaysEmitIntoClientAttr >();
2235
+ if (CurSILFn->markedAsAlwaysEmitIntoClient () &&
2236
+ CurSILFn-> hasOpaqueResultTypeWithAvailabilityConditions ()) {
2237
+ auto *V = CurSILFn-> getLocation ().castToASTNode <ValueDecl >();
2238
2238
auto *opaqueResult = V->getOpaqueResultTypeDecl ();
2239
2239
// `@_alwaysEmitIntoClient` declaration with opaque result
2240
2240
// has to emit opaque type descriptor into client module
2241
2241
// when it has availability conditions because the underlying
2242
2242
// type in such cases is unknown until runtime.
2243
- if (alwaysEmitIntoClient && opaqueResult &&
2244
- opaqueResult->hasConditionallyAvailableSubstitutions ()) {
2245
- IGM.maybeEmitOpaqueTypeDecl (opaqueResult);
2246
- }
2243
+ IGM.maybeEmitOpaqueTypeDecl (opaqueResult);
2247
2244
}
2248
2245
}
2249
2246
Original file line number Diff line number Diff line change @@ -708,6 +708,13 @@ SILFunction::isPossiblyUsedExternally() const {
708
708
if (isDistributed () && isThunk ())
709
709
return true ;
710
710
711
+ // Declaration marked as `@_alwaysEmitIntoClient` that
712
+ // returns opaque result type with availability conditions
713
+ // has to be kept alive to emit opaque type metadata descriptor.
714
+ if (markedAsAlwaysEmitIntoClient () &&
715
+ hasOpaqueResultTypeWithAvailabilityConditions ())
716
+ return true ;
717
+
711
718
return swift::isPossiblyUsedExternally (linkage, getModule ().isWholeModule ());
712
719
}
713
720
You can’t perform that action at this time.
0 commit comments