@geastack/compiler 1.0.15

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 (966) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +149 -0
  3. package/dist/cli-analyze.d.ts +1 -0
  4. package/dist/cli-analyze.js +61 -0
  5. package/dist/cli-coverage.d.ts +1 -0
  6. package/dist/cli-coverage.js +329 -0
  7. package/dist/cli-emit.d.ts +10 -0
  8. package/dist/cli-emit.js +398 -0
  9. package/dist/cli-module-graph.d.ts +18 -0
  10. package/dist/cli-module-graph.js +123 -0
  11. package/dist/cli-package-source.d.ts +5 -0
  12. package/dist/cli-package-source.js +116 -0
  13. package/dist/cli-project.d.ts +2 -0
  14. package/dist/cli-project.js +60 -0
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +199 -0
  17. package/dist/compiler.d.ts +228 -0
  18. package/dist/compiler.js +1029 -0
  19. package/dist/conversion/algebra.d.ts +218 -0
  20. package/dist/conversion/algebra.js +155 -0
  21. package/dist/conversion/build.d.ts +67 -0
  22. package/dist/conversion/build.js +1378 -0
  23. package/dist/conversion/derive.d.ts +37 -0
  24. package/dist/conversion/derive.js +260 -0
  25. package/dist/conversion/graph-validation.d.ts +8 -0
  26. package/dist/conversion/graph-validation.js +97 -0
  27. package/dist/conversion/native-callable-adapter.d.ts +13 -0
  28. package/dist/conversion/native-callable-adapter.js +53 -0
  29. package/dist/conversion/native-class-reference.d.ts +12 -0
  30. package/dist/conversion/native-class-reference.js +39 -0
  31. package/dist/conversion/native-payload-transport.d.ts +25 -0
  32. package/dist/conversion/native-payload-transport.js +33 -0
  33. package/dist/conversion/native-selection.d.ts +49 -0
  34. package/dist/conversion/native-selection.js +135 -0
  35. package/dist/conversion/native-sum.d.ts +42 -0
  36. package/dist/conversion/native-sum.js +115 -0
  37. package/dist/conversion/nodes.d.ts +55 -0
  38. package/dist/conversion/nodes.js +91 -0
  39. package/dist/conversion/operand-view.d.ts +14 -0
  40. package/dist/conversion/operand-view.js +20 -0
  41. package/dist/conversion/record-view.d.ts +157 -0
  42. package/dist/conversion/record-view.js +273 -0
  43. package/dist/conversion/registry.d.ts +217 -0
  44. package/dist/conversion/registry.js +1 -0
  45. package/dist/diagnostics/model.d.ts +76 -0
  46. package/dist/diagnostics/model.js +60 -0
  47. package/dist/diagnostics/sweep.d.ts +31 -0
  48. package/dist/diagnostics/sweep.js +112 -0
  49. package/dist/identity/ids.d.ts +179 -0
  50. package/dist/identity/ids.js +212 -0
  51. package/dist/ir/absent-class-arm.d.ts +48 -0
  52. package/dist/ir/absent-class-arm.js +157 -0
  53. package/dist/ir/borrow-effects.d.ts +23 -0
  54. package/dist/ir/borrow-effects.js +151 -0
  55. package/dist/ir/borrowed-call-arguments.d.ts +40 -0
  56. package/dist/ir/borrowed-call-arguments.js +117 -0
  57. package/dist/ir/build.d.ts +168 -0
  58. package/dist/ir/build.js +459 -0
  59. package/dist/ir/call-dispatch.d.ts +38 -0
  60. package/dist/ir/call-dispatch.js +502 -0
  61. package/dist/ir/call-entry.d.ts +142 -0
  62. package/dist/ir/call-entry.js +386 -0
  63. package/dist/ir/callable-class-flow.d.ts +27 -0
  64. package/dist/ir/callable-class-flow.js +1386 -0
  65. package/dist/ir/callable-field-slots.d.ts +22 -0
  66. package/dist/ir/callable-field-slots.js +166 -0
  67. package/dist/ir/callable-identity-demand.d.ts +52 -0
  68. package/dist/ir/callable-identity-demand.js +460 -0
  69. package/dist/ir/callable-member-candidates.d.ts +9 -0
  70. package/dist/ir/callable-member-candidates.js +39 -0
  71. package/dist/ir/callable-records.d.ts +21 -0
  72. package/dist/ir/callable-records.js +411 -0
  73. package/dist/ir/captures.d.ts +26 -0
  74. package/dist/ir/captures.js +335 -0
  75. package/dist/ir/certificate.d.ts +45 -0
  76. package/dist/ir/certificate.js +47 -0
  77. package/dist/ir/certify/carrier-keys.d.ts +73 -0
  78. package/dist/ir/certify/carrier-keys.js +221 -0
  79. package/dist/ir/certify/function-source.d.ts +4 -0
  80. package/dist/ir/certify/function-source.js +28 -0
  81. package/dist/ir/certify/has-property-key.d.ts +88 -0
  82. package/dist/ir/certify/has-property-key.js +116 -0
  83. package/dist/ir/certify/instanceof-key.d.ts +24 -0
  84. package/dist/ir/certify/instanceof-key.js +35 -0
  85. package/dist/ir/certify/property-access-keys.d.ts +172 -0
  86. package/dist/ir/certify/property-access-keys.js +291 -0
  87. package/dist/ir/certify/property-access.d.ts +3 -0
  88. package/dist/ir/certify/property-access.js +597 -0
  89. package/dist/ir/certify/runtime-helper.d.ts +3 -0
  90. package/dist/ir/certify/runtime-helper.js +326 -0
  91. package/dist/ir/certify/typeof-operand.d.ts +14 -0
  92. package/dist/ir/certify/typeof-operand.js +16 -0
  93. package/dist/ir/certify.d.ts +123 -0
  94. package/dist/ir/certify.js +481 -0
  95. package/dist/ir/class-evaluation.d.ts +26 -0
  96. package/dist/ir/class-evaluation.js +50 -0
  97. package/dist/ir/class-static-fields.d.ts +60 -0
  98. package/dist/ir/class-static-fields.js +108 -0
  99. package/dist/ir/construct-entry.d.ts +26 -0
  100. package/dist/ir/construct-entry.js +117 -0
  101. package/dist/ir/dead-values.d.ts +90 -0
  102. package/dist/ir/dead-values.js +184 -0
  103. package/dist/ir/deferral.d.ts +99 -0
  104. package/dist/ir/deferral.js +409 -0
  105. package/dist/ir/dense-loops.d.ts +230 -0
  106. package/dist/ir/dense-loops.js +697 -0
  107. package/dist/ir/dominance.d.ts +82 -0
  108. package/dist/ir/dominance.js +268 -0
  109. package/dist/ir/emission-representations.d.ts +71 -0
  110. package/dist/ir/emission-representations.js +350 -0
  111. package/dist/ir/facts.d.ts +218 -0
  112. package/dist/ir/facts.js +181 -0
  113. package/dist/ir/fixed-data-definition.d.ts +19 -0
  114. package/dist/ir/fixed-data-definition.js +49 -0
  115. package/dist/ir/generator-split.d.ts +38 -0
  116. package/dist/ir/generator-split.js +329 -0
  117. package/dist/ir/hoist.d.ts +55 -0
  118. package/dist/ir/hoist.js +375 -0
  119. package/dist/ir/instantiation.d.ts +61 -0
  120. package/dist/ir/instantiation.js +137 -0
  121. package/dist/ir/integer-storage.d.ts +170 -0
  122. package/dist/ir/integer-storage.js +822 -0
  123. package/dist/ir/integers.d.ts +161 -0
  124. package/dist/ir/integers.js +539 -0
  125. package/dist/ir/integrity-restrictions.d.ts +50 -0
  126. package/dist/ir/integrity-restrictions.js +118 -0
  127. package/dist/ir/local-iterators.d.ts +4 -0
  128. package/dist/ir/local-iterators.js +27 -0
  129. package/dist/ir/lower-allocation.d.ts +4 -0
  130. package/dist/ir/lower-allocation.js +325 -0
  131. package/dist/ir/lower-completion.d.ts +15 -0
  132. package/dist/ir/lower-completion.js +25 -0
  133. package/dist/ir/lower-destructuring.d.ts +5 -0
  134. package/dist/ir/lower-destructuring.js +693 -0
  135. package/dist/ir/lower-element.d.ts +29 -0
  136. package/dist/ir/lower-element.js +111 -0
  137. package/dist/ir/lower-exceptions.d.ts +47 -0
  138. package/dist/ir/lower-exceptions.js +92 -0
  139. package/dist/ir/lower-flow.d.ts +137 -0
  140. package/dist/ir/lower-flow.js +600 -0
  141. package/dist/ir/lower-graph.d.ts +218 -0
  142. package/dist/ir/lower-graph.js +687 -0
  143. package/dist/ir/lower-invocation.d.ts +4 -0
  144. package/dist/ir/lower-invocation.js +514 -0
  145. package/dist/ir/lower-narrow.d.ts +53 -0
  146. package/dist/ir/lower-narrow.js +320 -0
  147. package/dist/ir/lower-operands.d.ts +272 -0
  148. package/dist/ir/lower-operands.js +461 -0
  149. package/dist/ir/lower-property.d.ts +21 -0
  150. package/dist/ir/lower-property.js +132 -0
  151. package/dist/ir/lower-protocol.d.ts +11 -0
  152. package/dist/ir/lower-protocol.js +118 -0
  153. package/dist/ir/lower-short-circuit.d.ts +41 -0
  154. package/dist/ir/lower-short-circuit.js +63 -0
  155. package/dist/ir/lower.d.ts +82 -0
  156. package/dist/ir/lower.js +1346 -0
  157. package/dist/ir/model.d.ts +1474 -0
  158. package/dist/ir/model.js +6 -0
  159. package/dist/ir/native-absent-property.d.ts +3 -0
  160. package/dist/ir/native-absent-property.js +13 -0
  161. package/dist/ir/native-array-transport.d.ts +7 -0
  162. package/dist/ir/native-array-transport.js +46 -0
  163. package/dist/ir/native-callable-bind.d.ts +9 -0
  164. package/dist/ir/native-callable-bind.js +30 -0
  165. package/dist/ir/native-carrier-predicate.d.ts +34 -0
  166. package/dist/ir/native-carrier-predicate.js +49 -0
  167. package/dist/ir/native-class-accessor.d.ts +18 -0
  168. package/dist/ir/native-class-accessor.js +52 -0
  169. package/dist/ir/native-class-construction.d.ts +16 -0
  170. package/dist/ir/native-class-construction.js +71 -0
  171. package/dist/ir/native-class-initialization.d.ts +15 -0
  172. package/dist/ir/native-class-initialization.js +56 -0
  173. package/dist/ir/native-class-origins.d.ts +13 -0
  174. package/dist/ir/native-class-origins.js +237 -0
  175. package/dist/ir/native-dictionary-transport.d.ts +6 -0
  176. package/dist/ir/native-dictionary-transport.js +37 -0
  177. package/dist/ir/native-enumeration.d.ts +14 -0
  178. package/dist/ir/native-enumeration.js +26 -0
  179. package/dist/ir/native-equality.d.ts +10 -0
  180. package/dist/ir/native-equality.js +18 -0
  181. package/dist/ir/native-field-owner.d.ts +37 -0
  182. package/dist/ir/native-field-owner.js +183 -0
  183. package/dist/ir/native-fixed-layout.d.ts +41 -0
  184. package/dist/ir/native-fixed-layout.js +232 -0
  185. package/dist/ir/native-host-construction.d.ts +53 -0
  186. package/dist/ir/native-host-construction.js +62 -0
  187. package/dist/ir/native-key-query.d.ts +4 -0
  188. package/dist/ir/native-key-query.js +38 -0
  189. package/dist/ir/native-merge-transport.d.ts +25 -0
  190. package/dist/ir/native-merge-transport.js +71 -0
  191. package/dist/ir/native-record-index-transport.d.ts +11 -0
  192. package/dist/ir/native-record-index-transport.js +34 -0
  193. package/dist/ir/native-record-index.d.ts +12 -0
  194. package/dist/ir/native-record-index.js +27 -0
  195. package/dist/ir/native-reflect-field.d.ts +5 -0
  196. package/dist/ir/native-reflect-field.js +33 -0
  197. package/dist/ir/native-sequence-transport.d.ts +7 -0
  198. package/dist/ir/native-sequence-transport.js +53 -0
  199. package/dist/ir/numeric-intrinsics.d.ts +13 -0
  200. package/dist/ir/numeric-intrinsics.js +57 -0
  201. package/dist/ir/object-value-conversions.d.ts +20 -0
  202. package/dist/ir/object-value-conversions.js +50 -0
  203. package/dist/ir/physical-class-reflection.d.ts +9 -0
  204. package/dist/ir/physical-class-reflection.js +57 -0
  205. package/dist/ir/presence-proof.d.ts +42 -0
  206. package/dist/ir/presence-proof.js +490 -0
  207. package/dist/ir/program-facts.d.ts +106 -0
  208. package/dist/ir/program-facts.js +319 -0
  209. package/dist/ir/proven-branches.d.ts +16 -0
  210. package/dist/ir/proven-branches.js +219 -0
  211. package/dist/ir/queries.d.ts +41 -0
  212. package/dist/ir/queries.js +213 -0
  213. package/dist/ir/reflection-demand.d.ts +64 -0
  214. package/dist/ir/reflection-demand.js +1394 -0
  215. package/dist/ir/refusal.d.ts +43 -0
  216. package/dist/ir/refusal.js +28 -0
  217. package/dist/ir/shake.d.ts +37 -0
  218. package/dist/ir/shake.js +1078 -0
  219. package/dist/ir/static-callables.d.ts +11 -0
  220. package/dist/ir/static-callables.js +163 -0
  221. package/dist/ir/string-layout-reuse.d.ts +13 -0
  222. package/dist/ir/string-layout-reuse.js +39 -0
  223. package/dist/ir/string-length-reuse.d.ts +8 -0
  224. package/dist/ir/string-length-reuse.js +47 -0
  225. package/dist/ir/transfer.d.ts +78 -0
  226. package/dist/ir/transfer.js +270 -0
  227. package/dist/ir/type-query-results.d.ts +25 -0
  228. package/dist/ir/type-query-results.js +96 -0
  229. package/dist/ir/typed-property-access.d.ts +100 -0
  230. package/dist/ir/typed-property-access.js +161 -0
  231. package/dist/ir/verify.d.ts +19 -0
  232. package/dist/ir/verify.js +355 -0
  233. package/dist/plugins/apple/constructors.d.ts +112 -0
  234. package/dist/plugins/apple/constructors.js +217 -0
  235. package/dist/plugins/apple/host.d.ts +181 -0
  236. package/dist/plugins/apple/host.js +262 -0
  237. package/dist/plugins/apple/jsx.d.ts +2 -0
  238. package/dist/plugins/apple/jsx.js +293 -0
  239. package/dist/plugins/apple/members.d.ts +16 -0
  240. package/dist/plugins/apple/members.js +190 -0
  241. package/dist/plugins/apple/plugin.d.ts +2 -0
  242. package/dist/plugins/apple/plugin.js +156 -0
  243. package/dist/plugins/gea/component-classes.d.ts +25 -0
  244. package/dist/plugins/gea/component-classes.js +162 -0
  245. package/dist/plugins/gea/component-inline.d.ts +13 -0
  246. package/dist/plugins/gea/component-inline.js +532 -0
  247. package/dist/plugins/gea/constructors.d.ts +23 -0
  248. package/dist/plugins/gea/constructors.js +100 -0
  249. package/dist/plugins/gea/contract.d.ts +150 -0
  250. package/dist/plugins/gea/contract.js +195 -0
  251. package/dist/plugins/gea/element-ref.d.ts +31 -0
  252. package/dist/plugins/gea/element-ref.js +45 -0
  253. package/dist/plugins/gea/host.d.ts +520 -0
  254. package/dist/plugins/gea/host.js +762 -0
  255. package/dist/plugins/gea/lower.d.ts +6 -0
  256. package/dist/plugins/gea/lower.js +195 -0
  257. package/dist/plugins/gea/members.d.ts +22 -0
  258. package/dist/plugins/gea/members.js +221 -0
  259. package/dist/plugins/gea/plugin.d.ts +22 -0
  260. package/dist/plugins/gea/plugin.js +307 -0
  261. package/dist/plugins/gea/prelude.d.ts +78 -0
  262. package/dist/plugins/gea/prelude.js +153 -0
  263. package/dist/plugins/gea/producer.d.ts +5 -0
  264. package/dist/plugins/gea/producer.js +52 -0
  265. package/dist/plugins/gea/reactive-slots.d.ts +49 -0
  266. package/dist/plugins/gea/reactive-slots.js +578 -0
  267. package/dist/plugins/gea/render-bridge.d.ts +6 -0
  268. package/dist/plugins/gea/render-bridge.js +281 -0
  269. package/dist/plugins/gea/slots.d.ts +15 -0
  270. package/dist/plugins/gea/slots.js +36 -0
  271. package/dist/plugins/gea/template-analysis.d.ts +151 -0
  272. package/dist/plugins/gea/template-analysis.js +346 -0
  273. package/dist/plugins/gea/user-agent-styles.d.ts +9 -0
  274. package/dist/plugins/gea/user-agent-styles.js +94 -0
  275. package/dist/plugins/installed.d.ts +19 -0
  276. package/dist/plugins/installed.js +21 -0
  277. package/dist/plugins/load.d.ts +7 -0
  278. package/dist/plugins/load.js +207 -0
  279. package/dist/plugins/model.d.ts +735 -0
  280. package/dist/plugins/model.js +47 -0
  281. package/dist/plugins/webgl/host.d.ts +77 -0
  282. package/dist/plugins/webgl/host.js +162 -0
  283. package/dist/plugins/webgl/plugin.d.ts +40 -0
  284. package/dist/plugins/webgl/plugin.js +99 -0
  285. package/dist/preflight/obligations.d.ts +206 -0
  286. package/dist/preflight/obligations.js +36 -0
  287. package/dist/preflight/report.d.ts +20 -0
  288. package/dist/preflight/report.js +61 -0
  289. package/dist/preflight/run.d.ts +39 -0
  290. package/dist/preflight/run.js +403 -0
  291. package/dist/project-preparation.d.ts +33 -0
  292. package/dist/project-preparation.js +314 -0
  293. package/dist/projection/abi.d.ts +82 -0
  294. package/dist/projection/abi.js +349 -0
  295. package/dist/projection/apply-arguments.d.ts +12 -0
  296. package/dist/projection/apply-arguments.js +20 -0
  297. package/dist/projection/bindings.d.ts +250 -0
  298. package/dist/projection/bindings.js +340 -0
  299. package/dist/projection/callee.d.ts +196 -0
  300. package/dist/projection/callee.js +444 -0
  301. package/dist/projection/class-property-presence.d.ts +28 -0
  302. package/dist/projection/class-property-presence.js +58 -0
  303. package/dist/projection/class-prototype.d.ts +5 -0
  304. package/dist/projection/class-prototype.js +23 -0
  305. package/dist/projection/class-storage.d.ts +26 -0
  306. package/dist/projection/class-storage.js +236 -0
  307. package/dist/projection/classes.d.ts +283 -0
  308. package/dist/projection/classes.js +944 -0
  309. package/dist/projection/coercions.d.ts +20 -0
  310. package/dist/projection/coercions.js +33 -0
  311. package/dist/projection/dispatch.d.ts +167 -0
  312. package/dist/projection/dispatch.js +379 -0
  313. package/dist/projection/fields.d.ts +123 -0
  314. package/dist/projection/fields.js +383 -0
  315. package/dist/projection/instance-test.d.ts +78 -0
  316. package/dist/projection/instance-test.js +156 -0
  317. package/dist/projection/slots.d.ts +146 -0
  318. package/dist/projection/slots.js +663 -0
  319. package/dist/projection/synthesized-abi.d.ts +61 -0
  320. package/dist/projection/synthesized-abi.js +94 -0
  321. package/dist/representation/array-index.d.ts +14 -0
  322. package/dist/representation/array-index.js +17 -0
  323. package/dist/representation/callable-object.d.ts +3 -0
  324. package/dist/representation/callable-object.js +6 -0
  325. package/dist/representation/collections.d.ts +84 -0
  326. package/dist/representation/collections.js +139 -0
  327. package/dist/representation/derive.d.ts +159 -0
  328. package/dist/representation/derive.js +2546 -0
  329. package/dist/representation/difference.d.ts +30 -0
  330. package/dist/representation/difference.js +240 -0
  331. package/dist/representation/field-descriptor-policy.d.ts +19 -0
  332. package/dist/representation/field-descriptor-policy.js +39 -0
  333. package/dist/representation/function-constructor.d.ts +13 -0
  334. package/dist/representation/function-constructor.js +9 -0
  335. package/dist/representation/host-abi.d.ts +32 -0
  336. package/dist/representation/host-abi.js +97 -0
  337. package/dist/representation/host-templates.d.ts +67 -0
  338. package/dist/representation/host-templates.js +94 -0
  339. package/dist/representation/intersection.d.ts +84 -0
  340. package/dist/representation/intersection.js +149 -0
  341. package/dist/representation/literal-destination.d.ts +43 -0
  342. package/dist/representation/literal-destination.js +133 -0
  343. package/dist/representation/merge.d.ts +18 -0
  344. package/dist/representation/merge.js +83 -0
  345. package/dist/representation/model.d.ts +1160 -0
  346. package/dist/representation/model.js +1019 -0
  347. package/dist/representation/numeric-index.d.ts +13 -0
  348. package/dist/representation/numeric-index.js +29 -0
  349. package/dist/representation/object-shape.d.ts +109 -0
  350. package/dist/representation/object-shape.js +123 -0
  351. package/dist/representation/optional.d.ts +12 -0
  352. package/dist/representation/optional.js +87 -0
  353. package/dist/representation/plan.d.ts +60 -0
  354. package/dist/representation/plan.js +78 -0
  355. package/dist/representation/policies.d.ts +589 -0
  356. package/dist/representation/policies.js +107 -0
  357. package/dist/representation/primitive-domain.d.ts +1 -0
  358. package/dist/representation/primitive-domain.js +1 -0
  359. package/dist/representation/primitives.d.ts +44 -0
  360. package/dist/representation/primitives.js +78 -0
  361. package/dist/representation/publish.d.ts +49 -0
  362. package/dist/representation/publish.js +648 -0
  363. package/dist/representation/record-fields.d.ts +96 -0
  364. package/dist/representation/record-fields.js +116 -0
  365. package/dist/representation/template-object.d.ts +11 -0
  366. package/dist/representation/template-object.js +26 -0
  367. package/dist/representation/union.d.ts +30 -0
  368. package/dist/representation/union.js +324 -0
  369. package/dist/representation/value-records.d.ts +3 -0
  370. package/dist/representation/value-records.js +307 -0
  371. package/dist/representation/verify.d.ts +17 -0
  372. package/dist/representation/verify.js +221 -0
  373. package/dist/semantics/alias-this-field-declaration-transform.d.ts +4 -0
  374. package/dist/semantics/alias-this-field-declaration-transform.js +207 -0
  375. package/dist/semantics/ambient-type-realization-transform.d.ts +62 -0
  376. package/dist/semantics/ambient-type-realization-transform.js +168 -0
  377. package/dist/semantics/ambient.d.ts +24 -0
  378. package/dist/semantics/ambient.js +119 -0
  379. package/dist/semantics/borrowed-builtin-call-bind-source-transform.d.ts +4 -0
  380. package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +341 -0
  381. package/dist/semantics/callable-origins.d.ts +46 -0
  382. package/dist/semantics/callable-origins.js +354 -0
  383. package/dist/semantics/class-alias.d.ts +7 -0
  384. package/dist/semantics/class-alias.js +37 -0
  385. package/dist/semantics/class-heritage.d.ts +34 -0
  386. package/dist/semantics/class-heritage.js +104 -0
  387. package/dist/semantics/commonjs-wrapper.d.ts +69 -0
  388. package/dist/semantics/commonjs-wrapper.js +231 -0
  389. package/dist/semantics/constructor-slot-subclasses.d.ts +28 -0
  390. package/dist/semantics/constructor-slot-subclasses.js +112 -0
  391. package/dist/semantics/declaration-overlay-transform.d.ts +35 -0
  392. package/dist/semantics/declaration-overlay-transform.js +2157 -0
  393. package/dist/semantics/define-property-source-transform.d.ts +4 -0
  394. package/dist/semantics/define-property-source-transform.js +437 -0
  395. package/dist/semantics/diagnostic-source-preparation.d.ts +24 -0
  396. package/dist/semantics/diagnostic-source-preparation.js +82 -0
  397. package/dist/semantics/documentation-ranges.d.ts +22 -0
  398. package/dist/semantics/documentation-ranges.js +36 -0
  399. package/dist/semantics/dynamic-fallback.d.ts +86 -0
  400. package/dist/semantics/dynamic-fallback.js +249 -0
  401. package/dist/semantics/frontend-timing.d.ts +6 -0
  402. package/dist/semantics/frontend-timing.js +35 -0
  403. package/dist/semantics/frontend.d.ts +504 -0
  404. package/dist/semantics/frontend.js +1157 -0
  405. package/dist/semantics/host-declaration-provenance.d.ts +11 -0
  406. package/dist/semantics/host-declaration-provenance.js +18 -0
  407. package/dist/semantics/host-methods.d.ts +24 -0
  408. package/dist/semantics/host-methods.js +74 -0
  409. package/dist/semantics/host-protocols.d.ts +429 -0
  410. package/dist/semantics/host-protocols.js +1501 -0
  411. package/dist/semantics/inherited-accessor.d.ts +7 -0
  412. package/dist/semantics/inherited-accessor.js +48 -0
  413. package/dist/semantics/interface-families.d.ts +70 -0
  414. package/dist/semantics/interface-families.js +180 -0
  415. package/dist/semantics/interface-implementors.d.ts +53 -0
  416. package/dist/semantics/interface-implementors.js +87 -0
  417. package/dist/semantics/jsdoc-namepath-transform.d.ts +4 -0
  418. package/dist/semantics/jsdoc-namepath-transform.js +85 -0
  419. package/dist/semantics/model/coverage.d.ts +68 -0
  420. package/dist/semantics/model/coverage.js +73 -0
  421. package/dist/semantics/model/edges.d.ts +103 -0
  422. package/dist/semantics/model/edges.js +20 -0
  423. package/dist/semantics/model/graph.d.ts +55 -0
  424. package/dist/semantics/model/graph.js +129 -0
  425. package/dist/semantics/model/operands.d.ts +159 -0
  426. package/dist/semantics/model/operands.js +26 -0
  427. package/dist/semantics/model/operations.d.ts +496 -0
  428. package/dist/semantics/model/operations.js +2 -0
  429. package/dist/semantics/model/primitive-domain.d.ts +26 -0
  430. package/dist/semantics/model/primitive-domain.js +38 -0
  431. package/dist/semantics/model/selected-signature.d.ts +261 -0
  432. package/dist/semantics/model/selected-signature.js +55 -0
  433. package/dist/semantics/model/structural-type-table.d.ts +93 -0
  434. package/dist/semantics/model/structural-type-table.js +237 -0
  435. package/dist/semantics/model/structural-types.d.ts +367 -0
  436. package/dist/semantics/model/structural-types.js +200 -0
  437. package/dist/semantics/module-resolution.d.ts +23 -0
  438. package/dist/semantics/module-resolution.js +227 -0
  439. package/dist/semantics/new-callee-class-tag-source-transform.d.ts +4 -0
  440. package/dist/semantics/new-callee-class-tag-source-transform.js +64 -0
  441. package/dist/semantics/node-project.d.ts +13 -0
  442. package/dist/semantics/node-project.js +107 -0
  443. package/dist/semantics/node-source-hooks.d.ts +1 -0
  444. package/dist/semantics/node-source-hooks.js +63 -0
  445. package/dist/semantics/normalize/absent-globals.d.ts +143 -0
  446. package/dist/semantics/normalize/absent-globals.js +191 -0
  447. package/dist/semantics/normalize/arguments-objects.d.ts +43 -0
  448. package/dist/semantics/normalize/arguments-objects.js +60 -0
  449. package/dist/semantics/normalize/asserted-arm-absence.d.ts +28 -0
  450. package/dist/semantics/normalize/asserted-arm-absence.js +61 -0
  451. package/dist/semantics/normalize/assignment-patterns.d.ts +70 -0
  452. package/dist/semantics/normalize/assignment-patterns.js +147 -0
  453. package/dist/semantics/normalize/bag-absence.d.ts +8 -0
  454. package/dist/semantics/normalize/bag-absence.js +42 -0
  455. package/dist/semantics/normalize/binding-fixpoint.d.ts +36 -0
  456. package/dist/semantics/normalize/binding-fixpoint.js +140 -0
  457. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +16 -0
  458. package/dist/semantics/normalize/callback-parameter-contracts.js +91 -0
  459. package/dist/semantics/normalize/cells/agreement.d.ts +46 -0
  460. package/dist/semantics/normalize/cells/agreement.js +34 -0
  461. package/dist/semantics/normalize/cells/candidates.d.ts +17 -0
  462. package/dist/semantics/normalize/cells/candidates.js +35 -0
  463. package/dist/semantics/normalize/cells/facts.d.ts +19 -0
  464. package/dist/semantics/normalize/cells/facts.js +90 -0
  465. package/dist/semantics/normalize/cells/index.d.ts +10 -0
  466. package/dist/semantics/normalize/cells/index.js +6 -0
  467. package/dist/semantics/normalize/cells/model.d.ts +98 -0
  468. package/dist/semantics/normalize/cells/model.js +2 -0
  469. package/dist/semantics/normalize/cells/policies/bag.d.ts +44 -0
  470. package/dist/semantics/normalize/cells/policies/bag.js +114 -0
  471. package/dist/semantics/normalize/cells/policies/collection.d.ts +42 -0
  472. package/dist/semantics/normalize/cells/policies/collection.js +218 -0
  473. package/dist/semantics/normalize/cells/policies/field.d.ts +28 -0
  474. package/dist/semantics/normalize/cells/policies/field.js +40 -0
  475. package/dist/semantics/normalize/cells/policies/index.d.ts +49 -0
  476. package/dist/semantics/normalize/cells/policies/index.js +58 -0
  477. package/dist/semantics/normalize/cells/policies/local.d.ts +18 -0
  478. package/dist/semantics/normalize/cells/policies/local.js +37 -0
  479. package/dist/semantics/normalize/cells/policies/parameter.d.ts +28 -0
  480. package/dist/semantics/normalize/cells/policies/parameter.js +39 -0
  481. package/dist/semantics/normalize/cells/policies/return.d.ts +26 -0
  482. package/dist/semantics/normalize/cells/policies/return.js +45 -0
  483. package/dist/semantics/normalize/cells/policies/shared.d.ts +33 -0
  484. package/dist/semantics/normalize/cells/policies/shared.js +45 -0
  485. package/dist/semantics/normalize/cells/policy.d.ts +72 -0
  486. package/dist/semantics/normalize/cells/policy.js +18 -0
  487. package/dist/semantics/normalize/cells/registry.d.ts +14 -0
  488. package/dist/semantics/normalize/cells/registry.js +17 -0
  489. package/dist/semantics/normalize/census-refusal.d.ts +62 -0
  490. package/dist/semantics/normalize/census-refusal.js +27 -0
  491. package/dist/semantics/normalize/census.d.ts +109 -0
  492. package/dist/semantics/normalize/census.js +667 -0
  493. package/dist/semantics/normalize/collection-bindings.d.ts +278 -0
  494. package/dist/semantics/normalize/collection-bindings.js +677 -0
  495. package/dist/semantics/normalize/commonjs-module-record.d.ts +21 -0
  496. package/dist/semantics/normalize/commonjs-module-record.js +289 -0
  497. package/dist/semantics/normalize/commonjs-require.d.ts +13 -0
  498. package/dist/semantics/normalize/commonjs-require.js +1527 -0
  499. package/dist/semantics/normalize/contribution.d.ts +63 -0
  500. package/dist/semantics/normalize/contribution.js +172 -0
  501. package/dist/semantics/normalize/dead-typeof-guards.d.ts +64 -0
  502. package/dist/semantics/normalize/dead-typeof-guards.js +152 -0
  503. package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +57 -0
  504. package/dist/semantics/normalize/deferred-intrinsic-protocols.js +109 -0
  505. package/dist/semantics/normalize/derived-expression-type.d.ts +1070 -0
  506. package/dist/semantics/normalize/derived-expression-type.js +3463 -0
  507. package/dist/semantics/normalize/evaluation-order.d.ts +16 -0
  508. package/dist/semantics/normalize/evaluation-order.js +37 -0
  509. package/dist/semantics/normalize/field-bindings.d.ts +167 -0
  510. package/dist/semantics/normalize/field-bindings.js +1125 -0
  511. package/dist/semantics/normalize/flow/array-element-continuation.d.ts +27 -0
  512. package/dist/semantics/normalize/flow/array-element-continuation.js +1452 -0
  513. package/dist/semantics/normalize/flow/callable-array-origins.d.ts +42 -0
  514. package/dist/semantics/normalize/flow/callable-array-origins.js +318 -0
  515. package/dist/semantics/normalize/flow/callable-completions.d.ts +45 -0
  516. package/dist/semantics/normalize/flow/callable-completions.js +82 -0
  517. package/dist/semantics/normalize/flow/callable-reach.d.ts +237 -0
  518. package/dist/semantics/normalize/flow/callable-reach.js +7174 -0
  519. package/dist/semantics/normalize/flow/class-family-member-read.d.ts +16 -0
  520. package/dist/semantics/normalize/flow/class-family-member-read.js +992 -0
  521. package/dist/semantics/normalize/flow/collection-value-continuation.d.ts +21 -0
  522. package/dist/semantics/normalize/flow/collection-value-continuation.js +192 -0
  523. package/dist/semantics/normalize/flow/component-solver.d.ts +199 -0
  524. package/dist/semantics/normalize/flow/component-solver.js +587 -0
  525. package/dist/semantics/normalize/flow/computed-key-set.d.ts +84 -0
  526. package/dist/semantics/normalize/flow/computed-key-set.js +660 -0
  527. package/dist/semantics/normalize/flow/export-importers.d.ts +24 -0
  528. package/dist/semantics/normalize/flow/export-importers.js +269 -0
  529. package/dist/semantics/normalize/flow/host-text-sink.d.ts +25 -0
  530. package/dist/semantics/normalize/flow/host-text-sink.js +87 -0
  531. package/dist/semantics/normalize/flow/intrinsic-array-callback-frames.d.ts +84 -0
  532. package/dist/semantics/normalize/flow/intrinsic-array-callback-frames.js +180 -0
  533. package/dist/semantics/normalize/flow/intrinsic-data-definition.d.ts +35 -0
  534. package/dist/semantics/normalize/flow/intrinsic-data-definition.js +140 -0
  535. package/dist/semantics/normalize/flow/invocation-facts.d.ts +98 -0
  536. package/dist/semantics/normalize/flow/invocation-facts.js +257 -0
  537. package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +122 -0
  538. package/dist/semantics/normalize/flow/member-call-forwarding.js +835 -0
  539. package/dist/semantics/normalize/flow/model.d.ts +357 -0
  540. package/dist/semantics/normalize/flow/model.js +177 -0
  541. package/dist/semantics/normalize/flow/native-collection-protocol.d.ts +24 -0
  542. package/dist/semantics/normalize/flow/native-collection-protocol.js +252 -0
  543. package/dist/semantics/normalize/flow/node-path-token.d.ts +3 -0
  544. package/dist/semantics/normalize/flow/node-path-token.js +53 -0
  545. package/dist/semantics/normalize/flow/object-binding-continuation.d.ts +11 -0
  546. package/dist/semantics/normalize/flow/object-binding-continuation.js +42 -0
  547. package/dist/semantics/normalize/flow/origin-authority.d.ts +56 -0
  548. package/dist/semantics/normalize/flow/origin-authority.js +2 -0
  549. package/dist/semantics/normalize/flow/owned-class-receivers.d.ts +35 -0
  550. package/dist/semantics/normalize/flow/owned-class-receivers.js +191 -0
  551. package/dist/semantics/normalize/flow/parameter-values.d.ts +27 -0
  552. package/dist/semantics/normalize/flow/parameter-values.js +251 -0
  553. package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +66 -0
  554. package/dist/semantics/normalize/flow/proof-hypotheses.js +162 -0
  555. package/dist/semantics/normalize/flow/record-alias-closure.d.ts +27 -0
  556. package/dist/semantics/normalize/flow/record-alias-closure.js +298 -0
  557. package/dist/semantics/normalize/flow/seeded-origins.d.ts +43 -0
  558. package/dist/semantics/normalize/flow/seeded-origins.js +54 -0
  559. package/dist/semantics/normalize/flow/source-class-data.d.ts +132 -0
  560. package/dist/semantics/normalize/flow/source-class-data.js +838 -0
  561. package/dist/semantics/normalize/flow/source-class-instanceof.d.ts +13 -0
  562. package/dist/semantics/normalize/flow/source-class-instanceof.js +37 -0
  563. package/dist/semantics/normalize/flow/source-class-static-data.d.ts +16 -0
  564. package/dist/semantics/normalize/flow/source-class-static-data.js +47 -0
  565. package/dist/semantics/normalize/flow/source-construction-frames.d.ts +12 -0
  566. package/dist/semantics/normalize/flow/source-construction-frames.js +118 -0
  567. package/dist/semantics/normalize/flow/source-invocation-frame-layout.d.ts +34 -0
  568. package/dist/semantics/normalize/flow/source-invocation-frame-layout.js +78 -0
  569. package/dist/semantics/normalize/flow/source-invocation-receiver.d.ts +37 -0
  570. package/dist/semantics/normalize/flow/source-invocation-receiver.js +95 -0
  571. package/dist/semantics/normalize/flow/source-prototype-method-identity.d.ts +23 -0
  572. package/dist/semantics/normalize/flow/source-prototype-method-identity.js +81 -0
  573. package/dist/semantics/normalize/flow/source-record-data.d.ts +29 -0
  574. package/dist/semantics/normalize/flow/source-record-data.js +626 -0
  575. package/dist/semantics/normalize/flow/source-value-session.d.ts +77 -0
  576. package/dist/semantics/normalize/flow/source-value-session.js +3089 -0
  577. package/dist/semantics/normalize/flow/targets.d.ts +118 -0
  578. package/dist/semantics/normalize/flow/targets.js +405 -0
  579. package/dist/semantics/normalize/flow/value-flow.d.ts +36 -0
  580. package/dist/semantics/normalize/flow/value-flow.js +823 -0
  581. package/dist/semantics/normalize/flow/value-provenance.d.ts +31 -0
  582. package/dist/semantics/normalize/flow/value-provenance.js +112 -0
  583. package/dist/semantics/normalize/gating.d.ts +51 -0
  584. package/dist/semantics/normalize/gating.js +560 -0
  585. package/dist/semantics/normalize/generic-function-choice.d.ts +31 -0
  586. package/dist/semantics/normalize/generic-function-choice.js +115 -0
  587. package/dist/semantics/normalize/global-host-mutations.d.ts +51 -0
  588. package/dist/semantics/normalize/global-host-mutations.js +5989 -0
  589. package/dist/semantics/normalize/host-effect-contracts.d.ts +77 -0
  590. package/dist/semantics/normalize/host-effect-contracts.js +143 -0
  591. package/dist/semantics/normalize/host-mutation-computed-keys.d.ts +38 -0
  592. package/dist/semantics/normalize/host-mutation-computed-keys.js +26 -0
  593. package/dist/semantics/normalize/host-mutation-key-reader.d.ts +66 -0
  594. package/dist/semantics/normalize/host-mutation-key-reader.js +192 -0
  595. package/dist/semantics/normalize/host-mutation-keys.d.ts +114 -0
  596. package/dist/semantics/normalize/host-mutation-keys.js +183 -0
  597. package/dist/semantics/normalize/identities.d.ts +172 -0
  598. package/dist/semantics/normalize/identities.js +426 -0
  599. package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +97 -0
  600. package/dist/semantics/normalize/implicit-arguments-tuple.js +197 -0
  601. package/dist/semantics/normalize/implicit-arguments.d.ts +11 -0
  602. package/dist/semantics/normalize/implicit-arguments.js +39 -0
  603. package/dist/semantics/normalize/instantiation.d.ts +73 -0
  604. package/dist/semantics/normalize/instantiation.js +399 -0
  605. package/dist/semantics/normalize/intrinsic-property-call.d.ts +18 -0
  606. package/dist/semantics/normalize/intrinsic-property-call.js +69 -0
  607. package/dist/semantics/normalize/intrinsic-prototype.d.ts +41 -0
  608. package/dist/semantics/normalize/intrinsic-prototype.js +87 -0
  609. package/dist/semantics/normalize/intrinsic-static-member.d.ts +14 -0
  610. package/dist/semantics/normalize/intrinsic-static-member.js +23 -0
  611. package/dist/semantics/normalize/jsdoc-type-names.d.ts +32 -0
  612. package/dist/semantics/normalize/jsdoc-type-names.js +512 -0
  613. package/dist/semantics/normalize/keyof.d.ts +32 -0
  614. package/dist/semantics/normalize/keyof.js +110 -0
  615. package/dist/semantics/normalize/local-bindings.d.ts +176 -0
  616. package/dist/semantics/normalize/local-bindings.js +1826 -0
  617. package/dist/semantics/normalize/logical-result-type.d.ts +16 -0
  618. package/dist/semantics/normalize/logical-result-type.js +102 -0
  619. package/dist/semantics/normalize/namespace-paths.d.ts +57 -0
  620. package/dist/semantics/normalize/namespace-paths.js +108 -0
  621. package/dist/semantics/normalize/normalize.d.ts +57 -0
  622. package/dist/semantics/normalize/normalize.js +68 -0
  623. package/dist/semantics/normalize/object-bag-bindings.d.ts +305 -0
  624. package/dist/semantics/normalize/object-bag-bindings.js +1290 -0
  625. package/dist/semantics/normalize/omitted-stated-parameter.d.ts +53 -0
  626. package/dist/semantics/normalize/omitted-stated-parameter.js +59 -0
  627. package/dist/semantics/normalize/open-type-form.d.ts +10 -0
  628. package/dist/semantics/normalize/open-type-form.js +32 -0
  629. package/dist/semantics/normalize/parameter-bindings.d.ts +361 -0
  630. package/dist/semantics/normalize/parameter-bindings.js +3339 -0
  631. package/dist/semantics/normalize/parameter-slot.d.ts +264 -0
  632. package/dist/semantics/normalize/parameter-slot.js +491 -0
  633. package/dist/semantics/normalize/physical-overload-result.d.ts +77 -0
  634. package/dist/semantics/normalize/physical-overload-result.js +99 -0
  635. package/dist/semantics/normalize/primitive-property-absence.d.ts +12 -0
  636. package/dist/semantics/normalize/primitive-property-absence.js +60 -0
  637. package/dist/semantics/normalize/producer-context.d.ts +376 -0
  638. package/dist/semantics/normalize/producer-context.js +1 -0
  639. package/dist/semantics/normalize/producers/allocations.d.ts +3 -0
  640. package/dist/semantics/normalize/producers/allocations.js +863 -0
  641. package/dist/semantics/normalize/producers/binding-kind.d.ts +37 -0
  642. package/dist/semantics/normalize/producers/binding-kind.js +36 -0
  643. package/dist/semantics/normalize/producers/bindings.d.ts +85 -0
  644. package/dist/semantics/normalize/producers/bindings.js +710 -0
  645. package/dist/semantics/normalize/producers/boundary.d.ts +34 -0
  646. package/dist/semantics/normalize/producers/boundary.js +123 -0
  647. package/dist/semantics/normalize/producers/class-lifecycle.d.ts +3 -0
  648. package/dist/semantics/normalize/producers/class-lifecycle.js +902 -0
  649. package/dist/semantics/normalize/producers/computations.d.ts +3 -0
  650. package/dist/semantics/normalize/producers/computations.js +613 -0
  651. package/dist/semantics/normalize/producers/control-loops.d.ts +30 -0
  652. package/dist/semantics/normalize/producers/control-loops.js +91 -0
  653. package/dist/semantics/normalize/producers/control.d.ts +30 -0
  654. package/dist/semantics/normalize/producers/control.js +923 -0
  655. package/dist/semantics/normalize/producers/declaration-lifecycle.d.ts +3 -0
  656. package/dist/semantics/normalize/producers/declaration-lifecycle.js +390 -0
  657. package/dist/semantics/normalize/producers/destructuring.d.ts +45 -0
  658. package/dist/semantics/normalize/producers/destructuring.js +1180 -0
  659. package/dist/semantics/normalize/producers/dynamic-language.d.ts +3 -0
  660. package/dist/semantics/normalize/producers/dynamic-language.js +70 -0
  661. package/dist/semantics/normalize/producers/erasure.d.ts +51 -0
  662. package/dist/semantics/normalize/producers/erasure.js +90 -0
  663. package/dist/semantics/normalize/producers/installed.d.ts +3 -0
  664. package/dist/semantics/normalize/producers/installed.js +55 -0
  665. package/dist/semantics/normalize/producers/invocations.d.ts +35 -0
  666. package/dist/semantics/normalize/producers/invocations.js +1796 -0
  667. package/dist/semantics/normalize/producers/iteration-yield.d.ts +59 -0
  668. package/dist/semantics/normalize/producers/iteration-yield.js +235 -0
  669. package/dist/semantics/normalize/producers/jsx.d.ts +3 -0
  670. package/dist/semantics/normalize/producers/jsx.js +360 -0
  671. package/dist/semantics/normalize/producers/mint.d.ts +39 -0
  672. package/dist/semantics/normalize/producers/mint.js +44 -0
  673. package/dist/semantics/normalize/producers/nullish.d.ts +16 -0
  674. package/dist/semantics/normalize/producers/nullish.js +27 -0
  675. package/dist/semantics/normalize/producers/object-assignment.d.ts +8 -0
  676. package/dist/semantics/normalize/producers/object-assignment.js +204 -0
  677. package/dist/semantics/normalize/producers/object-tag.d.ts +9 -0
  678. package/dist/semantics/normalize/producers/object-tag.js +119 -0
  679. package/dist/semantics/normalize/producers/optional-chain.d.ts +44 -0
  680. package/dist/semantics/normalize/producers/optional-chain.js +75 -0
  681. package/dist/semantics/normalize/producers/properties.d.ts +21 -0
  682. package/dist/semantics/normalize/producers/properties.js +1053 -0
  683. package/dist/semantics/normalize/producers/protocol.d.ts +67 -0
  684. package/dist/semantics/normalize/producers/protocol.js +695 -0
  685. package/dist/semantics/normalize/producers/references.d.ts +53 -0
  686. package/dist/semantics/normalize/producers/references.js +1027 -0
  687. package/dist/semantics/normalize/producers/shared.d.ts +561 -0
  688. package/dist/semantics/normalize/producers/shared.js +1683 -0
  689. package/dist/semantics/normalize/producers/spread-arguments.d.ts +72 -0
  690. package/dist/semantics/normalize/producers/spread-arguments.js +375 -0
  691. package/dist/semantics/normalize/producers/tagged-template.d.ts +5 -0
  692. package/dist/semantics/normalize/producers/tagged-template.js +307 -0
  693. package/dist/semantics/normalize/producers/tuple-spread.d.ts +189 -0
  694. package/dist/semantics/normalize/producers/tuple-spread.js +279 -0
  695. package/dist/semantics/normalize/property-key-domain.d.ts +36 -0
  696. package/dist/semantics/normalize/property-key-domain.js +150 -0
  697. package/dist/semantics/normalize/reachability.d.ts +189 -0
  698. package/dist/semantics/normalize/reachability.js +1057 -0
  699. package/dist/semantics/normalize/reassigned-bindings.d.ts +13 -0
  700. package/dist/semantics/normalize/reassigned-bindings.js +41 -0
  701. package/dist/semantics/normalize/record-storage-families.d.ts +11 -0
  702. package/dist/semantics/normalize/record-storage-families.js +109 -0
  703. package/dist/semantics/normalize/return-bindings.d.ts +260 -0
  704. package/dist/semantics/normalize/return-bindings.js +1311 -0
  705. package/dist/semantics/normalize/return-paths.d.ts +2 -0
  706. package/dist/semantics/normalize/return-paths.js +28 -0
  707. package/dist/semantics/normalize/script-global-redefinition.d.ts +44 -0
  708. package/dist/semantics/normalize/script-global-redefinition.js +75 -0
  709. package/dist/semantics/normalize/specialization.d.ts +201 -0
  710. package/dist/semantics/normalize/specialization.js +1824 -0
  711. package/dist/semantics/normalize/structural-array-element.d.ts +176 -0
  712. package/dist/semantics/normalize/structural-array-element.js +700 -0
  713. package/dist/semantics/normalize/structural-array-read.d.ts +13 -0
  714. package/dist/semantics/normalize/structural-array-read.js +124 -0
  715. package/dist/semantics/normalize/structural-callable.d.ts +12 -0
  716. package/dist/semantics/normalize/structural-callable.js +82 -0
  717. package/dist/semantics/normalize/structural-creation-order.d.ts +32 -0
  718. package/dist/semantics/normalize/structural-creation-order.js +111 -0
  719. package/dist/semantics/normalize/structural-declarations.d.ts +395 -0
  720. package/dist/semantics/normalize/structural-declarations.js +968 -0
  721. package/dist/semantics/normalize/structural-declared-body.d.ts +25 -0
  722. package/dist/semantics/normalize/structural-declared-body.js +147 -0
  723. package/dist/semantics/normalize/structural-generics.d.ts +56 -0
  724. package/dist/semantics/normalize/structural-generics.js +120 -0
  725. package/dist/semantics/normalize/structural-indexed-access.d.ts +11 -0
  726. package/dist/semantics/normalize/structural-indexed-access.js +126 -0
  727. package/dist/semantics/normalize/structural-instantiated-member.d.ts +64 -0
  728. package/dist/semantics/normalize/structural-instantiated-member.js +407 -0
  729. package/dist/semantics/normalize/structural-joins.d.ts +44 -0
  730. package/dist/semantics/normalize/structural-joins.js +143 -0
  731. package/dist/semantics/normalize/structural-layout-relevance.d.ts +29 -0
  732. package/dist/semantics/normalize/structural-layout-relevance.js +391 -0
  733. package/dist/semantics/normalize/structural-layout-type.d.ts +11 -0
  734. package/dist/semantics/normalize/structural-layout-type.js +1468 -0
  735. package/dist/semantics/normalize/structural-leaves.d.ts +49 -0
  736. package/dist/semantics/normalize/structural-leaves.js +125 -0
  737. package/dist/semantics/normalize/structural-local-union.d.ts +13 -0
  738. package/dist/semantics/normalize/structural-local-union.js +133 -0
  739. package/dist/semantics/normalize/structural-members.d.ts +26 -0
  740. package/dist/semantics/normalize/structural-members.js +84 -0
  741. package/dist/semantics/normalize/structural-mutable-method.d.ts +15 -0
  742. package/dist/semantics/normalize/structural-mutable-method.js +109 -0
  743. package/dist/semantics/normalize/structural-parts.d.ts +131 -0
  744. package/dist/semantics/normalize/structural-parts.js +737 -0
  745. package/dist/semantics/normalize/structural-receiver.d.ts +66 -0
  746. package/dist/semantics/normalize/structural-receiver.js +551 -0
  747. package/dist/semantics/normalize/structural-rules.d.ts +112 -0
  748. package/dist/semantics/normalize/structural-rules.js +93 -0
  749. package/dist/semantics/normalize/structural-self-reference.d.ts +150 -0
  750. package/dist/semantics/normalize/structural-self-reference.js +494 -0
  751. package/dist/semantics/normalize/structural.d.ts +202 -0
  752. package/dist/semantics/normalize/structural.js +4218 -0
  753. package/dist/semantics/normalize/unreduced-type-form.d.ts +41 -0
  754. package/dist/semantics/normalize/unreduced-type-form.js +53 -0
  755. package/dist/semantics/normalize/unresolvable-names.d.ts +56 -0
  756. package/dist/semantics/normalize/unresolvable-names.js +140 -0
  757. package/dist/semantics/package-sources.d.ts +16 -0
  758. package/dist/semantics/package-sources.js +365 -0
  759. package/dist/semantics/program.d.ts +151 -0
  760. package/dist/semantics/program.js +667 -0
  761. package/dist/semantics/prototype-install-source-transform.d.ts +4 -0
  762. package/dist/semantics/prototype-install-source-transform.js +341 -0
  763. package/dist/semantics/prototype-object-class-source-transform.d.ts +4 -0
  764. package/dist/semantics/prototype-object-class-source-transform.js +525 -0
  765. package/dist/semantics/prototype-reparenting.d.ts +50 -0
  766. package/dist/semantics/prototype-reparenting.js +317 -0
  767. package/dist/semantics/stable-checker.d.ts +10 -0
  768. package/dist/semantics/stable-checker.js +148 -0
  769. package/dist/semantics/subclass-member-overlay-transform.d.ts +35 -0
  770. package/dist/semantics/subclass-member-overlay-transform.js +1418 -0
  771. package/dist/semantics/symbol-keyed-expando-source-transform.d.ts +4 -0
  772. package/dist/semantics/symbol-keyed-expando-source-transform.js +66 -0
  773. package/dist/semantics/this-constructor-source-transform.d.ts +4 -0
  774. package/dist/semantics/this-constructor-source-transform.js +122 -0
  775. package/dist/semantics/uninstantiable-classes.d.ts +22 -0
  776. package/dist/semantics/uninstantiable-classes.js +75 -0
  777. package/dist/targets/cpp/balanced-units.d.ts +3 -0
  778. package/dist/targets/cpp/balanced-units.js +58 -0
  779. package/dist/targets/cpp/borrowed-call-entry.d.ts +30 -0
  780. package/dist/targets/cpp/borrowed-call-entry.js +68 -0
  781. package/dist/targets/cpp/captures.d.ts +68 -0
  782. package/dist/targets/cpp/captures.js +269 -0
  783. package/dist/targets/cpp/class-layout.d.ts +313 -0
  784. package/dist/targets/cpp/class-layout.js +483 -0
  785. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +25 -0
  786. package/dist/targets/cpp/class-properties/computed-method-value.js +22 -0
  787. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +216 -0
  788. package/dist/targets/cpp/class-properties/emit-class-properties.js +917 -0
  789. package/dist/targets/cpp/class-properties/native-prototype.d.ts +11 -0
  790. package/dist/targets/cpp/class-properties/native-prototype.js +101 -0
  791. package/dist/targets/cpp/class-ref-transport.d.ts +12 -0
  792. package/dist/targets/cpp/class-ref-transport.js +32 -0
  793. package/dist/targets/cpp/conversions.d.ts +3 -0
  794. package/dist/targets/cpp/conversions.js +2027 -0
  795. package/dist/targets/cpp/deferral-safety.d.ts +82 -0
  796. package/dist/targets/cpp/deferral-safety.js +86 -0
  797. package/dist/targets/cpp/direct-call-receivers.d.ts +37 -0
  798. package/dist/targets/cpp/direct-call-receivers.js +79 -0
  799. package/dist/targets/cpp/document.d.ts +74 -0
  800. package/dist/targets/cpp/document.js +106 -0
  801. package/dist/targets/cpp/emit-allocation.d.ts +60 -0
  802. package/dist/targets/cpp/emit-allocation.js +573 -0
  803. package/dist/targets/cpp/emit-arrays.d.ts +119 -0
  804. package/dist/targets/cpp/emit-arrays.js +1047 -0
  805. package/dist/targets/cpp/emit-binding-reference.d.ts +17 -0
  806. package/dist/targets/cpp/emit-binding-reference.js +120 -0
  807. package/dist/targets/cpp/emit-bindings.d.ts +158 -0
  808. package/dist/targets/cpp/emit-bindings.js +769 -0
  809. package/dist/targets/cpp/emit-buffers.d.ts +156 -0
  810. package/dist/targets/cpp/emit-buffers.js +573 -0
  811. package/dist/targets/cpp/emit-callable.d.ts +230 -0
  812. package/dist/targets/cpp/emit-callable.js +2154 -0
  813. package/dist/targets/cpp/emit-carrier-members.d.ts +406 -0
  814. package/dist/targets/cpp/emit-carrier-members.js +1224 -0
  815. package/dist/targets/cpp/emit-coercion.d.ts +26 -0
  816. package/dist/targets/cpp/emit-coercion.js +39 -0
  817. package/dist/targets/cpp/emit-context.d.ts +1882 -0
  818. package/dist/targets/cpp/emit-context.js +904 -0
  819. package/dist/targets/cpp/emit-dynamic-properties.d.ts +174 -0
  820. package/dist/targets/cpp/emit-dynamic-properties.js +1249 -0
  821. package/dist/targets/cpp/emit-equality.d.ts +39 -0
  822. package/dist/targets/cpp/emit-equality.js +472 -0
  823. package/dist/targets/cpp/emit-exceptions.d.ts +104 -0
  824. package/dist/targets/cpp/emit-exceptions.js +513 -0
  825. package/dist/targets/cpp/emit-field-owner.d.ts +4 -0
  826. package/dist/targets/cpp/emit-field-owner.js +27 -0
  827. package/dist/targets/cpp/emit-in.d.ts +31 -0
  828. package/dist/targets/cpp/emit-in.js +426 -0
  829. package/dist/targets/cpp/emit-instanceof.d.ts +19 -0
  830. package/dist/targets/cpp/emit-instanceof.js +601 -0
  831. package/dist/targets/cpp/emit-integers.d.ts +68 -0
  832. package/dist/targets/cpp/emit-integers.js +184 -0
  833. package/dist/targets/cpp/emit-iterator.d.ts +100 -0
  834. package/dist/targets/cpp/emit-iterator.js +1137 -0
  835. package/dist/targets/cpp/emit-json.d.ts +73 -0
  836. package/dist/targets/cpp/emit-json.js +823 -0
  837. package/dist/targets/cpp/emit-jsx.d.ts +74 -0
  838. package/dist/targets/cpp/emit-jsx.js +806 -0
  839. package/dist/targets/cpp/emit-mixed-binary.d.ts +51 -0
  840. package/dist/targets/cpp/emit-mixed-binary.js +60 -0
  841. package/dist/targets/cpp/emit-namespaces.d.ts +101 -0
  842. package/dist/targets/cpp/emit-namespaces.js +133 -0
  843. package/dist/targets/cpp/emit-narrowing.d.ts +738 -0
  844. package/dist/targets/cpp/emit-narrowing.js +3967 -0
  845. package/dist/targets/cpp/emit-native-equality.d.ts +3 -0
  846. package/dist/targets/cpp/emit-native-equality.js +14 -0
  847. package/dist/targets/cpp/emit-native-selection.d.ts +5 -0
  848. package/dist/targets/cpp/emit-native-selection.js +37 -0
  849. package/dist/targets/cpp/emit-object-tag.d.ts +4 -0
  850. package/dist/targets/cpp/emit-object-tag.js +108 -0
  851. package/dist/targets/cpp/emit-owned-record.d.ts +2 -0
  852. package/dist/targets/cpp/emit-owned-record.js +15 -0
  853. package/dist/targets/cpp/emit-presence.d.ts +78 -0
  854. package/dist/targets/cpp/emit-presence.js +376 -0
  855. package/dist/targets/cpp/emit-properties.d.ts +105 -0
  856. package/dist/targets/cpp/emit-properties.js +1640 -0
  857. package/dist/targets/cpp/emit-record-view.d.ts +20 -0
  858. package/dist/targets/cpp/emit-record-view.js +354 -0
  859. package/dist/targets/cpp/emit-return.d.ts +5 -0
  860. package/dist/targets/cpp/emit-return.js +237 -0
  861. package/dist/targets/cpp/emit-sum-widening.d.ts +10 -0
  862. package/dist/targets/cpp/emit-sum-widening.js +69 -0
  863. package/dist/targets/cpp/emit-tonumber.d.ts +38 -0
  864. package/dist/targets/cpp/emit-tonumber.js +177 -0
  865. package/dist/targets/cpp/emit-tostring.d.ts +92 -0
  866. package/dist/targets/cpp/emit-tostring.js +556 -0
  867. package/dist/targets/cpp/emit-typeof.d.ts +49 -0
  868. package/dist/targets/cpp/emit-typeof.js +317 -0
  869. package/dist/targets/cpp/emit-union-properties.d.ts +181 -0
  870. package/dist/targets/cpp/emit-union-properties.js +1281 -0
  871. package/dist/targets/cpp/emit.d.ts +45 -0
  872. package/dist/targets/cpp/emit.js +2225 -0
  873. package/dist/targets/cpp/error-types.d.ts +4 -0
  874. package/dist/targets/cpp/error-types.js +11 -0
  875. package/dist/targets/cpp/function-source-reads.d.ts +72 -0
  876. package/dist/targets/cpp/function-source-reads.js +148 -0
  877. package/dist/targets/cpp/host/atomics.d.ts +25 -0
  878. package/dist/targets/cpp/host/atomics.js +63 -0
  879. package/dist/targets/cpp/host/core-globals.d.ts +108 -0
  880. package/dist/targets/cpp/host/core-globals.js +158 -0
  881. package/dist/targets/cpp/host/dynamic-argument-members.d.ts +42 -0
  882. package/dist/targets/cpp/host/dynamic-argument-members.js +61 -0
  883. package/dist/targets/cpp/host/emit-host-arity.d.ts +139 -0
  884. package/dist/targets/cpp/host/emit-host-arity.js +232 -0
  885. package/dist/targets/cpp/host/emit-host-invoke.d.ts +91 -0
  886. package/dist/targets/cpp/host/emit-host-invoke.js +1105 -0
  887. package/dist/targets/cpp/host/emit-host-object.d.ts +55 -0
  888. package/dist/targets/cpp/host/emit-host-object.js +2206 -0
  889. package/dist/targets/cpp/host/emit-host-properties.d.ts +69 -0
  890. package/dist/targets/cpp/host/emit-host-properties.js +533 -0
  891. package/dist/targets/cpp/host/emit-host-reflect.d.ts +4 -0
  892. package/dist/targets/cpp/host/emit-host-reflect.js +180 -0
  893. package/dist/targets/cpp/host/emit-host-value.d.ts +120 -0
  894. package/dist/targets/cpp/host/emit-host-value.js +392 -0
  895. package/dist/targets/cpp/host/host-members.d.ts +505 -0
  896. package/dist/targets/cpp/host/host-members.js +819 -0
  897. package/dist/targets/cpp/host/host-method-aliases.d.ts +30 -0
  898. package/dist/targets/cpp/host/host-method-aliases.js +76 -0
  899. package/dist/targets/cpp/host/native-protocols.d.ts +47 -0
  900. package/dist/targets/cpp/host/native-protocols.js +183 -0
  901. package/dist/targets/cpp/host/object-protocol.d.ts +351 -0
  902. package/dist/targets/cpp/host/object-protocol.js +671 -0
  903. package/dist/targets/cpp/host-namespace-reads.d.ts +83 -0
  904. package/dist/targets/cpp/host-namespace-reads.js +113 -0
  905. package/dist/targets/cpp/manifest/capabilities.d.ts +39 -0
  906. package/dist/targets/cpp/manifest/capabilities.js +1484 -0
  907. package/dist/targets/cpp/manifest.d.ts +23 -0
  908. package/dist/targets/cpp/manifest.js +113 -0
  909. package/dist/targets/cpp/native-error-base.d.ts +38 -0
  910. package/dist/targets/cpp/native-error-base.js +74 -0
  911. package/dist/targets/cpp/native-narrowing-transport.d.ts +12 -0
  912. package/dist/targets/cpp/native-narrowing-transport.js +151 -0
  913. package/dist/targets/cpp/native-selection-helpers.d.ts +11 -0
  914. package/dist/targets/cpp/native-selection-helpers.js +46 -0
  915. package/dist/targets/cpp/native-symbol-keys.d.ts +8 -0
  916. package/dist/targets/cpp/native-symbol-keys.js +34 -0
  917. package/dist/targets/cpp/ownership.d.ts +43 -0
  918. package/dist/targets/cpp/ownership.js +38 -0
  919. package/dist/targets/cpp/owning-conversion-input.d.ts +14 -0
  920. package/dist/targets/cpp/owning-conversion-input.js +12 -0
  921. package/dist/targets/cpp/property-read-claims.d.ts +62 -0
  922. package/dist/targets/cpp/property-read-claims.js +23 -0
  923. package/dist/targets/cpp/property-store-claims.d.ts +62 -0
  924. package/dist/targets/cpp/property-store-claims.js +26 -0
  925. package/dist/targets/cpp/prototype/emit-prototype-array.d.ts +111 -0
  926. package/dist/targets/cpp/prototype/emit-prototype-array.js +602 -0
  927. package/dist/targets/cpp/prototype/emit-prototype-date.d.ts +133 -0
  928. package/dist/targets/cpp/prototype/emit-prototype-date.js +515 -0
  929. package/dist/targets/cpp/prototype/emit-prototype-error.d.ts +13 -0
  930. package/dist/targets/cpp/prototype/emit-prototype-error.js +54 -0
  931. package/dist/targets/cpp/prototype/emit-prototype-invoke.d.ts +34 -0
  932. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +1003 -0
  933. package/dist/targets/cpp/prototype/emit-prototype-iterator.d.ts +47 -0
  934. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +250 -0
  935. package/dist/targets/cpp/prototype/emit-prototype-promise.d.ts +46 -0
  936. package/dist/targets/cpp/prototype/emit-prototype-promise.js +143 -0
  937. package/dist/targets/cpp/prototype/emit-prototype-regexp.d.ts +335 -0
  938. package/dist/targets/cpp/prototype/emit-prototype-regexp.js +853 -0
  939. package/dist/targets/cpp/prototype/emit-prototype-string.d.ts +42 -0
  940. package/dist/targets/cpp/prototype/emit-prototype-string.js +252 -0
  941. package/dist/targets/cpp/prototype/prototype-method-reads.d.ts +25 -0
  942. package/dist/targets/cpp/prototype/prototype-method-reads.js +182 -0
  943. package/dist/targets/cpp/reactive-dependencies.d.ts +140 -0
  944. package/dist/targets/cpp/reactive-dependencies.js +432 -0
  945. package/dist/targets/cpp/reactive-origins.d.ts +44 -0
  946. package/dist/targets/cpp/reactive-origins.js +82 -0
  947. package/dist/targets/cpp/records.d.ts +277 -0
  948. package/dist/targets/cpp/records.js +2427 -0
  949. package/dist/targets/cpp/recursive-containers.d.ts +43 -0
  950. package/dist/targets/cpp/recursive-containers.js +144 -0
  951. package/dist/targets/cpp/regexp-types.d.ts +56 -0
  952. package/dist/targets/cpp/regexp-types.js +59 -0
  953. package/dist/targets/cpp/substrate.d.ts +125 -0
  954. package/dist/targets/cpp/substrate.js +12 -0
  955. package/dist/targets/cpp/translation-unit.d.ts +219 -0
  956. package/dist/targets/cpp/translation-unit.js +2063 -0
  957. package/dist/targets/cpp/types.d.ts +280 -0
  958. package/dist/targets/cpp/types.js +1135 -0
  959. package/dist/targets/cpp/virtual-methods.d.ts +95 -0
  960. package/dist/targets/cpp/virtual-methods.js +264 -0
  961. package/package.json +95 -0
  962. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +824 -0
  963. package/src/targets/cpp/runtime/gea_eval.h +1376 -0
  964. package/src/targets/cpp/runtime/gea_native_class_prototype.h +44 -0
  965. package/src/targets/cpp/runtime/gea_runtime.h +29222 -0
  966. package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +55 -0
