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

Confusing note about action_run switch #1260

Open
vlstill opened this issue Jul 12, 2023 · 4 comments
Open

Confusing note about action_run switch #1260

vlstill opened this issue Jul 12, 2023 · 4 comments

Comments

@vlstill
Copy link
Contributor

vlstill commented Jul 12, 2023

In section 12.7.1 Switch statement with action_run expression of P4 spec v1.2.3 (but the paragraph is also in the current main of spec), there is this note below the code:

Note that the default label of the switch statement is used to match on the kind of action executed, no matter whether there was a table hit or miss. The default label does not indicate that the table missed and the default_action was executed.

I find the first sentence confusing. I think it should be concerned with switch labels in general, not with default (i.e. switch label is used to match on the kind of action executed). This way, it seem to imply that the default is somehow behaving differently than in normal switch, which could suggest it match on whether there was a hit or miss. But that is contradictory to the second sentence. And indeed section 14.2.3. Match-action unit execution semantics indicates that the action_run should contain the ID of the action and whether it was a hit or miss does not come into question.

Does the default label in action_run behave as is usual for switch (i.e. covering cases that were not mentioned before)? Would it be possible to clarify the note to avoid confusion?

@jafingerhut
Copy link
Collaborator

The intended meaning is that in a switch (table_name.apply().action_run) statement, the case labels are expressions that identify actions from the actions list of the table table_name. default means exactly what one might expect in that situation, which is that it is executed if no earlier case labels match.

The mention of table hit/miss is attempting to clarify that default in this situation has nothing to do with whether the table_name.apply() hit or missed.

If you have a suggestion for alternate wording that would make it clearer for you, and yet also explicitly mention that default has nothing to do with whether table_name.apply() got a hit or a miss, we can certainly evaluate such alternate text.

@vlstill
Copy link
Contributor Author

vlstill commented Jul 13, 2023

Thank you. Maybe something like this?

Note that the labels match on the kind of action executed, no matter if the action run due to table hit or due to table miss and default_action. The optional default label behaves as in any other switch and does not indicate that the table missed and the default_action was executed.

@jafingerhut
Copy link
Collaborator

Would you mind creating a PR on this repo with the change you wish to see, so it can be reviewed by others?

@jnfoster
Copy link
Collaborator

jnfoster commented Nov 11, 2023

@vlstill we'd love to have a PR with your proposed change!

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

No branches or pull requests

3 participants