mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SymbolGraphGen] only include the given symbol for qualified imports (#59852)
* only include the given symbol for qualified imports rdar://96309088 * re-exporting one type should not allow unrelated types to sneak in * ensure that children of re-exported types are also re-exported
This commit is contained in:
@@ -792,15 +792,33 @@ bool ModuleDecl::shouldCollectDisplayDecls() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void swift::collectParsedExportedImports(const ModuleDecl *M, SmallPtrSetImpl<ModuleDecl *> &Imports) {
|
||||
void swift::collectParsedExportedImports(const ModuleDecl *M,
|
||||
SmallPtrSetImpl<ModuleDecl *> &Imports,
|
||||
llvm::SmallDenseMap<ModuleDecl *, SmallPtrSet<Decl *, 4>, 4> &QualifiedImports) {
|
||||
for (const FileUnit *file : M->getFiles()) {
|
||||
if (const SourceFile *source = dyn_cast<SourceFile>(file)) {
|
||||
if (source->hasImports()) {
|
||||
for (auto import : source->getImports()) {
|
||||
if (import.options.contains(ImportFlags::Exported) &&
|
||||
!Imports.contains(import.module.importedModule) &&
|
||||
import.module.importedModule->shouldCollectDisplayDecls()) {
|
||||
Imports.insert(import.module.importedModule);
|
||||
auto *TheModule = import.module.importedModule;
|
||||
|
||||
if (import.module.getAccessPath().size() > 0) {
|
||||
if (QualifiedImports.find(TheModule) == QualifiedImports.end()) {
|
||||
QualifiedImports.try_emplace(TheModule);
|
||||
}
|
||||
auto collectDecls = [&](ValueDecl *VD,
|
||||
DeclVisibilityKind reason) {
|
||||
if (reason == DeclVisibilityKind::VisibleAtTopLevel)
|
||||
QualifiedImports[TheModule].insert(VD);
|
||||
};
|
||||
auto consumer = makeDeclConsumer(std::move(collectDecls));
|
||||
TheModule->lookupVisibleDecls(
|
||||
import.module.getAccessPath(), consumer,
|
||||
NLKind::UnqualifiedLookup);
|
||||
} else if (!Imports.contains(TheModule)) {
|
||||
Imports.insert(TheModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -956,7 +974,12 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
|
||||
void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results, bool Recursive) const {
|
||||
if (Recursive && isParsedModule(this)) {
|
||||
SmallPtrSet<ModuleDecl *, 4> Modules;
|
||||
collectParsedExportedImports(this, Modules);
|
||||
llvm::SmallDenseMap<ModuleDecl *, SmallPtrSet<Decl *, 4>, 4> QualifiedImports;
|
||||
collectParsedExportedImports(this, Modules, QualifiedImports);
|
||||
for (const auto &QI : QualifiedImports) {
|
||||
auto &Decls = QI.getSecond();
|
||||
Results.append(Decls.begin(), Decls.end());
|
||||
}
|
||||
for (const ModuleDecl *import : Modules) {
|
||||
import->getDisplayDecls(Results, Recursive);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user