Skip to content

Commit 58edd83

Browse files
committed
[SymbolGraph] Completely filter unavailable/obsoleted symbols
Symbol graph files are processed per platform--documentation for symbols that are unconditionally unavailable or obsoleted on a platform shouldn't be shown for that same platform. Also, removes `isUnconditionallyUnavailable` from the JSON format. If it's unconditionally unavailable, it won't show up at all. rdar://60193675
1 parent 85c4e01 commit 58edd83

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

lib/SymbolGraphGen/FormatVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515

1616
#define SWIFT_SYMBOLGRAPH_FORMAT_MAJOR 0
1717
#define SWIFT_SYMBOLGRAPH_FORMAT_MINOR 4
18-
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 0
18+
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 1
1919

2020
#endif // SWIFT_SYMBOLGRAPHGEN_FORMATVERSION_H

lib/SymbolGraphGen/Symbol.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,6 @@ void Symbol::serializeAvailabilityMixin(llvm::json::OStream &OS) const {
396396
if (AvAttr->isUnconditionallyDeprecated()) {
397397
OS.attribute("isUnconditionallyDeprecated", true);
398398
}
399-
if (AvAttr->isUnconditionallyUnavailable()) {
400-
OS.attribute("isUnconditionallyUnavailable", true);
401-
}
402399
}); // end availability object
403400
}
404401
}); // end availability: []

lib/SymbolGraphGen/SymbolGraphASTWalker.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,26 @@ SymbolGraph *SymbolGraphASTWalker::getModuleSymbolGraph(ModuleDecl *M) {
4646
return SG;
4747
}
4848

49+
namespace {
50+
bool isUnavailableOrObsoleted(const Decl *D) {
51+
if (const auto *Avail =
52+
D->getAttrs().getUnavailable(D->getASTContext())) {
53+
switch (Avail->getVersionAvailability(D->getASTContext())) {
54+
case AvailableVersionComparison::Unavailable:
55+
case AvailableVersionComparison::Obsoleted:
56+
return true;
57+
default:
58+
break;
59+
}
60+
}
61+
return false;
62+
}
63+
} // end anonymous namespace
64+
4965
bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
66+
if (isUnavailableOrObsoleted(D)) {
67+
return false;
68+
}
5069

5170
switch (D->getKind()) {
5271
// We'll record nodes for the following kinds of declarations.
@@ -80,6 +99,10 @@ bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
8099
return false;
81100
}
82101

102+
if (isUnavailableOrObsoleted(ExtendedNominal)) {
103+
return false;
104+
}
105+
83106
// If there are some protocol conformances on this extension, we'll
84107
// grab them for some new conformsTo relationships.
85108
if (!Extension->getInherited().empty()) {

test/SymbolGraph/Symbols/Mixins/Availability/UnconditionallyUnavailable.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Unavailable -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Unavailable -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Unavailable.symbols.json
5+
6+
// REQUIRES: OS=macosx
7+
8+
public struct ShouldAppear {}
9+
10+
// CHECK-NOT: OSXUnavailable
11+
@available(OSX, unavailable)
12+
public struct OSXUnavailable {}
13+
14+
@available(OSX, unavailable)
15+
extension ShouldAppear {
16+
public func shouldntAppear1() {}
17+
}
18+
19+
// CHECK-NOT: OSXObsoleted
20+
@available(OSX, obsoleted: 10.9)
21+
public struct OSXObsoleted {}
22+
23+
@available(OSX, obsoleted: 10.9)
24+
extension ShouldAppear {
25+
public func shouldntAppear2() {}
26+
}
27+
28+
// CHECK-NOT: SwiftObsoleted
29+
@available(swift, obsoleted: 1.0)
30+
public struct SwiftObsoleted {}
31+
32+
@available(swift, obsoleted: 1.0)
33+
extension ShouldAppear {
34+
public func shouldntAppear3() {}
35+
}
36+
37+
// CHECK-NOT: shouldntAppear

0 commit comments

Comments
 (0)