Skip to content

Commit 2e70d45

Browse files
authored
Merge pull request #30140 from bitjammer/acgarland/rdar-59841727-sg-granular-kinds
SymbolGraph: Add more granular kinds
2 parents 9fcda11 + 72715ea commit 2e70d45

20 files changed

+240
-53
lines changed

lib/SymbolGraphGen/Symbol.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,40 @@ void Symbol::serializeKind(llvm::json::OStream &OS) const {
4949
serializeKind("swift.protocol", "Protocol", OS);
5050
break;
5151
case swift::DeclKind::Constructor:
52-
serializeKind("swift.initializer", "Initializer", OS);
52+
serializeKind("swift.init", "Initializer", OS);
5353
break;
5454
case swift::DeclKind::Func:
55-
serializeKind("swift.function", "Function", OS);
55+
if (VD->isOperator()) {
56+
serializeKind("swift.func.op", "Operator", OS);
57+
} else if (VD->isStatic()) {
58+
serializeKind("swift.type.method", "Type Method", OS);
59+
} else if (VD->getDeclContext()->getSelfNominalTypeDecl()){
60+
serializeKind("swift.method", "Instance Method", OS);
61+
} else {
62+
serializeKind("swift.func", "Function", OS);
63+
}
5664
break;
5765
case swift::DeclKind::Var:
58-
serializeKind("swift.variable", "Variable", OS);
66+
if (VD->isStatic()) {
67+
serializeKind("swift.type.property", "Type Property", OS);
68+
} else if (VD->getDeclContext()->getSelfNominalTypeDecl()) {
69+
serializeKind("swift.property", "Instance Property", OS);
70+
} else {
71+
serializeKind("swift.var", "Global Variable", OS);
72+
}
73+
break;
74+
case swift::DeclKind::Subscript:
75+
if (VD->isStatic()) {
76+
serializeKind("swift.type.subscript", "Type Subscript", OS);
77+
} else {
78+
serializeKind("swift.subscript", "Instance Subscript", OS);
79+
}
5980
break;
6081
case swift::DeclKind::TypeAlias:
6182
serializeKind("swift.typealias", "Type Alias", OS);
6283
break;
63-
case swift::DeclKind::InfixOperator:
64-
serializeKind("swift.infixOperator", "Infix Operator", OS);
65-
break;
66-
case swift::DeclKind::PrefixOperator:
67-
serializeKind("swift.prefixOperator", "Prefix Operator", OS);
68-
break;
69-
case swift::DeclKind::PostfixOperator:
70-
serializeKind("swift.postfixOperator", "Postfix Operator", OS);
84+
case swift::DeclKind::AssociatedType:
85+
serializeKind("swift.associatedtype", "Associated Type", OS);
7186
break;
7287
default:
7388
llvm_unreachable("Unsupported declaration kind for symbol graph");

lib/SymbolGraphGen/SymbolGraphASTWalker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ bool SymbolGraphASTWalker::walkToDeclPre(Decl *D, CharSourceRange Range) {
114114
case swift::DeclKind::Constructor:
115115
case swift::DeclKind::Func:
116116
case swift::DeclKind::Var:
117+
case swift::DeclKind::Subscript:
117118
case swift::DeclKind::TypeAlias:
119+
case swift::DeclKind::AssociatedType:
118120
break;
119121

120122
// We'll descend into everything else.

test/SymbolGraph/Symbols/Kinds.swift

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name AssociatedType -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name AssociatedType -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/AssociatedType.symbols.json
5+
6+
public protocol P {
7+
// CHECK: "identifier": "swift.associatedtype"
8+
// CHECK-NEXT: "displayName": "Associated Type"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "P"
11+
// CHECK-NEXT: "Thing"
12+
associatedtype Thing
13+
}
14+
15+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Class -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Class -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Class.symbols.json
5+
6+
// CHECK: "identifier": "swift.class"
7+
// CHECK-NEXT: "displayName": "Class"
8+
// CHECK: pathComponents
9+
// CHECK-NEXT: "C"
10+
public class C {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Enum -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Enum -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Enum.symbols.json
5+
6+
// CHECK: "identifier": "swift.enum"
7+
// CHECK-NEXT: "displayName": "Enumeration"
8+
// CHECK: pathComponents
9+
// CHECK-NEXT: "E"
10+
public enum E {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Kinds -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Kinds -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Kinds.symbols.json
5+
6+
public enum E {
7+
// CHECK: "identifier": "swift.enum.case"
8+
// CHECK-NEXT: "displayName": "Case"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "E"
11+
// CHECK-NEXT: "oneCase"
12+
case oneCase
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Function -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Function -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Function.symbols.json
5+
6+
// CHECK: "identifier": "swift.func"
7+
// CHECK-NEXT: "displayName": "Function"
8+
// CHECK: pathComponents
9+
// CHECK-NEXT: "foo()"
10+
public func foo() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name GlobalVariable -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name GlobalVariable -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/GlobalVariable.symbols.json
5+
6+
// CHECK: "identifier": "swift.var"
7+
// CHECK-NEXT: "displayName": "Global Variable"
8+
// CHECK: pathComponents
9+
// CHECK-NEXT: "global"
10+
public let global = 2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Init -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Init -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Init.symbols.json
5+
6+
public struct S {
7+
public var x: Int
8+
9+
// CHECK: "identifier": "swift.init"
10+
// CHECK-NEXT: "displayName": "Initializer"
11+
// CHECK: pathComponents
12+
// CHECK-NEXT: "S"
13+
// CHECK-NEXT: "init(x:)"
14+
public init(x: Int) {
15+
self.x = x
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name InstanceMethod -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name InstanceMethod -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/InstanceMethod.symbols.json
5+
6+
public struct S {
7+
// CHECK: "identifier": "swift.method"
8+
// CHECK-NEXT: "displayName": "Instance Method"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "S"
11+
// CHECK-NEXT: "foo()"
12+
public func foo() {}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name InstanceProperty -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name InstanceProperty -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/InstanceProperty.symbols.json
5+
6+
public struct S {
7+
// CHECK: "identifier": "swift.property"
8+
// CHECK-NEXT: "displayName": "Instance Property"
9+
// CHECK: pathComponents
10+
// CHECK: "S"
11+
// CHECK-NEXT: "x"
12+
public var x: Int
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name InstanceSubscript -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name InstanceSubscript -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/InstanceSubscript.symbols.json
5+
6+
public struct S {
7+
// CHECK: "identifier": "swift.subscript"
8+
// CHECK-NEXT: "displayName": "Instance Subscript"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "S"
11+
// CHECK-NEXT: "subscript(_:)"
12+
public subscript(i: Int) -> Int {
13+
return 2
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Operator -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Operator -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Operator.symbols.json
5+
6+
public struct S {
7+
// CHECK: "identifier": "swift.func.op"
8+
// CHECK-NEXT: "displayName": "Operator"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "S"
11+
// CHECK-NEXT: "+(_:_:)"
12+
public static func +(lhs: S, rhs: S) -> S {
13+
return lhs
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Protocol -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Protocol -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Protocol.symbols.json
5+
6+
// CHECK: "identifier": "swift.protocol"
7+
// CHECK-NEXT: "displayName": "Protocol"
8+
// CHECK: pathComponents
9+
// CHECK-NEXT: "P"
10+
public protocol P {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name Struct -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name Struct -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/Struct.symbols.json
5+
6+
// CHECK: "identifier": "swift.struct"
7+
// CHECK-NEXT: "displayName": "Structure"
8+
// CHECK: pathComponents
9+
// CHECK-NEXT: "S"
10+
public struct S {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name TypeAlias -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name TypeAlias -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/TypeAlias.symbols.json
5+
6+
// CHECK: "identifier": "swift.typealias"
7+
// CHECK-NEXT: "displayName": "Type Alias"
8+
// CHECK: pathComponents
9+
// CHECK-NEXT: "Alias"
10+
public typealias Alias = Int
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name TypeMethod -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name TypeMethod -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/TypeMethod.symbols.json
5+
6+
public struct S {
7+
// CHECK: "identifier": "swift.type.method"
8+
// CHECK-NEXT: "displayName": "Type Method"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "S"
11+
// CHECK-NEXT: "bar()"
12+
public static func bar() {}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name TypeProperty -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name TypeProperty -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/TypeProperty.symbols.json
5+
6+
public struct S {
7+
// CHECK: "identifier": "swift.type.property"
8+
// CHECK-NEXT: "displayName": "Type Property"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "S"
11+
// CHECK-NEXT: "y"
12+
public static let y = 2
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name TypeSubscript -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name TypeSubscript -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/TypeSubscript.symbols.json
5+
6+
public struct S {
7+
// CHECK: "identifier": "swift.type.subscript"
8+
// CHECK-NEXT: "displayName": "Type Subscript"
9+
// CHECK: pathComponents
10+
// CHECK-NEXT: "S"
11+
// CHECK-NEXT: "subscript(_:)"
12+
public static subscript(i: Int) -> Int {
13+
return 2
14+
}
15+
}

0 commit comments

Comments
 (0)