Compiler does not implicitly calculate priorities and does not allow explicit priorities for `const entries`
Currently the compiler does not implicitly calculate priorities that are not explicitly provided when the entries are const, and reports an error message when const entries have explicit priorities:
if (ep->isConstant) {
if (withPriority)
::error(ErrorType::ERR_INVALID,
"%1%: Table with 'const' entries cannot have priorities", withPriority);
return entries;
}
Why does it do this? Can anyone point me to where in the spec this const entries-specific behavior is described?
For example:
const entries = {
(0x1, 0x2) : a(0, 1, 2);
(0x3, 0x4) : a(3, 4, 5);
(0x5, 0x6) : a(6, 7, 8);
(0x7, _) : a(9, 10, 11);
(_, 0x8) : a(12, 13, 14);
}
With const entries, the control plane cannot insert more entries (or remove entries), so the compiler has complete control. The priorities in that case are solely based on the order of the const entries, and there's no need for priorities. The priorities only matter if the control-plane can add entries (which will have priorities), in which case they're needed to determine the relative priorities of the control-plane and static entries.
I have reviewed the sub-section named "Entries" within the section 14.2.1 "Table Properties" of the latest version of the language spec as of 2024-Jul-09, and I did not notice anything there that specifically forbids entry priorities to be specified for a const entries table property.
I agree with Chris Dodd that it does not seem very useful to allow a P4 developer to specify them -- the textual order of entries specifies the relative priority, if that match kind of the keys requires it, and specifying particular numeric values would just be an extra burden on the P4 develeper.
@ChrisDodd @jafingerhut Thank you for clarifying. Would it make sense to make the spec more explicit regarding priorities of const entries?
It would not bother me if the spec explicitly forbade explicit priority values from being specified inside of const entries, with a brief description of the reason. Are you interested in suggesting a PR for the spec that would do this?
@jafingerhut I probably won't do it anytime soon, but if you want to open a new issue in the p4-spec repo and assign to me I wouldn't mind trying to do that eventually.
I created this issue, but when I attempt to assign it to you, it does not seem to allow me to specify your Github id: https://github.com/p4lang/p4-spec/issues/1292
@jafingerhut Thanks. I will just assign this issue to myself instead as a reminder.