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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions p4-16/spec/P4-16-spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5463,12 +5463,12 @@ Statements can appear in several places:

* Within `parser` states
* Within a `control` block
* Within an `action`
* Within an `action` or function

There are restrictions for the kinds of statements that can appear in
each of these places. For example, ``return``s are not supported in
parsers, and `switch` statements are only supported in control
blocks. We present here the most general case, for control blocks.
each of these places. For example, neither ``return``s nor `switch`
statements are supported in parsers. We present here the most general
case, for control blocks.

[source,bison]
----
Expand Down Expand Up @@ -5621,7 +5621,8 @@ innermost `if` statement that does not have an `else` statement.
[#sec-switch-stmt]
=== Switch statement

The `switch` statement can only be used within `control` blocks.
The `switch` statement can only be used within `control` blocks, `action`
bodies, or function bodies.

[source,bison]
----
Expand All @@ -5646,9 +5647,10 @@ separately in the following two subsections.

==== Switch statement with `action_run` expression

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
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.

actions of the table `t`, or `default`.

[source,p4]
Expand Down