Skip to content

Disallowing default parameters in parser/control type declarations #5685

Description

@jaehyun1ee

This is a follow-up from a P4 spec issue p4lang/p4-spec#1348, following the discussion made in June 2026 LDWG Meeting.

Currently, p4c allows default parameters in parser/control type declarations, and I believe it should be disallowed (while still allowing those for parser/control declarations themselves).

Take the following program, [default-control-argument.p4](https://github.com/p4lang/p4c/blob/main/testdata/p4_16_samples/default-control-argument.p4) from p4_16_samples, for example.

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;

In the control type declaration of C<H, M>, it includes a default parameter, intr_md with an initial value, {0, 0}. And the control declaration MyC is expected to match the type of C<H, M> (where H is hdr_t and M is meta_t).

I believe this default parameter is misleading because,

  • The control type declaration C<H, M> implies that we may explicitly supply an argument, corresponding to the intr_md parameter.
  • So only looking at the type declaration (which is essentially a typed interface for parser/controls), users may think that we can supply a third argument, intr_md for MyC that is intended to implement C<H, M>.
  • However, this results in an error, because MyC only expects two parameters.

Three options were discussed in the LDWG, where the members suggested the first one, (A).

  • (A) Disallow default parameters in parser/control type declarations.
  • (B) Allow default parameters in parser/control type declarations, but parser/control declarations must define the same set of default parameters, with the same default values.
  • (C) Allow default parameters in parser/control type declarations, but parser/control declarations must define the same set of default parameters, but not required to have the same default values.

Thus, I suggest that we disallow default parameters in parser/control type declarations in the p4c frontend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions