[PATCH] D151785: [clangd] Desugar dependent type aliases for auto type hints

Younan Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 31 00:26:59 PDT 2023


zyounan created this revision.
Herald added subscribers: jeroen.dobbelaere, kadircet, arphaman.
Herald added a project: All.
zyounan requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This patch alleviates https://github.com/clangd/clangd/issues/1298.

Containers in C++ such as `std::vector` or `llvm::SmallVector`,
introduce a series of type aliases to adapt to generic algorithms.

Currently, If we write an declarator involving expressions with
these containers and `auto` placeholder, we probably obtain opaque
type alias like following:

  c++
  std::vector<int> v = {1, 2, 3};
  auto value = v[1]; // hint for `value`: value_type
  auto *ptr = &v[0]; // hint for `ptr`: value_type *

These hints are useless for most of the time. It would be nice if we
desugar the type of `value_type` and print `int`, `int *` respectively
in this situation. However, things are complicated if user introduces type-
alias for brevity: we don't want to make the length of hints be too long!

This patch introduces a heuristic method that displays the desugared type
for type-aliases that depend on some template parameters or simply
reduce to builtin types e.g. int, double.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151785

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151785.526935.patch
Type: text/x-patch
Size: 6573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230531/27dd6a98/attachment.bin>


More information about the cfe-commits mailing list