Skip to content

Commit 4c1f1e6

Browse files
Merge pull request #79955 from cachemeifyoucan/eng/PR-104876331
2 parents 7445282 + bb224a3 commit 4c1f1e6

File tree

3 files changed

+14
-69
lines changed

3 files changed

+14
-69
lines changed

include/swift/AST/EvaluatorDependencies.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/Basic/NullablePtr.h"
2525
#include "llvm/ADT/DenseMap.h"
2626
#include "llvm/ADT/DenseSet.h"
27+
#include "llvm/ADT/SetVector.h"
2728
#include <vector>
2829

2930
namespace swift {
@@ -57,9 +58,12 @@ class DependencyRecorder {
5758
/// References recorded while evaluating a dependency source request for each
5859
/// source file. This map is updated upon completion of a dependency source
5960
/// request, and includes all references from each downstream request as well.
60-
llvm::DenseMap<SourceFile *,
61-
llvm::DenseSet<DependencyCollector::Reference,
62-
DependencyCollector::Reference::Info>>
61+
llvm::DenseMap<
62+
SourceFile *,
63+
llvm::SetVector<DependencyCollector::Reference,
64+
llvm::SmallVector<DependencyCollector::Reference>,
65+
llvm::DenseSet<DependencyCollector::Reference,
66+
DependencyCollector::Reference::Info>>>
6367
fileReferences;
6468

6569
/// References recorded while evaluating each request. This map is populated
@@ -73,8 +77,11 @@ class DependencyRecorder {
7377
/// dependency sink request, we update the innermost set of references.
7478
/// Upon completion of a request, we union the completed request's references
7579
/// with the next innermost active request.
76-
std::vector<llvm::SmallDenseSet<DependencyCollector::Reference, 2,
77-
DependencyCollector::Reference::Info>>
80+
std::vector<llvm::SetVector<
81+
DependencyCollector::Reference,
82+
std::vector<DependencyCollector::Reference>,
83+
llvm::SmallDenseSet<DependencyCollector::Reference, 2,
84+
DependencyCollector::Reference::Info>>>
7885
activeRequestReferences;
7986

8087
#ifndef NDEBUG
@@ -163,8 +170,7 @@ void evaluator::DependencyRecorder::endRequest(const Request &req) {
163170
return;
164171

165172
// Convert the set of dependencies into a vector.
166-
std::vector<DependencyCollector::Reference>
167-
vec(recorded.begin(), recorded.end());
173+
std::vector<DependencyCollector::Reference> vec = recorded.takeVector();
168174

169175
// The recorded dependencies bubble up to the parent request.
170176
if (!activeRequestReferences.empty()) {

include/swift/AST/FineGrainedDependencies.h

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ template <typename KeyT, typename ValueT> class Memoizer {
137137
template <typename Key1, typename Key2, typename Value> class TwoStageMap {
138138
public:
139139
// Define this here so it can be changed easily.
140-
// TODO: Use llvm structure such as DenseMap. However, DenseMap does not
141-
// preserve pointers to elements, so be careful!
142-
// TODO: Consider using an ordered structure to guarantee determinism
143-
// when compilation order changes.
144140
template <typename Key, typename MapValue>
145141
using Map = std::unordered_map<Key, MapValue>;
146142

@@ -188,32 +184,6 @@ template <typename Key1, typename Key2, typename Value> class TwoStageMap {
188184
/// Returns the submap at \p k1. May create one if not present.
189185
Map<Key2, Value> &operator[](const Key1 &k1) { return map[k1]; }
190186

191-
/// Invoke \p fn on each Key2 and Value matching (k, *)
192-
void forEachValueMatching(
193-
const Key1 &k1,
194-
function_ref<void(const Key2 &, const Value &)> fn) const {
195-
const auto &iter = map.find(k1);
196-
if (iter == map.end())
197-
return;
198-
for (auto &p : iter->second)
199-
fn(p.first, p.second);
200-
}
201-
202-
/// Invoke \p fn for each entry
203-
void forEachEntry(
204-
function_ref<void(const Key1 &, const Key2 &, const Value &)> fn) const {
205-
for (const auto &p : map)
206-
for (const auto &p2 : p.second)
207-
fn(p.first, p2.first, p2.second);
208-
}
209-
210-
/// Invoke fn for each Key1 and submap
211-
void
212-
forEachKey1(function_ref<void(const Key1 &, const InnerMap &)> fn) const {
213-
for (const auto &p : map)
214-
fn(p.first, p.second);
215-
}
216-
217187
/// Check integrity and call \p verifyFn for each element, so that element can
218188
/// be verified.
219189
///
@@ -292,36 +262,6 @@ class BiIndexedTwoStageMap {
292262
return findAndErase(k1, k2);
293263
}
294264

295-
/// Invoke \p fn on each Key2 and Value matching (\p k1, *)
296-
void forEachValueMatching(
297-
const Key1 &k1,
298-
function_ref<void(const Key2 &, const Value &)> fn) const {
299-
map1.forEachValueMatching(k1, fn);
300-
}
301-
302-
/// Invoke \p fn on each Key1 and Value matching (*, \p k2)
303-
void forEachValueMatching(
304-
const Key2 &k2,
305-
function_ref<void(const Key1 &, const Value &)> fn) const {
306-
map2.forEachValueMatching(k2, fn);
307-
}
308-
309-
/// Invoke \p fn for each entry
310-
void forEachEntry(
311-
function_ref<void(const Key1 &, const Key2 &, const Value &)> fn) const {
312-
map1.forEachEntry(fn);
313-
}
314-
315-
/// Invoke fn for each Key1 and submap
316-
void forEachKey1(function_ref<void(const Key1 &, const Key2Map &)> fn) const {
317-
map1.forEachKey1(fn);
318-
}
319-
320-
/// Invoke fn for each Key2 and submap
321-
void forEachKey2(function_ref<void(const Key1 &, const Key1Map &)> fn) const {
322-
map2.forEachKey1(fn);
323-
}
324-
325265
/// Verify the integrity of each map and the cross-map consistency.
326266
/// Then call \p verifyFn for each entry found in each of the two maps,
327267
/// passing an index so that the verifyFn knows which map is being tested.

test/Frontend/output_determinism_check.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
/// object files should match when forcing object generation.
99
// RUN: %target-swift-frontend -module-name test -emit-dependencies -c -o %t/test.o -primary-file %s -enable-deterministic-check -always-compile-output-files 2>&1 | %FileCheck %s --check-prefix=OBJECT_OUTPUT --check-prefix=DEPS_OUTPUT
1010

11-
/// FIXME: Fine-grain dependencies graph is not deterministics.
12-
/// FAIL: %target-swift-frontend -module-name test -emit-reference-dependencies-path %t/test.swiftdeps -c -o %t/test.o -primary-file %s -enable-deterministic-check -always-compile-output-files
11+
/// RUN: %target-swift-frontend -module-name test -emit-reference-dependencies-path %t/test.swiftdeps -c -o %t/test.o -primary-file %s -enable-deterministic-check -always-compile-output-files
1312

1413
/// Explicit module build. Check building swiftmodule from interface file.
1514
// RUN: %target-swift-frontend -scan-dependencies -module-name test -o %t/test.json %s -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=DEPSCAN_OUTPUT

0 commit comments

Comments
 (0)