Skip to content

Commit b15fcda

Browse files
committed
[JSON] Export sortedElements and fix CLANGD_TRACE non-determinism
clangd/test/trace.test might fail as llvm::hash_value(StringRef) is non-deterministic per process (#96282).
1 parent 7082536 commit b15fcda

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

clang-tools-extra/clangd/support/Trace.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ class JSONTracer : public EventTracer {
159159
Out.object([&] {
160160
Out.attribute("pid", 0);
161161
Out.attribute("ph", Phase);
162-
for (const auto &KV : Event)
163-
Out.attribute(KV.first, KV.second);
162+
for (const auto *KV : llvm::json::sortedElements(Event))
163+
Out.attribute(KV->first, KV->second);
164164
});
165165
}
166166

clang-tools-extra/clangd/test/trace.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
# CHECK: "traceEvents": [
99
# CHECK: {
1010
# CHECK: "ph": "X",
11-
# CHECK: "name": "BuildPreamble",
1211
# CHECK: "args": {
1312
# CHECK: "File": "{{.*(/|\\)}}foo.c"
1413
# CHECK: },
14+
# CHECK: "name": "BuildPreamble",
1515
# CHECK: }
1616
# CHECK: {
1717
# CHECK: "ph": "X",
18-
# CHECK: "name": "BuildAST",
1918
# CHECK: "args": {
2019
# CHECK: "File": "{{.*(/|\\)}}foo.c"
2120
# CHECK: },
21+
# CHECK: "name": "BuildAST",
2222
# CHECK: }
2323
# CHECK: ]
2424
# CHECK: }

llvm/include/llvm/Support/JSON.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ inline bool Object::erase(StringRef K) {
647647
return M.erase(ObjectKey(K));
648648
}
649649

650+
std::vector<const Object::value_type *> sortedElements(const Object &O);
651+
650652
/// A "cursor" marking a position within a Value.
651653
/// The Value is a tree, and this is the path from the root to the current node.
652654
/// This is used to associate errors with particular subobjects.

llvm/lib/Support/JSON.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Error Path::Root::getError() const {
242242
return createStringError(llvm::inconvertibleErrorCode(), OS.str());
243243
}
244244

245-
static std::vector<const Object::value_type *> sortedElements(const Object &O) {
245+
std::vector<const Object::value_type *> sortedElements(const Object &O) {
246246
std::vector<const Object::value_type *> Elements;
247247
for (const auto &E : O)
248248
Elements.push_back(&E);

0 commit comments

Comments
 (0)