-
Notifications
You must be signed in to change notification settings - Fork 456
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
Compiler Bug: Could not find type of <Type_Header> ...
on specialized generic struct type
#4835
Comments
In your P4 program, you're trying to use a generic header standard_t, which should work with different types. However, the P4 language and its compiler have limitations when it comes to generics. Specifically, the pkt.extract() method requires a concrete header type, and the compiler struggles to resolve generic types at compile time. The P4 compiler requires that all header types be fully specified at compile time.
|
Thank you for the explanation! Yet, I'm afraid I did not understand what you meant by "concrete". So my question would boil down to: |
If I am understanding your issue correctly, then it is basically an issue about concretization and generic methods/constructors. I certainly am not the expert here but yes,
this is concrete, and as you've mentioned in your issue, the error pops up when you do not pass this concretized argument. So we're on the same page so far.
Yes, it is allowed as The P4 language specification allows the use of generic types and their specialization into concrete types. This is part of the language's design to provide flexibility and reuse through parameterized types. I'm certainly not the expert here but this is what I can make out of the entire situation. |
Ah, I see. Now I guess we are on the same page :) One minor clarification though,
The error pops up regardless of the type argument being passed. |
This might be a silly question but while running |
The compiler should never throw an exception like |
Hmm, I'm not sure if I can answer the question. The code example doesn't compile due to failure in the compiler's type checker, so I didn't have a chance to execute the code. |
Signed-off-by: Vladimír Štill <[email protected]>
The following program,
bug-generic.p4
fails to typecheck when given a command$ p4c --target bmv2 --arch v1model bug-generic.p4
.Here, I defined a generic struct
headers_t<T>
that has a field of generic header typestandard_t<T>
. In the parameter ofMyParser
, the type is specialized asheaders_t<big<8>>
. So I expect that bothpkt.extract(hdr.standard);
orpkt.extract<standard_t<bit<8>>>(hdr.standard);
should typecheck.However, the compiler fails to typecheck with an error message:
The same error message occurs when I do not pass the type argument
standard_t<bit<8>>
topkt.extract
method.The text was updated successfully, but these errors were encountered: