-
Notifications
You must be signed in to change notification settings - Fork 302
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
Use brackets for array types #854
Comments
I have some worries that appending modifiers at the end of type will lead to a similar syntax hell that C declarations have. IMHO the array syntax should surround the element type. Similarly to Swift's Alternatively Zig reverses the order, which helps with parsing too: |
I don't think we should be worried about C-like syntax hell, because we don't have prefixes in type names (pointers are not * in WGSL). I don't have a strong preference among the various proposals. |
Switching to |
MSL has established practice with the template notation.
|
Yes, Metal has both forms (with some semantic differences between them). However, the bracket form is much more common in MSL. Also, (AFAIK) both HLSL and GLSL only have the bracket form. |
Discussed at the 2020-07-28 meeting. |
A middle ground: T[N] desugars to array<T,N> |
For visibility: In the last meeting I expressed concern about ambiguity of having a type declaration structure where attributes are to the left, a base type is in the middle and array brackets are on the right:
In that case it's ambiguous whether the attributes apply to the element type or to the array type we're trying to express. Putting the array-brackets on the left disambiguates this:
@litherum rejected this as unfamiliar and hence not meeting their familiarity goal. |
Arguably since we're not trying to have C's confusing syntax anyway (more like Java I guess), you could go toward Rust and use the |
So an unsized array of size-two-array of two-floats would be:
That looks an awful lot like an attribute, and so it would extend the lookahead you'd need for parsing, both for humans and machines. |
It sounds like keeping |
Should we punt this into the post-mvp future? |
The discussion here seems to assume that This is the transpose of the way C and GLSL interpret For this proposal to work, the syntax would need to be something like:
where:
gets parenthesized as:
In other words, the grammar must grab all the subscripts at once, and apply them to the inner type from right to left. Note that Rust gets this sort of thing 'wrong': This is why Go has you write (I think it was a great choice for WGSL to avoid C-style type syntax, and not hide the identifier being declared in the midst of syntax specifying its type. But in doing so, we've traded |
WGSL meeting minutes 2021-08-17
|
The primary desire here is to increase familiarity - every popular human-writable shading language uses these square brackets. Solutions like There are a few natural situations about how the stride attribute could be applied with this new syntax:
|
In this proposal,
This matches C:
prints 28. I'm assuming the existing shading languages follow C. |
Drive-by 2 cents: please do not make this look like C. In C, In WGSL it would be the common (only) spelling, and it would clearly be self-inconsistent: Please do the Rust thing, the Go thing, or some other solution that is compatible with the fact that WGSL completely separates type from name (like Rust and Go) - the C syntax is deeply entrenched in the fact that C does not. |
Also please take into account that Rust and Go didn't invent array syntaxes for the fun of it - they did it because the C syntax is deeply incompatible with the type syntaxes of those languages. |
Adding to @kainino0x and @jimblandy I think it's a great property of a language if any type that is implicitly used is spelled out. Like, I can just take the span of the source file to show where this type is defined: let foo: array<array<i32, 3>, 4>; // the sub-type is "array<i32, 3>" If we allow C syntax for array declarations, this property is gone: let foo: i32[4][3]; // the sub-type is "i32[3]", which is not spelled out anywhere Another point I'd like to make is that WGSL's array semantics are closer to |
Just a note, I was trying to think of this yesterday but couldn't think of it. int[][] x = new int[2][5]; This is an array of 5 |
Yes. Same thing for 'expressions'. From the spec:
This simple mapping to source text has big benefits for understanding, and probably for tooling as well. |
One more nuance: We now have type-inference for let and var, so authors don't have to write down types nearly as much as in the original context of this issue. |
WGSL meeting minutes 2021-08-24
|
WGSL meeting minutes 2021-08-31
|
I would like to move this to post-v1 unless we get unblocked on getting feedback from prototyping here. |
WGSL meeting minutes 2022-05-10
|
`vec4()` is now a valid constructor. See: gpuweb#2305
This ship has sailed. Closing. |
Right now, WGSL has
array<vec4<f32>, 5>
. This would be much easier read if it wasvec4<f32>[5]
.(Bonus points for
fvec4[5]
if we do #736)The text was updated successfully, but these errors were encountered: