8000 Switch compilation from C++17 to C++20. by fruffy · Pull Request #4347 · p4lang/p4c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Switch compilation from C++17 to C++20. #4347

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Switch compilation from C++17 to C++20. #4347

wants to merge 4 commits into from

Conversation

fruffy
Copy link
Collaborator
@fruffy fruffy commented Jan 22, 2024

C++20 is now supported in most major distributions and compilers and there are several features that are useful for us to have. Let's switch to C++20.

@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Jan 22, 2024
@vlstill
Copy link
Contributor
vlstill commented Jan 23, 2024

I started looking at this some time ago in #4297. I was probably too sneaky though. Still not complete, there is quite lot of things that break and I don't have much time for it now. The main problem is clashing operators.

@fruffy
Copy link
Collaborator Author
fruffy commented Jan 23, 2024

I started looking at this some time ago in #4297. I was probably too sneaky though. Still not complete, there is quite lot of things that break and I don't have much time for it now. The main problem is clashing operators.

I can close this PR in favor of yours. I just wanted to see what needs to be done and it seems moving up is non-trivial.

@vlstill
Copy link
Contributor
vlstill commented Jan 23, 2024

I started looking at this some time ago in #4297. I was probably too sneaky though. Still not complete, there is quite lot of things that break and I don't have much time for it now. The main problem is clashing operators.

I can close this PR in favor of yours. I just wanted to see what needs to be done and it seems moving up is non-trivial.

OK. Yes, it does not seem as easy as was the move to C++17.

@fruffy fruffy closed this Jan 23, 2024
@fruffy fruffy deleted the fruffy/C++20 branch January 23, 2024 16:49
@fruffy fruffy restored the fruffy/C++20 branch April 11, 2024 18:01
@fruffy fruffy reopened this Apr 11, 2024
@fruffy fruffy added run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. run-static Use this tag to trigger static build CI run. labels Apr 11, 2024
@fruffy fruffy marked this pull request as ready for review May 31, 2024 12:41
@fruffy
Copy link
Collaborator Author
fruffy commented May 31, 2024

There is not much missing for C++20 support. It looks like there is just one small failure left.

@vlstill
Copy link
Contributor
vlstill commented May 31, 2024

Hmm, the error is in boost, that might be hard to fix unless it is our bad usage of boost of course :-). Seems to be related to a particular version as it fails just in the sanitizers build.

What are your thoughts on switching? Do you think it is time for that? We don't get many goodies until we bump minimal required GCC, but even some things from GCC 9 are nice. It would also unlock C++20 for downstreams that have newer compilers. On the other hand, we would be having a more experimental setup, with GCC that is far from stable on C++20.

@fruffy
Copy link
Collaborator Author
fruffy commented May 31, 2024

Hmm, the error is in boost, that might be hard to fix unless it is our bad usage of boost of course :-). Seems to be related to a particular version as it fails just in the sanitizers build.

The boost version should be the same for Ubuntu 20.04 but this compiler is Clang. Maybe that is the reason.

What are your thoughts on switching? Do you think it is time for that? We don't get many goodies until we bump minimal required GCC, but even some things from GCC 9 are nice. It would also unlock C++20 for downstreams that have newer compilers. On the other hand, we would be having a more experimental setup, with GCC that is far from stable on C++20.

I am happy to switch, there are some folks that have been waiting for us to upgrade to C++20 already. We can try to be conservative with the features we introduce and keep Ubuntu 20.04 as the minimum supported version until it hits EOL.

@fruffy fruffy changed the title Switch from C++17 to C++20. Switch compilation from C++17 to C++20. May 31, 2024
@fruffy
Copy link
Collaborator Author
fruffy commented May 31, 2024

Hmm, the error is in boost, that might be hard to fix unless it is our bad usage of boost of course :-). Seems to be related to a particular version as it fails just in the sanitizers build.

Cherrypicking #4663 fixes the issue. There were two more small fixes required which I can fork into a separate PR.

@vlstill
Copy link
Contributor
vlstill commented Jun 3, 2024

Hmm, the error is in boost, that might be hard to fix unless it is our bad usage of boost of course :-). Seems to be related to a particular version as it fails just in the sanitizers build.

Cherrypicking #4663 fixes the issue. There were two more small fixes required which I can fork into a separate PR.

Personally I'm OK with the operator fixes to be there, but the boost should be separate.

@vlstill
Copy link
Contributor
vlstill commented Jun 3, 2024

I've just notice that docs/C++.md still mentions C++11. No point fixing it to 17 now, but should be fixed when we switch to C++20.

@fruffy
Copy link
Collaborator Author
fruffy commented Jun 3, 2024

Personally I'm OK with the operator fixes to be there, but the boost should be separate.

