Details
- Reviewers
aaron.ballman erichkeane rsmith shafik cor3ntin - Group Reviewers
Restricted Project - Commits
- rG632dd6a4ca00: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Hey. Thanks a lot for working on this.
I did a first pass, looking at mostly style issues, looking at conformance will probably take me a lot more time, but i think this looks pretty good overall
clang/include/clang/AST/DeclCXX.h | ||
---|---|---|
1951 | I'm wondering if the constructor should take a DeductionCandidateKind defaulted to normal here. All the places where it's set seem to be immediately after construction. | |
1993–1997 | I'm not sure how useful these things are, isAggregateDeductionCandidate is only used once | |
clang/lib/Sema/SemaInit.cpp | ||
39 | This does not seems used | |
314 | I think using optional here would make more sense, I guess that's why you included it. | |
1103–1104 | Can you had a comment about that case? I'm not sure i understand what scenario we are handling | |
2187–2189 | Maybe using enumerate + a range for loop here would be cleaner? | |
clang/lib/Sema/SemaOverload.cpp | ||
7265–7266 |
Thanks for the quick fist-pass review. Appreciate it.
clang/include/clang/AST/DeclCXX.h | ||
---|---|---|
1951 | That's true indeed. The awkward aspect is that the CXXDeductionGuideDecl::Create call is far from setDeductionCandidateKind; making CXXDeductionGuideDecl::Create takes a DeductionCandidateKind would several other less related functions takes DeductionCandidateKind also. | |
1993–1997 | I meant to make it consistent with isCopyDeductionCandidate which is also used once. Maybe remove both isCopyDeductionCandidate and isAggregateDeductionCandidate? | |
clang/lib/Sema/SemaInit.cpp | ||
314 | I meant to make AggrDeductionCandidateParamTypes a byref semantic like FullyStructuredList. So the InitListChecker populates them as a side-effect. Using optional means the InitListChecker owes the deduced types which should work too but seems weird to me. | |
1103–1104 | Good point. On second thought, I think this is not needed. This function shouldn't accept dependent types. | |
2187–2189 | Using the iterator to test for the last element is easier. The index produced by enumerate would need to produce an iterator nevertheless. |
Sorry for not getting back to you earlier.
It mostly looks reasonable to me.
what do you think @erichkeane ?
clang/lib/Sema/SemaInit.cpp | ||
---|---|---|
10740 | I think we need to support A{("Hello")}; so we probably need to get rid of parentheses (maybe other implicit nodes?) | |
10766 | Maybe add a message here | |
clang/lib/Sema/SemaTemplate.cpp | ||
2596–2597 | Maybe we should have an asserton !isInvalid then? | |
clang/lib/Sema/SemaTemplateDeduction.cpp | ||
363 | I think you can do that in the for loop as it was before | |
995 | That could always be initialized, to avoid future surprises |
clang/include/clang/AST/DeclCXX.h | ||
---|---|---|
1993–1997 | Yes, i think we might as well |
+ @hubert.reinterpretcast In case i missed something conformance wise.
Speaking of conformance, your implementation does not appear to gate the feature on C++20, which it should, so you should add a test that it doesn't compile in c++17 (I'm not sure we could support it as an extension... maybe?)
clang/lib/Sema/SemaInit.cpp | ||
---|---|---|
13 | Do we actually need that? |
clang/lib/Sema/SemaInit.cpp | ||
---|---|---|
10676–10680 | Minor issues, we need to match the format expected by bugprone-comment | |
clang/lib/Sema/SemaOverload.cpp | ||
7386–7387 | formatting fix again. | |
clang/lib/Sema/SemaTemplate.cpp | ||
2593 | formatting. |
Thanks for your effort on this!
FYI I landed parenthesized aggregate initialization in D141546, so CTAD for that feature should no longer be blocked.
Thanks for letting me know. Considering the existing reviews, I'll create a separate patch for the parenthesized expression-list support.
@erichkeane @aaron.ballman I think we should determine how much works remains there and if the author is not responsive maybe one of us can push this up the finishing line.
That seems like a reasonable approach to me; it'd be good to get this into Clang 17 if possible, and @ychen seems to have been away for ~2 months now, so it seems reasonable to commandeer this review if we need to.
I think this is starting to look good, My biggest question is the remaining fixme, how much work would it be to do in this PR?
clang/include/clang/Sema/TemplateDeduction.h | ||
---|---|---|
237 ↗ | (On Diff #521965) | Can you specify which c++ version this quote is from? |
clang/lib/Sema/SemaTemplate.cpp | ||
2597 | Maybe you could do this in this PR? | |
clang/www/cxx_status.html | ||
1249 ↗ | (On Diff #521965) | I think this should be marked a partially supported until we support parenthesized init. |
@cor3ntin Thanks for the review. I've added the parenthesized expression-list support by treating it as braced-init-list during CTAD.
- adjust test check for Windows
- support parenthesized expression-list
- add an InitializationKind BuildingDeductionGuides to help diagnoses
Thanks, It's great to have the complete feature in on PR
clang/include/clang/Sema/Sema.h | ||
---|---|---|
9661 ↗ | (On Diff #524045) | Is that comment correct? |
clang/lib/Sema/SemaDecl.cpp | ||
12637 ↗ | (On Diff #524045) | |
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
1059–1062 ↗ | (On Diff #524045) | This seems unfinished |
Thank you for working on this! Some high-level comments while I was here; I'm still grokking the implementation.
clang/include/clang/AST/DeclBase.h | ||
---|---|---|
1689 ↗ | (On Diff #524045) | Best not to give this the same name as a type (I don't care which one changes names). |
clang/include/clang/AST/DeclCXX.h | ||
1986 | Er, seems a bit odd to cast an 8-bit type to a 64-bit type only to shove it into a 2-bit bit-field. I think DeductionCandidateKind should be an enum class whose underlying type is int and we cast to/from int as needed. | |
clang/include/clang/Sema/Sema.h | ||
3992 ↗ | (On Diff #524045) | We're up to 12 parameters for this function, five of which are bool parameters... at some point, this probably needs to be refactored. |
9346 ↗ | (On Diff #524045) |
clang/include/clang/Sema/Sema.h | ||
---|---|---|
9661 ↗ | (On Diff #524045) | Yeah, the comment seems off to me. |
clang/lib/Sema/SemaInit.cpp | ||
504–515 | We shouldn't force the caller to use the same-sized SmallVector, right? | |
1036 | Can we make this return a const RecordDecl * or does that run into viral const issues? | |
1037–1038 | ||
1039–1040 | ||
1444–1446 | Be sure to add test coverage for use of VLAs in C++ (we support it as an extension). | |
10699 | ||
10710–10711 | ||
clang/lib/Sema/SemaTemplate.cpp | ||
2576 | Something is amiss here. Either this should be using dyn_cast or it should not be in an if statement (cast cannot fail; it asserts if it does). | |
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
1059–1062 ↗ | (On Diff #524045) | +1 |
- address existing comments
clang/include/clang/AST/DeclBase.h | ||
---|---|---|
1689 ↗ | (On Diff #524045) | I've changed the type name and kept this as is. |
clang/include/clang/Sema/Sema.h | ||
3992 ↗ | (On Diff #524045) | Agreed. I will keep my eye on it. |
clang/lib/Sema/SemaInit.cpp | ||
504–515 | That's right. | |
1036 | "viral const issues". Deep somewhere else needs it non-const. | |
1444–1446 | Array::a2 test case covers this. | |
clang/lib/Sema/SemaTemplate.cpp | ||
2576 | It's the getDefinition() that may be null. I've hoist the cast out to make it obvious. | |
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
1059–1062 ↗ | (On Diff #524045) | I meant to keep this a future work since this path is dead until some errors could be thrown out of this context. In the future, if errors happen during building deduction guides, this assertion failure could trigger at build time. |
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
---|---|---|
1059–1062 ↗ | (On Diff #524045) | In this case, maybe change the message |
clang/lib/Sema/SemaTemplateInstantiate.cpp | ||
---|---|---|
1059–1062 ↗ | (On Diff #524045) | Done. I've made it llvm_unreachable to catch the rare chances that users hit this. |
clang/test/SemaTemplate/aggregate-deduction-candidate.cpp | ||
---|---|---|
101 ↗ | (On Diff #528918) | I would also like to see this test: template <typename T> struct I { using type = T; }; template <typename T> struct E { typename I<T>::type i; T t; }; E e1 = {1, 2}; // OK, E<int> deduced Since it is in the paper, this should cover it but it can't hurt. |
clang/test/SemaTemplate/aggregate-deduction-candidate.cpp | ||
---|---|---|
101 ↗ | (On Diff #528918) | Yep, just added this test. |
clang/include/clang/AST/DeclBase.h | ||
---|---|---|
1686 ↗ | (On Diff #528918) | Why remove [C++17] ? |
clang/include/clang/AST/DeclCXX.h | ||
1986 | It feels a bit weird that we are taking an enum w/ an underlying type of unsigned char casting it to int and then placing it in an unsigned bit-field. I don't have a better suggestion ATM but I wish we had something better. | |
clang/lib/Sema/SemaDecl.cpp | ||
12647 ↗ | (On Diff #528918) | nitpick but we seem to use Expr* everywhere else. |
clang/lib/Sema/SemaInit.cpp | ||
15 | I saw your adding headers. How did you figure out which ones were missing? | |
508 | nit | |
10680 | nit, note: PO` is not a very descriptive name. | |
10706–10707 |
| |
10734 | ||
10741 |
clang/include/clang/AST/DeclBase.h | ||
---|---|---|
1686 ↗ | (On Diff #528918) | I don't think this adds any information, I'm happy to see it removed. And arguably in c++17 there was only one kind of DG. |
- address comments
clang/include/clang/AST/DeclCXX.h | ||
---|---|---|
1986 | I've changed it to casting to underlying type of DeductionCandidate so it has one less step of conversion. | |
clang/lib/Sema/SemaInit.cpp | ||
15 | Added headers provide APIs for the new code. I guess many of them are included already indirectly (SmallVector for example). But I thought the best practice is not relying on that, so I added these. |
clang/lib/Sema/SemaInit.cpp | ||
---|---|---|
15 | I think it's easier fore reviewers not to add things are are not needed, I would suggest trying to keep the change to the list of includes to the minimum |
@ychen You probably want to update the description, i think it's updated (you implemented ctad for parenthesized ctrs)
Thanks for this! I have no concerns from what I can see, but I see the others are doing a very thorough review, so I'll let them do the approvals.
clang/include/clang/AST/DeclCXX.h | ||
---|---|---|
1951 | I'm in favor of having this be a part of CXXDeductionGuideDecl::Create and the ctor as a parameter instead as well. |
Please give @aaron.ballman a few days to get another look, but otherwise LGTM
Thanks a lot for working on this and your patience during the review.
LGTM aside from some minor issues, thank you!
clang/docs/ReleaseNotes.rst | ||
---|---|---|
98 ↗ | (On Diff #535132) | Paren aggregate init is now supported, so this should be updated. |
clang/lib/Sema/SemaInit.cpp | ||
3271–3273 | For local style consistency. | |
10688 | ||
clang/lib/Sema/SemaTemplate.cpp | ||
2577–2580 | I think this is a bit more clear as to what's happening. |
- address comments
clang/docs/ReleaseNotes.rst | ||
---|---|---|
98 ↗ | (On Diff #535132) | Thanks for catching this. |
Thanks a lot for working on this!
Do you need Aaron or myself to commit this for you? If so, which name / mail do you want us to use?
The changes to clang/www/cxx_status.html got lost during the rebase, can you fix that? Thanks!
So while working on D148474 I realized this PR introduced a new crash bug, see the following code: https://godbolt.org/z/h1EezGjbr
template<typename A3> class B3 : A3 { template<bool = C3<B3>()> B3(); }; B3();
which is one of my test cases. I had though it was an interaction between my new code and this but then realized this exists w/o my new code. We can also see from the godbolt above that the crash in this code changed from an assertion to an unreachable. My PR will fix the assertion but I need a good solution to the unreachable bug. I tried changing the unreachable to a break but it reduces the quality of the diagnostic and I don't think it is the correct fix.
Note we have a second crash linked to this PR: https://github.com/llvm/llvm-project/issues/67173#issuecomment-1733647699
I'm wondering if the constructor should take a DeductionCandidateKind defaulted to normal here. All the places where it's set seem to be immediately after construction.