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.
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);
/// currently active preprocessor.
ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
/// The set of files that should not be minimized.
- llvm::StringSet<> IgnoredFiles;
+ llvm::StringSet<> NotToBeMinimized;
};
} // end namespace dependencies
///
/// 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
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) {
+void DependencyScanningWorkerFilesystem::disableMinimization(
+ StringRef RawFilename) {
llvm::SmallString<256> Filename;
llvm::sys::path::native(RawFilename, Filename);
- IgnoredFiles.insert(Filename);
+ NotToBeMinimized.insert(Filename);
}
-bool DependencyScanningWorkerFilesystem::shouldIgnoreFile(
- StringRef RawFilename) {
+bool DependencyScanningWorkerFilesystem::shouldMinimize(StringRef RawFilename) {
+ if (!shouldMinimizeBasedOnExtension(RawFilename))
+ return false;
+
llvm::SmallString<256> Filename;
llvm::sys::path::native(RawFilename, Filename);
- return IgnoredFiles.contains(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;
// 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.
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);