Closed jaehyun1ee closed 5 months ago
I agree that at least for extern object instances passed in this way, passing by reference seems to be the only thing that makes sense, and a clarification saying so explicitly would be a good thing. There might already be somewhere in the language spec that says this, but if so, I do not recall off-hand where it would be.
Are you interested in creating a pull request with a suggested change?
Are you interested in creating a pull request with a suggested change?
I'd be happy to, but I'm afraid I am unsure of what exactly to specify and at which part of the specification.
Would this change in bold be acceptable?
- The meaning of parameters with no direction depends upon the kind of entity the parameter is for:
- For anything other than an action, e.g. a control, parser, or function, a directionless parameter means that the value supplied as an argument in a call must be a compile-time known value (see Section 18.1).
- A directionless parameter of extern object type is passed by reference.
- For an action, a directionless parameter indicates that it is “action data”. See Section 14.1 for the meaning of action data, but its meaning includes the following possibilities:
- The parameter's value is provided in the P4 program. In this case, the parameter behaves as if the direction were in. Such an argument expression need not be a compile-time known value.
- The parameter's value is provided by the control plane software when an entry is added to a table that uses that action. See Section 14.1.
That suggested addition looks like a good starting point for discussion by the language design work group to me.
Thank you for the help, closed as merged
In the below parser type declaration, the first parameter,
packet_in b
is an directionless extern object.Spec section 6.8. Calling convention: call by copy in/copy out discusses the calling convention on directionless parameter as follows:
Yet, it does not discuss how the parameter
packet_in b
should actually be passed to the parser block.Given that the
packet_in
object is stateful (+ instantiated by the target), it seems reasonable to assume that passing it by reference would be the appropriate approach, rather than copying the entire object.I suggest that the specification clarify this point by providing guidance on how directionless extern parameters should be passed to parsers, controls, or functions.