-
Notifications
You must be signed in to change notification settings - Fork 80
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
Clarifications on implicit cast on function/method calls #1312
Comments
For (1), I noticed that the spec mentions the following in section 6.8.1.
So a directionless parameter passed to an action in a P4 program can be implicitly cast, because they are treated as direction But regarding (2), I found a lot of use cases in the p4c compiler test suite that expects implicit cast on function/method and constructor calls. List of tests
Would allowing implicit cast for directionless parameters, as well as |
Are you asking about directionless parameters on actions only? Or directionless parameters on other kinds of things? The reason I ask is because directionless parameters on actions are a bit different than on other types of things. Section 6.8 of the spec describes this for actions vs. non-actions. That difference implies to me that perhaps the answer for implicit casts might be done by the compiler could be different for directionless parameters to actions, vs. directionless parameters to non-actions. |
I was asking about directionless parameters for other kinds (such as extern methods, functions, and constructors). For actions (and when the parameter is supplied by the P4 program, not the control plane), I think the below parts mention that we can apply implicit cast.
However for other kinds, the spec mentions only that the directionless parameter should be a compile-time known value. But it does not mention that they can be implicitly cast.
So although there seem to be many use cases expecting implicit casts on directionless parameter, for example like the one below, when calling an extern constructor, we cannot type the program as valid as per the spec. extern E {
E(bit<32> size);
}
control c() {
E(12) e;
apply {}
} |
I don't think there's anything special about The requirement that the value given for a directionless argument be compile-time known is independent of the typing. |
How about revising the spec such that it mentions, (Current)
(Revised)
Or at least allowing it for directionless arguments,
If we allow implicit cast for |
There seems to be unspecified bits regarding implicit cast on function/method/(and action) calls.
Spec section 8.20. Method invocations and function calls mentions:
(1) How do we define implicit cast for action calls?
Strictly speaking, actions are neither a function nor a method, while they are quite similar constructs.
But, the spec does not mention how casts should be inserted on action calls.
Would it be safe to consider that implicit cast on action arguments behave the same as function/method arguments?
(2) Do we insert implicit cast for directionless arguments?
While the spec mentions that we only insert cast for direction
in
arguments, there exist some examples in the p4c compiler test suite where it expects to insert implicit casts for directionless arguments also.(a)
extern2.p4
Here, it is expected that the first directionless argument,
0
ofx.method
is implicitly casted tobit<16>
.(b)
action-bind.p4
Also here, the second directionless argument
0
for the default actiona
is expected to be implicitly cast tobit<32>
type.I wonder whether the p4c test suite is in a disagreement with the current spec, or the current spec is ambiguous.
The text was updated successfully, but these errors were encountered: