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

Add type nesting rules for extern, parser, control, and package types #1343

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaehyun1ee
Copy link
Contributor

I would like to propose a change to the spec following the discussion made in #1324.
This adds the cases for extern / parser / control / package types for the type nesting rule defined in section 7.2.8.

In summary,

  • It disallows extern / parser / control / package types from being nested inside a header / header union / struct / tuple / list / header stack.
  • It allows extern / parser / control / package to be aliased by typedef, but disallows for type.

@vlstill vlstill self-requested a review January 13, 2025 21:39
@jafingerhut
Copy link
Collaborator

vlstill agreed to review. Some discussion in 2025-Jan-13 LDWG meeting. If vlstill approves, the other members of the LDWG meeting could think of no objections to merging with vlstill's approval.

@jaehyun1ee
Copy link
Contributor Author

Just double-checked with the behavior of p4c,

extern E {}
// struct S { E e; }
// type E e_new;
parser P() { state start {} }
// struct S { P p; }
// type P p_new;
control C() { apply {} }
// struct S { C c; }
// type C c_new;
package Pkg();
// struct S { Pkg pkg; }
// type Pkg pkg_new;

all commented lines result in the program being rejected by the frontend.

Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the changes, except for some formatting issues.


With type I think for these types of entities it is pretty clear the newly defined type would be (almost) unusable, and we already disallow a lot of types in type. So I am fine with disallowing those. I can see much more use for type X = string or type X = int than for these, but that is for a different discussion :-).

Side note: With these changes, it makes even less sense to prohibit typedef on match_kind and void. Maybe we should just say that any type can be typedef'ed.

Comment on lines +2617 to +2625
| `enumeration types` | allowed | error

| `header types` | allowed | error

| `header stacks` | allowed | error

| `header unions` | allowed | error

| `struct types` | allowed | error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should not be in backticks. The rule should be something like: if it is an actual piece of code/if it is type (possibly generic) than it is in backticks, but if it is a type "category" (like "header unions") than it should be plain text. For this second table, that was preserved in the asciidoc, but for the first one it probably got mistakenly reformated in the conversion -- compare https://p4.org/p4-spec/docs/p4-16-working-draft.html#sec-type-nesting and https://p4.org/wp-content/uploads/2024/10/P4-16-spec-v1.2.5.html#sec-type-nesting. I think the formatting in 1.2.5 is correct, while the draft is wrong in the first table.

I suggest we keep consistent in each of the tables separately in this PR and then file a follow-on PR to fix format in the first table (I can do that once this is merged).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought is we should have backticks around (only) things that literally might appear in a P4 program. So "enumueration types" is definitely wrong, but maybe should have "struct types"?

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 agree to both: (1) having a separate PR to fix the backticks consistently and (2) putting [ header types, header stacks, header unions, and struct types ].

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

Successfully merging this pull request may close these issues.

4 participants