https://github.com/artemcm created https://github.com/llvm/llvm-project/pull/88152
As-is, calls to `exists()` fallback on the implementation in `ProxyFileSystem::exists` which explicitly calls out to the underlying `FS`, which for the `DependencyScanningFilesystem` (overlay) is the real underlying filesystem. Instead, directly overloading `exists` allows us to have it rely on the cached `status` behavior used elsewhere by the `DependencyScanningFilesystem`. >From 8be194ac570d702b5df2fdcd42868122b0ae16dd Mon Sep 17 00:00:00 2001 From: Artem Chikin <achi...@apple.com> Date: Tue, 9 Apr 2024 09:37:09 -0700 Subject: [PATCH] [clang][deps] Overload 'Filesystem::exists' in 'DependencyScanningFilesystem' to have it use cached `status` As-is, calls to `exists()` fallback on the implementation in 'ProxyFileSystem::exists' which explicitly calls out to the underlying `FS`, which for the 'DependencyScanningFilesystem' (overlay) is the real underlying filesystem. Instead, directly overloading 'exists' allows us to have it rely on the cached `status` behavior used elsewhere by the 'DependencyScanningFilesystem'. --- .../DependencyScanning/DependencyScanningFilesystem.h | 4 ++++ .../DependencyScanning/DependencyScanningFilesystem.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h index 9a522a3e2fe252..4fdfebada5b7f7 100644 --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h @@ -365,6 +365,10 @@ class DependencyScanningWorkerFilesystem return LocalCache.insertEntryForFilename(Filename, Entry); } + /// Check whether \p Path exists. By default checks cached result of \c status(), + /// and falls back on FS if unable to do so. + bool exists(const Twine &Path) override; + /// Returns entry associated with the filename in the shared cache if there is /// some. Otherwise, constructs new one with the given error code, associates /// it with the filename and returns the result. diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp index 9b7812a1adb9e3..174edc98da5877 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -270,6 +270,12 @@ DependencyScanningWorkerFilesystem::status(const Twine &Path) { return Result->getStatus(); } +bool +DependencyScanningWorkerFilesystem::exists(const Twine &Path) { + auto Status = status(Path); + return Status && Status->exists(); +} + namespace { /// The VFS that is used by clang consumes the \c CachedFileSystemEntry using _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits