react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/hermes/CMakeLists.txt +874 -0
  2. package/hermes/android/HostObjectJniTest.cpp +178 -0
  3. package/hermes/android/build-logic/build.gradle.kts +31 -0
  4. package/hermes/android/build-logic/settings.gradle.kts +17 -0
  5. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
  6. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
  7. package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
  8. package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
  9. package/hermes/android/build.gradle.kts +332 -0
  10. package/hermes/android/cppruntime/build.gradle +72 -0
  11. package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
  12. package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
  13. package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
  14. package/hermes/android/cross-compile/swift-libicu.patch +13 -0
  15. package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
  16. package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
  17. package/hermes/android/gradle/libs.versions.toml +30 -0
  18. package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  19. package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  20. package/hermes/android/gradle.properties +3 -0
  21. package/hermes/android/gradlew +248 -0
  22. package/hermes/android/gradlew.bat +93 -0
  23. package/hermes/android/intltest/build.gradle +147 -0
  24. package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
  25. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
  26. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
  27. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
  28. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
  29. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
  30. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
  31. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
  32. package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
  33. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
  34. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
  35. package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
  36. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
  37. package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
  38. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
  39. package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
  40. package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
  41. package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
  42. package/hermes/android/settings.gradle.kts +27 -0
  43. package/hermes/cmake/modules/Hermes.cmake +481 -0
  44. package/hermes/cmake/modules/Lit.cmake +96 -0
  45. package/hermes/doc/Branches.md +38 -0
  46. package/hermes/doc/BuildingAndRunning.md +121 -0
  47. package/hermes/doc/CodingStandards.md +112 -0
  48. package/hermes/doc/CrossCompilation.md +79 -0
  49. package/hermes/doc/Design.md +217 -0
  50. package/hermes/doc/Emscripten.md +156 -0
  51. package/hermes/doc/Features.md +143 -0
  52. package/hermes/doc/GCSafeCoding.md +563 -0
  53. package/hermes/doc/GenGC.md +300 -0
  54. package/hermes/doc/Hades.md +344 -0
  55. package/hermes/doc/HighLevelOptimizations.md +37 -0
  56. package/hermes/doc/IR.md +1306 -0
  57. package/hermes/doc/IntlAPIs.md +196 -0
  58. package/hermes/doc/JIT.md +999 -0
  59. package/hermes/doc/LazyEvalCompilation.md +84 -0
  60. package/hermes/doc/MemoryProfilers.md +316 -0
  61. package/hermes/doc/Modules.md +144 -0
  62. package/hermes/doc/Optimizer.md +83 -0
  63. package/hermes/doc/PerfProfiling.md +29 -0
  64. package/hermes/doc/ProhibitInvoke.md +329 -0
  65. package/hermes/doc/ReactNative.md +40 -0
  66. package/hermes/doc/ReactNativeIntegration.md +94 -0
  67. package/hermes/doc/RegExp.md +24 -0
  68. package/hermes/doc/SpecIncompat.md +85 -0
  69. package/hermes/doc/Strings.md +140 -0
  70. package/hermes/doc/TypedLanguage.md +432 -0
  71. package/hermes/doc/VM.md +174 -0
  72. package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
  73. package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
  74. package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
  75. package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
  76. package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
  77. package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
  78. package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
  79. package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
  80. package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
  81. package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
  82. package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
  83. package/hermes/doc/blog/README.md +25 -0
  84. package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
  85. package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
  86. package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
  87. package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
  88. package/hermes/doc/icu_license.txt +420 -0
  89. package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
  90. package/hermes/doc/img/logo.svg +1 -0
  91. package/hermes/doc/img/object_captured_by_environment.png +0 -0
  92. package/hermes/doc/img/root_categories.png +0 -0
  93. package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
  94. package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
  95. package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
  96. package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
  97. package/hermes/doc/plans/ir-type/memory.md +48 -0
  98. package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
  99. package/hermes/doc/plans/ir-type/progress.md +239 -0
  100. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
  101. package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
  102. package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
  103. package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
  104. package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
  105. package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
  106. package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
  107. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
  108. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
  109. package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
  110. package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
  111. package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
  112. package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
  113. package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
  114. package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
  115. package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
  116. package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
  117. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
  118. package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
  119. package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
  120. package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
  121. package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
  122. package/hermes/doc/typescript-stripping.md +90 -0
  123. package/hermes/external/CMakeLists.txt +20 -0
  124. package/hermes/utils/IntlGen/IntlGen.java +531 -0
  125. package/hermes/utils/bench_with_stats.py +827 -0
  126. package/hermes/utils/build-apple-framework.sh +323 -0
  127. package/hermes/utils/chrome_snapshot_parser.py +210 -0
  128. package/hermes/utils/cmake-dev-build.sh +18 -0
  129. package/hermes/utils/commons.sh +55 -0
  130. package/hermes/utils/dump-cpp-funcs.sh +3 -0
  131. package/hermes/utils/es5objects.js +198 -0
  132. package/hermes/utils/format.sh +145 -0
  133. package/hermes/utils/gen-promise-internal-bc.sh +66 -0
  134. package/hermes/utils/genUnicodeTable.py +2503 -0
  135. package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
  136. package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
  137. package/hermes/utils/jit/README.md +134 -0
  138. package/hermes/utils/jit/jit-diff.sh +160 -0
  139. package/hermes/utils/jit/jit-dump.sh +193 -0
  140. package/hermes/utils/lit-expect-gen/generate.py +217 -0
  141. package/hermes/utils/promise/index.js +15 -0
  142. package/hermes/utils/promise/package.json +13 -0
  143. package/hermes/utils/promise/rollup.config.js +19 -0
  144. package/hermes/utils/promise/yarn.lock +247 -0
  145. package/hermes/utils/scripts/hermes/consts.js +26 -0
  146. package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
  147. package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
  148. package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
  149. package/hermes/utils/scripts/hermes/package.json +6 -0
  150. package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
  151. package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
  152. package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
  153. package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
  154. package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
  155. package/hermes/utils/scripts/hermes/version-utils.js +98 -0
  156. package/hermes/utils/scripts/hermes/yarn.lock +240 -0
  157. package/hermes/utils/summarize_sizes.py +184 -0
  158. package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
  159. package/hermes/utils/test_runner.py +13 -0
  160. package/hermes/utils/testsuite/README.facebook +3 -0
  161. package/hermes/utils/testsuite/README.md +69 -0
  162. package/hermes/utils/testsuite/cli.py +547 -0
  163. package/hermes/utils/testsuite/es_ast.py +337 -0
  164. package/hermes/utils/testsuite/external/LICENSE +28 -0
  165. package/hermes/utils/testsuite/external/README.facebook +8 -0
  166. package/hermes/utils/testsuite/external/__init__.py +0 -0
  167. package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
  168. package/hermes/utils/testsuite/external/parse_test262.py +141 -0
  169. package/hermes/utils/testsuite/hermes.py +522 -0
  170. package/hermes/utils/testsuite/preprocess.py +365 -0
  171. package/hermes/utils/testsuite/progress.py +377 -0
  172. package/hermes/utils/testsuite/skiplist.json +4356 -0
  173. package/hermes/utils/testsuite/skiplist.py +270 -0
  174. package/hermes/utils/testsuite/test_run_defs.py +435 -0
  175. package/hermes/utils/testsuite/typing_defs.py +52 -0
  176. package/hermes/utils/testsuite/utils.py +214 -0
  177. package/hermes/utils/tidy.sh +22 -0
  178. package/hermes/utils/update-fbcode-hermes.sh +53 -0
  179. package/hermes/utils/updateErrorTest.py +193 -0
  180. package/hermes/utils/wasm-compile.sh +65 -0
  181. package/package.json +1 -1
