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: Convenient initialization of header/structs #341
Comments
Thanks a lot, @jafingerhut ! I hope this construct will promote using local metadata as much as possible, as opposed to the current model, where everything is global, partially due to the convenience of the global metadata being initialized by the architecture. |
This is addressed partially by #717 |
How about using 'false' to initialize an invalid header? |
Could we allow assigning |
I thought, we discussed an option of distinguishing between:
and
|
We have discussed, but I don't think we have agreed. |
We can agree that if someone wants to make an empty header valid, they should use |
@vgurevich IMHO, special cases like this are generally a bad idea in language design. |
Also, this would be a breaking change in the current definition. |
@jnfoster -- I am not sure that this will be a special case. @mbudiu-vmw -- yes, I agree, this is going to alter the corner case, so we should weigh the pros and cons. I feel that in this case the pros outweigh the cons, but I might be wrong. One way to decide is to check how many programs in use today use both empty headers (or structs), paired with this specific initialization construct. |
|
Overloading |
The keyword needs to be an expression. |
How about adding a new 'invalid' literal that means "invalid header"? |
|
I forgot about this issue, and created this related one, specifically on the question of a literal syntax for an invalid header: #1021 Note that because both headers and structs with 0 fields are legal in P4, the open source p4c compiler today treats |
Have we done this now? Can we close it? |
It looks done to me. |
Personnel
Design
Implementation
p4-spec
: Describe structure initializer expressions #717p4c
: Structs, headers and tuples initialization/assignment support (#762) … p4c#2368Process
p4-spec
:p4c
:I believe @vgurevich proposed this late before the P4_16 spec was finalized, and I do not see any issue here to track it, so wanted to add one. Feel free to mark it "Post P4_16" if that helps.
This is primarily a feature for P4 program writing convenience. The effect of initializing all fields of a header, or all fields of a struct, including headers or structs defined within a containing struct, can certainly be achieved by writing as many separate assignment statements as needed to assign them all. I believe the syntax that Vladimir proposed for such a "initialize everything to 0" operation was:
For all 'leaf fields', no matter how deeply embedded, that are bit or int type, they would be initialized with 0. varbit fields would be initialized to 0 length. bool fields would be initialized to false.
error or enum field intialization is TBD. Perhaps the compiler would not allow such initialization for such structs and give an error. Also TBD if a struct contains a header stack or header union member.
The text was updated successfully, but these errors were encountered: