Skip to content

Commit 76cd4bf

Browse files
committed
[NFC] Differential Incremental External Dependencies in DependencyTracker
Also perform the plumbing necessary to convince the rest of the compiler that they're just ordinary external dependencies. In particular, we will still emit these depenencies into .d files, and code completion will still index them.
1 parent 360afd6 commit 76cd4bf

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ enum class IntermoduleDepTrackingMode {
7575
/// implemented in terms of a wrapped clang::DependencyCollector.
7676
class DependencyTracker {
7777
std::shared_ptr<clang::DependencyCollector> clangCollector;
78+
SmallVector<std::string, 8> incrementalDeps;
79+
llvm::StringSet<> incrementalDepsUniquer;
80+
7881
public:
7982
explicit DependencyTracker(
8083
IntermoduleDepTrackingMode Mode,
@@ -87,9 +90,19 @@ class DependencyTracker {
8790
/// No path canonicalization is done.
8891
void addDependency(StringRef File, bool IsSystem);
8992

93+
/// Adds a file as an incremental dependency.
94+
///
95+
/// No additional canonicalization or adulteration of the file path in
96+
/// \p File is performed.
97+
void addIncrementalDependency(StringRef File);
98+
9099
/// Fetches the list of dependencies.
91100
ArrayRef<std::string> getDependencies() const;
92101

102+
/// Fetches the list of dependencies that are known to have incremental swift
103+
/// dependency information embedded inside of them.
104+
ArrayRef<std::string> getIncrementalDependencies() const;
105+
93106
/// Return the underlying clang::DependencyCollector that this
94107
/// class wraps.
95108
std::shared_ptr<clang::DependencyCollector> getClangCollector();

include/swift/Basic/Statistics.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ FRONTEND_STATISTIC(AST, NumASTBytesAllocated)
114114
/// Number of file-level dependencies of this frontend job, as tracked in the
115115
/// AST context's dependency collector.
116116
FRONTEND_STATISTIC(AST, NumDependencies)
117+
FRONTEND_STATISTIC(AST, NumIncrementalDependencies)
117118

118119
/// Number of top-level, dynamic, and member names referenced in this frontend
119120
/// job's source file, as tracked by the AST context's referenced-name tracker.

lib/AST/ModuleLoader.cpp

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

53+
void DependencyTracker::addIncrementalDependency(StringRef File) {
54+
if (incrementalDepsUniquer.insert(File).second) {
55+
incrementalDeps.emplace_back(File.str());
56+
}
57+
}
58+
5359
ArrayRef<std::string>
5460
DependencyTracker::getDependencies() const {
5561
return clangCollector->getDependencies();
5662
}
5763

64+
ArrayRef<std::string>
65+
DependencyTracker::getIncrementalDependencies() const {
66+
return incrementalDeps;
67+
}
68+
5869
std::shared_ptr<clang::DependencyCollector>
5970
DependencyTracker::getClangCollector() {
6071
return clangCollector;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ static bool emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
209209
dependencyString.push_back(' ');
210210
dependencyString.append(frontend::utils::escapeForMake(path, buffer).str());
211211
}
212+
auto incrementalDependencyPaths =
213+
reversePathSortedFilenames(depTracker->getIncrementalDependencies());
214+
for (auto const &path : incrementalDependencyPaths) {
215+
dependencyString.push_back(' ');
216+
dependencyString.append(frontend::utils::escapeForMake(path, buffer).str());
217+
}
212218

213219
// FIXME: Xcode can't currently handle multiple targets in a single
214220
// dependency line.
@@ -1176,6 +1182,7 @@ static void countASTStats(UnifiedStatsReporter &Stats,
11761182

11771183
if (auto *D = Instance.getDependencyTracker()) {
11781184
C.NumDependencies = D->getDependencies().size();
1185+
C.NumIncrementalDependencies = D->getIncrementalDependencies().size();
11791186
}
11801187

11811188
for (auto SF : Instance.getPrimarySourceFiles()) {

lib/IDE/CompletionInstance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ forEachDependencyUntilTrue(CompilerInstance &CI, unsigned excludeBufferID,
198198
if (callback(dep))
199199
return true;
200200
}
201+
for (auto &dep : CI.getDependencyTracker()->getIncrementalDependencies()) {
202+
if (callback(dep))
203+
return true;
204+
}
201205

202206
return false;
203207
}

0 commit comments

Comments
 (0)