-
Notifications
You must be signed in to change notification settings - Fork 82
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
P4_16 Should the order of annotations be defined to be significant? #715
Comments
One quick remark. The statement you quote:
does not hold for the reference p4c implementation. p4c uses an |
In general we allow many annotations with the same name on an object. |
Would it be reasonable to change this sentence in the latest P4_16 spec:
to something more like the following?
@chrispsommers Any thoughts on such a change in the spec? In this case, the only reason I am proposing it is to more closely match the current implementation, but you may have objections based upon hopes or plans that the implementation would behave as the spec is currently written? (which I believe you wrote this section?) |
yes, I think we should do that. |
I created a PR for that suggested change. However, the following questions I mentioned in the original issue still remain: In general, is it perhaps worth defining whether the order of annotations on the same P4 object is allowed to be significant, or can never be significant? Between those two choices, the example above suggests that perhaps it can be significant in at least some cases, and perhaps a blanket statement that P4Runtime P4Info should always preserve the order of annotations from the source code would help people rely on that fact? @liujed Pinging you because if the purpose of free-form annotation values is for things like assertions, would you expect that if there are multiple such assertions on a single P4 object, e.g. an assignment statement, that the compiler would preserve the relative order from the source code in any intermediate forms it produces that preserve those annotations? Or would you be content if the compiler was free to reorder those annotations in its output, relative to the order they appear in the source code? |
The compiler is the consumer (and sometimes producer) of many annotations. So I don't think we need to make any promises with respect to the order of annotations to P4 programmers. This would be relevant only if we used the compilers are source-to-source translators (which we can), but that's not part of the spec. |
But annotations are also part of the output of the compiler, e.g. for control plane API generation, and perhaps other tools that would make use of the new free-form value annotations that @liujed is proposing. If he is thinking "of course the relative order of annotations in the P4 source code should be preserved in the compiler output, because my new application needs it", and you are thinking "of course no one should rely on that order", then we have a disconnect where a few sentences in the spec might help to avoid trouble in the future. |
The API generation is technically part of the compiler, and it only cares about a small number of annotations. |
@jafingerhut I'm OK with your proposal about uniqueness of kv-pairs and also approved @antoninbas similar proposal for the P4Runtime spec. Regarding ordering, I'll defer to @mbudiu-vmw 's opinion which seems sensible. |
I think we should aim for maximum flexibility of annotation semantics. Why not specify that there may be multiple annotations of the same kind on an object, and that the order of annotations on an object is allowed to be significant, even across different kinds of annotations? (Individual annotations, of course, may refine this. For instance, the My specific use case of
If the spec were to dictate that order must never matter, one workaround might be to attach each of my annotations to a separate empty statement, thereby imposing an ordering. This raises the issue that AST transformations in the front- and mid-ends might alter annotation semantics (e.g., statement reordering), but that's a whole different can of worms. |
I agree that we want maximum flexibility. |
At least for the specific examples of The general point that some kinds of assertions could benefit from preserving their source code order, at least for some compiler runs (i.e., perhaps only compilation runs with additional options enabled), seems worth at least noting. |
Sure, by "empty statement", I meant an empty block statement: Designing a reference compiler that supports annotations with unknown semantics is indeed a challenge; I'm not sure how to best address this. One strategy might be to just do those transformations necessary in the front and mid ends to obtain the back end, and let back-end implementers do the heavy optimizations. To make their lives easier, we could supply a suite of standard optimization passes that they could invoke. Another strategy, inspired by the Polyglot compiler, might be to make the front and mid ends more easily customizable. For instance, we could use the factory pattern to provide hooks for back-end implementers to easily override problematic front/mid-end passes with custom implementations that preserve annotation semantics. These hooks would be useful in general—they would allow someone to swap in a "better" constant-folding pass, for example. These strategies aren't mutually exclusive, of course, but I think both might involve non-trivial changes to what we have now, and would certainly affect existing back-end implementations. |
@liujed Just an off-the-cuff suggestion here regarding assert and assume implementation, given the potential difficulties with implementing them using annotations, and preserving those annotations throughout the steps you hope they will. If they were new statements in the source language, similar the P4_16 |
I agree. I think they should be just extern functions. |
I think we can clearly define the semantics for these as statements. Why make them externs? (and therefore opaque to the compiler). |
The compiler already understands the semantics of some functions, like the methods of packet_in. |
So what is the conclusion of this discussion? |
Do we close this issue or do we need to discuss this further in the LDWG? |
It sounds like the consensus is that ordering of annotations is allowed to be significant. To me, this means that the compiler should preserve the ordering of annotations. I think it already does for unstructured annotations. With #796, I think the compiler should preserve the ordering of all annotations: structured, unstructured, and their interleaving. |
I will then put this on the LDWG list for a short discussion. The problem is that the compiler can in principle modify, insert or delete annotations too; I don't know what is the exact promise it should keep, and it probably can only apply to user-defined annotations. |
Has this every been resolved? Can we write down if the order is meaningful or not in the spec? |
I don't think we have reached a conclusion. |
In the interest of tidying up the set of active issues on the P4 specification repository, I'm marking this as "stalled" and closing it. Of course, we can always re-open it in the future if there is interest in resurrecting it. |
This question occurred to me while reviewing the P4Runtime API specification, where annotations are explicitly represented in a P4Info file that is auto-generated from a P4_16 source program and used to represent the control plane API of a P4 program.
It preserves information about most (maybe all) of the annotations from the source program.
The most relevant part of the P4_16 v1.1.0 language spec I have found so far is this statement in Section 18.1 "Key-Value Pairs in Annotations"):
I understand that this statement applies to multiple key-value pairs inside of one annotation, but the next section also shows an example of a single instantiation of
main
with multiple@pkginfo
annotations on it. It does not explicitly say what should happen if the same key appears in multiple _different@pkginfo
annotations, but one would perhaps guess that the "latest value will replace all earlier ones" might apply in that situation, too. Stating so explicitly might be helpful.In general, is it perhaps worth defining whether the order of annotations on the same P4 object is allowed to be significant, or can never be significant? Between those two choices, the example above suggests that perhaps it can be significant in at least some cases, and perhaps a blanket statement that P4Runtime P4Info should always preserve the order of annotations from the source code would help people rely on that fact?
The text was updated successfully, but these errors were encountered: