p4c
p4c copied to clipboard
directionless argument with default paramater on action vs actions in table
This is a fuzzy area of the specifications so I am not 100% sure this is a compiler bug but it might be a specifications oversight too. Take:
#include <core.p4>
action a(bit t = 1) {}
action b(in bit t = 1) { a(); }
control c()
{
table t {
actions = { a; b; }
default_action = a(0);
}
apply {}
}
I would have assumed the compiler would accept this as the argument t for action a would be supplied by the control plane but the compiler decided that the argument t was bound during the definition. As I said this area seems not well enough defined and both ways seems acceptable to me really.
This what the spec says for default_action.
Note that the specified default action must supply arguments for the control-plane bound parameters (i.e., the directionless parameters), since the action is synthesized at compilation time.
This is another one which is why I said the specifications in this area seems fuzzy:
#include <core.p4>
action a(in bit r, in bit t = 1, bit tt) {}
action b() { a(r = 1, tt = 1); }
control c()
{
table t {
actions = { a(r = 1); }
default_action = a(r = 1, tt = 1);
}
apply {}
}
To me t is bound because of the default argument. I know I can't bind tt in the actions section. And the call to the action in b works without supplying the t argument.
Note the specifications does have this:
Actions can also be explicitly invoked using function call syntax, either from a control block or from another action. In this case, values for all action parameters must be supplied explicitly, including values for the directionless parameters.
But the call inside b shows that you don't. There is definitely a specification issue here too.
Here is the output produced by the compiler for the first example:
issue3657.p4(2): [--Werror=type-error] error: t = 1: parameter t cannot be bound: it is set by the control plane
action a(bit t = 1) {}
^
issue3657.p4(2)
action a(bit t = 1) {}
^
issue3657.p4(8): [--Werror=type-error] error: 1w0: argument does not match declaration in actions list: t = 1
default_action = a(0);
^
issue3657.p4(2)
action a(bit t = 1) {}
^
Here is the output of the compiler on the second example:
issue3657-1.p4(2): [--Werror=type-error] error: t: parameter should be assigned in call a
action a(in bit r, in bit t = 1, bit tt) {}
^
issue3657-1.p4(8)
default_action = a(r = 1, tt = 1);
^^^^^^^^^^^^^^^^