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 @@ -2221,18 +2221,15 @@ void IRGenSILFunction::emitSILFunction() {
2221
2221
IGM.IRGen .addDynamicReplacement (CurSILFn);
2222
2222
2223
2223
if (CurSILFn->getLinkage () == SILLinkage::Shared) {
2224
- if (auto *V = CurSILFn->getLocation (). getAsASTNode <ValueDecl>()) {
2225
- bool alwaysEmitIntoClient =
2226
- V-> getAttrs ().hasAttribute <AlwaysEmitIntoClientAttr >();
2224
+ if (CurSILFn->markedAsAlwaysEmitIntoClient () &&
2225
+ CurSILFn-> hasOpaqueResultTypeWithAvailabilityConditions ()) {
2226
+ auto *V = CurSILFn-> getLocation ().castToASTNode <ValueDecl >();
2227
2227
auto *opaqueResult = V->getOpaqueResultTypeDecl ();
2228
2228
// `@_alwaysEmitIntoClient` declaration with opaque result
2229
2229
// has to emit opaque type descriptor into client module
2230
2230
// when it has availability conditions because the underlying
2231
2231
// type in such cases is unknown until runtime.
2232
- if (alwaysEmitIntoClient && opaqueResult &&
2233
- opaqueResult->hasConditionallyAvailableSubstitutions ()) {
2234
- IGM.maybeEmitOpaqueTypeDecl (opaqueResult);
2235
- }
2232
+ IGM.maybeEmitOpaqueTypeDecl (opaqueResult);
2236
2233
}
2237
2234
}
2238
2235
Original file line number Diff line number Diff line change @@ -704,6 +704,13 @@ SILFunction::isPossiblyUsedExternally() const {
704
704
if (isDistributed () && isThunk ())
705
705
return true ;
706
706
707
+ // Declaration marked as `@_alwaysEmitIntoClient` that
708
+ // returns opaque result type with availability conditions
709
+ // has to be kept alive to emit opaque type metadata descriptor.
710
+ if (markedAsAlwaysEmitIntoClient () &&
711
+ hasOpaqueResultTypeWithAvailabilityConditions ())
712
+ return true ;
713
+
707
714
return swift::isPossiblyUsedExternally (linkage, getModule ().isWholeModule ());
708
715
}
709
716
You can’t perform that action at this time.
0 commit comments