llvm / llvm/llvm-project

[clangd] When a header file is modified, the corresponding source file is not re-parsed if the inclusion of that header file happens outside the preamble

Open
#189,804 1 comment 0 reactions 0 assignees View on GitHub
clangd
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Initially problem was reported here https://github.com/clangd/clangd/issues/107
And the fix https://github.com/llvm/llvm-project/commit/596b63ad4019e61030803789a1844a0f1aeb34db covers only cases when modified header is included inside the preamble bounds (preamble became incompatible if one of files used by the preamble have changed)

But if include of the modified file somewhere after the preamble, the source file won't be reparsed.
E.g.
```
#include "dummy.h"
int test;

#include "modified.h" // modification of this file doesn't lead to the file reparsing.
// some usages of symbols from "modified.h"
```

This may not be the most common case, but we encountered this problem when trying to not build a preamble https://github.com/llvm/llvm-project/pull/189284#issuecomment-4154226212

I see the following abilities to fix this:
- use cached ASTs when possible. If we have AST in a cache, we can check include structure. Relatively easy to implement, but limited with AST cache size (3 by default)
- add file dependencies into the dynamic index. As far as dynamic index is relatively small, maybe this solution can be preferred. This information also can be used to get compile command for a header (currently we choose it based on heuristics, but better to ensure that we borrow compile command from a file which really includes this header file)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.