Skip to content

Commit 520b801

Browse files
author
David Ungar
authored
Merge pull request swiftlang#21177 from davidungar/A-exp-dep-graph-12-10-18
First cut at graph-based fine-grained experimental dependencies.
2 parents b529953 + cf856bb commit 520b801

18 files changed

+3219
-40
lines changed

include/swift/AST/ExperimentalDependencies.h

Lines changed: 983 additions & 0 deletions
Large diffs are not rendered by default.

include/swift/Basic/LangOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ namespace swift {
295295
/// and faster rebuilds.
296296
bool EnableExperimentalDependencies = false;
297297

298+
/// To mimic existing system, set to false.
299+
/// To experiment with including file-private and private dependency info,
300+
/// set to true.
301+
bool ExperimentalDependenciesIncludeIntrafileOnes = false;
302+
298303
/// Sets the target we are building for and updates platform conditions
299304
/// to match.
300305
///

include/swift/Driver/Compilation.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ class Compilation {
210210
/// faster rebuilds.
211211
const bool EnableExperimentalDependencies;
212212

213+
/// Helpful for debugging, but slows down the driver. So, only turn on when
214+
/// needed.
215+
const bool VerifyExperimentalDependencyGraphAfterEveryImport;
216+
/// Helpful for debugging, but slows down the driver. So, only turn on when
217+
/// needed.
218+
const bool EmitExperimentalDependencyDotFileAfterEveryImport;
219+
220+
/// Experiment with inter-file dependencies
221+
const bool ExperimentalDependenciesIncludeIntrafileOnes;
222+
213223
template <typename T>
214224
static T *unwrap(const std::unique_ptr<T> &p) {
215225
return p.get();
@@ -220,6 +230,7 @@ class Compilation {
220230
ArrayRefView<std::unique_ptr<T>, T *, Compilation::unwrap<T>>;
221231

222232
public:
233+
// clang-format off
223234
Compilation(DiagnosticEngine &Diags, const ToolChain &TC,
224235
OutputInfo const &OI,
225236
OutputLevel Level,
@@ -239,7 +250,11 @@ class Compilation {
239250
bool SaveTemps = false,
240251
bool ShowDriverTimeCompilation = false,
241252
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr,
242-
bool EnableExperimentalDependencies = false);
253+
bool EnableExperimentalDependencies = false,
254+
bool VerifyExperimentalDependencyGraphAfterEveryImport = false,
255+
bool EmitExperimentalDependencyDotFileAfterEveryImport = false,
256+
bool ExperimentalDependenciesIncludeIntrafileOnes = false);
257+
// clang-format on
243258
~Compilation();
244259

245260
ToolChain const &getToolChain() const {
@@ -298,6 +313,18 @@ class Compilation {
298313
return EnableExperimentalDependencies;
299314
}
300315

316+
bool getVerifyExperimentalDependencyGraphAfterEveryImport() const {
317+
return VerifyExperimentalDependencyGraphAfterEveryImport;
318+
}
319+
320+
bool getEmitExperimentalDependencyDotFileAfterEveryImport() const {
321+
return EmitExperimentalDependencyDotFileAfterEveryImport;
322+
}
323+
324+
bool getExperimentalDependenciesIncludeIntrafileOnes() const {
325+
return ExperimentalDependenciesIncludeIntrafileOnes;
326+
}
327+
301328
bool getBatchModeEnabled() const {
302329
return EnableBatchMode;
303330
}
@@ -312,7 +339,7 @@ class Compilation {
312339
bool getShowIncrementalBuildDecisions() const {
313340
return ShowIncrementalBuildDecisions;
314341
}
315-
void setShowsIncrementalBuildDecisions(bool value = true) {
342+
void setShowIncrementalBuildDecisions(bool value = true) {
316343
ShowIncrementalBuildDecisions = value;
317344
}
318345

@@ -335,6 +362,12 @@ class Compilation {
335362
return Stats.get();
336363
}
337364

365+
/// True if extra work has to be done when tracing through the dependency
366+
/// graph, either in order to print dependencies or to collect statistics.
367+
bool getTraceDependencies() const {
368+
return getShowIncrementalBuildDecisions() || getStatsReporter();
369+
}
370+
338371
OutputLevel getOutputLevel() const {
339372
return Level;
340373
}

include/swift/Driver/DependencyGraph.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_DRIVER_DEPENDENCYGRAPH_H
1414
#define SWIFT_DRIVER_DEPENDENCYGRAPH_H
1515

16+
#include "swift/AST/DiagnosticEngine.h"
1617
#include "swift/Basic/LLVM.h"
1718
#include "swift/Basic/OptionSet.h"
1819
#include "llvm/ADT/ArrayRef.h"
@@ -121,7 +122,6 @@ class DependencyGraphImpl {
121122
llvm::StringMap<std::pair<std::vector<DependencyEntryTy>, DependencyMaskTy>> Dependencies;
122123

123124
/// The set of marked nodes.
124-
125125
llvm::SmallPtrSet<const void *, 16> Marked;
126126

127127
/// A list of all external dependencies that cannot be resolved from just this
@@ -231,7 +231,10 @@ class DependencyGraph : public DependencyGraphImpl {
231231
/// ("depends") are not cleared; new dependencies are considered additive.
232232
///
233233
/// If \p node has already been marked, only its outgoing edges are updated.
234-
LoadResult loadFromPath(T node, StringRef path) {
234+
/// The third argument is ignored here, but must be present so that the same
235+
/// call site can polymorphically call \ref
236+
/// experimental_dependencies::ModuleDepGraph::loadFromPath
237+
LoadResult loadFromPath(T node, StringRef path, DiagnosticEngine &) {
235238
return DependencyGraphImpl::loadFromPath(Traits::getAsVoidPointer(node),
236239
path);
237240
}

0 commit comments

Comments
 (0)