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 c++17 fold expression #234

Merged
merged 1 commit into from Feb 8, 2023

Conversation

i-garrison
Copy link
Contributor

No description provided.

@jonahgraham jonahgraham added the language C/C++ Language Support label Jan 16, 2023
@jonahgraham
Copy link
Member

Added call for reviewers on cdt-dev. If none are forthcoming we'll need a plan-B (me learning this area?)

@ddscharfe
Copy link
Contributor

  • AST2TemplateTests::testFoldExpression1() fails on my machine on line 11426.
  • I get Invalid overload of 'std::endl' for the following example, don't know if this is a use case you want to cover:
#include <iostream>

template<typename ... T>
void sum(T ... vals) {
	std::cout << "Total = " << (... + vals) << std::endl;
}

int main() {
	sum(1, 2, 3);
	return 0;
}

@i-garrison
Copy link
Contributor Author

  • AST2TemplateTests::testFoldExpression1() fails on my machine on line 11426.

Yes this test actually depends on pack expansion fix #230 to calculate size of char array in the third argument. If #230 will get delayed I'll change this test to just use simple types to not stumble upon that composite access issue.

@i-garrison
Copy link
Contributor Author

  • I get Invalid overload of 'std::endl' for the following example, don't know if this is a use case you want to cover:

Thanks, this turned out to be a bug in implementation - fixed and added a test for fold expression inside binary expression.

Copy link
Contributor

@ddscharfe ddscharfe left a comment

Choose a reason for hiding this comment

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

LGTM.

As the logic you implemented is not trivial (at least to me), it might be good to add some additional tests. E.g. there is no test for the parser part which checks if there are more than one folds. I don't know if you are aware, but you can launch the tests as coverage and you will get a report about which code lines are covered by tests.
However there is no requirement for having a certain test coverage.

One thing I noticed is that the parser does not complain about some errors, e.g.

template<typename ... T>
void sum(T const ... vals) {
	auto foo = bar (...+vals);
}

or

template<typename ... T>
void sum(T const ... vals) {
	...+vals;
}

Not sure if this intended, but I think it is okay, because the compiler will complain later.

@i-garrison i-garrison marked this pull request as draft January 24, 2023 17:20
@i-garrison
Copy link
Contributor Author

template<typename ... T>
void sum(T const ... vals) {
	...+vals;
}
    

Not sure if this intended, but I think it is okay, because the compiler will complain later.

I now fixed two cases that you indicated by limiting fold expression recognition to primary expression case. Will try to add more tests.

Looking back I might have started adding fold expression to parser in the wrong place (altering binary expression handling) but at the time changing the proper place (primary expression handling) looked too difficult for me.

@i-garrison i-garrison marked this pull request as ready for review January 24, 2023 21:42
@i-garrison
Copy link
Contributor Author

Rebased to master after #230 merged to resolve ITypeMarshalBuffer constants.

@github-actions
Copy link

github-actions bot commented Jan 26, 2023

Test Results

     594 files       594 suites   17m 20s ⏱️
10 141 tests 10 118 ✔️ 22 💤 1
10 157 runs  10 134 ✔️ 22 💤 1

For more details on these failures, see this check.

Results for commit 44cab9a.

♻️ This comment has been updated with latest results.

@jonahgraham
Copy link
Member

Looking back I might have started adding fold expression to parser in the wrong place (altering binary expression handling) but at the time changing the proper place (primary expression handling) looked too difficult for me.

I don't know if anyone else can comment/confirm that at the high level you have the addition in the correct place.

This change is also large and needs a quick run through the IP team, quoted from eclipsefdn/eca check:

Eclipse Intellectual Property Management:

Some contributions of code to be maintained by Eclipse Projects must be reviewed by the IP Team; in particular if they contain third party content and/or are over 1,000 Lines of Code. Further information can be read via the Eclipse Handbook.

@i-garrison
Copy link
Contributor Author

This change is also large and needs a quick run through the IP team, quoted from eclipsefdn/eca check:

Eclipse Intellectual Property Management:
Some contributions of code to be maintained by Eclipse Projects must be reviewed by the IP Team; in particular if they contain third party content and/or are over 1,000 Lines of Code. Further information can be read via the Eclipse Handbook.

I'm sure this is mostly due to long lists of allowed fold expression operators )) Happy to assist if needed.

