Weak-Link the Immediate Re-Exports of a Weak-Linked Module

When a module is imported @_weakLinked, its re-exported peer modules
have their definitions imported with strong linkage which can often
defeat the point of weak linking the parent in the first place. Allow
the weak-linkage to float to the immediate re-exports of the @_weakLinked
module.

Resolves rdar://117166194
This commit is contained in:
Robert Widmann
2023-10-31 18:45:32 -06:00
parent e19954f981
commit 13140df3a4
2 changed files with 26 additions and 0 deletions

View File

@@ -3441,6 +3441,17 @@ bool SourceFile::importsModuleAsWeakLinked(const ModuleDecl *module) const {
importedModule->getUnderlyingModuleIfOverlay();
if (module == clangModule)
return true;
// Traverse the exported modules of this weakly-linked module to ensure
// that we weak-link declarations from its exported peers.
SmallVector<ImportedModule, 8> reexportedModules;
importedModule->getImportedModules(reexportedModules,
ModuleDecl::ImportFilterKind::Exported);
for (const ImportedModule &reexportedModule : reexportedModules) {
if (!module->isNonSwiftModule() &&
module == reexportedModule.importedModule)
return true;
}
}
return false;
}