Skip to content

Allow SymbolicArray to represent arrays of non-header/header union types#5516

Open
kfcripps wants to merge 2 commits intop4lang:mainfrom
kfcripps:non-header-array-interpreter-fix
Open

Allow SymbolicArray to represent arrays of non-header/header union types#5516
kfcripps wants to merge 2 commits intop4lang:mainfrom
kfcripps:non-header-array-interpreter-fix

Conversation

@kfcripps
Copy link
Contributor

@kfcripps kfcripps commented Mar 7, 2026

For the following parser:

parser p(packet_in packet, out metadata_t metadata) {
    state start { transition s0; }
    state s0 {
        transition select(packet.lookahead<bit<8>>()) {
            1 : s1;
            default : accept;
        }
    }
    state s1 {
        packet.extract(metadata.h);
        metadata.array[1].f1 = metadata.h.array[0].f1;
        transition accept;
    }
}

Without these changes, the output of --top4 MidEndLast looks like this:

parser p(packet_in packet, out metadata_t metadata) {
    @name("p.tmp_0") bit<8> tmp_0;
    state stateOutOfBound {
        verify(false, error.StackOutOfBounds);
        transition reject;
    }
    state s1 {
        packet.extract<h_t>(metadata.h);
        transition stateOutOfBound;
    }
    state start {
        tmp_0 = packet.lookahead<bit<8>>();
        transition select(tmp_0) {
            8w1: s1;
            default: accept;
        }
    }
}

and with the changes:

parser p(packet_in packet, out metadata_t metadata) {
    @name("p.tmp_0") bit<8> tmp_0;
    state s1 {
        packet.extract<h_t>(metadata.h);
        metadata.array[1].f1 = metadata.h.array[0].f1;
        transition accept;
    }
    state start {
        tmp_0 = packet.lookahead<bit<8>>();
        transition select(tmp_0) {
            8w1: s1;
            default: accept;
        }
    }
}

Without the changes, metadata.array[1].f1 = metadata.h.array[0].f1; assignment incorrectly gets removed.

@kfcripps kfcripps requested review from ChrisDodd and fruffy March 7, 2026 01:28
@kfcripps kfcripps added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Mar 7, 2026
kfcripps added 2 commits March 6, 2026 17:38
Signed-off-by: kfcripps <kyle@pensando.io>
Signed-off-by: Kyle Cripps <kyle@pensando.io>
@kfcripps kfcripps force-pushed the non-header-array-interpreter-fix branch from 03c2281 to 02faef6 Compare March 7, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Topics concerning the core segments of the compiler (frontend, midend, parser)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants