Repository navigation
Allow Unicode Identifiers - #2595
Conversation
Coming in with no context. Can we just forbid user-defined identifiers from starting with double underscore, rather than actually encoding that into the grammar for |
|
@kainino0x the previous regex did ban it inside ident but I think the way you want might already be in the spec per: |
|
I think that text is just meant to describe the contents of the regex on the next line. That rule could be kept as a separate rule though, yeah. |
|
Thanks for moving those rules out into prose instead of buried in the regex! |
|
Just verifying that this PR intends to be incompatible with JavaScript identifiers which don't normalize. From the JS spec
|
|
Yes, you're right that this is different from javascript. I'd argue that this is a usability progression, though. Personally, my biggest worry is about the perf. But it probably makes sense to be international-by-default, and only revert if we have implementation evidence that doing so would be unacceptable for some reason (possibly runtime performance). Also, if someone has a javascript program that they're trying to transcribe into a shader, they're going to have bigger problems than identifier equality checks. |
|
I guess my point (which I brought up in #1160) is, like JavaScript, normalization is left to the user. The JS spec says
Which can be the same fo webgpu. If you want to normalize you just do |
|
Note: if Immutable Identifiers become the consensus (which will have to still cite UAX31 as in this PR), I will change the RegEx to be (which fortunately can even capture double underscore being an invalid code): See: #1160 (comment) Using shortnames: |
|
The latest commit to this PR adjusts the text to follow Meeting on 2022 March 22. Namely, it opts for Option 1 in this #1160 (comment) comment and updates the decision of VF2F to omit NFC normalization, and instead, encourage UA to issue warnings which can improve the experience for even more users by providing feedback when there are lookalike characters, or do even an NFKC check, furthermore CJK, and not rely on NFC as the only metric. The discussion will get a copy probably soon from the meeting minutes. I think following the closing argument on the way to have forward progression without stagnation would benefit everybody and not be an impedance to anybody; thanks. cc: @dneto0 @litherum @kdashg @ben-clayton @jimblandy (and all who already should be getting email from this comment) |
|
The minutes as mentioned above #2595 (comment) is here (thanks @kdashg): #1160 (comment) |
dneto0
left a comment
There was a problem hiding this comment.
Thanks, this is nearly there!
| <dfn for=syntax>ident</dfn> : | ||
|
|
||
| | `/([a-zA-Z_][0-9a-zA-Z][0-9a-zA-Z_]*)|([a-zA-Z][0-9a-zA-Z_]*)/` | ||
| | `/([\p{XID_Start}])|([_\p{XID_Start}][\p{XID_Continue}]+)/` |
There was a problem hiding this comment.
This does not allow the identifer x_
I think this needs an underscore to be allowed beside the XID_Continue.
([\p{XID_Start}])|([_\p{XID_Start}][_\p{XID_Continue}]+)
If you are trying to exclude the _ and __ cases then I think you would need to break out more cases.
\p{XID_Start}
[_\p{XID_Start}][\p{XID_Continue}][_\p{XID_Continue}]*
[\p{XID_Start}][_\p{XID_Continue}]+
There was a problem hiding this comment.
XID_Continue includes _ (low line), that's why it is not additionally included. So that kind of makes it impossible to do exception for double underscore case... :\
There was a problem hiding this comment.
But I was able to get more RegEx engines to behave better by using the following:
/([_\p{XID_Start}][\p{XID_Continue}]+)|([\p{XID_Start}])/uy
There was a problem hiding this comment.
@dneto0 I applied this latest regex, hopefully it does capture cases like x_ in your test RegEx engine too.
There was a problem hiding this comment.
(just for anybody reading and having issues, the uy suffix is important in JS RegEx and in Python, you should probably use the Unicode RegEx package and not the built-in)
There was a problem hiding this comment.
@dneto0 The second one with omission of low-line in second character I think tries to block starting with double underscore, but it will still pass because even if there is no underscore there, XID_Continue does have support for underscore intrinsically, and unfortunately support for Unicode Set operations (to say, e.g., XID_Continue but without underscore) are not universal in RegEx engines. And XID_Start, which does actually omit low-line underscore, can not substitute XID_Continue for a second character.
There was a problem hiding this comment.
Unicode provided listing of XID_Continue content: https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5B%3AXID_Continue%3A%5D&g=&i=
There was a problem hiding this comment.
What are the uy modifiers? I can't find documentation for them.
There was a problem hiding this comment.
'y' modifier is: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky
'u' modifier is for unicode: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode
There was a problem hiding this comment.
And yeah, I didn't realize the XID_Continue set included underscore "Low line" until I looked.
So my suggestions were incorrect.
| [=UAX31 Lexical Classes|XID_Continue=]. | ||
|
|
||
| Note: User agents should consider issuing developer-visible warnings in most or all | ||
| situations where display of two identifiers with different code point sequences |
There was a problem hiding this comment.
This is a little too broad, I think.
It should be ok to have different spellings of things that look the same, but for different declarations:
fn here() { let foo: i32 = 12; }
fn there() { let foo: i32 = 14; /// assume I spelled foo with a different codepoint sequence }
There is no problem to be flagged here, since the two scopes don't overlap.
I suggest qualifying it a little more tightly:
Note: A user agent or should issue developer-visible warnings when the meaning of a WGSL program would change if all instances of an identifier spelled with a specific codepoint sequence are replaced by another codepoint sequence that would appear the same to a reader. For example, remapping each identifier to its canonical equivalent spelling under [=UAX15 Normalization Forms|Normaliztaion Form C (NFC)=] must permit the same set of declarations (avoiding new identifier collisions), and must not change how identifier uses [=resolve=] to their declarations.
There was a problem hiding this comment.
@dneto0 this makes sense. Change done, thanks!
| The key of each key-value pair must equal the identifier string of one such constant. | ||
| When the pipeline is executed, that constant will have the specified value. | ||
|
|
||
| Note: User agents should consider issuing developer-visible warnings in most or all |
There was a problem hiding this comment.
I'm not sure the warning makes sense here.
Maybe suggest replacing with this?
Note: A user agent or should issue developer-visible warnings when the meaning of a WGSL program would change if all instances of an identifier spelled with a specific codepoint sequence are replaced by another codepoint sequence that would appear the same to a reader.
| Entry point names compare by their code points and | ||
| do not follow [=UAX15 Equivalences=] for [[!UnicodeVersion14|Unicode Version 14.0.0]]. | ||
|
|
||
| Note: User agents should consider issuing developer-visible warnings in most or all |
There was a problem hiding this comment.
I'm not sure this is the right time for an implementation to check for collisions.
I would probably drop this note here.
dneto0
left a comment
There was a problem hiding this comment.
Thanks! This is a great improvement to WGSL!
|
Thank you and all the working group for shaping this support which makes the language factually more inclusive and removes virtual mental barriers around programming! |
Tries to apply #1160 consensus.
This PR applies the accepted form of Unicode Identifiers to WGSL and WebGPU specifications where characters are constrained by XID_Start and XID_Continue from UAX31 and does not follow canonical equivalence, all Unicode references per version 14.0.0.
There is a caveat in the spec's identifier regex such that generated parser can recognize double underscore as a correct start for an identifier. This issue stems from the fact that the underlying library does not allow for look-ahead constructions in RegEx. Otherwise, the definition of accepting the second character as XID_Continue without underscore would require a set difference operation from the Unicode Set. Although there has always been the caveat of reserved words that will go away (see tree-sitter/tree-sitter#1635 change), still bundling other missing aspects skipped by grammar definitions beg for a paragraph that clarifies that spec is only entirely understood with the surrounding text and not the syntactic definitions isolated. The undertaking of such a paragraph is not in this PR as it should be done with further discussion.
There is the possibility of defining identifier as a custom scanner in C to avoid double underscore identifiers in the generated parser. Should we remove the identifier syntax definition from spec and do that instead (I kept it due to considerations given in the prior paragraph and given that support for XID_Start and XID_Continue in RegEx makes it an easy to understand one for readers)?
On top of WGSL deficiencies in my attempt, I think I would genuinely benefit from guidance on how to improve the WebGPU spec side, as I did a terrible job there beyond including citations.
Preview | Diff