You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d1c4b04
Browse filesBrowse the repository at this point in the historyBrowse files
Compile character range patterns in linear time (#8868)
Why:
A character range pattern is expanded into one or-pattern alternative
per character, and typing, the exhaustiveness and unused-case checks,
default matrices and switch compilation each took time quadratic in
the number of alternatives: a range over the CJK block ran out of
memory (#8866).
Matching modified (character range patterns):
Example:
let f = c =>
switch c {
| '\u{100}' .. '\u{1100}' => 1
| _ => 0
}
Before (lambda):
(let
(f/1001 =
(function c/1002
(catch
(catch
(if (|| (>[int] c/1002 4352) (<[int] c/1002 256)) (exit 2)
(exit 1))
with (2) 0)
with (1) 1)))
(makeblock module/exports f/1001))
After (lambda):
(let
(f/1001 =
(function c/1002
(catch
(catch
(if (|| (>[int] c/1002 4352) (<[int] c/1002 256)) (exit 2)
(exit 1))
with (2) 0)
with (1) 1)))
(makeblock module/exports f/1001))
Before (text): `/usr/bin/time -l bsc` on the example, three runs
2.22 real 2.03 user 0.18 sys
1273511936 maximum resident set size
2.20 real 2.02 user 0.16 sys
1271463936 maximum resident set size
2.21 real 2.03 user 0.17 sys
1273659392 maximum resident set size
After (text): `/usr/bin/time -l bsc` on the example, three runs
0.02 real 0.02 user 0.00 sys
25395200 maximum resident set size
0.02 real 0.02 user 0.00 sys
25624576 maximum resident set size
0.03 real 0.02 user 0.00 sys
25591808 maximum resident set size
Review: Where did the time go? Typing copied the right subtree of each
nested or-pattern to rename variables even when there are none; the
checks searched the groups linearly for each row and compared all
pairs of rows for the default matrix minima; switch compilation found
each key's cell with `List.find`. Groups, minima and int, char and
string cells are now found by hashing, and the copy is skipped when
nothing is renamed.
Review: Does the generated code change? No: #8868 reports byte-identical
JavaScript and warnings across `tests/tests/src`, the `super_errors`
fixtures and the runtime.
Re-applies #8868 by @cknitt for illustration.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
- Fix quadratic compile time and memory of large character range patterns, and speed up switches over many constants. https://github.com/rescript-lang/rescript/pull/8868
0 commit comments