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.
Files changed (181) hide show
  1. package/hermes/CMakeLists.txt +874 -0
  2. package/hermes/android/HostObjectJniTest.cpp +178 -0
  3. package/hermes/android/build-logic/build.gradle.kts +31 -0
  4. package/hermes/android/build-logic/settings.gradle.kts +17 -0
  5. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
  6. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
  7. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
  8. package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
  9. package/hermes/android/build.gradle.kts +332 -0
  10. package/hermes/android/cppruntime/build.gradle +72 -0
  11. package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
  12. package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
  13. package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
  14. package/hermes/android/cross-compile/swift-libicu.patch +13 -0
  15. package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
  16. package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
  17. package/hermes/android/gradle/libs.versions.toml +30 -0
  18. package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  19. package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  20. package/hermes/android/gradle.properties +3 -0
  21. package/hermes/android/gradlew +248 -0
  22. package/hermes/android/gradlew.bat +93 -0
  23. package/hermes/android/intltest/build.gradle +147 -0
  24. package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
  25. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
  26. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
  27. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
  28. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
  29. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
  30. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
  31. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
  32. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
  33. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
  34. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
  35. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
  36. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
  37. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
  38. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
  39. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
  40. package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
  41. package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
  42. package/hermes/android/settings.gradle.kts +27 -0
  43. package/hermes/cmake/modules/Hermes.cmake +481 -0
  44. package/hermes/cmake/modules/Lit.cmake +96 -0
  45. package/hermes/doc/Branches.md +38 -0
  46. package/hermes/doc/BuildingAndRunning.md +121 -0
  47. package/hermes/doc/CodingStandards.md +112 -0
  48. package/hermes/doc/CrossCompilation.md +79 -0
  49. package/hermes/doc/Design.md +217 -0
  50. package/hermes/doc/Emscripten.md +156 -0
  51. package/hermes/doc/Features.md +143 -0
  52. package/hermes/doc/GCSafeCoding.md +563 -0
  53. package/hermes/doc/GenGC.md +300 -0
  54. package/hermes/doc/Hades.md +344 -0
  55. package/hermes/doc/HighLevelOptimizations.md +37 -0
  56. package/hermes/doc/IR.md +1306 -0
  57. package/hermes/doc/IntlAPIs.md +196 -0
  58. package/hermes/doc/JIT.md +999 -0
  59. package/hermes/doc/LazyEvalCompilation.md +84 -0
  60. package/hermes/doc/MemoryProfilers.md +316 -0
  61. package/hermes/doc/Modules.md +144 -0
  62. package/hermes/doc/Optimizer.md +83 -0
  63. package/hermes/doc/PerfProfiling.md +29 -0
  64. package/hermes/doc/ProhibitInvoke.md +329 -0
  65. package/hermes/doc/ReactNative.md +40 -0
  66. package/hermes/doc/ReactNativeIntegration.md +94 -0
  67. package/hermes/doc/RegExp.md +24 -0
  68. package/hermes/doc/SpecIncompat.md +85 -0
  69. package/hermes/doc/Strings.md +140 -0
  70. package/hermes/doc/TypedLanguage.md +432 -0
  71. package/hermes/doc/VM.md +174 -0
  72. package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
  73. package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
  74. package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
  75. package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
  76. package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
  77. package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
  78. package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
  79. package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
  80. package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
  81. package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
  82. package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
  83. package/hermes/doc/blog/README.md +25 -0
  84. package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
  85. package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
  86. package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
  87. package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
  88. package/hermes/doc/icu_license.txt +420 -0
  89. package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
  90. package/hermes/doc/img/logo.svg +1 -0
  91. package/hermes/doc/img/object_captured_by_environment.png +0 -0
  92. package/hermes/doc/img/root_categories.png +0 -0
  93. package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
  94. package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
  95. package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
  96. package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
  97. package/hermes/doc/plans/ir-type/memory.md +48 -0
  98. package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
  99. package/hermes/doc/plans/ir-type/progress.md +239 -0
  100. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
  101. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
  102. package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
  103. package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
  104. package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
  105. package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
  106. package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
  107. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
  108. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
  109. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
  110. package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
  111. package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
  112. package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
  113. package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
  114. package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
  115. package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
  116. package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
  117. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
  118. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
  119. package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
  120. package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
  121. package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
  122. package/hermes/doc/typescript-stripping.md +90 -0
  123. package/hermes/external/CMakeLists.txt +20 -0
  124. package/hermes/utils/IntlGen/IntlGen.java +531 -0
  125. package/hermes/utils/bench_with_stats.py +827 -0
  126. package/hermes/utils/build-apple-framework.sh +323 -0
  127. package/hermes/utils/chrome_snapshot_parser.py +210 -0
  128. package/hermes/utils/cmake-dev-build.sh +18 -0
  129. package/hermes/utils/commons.sh +55 -0
  130. package/hermes/utils/dump-cpp-funcs.sh +3 -0
  131. package/hermes/utils/es5objects.js +198 -0
  132. package/hermes/utils/format.sh +145 -0
  133. package/hermes/utils/gen-promise-internal-bc.sh +66 -0
  134. package/hermes/utils/genUnicodeTable.py +2503 -0
  135. package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
  136. package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
  137. package/hermes/utils/jit/README.md +134 -0
  138. package/hermes/utils/jit/jit-diff.sh +160 -0
  139. package/hermes/utils/jit/jit-dump.sh +193 -0
  140. package/hermes/utils/lit-expect-gen/generate.py +217 -0
  141. package/hermes/utils/promise/index.js +15 -0
  142. package/hermes/utils/promise/package.json +13 -0
  143. package/hermes/utils/promise/rollup.config.js +19 -0
  144. package/hermes/utils/promise/yarn.lock +247 -0
  145. package/hermes/utils/scripts/hermes/consts.js +26 -0
  146. package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
  147. package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
  148. package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
  149. package/hermes/utils/scripts/hermes/package.json +6 -0
  150. package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
  151. package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
  152. package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
  153. package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
  154. package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
  155. package/hermes/utils/scripts/hermes/version-utils.js +98 -0
  156. package/hermes/utils/scripts/hermes/yarn.lock +240 -0
  157. package/hermes/utils/summarize_sizes.py +184 -0
  158. package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
  159. package/hermes/utils/test_runner.py +13 -0
  160. package/hermes/utils/testsuite/README.facebook +3 -0
  161. package/hermes/utils/testsuite/README.md +69 -0
  162. package/hermes/utils/testsuite/cli.py +547 -0
  163. package/hermes/utils/testsuite/es_ast.py +337 -0
  164. package/hermes/utils/testsuite/external/LICENSE +28 -0
  165. package/hermes/utils/testsuite/external/README.facebook +8 -0
  166. package/hermes/utils/testsuite/external/__init__.py +0 -0
  167. package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
  168. package/hermes/utils/testsuite/external/parse_test262.py +141 -0
  169. package/hermes/utils/testsuite/hermes.py +522 -0
  170. package/hermes/utils/testsuite/preprocess.py +365 -0
  171. package/hermes/utils/testsuite/progress.py +377 -0
  172. package/hermes/utils/testsuite/skiplist.json +4356 -0
  173. package/hermes/utils/testsuite/skiplist.py +270 -0
  174. package/hermes/utils/testsuite/test_run_defs.py +435 -0
  175. package/hermes/utils/testsuite/typing_defs.py +52 -0
  176. package/hermes/utils/testsuite/utils.py +214 -0
  177. package/hermes/utils/tidy.sh +22 -0
  178. package/hermes/utils/update-fbcode-hermes.sh +53 -0
  179. package/hermes/utils/updateErrorTest.py +193 -0
  180. package/hermes/utils/wasm-compile.sh +65 -0
  181. package/package.json +1 -1
