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

Action calls from parsers #151

Closed
mihaibudiu opened this issue Apr 1, 2017 · 11 comments
Closed

Action calls from parsers #151

mihaibudiu opened this issue Apr 1, 2017 · 11 comments

Comments

@mihaibudiu
Copy link
Contributor

Can parsers directly call actions?

@mihaibudiu
Copy link
Contributor Author

One issue to consider is whether such actions can call exit. exit is only allowed in controls.

@jafingerhut
Copy link
Collaborator

It seems perfectly reasonable that if actions can be called from parsers, then those actions should be limited to things that could be done within a parser, e.g. no return, no exit, no apply on tables, etc.

Even with those restrictions, such an action seems useful in some scenarios, e.g. to give a name to that function, and enable using it in multiple places without copy & paste.

@jnfoster
Copy link
Collaborator

jnfoster commented Apr 3, 2017 via email

@mihaibudiu
Copy link
Contributor Author

This should be on the agenda for the next design meeting.

@cole-barefoot
Copy link
Contributor

From a usability/code reuse perspective, it would be nice to know from the type of an action whether it can be used in a parser, rather than having to inspect the body of the action. But maybe this is a longer-term goal...

@jafingerhut
Copy link
Collaborator

jafingerhut commented Apr 11, 2017

In 2017-Apr-10 language design meeting, someone suggested keeping this issue, but changing the title to 'Add functions to P4' (some time after P4_16 first release in May). @mbudiu-vmw Do you have ability to change the title? I don't think I do. Also happy to close this one and open a new one if that is easier.

Rationale for not allowing actions to be called from within parsers - actions are intended to be part of a match-action pipeline. It seems a bit too much of a hack to allow calling them from inside parsers. It would be preferable to add functions to P4 vs. using actions in places they were not intended.

Below are what I think might be some properties of P4 functions. They have a heavy overlap with properties of actions. The main difference between actions and functions as I describe them below are that actions can have directionless parameters, but functions cannot, and functions can have return values. I realize that maybe my expectations of P4 functions are different than those of others.

  • all parameters must have directions specified, i.e. no directionless parameters
  • have a return type that could be of many possible types, at least bit<W> and int<W>, and perhaps most base types and even derived types like structs would be allowed as return types.
  • Can be called from inside parser states, control apply blocks, actions, or other functions. As always, target-specific compilers would be responsible for rejecting programs that are too complex for the target.
  • Can be defined at top level, or inside of a parser or control block top level. TBD whether it is considered important to be able to define them within parser states, control apply blocks, actions, or other functions.
  • Can read header or metadata values that are in scope where they are defined, or modify them (i.e. side effects would be permitted), subject to possible in/out/inout restrictions on access to those values in the enclosing scope.

@mihaibudiu
Copy link
Contributor Author

Adding functions would also solve issue #51

@jnfoster
Copy link
Collaborator

jnfoster commented May 8, 2017

@jafingerhut I think we resolved not to take this and think about adding proper functions down the road. If you agree, can we close this? If not, let's update the spec?

@jafingerhut
Copy link
Collaborator

@jnfoster I am perfectly fine with either of these: (a) rename this issue as 'Add functions to P4' and mark it as post P4_16, (b) close this issue and create a new one for adding functions to P4.

@jnfoster jnfoster added this to the post P4_16 milestone May 8, 2017
@jnfoster
Copy link
Collaborator

jnfoster commented May 8, 2017

Tagged as post P4_16.

@mihaibudiu
Copy link
Contributor Author

Since we have functions I think we can close this issue.

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

4 participants