react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hermes/CMakeLists.txt +874 -0
- package/hermes/android/HostObjectJniTest.cpp +178 -0
- package/hermes/android/build-logic/build.gradle.kts +31 -0
- package/hermes/android/build-logic/settings.gradle.kts +17 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
- package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
- package/hermes/android/build.gradle.kts +332 -0
- package/hermes/android/cppruntime/build.gradle +72 -0
- package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
- package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
- package/hermes/android/cross-compile/swift-libicu.patch +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
- package/hermes/android/gradle/libs.versions.toml +30 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/hermes/android/gradle.properties +3 -0
- package/hermes/android/gradlew +248 -0
- package/hermes/android/gradlew.bat +93 -0
- package/hermes/android/intltest/build.gradle +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
- package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
- package/hermes/android/settings.gradle.kts +27 -0
- package/hermes/cmake/modules/Hermes.cmake +481 -0
- package/hermes/cmake/modules/Lit.cmake +96 -0
- package/hermes/doc/Branches.md +38 -0
- package/hermes/doc/BuildingAndRunning.md +121 -0
- package/hermes/doc/CodingStandards.md +112 -0
- package/hermes/doc/CrossCompilation.md +79 -0
- package/hermes/doc/Design.md +217 -0
- package/hermes/doc/Emscripten.md +156 -0
- package/hermes/doc/Features.md +143 -0
- package/hermes/doc/GCSafeCoding.md +563 -0
- package/hermes/doc/GenGC.md +300 -0
- package/hermes/doc/Hades.md +344 -0
- package/hermes/doc/HighLevelOptimizations.md +37 -0
- package/hermes/doc/IR.md +1306 -0
- package/hermes/doc/IntlAPIs.md +196 -0
- package/hermes/doc/JIT.md +999 -0
- package/hermes/doc/LazyEvalCompilation.md +84 -0
- package/hermes/doc/MemoryProfilers.md +316 -0
- package/hermes/doc/Modules.md +144 -0
- package/hermes/doc/Optimizer.md +83 -0
- package/hermes/doc/PerfProfiling.md +29 -0
- package/hermes/doc/ProhibitInvoke.md +329 -0
- package/hermes/doc/ReactNative.md +40 -0
- package/hermes/doc/ReactNativeIntegration.md +94 -0
- package/hermes/doc/RegExp.md +24 -0
- package/hermes/doc/SpecIncompat.md +85 -0
- package/hermes/doc/Strings.md +140 -0
- package/hermes/doc/TypedLanguage.md +432 -0
- package/hermes/doc/VM.md +174 -0
- package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
- package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
- package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
- package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
- package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
- package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
- package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
- package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
- package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
- package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
- package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
- package/hermes/doc/blog/README.md +25 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
- package/hermes/doc/icu_license.txt +420 -0
- package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
- package/hermes/doc/img/logo.svg +1 -0
- package/hermes/doc/img/object_captured_by_environment.png +0 -0
- package/hermes/doc/img/root_categories.png +0 -0
- package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
- package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
- package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
- package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
- package/hermes/doc/plans/ir-type/memory.md +48 -0
- package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
- package/hermes/doc/plans/ir-type/progress.md +239 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
- package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
- package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
- package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
- package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
- package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
- package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
- package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
- package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
- package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
- package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
- package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
- package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
- package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
- package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
- package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
- package/hermes/doc/typescript-stripping.md +90 -0
- package/hermes/external/CMakeLists.txt +20 -0
- package/hermes/utils/IntlGen/IntlGen.java +531 -0
- package/hermes/utils/bench_with_stats.py +827 -0
- package/hermes/utils/build-apple-framework.sh +323 -0
- package/hermes/utils/chrome_snapshot_parser.py +210 -0
- package/hermes/utils/cmake-dev-build.sh +18 -0
- package/hermes/utils/commons.sh +55 -0
- package/hermes/utils/dump-cpp-funcs.sh +3 -0
- package/hermes/utils/es5objects.js +198 -0
- package/hermes/utils/format.sh +145 -0
- package/hermes/utils/gen-promise-internal-bc.sh +66 -0
- package/hermes/utils/genUnicodeTable.py +2503 -0
- package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
- package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
- package/hermes/utils/jit/README.md +134 -0
- package/hermes/utils/jit/jit-diff.sh +160 -0
- package/hermes/utils/jit/jit-dump.sh +193 -0
- package/hermes/utils/lit-expect-gen/generate.py +217 -0
- package/hermes/utils/promise/index.js +15 -0
- package/hermes/utils/promise/package.json +13 -0
- package/hermes/utils/promise/rollup.config.js +19 -0
- package/hermes/utils/promise/yarn.lock +247 -0
- package/hermes/utils/scripts/hermes/consts.js +26 -0
- package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
- package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
- package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
- package/hermes/utils/scripts/hermes/package.json +6 -0
- package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
- package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
- package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
- package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
- package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
- package/hermes/utils/scripts/hermes/version-utils.js +98 -0
- package/hermes/utils/scripts/hermes/yarn.lock +240 -0
- package/hermes/utils/summarize_sizes.py +184 -0
- package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
- package/hermes/utils/test_runner.py +13 -0
- package/hermes/utils/testsuite/README.facebook +3 -0
- package/hermes/utils/testsuite/README.md +69 -0
- package/hermes/utils/testsuite/cli.py +547 -0
- package/hermes/utils/testsuite/es_ast.py +337 -0
- package/hermes/utils/testsuite/external/LICENSE +28 -0
- package/hermes/utils/testsuite/external/README.facebook +8 -0
- package/hermes/utils/testsuite/external/__init__.py +0 -0
- package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
- package/hermes/utils/testsuite/external/parse_test262.py +141 -0
- package/hermes/utils/testsuite/hermes.py +522 -0
- package/hermes/utils/testsuite/preprocess.py +365 -0
- package/hermes/utils/testsuite/progress.py +377 -0
- package/hermes/utils/testsuite/skiplist.json +4356 -0
- package/hermes/utils/testsuite/skiplist.py +270 -0
- package/hermes/utils/testsuite/test_run_defs.py +435 -0
- package/hermes/utils/testsuite/typing_defs.py +52 -0
- package/hermes/utils/testsuite/utils.py +214 -0
- package/hermes/utils/tidy.sh +22 -0
- package/hermes/utils/update-fbcode-hermes.sh +53 -0
- package/hermes/utils/updateErrorTest.py +193 -0
- package/hermes/utils/wasm-compile.sh +65 -0
- package/package.json +1 -1
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
# ICU-free `normalize` on Linux
|
|
2
|
+
|
|
3
|
+
Date: 2026-08-26
|
|
4
|
+
Status: approved, ready for implementation planning
|
|
5
|
+
|
|
6
|
+
## Context
|
|
7
|
+
|
|
8
|
+
On Linux, Hermes depends on ICU4C for exactly four functions, all in
|
|
9
|
+
`lib/Platform/Unicode/PlatformUnicodeICU.cpp`:
|
|
10
|
+
|
|
11
|
+
| Function | ICU symbols | JS surface |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `localeCompare` | `ucol_open`, `ucol_setAttribute`, `ucol_strcoll`, `uloc_getDefault` | `String.prototype.localeCompare` |
|
|
14
|
+
| `dateFormat` | `udat_open`, `udat_format`, `udat_close`, `uloc_getDefault` | `Date.prototype.toLocale{,Date,Time}String` |
|
|
15
|
+
| `convertToCase` | `u_strToUpper`, `u_strToLower`, `uloc_getDefault` | `String.prototype.to{Upper,Lower}Case` (non-ASCII only) and `toLocale{Upper,Lower}Case` (always) |
|
|
16
|
+
| `normalize` | `unorm2_get{NFC,NFD,NFKC,NFKD}Instance`, `unorm2_normalize` | `String.prototype.normalize` |
|
|
17
|
+
|
|
18
|
+
`BUCK:858` selects the ICU backend for Linux and `BUCK:1116-1117` pulls in the
|
|
19
|
+
checked-in ICU 77.1 from `//third-party/icu`. CMake hard-errors when no ICU is
|
|
20
|
+
found (`CMakeLists.txt:686`).
|
|
21
|
+
|
|
22
|
+
Intl is not a factor on Linux. `-DHERMES_ENABLE_INTL` is set only for Android
|
|
23
|
+
(`BUCK:964-966`), the internal build pins `intl_enabled = "0"` (`BUCK:1818`),
|
|
24
|
+
and CMake defaults `HERMES_ENABLE_INTL` to OFF (`CMakeLists.txt:288`), so
|
|
25
|
+
`PlatformIntlICU.cpp` and `lib/Platform/Intl/impl_icu/` never compile there.
|
|
26
|
+
|
|
27
|
+
Removing ICU drops a large dependency, removes the `shermes` shipping tax at
|
|
28
|
+
`BUCK:1320-1345` (which copies the entire ICU library directory next to
|
|
29
|
+
`shermes` output), and retires the license obligation tracked in
|
|
30
|
+
`doc/icu_license.txt`.
|
|
31
|
+
|
|
32
|
+
### Why not libc
|
|
33
|
+
|
|
34
|
+
`strcoll_l` and friends were considered as a replacement for the locale-aware
|
|
35
|
+
functions and rejected for `localeCompare` on correctness grounds: it is
|
|
36
|
+
NUL-terminated so embedded U+0000 truncates the comparison (ICU's
|
|
37
|
+
`ucol_strcoll` takes explicit lengths, `PlatformUnicodeICU.cpp:63-69`),
|
|
38
|
+
unpaired surrogates have no valid UTF-8 encoding, and glibc performs no
|
|
39
|
+
normalization preprocessing, silently dropping the `UCOL_NORMALIZATION_MODE`
|
|
40
|
+
behavior the current code deliberately opts into at
|
|
41
|
+
`PlatformUnicodeICU.cpp:50`. It is also non-deterministic across machines,
|
|
42
|
+
degrading to byte order on musl and in images without a locale archive.
|
|
43
|
+
`dateFormat` has no table-driven alternative and will use `strftime_l`, which
|
|
44
|
+
is addressed in its own spec.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
The ICU removal is decomposed into four sub-projects, each with its own spec,
|
|
49
|
+
plan, and diff stack:
|
|
50
|
+
|
|
51
|
+
1. **`normalize`** (this spec)
|
|
52
|
+
2. `convertToCase`
|
|
53
|
+
3. `localeCompare`, which reuses the normalization tables from (1) to preserve
|
|
54
|
+
the normalization-insensitive comparison ICU gives today
|
|
55
|
+
4. `dateFormat`
|
|
56
|
+
|
|
57
|
+
ICU stays linked until (4) lands; the dependency drop is a single change at the
|
|
58
|
+
end.
|
|
59
|
+
|
|
60
|
+
### Non-goals
|
|
61
|
+
|
|
62
|
+
- Changing the Android (Java) or Apple (CoreFoundation) backends. These have
|
|
63
|
+
real platform normalizers and do not compile the tables.
|
|
64
|
+
- Regenerating `lib/Platform/Unicode/UnicodeData.inc`.
|
|
65
|
+
- Implementing Intl.
|
|
66
|
+
- Any behavior change on a platform that already had a working `normalize`,
|
|
67
|
+
beyond the UCD version skew described below. Note that LITE and Emscripten
|
|
68
|
+
did **not** have one — both were no-ops — so for them this is a deliberate
|
|
69
|
+
and substantial behavior change, from returning the input untouched to
|
|
70
|
+
actually normalizing it.
|
|
71
|
+
|
|
72
|
+
### UCD version skew against ICU
|
|
73
|
+
|
|
74
|
+
The checked-in ICU 77.1 implements Unicode 16.0
|
|
75
|
+
(`third-party/icu/72.1/v77.1/common/unicode/uchar.h:64`), while
|
|
76
|
+
`genUnicodeTable.py` is pinned to UCD 17.0.0. Output is therefore *not*
|
|
77
|
+
byte-identical to ICU in every case.
|
|
78
|
+
|
|
79
|
+
The divergence is tightly bounded. Unicode's Normalization Stability Policy
|
|
80
|
+
guarantees that the decomposition of an already-encoded character never
|
|
81
|
+
changes and that no decomposition is ever added to an existing character, so
|
|
82
|
+
every code point assigned in 16.0 normalizes identically under both. The only
|
|
83
|
+
possible differences are code points newly assigned in 17.0 that carry a
|
|
84
|
+
decomposition mapping: ICU sees them as unassigned and passes them through,
|
|
85
|
+
whereas these tables decompose them correctly.
|
|
86
|
+
|
|
87
|
+
This is the correct direction to diverge, and the codebase already has this
|
|
88
|
+
skew — `UnicodeData.inc` has been generated at 17.0.0 against the same
|
|
89
|
+
Unicode 16.0 ICU since 2026-04-30. It does mean the conformance suite is the
|
|
90
|
+
authority for correctness, not a differential comparison against ICU.
|
|
91
|
+
|
|
92
|
+
## Increment model
|
|
93
|
+
|
|
94
|
+
The normalizer is a plain function, `hermes::unicode::normalizeUTF16`, with no
|
|
95
|
+
build mode of its own. Every backend for a platform that lacks a
|
|
96
|
+
higher-quality normalizer calls it. That is a wider set than Linux and Windows:
|
|
97
|
+
`PlatformUnicodeLite.cpp` and `PlatformUnicodeEmscripten.cpp` both had
|
|
98
|
+
`normalize` as an outright no-op, and LITE's documented purpose in BUCK and
|
|
99
|
+
CMake is to avoid depending on system libraries rather than to be small, so a
|
|
100
|
+
self-contained normalizer is exactly what it always wanted. Android and Apple
|
|
101
|
+
keep their platform normalizers and never compile it.
|
|
102
|
+
|
|
103
|
+
For Linux and Windows specifically, a new `HERMES_PLATFORM_UNICODE_HERMES`
|
|
104
|
+
backend becomes the default in the last diff of this sub-project. It calls the
|
|
105
|
+
shared normalizer and forwards the other three functions to the existing ICU
|
|
106
|
+
code. Each later sub-project replaces one forwarder; the final one deletes the
|
|
107
|
+
forwarding layer and the `//third-party/icu` dependencies.
|
|
108
|
+
|
|
109
|
+
This means every increment is covered by the existing test262 and lit runs the
|
|
110
|
+
moment it lands, with no parallel build configuration to maintain. The cost is
|
|
111
|
+
a transient `#include` of the ICU headers in the new backend for three diffs.
|
|
112
|
+
|
|
113
|
+
Once all four functions are native, `HERMES_PLATFORM_UNICODE_LITE` and
|
|
114
|
+
`HERMES_PLATFORM_UNICODE_HERMES` become the same thing and should be merged.
|
|
115
|
+
|
|
116
|
+
The shared function is named `normalizeUTF16` rather than `normalize` because
|
|
117
|
+
`NormalizationForm` lives in `hermes::unicode`, so argument-dependent lookup
|
|
118
|
+
finds that namespace from every unqualified `normalize(buf, form)` call and
|
|
119
|
+
collides with the identically-signatured `platform_unicode::normalize`.
|
|
120
|
+
|
|
121
|
+
## Approach
|
|
122
|
+
|
|
123
|
+
Sorted-range tables with binary search, reusing the `std::binary_search` and
|
|
124
|
+
`UnicodeRangeComp` idiom already established in `CharacterProperties.cpp:32`.
|
|
125
|
+
|
|
126
|
+
Rejected alternatives:
|
|
127
|
+
|
|
128
|
+
- **Two-stage trie (ICU `UTrie` shape).** O(1) lookups and likely smaller for
|
|
129
|
+
the dense CCC data, but introduces a data structure found nowhere else in the
|
|
130
|
+
codebase and complicates the generator, for a function that is not hot. If
|
|
131
|
+
`localeCompare` profiling later demands faster CCC lookups, a single table
|
|
132
|
+
can be upgraded in isolation without touching the algorithm.
|
|
133
|
+
- **Porting a third-party normalizer's tables (utf8proc-style).** Adds a
|
|
134
|
+
dependency in order to remove one, with its own licensing and UCD-version
|
|
135
|
+
story.
|
|
136
|
+
|
|
137
|
+
Two optimizations are included because they are nearly free:
|
|
138
|
+
|
|
139
|
+
- **Quick_Check fast path.** If every character is `QC=Yes` for the target form
|
|
140
|
+
and no canonical ordering violation is present, return the input untouched
|
|
141
|
+
with no allocation. This is the common case and yields an all-ASCII fast path
|
|
142
|
+
for free, since ASCII is uniformly `QC=Yes` and `CCC=0`.
|
|
143
|
+
- **Pre-expanded decompositions.** Recursive decomposition is resolved at
|
|
144
|
+
table-generation time, so the runtime never recurses.
|
|
145
|
+
|
|
146
|
+
The tables were estimated at 40-60 KB before they existed. The straightforward
|
|
147
|
+
encoding measured 147,920 bytes, roughly two and a half times that, with the
|
|
148
|
+
two decomposition tables and their pool accounting for 120 KB of it. Note that
|
|
149
|
+
the mitigation this spec originally proposed, a trie for the CCC and
|
|
150
|
+
Quick_Check tables, targeted the wrong tables: those are only 13 KB combined.
|
|
151
|
+
|
|
152
|
+
Three changes brought it to **86,336 bytes**, a 42% reduction:
|
|
153
|
+
|
|
154
|
+
- `DecompEntry` packed into 8 bytes rather than the natural 12, as
|
|
155
|
+
`uint32_t cp : 21; uint32_t length : 5; uint32_t wide : 1; uint32_t offset;`.
|
|
156
|
+
- `COMPAT_DECOMP` stores only the 3,849 mappings that differ from their
|
|
157
|
+
canonical counterpart, down from 5,914, with lookup falling back to
|
|
158
|
+
`CANON_DECOMP`.
|
|
159
|
+
- Sequences interned into a `char16_t` pool (6,542 values) or, when they
|
|
160
|
+
contain a supplementary-plane code point, a `char32_t` one (221 values).
|
|
161
|
+
|
|
162
|
+
86 KB is a rounding error against the roughly 30 MB of ICU it displaces on
|
|
163
|
+
Linux and Windows, and Android and Apple do not compile it at all.
|
|
164
|
+
|
|
165
|
+
## File structure
|
|
166
|
+
|
|
167
|
+
New files:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
include/hermes/Platform/Unicode/UnicodeNormalization.h
|
|
171
|
+
lib/Platform/Unicode/UnicodeNormalization.cpp
|
|
172
|
+
lib/Platform/Unicode/NormalizationData.inc generated, checked in
|
|
173
|
+
lib/Platform/Unicode/PlatformUnicodeHermes.cpp
|
|
174
|
+
lib/Platform/Unicode/PlatformUnicodeICUImpl.h temporary
|
|
175
|
+
unittests/PlatformUnicode/NormalizationConformanceTest.cpp
|
|
176
|
+
unittests/PlatformUnicode/NormalizationTestData.inc generated, checked in
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`UnicodeNormalization.cpp` includes `NormalizationData.inc` inside its
|
|
180
|
+
namespace, mirroring `CharacterProperties.cpp:20`.
|
|
181
|
+
|
|
182
|
+
### `NormalizationForm` placement
|
|
183
|
+
|
|
184
|
+
`NormalizationForm` currently lives in `PlatformUnicode.h`, the backend
|
|
185
|
+
*selection* header. Having the low-level normalizer include that header would
|
|
186
|
+
invert the layering, so the enum moves into `UnicodeNormalization.h` and
|
|
187
|
+
`platform_unicode` retains a `using NormalizationForm = unicode::NormalizationForm;`
|
|
188
|
+
alias. Every existing call site continues to compile unchanged.
|
|
189
|
+
|
|
190
|
+
**The enumerator order must not change.** `PlatformUnicodeJava.cpp` passes the
|
|
191
|
+
ordinal across JNI; this is the constraint the comment at `PlatformUnicode.h:64`
|
|
192
|
+
refers to, and `AndroidUnicodeUtils.java` depends on it.
|
|
193
|
+
|
|
194
|
+
### ICU delegation shim
|
|
195
|
+
|
|
196
|
+
Rather than add a source file, `PlatformUnicodeICU.cpp` keeps its four function
|
|
197
|
+
bodies but moves them into `namespace icu_impl`, guarded by
|
|
198
|
+
`#if HERMES_PLATFORM_UNICODE == HERMES_PLATFORM_UNICODE_ICU || HERMES_PLATFORM_UNICODE == HERMES_PLATFORM_UNICODE_HERMES`.
|
|
199
|
+
The public `platform_unicode` entry points remain in the same file behind
|
|
200
|
+
`#if HERMES_PLATFORM_UNICODE == HERMES_PLATFORM_UNICODE_ICU`.
|
|
201
|
+
`PlatformUnicodeICUImpl.h` declares the `icu_impl` functions so
|
|
202
|
+
`PlatformUnicodeHermes.cpp` can call them. Both are deleted by sub-project (4).
|
|
203
|
+
|
|
204
|
+
## Generator changes
|
|
205
|
+
|
|
206
|
+
`utils/genUnicodeTable.py` is extended rather than supplemented with a second
|
|
207
|
+
script, so the UCD version pin and the download cache stay in one place. That
|
|
208
|
+
is what makes it impossible for the tables and the conformance data to
|
|
209
|
+
reference different UCD versions.
|
|
210
|
+
|
|
211
|
+
- Add `NormalizationTest.txt` to `UnicodeDataFiles.URLS` at the existing pinned
|
|
212
|
+
`VERSION = "17.0.0"`. `UnicodeData.txt` and `DerivedNormalizationProps.txt`
|
|
213
|
+
are already fetched.
|
|
214
|
+
- Add `--table {properties,normalization,normtest}`, defaulting to `properties`
|
|
215
|
+
so the documented `genUnicodeTable.py | clang-format > UnicodeData.inc`
|
|
216
|
+
invocation is unchanged.
|
|
217
|
+
- Emit the same SHA1 and version provenance block that `UnicodeData.inc`
|
|
218
|
+
already carries into every generated file, so a partial UCD bump is visible
|
|
219
|
+
in review.
|
|
220
|
+
|
|
221
|
+
`UnicodeData.inc` is not regenerated. It was generated 2026-04-30 at UCD
|
|
222
|
+
17.0.0; regenerating it risks shifting RegExp property-escape ranges and
|
|
223
|
+
churning unrelated tests. The new tables are generated at that same pinned
|
|
224
|
+
version into separate files.
|
|
225
|
+
|
|
226
|
+
### Extracted data
|
|
227
|
+
|
|
228
|
+
From `UnicodeData.txt`:
|
|
229
|
+
|
|
230
|
+
- Canonical decompositions (field 5, no `<tag>`), recursively pre-expanded.
|
|
231
|
+
- Compatibility decompositions (field 5, with `<tag>`), recursively
|
|
232
|
+
pre-expanded, and including the canonical mappings so that NFKD is a superset
|
|
233
|
+
of NFD.
|
|
234
|
+
- Canonical combining class (field 3).
|
|
235
|
+
|
|
236
|
+
From `DerivedNormalizationProps.txt`:
|
|
237
|
+
|
|
238
|
+
- `Full_Composition_Exclusion`.
|
|
239
|
+
- `NFC_QC`, `NFD_QC`, `NFKC_QC`, `NFKD_QC`, each Yes, No, or Maybe.
|
|
240
|
+
|
|
241
|
+
The canonical composition table is the inverse of the canonical decomposition
|
|
242
|
+
mappings, minus full composition exclusions, singleton decompositions, and
|
|
243
|
+
non-starter decompositions (those whose first character has `CCC != 0`).
|
|
244
|
+
|
|
245
|
+
Hangul is handled arithmetically per UAX #15 and contributes no table entries.
|
|
246
|
+
|
|
247
|
+
### Runtime representation
|
|
248
|
+
|
|
249
|
+
- Decomposition mappings: `CANON_DECOMP` and `COMPAT_DECOMP`, each sorted by
|
|
250
|
+
code point, each entry packed into 8 bytes holding the code point, a length,
|
|
251
|
+
a `wide` bit selecting the pool, and an offset into it. `COMPAT_DECOMP` omits
|
|
252
|
+
any mapping equal to the canonical one, so a compatibility lookup that misses
|
|
253
|
+
falls back to `CANON_DECOMP`.
|
|
254
|
+
- Decomposition pools: `DECOMP_POOL16` (`char16_t`) and `DECOMP_POOL32`
|
|
255
|
+
(`char32_t`), with identical sequences interned across both tables.
|
|
256
|
+
- CCC and the four Quick_Check properties: sorted range arrays, `CCCRange` and
|
|
257
|
+
`NormRange`. These deliberately do not reuse `UnicodeRange`, which is
|
|
258
|
+
declared inside `UnicodeData.inc` and so is not visible outside
|
|
259
|
+
`CharacterProperties.cpp`; keeping the two generated files independent means
|
|
260
|
+
neither can break the other.
|
|
261
|
+
- Canonical composition: array sorted by `(starter, combining)` yielding the
|
|
262
|
+
composite.
|
|
263
|
+
|
|
264
|
+
## Algorithm
|
|
265
|
+
|
|
266
|
+
Standard UAX #15:
|
|
267
|
+
|
|
268
|
+
1. Quick-check the input against the target form's `*_QC` property and
|
|
269
|
+
canonical ordering. If it is already normalized, return with no allocation.
|
|
270
|
+
2. Decompose into a `SmallVector<char32_t>` scratch buffer, emitting each code
|
|
271
|
+
point's pre-expanded mapping for the form's decomposition type, or the code
|
|
272
|
+
point itself. Hangul syllables decompose arithmetically.
|
|
273
|
+
3. Canonically order: stable-sort each maximal run of `CCC != 0` by CCC.
|
|
274
|
+
4. For forms C and KC, apply the UAX #15 canonical composition algorithm.
|
|
275
|
+
Hangul composes arithmetically.
|
|
276
|
+
5. Re-encode to UTF-16 into the caller's buffer.
|
|
277
|
+
|
|
278
|
+
### Correctness requirements
|
|
279
|
+
|
|
280
|
+
These are the WTF-16 hazards that motivated rejecting the libc approach, and
|
|
281
|
+
they must hold here:
|
|
282
|
+
|
|
283
|
+
- **Unpaired surrogates pass through unchanged.** They have `CCC=0`, `QC=Yes`,
|
|
284
|
+
and no decomposition. The implementation must not crash, drop them, or
|
|
285
|
+
substitute U+FFFD.
|
|
286
|
+
- **Embedded NUL is a non-event.** The API operates on
|
|
287
|
+
`SmallVectorImpl<char16_t>` with an explicit length; no code path may treat
|
|
288
|
+
U+0000 as a terminator.
|
|
289
|
+
- **Supplementary-plane decompositions work.** Surrogate pairs are decoded to
|
|
290
|
+
code points before lookup and re-encoded afterwards, so characters such as
|
|
291
|
+
the musical symbols at U+1D15E decompose correctly rather than being skipped.
|
|
292
|
+
|
|
293
|
+
## Testing
|
|
294
|
+
|
|
295
|
+
- **Conformance suite.** `NormalizationConformanceTest.cpp` drives all 20,034
|
|
296
|
+
rows of `NormalizationTest.txt`, asserting the UAX #15 invariants across all
|
|
297
|
+
four forms, including the Part 1 invariant that code points not listed in the
|
|
298
|
+
file normalize to themselves. The rows are emitted as string literals in the
|
|
299
|
+
upstream format and parsed by the test rather than pre-expanded into arrays:
|
|
300
|
+
that is a third the source size, compiles far faster, stays greppable against
|
|
301
|
+
the upstream file, and lets a failure print the row verbatim.
|
|
302
|
+
- **A populated-data guard.** `TestDataIsPopulated` asserts the generated
|
|
303
|
+
tables are non-empty, so a generator bug cannot make every other assertion in
|
|
304
|
+
the file pass vacuously.
|
|
305
|
+
- **Targeted gtests** for each correctness requirement above, plus the empty
|
|
306
|
+
string, a string that grows under NFD, one that shrinks under NFC, Hangul
|
|
307
|
+
round-tripping, and the compatibility-to-canonical fallback.
|
|
308
|
+
- **test262** `String.prototype.normalize` through the existing runner. Because
|
|
309
|
+
the Hermes backend becomes the Linux default in the final diff of this
|
|
310
|
+
sub-project, this exercises the new code end to end.
|
|
311
|
+
|
|
312
|
+
A conformance suite that cannot fail is worthless, so the suite is checked
|
|
313
|
+
against a deliberately broken build: short-circuiting `composeInPlace` must
|
|
314
|
+
produce mismatches. It does, from row 0, failing three tests.
|
|
315
|
+
|
|
316
|
+
## Diff breakdown
|
|
317
|
+
|
|
318
|
+
1. Generator: `--table` flag and `NormalizationTest.txt` fetch; both generated
|
|
319
|
+
files checked in. No behavior change.
|
|
320
|
+
2. `UnicodeNormalization.{h,cpp}` and the conformance test, wired into the LITE
|
|
321
|
+
and Emscripten backends, whose `normalize` was a no-op. Linux and Windows
|
|
322
|
+
still use ICU at this point.
|
|
323
|
+
3. `PlatformUnicodeICU.cpp` refactored into `icu_impl` plus
|
|
324
|
+
`PlatformUnicodeICUImpl.h`. Pure refactor, no behavior change.
|
|
325
|
+
4. `PlatformUnicodeHermes.cpp` and the BUCK and CMake wiring. Linux and Windows
|
|
326
|
+
switch to the new backend; `normalize` is table-driven and the other three
|
|
327
|
+
functions forward to ICU. The full test262 run is the gate.
|
|
328
|
+
|
|
329
|
+
## Risks
|
|
330
|
+
|
|
331
|
+
- ~~**Table size exceeds the estimate.**~~ Realized and resolved: the tables
|
|
332
|
+
measured 147,920 bytes against a 40-60 KB estimate, and were compacted to
|
|
333
|
+
86,336 bytes. They are compiled only for the backends that call them, so
|
|
334
|
+
Android and Apple pay nothing. See the Approach section.
|
|
335
|
+
- **Quick_Check fast path is subtly wrong**, returning unnormalized strings
|
|
336
|
+
unchanged. Mitigation: the conformance suite runs every case through the full
|
|
337
|
+
path and the fast path; a `QC=Maybe` code point must never take the fast
|
|
338
|
+
path.
|
|
339
|
+
- **UCD version drift** between `UnicodeData.inc` and the new tables. Mitigation:
|
|
340
|
+
the shared version pin and the provenance block in every generated file.
|
|
341
|
+
- **A test262 case covers a code point newly assigned in UCD 17.0** and encodes
|
|
342
|
+
the Unicode 16.0 answer, producing a spurious failure against the ICU
|
|
343
|
+
baseline. Mitigation: expected to be unlikely, since the test262 normalize
|
|
344
|
+
tests are largely version-agnostic. If it occurs, the resolution is to keep
|
|
345
|
+
the 17.0 behavior and record the divergence, not to regress the tables.
|
|
346
|
+
|
|
347
|
+
## Success criteria
|
|
348
|
+
|
|
349
|
+
- The conformance suite passes for all four normalization forms.
|
|
350
|
+
- test262 `String.prototype.normalize` results are unchanged from the ICU
|
|
351
|
+
baseline, or any difference is traced to the documented UCD 17.0 versus
|
|
352
|
+
Unicode 16.0 skew and accepted.
|
|
353
|
+
- `check-hermes` and `//xplat/static_h:testsuite_tests` pass on Linux with the
|
|
354
|
+
Hermes backend as the default.
|
|
355
|
+
- `normalize` no longer calls any ICU symbol on Linux or Windows.
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# ICU-free `convertToCase`
|
|
2
|
+
|
|
3
|
+
Date: 2026-08-27
|
|
4
|
+
Status: approved, ready for implementation planning
|
|
5
|
+
|
|
6
|
+
Sub-project 2 of 4 in the ICU4C removal. See
|
|
7
|
+
`doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md` for the overall
|
|
8
|
+
decomposition and the shared conventions this follows.
|
|
9
|
+
|
|
10
|
+
## Context
|
|
11
|
+
|
|
12
|
+
`convertToCase` is one of the four functions Hermes still needs ICU for on
|
|
13
|
+
Linux and Windows. It backs `String.prototype.toUpperCase`,
|
|
14
|
+
`toLowerCase`, `toLocaleUpperCase` and `toLocaleLowerCase`.
|
|
15
|
+
|
|
16
|
+
`String.cpp:947` has an ASCII fast path that avoids the backend entirely, but
|
|
17
|
+
only when `useCurrentLocale` is false, so `toLocaleUpperCase("abc")` reaches
|
|
18
|
+
the backend today even though nothing about it needs a locale.
|
|
19
|
+
|
|
20
|
+
### Locale-sensitive casing is a deliberate cross-platform contract
|
|
21
|
+
|
|
22
|
+
Every backend that implements this function honors `useCurrentLocale`:
|
|
23
|
+
|
|
24
|
+
| Platform | Backend | Locale source |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| Android | Java via JNI | `Locale.getDefault()` |
|
|
27
|
+
| iOS, macOS | CoreFoundation | `CFLocaleCopyCurrent()`, overridable by `_HERMES_TEST_LOCALE` |
|
|
28
|
+
| Linux, Windows | ICU | `uloc_getDefault()` |
|
|
29
|
+
| Emscripten | none | no-op, `// FIXME: implement this` |
|
|
30
|
+
| LITE | none | no-op |
|
|
31
|
+
|
|
32
|
+
`AndroidUnicodeUtils.java` carries an explicit comment about Turkish dotless i,
|
|
33
|
+
so the behavior is intentional rather than incidental.
|
|
34
|
+
|
|
35
|
+
`test/hermes/string-locale.js` tests it directly, running the same script under
|
|
36
|
+
`LC_ALL=en_US`, `LC_ALL=tr_TR` and bare `LC_ALL=UTF-8` with a separate check
|
|
37
|
+
prefix for each, asserting `'aeiou'.toLocaleUpperCase()` is `AEİOU` under
|
|
38
|
+
Turkish. That test is live: mutating the Turkish expectation fails
|
|
39
|
+
`buck2 test //xplat/static_h:lit`.
|
|
40
|
+
|
|
41
|
+
This spec therefore **preserves** locale-sensitive casing. Dropping it was
|
|
42
|
+
considered and rejected: it would break a checked-in test and make Linux the
|
|
43
|
+
only platform that ignores the user's locale for casing.
|
|
44
|
+
|
|
45
|
+
### Measured behavior of the code being replaced
|
|
46
|
+
|
|
47
|
+
Established empirically against the current ICU build, not inferred:
|
|
48
|
+
|
|
49
|
+
- Turkish and Azeri: `upper("i")` is U+0130, `lower("I")` is U+0131.
|
|
50
|
+
- Lithuanian: `lower("Ì")` is `0069 0307 0300` (dot added),
|
|
51
|
+
`upper("i̇")` is `0049` (dot removed).
|
|
52
|
+
- Locale precedence is `LC_ALL`, then `LC_MESSAGES`, then `LANG`. **`LC_CTYPE`
|
|
53
|
+
is ignored**, despite POSIX convention; `LC_CTYPE=en_US` with `LANG=tr_TR`
|
|
54
|
+
still yields Turkish casing.
|
|
55
|
+
- No system locale data is required. `tr_TR` is not installed on the
|
|
56
|
+
development host, yet Turkish casing works, because ICU parses the
|
|
57
|
+
environment string against its own bundled data.
|
|
58
|
+
- Accepted formats include `tr`, `tr_TR`, `tr_TR.UTF-8` and `tr-TR`.
|
|
59
|
+
- The locale *argument* is ignored: `"i".toLocaleUpperCase("en")` returns
|
|
60
|
+
U+0130 under `LANG=tr_TR`. This is correct for a non-ECMA-402
|
|
61
|
+
implementation, which ECMA-262 directs to the host environment's current
|
|
62
|
+
locale.
|
|
63
|
+
|
|
64
|
+
## Scope
|
|
65
|
+
|
|
66
|
+
Replace `convertToCase` with a self-contained implementation on every platform
|
|
67
|
+
that lacks a better one: Linux, Windows, Emscripten and LITE. Android and Apple
|
|
68
|
+
keep their platform backends.
|
|
69
|
+
|
|
70
|
+
### Non-goals
|
|
71
|
+
|
|
72
|
+
- Changing the Android or Apple backends.
|
|
73
|
+
- Implementing Intl, or honoring the locale argument. When
|
|
74
|
+
`HERMES_ENABLE_INTL` is on, `intlStringPrototypeToLocaleUpperCase` already
|
|
75
|
+
takes over and does this properly from the argument.
|
|
76
|
+
- Regenerating `UnicodeData.inc`.
|
|
77
|
+
- Removing the ICU dependency, which happens in sub-project 4.
|
|
78
|
+
|
|
79
|
+
### Deliberate behavior changes
|
|
80
|
+
|
|
81
|
+
- **LITE and Emscripten gain working case conversion.** Both return their input
|
|
82
|
+
unchanged today, so this is a substantial improvement rather than a
|
|
83
|
+
regression.
|
|
84
|
+
- **`_HERMES_TEST_LOCALE` starts working on Linux and Windows.** It is
|
|
85
|
+
currently honored only by `PlatformUnicodeCF.cpp:26`. Supporting it uniformly
|
|
86
|
+
lets the lit tests drive the locale directly instead of depending on
|
|
87
|
+
`LC_ALL` resolving, which matters because `date-locale.js` is already skipped
|
|
88
|
+
under ubsan.
|
|
89
|
+
- **`toLocaleUpperCase` on ASCII stops allocating** when the host locale does
|
|
90
|
+
not affect casing, which is the common case.
|
|
91
|
+
|
|
92
|
+
## Approach
|
|
93
|
+
|
|
94
|
+
Delta-range blocks for the simple mappings plus a side table for the full
|
|
95
|
+
ones, reusing the `UnicodeTransformRange` encoding that `UNICODE_FOLDS`
|
|
96
|
+
already uses and the `DeltaMapBlock` machinery already in
|
|
97
|
+
`utils/genUnicodeTable.py`.
|
|
98
|
+
|
|
99
|
+
Rejected alternatives:
|
|
100
|
+
|
|
101
|
+
- **Flat sorted `cp -> mapping` arrays.** Roughly 24 KB instead of 8 KB, for a
|
|
102
|
+
simpler generator, while abandoning an encoding the codebase already applies
|
|
103
|
+
to this exact shape of data.
|
|
104
|
+
- **Two-stage trie.** Same reasoning as the normalizer: a data structure found
|
|
105
|
+
nowhere else here, for a function that is not hot.
|
|
106
|
+
|
|
107
|
+
### Measured table sizes
|
|
108
|
+
|
|
109
|
+
| Table | Encoding | Size |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| `toUpper` simple mappings | ~130 delta blocks | 1.0 KB |
|
|
112
|
+
| `toLower` simple mappings | ~130 delta blocks | 1.0 KB |
|
|
113
|
+
| Full mappings (102 upper, 1 lower) | 103 entries plus `char16_t` pool | 1.3 KB |
|
|
114
|
+
| `Cased` | 158 ranges | 1.2 KB |
|
|
115
|
+
| `Case_Ignorable` | 464 ranges | 3.6 KB |
|
|
116
|
+
| `Soft_Dotted` | 34 ranges | 0.3 KB |
|
|
117
|
+
| Canonical combining class | reused from the normalizer | 0 |
|
|
118
|
+
| **Total** | | **~8.4 KB** |
|
|
119
|
+
|
|
120
|
+
1,505 simple uppercase mappings compress to roughly 130 blocks, the same ratio
|
|
121
|
+
`UNICODE_FOLDS` achieves. These are projections from measured input counts and
|
|
122
|
+
the existing encoding's behavior; the figure is to be confirmed once the tables
|
|
123
|
+
exist, as it was for the normalizer.
|
|
124
|
+
|
|
125
|
+
## Architecture
|
|
126
|
+
|
|
127
|
+
### Shared layer
|
|
128
|
+
|
|
129
|
+
`include/hermes/Platform/Unicode/UnicodeCaseConversion.h`:
|
|
130
|
+
|
|
131
|
+
```cpp
|
|
132
|
+
namespace hermes {
|
|
133
|
+
namespace unicode {
|
|
134
|
+
|
|
135
|
+
/// Options for case conversion.
|
|
136
|
+
enum class CaseConversion { ToUpper, ToLower };
|
|
137
|
+
|
|
138
|
+
/// The language-specific casing rules to apply. Azerbaijani shares Turkish's
|
|
139
|
+
/// rules, so it has no separate enumerator.
|
|
140
|
+
enum class CaseLocale { Root, Turkish, Lithuanian };
|
|
141
|
+
|
|
142
|
+
/// Convert \p buf to \p targetCase in place, applying the full Unicode case
|
|
143
|
+
/// mappings from SpecialCasing.txt and the conditional rules for \p locale.
|
|
144
|
+
void convertCaseUTF16(
|
|
145
|
+
llvh::SmallVectorImpl<char16_t> &buf,
|
|
146
|
+
CaseConversion targetCase,
|
|
147
|
+
CaseLocale locale);
|
|
148
|
+
|
|
149
|
+
} // namespace unicode
|
|
150
|
+
} // namespace hermes
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`platform_unicode` keeps a `using CaseConversion = unicode::CaseConversion;`
|
|
154
|
+
alias so existing call sites are unchanged, mirroring what `NormalizationForm`
|
|
155
|
+
already does.
|
|
156
|
+
|
|
157
|
+
The function is named `convertCaseUTF16` rather than `convertToCase` for the
|
|
158
|
+
same reason `normalizeUTF16` is not `normalize`: with `CaseConversion` living
|
|
159
|
+
in `hermes::unicode`, argument-dependent lookup finds that namespace from every
|
|
160
|
+
unqualified call and would collide with the identically-signatured
|
|
161
|
+
`platform_unicode::convertToCase`.
|
|
162
|
+
|
|
163
|
+
### Locale detection belongs to the backend
|
|
164
|
+
|
|
165
|
+
`convertCaseUTF16` takes an explicit `CaseLocale` and is pure. Deciding what
|
|
166
|
+
the host locale is stays in the backend, which is where the other platforms
|
|
167
|
+
already put it:
|
|
168
|
+
|
|
169
|
+
- `PlatformUnicodeHermes.cpp` reads the environment.
|
|
170
|
+
- `PlatformUnicodeLite.cpp` passes `Root` unconditionally, preserving its
|
|
171
|
+
contract of not depending on system state.
|
|
172
|
+
- `PlatformUnicodeEmscripten.cpp` passes `Root`.
|
|
173
|
+
|
|
174
|
+
Detection replicates ICU's observed behavior exactly: `_HERMES_TEST_LOCALE`,
|
|
175
|
+
then `LC_ALL`, then `LC_MESSAGES`, then `LANG`; first non-empty wins. It
|
|
176
|
+
deliberately does **not** consult `LC_CTYPE`, even though POSIX convention
|
|
177
|
+
would suggest it for a character-handling category, because diverging from ICU
|
|
178
|
+
here would be a silent behavior change for anyone who sets it. The language
|
|
179
|
+
subtag is the text before the first `_`, `-`, `.` or `@`; `tr` and `az` map to
|
|
180
|
+
`Turkish`, `lt` to `Lithuanian`, everything else to `Root`.
|
|
181
|
+
|
|
182
|
+
The result is computed once and cached, since it cannot change within a
|
|
183
|
+
process.
|
|
184
|
+
|
|
185
|
+
### Conditional rules
|
|
186
|
+
|
|
187
|
+
From `SpecialCasing.txt`, 16 conditional entries:
|
|
188
|
+
|
|
189
|
+
- **`Final_Sigma`** (1 entry, locale-independent, always applied). Lowercasing
|
|
190
|
+
U+03A3 yields U+03C2 when preceded by a `Cased` character, ignoring any
|
|
191
|
+
`Case_Ignorable` characters between, and not followed by one. Required
|
|
192
|
+
regardless of the locale decision, and already covered by
|
|
193
|
+
`PlatformUnicodeTest.cpp:29` and test262.
|
|
194
|
+
- **Turkish and Azeri** (7 entries): `After_I` and `Not_Before_Dot`, plus the
|
|
195
|
+
unconditional dotted and dotless i mappings.
|
|
196
|
+
- **Lithuanian** (8 entries): `More_Above`, `After_Soft_Dotted`, and the rules
|
|
197
|
+
adding or removing U+0307.
|
|
198
|
+
|
|
199
|
+
`More_Above` and `After_Soft_Dotted` need the canonical combining class, which
|
|
200
|
+
the normalizer already ships. `UnicodeNormalization.h` gains a
|
|
201
|
+
`getCanonicalCombiningClass(uint32_t)` accessor rather than duplicating the
|
|
202
|
+
table.
|
|
203
|
+
|
|
204
|
+
### ASCII fast path
|
|
205
|
+
|
|
206
|
+
`platform_unicode` gains:
|
|
207
|
+
|
|
208
|
+
```cpp
|
|
209
|
+
/// \return true if the host locale changes case conversion results, i.e. it
|
|
210
|
+
/// is Turkish, Azerbaijani or Lithuanian. Cached.
|
|
211
|
+
bool localeAffectsCasing();
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`String.cpp:947` then guards the ASCII fast path with
|
|
215
|
+
`!useCurrentLocale || !localeAffectsCasing()` instead of `!useCurrentLocale`,
|
|
216
|
+
so `toLocaleUpperCase` on ASCII avoids the copy for everyone outside those
|
|
217
|
+
three languages. Android and Apple implement it against their own locale APIs.
|
|
218
|
+
|
|
219
|
+
## Generator changes
|
|
220
|
+
|
|
221
|
+
`utils/genUnicodeTable.py` gains `--table casing`, emitting
|
|
222
|
+
`lib/Platform/Unicode/CaseData.inc`:
|
|
223
|
+
|
|
224
|
+
- `TO_UPPER_DELTAS[]`, `TO_LOWER_DELTAS[]` as `UnicodeTransformRange`, built
|
|
225
|
+
with the existing `DeltaMapBlock`.
|
|
226
|
+
- `FULL_UPPER[]`, `FULL_LOWER[]` mapping a code point to an offset and length
|
|
227
|
+
in a shared `char16_t` pool, for the unconditional multi-character mappings.
|
|
228
|
+
- `CASED_RANGES[]`, `CASE_IGNORABLE_RANGES[]`, `SOFT_DOTTED_RANGES[]`.
|
|
229
|
+
|
|
230
|
+
The existing `CaseMap` class is **not** reused. It is built for RegExp
|
|
231
|
+
canonicalization and deliberately discards exactly what is needed here: it
|
|
232
|
+
skips any mapping producing more than one character, and ignores every
|
|
233
|
+
conditional `SpecialCasing.txt` entry.
|
|
234
|
+
|
|
235
|
+
`DerivedCoreProperties.txt` and `PropList.txt` are already fetched.
|
|
236
|
+
`CASING_FILES` joins the existing per-table file lists so the provenance header
|
|
237
|
+
records only what this table derives from.
|
|
238
|
+
|
|
239
|
+
## Testing
|
|
240
|
+
|
|
241
|
+
There is no single UCD conformance file for casing, so coverage comes from
|
|
242
|
+
several directions:
|
|
243
|
+
|
|
244
|
+
- **Generated exhaustive mapping check.** For every code point with a
|
|
245
|
+
non-identity simple mapping, assert the compressed delta-block lookup agrees
|
|
246
|
+
with an expectation derived independently from `UnicodeData.txt`. The delta
|
|
247
|
+
encoding is where bugs hide, and this is the only test that isolates it.
|
|
248
|
+
- **Targeted gtests per conditional rule**, covering each of `Final_Sigma`,
|
|
249
|
+
`After_I`, `Not_Before_Dot`, `More_Above` and `After_Soft_Dotted`, in both
|
|
250
|
+
the matching and non-matching direction.
|
|
251
|
+
- **A populated-data guard**, as the normalizer has, so empty tables cannot
|
|
252
|
+
make the rest pass vacuously.
|
|
253
|
+
- **Existing coverage already in the suites**: test262's `special_casing.js`,
|
|
254
|
+
`special_casing_conditional.js`, `Final_Sigma_U180E.js` and
|
|
255
|
+
`supplementary_plane.js`; and the lit test `string-locale.js`, which
|
|
256
|
+
exercises Turkish through `LC_ALL`.
|
|
257
|
+
- **Mutation check.** As with the normalizer, the suite must be shown to fail
|
|
258
|
+
when the implementation is broken, rather than assumed to.
|
|
259
|
+
|
|
260
|
+
`buck2 test //xplat/static_h:lit` is part of the gate for this sub-project. It
|
|
261
|
+
was not run during the normalizer work, which was a gap; `string-locale.js` is
|
|
262
|
+
the test most likely to catch a regression here.
|
|
263
|
+
|
|
264
|
+
## Diff breakdown
|
|
265
|
+
|
|
266
|
+
1. Generator: `--table casing`, emitting `CaseData.inc`. Generated file checked
|
|
267
|
+
in. No behavior change.
|
|
268
|
+
2. `UnicodeCaseConversion.{h,cpp}` and its tests, wired into the LITE and
|
|
269
|
+
Emscripten backends whose `convertToCase` is a no-op today. Adds
|
|
270
|
+
`getCanonicalCombiningClass` to the normalizer's header.
|
|
271
|
+
3. Locale detection and `localeAffectsCasing` in `PlatformUnicodeHermes.cpp`,
|
|
272
|
+
switching Linux and Windows off `icu_impl::convertToCase`. The `lit` and
|
|
273
|
+
`testsuite_tests` runs are the gate.
|
|
274
|
+
4. The `String.cpp` ASCII fast-path guard, with the Android and Apple
|
|
275
|
+
implementations of `localeAffectsCasing`.
|
|
276
|
+
|
|
277
|
+
## Risks
|
|
278
|
+
|
|
279
|
+
- **Locale detection diverges from ICU** in a case not covered by the
|
|
280
|
+
measurements, silently changing behavior. Mitigation: the precedence and
|
|
281
|
+
format handling above are measured, not assumed; `string-locale.js` covers
|
|
282
|
+
the main path, and diff 3 should re-run the measurement matrix against the
|
|
283
|
+
new implementation.
|
|
284
|
+
- **A conditional rule is subtly wrong**, which unit tests might miss because
|
|
285
|
+
the rules are context-sensitive. Mitigation: per-rule tests in both
|
|
286
|
+
directions, plus test262's conditional coverage and the mutation check.
|
|
287
|
+
- **Table size exceeds the projection.** Lower risk than the normalizer, since
|
|
288
|
+
the encoding is already in use on comparable data, but the figure is a
|
|
289
|
+
projection and will be measured.
|
|
290
|
+
- **`String.cpp` fast-path change alters behavior** for a locale that affects
|
|
291
|
+
casing beyond ASCII. Mitigation: `localeAffectsCasing` returns true for all
|
|
292
|
+
three special languages, so the fast path is only taken when the locale is
|
|
293
|
+
`Root`, where ASCII casing is unambiguous.
|
|
294
|
+
|
|
295
|
+
## Success criteria
|
|
296
|
+
|
|
297
|
+
- The exhaustive mapping check and per-rule tests pass.
|
|
298
|
+
- `buck2 test //xplat/static_h:HermesUnitTests`, `:lit` and `:testsuite_tests`
|
|
299
|
+
all pass.
|
|
300
|
+
- The measured locale matrix behaves identically to the ICU build: Turkish and
|
|
301
|
+
Azeri dotted and dotless i, the Lithuanian dot rules, and the documented
|
|
302
|
+
environment variable precedence.
|
|
303
|
+
- `convertToCase` calls no ICU symbol on Linux or Windows.
|
|
304
|
+
- LITE and Emscripten perform real case conversion.
|
|
305
|
+
- Table size is measured and recorded.
|