-
Notifications
You must be signed in to change notification settings - Fork 441
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
Support for general-purpose safe unions #2615
base: main
Are you sure you want to change the base?
Conversation
@jafingerhut @jnfoster This is an implementation of safe tagged unions. It diverges somewhat from Andy's proposal from the LDWG, but it sticks very close to the existing syntax. Please take a look particularly at the new test cases. A midend pass eliminates unions into structs plus tags. |
There's a hole in this design. Consider the following:
This can potentially mutate I think this can be fixed. I hope there are no other holes. |
The language design working group has asked for some examples using unions. Here are some use cases that I find very compelling: exposing data structures to the dataplane, including mutable tables. Here is the design of an API for action-less tables, that could be compiled into traditional tables.
Here is a sample program using the SimpleTable:
|
Compounding this example, one can even create tables where the values are unions themselves. |
For each entry in a table, a counter already tracks hit or miss. Why do we need to update hit/miss count using an API in a new extern? Does it make sense, to add a "show table" API so that a user gets a list of all entries in the table? I think P4Runtime should already support getting such data. If the design adds mutable table entries, since p4c already supports "const entries = { }", is the plan to support "entries = { }" to configure a mutable entry? Or would you add an explicit table property for a table being mutable in data plane or both? I suppose such new externs go into psa.p4 and pna.p4 architecture files? |
There is nothing in this API about counting.
That is a control-plane API, these are all data-plane APIs.
That is completely independent of this proposal. The reason we haven't done it is that we don't have syntax to represent table contents for arbitrary table representations; e.g., priorities. But since match_kind can be user-defined, the shape of tables is not fixed.
They could be included in architectures that support such tables, but they could also be in independent libraries. I plan to implement a pass which converts such tables into traditional tables, so the API could be supported potentially on any architecture. |
@mbudiu-vmw OK, understood - thanks for your reply. It's a very good API design for data plane. |
Updating an entry to the data plane from the data plane is expected to be an asynchronous call. When the writing is done, the data plane should notify the caller if update of an entry was successful or failed? Currently, in P4, the data plane does not read counters. But, the counters on the entry are available in the data plane to see if a counter in increasing for hit after an Update. If an entry can be updated by data plane, maybe it’s not a stretch to change behavior that the data plane also reads counters? |
You can extend this API in many ways, including adding a new method to access counters associated with a key. |
Sounds good. We can now take this discussion to a PNA meeting to tweak the API since the NIC is expected to use writing to data plane by the data plane . |
I plan to provide a working implementation of this API in the ebpf backend. Once it's working end to end we can be more confident. |
Unfortunately this proposal is flawed. The problem is that one can surreptitiously modify the union that is being accessed, e.g., |
This is a reworked implementation of safe unions. |
Some bikeshedding thoughts:
|
Mihai suggested that syntax like |
…r just the same fields
This PR is built on top of general-purpose switch statements: #2575.