Skip to content

Commit 108bd50

Browse files
committed
Teach DependencyTracker to track Fingerprints of Incremental Dependencies
1 parent b960c6e commit 108bd50

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
#include "swift/AST/Identifier.h"
2121
#include "swift/AST/Import.h"
22+
#include "swift/AST/ModuleDependencies.h"
23+
#include "swift/Basic/ArrayRefView.h"
24+
#include "swift/Basic/Fingerprint.h"
2225
#include "swift/Basic/LLVM.h"
2326
#include "swift/Basic/Located.h"
2427
#include "swift/Basic/SourceLoc.h"
2528
#include "llvm/ADT/SetVector.h"
2629
#include "llvm/ADT/TinyPtrVector.h"
27-
#include "swift/AST/ModuleDependencies.h"
2830
#include <system_error>
2931

3032
namespace llvm {
@@ -74,8 +76,25 @@ enum class IntermoduleDepTrackingMode {
7476
/// Records dependencies on files outside of the current module;
7577
/// implemented in terms of a wrapped clang::DependencyCollector.
7678
class DependencyTracker {
79+
public:
80+
/// A representation of a first-class incremental dependency known to the
81+
/// Swift compiler.
82+
struct IncrementalDependency {
83+
std::string path;
84+
Fingerprint fingerprint;
85+
86+
IncrementalDependency(std::string Path, Fingerprint FP)
87+
: path(std::move(Path)), fingerprint(std::move(FP)) {}
88+
};
89+
90+
inline static std::string getPath(const IncrementalDependency &id) {
91+
return id.path;
92+
}
93+
typedef ArrayRefView<IncrementalDependency, std::string, getPath>
94+
DependencyPathArrayRef;
95+
7796
std::shared_ptr<clang::DependencyCollector> clangCollector;
78-
SmallVector<std::string, 8> incrementalDeps;
97+
SmallVector<IncrementalDependency, 8> incrementalDeps;
7998
llvm::StringSet<> incrementalDepsUniquer;
8099

81100
public:
@@ -94,14 +113,20 @@ class DependencyTracker {
94113
///
95114
/// No additional canonicalization or adulteration of the file path in
96115
/// \p File is performed.
97-
void addIncrementalDependency(StringRef File);
116+
void addIncrementalDependency(StringRef File, Fingerprint FP);
98117

99118
/// Fetches the list of dependencies.
100119
ArrayRef<std::string> getDependencies() const;
101120

102121
/// Fetches the list of dependencies that are known to have incremental swift
103122
/// dependency information embedded inside of them.
104-
ArrayRef<std::string> getIncrementalDependencies() const;
123+
ArrayRef<IncrementalDependency> getIncrementalDependencies() const;
124+
125+
/// A view of the paths of the dependencies known to have incremental swift
126+
/// dependency information embedded inside of them.
127+
DependencyPathArrayRef getIncrementalDependencyPaths() const {
128+
return DependencyPathArrayRef(getIncrementalDependencies());
129+
}
105130

106131
/// Return the underlying clang::DependencyCollector that this
107132
/// class wraps.

lib/AST/ModuleLoader.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ DependencyTracker::addDependency(StringRef File, bool IsSystem) {
5050
/*IsMissing=*/false);
5151
}
5252

53-
void DependencyTracker::addIncrementalDependency(StringRef File) {
53+
void DependencyTracker::addIncrementalDependency(StringRef File,
54+
Fingerprint FP) {
5455
if (incrementalDepsUniquer.insert(File).second) {
55-
incrementalDeps.emplace_back(File.str());
56+
incrementalDeps.emplace_back(File.str(), FP);
5657
}
5758
}
5859

@@ -61,7 +62,7 @@ DependencyTracker::getDependencies() const {
6162
return clangCollector->getDependencies();
6263
}
6364

64-
ArrayRef<std::string>
65+
ArrayRef<DependencyTracker::IncrementalDependency>
6566
DependencyTracker::getIncrementalDependencies() const {
6667
return incrementalDeps;
6768
}

lib/FrontendTool/MakeStyleDependencies.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ swift::frontend::utils::escapeForMake(StringRef raw,
7575
/// should appear in roughly the same order relative to other paths. Ultimately,
7676
/// this makes it easier to test the contents of the emitted files with tools
7777
/// like FileCheck.
78+
template <typename Container>
7879
static std::vector<std::string>
79-
reversePathSortedFilenames(const ArrayRef<std::string> elts) {
80+
reversePathSortedFilenames(const Container &elts) {
8081
std::vector<std::string> tmp(elts.begin(), elts.end());
8182
std::sort(tmp.begin(), tmp.end(),
8283
[](const std::string &a, const std::string &b) -> bool {
@@ -127,7 +128,7 @@ bool swift::emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
127128
dependencyString.append(frontend::utils::escapeForMake(path, buffer).str());
128129
}
129130
auto incrementalDependencyPaths =
130-
reversePathSortedFilenames(depTracker->getIncrementalDependencies());
131+
reversePathSortedFilenames(depTracker->getIncrementalDependencyPaths());
131132
for (auto const &path : incrementalDependencyPaths) {
132133
dependencyString.push_back(' ');
133134
dependencyString.append(frontend::utils::escapeForMake(path, buffer).str());

lib/IDE/CompletionInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ forEachDependencyUntilTrue(CompilerInstance &CI, unsigned excludeBufferID,
199199
if (callback(dep))
200200
return true;
201201
}
202-
for (auto &dep : CI.getDependencyTracker()->getIncrementalDependencies()) {
202+
for (auto dep : CI.getDependencyTracker()->getIncrementalDependencyPaths()) {
203203
if (callback(dep))
204204
return true;
205205
}

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ SerializedModuleLoaderBase::loadModule(SourceLoc importLoc,
10011001
// Don't record cached artifacts as dependencies.
10021002
if (!isCached(DepPath)) {
10031003
if (M->hasIncrementalInfo()) {
1004-
dependencyTracker->addIncrementalDependency(DepPath);
1004+
dependencyTracker->addIncrementalDependency(DepPath,
1005+
M->getFingerprint());
10051006
} else {
10061007
dependencyTracker->addDependency(DepPath, /*isSystem=*/false);
10071008
}

0 commit comments

Comments
 (0)