Skip to content

Commit 1451960

Browse files
[SymbolGraph] add a USR for RHS types in generic conformances (#36242)
rdar://70442228
1 parent 3eb73a5 commit 1451960

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
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 5
18-
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 1
18+
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 2
1919

2020
#endif // SWIFT_SYMBOLGRAPHGEN_FORMATVERSION_H

lib/SymbolGraphGen/JSON.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/GenericParamList.h"
1717
#include "swift/AST/Module.h"
1818
#include "swift/AST/Type.h"
19+
#include "swift/AST/USRGeneration.h"
1920
#include "JSON.h"
2021

2122
void swift::symbolgraphgen::serialize(const llvm::VersionTuple &VT,
@@ -105,6 +106,16 @@ void swift::symbolgraphgen::serialize(const Requirement &Req,
105106
OS.attribute("kind", Kind);
106107
OS.attribute("lhs", Req.getFirstType()->getString());
107108
OS.attribute("rhs", Req.getSecondType()->getString());
109+
110+
// If the RHS type has a USR we can link to, add it to the output
111+
if (auto *TyDecl = Req.getSecondType()->getAnyNominal()) {
112+
SmallString<256> USR;
113+
{
114+
llvm::raw_svector_ostream SOS(USR);
115+
ide::printDeclUSR(TyDecl, SOS);
116+
}
117+
OS.attribute("rhsPrecise", USR.str());
118+
}
108119
});
109120
}
110121

test/SymbolGraph/Symbols/Mixins/Extension/IgnoreInherited.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ extension S: P where T: Sequence, T.Element == Int {
2222
// CHECK-NEXT: {
2323
// CHECK-NEXT: "kind": "conformance",
2424
// CHECK-NEXT: "lhs": "T",
25-
// CHECK-NEXT: "rhs": "Sequence"
25+
// CHECK-NEXT: "rhs": "Sequence",
26+
// CHECK-NEXT: "rhsPrecise": "s:ST"
2627
// CHECK-NEXT: },
2728
// CHECK-NEXT: {
2829
// CHECK-NEXT: "kind": "sameType",
2930
// CHECK-NEXT: "lhs": "T.Element",
30-
// CHECK-NEXT: "rhs": "Int"
31+
// CHECK-NEXT: "rhs": "Int",
32+
// CHECK-NEXT: "rhsPrecise": "s:Si"
3133
// CHECK-NEXT: }
3234
// CHECK-NEXT: ]

test/SymbolGraph/Symbols/Mixins/Generics/ConstraintsOnLocalContext.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public func foo<T: Sequence>(x: T) {}
1717
// {
1818
// CHECK: "kind": "conformance"
1919
// CHECK-NEXT: "lhs": "T"
20-
// CHECK-NEXT: "rhs": "Sequence"
20+
// CHECK-NEXT: "rhs": "Sequence",
21+
// CHECK-NEXT: "rhsPrecise": "s:ST"
2122
// CHECK-NEXT: }
2223
// CHECK-NEXT: ]

test/SymbolGraph/Symbols/Mixins/Generics/ConstraintsOnOuterContext.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ public struct MyStruct<S: Sequence> {
1818
// CHECK: "kind": "conformance"
1919
// CHECK-NEXT: "lhs": "S"
2020
// CHECK-NEXT: "rhs": "Sequence"
21-
// },
21+
// CHECK-NEXT: "rhsPrecise": "s:ST"
22+
// CHECK-NEXT: },
2223
// {
2324
// CHECK: "kind": "sameType"
2425
// CHECK-NEXT: "lhs": "S.Element"
2526
// CHECK-NEXT: "rhs": "Int"
27+
// CHECK-NEXT: "rhsPrecise": "s:Si"
2628
// CHECK-NEXT: }
2729
// CHECK-NEXT: ]

test/SymbolGraph/Symbols/Mixins/Generics/WhereClause.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ public func foo<T>(x: T) where T: Sequence {}
1818
// CHECK: "kind": "conformance"
1919
// CHECK-NEXT: "lhs": "T"
2020
// CHECK-NEXT: "rhs": "Sequence"
21+
// CHECK-NEXT: "rhsPrecise": "s:ST"
2122
// CHECK-NEXT: }
2223
// CHECK-NEXT: ]

0 commit comments

Comments
 (0)