Skip to content

Symbol tags in SymbolInformation, WorkspaceSymbol, CallHierarchyItem and TypeHierarchyItem#170103

Open
ratzdi wants to merge 30 commits intollvm:mainfrom
aboutthinkdigital:users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info
Open

Symbol tags in SymbolInformation, WorkspaceSymbol, CallHierarchyItem and TypeHierarchyItem#170103
ratzdi wants to merge 30 commits intollvm:mainfrom
aboutthinkdigital:users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info

Conversation

@ratzdi
Copy link
Copy Markdown
Contributor

@ratzdi ratzdi commented Dec 1, 2025

This PR is continuation of #167536.

What is new?

It adds code to compute symbol tags for the following types:
SymbolInformation
WorkspaceSymbol
CallHierarchyItem
TypeHierarchyItem

Calculation of the symbol tags Overrides and Implements
Calculation of symbol tags during the AST creation and embedding them in Symbol.

Minor change on struct Symbol to minimize paddings and thus reducing momory consumption.

Related issues:

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 1, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@ratzdi ratzdi mentioned this pull request Dec 16, 2025
@ratzdi ratzdi force-pushed the users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info branch 2 times, most recently from 6108868 to 6249e32 Compare January 21, 2026 14:57
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 23, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 23, 2026

🐧 Linux x64 Test Results

  • 4927 tests passed
  • 7 tests skipped

✅ The build succeeded and all tests passed.

@ratzdi ratzdi force-pushed the users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info branch 3 times, most recently from 5633044 to 96218ec Compare January 25, 2026 21:20
@ratzdi ratzdi marked this pull request as ready for review January 25, 2026 21:26
@ratzdi ratzdi force-pushed the users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info branch from 96218ec to 79c265d Compare January 25, 2026 21:38
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 27, 2026

🪟 Windows x64 Test Results

  • 3152 tests passed
  • 30 tests skipped

✅ The build succeeded and all tests passed.

@ratzdi ratzdi force-pushed the users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info branch from cd4aecb to 007764f Compare February 27, 2026 10:13
ratzdi added 2 commits March 4, 2026 10:40
Changed the usage of SymbolTag:
- Abstract = pure virtual
- Virtual = a virtual method implemented in that class, not implementing or overriding a method from base class
- Implements = implements pure virtual method from base class
- Override = overriding a virtual method implemented in base class
- Final = final method
@ratzdi ratzdi force-pushed the users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info branch from 31a4fd5 to 2c0475f Compare March 5, 2026 14:52
@ratzdi ratzdi force-pushed the users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info branch from ffb31c3 to fad6461 Compare March 31, 2026 07:18
64-bit

The problematic areas are:

SymInfo (6 bytes) → followed by a 2-byte gap
Origin (2 bytes) → followed by a 2-byte gap before StringRef
Tags (4 bytes) → followed by a 4-byte gap before SmallVector
Flags at the end → 7 bytes end padding

32-bit

SymInfo → 2-byte gap
Origin → 2-byte gap
Flags at the end → 3 bytes end padding

This patch reduces paddings:
64-bit: 240 -> 232 (-8 Bytes, ~3.3%)
32-bit: 144 -> 140 (-4 Bytes, ~2.8%)
@ratzdi
Copy link
Copy Markdown
Contributor Author

ratzdi commented Mar 31, 2026

preliminary results:
clangd version > 18.01.3 this branch main @07ff1a63
background index ~1400 MB ~2972 MB ~2903 MB
index cache disk usage ~159 MB ~188 MB ~187 MB

Unrelated to this patch but, wow, that doubling of the index memory usage between 18.x and trunk is quite something. That probably deserves to be spun out into a separate issue and investigated further.

I cannot explain how the outlier occurred in the first measurement with 18.1.3. In the second measurement with 18.1.3, the memory/disc consumption is now more consistent.

current results:
clangd version > 18.1.3 this branch main @07ff1a63
background index ~2721 MB ~2972 MB ~2903 MB
index cache disk usage ~184 MB ~188 MB ~187 MB

Minor change on struct Symbol to minimize paddings:

64-bit

The problematic areas are:

SymInfo (6 bytes) → followed by a 2-byte gap
Origin (2 bytes) → followed by a 2-byte gap before StringRef
Tags (4 bytes) → followed by a 4-byte gap before SmallVector
Flags at the end → 7 bytes end padding

32-bit

SymInfo → 2-byte gap
Origin → 2-byte gap
Flags at the end → 3 bytes end padding

