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

[#1362] Clarify that switch statements _are_ allowed in action/function bodies, and that switch statements with action_run expressions are only allowed in control apply blocks #1363

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kfcripps
Copy link
Contributor

@kfcripps kfcripps commented Feb 4, 2025

Cleans up some wording that was missed by #945, which makes it unclear as to whether switch statements are actually supported in actions/functions or not.

Closes #1362.

@vlstill
Copy link
Contributor

vlstill commented Feb 4, 2025

So this does work in the P4C, right?

@vlstill vlstill self-requested a review February 4, 2025 19:12
@kfcripps
Copy link
Contributor Author

kfcripps commented Feb 4, 2025

So this does work in the P4C, right?

@vlstill For backends that don't run the EliminateSwitch midend pass, yes, it already works. The p4c frontend passes produce valid IR from a switch statement.

Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the clarifications.

This type of `switch` statement can only be used within control `apply`
blocks. For this variant of `switch` statement, the expression must be
of the form `t.apply().action_run`, where `t` is the name of a table
(see <<sec-invoke-mau>>). All switch labels must be names of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this implicit from the fact that table.apply() can only be used in control apply blocks, not in functions or actions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This type of switch statement can only be used within control apply blocks." is definitely implied by other parts of the spec, but it seems reasonable to say here, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think it hurts to explicitly state that here, but if anyone strongly opposes it I can remove it.

The other clarifications are the most important parts of this PR.

Copy link
Collaborator

@jafingerhut jafingerhut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Successfully merging this pull request may close these issues.

Clarify whether P4-16 allows switch statements in actions
4 participants