[all-commits] [llvm/llvm-project] 7115ed: [Clang] Unify interface for accessing template arg...

Krystian Stasiowski via All-commits all-commits at lists.llvm.org
Tue May 7 11:46:13 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7115ed0fff027b65fa76fdfae215ed1382ed1473
      https://github.com/llvm/llvm-project/commit/7115ed0fff027b65fa76fdfae215ed1382ed1473
  Author: Krystian Stasiowski <sdkrystian at gmail.com>
  Date:   2024-05-07 (Tue, 07 May 2024)

  Changed paths:
    M clang-tools-extra/clangd/AST.cpp
    M clang-tools-extra/clangd/SemanticHighlighting.cpp
    M clang-tools-extra/include-cleaner/lib/WalkAST.cpp
    M clang/docs/LibASTMatchersReference.html
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/AST/DeclTemplate.h
    M clang/include/clang/AST/RecursiveASTVisitor.h
    M clang/include/clang/ASTMatchers/ASTMatchers.h
    M clang/include/clang/ASTMatchers/ASTMatchersInternal.h
    M clang/lib/AST/ASTImporter.cpp
    M clang/lib/AST/DeclPrinter.cpp
    M clang/lib/AST/DeclTemplate.cpp
    M clang/lib/AST/TypePrinter.cpp
    M clang/lib/Index/IndexDecl.cpp
    M clang/lib/Sema/Sema.cpp
    M clang/lib/Sema/SemaTemplate.cpp
    M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    M clang/lib/Serialization/ASTReaderDecl.cpp
    M clang/lib/Serialization/ASTWriterDecl.cpp
    M clang/lib/Tooling/Syntax/BuildTree.cpp
    M clang/test/AST/ast-dump-template-decls.cpp
    M clang/test/Index/Core/index-source.cpp
    M clang/test/Index/index-refs.cpp
    M clang/tools/libclang/CIndex.cpp
    M clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
    M clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

  Log Message:
  -----------
  [Clang] Unify interface for accessing template arguments as written for class/variable template specializations (#81642)

Our current method of storing the template arguments as written for
`(Class/Var)Template(Partial)SpecializationDecl` suffers from a number
of flaws:
- We use `TypeSourceInfo` to store `TemplateArgumentLocs` for class
template/variable template partial/explicit specializations. For
variable template specializations, this is a rather unintuitive hack (as
we store a non-type specialization as a type). Moreover, we don't ever
*need* the type as written -- in almost all cases, we only want the
template arguments (e.g. in tooling use-cases).
- The template arguments as written are stored in a number of redundant
data members. For example, `(Class/Var)TemplatePartialSpecialization`
have their own `ArgsAsWritten` member that stores an
`ASTTemplateArgumentListInfo` (the template arguments).
`VarTemplateSpecializationDecl` has yet _another_ redundant member
"`TemplateArgsInfo`" that also stores an `ASTTemplateArgumentListInfo`.

This patch eliminates all
`(Class/Var)Template(Partial)SpecializationDecl` members which store the
template arguments as written, and turns the `ExplicitInfo` member into
a `llvm::PointerUnion<const ASTTemplateArgumentListInfo*,
ExplicitInstantiationInfo*>` (to avoid unnecessary allocations when the
declaration isn't an explicit instantiation). The template arguments as
written are now accessed via `getTemplateArgsWritten` in all cases.

The "most breaking" change is to AST Matchers, insofar that `hasTypeLoc`
will no longer match class template specializations (since they no
longer store the type as written).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list