Skip to content

[SymbolGraph] add a USR for RHS types in generic conformances #36242

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 2 commits into from
Mar 5, 2021
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
2 changes: 1 addition & 1 deletion lib/SymbolGraphGen/FormatVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

#define SWIFT_SYMBOLGRAPH_FORMAT_MAJOR 0
#define SWIFT_SYMBOLGRAPH_FORMAT_MINOR 5
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 1
#define SWIFT_SYMBOLGRAPH_FORMAT_PATCH 2

#endif // SWIFT_SYMBOLGRAPHGEN_FORMATVERSION_H
11 changes: 11 additions & 0 deletions lib/SymbolGraphGen/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "swift/AST/GenericParamList.h"
#include "swift/AST/Module.h"
#include "swift/AST/Type.h"
#include "swift/AST/USRGeneration.h"
#include "JSON.h"

void swift::symbolgraphgen::serialize(const llvm::VersionTuple &VT,
Expand Down Expand Up @@ -105,6 +106,16 @@ void swift::symbolgraphgen::serialize(const Requirement &Req,
OS.attribute("kind", Kind);
OS.attribute("lhs", Req.getFirstType()->getString());
OS.attribute("rhs", Req.getSecondType()->getString());

// If the RHS type has a USR we can link to, add it to the output
if (auto *TyDecl = Req.getSecondType()->getAnyNominal()) {
SmallString<256> USR;
{
llvm::raw_svector_ostream SOS(USR);
ide::printDeclUSR(TyDecl, SOS);
}
OS.attribute("rhsPrecise", USR.str());
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ extension S: P where T: Sequence, T.Element == Int {
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "conformance",
// CHECK-NEXT: "lhs": "T",
// CHECK-NEXT: "rhs": "Sequence"
// CHECK-NEXT: "rhs": "Sequence",
// CHECK-NEXT: "rhsPrecise": "s:ST"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "sameType",
// CHECK-NEXT: "lhs": "T.Element",
// CHECK-NEXT: "rhs": "Int"
// CHECK-NEXT: "rhs": "Int",
// CHECK-NEXT: "rhsPrecise": "s:Si"
// CHECK-NEXT: }
// CHECK-NEXT: ]
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public func foo<T: Sequence>(x: T) {}
// {
// CHECK: "kind": "conformance"
// CHECK-NEXT: "lhs": "T"
// CHECK-NEXT: "rhs": "Sequence"
// CHECK-NEXT: "rhs": "Sequence",
// CHECK-NEXT: "rhsPrecise": "s:ST"
// CHECK-NEXT: }
// CHECK-NEXT: ]
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public struct MyStruct<S: Sequence> {
// CHECK: "kind": "conformance"
// CHECK-NEXT: "lhs": "S"
// CHECK-NEXT: "rhs": "Sequence"
// },
// CHECK-NEXT: "rhsPrecise": "s:ST"
// CHECK-NEXT: },
// {
// CHECK: "kind": "sameType"
// CHECK-NEXT: "lhs": "S.Element"
// CHECK-NEXT: "rhs": "Int"
// CHECK-NEXT: "rhsPrecise": "s:Si"
// CHECK-NEXT: }
// CHECK-NEXT: ]
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public func foo<T>(x: T) where T: Sequence {}
// CHECK: "kind": "conformance"
// CHECK-NEXT: "lhs": "T"
// CHECK-NEXT: "rhs": "Sequence"
// CHECK-NEXT: "rhsPrecise": "s:ST"
// CHECK-NEXT: }
// CHECK-NEXT: ]