Yes, the changes were for testing purposes, I will move them into separate PRs.

@fruffy fruffy force-pushed the fruffy/C++20 branch 3 times, most recently from 63d7c31 to 07beb28 Compare June 3, 2024 18:08
@fruffy
Copy link
Collaborator Author
fruffy commented Jun 3, 2024

It looks like there is very little that can be done to fix the compilation issue sans fixing boost. I am not sure why this pops up with clang only though.

@fruffy fruffy added the p4tc Topics related to the P4-TC back end. On PRs, also triggers p4tc CI tests to run. label Mar 17, 2025
@fruffy
Copy link
Collaborator Author
fruffy commented Mar 17, 2025

That said, we should probably merge #5121 before this one.

Kinda scared of that one and C++20, ha.

@vlstill
Copy link
Contributor
vlstill commented Mar 18, 2025

FYI, locally I am still hitting the boost bug from #4874.

That said, we should probably merge #5121 before this one.

Kinda scared of that one and C++20, ha.

yes, the bf-asm is huge and I don't know what could be hiding there :-D. And C++20 is not 100 % backward compatible, especially when considering the various bugs that creep in g++ versions we need to 8000 support.

@vlstill
Copy link
Contributor
vlstill commented Mar 18, 2025

We will also need to run this on tofino, currently I am getting problems in bf-p4c/mau/stateful_alu.cpp so I did not yet get to the problem with Ubuntu 22.

@fruffy
Copy link
Collaborator Author
fruffy commented Mar 18, 2025

FYI, locally I am still hitting the boost bug from #4874.

Personally, I still think the best way to solve this is to build with our own boost version.

@asl
Copy link
Contributor
asl commented Mar 18, 2025

Personally, I still think the best way to solve this is to build with our own boost version.

Or at least require boost version w/o the bug? Do we know what is the minimum Ubuntu version that works here?

@fruffy
Copy link
Collaborator Author
fruffy commented Mar 18, 2025

Personally, I still think the best way to solve this is to build with our own boost version.

Or at least require boost version w/o the bug? Do we know what is the minimum Ubuntu version that works here?

iirc it was Boost 1.76+ https://stackoverflow.com/a/67702145, which is supplied with Ubuntu 22.04 and above. Since we are deprecating Ubuntu 20.04 we should not run into this anymore.

@fruffy fruffy force-pushed the fruffy/C++20 branch 6 times, most recently from ff023c7 to c13b298 Compare April 12, 2025 19:38
@fruffy fruffy force-pushed the fruffy/C++20 branch 2 times, most recently from 51bcc1b to 5ddbf9a Compare May 19, 2025 00:57
@@ -160,7 +160,7 @@ const IR::Expression *CanonGatewayExpr::postorder(IR::Operation::Relation *e) {
Pattern::Match<IR::Expression> e1, e2;
Pattern::Match<IR::Constant> k1, k2;
int width = safe_width_bits(e->left->type);
if (((e1 & k1) == k2).match(e) || ((e1 & k1) != k2).match(e)) {
if (((e1 & k1) == k2).match(e) || ((e1 & k1) == k2).match(e)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes what is being matched (from an IR::Neq to an IR::Equ) to completely change the behavior of the code. It seems just wrong

@@ -3111,7 +3111,7 @@ const IR::Node *RemoveUnnecessaryActionArgSlice::preorder(IR::Slice *sl) {
// Simplify "actionArg != 0 ? f0 : f1" to "actionArg ? f0 : f1"
const IR::Node *SimplifyConditionalActionArg::postorder(IR::Mux *mux) {
Pattern::Match<IR::MAU::ActionArg> aa;
if ((0 != aa).match(mux->e0)) mux->e0 = aa;
if ((aa.operator!=(0)).match(mux->e0)) mux->e0 = aa;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be necessary.

if (Device::statefulAluSpec().CmpMask && ((e1 & k) == e2).match(rel) && !k->fitsUint() &&
!k->fitsInt()) {
if (Device::statefulAluSpec().CmpMask && ((e1 & k).operator==(e2)).match(rel) &&
!k->fitsUint() && !k->fitsInt()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be necessary

@fruffy fruffy force-pushed the fruffy/C++20 branch 3 times, most recently from aa8e764 to c50c865 Compare May 25, 2025 00:21
@fruffy fruffy force-pushed the fruffy/C++20 branch 2 times, most recently from f71b522 to 221a4c6 Compare June 15, 2025 15:40
fruffy added 3 commits June 15, 2025 13:40
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser) p4tc Topics related to the P4-TC back end. On PRs, also triggers p4tc CI tests to run. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. run-static Use this tag to trigger static build CI run. run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run. run-validation Use this tag to trigger a Validation CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0