Skip to content

error type used as a ternary match type should be disallowed #5637

@jaehyun1ee

Description

@jaehyun1ee

This is a follow-up issue from the discussion made in LDWG regarding p4lang/p4-spec#1389.

The specification mentions about ternary as:

a ternary match kind on a key field means that the field in the table specifies a set of values for the key field using a value and a mask. The meaning of the (value, mask) pair is similar to the P4 mask expressions, as described in Section 8.15.3: a key field k matches the table entry when k & mask == value & mask.

Thus, a ternary match makes sense for numeric types, but should not make sense for non-numeric types.

However, p4c allows non-numeric types for ternary matches, e.g., p4c/testdata/p4_16_samples/metrics/metrics_test_4.p4:

struct meta_t {
        /* ... omitted ... */
        error err_field; // error code
}

control ingress(
    inout headers_t hdr,
    inout meta_t meta,
    inout standard_metadata_t standard_metadata)

    table custom_table {
        key = {
            /* ... omitted ... */
            meta.err_field : ternary;
        }
        actions = {
            set_output;
            set_headers;
            my_drop;
        }
        default_action = my_drop();
    }
}

meta.err_field has error type, matched with ternary in custom_table. Because error types are neither numeric nor serializable, the semantics is the match is unclear.

Discussion within 2026-May LDWG was that p4c should disallow such program, where the example program can be amended by declaring the match kind as optional rather than ternary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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