[clang] [clang-tools-extra] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 29 00:41:13 PST 2024
================
@@ -138,15 +138,9 @@ std::string getNamespaceScope(const Decl *D) {
std::string printDefinition(const Decl *D, PrintingPolicy PP,
const syntax::TokenBuffer &TB) {
- if (auto *VD = llvm::dyn_cast<VarDecl>(D)) {
- if (auto *IE = VD->getInit()) {
- // Initializers might be huge and result in lots of memory allocations in
- // some catostrophic cases. Such long lists are not useful in hover cards
- // anyway.
- if (200 < TB.expandedTokens(IE->getSourceRange()).size())
- PP.SuppressInitializers = true;
- }
- }
+ // Initializers might be huge and result in lots of memory allocations in some
+ // catostrophic cases. Such long lists are not useful in hover cards anyway.
+ PP.EntireContentsOfLargeArray = false;
----------------
kadircet wrote:
i am not sure if this completely addresses the previous implementation. e.g. we can have a nested initializer list, which never has more than N elements directly, but the overall initalizer list might be huge. in such a scenario, we'll still end up allocating lots of strings.
so can we keep the old filtering while also setting this flag here? note that it'll still be ~incomplete. a more concrete approach could be based on counting number of "total" elements in the initializer list, and setting the suppression flag based on that. i'd actually lean towards such a solution, WDYT?
https://github.com/llvm/llvm-project/pull/79746
More information about the cfe-commits
mailing list