-
Notifications
You must be signed in to change notification settings - Fork 444
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
[P4Testgen] Set other headers also invalid when calling setInvalid on a union header. #4853
base: main
Are you sure you want to change the base?
Conversation
@p-sawicki This is a potential fix but it currently causes BMv2 test failures. |
backends/bmv2/common/action.cpp
Outdated
// If setInvalid is called on a header union, we need to invalidate all other | ||
// headers in the union. | ||
if (const auto *parentStructure = builtin->appliedTo->to<IR::Member>()) { | ||
invalidateOtherHeaderUnionHeaders(parentStructure, *ctxt, result, s); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can think about whether it makes sense to do that in bmv2 (to be fair, I find the specified behavior a bit surprising here), but this part looks good to me for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM on the bmv2 side
The failure in issue1897-bmv2.p4 is because of #3842.
to
This assignment always invalidates Unfortunately, the FlattenUnion pass, which could be used to fix this, does not work. Instead, I introduced a configuration option for CopyStructures to disable expansion of header union assignment in specific cases. |
140f4d2
to
c464233
Compare
7bc38b0
to
fd9ccd4
Compare
@antoninbas I had to make some changes to the |
I haven't worked on this code in so long that it's hard for me to provide good insights there (I also didn't author it in the first place). Ideally there wouldn't be that many differences in the backend code between parser and actions, as there aren't really differences when it comes to the format of the output JSON. A simple alternative would be to add a new The easiest alternative all around would be to change the implementation of |
The current changes in the compiler work, but they are inefficient/hacky. We could end up generating many redundant If the implementation in BMv2 is not too hard we can do it. It might require a package update too etc. I am all for considering this a bug in BMv2 and adding a config (this could even be optional). We can get the conversation on that started with the PR on the BMv2 side. |
A minor suggestion: If you make changes to BMv2 to make this more efficient, I would recommend adding a new operation that causes all members of the union to become invalid, while also keeping the operation that makes only the selected member of the header union invalid, without modifying the validity of any other members. Reason: In case the language spec changes to have both kinds of operations in the future. I have no plans to make such a change, but others have asked about it on occasion. |
8344c44
to
5fa67ef
Compare
Antonin's suggestion of adding a new method to BMv2, e.g. "A simple alternative would be to add a new remove_header_conformant primitive to bmv2 targets, which would strictly conform to the spec." and then having the p4c BMv2 back end use that, and leave the existing BMv2 methods unchanged, is certainly the easiest way to get backwards compatibility across all code that exists today. I don't see any disadvantages to that approach, especially if it is documented in comments why the new method was created, and how it differs in behavior from the existing method. |
This PR is currently stuck. I can move out the testgen-specific fixes and mark the failures Xfail. |
I have split the PR into two. This PR only contains the P4Testgen fixes. #4982 contains the BMv2 compiler fixes, which may or may not be used. |
…der. Signed-off-by: fruffy <[email protected]>
Signed-off-by: fruffy <[email protected]>
Fixes #4448.