p4-spec icon indicating copy to clipboard operation
p4-spec copied to clipboard

Allow compile-time resolvable expressions for switch labels?

Open fruffy opened this issue 9 months ago • 5 comments

Prompted by the discussion in https://github.com/p4lang/p4c/pull/4657.

Currently, this program is illegal according to the P4 specification:

action a(){}
action b(){}
action NoAction(){}
control c()
{
  table t  {
    actions = { a ; b;  }
  }
  apply {
    switch(t.apply().action_run) {
      true ? a : b : {}
    }
  }
}

There was a fix in the compiler that made it illegal: https://github.com/p4lang/p4c/issues/3622 The spec reason is: All switch labels must be names of actions of the table t, or default.

Should this actually be illegal? I currently can not think of a case where this would be troublesome. It might even be useful to change labels because of a compile-time value change?

fruffy avatar May 09 '24 22:05 fruffy