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

Use a struct type as T in value_set<T> #1270

Closed
hanw opened this issue May 4, 2018 · 4 comments
Closed

Use a struct type as T in value_set<T> #1270

hanw opened this issue May 4, 2018 · 4 comments
Labels
enhancement This topic discusses an improvement to existing compiler code. fixed This topic is considered to be fixed. question This is a topic requesting clarification.

Comments

@hanw
Copy link
Contributor

hanw commented May 4, 2018

Is the following P4 code correct syntax when the type T in PVS is a struct?

struct my_packet {
  bit<32> data;
}

struct value_set_t {
  bit<32> field;
}

parser MyParser(packet_in b, out my_packet p, inout my_metadata m, inout standard_metadata_t s) {

    value_set<value_set_t>(4) pvs;

    state start {
        b.extract(p.data);
        transition select({ p.data }) {
            pvs: accept;
            {0x810} : foo;
        }
    }

    state foo {
        transition accept;
    }
}

When I compile with p4test at commit d50facb, type unification failed at the constant key expression {0x810}.

error: SelectExpression: Cannot unify tuple type Tuple(1) with non tuple-type int
        transition select({ p.data.da }) {

Complete test program below:
pvs.p4.gz

@hanw
Copy link
Contributor Author

hanw commented May 4, 2018

An alternative syntax would be

parser MyParser(packet_in b, out my_packet p, inout my_metadata m, inout standard_metadata_t s) {

    value_set<value_set_t>(4) pvs;

    state start {
        b.extract(p.data);
        transition select(p.data) {
            pvs: accept;
            0x810 : foo;
        }
    }

    state foo {
        transition accept;
    }
}

I am not sure which one should we support.

@hanw hanw added the question This is a topic requesting clarification. label May 4, 2018
@jafingerhut
Copy link
Contributor

Do you get a similar error message if the struct contains 2 fields, and the transition select expression is a list of 2 expressions with type bit<W>?

Or does the error only occur for a struct with 1 field, and a list of 1 value?

@mihaibudiu
Copy link
Contributor

We should support the second variant: the most natural one for the user, even if the compiler has to do a bit more work. I will tag these as enhancements, because they are in line with the current spec; we should update the spec to allow struct types for value sets.

@mihaibudiu mihaibudiu added the enhancement This topic discusses an improvement to existing compiler code. label May 4, 2018
@hanw
Copy link
Contributor Author

hanw commented May 7, 2018

Updated text and example in spec to allow struct type for the value set as part of p4lang/p4-spec#602 p4lang/p4-spec@278afae

@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This topic discusses an improvement to existing compiler code. fixed This topic is considered to be fixed. question This is a topic requesting clarification.
Projects
None yet
Development

No branches or pull requests

3 participants