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

Type nesting rule for extern, parser, control, and package types #1324

Open
jaehyun1ee opened this issue Nov 2, 2024 · 1 comment
Open

Comments

@jaehyun1ee
Copy link
Contributor

Section 7.2.8 defines the type nesting rules of P4. But it is not explicitly defined for extern, parser, control, and package types.

How about adding the following to the spec? I marked them as (new).

Element type \ Container type header header_union struct or tuple list header stack
bit<W> allowed error allowed allowed error
int<W> allowed error allowed allowed error
varbit<W> allowed error allowed allowed error
int error error error allowed error
void error error error error error
string error error error allowed error
error error error allowed allowed error
match_kind error error error allowed error
bool allowed error allowed allowed error
enumeration types allowed error allowed allowed error
header types error allowed allowed allowed allowed
header stacks error error allowed allowed error
header unions error error allowed allowed allowed
struct types allowed error allowed allowed error
tuple types error error allowed allowed error
list types error error error allowed error
(new) extern types error error error error error
(new) parser types error error error error error
(new) control types error error error error error
(new) package types error error error error error

And for typedef and type,

Base type B typedef B <name> type B <name>
bit<W> allowed allowed
int<W> allowed allowed
varbit<W> allowed error
int allowed error
void error error
string allowed error
error allowed error
match_kind error error
bool allowed allowed
enumeration types allowed error
header types allowed error
header stacks allowed error
header unions allowed error
struct types allowed error
tuple types allowed error
list types allowed error
(new) extern types allowed error
(new) parser types allowed error
(new) control types allowed error
(new) package types allowed error
a typedef name allowed allowed
a type name allowed allowed

Allowing typedef for extern, parser, control, and package type is reflected on the following use cases in the p4c compiler test suite. (extern-inst-as-param.p4, issue2735-bmv2.p4, issue2735.p4, and typedef-constructor.p4)

extern MyCounter<I> {
    MyCounter(bit<32> size);
    void count(in I index);
}
typedef bit<10> my_counter_index_t;
typedef MyCounter<my_counter_index_t> my_counter_t;

And when those types are aliased, it must be that all the type variables are bound.

@jafingerhut
Copy link
Collaborator

Adding the new entries you describe in those tables looks reasonable to me. Thanks for the links to relevant test cases in the existing p4c test suite.

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

No branches or pull requests

2 participants