@@ -0,0 +1,324 @@
1
+ # Flow Type System (FlowContext)
2
+
3
+ ## Overview
4
+
5
+ The Flow type system in Hermes is a full semantic type system used during static
6
+ analysis and type checking. Unlike the IR bitmask type system (13 bits, 2 bytes),
7
+ it supports nominal classes, generics, function signatures, tuples, exact objects,
8
+ union types with recursive structures, and subtyping with variance rules.
9
+
10
+ **Key files:**
11
+ - `include/hermes/Sema/FlowContext.h` — all type class definitions
12
+ - `lib/Sema/FlowContext.cpp` — comparison, hashing, canonicalization
13
+ - `lib/Sema/FlowChecker.cpp` — type checking, `canAFlowIntoB()`, annotation parsing
14
+ - `lib/Sema/FlowChecker-scopetypes.cpp` — scope resolution, alias resolution, looping type detection
15
+
16
+ ## Memory Representation
17
+
18
+ Types use a three-layer architecture:
19
+
20
+ 1. **`Type`** — a lightweight wrapper holding a `TypeInfo *info` pointer, an
21
+ `ESTree::Node *node` (source location), and an `isLooping` flag for recursive
22
+ structures.
23
+
24
+ 2. **`TypeInfo`** — abstract base class for type backing storage. Carries:
25
+ - `TypeKind kind_` — discriminator enum
26
+ - Lazy-cached hash (`hashed_`, `hashValue_`)
27
+ - Virtual `_compareImpl()`, `_equalsImpl()`, `_hashImpl()`
28
+
29
+ 3. **Concrete type classes** — `UnionType`, `ClassType`, `TypedFunctionType`, etc.
30
+
31
+ All types are allocated in `std::deque` containers within `FlowContext`, providing
32
+ stable pointers without invalidation. Singleton types (Void, Null, Number, etc.)
33
+ exist as single instances; complex types are interned via hash-consing where
34
+ appropriate.
35
+
36
+ ## Complete Type Kinds
37
+
38
+ ### Singleton Types (immutable, one instance each)
39
+
40
+ | Type | Meaning |
41
+ |------|---------|
42
+ | `Void` | JS `undefined` / absence of value |
43
+ | `Null` | JS `null` |
44
+ | `Boolean` | `true` or `false` |
45
+ | `String` | JS string |
46
+ | `Number` | IEEE 754 double |
47
+ | `BigInt` | Arbitrary-precision integer |
48
+ | `CPtr` | Internal C pointer (native interop) |
49
+ | `Any` | Supertype of everything; outputs require checked casts |
50
+ | `Mixed` | Bidirectional any (flows both in and out freely) |
51
+ | `Generic` | Placeholder for unspecialized generic class/alias (must not escape checker) |
52
+ | `InferencePlaceholder` | Used during generic type argument inference |
53
+
54
+ ### Complex (Structural) Types
55
+
56
+ | Type | Description |
57
+ |------|-------------|
58
+ | `Union` | `A \| B \| C` — canonical sorted union with looping-arm support |
59
+ | `Array` | `Array<T>` — single element type, invariant |
60
+ | `Tuple` | `[A, B, C]` — fixed-length, ordered, typed |
61
+ | `ExactObject` | `{x: A, y: B}` — named fields, exact (no extra properties) |
62
+ | `TypedFunction` | `(p1: A, p2: B) => R` — full signature with this-param, optional params |
63
+ | `UntypedFunction` | Function with no type information (only async/generator flags) |
64
+ | `NativeFunction` | C++ native function with a `NativeSignature` |
65
+ | `Class` | Nominal class with fields, methods, constructor, superclass chain |
66
+ | `ClassConstructor` | Type of a class variable/declaration (distinct from instance type) |
67
+
68
+ ## Singleton Types
69
+
70
+ Created once in `FlowContext` and accessed via getters (`getVoid()`, `getNull()`,
71
+ etc.). Comparison is pointer identity (O(1)). Hash is the `TypeKind` ordinal.
72
+
73
+ ### `Any` vs `Mixed`
74
+
75
+ - **`Any`**: accepts all inputs. When a value typed `any` flows *out* to a
76
+ concrete type, a runtime checked cast is required (`needCheckedCast = true`).
77
+ - **`Mixed`**: flows both directions without checked casts. Used where the type
78
+ system cannot determine the type but no runtime check is desired.
79
+
80
+ ## Union Types
81
+
82
+ Represents `A | B | C`. Encoded as a vector of arms with a dual-mode
83
+ canonicalization strategy.
84
+
85
+ ### Canonicalization
86
+
87
+ 1. Nested unions are flattened (one level).
88
+ 2. Arms are partitioned into **non-looping** (sorted, uniqued via structural
89
+ comparison) and **looping** (recursive arms, deduplicated via O(n²) matching).
90
+ 3. `numNonLoopingTypes_` tracks the boundary.
91
+ 4. Single-arm unions collapse: `maybeCreateUnion()` returns the arm directly.
92
+
93
+ ### Optional / Nullable
94
+
95
+ No separate Optional type. These are represented as unions:
96
+ - `type?` → `Void | Null | type`
97
+ - `?type` (nullable) → `Void | Null | type`
98
+
99
+ `createPopulatedNullable(type)` creates the canonical union.
100
+
101
+ ### Looping (Recursive) Types
102
+
103
+ Structural recursive types like `type Tree = null | {val: number, children: Tree[]}`
104
+ cause cycles. The `FindLoopingTypes` pass marks all arms on a cycle with
105
+ `isLooping = true`. Looping arms use slow O(n²) matching during comparison since
106
+ they cannot be deterministically sorted. Nominal types (classes) stop recursion
107
+ traversal — they are compared by identity, not structure.
108
+
109
+ ## Array Types
110
+
111
+ `Array<T>` with a single element type. **Invariant**: `Array<A>` does NOT flow to
112
+ `Array<B>` even if `A <: B`, because arrays are mutable at runtime.
113
+
114
+ ## Tuple Types
115
+
116
+ `[A, B, C]` — fixed length, positional types. **Invariant**: element count and
117
+ types must match exactly.
118
+
119
+ ## Exact Object Types
120
+
121
+ `{x: A, y: B}` — named, typed fields with exact semantics (no extra properties
122
+ allowed). Field order matters for comparison. Each field has:
123
+ - `Identifier name`
124
+ - `Type *type`
125
+
126
+ A `fieldNameMap_` provides O(1) lookup by name.
127
+
128
+ Note: Inexact objects (`{x: number, ...}`) are not yet implemented.
129
+
130
+ ## Function Types
131
+
132
+ ### Base: `BaseFunctionType`
133
+ Carries `isAsync_` and `isGenerator_` flags. Async/generator status must match
134
+ exactly for subtyping.
135
+
136
+ ### `TypedFunctionType`
137
+ Full signature: return type, optional this-param, parameter list where each
138
+ parameter has a name, type, and optional flag.
139
+
140
+ ### `UntypedFunctionType`
141
+ No signature — only async/generator flags. Flows to other untyped functions
142
+ regardless of actual parameters.
143
+
144
+ ### `NativeFunctionType`
145
+ Points to a `NativeSignature` from NativeContext. Flows only if signatures are
146
+ identical (pointer equality).
147
+
148
+ ### Function Subtyping
149
+
150
+ Functions use standard variance rules:
151
+ - **Contravariant in parameters**: callee's parameter types must accept the
152
+ caller's argument types.
153
+ - **Covariant in return type**: callee's return type must be accepted where the
154
+ caller's return type is expected.
155
+ - Async/generator status must match exactly.
156
+ - Function kind must match (Typed ≠ Untyped ≠ Native).
157
+
158
+ ## Class Types (Nominal)
159
+
160
+ Classes are **nominal** — subtyping is based on the inheritance chain, not
161
+ structure. Each class has a unique ID (`TypeWithId` base class).
162
+
163
+ ### Fields
164
+
165
+ ```cpp
166
+ struct Field {
167
+ Identifier name;
168
+ Type *type;
169
+ size_t layoutSlotIR; // maps to PrLoad/PrStore IR slots
170
+ bool isPrivate;
171
+ ESTree::MethodDefinitionNode *method; // nullptr for data fields
172
+ bool overridden; // can be modified by subclasses
173
+ };
174
+ ```
175
+
176
+ - `fields_` — direct (non-inherited) fields only.
177
+ - `fieldNameMap_` — all accessible fields including inherited (name → index).
178
+ - `privateFieldNameMap_` — private fields (own class only).
179
+
180
+ ### Other Properties
181
+
182
+ - `constructorType_` — function type of the constructor.
183
+ - `homeObjectType_` — the class representing `[[HomeObject]]` prototype.
184
+ - `superClass_` — parent class (nullable).
185
+
186
+ ### Class Subtyping
187
+
188
+ `ClassA` flows to `ClassB` iff `ClassB` is in `ClassA`'s superclass chain.
189
+ No structural matching — two classes with identical fields but different
190
+ declarations are incompatible.
191
+
192
+ ### `ClassConstructorType`
193
+
194
+ The type of a class declaration/variable (e.g., `const C = class { ... }`).
195
+ Wraps a `ClassType`. Distinct from the instance type.
196
+
197
+ ## Generics
198
+
199
+ ### Representation
200
+
201
+ ```cpp
202
+ template <class Spec>
203
+ class GenericInfo {
204
+ ESTree::Node *originalNode;
205
+ DenseMap<ArrayRef<TypeInfo*>, Spec*> specializations; // memoized
206
+ };
207
+ ```
208
+
209
+ ### Specialization
210
+
211
+ - Type arguments are matched to type parameters.
212
+ - A specialization cache maps type argument tuples to instantiated types/AST
213
+ clones, preventing duplicate work.
214
+ - `validateAndBindTypeParameters()` populates a binding table mapping parameter
215
+ names to concrete types.
216
+
217
+ ### `InferencePlaceholder`
218
+
219
+ Used during generic type argument inference. When a generic function is called
220
+ without explicit type arguments, placeholders are created and filled in by
221
+ `matchConstraintToType()` based on argument types.
222
+
223
+ ## Subtyping (`canAFlowIntoB`)
224
+
225
+ The core function returns `CanFlowResult { bool canFlow, bool needCheckedCast }`.
226
+
227
+ ### Rules (in priority order)
228
+
229
+ 1. **Identity**: `a == b` → flows.
230
+ 2. **Top types**: `_ → any` flows; `_ → mixed` flows; `any → _` flows but
231
+ requires checked cast.
232
+ 3. **Unions**:
233
+ - `(A | B) → C` flows iff `A → C` AND `B → C`.
234
+ - `A → (B | C)` flows iff `A → B` OR `A → C`.
235
+ 4. **Structural types** (all invariant):
236
+ - Arrays: element types must be equal.
237
+ - Tuples: length must match, element-wise equal.
238
+ - Objects: field names, order, and types must match exactly.
239
+ 5. **Nominal types**: class chain lookup.
240
+ 6. **Functions**: contravariant params, covariant return, matching kind and
241
+ async/generator flags.
242
+
243
+ ### Checked Casts
244
+
245
+ When `any` flows into a concrete type, `needCheckedCast = true` signals that
246
+ IRGen must insert a runtime type check instruction (`CheckedTypeCastInst`).
247
+
248
+ ## Type Comparison, Equality, and Hashing
249
+
250
+ ### Comparison (`TypeInfo::compare`)
251
+
252
+ Lexicographic structural ordering. Tracks visited pairs in `CompareState` to
253
+ detect cycles (returns 0 for revisited pairs). Results are cached.
254
+
255
+ ### Equality (`TypeInfo::equals`)
256
+
257
+ Structural equality with cycle tolerance. Special handling for incomplete unions
258
+ (created during alias resolution before canonicalization).
259
+
260
+ ### Hashing (`TypeInfo::hash`)
261
+
262
+ Intentionally shallow — unions hash on `(kind, armCount)`, arrays ignore element
263
+ type, tuples/objects hash on size only. This avoids O(n) cost in hash tables while
264
+ maintaining the invariant that `equals()` implies equal hashes.
265
+
266
+ ## Type Resolution Pipeline
267
+
268
+ Three stages during scope processing:
269
+
270
+ 1. **Forward declarations** — create `ClassType` instances with IDs but no fields.
271
+ Record type alias names without resolving their RHS.
272
+
273
+ 2. **Alias resolution** — resolve type alias RHS annotations. Detect and reject
274
+ union-only cycles. Populate forward-declared aliases.
275
+
276
+ 3. **Complete declarations** — parse class bodies (fields, methods, constructor,
277
+ superclass). Initialize `ClassType` fields. Canonicalize unions.
278
+
279
+ This staging allows mutual references between classes and type aliases.
280
+
281
+ ## Type Narrowing
282
+
283
+ ### `getNonOptionalSingleType(type)`
284
+
285
+ Extracts the single non-void, non-null arm from a union. Returns nullptr if
286
+ multiple non-optional arms exist. Used in control flow after null checks.
287
+
288
+ ### `tryNarrowType(exprType, targetType)`
289
+
290
+ Attempts to narrow a union to a target type. Returns the narrowed type and whether
291
+ a checked cast is needed. Used after type guards and conditional branches.
292
+
293
+ ## Relationship to the IR Type System
294
+
295
+ The Flow type system and IR type system are separate:
296
+
297
+ - **Flow types** operate during semantic analysis (`FlowChecker`). They are rich,
298
+ structural/nominal, and support generics.
299
+ - **IR types** operate during optimization and codegen. They are a 16-bit bitmask
300
+ of 13 primitive kinds.
301
+
302
+ Connection points:
303
+ - `ClassType::Field::layoutSlotIR` maps Flow fields to IR `PrLoad`/`PrStore` slot
304
+ indices.
305
+ - IRGen converts Flow types to IR types and inserts `CheckedTypeCastInst` where
306
+ `needCheckedCast` was flagged.
307
+ - Flow's `Number`, `String`, `Boolean`, etc. map directly to IR type bits.
308
+ - Flow's `Class` maps to IR's `Object` bit.
309
+ - Flow's `Union` maps to the IR union of its arms' IR types.
310
+
311
+ ## Key Design Properties
312
+
313
+ - **Nominal classes, structural everything else**: classes use identity; arrays,
314
+ tuples, objects, functions use structure.
315
+ - **Invariant containers**: arrays, tuples, and objects are invariant because JS
316
+ values are mutable.
317
+ - **Cycle-tolerant**: comparison, equality, and hashing all handle recursive types
318
+ via visited-pair tracking.
319
+ - **Lazy hashing**: avoids expensive recursive hashing until a type enters a hash
320
+ table.
321
+ - **Stable pointers**: `std::deque` allocation ensures type pointers never
322
+ invalidate.
323
+ - **Forward declaration support**: types can be created with an ID before their
324
+ fields are known, enabling mutual references.