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
Tuple fields #877
Tuple fields #877
Conversation
Perhaps this is intended by design, but this proposal syntactically disallows the ability to have a run-time variable expression, or even a named compile-time constant (e.g. #define symbol, or Using syntax like
|
Yes, this is by design, with a dynamic index we cannot statically tell the field type. |
So compile-time known value is needed, understood. But an expression still might be useful for developers? We allow compile-time known value expressions in bit slices today, and in place of the |
This syntax won't work for expressions. |
Fixes #864 |
I approve but let's discuss at the July LDWG. |
+1 for array indexing syntax, even if the indices are restricted to compile-time constant expressions. |
Actually, upon reflection, I think array indexing is much better than |
p4-16/spec/P4-16-spec.mdk
Outdated
@@ -3701,6 +3701,9 @@ list expressions. | |||
tuple<bit<32>, bool> x = { 10, false }; | |||
~ End P4Example | |||
|
|||
The fields of a tuple are named `f0`, `f1`, etc,; they can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "etc." not "etc,"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically one dot is for the etc abbreviation, and the second is the sentence-ending dot.
p4-16/spec/P4-16-spec.mdk
Outdated
@@ -2486,7 +2486,7 @@ struct Parsed_headers { | |||
### Tuple types { #sec-tuple-types } | |||
|
|||
A tuple is similar to a `struct`, in that it holds multiple | |||
values. Unlike a `struct` type, tuples have no named fields. The | |||
values. The fields of a tuple are named in order `f0`, `f1`, etc.. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "etc." not "etc.."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if I can implement an alternative prototype for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically one dot is for the etc abbreviation, and the second is the sentence-ending dot.
That might seem logical, but English defies logic in many ways. https://english.stackexchange.com/questions/8382/when-etc-is-at-the-end-of-a-phrase-do-you-place-a-period-after-it/8385#8385
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Chicago Manual of Style agrees :-)
https://www.chicagomanualofstyle.org/qanda/data/faq/topics/Punctuation/faq0040.html
Would it make sense to introduce optional field names that can be defined by the programmer, while using |
@vgurevich can you elaborate on your proposal? |
@mbudiu-vmw -- something like:
|
This is an anonymous struct, not a tuple. We have an issue filed for supporting anonymous structs, and you are listed as an owner. |
The spec should say whether tuple fields can be left values. |
Hi @mbudiu-vmw, this is the ONF bot 🤖 I'm glad you want to contribute to our projects! However, before accepting your contribution, we need to ask you to sign a Contributor License Agreement (CLA). You can do it online, it will take only a few minutes: ✒️ 👉 https://cla.opennetworking.org After signing, make sure to add your Github user ID For more information or help:" |
@jnfoster : made the requested typo fix. If you approve we can merge this. |
This small PR introduces tuple field extraction. Initially I was thinking to use a syntax like
t.0
to extract a field, but usingt.f0
seems equally good and requires no changes to the grammar, and will not introduce ambiguities.