-
Notifications
You must be signed in to change notification settings - Fork 5
/
UAX31-EWG-slides.html
457 lines (378 loc) · 12.2 KB
/
UAX31-EWG-slides.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>C++ Identifiers using UAX 31</title>
<meta name="author" content="Steve Downey"/>
<meta name="description" content="
"/>
<meta name="keywords" content=" "/>
<style type="text/css">
.underline { text-decoration: underline; }
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js/dist/reveal.css"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js/dist/theme/black.css" id="theme"/>
<link rel="stylesheet" href="http://sdowney.org/css/smd-zenburn.css"/>
<link rel="stylesheet" href="./footer.css"/>
<link rel="stylesheet" type="text/css" href="http://sdowney.org/css/smd-zenburn.css" />
</head>
<body>
<div class="reveal">
<div class="slides">
<section id="sec-title-slide">
<h1 class="title">C++ Identifiers using UAX 31</h1>
</section>
<section>
<section id="slide-org6746883">
<h2 id="org6746883">C++ Identifier Syntax using Unicode Standard Annex 31</h2>
<ul>
<li><p>
That C++ identifiers match the pattern
</p>
<blockquote>
<p>
(XID_Start + _ ) + XID_Continue*.
</p>
</blockquote></li>
<li>That portable source is required to be normalized as NFC.</li>
<li>That using unassigned code points be ill-formed.</li>
</ul>
</section>
<section id="slide-org39b5874">
<h3 id="org39b5874">Problem this fixes : NL 029</h3>
<blockquote>
<p>
Allowed characters include those from U+200b until U+206x; these are zero-width and control characters that lead to impossible to type names, indistinguishable names and unusable code & compile errors (such as those accidentally including RTL modifiers).
</p>
</blockquote>
</section>
<section id="slide-org86193c9">
<h3 id="org86193c9">Status Quo: we allow other "weird identifier code points"</h3>
<ul>
<li>The middle dot · which looks like an operator.</li>
<li>Many non-combining "modifiers" and accent marks, such as ´ and ¨ and ꓻ which don't really make sense on their own.</li>
<li>"Tone marks" from various languages, including ˫ (similar to a box-drawing character ├ which is an operator).</li>
<li>The "Greek question mark" ;</li>
<li>Symbols which are simply not linguistic, such as ۞ and ༒.</li>
</ul>
<p>
<a href="https://gist.github.com/jtbandes/c0b0c072181dcd22c3147802025d0b59#weird-identifier-code-points">https://gist.github.com/jtbandes/c0b0c072181dcd22c3147802025d0b59#weird-identifier-code-points</a>
</p>
</section>
<section id="slide-orgffbd8f8">
<h3 id="orgffbd8f8">UAX 31 - Unicode Identifier and Pattern Syntax</h3>
<ul>
<li>Follows the same principles as originally used for C++</li>
<li>Actively maintained</li>
<li>Stable</li>
</ul>
</section>
<section id="slide-org213e155">
<h3 id="org213e155">XID_Start and XID_Continue</h3>
<ul>
<li>Unicode database defined properties</li>
<li>Closed under normalization for all four forms</li>
<li>Once a code point has the property it is never removed</li>
<li>Roughly:
<ul>
<li>Start == letters</li>
<li>Continue == Start + numbers + some punctuation</li>
</ul></li>
</ul>
</section>
</section>
<section>
<section id="slide-org1774cc5">
<h2 id="org1774cc5">The Emoji Problem</h2>
<ul>
<li>The emoji-like code points that we knew about were excluded</li>
<li>We included all unassigned code points</li>
<li>Status Quo Emoji 'support' is an accident, incomplete, and broken</li>
</ul>
</section>
<section id="slide-orgfe900bb">
<h3 id="orgfe900bb">Status quo is broken</h3>
<div class="outline-text-3" id="text-orgfe900bb">
</div>
</section>
<section id="slide-org28d7c31">
<h4 id="org28d7c31">Some Status Quo examples</h4>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Not Valid</th>
<th scope="col" class="org-left">Valid</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">int ⏰ = 0;</td>
<td class="org-left">int 🕐 = 0;</td>
</tr>
<tr>
<td class="org-left">int ☠️ = 0;</td>
<td class="org-left">int 💀 = 0;</td>
</tr>
<tr>
<td class="org-left">int ✋️ = 0;</td>
<td class="org-left">int 👊 = 0;</td>
</tr>
<tr>
<td class="org-left">int ✈️ = 0;</td>
<td class="org-left">int 🚀 = 0;</td>
</tr>
<tr>
<td class="org-left">int ☹️ = 0;</td>
<td class="org-left">int 😀 = 0;</td>
</tr>
</tbody>
</table>
<p>
When the character was added to Unicode controls validity
</p>
</section>
<section id="slide-org64948ae">
<h4 id="org64948ae">Status Quo: ♀ and ♂ are disallowed</h4>
<p>
Gendered variants of emoji are selected by using a zero width joiner together
with the male and female sign.
</p>
<div class="org-src-container">
<pre class="src src-C++"><span class="org-comment-delimiter">// </span><span class="org-comment">Valid</span>
<span class="org-type">bool</span> 👷 = <span class="org-constant">true</span>; <span class="org-comment-delimiter">// </span><span class="org-comment">Construction Worker</span>
<span class="org-comment-delimiter">// </span><span class="org-comment">Not valid</span>
<span class="org-type">bool</span> 👷‍♀ = <span class="org-constant">false</span>; <span class="org-comment-delimiter">// </span><span class="org-comment">Woman Construction Worker ({Construction Worker}{ZWJ}{Female Sign})</span>
</pre>
</div>
</section>
<section id="slide-org8578b9d">
<h3 id="org8578b9d">Problems adding Emoji as identifiers</h3>
<div class="outline-text-3" id="text-org8578b9d">
</div>
</section>
<section id="slide-orga19dfdd">
<h4 id="orga19dfdd">Emoji are complex</h4>
<ul>
<li>Not just code points</li>
<li>Need grapheme cluster analysis</li>
<li>May incur costs even for code not using emoji</li>
</ul>
</section>
<section id="slide-orgc99cd88">
<h4 id="orgc99cd88">Emoji are not "Stable" in Unicode</h4>
<p>
From the emoji spec
</p>
<blockquote>
<p>
isEmoji(♟)=false for Emoji Version 5.0, but true for Version 11.0.
</p>
</blockquote>
<p>
It is possible that the emoji property could be removed.
</p>
</section>
<section id="slide-org7945c40">
<h4 id="org7945c40">Identifying Emoji is difficult</h4>
<p>
The unicode standard provides a regex that will reject non-emoji, but does not guarantee a valid emoji sequence.
</p>
<pre class="example" id="org80bb79b">
\p{RI} \p{RI}
| \p{Emoji}
( \p{EMod}
| \x{FE0F} \x{20E3}?
| [\x{E0020}-\x{E007E}]+ \x{E007F} )?
(\x{200D} \p{Emoji}
( \p{EMod}
| \x{FE0F} \x{20E3}?
| [\x{E0020}-\x{E007E}]+ \x{E007F} )?
)*
</pre>
<p>
It's not clear how much of the unicode database would be required for complete support.
</p>
<p>
<a href="https://unicode.org/reports/tr51/">UNICODE EMOJI</a>
</p>
</section>
<section id="slide-org6efadf2">
<h4 id="org6efadf2">Some surprising things are emoji</h4>
<pre class="example" id="org1759999">
002A ; Emoji # E0.0 [1] (*️) asterisk
0030..0039 ; Emoji # E0.0 [10] (0️..9️) digit zero..digit nine
</pre>
<pre class="example" id="orgd59ae26">
{DIGIT ONE}{VARIATION SELECTOR-16}{COMBINING ENCLOSING KEYCAP} 1️⃣
{ASTERISK}{VARIATION SELECTOR-16}{COMBINING ENCLOSING KEYCAP} *️⃣
</pre>
<div class="org-src-container">
<pre class="src src-C++"><span class="org-comment-delimiter">/// </span><span class="org-comment">would this be valid?</span>
<span class="org-type">int</span> 1️⃣ = 1;
</pre>
</div>
</section>
<section id="slide-orgf1b632e">
<h4 id="orgf1b632e">Fixing the emoji problem would mean being inventive</h4>
<p>
Being inventive in an area outside our expertise is HARD
</p>
<p>
Adopting UAX31 as a base to move forward is conservative
</p>
<p>
UAX 31 is a known good state
</p>
</section>
</section>
<section>
<section id="slide-org2ce257a">
<h2 id="org2ce257a">Script Issues</h2>
<p>
Some scripts require characters to control display or require punctuation that are not in the identifier set.
</p>
</section>
<section id="slide-org36ba9d3">
<h3 id="org36ba9d3">This includes English</h3>
<ul>
<li>Apostrophe and dash
<ul>
<li><code>won't</code></li>
<li><code>can't</code></li>
<li><code>mustn't</code></li>
<li><code>mother-in-law</code></li>
</ul></li>
<li>Programmers are used to this and do not notice</li>
</ul>
</section>
<section id="slide-orgcb84853">
<h3 id="orgcb84853">Zero Width characters are excluded by UAX 31</h3>
<p>
Status quo allows these invisible characters
</p>
<div class="org-src-container">
<pre class="src src-C++"><span class="org-type">int</span> <span class="org-variable-name">tmp</span> = 0;
<span class="org-type">int</span> <span class="org-variable-name">t</span>‍‍mp = 0;
</pre>
</div>
<ul>
<li><p>
clang 10 warns
</p>
<p>
<source>:2:6: warning: identifier contains Unicode character <U+200D> that is invisible in some environments [-Wunicode-zero-width]
</p></li>
</ul>
<p>
int t<U+200D><U+200D>mp = 0;
</p>
</section>
<section id="slide-orga42b697">
<h3 id="orga42b697">ZWJ and ZWNJ</h3>
<p>
However zero width joiner and non joiner are used in some scripts
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">Farsi word "names"</td>
</tr>
<tr>
<td class="org-left">نامهای</td>
</tr>
<tr>
<td class="org-left">NOON + ALEF + MEEM + HEH + ALEF + FARSI YEH</td>
</tr>
<tr>
<td class="org-left"><img src="https://www.unicode.org/reports/tr31/images/uax31-figure-2-farsi-ex1-v1-web.jpg" alt="uax31-figure-2-farsi-ex1-v1-web.jpg" /></td>
</tr>
</tbody>
</table>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left">Farsi word "a letter"</td>
</tr>
<tr>
<td class="org-left">نامهای</td>
</tr>
<tr>
<td class="org-left">NOON + ALEF + MEEM + HEH + <b>ZWNJ</b> + ALEF + FARSI YEH</td>
</tr>
<tr>
<td class="org-left"><img src="https://www.unicode.org/reports/tr31/images/uax31-figure-2-farsi-ex2-v1-web.jpg" alt="uax31-figure-2-farsi-ex2-v1-web.jpg" /></td>
</tr>
</tbody>
</table>
<p>
Anecdotally, these issues are understood and worked around
</p>
</section>
<section id="slide-orgd091436">
<h3 id="orgd091436">UAX 31 has an expensive solution</h3>
<p>
Identifiers can be checked for what script the code points in the identifier are used, and the rules for allowed characters can be tailored. This requires a Unicode database and would require extensive analysis during lexing.
</p>
<p>
SG 16 does not recommend this.
</p>
</section>
</section>
<section>
<section id="slide-org0ae771a">
<h2 id="org0ae771a">Other adopters</h2>
<ul>
<li>Java (<a href="https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.8">https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.8</a>)</li>
<li>Python 3 <a href="https://www.python.org/dev/peps/pep-3131/">https://www.python.org/dev/peps/pep-3131/</a></li>
<li>Erlang <a href="https://www.erlang.org/erlang-enhancement-proposals/eep-0040.html">https://www.erlang.org/erlang-enhancement-proposals/eep-0040.html</a></li>
<li>Rust <a href="https://rust-lang.github.io/rfcs/2457-non-ascii-idents.html">https://rust-lang.github.io/rfcs/2457-non-ascii-idents.html</a></li>
<li>JS <a href="https://tc39.es/ecma262/">https://tc39.es/ecma262/</a></li>
</ul>
</section>
</section>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/reveal.js/dist/reveal.js"></script>
<script src="https://cdn.jsdelivr.net/npm/reveal.js/plugin/markdown/markdown.js"></script>
<script src="https://cdn.jsdelivr.net/npm/reveal.js/plugin/notes/notes.js"></script>
<script src="https://cdn.jsdelivr.net/npm/reveal.js/plugin/search/search.js"></script>
<script src="https://cdn.jsdelivr.net/npm/reveal.js/plugin/zoom/zoom.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: false,
center: true,
slideNumber: 'c',
rollingLinks: false,
keyboard: true,
mouseWheel: false,
fragmentInURL: false,
hashOneBasedIndex: false,
pdfSeparateFragments: true,
overview: true,
width: 1600,
height: 900,
transition: 'fade',
transitionSpeed: 'default',
// Plugins with reveal.js 4.x
plugins: [ RevealMarkdown, RevealNotes, RevealSearch, RevealZoom ],
// Optional libraries used to extend reveal.js
dependencies: [
]
});
</script>
</body>
</html>