The following program, bug-generic.p4 fails to typecheck when given a command $ p4c --target bmv2 --arch v1model bug-generic.p4.
#include <core.p4>
#include <v1model.p4>
typedef standard_metadata_t std_meta_t;
header standard_t<T> {
T src;
T dst;
}
struct headers_t<T> {
standard_t<T> standard;
}
struct meta_t { }
parser MyParser(packet_in pkt, out headers_t<bit<8>> hdr, inout meta_t meta, inout std_meta_t std_meta) {
state start {
pkt.extract<standard_t<bit<8>>>(hdr.standard);
// pkt.extract(hdr.standard); <-- this also fails
transition accept;
}
}
control MyVerifyChecksum(inout headers_t<bit<8>> hdr, inout meta_t meta) {
apply { }
}
control MyComputeChecksum(inout headers_t<bit<8>> hdr, inout meta_t meta) {
apply { }
}
control MyIngress(inout headers_t<bit<8>> hdr, inout meta_t meta, inout std_meta_t std_meta) {
apply { }
}
control MyEgress(inout headers_t<bit<8>> hdr, inout meta_t meta, inout std_meta_t std_meta) {
apply { }
}
control MyDeparser(packet_out pkt, in headers_t<bit<8>> hdr) {
apply { }
}
V1Switch(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main;
Here, I defined a generic struct headers_t<T> that has a field of generic header type standard_t<T>. In the parameter of MyParser, the type is specialized as headers_t<big<8>>. So I expect that both pkt.extract(hdr.standard); or pkt.extract<standard_t<bit<8>>>(hdr.standard); should typecheck.
However, the compiler fails to typecheck with an error message:
Compiler Bug: bug-generic.p4(19): Could not find type of <Type_Header>(40455) standard_t_0/66 header standard_t_0 {
bit<8> src;
bit<8> dst; }
header standard_t<T> {
^^^^^^^^^^
The same error message occurs when I do not pass the type argument standard_t<bit<8>> to pkt.extract method.
The following program,
bug-generic.p4fails 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.extractmethod.