@@ -780,6 +780,30 @@ void SourceFile::lookupObjCMethods(
780780 results.append (known->second .begin (), known->second .end ());
781781}
782782
783+ bool ModuleDecl::shouldCollectDisplayDecls () const {
784+ for (const FileUnit *file : Files) {
785+ if (!file->shouldCollectDisplayDecls ())
786+ return false ;
787+ }
788+ return true ;
789+ }
790+
791+ static void collectParsedExportedImports (const ModuleDecl *M, SmallPtrSetImpl<ModuleDecl *> &Imports) {
792+ for (const FileUnit *file : M->getFiles ()) {
793+ if (const SourceFile *source = dyn_cast<SourceFile>(file)) {
794+ if (source->hasImports ()) {
795+ for (auto import : source->getImports ()) {
796+ if (import .options .contains (ImportFlags::Exported) &&
797+ !Imports.contains (import .module .importedModule ) &&
798+ import .module .importedModule ->shouldCollectDisplayDecls ()) {
799+ Imports.insert (import .module .importedModule );
800+ }
801+ }
802+ }
803+ }
804+ }
805+ }
806+
783807void ModuleDecl::getLocalTypeDecls (SmallVectorImpl<TypeDecl*> &Results) const {
784808 FORWARD (getLocalTypeDecls, (Results));
785809}
@@ -788,6 +812,24 @@ void ModuleDecl::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
788812 FORWARD (getTopLevelDecls, (Results));
789813}
790814
815+ void ModuleDecl::dumpDisplayDecls () const {
816+ SmallVector<Decl *, 32 > Decls;
817+ getDisplayDecls (Decls);
818+ for (auto *D : Decls) {
819+ D->dump (llvm::errs ());
820+ llvm::errs () << " \n " ;
821+ }
822+ }
823+
824+ void ModuleDecl::dumpTopLevelDecls () const {
825+ SmallVector<Decl *, 32 > Decls;
826+ getTopLevelDecls (Decls);
827+ for (auto *D : Decls) {
828+ D->dump (llvm::errs ());
829+ llvm::errs () << " \n " ;
830+ }
831+ }
832+
791833void ModuleDecl::getExportedPrespecializations (
792834 SmallVectorImpl<Decl *> &Results) const {
793835 FORWARD (getExportedPrespecializations, (Results));
@@ -908,8 +950,23 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
908950}
909951
910952void ModuleDecl::getDisplayDecls (SmallVectorImpl<Decl*> &Results) const {
953+ if (isParsedModule (this )) {
954+ SmallPtrSet<ModuleDecl *, 4 > Modules;
955+ collectParsedExportedImports (this , Modules);
956+ for (const ModuleDecl *import : Modules) {
957+ import ->getDisplayDecls (Results);
958+ }
959+ }
911960 // FIXME: Should this do extra access control filtering?
912961 FORWARD (getDisplayDecls, (Results));
962+
963+ #ifndef NDEBUG
964+ llvm::DenseSet<Decl *> visited;
965+ for (auto *D : Results) {
966+ auto inserted = visited.insert (D).second ;
967+ assert (inserted && " there should be no duplicate decls" );
968+ }
969+ #endif
913970}
914971
915972ProtocolConformanceRef
@@ -3066,6 +3123,22 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
30663123 Results.erase (newEnd, Results.end ());
30673124}
30683125
3126+ void FileUnit::dumpDisplayDecls () const {
3127+ SmallVector<Decl *, 32 > Decls;
3128+ getDisplayDecls (Decls);
3129+ for (auto *D : Decls) {
3130+ D->dump (llvm::errs ());
3131+ }
3132+ }
3133+
3134+ void FileUnit::dumpTopLevelDecls () const {
3135+ SmallVector<Decl *, 32 > Decls;
3136+ getTopLevelDecls (Decls);
3137+ for (auto *D : Decls) {
3138+ D->dump (llvm::errs ());
3139+ }
3140+ }
3141+
30693142void swift::simple_display (llvm::raw_ostream &out, const FileUnit *file) {
30703143 if (!file) {
30713144 out << " (null)" ;
0 commit comments