Skip to content

Commit be92320

Browse files
Merge pull request #80687 from cachemeifyoucan/eng/issue-59602-6.2
[6.2][SymbolGraph] Make symbol-graph output deterministic
2 parents 9c6e4dd + 58087af commit be92320

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -650,21 +650,6 @@ void SymbolGraph::serialize(llvm::json::OStream &OS) {
650650
}
651651
});
652652

653-
#ifndef NDEBUG
654-
// FIXME (solver-based-verification-sorting): In assert builds sort the
655-
// edges so we get consistent symbol graph output. This allows us to compare
656-
// the string representation of the symbolgraph between the solver-based
657-
// and AST-based result.
658-
// This can be removed once the AST-based cursor info has been removed.
659-
SmallVector<Edge> Edges(this->Edges.begin(), this->Edges.end());
660-
std::sort(Edges.begin(), Edges.end(), [](const Edge &LHS, const Edge &RHS) {
661-
SmallString<256> LHSTargetUSR, RHSTargetUSR;
662-
LHS.Target.getUSR(LHSTargetUSR);
663-
RHS.Target.getUSR(RHSTargetUSR);
664-
return LHSTargetUSR < RHSTargetUSR;
665-
});
666-
#endif
667-
668653
OS.attributeArray("relationships", [&](){
669654
for (const auto &Relationship : Edges) {
670655
Relationship.serialize(OS);

lib/SymbolGraphGen/SymbolGraph.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
#ifndef SWIFT_SYMBOLGRAPHGEN_SYMBOLGRAPH_H
1414
#define SWIFT_SYMBOLGRAPHGEN_SYMBOLGRAPH_H
1515

16-
#include "llvm/ADT/SmallSet.h"
17-
#include "llvm/Support/JSON.h"
18-
#include "llvm/Support/VersionTuple.h"
16+
#include "Edge.h"
17+
#include "Symbol.h"
1918
#include "swift/Basic/LLVM.h"
2019
#include "swift/Markup/Markup.h"
2120
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
22-
#include "Edge.h"
23-
#include "JSON.h"
24-
#include "Symbol.h"
21+
#include "llvm/ADT/SetVector.h"
22+
#include "llvm/Support/JSON.h"
23+
#include "llvm/Support/VersionTuple.h"
2524

2625
namespace swift {
2726
namespace symbolgraphgen {
@@ -67,12 +66,12 @@ struct SymbolGraph {
6766
/**
6867
The symbols in a module: the nodes in the graph.
6968
*/
70-
llvm::DenseSet<Symbol> Nodes;
69+
llvm::SetVector<Symbol> Nodes;
7170

7271
/**
7372
The relationships between symbols: the edges in the graph.
7473
*/
75-
llvm::DenseSet<Edge> Edges;
74+
llvm::SetVector<Edge> Edges;
7675

7776
/**
7877
True if this graph is for a single symbol, rather than an entire module.

test/Frontend/output_determinism_check.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: echo '[]' > %t/protocol.json
3-
// RUN: %target-swift-frontend -module-name test -emit-module -o %t/test.swiftmodule %s -emit-module-doc-path %t/test.docc -const-gather-protocols-file %t/protocol.json -emit-const-values-path %t/test.swiftconstvalues -emit-tbd-path %t/test.tbd -tbd-current-version 1 -tbd-compatibility-version 1 -tbd-install_name @rpath/test.dylib -emit-loaded-module-trace -emit-loaded-module-trace-path %t/test.trace.json -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=MODULE_OUTPUT --check-prefix=DOCC_OUTPUT --check-prefix=CONSTVALUE_OUTPUT --check-prefix=TBD_OUTPUT --check-prefix=TRACE_OUTPUT
3+
// RUN: %target-swift-frontend -module-name test -emit-module -o %t/test.swiftmodule %s -emit-module-doc-path %t/test.docc -const-gather-protocols-file %t/protocol.json -emit-const-values-path %t/test.swiftconstvalues -emit-symbol-graph -emit-symbol-graph-dir %t/symbols -emit-tbd-path %t/test.tbd -tbd-current-version 1 -tbd-compatibility-version 1 -tbd-install_name @rpath/test.dylib -emit-loaded-module-trace -emit-loaded-module-trace-path %t/test.trace.json -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=MODULE_OUTPUT --check-prefix=DOCC_OUTPUT --check-prefix=CONSTVALUE_OUTPUT --check-prefix=TBD_OUTPUT --check-prefix=TRACE_OUTPUT --check-prefix=SYMBOLGRAPH_OUTPUT
44
// RUN: %target-swift-frontend -module-name test -emit-sib -o %t/test.sib -primary-file %s -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=SIB_OUTPUT
55

66
/// object files are "not" deterministic because the second run going to match the mod hash and skip code generation.
@@ -22,6 +22,7 @@
2222

2323
// RUN: %target-swift-frontend -emit-pcm -module-name UserClangModule -o %t/test.pcm %S/Inputs/dependencies/module.modulemap -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=PCM_OUTPUT
2424

25+
// SYMBOLGRAPH_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.symbols.json'
2526
// DOCC_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.docc'
2627
// CONSTVALUE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftconstvalues'
2728
// MODULE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftmodule'

0 commit comments

Comments
 (0)