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,239 @@
|
|
|
1
|
+
# Implementation Progress
|
|
2
|
+
|
|
3
|
+
Tracks progress of `doc/plans/ir-type/phase1-steps.md` for
|
|
4
|
+
`doc/plans/ir-type/ir-type-system-v2-design.md` and
|
|
5
|
+
`doc/plans/ir-type/ir-type-v2-implementation.md`.
|
|
6
|
+
|
|
7
|
+
The file has two sections: "Status" and "Context Notes".
|
|
8
|
+
|
|
9
|
+
**Status Section**:
|
|
10
|
+
|
|
11
|
+
Each row contains the step label from the detailed, plan, a brief description, list of
|
|
12
|
+
dependency labels, Status (initially empty), optional brief note (initially empty).
|
|
13
|
+
|
|
14
|
+
The status of a row is one of:
|
|
15
|
+
- "" (empty) initially, before work has started
|
|
16
|
+
- "wip" as soon as work on that raw has started.
|
|
17
|
+
- "done" when work has completed successfully. Rarely "Brief Note" may contain very brief
|
|
18
|
+
explanation. More details in "Context Notes".
|
|
19
|
+
- "blocked" when work cannot proceed for some reason. "Brief Note" must contain a brief
|
|
20
|
+
explanation. More details in "Context Notes".
|
|
21
|
+
|
|
22
|
+
Example on start:
|
|
23
|
+
|
|
24
|
+
| Step 11 | Port util binding | 5 | | |
|
|
25
|
+
|
|
26
|
+
**Context Notes**:
|
|
27
|
+
|
|
28
|
+
After completing work on a step, either successfully or by blocking, a section for that
|
|
29
|
+
step is added. It needs to have the format from the following example (empty bullets can
|
|
30
|
+
be omitted):
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
### Step 11: Port util binding
|
|
34
|
+
- **Files**: created `foo.c`, modified `bar.c`.
|
|
35
|
+
- **Decisions**:
|
|
36
|
+
-- Decision 1 concise explanation
|
|
37
|
+
-- Decision 2 concise explanation
|
|
38
|
+
- **What was done**: ...
|
|
39
|
+
- **Issues**: ...
|
|
40
|
+
- **Notes for next step**: ...
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Status
|
|
44
|
+
|
|
45
|
+
| Step | Description | Depends On | Status | Brief Note (optional) |
|
|
46
|
+
|------|-------------|------------|--------|-----------------------|
|
|
47
|
+
| P1-S1 | TypeContext skeleton with well-known types | — | done | |
|
|
48
|
+
| P1-S2 | Type queries on TypeContext | P1-S1 | done | |
|
|
49
|
+
| P1-S3 | Type operations with interning | P1-S2 | done | |
|
|
50
|
+
| P1-S4 | Utility methods | P1-S3 | done | |
|
|
51
|
+
| P1-S5 | Thread-local context and RAII guard | P1-S1 | done | |
|
|
52
|
+
| P1-S6 | Wire TypeContext into Module | P1-S1 | done | |
|
|
53
|
+
| P1-S7 | Install RAII guards at compilation entry points | P1-S5, P1-S6 | done | |
|
|
54
|
+
| P1-S7.5 | Add RAII guards to unit tests | P1-S7 | done | |
|
|
55
|
+
| P1-S8 | Rewrite Type class | P1-S4, P1-S7.5 | done | |
|
|
56
|
+
| P2-S1 | Foundation: accessors and conventions | P1-S8 | done | |
|
|
57
|
+
| P2-S2 | Migrate IRVerifier to explicit context | P2-S1 | done | |
|
|
58
|
+
| P2-S3 | Migrate Instrs.{h,cpp} and IR.cpp | P2-S1 | done | |
|
|
59
|
+
| P2-S4 | Migrate IRGen (ESTreeIRGen-*.cpp) | P2-S1 | done | |
|
|
60
|
+
| P2-S5 | Migrate InstSimplify pass | P2-S1 | done | |
|
|
61
|
+
| P2-S6 | Migrate TypeInference pass (heaviest) | P2-S1 | done | |
|
|
62
|
+
| P2-S7 | Migrate remaining optimizer + BCGen | P2-S1 | done | |
|
|
63
|
+
| P2-S8 | Migrate test fixtures | P2-S1 | done | |
|
|
64
|
+
| P2-S8.5 | Migrate IRPrinter (Dumper) off TLS Type printing | P2-S1 | done | |
|
|
65
|
+
| P2-S9 | Remove TLS infrastructure | P2-S8.5 | done | |
|
|
66
|
+
|
|
67
|
+
## Context Notes
|
|
68
|
+
|
|
69
|
+
### P2-S1: Foundation — accessors and conventions
|
|
70
|
+
- **Files**: modified `include/hermes/IR/IRBuilder.h`, `lib/IRGen/ESTreeIRGen.h`, `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `unittests/IR/TypeContextTest.cpp`.
|
|
71
|
+
- **What was done**: Added `IRBuilder::getTypeContext()` and `ESTreeIRGen::getTypeContext()` accessors. Renamed `TypeContext::format` → `TypeContext::print` (matches `Type::print`). Added missing operations on TypeContext to reach API parity with TLS-using `Type` methods: `canBeAny`, `canBeType`, `isProperSubsetOf`, `isKnownPrimitiveType`, plus the `arms()` range adapter (returns `ArmRange` over a Type — yields the type itself for non-unions, each arm for unions, nothing for NoType). 4 new unit tests (42 total `TypeContextTest` cases). Phase 2 row added to status table for tracking.
|
|
72
|
+
- **Decisions**:
|
|
73
|
+
- `ArmRange` and its iterator store the raw `uint32_t typeId_` instead of `Type` because `Type` is forward-declared in `TypeContext.h` (definition is in `IR.h`, which includes `TypeContext.h`). Methods that touch `Type` (`arms()`, `iterator::operator*`, `ArmRange::end`) are out-of-line in `TypeContext.cpp` where `Type` is complete. Same pattern as the existing `getUnionArms`.
|
|
74
|
+
- The new helpers (`canBeAny`, `canBeType`, etc.) are also out-of-line for the same incomplete-type reason. Once Phase 2 is complete and Type loses its TLS-using methods, the layering can be revisited but it's not necessary.
|
|
75
|
+
- `print` chosen over `format` for naming consistency with `Type::print` and `llvh::raw_ostream` conventions; `format` would have implied "build a string".
|
|
76
|
+
- No callers migrated yet — the TLS-using methods on `Type` remain intact so the build stays green throughout P2-S2…P2-S8.
|
|
77
|
+
|
|
78
|
+
### P2-S8.5: Migrate IRPrinter (Dumper) off TLS Type printing
|
|
79
|
+
- **Files**: modified `include/hermes/Utils/Dumper.h`, `lib/Utils/Dumper.cpp`.
|
|
80
|
+
- **What was done**: Added a `Module *currentModule_` member to `IRPrinter`, set in `visitFunction` from `F.getParent()`. Migrated the three sites that previously relied on `Type::print(OS)`'s TLS lookup to format pretty type names: `printTypeLabel` (value types), `printFunctionHeader` (function return types), and the `LiteralIRType` operand branch in `printValueLabel` (the `type(...)` syntax in IR dumps). Each new path uses `currentModule_->getTypeContext().print(os_, t)`; falls back to the old `os_ << t` path when `currentModule_` is null.
|
|
81
|
+
- **Decisions**:
|
|
82
|
+
- This is a missed migration step — should have happened during P2-S2…P2-S8 alongside the rest of the subsystem migrations. The greps used to find TLS callers searched for `Type::xxx` and `t.canBeX()` patterns and missed the implicit `os << type` pattern through `operator<<(raw_ostream &, Type)`. Adding it as P2-S8.5 keeps the cleanup commit (P2-S9) a pure dead-code deletion.
|
|
83
|
+
- No behavior change: while TLS is still installed (which it is up through this commit), both the new `currentModule_` path and the old `operator<<` path produce the same pretty-printed names.
|
|
84
|
+
|
|
85
|
+
### P2-S9: Remove TLS infrastructure
|
|
86
|
+
- **Files**: modified `include/hermes/IR/IR.h`, `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `unittests/IR/TypeContextTest.cpp`. Deleted `TypeContextRAII typeContextGuard(...)` lines from 4 production files (`lib/BCGen/HBC/HBC.cpp`, `lib/BCGen/HBC/BCProviderFromSrc.cpp`, `lib/CompilerDriver/CompilerDriver.cpp`, `tools/shermes/shermes.cpp`) and 17 unittests/API files via sed.
|
|
87
|
+
- **What was deleted**:
|
|
88
|
+
- `TypeContextRAII` class entirely.
|
|
89
|
+
- `TypeContext::current_`, `current()`, `hasCurrent()`.
|
|
90
|
+
- All TLS-using `Type::xxx` delegation methods: `unionTy`, `intersectTy`, `subtractTy`, `getFirstTypeKind`, `countTypes`, `isPrimitive`, `canBePrimitive`, `isNonPtr`, `isSubsetOf`, `canBeString/BigInt/Symbol/Number/Object/Boolean/Empty/Uninit/Undefined/Null/Any`. Convenience inline methods on Type that built on these (`isKnownPrimitiveType`, `canBeType`, `isProperSubsetOf`) also removed.
|
|
91
|
+
- `Type::iterator` class entirely.
|
|
92
|
+
- Two TLS-specific tests in `TypeContextTest.cpp` (`CurrentWithGuard`, `NestedGuards`); the `PrintWithoutGuardFallback` test renamed to `PrintFallback` and rewritten to assert the unconditional placeholder format.
|
|
93
|
+
- **What was kept on Type**:
|
|
94
|
+
- All `is*Type()` (id-equality), `operator==/!=`, `hash`, `Profile`, all `createXxx()` constexpr factories.
|
|
95
|
+
- `Type::print(OS)` retained as a minimal placeholder (`type#<id>`) for diagnostic streams that have no `TypeContext` available.
|
|
96
|
+
- **Decisions**:
|
|
97
|
+
- The `operator<<(raw_ostream &, Type)` overload (in `IR.cpp`) was kept and now always prints the `type#<id>` placeholder. Pretty-printed type names require an explicit `TypeContext::print(os, t)` call (or for IR dumps, the `IRPrinter::currentModule_` plumbing added in P2-S8.5).
|
|
98
|
+
- `TypeInference`'s `LLVM_DEBUG(dbgs() << inst->getType())` calls were left as-is. They now print `type#<id>` instead of pretty names in `--debug-only=typeinference` output, which is acceptable for debug-only diagnostics.
|
|
99
|
+
|
|
100
|
+
### P2-S8: Migrate test fixtures (and a stray IREval helper)
|
|
101
|
+
- **Files**: modified `unittests/IR/BuilderTest.cpp`, `lib/IR/IREval.cpp`.
|
|
102
|
+
- **What was done**: Migrated the only two TLS-using `Type` calls left in test code: `X->getType().isPrimitive()` in `BuilderTest::TestValueTypes` (now `M.getTypeContext().isPrimitive(...)`) and the body of `BuilderTest::Types` (now uses a local `TypeContext tc;` and calls `tc.unionTy(...)` / `tc.isPrimitive(...)` directly, dropping the now-unnecessary RAII guard for that test). All other test-fixture call sites already used the new explicit-context API; they only retain `TypeContextRAII` install lines, which P2-S9 deletes.
|
|
103
|
+
- **Bonus**: `lib/IR/IREval.cpp::disjointComparisonTypes` was a free helper missed by earlier passes (it is in `lib/IR`, not `lib/Optimizer` or `lib/BCGen`). Threaded `TypeContext &tc` as the first parameter; the single caller in `evalBinaryOperator` passes `builder.getTypeContext()`.
|
|
104
|
+
- **Decisions**:
|
|
105
|
+
- Left the per-fixture `TypeContextRAII typeContextGuard(M.getTypeContext())` lines untouched. They still keep TLS valid for the unmigrated `Type` delegation methods that remain in P2-S8 state. P2-S9 deletes both the RAII class and these install sites in one motion.
|
|
106
|
+
- In `BuilderTest::Types` the test never wraps a Module — it constructed a standalone `TypeContext` and installed the RAII guard purely to support `Type::unionTy`. With the explicit API the RAII guard is redundant; it is removed in this step (the only test fixture in P2-S8 that drops a guard early).
|
|
107
|
+
|
|
108
|
+
### P2-S7: Migrate remaining optimizer + BCGen
|
|
109
|
+
- **Files**: modified `lib/Optimizer/Scalar/{ObjectMergeNewStores,ObjectStackPromotion,TDZDedup,Inlining,FunctionAnalysis,Auditor}.cpp`, `lib/BCGen/{Lowering,RegAlloc}.cpp`, `lib/BCGen/HBC/{ISel,Passes}.cpp`, `lib/BCGen/HBC/Passes/PeepholeLowering.cpp`, `lib/BCGen/SH/{LowerNanBoxedUnionNarrowT,SHRegAlloc,RecreateCheapValues,SH}.cpp`, `lib/BCGen/facebook/Mins/{LowerNanBoxedUnionNarrowT,RecreateCheapValues,Mins}.cpp`.
|
|
110
|
+
- **What was done**: Migrated all remaining TLS-using `Type` calls in the optimizer and BCGen subsystems. Three patterns:
|
|
111
|
+
1. Per-call lookup via an existing carrier: `builder.getTypeContext().foo(t)` (Lowering, ObjectMergeNewStores, RecreateCheapValues, LowerNanBoxedUnionNarrowT, ObjectStackPromotion, TDZDedup, Inlining), or `inst->getModule()->getTypeContext().foo(t)` (RegAlloc, ISel, SHRegAlloc, Auditor).
|
|
112
|
+
2. Stored member: SH.cpp's `InstrGen` got a `TypeContext &typeCtx_` initialized inline from `F_.getParent()->getTypeContext()`; PeepholeLowering threaded `tc` through `irTypeToTypeOfIsTypes` and used `builder_.getTypeContext()` in `lowerCheckedTypeCast`.
|
|
113
|
+
3. Threaded parameter: free helpers (`isAnalyzableVariable` in FunctionAnalysis, `canCompareStrictEqualityRaw` in SH.cpp and Mins.cpp) gained a leading `TypeContext &tc` parameter.
|
|
114
|
+
Replaced two more inline `Type::unionTy(Object, Undefined)` and `Type::unionTy(Empty, Uninit)` sites with the well-known constexpr factories from P2-S3.
|
|
115
|
+
- **Decisions**:
|
|
116
|
+
- SH.cpp's `_typeCastHelper` now iterates `typeCtx_.arms(checkTypes)` instead of relying on `Type::iterator`'s TLS-using dereference. This was the single user of that iterator outside of the Type class itself.
|
|
117
|
+
- Marked the unused `canCompareStrictEqualityRaw` in `lib/BCGen/facebook/Mins/Mins.cpp` as `[[maybe_unused]]`. It was already dead but still compiled (no static-unused warning was firing); migrating preserves it for whenever the Mins backend wires it back up.
|
|
118
|
+
- Dropped the redundant `assert` in `setInvalidTypes` in P2-S3 already; the corresponding asserts in `_typeCastHelper`/`generateThrowIfInst` (which still exist) now use the explicit context.
|
|
119
|
+
|
|
120
|
+
### P2-S6: Migrate TypeInference pass
|
|
121
|
+
- **Files**: modified `lib/Optimizer/Scalar/TypeInference.cpp`.
|
|
122
|
+
- **What was done**: Added `TypeContext &typeCtx_` member to `TypeInferenceImpl` (initialized via `M->getTypeContext()` in a new explicit constructor) and updated `TypeInference::runOnModule` to pass the Module. Threaded `TypeContext &tc` as the first parameter through eight file-scope helpers: `isBigIntOrObject`, `inferUnaryArith`, `inferUnaryArithDefault`, `inferTilde`, `inferMemoryLocationType`, `inferBinaryArith`, `inferBinaryBitwise`, `inferBinaryInst`. Migrated the remaining inline call sites in member methods (`inferPhi` union, `inferToPropertyKeyInst`, `inferThrowIfInst`, `inferUnionNarrowTrustedInst`, `inferCheckedTypeCastInst`, parameter type union, return type union, and the post-pass intersection in the prePassTypes narrowing).
|
|
123
|
+
- **Decisions**:
|
|
124
|
+
- Threaded `TypeContext &tc` as a parameter to the file-scope helpers rather than moving them into the impl class. The helpers are already self-contained and just gained one extra leading parameter; relocating would have meant a larger restructure for marginal benefit.
|
|
125
|
+
- Replaced one inline `Type::unionTy(Type::createObject(), Type::createUndefined())` with the well-known `Type::createObjectOrUndef()` factory added in P2-S3, and one `Type::unionTy(String, Symbol)` with `Type::createStringOrSymbol()` — both eliminate context lookups for fixed types.
|
|
126
|
+
|
|
127
|
+
### P2-S5: Migrate InstSimplify pass
|
|
128
|
+
- **Files**: modified `lib/Optimizer/Scalar/InstSimplify.cpp`.
|
|
129
|
+
- **What was done**: Added `TypeContext &typeCtx_` member to `InstSimplifyImpl`, initialized from `builder_.getTypeContext()` in the constructor. Migrated the 12 TLS-using call sites: `canBeNumber`, `isPrimitive` (×2), `canBeUndefined`, `canBeObject`, `isSubsetOf` (×6 — equality/inequality fast paths, CoerceThisNS short-circuit, UnionNarrowTrusted no-op, CheckedTypeCast widening), `intersectTy` (×6 — strict equality, ThrowIf invalidation, CheckedTypeCast result computation), `isKnownPrimitiveType` (×2 — equality promotion). The free `notNaN` helper grew a `TypeContext &` parameter (only one caller, threaded `typeCtx_`).
|
|
130
|
+
- **Decisions**:
|
|
131
|
+
- Stored `TypeContext &` directly even though `builder_.getTypeContext()` is one indirection: 12 use sites and the InstSimplifyImpl is constructed once per function, so caching reduces repetition without measurable cost.
|
|
132
|
+
- The `kNullOrUndef` constexpr at file scope is unchanged — it is just a cheap constant Type tag and works fine as a constexpr.
|
|
133
|
+
|
|
134
|
+
### P2-S4: Migrate IRGen (ESTreeIRGen-*.cpp)
|
|
135
|
+
- **Files**: modified `lib/IRGen/ESTreeIRGen.h`, `lib/IRGen/ESTreeIRGen.cpp`, `lib/IRGen/ESTreeIRGen-func.cpp`, `lib/IRGen/ESTreeIRGen-expr.cpp`, `lib/IRGen/ESTreeIRGen-typed-class.cpp`.
|
|
136
|
+
- **What was done**: Migrated every TLS-using `Type` call in IRGen to the explicit `getTypeContext().foo(t, ...)` form (or to a local `TypeContext &tc` reference where the same context is used multiple times in a small scope). Affected operations: `unionTy` (×7 sites in func and expr), `subtractTy` (×2 in ESTreeIRGen.cpp), `isSubsetOf` (×3 in expr), `canBePrimitive` (×2), `isNonPtr` (×4), and the assertion-flow comparison in `enforceExprType`.
|
|
137
|
+
- **Decisions**:
|
|
138
|
+
- Made `ESTreeIRGen::flowTypeToIRType` non-static (was `static`). It needs `getTypeContext()` for the `Union` arm, and `static` would have meant either threading TypeContext through every caller or special-casing the union case. All callers were already on instances — no caller change required.
|
|
139
|
+
- Did not add new well-known unions for the TDZ shapes (`AnyType | Empty`, `irType | Undefined`, etc.) even though some appear three times. The dynamic forms (`irType | Undefined`) need real interning anyway, and the constant ones (`AnyType | Empty`) are infrequent enough that one extra well-known per shape is not worth the bloat.
|
|
140
|
+
- For methods that use the context just once, used `getTypeContext().foo(...)` inline. For the few sites that use it multiple times in short scope (`enforceExprType`, the union loop in `flowTypeToIRType`, the `Optional` field flow in expr.cpp), introduced a local `TypeContext &tc` reference.
|
|
141
|
+
|
|
142
|
+
### P2-S3: Migrate Instrs.{h,cpp} and IR.cpp
|
|
143
|
+
- **Files**: modified `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `include/hermes/IR/IR.h`, `include/hermes/IR/Instrs.h`, `lib/IR/IR.cpp`, `lib/IR/Instrs.cpp`, `lib/IR/IRBuilder.cpp`, `unittests/IR/TypeContextTest.cpp`.
|
|
144
|
+
- **What was done**:
|
|
145
|
+
- Added 4 new well-known union IDs to `TypeContext`: `kStringOrSymbolId`, `kEmptyOrUninitId`, `kObjectOrNullId`, `kObjectOrUndefId`. Each is pre-allocated in the constructor and added to the intern table. Added matching `Type::createXxx()` constexpr factories.
|
|
146
|
+
- Replaced inline header `Type::unionTy(constant, constant)` calls with the new constexpr factories: `ToPropertyKeyInst`, `LoadParentNoTrapsInst::getInherentTypeImpl`, `functionNewTargetType` (in IR.cpp).
|
|
147
|
+
- `ThrowIfInst`: removed the constructor-side `Type::subtractTy` call and the assertion that uses TLS-based `.isSubsetOf`. Added a `resultType` parameter to the constructor; `IRBuilder::createThrowIfInst` now computes the result type via `tc.subtractTy` and asserts the precondition. Dropped the now-redundant assert in `setInvalidTypes` (only one external caller, InstSimplify, and it derives `invalidSubset` via `intersectTy` so the invariant is preserved).
|
|
148
|
+
- `BinaryOperatorInst::getBinarySideEffect`: added `TypeContext &tc` as the first parameter; updated the two callers (in `Instrs.h`) to pass `getModule()->getTypeContext()`.
|
|
149
|
+
- `UnaryOperatorInst::getSideEffectImpl`, `PhiInst::addEntry`, `PhiInst::recalculateResultType`: switched from TLS-using calls to `getModule()->getTypeContext()`.
|
|
150
|
+
- `PhiInst::PhiInst` constructor: removed the implicit `recalculateResultType()` call (it would crash because the inst has no parent yet). The builder now calls `recalculateResultType()` after `insert()`. Made the method public for that.
|
|
151
|
+
- Updated `ReservedSlots` test to scan from `kObjectOrUndefId + 1`.
|
|
152
|
+
- **Decisions**:
|
|
153
|
+
- Added well-known IDs for fixed-shape unions used in inline headers. Avoids both threading TypeContext through dozens of constructors and creating fresh union entries at runtime; result is constexpr.
|
|
154
|
+
- Moved the type computation for `ThrowIfInst` into the builder rather than threading TypeContext through its constructor. The constructor's only computed type was `subtractTy(operand, invalidTypes)` — easier to do once at construction time in the builder than to thread context everywhere.
|
|
155
|
+
- Made `PhiInst::recalculateResultType` public rather than friending IRBuilder. It is logically a public operation (already exposed via `addEntry`/`removeEntry` side effects).
|
|
156
|
+
- For static helpers like `getBinarySideEffect`, threading `TypeContext &` as the first parameter is the natural fit — alternative (lookup via `getModule()` on a passed-in inst) would require passing the inst too.
|
|
157
|
+
|
|
158
|
+
### P2-S2: Migrate IRVerifier to explicit context
|
|
159
|
+
- **Files**: modified `include/hermes/IR/IR.h`, `lib/IR/IRVerifier.cpp`.
|
|
160
|
+
- **What was done**: Added `TypeContext &ctx_` member to the `Verifier` class, initialized from `M.getTypeContext()` in the constructor. Migrated 9 TLS-using call sites to the explicit `ctx_.foo(t, ...)` form (`canBeType`, `canBeEmpty` ×2, `canBeUninit`, `isSubsetOf` ×4, `unionTy`, `intersectTy`). Static factory calls (`Type::createNumber()` etc.) and `operator==` checks remain unchanged because they don't need a context.
|
|
161
|
+
- **Decisions**:
|
|
162
|
+
- Made `Module::typeContext_` `mutable` and `Module::getTypeContext()` `const`. The Verifier holds `const Module &` (it doesn't mutate IR), but TypeContext is a side-cache whose intern table grows with each `unionTy`/`intersectTy` call — the standard "logical const" pattern. This unblocks any future const-Module consumer that needs type operations.
|
|
163
|
+
- Stored `TypeContext &` directly rather than calling `M.getTypeContext()` at each use site: it's used in many methods, the reference is cheap to store, and it documents the dependency.
|
|
164
|
+
|
|
165
|
+
### P1-S2: Type queries on TypeContext
|
|
166
|
+
- **Files**: modified `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `unittests/IR/TypeContextTest.cpp`.
|
|
167
|
+
- **What was done**: Added `canBeNumber`, `canBeString`, `canBeObject`, `canBeNull`, `canBeUndefined`, `canBeEmpty`, `canBeUninit`, `canBeBigInt`, `canBeBoolean`, `canBeSymbol`, `isNoType`, `isPrimitive`, `canBePrimitive`, `isNonPtr`. Private helpers `containsMatchingKind` and `allMatchKind` take predicate functions for leaf/union dispatch. File-scoped kind helpers (`isNumberKind`, `isObjectKind`, `isPrimitiveKind`, `isNonPtrKind`) encode subtype relationships. 7 new unit tests (13 total).
|
|
168
|
+
- **Decisions**:
|
|
169
|
+
- Well-known ID fast paths in each `canBeX` method, per the plan spec. Avoids table lookups for common types.
|
|
170
|
+
- Kind helpers are subtype-aware: `isNumberKind` includes Int32/Uint32, `isObjectKind` includes ClassInstance/Array/Tuple/Function/ExactObject, `isPrimitiveKind` and `isNonPtrKind` include number subtypes. Refined kinds are dead code in Phase 1 but the predicates are correct when they activate.
|
|
171
|
+
- `isPrimitive`/`isNonPtr` return false for NoType, matching the old bitmask semantics (`bitmask_ && !(bitmask_ & ~BITS)`).
|
|
172
|
+
|
|
173
|
+
### P1-S3: Type operations with interning
|
|
174
|
+
- **Files**: modified `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `unittests/IR/TypeContextTest.cpp`.
|
|
175
|
+
- **What was done**: Added `isSubsetOf`, `areDisjoint`, `unionTy`, `intersectTy`, `subtractTy` public methods. Added `UnionInternKey`/`UnionInternKeyInfo` structs for DenseMap-based union interning. Private `createUnionImpl` handles full canonicalization (flatten, sort, dedup, subsume, intern). Static helpers `isLeafSubtype` and `areLeafKindsDisjoint` handle leaf-level type relationships including future-proof Number/Object family rules. Intern table pre-populated with well-known unions in constructor. 10 new unit tests (23 total TypeContext tests).
|
|
176
|
+
- **Decisions**:
|
|
177
|
+
- Used `DenseMap<UnionInternKey, uint32_t, UnionInternKeyInfo>` with SmallVector<uint32_t, 8> key and custom DenseMapInfo (sentinels use size-1 vectors with UINT32_MAX/UINT32_MAX-1, real keys always size >= 2).
|
|
178
|
+
- `isLeafSubtype` handles Int32/Uint32 <: Number and object refinements <: Object even though unused in Phase 1 — keeps algorithms correct when refined types arrive.
|
|
179
|
+
- `areLeafKindsDisjoint` uses the subtype check plus Number-family overlap rule; all other distinct kinds are disjoint.
|
|
180
|
+
- `subtractTy` returns conservative approximation (returns `a` unchanged) when a is a leaf that's not subset of b and not disjoint from b.
|
|
181
|
+
- `intersectTy` distributes over unions recursively; base case for two non-subset number-family leafs returns `kUInt31Id` (the only such overlap); other non-subset leafs return NoType.
|
|
182
|
+
- Added `TypeKind::UInt31` (Int32 ∩ Uint32, integers in [0, 2^31-1]) to close the lattice gap. UInt31 <: Int32, UInt31 <: Uint32, UInt31 <: Number. Pre-allocated as well-known IDs: kInt32Id=15, kUint32Id=16, kUInt31Id=17 (shifted union IDs up by 3). 5 new unit tests (28 total).
|
|
183
|
+
|
|
184
|
+
### P1-S4: Utility methods
|
|
185
|
+
- **Files**: modified `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `unittests/IR/TypeContextTest.cpp`.
|
|
186
|
+
- **What was done**: Added `countKinds`, `getFirstKind`, `format` methods. Added `kindName` file-scoped helper for TypeKind→string mapping. Forward-declared `llvh::raw_ostream` in header. 5 new unit tests (28 total).
|
|
187
|
+
- **Decisions**:
|
|
188
|
+
- `format` uses "any" shorthand when the union is a superset of AnyType (matching old `Type::print()`). Extra arms beyond AnyType (e.g. empty, uninit) are appended with `|`.
|
|
189
|
+
- `kindName` covers all TypeKind values including deferred refined types and Bits32, for completeness.
|
|
190
|
+
- `getFirstKind` returns `TypeKind::NoType` for NoType (matching old behavior where `getFirstTypeKind` returns `LAST_TYPE` for empty bitmask — callers check `isNoType()` first).
|
|
191
|
+
|
|
192
|
+
### P1-S5: Thread-local context and RAII guard
|
|
193
|
+
- **Files**: modified `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `unittests/IR/TypeContextTest.cpp`.
|
|
194
|
+
- **What was done**: Added `static thread_local TypeContext *current_` and `static TypeContext ¤t()` to `TypeContext`. Added `TypeContextRAII` class with save/restore semantics. 2 new unit tests (35 total).
|
|
195
|
+
- **Decisions**:
|
|
196
|
+
- `TypeContextRAII` is a friend of `TypeContext` to access `current_` directly, keeping the static member private.
|
|
197
|
+
- `current()` returns a reference (not pointer) and asserts non-null — callers never need to check.
|
|
198
|
+
|
|
199
|
+
### P1-S1: TypeContext skeleton with well-known types
|
|
200
|
+
- **Files**: created `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `unittests/IR/TypeContextTest.cpp`; modified `lib/CMakeLists.txt`, `unittests/IR/CMakeLists.txt`.
|
|
201
|
+
- **Decisions**:
|
|
202
|
+
- TypeEntry uses raw `uint32_t` for all type references (not `Type`) since `Type` is still a bitmask. Changed to `Type` in P1-S8.
|
|
203
|
+
- Added `kNullOrUndefId` (id=18) as a well-known union, needed for InstSimplify.cpp migration in P1-S8.
|
|
204
|
+
- Reserved IDs 19-31 padded with NoType placeholders.
|
|
205
|
+
- Union arm arrays stored in sorted order by ID for AnyType and AnyEmptyUninit.
|
|
206
|
+
- **What was done**: Created TypeContext with TypeKind enum (all kinds including deferred refined types), TypeEntry tagged-union struct, well-known ID constants, constructor that pre-allocates 15 leaf types and 4 well-known unions, getKind() and getUnionArms() accessors. Added to hermesFrontend build target. 6 unit tests.
|
|
207
|
+
|
|
208
|
+
### P1-S6: Wire TypeContext into Module
|
|
209
|
+
- **Files**: modified `include/hermes/IR/IR.h`.
|
|
210
|
+
- **What was done**: Added `#include "hermes/IR/TypeContext.h"` to IR.h. Added `TypeContext typeContext_` private member and `getTypeContext()` public accessor to `Module`. The context is default-constructed when `Module` is constructed. No semantic change — nothing uses `typeContext_` yet.
|
|
211
|
+
- **Decisions**:
|
|
212
|
+
- Included `TypeContext.h` at the top with other hermes includes (alphabetically after `hermes/FrontEndDefs/Typeof.h`) rather than mid-file, since TypeContext.h has no dependency on `Type` or other IR.h definitions.
|
|
213
|
+
|
|
214
|
+
### P1-S7: Install RAII guards at compilation entry points
|
|
215
|
+
- **Files**: modified `lib/BCGen/HBC/BCProviderFromSrc.cpp`, `lib/CompilerDriver/CompilerDriver.cpp`, `tools/shermes/shermes.cpp`.
|
|
216
|
+
- **What was done**: Added `TypeContextRAII typeContextGuard(M->getTypeContext())` (or `M.getTypeContext()` for stack-allocated Module) immediately after Module creation in all three production compilation entry points. No new includes needed — all files already include `IR.h` which includes `TypeContext.h`.
|
|
217
|
+
- **Decisions**:
|
|
218
|
+
- Test files that create `Module` (BasicBlockTest, LoopAnalysisTest, BCGen/TestHelpers, BCGen/HBC, VMRuntime/TestHelpers1, API/SegmentTestCompile) are deferred to P1-S7.5.
|
|
219
|
+
- No additional production `Module` creation sites found beyond the three in the plan.
|
|
220
|
+
|
|
221
|
+
### P1-S7.5: Add RAII guards to unit tests
|
|
222
|
+
- **Files**: modified `unittests/IR/BuilderTest.cpp`, `unittests/IR/VariableTest.cpp`, `unittests/IR/IRUtilsTest.cpp`, `unittests/IR/IRVerifierTest.cpp`.
|
|
223
|
+
- **What was done**: Added `TypeContextRAII typeContextGuard(M.getTypeContext())` after Module creation in every test that uses `Type::` operations. For `BuilderTest::Types` (which uses `Type::unionTy` without a Module), added a standalone `TypeContext` + RAII guard.
|
|
224
|
+
- **Decisions**:
|
|
225
|
+
- Only added guards to tests that directly use `Type::` operations (grep-verified). Test files that create Module but don't use `Type::` (BasicBlockTest, LoopAnalysisTest, etc.) were not modified — they don't need guards since P1-S8's static constructors (`createAnyType()`, etc.) remain constexpr and don't require the thread-local context. **(P1-S8 retroactively required guards in ALL Module-creating tests.)**
|
|
226
|
+
- No new includes needed — all four files already include `IR.h` which includes `TypeContext.h`.
|
|
227
|
+
|
|
228
|
+
### P1-S8: Rewrite Type class
|
|
229
|
+
- **Files**: modified `include/hermes/IR/IR.h`, `include/hermes/IR/TypeContext.h`, `lib/IR/TypeContext.cpp`, `lib/IR/IR.cpp`, `lib/BCGen/SH/SH.cpp`, `lib/Optimizer/Scalar/InstSimplify.cpp`, `lib/BCGen/HBC/HBC.cpp`, and many test files (BasicBlockTest, LoopAnalysisTest, IRHashTest, BuilderTest, IRVerifierTest, IRUtilsTest, BCGen/TestHelpers, BCGen/HBC, VMRuntime/TestHelpers1, API/SegmentTestCompile, Optimizer/InstructionEscapeAnalysisTest, Optimizer/PassManagerTest).
|
|
230
|
+
- **What was done**: Replaced `Type`'s `uint16_t bitmask_` with `uint32_t id_` (index into TypeContext). Removed old nested `enum TypeKind` and bitmask infrastructure. All type operations (`unionTy`, `intersectTy`, `subtractTy`, predicates, `print`, `iterator`) delegate to `TypeContext::current()`. Well-known constructors and identity checks remain `constexpr`. Changed `TypeContext::typeArrays_` from `vector<uint32_t>` to `vector<Type>`. Moved `getUnionArms` out-of-line to resolve incomplete-type issue. Fixed SH.cpp to use `TypeKind::Empty` etc. instead of `Type::Empty`. Replaced `constexpr Type kNullOrUndef` in InstSimplify.cpp with `Type::createNullOrUndef()`. Added RAII guards at lazy compilation (`compileLazyFunctionWorker`) and eval compilation (`compileEvalWorker`) entry points in HBC.cpp. Added RAII guards to all remaining Module-creating test files.
|
|
231
|
+
- **Decisions**:
|
|
232
|
+
- `Type` methods that need the context (queries, operations, `print`, `iterator`) are defined out-of-line in `TypeContext.cpp` to avoid include-order coupling. Only `constexpr` methods (identity checks, constructors, `operator==`) remain inline in `IR.h`.
|
|
233
|
+
- `TypeContext::getUnionArms` moved out-of-line because `ArrayRef<Type>` pointer arithmetic requires `Type` to be complete, but `Type` is defined after `TypeContext.h` is included.
|
|
234
|
+
- Fixed latent iterator-invalidation bug in `intersectTy`/`subtractTy`: arms are now copied to a `SmallVector` before calling `unionTy` which may reallocate `typeArrays_`.
|
|
235
|
+
- Added `createNullOrUndef()` static constructor to Type (returns well-known `kNullOrUndefId`).
|
|
236
|
+
- `sizeof(Type)` changed from 2 to 4 bytes. Updated `static_assert`.
|
|
237
|
+
- `Type::iterator` reimplemented: for non-union types yields the type itself; for unions iterates arms via `getUnionArms`.
|
|
238
|
+
- **Issues**: P1-S7/P1-S7.5 missed two production compilation paths (`compileLazyFunctionWorker`, `compileEvalWorker` in HBC.cpp) and many test files that create Module but don't directly use `Type::`. These all needed RAII guards once Type methods became non-trivial.
|
|
239
|
+
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Primitive-Bitmask Fast Path for TypeContext — Design
|
|
2
|
+
|
|
3
|
+
> **Status: shipped.** The fast path uses a single **DenseMap** mask→Type cache.
|
|
4
|
+
> The prototype also evaluated lazy-flat and eager-flat array caches behind a
|
|
5
|
+
> build-time `HERMES_PRIMCACHE` selector; the live working set turned out to be
|
|
6
|
+
> tiny (~40–60 distinct primitive masks per compile), so the DenseMap won on
|
|
7
|
+
> cache locality and the flat variants and selector were removed. See the
|
|
8
|
+
> companion results note. Sections below that describe the three-variant cache
|
|
9
|
+
> abstraction are retained for historical rationale.
|
|
10
|
+
|
|
11
|
+
## Context
|
|
12
|
+
|
|
13
|
+
The IR Type v2 redesign replaced the old 2-byte inline bitmask `Type` with a
|
|
14
|
+
4-byte handle (`id_`) into a per-`Module` `TypeContext`. Type operations became
|
|
15
|
+
out-of-line calls; union/intersect canonicalization goes through a
|
|
16
|
+
`DenseMap<UnionInternKey, …>` whose key is a `SmallVector<uint32_t,8>`.
|
|
17
|
+
|
|
18
|
+
Measured cost (direct in-source `[TI-TIMER]`, Release, 5-run median; OLD =
|
|
19
|
+
pre-Phase-1 bitmask `e91cc037f`, NEW = `static_h` HEAD):
|
|
20
|
+
|
|
21
|
+
| Bundle | OLD | NEW | regression |
|
|
22
|
+
|---|---|---|---|
|
|
23
|
+
| Fb4aBundle.js 2019 (40MB) | 4.49s | 5.32s | +18.6% |
|
|
24
|
+
| map/bundle-new.js 2023 (78MB) | 1.79s | 2.02s | +12.7% |
|
|
25
|
+
| fb4a marketplace 2026 (52MB) | 6.36s | 7.24s | +13.9% |
|
|
26
|
+
|
|
27
|
+
Profiling (`sample`) attributes the dominant added cost to `unionTy` →
|
|
28
|
+
`createUnionImpl` (the `DenseMap`/`SmallVector` interning) and, secondarily,
|
|
29
|
+
`isSubsetOf`/`intersectTy`. The hottest per-instruction operations
|
|
30
|
+
(`operator==` for fixpoint convergence, `getType`/`setType`) are inline `uint32`
|
|
31
|
+
ops and were never the problem.
|
|
32
|
+
|
|
33
|
+
This design re-embeds the old bitmask as a **fast path** for primitive-only
|
|
34
|
+
types so that the common case of `union`/`intersect`/`subset`/`canBe*` becomes
|
|
35
|
+
inline bit/table-lookup work with no `DenseMap` access — while keeping the
|
|
36
|
+
`Type` handle and the `id_`-equality invariant untouched.
|
|
37
|
+
|
|
38
|
+
## Goal & Scope
|
|
39
|
+
|
|
40
|
+
- **Bar (i): measurement-grade prototype** — semantically exact for everything
|
|
41
|
+
TypeInference exercises (so convergence/iteration is identical and timings are
|
|
42
|
+
trustworthy), but we do not port non-hot consumers or polish diagnostics.
|
|
43
|
+
- Must support **integer types first-class** (Int32/Uint32/UInt31), because
|
|
44
|
+
integer-producing inference and instructions are planned next. Integers are
|
|
45
|
+
handled in the fast path, not punted to the slow path.
|
|
46
|
+
- Out of scope: refined object types (ClassInstance/Array/…) stay on the slow
|
|
47
|
+
path; no changes to `getKind`/`getUnionArms`/`print`/iterators.
|
|
48
|
+
|
|
49
|
+
## Maskable Set (12-bit mask)
|
|
50
|
+
|
|
51
|
+
The mask covers exactly the kinds that flow through inference's algebra:
|
|
52
|
+
|
|
53
|
+
- **9 disjoint bits**: Undefined, Null, Boolean, BigInt, String, Symbol,
|
|
54
|
+
Object, Empty, Uninit.
|
|
55
|
+
- **3-bit number-family code** (see lattice below).
|
|
56
|
+
|
|
57
|
+
Empty/Uninit are included because TDZ inference manipulates them (Phis union
|
|
58
|
+
them; `ThrowIf`/`UnionNarrowTrusted` subtract `Empty`).
|
|
59
|
+
|
|
60
|
+
**Non-maskable** (→ existing slow path; correct but ~never exercised because
|
|
61
|
+
these are always-known, never inferred, and never merged with JS values):
|
|
62
|
+
Environment, FunctionCode, PrivateName, Bits32, and all refined object kinds.
|
|
63
|
+
|
|
64
|
+
Packed cache index = `(disjointBits << 3) | numberCode` → up to 12 bits
|
|
65
|
+
(`2^12 = 4096`; valid number codes 0..5, so ~3072 reachable combinations).
|
|
66
|
+
|
|
67
|
+
## Number-Family Lattice
|
|
68
|
+
|
|
69
|
+
Six elements, all subsets of `Number` (fp64):
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Number code 5
|
|
73
|
+
|
|
|
74
|
+
Int32 ∪ Uint32 code 4 (join of Int32, Uint32)
|
|
75
|
+
/ \
|
|
76
|
+
Int32 Uint32 code 2 / 3
|
|
77
|
+
\ /
|
|
78
|
+
UInt31 code 1 (Int32 ∩ Uint32, the meet)
|
|
79
|
+
|
|
|
80
|
+
∅ code 0
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Three constexpr 6×6 tables: `join` (union), `meet` (intersect), `sub`
|
|
84
|
+
(subtract → tightest representable superset, e.g. `Number − Int32 = Number`).
|
|
85
|
+
`subset(a,b)` derivable as `meet(a,b)==a` or a 4th boolean table. Tables only
|
|
86
|
+
ever yield the six valid codes ⇒ canonical-by-construction (no post-hoc
|
|
87
|
+
canonicalization pass).
|
|
88
|
+
|
|
89
|
+
## Type → Mask
|
|
90
|
+
|
|
91
|
+
Add `uint16_t primMask` to `TypeEntry`, sentinel `kNotMaskable = 0xFFFF`. Set at
|
|
92
|
+
every entry-creation site:
|
|
93
|
+
- leaf maskable kind → its bit (number leaves → the matching number code);
|
|
94
|
+
- `NoType` → 0;
|
|
95
|
+
- union → if all arms maskable, disjoint = OR of arm disjoint-bits and number =
|
|
96
|
+
`join` of arm number-codes; else `kNotMaskable`;
|
|
97
|
+
- refined/internal creators → `kNotMaskable`.
|
|
98
|
+
|
|
99
|
+
Free to read: rides the `entries_[id]` cache line already loaded for `.kind`.
|
|
100
|
+
|
|
101
|
+
## Operations
|
|
102
|
+
|
|
103
|
+
Each hot op gains a top-of-function fast path; if either operand is
|
|
104
|
+
`kNotMaskable`, fall through to the existing implementation unchanged.
|
|
105
|
+
|
|
106
|
+
- **Queries** (`isSubsetOf`, `areDisjoint`, `canBe*`, `isPrimitive`,
|
|
107
|
+
`canBePrimitive`, `isNonPtr`, `isKnownPrimitiveType`): disjoint-bit tests plus
|
|
108
|
+
a number-code table lookup. No cache access, no materialization.
|
|
109
|
+
`isSubsetOf = (da&db)==da && numberSubset(na,nb)`; `canBeNumber = nc != 0`;
|
|
110
|
+
etc.
|
|
111
|
+
- **Constructors** (`unionTy`/`intersectTy`/`subtractTy`): compute the result
|
|
112
|
+
mask (disjoint via `OR`/`AND`/`&~`, number via `join`/`meet`/`sub`), then
|
|
113
|
+
`lookupPrimMask(result)`.
|
|
114
|
+
- `lookupPrimMask(m)`: consult the cache; on miss, **materialize** — decode the
|
|
115
|
+
mask to leaf ids (number code → `Number` / `Int32` / `Uint32` / `UInt31` /
|
|
116
|
+
the `{Int32,Uint32}` arm pair) and intern via the **existing**
|
|
117
|
+
`createUnionFromLeafArms` — then record in the cache, and set the resulting
|
|
118
|
+
entry's `primMask`.
|
|
119
|
+
|
|
120
|
+
## Cache Abstraction (prototype)
|
|
121
|
+
|
|
122
|
+
> Historical: this three-variant comparison was prototype-only. The shipped code
|
|
123
|
+
> uses the **DenseMap** variant exclusively; the seam, the `HERMES_PRIMCACHE`
|
|
124
|
+
> selector, and the flat/eager variants were removed (the live working set is
|
|
125
|
+
> ~40–60 masks, so DenseMap won on locality). See the results note.
|
|
126
|
+
|
|
127
|
+
The mask→Type cache sat behind a small seam (`PrimMaskCache`) so we could build
|
|
128
|
+
three binaries and run the identical harness on each. Selected at build time
|
|
129
|
+
(macro or template tag — separate binaries, so no runtime cost):
|
|
130
|
+
|
|
131
|
+
1. **DenseMap** — `DenseMap<uint32_t, Type>`, lazy. Sparse; single-`uint32` key
|
|
132
|
+
(far cheaper than today's `SmallVector` key).
|
|
133
|
+
2. **Lazy flat** — `std::vector<Type>` of size `2^12`, init `kInvalidId`;
|
|
134
|
+
lookup is an index, miss → materialize+store.
|
|
135
|
+
3. **Eager flat** — same array, fully populated at `TypeContext` construction
|
|
136
|
+
(materialize all reachable masks up front); lookup is a pure index load,
|
|
137
|
+
never a miss. Construction cost is one-time per Module; report it separately
|
|
138
|
+
from `[TI-TIMER]` (which times only `runOnModule`).
|
|
139
|
+
|
|
140
|
+
All three funnel materialization through the same interning routine, so they are
|
|
141
|
+
behaviorally identical and differ only in lookup cost / construction cost.
|
|
142
|
+
|
|
143
|
+
## Canonical-Form Invariant & Safety
|
|
144
|
+
|
|
145
|
+
The `primMask` field and the cache are **pure accelerators in front of
|
|
146
|
+
`internTable_`, which remains the single source of canonical truth.** A type is
|
|
147
|
+
maskable-or-not deterministically by its kinds; both the fast and slow paths
|
|
148
|
+
intern through `internTable_`, so every type has exactly one canonical `id_`
|
|
149
|
+
regardless of path. `operator==` (and the fixpoint convergence test) is
|
|
150
|
+
therefore unaffected.
|
|
151
|
+
|
|
152
|
+
## Correctness Gate
|
|
153
|
+
|
|
154
|
+
The fast path is a pure optimization. Validation:
|
|
155
|
+
1. Emitted `.hbc` must be **byte-identical** to baseline-NEW for all three
|
|
156
|
+
bundles (`cmp` the outputs).
|
|
157
|
+
2. `[TI-COUNTERS]` amplification must be **unchanged** vs baseline-NEW (proves
|
|
158
|
+
per-op cost changed, not convergence behavior).
|
|
159
|
+
3. Existing `TypeContextTest` unit tests pass.
|
|
160
|
+
|
|
161
|
+
## Measurement Plan (prototype)
|
|
162
|
+
|
|
163
|
+
> Historical: how the three variants were compared. Final shipped numbers are in
|
|
164
|
+
> the results note (taken with `-ftime-report`).
|
|
165
|
+
|
|
166
|
+
`cp` the current NEW `hermesc` aside (preserve baseline binary). Build the three
|
|
167
|
+
cache variants. For each variant, run the `[TI-TIMER]` harness (5 runs, median)
|
|
168
|
+
on the three bundles; compare to baseline-NEW (5.32 / 2.02 / 7.24 s) and the OLD
|
|
169
|
+
floor (4.49 / 1.79 / 6.36 s). Also record eager-flat construction overhead.
|
|
170
|
+
Report a table: {OLD, NEW-baseline, NEW+DenseMap, NEW+lazy-flat,
|
|
171
|
+
NEW+eager-flat} × {three bundles}.
|
|
172
|
+
|
|
173
|
+
## Files (as shipped)
|
|
174
|
+
|
|
175
|
+
- `include/hermes/IR/TypeContext.h`: `TypeEntry::primMask` + the `kNotMaskable`
|
|
176
|
+
sentinel; mask bit / number-code constants; the three number-family
|
|
177
|
+
`inline constexpr` tables (join/meet/subtract); `leafKindToMask`;
|
|
178
|
+
`kNumPrimMasks`; the `llvh::DenseMap<uint32_t, Type> primCache_` member; the
|
|
179
|
+
`lookupPrimMask`/`materializePrimMask` declarations.
|
|
180
|
+
- `lib/IR/TypeContext.cpp`: the both-operands-maskable fast paths in the hot ops
|
|
181
|
+
(union/intersect/subtract, isSubsetOf/areDisjoint, the canBe* queries, the
|
|
182
|
+
isPrimitive/canBePrimitive/isNonPtr/isKnownPrimitiveType predicates);
|
|
183
|
+
`lookupPrimMask` (DenseMap find/insert) + `materializePrimMask`; `primMask`
|
|
184
|
+
population in `TypeEntry::createLeaf` and `TypeContext::addUnionEntry`.
|
|
185
|
+
- `unittests/IR/TypeContextTest.cpp`: primMask-value, materialization
|
|
186
|
+
round-trip, and per-op fast/slow equivalence tests.
|
|
187
|
+
|
|
188
|
+
There is no `PrimMaskCache` seam, `HERMES_PRIMCACHE` selector, or eager
|
|
189
|
+
population path in the shipped code — those were prototype-only; see the
|
|
190
|
+
"Cache Abstraction (prototype)" section below for the historical rationale.
|
|
191
|
+
|
|
192
|
+
The prototype also used a throwaway measurement scaffold (`[TI-TIMER]` /
|
|
193
|
+
`[TI-COUNTERS]` in `lib/Optimizer/Scalar/TypeInference.cpp`); it was reverted
|
|
194
|
+
and is not part of the shipped change. Final numbers were taken with the
|
|
195
|
+
built-in `-ftime-report` instead (see the results note).
|
|
196
|
+
|
|
197
|
+
## Deferred (post-prototype, if the win justifies productionization)
|
|
198
|
+
|
|
199
|
+
- Port non-hot consumers / printing if we later embed the mask in the handle.
|
|
200
|
+
- Number-family extensions beyond the 6-element lattice (if future refinements
|
|
201
|
+
add elements, the tables grow accordingly).
|
|
202
|
+
- The worklist / no-clear-rerun restructuring of TypeInference itself (the
|
|
203
|
+
larger, orthogonal lever — separate effort).
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Primitive-Bitmask Fast Path — Results
|
|
2
|
+
|
|
3
|
+
Prototype per `typeinference-primitive-fastpath-design.md`, implemented on branch
|
|
4
|
+
`ir-type-speed`. Measured TypeInference time via `hermesc -O -ftime-report`
|
|
5
|
+
(sum of the `TypeInference` pass lines across its pipeline invocations), Release
|
|
6
|
+
builds, 3 runs, median. Bundles: Fb4aBundle.js (2019, 40MB),
|
|
7
|
+
map-20230823/bundle-new.js (2023, 78MB), fb4a marketplace 2026 (52MB).
|
|
8
|
+
|
|
9
|
+
## TypeInference median time
|
|
10
|
+
|
|
11
|
+
| variant | Fb4a-2019 | map-2023 | mkt-2026 |
|
|
12
|
+
|--------------------|-----------|----------|----------|
|
|
13
|
+
| OLD (bitmask) | 4.741s | 1.840s | 6.508s |
|
|
14
|
+
| NEW baseline | 5.203s | 2.054s | 7.212s |
|
|
15
|
+
| +DenseMap cache | 4.851s | 1.895s | 6.575s |
|
|
16
|
+
| +lazy-flat cache | 4.913s | 1.960s | 6.782s |
|
|
17
|
+
| +eager-flat cache | 4.878s | 1.868s | 6.436s |
|
|
18
|
+
|
|
19
|
+
## Regression recovered (NEW baseline → OLD floor)
|
|
20
|
+
|
|
21
|
+
Baseline regression vs OLD: +9.7% / +11.7% / +10.8%.
|
|
22
|
+
|
|
23
|
+
| variant | Fb4a-2019 | map-2023 | mkt-2026 |
|
|
24
|
+
|---------------|-----------|----------|----------|
|
|
25
|
+
| +DenseMap | 76% | 74% | 90% |
|
|
26
|
+
| +lazy-flat | 63% | 44% | 61% |
|
|
27
|
+
| +eager-flat | 70% | 87% | 110% |
|
|
28
|
+
|
|
29
|
+
(110% = eager-flat beat the old bitmask on the marketplace bundle.)
|
|
30
|
+
|
|
31
|
+
## Findings
|
|
32
|
+
|
|
33
|
+
- The fast path works: it recovers most of the v2 TypeInference regression. With
|
|
34
|
+
the DenseMap cache, NEW is back to within +1–3% of the OLD bitmask; eager-flat
|
|
35
|
+
closes it entirely (and slightly beats OLD on mkt-2026).
|
|
36
|
+
- **Cache-variant ranking**: eager-flat ≳ DenseMap > lazy-flat, but the gaps are
|
|
37
|
+
small (≤ ~0.2s at 5–7s totals) and within run-to-run noise at 3 runs. The
|
|
38
|
+
surprising bit is that lazy-flat trails DenseMap — likely the lazy first-touch
|
|
39
|
+
materialization plus larger working set vs. the small hot set the DenseMap
|
|
40
|
+
keeps warm. Eager-flat removes the miss path entirely; its one-time
|
|
41
|
+
construction (≤3072 masks materialized per Module) did not show up as a
|
|
42
|
+
regression on these whole-program compiles.
|
|
43
|
+
- **Correctness**: every variant produces byte-identical `.hbc` to baseline on
|
|
44
|
+
all three bundles, and passes the 45 `TypeContextTest` unit tests and the
|
|
45
|
+
type-inference/InstSimplify lit subset. The fast path is a pure optimization.
|
|
46
|
+
- **Working set is tiny.** Instrumenting the DenseMap to report its populated
|
|
47
|
+
size showed only **38–58 distinct primitive masks out of 4096** were ever
|
|
48
|
+
created per compile (Fb4a 43, map 38, marketplace 58). That explains the
|
|
49
|
+
ranking: the DenseMap keeps those ~40–60 live entries hot in a few cache
|
|
50
|
+
lines, whereas the flat array scatters them across a 4096-slot / 16 KB region
|
|
51
|
+
(worse locality — why lazy-flat trailed), and the eager array materializes
|
|
52
|
+
~3072 masks of which ~98% are never read.
|
|
53
|
+
|
|
54
|
+
## Decision (shipped)
|
|
55
|
+
|
|
56
|
+
Ship the **DenseMap** cache. The flat/eager variants and the build-time
|
|
57
|
+
`HERMES_PRIMCACHE` selector were prototype-only measurement scaffolding and have
|
|
58
|
+
been removed: at a ~40–60 working set, cache locality dominates and the flat
|
|
59
|
+
array's hash-avoidance is a mirage, while the DenseMap also uses far less memory.
|
|
60
|
+
No re-measurement at higher run counts was needed — the DenseMap-vs-baseline win
|
|
61
|
+
is clear and the inter-variant deltas were noise-sized.
|
|
62
|
+
|
|
63
|
+
The larger remaining lever is unchanged: the ~10–13× re-inference amplification
|
|
64
|
+
in the TypeInference fixpoint (a separate worklist effort), which this fast path
|
|
65
|
+
does not address.
|
|
66
|
+
|
|
67
|
+
## Notes
|
|
68
|
+
|
|
69
|
+
- Measured via `-ftime-report` (built-in PassManager timer), so all five
|
|
70
|
+
binaries (OLD, NEW baseline, and the three cache variants) were measured
|
|
71
|
+
uniformly with no source instrumentation.
|