current results for the patch f99012b:

 clangd version > 18.1.3 before f99012b this from f99012b main @07ff1a63
background index ~2721 MB ~2972 MB ~2810 MB ~2903 MB
index cache disk usage ~184 MB ~188 MB ~188 MB ~187 MB

This patch f99012b reduces paddings:
64-bit: 240 -> 232 (-8 Bytes, ~3.3%)
32-bit: 144 -> 140 (-4 Bytes, ~2.8%)

Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp
Comment thread clang-tools-extra/clangd/FindSymbols.cpp
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/index/SymbolCollector.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Apply consistent SymbolTag filtering for indexed C++ methods

Introduce `getSymbolTags(const Symbol&)` and use it for index-backed symbol
paths so tag filtering is applied consistently outside AST-based code paths.

- add `getSymbolTags(const Symbol&)` in `FindSymbols` and document behavior
- apply method-specific tag filtering in:
  - workspace symbols (`FindSymbols.cpp`)
  - hierarchy items (`XRefs.cpp`)
- simplify `filterSymbolTags` to operate on `SymbolTags` only
- keep `Declaration`/`Definition` tags for virtual/override/implements cases
  (only remove tags that are semantically implied, e.g. `Virtual` by
  `Overrides`/`Implements`/`Abstract`)
- update unit tests in `FindSymbolsTests.cpp` and
  `SymbolCollectorTests.cpp` to assert the new expected tag sets
- use `getSymbolTags(...)` in tests instead of directly expanding raw bitmasks
- minor cleanup in `SymbolCollector::addDeclaration` tag assignment ordering
@ratzdi ratzdi force-pushed the users/ratzdi/symbol_tags_in_call_type_hierarchies_and_symbol_info branch from dd4d9fc to 317abd3 Compare April 16, 2026 10:36
@ratzdi ratzdi requested a review from timon-ul April 17, 2026 11:00
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/index/SymbolCollector.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp
Comment thread clang-tools-extra/clangd/FindSymbols.cpp
ratzdi added 4 commits April 21, 2026 14:59
Refine filterSymbolTags semantics for method-related tags

Improve SymbolTag normalization in `filterSymbolTags` by making tag
precedence explicit and handling redundant combinations consistently.

Changes:
- Introduce local bitmask constants (`Virtual`, `Overrides`, `Implements`,
  `Abstract`, `Final`) for readability and maintainability.
- Keep precedence logic explicit:
  - `Implements` removes `Overrides` and `Virtual`
  - `Overrides` removes `Virtual`
  - `Abstract` removes `Virtual`
  - `Final` removes redundant `Virtual`/`Overrides`
- Align inline comments with actual filtering behavior.

This makes tag filtering easier to reason about and avoids inconsistent
symbol-tag output for C++ methods.
Replace raw integer-based SymbolTags with a dedicated strong type that is
tied to SymbolTag and sanitizes invalid bits. This removes a fragile coupling
between SymbolTag and SymbolTags and prevents representing non-existing tags.

Update clangd tag logic and serialization paths accordingly:
- switch tag construction/checks to SymbolTags::fromTag()/typed operations
- keep existing on-disk bit positions compatible
- adapt RIFF/YAML serialization to read/write raw SymbolTags storage safely
- update serialization tests to use the typed SymbolTags API

This improves robustness and maintainability while preserving behavior and
backward compatibility of serialized tag values.
@ratzdi ratzdi requested a review from timon-ul April 22, 2026 13:42
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/index/YAMLSerialization.cpp Outdated
Comment thread clang-tools-extra/clangd/index/YAMLSerialization.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/index/Symbol.h Outdated
ratzdi added 4 commits April 27, 2026 09:39
- Reused a combined mask (`RemoveVirtualAndOverrides`) to avoid repeating `~(Overrides | Virtual)`.
- Merged the two identical "remove virtual" cases (`Overrides`, `Abstract`) into one condition.
@ratzdi ratzdi requested a review from timon-ul April 28, 2026 09:00
@timon-ul
Copy link
Copy Markdown
Contributor

@ratzdi you requested a review but you did not undo the changes we talked about? SymbolTags is still a class. Unless I misunderstood you.

Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Comment thread clang-tools-extra/clangd/FindSymbols.cpp Outdated
Copy link
Copy Markdown
Contributor

@timon-ul timon-ul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now, @HighCommander4 please have a look next :)

@ratzdi ratzdi requested a review from HighCommander4 April 30, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants