Skip to content

Commit 2133d12

Browse files
committed
Address review comments.
1 parent 2187de3 commit 2133d12

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,40 +220,33 @@ class DependencyScanningFilesystemSharedCache {
220220
CacheShard &getShardForFilename(StringRef Filename) const;
221221
CacheShard &getShardForUID(llvm::sys::fs::UniqueID UID) const;
222222

223-
struct InvalidEntryDiagInfo {
223+
struct OutOfDateEntry {
224224
// A null terminated string that contains a path.
225225
const char *Path = nullptr;
226226

227-
enum class Type : unsigned char { NegativeCaching = 1, SizeChanged = 2 };
228-
229-
Type T;
230-
227+
struct NegativelyCachedInfo {};
231228
struct SizeChangedInfo {
232229
uint64_t CachedSize = 0;
233230
uint64_t ActualSize = 0;
234231
};
235232

236-
std::optional<SizeChangedInfo> SizeInfo;
233+
std::variant<NegativelyCachedInfo, SizeChangedInfo> Info;
237234

238-
InvalidEntryDiagInfo(const char *Path) : Path(Path) {
239-
T = Type::NegativeCaching;
240-
}
235+
OutOfDateEntry(const char *Path)
236+
: Path(Path), Info(NegativelyCachedInfo{}) {}
241237

242-
InvalidEntryDiagInfo(const char *Path, uint64_t CachedSize,
243-
uint64_t ActualSize)
244-
: Path(Path), SizeInfo({CachedSize, ActualSize}) {
245-
T = Type::SizeChanged;
246-
}
238+
OutOfDateEntry(const char *Path, uint64_t CachedSize, uint64_t ActualSize)
239+
: Path(Path), Info(SizeChangedInfo{CachedSize, ActualSize}) {}
247240
};
248241

249242
/// Visits all cached entries and re-stat an entry using UnderlyingFS to check
250-
/// if the cache contains invalid entries. An entry can be invalid for two
251-
/// reasons:
243+
/// if the cache contains out-of-date entries. An entry can be out-of-date for
244+
/// two reasons:
252245
/// 1. The entry contains a stat error, indicating the file did not exist
253246
/// in the cache, but the file exists on the UnderlyingFS.
254247
/// 2. The entry is associated with a file whose size is different from the
255-
/// actual size on the UnderlyingFS.
256-
std::vector<InvalidEntryDiagInfo>
248+
/// size of the file on the same path on the UnderlyingFS.
249+
std::vector<OutOfDateEntry>
257250
getInvalidEntryDiagInfo(llvm::vfs::FileSystem &UnderlyingFS) const;
258251

259252
private:

clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ DependencyScanningFilesystemSharedCache::getShardForUID(
107107
return CacheShards[Hash % NumShards];
108108
}
109109

110-
std::vector<DependencyScanningFilesystemSharedCache::InvalidEntryDiagInfo>
110+
std::vector<DependencyScanningFilesystemSharedCache::OutOfDateEntry>
111111
DependencyScanningFilesystemSharedCache::getInvalidEntryDiagInfo(
112112
llvm::vfs::FileSystem &UnderlyingFS) const {
113113
// Iterate through all shards and look for cached stat errors.
114-
std::vector<InvalidEntryDiagInfo> InvalidDiagInfo;
114+
std::vector<OutOfDateEntry> InvalidDiagInfo;
115115
for (unsigned i = 0; i < NumShards; i++) {
116116
const CacheShard &Shard = CacheShards[i];
117117
std::lock_guard<std::mutex> LockGuard(Shard.CacheLock);

clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ TEST(DependencyScanningFilesystem, DiagnoseCachedFileSizeChange) {
226226

227227
ASSERT_EQ(InvalidEntries.size(), 1u);
228228
ASSERT_STREQ("/path1.suffix", InvalidEntries[0].Path);
229-
auto SizeInfo = InvalidEntries[0].SizeInfo;
229+
auto SizeInfo = std::get_if<
230+
DependencyScanningFilesystemSharedCache::OutOfDateEntry::SizeChangedInfo>(
231+
&InvalidEntries[0].Info);
230232
ASSERT_TRUE(SizeInfo);
231233
ASSERT_EQ(SizeInfo->CachedSize, 0u);
232234
ASSERT_EQ(SizeInfo->ActualSize, 8u);

0 commit comments

Comments
 (0)