Skip to content

Commit 2e1e428

Browse files
author
David Ungar
committed
Added ability to add fingerprint via #
1 parent 454b30d commit 2e1e428

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
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

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

0 commit comments

Comments
 (0)