p4c icon indicating copy to clipboard operation
p4c copied to clipboard

directionless argument with default paramater on action vs actions in table

Open apinski-cavium opened this issue 2 years ago • 5 comments

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.

apinski-cavium avatar Nov 03 '22 02:11 apinski-cavium

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.

hesingh avatar Nov 03 '22 11:11 hesingh

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.

apinski-cavium avatar Nov 03 '22 23:11 apinski-cavium

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.

apinski-cavium avatar Nov 03 '22 23:11 apinski-cavium

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) {}
             ^

mihaibudiu avatar Nov 05 '22 01:11 mihaibudiu

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);
                     ^^^^^^^^^^^^^^^^

mihaibudiu avatar Nov 05 '22 01:11 mihaibudiu