-
Notifications
You must be signed in to change notification settings - Fork 15k
Reland "[clangd] Add feature modules registry" #154836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This patch adds feature modules registry, which allows to discover registered feature modules and add them into the clangd's feature module set
|
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: Aleksandr Platonov (ArcsinX) ChangesReland #153756 LLVM_INSTANTIATE_REGISTRY(..) and FeatureModuleRegistry::entries() were in different translation units, that rises a warning when compiling with clang and leads to compilation failure if -Werror flag is set. Full diff: https://github.com/llvm/llvm-project/pull/154836.diff 3 Files Affected:
diff --git a/clang-tools-extra/clangd/FeatureModule.cpp b/clang-tools-extra/clangd/FeatureModule.cpp
index 872cea1443789..38461e3db4e6b 100644
--- a/clang-tools-extra/clangd/FeatureModule.cpp
+++ b/clang-tools-extra/clangd/FeatureModule.cpp
@@ -22,6 +22,10 @@ FeatureModule::Facilities &FeatureModule::facilities() {
return *Fac;
}
+void FeatureModuleSet::add(std::unique_ptr<FeatureModule> M) {
+ Modules.push_back(std::move(M));
+}
+
bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
const char *Source) {
if (!Map.try_emplace(Key, M.get()).second) {
@@ -33,5 +37,16 @@ bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
return true;
}
+FeatureModuleSet FeatureModuleSet::fromRegistry() {
+ FeatureModuleSet ModuleSet;
+ for (FeatureModuleRegistry::entry E : FeatureModuleRegistry::entries()) {
+ vlog("Adding feature module '{0}' ({1})", E.getName(), E.getDesc());
+ ModuleSet.add(E.instantiate());
+ }
+ return ModuleSet;
+}
+
} // namespace clangd
} // namespace clang
+
+LLVM_INSTANTIATE_REGISTRY(clang::clangd::FeatureModuleRegistry)
diff --git a/clang-tools-extra/clangd/FeatureModule.h b/clang-tools-extra/clangd/FeatureModule.h
index 7b6883507be3f..ee65aa8a59ed2 100644
--- a/clang-tools-extra/clangd/FeatureModule.h
+++ b/clang-tools-extra/clangd/FeatureModule.h
@@ -15,6 +15,7 @@
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/JSON.h"
+#include "llvm/Support/Registry.h"
#include <memory>
#include <optional>
#include <type_traits>
@@ -143,9 +144,14 @@ class FeatureModule {
/// A FeatureModuleSet is a collection of feature modules installed in clangd.
///
-/// Modules can be looked up by type, or used via the FeatureModule interface.
-/// This allows individual modules to expose a public API.
-/// For this reason, there can be only one feature module of each type.
+/// Modules added with explicit type specification can be looked up by type, or
+/// used via the FeatureModule interface. This allows individual modules to
+/// expose a public API. For this reason, there can be only one feature module
+/// of each type.
+///
+/// Modules added using a base class pointer can be used only via the
+/// FeatureModule interface and can't be looked up by type, thus custom public
+/// API (if provided by the module) can't be used.
///
/// The set owns the modules. It is itself owned by main, not ClangdServer.
class FeatureModuleSet {
@@ -164,6 +170,8 @@ class FeatureModuleSet {
public:
FeatureModuleSet() = default;
+ static FeatureModuleSet fromRegistry();
+
using iterator = llvm::pointee_iterator<decltype(Modules)::iterator>;
using const_iterator =
llvm::pointee_iterator<decltype(Modules)::const_iterator>;
@@ -172,6 +180,7 @@ class FeatureModuleSet {
const_iterator begin() const { return const_iterator(Modules.begin()); }
const_iterator end() const { return const_iterator(Modules.end()); }
+ void add(std::unique_ptr<FeatureModule> M);
template <typename Mod> bool add(std::unique_ptr<Mod> M) {
return addImpl(&ID<Mod>::Key, std::move(M), LLVM_PRETTY_FUNCTION);
}
@@ -185,6 +194,8 @@ class FeatureModuleSet {
template <typename Mod> int FeatureModuleSet::ID<Mod>::Key;
+using FeatureModuleRegistry = llvm::Registry<FeatureModule>;
+
} // namespace clangd
} // namespace clang
#endif
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index f287439f10cab..1856d4f47ffc5 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -13,6 +13,7 @@
#include "Config.h"
#include "ConfigProvider.h"
#include "Feature.h"
+#include "FeatureModule.h"
#include "IncludeCleaner.h"
#include "PathMapping.h"
#include "Protocol.h"
@@ -1017,6 +1018,10 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
: static_cast<int>(ErrorResultCode::CheckFailed);
}
+ FeatureModuleSet ModuleSet = FeatureModuleSet::fromRegistry();
+ if (ModuleSet.begin() != ModuleSet.end())
+ Opts.FeatureModules = &ModuleSet;
+
// Initialize and run ClangdLSPServer.
// Change stdin to binary to not lose \r\n on windows.
llvm::sys::ChangeStdinToBinary();
|
|
@kadircet Sorry to bother you. Can you please take a look on this once again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot! sorry i got tangled up in couple of other things, hoping to catch up on rest of the reviews soon.
clang-tools-extra/clangd/unittests/FeatureModulesRegistryTests.cpp
Outdated
Show resolved
Hide resolved
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/16372 Here is the relevant piece of the build log for the reference |
* main: (1562 commits) Document Policy on supporting newer C++ standard in LLVM codebase (llvm#156823) [MLIR][Transform][SMT] Introduce transform.smt.constrain_params (llvm#159450) Reapply "[compiler-rt] Remove %T from shared object substitutions (llvm#155302)" [NFC] [IndVarSimplify] Add non-overflowing usub test (llvm#159683) [Github] Remove separate tools checkout from pr-code workflows (llvm#159967) [clang] fix using enum redecl in template regression (llvm#159996) [DAG] Skip `mstore` combine for `<1 x ty>` vectors (llvm#159915) [mlir] Expose optional `PatternBenefit` to `func` populate functions (NFC) (llvm#159986) [LV] Set correct costs for interleave group members. [clang] ast-dump: use template pattern for `instantiated_from` (llvm#159952) [ARM] ha-alignstack-call.ll - regenerate test checks (llvm#159988) [LLD][MachO] Silence warning when building with MSVC [llvm][Analysis] Silence warning when building with MSVC [LV] Skip select cost for invariant divisors in legacy cost model. [Clang] Fix an error-recovery crash after d1a80de (llvm#159976) [VPlanPatternMatch] Introduce m_ConstantInt (llvm#159558) [GlobalISel] Add G_ABS computeKnownBits (llvm#154413) [gn build] Port 4cabd1e Reland "[clangd] Add feature modules registry" (llvm#154836) [LV] Also handle non-uniform scalarized loads when processing AddrDefs. ...
Reland #153756
LLVM_INSTANTIATE_REGISTRY(..) and FeatureModuleRegistry::entries() were in different translation units, that rises a warning when compiling with clang and leads to compilation failure if -Werror flag is set.
Instead of iterating directly in the main function, a static method FeatureModuleSet::fromRegistry() was added and it is called in the main function.