[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 26 03:58:57 PDT 2023


================
@@ -0,0 +1,78 @@
+//===---------------- ModuleDependencyScanner.cpp ----------------*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "ModuleDependencyScanner.h"
+
+namespace clang {
+namespace clangd {
+
+std::optional<ModuleDependencyScanner::ModuleDependencyInfo>
+ModuleDependencyScanner::scan(PathRef FilePath) {
+  std::optional<tooling::CompileCommand> Cmd = CDB.getCompileCommand(FilePath);
+
+  if (!Cmd)
+    return std::nullopt;
+
+  using namespace clang::tooling::dependencies;
+
+  llvm::SmallString<128> FilePathDir(FilePath);
+  llvm::sys::path::remove_filename(FilePathDir);
+  DependencyScanningTool ScanningTool(Service, TFS.view(FilePathDir));
----------------
sam-mccall wrote:

is ScanningTool designed for one instance to be reused across invocations of `getP1689ModuleDependencyFile`, and share caches?
Should we try to do that here, since almost all the time we're calling scan() in a sequential loop?

I get that ultimately we want to have a shared cache across all module scanning happening in the project and this may conflict a little, this just seems like really low-hanging fruit.

Up to you though.

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


More information about the cfe-commits mailing list