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

P4_14 converter and action functions #753

Open
jnfoster opened this issue Jun 30, 2017 · 0 comments
Open

P4_14 converter and action functions #753

jnfoster opened this issue Jun 30, 2017 · 0 comments
Labels
bug This behavior is unintended and should be fixed. core Topics concerning the core segments of the compiler (frontend, midend, parser)

Comments

@jnfoster
Copy link
Contributor

jnfoster commented Jun 30, 2017

The converter from P4_14 to P4_16 allows action functions to be used as functions -- e.g., one action may invoke another. It's not clear that this is always in-line with the P4_14 spec.

For example, consider the following snippet of code from testdata/p4_14_samples/action_inline.p4 (also attached to the bottom of this issue):

action a(y0)
{ add_to_field(y0, 1); }
    
action b() {
    a(md.b);
    a(md.b);
}

According to the spec, the first argument to the add_to_field primitive should be a field. However, here it is a parameter y0, which could either be a field or action data supplied by the control plane.

In this case, since a is only invoked by b, the compiler happily generates the following:

    @name(".a") action a(inout bit<1> y0) {
        y0 = y0 + 1w1;
    }
    @name(".b") action b() {
        a(meta.md.b);
        a(meta.md.b);
    }

which is fine.

However, if we also use a in a table, then we get the following error:

action_inline_tweaked.p4(25): error: a: parameter y0 must be bound
action a(y0)
         ^^

This error disappears if we replace the body of a with different code.

Going a step further, if we change b to invoke a on another field with another width (7 bits instead of 1), we get a different error:

action_inline_tweaked.p4(29): error: cast: must be a left-value
    a(md.b);
      ^^^^

The relevant code generated by the converter is

    @name(".a") action a(inout bit<7> y0) {
        y0 = y0 + 7w1;
    }
    @name(".b") action b() {
        a((bit<7>)meta.md.b);
        a(meta.md.c);
    }
    @name(".t") table t {
        actions = {
            a;
            b;
        }
    }

I'm not sure what's intended, and I'm all for abstraction, but what we currently have seems somewhat...

See here for the P4 sources:
action_inline.txt
action_inline_tweaked.txt

@mihaibudiu mihaibudiu added the bug This behavior is unintended and should be fixed. label Jul 20, 2017
@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This behavior is unintended and should be fixed. core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

No branches or pull requests

3 participants