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

Improve PNA system library organization with smaller usable components #4752

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

Conversation

qobilidop
Copy link
Member

No description provided.

@qobilidop qobilidop marked this pull request as draft June 24, 2024 04:41
@qobilidop qobilidop force-pushed the p4include-pna branch 6 times, most recently from 5ad47eb to 3d14cfb Compare June 24, 2024 06:39
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
@fruffy fruffy added core Topics concerning the core segments of the compiler (frontend, midend, parser) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). labels Jun 24, 2024
@jafingerhut
Copy link
Contributor

@qobilidop The changes you have to separate out the relatively small different parts of the pna.p4 include files into types_metadata.p4 and blocks.p4 for v0_5, v0_7, and latest dev version look reasonable to me.

The test failures you are seeing are likely because the P4_16 code output from the front-end and mid-end of the p4c compiler is changing as a result of your header file changes, and there are expected output files checked into the *_samples_outputs directories that they are being diff'd against, and even one character change there is enough to cause a test failure.

Do you know how to update the contents of the *_samples_outputs files on your local system while testing?

@qobilidop
Copy link
Member Author

@jafingerhut Thanks for your review comments!

I have done the test data updates a few times in the past, but it's been a while that I forgot the details. I'll review the instructions from https://github.com/p4lang/p4c/tree/main/docs#testing and update the sample outputs as the next step.

@fruffy
Copy link
Collaborator

fruffy commented Jun 26, 2024

@jafingerhut Thanks for your review comments!

I have done the test data updates a few times in the past, but it's been a while that I forgot the details. I'll review the instructions from https://github.com/p4lang/p4c/tree/main/docs#testing and update the sample outputs as the next step.

P4TEST_REPLACE=True ctest -j5 or something similar should do the trick.

Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Comment on lines 7 to 9
#include <pna.p4>
#include <pna/v0_5/types_metadata.p4>
#include <pna/v0_5/blocks.p4>
Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is deeper than I originally thought. This transformation result is problematic because #include <pna/v0_5/types_metadata.p4> will duplicate #include <pna.p4> contents, leading to later compiling errors.

Maybe the correct behavior should be #include <pna.p4> not expanded at all? I need to figure out the relevant frontend pass responsible for this transformation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The pass that does this toP4. SourceInfo contains information about the source path a node came from. Iirc if this source path is considered a systems file the include is added.

This is super janky and leads to problem like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've figured out a relatively hacky solution, similar to the #4742 approach.

Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
Signed-off-by: Bili Dong <qobilidop@gmail.com>
@qobilidop qobilidop marked this pull request as ready for review July 1, 2024 01:23
@qobilidop qobilidop changed the title Explore possibilities to improve PNA p4include file organization Improve PNA system library organization with smaller usable components Jul 1, 2024
@qobilidop qobilidop marked this pull request as draft July 1, 2024 01:35
Signed-off-by: Bili Dong <qobilidop@gmail.com>
@qobilidop qobilidop marked this pull request as ready for review July 1, 2024 03:48
@@ -1235,7 +1235,10 @@ const PNAEbpfGenerator *ConvertToEbpfPNA::build(const IR::ToplevelBlock *tlb) {
!d->is<IR::Type_Error>()) {
if (d->srcInfo.isValid()) {
auto sourceFile = d->srcInfo.getSourceFile();
if (sourceFile.endsWith("/pna.p4")) {
// TODO: Similar logic exists in frontends/p4/toP4/toP4.cpp. Consider replacing
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like the parser should already determine whether an object is source from a systems file and add this information to the source information.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree this will be a better solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ChrisDodd Do you think this could be done in the P4 parser? How much work would it be?

@@ -32,6 +32,7 @@ limitations under the License.
// Standard include paths for .p4 header files. The values are determined by
// `configure`.
extern const char *p4includePath;
extern const char *p4includeInternalPath;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The discussion in #4742 makes me thing we just should have this be a set. Do not know how difficult this is to implement with all the back ends.

@@ -72,6 +72,7 @@ class ToP4 : public Inspector {
listTerminators.pop_back();
}
bool isSystemFile(cstring file);
bool isSystemInternalFile(cstring file);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the definition of a system internal file. Any private header include prefixed with _internal?

Copy link
Member Author

@qobilidop qobilidop Jul 1, 2024

Choose a reason for hiding this comment

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

This is the hacky part. What happened is that in the following loop, program->objects would contain not only #include <pna.p4> that is directly from the source program, but all the transitive <*.p4> libraries, like <_internal/pna/dev/blocks.p4>. This will lead to compiler errors of duplicate definitions on the ToP4 generated code.

for (auto a : program->objects) {

My current solution is to define this special p4include/_internal/ ("system internal") directory, and filter it out in the ToP4 looping. But I don't think this is a proper solution in the long term.

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) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants