Add arrays of non-header types
Should we in this PR also define literal syntax for arrays, e.g. perhaps something like (typeRef[4]) {expr0, expr1, expr2, expr3}?
In this section:
[#sec-uninitialized-values-and-writing-invalid-headers]
=== Reading uninitialized values and writing fields of invalid headers
there is an explicit statement about accessing elements of header stacks that are outside of range:
The result of reading a value in any of the situations below is that
some unspecified value will be used for that field.
[ ... ]
* reading a field of a header that is an element of a header stack,
where the index is out of range for the header stack.
Should that be generalized to reading an element of an array where the index is out of range for the array?
Similarly later in that section for attempted writes to a header stack element it says:
If any of these kinds of writes are performed:
[ ... ]
* a write to a field in an element of a header stack, where the index
is out of range
[ ... ]
then that write must not change any state that is currently defined in
the system, neither in header fields nor anywhere else.
Should that also be generalized to attempting to write to elements of an array where the index is out of bounds?
This opens up the possibility of having nested arrays, which could potentially complicate array / header stack processing in some passes. We might consider explicitly prohibiting nested arrays until there is real motivation to support them. Related discussion: https://github.com/p4lang/p4c/pull/5115#discussion_r1936292442
Most of the support for this is already in p4c -- last remaining piece is https://github.com/p4lang/p4c/pull/5338
Ready for review and merging. @jonathan-dilorenzo and @jafingerhut to review.
Let's resolve the "error?" to error and make a note that this isn't done for any deep reason, but simply due to the lack of compelling use cases and the ability to change our minds in a non-breaking way.