Skip to content

Make P4-14 optional. - #5399

Open
fruffy wants to merge 9 commits into
mainfrom
fruffy/p4-14
Open

Make P4-14 optional.#5399
fruffy wants to merge 9 commits into
mainfrom
fruffy/p4-14

Conversation

@fruffy

@fruffy fruffy commented Oct 18, 2025

Copy link
Copy Markdown
Collaborator

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

@ChrisDodd ChrisDodd left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread frontends/CMakeLists.txt
Comment thread frontends/common/parser_options.cpp Outdated
Comment thread ir/type.def Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
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

fruffy commented Oct 18, 2025

Copy link
Copy Markdown
Collaborator Author

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

fruffy commented Oct 19, 2025

Copy link
Copy Markdown
Collaborator Author

@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

@asl asl left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

Comment thread frontends/p4/typeChecking/typeCheckExpr.cpp Outdated
Comment thread frontends/parsers/parserDriver.cpp Outdated
Comment thread test/gtest/parser_unroll.cpp
@smolkaj

smolkaj commented Oct 29, 2025

Copy link
Copy Markdown
Member

@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

fruffy commented Oct 29, 2025

Copy link
Copy Markdown
Collaborator Author

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

fruffy commented Oct 29, 2025

Copy link
Copy Markdown
Collaborator Author

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 fruffy added 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
@fruffy
fruffy force-pushed the fruffy/p4-14 branch 2 times, most recently from d85a815 to 7213a10 Compare April 19, 2026 22:54
@fruffy
fruffy requested review from ChrisDodd, asl and smolkaj and removed request for ChrisDodd, asl and smolkaj April 19, 2026 23:31
@fruffy
fruffy requested review from ChrisDodd and removed request for ChrisDodd, asl and smolkaj July 19, 2026 18:17

@ChrisDodd ChrisDodd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like this won't work with the tofino backend, as it uses IR::Primitive internally in a bunch of places (and possibly other ir-v1.def things). Still a step in right direction

Comment thread frontends/common/parseInput.cpp Outdated
#ifdef SUPPORT_P4_14
CompilerOptions::FrontendVersion version) {
#else
CompilerOptions::FrontendVersion /*version*/) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe this argument should go away completely if !SUPPORT_P4_14?

Comment thread frontends/p4-14/ir-v1.def Outdated
ID Name() const { return obj->to<IInstance>()->Name(); }
dbprint { out << obj->to<IInstance>()->Name(); }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to be a noop change? This codeblock has just been moved up in the file with no changes.

Comment thread frontends/p4/actionsInlining_p4_14.h Outdated
@@ -0,0 +1,55 @@
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably makes sense to move this file into frontends/p4-14

fruffy added 9 commits July 28, 2026 19:54
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>
Signed-off-by: fruffy <fruffy@nyu.edu>
@fruffy
fruffy enabled auto-merge July 28, 2026 19:54
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