-
Notifications
You must be signed in to change notification settings - Fork 449
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
What happens with enums in the parser? #2331
Comments
The v1model architecture implemented by simple_switch has this in its documentation: https://github.com/p4lang/p4c/blob/master/p4include/v1model.p4#L711-L712 "H must be a struct where every one if its members is of type header, header stack, or header_union." I do not believe that the p4c compiler enforces this today, but it is definitely the intent that type H is a struct that only contains members with one of those types. So the example you give with a member that has type The same goes for the PSA architecture, although it might not be explicitly documented right now, as it is for the v1model architecture. headers, both normal headers and elements of header stacks, have a 'hidden' valid bit, but enum types do not, so it is illegal to try to call setValid, setInvalid, or isValid on them. The P4_16 language specification does say (see below) that all direction Section 6.7 "Calling convention: call by copy in/copy out" of the P4_16 language spec says this: "out parameters are uninitialized (parameters of type header or header_union are set to “invalid”) and are treated as l-values (See Section 6.6) within the body of the method or function. An arguments passed as an out parameter must be an l-value; after the execution of the call, the value of the parameter is copied to the corresponding storage location for that l-value." I had a harder time finding a justification for the guarantee that local variables with type header are initialized to invalid, but I think it is the following: Section 7.2.2 "Header types" says: "When a header is created its “validity” bit is automatically set to false." Please ask again if I missed any aspect of your question. |
Here is an issue I created for the PSA specification that suggests the restriction on the type of H should be similar to those described above for v1model: p4lang/p4-spec#722. It is not yet part of any published PSA specification, though. |
Thank you! Did not know about that spec issue, that simplifies things a lot, great. |
Your enum is not within a header. |
Well, he has two enums in his example. One is inside of a header, and one was not. Most of my comment was addressed to the fact that the enum that was inside of the For most practical purposes an enum backed by a So yes, all of the same issues for when a field inside of a header as discussed in #2323 apply here, too. |
Thanks, that answers my questions. |
More questions. I have been looking at the sample program
psa-example-digest-bmv2.p4
recently, in particular at the line where an enum is a member of the header that is being parsed.This seems to be okay according to the type nesting rules of the spec, although the
simple_switch
backend does not accept such combinations, onlypsa
.I am bit unclear what this means though. As an example take a stripped version of the psa-example program. In the Inlining pass, the sub-parser with
out
parameters is inlined fromto
Ultimately, enums are converted to typical bitvectors:
What are the values of the enum in the Headers struct and is it meant to be parsed? Is it possible to set it as invalid? Or what happens if this data structure is passed into a function with out parameters? I can't quite figure this out.
The text was updated successfully, but these errors were encountered: