[clang][deps] NFC: Use clearer wording around entry initialization
authorJan Svoboda <jan_svoboda@apple.com>
Fri, 10 Dec 2021 13:16:29 +0000 (14:16 +0100)
committerJan Svoboda <jan_svoboda@apple.com>
Wed, 15 Dec 2021 15:14:44 +0000 (16:14 +0100)
The code and documentation around `CachedFileSystemEntry` use the following terms:
* "invalid stat" for `llvm::ErrorOr<llvm::vfs::Status>` that is *not* an error and contains an unknown status,
* "initialized entry" for an entry that contains "invalid stat",
* "valid entry" for an entry that contains "invalid stat", synonymous to "initialized" entry.

Having an entry be "valid" while it contains an "invalid" status object is counter-intuitive.
This patch cleans up the wording by referring to the status as "unknown" and to the entry as either "initialized" or "uninitialized".

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

index 25a7d57..4b286df 100644 (file)
@@ -30,10 +30,10 @@ namespace dependencies {
 /// - an opened source file with original contents and a stat value.
 /// - a directory entry with its stat value.
 /// - an error value to represent a file system error.
-/// - a placeholder with an invalid stat indicating a not yet initialized entry.
+/// - uninitialized entry with unknown status.
 class CachedFileSystemEntry {
 public:
-  /// Default constructor creates an entry with an invalid stat.
+  /// Creates an uninitialized entry.
   CachedFileSystemEntry() : MaybeStat(llvm::vfs::Status()) {}
 
   CachedFileSystemEntry(std::error_code Error) : MaybeStat(std::move(Error)) {}
@@ -51,8 +51,10 @@ public:
   /// Create an entry that represents a directory on the filesystem.
   static CachedFileSystemEntry createDirectoryEntry(llvm::vfs::Status &&Stat);
 
-  /// \returns True if the entry is valid.
-  bool isValid() const { return !MaybeStat || MaybeStat->isStatusKnown(); }
+  /// \returns True if the entry is initialized.
+  bool isInitialized() const {
+    return !MaybeStat || MaybeStat->isStatusKnown();
+  }
 
   /// \returns True if the current entry points to a directory.
   bool isDirectory() const { return MaybeStat && MaybeStat->isDirectory(); }
@@ -62,19 +64,19 @@ public:
     if (!MaybeStat)
       return MaybeStat.getError();
     assert(!MaybeStat->isDirectory() && "not a file");
-    assert(isValid() && "not initialized");
+    assert(isInitialized() && "not initialized");
     return Contents->getBuffer();
   }
 
   /// \returns The error or the status of the entry.
   llvm::ErrorOr<llvm::vfs::Status> getStatus() const {
-    assert(isValid() && "not initialized");
+    assert(isInitialized() && "not initialized");
     return MaybeStat;
   }
 
   /// \returns the name of the file.
   StringRef getName() const {
-    assert(isValid() && "not initialized");
+    assert(isInitialized() && "not initialized");
     return MaybeStat->getName();
   }
 
index 367989f..32e8acb 100644 (file)
@@ -188,7 +188,7 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
     std::lock_guard<std::mutex> LockGuard(SharedCacheEntry.ValueLock);
     CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
 
-    if (!CacheEntry.isValid()) {
+    if (!CacheEntry.isInitialized()) {
       auto MaybeStatus = getUnderlyingFS().status(Filename);
       if (!MaybeStatus && !shouldCacheStatFailures(Filename))
         // HACK: We need to always restat non source files if the stat fails.