[clang-tools-extra] [clangd] Fix prerequisite module stale dependency detection (PR #234181)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 05:56:27 PST 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- clang-tools-extra/clangd/ModulesBuilder.cpp clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp
index 47c357f9a..b73d1352e 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -1163,7 +1163,7 @@ private:
/// they import, so the AST reader can't detect this kind of staleness.
bool hasNewerDependency(PathRef PublishedModuleFilePath,
PathRef RequiredSource, PathRef ModuleUnitFileName,
- CachingProjectModules &MDB, const ThreadsafeFS& TFS);
+ CachingProjectModules &MDB, const ThreadsafeFS &TFS);
ModuleFileCache Cache;
ObservedModuleFiles ObservedFiles;
@@ -1244,22 +1244,22 @@ void ModulesBuilder::ModulesBuilderImpl::getPrebuiltModuleFile(
}
bool ModulesBuilder::ModulesBuilderImpl::hasNewerDependency(
- PathRef PublishedModuleFilePath,
- PathRef RequiredSource, PathRef ModuleUnitFileName,
- CachingProjectModules &MDB, const ThreadsafeFS& TFS) {
+ PathRef PublishedModuleFilePath, PathRef RequiredSource,
+ PathRef ModuleUnitFileName, CachingProjectModules &MDB,
+ const ThreadsafeFS &TFS) {
std::vector<std::string> Deps = MDB.getRequiredModules(ModuleUnitFileName);
if (Deps.empty())
return false;
auto ErrOrStatus = TFS.view(std::nullopt)->status(PublishedModuleFilePath);
-
+
// Without a published module file there is nothing to compare against, so
// treat any cached copy as stale.
if (!ErrOrStatus)
return true;
- llvm::vfs::Status& Status = ErrOrStatus.get();
-
+ llvm::vfs::Status &Status = ErrOrStatus.get();
+
const auto ModuleTime = Status.getLastModificationTime();
return llvm::any_of(Deps, [&](const std::string &Dep) {
@@ -1272,13 +1272,13 @@ bool ModulesBuilder::ModulesBuilderImpl::hasNewerDependency(
const std::string DepPublishedPath = getPublishedModuleFilePath(
Dep, getModuleFilesDirectory(DepSource, *DepCmd, getCDB()));
auto ErrOrDepStatus = TFS.view(std::nullopt)->status(DepPublishedPath);
-
+
// Dependencies that clangd didn't publish, like module files from the
// build system, are validated by the AST reader instead.
if (!ErrOrDepStatus)
return false;
- llvm::vfs::Status& DepStatus = ErrOrDepStatus.get();
+ llvm::vfs::Status &DepStatus = ErrOrDepStatus.get();
return DepStatus.getLastModificationTime() > ModuleTime;
});
}
@@ -1333,10 +1333,9 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
auto SourceLock = ScopedModuleSourceLock::acquire(ReqFileName, getCDB());
if (!SourceLock)
return SourceLock.takeError();
-
- const bool DependencyRebuilt =
- hasNewerDependency(PublishedModuleFilePath,
- RequiredSource, ReqFileName, MDB, TFS);
+
+ const bool DependencyRebuilt = hasNewerDependency(
+ PublishedModuleFilePath, RequiredSource, ReqFileName, MDB, TFS);
std::shared_ptr<const ModuleFile> Cached =
Cache.getModule(ReqModuleName, ReqFileName, CommandHash);
``````````
</details>
https://github.com/llvm/llvm-project/pull/234181
More information about the cfe-commits
mailing list