Skip to content

Commit 9cca3c1

Browse files
allow implementation symbols to remain if they have their own docs
1 parent 7ed30c9 commit 9cca3c1

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "clang/AST/DeclObjC.h"
1414
#include "swift/AST/ASTContext.h"
15+
#include "swift/AST/Comment.h"
1516
#include "swift/AST/Decl.h"
1617
#include "swift/AST/Module.h"
1718
#include "swift/AST/ProtocolConformance.h"
@@ -190,7 +191,12 @@ SymbolGraph::isRequirementOrDefaultImplementation(const ValueDecl *VD) const {
190191

191192
void SymbolGraph::recordNode(Symbol S) {
192193
if (Walker.Options.SkipProtocolImplementations && S.getInheritedDecl()) {
193-
return;
194+
const auto *DocCommentProvidingDecl =
195+
getDocCommentProvidingDecl(S.getLocalSymbolDecl(), /*AllowSerialized=*/true);
196+
197+
// allow implementation symbols to remain if they have their own comment
198+
if (DocCommentProvidingDecl != S.getLocalSymbolDecl())
199+
return;
194200
}
195201

196202
Nodes.insert(S);
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -module-name SkipProtocolImplementations -emit-module -emit-module-path %t/
2+
// RUN: %target-swift-frontend %s -module-name SkipProtocolImplementations -emit-module -emit-module-path %t/SkipProtocolImplementations.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/ -skip-protocol-implementations
3+
// RUN: %{python} -m json.tool %t/SkipProtocolImplementations.symbols.json %t/SkipProtocolImplementations.formatted.symbols.json
4+
// RUN: %FileCheck %s --input-file %t/SkipProtocolImplementations.formatted.symbols.json
5+
6+
// RUN: %empty-directory(%t)
7+
// RUN: %target-swift-frontend %s -module-name SkipProtocolImplementations -emit-module -emit-module-path %t/SkipProtocolImplementations.swiftmodule -emit-module-doc-path %t/SkipProtocolImplementations.swiftdoc
38
// RUN: %target-swift-symbolgraph-extract -module-name SkipProtocolImplementations -I %t -skip-protocol-implementations -pretty-print -output-dir %t
49
// RUN: %FileCheck %s --input-file %t/SkipProtocolImplementations.symbols.json
510

611
// make sure that using `-skip-protocol-implementations` removes the functions from `SomeProtocol` on `SomeStruct`
712
// CHECK-NOT: s:27SkipProtocolImplementations04SomeB0PAAE9bonusFuncyyF::SYNTHESIZED::s:27SkipProtocolImplementations10SomeStructV
813
// CHECK-NOT: s:27SkipProtocolImplementations10SomeStructV8someFuncyyF
914

10-
// the `-skip-protocol-implementations` code should drop any symbol that would get source-origin information
11-
// CHECK-NOT: sourceOrigin
15+
// CHECK-LABEL: "symbols": [
16+
17+
// SomeStruct.otherFunc() should be present because it has its own doc comment
18+
// CHECK: s:27SkipProtocolImplementations10SomeStructV9otherFuncyyF
19+
20+
// CHECK-LABEL: "relationships": [
1221

13-
// however, we want to make sure that the conformance relationship itself stays
14-
// CHECK: conformsTo
22+
// we want to make sure that the conformance relationship itself stays
23+
// CHECK-DAG: conformsTo
24+
25+
// SomeStruct.otherFunc() should be the only one with sourceOrigin information
26+
// CHECK-COUNT-1: sourceOrigin
1527

1628
public protocol SomeProtocol {
29+
/// Base docs
1730
func someFunc()
31+
32+
/// Base docs
33+
func otherFunc()
1834
}
1935

2036
public extension SomeProtocol {
@@ -23,4 +39,7 @@ public extension SomeProtocol {
2339

2440
public struct SomeStruct: SomeProtocol {
2541
public func someFunc() {}
42+
43+
/// Local docs
44+
public func otherFunc() {}
2645
}

0 commit comments

Comments
 (0)