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
package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
# RegExp start-position filter and builtin-exec fast paths
|
|
2
|
+
|
|
3
|
+
Status: design. Branch `regexp-speedup`, on top of the regexp bytecode
|
|
4
|
+
sharing work (`ea916884b`) and `static_h` `f837b9dd8`.
|
|
5
|
+
|
|
6
|
+
Two independent changes, one commit each:
|
|
7
|
+
|
|
8
|
+
- **Part A**, a start-position filter in the regex engine.
|
|
9
|
+
- **Part B**, fast paths in the RegExp library glue for a regexp whose
|
|
10
|
+
`exec` is the builtin.
|
|
11
|
+
|
|
12
|
+
## Problem
|
|
13
|
+
|
|
14
|
+
Measured on a release build (`-g -fno-omit-frame-pointer`, x86-64) at
|
|
15
|
+
`de0922711`, best of three:
|
|
16
|
+
|
|
17
|
+
| Benchmark | Result |
|
|
18
|
+
|---|---|
|
|
19
|
+
| Octane RegExp | 956 (score) |
|
|
20
|
+
| `micros/stringMatch.js` | 1195 ms |
|
|
21
|
+
| `micros/stringSearch.js` | 1186 ms |
|
|
22
|
+
| `micros/regExpSearch.js` | 700 ms |
|
|
23
|
+
| `micros/regExpMatch.js` | 495 ms |
|
|
24
|
+
| `micros/regExpSplit.js` | 436 ms |
|
|
25
|
+
| `micros/regExpReplace.js` | 293 ms |
|
|
26
|
+
|
|
27
|
+
**The matcher tries every start position.** `Context::match`
|
|
28
|
+
(`lib/Regex/Executor.cpp:1063`) loops over `locsToCheckCount` positions
|
|
29
|
+
(`:1087`, `:1115-1120`) and runs the whole instruction loop at each.
|
|
30
|
+
Nothing skips a position whose first code unit cannot begin a match.
|
|
31
|
+
Temporary counters in that loop, over one Octane RegExp run, gave:
|
|
32
|
+
|
|
33
|
+
- 5.9M searches tried 282M start positions.
|
|
34
|
+
- 278M of those failed. 200.6M failed after one dispatched instruction,
|
|
35
|
+
and 218.2M after at most two.
|
|
36
|
+
- Failed positions account for 534M of 560M dispatched instructions
|
|
37
|
+
(95%).
|
|
38
|
+
|
|
39
|
+
`perf` puts `Context::match`, `backtrack`, `matchWidth1Loop` and
|
|
40
|
+
`bracketMatchesChar` at about 58% of Octane RegExp, and at 85-90% of
|
|
41
|
+
`stringMatch` and `regExpSearch`.
|
|
42
|
+
|
|
43
|
+
**The glue builds arrays nobody sees.** In `regExpMatch`, the top
|
|
44
|
+
symbols are `directRegExpExec`, `getNamedDescriptorUnsafe`,
|
|
45
|
+
`createNoAllocPropStorage`, `_setOwnIndexedImpl`, `slice`,
|
|
46
|
+
`SmallVector` copies and `executeCall1`. A global `@@match` runs
|
|
47
|
+
`regExpExec` per match (`lib/VM/JSLib/RegExp.cpp:1858`): an uncached
|
|
48
|
+
`Get(rx, "exec")` (`:1158`), a JS-level call to the native exec
|
|
49
|
+
(`:1171`), and a full result array with `index`, `input` and `groups`
|
|
50
|
+
(`directRegExpExec`, `:1013-1105`), of which it reads only element 0
|
|
51
|
+
(`:1873`). `@@replace` keeps every result array until phase 2 and then
|
|
52
|
+
reads them back through generic `Get`s (`:2083-2264`).
|
|
53
|
+
|
|
54
|
+
## Goals
|
|
55
|
+
|
|
56
|
+
- **A.** Skip start positions that cannot begin a match, computed once
|
|
57
|
+
at regex compile time.
|
|
58
|
+
- **B.** When `exec` is the builtin, run the builtin exec's effects
|
|
59
|
+
without a JS call or a result array the caller would only read back.
|
|
60
|
+
- Neither changes any observable behavior, including the existing
|
|
61
|
+
deviations listed under Non-goals, with one stated exception: a regex
|
|
62
|
+
resource limit (A.5).
|
|
63
|
+
|
|
64
|
+
## Non-goals
|
|
65
|
+
|
|
66
|
+
- Fixing existing spec deviations: `test` never looks up `exec`
|
|
67
|
+
(`RegExp.cpp:1239-1247`); `@@search` always sets and restores
|
|
68
|
+
`lastIndex` (`:1953`, `:1966`); `@@match` and `@@replace` read
|
|
69
|
+
`global`/`unicode` rather than `flags`; `@@split` and `@@matchAll`
|
|
70
|
+
have no `SpeciesConstructor`. Each stays as it is.
|
|
71
|
+
- `@@split` (`:2380-2665`). It already calls `JSRegExp::search` on a
|
|
72
|
+
private splitter without `exec`; it only gets the cheaper search of
|
|
73
|
+
B.4.
|
|
74
|
+
- Literal prefixes longer than one character, and Boyer-Moore.
|
|
75
|
+
- Regenerating the sandbox. Its generated C already carries bytecode
|
|
76
|
+
version 99 against the tree's 100, so `verify_generated.py` fails today
|
|
77
|
+
("the bytecode version check uses BYTECODE_VERSION 100", twice); the
|
|
78
|
+
last bump, `defe64b07`, also changed only the version line. A
|
|
79
|
+
regeneration is a separate task.
|
|
80
|
+
- A regex JIT.
|
|
81
|
+
|
|
82
|
+
## Part A: start-position filter
|
|
83
|
+
|
|
84
|
+
### The start set
|
|
85
|
+
|
|
86
|
+
A **start set** describes which code units can be the first unit of a
|
|
87
|
+
match:
|
|
88
|
+
|
|
89
|
+
- `ascii[16]`: a 128-bit bitmap. Bit `u` is set if a match can begin
|
|
90
|
+
with code unit `u`.
|
|
91
|
+
- `nonASCII`: true if a match can begin with a unit >= 0x80.
|
|
92
|
+
|
|
93
|
+
The set may be a superset of the truth, never a subset. A regex has
|
|
94
|
+
**no filter** when it can match the empty string, or when the analysis
|
|
95
|
+
cannot bound its first unit. Every non-ASCII unit is treated alike; this
|
|
96
|
+
keeps the `/u` invariant that the matcher never starts inside a
|
|
97
|
+
surrogate pair except at the first position (A.4).
|
|
98
|
+
|
|
99
|
+
### Computing it
|
|
100
|
+
|
|
101
|
+
The set is computed in `Regex::parseWithBackRefLimit`, after
|
|
102
|
+
`optimizeNodeList` and next to `matchConstraints_`
|
|
103
|
+
(`include/hermes/Regex/Regex.h:357-370`), and stored in a new member.
|
|
104
|
+
`compile()` (`Regex.h:142-158`) writes it into the header.
|
|
105
|
+
|
|
106
|
+
Node fields are private and there is no RTTI or node-kind enum
|
|
107
|
+
(`include/hermes/Regex/RegexNode.h:47-148`), so the analysis is a new
|
|
108
|
+
virtual method on `Node`:
|
|
109
|
+
|
|
110
|
+
```cpp
|
|
111
|
+
/// Add to \p set every code unit that can begin a match of this node.
|
|
112
|
+
/// \return true if the node can match without consuming input, so the
|
|
113
|
+
/// caller must also add the start set of what follows.
|
|
114
|
+
/// \p depth bounds the recursion; at kMaxStartSetDepth the caller gives
|
|
115
|
+
/// up (no filter).
|
|
116
|
+
virtual StartSetResult addStartSet(StartSet &set, unsigned depth) const;
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`StartSetResult` is `{Consumes, Nullable, Unknown}`. A list is walked
|
|
120
|
+
in order: each node's set is added, and the walk stops at the first
|
|
121
|
+
node that returns `Consumes`. A list whose every node is `Nullable` is
|
|
122
|
+
`Nullable`. `Unknown` anywhere makes the whole result `Unknown`.
|
|
123
|
+
|
|
124
|
+
Rules per node, with the bytecode each emits:
|
|
125
|
+
|
|
126
|
+
| Node | Result |
|
|
127
|
+
|---|---|
|
|
128
|
+
| base `Node` (the leading no-op, `Regex.h:349`) | `Nullable`, adds nothing |
|
|
129
|
+
| `GoalNode` | `Nullable`. Reaching it at top level means the regex can match empty: no filter |
|
|
130
|
+
| `LeftAnchorNode`, `RightAnchorNode`, `WordBoundaryNode` | `Nullable`, adds nothing (zero-width) |
|
|
131
|
+
| `LookaroundNode`, every kind | `Nullable`, adds nothing, does not descend. A lookbehind body is reversed and reads text to the left (`Regex.h:478-491`) |
|
|
132
|
+
| `BackRefNode` | `Unknown`. It can repeat text captured inside a lookahead, e.g. `/(?=(a))\1/` |
|
|
133
|
+
| `MarkedSubexpressionNode` | the result of its contents |
|
|
134
|
+
| `AlternationNode` | the union over the alternatives; `Nullable` if any is; `Unknown` if any is. An alternative may be empty (`/a\|/`) |
|
|
135
|
+
| `LoopNode` | its loopee's set; `Nullable` if `min_ == 0` or the loopee is nullable. `{0}` adds the loopee's set anyway (a superset is safe) |
|
|
136
|
+
| `MatchAnyNode` | `Consumes`. dotAll: all of `ascii`, `nonASCII`. Otherwise all ASCII except 0x0A and 0x0D, plus `nonASCII` (U+2028/2029 are the other line terminators, `Executor.cpp:573-576`) |
|
|
137
|
+
| `MatchCharNode` | `Consumes`; see below |
|
|
138
|
+
| `BracketNode` | `Consumes`; see below |
|
|
139
|
+
|
|
140
|
+
Depth: there is no nesting limit, and `test/hermes/regexp.js:94` nests
|
|
141
|
+
50000 groups. Each descent into a child list adds one to `depth`; at
|
|
142
|
+
`kMaxStartSetDepth = 64` the result is `Unknown`. The parser and
|
|
143
|
+
`Node::compile` are iterative for the same reason
|
|
144
|
+
(`RegexParser.cpp:172-173`, `RegexNode.h:64-74`).
|
|
145
|
+
|
|
146
|
+
**`MatchCharNode`.** The first unit is `chars_[0]`, or its high
|
|
147
|
+
surrogate when it is astral under `/u`. A lone surrogate under `/u`
|
|
148
|
+
emits `U16MatchChar32` (`RegexNode.h:662-674`) and is non-ASCII.
|
|
149
|
+
|
|
150
|
+
- Case-sensitive: add that unit.
|
|
151
|
+
- `icase_` (node-local; modifier groups change it, `Regex.h:49-54`):
|
|
152
|
+
`chars_[0]` is already canonical (`Regex.h:406-411`). Add every ASCII
|
|
153
|
+
unit `u` with `canonicalize(u, unicode) == chars_[0]`, the executor's
|
|
154
|
+
own test (`Executor.cpp:892-904`). If `chars_[0]` is non-ASCII, set
|
|
155
|
+
`nonASCII`. If the regex is `/u`, set `nonASCII` too: under `/iu`,
|
|
156
|
+
U+017F and U+212A fold to `s` and `k` (the only two non-ASCII-to-ASCII
|
|
157
|
+
folds in `UNICODE_FOLDS`; `LEGACY_CANONS` has none). Setting it for
|
|
158
|
+
every `/iu` char is a deliberate superset.
|
|
159
|
+
|
|
160
|
+
**`BracketNode`.** For each ASCII unit `u`, the bit is the executor's
|
|
161
|
+
answer for `u`: `bracketMatchesChar` (`Executor.cpp:722-757`) on the
|
|
162
|
+
emitted ranges, which under `icase` are closed with
|
|
163
|
+
`makeCanonicallyEquivalent` at emit time (`RegexNode.h:829-831`). The
|
|
164
|
+
closure moves into a `BracketNode` helper that `emitStep` and
|
|
165
|
+
`addStartSet` both call, so the two cannot diverge. Character classes
|
|
166
|
+
use the same `characterHasType`, with the input canonicalized first
|
|
167
|
+
under `/iu` (`Executor.cpp:738-740`). `nonASCII` is set if the bracket
|
|
168
|
+
is negated, if any emitted range reaches 0x80 or above, or if it has any
|
|
169
|
+
class other than a positive `\d` (a negative class such as `\D` or
|
|
170
|
+
`\W` sets it). Classes and negation are thus a superset on the
|
|
171
|
+
non-ASCII side and exact on the ASCII side.
|
|
172
|
+
|
|
173
|
+
### Storing it
|
|
174
|
+
|
|
175
|
+
The header is a packed 6-byte struct (`RegexBytecodeHeader`,
|
|
176
|
+
`include/hermes/Regex/RegexBytecode.h:285-297`). It grows by 18 bytes:
|
|
177
|
+
|
|
178
|
+
```cpp
|
|
179
|
+
/// Start filter flags: StartFilterPresent, StartFilterNonASCII,
|
|
180
|
+
/// StartFilterSingleChar.
|
|
181
|
+
uint8_t startFlags;
|
|
182
|
+
/// The only start unit when StartFilterSingleChar is set.
|
|
183
|
+
uint8_t startChar;
|
|
184
|
+
/// Bit u (u < 128) set if a match can begin with code unit u.
|
|
185
|
+
uint8_t startASCII[16];
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`StartFilterSingleChar` is set when exactly one ASCII bit is set;
|
|
189
|
+
`startChar` is that unit. `nonASCII` may be set as well.
|
|
190
|
+
|
|
191
|
+
Instruction offsets exclude the header (`RegexBytecode.h:373-377`;
|
|
192
|
+
`Executor.cpp:1073`), so no jump target and no dumped offset moves.
|
|
193
|
+
HBC and SH store the bytes as opaque blobs (`BytecodeStream.cpp:430-438`;
|
|
194
|
+
`SH.cpp:192-203`). The bytes format changes, so `BYTECODE_VERSION`
|
|
195
|
+
goes from 100 to 101 (`include/hermes/BCGen/HBC/BytecodeVersion.h`).
|
|
196
|
+
SH units carry no version; generated C must be rebuilt, as for any SH
|
|
197
|
+
ABI change.
|
|
198
|
+
|
|
199
|
+
`dumpRegexBytecode` (`lib/Regex/RegexSerialization.cpp:342-352`) prints
|
|
200
|
+
a new line after `Header:` when a filter is present:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
StartSet: 0x61-0x63 0x6b nonascii
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
ASCII members print as hex ranges in increasing order; `nonascii` is
|
|
207
|
+
printed when the flag is set.
|
|
208
|
+
|
|
209
|
+
### Using it
|
|
210
|
+
|
|
211
|
+
In `Context::match` (`Executor.cpp:1115-1120`), when `!onlyAtStart` and
|
|
212
|
+
the filter is present, the loop advances `locIndex` to the first
|
|
213
|
+
position `p < charsToRight` whose unit passes the filter before
|
|
214
|
+
`c.setCurrentPointer`. If none does, `match` returns no match. The extra
|
|
215
|
+
end-of-input position (`locsToCheckCount = 1 + charsToRight`, `:1087`)
|
|
216
|
+
needs no check: a filtered regex cannot match empty.
|
|
217
|
+
|
|
218
|
+
- One predicate decides whether a unit passes: a unit >= 0x80 passes
|
|
219
|
+
iff `nonASCII`; an ASCII unit passes iff its bitmap bit is set. Both
|
|
220
|
+
input widths use it. The `char` path is not always 7-bit:
|
|
221
|
+
`JSRegExp::search` passes only ASCII strings there, but
|
|
222
|
+
`GraphQLDependencyExtractor.h:43` passes raw UTF-8.
|
|
223
|
+
- The current position's unit is tested inline. Only when it fails does
|
|
224
|
+
the loop scan forward from the next position: `memchr` for
|
|
225
|
+
`StartFilterSingleChar` on `char` input, otherwise a loop over the
|
|
226
|
+
predicate.
|
|
227
|
+
- When the filter rarely rejects (e.g. `[a-z]` over lowercase text), the
|
|
228
|
+
per-position test is pure overhead. Once 16 attempted positions in a
|
|
229
|
+
row have passed since the last skip, the filter is turned off for the
|
|
230
|
+
rest of that `match` call. A filtered search still visits a subset of the
|
|
231
|
+
unfiltered positions, so A.5 holds unchanged.
|
|
232
|
+
- `onlyAtStart` is true for sticky, for `AnchoredAtStart`
|
|
233
|
+
(`searchWithBytecodeImpl`, `:1667-1668`) and for every lookaround
|
|
234
|
+
recursion (`:1437`), which also runs backwards cursors. The filter is
|
|
235
|
+
never applied there. Sticky and anchored searches try one position,
|
|
236
|
+
and the first instruction already rejects it cheaply.
|
|
237
|
+
- After the skip, the loop's own `advanceStringIndex` (`:1035-1061`)
|
|
238
|
+
continues as now. Under `/u`, a scan stops on a high surrogate before
|
|
239
|
+
its low surrogate whenever `nonASCII` is set, and skips both when it
|
|
240
|
+
is not, so it never lands inside a pair it did not start at.
|
|
241
|
+
- `backtracksRemaining_` is shared across positions (`:404`); skipping
|
|
242
|
+
positions only saves budget.
|
|
243
|
+
|
|
244
|
+
### A.5 Resource limits
|
|
245
|
+
|
|
246
|
+
A skipped position is not free today: it can push backtrack records, and
|
|
247
|
+
so spend budget (`pushBacktrack`, `Executor.cpp:457-467`) or stack depth,
|
|
248
|
+
before its first unit is tested, e.g. by entering a capture group or a
|
|
249
|
+
mandatory loop. `/(){999999999}a/.exec("b")` overflows today
|
|
250
|
+
(`RegexTest.cpp:97` expects overflow for `(){999999999}`) and finds no
|
|
251
|
+
match with the filter, because the filter skips every position.
|
|
252
|
+
|
|
253
|
+
For every unfiltered search that completes without `StackOverflow`, the
|
|
254
|
+
filtered search performs a subsequence of its per-position matcher work:
|
|
255
|
+
the positions it visits run exactly as before, with at least as much
|
|
256
|
+
budget left. Each position resets the cursor and `ip_`
|
|
257
|
+
(`Executor.cpp:1116-1120`), and an exhausted position drains its
|
|
258
|
+
backtrack records, restoring captures and loop data (`:803-871`). So
|
|
259
|
+
**the results differ only when the unfiltered search ends in
|
|
260
|
+
`StackOverflow`** (a `RangeError`, "Maximum regex stack depth reached",
|
|
261
|
+
`JSRegExp.cpp:310-311`). The filter may avoid such a limit, never cause
|
|
262
|
+
one. Keeping the limit exact would forbid the filter for any regex that
|
|
263
|
+
begins with a group, so this is accepted as the one behavior change.
|
|
264
|
+
|
|
265
|
+
`searchWithBytecode` gains a flag, `matchNoStartFilter`, that disables
|
|
266
|
+
the filter. Only tests use it, to compare filtered and unfiltered
|
|
267
|
+
results.
|
|
268
|
+
|
|
269
|
+
## Part B: builtin-exec fast paths
|
|
270
|
+
|
|
271
|
+
### B.1 The builtin exec core
|
|
272
|
+
|
|
273
|
+
`directRegExpExec` (`RegExp.cpp:899-1110`) is split:
|
|
274
|
+
|
|
275
|
+
```cpp
|
|
276
|
+
/// RegExpBuiltinExec up to, but not including, building the result array:
|
|
277
|
+
/// Get and ToLength lastIndex, search, Set lastIndex, and the unicode
|
|
278
|
+
/// adjustment of the ranges. \return false on no match; on a match fill
|
|
279
|
+
/// \p match.
|
|
280
|
+
static CallResult<bool> regExpBuiltinExecMatch(
|
|
281
|
+
Handle<JSRegExp> regexp, Runtime &runtime, Handle<StringPrimitive> S,
|
|
282
|
+
RegExpMatch &match);
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`directRegExpExec` becomes `regExpBuiltinExecMatch` followed by the
|
|
286
|
+
existing array building (`:1013-1105`). The observable operations are
|
|
287
|
+
exactly today's: the `Get` and `ToLength` of `lastIndex` (`:918-928`),
|
|
288
|
+
and one `Set` of `lastIndex` to 0 or `e` (`:977-1011`). `JSRegExp::search`
|
|
289
|
+
still updates the legacy statics on every success
|
|
290
|
+
(`lib/VM/JSRegExp.cpp:376-383`).
|
|
291
|
+
|
|
292
|
+
`test` (`RegExp.cpp:1239-1247`) calls `regExpBuiltinExecMatch` and
|
|
293
|
+
never builds the array. It already requires a `JSRegExp` and never
|
|
294
|
+
looks up `exec`; that stays.
|
|
295
|
+
|
|
296
|
+
### B.2 Recognizing the builtin exec
|
|
297
|
+
|
|
298
|
+
`Runtime` saves the builtin: `regExpPrototypeExec`, a new
|
|
299
|
+
`RUNTIME_HV_FIELD` (`include/hermes/VM/RuntimeHermesValueFields.def`),
|
|
300
|
+
assigned from `defineMethod` (`RegExp.cpp:82-87`), as
|
|
301
|
+
`arrayPrototypeValues` is (`lib/VM/JSLib/Array.cpp:146`).
|
|
302
|
+
|
|
303
|
+
```cpp
|
|
304
|
+
/// \return true if \p R is a JSRegExp and Get(R, "exec") would return the
|
|
305
|
+
/// builtin exec from a plain data property, with no proxy, host object or
|
|
306
|
+
/// accessor on the lookup path.
|
|
307
|
+
static bool hasBuiltinExec(Runtime &runtime, Handle<JSObject> R);
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
It follows the existing precedent (`lib/VM/JSLib/HermesBuiltin.cpp:590-606`,
|
|
311
|
+
`Interpreter-slowpaths.cpp:330-348`): `getNamedDescriptorPredefined`
|
|
312
|
+
for `exec`, bail if no property, `desc.flags.proxyObject`,
|
|
313
|
+
`desc.flags.hostObject` or `desc.flags.accessor`, then compare the slot
|
|
314
|
+
value with `runtime.regExpPrototypeExec`. A data-property `Get` runs no
|
|
315
|
+
user code, so skipping it is unobservable. A hidden-class check alone
|
|
316
|
+
would not do: `RegExp.prototype.exec = f` rewrites the slot without a
|
|
317
|
+
new class (`lib/VM/JSObject.cpp:3254-3283`).
|
|
318
|
+
|
|
319
|
+
### B.3 Where it is used
|
|
320
|
+
|
|
321
|
+
**The exec frame stays.** Calling the builtin's effects without calling
|
|
322
|
+
the builtin would drop the native `exec` frame. Stack traces record it
|
|
323
|
+
(`JSError.cpp:355`, `:708`), both for user code that runs inside exec
|
|
324
|
+
(`ToLength` of a `lastIndex` object, `RegExp.cpp:923`) and for errors the
|
|
325
|
+
engine raises there: the `TypeError` of a non-writable `lastIndex`
|
|
326
|
+
(`:977`, `:1005`), and the regex limit `RangeError`. So every site that
|
|
327
|
+
today reaches the builtin through `executeCall1` (inside `regExpExec`,
|
|
328
|
+
`RegExp.cpp:1168`) runs its builtin-exec work inside a frame for the
|
|
329
|
+
builtin, built the way a call builds it. Those sites are `regExpExec`'s
|
|
330
|
+
direct dispatch, the global `@@match` loop, `@@replace` phase 1 and
|
|
331
|
+
`@@search`. Sites that call the C++ exec directly today and so have no
|
|
332
|
+
exec frame keep none: `test` (`RegExp.cpp:1239-1247`), the fallback for
|
|
333
|
+
a non-callable `exec` (`:1187-1194`), and the shared core itself (no
|
|
334
|
+
double frame). The frame is:
|
|
335
|
+
|
|
336
|
+
- a `ScopedNativeCallFrame` with one argument, callee
|
|
337
|
+
`runtime.regExpPrototypeExec`, `this` = `R` and argument `S`, with its
|
|
338
|
+
overflow check, exactly as `Callable::executeCall1` builds it
|
|
339
|
+
(`lib/VM/Callable.cpp:322-339`);
|
|
340
|
+
- then, as `Callable::call` does before dispatch, `potentiallyMoveHeap()`
|
|
341
|
+
once the frame's arguments are set (`include/hermes/VM/Callable.h:282`),
|
|
342
|
+
with the callee rooted and reloaded across it and across the body;
|
|
343
|
+
- then the body of `NativeFunction::_nativeCall`
|
|
344
|
+
(`include/hermes/VM/Callable.h:730-764`): the native depth tracker,
|
|
345
|
+
`validateSavedIPBeforeCall`, `setCurrentFrameToTopOfStack`, and
|
|
346
|
+
`restoreStackAndPreviousFrame`, plus the `HERMESVM_PROFILER_NATIVECALL`
|
|
347
|
+
counters. `_nativeCall` is split into a template that runs a given body
|
|
348
|
+
inside that setup, and itself calls it with `functionPtr_`, so the fast
|
|
349
|
+
paths share the code instead of copying it.
|
|
350
|
+
|
|
351
|
+
What the fast paths skip is the `exec` lookup, the dispatch through
|
|
352
|
+
`Callable::call`, the native's `ToString` of a string, and the result
|
|
353
|
+
array. `NativeFunction::_callImpl` only forwards to `_nativeCall`
|
|
354
|
+
(`lib/VM/Callable.cpp:1189`), and debugger and sampling-profiler stack
|
|
355
|
+
walks read the runtime frames (`Debugger.cpp:649`,
|
|
356
|
+
`SamplingProfiler.cpp:81`), so the frame is the same to all of them.
|
|
357
|
+
|
|
358
|
+
**`regExpExec`** (`RegExp.cpp:1149-1195`) keeps its `Get(R, "exec")`.
|
|
359
|
+
When the value is `runtime.regExpPrototypeExec` and `R` is a
|
|
360
|
+
`JSRegExp`, it runs `regExpBuiltinExec` in the exec frame instead of
|
|
361
|
+
`executeCall1`. The native exec would only run `ToString` on
|
|
362
|
+
a string (a no-op) and the same `directRegExpExec`. This covers
|
|
363
|
+
non-global `@@match`, `@@search` and the `matchAll` iterator
|
|
364
|
+
(`JSRegExpStringIterator.cpp:87`).
|
|
365
|
+
|
|
366
|
+
**Loops.** The other callers run `regExpExec` in a loop, or once, with
|
|
367
|
+
no user code between iterations: each iteration's only other operations
|
|
368
|
+
are `ToString` of a string from the builtin exec, and a `Get`/`ToLength`
|
|
369
|
+
of a `lastIndex` that holds a number the builtin exec wrote. So `exec`
|
|
370
|
+
cannot change during the loop, and one `hasBuiltinExec` check, made
|
|
371
|
+
after the last user-code step before the loop, covers every iteration.
|
|
372
|
+
|
|
373
|
+
- **Global `@@match`** (`RegExp.cpp:1781-1917`). After `Get global`,
|
|
374
|
+
`Get unicode` and `Set lastIndex = 0` (`:1811-1834`), if
|
|
375
|
+
`hasBuiltinExec(rx)`, the loop runs `regExpBuiltinExecMatch` in the
|
|
376
|
+
exec frame and
|
|
377
|
+
appends a slice of range 0 to `A`. Empty matches do the same
|
|
378
|
+
`Get`/`ToLength`/`advanceStringIndex`/`Set` of `lastIndex` as now
|
|
379
|
+
(`:1889-1910`).
|
|
380
|
+
- **`@@replace`** (`RegExp.cpp:1988-2374`). After `ToString(S)`,
|
|
381
|
+
`ToString(replaceValue)` when not callable, `Get global`,
|
|
382
|
+
`Get unicode` and the `Set` (`:2021-2068`), if `hasBuiltinExec(rx)`
|
|
383
|
+
|
|
384
|
+
phase 1 runs each builtin exec in the exec frame and stores each `RegExpMatch` in a C++ vector instead of a result
|
|
385
|
+
array. Phase 2 is factored into one step per match that takes
|
|
386
|
+
`matched`, `position`, the captures list and `namedCaptures`. The
|
|
387
|
+
slow path extracts them from the result array with today's `Get`s
|
|
388
|
+
(`:2157-2264`); the fast path builds them from the ranges:
|
|
389
|
+
`matched` and the captures are slices (`undefined` for unmatched
|
|
390
|
+
groups), `position` is range 0's location, and `namedCaptures` is a
|
|
391
|
+
groups object built from the regexp's group-name mapping
|
|
392
|
+
(`getGroupNameMappings`, `JSRegExp.cpp:261-267`) and the captures.
|
|
393
|
+
`buildGroupsObject` (`RegExp.cpp:694-763`) is generalized to read
|
|
394
|
+
captures from either source. The `Get`s it replaces are on own
|
|
395
|
+
properties of an array that user code never sees, so they are
|
|
396
|
+
unobservable. The callback still runs in phase 2, after every exec,
|
|
397
|
+
as now.
|
|
398
|
+
- **`@@search`** (`RegExp.cpp:1920-1985`). Between its two `Set`s of
|
|
399
|
+
`lastIndex`, if `hasBuiltinExec(rx)`, it runs
|
|
400
|
+
`regExpBuiltinExecMatch` in the exec frame and returns range 0's location, instead of
|
|
401
|
+
`Get(result, "index")` on an array.
|
|
402
|
+
|
|
403
|
+
`lastIndex` is still read and written exactly as today on every path.
|
|
404
|
+
If `lastIndex` is non-writable, the `Set` before each loop throws
|
|
405
|
+
TypeError as now (`setLastIndex`, `lib/VM/JSLib/JSLibInternal.h:300-311`;
|
|
406
|
+
`Runtime.cpp:211-243`).
|
|
407
|
+
|
|
408
|
+
### B.4 Fewer copies per search
|
|
409
|
+
|
|
410
|
+
`performSearch` (`JSRegExp.cpp:293-332`) allocates a
|
|
411
|
+
`std::vector<regex::CapturedRange>` per search and copies it into a
|
|
412
|
+
`RegExpMatch` (`SmallVector<OptValue<RegExpMatchRange>, 4>`,
|
|
413
|
+
`include/hermes/VM/RegExpMatch.h:30`). The vector becomes a
|
|
414
|
+
`Runtime`-owned buffer that keeps its capacity; it is used only between
|
|
415
|
+
the executor's return and the copy into the `RegExpMatch`, and the
|
|
416
|
+
executor runs no JS and no GC allocation, so it is never reentered. The
|
|
417
|
+
`@@split` loop moves its `RegExpMatch` instead of copying it
|
|
418
|
+
(`RegExp.cpp:2531`).
|
|
419
|
+
|
|
420
|
+
### GC safety
|
|
421
|
+
|
|
422
|
+
- `RegExpMatch` holds integers; it survives any allocation.
|
|
423
|
+
- Slices come from `S`, which `JSRegExp::search` flattens
|
|
424
|
+
(`StringPrimitive::createStringView` → `ensureFlat`), and `slice`
|
|
425
|
+
reads the characters after it allocates (`StringPrimitive.cpp:350-382`).
|
|
426
|
+
- No raw character pointer or `StringView` iterator is held across a
|
|
427
|
+
`slice`, `setElementAt`, `push_back` or call.
|
|
428
|
+
- Loops keep today's `GCScope` markers; the phase-2 step keeps
|
|
429
|
+
`marker1`/`marker2` (`RegExp.cpp:2154`, `:2226`).
|
|
430
|
+
- The C++ vector of matches in `@@replace` is malloc'd; it is not
|
|
431
|
+
reachable from the GC and holds no GC pointers.
|
|
432
|
+
- `RegExpMatch` vectors and `Locals` are destroyed normally; nothing
|
|
433
|
+
RAII spans a call that can throw by longjmp beyond what the existing
|
|
434
|
+
code already holds.
|
|
435
|
+
|
|
436
|
+
## Tests
|
|
437
|
+
|
|
438
|
+
### Part A
|
|
439
|
+
|
|
440
|
+
- **Header contents** (`unittests/Support/RegexTest.cpp`, which builds
|
|
441
|
+
`cregex(u"pat", u"flags")` and can read the header from `compile()`):
|
|
442
|
+
a table of patterns with the expected `startFlags`, `startChar` and
|
|
443
|
+
bitmap. It includes: a literal (`/abc/` → single char `a`); `/i`
|
|
444
|
+
(`/a/i` → `a`, `A`); `/iu` with `s` and `k` (nonASCII set); `/i`
|
|
445
|
+
without `u` on `s` (nonASCII clear); `ſ` under `/i` (nonASCII only);
|
|
446
|
+
alternation (`/ab|cd/`); an empty alternative (`/a|/`, no filter);
|
|
447
|
+
`x*y` (both); `x+y` (`x` only); a leading anchor, `\b`, lookahead and
|
|
448
|
+
lookbehind (transparent); a back-reference first (no filter); `.`
|
|
449
|
+
with and without `s`; brackets, negated brackets, `\d`, `\w`, `\s`,
|
|
450
|
+
`[^a]`; an astral literal under `/u` (nonASCII); `(?i:a)b` and
|
|
451
|
+
`a(?i:b)` (node-local icase); 100 nested groups (no filter, depth
|
|
452
|
+
cap); `/^a/` (anchored; set computed but never used).
|
|
453
|
+
Fails before: the fields do not exist.
|
|
454
|
+
- **Differential** (same file): a corpus of the patterns above plus
|
|
455
|
+
`\s`-heavy, multiline and sticky ones, each searched over ASCII
|
|
456
|
+
`char` input and UTF-16 input (with U+017F, U+212A, U+2028, a
|
|
457
|
+
surrogate pair, a lone surrogate, and a start index inside a pair),
|
|
458
|
+
at every start index, with and without `matchNoStartFilter`. The
|
|
459
|
+
helper compares the whole `MatchRuntimeResult` and the captures (the
|
|
460
|
+
existing boolean helper, `RegexTest.cpp:22-30`, folds overflow into
|
|
461
|
+
no match). They must be equal unless the unfiltered result is
|
|
462
|
+
`StackOverflow` (A.5); `/(){999999999}a/` over `"b"` is in the corpus
|
|
463
|
+
and pins that case: unfiltered overflows, filtered is `NoMatch`. Mutations it must catch: drop the other
|
|
464
|
+
case of an `/i` letter; clear `nonASCII` for `/iu` `s`; treat a
|
|
465
|
+
lookahead's body as consuming; let `MatchAny` exclude a non-ASCII
|
|
466
|
+
unit; apply the filter when `onlyAtStart`.
|
|
467
|
+
- **Dump** (`test/hermes/regexp_bytecode.js`): its 28 `Header:` CHECK
|
|
468
|
+
lines gain the `StartSet:` line where a filter exists; at least one
|
|
469
|
+
case each for single char, a range, and `nonascii`. Fails before: the
|
|
470
|
+
line is not printed.
|
|
471
|
+
- **Existing**: `test/hermes/regexp*.js`, `test/hermes/regex*.js`, the
|
|
472
|
+
50000-deep nesting at `regexp.js:94`, and the whole `check-hermes`.
|
|
473
|
+
|
|
474
|
+
### Part B
|
|
475
|
+
|
|
476
|
+
A new `test/hermes/regexp-exec-fast-path.js`, run under `%hermes`,
|
|
477
|
+
`%hermes -lazy`, `-gc-sanitize-handles=1` and `%shermes -exec`. Each
|
|
478
|
+
case states the observable that the fast path must not change:
|
|
479
|
+
|
|
480
|
+
- `RegExp.prototype.exec` replaced by a counting function: global
|
|
481
|
+
`match`, `replace` (string and callback), `search` and non-global
|
|
482
|
+
`match` call it, with the right arguments and count. An own `exec` on
|
|
483
|
+
the instance, and on a subclass prototype, likewise.
|
|
484
|
+
- `exec` as an accessor on `RegExp.prototype`: the getter runs once per
|
|
485
|
+
iteration, as now.
|
|
486
|
+
- A regexp whose prototype is a `Proxy` of `RegExp.prototype`: the
|
|
487
|
+
proxy's `get` trap sees each `exec` lookup.
|
|
488
|
+
- A frozen global regexp: `match` and `replace` throw TypeError from
|
|
489
|
+
the pre-loop `Set`, so the error's stack has no `exec` frame.
|
|
490
|
+
- `lastIndex` holding an object with `valueOf` on a non-global regexp:
|
|
491
|
+
`valueOf` runs once per `exec`/`test`, as now.
|
|
492
|
+
- Legacy statics (`RegExp.$1`, `lastMatch`, `leftContext`,
|
|
493
|
+
`rightContext`) after `test`, global `match`, `search` and `replace`,
|
|
494
|
+
and inside a replace callback.
|
|
495
|
+
- Global `match` and `replace` with empty matches, under `/u` over a
|
|
496
|
+
surrogate pair (advance by code point) and without `/u`.
|
|
497
|
+
- Sticky plus global `match` and `replace`.
|
|
498
|
+
- `replace` with `$<name>`, `$1`, `` $` ``, `$'`, `$&`, and a callback
|
|
499
|
+
receiving captures, position, the string and `groups`; unmatched
|
|
500
|
+
groups as `undefined`.
|
|
501
|
+
- `hasIndices` on non-global `match` (array built in full).
|
|
502
|
+
|
|
503
|
+
- Stack observation, each showing the native `exec` frame as today:
|
|
504
|
+
a non-global regexp whose `lastIndex` is an object whose `valueOf`
|
|
505
|
+
records `new Error().stack`, under `match` and `replace` (`search`
|
|
506
|
+
overwrites `lastIndex` with 0 before exec, `RegExp.cpp:1953`, so it
|
|
507
|
+
never coerces it); a frozen sticky non-global regexp under `match`,
|
|
508
|
+
whose exec `Set` throws; a global `match` whose regex hits the stack
|
|
509
|
+
limit inside exec; and `@@search` with `/(){999999999}/`, whose limit
|
|
510
|
+
`RangeError` comes from inside exec (the pattern is nullable, so the
|
|
511
|
+
start filter does not apply). `test` with a `lastIndex.valueOf` still
|
|
512
|
+
shows no `exec` frame, as today.
|
|
513
|
+
|
|
514
|
+
Every case has a mutation that it, and not only some other case, fails
|
|
515
|
+
under:
|
|
516
|
+
|
|
517
|
+
| Case | Mutation |
|
|
518
|
+
|---|---|
|
|
519
|
+
| replaced / own / subclass `exec` | `hasBuiltinExec` always true |
|
|
520
|
+
| `exec` accessor | `hasBuiltinExec` does one ordinary `Get`, accepts an accessor that returns the builtin, and the result is hoisted out of the loop (a counting accessor that returns the builtin then sees 1 lookup instead of one per iteration). Deleting the `desc.flags.accessor` test alone is masked: the slot holds a `PropertyAccessor`, never equal to the builtin (`JSObject.cpp:3278`) |
|
|
521
|
+
| `Proxy` prototype | the `proxyObject` test removed |
|
|
522
|
+
| frozen regexp | the fast path skips the pre-loop `Set`; the TypeError then comes from inside exec and its stack gains the `exec` frame |
|
|
523
|
+
| `lastIndex.valueOf` count | `regExpBuiltinExecMatch` skips `ToLength` for a non-global, non-sticky regexp |
|
|
524
|
+
| stack observation | each framed site in turn (direct dispatch, `@@match`, `@@replace`, `@@search`) runs the core without the exec frame; `test` given a frame |
|
|
525
|
+
| statics | `test` searches without recording statics |
|
|
526
|
+
| empty matches under `/u` | the fast loop advances by one code unit regardless of `unicode` |
|
|
527
|
+
| sticky plus global | the fast loop clears sticky before searching |
|
|
528
|
+
| replacement patterns and callback arguments | phase 2 uses range 0 for every capture; unmatched groups become `""` |
|
|
529
|
+
| `hasIndices` | non-global `match` takes the array-free path |
|
|
530
|
+
|
|
531
|
+
Each mutation is run and its failing case recorded in the plan.
|
|
532
|
+
|
|
533
|
+
## Measurements
|
|
534
|
+
|
|
535
|
+
The benchmarks of the Problem section are re-run after each part, on the
|
|
536
|
+
same release build configuration, best of three, and reported in the
|
|
537
|
+
commit message. There is no pass/fail threshold.
|
|
538
|
+
|
|
539
|
+
## Risks
|
|
540
|
+
|
|
541
|
+
- **A superset rule written as a subset loses matches.** The
|
|
542
|
+
differential test is the guard; the case analysis for `icase` and
|
|
543
|
+
brackets reuses the executor's own predicates rather than restating
|
|
544
|
+
them.
|
|
545
|
+
- **Bytecode format.** Old HBC files are rejected by the version check;
|
|
546
|
+
old SH-generated C is not checked and would misread the header.
|
|
547
|
+
- **Fast paths and user code.** B relies on no user code running
|
|
548
|
+
inside the loops. Every user-code step (`ToString`, `Get global`,
|
|
549
|
+
`Get unicode`, `Get flags`) happens before the check; the callback of
|
|
550
|
+
`@@replace` runs after phase 1. A future edit that adds user code
|
|
551
|
+
inside a loop must move the check.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# TypeScript Type Stripping
|
|
2
|
+
|
|
3
|
+
Hermes supports stripping erasable TypeScript syntax from source files via the
|
|
4
|
+
`--transform-ts` flag, similar to Node.js's `--strip-types`. This allows
|
|
5
|
+
running TypeScript files directly without a separate transpilation step, as long
|
|
6
|
+
as the code uses only erasable type syntax.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
# Run a TypeScript file directly
|
|
12
|
+
hermes --transform-ts file.ts
|
|
13
|
+
|
|
14
|
+
# Compile to bytecode
|
|
15
|
+
hermesc --transform-ts -emit-binary -out file.hbc file.ts
|
|
16
|
+
|
|
17
|
+
# With shermes
|
|
18
|
+
shermes --transform-ts file.ts
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The `--transform-ts` flag implies `--parse-ts` (TypeScript parsing is enabled
|
|
22
|
+
automatically).
|
|
23
|
+
|
|
24
|
+
## Supported Erasable Syntax
|
|
25
|
+
|
|
26
|
+
The following TypeScript constructs are erased (removed or unwrapped) during
|
|
27
|
+
the AST transformation pass:
|
|
28
|
+
|
|
29
|
+
- **Type annotations** on variables, parameters, and return types
|
|
30
|
+
(`let x: number`, `function f(a: string): void`)
|
|
31
|
+
- **Type aliases** (`type Foo = string`)
|
|
32
|
+
- **Interfaces** (`interface Bar { ... }`)
|
|
33
|
+
- **Generic type parameters** (`function f<T>(x: T): T`, `class C<T>`)
|
|
34
|
+
- **Type assertions** (`x as T`, `<T>x`)
|
|
35
|
+
- **Type-only imports** (`import type { Foo } from "bar"`)
|
|
36
|
+
- **Type-only exports** (`export type { Foo }`)
|
|
37
|
+
- **`implements` clauses** on classes (`class Foo implements Bar`)
|
|
38
|
+
- **Type arguments** on call/new expressions (`foo<T>(x)`, `new C<T>()`)
|
|
39
|
+
- **TS modifiers** on class properties (`readonly`, access modifiers when used
|
|
40
|
+
only as type-level annotations on properties)
|
|
41
|
+
- **`superTypeArguments`** on classes (`class Foo extends Bar<T>`)
|
|
42
|
+
|
|
43
|
+
## Unsupported Non-Erasable Syntax
|
|
44
|
+
|
|
45
|
+
The following TypeScript constructs have runtime semantics and cannot be
|
|
46
|
+
simply erased. Using them with `--transform-ts` produces an error:
|
|
47
|
+
|
|
48
|
+
- **Enums** (`enum Color { Red, Green, Blue }`)
|
|
49
|
+
- **Namespaces / modules** (`namespace Foo { ... }`)
|
|
50
|
+
- **Parameter properties** (`constructor(public x: number)`)
|
|
51
|
+
|
|
52
|
+
## Restrictions
|
|
53
|
+
|
|
54
|
+
- `--transform-ts` is incompatible with `--typed` (typed mode). Using both
|
|
55
|
+
together produces an error.
|
|
56
|
+
|
|
57
|
+
## How It Works
|
|
58
|
+
|
|
59
|
+
The stripping pass runs as an AST transformation before semantic analysis,
|
|
60
|
+
in the same pipeline slot as the async generator transform. It operates by:
|
|
61
|
+
|
|
62
|
+
1. Walking the AST using the recursive visitor framework.
|
|
63
|
+
2. Nulling out type annotation fields on nodes (identifiers, functions,
|
|
64
|
+
classes, patterns, call expressions).
|
|
65
|
+
3. Removing type-only declaration nodes from statement lists (type aliases,
|
|
66
|
+
interfaces, type-only imports/exports).
|
|
67
|
+
4. Unwrapping type assertion expressions (`x as T` becomes `x`).
|
|
68
|
+
5. Reporting errors for non-erasable constructs.
|
|
69
|
+
|
|
70
|
+
Deep TS type nodes (e.g., `TSAnyKeyword`, `TSFunctionType`, `TSUnionType`)
|
|
71
|
+
only appear as descendants of type annotation fields. Nulling those fields at
|
|
72
|
+
the parent level makes them unreachable, so no explicit handlers are needed.
|
|
73
|
+
|
|
74
|
+
## Comparison with Node.js
|
|
75
|
+
|
|
76
|
+
| Feature | Hermes `--transform-ts` | Node.js `--strip-types` |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| Type annotations | Stripped | Stripped |
|
|
79
|
+
| Interfaces / type aliases | Stripped | Stripped |
|
|
80
|
+
| Enums | Error | Error (unless `--experimental-transform-types`) |
|
|
81
|
+
| Namespaces | Error | Error (unless `--experimental-transform-types`) |
|
|
82
|
+
| Parameter properties | Error | Error (unless `--experimental-transform-types`) |
|
|
83
|
+
| `import type` | Stripped | Stripped |
|
|
84
|
+
| Per-specifier `import { type X }` | Not yet supported | Stripped |
|
|
85
|
+
|
|
86
|
+
## Future Work
|
|
87
|
+
|
|
88
|
+
- Per-specifier type import stripping (`import { type X, Y } from "bar"`)
|
|
89
|
+
- Enum lowering (transform enums to JavaScript objects)
|
|
90
|
+
- Namespace lowering (transform namespaces to IIFEs)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
add_subdirectory(dtoa)
|
|
2
|
+
if(HERMES_ENABLE_NAPI)
|
|
3
|
+
add_subdirectory(node-api-cts/implementors/hermes)
|
|
4
|
+
add_subdirectory(node-api-tests/hermes)
|
|
5
|
+
|
|
6
|
+
# Combined target to run all NAPI tests (CTS + Node.js).
|
|
7
|
+
add_custom_target(check-napi
|
|
8
|
+
DEPENDS check-napi-cts check-napi-node-tests
|
|
9
|
+
COMMENT "Running all Node-API tests under Hermes"
|
|
10
|
+
)
|
|
11
|
+
endif()
|
|
12
|
+
|
|
13
|
+
add_subdirectory(zip)
|
|
14
|
+
if(HERMESVM_ALLOW_JIT)
|
|
15
|
+
add_subdirectory(asmjit)
|
|
16
|
+
endif()
|
|
17
|
+
add_subdirectory(llvh)
|
|
18
|
+
if (HERMES_USE_BOOST_CONTEXT)
|
|
19
|
+
add_subdirectory(boost)
|
|
20
|
+
endif()
|