@@ -780,6 +780,22 @@ void SourceFile::lookupObjCMethods(
780780 results.append (known->second .begin (), known->second .end ());
781781}
782782
783+ static void collectParsedExportedImports (const ModuleDecl *M, SmallPtrSetImpl<ModuleDecl *> &Imports) {
784+ for (const FileUnit *file : M->getFiles ()) {
785+ if (const SourceFile *source = dyn_cast<SourceFile>(file)) {
786+ if (source->hasImports ()) {
787+ for (auto import : source->getImports ()) {
788+ if (import .options .contains (ImportFlags::Exported)) {
789+ if (!Imports.contains (import .module .importedModule )) {
790+ Imports.insert (import .module .importedModule );
791+ }
792+ }
793+ }
794+ }
795+ }
796+ }
797+ }
798+
783799void ModuleDecl::getLocalTypeDecls (SmallVectorImpl<TypeDecl*> &Results) const {
784800 FORWARD (getLocalTypeDecls, (Results));
785801}
@@ -822,17 +838,6 @@ void SourceFile::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
822838 Results.append (decls.begin (), decls.end ());
823839}
824840
825- void SourceFile::getDisplayDecls (SmallVectorImpl<Decl*> &Results) const {
826- if (Imports.hasValue ()) {
827- for (auto import : *Imports) {
828- if (import .options .contains (ImportFlags::Exported)) {
829- import .module .importedModule ->getDisplayDecls (Results);
830- }
831- }
832- }
833- getTopLevelDecls (Results);
834- }
835-
836841void ModuleDecl::getOperatorDecls (
837842 SmallVectorImpl<OperatorDecl *> &results) const {
838843 // For a parsed module, we can check the source cache on the module rather
@@ -937,8 +942,23 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
937942}
938943
939944void ModuleDecl::getDisplayDecls (SmallVectorImpl<Decl*> &Results) const {
945+ if (isParsedModule (this )) {
946+ SmallPtrSet<ModuleDecl *, 4 > Modules;
947+ collectParsedExportedImports (this , Modules);
948+ for (const ModuleDecl *import : Modules) {
949+ import ->getDisplayDecls (Results);
950+ }
951+ }
940952 // FIXME: Should this do extra access control filtering?
941953 FORWARD (getDisplayDecls, (Results));
954+
955+ #ifndef NDEBUG
956+ llvm::DenseSet<Decl *> visited;
957+ for (auto *D : Results) {
958+ auto inserted = visited.insert (D).second ;
959+ assert (inserted && " there should be no duplicate decls" );
960+ }
961+ #endif
942962}
943963
944964ProtocolConformanceRef
0 commit comments