Skip to content

Commit 0a3be75

Browse files
author
David Ungar
committed
unit tests compile
1 parent d7474ec commit 0a3be75

File tree

6 files changed

+1035
-200
lines changed

6 files changed

+1035
-200
lines changed

include/swift/AST/FineGrainedDependencies.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,12 @@ class SourceFileDepGraph {
800800

801801
static constexpr char noncascadingOrPrivatePrefix = '#';
802802

803+
static std::string noncascading(std::string name);
804+
805+
LLVM_ATTRIBUTE_UNUSED
806+
static std::string privatize(std::string name);
807+
808+
803809
/// Nodes are owned by the graph.
804810
~SourceFileDepGraph() {
805811
forEachNode([&](SourceFileDepGraphNode *n) { delete n; });

include/swift/Driver/FineGrainedDependencyDriverGraph.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,10 @@ class ModuleDepGraph {
312312
}
313313

314314
/// For unit tests.
315-
ModuleDepGraph(const bool EnableTypeFingerprints = false)
315+
ModuleDepGraph(const bool EnableTypeFingerprints)
316316
: ModuleDepGraph(true, false, EnableTypeFingerprints, false, nullptr) {}
317+
318+
317319
//============================================================================
318320
// MARK: ModuleDepGraph - updating from a switdeps file
319321
//============================================================================
@@ -330,6 +332,16 @@ class ModuleDepGraph {
330332
Changes loadFromSourceFileDepGraph(const driver::Job *cmd,
331333
const SourceFileDepGraph &);
332334

335+
/// Also for unit tests
336+
Changes
337+
simulateLoad(const driver::Job *cmd,
338+
llvm::StringMap<std::vector<std::string>> simpleNames,
339+
llvm::StringMap<std::vector<std::pair<std::string, std::string>>>
340+
compoundNames = {},
341+
const bool includePrivateDeps = false,
342+
const bool hadCompilationError = false);
343+
344+
333345
private:
334346
/// Read a SourceFileDepGraph belonging to \p job from \p buffer
335347
/// and integrate it into the ModuleDepGraph.
@@ -515,7 +527,7 @@ class ModuleDepGraph {
515527
void forEachUntracedJobDirectlyDependentOnExternalSwiftDeps(
516528
StringRef externalDependency, function_ref<void(const driver::Job *)> fn);
517529
//============================================================================
518-
// MARK: ModuleDepGraph - verifyication
530+
// MARK: ModuleDepGraph - verification
519531
//============================================================================
520532

521533
private:
@@ -563,6 +575,9 @@ class ModuleDepGraph {
563575
assert(swiftDeps.empty() || getJob(swiftDeps));
564576
return true;
565577
}
578+
579+
static std::vector<const driver::Job *>
580+
printJobsForDebugging(const std::vector<const driver::Job *> &jobs);
566581
};
567582
} // namespace fine_grained_dependencies
568583
} // namespace swift

lib/Driver/FineGrainedDependencyDriverGraph.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,54 @@ using namespace swift;
3838
using namespace swift::fine_grained_dependencies;
3939
using namespace swift::driver;
4040

41+
//==============================================================================
42+
// MARK: Affordances to unit tests
43+
//==============================================================================
44+
/// Initial underscore makes non-cascading, on member means private.
45+
ModuleDepGraph::Changes
46+
ModuleDepGraph::simulateLoad(const Job *cmd,
47+
llvm::StringMap<std::vector<std::string>> simpleNames,
48+
llvm::StringMap<std::vector<std::pair<std::string, std::string>>>
49+
compoundNames,
50+
const bool includePrivateDeps,
51+
const bool hadCompilationError) {
52+
StringRef swiftDeps =
53+
cmd->getOutput().getAdditionalOutputForType(file_types::TY_SwiftDeps);
54+
assert(!swiftDeps.empty());
55+
StringRef interfaceHash = swiftDeps;
56+
auto sfdg = SourceFileDepGraph::simulateLoad(
57+
swiftDeps, includePrivateDeps, hadCompilationError, interfaceHash,
58+
simpleNames, compoundNames);
59+
60+
return loadFromSourceFileDepGraph(cmd, sfdg);
61+
}
62+
63+
std::string SourceFileDepGraph::noncascading(std::string name) {
64+
std::string s{SourceFileDepGraph::noncascadingOrPrivatePrefix};
65+
s += name;
66+
return s;
67+
}
68+
69+
LLVM_ATTRIBUTE_UNUSED
70+
std::string SourceFileDepGraph::privatize(std::string name) {
71+
std::string s{SourceFileDepGraph::noncascadingOrPrivatePrefix};
72+
s += name;
73+
return s;
74+
}
75+
76+
LLVM_ATTRIBUTE_UNUSED
77+
std::vector<const Job *>
78+
ModuleDepGraph::printJobsForDebugging(const std::vector<const Job *> &jobs) {
79+
llvm::errs() << "\nprintForDebugging: ";
80+
for (auto *j : jobs) {
81+
const auto swiftDeps =
82+
j->getOutput().getAdditionalOutputForType(file_types::TY_SwiftDeps);
83+
assert(!swiftDeps.empty());
84+
llvm::errs() << "job" << swiftDeps << ", ";
85+
}
86+
llvm::errs() << "\n";
87+
return jobs;
88+
}
4189
//==============================================================================
4290
// MARK: Interfacing to Compilation
4391
//==============================================================================

unittests/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_swift_unittest(SwiftDriverTests
22
CoarseGrainedDependencyGraphTests.cpp
33
FineGrainedDependencyGraphTests.cpp
4+
TypeBodyFingerprintsDependencyGraphTests.cpp
45
)
56

67
target_link_libraries(SwiftDriverTests

0 commit comments

Comments
 (0)