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

Add arrays of non-header types #1360

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

ChrisDodd
Copy link
Contributor

No description provided.

@jafingerhut
Copy link
Collaborator

Should we in this PR also define literal syntax for arrays, e.g. perhaps something like (typeRef[4]) {expr0, expr1, expr2, expr3}?

@jafingerhut
Copy link
Collaborator

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?

@jafingerhut jafingerhut added the ldwg-discussion Plan to discuss at next LDWG label Feb 1, 2025
Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

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

Looks good to me, I agree we should have exact semantics of out-of-bounds access as suggested in #1360 (comment).

Comment on lines +2587 to +2590
[4] This is for array types that are not header stacks (the array element
type is not a header or header_union)

[5] Architectures may disallow arrays of arrays
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick:

Suggested change
[4] This is for array types that are not header stacks (the array element
type is not a header or header_union)
[5] Architectures may disallow arrays of arrays
[4] This is for array types that are not header stacks (the array element
type is not a header or header_union).
[5] Architectures may disallow arrays of arrays.

@kfcripps
Copy link
Contributor

kfcripps commented Feb 3, 2025

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: p4lang/p4c#5115 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ldwg-discussion Plan to discuss at next LDWG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants