@@ -104,6 +104,21 @@ static void printImports(raw_ostream &out,
104104 allImportFilter |= ModuleDecl::ImportFilterKind::Private;
105105 allImportFilter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
106106
107+ // With -experimental-spi-imports:
108+ // When printing the private swiftinterface file, print implementation-only
109+ // imports only if they are also SPI. First, list all implementation-only
110+ // imports and filter them later.
111+ llvm::SmallSet<ModuleDecl::ImportedModule, 4 ,
112+ ModuleDecl::OrderImportedModules> ioiImportSet;
113+ if (Opts.PrintSPIs && Opts.ExperimentalSPIImports ) {
114+ allImportFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
115+
116+ SmallVector<ModuleDecl::ImportedModule, 4 > ioiImport;
117+ M->getImportedModules (ioiImport,
118+ ModuleDecl::ImportFilterKind::ImplementationOnly);
119+ ioiImportSet.insert (ioiImport.begin (), ioiImport.end ());
120+ }
121+
107122 SmallVector<ModuleDecl::ImportedModule, 8 > allImports;
108123 M->getImportedModules (allImports, allImportFilter);
109124 ModuleDecl::removeDuplicateImports (allImports);
@@ -124,13 +139,21 @@ static void printImports(raw_ostream &out,
124139 continue ;
125140 }
126141
142+ llvm::SmallVector<Identifier, 4 > spis;
143+ M->lookupImportedSPIGroups (importedModule, spis);
144+
145+ // Only print implementation-only imports which have an SPI import.
146+ if (ioiImportSet.count (import )) {
147+ if (spis.empty ())
148+ continue ;
149+ out << " @_implementationOnly " ;
150+ }
151+
127152 if (publicImportSet.count (import ))
128153 out << " @_exported " ;
129154
130155 // SPI attribute on imports
131156 if (Opts.PrintSPIs ) {
132- SmallVector<Identifier, 4 > spis;
133- M->lookupImportedSPIGroups (importedModule, spis);
134157 for (auto spiName : spis)
135158 out << " @_spi(" << spiName << " ) " ;
136159 }
0 commit comments