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

New class ICastable; new type constraint added #3542

Merged
merged 2 commits into from
Oct 2, 2022

Conversation

mihaibudiu
Copy link
Contributor

Fixed #3534

Mihai Budiu added 2 commits September 29, 2022 15:43
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
…allowed

Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
Copy link
Member

@rst0git rst0git left a comment

Choose a reason for hiding this comment

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

LGTM

@mihaibudiu mihaibudiu merged commit 7e5040f into p4lang:main Oct 2, 2022
@mihaibudiu mihaibudiu deleted the issue3534 branch October 2, 2022 09:05
@kamleshbhalui
Copy link
Contributor

@mbudiu-vmw unable to compile this test after this commit.

~/workarea/p4c/build$ ./p4test test2.p4 
test2.p4(117): [--Werror=type-error] error: Entry
            (true,48w1,48w2,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w4, 48w10) : execute(48w1);
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ---- Actual error:
  test2.p4(43): Cannot unify type 'Proto' with type 'bit<8>'
  enum bit<8> Proto {
              ^^^^^
  ---- Originating from:
  test2.p4(117): Table entry has type 'tuple<bool, bit<48>, bit<48>, bit<8>, bit<48>, bit<48>, bit<48>>' which is not the expected type 'tuple<bool, bit<48>, bit<48>, Proto, bit<48>, bit<48>, bit<48>>'
              (true,48w1,48w2,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w4, 48w10) : execute(48w1);
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test2.p4(118): [--Werror=type-error] error: Entry
            (true,48w1,48w2,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w5, 48w10) : execute(48w1);
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ---- Actual error:
  test2.p4(43): Cannot unify type 'Proto' with type 'bit<8>'
  enum bit<8> Proto {
              ^^^^^
  ---- Originating from:
  test2.p4(117): Table entry has type 'tuple<bool, bit<48>, bit<48>, bit<8>, bit<48>, bit<48>, bit<48>>' which is not the expected type 'tuple<bool, bit<48>, bit<48>, Proto, bit<48>, bit<48>, bit<48>>'
              (true,48w1,48w2,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w4, 48w10) : execute(48w1);
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test2.p4(119): [--Werror=type-error] error: Entry
            (true,48w3,48w3,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w6, 48w10) : execute(48w1);
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ---- Actual error:
  test2.p4(43): Cannot unify type 'Proto' with type 'bit<8>'
  enum bit<8> Proto {
              ^^^^^
  ---- Originating from:
  test2.p4(117): Table entry has type 'tuple<bool, bit<48>, bit<48>, bit<8>, bit<48>, bit<48>, bit<48>>' which is not the expected type 'tuple<bool, bit<48>, bit<48>, Proto, bit<48>, bit<48>, bit<48>>'
              (true,48w1,48w2,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w4, 48w10) : execute(48w1);
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#include <core.p4>
#include <psa.p4>


typedef bit<48>  EthernetAddress;

header ethernet_t {
    EthernetAddress dstAddr;
    EthernetAddress srcAddr;
    bit<16>         etherType;
}

header ipv4_t {
    bit<4>  version;
    bit<4>  ihl;
    bit<8>  diffserv;
    bit<16> totalLen;
    bit<16> identification;
    bit<3>  flags;
    bit<13> fragOffset;
    bit<8>  ttl;
    bit<8>  protocol;
    bit<16> hdrChecksum;
    bit<32> srcAddr;
    bit<32> dstAddr;
    bit<80> newfield;
}

header tcp_t {
    bit<16> srcPort;
    bit<16> dstPort;
    bit<32> seqNo;
    bit<32> ackNo;
    bit<4>  dataOffset;
    bit<3>  res;
    bit<3>  ecn;
    bit<6>  ctrl;
    bit<16> window;
    bit<16> checksum;
    bit<16> urgentPtr;
}

enum bit<8> Proto {
proto1=0x1,
proto2=0x2
}

struct empty_metadata_t {
}


struct metadata {
     bit<16> data;
     bit<48> key1;
     bit<48> key2;
     bit<48> key3;
     bit<48> key4;
}

struct headers {
    ethernet_t       ethernet;
    ipv4_t           ipv4;
    tcp_t            tcp;
}


parser IngressParserImpl(packet_in buffer,
                         out headers hdr,
                         inout metadata user_meta,
                         in psa_ingress_parser_input_metadata_t istd,
                         in empty_metadata_t resubmit_meta,
                         in empty_metadata_t recirculate_meta)
{
    state start {
        buffer.extract(hdr.ethernet);
        transition select(hdr.ethernet.etherType) {
            0x0800 &&& 0x0F00 : parse_ipv4;
            16w0x0d00 : parse_tcp;
            default : accept;
        }
    }
    state parse_ipv4 {
        buffer.extract(hdr.ipv4);
        transition select(hdr.ipv4.protocol) {
            8w4 .. 8w7: parse_tcp;
            default: accept;
        }
    }
    state parse_tcp {
        buffer.extract(hdr.tcp);
        transition accept;
    }
}

control ingress(inout headers hdr,
                inout metadata user_meta,
                in    psa_ingress_input_metadata_t  istd,
                inout psa_ingress_output_metadata_t ostd)
{
    action execute(bit<48> x) {
        user_meta.data = 1;
    }
    table tbl {
        key = {
            hdr.ethernet.isValid(): exact;
            hdr.ethernet.dstAddr : exact;
            hdr.ethernet.srcAddr : exact;
            hdr.ipv4.protocol: exact;
            user_meta.key1 : ternary;
            user_meta.key2 : range;
            user_meta.key4: optional;

        }

        actions = { NoAction; execute; }
        const entries = {
            (true,48w1,48w2,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w4, 48w10) : execute(48w1);
            (true,48w1,48w2,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w5, 48w10)  : execute(48w1);
            (true,48w3,48w3,Proto.proto1, 48w2&&&48w3, 48w2 .. 48w6, 48w10) : execute(48w1);
            }
    }
    table tbl1 {
        key = {
            hdr.ethernet.isValid(): exact;
            hdr.ethernet.dstAddr : exact;
            hdr.ethernet.srcAddr : exact;
            user_meta.key3: lpm;
        }

        actions = { NoAction; execute; }
        const entries = {
            (true,48w1,48w2, 48w10) : execute(48w1);
            (true,48w1,48w2, 48w11)  : execute(48w1);
            (true,48w3,48w3, 48w12) : execute(48w1);
            }
    }
    apply {
            tbl.apply();
            tbl1.apply();
    }
}

parser EgressParserImpl(packet_in buffer,
                        out headers hdr,
                        inout metadata user_meta,
                        in psa_egress_parser_input_metadata_t istd,
                        in empty_metadata_t normal_meta,
                        in empty_metadata_t clone_i2e_meta,
                        in empty_metadata_t clone_e2e_meta)
{
    state start {
        transition accept;
    }
}

control egress(inout headers hdr,
               inout metadata user_meta,
               in    psa_egress_input_metadata_t  istd,
               inout psa_egress_output_metadata_t ostd)
{
    apply { }
}

control IngressDeparserImpl(packet_out packet,
                            out empty_metadata_t clone_i2e_meta,
                            out empty_metadata_t resubmit_meta,
                            out empty_metadata_t normal_meta,
                            inout headers hdr,
                            in metadata meta,
                            in psa_ingress_output_metadata_t istd)
{
    apply {
        packet.emit(hdr.ethernet);
        packet.emit(hdr.ipv4);
        packet.emit(hdr.tcp);
    }
}

control EgressDeparserImpl(packet_out packet,
                           out empty_metadata_t clone_e2e_meta,
                           out empty_metadata_t recirculate_meta,
                           inout headers hdr,
                           in metadata meta,
                           in psa_egress_output_metadata_t istd,
                           in psa_egress_deparser_input_metadata_t edstd)
{
    apply {
        packet.emit(hdr.ethernet);
        packet.emit(hdr.ipv4);
        packet.emit(hdr.tcp);
    }
}

IngressPipeline(IngressParserImpl(),
                ingress(),
                IngressDeparserImpl()) ip;

EgressPipeline(EgressParserImpl(),
               egress(),
               EgressDeparserImpl()) ep;

PSA_Switch(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main;

@mihaibudiu
Copy link
Contributor Author

You should file this as a new issue, not as a comment to a merged PR.
I will add this as a test case and make sure it works.

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.

Inconsistency of type of ?: (conditional expression) with enum types
3 participants