Skip to content

Commit 7c5a8fd

Browse files
committed
[SymbolGraph] Don't emit symbols that are unavailable on all platforms
rdar://88807294
1 parent 8166ad4 commit 7c5a8fd

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,17 @@ bool SymbolGraph::isImplicitlyPrivate(const Decl *D,
661661
return false;
662662
}
663663

664+
bool SymbolGraph::isUnconditionallyUnavailableOnAllPlatforms(const Decl *D) const {
665+
return llvm::any_of(D->getAttrs(), [](const auto *Attr) {
666+
if (const auto *AvAttr = dyn_cast<AvailableAttr>(Attr)) {
667+
return !AvAttr->hasPlatform()
668+
&& AvAttr->isUnconditionallyUnavailable();
669+
}
670+
671+
return false;
672+
});
673+
}
674+
664675
/// Returns `true` if the symbol should be included as a node in the graph.
665676
bool SymbolGraph::canIncludeDeclAsNode(const Decl *D) const {
666677
// If this decl isn't in this module, don't record it,
@@ -672,5 +683,6 @@ bool SymbolGraph::canIncludeDeclAsNode(const Decl *D) const {
672683
if (!isa<ValueDecl>(D)) {
673684
return false;
674685
}
675-
return !isImplicitlyPrivate(cast<ValueDecl>(D));
686+
return !isImplicitlyPrivate(cast<ValueDecl>(D))
687+
&& !isUnconditionallyUnavailableOnAllPlatforms(cast<ValueDecl>(D));
676688
}

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
bool isImplicitlyPrivate(const Decl *D,
227227
bool IgnoreContext = false) const;
228228

229+
/// Returns `true` if the declaration has an availability attribute
230+
/// that marks it as unconditionally unavailable on all platforms (i.e., where
231+
/// the platform is marked '*').
232+
bool isUnconditionallyUnavailableOnAllPlatforms(const Decl *D) const;
233+
229234
/// Returns `true` if the declaration should be included as a node
230235
/// in the graph.
231236
bool canIncludeDeclAsNode(const Decl *D) const;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name UnavailableOnAllPlatforms -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name UnavailableOnAllPlatforms -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/UnavailableOnAllPlatforms.symbols.json
5+
6+
// REQUIRES: OS=macosx
7+
8+
// CHECK: ShouldAppear
9+
@available(Linux, unavailable)
10+
public struct ShouldAppear {}
11+
12+
// CHECK-NOT: ShouldntAppear
13+
@available(*, unavailable)
14+
public struct ShouldntAppear {
15+
16+
// CHECK-NOT: shouldntAppearFunc
17+
public func shouldntAppearFunc() {}
18+
}
19+
20+
// CHECK-NOT: shouldntAppearGlobalFunc
21+
@available(*, unavailable)
22+
public func shouldntAppearGlobalFunc() {}

0 commit comments

Comments
 (0)