@@ -104,6 +104,21 @@ static void printImports(raw_ostream &out,
104
104
allImportFilter |= ModuleDecl::ImportFilterKind::Private;
105
105
allImportFilter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
106
106
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
+
107
122
SmallVector<ModuleDecl::ImportedModule, 8 > allImports;
108
123
M->getImportedModules (allImports, allImportFilter);
109
124
ModuleDecl::removeDuplicateImports (allImports);
@@ -124,13 +139,21 @@ static void printImports(raw_ostream &out,
124
139
continue ;
125
140
}
126
141
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
+
127
152
if (publicImportSet.count (import ))
128
153
out << " @_exported " ;
129
154
130
155
// SPI attribute on imports
131
156
if (Opts.PrintSPIs ) {
132
- SmallVector<Identifier, 4 > spis;
133
- M->lookupImportedSPIGroups (importedModule, spis);
134
157
for (auto spiName : spis)
135
158
out << " @_spi(" << spiName << " ) " ;
136
159
}
0 commit comments