@@ -69,15 +69,24 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
69
69
out << " -module-alias " << MODULE_DISAMBIGUATING_PREFIX <<
70
70
moduleName << " =" << moduleName;
71
71
72
- SmallVector<ImportedModule> imports;
73
- M->getImportedModules (imports,
74
- {ModuleDecl::ImportFilterKind::Default,
72
+ ModuleDecl::ImportFilter filter = {ModuleDecl::ImportFilterKind::Default,
75
73
ModuleDecl::ImportFilterKind::Exported,
76
- ModuleDecl::ImportFilterKind::SPIOnly,
77
- ModuleDecl::ImportFilterKind::SPIAccessControl});
74
+ ModuleDecl::ImportFilterKind::SPIAccessControl};
75
+ if (Opts.PrintPrivateInterfaceContent )
76
+ filter |= ModuleDecl::ImportFilterKind::SPIOnly;
77
+
78
+ SmallVector<ImportedModule> imports;
79
+ M->getImportedModules (imports, filter);
78
80
M->getMissingImportedModules (imports);
81
+
79
82
for (ImportedModule import : imports) {
80
83
StringRef importedName = import .importedModule ->getNameStr ();
84
+ // Skip Swift as it's commonly used in inlinable code,
85
+ // and Builtin as it's imported implicitly by name.
86
+ if (importedName == STDLIB_NAME ||
87
+ importedName == BUILTIN_NAME)
88
+ continue ;
89
+
81
90
if (AliasModuleNamesTargets.insert (importedName).second ) {
82
91
out << " -module-alias " << MODULE_DISAMBIGUATING_PREFIX <<
83
92
importedName << " =" << importedName;
@@ -212,7 +221,9 @@ static void diagnoseScopedImports(DiagnosticEngine &diags,
212
221
// / source declarations.
213
222
static void printImports (raw_ostream &out,
214
223
ModuleInterfaceOptions const &Opts,
215
- ModuleDecl *M) {
224
+ ModuleDecl *M,
225
+ const llvm::SmallSet<StringRef, 4 >
226
+ &AliasModuleNamesTargets) {
216
227
// FIXME: This is very similar to what's in Serializer::writeInputBlock, but
217
228
// it's not obvious what higher-level optimization would be factored out here.
218
229
ModuleDecl::ImportFilter allImportFilter = {
@@ -322,7 +333,8 @@ static void printImports(raw_ostream &out,
322
333
}
323
334
324
335
out << " import " ;
325
- if (Opts.AliasModuleNames )
336
+ if (Opts.AliasModuleNames &&
337
+ AliasModuleNamesTargets.contains (importedModule->getName ().str ()))
326
338
out << MODULE_DISAMBIGUATING_PREFIX;
327
339
importedModule->getReverseFullModuleName ().printForward (out);
328
340
@@ -786,7 +798,7 @@ bool swift::emitSwiftInterface(raw_ostream &out,
786
798
llvm::SmallSet<StringRef, 4 > aliasModuleNamesTargets;
787
799
printToolVersionAndFlagsComment (out, Opts, M, aliasModuleNamesTargets);
788
800
789
- printImports (out, Opts, M);
801
+ printImports (out, Opts, M, aliasModuleNamesTargets );
790
802
791
803
static bool forceUseExportedModuleNameInPublicOnly =
792
804
getenv (" SWIFT_DEBUG_USE_EXPORTED_MODULE_NAME_IN_PUBLIC_ONLY" );
0 commit comments