Skip to content

Commit 5083f83

Browse files
authored
Merge pull request #32193 from bitjammer/acgarland/rdar-63058801-dont-emit-empty-sgf
[SymbolGraph] Don't emit extension symbol graphs if empty
2 parents 91be29a + 0e7a329 commit 5083f83

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/SymbolGraphGen/SymbolGraph.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ struct SymbolGraph {
226226
/// Returns `true` if the declaration is a requirement of a protocol
227227
/// or is a default implementation of a protocol
228228
bool isRequirementOrDefaultImplementation(const ValueDecl *VD) const;
229+
230+
/// Returns `true` if there are no nodes or edges in this graph.
231+
bool empty() const {
232+
return Nodes.empty() && Edges.empty();
233+
}
229234
};
230235

231236
} // end namespace symbolgraphgen

lib/SymbolGraphGen/SymbolGraphGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ symbolgraphgen::emitSymbolGraphForModule(ModuleDecl *M,
7474
Success |= serializeSymbolGraph(Walker.MainGraph, Options);
7575

7676
for (const auto &Entry : Walker.ExtendedModuleGraphs) {
77+
if (Entry.getValue()->empty()) {
78+
continue;
79+
}
7780
Success |= serializeSymbolGraph(*Entry.getValue(), Options);
7881
}
7982

test/SymbolGraph/EmptyExtension.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name EmptyExtension -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name EmptyExtension -I %t -pretty-print -output-dir %t
4+
// RUN: %{python} -c 'import os.path; import sys; sys.exit(1 if os.path.exists(sys.argv[1]) else 0)' %t/[email protected]
5+
6+
extension Sequence {
7+
func foo() {}
8+
}

0 commit comments

Comments
 (0)