Skip to content
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

Rationale for allowing 0-width type bit<0> ? #1252

Closed
jafingerhut opened this issue May 14, 2023 · 6 comments
Closed

Rationale for allowing 0-width type bit<0> ? #1252

jafingerhut opened this issue May 14, 2023 · 6 comments
Assignees
Labels

Comments

@jafingerhut
Copy link
Collaborator

I know I was there in the P4 language design work group meetings where this was discussed. I had no objections at the time, and I still don't actually have any objections. I do have a few questions, though:

  • Has anyone used a type bit<0> in a P4 program for something? If yes, what for?
  • If not, can you imagine a situation where it seems useful?

I am not sure, but my guess is that the primary reason for making a change to the spec to allow type bit<0> was along the lines of: well, we support structs and header type with no member fields, and tuples with 0 members, why not type bit<0>, also?

One of my reasons for asking is in thinking about whether it is considered important to make changes to the P4Runtime API specification to allow values of type bit<0> in control plane API messages, or whether to simply say "that type is not supported in the P4Runtime API": p4lang/p4runtime#428

@mihaibudiu
Copy link
Contributor

For exeample

#define WIDTH 0 
struct H { bit<WIDTH> field; }

@jafingerhut
Copy link
Collaborator Author

Thanks, Mihai, for the example.

Are you intending that as an example of something you have found useful to include in a P4 program before?

Or is it more along the lines of: "I (Mihai) would guess that someone might find code like this useful?"

@jnfoster
Copy link
Collaborator

I think the point is that you might write a program with a macro that gets filled in according to a profile or configuration. If the value of the macro determines the width of a bitstring, and can assume the value 0, then having bit<0> may be useful. (It would be even better if the compiler optimized the code aggressively, so there was zero cost for using that feature instead of #ifdef-ing the code away by hand.)

@chrispsommers
Copy link
Contributor

Thanks for the explanations. That makes sense: widths of zero might be the outcome of some profile, not so much a goal as much as a consequence.

@jnfoster
Copy link
Collaborator

jnfoster commented Jun 5, 2023

Do we keep this open? Or has it converged?

@jafingerhut
Copy link
Collaborator Author

I think the issue has served its purpose of asking and answering the question. I will close it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants