[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 30 01:16:40 PDT 2024


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 d68059bcfd1cc27e378c43b1f16019c5baccb06d 1cd6f553f8c8f0f0a8dc691d3dcb413db9f4c051 --extensions h,cpp -- clang-tools-extra/clangd/ClangdLSPServer.cpp clang-tools-extra/clangd/ClangdLSPServer.h clang-tools-extra/clangd/ModulesBuilder.cpp clang-tools-extra/clangd/ModulesBuilder.h clang-tools-extra/clangd/tool/Check.cpp clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.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 82aa7d181f..a674e68ca7 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -217,12 +217,11 @@ private:
 
 /// Build a module file for module with `ModuleName`. The information of built
 /// module file are stored in \param BuiltModuleFiles.
-llvm::Expected<ModuleFile> buildModuleFile(llvm::StringRef ModuleName,
-                            PathRef ModuleUnitFileName,
-                            const GlobalCompilationDatabase &CDB,
-                            const ThreadsafeFS &TFS,
-                            PathRef ModuleFilesPrefix,
-                            const ReusablePrerequisiteModules &BuiltModuleFiles) {
+llvm::Expected<ModuleFile>
+buildModuleFile(llvm::StringRef ModuleName, PathRef ModuleUnitFileName,
+                const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS,
+                PathRef ModuleFilesPrefix,
+                const ReusablePrerequisiteModules &BuiltModuleFiles) {
   // Try cheap operation earlier to boil-out cheaply if there are problems.
   auto Cmd = CDB.getCompileCommand(ModuleUnitFileName);
   if (!Cmd)
@@ -286,9 +285,10 @@ public:
   buildPrerequisiteModulesFor(PathRef File, const ThreadsafeFS &TFS) override;
 
 private:
-  llvm::Error getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
-                            ProjectModules &MDB,
-                            ReusablePrerequisiteModules &RequiredModules);
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+                       ProjectModules &MDB,
+                       ReusablePrerequisiteModules &RequiredModules);
 
   std::shared_ptr<ModuleFile>
   getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
@@ -318,7 +318,8 @@ private:
   // an unbuilt module shouldn't be in this set.
   // This set is helpful to control the behavior of the condition variables.
   llvm::StringSet<> BuildingModules;
-  // Lock when we access BuildingModules, BuildingModuleMutexes and BuildingModuleCVs.
+  // Lock when we access BuildingModules, BuildingModuleMutexes and
+  // BuildingModuleCVs.
   std::mutex ModulesBuildingMutex;
 
   void startBuildingModule(StringRef ModuleName) {
@@ -426,7 +427,7 @@ std::shared_ptr<ModuleFile> ReusableModulesBuilder::getValidModuleFile(
 
 std::unique_ptr<PrerequisiteModules>
 ReusableModulesBuilder::buildPrerequisiteModulesFor(PathRef File,
-                                            const ThreadsafeFS &TFS) {
+                                                    const ThreadsafeFS &TFS) {
   std::unique_ptr<ProjectModules> MDB = CDB.getProjectModules(File);
   if (!MDB) {
     elog("Failed to get Project Modules information for {0}", File);
@@ -446,8 +447,8 @@ ReusableModulesBuilder::buildPrerequisiteModulesFor(PathRef File,
 
   for (llvm::StringRef RequiredModuleName : RequiredModuleNames) {
     // Return early if there is any error.
-    if (llvm::Error Err = 
-        getOrBuildModuleFile(RequiredModuleName, TFS, *MDB.get(), *RequiredModules.get())) {
+    if (llvm::Error Err = getOrBuildModuleFile(
+            RequiredModuleName, TFS, *MDB.get(), *RequiredModules.get())) {
       elog("Failed to build module {0}; due to {1}", RequiredModuleName,
            toString(std::move(Err)));
       return std::make_unique<FailedPrerequisiteModules>();
@@ -460,8 +461,7 @@ ReusableModulesBuilder::buildPrerequisiteModulesFor(PathRef File,
 }
 
 ReusableModulesBuilder::ModuleBuildingSharedOwner
-ReusableModulesBuilder::getOrCreateModuleBuildingOwner(
-    StringRef ModuleName) {
+ReusableModulesBuilder::getOrCreateModuleBuildingOwner(StringRef ModuleName) {
   std::lock_guard<std::mutex> _(ModulesBuildingMutex);
 
   auto MutexIter = BuildingModuleMutexes.find(ModuleName);
@@ -496,13 +496,14 @@ llvm::Error ReusableModulesBuilder::getOrBuildModuleFile(
   /// third party modules, we should return true instead of false here.
   /// Currently we simply bail out.
   if (ModuleUnitFileName.empty())
-    return llvm::createStringError(llvm::formatv("Don't get the module unit for module {0}", ModuleName));
+    return llvm::createStringError(
+        llvm::formatv("Don't get the module unit for module {0}", ModuleName));
 
   for (auto &RequiredModuleName : MDB.getRequiredModules(ModuleUnitFileName))
     // Return early if there are errors building the module file.
     if (!getOrBuildModuleFile(RequiredModuleName, TFS, MDB, BuiltModuleFiles))
-      return llvm::createStringError(llvm::formatv("Failed to build module {0}",
-                                                   RequiredModuleName));
+      return llvm::createStringError(
+          llvm::formatv("Failed to build module {0}", RequiredModuleName));
 
   if (std::shared_ptr<ModuleFile> Cached =
           getValidModuleFile(ModuleName, MDB, TFS, BuiltModuleFiles)) {
@@ -533,8 +534,9 @@ llvm::Error ReusableModulesBuilder::getOrBuildModuleFile(
     // If the module file is not in the cache, it indicates that the building
     // from other thread failed, so we give up earlier in this case to avoid
     // wasting time.
-    return llvm::createStringError(llvm::formatv("The module file {0} may be failed to build in other thread.",
-                                   ModuleName));
+    return llvm::createStringError(llvm::formatv(
+        "The module file {0} may be failed to build in other thread.",
+        ModuleName));
   }
 
   log("Building module {0}", ModuleName);
@@ -548,7 +550,8 @@ llvm::Error ReusableModulesBuilder::getOrBuildModuleFile(
   llvm::SmallString<256> ModuleFilesPrefix =
       getUniqueModuleFilesPath(ModuleUnitFileName);
 
-  llvm::Expected<ModuleFile> MF = buildModuleFile(ModuleName, ModuleUnitFileName, CDB, TFS,
+  llvm::Expected<ModuleFile> MF =
+      buildModuleFile(ModuleName, ModuleUnitFileName, CDB, TFS,
                       ModuleFilesPrefix, BuiltModuleFiles);
   if (llvm::Error Err = MF.takeError())
     return Err;

``````````

</details>


https://github.com/llvm/llvm-project/pull/106683


More information about the cfe-commits mailing list