Repository navigation
Commit cc6be0b
Represent char range patterns with a typed-tree node
A char range pattern such as `'a' .. 'z'` used to be expanded by the type
checker into an or-pattern with one constant per character, so compile time
and memory grew with the width of the range. It is now one `Tpat_interval`
node. Exhaustiveness and match compilation split each column at the bounds
of its ranges into pieces that every range covers fully or not at all, so
the work depends on the number of patterns, not on the number of characters.
Missing-case warnings show ranges instead of listing every character.
Example (rescript):
let f = (a, b) =>
switch (a, b) {
| ('a' .. 'z', 'a' .. 'z') => 1
| (_, '\u{0}' .. '`') => 2
}
Before (text):
You forgot to handle a possible case here, for example:
| ('t', '{')
| ('u', '{')
| ('v', '{')
| ('w', '{')
| ('x', '{')
| ('y', '{')
| ('z', '{')
After (text):
You forgot to handle a possible case here, for example:
| ('a' .. 'z', '{') | ('\x00', 'a')
Source: tests/build_tests/super_errors/fixtures/warning_8_char_range_example.res,
compiled with the parent commit and with this one.
Review: Is the generated JavaScript the same? Every committed snapshot is
byte-identical. A differential fuzzer (900 random switches over overlapping
char ranges, or-patterns, guards, tuples and options) compiled each program
with the parent commit and with this one: results equal a reference
evaluation for every input, warning numbers and locations are equal, and the
JS differs in shape for some programs and is 0.4% smaller in total
(296,645 -> 295,495 characters).
Review: Why are intervals precompiled like or-patterns? An expanded range
used to be an or-pattern, whose row is compiled once in a handler. Doing the
same for an interval whose row tests further columns keeps that sharing;
dividing such rows by piece instead made the fuzzer's output 16% larger.
Review: Why is the action of a range stored as shared? The switch emits it
for each value of the range. An expanded range shared it the same way,
because its values had equal actions; a copy per value would declare the
action's variables twice in one JavaScript scope.
Review: Are int ranges such as `1 .. 5` accepted? Not yet; they still report
`Invalid_interval`. The node and the algorithms already work on int and
char constants, for a follow-up.
Area: typechecker lambda analysis tests
Output: unchanged, all committed generated JS is byte-identical
(char_range_test.mjs changes with its source)
Formatting: unchanged
Formats: cmt (Caml1999T045 -> Caml1999T046)
PPX: unchanged, Ppat_interval already exists in the v0 parsetree
Editor: unchanged; analysis visits the new node like a constant
Errors: ERROR_VARIANTS.md warnings section lists the two new fixtures
Tests: ~tests/tests/src/char_range_test.res
+tests/build_tests/super_errors/fixtures/warning_8_char_range_example.res
+tests/build_tests/super_errors/fixtures/warning_11_char_range_covered.res
Measured: switch on '\u{0}' .. '\u{10FFFF}': 15.75 s and 1.78 GB -> 0.02 s and
19 MB (bsc wall time and max RSS, /usr/bin/time, parent commit vs this one);
switch on '\u{0}' .. '\u{FFFF}': 0.55 s and 135 MB -> 0.02 s and 20 MB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo
Signed-off-by: Christoph Knittel <ck@cca.io>1 parent 001621d commit cc6be0b
23 files changed
Lines changed: 680 additions & 143 deletions
File tree
- analysis/src
- changes
- compiler
- common
- ext
- ml
- tests
- build_tests/super_errors
- expected
- fixtures
- tests/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
538 | | - | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
539 | 541 | | |
540 | 542 | | |
541 | 543 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
112 | | - | |
113 | | - | |
114 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
0 commit comments