@@ -0,0 +1,478 @@
1
+ # Shared JIT Compiler Driver Implementation Plan
2
+
3
+ > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+ **Goal:** Extract the arch-independent Compiler decode driver out of
6
+ `lib/VM/JIT/arm64/JIT.cpp` into a shared file compiled once per arch, with
7
+ byte-identical arm64 emission as the acceptance gate.
8
+
9
+ **Architecture:** The `JITContext::Compiler` nested class (bytecode decode,
10
+ BB walk, label management, error paths — no assembly) moves verbatim into
11
+ `lib/VM/JIT/JitCompiler.cpp`, wrapped in the arch namespace via a macro
12
+ supplied by a new dispatch header `lib/VM/JIT/JitCurArch.h`. Only the
13
+ `JITContext` housekeeping methods stay in `arm64/JIT.cpp`. This is
14
+ milestone 0 of the x86-64 backend spec: after it, the emitter method
15
+ surface is the compiler-enforced porting contract.
16
+
17
+ **Tech Stack:** C++17, CMake/Ninja, aarch64 cross build under qemu-user
18
+ (`aarch64/README.md`), `utils/jit/jit-dump.sh` / `jit-diff.sh`.
19
+
20
+ **Spec:** `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`
21
+
22
+ ## Global Constraints
23
+
24
+ - Work in the worktree `/home/tmikov/work/hermes-x86-jit`, branch
25
+ `x86-jit`. NEVER `cd`; pass paths to commands (project rule).
26
+ - The build to verify against is `cmake-build-arm64` (aarch64 cross build,
27
+ already configured; see `aarch64/README.md`). It runs via qemu binfmt:
28
+ prefix runs with `QEMU_LD_PREFIX=/usr/aarch64-linux-gnu` when invoking
29
+ the binary directly.
30
+ - 80-column limit, 2-space indent, copyright header on every new file
31
+ (exact header shown in Task 2).
32
+ - Acceptance gate for the whole plan: `jit-diff.sh` reports the dumps
33
+ identical (exit 0, no `--comments-ok`), `aarch64/qemu-sanity.sh` passes
34
+ 9/9, and `LIT_FILTER="jit/"` check-hermes shows 46 passes + 1
35
+ unsupported.
36
+ - Commit messages end with:
37
+ `Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>`
38
+
39
+ ---
40
+
41
+ ### Task 1: Capture the pre-refactor baseline dump
42
+
43
+ **Files:** none modified. Produces
44
+ `cmake-build-arm64/jit-baseline.dump` (untracked build artifact).
45
+
46
+ - [ ] **Step 1: Ensure the current tree builds clean**
47
+
48
+ Run:
49
+ ```bash
50
+ cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target hermes -j "$(nproc)"
51
+ ```
52
+ Expected: successful link of `bin/hermes`.
53
+
54
+ - [ ] **Step 2: Capture the baseline**
55
+
56
+ Run:
57
+ ```bash
58
+ QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
59
+ /home/tmikov/work/hermes-x86-jit/utils/jit/jit-dump.sh \
60
+ -o /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline.dump \
61
+ /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/bin/hermes
62
+ ```
63
+ Expected: a summary line on stderr; the dump file is non-empty (hundreds
64
+ of KB). If the script errors, do NOT improvise a replacement — stop and
65
+ report.
66
+
67
+ - [ ] **Step 3: Sanity-check the capture is comparable to itself**
68
+
69
+ Run the capture a second time to a different file and compare:
70
+ ```bash
71
+ QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
72
+ /home/tmikov/work/hermes-x86-jit/utils/jit/jit-dump.sh -q \
73
+ -o /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline2.dump \
74
+ /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/bin/hermes
75
+ /home/tmikov/work/hermes-x86-jit/utils/jit/jit-diff.sh --dumps \
76
+ /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline.dump \
77
+ /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline2.dump
78
+ ```
79
+ Expected: exit 0, dumps identical. (This validates the canonicalization
80
+ before we rely on it.) Then delete `jit-baseline2.dump`.
81
+
82
+ No commit for this task (no repo changes).
83
+
84
+ ---
85
+
86
+ ### Task 2: Move the Compiler driver to `lib/VM/JIT/JitCompiler.cpp`
87
+
88
+ **Files:**
89
+ - Create: `lib/VM/JIT/JitCurArch.h`
90
+ - Create: `lib/VM/JIT/JitCompiler.cpp`
91
+ - Modify: `lib/VM/JIT/arm64/JIT.cpp` (shrinks from 1379 lines to ~60)
92
+ - Modify: `lib/VM/CMakeLists.txt` (JIT source list, currently lines
93
+ 159–177)
94
+
95
+ **Interfaces:**
96
+ - Consumes: the existing `arm64::Emitter` and `arm64::JITContext` —
97
+ unchanged.
98
+ - Produces: `HERMESVM_JIT_ARCH_NS` (macro naming the current arch
99
+ namespace, defined by `JitCurArch.h`) and the shared
100
+ `JitCompiler.cpp`, which later milestones extend with an x86-64 branch
101
+ in `JitCurArch.h`. No signature changes anywhere.
102
+
103
+ This is pure code motion. The moved block must not be edited in any way —
104
+ byte-identical emission is the gate, and the smaller the diff, the easier
105
+ the review.
106
+
107
+ - [ ] **Step 1: Create `lib/VM/JIT/JitCurArch.h`**
108
+
109
+ Exact content:
110
+
111
+ ```cpp
112
+ /*
113
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
114
+ *
115
+ * This source code is licensed under the MIT license found in the
116
+ * LICENSE file in the root directory of this source tree.
117
+ */
118
+
119
+ #ifndef HERMES_VM_JIT_JITCURARCH_H
120
+ #define HERMES_VM_JIT_JITCURARCH_H
121
+
122
+ #include "hermes/VM/JIT/Config.h"
123
+
124
+ #if HERMESVM_JIT
125
+
126
+ #if defined(__aarch64__) || defined(_M_ARM64)
127
+
128
+ #include "hermes/VM/JIT/arm64/JIT.h"
129
+
130
+ #include "arm64/JitEmitter.h"
131
+ #include "arm64/JitImpl.h"
132
+
133
+ /// The namespace containing the current architecture's JIT backend. The
134
+ /// shared compiler driver (JitCompiler.cpp) is compiled inside this
135
+ /// namespace, so its unqualified references to Emitter, JITContext, FR,
136
+ /// FRType, etc. resolve to the current backend's types.
137
+ #define HERMESVM_JIT_ARCH_NS arm64
138
+
139
+ #else
140
+ #error "JitCurArch.h: unsupported JIT architecture"
141
+ #endif
142
+
143
+ #endif // HERMESVM_JIT
144
+ #endif // HERMES_VM_JIT_JITCURARCH_H
145
+ ```
146
+
147
+ Rationale recorded in the spec: the Compiler is a *nested private class*
148
+ of each arch's `JITContext`, so a `using CurEmitter = ...` alias cannot
149
+ express it; compiling the shared file inside the arch namespace moves the
150
+ code with zero identifier changes.
151
+
152
+ - [ ] **Step 2: Create `lib/VM/JIT/JitCompiler.cpp`**
153
+
154
+ Open `lib/VM/JIT/arm64/JIT.cpp` and locate the boundaries of the moved
155
+ block:
156
+ - START: the comment line `// Calculate the address of the next
157
+ instruction given the name of the` (currently line 57, immediately
158
+ after the closing brace of `JITContext::markRoots`).
159
+ - END: the closing brace of `Compiler::emitCreateRegExp` (currently line
160
+ 1374, immediately before `} // namespace arm64`).
161
+
162
+ Create `JitCompiler.cpp` with this frame, pasting the block **verbatim**
163
+ (no reflowing, no comment edits) where indicated:
164
+
165
+ ```cpp
166
+ /*
167
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
168
+ *
169
+ * This source code is licensed under the MIT license found in the
170
+ * LICENSE file in the root directory of this source tree.
171
+ */
172
+
173
+ /// \file
174
+ /// The arch-independent JIT compiler driver: bytecode decode, basic-block
175
+ /// walk, label management and error handling. It contains no assembly; it
176
+ /// forwards to the current arch's Emitter, whose namespace is selected by
177
+ /// JitCurArch.h. Compiled once per binary, for exactly one arch.
178
+
179
+ #include "hermes/VM/JIT/Config.h"
180
+ #if HERMESVM_JIT
181
+ #include "JitCurArch.h"
182
+
183
+ #include "hermes/Inst/InstDecode.h"
184
+ #include "hermes/VM/JIT/DiscoverBB.h"
185
+ #include "hermes/VM/RuntimeModule.h"
186
+ #include "hermes/VM/StringPrimitiveValueDenseMapInfo-inline.h"
187
+
188
+ #define DEBUG_TYPE "jit"
189
+
190
+ namespace hermes {
191
+ namespace vm {
192
+ namespace HERMESVM_JIT_ARCH_NS {
193
+
194
+ // <<< PASTE the moved block (old JIT.cpp lines 57-1374) here, verbatim >>>
195
+
196
+ } // namespace HERMESVM_JIT_ARCH_NS
197
+ } // namespace vm
198
+ } // namespace hermes
199
+ #endif // HERMESVM_JIT
200
+ ```
201
+
202
+ The moved block starts with the `NEXTINST`/`IPADD`/`ID`/`JIT_INLINE`
203
+ macro definitions and contains, in order: the `class JITContext::Compiler`
204
+ definition, `JITContext::compileImpl`, `Compiler::compileCodeBlock`,
205
+ `Compiler::compileCodeBlockImpl`, and every `Compiler::emit*` method
206
+ through `emitCreateRegExp`.
207
+
208
+ - [ ] **Step 3: Shrink `lib/VM/JIT/arm64/JIT.cpp`**
209
+
210
+ Delete the moved block from `JIT.cpp`. The remaining file is exactly:
211
+
212
+ ```cpp
213
+ /*
214
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
215
+ *
216
+ * This source code is licensed under the MIT license found in the
217
+ * LICENSE file in the root directory of this source tree.
218
+ */
219
+
220
+ #include "hermes/VM/JIT/Config.h"
221
+ #if HERMESVM_JIT
222
+ #include "hermes/VM/JIT/arm64/JIT.h"
223
+
224
+ #include "JitImpl.h"
225
+
226
+ #define DEBUG_TYPE "jit"
227
+
228
+ namespace hermes {
229
+ namespace vm {
230
+ namespace arm64 {
231
+
232
+ JITContext::JITContext(bool enable) : enabled_(enable) {
233
+ if (!enable)
234
+ return;
235
+ impl_ = std::make_unique<Impl>();
236
+ }
237
+
238
+ JITContext::~JITContext() = default;
239
+
240
+ void JITContext::setHCIdLimit(uint32_t hcIdLimit) {
241
+ if (impl_)
242
+ impl_->hcIdLimit = std::min<uint32_t>(hcIdLimit, Impl::kHCIdOverflow);
243
+ }
244
+
245
+ void JITContext::dumpCounters(llvh::raw_ostream &os) {
246
+ static constexpr const char *kCounterNames[] = {
247
+ #define COUNTER_NAME(name) #name,
248
+ JIT_COUNTERS(COUNTER_NAME)
249
+ #undef COUNTER_NAME
250
+ };
251
+ for (unsigned i = 0; i < (unsigned)JitCounter::_Last; ++i)
252
+ os << kCounterNames[i] << ": " << counters_[i] << "\n";
253
+ }
254
+
255
+ void JITContext::markRoots(
256
+ RootAcceptorWithNames &acceptor,
257
+ bool markLongLived) {
258
+ if (!impl_)
259
+ return;
260
+ acceptor.accept(impl_->usedHCs);
261
+ }
262
+
263
+ } // namespace arm64
264
+ } // namespace vm
265
+ } // namespace hermes
266
+ #endif // HERMESVM_JIT
267
+ ```
268
+
269
+ Note the include set: `JitEmitter.h`, `InstDecode.h`, `DiscoverBB.h`,
270
+ `RuntimeModule.h`, and `StringPrimitiveValueDenseMapInfo-inline.h` are no
271
+ longer needed here and are dropped; `JitImpl.h` stays (`Impl` must be
272
+ complete for the ctor/dtor and `markRoots`). If the compiler reports a
273
+ missing type in this file, add back the *single* header that provides it
274
+ rather than restoring the whole include list.
275
+
276
+ - [ ] **Step 4: Add the new files to the build**
277
+
278
+ In `lib/VM/CMakeLists.txt`, inside the `if (HERMESVM_ALLOW_JIT)` source
279
+ list, change the line
280
+
281
+ ```
282
+ JIT/JitHandlers.cpp JIT/JitHandlers.h
283
+ ```
284
+
285
+ to
286
+
287
+ ```
288
+ JIT/JitHandlers.cpp JIT/JitHandlers.h
289
+ JIT/JitCompiler.cpp JIT/JitCurArch.h
290
+ ```
291
+
292
+ - [ ] **Step 5: Build**
293
+
294
+ Run:
295
+ ```bash
296
+ cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target hermes -j "$(nproc)"
297
+ ```
298
+ Expected: clean build. Likely first-attempt errors and their fixes:
299
+ - "member access into incomplete type" in `JitCompiler.cpp` → a header
300
+ that `arm64/JIT.cpp` previously included transitively is missing; add
301
+ it to `JitCompiler.cpp`'s include list.
302
+ - Duplicate symbol at link → part of the moved block was left behind in
303
+ `arm64/JIT.cpp`; delete it there, never by editing the copy in
304
+ `JitCompiler.cpp`.
305
+
306
+ - [ ] **Step 6: Byte-identical gate**
307
+
308
+ Run:
309
+ ```bash
310
+ QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \
311
+ /home/tmikov/work/hermes-x86-jit/utils/jit/jit-dump.sh -q \
312
+ -o /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-after.dump \
313
+ /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/bin/hermes
314
+ /home/tmikov/work/hermes-x86-jit/utils/jit/jit-diff.sh --dumps \
315
+ /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-baseline.dump \
316
+ /home/tmikov/work/hermes-x86-jit/cmake-build-arm64/jit-after.dump
317
+ ```
318
+ Expected: exit 0, dumps identical — including comments (do NOT pass
319
+ `--comments-ok`; the moved code contains the comment-emitting paths, so
320
+ comment drift would also indicate a real change). Any difference at all
321
+ means the move was not verbatim: diff the moved block against git history
322
+ (`git diff HEAD -- lib/VM/JIT/arm64/JIT.cpp lib/VM/JIT/JitCompiler.cpp`)
323
+ and fix the discrepancy; do not rationalize differences away.
324
+
325
+ - [ ] **Step 7: Prove the gate can fail**
326
+
327
+ Temporarily change, in `JitCompiler.cpp`, the body of `emitLoadConstZero`
328
+ from
329
+
330
+ ```cpp
331
+ em_.loadConstDouble(FR(inst->op1), 0, "Zero");
332
+ ```
333
+
334
+ to
335
+
336
+ ```cpp
337
+ em_.loadConstDouble(FR(inst->op1), 1, "Zero");
338
+ ```
339
+
340
+ Rebuild, re-run Step 6's capture+diff (to a throwaway output file).
341
+ Expected: `jit-diff.sh` exits 1 and reports instruction differences.
342
+ Then **revert the change**, rebuild, and re-run Step 6 verbatim.
343
+ Expected: exit 0 again. This proves the pipeline is actually comparing
344
+ emitted code.
345
+
346
+ - [ ] **Step 8: Functional gates**
347
+
348
+ Run:
349
+ ```bash
350
+ /home/tmikov/work/hermes-x86-jit/aarch64/qemu-sanity.sh
351
+ LIT_FILTER="jit/" cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-arm64 --target check-hermes -j "$(nproc)"
352
+ ```
353
+ Expected: sanity 9/9 passed; lit shows `Expected Passes: 46`,
354
+ `Unsupported Tests: 1`.
355
+
356
+ - [ ] **Step 9: Confirm non-JIT builds are unaffected**
357
+
358
+ Run:
359
+ ```bash
360
+ cmake --build /home/tmikov/work/hermes-x86-jit/cmake-build-host --target hermes -j "$(nproc)"
361
+ ```
362
+ Expected: clean build (this x86-64 host build has the JIT off; the new
363
+ files must compile to nothing under `#if HERMESVM_JIT` being 0 — note
364
+ `HERMESVM_ALLOW_JIT` is not set for this tree, so they are not even
365
+ listed; the point is the CMake edit broke nothing).
366
+
367
+ - [ ] **Step 10: Commit**
368
+
369
+ ```bash
370
+ git -C /home/tmikov/work/hermes-x86-jit add lib/VM/JIT/JitCurArch.h \
371
+ lib/VM/JIT/JitCompiler.cpp lib/VM/JIT/arm64/JIT.cpp lib/VM/CMakeLists.txt
372
+ git -C /home/tmikov/work/hermes-x86-jit commit -m "JIT: Move the compiler driver to a shared file
373
+
374
+ The Compiler nested class -- bytecode decode, BB walk, labels, error
375
+ paths -- contains no assembly and forwards to the Emitter, so it is
376
+ arch-independent by construction. Move it verbatim from arm64/JIT.cpp
377
+ to lib/VM/JIT/JitCompiler.cpp, compiled inside the arch namespace
378
+ selected by the new JitCurArch.h. arm64/JIT.cpp keeps only the
379
+ JITContext housekeeping methods.
380
+
381
+ This is milestone 0 of the x86-64 backend plan: the emitter method
382
+ surface becomes the compiler-enforced porting contract, and the
383
+ x86-64 backend will plug in as a second branch in JitCurArch.h.
384
+
385
+ Verified byte-identical emission over the jit-dump corpus, plus
386
+ qemu-sanity 9/9 and test/jit 46+1 under qemu.
387
+
388
+ Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>"
389
+ ```
390
+
391
+ ---
392
+
393
+ ### Task 3: Update the docs to match
394
+
395
+ **Files:**
396
+ - Modify: `doc/JIT.md` (source-layout table row for `JIT.cpp`, ~line 37;
397
+ porting-notes bullet about arch-independent pieces, ~line 498)
398
+ - Modify: `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`
399
+ (the shared-by-construction bullet's mechanism description)
400
+
401
+ **Interfaces:** documentation only.
402
+
403
+ - [ ] **Step 1: Update the `doc/JIT.md` source-layout table**
404
+
405
+ Replace the row
406
+
407
+ ```
408
+ | `lib/VM/JIT/arm64/JIT.cpp` | `JITContext::Compiler`: per-opcode `emitXXX` methods that decode operands and forward to the `Emitter`. Drives BB-by-BB compilation. |
409
+ ```
410
+
411
+ with
412
+
413
+ ```
414
+ | `lib/VM/JIT/JitCompiler.cpp` | `JITContext::Compiler`: per-opcode `emitXXX` methods that decode operands and forward to the `Emitter`. Drives BB-by-BB compilation. Arch-independent; compiled inside the arch namespace selected by `JitCurArch.h`. |
415
+ | `lib/VM/JIT/arm64/JIT.cpp` | `JITContext` housekeeping: construction, `setHCIdLimit`, `dumpCounters`, `markRoots`. |
416
+ ```
417
+
418
+ - [ ] **Step 2: Update the porting-notes bullet in `doc/JIT.md`**
419
+
420
+ Replace
421
+
422
+ ```
423
+ - **Arch-independent pieces** usable as-is: DiscoverBB, RuntimeOffsets,
424
+ PerfJitDump, JitHandlers and JitCounters (both already moved out of
425
+ `arm64/`), the Compiler driver in JIT.cpp (contains no assembly; it could
426
+ move to a shared location or be duplicated with the namespace changed).
427
+ ```
428
+
429
+ with
430
+
431
+ ```
432
+ - **Arch-independent pieces** usable as-is: DiscoverBB, RuntimeOffsets,
433
+ PerfJitDump, JitHandlers, JitCounters, and the Compiler driver
434
+ (JitCompiler.cpp) -- all now outside `arm64/`. A new backend implements
435
+ the Emitter method surface and adds its branch to `JitCurArch.h`; the
436
+ driver then compiles against it unchanged.
437
+ ```
438
+
439
+ - [ ] **Step 3: Correct the mechanism description in the spec**
440
+
441
+ In `doc/superpowers/specs/2026-08-23-x86-64-jit-design.md`, in the
442
+ "Shared by construction" bullet, replace the parenthetical
443
+
444
+ ```
445
+ (`JitCurArch.h`: `using CurEmitter =
446
+ arm64::Emitter;` / `x86_64::Emitter` under the same `#if`s as
447
+ `JIT/JIT.h`). Not a template: only one arch is ever compiled per binary,
448
+ ```
449
+
450
+ with
451
+
452
+ ```
453
+ (`JitCurArch.h` defines `HERMESVM_JIT_ARCH_NS` and includes the arch's
454
+ emitter headers under the same `#if`s as `JIT/JIT.h`; the driver is
455
+ compiled inside that namespace, so the Compiler stays a nested private
456
+ class of the arch's `JITContext` with zero identifier changes -- a
457
+ `using` alias cannot express a nested class). Not a template: only one
458
+ arch is ever compiled per binary,
459
+ ```
460
+
461
+ - [ ] **Step 4: Commit**
462
+
463
+ ```bash
464
+ git -C /home/tmikov/work/hermes-x86-jit add doc/JIT.md \
465
+ doc/superpowers/specs/2026-08-23-x86-64-jit-design.md
466
+ git -C /home/tmikov/work/hermes-x86-jit commit -m "doc: JIT.md and x86-64 spec updates for the shared compiler driver
467
+
468
+ Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>"
469
+ ```
470
+
471
+ ---
472
+
473
+ ## Out of scope for this plan
474
+
475
+ Milestones 1-6 of the spec (the x86-64 tree itself) each get their own
476
+ plan, written when the preceding milestone completes. Nothing in this
477
+ plan creates any x86-64 code; `JitCurArch.h`'s `#error` branch is the
478
+ placeholder the milestone-1 plan replaces.