Skip to content

Commit 2435b3e

Browse files
committed
[SymbolGraph] Sort edges to get consistent symbol graph string representations
1 parent dbb3a64 commit 2435b3e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,21 @@ void SymbolGraph::serialize(llvm::json::OStream &OS) {
547547
}
548548
});
549549

550+
#ifndef NDEBUG
551+
// FIXME (solver-based-verification-sorting): In assert builds sort the
552+
// edges so we get consistent symbol graph output. This allows us to compare
553+
// the string representation of the symbolgraph between the solver-based
554+
// and AST-based result.
555+
// This can be removed once the AST-based cursor info has been removed.
556+
SmallVector<Edge> Edges(this->Edges.begin(), this->Edges.end());
557+
std::sort(Edges.begin(), Edges.end(), [](const Edge &LHS, const Edge &RHS) {
558+
SmallString<256> LHSTargetUSR, RHSTargetUSR;
559+
LHS.Target.getUSR(LHSTargetUSR);
560+
RHS.Target.getUSR(RHSTargetUSR);
561+
return LHSTargetUSR < RHSTargetUSR;
562+
});
563+
#endif
564+
550565
OS.attributeArray("relationships", [&](){
551566
for (const auto &Relationship : Edges) {
552567
Relationship.serialize(OS);

0 commit comments

Comments
 (0)