RecursiveASTVisitor needs to traverse TypeConstraint::ImmediatelyDeclaredConstraint
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
just some drive-by comments.
clang-tools-extra/clangd/unittests/FindTargetTests.cpp | ||
---|---|---|
457 | Flags is preserved between EXPECT_DECLS calls, so either use assignment or set it only once at the beginning of the test. | |
clang/include/clang/AST/ExprConcepts.h | ||
132 ↗ | (On Diff #279135) | i think we should have some tests in clang, at least an ast-dump test in clang/test/AST/ (for both cases) and possibly also in clang/unittests/AST/SourceLocationTest.cpp |
as you mentioned in the description, there are two problems, I'd prefer address them in two different patches.
clang/include/clang/AST/ExprConcepts.h | ||
---|---|---|
132 ↗ | (On Diff #279135) | +1, ast-dump should be enough to test the invalid end loc, I have a D84461 to slightly improve the dump. |
clang/include/clang/AST/RecursiveASTVisitor.h | ||
1780 | Looks like we may visit some nodes in ConceptReference twice:
It is sad that we don't have enough test coverage, could you write some tests in clang/unittests/Tooling/RecursiveASTVisitorTests/? |
clang/include/clang/AST/ExprConcepts.h | ||
---|---|---|
132 ↗ | (On Diff #279135) | Will do. By the way, is there something more tailored than ninja check-clang to run these ast-dump tests? ninja check-clang takes quite a while to run... |
Spun off the source-location issue to D84613.
Some other review comments remain to be addressed.
clang/include/clang/AST/RecursiveASTVisitor.h | ||
---|---|---|
1780 | It is true that there will be two calls to TraverseConceptReference(). However, they are called on two different ConceptReference objects:
So, I think this is fine -- there are two distinct ConceptReference objects in the AST, and with this patch we visit both of them. |
clang-tools-extra/clangd/unittests/FindTargetTests.cpp | ||
---|---|---|
435 | I'd like to keep this clangd-specific test coverage as I think it's valuable to have. However, I can spin it off into a separate patch if you prefer. |
Will do. By the way, is there something more tailored than ninja check-clang to run these ast-dump tests? ninja check-clang takes quite a while to run...
You can use check-clang-ast for the lit tests in AST/, check-clang-sema for the lit tests in Sema/ and so on. Or you can run an individual test with llvm-lit ~/path/to/the/lit/test.
clang/include/clang/AST/RecursiveASTVisitor.h | ||
---|---|---|
1780 | I understand that they are two different ConceptReference objects, but they have members (FoundDecl, ArgsAsWritten) that may refer to the same AST nodes. template <typename T, typename U> concept binary_concept = true; struct Foo {}; template<binary_concept<Foo> T> // the template argument Foo will be visited twice. void k2(); I'm not sure what's is the right approach here, I can see two options:
@rsmith, do you have any idea about this? |
clang/include/clang/AST/RecursiveASTVisitor.h | ||
---|---|---|
1780 | From clangd's point of view, it would be sufficient to visit the immediately-declared-constraint-expr without visiting any of its descendants. However, I'm not sure how to accomplish this using RecursiveASTVisitor. (I think I'd want to call WalkUpFromXXX(TC->getImmediatelyDeclaredConstraint()), where XXX is the dynamic type of the immediately-delcared-constraint, but I don't know how to dispatch to that dynamic type; RecursiveASTVisitor seems to be designed to do the dispatch on Traverse calls, not WalkUpFrom calls). |
clang/include/clang/AST/RecursiveASTVisitor.h | ||
---|---|---|
1780 | Thinking more about this. I'm aligned on the idea of only traversing the immediately declared constraint since the TypeContraint is a wrapper of it. The regression is that we'd not perform traversal if the immediately declared constraint is nullptr (this just happens for broken code). Fix ideas:
|
clang/include/clang/AST/RecursiveASTVisitor.h | ||
---|---|---|
1780 | Thanks, this suggestion makes sense to me. I went with the second approach. |
I'd like to keep this clangd-specific test coverage as I think it's valuable to have. However, I can spin it off into a separate patch if you prefer.