Skip to content

Commit b7df804

Browse files
authored
Merge pull request #31169 from bitjammer/acgarland/rdar-62081711-sgf-filter-spi
[SymbolGraph] Filter @_spi declarations
2 parents 4f3eab3 + 9d6ec07 commit b7df804

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ bool SymbolGraph::isImplicitlyPrivate(const ValueDecl *VD) const {
513513
return true;
514514
}
515515

516+
// Don't include declarations with the @_spi attribute for now.
517+
if (VD->getAttrs().getAttribute(DeclAttrKind::DAK_SPIAccessControl)) {
518+
return true;
519+
}
520+
516521
// Symbols must meet the minimum access level to be included in the graph.
517522
if (VD->getFormalAccess() < Walker.Options.MinimumAccessLevel) {
518523
return true;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name SkipsSPI -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name SkipsSPI -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/SkipsSPI.symbols.json
5+
6+
// CHECK-NOT: ShouldntAppear
7+
8+
@_spi(OtherModule)
9+
public struct StructShouldntAppear {
10+
// This shouldn't appear because the owner is @_spi(OtherModule).
11+
public func functionShouldntAppear() {}
12+
13+
// Although not @_spi(OtherModule), is in @_spi(OtherModule) struct, so shouldn't appear.
14+
public struct InnerStructShouldntAppear {}
15+
}
16+
17+
@_spi(OtherModule)
18+
public func functionShouldntAppear() {}
19+
20+
@_spi(OtherModule)
21+
public protocol ProtocolShouldntAppear {}
22+
23+
@_spi(OtherModule)
24+
public enum EnumShouldntAppear {}
25+
26+
@_spi(OtherModule)
27+
public class ClassShouldntAppear {}
28+
29+
// This struct should appear
30+
public struct StructShouldAppear {
31+
32+
// This shouldn't appear beacause it is @_spi(OtherModule), despite `StructShouldAppear`.
33+
@_spi(OtherModule)
34+
public func functionShouldntAppear() {}
35+
36+
// This shouldn't appear beacause it is @_spi(OtherModule), despite `StructShouldAppear`.
37+
@_spi(OtherModule)
38+
public struct InnerStructShouldntAppear {}
39+
}
40+
41+
extension StructShouldAppear {
42+
// This shouldn't appear because it is @_spi(OtherModule), despite `StructShouldAppear`.
43+
@_spi(OtherModule)
44+
public func extendedFunctionShouldntAppear() {}
45+
}
46+
47+
extension StructShouldAppear.InnerStructShouldntAppear {
48+
49+
// This should not appear because `StructShouldAppear.InnerStructShouldntAppear`
50+
// is @_spi(OtherModule).
51+
public func extendedFunctionShouldntAppear() {}
52+
}
53+
54+
extension StructShouldntAppear.InnerStructShouldntAppear {
55+
// This should not appear because `StructShouldntAppear.InnerStructShouldntAppear`
56+
// is @_spi(OtherModule).
57+
@_spi(OtherModule)
58+
public func extendedFunctionShouldntAppear() {}
59+
}

0 commit comments

Comments
 (0)