Adds macro references to the dynamic index (FileIndex).
Tests added.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Unit tests: pass. 60496 tests passed, 0 failed and 726 were skipped.
clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or apply this patch.
Build artifacts: console-log.txt, CMakeCache.txt, clang-format.patch, test-results.xml, diff.json
clang-tools-extra/clangd/URI.h | ||
---|---|---|
115 ↗ | (On Diff #233561) | This function does a very specialized form of path-to-uri conversion (fallback dirs, traversing schemes, etc.) Another concern is layering. URI.h currently does not depend on SourceManager and, arguably, it should stay that way. We define an interface to extend the URI schemes that clangd supports, there's no reason for it to depend on SourceManager. |
clang-tools-extra/clangd/index/FileIndex.cpp | ||
88 | This is trying to emulate existing logic in SymbolCollector::finish. Is there a way we could share this? One potential way to do this is to have an alternative version of handleMacroOccurence, which would fill SymbolCollector::MacroRefs directly and call this right after indexTopLevelDecls. |
@ilya-biryukov thanks for taking it during my OOO, just a drive-by comment :)
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
88 | +1 on the concern about performance (this is a hot function, we are paying an extra cost of copying all refs, which should be avoided), and the layering of toURI.
the main problem is that at this point (parsing is finished), preprocessor callback is not available, so we won't see macro references (SymbolCollector::handleMacroOccurence will only receive macro definitions). I think two options:
|
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
88 | Thanks, good point, in my proposal we should populate macro references before calling indexTopLevelDecls. I would still suggest going with the first option, it seems simpler to me. But up to you, @usaxena95. |
Added another version of handleMacroOccurence to handle MacroReferences from main file.
clang-tools-extra/clangd/index/FileIndex.cpp | ||
---|---|---|
88 | This looks much better now. Thanks for your inputs Haojian and Ilya.
@hokein |
Unit tests: pass. 60496 tests passed, 0 failed and 726 were skipped.
clang-tidy: pass.
clang-format: pass.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
clang-tools-extra/clangd/index/SymbolCollector.cpp | ||
---|---|---|
350 | Does this ever happen? | |
362 | Won't we get a dangling pointer inside Refs after leaving this function? | |
clang-tools-extra/clangd/index/SymbolCollector.h | ||
108 | NIT: could you name it in plural? handleMacros or handleMacroOccurences? It's different from the other version in this regard, which adds only a single occurrence. |
clang-tools-extra/clangd/index/SymbolCollector.cpp | ||
---|---|---|
362 | Yeah I also thought the same when I saw this at other places too. But the Refs.insert(IDToRefs.first, R); actually does a copy of this string and owns the copy. | |
clang-tools-extra/clangd/index/SymbolCollector.h | ||
108 | Renamed to handleMacros to avoid confusion with the virtual method. |
LGTM
clang-tools-extra/clangd/index/SymbolCollector.cpp | ||
---|---|---|
362 | Ah, makes sense. Thanks for explaining this. | |
clang-tools-extra/clangd/unittests/FileIndexTests.cpp | ||
368 | Why do we need two tests? To test the file URI? I suggest removing Test2 completely, it does not seem to test anything new and creates noise. Unless there are things I'm missing that it test. |
Unit tests: pass. 60496 tests passed, 0 failed and 726 were skipped.
clang-tidy: pass.
clang-format: pass.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
Unit tests: pass. 60496 tests passed, 0 failed and 726 were skipped.
clang-tidy: pass.
clang-format: pass.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
Unit tests: pass. 61298 tests passed, 0 failed and 736 were skipped.
clang-tidy: fail. Please fix clang-tidy findings.
clang-format: pass.
Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml
This is trying to emulate existing logic in SymbolCollector::finish. Is there a way we could share this?
Would avoid creating extra copies of reference slabs and allow to keep the code in one place, rather than scattering it between FileIndex.cpp and SymbolCollector.cpp. Would also allow to keep toURI private, meaning we don't have to worry about naming it and the fact it's exposed in the public interface.
One potential way to do this is to have an alternative version of handleMacroOccurence, which would fill SymbolCollector::MacroRefs directly and call this right after indexTopLevelDecls.
Would that work?