Skip to content

What is the semantics of a ternary match on bool and error types? #1389

Description

@jaehyun1ee

Two tests in p4c use a ternary match on bool and error types. However, it is unclear what its semantics should be.

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 I'm not sure what its semantics is for non-numeric types, and whether they should be allowed at the first place.

Below are the two tests in p4c that exhibit such use case:

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.

    table test_table {
        key = {
            hdr.ethernet.isValid() : ternary;
        }
        actions = {
            DummyAction;
            NoAction;
        }
        const entries = {
            (true) : DummyAction();
        }
    }

hdr.ethernet.isValid() has bool type, matched with ternary in test_table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions