[clang][deps] NFC: Clean up wording (ignored vs minimized)
The filesystem used during dependency scanning does two things: it caches file entries and minimizes source file contents. We use the term "ignored file" in a couple of places, but it's not clear what exactly that means. This commit clears up the semantics, explicitly spelling out this relates to minimization.
GitOrigin-RevId: 12eafd944e0ffccae93402ddbe2855beb7a939ff
diff --git a/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
index c52da33..b3a869a 100644
--- a/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ b/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -195,11 +195,14 @@
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
openFileForRead(const Twine &Path) override;
- void clearIgnoredFiles() { IgnoredFiles.clear(); }
- void ignoreFile(StringRef Filename);
+ /// Disable minimization of the given file.
+ void disableMinimization(StringRef Filename);
+ /// Enable minimization of all files.
+ void enableMinimizationOfAllFiles() { NotToBeMinimized.clear(); }
private:
- bool shouldIgnoreFile(StringRef Filename);
+ /// Check whether the file should be minimized.
+ bool shouldMinimize(StringRef Filename);
llvm::ErrorOr<const CachedFileSystemEntry *>
getOrCreateFileSystemEntry(const StringRef Filename);
@@ -214,7 +217,7 @@
/// currently active preprocessor.
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
/// The set of files that should not be minimized.
- llvm::StringSet<> IgnoredFiles;
+ llvm::StringSet<> NotToBeMinimized;
};
} // end namespace dependencies
diff --git a/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 5f3e648..8973f26 100644
--- a/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -129,7 +129,7 @@
///
/// This is kinda hacky, it would be better if we knew what kind of file Clang
/// was expecting instead.
-static bool shouldMinimize(StringRef Filename) {
+static bool shouldMinimizeBasedOnExtension(StringRef Filename) {
StringRef Ext = llvm::sys::path::extension(Filename);
if (Ext.empty())
return true; // C++ standard library
@@ -147,26 +147,30 @@
StringRef Ext = llvm::sys::path::extension(Filename);
if (Ext.empty())
return false; // This may be the module cache directory.
- return shouldMinimize(Filename); // Only cache stat failures on source files.
+ // Only cache stat failures on source files.
+ return shouldMinimizeBasedOnExtension(Filename);
}
-void DependencyScanningWorkerFilesystem::ignoreFile(StringRef RawFilename) {
- llvm::SmallString<256> Filename;
- llvm::sys::path::native(RawFilename, Filename);
- IgnoredFiles.insert(Filename);
-}
-
-bool DependencyScanningWorkerFilesystem::shouldIgnoreFile(
+void DependencyScanningWorkerFilesystem::disableMinimization(
StringRef RawFilename) {
llvm::SmallString<256> Filename;
llvm::sys::path::native(RawFilename, Filename);
- return IgnoredFiles.contains(Filename);
+ NotToBeMinimized.insert(Filename);
+}
+
+bool DependencyScanningWorkerFilesystem::shouldMinimize(StringRef RawFilename) {
+ if (!shouldMinimizeBasedOnExtension(RawFilename))
+ return false;
+
+ llvm::SmallString<256> Filename;
+ llvm::sys::path::native(RawFilename, Filename);
+ return !NotToBeMinimized.contains(Filename);
}
llvm::ErrorOr<const CachedFileSystemEntry *>
DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
const StringRef Filename) {
- bool ShouldMinimize = !shouldIgnoreFile(Filename) && shouldMinimize(Filename);
+ bool ShouldMinimize = shouldMinimize(Filename);
if (const auto *Entry = Cache.getCachedEntry(Filename, ShouldMinimize))
return Entry;
diff --git a/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 7fdc492..70bb6c5 100644
--- a/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -193,20 +193,19 @@
// Use the dependency scanning optimized file system if requested to do so.
if (DepFS) {
- DepFS->clearIgnoredFiles();
- // Ignore any files that contributed to prebuilt modules. The implicit
- // build validates the modules by comparing the reported sizes of their
- // inputs to the current state of the filesystem. Minimization would throw
- // this mechanism off.
+ DepFS->enableMinimizationOfAllFiles();
+ // Don't minimize any files that contributed to prebuilt modules. The
+ // implicit build validates the modules by comparing the reported sizes of
+ // their inputs to the current state of the filesystem. Minimization would
+ // throw this mechanism off.
for (const auto &File : PrebuiltModulesInputFiles)
- DepFS->ignoreFile(File.getKey());
- // Add any filenames that were explicity passed in the build settings and
- // that might be opened, as we want to ensure we don't run source
- // minimization on them.
+ DepFS->disableMinimization(File.getKey());
+ // Don't minimize any files that were explicitly passed in the build
+ // settings and that might be opened.
for (const auto &E : ScanInstance.getHeaderSearchOpts().UserEntries)
- DepFS->ignoreFile(E.Path);
+ DepFS->disableMinimization(E.Path);
for (const auto &F : ScanInstance.getHeaderSearchOpts().VFSOverlayFiles)
- DepFS->ignoreFile(F);
+ DepFS->disableMinimization(F);
// Support for virtual file system overlays on top of the caching
// filesystem.
diff --git a/unittests/Tooling/DependencyScannerTest.cpp b/unittests/Tooling/DependencyScannerTest.cpp
index a45223b..0488b5c 100644
--- a/unittests/Tooling/DependencyScannerTest.cpp
+++ b/unittests/Tooling/DependencyScannerTest.cpp
@@ -214,12 +214,12 @@
DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
auto StatusMinimized0 = DepFS.status("/mod.h");
- DepFS.ignoreFile("/mod.h");
+ DepFS.disableMinimization("/mod.h");
auto StatusFull1 = DepFS.status("/mod.h");
- DepFS.clearIgnoredFiles();
+ DepFS.enableMinimizationOfAllFiles();
auto StatusMinimized2 = DepFS.status("/mod.h");
- DepFS.ignoreFile("/mod.h");
+ DepFS.disableMinimization("/mod.h");
auto StatusFull3 = DepFS.status("/mod.h");
EXPECT_TRUE(StatusMinimized0);