@jonahgraham
Copy link
Member

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.

This looks fine to me. Needs iplab resolved before it can be merged.

Thanks @i-garrison for the improvement and thanks @ddscharfe for reviewing.

@i-garrison
Copy link
Contributor Author

The iplab entry is here https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/6713

Hi @jonahgraham would you believe we can get this approved before next milestone deadline?

I'm thinking about yet another bugfix, which is not critical though - the fold expression validity check is currently too permissive. This does not affect valid code and does not affect parsing of fold expression either, so I'm planning to submit the improvement later after this PR is hopefully merged.

@jonahgraham
Copy link
Member

The iplab entry is here https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/6713

Hi @jonahgraham would you believe we can get this approved before next milestone deadline?

I hope so! My past experience of reviews of this type have been very quick. I have pinged the IP team too.

I'm thinking about yet another bugfix, which is not critical though - the fold expression validity check is currently too permissive. This does not affect valid code and does not affect parsing of fold expression either, so I'm planning to submit the improvement later after this PR is hopefully merged.

Fair enough, I hope that the IP process isn't too cumbersome. Once you have a track record of contributions then you can become a committer on the project, as a committer your changes don't need further IP reviews as the committer agreement handles that.

@jonahgraham jonahgraham added this to the 11.1.0 milestone Feb 4, 2023
@jonahgraham jonahgraham added the ipteam PR is waiting on a review from Eclipse Foundation IP team label Feb 4, 2023
@jonahgraham jonahgraham merged commit f2f8623 into eclipse-cdt:main Feb 8, 2023
@jonahgraham jonahgraham removed the ipteam PR is waiting on a review from Eclipse Foundation IP team label Feb 8, 2023
@jonahgraham
Copy link
Member

The ipteam have completed their review and therefore I have merged this change.

Thanks @i-garrison!

@jonahgraham
Copy link
Member

Oops, I guess I should have rebased the PR before merging it, unfortunately this PR did not apply cleanly, it led to compilation errors:

Error:  Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:2.7.5:compile (default-compile) on project org.eclipse.cdt.core.tests: Compilation failure: Compilation failure: 
Error:  /home/runner/work/cdt/cdt/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/FoldExpressionTests.java:[108] 
Error:  	IASTTranslationUnit tu = parse(code, CPP, false, false);
Error:  	                         ^^^^^
Error:  The method parse(String, ParserLanguage, AST2TestBase.ScannerKind, boolean) in the type AST2TestBase is not applicable for the arguments (String, ParserLanguage, boolean, boolean)
Error:  /home/runner/work/cdt/cdt/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/FoldExpressionTests.java:[120] 
Error:  	IASTTranslationUnit tu = parse(code, CPP, false, false);
Error:  	                         ^^^^^
Error:  The method parse(String, ParserLanguage, AST2TestBase.ScannerKind, boolean) in the type AST2TestBase is not applicable for the arguments (String, ParserLanguage, boolean, boolean)
Error: [ERROR] 2 problems (2 errors)
Error:  -> [Help 1]
Error:  
Error:  To see the full stack trace of the errors, re-run Maven with the -e switch.
Error:  Re-run Maven using the -X switch to enable full debug logging.
Error:  
Error:  For more information about the errors and possible solutions, please read the following articles:
Error:  [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Error:  
Error:  After correcting the problems, you can resume the build with the command
Error:    mvn <args> -rf :org.eclipse.cdt.core.tests
Error: Process completed with exit code 1.

I have created a revert PR here: #278 - but I will have a quick go fixing the error before I merge #278.

jonahgraham added a commit to jonahgraham/cdt that referenced this pull request Feb 8, 2023
PR eclipse-cdt#234 had a compilation error once it was rebased which
wasn't identified until after it was rebased and merged
to main causing build to fail.

This PR is to fix that rebase error.
@jonahgraham
Copy link
Member

#279 has the fixup. The issue was the change that had happened in parallel changing boolean -> ScannerKind in 5622e59

jonahgraham added a commit that referenced this pull request Feb 8, 2023
PR #234 had a compilation error once it was rebased which
wasn't identified until after it was rebased and merged
to main causing build to fail.

This PR is to fix that rebase error.
@i-garrison i-garrison deleted the pr/c++17-fold-expression branch February 8, 2023 06:46
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.

None yet

3 participants