diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2021-12-02 21:02:54 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2021-12-02 21:02:54 +0000 |
| commit | f65dcba83ce5035ab88a85fe17628b447eb56e1b (patch) | |
| tree | 35f37bb72b3cfc6060193e66c76ee7c9478969b0 /clang/lib/Tooling/DependencyScanning | |
| parent | 846a2208a8ab099f595fe7e8b2e6d54a7b5e67fb (diff) | |
Diffstat (limited to 'clang/lib/Tooling/DependencyScanning')
| -rw-r--r-- | clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp | 59 | ||||
| -rw-r--r-- | clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp | 21 |
2 files changed, 44 insertions, 36 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp index 40e8bd2b8776..f7c711690d7e 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -129,7 +129,7 @@ DependencyScanningFilesystemSharedCache::get(StringRef Key, bool Minimized) { /// /// 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,43 @@ static bool shouldCacheStatFailures(StringRef Filename) { 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); +} + +CachedFileSystemEntry DependencyScanningWorkerFilesystem::createFileSystemEntry( + llvm::ErrorOr<llvm::vfs::Status> &&MaybeStatus, StringRef Filename, + bool ShouldMinimize) { + if (!MaybeStatus) + return CachedFileSystemEntry(MaybeStatus.getError()); + + if (MaybeStatus->isDirectory()) + return CachedFileSystemEntry::createDirectoryEntry(std::move(*MaybeStatus)); + + return CachedFileSystemEntry::createFileEntry(Filename, getUnderlyingFS(), + ShouldMinimize); } 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; @@ -182,23 +199,15 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry( CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value; if (!CacheEntry.isValid()) { - llvm::vfs::FileSystem &FS = getUnderlyingFS(); - auto MaybeStatus = FS.status(Filename); - if (!MaybeStatus) { - if (!shouldCacheStatFailures(Filename)) - // HACK: We need to always restat non source files if the stat fails. - // This is because Clang first looks up the module cache and module - // files before building them, and then looks for them again. If we - // cache the stat failure, it won't see them the second time. - return MaybeStatus.getError(); - else - CacheEntry = CachedFileSystemEntry(MaybeStatus.getError()); - } else if (MaybeStatus->isDirectory()) - CacheEntry = CachedFileSystemEntry::createDirectoryEntry( - std::move(*MaybeStatus)); - else - CacheEntry = CachedFileSystemEntry::createFileEntry(Filename, FS, - ShouldMinimize); + auto MaybeStatus = getUnderlyingFS().status(Filename); + if (!MaybeStatus && !shouldCacheStatFailures(Filename)) + // HACK: We need to always restat non source files if the stat fails. + // This is because Clang first looks up the module cache and module + // files before building them, and then looks for them again. If we + // cache the stat failure, it won't see them the second time. + return MaybeStatus.getError(); + CacheEntry = createFileSystemEntry(std::move(MaybeStatus), Filename, + ShouldMinimize); } Result = &CacheEntry; diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index 7fdc49271791..70bb6c5caf87 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -193,20 +193,19 @@ public: // 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. |
