@@ -639,8 +639,9 @@ void ModuleDecl::lookupObjCMethods(
639
639
FORWARD (lookupObjCMethods, (selector, results));
640
640
}
641
641
642
- void ModuleDecl::lookupImportedSPIGroups (const ModuleDecl *importedModule,
643
- SmallVectorImpl<Identifier> &spiGroups) const {
642
+ void ModuleDecl::lookupImportedSPIGroups (
643
+ const ModuleDecl *importedModule,
644
+ llvm::SmallSetVector<Identifier, 4 > &spiGroups) const {
644
645
FORWARD (lookupImportedSPIGroups, (importedModule, spiGroups));
645
646
}
646
647
@@ -2190,31 +2191,50 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
2190
2191
return !imports.isImportedBy (module, getParentModule ());
2191
2192
}
2192
2193
2193
- void SourceFile::lookupImportedSPIGroups (const ModuleDecl *importedModule,
2194
- SmallVectorImpl<Identifier> &spiGroups) const {
2194
+ bool ModuleDecl::isImportedImplementationOnly (const ModuleDecl *module) const {
2195
+ auto &imports = getASTContext ().getImportCache ();
2196
+
2197
+ // Look through non-implementation-only imports to see if module is imported
2198
+ // in some other way. Otherwise we assume it's implementation-only imported.
2199
+ ModuleDecl::ImportFilter filter;
2200
+ filter |= ModuleDecl::ImportFilterKind::Public;
2201
+ filter |= ModuleDecl::ImportFilterKind::Private;
2202
+ filter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
2203
+ filter |= ModuleDecl::ImportFilterKind::ShadowedBySeparateOverlay;
2204
+ SmallVector<ModuleDecl::ImportedModule, 4 > results;
2205
+ getImportedModules (results, filter);
2206
+
2207
+ for (auto &desc : results) {
2208
+ if (imports.isImportedBy (module, desc.second ))
2209
+ return false ;
2210
+ }
2211
+
2212
+ return true ;
2213
+ }
2214
+
2215
+ void SourceFile::lookupImportedSPIGroups (
2216
+ const ModuleDecl *importedModule,
2217
+ llvm::SmallSetVector<Identifier, 4 > &spiGroups) const {
2195
2218
for (auto &import : Imports) {
2196
2219
if (import.importOptions .contains (ImportFlags::SPIAccessControl) &&
2197
2220
importedModule == std::get<ModuleDecl*>(import.module )) {
2198
2221
auto importedSpis = import.spiGroups ;
2199
- spiGroups.append (importedSpis.begin (), importedSpis.end ());
2222
+ spiGroups.insert (importedSpis.begin (), importedSpis.end ());
2200
2223
}
2201
2224
}
2202
2225
}
2203
2226
2204
2227
bool SourceFile::isImportedAsSPI (const ValueDecl *targetDecl) const {
2205
2228
auto targetModule = targetDecl->getModuleContext ();
2206
- SmallVector <Identifier, 4 > importedSPIGroups;
2229
+ llvm::SmallSetVector <Identifier, 4 > importedSPIGroups;
2207
2230
lookupImportedSPIGroups (targetModule, importedSPIGroups);
2208
2231
if (importedSPIGroups.empty ()) return false ;
2209
2232
2210
2233
auto declSPIGroups = targetDecl->getSPIGroups ();
2211
2234
2212
- // Note: If we reach a point where there are many SPI imports or SPI groups
2213
- // on decls we could optimize this further by using a set.
2214
- for (auto importedSPI : importedSPIGroups)
2215
- for (auto declSPI : declSPIGroups)
2216
- if (importedSPI == declSPI)
2217
- return true ;
2235
+ for (auto declSPI : declSPIGroups)
2236
+ if (importedSPIGroups.count (declSPI))
2237
+ return true ;
2218
2238
2219
2239
return false ;
2220
2240
}
0 commit comments