-
Notifications
You must be signed in to change notification settings - Fork 463
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
Duplicate annotations are not diagnosed #5182
Comments
Some of the discussion on this older p4-spec issue might be relevant, but I have not re-digested it all to come up with a summary yet: p4lang/p4-spec#715 |
I agree that we should consider it a p4c bug if the behavior of having multiple annotations with the same annotation name on the same P4 object is unpredictable. While one alternative is to make this situation a compile-time error, it does seem worth a discussion in the P4 LDWG and P4 API work group meetings whether there is a good use case for such annotations, and if so, why. Pinging several folks for their thoughts: @smolkaj @chrispsommers @jonathan-dilorenzo |
Here is a section of the P4Runtime specification that shows multiple If there are people who currently actively write and use such P4 programs, it seems less like a good idea to make it a compile-time error for there ever to be two annotations with the same annotation name on the same P4 object. These possibilities come to mind, but I do not know which statements made below are true: (a) The example in the P4Runtime API spec is obsolete, and no one wants to do this kind of thing. All stakeholders agree that making this situation a compile-time error is acceptable. |
It should probably be up to the target/arch as to whether duplicate annotations are allowed or should be a warning or should be an error. We could perhaps adds something to |
I guess this effectively boils down to the question if two annotations of the same name could be merged together in a well-defined way. My view would be that this is only possible for dictionary-like annotations that take pairs of key / values. In such case We'd just combine two dictionaries together. Still, the question is whether duplicate key would override the old value or cause some further merging. While we can say that this is for target to define, I'd probably respond, that not always. Annotations are used by frontend / midend, so at least some annotations that are defined in the language spec should have some well-defined behavior. Is there any sane target that would allow multiple |
testdata/p4_16_samples/action_profile_max_group_size_annotation.p4
contains the following code:Note that
indirect_ws
has two@name
and two@max_group_size
annotations specified. Likely just a copy-paste from tableindirect
. Still, the duplicate annotations are not diagnosed, however, they are looked in p4c by name, so arbitrary results might be returned depending on the lookup order. While this certainly benign formax_member_weight
, the@name
clashes could lead to unexpected side effects (here fortunately, first the correct name was defined and lookup normally returns first annotations having the given name).The text was updated successfully, but these errors were encountered: