Skip to content

Make P4-14 optional.#5399

Open
fruffy wants to merge 8 commits intomainfrom
fruffy/p4-14
Open

Make P4-14 optional.#5399
fruffy wants to merge 8 commits intomainfrom
fruffy/p4-14

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
@fruffy fruffy force-pushed the fruffy/p4-14 branch 2 times, most recently from a85b447 to 8f41873 Compare October 18, 2025 18:15
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.

ir/type.def Outdated
}

/// 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.

@fruffy fruffy force-pushed the fruffy/p4-14 branch 3 times, most recently from a081d51 to ad5f087 Compare October 21, 2025 18:21
@fruffy fruffy marked this pull request as ready for review October 21, 2025 21:25
@fruffy fruffy force-pushed the fruffy/p4-14 branch 3 times, most recently from 189b7b2 to ae41d34 Compare October 21, 2025 23:28
@fruffy fruffy requested a review from smolkaj October 21, 2025 23:38
@fruffy fruffy force-pushed the fruffy/p4-14 branch 3 times, most recently from dc47ee3 to 6ddcd13 Compare October 23, 2025 02:25
@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?

@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

@fruffy fruffy force-pushed the fruffy/p4-14 branch 3 times, most recently from da08e66 to bfa7a48 Compare February 22, 2026 15:09
@fruffy
Copy link
Collaborator Author

fruffy commented Feb 22, 2026

@ChrisDodd Reworked the IR to move P4-14 constructs to P4-14 def files.

@asl Split up some files and added an auto-translated version of switch.p4

@fruffy fruffy requested review from ChrisDodd and asl February 22, 2026 18:34
@fruffy fruffy added breaking-change This change may break assumptions of compiler back ends. p4tc Topics related to the P4-TC back end. On PRs, also triggers p4tc CI tests to run. run-validation Use this tag to trigger a Validation 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 Feb 22, 2026
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
…lated to the bmv2 v1model.

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>
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

bmv2 Topics related to BMv2 or v1model breaking-change This change may break assumptions of compiler back ends. 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-validation Use this tag to trigger a Validation CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it possible to compile P4C without P4-14 support

4 participants