p4c icon indicating copy to clipboard operation
p4c copied to clipboard

Can tables be defined without an actions property?

Open apinski-cavium opened this issue 3 years ago • 3 comments

Take:

action NoAction() {}
control c()
{
  table t {
    const g = 1;
  }
  apply {
  }
}

The way I read the spec is that actions will always be defined to include NoAction is default_action is not supplied and therefore the above table is a valid table. The language from the spec:

A table must declare all possible actions that may appear within the associated lookup table or in the default action

...

The compiler must set the default_action to NoAction (and also insert it into the list of actions) for tables that do not define the default_action property. This is consistent with the semantics given in Section [14.2.1.3](https://p4.org/p4-spec/docs/P4-16-v-1.2.3.html#sec-default-action). Hence, all tables can be thought of as having a default_action property, either implicitly or explicitly.

The also insert it into the list of actions make it sound like actions is always there even if the developer does not supply it. This might be a spec issue of requiring always an actions property but I am not fully convinced that we should require it.

apinski-cavium avatar Oct 13 '22 19:10 apinski-cavium

If such a table definition were legal, applying it would always be a no-op, i.e. execute only NoAction, true?

I cannot think of any problem with allowing such a table definition, but it doesn't add any expressive power to the language that I can see.

jfingerh avatar Oct 13 '22 19:10 jfingerh

Oh, and for anyone curious, I tried it with latest open source p4c and p4test, and both give a compile-time error that looks like the below if you try to define a table with no actions property at all:

error: my_table: expected 'actions' property

jfingerh avatar Oct 13 '22 19:10 jfingerh

The p4c behavior is correct. default_action is invoked on table miss. However, no action has been specified for table hit, so why should p4c accept the table?

hesingh avatar Oct 14 '22 00:10 hesingh

I assume we can close this question.

mihaibudiu avatar Dec 22 '22 22:12 mihaibudiu