[clang-tools-extra] [clangd] Introduce reusable modules builder (PR #73483)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 26 21:53:50 PST 2023
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 e89324219acf3d799a86fed5651e492bbab4867c 052e2da0ede8cc72e22ad9ba75ddf2868e5fffe1 -- clang-tools-extra/clangd/ModuleDependencyScanner.cpp clang-tools-extra/clangd/ModuleDependencyScanner.h clang-tools-extra/clangd/ModulesBuilder.cpp clang-tools-extra/clangd/ModulesBuilder.h clang-tools-extra/clangd/PrerequisiteModules.h clang-tools-extra/clangd/ProjectModules.cpp clang-tools-extra/clangd/ProjectModules.h clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp clang-tools-extra/clangd/unittests/ModulesTestSetup.h clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/ClangdServer.h clang-tools-extra/clangd/GlobalCompilationDatabase.cpp clang-tools-extra/clangd/GlobalCompilationDatabase.h clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/Preamble.h clang-tools-extra/clangd/TUScheduler.cpp clang-tools-extra/clangd/TUScheduler.h clang-tools-extra/clangd/tool/Check.cpp clang-tools-extra/clangd/tool/ClangdMain.cpp clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp clang-tools-extra/clangd/unittests/FileIndexTests.cpp clang-tools-extra/clangd/unittests/ParsedASTTests.cpp clang-tools-extra/clangd/unittests/PreambleTests.cpp clang-tools-extra/clangd/unittests/TestTU.cpp
``````````
</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 c3a2ba89e9..b7c71bb31e 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -100,9 +100,9 @@ struct ModuleFile {
ModuleFile(ModuleFile &&Other)
: ModuleName(std::move(Other.ModuleName)),
ModuleFilePath(std::move(Other.ModuleFilePath)) {
- Other.ModuleName.clear();
- Other.ModuleFilePath.clear();
- }
+ Other.ModuleName.clear();
+ Other.ModuleFilePath.clear();
+ }
ModuleFile &operator=(ModuleFile &&Other) = delete;
@@ -140,7 +140,8 @@ buildModuleFile(StringRef ModuleName, PathRef ModuleUnitFile,
IgnoreDiagnostics IgnoreDiags;
auto CI = buildCompilerInvocation(Inputs, IgnoreDiags);
if (!CI) {
- log("Failed to build module {0} since build Compiler invocation failed", ModuleName);
+ log("Failed to build module {0} since build Compiler invocation failed",
+ ModuleName);
return std::nullopt;
}
@@ -151,7 +152,7 @@ buildModuleFile(StringRef ModuleName, PathRef ModuleUnitFile,
log("Failed to build module {0} since get buffer failed", ModuleName);
return std::nullopt;
}
-
+
// Try to use the built module files from clangd first.
BuiltModuleFiles.adjustHeaderSearchOptions(CI->getHeaderSearchOpts());
@@ -167,7 +168,8 @@ buildModuleFile(StringRef ModuleName, PathRef ModuleUnitFile,
prepareCompilerInstance(std::move(CI), /*Preamble=*/nullptr,
std::move(*Buf), std::move(FS), IgnoreDiags);
if (!Clang) {
- log("Failed to build module {0} since build compiler instance failed", ModuleName);
+ log("Failed to build module {0} since build compiler instance failed",
+ ModuleName);
return std::nullopt;
}
@@ -192,8 +194,7 @@ public:
/// We shouldn't adjust the compilation commands based on
/// FailedPrerequisiteModules.
- void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
- }
+ void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {}
/// FailedPrerequisiteModules can never be reused.
bool
canReuse(const CompilerInvocation &CI,
@@ -492,8 +493,8 @@ private:
std::shared_ptr<std::condition_variable> &CV,
ReusableModulesBuilder &Builder)
: ModuleName(ModuleName), Mutex(Mutex), CV(CV), Builder(Builder) {
- IsFirstTask = (Mutex.use_count() == 2);
- }
+ IsFirstTask = (Mutex.use_count() == 2);
+ }
~ModuleBuildingSharedOwner();
@@ -641,7 +642,8 @@ bool ReusableModulesBuilder::getOrBuildModuleFile(
if (std::shared_ptr<ModuleFile> Cached =
getValidModuleFile(ModuleName, MDB)) {
- log("Reusing Built Module {0} with {1}", Cached->ModuleName, Cached->ModuleFilePath);
+ log("Reusing Built Module {0} with {1}", Cached->ModuleName,
+ Cached->ModuleFilePath);
BuiltModuleFiles.addModuleFile(Cached);
return true;
}
diff --git a/clang-tools-extra/clangd/ProjectModules.h b/clang-tools-extra/clangd/ProjectModules.h
index 3c47863cf8..5a3ca3a05f 100644
--- a/clang-tools-extra/clangd/ProjectModules.h
+++ b/clang-tools-extra/clangd/ProjectModules.h
@@ -46,7 +46,7 @@ public:
virtual PathRef
getSourceForModuleName(StringRef ModuleName,
PathRef RequiredSrcFile = PathRef()) = 0;
-
+
virtual ~ProjectModules() = default;
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/73483
More information about the cfe-commits
mailing list