[clang-tools-extra] [clangd] Invalidate preamble when new module imports are added (PR #199460)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon May 25 19:40:57 PDT 2026


================
@@ -728,11 +728,20 @@ bool isPreambleCompatible(const PreambleData &Preamble,
   auto Bounds = computePreambleBounds(CI.getLangOpts(), *ContentsBuffer,
                                       Inputs.Opts.SkipPreambleBuild);
   auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
+  auto RequiredModulesMatch = [&]() -> bool {
+    if (!Inputs.ModulesManager || !Preamble.RequiredModules)
+      return true;
+    auto NewNames = Inputs.ModulesManager->getRequiredModuleNames(FileName);
+    llvm::StringSet<> NewNameSet;
+    NewNameSet.insert_range(NewNames);
+    return NewNameSet == Preamble.RequiredModules->getRequiredModuleNames();
+  };
----------------
ChuanqiXu9 wrote:

We need to add a comment to explain why do we need this here.  Because `Preamble.RequiredModules->canReuse` only checks if the previously built module files are up to date or not. But if we introduce a new import, it can't detect it.

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


More information about the cfe-commits mailing list