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,48 @@
|
|
|
1
|
+
# Implementation Memory
|
|
2
|
+
|
|
3
|
+
Quick reference for the IR type system v2. For full design see
|
|
4
|
+
[ir-type-v2-implementation.md](ir-type-v2-implementation.md).
|
|
5
|
+
|
|
6
|
+
## Build
|
|
7
|
+
- ASan build: `cmake -B cmake-build-asan -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DHERMES_ENABLE_ADDRESS_SANITIZER=ON -DCMAKE_CXX_FLAGS="-O1" -DCMAKE_C_FLAGS="-O1"`
|
|
8
|
+
- TypeContext.cpp is part of `hermesFrontend` target in `lib/CMakeLists.txt`.
|
|
9
|
+
- Unit test target: `HermesIRTests` (in `unittests/IR/CMakeLists.txt`).
|
|
10
|
+
|
|
11
|
+
## Well-Known IDs
|
|
12
|
+
Leaf types and well-known unions (NullOrUndef, AnyType, Numeric, AnyEmptyUninit) are pre-allocated with fixed IDs. Remaining IDs up to `kFirstDynamicId` are reserved padding.
|
|
13
|
+
|
|
14
|
+
## Design Decisions Beyond the Design Docs
|
|
15
|
+
- Added `TypeKind::UInt31` to close the lattice: `Int32 ∩ Uint32 = UInt31` (integers in [0, 2^31-1]). The design doc left this as an open question. UInt31 <: Int32, UInt31 <: Uint32, UInt31 <: Number.
|
|
16
|
+
- Added `kNullOrUndefId` as a well-known union (needed for `InstSimplify.cpp` migration).
|
|
17
|
+
|
|
18
|
+
## Type Class
|
|
19
|
+
- `Type` is 4 bytes (`uint32_t id_`). `TypeContext` is a `friend`.
|
|
20
|
+
- `constexpr` methods (identity checks, well-known constructors) stay inline in `IR.h`.
|
|
21
|
+
- All non-trivial methods (`canBeX`, `unionTy`, `print`, `iterator`, etc.) defined in `TypeContext.cpp` to avoid include-order coupling.
|
|
22
|
+
- `getUnionArms` is out-of-line because `ArrayRef<Type>` pointer arithmetic needs complete `Type`.
|
|
23
|
+
- `typeArrays_` is `vector<Type>`. Union arm arrays and tuple elements stored there.
|
|
24
|
+
|
|
25
|
+
## Queries & Operations
|
|
26
|
+
- Each `canBeX` has well-known ID fast paths before falling back to `containsMatchingKind`, a private template helper taking a predicate. `allMatchKind` is the universal-quantifier counterpart.
|
|
27
|
+
- File-scoped kind helpers (`isNumberKind`, `isObjectKind`, `isPrimitiveKind`, `isNonPtrKind`) encode subtype relationships: Int32/Uint32/UInt31 are number subtypes; ClassInstance/Array/Tuple/Function/ExactObject are object refinements.
|
|
28
|
+
- Union intern table: `DenseMap<UnionInternKey, uint32_t, UnionInternKeyInfo>`. Key is sorted arm IDs in a SmallVector. Pre-populated for well-known unions.
|
|
29
|
+
- `createUnionImpl`: flatten → sort → dedup → subsume → intern.
|
|
30
|
+
- `isSubsetOf`/`areDisjoint` are `const`; `unionTy`/`intersectTy`/`subtractTy` are non-const (may create entries).
|
|
31
|
+
- `intersectTy` leaf-leaf: returns UInt31 for overlapping number-family (Int32 ∩ Uint32), NoType otherwise.
|
|
32
|
+
- `subtractTy` returns conservative approximation when exact result is not representable.
|
|
33
|
+
|
|
34
|
+
## Thread-Local Context & Module
|
|
35
|
+
- `TypeContext::current_` is `static thread_local` (defined in `TypeContext.cpp`).
|
|
36
|
+
- `TypeContextRAII` saves/restores the pointer (friend of `TypeContext`).
|
|
37
|
+
- `Module` owns `TypeContext typeContext_` (default-constructed). Access via `getTypeContext()`.
|
|
38
|
+
- `TypeContext.h` is included in `IR.h` (no dependency on `Type` definition).
|
|
39
|
+
- RAII guards installed at all production compilation entry points (`BCProviderFromSrc.cpp`, `CompilerDriver.cpp`, `shermes.cpp`, plus lazy/eval paths in `HBC.cpp`).
|
|
40
|
+
|
|
41
|
+
## Gotchas
|
|
42
|
+
- **Iterator invalidation**: `intersectTy`/`subtractTy` must copy union arms to a `SmallVector` before calling `unionTy`, because `unionTy` may reallocate `typeArrays_`.
|
|
43
|
+
- **RAII guards everywhere**: ALL test files creating Module need guards — not just those using `Type::` directly. Instruction constructors call `unionTy`.
|
|
44
|
+
- **Header layering**: see "Type Class" above — non-trivial methods must be out-of-line.
|
|
45
|
+
|
|
46
|
+
## Formatting
|
|
47
|
+
- `format` uses "any" shorthand when the type is a superset of AnyType. Extra arms (empty, uninit) appended with `|`.
|
|
48
|
+
- `kindName()` is file-scoped in `TypeContext.cpp`, covers all `TypeKind` values.
|
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
# Phase 1 Implementation Steps
|
|
2
|
+
|
|
3
|
+
Phase 1 replaces the 2-byte bitmask `Type` with a 4-byte opaque index into
|
|
4
|
+
`TypeContext`, maintaining API compatibility for the vast majority of
|
|
5
|
+
call sites. A small number of call sites require targeted changes — see
|
|
6
|
+
"Known Call-Site Migrations" below.
|
|
7
|
+
|
|
8
|
+
References:
|
|
9
|
+
- [ir-type-v2-implementation.md](ir-type-v2-implementation.md) — full design
|
|
10
|
+
- [ir-type-system.md](ir-type-system.md) — current bitmask system
|
|
11
|
+
|
|
12
|
+
## Performance Note
|
|
13
|
+
|
|
14
|
+
Phase 1 replaces inline constexpr bitwise ops (single OR/AND/NOT) with
|
|
15
|
+
thread-local lookup → table lookup → (for unions) arm iteration. This is
|
|
16
|
+
inherently slower. For Phase 1, only well-known types exist, so the
|
|
17
|
+
well-known ID fast paths in `canBeX()` (`if (id == kAnyTypeId) return
|
|
18
|
+
true`) keep the common case to a few integer comparisons — slower than a
|
|
19
|
+
bitmask AND, but not drastically so.
|
|
20
|
+
|
|
21
|
+
If profiling reveals a bottleneck, a bitmask cache can be layered on
|
|
22
|
+
without changing the type algebra: each `TypeEntry` stores a precomputed
|
|
23
|
+
`uint16_t kindMask`, and `canBeNumber(t)` becomes
|
|
24
|
+
`entries_[t].kindMask & NumberBit`. See implementation design §12. This
|
|
25
|
+
optimization is explicitly deferred until profiling on real workloads.
|
|
26
|
+
|
|
27
|
+
## Dependency Graph
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
P1-S1 (skeleton)
|
|
31
|
+
├──→ P1-S2 (queries) ──→ P1-S3 (operations) ──→ P1-S4 (utilities)
|
|
32
|
+
├──→ P1-S5 (thread-local)
|
|
33
|
+
└──→ P1-S6 (wire into Module)
|
|
34
|
+
P1-S5 + P1-S6 ──→ P1-S7 (RAII at entry points)
|
|
35
|
+
P1-S7 ──→ P1-S7.5 (RAII in tests)
|
|
36
|
+
P1-S4 + P1-S7.5 ──→ P1-S8 (rewrite Type)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Commits are linear; the order below respects all dependencies.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Known Call-Site Migrations
|
|
44
|
+
|
|
45
|
+
These call sites cannot be preserved as-is and require targeted changes
|
|
46
|
+
in P1-S8:
|
|
47
|
+
|
|
48
|
+
1. **`constexpr Type` via `unionTy`**: `lib/Optimizer/Scalar/InstSimplify.cpp:41`
|
|
49
|
+
defines `constexpr Type kNullOrUndef = Type::unionTy(...)`. After the
|
|
50
|
+
rewrite, `unionTy` delegates to the thread-local context and cannot be
|
|
51
|
+
`constexpr`. Fix: add `kNullOrUndefId` to the well-known
|
|
52
|
+
pre-allocated types in P1-S1 and replace the `constexpr` expression
|
|
53
|
+
with `Type::createNullOrUndef()`.
|
|
54
|
+
|
|
55
|
+
2. **`switch` on `Type::` enum values**: `lib/BCGen/SH/SH.cpp:2279–2307`
|
|
56
|
+
switches on `type.getFirstTypeKind()` using `case Type::String`,
|
|
57
|
+
`case Type::LAST_TYPE`, etc. These reference the old nested `TypeKind`
|
|
58
|
+
enum. Fix: change to `case TypeKind::String`, etc. Remove the
|
|
59
|
+
`LAST_TYPE` case (add a `default:` or exhaust all cases).
|
|
60
|
+
|
|
61
|
+
3. **`Type::iterator` yields `Type`, not `TypeKind`**:
|
|
62
|
+
`lib/BCGen/SH/SH.cpp:2332` does `for (Type t : checkTypes)`. The
|
|
63
|
+
current iterator dereferences to a single-kind `Type` object (e.g.,
|
|
64
|
+
`Type(1 << index_)`). The new iterator must preserve this contract:
|
|
65
|
+
dereference yields a `Type` (with a single-kind well-known ID), not a
|
|
66
|
+
`TypeKind`.
|
|
67
|
+
|
|
68
|
+
4. **`Type::LAST_TYPE` sentinel**: Used in `SH.cpp:2305`, `IR.h`, and
|
|
69
|
+
`IR.cpp:1054`. Removed in the new enum. Each usage needs a case-by-case
|
|
70
|
+
fix (typically replace with `default:` or remove).
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## P1-S1: TypeContext skeleton with well-known types
|
|
75
|
+
|
|
76
|
+
**Short description:** Create `TypeContext` with `TypeKind` enum,
|
|
77
|
+
`TypeEntry` struct, well-known ID constants, and constructor that
|
|
78
|
+
pre-allocates all well-known type entries (primitives and common unions).
|
|
79
|
+
|
|
80
|
+
**Dependencies:** None.
|
|
81
|
+
|
|
82
|
+
**Details:**
|
|
83
|
+
|
|
84
|
+
New files:
|
|
85
|
+
- `include/hermes/IR/TypeContext.h`
|
|
86
|
+
- `lib/IR/TypeContext.cpp`
|
|
87
|
+
|
|
88
|
+
Add `IR/TypeContext.cpp` to the `hermesFrontend` source list in
|
|
89
|
+
`lib/CMakeLists.txt`.
|
|
90
|
+
|
|
91
|
+
Define:
|
|
92
|
+
- `enum class TypeKind : uint8_t` — all kinds from the design (leaf kinds,
|
|
93
|
+
refined kinds, Union). Refined kinds (ClassInstance, Array, Tuple, Function,
|
|
94
|
+
ExactObject, Int32, Uint32) are defined but unused in Phase 1.
|
|
95
|
+
- `struct TypeEntry` — tagged union with kind-specific payloads.
|
|
96
|
+
- `struct FunctionParam`, `struct ExactObjectField` — side array element
|
|
97
|
+
types (defined but unused in Phase 1).
|
|
98
|
+
- Well-known ID constants (`kNoTypeId` through `kFirstDynamicId`).
|
|
99
|
+
- `class TypeContext`:
|
|
100
|
+
- `std::vector<TypeEntry> entries_` — type table.
|
|
101
|
+
- `std::vector<uint32_t> typeArrays_` — stores union arm IDs (using raw
|
|
102
|
+
`uint32_t` since `Type` is still a bitmask at this point; changed to
|
|
103
|
+
`Type` in P1-S8).
|
|
104
|
+
- Constructor pre-allocates all well-known entries: leaf primitives
|
|
105
|
+
(NoType through Bits32) and well-known unions (AnyType, Numeric,
|
|
106
|
+
AnyEmptyUninit, NullOrUndef). Asserts
|
|
107
|
+
`entries_.size() == kFirstDynamicId` at end.
|
|
108
|
+
- `TypeKind getKind(uint32_t id) const` — returns the kind of a type
|
|
109
|
+
entry.
|
|
110
|
+
- `llvh::ArrayRef<uint32_t> getUnionArms(uint32_t id) const` — returns
|
|
111
|
+
the arm IDs of a union entry.
|
|
112
|
+
|
|
113
|
+
All public methods take `uint32_t` IDs (not `Type`). Changed to `Type` in
|
|
114
|
+
P1-S8 when the `Type` class is rewritten.
|
|
115
|
+
|
|
116
|
+
**Completion criteria:**
|
|
117
|
+
- Builds successfully.
|
|
118
|
+
- New unit test file `unittests/IR/TypeContextTest.cpp` (added to
|
|
119
|
+
`unittests/IR/CMakeLists.txt`):
|
|
120
|
+
- Constructs an `TypeContext`.
|
|
121
|
+
- Verifies `getKind(kNumberId) == TypeKind::Number` (and other
|
|
122
|
+
primitives).
|
|
123
|
+
- Verifies `getKind(kAnyTypeId) == TypeKind::Union`.
|
|
124
|
+
- Verifies `getUnionArms(kAnyTypeId)` contains the expected primitive
|
|
125
|
+
IDs.
|
|
126
|
+
- Verifies `getUnionArms(kNumericId)` = {kNumberId, kBigIntId}.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## P1-S2: Type queries on TypeContext
|
|
131
|
+
|
|
132
|
+
**Short description:** Add `canBeX()`, `isPrimitive()`, `isNonPtr()`, and
|
|
133
|
+
related predicate methods to `TypeContext`.
|
|
134
|
+
|
|
135
|
+
**Dependencies:** P1-S1.
|
|
136
|
+
|
|
137
|
+
**Details:**
|
|
138
|
+
|
|
139
|
+
Add methods to `TypeContext` (all take `uint32_t id`):
|
|
140
|
+
- `canBeNumber`, `canBeString`, `canBeObject`, `canBeNull`,
|
|
141
|
+
`canBeUndefined`, `canBeEmpty`, `canBeUninit`, `canBeBigInt`,
|
|
142
|
+
`canBeBoolean`, `canBeSymbol`.
|
|
143
|
+
- `isNoType`, `isPrimitive`, `canBePrimitive`, `isNonPtr`.
|
|
144
|
+
|
|
145
|
+
Each method implements well-known ID fast paths (e.g., `canBeNumber` returns
|
|
146
|
+
true immediately for `kAnyTypeId`, `kNumberId`, `kNumericId`) before falling
|
|
147
|
+
back to kind-based checks. For unions, iterate arms and check recursively
|
|
148
|
+
(arms are never unions, so recursion depth is 1).
|
|
149
|
+
|
|
150
|
+
**Completion criteria:**
|
|
151
|
+
- Builds successfully.
|
|
152
|
+
- Unit tests in `TypeContextTest.cpp`:
|
|
153
|
+
- `canBeNumber(kNumberId)` is true.
|
|
154
|
+
- `canBeNumber(kStringId)` is false.
|
|
155
|
+
- `canBeNumber(kAnyTypeId)` is true (AnyType is a union containing
|
|
156
|
+
Number).
|
|
157
|
+
- `canBeNumber(kNumericId)` is true.
|
|
158
|
+
- `isPrimitive(kNumberId)` is true.
|
|
159
|
+
- `isPrimitive(kObjectId)` is false (Object is NOT in `PRIMITIVE_BITS`;
|
|
160
|
+
primitives are: Number, String, BigInt, Null, Undefined, Boolean,
|
|
161
|
+
Symbol).
|
|
162
|
+
- `isNonPtr(kNumberId)` is true.
|
|
163
|
+
- `isNonPtr(kStringId)` is false.
|
|
164
|
+
- Queries on well-known union types return correct results.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## P1-S3: Type operations with interning
|
|
169
|
+
|
|
170
|
+
**Short description:** Add `unionTy`, `intersectTy`, `subtractTy`,
|
|
171
|
+
`isSubsetOf`, and `areDisjoint` to `TypeContext`. Add the intern table
|
|
172
|
+
for deduplicating dynamically created union types.
|
|
173
|
+
|
|
174
|
+
**Dependencies:** P1-S2.
|
|
175
|
+
|
|
176
|
+
**Details:**
|
|
177
|
+
|
|
178
|
+
Add to `TypeContext`:
|
|
179
|
+
- `llvh::DenseMap<TypeEntryKey, uint32_t> internTable_` — maps structural
|
|
180
|
+
keys to type IDs. Pre-populated for well-known types in the constructor.
|
|
181
|
+
- `struct TypeEntryKey` — hashable/comparable key derived from a
|
|
182
|
+
`TypeEntry`'s contents. For unions, the key includes the sorted arm IDs.
|
|
183
|
+
- `bool isSubsetOf(uint32_t a, uint32_t b)` — full implementation per
|
|
184
|
+
design: union-on-left (all arms subset), union-on-right (some arm is
|
|
185
|
+
superset), base cases.
|
|
186
|
+
- `bool areDisjoint(uint32_t a, uint32_t b)` — kind-based disjointness
|
|
187
|
+
without materializing intersections.
|
|
188
|
+
- `uint32_t unionTy(uint32_t a, uint32_t b)` — identity shortcuts, subset
|
|
189
|
+
shortcuts, then `createUnionImpl` with full canonicalization (flatten,
|
|
190
|
+
dedup, subsume, sort by ID, collapse single-arm, intern).
|
|
191
|
+
- `uint32_t intersectTy(uint32_t a, uint32_t b)` — subset shortcuts,
|
|
192
|
+
distribute over unions.
|
|
193
|
+
- `uint32_t subtractTy(uint32_t a, uint32_t b)` — subset → NoType,
|
|
194
|
+
disjoint → A, distribute over unions in A.
|
|
195
|
+
|
|
196
|
+
In Phase 1, the only dynamically created types are unions of well-known
|
|
197
|
+
primitives. Refined-type cases (ClassInstance subtyping, Array invariance,
|
|
198
|
+
etc.) are dead code paths that return conservative results or assert.
|
|
199
|
+
|
|
200
|
+
**Completion criteria:**
|
|
201
|
+
- Builds successfully.
|
|
202
|
+
- Unit tests in `TypeContextTest.cpp`:
|
|
203
|
+
- `unionTy(kNumberId, kStringId)` returns a union; querying its arms
|
|
204
|
+
gives {kNumberId, kStringId} (sorted).
|
|
205
|
+
- `unionTy(kNumberId, kNumberId)` returns `kNumberId` (identity).
|
|
206
|
+
- `unionTy(kNoTypeId, kStringId)` returns `kStringId`.
|
|
207
|
+
- `unionTy(kNumberId, kAnyTypeId)` returns `kAnyTypeId` (subset
|
|
208
|
+
subsumed).
|
|
209
|
+
- Interning: two calls to `unionTy(kNumberId, kStringId)` return the
|
|
210
|
+
same ID.
|
|
211
|
+
- `intersectTy(kNumberId, kStringId)` returns `kNoTypeId` (disjoint).
|
|
212
|
+
- `intersectTy(kNumberId, kAnyTypeId)` returns `kNumberId`.
|
|
213
|
+
- `subtractTy(kAnyTypeId, kNumberId)` returns a union without Number.
|
|
214
|
+
- `isSubsetOf(kNumberId, kAnyTypeId)` is true.
|
|
215
|
+
- `isSubsetOf(kAnyTypeId, kNumberId)` is false.
|
|
216
|
+
- `isSubsetOf(kNoTypeId, kNumberId)` is true.
|
|
217
|
+
- `areDisjoint(kNumberId, kStringId)` is true.
|
|
218
|
+
- `areDisjoint(kNumberId, kNumericId)` is false.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## P1-S4: Utility methods
|
|
223
|
+
|
|
224
|
+
**Short description:** Add `countKinds`, type formatting, and union arm
|
|
225
|
+
iteration helpers to `TypeContext`.
|
|
226
|
+
|
|
227
|
+
**Dependencies:** P1-S3.
|
|
228
|
+
|
|
229
|
+
**Details:**
|
|
230
|
+
|
|
231
|
+
Add to `TypeContext`:
|
|
232
|
+
- `unsigned countKinds(uint32_t id)` — returns 0 for NoType, arm count
|
|
233
|
+
for Union, 1 otherwise. Replacement for `Type::countTypes()`.
|
|
234
|
+
- `TypeKind getFirstKind(uint32_t id)` — returns the TypeKind for
|
|
235
|
+
non-union types; for unions, returns the kind of the first arm.
|
|
236
|
+
Replacement for `Type::getFirstTypeKind()`.
|
|
237
|
+
- `void format(llvh::raw_ostream &OS, uint32_t id) const` — prints the
|
|
238
|
+
human-readable type name. Leaf kinds print their name (`number`,
|
|
239
|
+
`string`, etc.). Unions print pipe-separated arms (`number|string`).
|
|
240
|
+
Special cases: NoType → `notype`, AnyType → `any`.
|
|
241
|
+
Replacement for `Type::print()`.
|
|
242
|
+
|
|
243
|
+
**Completion criteria:**
|
|
244
|
+
- Builds successfully.
|
|
245
|
+
- Unit tests:
|
|
246
|
+
- `countKinds(kNoTypeId)` returns 0.
|
|
247
|
+
- `countKinds(kNumberId)` returns 1.
|
|
248
|
+
- `countKinds(kAnyTypeId)` returns 8 (all JS-observable types).
|
|
249
|
+
- `countKinds(unionTy(kNumberId, kStringId))` returns 2.
|
|
250
|
+
- `getFirstKind(kNumberId)` returns `TypeKind::Number`.
|
|
251
|
+
- `format` output matches current `Type::print()` output for all
|
|
252
|
+
well-known types and simple unions.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## P1-S5: Thread-local context and RAII guard
|
|
257
|
+
|
|
258
|
+
**Short description:** Add `TypeContext::current()` thread-local accessor
|
|
259
|
+
and `TypeContextRAII` RAII guard.
|
|
260
|
+
|
|
261
|
+
**Dependencies:** P1-S1.
|
|
262
|
+
|
|
263
|
+
**Details:**
|
|
264
|
+
|
|
265
|
+
Add to `TypeContext`:
|
|
266
|
+
- `static thread_local TypeContext *current_` — private.
|
|
267
|
+
- `static TypeContext ¤t()` — asserts `current_ != nullptr`,
|
|
268
|
+
returns `*current_`.
|
|
269
|
+
|
|
270
|
+
New class `TypeContextRAII`:
|
|
271
|
+
- Constructor takes `TypeContext &`, saves `current_`, sets new current.
|
|
272
|
+
- Destructor restores previous `current_`.
|
|
273
|
+
- Non-copyable, non-movable.
|
|
274
|
+
|
|
275
|
+
**Completion criteria:**
|
|
276
|
+
- Builds successfully.
|
|
277
|
+
- Unit tests:
|
|
278
|
+
- Install guard with context A: `TypeContext::current()` returns A.
|
|
279
|
+
- Nested guards: inner guard returns inner context, after destruction
|
|
280
|
+
outer context is restored.
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## P1-S6: Wire TypeContext into Module
|
|
285
|
+
|
|
286
|
+
**Short description:** Add `TypeContext` member to `Module` and the
|
|
287
|
+
necessary header includes.
|
|
288
|
+
|
|
289
|
+
**Dependencies:** P1-S1.
|
|
290
|
+
|
|
291
|
+
**Details:**
|
|
292
|
+
|
|
293
|
+
In `include/hermes/IR/IR.h`:
|
|
294
|
+
- Forward-declare `class TypeContext;` near the top (before `Type`).
|
|
295
|
+
- Include `hermes/IR/TypeContext.h` after the `Type` class definition
|
|
296
|
+
and before the `Module` class definition.
|
|
297
|
+
- Add `TypeContext typeContext_;` private member to `Module`.
|
|
298
|
+
- Add `TypeContext &getTypeContext() { return typeContext_; }` public
|
|
299
|
+
accessor.
|
|
300
|
+
|
|
301
|
+
The `TypeContext` constructor runs automatically when `Module` is
|
|
302
|
+
constructed. No semantic change — nothing uses `typeContext_` yet.
|
|
303
|
+
|
|
304
|
+
**Completion criteria:**
|
|
305
|
+
- Builds successfully (full build including all tests, no test changes
|
|
306
|
+
needed).
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## P1-S7: Install RAII guards at compilation entry points
|
|
311
|
+
|
|
312
|
+
**Short description:** Install `TypeContextRAII` at all known `Module`
|
|
313
|
+
creation sites so the thread-local context is set during compilation.
|
|
314
|
+
|
|
315
|
+
**Dependencies:** P1-S5, P1-S6.
|
|
316
|
+
|
|
317
|
+
**Details:**
|
|
318
|
+
|
|
319
|
+
Install `TypeContextRAII` immediately after `Module` creation in every
|
|
320
|
+
site that creates a `Module` and performs type operations on it:
|
|
321
|
+
1. `lib/BCGen/HBC/BCProviderFromSrc.cpp` — in `BCProviderFromSrc::create`,
|
|
322
|
+
after the `std::make_shared<Module>(context)` call (~line 233).
|
|
323
|
+
2. `lib/CompilerDriver/CompilerDriver.cpp` — after the
|
|
324
|
+
`std::make_shared<Module>(context)` call (~line 1983).
|
|
325
|
+
3. `tools/shermes/shermes.cpp` — after the stack-allocated
|
|
326
|
+
`Module M(context)` (~line 911).
|
|
327
|
+
|
|
328
|
+
Any additional `Module` creation sites discovered during implementation
|
|
329
|
+
(e.g., in tests or tools) must also install the guard. A grep for
|
|
330
|
+
`Module(` and `make_shared<Module>` across the tree should catch them all.
|
|
331
|
+
|
|
332
|
+
The guard must be in a scope that encompasses all subsequent type operations
|
|
333
|
+
on the Module (IR construction, optimization passes, codegen). In all
|
|
334
|
+
cases, the existing scope after Module creation covers this.
|
|
335
|
+
|
|
336
|
+
No semantic change — `TypeContext::current()` is now set during
|
|
337
|
+
compilation, but nothing calls it yet.
|
|
338
|
+
|
|
339
|
+
**Completion criteria:**
|
|
340
|
+
- Builds successfully (full build including all tests, no test changes
|
|
341
|
+
needed).
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## P1-S7.5: Add RAII guards to unit tests (preparation)
|
|
346
|
+
|
|
347
|
+
**Short description:** Add `TypeContext` and `TypeContextRAII` setup
|
|
348
|
+
to all test fixtures that use `Type` operations, in preparation for the
|
|
349
|
+
Type rewrite. While `Type` is still bitmask-based, the guards are no-ops.
|
|
350
|
+
|
|
351
|
+
**Dependencies:** P1-S7.
|
|
352
|
+
|
|
353
|
+
**Details:**
|
|
354
|
+
|
|
355
|
+
Grep for `Type::` across all test files to find every test that uses
|
|
356
|
+
`Type` operations. For each, add an `TypeContext` instance and
|
|
357
|
+
`TypeContextRAII` guard to the test fixture (constructor or `SetUp()`).
|
|
358
|
+
|
|
359
|
+
Known test files:
|
|
360
|
+
- `unittests/IR/BuilderTest.cpp` — uses `Type::unionTy()`, `canBeX()`,
|
|
361
|
+
`isAnyEmptyUninitType()`.
|
|
362
|
+
- `unittests/IR/VariableTest.cpp` — uses `Type::createAnyType()`.
|
|
363
|
+
- `unittests/IR/IRUtilsTest.cpp` — uses `Type::createAnyType()`.
|
|
364
|
+
- `unittests/IR/IRVerifierTest.cpp` — uses `Type::createNumber()`,
|
|
365
|
+
`Type::createString()`.
|
|
366
|
+
|
|
367
|
+
Additional test files may be discovered by the grep.
|
|
368
|
+
|
|
369
|
+
No semantic change — `Type` still uses the bitmask; the guards prepare
|
|
370
|
+
for P1-S8 so that the Type rewrite doesn't need to touch test files.
|
|
371
|
+
|
|
372
|
+
**Completion criteria:**
|
|
373
|
+
- All tests pass unchanged (guards are no-ops).
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## P1-S8: Rewrite Type class
|
|
378
|
+
|
|
379
|
+
**Short description:** Replace `Type`'s `uint16_t bitmask_` with
|
|
380
|
+
`uint32_t id_`, delegate all methods to `TypeContext::current()`, and
|
|
381
|
+
replace the `TypeKind` enum.
|
|
382
|
+
|
|
383
|
+
**Dependencies:** P1-S4, P1-S7.5 (all prior steps).
|
|
384
|
+
|
|
385
|
+
**Details:**
|
|
386
|
+
|
|
387
|
+
This is the largest step. It is atomic because changing the representation
|
|
388
|
+
breaks all method implementations simultaneously.
|
|
389
|
+
|
|
390
|
+
**In `include/hermes/IR/IR.h`:**
|
|
391
|
+
|
|
392
|
+
Remove:
|
|
393
|
+
- Old `enum TypeKind { Empty, ..., LAST_TYPE }` (lines 61-86).
|
|
394
|
+
- Old `Type` class body (lines 58-414).
|
|
395
|
+
- Old `Type::iterator` class (lines 419-460).
|
|
396
|
+
|
|
397
|
+
Replace with new `Type` class:
|
|
398
|
+
- `uint32_t id_` private member.
|
|
399
|
+
- `constexpr explicit Type(uint32_t id)` private constructor.
|
|
400
|
+
- Static well-known constructors (`createNoType()`, `createNumber()`, etc.)
|
|
401
|
+
return well-known IDs. These remain `static constexpr`.
|
|
402
|
+
- `createInt32()` and `createUint32()` are aliases for `createNumber()`.
|
|
403
|
+
- `createNullOrUndef()` returns `kNullOrUndefId` (for InstSimplify.cpp
|
|
404
|
+
migration).
|
|
405
|
+
- `createNumeric()` returns `kNumericId`. All well-known union
|
|
406
|
+
constructors return pre-allocated IDs directly — they must NOT call
|
|
407
|
+
`unionTy()`, which would require the thread-local context.
|
|
408
|
+
- `operator==`, `operator!=` compare `id_` values.
|
|
409
|
+
- `hash()` returns `llvh::hash_value(id_)`.
|
|
410
|
+
- `Profile()` uses `ID.AddInteger(id_)`.
|
|
411
|
+
- All type operations (`unionTy`, `intersectTy`, `subtractTy`) delegate
|
|
412
|
+
to `TypeContext::current()`.
|
|
413
|
+
- All type queries (`canBeNumber()`, `isPrimitive()`, etc.) delegate to
|
|
414
|
+
`TypeContext::current()`.
|
|
415
|
+
- `isNoType()` and `isAnyType()` can compare directly against well-known
|
|
416
|
+
IDs without context lookup.
|
|
417
|
+
- `countTypes()` delegates to `TypeContext::current().countKinds()`.
|
|
418
|
+
- `getFirstTypeKind()` delegates to
|
|
419
|
+
`TypeContext::current().getFirstKind()`.
|
|
420
|
+
- `print()` delegates to `TypeContext::current().format()`.
|
|
421
|
+
- `Type::iterator` reimplemented: dereference yields a single-kind `Type`
|
|
422
|
+
(not `TypeKind`) to preserve the existing API contract. For non-union
|
|
423
|
+
types, yields the type itself as the single element. For unions,
|
|
424
|
+
iterates arms via `TypeContext::current().getUnionArms()`, wrapping
|
|
425
|
+
each arm ID as a `Type`.
|
|
426
|
+
|
|
427
|
+
**In `TypeContext.h` / `TypeContext.cpp`:**
|
|
428
|
+
|
|
429
|
+
Change all public method signatures from `uint32_t` to `Type`. Internally
|
|
430
|
+
extract `id_` via friend access. This is mechanical.
|
|
431
|
+
|
|
432
|
+
Change `typeArrays_` from `std::vector<uint32_t>` to `std::vector<Type>`.
|
|
433
|
+
|
|
434
|
+
**Header layering:** `Type` methods that call `TypeContext::current()`
|
|
435
|
+
are defined out-of-line in `IR.cpp` (not inline in `IR.h`). This avoids
|
|
436
|
+
include-order coupling between `IR.h` and `TypeContext.h`. Only methods
|
|
437
|
+
that don't need the context (e.g., `isNoType()`, `operator==`, static
|
|
438
|
+
well-known constructors) remain inline/constexpr in `IR.h`.
|
|
439
|
+
|
|
440
|
+
**In `lib/IR/IR.cpp`:**
|
|
441
|
+
|
|
442
|
+
Remove old `Type::print()` implementation (~lines 1040-1080). Replace with
|
|
443
|
+
delegation to `TypeContext::current().format()`.
|
|
444
|
+
|
|
445
|
+
**Old `TypeKind` callers:**
|
|
446
|
+
|
|
447
|
+
The old `TypeKind` enum (plain `enum` in `hermes` namespace) is replaced by
|
|
448
|
+
the new `enum class TypeKind` in `TypeContext.h`. Callers that reference
|
|
449
|
+
`TypeKind::Number` etc. continue to work (same qualified names). Callers
|
|
450
|
+
that relied on implicit integer conversion (e.g., `1 << TypeKind::Number`
|
|
451
|
+
for bitmask construction) no longer exist — the bitmask is gone.
|
|
452
|
+
|
|
453
|
+
The `LAST_TYPE` sentinel is removed. Callers using it need case-by-case
|
|
454
|
+
fixes.
|
|
455
|
+
|
|
456
|
+
**Note:** Unit test RAII guards are already in place from P1-S7.5.
|
|
457
|
+
P1-S8 should not need to modify test files (other than updating
|
|
458
|
+
`getUnionArms()` return type from `ArrayRef<uint32_t>` to
|
|
459
|
+
`ArrayRef<Type>` in `TypeContextTest.cpp`).
|
|
460
|
+
|
|
461
|
+
**Note:** `IR.h:707` has a pre-edited comment saying "Type is 4 bytes"
|
|
462
|
+
while `sizeof(Type)` is currently 2. This becomes correct after P1-S8;
|
|
463
|
+
update the `static_assert(sizeof(Type) == 2)` at `IR.h:416` to
|
|
464
|
+
`static_assert(sizeof(Type) == 4)`.
|
|
465
|
+
|
|
466
|
+
**API parity checklist — complete list of public `Type` methods that
|
|
467
|
+
must be preserved with identical semantics:**
|
|
468
|
+
|
|
469
|
+
Static constructors (all remain `static constexpr`):
|
|
470
|
+
- `createNoType()`, `createAnyType()`, `createAnyEmptyUninit()`.
|
|
471
|
+
- `createEmpty()`, `createUninit()`, `createUndefined()`, `createNull()`,
|
|
472
|
+
`createBoolean()`, `createString()`, `createNumber()`, `createBigInt()`,
|
|
473
|
+
`createSymbol()`, `createObject()`.
|
|
474
|
+
- `createInt32()`, `createUint32()` (aliases for `createNumber()`).
|
|
475
|
+
- `createNumeric()`, `createEnvironment()`, `createPrivateName()`,
|
|
476
|
+
`createFunctionCode()`.
|
|
477
|
+
- `createNullOrUndef()` (new, for InstSimplify.cpp migration).
|
|
478
|
+
|
|
479
|
+
Static operations (delegate to `TypeContext::current()`):
|
|
480
|
+
- `unionTy(Type, Type)`, `intersectTy(Type, Type)`,
|
|
481
|
+
`subtractTy(Type, Type)`.
|
|
482
|
+
|
|
483
|
+
Instance predicates (delegate to `TypeContext::current()`):
|
|
484
|
+
- `isSubsetOf(Type)`, `canBeType(Type)`, `isProperSubsetOf(Type)`.
|
|
485
|
+
- `canBeString()`, `canBeBigInt()`, `canBeSymbol()`, `canBeNumber()`,
|
|
486
|
+
`canBeObject()`, `canBeBoolean()`, `canBeEmpty()`, `canBeUninit()`,
|
|
487
|
+
`canBeUndefined()`, `canBeNull()`, `canBeAny()`.
|
|
488
|
+
- `isPrimitive()`, `canBePrimitive()`, `isNonPtr()`,
|
|
489
|
+
`isKnownPrimitiveType()`.
|
|
490
|
+
|
|
491
|
+
Instance type checks (compare against well-known IDs, no context needed):
|
|
492
|
+
- `isNoType()`, `isAnyType()`, `isAnyEmptyUninitType()`.
|
|
493
|
+
- `isEmptyType()`, `isUninitType()`, `isUndefinedType()`, `isNullType()`,
|
|
494
|
+
`isBooleanType()`, `isStringType()`, `isObjectType()`, `isNumberType()`,
|
|
495
|
+
`isBigIntType()`, `isSymbolType()`, `isEnvironmentType()`,
|
|
496
|
+
`isPrivateNameType()`, `isFunctionCodeType()`.
|
|
497
|
+
|
|
498
|
+
Utilities (delegate to `TypeContext::current()`):
|
|
499
|
+
- `countTypes()`, `getFirstTypeKind()`.
|
|
500
|
+
- `print(raw_ostream &)`.
|
|
501
|
+
- `Type::iterator` (dereferences to `Type`).
|
|
502
|
+
|
|
503
|
+
Identity / hashing (no context needed):
|
|
504
|
+
- `operator==`, `operator!=`, `hash()`, `Profile()`.
|
|
505
|
+
|
|
506
|
+
**Completion criteria:**
|
|
507
|
+
- Full build succeeds.
|
|
508
|
+
- `check-hermes` passes — all existing tests produce identical results.
|
|
509
|
+
- Call-site changes limited to: `Type`, `TypeContext`, `IR.cpp`, unit
|
|
510
|
+
test fixtures, and the known migrations listed in "Known Call-Site
|
|
511
|
+
Migrations" above (InstSimplify.cpp, SH.cpp, and any other
|
|
512
|
+
`LAST_TYPE` / nested-enum users).
|