Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for c++17 deduction guides #344

Merged

Conversation

i-garrison
Copy link
Contributor

No description provided.

@i-garrison i-garrison force-pushed the pr/c++17-deduction-guides-basic branch from e4ecc2f to 98f5736 Compare March 27, 2023 22:56
@jonahgraham
Copy link
Member

@ddscharfe are you interested in doing another review?

@i-garrison this one is a bit bigger and I think it needs me to have more knowledge before I can review it properly. I will revisit if @ddscharfe isn't able to review.

@jonahgraham jonahgraham added the language C/C++ Language Support label Apr 4, 2023
@ddscharfe
Copy link
Contributor

@i-garrison @jonahgraham I'm afraid I won't be able to find the time to review this thoroughly very soon. Maybe I can do a quick review next week, but I can't promise.

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My overall impression is that this change looks of @i-garrison's standard high quality PRs. I don't quite follow all the changes as many of them are in areas I am not familiar with. I would really like it if someone at least gives it a once over and I am grateful @ddscharfe that you may have a few minutes for this.

public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTestBase {
private static void cxx17SetUp() {
// // STD C++ parts
// TestScannerProvider.sDefinedSymbols.put("__SIZEOF_SHORT__", "2");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I was not sure if it will have a lot of sense to somehow join AST2TestBase support for version-specific sets of macros but in the end only specific feature-detection was needed for new test. Cleaned this up now.

@jonahgraham
Copy link
Member

PS: This branch has conflicts that must be resolved conflicting files:

  • core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java
  • core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java

@i-garrison i-garrison force-pushed the pr/c++17-deduction-guides-basic branch from 98f5736 to 4b99528 Compare April 11, 2023 01:31
@i-garrison
Copy link
Contributor Author

Rebased and fixed the conflict due to change in the same method.

@i-garrison i-garrison force-pushed the pr/c++17-deduction-guides-basic branch from 4b99528 to 2864b34 Compare April 11, 2023 01:37
@ddscharfe
Copy link
Contributor

My overall impression is that this change looks of @i-garrison's standard high quality PRs.
+1, @i-garrison I really appreciate the work you put into this (and all your other PRs).

My comments so far:

  • I couldn't get this to work in my CDT debugging instance, I must be doing something wrong. If I put the code of the tests (which do pass) into my debugging instance I get errors. I even set CPPASTTranslationUnit::getEnableClassTemplateArgumentDeduction to always return true in the code to make sure I didn't mess something up with the macro, but still.
  • Is there a reason not to always enable the deduction feature? I'd like to avoid adding methods to the ICPPASTTranslationUnit interface.
  • Unfortunately I don't have more time to dig further into the code and do an appropriate code review. As expected, it all looks very reasonable but I cannot approve it ATM.

@i-garrison
Copy link
Contributor Author

Hi @ddscharfe what is your compiler version? I'm testing with GCC 11.3

Yes I believe deduction guides can be enabled unconditionally, but would like to understand what's wrong with feature macro first.

@ddscharfe
Copy link
Contributor

ddscharfe commented Apr 18, 2023

Hi @ddscharfe what is your compiler version? I'm testing with GCC 11.3

Hi! I'm using gcc 8.5.0 (default on Rocky Linux 8)

Yes I believe deduction guides can be enabled unconditionally, but would like to understand what's wrong with feature macro first.

I think it is not very intuitive from a usability standpoint. One could argue that they could be enabled by default and can be disabled via the macro. However I'd try to avoid the conditional statements in the parser code, but if there is a good reason to make the feature optional the way you implemented it is fine.

@i-garrison
Copy link
Contributor Author

i-garrison commented Apr 18, 2023

Hi @ddscharfe what is your compiler version? I'm testing with GCC 11.3

Hi! I'm using gcc 8.5.0 (default on Rocky Linux 8)

I think what happens is that according to https://gcc.gnu.org/projects/cxx-status.html#cxx17 GCC 8.5 does have lower value of feature detection macro which explains why deduction guides are not enabled. We probably can lower the expected value without losing functionality though I did not checked what's changed since 8.5

Yes I believe deduction guides can be enabled unconditionally, but would like to understand what's wrong with feature macro first.

I think it is not very intuitive from a usability standpoint. One could argue that they could be enabled by default and can be disabled via the macro. However I'd try to avoid the conditional statements in the parser code, but if there is a good reason to make the feature optional the way you implemented it is fine.

Parsing the construct takes extra lookup, so this arguably should be made optional since unless parser is able to resolve the name already, lookup has to be performed even if there are no deduction guides defined.

On the other hand if code does not use deduction guides then the only way to get into that extra lookup is via parser bug, otherwise name should be resolved as before this change.

I can drop these conditionals together with feature macro if that would be the consensus here. I did not really looked at c++20 and later changes to deduction guides to see if feature macro test should be preserved but it would not be hard to restore it later anyway.

@jonahgraham
Copy link
Member

I can drop these conditionals together with feature macro if that would be the consensus here. I did not really looked at c++20 and later changes to deduction guides to see if feature macro test should be preserved but it would not be hard to restore it later anyway.

I don't have a strong opinion one way or another. For a long time the CDT parser has been as unconditional as possible, meaning that some code is accepted by CDT but then rejected by the compiler.

As @ddscharfe has 👍 the comment I think there is as much consensus as we'll get that we drop the conditionals.

Enabling C++17 deduction guides unconditionally causes one of the tests for
template instantiation to fail because one of instantiations can be done via
implicit deduction guide using default template arguments.
Test case is covering issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=207840
and remaining erroneous cases are not affected.

Amend the test and comment about change since C++17.
@i-garrison
Copy link
Contributor Author

Thanks for this discussion! I now added another change to make deduction guides unconditional (so this can be easily reverted again if needed.)

There is one extra change required for unit test covering https://bugs.eclipse.org/bugs/show_bug.cgi?id=207840 discussion. One of test cases there should be amended because instantiation is done via implicit deduction guide using default template argument.

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have raised https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/7922 for IP signoff as this change is > 1000 LOC.

@jonahgraham jonahgraham added the ipteam PR is waiting on a review from Eclipse Foundation IP team label Apr 22, 2023
@jonahgraham jonahgraham added this to the 11.2.0 milestone Apr 22, 2023
@jonahgraham
Copy link
Member

I have raised https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/7922 for IP signoff as this change is > 1000 LOC.

Approved!

@jonahgraham jonahgraham removed the ipteam PR is waiting on a review from Eclipse Foundation IP team label Apr 25, 2023
@jonahgraham jonahgraham merged commit b965559 into eclipse-cdt:main Apr 25, 2023
@i-garrison i-garrison deleted the pr/c++17-deduction-guides-basic branch April 26, 2023 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language C/C++ Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants