This is an archive of the discontinued LLVM Phabricator instance.

[clangd] add a config knob to disable modules
Needs ReviewPublic

Authored by sammccall on Jul 15 2023, 11:54 PM.

Details

Reviewers
kadircet
Summary

We don't yet have any intentional modules support:
https://github.com/clangd/clangd/issues/1293

However if the user has modules-related flags in their CDB, modules will still
be enabled inside clang.

  • for some configurations this works well enough, apparently. We should allow them to keep using this config if they wish, though unsupported.
  • for other configurations this is crashy/buggy. We can't really control the behavior/stability, so long-term this should not be the default.
  • there is no flag to disable modules if when using -std=c++20. Since clangd does not support modules, we should provide a mechanism.
  • in future we're likely to explicitly add modules support. This will not be a simple passthrough of flags to clang, so we'll need another mode.

This patch adds a config option:

CompileFlags:
  NaiveModules: false

For now, the default is true, and modules are internally enabled/disabled
according to compile flags. When set to false, we force Modules/CPlusPlusModules
lang opts off.

Diff Detail

Event Timeline

sammccall created this revision.Jul 15 2023, 11:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2023, 11:54 PM
Herald added a subscriber: arphaman. · View Herald Transcript
sammccall requested review of this revision.Jul 15 2023, 11:54 PM
sammccall added inline comments.Jul 15 2023, 11:56 PM
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
497

For existing tests of how modules interacts with other features, testing these with modules-enabled seems sufficient.

For tests that were specifically about modules, I think it makes sense to test in both modes (behavior may differ).

nridge added a subscriber: nridge.Jul 16 2023, 12:57 PM
kadircet added inline comments.Jul 19 2023, 6:35 AM
clang-tools-extra/clangd/unittests/ModulesTests.cpp
34

testing behaviour indirectly through config options cause some troubles in the long term (e.g. when we want to change the default behaviour a bunch of tests observe a different behaviour all of a sudden, or when we want to override behaviour at different layers it's hard to compose as we can't overlay configs but only override them)

so can we have this as a ParseInput::ParseOption instead? as discussed we can set it in ASTWorker, without doing the extra IO.

(you've got more context as we discussed this offline, there's also a solution that provides tests with the ability to have a different default "test" config and flips bits on it, but that's a little bit more involved so no need to block this patch on it)