-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tables with empty keys and without keys #1120
Comments
These should be equivalent |
@mbudiu-vmw Okay. Then let's say it in the spec. |
Just to state the obvious, it could instead be that a table with
|
Currently, the syntax doesn't allow defining an entry with empty tuple. |
Except for tables with |
If it's said there's no look-up table, then there are no entries, for both |
I think we can go either way:
(I don't think this is a big deal in practical programs...) |
It matters for practical programs. Practical programs do use
|
Of course. What I meant is that I don't know if having both no-key and empty-key tables (with different semantics) is important in practical programs. |
It seems difficult to imagine that allowing |
I guess, the question is: should the spec explicitly state that not specifying the key at all is totally equivalent to specifying an empty key or these constructs are not equivalent and the rest is left to the implementation. There might be one subtle difference between them, but today's front end does not allow us to see it (and that might be a good thing, actually) :) Imagine two tables:
Obviously, the first question is whether the table
In other words, if we state that a table with an empty key can have no entries ever, then I think that we will be in our full right to declare that no key and en empty key are the same thing. It will also mean that, indeed, the only result after applying the table with no key is a miss, confirming the correctness of what the spec states today. If, however, we find that it is OK for |
Yes. For this, I think the only behavior that is changed is |
Would collecting the current behavior of P4Runtime API, Barefoot API, and TDI in this area help provide guidance here? For example, if for all of them the behavior of a table with |
@vgurevich the bug you mention has been just fixed. |
@mbudiu-vmw @vgurevich So what's the current behavior of the compiler? In const entries = {
_ : a();
} does it allow |
The type of _ is Type_Dontcare, also written as _, and it unifies with anything. |
The latest version of p4-test still complains:
|
One thing that I can say is that that Tofino implementation treats tables with no key and with an empty key identically both at the compiler and at the API lieve.. @jafingerhut plans to test BMv2 implementation and if we found that they are treated the same way too, I think it might be reasonable just to codify it in the spec that |
That is because no one wants to review the fix in p4lang/p4c#3444 |
@mbudiu-vmw -- as per my previous message, it might actually not be a bad thing that we reject the program above -- in fact is strengthens the case for treating the "empty" key as "no key" |
Once the fix is merged you should file a new issue if you think that the error message is wrong. |
@mbudiu-vmw My point is that the way the compiler is today, it allows us to answer the question posed in this issue very easily. Once you merge the fix, the answer will be different, because it will open a new possibility :) |
It may well be a very good idea to rule out this program.
My suggestion to consider treating no key / empty key as different was not
me lobbying for that resolution. Rather, it came from a default approach
that starts by trying to have simple and uniform constructs that compose
cleanly in the language design (I.e. without myriad special cases). In
particular, because (i) key declarations are treated as tuples and (ii) we
have empty tuples / empty tuple types in the language, it would be
consistent/uniform/logical to treat the empty key as having the empty tuple
type.
But it is also totally sensible for us to decide that — for domain specific
reasons — we should depart from uniformity as an overarching design
principle and treat empty/missing key declarations as equivalent. In that
case, we should extend the typechecking rule for table declarations to
explicitly rule out tables with empty/missing keys and also const entries.
However, we should not
rely on a bug/glitch in the current implementation to enforce that
conditions.
That’s just how good language design and compiler engineering works…
…On Wed, Jul 20, 2022 at 5:42 PM Vladimir Gurevich ***@***.***> wrote:
@mbudiu-vmw <https://github.com/mbudiu-vmw> My point is that the way the
compiler is today, it allows us to answer the question posed in this issue
very easily. Once you merge the fix, the answer will be different, because
it will open a new possibility :)
—
Reply to this email directly, view it on GitHub
<#1120 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOCFUVAI3RLXEBVMQ2BTKDVVBXEBANCNFSM53TRVMFA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
For the test given by @vgurevich
I think the error message here hints that |
With Mihai's fix, table t {
key = {}
actions = { a; }
const entries = {
_ : a();
}
} as table t {
key = {}
actions = {
a();
@defaultonly NoAction();
}
const entries = {
default : a();
}
default_action = NoAction();
}
I agree, it would be good to fix this bug. If we want to rule out this P4 program it would be good to use an explicit error message. |
Qinshi,
I’m not exactly sure if this is what you are asking, but I believe an
underscore in an error message like this means any single type (and not
multiple types).
…-N
On Wed, Jul 20, 2022 at 7:24 PM Qinshi Wang ***@***.***> wrote:
For the test given by @vgurevich <https://github.com/vgurevich>
$ ~/tools/p4_test.sh empty_key.p4
empty_key.p4(86): [--Werror=type-error] error: Entry
_ : a();
^^^^^^^
---- Actual error:
Tuples with different sizes 0 vs 1
---- Originating from:
empty_key.p4(86): Table entry has type 'tuple<>' which is not the expected type 'tuple<_>'
_ : a();
^
I think the error message here hints that _ also doesn't work for tuple<_,
_>. Please let me know if that's true for p4_test.
—
Reply to this email directly, view it on GitHub
<#1120 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOCFURJC2B4QT22TGP6MC3VVCDBTANCNFSM53TRVMFA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Yes. The error message indicates that if you want a wildcard for |
|
Sorry, I do not have the code handy to show right now, but with a fairly simple P4 program and using |
The discussion conclusion in the LDWG is that an empty key is the same as no key. @jafingerhut should submit a PR against the spec. |
The manual says as follows:
I'm wondering if it also includes
key = { }
. I think literally it doesn't. It only means tables without the key property.The text was updated successfully, but these errors were encountered: