[SymbolGraph] Make symbol-graph output deterministic

SymbolGraph generation iterating over llvm::DenseSet, which makes the
symbols and relationship fields appear in non-deterministic ordering.
Switch to use llvm::SetVector to preserve the insertion order from
SourceEntityWalker to make order deterministic.

Resolves: https://github.com/swiftlang/swift/issues/59602
(cherry picked from commit dfa4a27ec8)
This commit is contained in:
Steven Wu
2025-04-08 12:30:09 -07:00
parent 7be76400c4
commit 58087af610
3 changed files with 9 additions and 24 deletions

View File

@@ -650,21 +650,6 @@ void SymbolGraph::serialize(llvm::json::OStream &OS) {
}
});
#ifndef NDEBUG
// FIXME (solver-based-verification-sorting): In assert builds sort the
// edges so we get consistent symbol graph output. This allows us to compare
// the string representation of the symbolgraph between the solver-based
// and AST-based result.
// This can be removed once the AST-based cursor info has been removed.
SmallVector<Edge> Edges(this->Edges.begin(), this->Edges.end());
std::sort(Edges.begin(), Edges.end(), [](const Edge &LHS, const Edge &RHS) {
SmallString<256> LHSTargetUSR, RHSTargetUSR;
LHS.Target.getUSR(LHSTargetUSR);
RHS.Target.getUSR(RHSTargetUSR);
return LHSTargetUSR < RHSTargetUSR;
});
#endif
OS.attributeArray("relationships", [&](){
for (const auto &Relationship : Edges) {
Relationship.serialize(OS);