Skip to content

Commit 30709ce

Browse files
author
David Ungar
authored
Merge pull request #29539 from davidungar/type-fingerprints-off-by-default-3
[Incremental: Add a unit test for individual node dependency propagation]
2 parents 2d59365 + 286781f commit 30709ce

6 files changed

+75
-9
lines changed

include/swift/AST/FineGrainedDependencies.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ class SourceFileDepGraph {
799799
compoundNamesByRDK);
800800

801801
static constexpr char noncascadingOrPrivatePrefix = '#';
802+
static constexpr char nameFingerprintSeparator = ',';
802803

803804
static std::string noncascading(std::string name);
804805

include/swift/Driver/FineGrainedDependencyDriverGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ class ModuleDepGraph {
437437
/// Call \p fn for each node whose key matches \p key.
438438
void
439439
forEachMatchingNode(const DependencyKey &key,
440-
function_ref<void(const ModuleDepGraphNode *)>) const;
440+
function_ref<void(ModuleDepGraphNode *)>) const;
441441

442442
void forEachNodeInJob(StringRef swiftDeps,
443443
function_ref<void(ModuleDepGraphNode *)>) const;

lib/AST/FineGrainedDependenciesSourceFileDepGraphConstructor.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -848,33 +848,54 @@ bool swift::fine_grained_dependencies::emitReferenceDependencies(
848848
static StringRef stripPrefix(const StringRef name) {
849849
return name.ltrim(SourceFileDepGraph::noncascadingOrPrivatePrefix);
850850
}
851+
static StringRef stripFingerprint(const StringRef nameAndFingerprint) {
852+
return nameAndFingerprint.split(SourceFileDepGraph::nameFingerprintSeparator)
853+
.first;
854+
}
855+
static StringRef stripName(const StringRef nameAndFingerprint) {
856+
return nameAndFingerprint.split(SourceFileDepGraph::nameFingerprintSeparator)
857+
.second;
858+
}
859+
static std::string extractName(const StringRef prefixNameFingerprint) {
860+
return stripFingerprint(stripPrefix(prefixNameFingerprint)).str();
861+
}
862+
static Optional<std::string> extractFingerprint(
863+
const StringRef prefixNameFingerprint) {
864+
const auto fp = stripName(stripPrefix(prefixNameFingerprint));
865+
return fp.empty() ? None : Optional<std::string>(fp.str());
866+
}
851867

852868
static std::vector<ContextNameFingerprint>
853869
getBaseNameProvides(ArrayRef<std::string> simpleNames) {
854870
std::vector<ContextNameFingerprint> result;
855871
for (StringRef n : simpleNames)
856-
result.push_back(ContextNameFingerprint("", stripPrefix(n).str(), None));
872+
result.push_back(ContextNameFingerprint("", extractName(n),
873+
extractFingerprint(n)));
857874
return result;
858875
}
859876

860877
static std::vector<ContextNameFingerprint>
861878
getMangledHolderProvides(ArrayRef<std::string> simpleNames) {
862879
std::vector<ContextNameFingerprint> result;
863880
for (StringRef n : simpleNames)
864-
result.push_back(ContextNameFingerprint(stripPrefix(n).str(), "", None));
881+
result.push_back(ContextNameFingerprint(extractName(n), "",
882+
extractFingerprint(n)));
865883
return result;
866884
}
867885

868886
static std::vector<ContextNameFingerprint> getCompoundProvides(
869887
ArrayRef<std::pair<std::string, std::string>> compoundNames) {
870888
std::vector<ContextNameFingerprint> result;
871889
for (const auto &p : compoundNames)
872-
result.push_back(ContextNameFingerprint(stripPrefix(p.first),
873-
stripPrefix(p.second), None));
890+
result.push_back(ContextNameFingerprint(extractName(p.first),
891+
extractName(p.second),
892+
extractFingerprint(p.second)));
874893
return result;
875894
}
876895

877-
static bool cascades(const std::string &s) { return s.empty() || s[0] != SourceFileDepGraph::noncascadingOrPrivatePrefix; }
896+
static bool cascades(const std::string &s) {
897+
return s.empty() || s[0] != SourceFileDepGraph::noncascadingOrPrivatePrefix;
898+
}
878899

879900
// Use '_' as a prefix for a file-private member
880901
static bool isPrivate(const std::string &s) {
@@ -904,7 +925,8 @@ getCompoundDepends(
904925
// (On Linux, the compiler needs more verbosity than:
905926
// result.push_back({{n, "", false}, cascades(n)});
906927
result.push_back(
907-
std::make_pair(std::make_tuple(stripPrefix(n), std::string(), false), cascades(n)));
928+
std::make_pair(std::make_tuple(stripPrefix(n), std::string(), false),
929+
cascades(n)));
908930
}
909931
for (auto &p : compoundNames) {
910932
// Likewise, for Linux expand the following out:
@@ -932,7 +954,8 @@ SourceFileDepGraph SourceFileDepGraph::simulateLoad(
932954
SourceFileDepGraphConstructor c(
933955
swiftDepsFilename, includePrivateDeps, hadCompilationError, interfaceHash,
934956
getSimpleDepends(simpleNamesByRDK[dependsTopLevel]),
935-
getCompoundDepends(simpleNamesByRDK[dependsNominal], compoundNamesByRDK[dependsMember]),
957+
getCompoundDepends(simpleNamesByRDK[dependsNominal],
958+
compoundNamesByRDK[dependsMember]),
936959
getSimpleDepends(simpleNamesByRDK[dependsDynamicLookup]),
937960
getExternalDepends(simpleNamesByRDK[dependsExternal]),
938961
{}, // precedence groups

lib/Driver/FineGrainedDependencyDriverGraph.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ ModuleDepGraph::findJobsToRecompileWhenNodesChange<
171171
std::unordered_set<ModuleDepGraphNode *>>(
172172
const std::unordered_set<ModuleDepGraphNode *> &);
173173

174+
template std::vector<const Job *>
175+
ModuleDepGraph::findJobsToRecompileWhenNodesChange<
176+
std::vector<ModuleDepGraphNode *>>(
177+
const std::vector<ModuleDepGraphNode *> &);
178+
174179
std::vector<std::string> ModuleDepGraph::computeSwiftDepsFromNodes(
175180
ArrayRef<const ModuleDepGraphNode *> nodes) const {
176181
llvm::StringSet<> swiftDepsOfNodes;
@@ -441,7 +446,7 @@ void ModuleDepGraph::forEachNode(
441446

442447
void ModuleDepGraph::forEachMatchingNode(
443448
const DependencyKey &key,
444-
function_ref<void(const ModuleDepGraphNode *)> fn) const {
449+
function_ref<void(ModuleDepGraphNode *)> fn) const {
445450
nodeMap.forEachValueMatching(
446451
key, [&](const std::string &, ModuleDepGraphNode *n) { fn(n); });
447452
}

unittests/Driver/FineGrainedDependencyGraphTests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,19 @@ TEST(ModuleDepGraph, MutualInterfaceHash) {
808808
const auto jobs = graph.findJobsToRecompileWhenWholeJobChanges(&job0);
809809
EXPECT_TRUE(contains(jobs, &job1));
810810
}
811+
812+
TEST(ModuleDepGraph, DisabledTypeBodyFingerprints) {
813+
ModuleDepGraph graph(/*EnableTypeFingerprints=*/ false);
814+
815+
graph.simulateLoad(&job0, {{dependsNominal, {"B2"}}});
816+
graph.simulateLoad(&job1, {{providesNominal, {"B1", "B2"}}});
817+
graph.simulateLoad(&job2, {{dependsNominal, {"B1"}}});
818+
819+
{
820+
const auto jobs = graph.findJobsToRecompileWhenWholeJobChanges(&job1);
821+
EXPECT_EQ(3u, jobs.size());
822+
EXPECT_TRUE(contains(jobs, &job0));
823+
EXPECT_TRUE(contains(jobs, &job1));
824+
EXPECT_TRUE(contains(jobs, &job2));
825+
}
826+
}

unittests/Driver/TypeBodyFingerprintsDependencyGraphTests.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,24 @@ TEST(ModuleDepGraphWithTypeBodyFingerprints, MutualInterfaceHash) {
808808
const auto jobs = graph.findJobsToRecompileWhenWholeJobChanges(&job0);
809809
EXPECT_TRUE(contains(jobs, &job1));
810810
}
811+
812+
TEST(ModuleDepGraph, EnabledTypeBodyFingerprints) {
813+
ModuleDepGraph graph(/*EnableTypeFingerprints=*/ true);
814+
815+
graph.simulateLoad(&job0, {{dependsNominal, {"B2"}}});
816+
graph.simulateLoad(&job1, {{providesNominal, {"B1", "B2"}}});
817+
graph.simulateLoad(&job2, {{dependsNominal, {"B1"}}});
818+
819+
820+
const DependencyKey k = DependencyKey(NodeKind::nominal,
821+
DeclAspect::interface, "B1", "");
822+
std::vector<ModuleDepGraphNode *> changedNodes;
823+
graph.forEachMatchingNode(
824+
k,
825+
[&](ModuleDepGraphNode* n) {changedNodes.push_back(n);});
826+
{
827+
const auto jobs = graph.findJobsToRecompileWhenNodesChange(changedNodes);
828+
EXPECT_TRUE(contains(jobs, &job2));
829+
EXPECT_FALSE(contains(jobs, &job0));
830+
}
831+
}

0 commit comments

Comments
 (0)