Open jafingerhut opened 1 year ago
I asked if the first example should really be valid before https://github.com/p4lang/p4-spec/issues/1087
There is another place which talks about when names are defined I thought.
@mihaibudiu Do you have any knowledge of whether this p4c limitation is a minor or fundamental issue in p4c?
In general we want to avoid defining recursive types, so that's a good reason prohibiting references to a type which within the definition of itself. But this construct is not leading to a recursive type, and it is possible it could be accepted. Perhaps a Petra model would be a better answer.
Petr4 accepts this program.
I haven't done a formal proof, but I don't believe allowing an extern to take an arguments of its own type is dangerous from a non-termination perspective. Once the computation is off in extern land, we already make no claims about semantic restrictions.
In fact, p4test
accepts this variant...
extern Bar {
Bar();
void m2<T>(T x);
}
control C() {
Bar() b;
apply {
b.m2<Bar>(b);
}
}
H/T @rcgoodfellow for coming up with it.
For reference, attached is a complete v1model architecture program that gives no error when you run p4test
on it, based upon Nate's example in the previous comment (I only changed the name of the method from m2
to add_dependency
).
Changes needed to close this issue.
p4c
needs to be updated to not reject these programs.
The latest open source
p4test
as of 2023-Jul-21 source p4lang/p4c source code allows this definition of an extern without any errors or warnings, as I would expect:but this one causes an error:
Full example v1model program is attached to this issue.
Is there some subtlety in formally defining a type system for P4 that anyone is aware of, and/or a difficulty in implementing type checking in open source p4c, by allowing such self-referencing extern types? [Uploading test-extern-as-parameter-to-extern-method-call.p4.txt…]()