[all-commits] [llvm/llvm-project] c2bf9b: Add a concept AST node.

jensmassberg via All-commits all-commits at lists.llvm.org
Thu Aug 31 01:38:37 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c2bf9baf59870532d0c503066634bf438c35184f
      https://github.com/llvm/llvm-project/commit/c2bf9baf59870532d0c503066634bf438c35184f
  Author: Jens Massberg <massberg at google.com>
  Date:   2023-08-31 (Thu, 31 Aug 2023)

  Changed paths:
    M clang/include/clang/AST/ASTConcept.h
    M clang/include/clang/AST/DeclTemplate.h
    M clang/include/clang/AST/ExprConcepts.h
    M clang/include/clang/AST/RecursiveASTVisitor.h
    M clang/include/clang/AST/TypeLoc.h
    M clang/include/clang/Serialization/ASTRecordReader.h
    M clang/include/clang/Serialization/ASTRecordWriter.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/AST/ASTImporter.cpp
    M clang/lib/AST/DeclTemplate.cpp
    M clang/lib/AST/ExprConcepts.cpp
    M clang/lib/AST/TypeLoc.cpp
    M clang/lib/Sema/SemaTemplate.cpp
    M clang/lib/Sema/SemaTemplateInstantiate.cpp
    M clang/lib/Sema/SemaType.cpp
    M clang/lib/Sema/TreeTransform.h
    M clang/lib/Serialization/ASTReader.cpp
    M clang/lib/Serialization/ASTReaderDecl.cpp
    M clang/lib/Serialization/ASTReaderStmt.cpp
    M clang/lib/Serialization/ASTWriter.cpp
    M clang/lib/Serialization/ASTWriterDecl.cpp
    M clang/lib/Serialization/ASTWriterStmt.cpp
    M clang/unittests/AST/SourceLocationTest.cpp
    M clang/unittests/Tooling/RecursiveASTVisitorTests/Concept.cpp

  Log Message:
  -----------
  Add a concept AST node.

This patch adds a concept AST node (`ConceptLoc`) and uses it at the corresponding places.

There are three objects that might have constraints via concepts:
`TypeConstraint`,  `ConceptSpecializationExpr` and `AutoTypeLoc`.
The first two inherit from `ConceptReference` while the latter has
the information about a possible constraint directly stored in `AutoTypeLocInfo`. It would be nice if the concept information would be stored the same way in all three cases.

Moreover the current structure makes it difficult to deal with these concepts. For example in Clangd accessing the locations of constraints of a `AutoTypeLoc` can only be done with quite ugly hacks.

So we think that it makes sense to create a new AST node for such concepts.

In details we propose the following:
- Rename `ConceptReference` to `ConceptLoc` (or something else what is approriate)
and make it the new AST node.
- `TypeConstraint` and `ConceptSpecializationExpr` do not longer inherit from `ConceptReference` but store a pointer to a `ConceptLoc`.
- `AutoTypeLoc` stores a pointer to `ConceptLoc` instead of storing the concept info in `AutoTypeLocInfo`.

This patch implements a first version of this idea which compiles and where the existing tests pass.
To make this patch as small as possible we keep the existing member functions to access concept data. Later these can be replaced by directly calling the corresponding functions of the `ConceptLoc`s.

Differential Revision: https://reviews.llvm.org/D155858




More information about the All-commits mailing list