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

Matching control types that have default parameters #1348

Open
jaehyun1ee opened this issue Nov 25, 2024 · 0 comments
Open

Matching control types that have default parameters #1348

jaehyun1ee opened this issue Nov 25, 2024 · 0 comments

Comments

@jaehyun1ee
Copy link
Contributor

P4 allows default control parameters.

The below program default-control-argument.p4 from the p4c test suite expects that control declaration MyC matches the control type signature C<H, M>. (The compiler frontend treats this program as valid.)

control C<H, M>(
    inout H hdr,
    inout M meta,
    in intrinsic_metadata_t intr_md = {0, 0});

package P<H, M>(C<H, M> c);

struct hdr_t { }
struct meta_t { }

control MyC(inout hdr_t hdr, inout meta_t meta) {
   apply {}
}

P(MyC()) main;

However, I wonder if the above program should actually be accepted as valid, as per the spec. Default parameters can be omitted when invoking the control instance, but I believe they cannot be omitted when declaring a control object.

The above code is also misleading because,

  • The control type declaration control<H, M> implies that we can explicitly supply an argument corresponding to the intr_md parameter.
  • However, if we were to supply a third argument for MyC, it would result in an error since the control declaration MyC expects only two.

A valid program would write something like:

control MyC(inout hdr_t hdr, inout meta_t meta, in instrinsic_metadata_t intr_md = { 0, 0 }) {
   apply {}
}
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

1 participant