This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Allow to build Clangd without decision forest
ClosedPublic

Authored by ilya-biryukov on Dec 1 2022, 6:17 AM.

Details

Summary

Make it possible to disable building the decision forest ranking
model for clangd. To unbreak build of Clangd on PPC32 in gentoo, see
https://bugs.gentoo.org/829602

Diff Detail

Event Timeline

ilya-biryukov created this revision.Dec 1 2022, 6:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 6:17 AM
ilya-biryukov requested review of this revision.Dec 1 2022, 6:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 6:17 AM

This seems to build in both modes, but I still need to figure out what to do with tests with decision forest off.
Also, maybe there is a way to minimize the use of preprocessor even more.

clang-tools-extra/clangd/decision-forest/DecisionForest.cpp
15 ↗(On Diff #479270)

Note to self: split into two namespace declarations for consistency with the rest of clangd

sammccall added inline comments.Dec 1 2022, 9:06 AM
clang-tools-extra/clangd/CMakeLists.txt
54

this muddies the waters a bit: the code in DecisionForest.cpp is *not* the generated completion model.
as mentioned below, I think it's a little clearer to have this be unconditionally a source file, and #ifdef the contents.

clang-tools-extra/clangd/Features.inc.in
7

we could include this in the feature-string too (Feature.cpp) but I think it's probably more noise than signal.

clang-tools-extra/clangd/decision-forest/DecisionForest_disabled.cpp
19 ↗(On Diff #479270)

As much as I dislike the preprocessor, I think conditionally including source files is undiscoverable enough (if you're reading the source code) that I'd have a preference for this being an #else branch in DecisionForest.cpp.

(It's also one mechanism vs two, given that we *do* still need the preprocessor elsewhere)

clang-tools-extra/clangd/tool/ClangdMain.cpp
215

hmm, while reordering these: hueristics -> heuristics? :-)

216

CodeCompleteOptions().RankingModel is also the one used in unit tests.
I think the default value in the struct should be ifdef'd, or if we really want to avoid pp-conditionals in header files, we could have an Auto value which acts sa the platform-default.

ilya-biryukov marked 4 inline comments as done.
  • Merge DecisionForest.cpp and *_disabled.cpp, change #ifndef to #if
  • Add decision_forest to the feature string
  • Set Heuristics as the default code completion model in tests
  • Do not compile decision forest tests when it's disabled
  • Remove the use of preprocessor for defining the default value of -ranking-model flag to clangd
clang-tools-extra/clangd/Features.inc.in
7

Maybe include only when it's disabled? I've added this to the commit, PTAL.

clang-tools-extra/clangd/tool/ClangdMain.cpp
215

I'm not sure how the reordering happened in the first place, TBH 🤔
I kept it and fixed the typo, but also let me know if I should keep the old order instead.

216

I have moved it to the .cpp file. I think that avoiding conditionals in the preprocessor is a good thing definitely.

I also considered putting the constant into DecisionForest.cpp to reduce the number of files that use #if CLANGD_DECISION_FOREST.
But the downside is that definition of the constant gets harder to find, so I opted for keeping it in this file.

sammccall accepted this revision.Dec 5 2022, 4:03 AM

Looks great, thanks!

clang-tools-extra/clangd/CMakeLists.txt
21

May want to add a motivating comment like "this involves generating and compiling large source files, which can run into toolchain limitations"?

(This does violate the convention that build configurations should be as mysterious as possible!)

clang-tools-extra/clangd/CodeComplete.cpp
26

Include feature.h instead of relying on it transitively?

(Important here as losing the include changes the behavior)

clang-tools-extra/clangd/CodeComplete.h
134

Nice, somehow i forgot this was an option

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
14

Feature.h here too

This revision is now accepted and ready to land.Dec 5 2022, 4:03 AM
ilya-biryukov marked 3 inline comments as done.
  • Add a comment to CMakelists.txt explaining motivation for the option
  • Add #include "Feature.h"
  • Revert changes to the order of compiler flags to keep this change more focused
  • clang-format
  • replace #ifndef with #if ! in ClangdMain.cpp
This revision was landed with ongoing or failed builds.Dec 7 2022, 4:52 AM
This revision was automatically updated to reflect the committed changes.

I have sent a follow-up NFC change to fix a typo in the documentation of --ranking-model=heuristics. Note that I decided to avoid changing the order of options for --ranking-model in the documentation, this didn't seem important.