Skip to content

Commit 79f8b48

Browse files
only recurse getDisplayDecls in SymbolGraphGen
1 parent 5cd941b commit 79f8b48

File tree

14 files changed

+45
-30
lines changed

14 files changed

+45
-30
lines changed

include/swift/AST/FileUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
246246
///
247247
/// This can differ from \c getTopLevelDecls, e.g. it returns decls from a
248248
/// shadowed clang module.
249-
virtual void getDisplayDecls(SmallVectorImpl<Decl*> &results) const {
249+
virtual void getDisplayDecls(SmallVectorImpl<Decl*> &results, bool recursive = false) const {
250250
getTopLevelDecls(results);
251251
}
252252

include/swift/AST/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ class ModuleDecl
780780
/// shadowed clang module. It does not force synthesized top-level decls that
781781
/// should be printed to be added; use \c swift::getTopLevelDeclsForDisplay()
782782
/// for that.
783-
void getDisplayDecls(SmallVectorImpl<Decl*> &results) const;
783+
void getDisplayDecls(SmallVectorImpl<Decl*> &results, bool recursive = false) const;
784784

785785
using LinkLibraryCallback = llvm::function_ref<void(LinkLibrary)>;
786786

include/swift/ClangImporter/ClangModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ClangModuleUnit final : public LoadedFile {
9191

9292
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
9393

94-
virtual void getDisplayDecls(SmallVectorImpl<Decl*> &results) const override;
94+
virtual void getDisplayDecls(SmallVectorImpl<Decl*> &results, bool recursive = false) const override;
9595

9696
virtual void
9797
getImportedModules(SmallVectorImpl<ImportedModule> &imports,

include/swift/Sema/IDETypeChecking.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace swift {
145145
/// \c ModuleDecl::getDisplayDecls() would only return if previous
146146
/// work happened to have synthesized them.
147147
void
148-
getTopLevelDeclsForDisplay(ModuleDecl *M, SmallVectorImpl<Decl*> &Results);
148+
getTopLevelDeclsForDisplay(ModuleDecl *M, SmallVectorImpl<Decl*> &Results, bool Recursive = false);
149149

150150
struct ExtensionInfo {
151151
// The extension with the declarations to apply.

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class SerializedASTFile final : public LoadedFile {
433433
virtual void
434434
getOpaqueReturnTypeDecls(SmallVectorImpl<OpaqueTypeDecl*> &results) const override;
435435

436-
virtual void getDisplayDecls(SmallVectorImpl<Decl*> &results) const override;
436+
virtual void getDisplayDecls(SmallVectorImpl<Decl*> &results, bool recursive = false) const override;
437437

438438
virtual void
439439
getImportedModules(SmallVectorImpl<ImportedModule> &imports,

lib/AST/Module.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -949,30 +949,32 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
949949
return Result;
950950
}
951951

952-
void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results) const {
953-
if (isParsedModule(this)) {
952+
void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results, bool Recursive) const {
953+
if (Recursive && isParsedModule(this)) {
954954
SmallPtrSet<ModuleDecl *, 4> Modules;
955955
collectParsedExportedImports(this, Modules);
956956
for (const ModuleDecl *import : Modules) {
957-
import->getDisplayDecls(Results);
957+
import->getDisplayDecls(Results, Recursive);
958958
}
959959
}
960960
// FIXME: Should this do extra access control filtering?
961961
FORWARD(getDisplayDecls, (Results));
962962

963963
#ifndef NDEBUG
964-
llvm::DenseSet<Decl *> visited;
965-
for (auto *D : Results) {
966-
// decls synthesized from implicit clang decls may appear multiple times;
967-
// e.g. if multiple modules with underlying clang modules are re-exported.
968-
// including duplicates of these is harmless, so skip them when counting
969-
// this assertion
970-
if (const auto *CD = D->getClangDecl()) {
971-
if (CD->isImplicit()) continue;
972-
}
964+
if (Recursive) {
965+
llvm::DenseSet<Decl *> visited;
966+
for (auto *D : Results) {
967+
// decls synthesized from implicit clang decls may appear multiple times;
968+
// e.g. if multiple modules with underlying clang modules are re-exported.
969+
// including duplicates of these is harmless, so skip them when counting
970+
// this assertion
971+
if (const auto *CD = D->getClangDecl()) {
972+
if (CD->isImplicit()) continue;
973+
}
973974

974-
auto inserted = visited.insert(D).second;
975-
assert(inserted && "there should be no duplicate decls");
975+
auto inserted = visited.insert(D).second;
976+
assert(inserted && "there should be no duplicate decls");
977+
}
976978
}
977979
#endif
978980
}

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,7 @@ static void getImportDecls(ClangModuleUnit *ClangUnit, const clang::Module *M,
31213121
}
31223122
}
31233123

3124-
void ClangModuleUnit::getDisplayDecls(SmallVectorImpl<Decl*> &results) const {
3124+
void ClangModuleUnit::getDisplayDecls(SmallVectorImpl<Decl*> &results, bool recursive) const {
31253125
if (clangModule)
31263126
getImportDecls(const_cast<ClangModuleUnit *>(this), clangModule, results);
31273127
getTopLevelDecls(results);

lib/ClangImporter/DWARFImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class DWARFModuleUnit final : public LoadedFile {
6464
getTopLevelDecls(SmallVectorImpl<Decl *> &results) const override {}
6565

6666
virtual void
67-
getDisplayDecls(SmallVectorImpl<Decl *> &results) const override {}
67+
getDisplayDecls(SmallVectorImpl<Decl *> &results, bool recursive = false) const override {}
6868

6969
virtual void
7070
getImportedModules(SmallVectorImpl<ImportedModule> &imports,

lib/IDE/IDETypeChecking.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ using namespace swift;
3535

3636
void
3737
swift::getTopLevelDeclsForDisplay(ModuleDecl *M,
38-
SmallVectorImpl<Decl*> &Results) {
38+
SmallVectorImpl<Decl*> &Results,
39+
bool Recursive) {
3940
auto startingSize = Results.size();
40-
M->getDisplayDecls(Results);
41+
M->getDisplayDecls(Results, Recursive);
4142

4243
// Force Sendable on all types, which might synthesize some extensions.
4344
// FIXME: We can remove this if @_nonSendable stops creating extensions.
@@ -49,7 +50,7 @@ swift::getTopLevelDeclsForDisplay(ModuleDecl *M,
4950
// Remove what we fetched and fetch again, possibly now with additional
5051
// extensions.
5152
Results.resize(startingSize);
52-
M->getDisplayDecls(Results);
53+
M->getDisplayDecls(Results, Recursive);
5354
}
5455

5556
static bool shouldPrintAsFavorable(const Decl *D, const PrintOptions &Options) {

lib/Serialization/ModuleFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,9 @@ ModuleFile::getOpaqueReturnTypeDecls(SmallVectorImpl<OpaqueTypeDecl *> &results)
973973
}
974974
}
975975

976-
void ModuleFile::getDisplayDecls(SmallVectorImpl<Decl *> &results) {
976+
void ModuleFile::getDisplayDecls(SmallVectorImpl<Decl *> &results, bool recursive) {
977977
if (UnderlyingModule)
978-
UnderlyingModule->getDisplayDecls(results);
978+
UnderlyingModule->getDisplayDecls(results, recursive);
979979

980980
PrettyStackTraceModuleFile stackEntry(*this);
981981
getImportDecls(results);

lib/Serialization/ModuleFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ class ModuleFile
672672
/// This includes all decls that should be displayed to clients of the module.
673673
/// This can differ from \c getTopLevelDecls, e.g. it returns decls from a
674674
/// shadowed clang module.
675-
void getDisplayDecls(SmallVectorImpl<Decl*> &results);
675+
void getDisplayDecls(SmallVectorImpl<Decl*> &results, bool recursive = false);
676676

677677
StringRef getModuleFilename() const {
678678
if (!Core->ModuleInterfacePath.empty())

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,8 @@ SerializedASTFile::getOpaqueReturnTypeDecls(
15261526
}
15271527

15281528
void
1529-
SerializedASTFile::getDisplayDecls(SmallVectorImpl<Decl*> &results) const {
1530-
File.getDisplayDecls(results);
1529+
SerializedASTFile::getDisplayDecls(SmallVectorImpl<Decl*> &results, bool recursive) const {
1530+
File.getDisplayDecls(results, recursive);
15311531
}
15321532

15331533
StringRef SerializedASTFile::getFilename() const {

lib/SymbolGraphGen/SymbolGraphGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ symbolgraphgen::emitSymbolGraphForModule(ModuleDecl *M,
5757
const SymbolGraphOptions &Options) {
5858
SymbolGraphASTWalker Walker(*M, Options);
5959
SmallVector<Decl *, 64> ModuleDecls;
60-
swift::getTopLevelDeclsForDisplay(M, ModuleDecls);
60+
swift::getTopLevelDeclsForDisplay(M, ModuleDecls, /*recursive*/true);
6161

6262
if (Options.PrintMessages)
6363
llvm::errs() << ModuleDecls.size()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module-path %t/Other.swiftmodule -module-name Other %S/Inputs/other.swift
3+
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module-path /dev/null -emit-module-interface-path %t/ExportedImport.swiftmodule -module-name ExportedImport %s -I %t
4+
5+
// RUN: %FileCheck --input-file %t/ExportedImport.swiftmodule %s
6+
7+
// CHECK-NOT: otherFileFunction
8+
9+
@_exported import Other
10+
11+
// CHECK: public struct SomeStruct
12+
public struct SomeStruct {}

0 commit comments

Comments
 (0)