Skip to content

[SymbolGraph] Filter @_spi declarations #31169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/SymbolGraphGen/SymbolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ bool SymbolGraph::isImplicitlyPrivate(const ValueDecl *VD) const {
return true;
}

// Don't include declarations with the @_spi attribute for now.
if (VD->getAttrs().getAttribute(DeclAttrKind::DAK_SPIAccessControl)) {
return true;
}

// Symbols must meet the minimum access level to be included in the graph.
if (VD->getFormalAccess() < Walker.Options.MinimumAccessLevel) {
return true;
Expand Down
59 changes: 59 additions & 0 deletions test/SymbolGraph/Symbols/SkipsSPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -module-name SkipsSPI -emit-module -emit-module-path %t/
// RUN: %target-swift-symbolgraph-extract -module-name SkipsSPI -I %t -pretty-print -output-dir %t
// RUN: %FileCheck %s --input-file %t/SkipsSPI.symbols.json

// CHECK-NOT: ShouldntAppear

@_spi(OtherModule)
public struct StructShouldntAppear {
// This shouldn't appear because the owner is @_spi(OtherModule).
public func functionShouldntAppear() {}

// Although not @_spi(OtherModule), is in @_spi(OtherModule) struct, so shouldn't appear.
public struct InnerStructShouldntAppear {}
}

@_spi(OtherModule)
public func functionShouldntAppear() {}

@_spi(OtherModule)
public protocol ProtocolShouldntAppear {}

@_spi(OtherModule)
public enum EnumShouldntAppear {}

@_spi(OtherModule)
public class ClassShouldntAppear {}

// This struct should appear
public struct StructShouldAppear {

// This shouldn't appear beacause it is @_spi(OtherModule), despite `StructShouldAppear`.
@_spi(OtherModule)
public func functionShouldntAppear() {}

// This shouldn't appear beacause it is @_spi(OtherModule), despite `StructShouldAppear`.
@_spi(OtherModule)
public struct InnerStructShouldntAppear {}
}

extension StructShouldAppear {
// This shouldn't appear because it is @_spi(OtherModule), despite `StructShouldAppear`.
@_spi(OtherModule)
public func extendedFunctionShouldntAppear() {}
}

extension StructShouldAppear.InnerStructShouldntAppear {

// This should not appear because `StructShouldAppear.InnerStructShouldntAppear`
// is @_spi(OtherModule).
public func extendedFunctionShouldntAppear() {}
}

extension StructShouldntAppear.InnerStructShouldntAppear {
// This should not appear because `StructShouldntAppear.InnerStructShouldntAppear`
// is @_spi(OtherModule).
@_spi(OtherModule)
public func extendedFunctionShouldntAppear() {}
}