@@ -0,0 +1,823 @@
1
+ import { allOperationsOf } from '../../ir/model.js';
2
+ import { representationKey } from '../../representation/model.js';
3
+ import { bindingReference, createCppEmitBlockedError, declareCell, defineValueAlias, operandText } from './emit-context.js';
4
+ import { cellValueText } from './emit-bindings.js';
5
+ import { dynamicCarrierBoxText } from './emit-narrowing.js';
6
+ import { classBoxable } from './class-layout.js';
7
+ import { readsCell } from './deferral-safety.js';
8
+ import { cppDateType } from './prototype/emit-prototype-date.js';
9
+ import { recordFieldsOfShape } from './records.js';
10
+ import { cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppStringLiteral, cppTypeOf } from './types.js';
11
+ import { armAt, armIs } from './emit-union-properties.js';
12
+ /**
13
+ * Whether `representation` is one JSON-carrying arm plus absence arms.
14
+ *
15
+ * Anything wider is a genuine sum with no JSON discriminator -- a document
16
+ * says `3`, not which arm of `number | Point` produced it -- so it answers
17
+ * `null` and the caller refuses by name. Shared by the collector and by the
18
+ * record renderer so both read exactly one rule.
19
+ */
20
+ const nullableUnionArmsOf = (representation) => {
21
+ if (representation.kind !== 'tagged-union')
22
+ return null;
23
+ const nullIndex = representation.arms.findIndex((arm) => arm.value.kind === 'null');
24
+ const undefinedIndex = representation.arms.findIndex((arm) => arm.value.kind === 'undefined');
25
+ const presentIndex = representation.arms.findIndex((arm) => arm.value.kind !== 'null' && arm.value.kind !== 'undefined');
26
+ const absenceCount = (nullIndex === -1 ? 0 : 1) + (undefinedIndex === -1 ? 0 : 1);
27
+ const payload = representation.arms[presentIndex]?.value;
28
+ if (nullIndex === -1 || presentIndex === -1 || payload === undefined)
29
+ return null;
30
+ if (representation.arms.length !== absenceCount + 1)
31
+ return null;
32
+ return { nullIndex, presentIndex, undefinedIndex, payload };
33
+ };
34
+ /** A fresh, empty collector for one walk. */
35
+ const emptyJsonCollected = () => ({ structs: new Map(), nullableUnions: new Map() });
36
+ /**
37
+ * Whether `representation` has a native `gea_json_write`/`gea_json_read`
38
+ * mapping, and -- as a side effect -- every record struct reaching that
39
+ * mapping requires, collected into `structsByName` (keyed by C++ struct name,
40
+ * so two call sites naming the same shape render its overload pair once).
41
+ *
42
+ * Returns `null` when supported; otherwise the reason, prefixed by nothing --
43
+ * callers add their own "JSON.stringify/parse cannot ... :" framing so one
44
+ * message reads naturally however deep the field/element nesting that
45
+ * produced it.
46
+ *
47
+ * `visiting` is the self-reference guard: a record shape entered while it is
48
+ * still on the walk's own stack is a cycle, refused by name instead of
49
+ * recursing forever the way a genuinely cyclic *value* would at runtime (see
50
+ * this file's own top comment).
51
+ */
52
+ const jsonUnsupportedReason = (deriver, representation, collected, visiting, direction) => {
53
+ switch (representation.kind) {
54
+ case 'dynamic':
55
+ return null;
56
+ case 'dictionary':
57
+ return direction === 'write' && representation.key === 'string' && representation.value.kind === 'dynamic'
58
+ ? null
59
+ : `representation "${representationKey(representation)}" has no native JSON.stringify/parse mapping`;
60
+ case 'string':
61
+ return null;
62
+ case 'scalar':
63
+ // `bigint`/`int32`/`uint32`/`float64` are narrower numeric domains this
64
+ // backend infers for typed-array elements and similar contexts, never
65
+ // for an ordinary interface field a JSON document would hold -- no
66
+ // corpus call site needs them, and JSON's own grammar has no way to
67
+ // round-trip a `bigint` losslessly through `number` anyway (ECMA-262
68
+ // `JSON.stringify` itself throws a `TypeError` on a real `bigint`).
69
+ return representation.domain === 'number' || representation.domain === 'boolean'
70
+ ? null
71
+ : `a "${representation.domain}" scalar has no JSON.stringify/parse mapping`;
72
+ case 'array-object':
73
+ return jsonUnsupportedReason(deriver, representation.element, collected, visiting, direction);
74
+ case 'record':
75
+ case 'native-record-ref': {
76
+ // A carrier whose struct the HOST declares has no compiler-emitted
77
+ // layout at all (`records.ts` renders none when `native` is stated), so
78
+ // the field-by-field overload pair below would name a type that does not
79
+ // exist -- which is a clang error rather than a refusal. Answered here,
80
+ // ahead of the layout walk, for every such carrier.
81
+ if (representation.kind === 'native-record-ref' && representation.native !== null) {
82
+ if (representation.native !== cppDateType) {
83
+ return (`"${representation.native}" is a struct the host declares, so this compiler emits no layout for it and cannot ` +
84
+ 'render a field-by-field JSON overload against it');
85
+ }
86
+ // A Date is the one such carrier with a real answer, and only for a
87
+ // value this walk reaches OUTSIDE a generated record: ECMA-262
88
+ // 25.5.2.2 step 3 calls `toJSON`, so writing one is its ISO string
89
+ // (or `null` for a non-finite time value), which `gea_runtime.h`
90
+ // supplies as its own `gea_json_write` overload -- nothing to collect
91
+ // here, because nothing is generated for it. Measured against node:
92
+ // `JSON.stringify(new Date(0))` and `JSON.stringify([d1, d2])` both
93
+ // match byte-for-byte.
94
+ //
95
+ // Three cases are refused instead, each by name:
96
+ //
97
+ // - READING one. JSON has no date type, so nothing in a document
98
+ // decodes into a Date; `JSON.parse(text) as Date` asserts a shape
99
+ // the grammar cannot carry (node answers a plain string for it).
100
+ // - A Date as a FIELD of a record. `renderJsonRecordOverloads` emits
101
+ // the write AND read halves of a struct's pair together, so a
102
+ // record with a Date member would render a `gea_json_read(reader,
103
+ // out.at)` against a Date -- the read this same walk just refused,
104
+ // reaching clang as an error rather than as a refusal. A non-empty
105
+ // `visiting` is exactly "inside a generated struct"; an array
106
+ // element is not, because the array writer is a runtime template
107
+ // with no generated pair.
108
+ if (direction === 'read') {
109
+ return ('JSON has no date type, so nothing in a document decodes into a Date; `JSON.parse(text) as Date` asserts a shape the ' +
110
+ 'grammar cannot carry (node answers a string for it), and reviving one is the `reviver` parameter this backend does not implement');
111
+ }
112
+ if (visiting.size > 0) {
113
+ return ('a Date inside a record has no JSON mapping here: a record renders its write and read overloads as one pair, and ' +
114
+ 'the read half would have to decode a Date out of a document that has no date type. A Date serialized on its own, ' +
115
+ 'or as an array element, does render');
116
+ }
117
+ return null;
118
+ }
119
+ const structName = cppRecordStructName(representation.shapeId);
120
+ // A record reached while it is still on this walk's own stack is a
121
+ // RECURSIVE TYPE, and a recursive type is not a cyclic value. `type Node
122
+ // = { children: Node[] }` describes every tree as well as every cycle,
123
+ // and a tree serializes finitely -- which is what the corpus actually
124
+ // holds: `bench/comparison`'s `json_stringify_nested` builds a depth-6
125
+ // fan-4 tree and node prints it without complaint.
126
+ //
127
+ // So the answer is the overload pair, which is recursive C++ and
128
+ // terminates on the same values the language terminates on.
129
+ // `renderJsonStructDeclarations` forward-declares every pair before any
130
+ // body, so a struct calling its own overload -- directly or through the
131
+ // array template -- names one already declared.
132
+ //
133
+ // What this gives up is the compile-time refusal of a cyclic VALUE, and
134
+ // it was never a sound one: the type says nothing about whether a given
135
+ // value has a back edge. A real cycle recurses until the stack
136
+ // overflows, which is exactly what this file's own header already
137
+ // discloses for every other self-referential value, and what node
138
+ // answers instead is a `TypeError` this backend does not raise.
139
+ if (visiting.has(structName))
140
+ return null;
141
+ if (collected.structs.has(structName))
142
+ return null;
143
+ const fields = recordFieldsOfShape(deriver, representation.shapeId);
144
+ if (fields === null)
145
+ return `no record layout could be derived for shape ${representation.shapeId}`;
146
+ const stillVisiting = new Set(visiting);
147
+ stillVisiting.add(structName);
148
+ for (const field of fields) {
149
+ // An actual `T | undefined` field (as opposed to a bare `?` marker,
150
+ // which `records.ts` documents as never producing an `optional`
151
+ // carrier at all) is the one place `optional` is legal here: ECMA-262
152
+ // omits the whole property rather than writing `null` for it, which
153
+ // only a record's own field position has a spelling for -- an array
154
+ // element or a bare call argument does not, so `optional` anywhere
155
+ // else falls through to the `default:` refusal below.
156
+ const fieldRepresentation = field.value.kind === 'optional' && field.value.absence === 'undefined' ? field.value.payload : field.value;
157
+ const reason = jsonUnsupportedReason(deriver, fieldRepresentation, collected, stillVisiting, direction);
158
+ if (reason)
159
+ return `field "${field.key}" of record "${structName}": ${reason}`;
160
+ }
161
+ // Recorded only after every field resolved: a record that turns out to
162
+ // be unsupported must not leave a partial entry another call site's
163
+ // `collected.structs.has(structName)` short-circuit could mistake for done.
164
+ collected.structs.set(structName, { structName, fields });
165
+ return null;
166
+ }
167
+ case 'tagged-union': {
168
+ const arms = nullableUnionArmsOf(representation);
169
+ if (arms === null) {
170
+ return ('representation kind "tagged-union" has no native JSON.stringify/parse mapping unless its arms are one JSON-carrying type ' +
171
+ 'plus `null` (optionally with `undefined` too); a wider sum has no discriminator in the document to decode back with');
172
+ }
173
+ const reason = jsonUnsupportedReason(deriver, arms.payload, collected, visiting, direction);
174
+ if (reason !== null)
175
+ return reason;
176
+ const typeName = cppTypeOf(representation);
177
+ // Keyed by the C++ type, so two shapes that lower to the same union
178
+ // render one pair -- the same rule the records above follow.
179
+ if (!collected.nullableUnions.has(typeName)) {
180
+ collected.nullableUnions.set(typeName, {
181
+ typeName,
182
+ nullIndex: arms.nullIndex,
183
+ presentIndex: arms.presentIndex,
184
+ payload: arms.payload
185
+ });
186
+ }
187
+ return null;
188
+ }
189
+ default:
190
+ // `dynamic`, `class-ref`, `record-with-index`, `dictionary`, `function`,
191
+ // `promise`, and everything else this switch does not name above: none
192
+ // has a native JSON mapping, and reaching for `gea_cpp_value` to give it
193
+ // one anyway is exactly the boxing shortcut this compiler forbids (see
194
+ // this repo's root CLAUDE.md, "The Compiler Rule: No Boxing").
195
+ return `representation "${representationKey(representation)}" has no native JSON.stringify/parse mapping`;
196
+ }
197
+ };
198
+ /**
199
+ * The `gea_json_write`/`gea_json_read` pair for one nullable union.
200
+ *
201
+ * A standalone overload on the union type rather than a case inside the record
202
+ * renderer, so the same shape serializes wherever it appears -- a field, an
203
+ * array element, or the whole argument -- and so the record renderer's plain
204
+ * field path reaches it by ordinary overload resolution. The one thing a
205
+ * standalone overload cannot express is a record field's `undefined` arm,
206
+ * because omitting a property is the enclosing OBJECT's spelling and not the
207
+ * value's; `renderJsonRecordOverloads` guards that case itself, exactly as it
208
+ * already does for an `optional(T, undefined)` field.
209
+ *
210
+ * The read side asks the reader for a `null` literal FIRST (`consumeNull`
211
+ * leaves the position untouched when the next value is not one), because that
212
+ * is the only question whose answer picks the arm; anything else is the payload
213
+ * and is decoded by the payload's own overload.
214
+ */
215
+ const renderJsonNullableUnionOverloads = (entry) => {
216
+ const payloadType = cppTypeOf(entry.payload);
217
+ const write = [
218
+ `inline void gea_json_write(std::string& out, const ${entry.typeName}& value) {`,
219
+ ` if (value.is<${entry.presentIndex}>()) { gea_json_write(out, value.get<${entry.presentIndex}>()); return; }`,
220
+ ` out += "null";`,
221
+ `}`
222
+ ];
223
+ const read = [
224
+ `inline void gea_json_read(gea::json::Reader& reader, ${entry.typeName}& out) {`,
225
+ ` if (reader.consumeNull()) {`,
226
+ ` out = ${entry.typeName}::ofArm<${entry.nullIndex}>(${entry.typeName}::ArmType<${entry.nullIndex}>{});`,
227
+ ` return;`,
228
+ ` }`,
229
+ ` ${payloadType} gea_json_arm{};`,
230
+ ` gea_json_read(reader, gea_json_arm);`,
231
+ ` out = ${entry.typeName}::ofArm<${entry.presentIndex}>(gea_json_arm);`,
232
+ `}`
233
+ ];
234
+ return `${write.join('\n')}\n\n${read.join('\n')}`;
235
+ };
236
+ /**
237
+ * A record field's JS property name, JSON-escaped and wrapped as a C++ string
238
+ * literal ending in the field's trailing colon -- e.g. `id` becomes the C++
239
+ * literal spelling `"\"id\":"`.
240
+ *
241
+ * `leading` is folded into the SAME literal rather than appended separately:
242
+ * the separator before a field the writer always emits is statically known, and
243
+ * `out += ",\"score\":"` is one capacity check where `out += ','; out +=
244
+ * "\"score\":";` is two.
245
+ */
246
+ const jsonKeyLiteral = (key, leading = '') => {
247
+ let jsonEscaped = '';
248
+ for (const ch of key) {
249
+ const code = ch.codePointAt(0) ?? 0;
250
+ if (ch === '"')
251
+ jsonEscaped += '\\"';
252
+ else if (ch === '\\')
253
+ jsonEscaped += '\\\\';
254
+ else if (ch === '\b')
255
+ jsonEscaped += '\\b';
256
+ else if (ch === '\f')
257
+ jsonEscaped += '\\f';
258
+ else if (ch === '\n')
259
+ jsonEscaped += '\\n';
260
+ else if (ch === '\r')
261
+ jsonEscaped += '\\r';
262
+ else if (ch === '\t')
263
+ jsonEscaped += '\\t';
264
+ else if (code < 0x20)
265
+ jsonEscaped += `\\u${code.toString(16).padStart(4, '0')}`;
266
+ else
267
+ jsonEscaped += ch;
268
+ }
269
+ return cppStringLiteral(`${leading}"${jsonEscaped}":`);
270
+ };
271
+ /**
272
+ * Whether a property name can be matched against the document BYTE FOR BYTE,
273
+ * which is what `gea::json::Reader::keyIs` does -- no scan for the key's closing
274
+ * quote, just a length-anchored `memcmp`.
275
+ *
276
+ * A key needing any JSON escape (a quote, a backslash, a control character) is
277
+ * spelled differently in the document than in the C++ literal, and a non-ASCII
278
+ * one is a different number of bytes than characters. Both answer `false`, and
279
+ * the generated reader then uses only its decoded chain -- the same one that
280
+ * catches an escaped spelling of an ordinary key.
281
+ */
282
+ const isPlainAsciiKey = (key) => {
283
+ for (const ch of key) {
284
+ const code = ch.codePointAt(0) ?? 0;
285
+ if (code < 0x20 || code > 0x7e || ch === '"' || ch === '\\')
286
+ return false;
287
+ }
288
+ return true;
289
+ };
290
+ /** The `gea_json_write(std::string&, const StructName&)` / `gea_json_read(gea::json::Reader&, StructName&)` overload pair for one record struct, walking its real fields -- never a boxed intermediate. */
291
+ const renderJsonRecordOverloads = (entry) => {
292
+ // Whether the object's first property is known at GENERATION time. It is,
293
+ // until a field that ECMA-262 25.5.2.2 may omit is reached -- and for a record
294
+ // with no such field (every record in the corpus) the whole `gea_json_first`
295
+ // bookkeeping disappears and each separator is folded into the key literal.
296
+ const omittable = (field) => {
297
+ if (!field.required)
298
+ return true;
299
+ const arms = nullableUnionArmsOf(field.value);
300
+ if (arms !== null && arms.undefinedIndex !== -1)
301
+ return true;
302
+ return field.value.kind === 'optional' && field.value.absence === 'undefined';
303
+ };
304
+ const anyOmittable = entry.fields.some(omittable);
305
+ let staticFirst = true;
306
+ const writeLines = [`inline void gea_json_write(std::string& out, const ${entry.structName}& value) {`, ` out += '{';`];
307
+ if (anyOmittable)
308
+ writeLines.push(` bool gea_json_first = true;`);
309
+ // The body that reads ONE field's value, rendered once and used by both key
310
+ // chains below.
311
+ const readBodyOf = (field, indent) => {
312
+ const target = cppRecordFieldName(field.key);
313
+ const optional = field.value.kind === 'optional' && (field.value.absence === 'undefined' || field.value.absence === 'null');
314
+ if (!optional) {
315
+ return [
316
+ `${indent}gea_json_read(reader, out.${target});`,
317
+ ...(!field.required ? [`${indent}out.${cppRecordFieldPresenceName(field.key)} = true;`] : [])
318
+ ];
319
+ }
320
+ const payloadType = cppTypeOf(field.value.kind === 'optional' ? field.value.payload : field.value);
321
+ return [
322
+ `${indent}${payloadType} gea_json_field{};`,
323
+ `${indent}gea_json_read(reader, gea_json_field);`,
324
+ `${indent}out.${target} = gea_json_field;`,
325
+ ...(!field.required ? [`${indent}out.${cppRecordFieldPresenceName(field.key)} = true;`] : [])
326
+ ];
327
+ };
328
+ const readLines = [
329
+ `inline void gea_json_read(gea::json::Reader& reader, ${entry.structName}& out) {`,
330
+ ` if (!reader.enterObject()) return;`,
331
+ // The key is taken as a VIEW of the document rather than copied into a
332
+ // buffer per property: an unescaped key is already a contiguous run there,
333
+ // and the comparisons below then discriminate on length before touching a
334
+ // byte. `gea_json_scratch` is the reader's decode buffer for the escaped
335
+ // key that cannot be viewed -- one per object, not one per key.
336
+ ` std::string gea_json_scratch;`,
337
+ ` std::string_view gea_json_key;`,
338
+ ` for (;;) {`
339
+ ];
340
+ // The fast chain: each candidate field name matched against the document
341
+ // where it stands, no scan for its closing quote. `nextKey` had to find that
342
+ // quote before it could compare anything at all, and finding it was 19% of
343
+ // `json_parse_records`. Only reachable when every key is plain ASCII -- see
344
+ // `isPlainAsciiKey` -- and a key the chain misses (an escaped spelling, a
345
+ // space before the colon, a key this record does not declare) falls through
346
+ // to the decoded chain below, which is what the reader always did.
347
+ const fastKeys = entry.fields.length > 0 && entry.fields.every((field) => isPlainAsciiKey(field.key));
348
+ // Both chains answer one question -- WHICH declared field this key names --
349
+ // and the answer is an index into a single `switch` that holds each field's
350
+ // read body exactly once. Rendering the body under every match spelled every
351
+ // field twice, once per chain: N extra copies of a read per N-field record,
352
+ // which the C++ compiler cannot share and which doubled the reader of every
353
+ // store record in `examples/apps/weather`.
354
+ readLines.push(` int gea_json_which = -1;`);
355
+ if (fastKeys) {
356
+ entry.fields.forEach((field, at) => {
357
+ readLines.push(` ${at === 0 ? 'if' : 'else if'} (reader.keyIs(${cppStringLiteral(field.key)}, ${field.key.length})) gea_json_which = ${at};`);
358
+ });
359
+ readLines.push(` else {`);
360
+ }
361
+ const inner = fastKeys ? ' ' : ' ';
362
+ readLines.push(`${inner}if (!reader.nextKey(gea_json_key, gea_json_scratch)) break;`);
363
+ let firstKey = true;
364
+ for (const [index, field] of entry.fields.entries()) {
365
+ const member = cppRecordFieldName(field.key);
366
+ const keyLiteral = jsonKeyLiteral(field.key);
367
+ // The read side compares the DECODED key text `nextKey` produced against
368
+ // the field's own JS property name -- an ordinary C++ string literal, not
369
+ // the JSON-escaped-then-quoted-with-a-colon form `jsonKeyLiteral` builds
370
+ // for the write side's output stream.
371
+ const keyComparisonLiteral = cppStringLiteral(field.key);
372
+ const isOptionalUndefined = field.value.kind === 'optional' && field.value.absence === 'undefined';
373
+ // `T | null | undefined` reaches here as a three-armed union rather than
374
+ // an `optional`, so the omission ECMA-262 25.5.2.2 requires for the
375
+ // `undefined` arm has to be asked of the union directly. Its `null` arm
376
+ // and its payload are the standalone overload's business, not this one's.
377
+ const unionArms = nullableUnionArmsOf(field.value);
378
+ const undefinedArmIndex = unionArms !== null && unionArms.undefinedIndex !== -1 ? unionArms.undefinedIndex : null;
379
+ // An omittable field cannot answer "is this the first property?" until it
380
+ // runs, so the first one hands the question over to `gea_json_first` -- and
381
+ // the flag has to be told what the fields before it already decided.
382
+ if (omittable(field) && staticFirst !== null) {
383
+ if (!staticFirst)
384
+ writeLines.push(` gea_json_first = false;`);
385
+ staticFirst = null;
386
+ }
387
+ // The separator, for a field the writer always emits: nothing before the
388
+ // first property, a comma after it, and only a record that has already
389
+ // passed an omittable field asks at run time.
390
+ const alwaysWritten = !omittable(field);
391
+ const foldedKey = alwaysWritten && staticFirst !== null ? jsonKeyLiteral(field.key, staticFirst ? '' : ',') : keyLiteral;
392
+ if (alwaysWritten && staticFirst !== null)
393
+ staticFirst = false;
394
+ else if (alwaysWritten)
395
+ writeLines.push(` if (!gea_json_first) out += ',';`);
396
+ if (!field.required)
397
+ writeLines.push(` if (value.${cppRecordFieldPresenceName(field.key)}) {`);
398
+ if (undefinedArmIndex !== null) {
399
+ writeLines.push(` if (!value.${member}.is<${undefinedArmIndex}>()) {`);
400
+ writeLines.push(` if (!gea_json_first) out += ',';`);
401
+ writeLines.push(` out += ${keyLiteral};`);
402
+ writeLines.push(` gea_json_write(out, value.${member});`);
403
+ writeLines.push(` gea_json_first = false;`);
404
+ writeLines.push(` }`);
405
+ }
406
+ else if (isOptionalUndefined) {
407
+ writeLines.push(` if (value.${member}.has_value()) {`);
408
+ writeLines.push(` if (!gea_json_first) out += ',';`);
409
+ writeLines.push(` out += ${keyLiteral};`);
410
+ writeLines.push(` gea_json_write(out, *value.${member});`);
411
+ writeLines.push(` gea_json_first = false;`);
412
+ writeLines.push(` }`);
413
+ }
414
+ else if (field.value.kind === 'optional' && field.value.absence === 'null') {
415
+ // ECMA-262 does not omit a `T | null` property the way it omits
416
+ // `undefined` -- it always writes the key, with `null` when absent.
417
+ if (!field.required)
418
+ writeLines.push(` if (!gea_json_first) out += ',';`);
419
+ writeLines.push(` out += ${foldedKey};`);
420
+ writeLines.push(` if (value.${member}.has_value()) gea_json_write(out, *value.${member}); else out += "null";`);
421
+ if (staticFirst === null)
422
+ writeLines.push(` gea_json_first = false;`);
423
+ }
424
+ else {
425
+ if (!field.required)
426
+ writeLines.push(` if (!gea_json_first) out += ',';`);
427
+ writeLines.push(` out += ${foldedKey};`);
428
+ writeLines.push(` gea_json_write(out, value.${member});`);
429
+ if (staticFirst === null)
430
+ writeLines.push(` gea_json_first = false;`);
431
+ }
432
+ if (!field.required)
433
+ writeLines.push(` }`);
434
+ readLines.push(`${inner}${firstKey ? 'if' : 'else if'} (gea_json_key == ${keyComparisonLiteral}) gea_json_which = ${index};`);
435
+ firstKey = false;
436
+ }
437
+ if (fastKeys)
438
+ readLines.push(` }`);
439
+ readLines.push(` switch (gea_json_which) {`);
440
+ entry.fields.forEach((field, at) => {
441
+ readLines.push(` case ${at}: {`);
442
+ readLines.push(...readBodyOf(field, ' '));
443
+ readLines.push(` break;`);
444
+ readLines.push(` }`);
445
+ });
446
+ readLines.push(` default:`);
447
+ readLines.push(` reader.skipValue();`);
448
+ readLines.push(` break;`);
449
+ readLines.push(` }`);
450
+ readLines.push(` if (!reader.advance()) break;`);
451
+ readLines.push(` }`);
452
+ readLines.push(`}`);
453
+ writeLines.push(` out += '}';`);
454
+ writeLines.push(`}`);
455
+ return `${writeLines.join('\n')}\n\n${readLines.join('\n')}`;
456
+ };
457
+ /**
458
+ * Every `JSON.stringify`/`JSON.parse` call site in `bodies`, found by walking
459
+ * IR directly rather than reading `EmitContext.hostMemberReads` -- that map is
460
+ * only populated incrementally as `emit-properties.ts` renders each body's own
461
+ * property reads, which happens *after* `translation-unit.ts` must already
462
+ * have every struct declaration in hand (see this file's own callers there).
463
+ *
464
+ * A `'get'` operation is a JSON-member reference when its RECEIVER's own
465
+ * representation is the `JSON` native handle and its key is the constant text
466
+ * `"stringify"`/`"parse"` -- the identical two facts
467
+ * `emit-properties.ts`'s `nativeHandleMemberText` keys its own dispatch on,
468
+ * just read here directly off the IR instead of through that file's
469
+ * emission-time bookkeeping. A `'call'` operation is then a JSON call when its
470
+ * callee traces back to one such `'get'`.
471
+ */
472
+ const jsonRootsOf = (bodies) => {
473
+ const sites = [];
474
+ for (const body of bodies) {
475
+ const constantTextOf = new Map();
476
+ for (const blockId of body.blockOrder) {
477
+ const block = body.blocks.get(blockId);
478
+ if (!block)
479
+ continue;
480
+ for (const operation of allOperationsOf(block)) {
481
+ if (operation.kind === 'constant')
482
+ constantTextOf.set(operation.result.id, operation.text);
483
+ }
484
+ }
485
+ const jsonMemberOf = new Map();
486
+ for (const blockId of body.blockOrder) {
487
+ const block = body.blocks.get(blockId);
488
+ if (!block)
489
+ continue;
490
+ for (const operation of allOperationsOf(block)) {
491
+ if (operation.kind !== 'get')
492
+ continue;
493
+ const receiverRepresentation = operation.receiver.representation;
494
+ if (receiverRepresentation.kind !== 'native-handle' || receiverRepresentation.protocol !== 'JSON')
495
+ continue;
496
+ const keyText = constantTextOf.get(operation.key.value);
497
+ if (keyText === 'stringify' || keyText === 'parse')
498
+ jsonMemberOf.set(operation.result.id, keyText);
499
+ }
500
+ }
501
+ if (jsonMemberOf.size === 0)
502
+ continue;
503
+ for (const blockId of body.blockOrder) {
504
+ const block = body.blocks.get(blockId);
505
+ if (!block)
506
+ continue;
507
+ for (const operation of allOperationsOf(block)) {
508
+ if (operation.kind !== 'call')
509
+ continue;
510
+ const member = jsonMemberOf.get(operation.callee.value);
511
+ if (member === undefined)
512
+ continue;
513
+ if (member === 'stringify') {
514
+ const argument = operation.arguments[0];
515
+ if (argument)
516
+ sites.push({ member, representation: argument.representation });
517
+ }
518
+ else if (operation.result) {
519
+ sites.push({ member, representation: operation.result.representation });
520
+ }
521
+ }
522
+ }
523
+ }
524
+ return sites;
525
+ };
526
+ /**
527
+ * Every `gea_json_write`/`gea_json_read` record overload this program's own
528
+ * JSON call sites require, rendered once each in deterministic (struct-name)
529
+ * order.
530
+ *
531
+ * Deliberately reports no refusals of its own: a call site whose shape this
532
+ * file cannot serialize/decode natively refuses at the SAME check,
533
+ * independently, when `jsonCallText` (below) renders that call for real
534
+ * during body emission -- duplicating that refusal here would either have to
535
+ * agree with it forever by construction (in which case it is dead code) or
536
+ * risk silently disagreeing with it (in which case one of the two is wrong).
537
+ * A struct this function fails to collect for an unsupported call site simply
538
+ * never gets declared; that call's own emission refuses by name, and the
539
+ * translation unit it belongs to is discarded whole, same as any other
540
+ * refused body (`translation-unit.ts`'s `CppTranslationUnitResult.source`).
541
+ */
542
+ export const renderJsonStructDeclarations = (bodies, deriver) => {
543
+ const collected = emptyJsonCollected();
544
+ for (const site of jsonRootsOf(bodies)) {
545
+ jsonUnsupportedReason(deriver, site.representation, collected, new Set(), site.member === 'stringify' ? 'write' : 'read');
546
+ }
547
+ const names = [...collected.structs.keys()].sort();
548
+ const unionNames = [...collected.nullableUnions.keys()].sort();
549
+ // Every pair is declared before any pair is defined. Required as soon as a
550
+ // record's field reaches the record itself: the write body calls
551
+ // `gea_json_write` on its own struct -- through `std::vector`'s template for
552
+ // a `Node[]` field, whose dependent call resolves at instantiation -- and a
553
+ // definition that has not been declared yet is a clang error rather than a
554
+ // refusal. Unconditional rather than only-when-recursive because the cost is
555
+ // two lines per struct and the alternative is a second rule deciding when
556
+ // they are needed.
557
+ const forwards = [...names, ...unionNames].flatMap((name) => [
558
+ `inline void gea_json_write(std::string& out, const ${name}& value);`,
559
+ `inline void gea_json_read(gea::json::Reader& reader, ${name}& out);`
560
+ ]);
561
+ const declarations = [
562
+ ...forwards,
563
+ ...names.map((name) => renderJsonRecordOverloads(collected.structs.get(name))),
564
+ ...unionNames.map((name) => renderJsonNullableUnionOverloads(collected.nullableUnions.get(name)))
565
+ ];
566
+ return { declarations, structNames: new Set(names) };
567
+ };
568
+ /**
569
+ * One `JSON.stringify`/`JSON.parse` call, rendered as a single C++ expression
570
+ * -- `emit-host-invoke.ts`'s `hostCallText` consumes this the same way it
571
+ * consumes every other host call's text, spliced directly into
572
+ * `${defineValue(ctx, operation.result)} = ${hostCall};` (`emit-callable.ts`).
573
+ * A lambda-IIFE is what makes a multi-statement C++ sequence (allocate a
574
+ * reader, decode into a local, return it) into one expression a plain
575
+ * assignment can consume; there is no other rendering site in this backend
576
+ * that needs the same trick, because every other host call already has a
577
+ * single C++ expression to name.
578
+ */
579
+ /**
580
+ * Whether a box of `representation` holds nothing the dynamic JSON writer
581
+ * cannot walk. The boxed route exists for a UNION of host objects and
582
+ * classes (hono's `BodyInit | null`, re-stringified from its body cache):
583
+ * what the value is at runtime is one of many arms, so serializing it is a
584
+ * dispatch over the box either way, and a class arm is admitted when the
585
+ * reflection census made the class boxable (`classBoxable`: its dynamic
586
+ * protocol is emitted, so the walk has fields to read).
587
+ *
588
+ * A carrier that IS a class -- bare, or `Class | undefined` -- is different:
589
+ * the layout is statically known and owned by this compiler, so its JSON is
590
+ * a native writer over that layout (not written yet), never a walk of its
591
+ * box, and the honest answer until then is the refusal the argument got
592
+ * before the boxed route existed (`test/runtime/class-json-reflection-
593
+ * refused.ts`). The walk is also WRONG for it today: with the protocol
594
+ * emitted it printed `{"first":0,"second":""}` for `first = 1; second =
595
+ * 'two'`, which is why the union case above is the whole of what this admits.
596
+ */
597
+ const boxHoldsOnlyBoxable = (ctx, representation, seen, whole) => {
598
+ const key = representationKey(representation);
599
+ if (seen.has(key))
600
+ return true;
601
+ seen.add(key);
602
+ switch (representation.kind) {
603
+ case 'class-ref':
604
+ return !whole && classBoxable(ctx.classes, representation.declaration);
605
+ case 'optional':
606
+ return boxHoldsOnlyBoxable(ctx, representation.payload, seen, whole);
607
+ case 'tagged-union':
608
+ return representation.arms.every((arm) => boxHoldsOnlyBoxable(ctx, arm.value, seen, false));
609
+ case 'array-object':
610
+ return boxHoldsOnlyBoxable(ctx, representation.element, seen, false);
611
+ case 'dictionary':
612
+ case 'promise':
613
+ return boxHoldsOnlyBoxable(ctx, representation.value, seen, false);
614
+ case 'record':
615
+ return representation.fields.every((field) => boxHoldsOnlyBoxable(ctx, field.value, seen, false));
616
+ default:
617
+ return true;
618
+ }
619
+ };
620
+ /**
621
+ * A value with no native serializer -- a union of host objects hono stringifies
622
+ * as `BodyInit` -- serialized from its box, which the dynamic writer walks as
623
+ * JSON.stringify walks any object.
624
+ */
625
+ const boxedJsonArgumentText = (ctx, argument) => {
626
+ if (!boxHoldsOnlyBoxable(ctx, argument.representation, new Set(), true))
627
+ return null;
628
+ const boxed = dynamicCarrierBoxText(argument.representation, operandText(ctx, argument));
629
+ if (boxed === null)
630
+ return null;
631
+ const dynamic = { kind: 'dynamic', reason: 'declared-any-never-narrowed' };
632
+ return jsonUnsupportedReason(ctx.deriver, dynamic, emptyJsonCollected(), new Set(), 'write') === null ? boxed : null;
633
+ };
634
+ export const jsonCallText = (ctx, member, operation) => {
635
+ if (member === 'stringify') {
636
+ if (operation.arguments.length < 1 || operation.arguments.length > 3) {
637
+ throw createCppEmitBlockedError('host-member-call:JSON.stringify', `JSON.stringify takes one to three arguments; this call passes ${operation.arguments.length}`);
638
+ }
639
+ const argument = operation.arguments[0];
640
+ const reason = jsonUnsupportedReason(ctx.deriver, argument.representation, emptyJsonCollected(), new Set(), 'write');
641
+ if (reason !== null) {
642
+ const boxed = operation.arguments.length === 1 ? boxedJsonArgumentText(ctx, argument) : null;
643
+ if (boxed !== null)
644
+ return `[&]() { std::string gea_json_out; gea_json_write(gea_json_out, ${boxed}); return gea_json_out; }()`;
645
+ throw createCppEmitBlockedError('host-member-call:JSON.stringify', `JSON.stringify cannot serialize this argument natively: ${reason}`);
646
+ }
647
+ const valueText = operandText(ctx, argument);
648
+ if (operation.arguments.length > 1) {
649
+ if (argument.representation.kind !== 'string' && argument.representation.kind !== 'dynamic') {
650
+ throw createCppEmitBlockedError('host-member-call:JSON.stringify', `JSON.stringify replacer support requires a string or genuinely dynamic input and this call carries "${representationKey(argument.representation)}"`);
651
+ }
652
+ const replacer = operation.arguments[1];
653
+ const leaves = [];
654
+ const collect = (representation, text, conditions) => {
655
+ if (representation.kind === 'optional') {
656
+ collect(representation.payload, `(*(${text}))`, [...conditions, `(${text}).has_value()`]);
657
+ return;
658
+ }
659
+ if (representation.kind === 'tagged-union') {
660
+ representation.arms.forEach((arm, index) => collect(arm.value, armAt(text, index), [...conditions, armIs(text, index)]));
661
+ return;
662
+ }
663
+ leaves.push({ condition: conditions.length === 0 ? 'true' : conditions.join(' && '), text, representation });
664
+ };
665
+ collect(replacer.representation, '__gea_replacer', []);
666
+ const callable = leaves.filter((leaf) => leaf.representation.kind === 'function-value-dispatch');
667
+ const invalid = leaves.filter((leaf) => leaf.representation.kind !== 'function-value-dispatch' &&
668
+ leaf.representation.kind !== 'array-object' &&
669
+ leaf.representation.kind !== 'null' &&
670
+ leaf.representation.kind !== 'undefined');
671
+ if (callable.length > 1 || invalid.length !== 0) {
672
+ throw createCppEmitBlockedError('host-member-call:JSON.stringify', `JSON.stringify replacer carries "${representationKey(replacer.representation)}"; expected null, undefined, a property-list array, or one callable arm`);
673
+ }
674
+ if (callable.length === 0) {
675
+ return `[&]() { std::string gea_json_out; gea_json_write(gea_json_out, ${valueText}); return gea_json_out; }()`;
676
+ }
677
+ const space = operation.arguments[2];
678
+ const gapText = (representation, text) => {
679
+ if (representation.kind === 'undefined' || representation.kind === 'null')
680
+ return 'std::string()';
681
+ if (representation.kind === 'string' || (representation.kind === 'scalar' && representation.domain === 'number')) {
682
+ return `gea::json::indentGap(${text})`;
683
+ }
684
+ if (representation.kind === 'optional') {
685
+ return `((${text}).has_value() ? ${gapText(representation.payload, `(*(${text}))`)} : std::string())`;
686
+ }
687
+ if (representation.kind === 'tagged-union') {
688
+ const arms = representation.arms.map((arm, index) => gapText(arm.value, armAt(text, index)));
689
+ return arms.reduceRight((rest, arm, index) => `${armIs(text, index)} ? ${arm} : (${rest})`);
690
+ }
691
+ throw createCppEmitBlockedError('host-member-call:JSON.stringify', `JSON.stringify space carries unsupported "${representationKey(representation)}"`);
692
+ };
693
+ const gap = space === undefined ? 'std::string()' : gapText(space.representation, '__gea_space');
694
+ const selected = callable[0];
695
+ const callableRepresentation = selected.representation;
696
+ const spaceBinding = space === undefined ? '' : `const auto& __gea_space = ${operandText(ctx, space)};`;
697
+ // A statically known string is the original specialized path. A
698
+ // genuinely dynamic value already IS the boxed boundary JSON's callback
699
+ // contract requires, so pass it through untouched. Extending this to a
700
+ // typed record would be the forbidden shortcut: that record must keep
701
+ // its native carrier, and needs a generated typed replacer traversal of
702
+ // its own before it can be admitted here.
703
+ const root = argument.representation.kind === 'string' ? 'gea::Value::box(gea::Value::Tag::String, std::string(__gea_value))' : '__gea_value';
704
+ const receiver = callableRepresentation.abi.receiver;
705
+ if (receiver !== null && receiver.kind !== 'dynamic') {
706
+ throw createCppEmitBlockedError('host-member-call:JSON.stringify', `JSON.stringify replacer receiver carries "${representationKey(receiver)}"; only the declared dynamic this-value is supported`);
707
+ }
708
+ const invoke = receiver === null ? '__gea_callable.call(__gea_key, __gea_member)' : '__gea_callable.call(__gea_holder, __gea_key, __gea_member)';
709
+ return (`([&]() { const auto& __gea_value = ${valueText}; const auto& __gea_replacer = ${operandText(ctx, replacer)}; ${spaceBinding} ` +
710
+ `const std::string __gea_gap = ${gap}; if (${selected.condition}) { const auto& __gea_callable = ${selected.text}; ` +
711
+ `return gea::json::stringifyWithReplacer(${root}, ` +
712
+ `[&](const gea::Value& __gea_holder, const std::string& __gea_key, const gea::Value& __gea_member) { ` +
713
+ `return ${invoke}; }, __gea_gap); } ` +
714
+ `std::string gea_json_out; gea_json_write(gea_json_out, __gea_value); return gea_json_out; })()`);
715
+ }
716
+ return `[&]() { std::string gea_json_out; gea_json_write(gea_json_out, ${valueText}); return gea_json_out; }()`;
717
+ }
718
+ if (operation.arguments.length !== 1) {
719
+ throw createCppEmitBlockedError('host-member-call:JSON.parse', `JSON.parse's "reviver" parameter is not implemented (this call passes ${operation.arguments.length} argument(s); only the single-argument form is)`);
720
+ }
721
+ if (operation.result === null) {
722
+ throw createCppEmitBlockedError('host-member-call:JSON.parse', 'this JSON.parse result is discarded; this backend only renders a parse whose value is used somewhere');
723
+ }
724
+ const resultRepresentation = operation.result.representation;
725
+ const reason = jsonUnsupportedReason(ctx.deriver, resultRepresentation, emptyJsonCollected(), new Set(), 'read');
726
+ if (reason !== null)
727
+ throw createCppEmitBlockedError('host-member-call:JSON.parse', `JSON.parse cannot decode natively into this asserted type: ${reason}`);
728
+ const textArgument = operandText(ctx, operation.arguments[0]);
729
+ const resultType = cppTypeOf(resultRepresentation);
730
+ return `[&]() { const std::string& gea_json_text = ${textArgument}; gea::json::Reader gea_json_reader(gea_json_text); ${resultType} gea_json_result{}; gea_json_read(gea_json_reader, gea_json_result); return gea_json_result; }()`;
731
+ };
732
+ /**
733
+ * `JSON.stringify(v)` written straight into the cell that receives it, as
734
+ * whole statements, instead of into a temporary the following write copies out
735
+ * of. `null` whenever any condition that would make the two observably
736
+ * different fails, in which case the ordinary expression form renders.
737
+ *
738
+ * The conditions are each a way the cell and the temporary are not the same
739
+ * storage:
740
+ * - the cell must HOLD a plain `std::string`. A union, an optional, a
741
+ * `Signal`, a shared box, an integer-narrowed cell: none of those is a
742
+ * buffer `gea_json_write` can append into, and a reactive cell additionally
743
+ * owes a notify the direct write would skip.
744
+ * - the cell must be this frame's own local or a file-scope cell it may name.
745
+ * - the write must not be one that renders nothing on its own
746
+ * (`formalCells`), which would leave the fill duplicating a value the
747
+ * formal already holds under another name.
748
+ * - the argument must not READ the cell, DIRECTLY OR THROUGH ANYTHING IT IS
749
+ * DERIVED FROM. `s = JSON.stringify(s)` reads the very buffer the `clear()`
750
+ * empties and would serialize `""`; so does `s = JSON.stringify({ s })`,
751
+ * whose argument is a record one of whose fields was loaded from that same
752
+ * buffer. Asked of the IR -- `ctx.valueCellReads`, the transitive closure of
753
+ * what each value's operands read -- rather than of the argument's rendered
754
+ * C++ text.
755
+ *
756
+ * Both halves of that matter, and they fail in opposite directions. A text
757
+ * scan misses a read of the same declaration reached through a
758
+ * differently-spelled reference (a reactive accessor, an environment
759
+ * indirection), because the cell's own name is not in the rendered text.
760
+ * Asking `bindingReadDeclarations` -- whether the argument IS that read --
761
+ * fixes that but narrows the question to one value, and a derived argument
762
+ * walks straight past it. The closure is the only form of the question that
763
+ * holds in both directions.
764
+ *
765
+ * One difference is real and deliberate: if the serializer throws part-way --
766
+ * which it can only do by failing to allocate -- the cell holds a partial
767
+ * document where the temporary form would have left the previous value. The
768
+ * hand-written baselines this is measured against (`text.clear(); ser(text,
769
+ * tree);`) have the same property, and a program that catches `bad_alloc` and
770
+ * then reads the half-written buffer is not a shape this compiler serves.
771
+ */
772
+ export const jsonStringifyFillLines = (ctx, operation) => {
773
+ if (operation.result === null || operation.arguments.length !== 1)
774
+ return null;
775
+ const read = ctx.hostMemberReads.get(operation.callee.value);
776
+ if (!read || read.protocol !== 'JSON' || read.member !== 'stringify')
777
+ return null;
778
+ const declaration = ctx.directBindingSinks.get(operation.result.id);
779
+ if (declaration === undefined)
780
+ return null;
781
+ if (ctx.formalCells.has(declaration) || ctx.integerBindings.has(declaration) || ctx.captures.isBoxed(declaration))
782
+ return null;
783
+ const placement = ctx.placements.get(declaration);
784
+ if (!placement || placement.representation?.kind !== 'string')
785
+ return null;
786
+ // A cell, and one this frame may assign. `local` owned elsewhere is another
787
+ // frame's storage reached through a capture; every other storage kind --
788
+ // a host singleton, a class object, an `extern` -- is not a buffer at all.
789
+ if (placement.storage.kind === 'local' && placement.storage.owner !== ctx.owner)
790
+ return null;
791
+ if (placement.storage.kind !== 'local' && placement.storage.kind !== 'region')
792
+ return null;
793
+ const argument = operation.arguments[0];
794
+ const reason = jsonUnsupportedReason(ctx.deriver, argument.representation, emptyJsonCollected(), new Set(), 'write');
795
+ if (reason !== null) {
796
+ // The expression form serializes the boxed value instead (`jsonCallText`).
797
+ if (boxedJsonArgumentText(ctx, argument) !== null)
798
+ return null;
799
+ throw createCppEmitBlockedError('host-member-call:JSON.stringify', `JSON.stringify cannot serialize this argument natively: ${reason}`);
800
+ }
801
+ const cell = bindingReference(ctx, declaration, 'a JSON.stringify written in place');
802
+ if (cell.boxed)
803
+ return null;
804
+ const target = cellValueText(cell);
805
+ if (readsCell(ctx, argument.value, declaration))
806
+ return null;
807
+ const valueText = operandText(ctx, argument);
808
+ const lines = [];
809
+ // The cell's own declaration, if this write is the one that would have made
810
+ // it: hoisted to the top of the frame exactly as `emit-bindings.ts` hoists
811
+ // it, so the fill has somewhere to append into and the write it replaces
812
+ // does not declare a second one.
813
+ if (cell.owned && !ctx.declaredBindings.has(declaration)) {
814
+ declareCell(ctx, cell.name, cppTypeOf(placement.representation));
815
+ ctx.declaredBindings.add(declaration);
816
+ }
817
+ lines.push(`${target}.clear();`);
818
+ lines.push(`gea_json_write(${target}, ${valueText});`);
819
+ // The result IS the cell now, so the write that follows recognizes its own
820
+ // storage on both sides and renders nothing (`emit-bindings.ts`).
821
+ defineValueAlias(ctx, operation.result, target);
822
+ return lines;
823
+ };