Open kainino0x opened 3 years ago
I definitely agree that we should not allow _
for the struct field names.
The semantic of "I don't need a name" could be useful in some cases, but we expect the most frequent case to be the same struct definition shared between different entry points (in which case _
isn't needed). We could easily move this to post-MVP.
I agree this is a good idea.
Note, an identifier of _
is already disallowed by the spec. The IDENTIFIER is defined as [a-zA-Z][0-9a-zA-Z_]*
which requires a leading character.
Can you write a short program where_
in a struct would be valuable in addition to offset
/span
/align
?
(Because we aren't a functional language, and don't have lambdas or function pointers, I don't see much value in doing this for function parameters today. Given our current type system, no WGSL programmer is going to want to curry, or write a function that expects a callback of a particular signature.)
Can we move this to post-MVP? Seems marginally useful and non-essential. We have bigger fish to fry atm.
Can you write a short program where
_
in a struct would be valuable in addition tooffset
/span
/align
?
It's sort of an alternative to offset/span/align. Potentially.
Can we move this to post-MVP? Seems marginally useful and non-essential. We have bigger fish to fry atm.
Like I said in the OP, all we really have to do is decide whether to reserve the syntax. Dan pointed out it's already an invalid identifier, so the syntax is already reserved. So yes.
It would have the special meaning of "unused" and it wouldn't be valid to use any
._
member from any code. Additionally, it would be valid to have multiple_
that would normally collide.We could do this in other places as well (function args in particular), but struct members are most important if you have to add struct members in order to insert padding.
Prior art comes from numerous functional-adjacent languages like Rust (which does not actually allow it in structs) and Haskell/OCaml (in matches and functions iirc, probably not in records).
If we don't want to do this now, the safe thing is to disallow identifiers of
_
so that we can use the syntax later. Rust does this.