@@ -79,6 +79,8 @@ class CrossModuleOptimization {
7979
8080 bool canSerializeType (SILType type);
8181
82+ bool canUseFromInline (DeclContext *declCtxt);
83+
8284 bool canUseFromInline (SILFunction *func);
8385
8486 bool shouldSerialize (SILFunction *F);
@@ -184,8 +186,7 @@ bool CrossModuleOptimization::canSerializeFunction(
184186 return iter->second ;
185187
186188 if (DeclContext *funcCtxt = function->getDeclContext ()) {
187- ModuleDecl *module = function->getModule ().getSwiftModule ();
188- if (!module ->canBeUsedForCrossModuleOptimization (funcCtxt))
189+ if (!canUseFromInline (funcCtxt))
189190 return false ;
190191 }
191192
@@ -335,7 +336,7 @@ bool CrossModuleOptimization::canSerializeType(SILType type) {
335336
336337 // Exclude types which are defined in an @_implementationOnly imported
337338 // module. Such modules are not transitively available.
338- if (!M. getSwiftModule ()-> canBeUsedForCrossModuleOptimization (subNT)) {
339+ if (!canUseFromInline (subNT)) {
339340 return true ;
340341 }
341342 }
@@ -364,10 +365,9 @@ static bool couldBeLinkedStatically(DeclContext *funcCtxt, SILModule &module) {
364365 return true ;
365366}
366367
367- // / Returns true if the function \p func can be used from a serialized function.
368- bool CrossModuleOptimization::canUseFromInline (SILFunction *function) {
369- DeclContext *funcCtxt = function->getDeclContext ();
370- if (funcCtxt && !M.getSwiftModule ()->canBeUsedForCrossModuleOptimization (funcCtxt))
368+ // / Returns true if the \p declCtxt can be used from a serialized function.
369+ bool CrossModuleOptimization::canUseFromInline (DeclContext *declCtxt) {
370+ if (!M.getSwiftModule ()->canBeUsedForCrossModuleOptimization (declCtxt))
371371 return false ;
372372
373373 // / If we are emitting a TBD file, the TBD file only contains public symbols
@@ -377,8 +377,18 @@ bool CrossModuleOptimization::canUseFromInline(SILFunction *function) {
377377 // / (potentially) linked statically. Unfortunately there is no way to find out
378378 // / if another module is linked statically or dynamically, so we have to be
379379 // / conservative here.
380- if (conservative && M.getOptions ().emitTBD && couldBeLinkedStatically (funcCtxt , M))
380+ if (conservative && M.getOptions ().emitTBD && couldBeLinkedStatically (declCtxt , M))
381381 return false ;
382+
383+ return true ;
384+ }
385+
386+ // / Returns true if the function \p func can be used from a serialized function.
387+ bool CrossModuleOptimization::canUseFromInline (SILFunction *function) {
388+ if (DeclContext *funcCtxt = function->getDeclContext ()) {
389+ if (!canUseFromInline (funcCtxt))
390+ return false ;
391+ }
382392
383393 switch (function->getLinkage ()) {
384394 case SILLinkage::PublicNonABI:
0 commit comments