Skip to content

Conversation

@fruffy
Copy link
Collaborator

@fruffy fruffy commented Oct 18, 2025

Fixes #4776. Add a CMake option to enable P4-14. Otherwise, add a bunch of code pragmas to selectively disable P4-14 constructs. We can clean these up over time.

The move of v1model.h to the BMv2 back end is intentional. With that it becomes clear which front/mid end segments are "dirty", i.e., they depend on back-end-specific code.

@fruffy fruffy added bmv2 Topics related to BMv2 or v1model core Topics concerning the core segments of the compiler (frontend, midend, parser) labels Oct 18, 2025
@fruffy fruffy marked this pull request as draft October 18, 2025 17:59
Signed-off-by: fruffy <[email protected]>
Copy link
Contributor

@ChrisDodd ChrisDodd left a comment

Choose a reason for hiding this comment

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

We'll need to ensure some CI builds are built with P4_14 and some without. Not sure we need every possible combination of OS + build tool + P4_14 on/off + unity on/off, but at least some orthogonal coverage.

}

/// FIXME: Only required for P4-14. Remove.
class Attribute : Declaration {
Copy link
Contributor

Choose a reason for hiding this comment

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

why move this here from ir-v1.def? That seems backwards as you'll get it built in to the compiler even when P4_14 is disabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Attribute is part of Type_Extern. And the ir-generator does not have support for preprocessor directives to conditionally ignore segments. If I do not include it optional inline NameMap<Attribute, ordered_map> attributes; // P4_14 only, currently a few lines below will produce an error.

@fruffy
Copy link
Collaborator Author

fruffy commented Oct 18, 2025

We'll need to ensure some CI builds are built with P4_14 and some without. Not sure we need every possible combination of OS + build tool + P4_14 on/off + unity on/off, but at least some orthogonal coverage.

Yes, my plan is to have one CI run that still builds with P4-14. I opened this PR a bit prematurely, there are still some changes necessary. P4-14 constructs are spread all across the front and mid end.

@fruffy fruffy force-pushed the fruffy/p4-14 branch 2 times, most recently from 007402c to c82e144 Compare October 19, 2025 16:08
@fruffy
Copy link
Collaborator Author

fruffy commented Oct 19, 2025

@smolkaj This PR makes the P4-14 parts optional. With respect to Bazel, I can remove the P4-14 parts from the build system (e.g. v1lexer) or enable building with P4-14 (this is the previous behavior). What do you prefer?

I can also try to add a toggle like we do in CMake, but I am not sure whether Bazel supports that well.

Signed-off-by: fruffy <[email protected]>
@fruffy fruffy marked this pull request as ready for review October 21, 2025 21:25
@fruffy fruffy force-pushed the fruffy/p4-14 branch 2 times, most recently from fd27e65 to 189b7b2 Compare October 21, 2025 22:10
@fruffy fruffy requested a review from smolkaj October 21, 2025 23:38
@fruffy fruffy force-pushed the fruffy/p4-14 branch 2 times, most recently from b4923e1 to dc47ee3 Compare October 23, 2025 02:22
Signed-off-by: fruffy <[email protected]>
@kfcripps kfcripps requested a review from asl October 29, 2025 01:13
Copy link
Contributor

@asl asl left a comment

Choose a reason for hiding this comment

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

See some comments. I'm not a huge fan of bunch of ifdefs spread across the whole frontend... Maybe this could be composed in some other way?


} // namespace P4

#ifdef SUPPORT_P4_14
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's worth to split this into a separate header rather than throwing ifdef?

return expression;
}

#ifdef SUPPORT_P4_14
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to separate file?


} // namespace P4

#ifdef SUPPORT_P4_14
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be split into a separate file?


#ifdef SUPPORT_P4_14
TEST_F(P4CParserUnroll, switch_20160512) {
auto parsers = loadExample("../p4_14_samples/switch_20160512/switch.p4",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very useful test for the compiler performance. Maybe re-instate its converted version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@smolkaj
Copy link
Member

smolkaj commented Oct 29, 2025

@smolkaj This PR makes the P4-14 parts optional. With respect to Bazel, I can remove the P4-14 parts from the build system (e.g. v1lexer) or enable building with P4-14 (this is the previous behavior). What do you prefer?

I can also try to add a toggle like we do in CMake, but I am not sure whether Bazel supports that well.

I don't think we need P4-14 support. I just want to make sure i understand -- P4-16 programs using v1model will continued to work?

@fruffy
Copy link
Collaborator Author

fruffy commented Oct 29, 2025

See some comments. I'm not a huge fan of bunch of ifdefs spread across the whole frontend... Maybe this could be composed in some other way?

I am converting some of this into issues, e.g., #5402. I also want to reduce the #ifdefs as much as possible but some refactorings are a little bit more involved (for example, splitting out the v1parser).

@fruffy
Copy link
Collaborator Author

fruffy commented Oct 29, 2025

I don't think we need P4-14 support. I just want to make sure i understand -- P4-16 programs using v1model will continued to work?

Yes, this will not affect P4-16 programs, but you might lose the ability to compile P4-14 programs. I do not think you work with those.

6ddcd13 is a possible implementation in Bazel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bmv2 Topics related to BMv2 or v1model core Topics concerning the core segments of the compiler (frontend, midend, parser)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it possible to compile P4C without P4-14 support

5 participants