Skip to content

Commit 9ef66a3

Browse files
committed
[Serialization] Avoid some non-determinism in the serializer.
Unfortunately, we still have non-determinism coming from elsewhere, so we can't start trying to test this yet. Motivated by rdar://problem/20539158 Swift SVN r28576
1 parent 0990446 commit 9ef66a3

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,16 @@ void Serializer::writeNormalConformance(
10231023
return false;
10241024
});
10251025

1026-
for (auto defaulted : conformance->getDefaultedDefinitions()) {
1026+
SmallVector<ValueDecl *, 4> defaultedDefinitions{
1027+
conformance->getDefaultedDefinitions().begin(),
1028+
conformance->getDefaultedDefinitions().end()
1029+
};
1030+
llvm::array_pod_sort(defaultedDefinitions.begin(), defaultedDefinitions.end(),
1031+
[](ValueDecl * const *left, ValueDecl * const *right) {
1032+
return (*left)->getFullName().compare((*right)->getFullName());
1033+
});
1034+
1035+
for (auto defaulted : defaultedDefinitions) {
10271036
data.push_back(addDeclRef(defaulted));
10281037
++numDefaultedDefinitions;
10291038
}

lib/Serialization/Serialization.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Subsystems.h"
2323
#include "swift/AST/Identifier.h"
2424
#include "swift/Basic/LLVM.h"
25+
#include "llvm/ADT/MapVector.h"
2526
#include <array>
2627
#include <queue>
2728
#include <tuple>
@@ -110,7 +111,7 @@ class Serializer {
110111
using DeclTableData = SmallVector<std::pair<uint8_t, DeclID>, 4>;
111112
/// The in-memory representation of what will eventually be an on-disk hash
112113
/// table.
113-
using DeclTable = llvm::DenseMap<Identifier, DeclTableData>;
114+
using DeclTable = llvm::MapVector<Identifier, DeclTableData>;
114115

115116
/// Returns the declaration the given generic parameter list is associated
116117
/// with.

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/SIL/SILModule.h"
1919
#include "swift/SIL/SILUndef.h"
2020

21+
#include "llvm/ADT/MapVector.h"
2122
#include "llvm/ADT/SmallString.h"
2223
#include "llvm/ADT/StringExtras.h"
2324
#include "llvm/Support/CommandLine.h"
@@ -123,7 +124,7 @@ namespace {
123124

124125
public:
125126
using TableData = FuncTableInfo::data_type;
126-
using Table = llvm::DenseMap<FuncTableInfo::key_type, TableData>;
127+
using Table = llvm::MapVector<FuncTableInfo::key_type, TableData>;
127128
private:
128129
/// FuncTable maps function name to an ID.
129130
Table FuncTable;

0 commit comments

Comments
 (0)