File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -734,7 +734,20 @@ class ModuleDecl : public DeclContext, public TypeDecl {
734
734
735
735
// / Calls \p callback for each source file of the module.
736
736
void collectBasicSourceFileInfo (
737
- llvm::function_ref<void (const BasicSourceFileInfo &)> callback);
737
+ llvm::function_ref<void (const BasicSourceFileInfo &)> callback) const ;
738
+
739
+ public:
740
+ // / Retrieve a fingerprint value that summarizes the contents of this module.
741
+ // /
742
+ // / This interface hash a of a module is guaranteed to change if the interface
743
+ // / hash of any of its (primary) source files changes. For example, when
744
+ // / building incrementally, the interface hash of this module will change when
745
+ // / the primaries contributing to its content changes. In contrast, when
746
+ // / a module is deserialized, the hash of every source file contributes to
747
+ // / the module's interface hash. It therefore serves as an effective, if
748
+ // / coarse-grained, way of determining when top-level changes to a module's
749
+ // / contents have been made.
750
+ Fingerprint getFingerprint () const ;
738
751
739
752
SourceRange getSourceRange () const { return SourceRange (); }
740
753
Original file line number Diff line number Diff line change @@ -94,6 +94,11 @@ class Fingerprint final {
94
94
return llvm::hash_value (fp.core );
95
95
}
96
96
97
+ public:
98
+ bool operator <(const Fingerprint &other) const {
99
+ return core < other.core ;
100
+ }
101
+
97
102
public:
98
103
// / The fingerprint value consisting of 32 bytes of zeroes.
99
104
// /
Original file line number Diff line number Diff line change @@ -1549,6 +1549,25 @@ void ModuleDecl::collectBasicSourceFileInfo(
1549
1549
}
1550
1550
}
1551
1551
1552
+ Fingerprint ModuleDecl::getFingerprint () const {
1553
+ StableHasher hasher = StableHasher::defaultHasher ();
1554
+ SmallVector<Fingerprint, 16 > FPs;
1555
+ collectBasicSourceFileInfo ([&](const BasicSourceFileInfo &bsfi) {
1556
+ FPs.emplace_back (bsfi.InterfaceHash );
1557
+ });
1558
+
1559
+ // Sort the fingerprints lexicographically so we have a stable hash despite
1560
+ // an unstable ordering of files across rebuilds.
1561
+ // FIXME: If we used a commutative hash combine (say, if we could take an
1562
+ // XOR here) we could avoid this sort.
1563
+ std::sort (FPs.begin (), FPs.end (), std::less<Fingerprint>());
1564
+ for (const auto &FP : FPs) {
1565
+ hasher.combine (FP);
1566
+ }
1567
+
1568
+ return Fingerprint{std::move (hasher)};
1569
+ }
1570
+
1552
1571
// ===----------------------------------------------------------------------===//
1553
1572
// Cross-Import Overlays
1554
1573
// ===----------------------------------------------------------------------===//
You can’t perform that action at this time.
0 commit comments