Skip to content

Tuple fields are not properly diagnosed as not being l-values #5315

Open
@asl

Description

@asl

Note that the code is ill-formed per spec (https://p4.org/p4-spec/docs/p4-16-working-draft.html#sec-tuple-exprs):
Currently tuple fields are not left-values, even if the tuple itself is. (I.e. a tuple can only be assigned monolithically, and the field values cannot be changed individually.) This restriction may be lifted in a future version of the language.

So, this should be properly diagnosed during type inferenced.

Originally posted by @asl in #4057

The code in question is:

#include <core.p4>
#include <v1model.p4>

header hdr {
    bit<8>  a;
}

struct Header_t {
    hdr h;
}

header SimpleHeader {
    bit<8> b;
}

struct ArrayStruct {
    tuple<SimpleHeader[10]> n;
}

struct Meta_t {
    ArrayStruct s;
}

parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) {
    state start {
        b.extract(h.h);
        transition accept;
    }
}

control vrfy(inout Header_t h, inout Meta_t m) { apply {} }
control update(inout Header_t h, inout Meta_t m) { apply {} }
control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) { apply {} }
control deparser(packet_out b, in Header_t h) { apply { b.emit(h.h); } }

control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) {
    apply {
       // Should cause error
        m.s.n[0][0].b = 1;
    }
}

V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Warnings and ErrorsAbsence of an expected error or warning message in the compilercoreTopics concerning the core segments of the compiler (frontend, midend, parser)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions