@geastack/compiler 1.0.27 → 1.0.29

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 (946) hide show
  1. package/dist/cli-coverage.js +2 -2
  2. package/dist/cli-emit.js +36 -12
  3. package/dist/compiler.d.ts +11 -9
  4. package/dist/compiler.js +264 -43
  5. package/dist/conversion/algebra.d.ts +84 -4
  6. package/dist/conversion/algebra.js +39 -0
  7. package/dist/conversion/array-view.d.ts +63 -0
  8. package/dist/conversion/array-view.js +186 -0
  9. package/dist/conversion/build.d.ts +8 -8
  10. package/dist/conversion/build.js +56 -50
  11. package/dist/conversion/certified-iterator-object-view.d.ts +13 -0
  12. package/dist/conversion/certified-iterator-object-view.js +31 -0
  13. package/dist/conversion/certified-iterator-protocols.d.ts +23 -0
  14. package/dist/conversion/certified-iterator-protocols.js +50 -0
  15. package/dist/conversion/checked-native-field-read.d.ts +7 -0
  16. package/dist/conversion/checked-native-field-read.js +36 -0
  17. package/dist/conversion/constructor-identity-family.d.ts +6 -6
  18. package/dist/conversion/constructor-identity-family.js +3 -3
  19. package/dist/conversion/derive.js +11 -8
  20. package/dist/conversion/dictionary-view.d.ts +114 -0
  21. package/dist/conversion/dictionary-view.js +275 -0
  22. package/dist/conversion/document-record-view.d.ts +89 -0
  23. package/dist/conversion/document-record-view.js +269 -0
  24. package/dist/conversion/dynamic-result-carriers.d.ts +6 -0
  25. package/dist/conversion/dynamic-result-carriers.js +43 -0
  26. package/dist/conversion/dynamic-wrapper.d.ts +52 -0
  27. package/dist/conversion/dynamic-wrapper.js +82 -0
  28. package/dist/conversion/impossible-field-read.d.ts +9 -0
  29. package/dist/conversion/impossible-field-read.js +28 -0
  30. package/dist/conversion/iterable-object-view.d.ts +1 -1
  31. package/dist/conversion/iterator-object-view.d.ts +2 -2
  32. package/dist/conversion/native-absence.d.ts +4 -0
  33. package/dist/conversion/native-absence.js +4 -0
  34. package/dist/conversion/native-buffer-method.d.ts +16 -0
  35. package/dist/conversion/native-buffer-method.js +37 -0
  36. package/dist/conversion/native-callable-adapter.d.ts +13 -0
  37. package/dist/conversion/native-callable-adapter.js +73 -0
  38. package/dist/conversion/native-descriptor-snapshot.d.ts +30 -0
  39. package/dist/conversion/native-descriptor-snapshot.js +75 -0
  40. package/dist/conversion/native-entry-writer.d.ts +21 -0
  41. package/dist/conversion/native-entry-writer.js +32 -0
  42. package/dist/conversion/native-field-view.d.ts +42 -0
  43. package/dist/conversion/native-field-view.js +145 -0
  44. package/dist/conversion/native-logical-receiver.d.ts +11 -0
  45. package/dist/conversion/native-logical-receiver.js +19 -0
  46. package/dist/conversion/native-method.d.ts +43 -0
  47. package/dist/conversion/native-method.js +56 -0
  48. package/dist/conversion/native-object-sample.d.ts +30 -0
  49. package/dist/conversion/native-object-sample.js +37 -0
  50. package/dist/conversion/native-payload-transport.d.ts +1 -1
  51. package/dist/conversion/native-payload-transport.js +1 -1
  52. package/dist/conversion/native-record-products.d.ts +15 -0
  53. package/dist/conversion/native-record-products.js +73 -0
  54. package/dist/conversion/native-selection.d.ts +18 -1
  55. package/dist/conversion/native-selection.js +117 -4
  56. package/dist/conversion/native-sum.d.ts +27 -0
  57. package/dist/conversion/native-sum.js +74 -9
  58. package/dist/conversion/native-view-origins.d.ts +12 -0
  59. package/dist/conversion/native-view-origins.js +97 -0
  60. package/dist/conversion/nodes.d.ts +75 -7
  61. package/dist/conversion/nodes.js +694 -19
  62. package/dist/conversion/number-storage.d.ts +8 -0
  63. package/dist/conversion/number-storage.js +8 -0
  64. package/dist/conversion/operand-view.js +10 -1
  65. package/dist/conversion/promise-adoption.d.ts +15 -0
  66. package/dist/conversion/promise-adoption.js +29 -0
  67. package/dist/conversion/protocol-iterator.d.ts +3 -3
  68. package/dist/conversion/recipe-closure.d.ts +14 -0
  69. package/dist/conversion/recipe-closure.js +135 -0
  70. package/dist/conversion/record-view.d.ts +51 -26
  71. package/dist/conversion/record-view.js +160 -97
  72. package/dist/conversion/registry.d.ts +18 -2
  73. package/dist/conversion/sibling-class.d.ts +4 -0
  74. package/dist/conversion/sibling-class.js +7 -0
  75. package/dist/conversion/structural-plan.d.ts +87 -0
  76. package/dist/conversion/structural-plan.js +480 -0
  77. package/dist/ir/absent-class-arm.d.ts +1 -1
  78. package/dist/ir/absent-class-arm.js +1 -1
  79. package/dist/ir/async-result-conventions.d.ts +15 -0
  80. package/dist/ir/async-result-conventions.js +140 -0
  81. package/dist/ir/borrowed-call-arguments.d.ts +3 -3
  82. package/dist/ir/borrowed-call-arguments.js +9 -9
  83. package/dist/ir/build.d.ts +20 -29
  84. package/dist/ir/build.js +116 -19
  85. package/dist/ir/call-dispatch.js +153 -40
  86. package/dist/ir/call-entry.d.ts +14 -3
  87. package/dist/ir/call-entry.js +63 -5
  88. package/dist/ir/callable-class-flow.d.ts +48 -3
  89. package/dist/ir/callable-class-flow.js +1509 -81
  90. package/dist/ir/callable-flow-candidates.d.ts +25 -0
  91. package/dist/ir/callable-flow-candidates.js +135 -0
  92. package/dist/ir/callable-identity-demand.d.ts +2 -2
  93. package/dist/ir/callable-identity-demand.js +33 -1
  94. package/dist/ir/callable-member-candidates.d.ts +1 -1
  95. package/dist/ir/callable-member-candidates.js +2 -2
  96. package/dist/ir/callable-records.js +1 -0
  97. package/dist/ir/callable-site-escape.js +3 -4
  98. package/dist/ir/captures.js +1 -1
  99. package/dist/ir/certificate.d.ts +1 -0
  100. package/dist/ir/certificate.js +2 -1
  101. package/dist/ir/certify/carrier-keys.d.ts +2 -2
  102. package/dist/ir/certify/carrier-keys.js +4 -4
  103. package/dist/ir/certify/has-property-key.d.ts +3 -3
  104. package/dist/ir/certify/has-property-key.js +3 -3
  105. package/dist/ir/certify/parallel-region.d.ts +26 -0
  106. package/dist/ir/certify/parallel-region.js +1331 -0
  107. package/dist/ir/certify/property-access-keys.d.ts +11 -11
  108. package/dist/ir/certify/property-access-keys.js +11 -11
  109. package/dist/ir/certify/property-access.js +7 -9
  110. package/dist/ir/certify.d.ts +66 -3
  111. package/dist/ir/certify.js +1197 -36
  112. package/dist/ir/class-allocation-domain.d.ts +9 -0
  113. package/dist/ir/class-allocation-domain.js +111 -0
  114. package/dist/ir/class-evaluation.d.ts +2 -3
  115. package/dist/ir/class-evaluation.js +2 -3
  116. package/dist/ir/class-static-fields.d.ts +12 -1
  117. package/dist/ir/class-static-fields.js +25 -0
  118. package/dist/ir/closed-normal-results.d.ts +18 -0
  119. package/dist/ir/closed-normal-results.js +208 -0
  120. package/dist/ir/construct-entry.js +1 -0
  121. package/dist/ir/construction-only-fields.d.ts +20 -1
  122. package/dist/ir/construction-only-fields.js +95 -9
  123. package/dist/ir/convert-carriers.d.ts +7 -0
  124. package/dist/ir/convert-carriers.js +12 -0
  125. package/dist/ir/coroutine-bodies.d.ts +74 -0
  126. package/dist/ir/coroutine-bodies.js +93 -0
  127. package/dist/ir/dead-logical-merge.d.ts +7 -0
  128. package/dist/ir/dead-logical-merge.js +84 -0
  129. package/dist/ir/dead-values.d.ts +7 -5
  130. package/dist/ir/dead-values.js +34 -5
  131. package/dist/ir/deferral.d.ts +3 -1
  132. package/dist/ir/deferral.js +19 -6
  133. package/dist/ir/dense-loops.d.ts +96 -7
  134. package/dist/ir/dense-loops.js +333 -17
  135. package/dist/ir/descriptor-own-protocol.d.ts +12 -0
  136. package/dist/ir/descriptor-own-protocol.js +35 -0
  137. package/dist/ir/dynamic-constructor-conversions.d.ts +17 -0
  138. package/dist/ir/dynamic-constructor-conversions.js +52 -0
  139. package/dist/ir/emission-representations.js +44 -2
  140. package/dist/ir/facts.d.ts +14 -2
  141. package/dist/ir/facts.js +23 -9
  142. package/dist/ir/fixed-data-definition-attributes.d.ts +10 -0
  143. package/dist/ir/fixed-data-definition-attributes.js +200 -0
  144. package/dist/ir/fixed-data-definition.d.ts +23 -5
  145. package/dist/ir/fixed-data-definition.js +80 -2
  146. package/dist/ir/function-reflection-demand.d.ts +11 -0
  147. package/dist/ir/function-reflection-demand.js +71 -0
  148. package/dist/ir/generic-call-entry.d.ts +18 -0
  149. package/dist/ir/generic-call-entry.js +94 -0
  150. package/dist/ir/hoist.d.ts +16 -3
  151. package/dist/ir/hoist.js +121 -8
  152. package/dist/ir/host-method-aliases.d.ts +15 -0
  153. package/dist/ir/host-method-aliases.js +61 -0
  154. package/dist/ir/host-namespace-reads.d.ts +24 -0
  155. package/dist/ir/host-namespace-reads.js +151 -0
  156. package/dist/ir/host-promise-conversions.d.ts +5 -0
  157. package/dist/ir/host-promise-conversions.js +61 -0
  158. package/dist/ir/host-template-conversions.d.ts +34 -0
  159. package/dist/ir/host-template-conversions.js +357 -0
  160. package/dist/ir/instance-reparenting.d.ts +3 -4
  161. package/dist/ir/instantiation.d.ts +1 -1
  162. package/dist/ir/instantiation.js +1 -1
  163. package/dist/ir/integer-storage.d.ts +19 -9
  164. package/dist/ir/integer-storage.js +158 -44
  165. package/dist/ir/integers.d.ts +34 -7
  166. package/dist/ir/integers.js +240 -7
  167. package/dist/ir/integrity-restrictions.d.ts +4 -4
  168. package/dist/ir/integrity-restrictions.js +7 -4
  169. package/dist/ir/internal-operation-conversions.d.ts +7 -0
  170. package/dist/ir/internal-operation-conversions.js +195 -0
  171. package/dist/ir/intrinsic-call-facts.d.ts +40 -0
  172. package/dist/ir/intrinsic-call-facts.js +176 -0
  173. package/dist/ir/key-order-observation.d.ts +1 -1
  174. package/dist/ir/lazy-splits.d.ts +20 -0
  175. package/dist/ir/lazy-splits.js +58 -0
  176. package/dist/ir/literal-set-membership.d.ts +2 -2
  177. package/dist/ir/literal-set-membership.js +2 -2
  178. package/dist/ir/logical-receivers.d.ts +15 -0
  179. package/dist/ir/logical-receivers.js +98 -0
  180. package/dist/ir/lower-allocation.js +16 -13
  181. package/dist/ir/lower-destructuring.js +7 -6
  182. package/dist/ir/lower-graph.d.ts +4 -4
  183. package/dist/ir/lower-graph.js +2 -2
  184. package/dist/ir/lower-invocation.d.ts +2 -2
  185. package/dist/ir/lower-invocation.js +99 -57
  186. package/dist/ir/lower-narrow.js +35 -13
  187. package/dist/ir/lower-operands.d.ts +40 -11
  188. package/dist/ir/lower-operands.js +206 -87
  189. package/dist/ir/lower-property.js +31 -8
  190. package/dist/ir/lower.js +9 -9
  191. package/dist/ir/merge-conversions.d.ts +18 -0
  192. package/dist/ir/merge-conversions.js +106 -0
  193. package/dist/ir/model.d.ts +138 -28
  194. package/dist/ir/native-accessor-definition.d.ts +104 -0
  195. package/dist/ir/native-accessor-definition.js +735 -0
  196. package/dist/ir/native-array-descriptor-snapshot.d.ts +45 -0
  197. package/dist/ir/native-array-descriptor-snapshot.js +380 -0
  198. package/dist/ir/native-array-insertion.d.ts +16 -0
  199. package/dist/ir/native-array-insertion.js +42 -0
  200. package/dist/ir/native-callable-argument.d.ts +38 -0
  201. package/dist/ir/native-callable-argument.js +128 -0
  202. package/dist/ir/native-callable-data-flow.d.ts +9 -0
  203. package/dist/ir/native-callable-data-flow.js +59 -0
  204. package/dist/ir/native-callable-data-owner.d.ts +45 -0
  205. package/dist/ir/native-callable-data-owner.js +755 -0
  206. package/dist/ir/native-callable-data-reads.d.ts +45 -0
  207. package/dist/ir/native-callable-data-reads.js +282 -0
  208. package/dist/ir/native-callable-data-slots.d.ts +78 -0
  209. package/dist/ir/native-callable-data-slots.js +403 -0
  210. package/dist/ir/native-callable-data-write.d.ts +58 -0
  211. package/dist/ir/native-callable-data-write.js +254 -0
  212. package/dist/ir/native-callable-integrity.d.ts +23 -0
  213. package/dist/ir/native-callable-integrity.js +77 -0
  214. package/dist/ir/native-callable-own-property.d.ts +42 -0
  215. package/dist/ir/native-callable-own-property.js +505 -0
  216. package/dist/ir/native-callable-prototype.d.ts +38 -0
  217. package/dist/ir/native-callable-prototype.js +307 -0
  218. package/dist/ir/native-callable-readonly-set.d.ts +25 -0
  219. package/dist/ir/native-callable-readonly-set.js +238 -0
  220. package/dist/ir/native-class-accessor.d.ts +3 -3
  221. package/dist/ir/native-class-accessor.js +3 -3
  222. package/dist/ir/native-class-construction.js +2 -2
  223. package/dist/ir/native-constructor-reads.d.ts +15 -0
  224. package/dist/ir/native-constructor-reads.js +156 -0
  225. package/dist/ir/native-constructor-static.d.ts +18 -0
  226. package/dist/ir/native-constructor-static.js +61 -0
  227. package/dist/ir/native-data-definition.d.ts +43 -0
  228. package/dist/ir/native-data-definition.js +222 -0
  229. package/dist/ir/native-document-array-entries.d.ts +15 -0
  230. package/dist/ir/native-document-array-entries.js +37 -0
  231. package/dist/ir/native-document-entries.d.ts +21 -0
  232. package/dist/ir/native-document-entries.js +74 -0
  233. package/dist/ir/native-entry-field-views.d.ts +18 -0
  234. package/dist/ir/native-entry-field-views.js +62 -0
  235. package/dist/ir/native-field-view-domains.d.ts +43 -0
  236. package/dist/ir/native-field-view-domains.js +300 -0
  237. package/dist/ir/native-field-view-facts.d.ts +97 -0
  238. package/dist/ir/native-field-view-facts.js +341 -0
  239. package/dist/ir/native-fixed-layout.js +1 -1
  240. package/dist/ir/native-host-construction.d.ts +4 -6
  241. package/dist/ir/native-host-construction.js +4 -6
  242. package/dist/ir/native-host-method-reads.d.ts +13 -0
  243. package/dist/ir/native-host-method-reads.js +53 -0
  244. package/dist/ir/native-iterator-field-views.d.ts +15 -0
  245. package/dist/ir/native-iterator-field-views.js +39 -0
  246. package/dist/ir/native-iterator-receivers.d.ts +8 -0
  247. package/dist/ir/native-iterator-receivers.js +59 -0
  248. package/dist/ir/native-logical-receiver-body.d.ts +8 -0
  249. package/dist/ir/native-logical-receiver-body.js +23 -0
  250. package/dist/ir/native-method-frames.d.ts +18 -0
  251. package/dist/ir/native-method-frames.js +127 -0
  252. package/dist/ir/native-method-read-source.d.ts +16 -0
  253. package/dist/ir/native-method-read-source.js +61 -0
  254. package/dist/ir/native-object-data-slots.d.ts +60 -0
  255. package/dist/ir/native-object-data-slots.js +493 -0
  256. package/dist/ir/native-object-sample.d.ts +32 -0
  257. package/dist/ir/native-object-sample.js +113 -0
  258. package/dist/ir/native-own-assignment.d.ts +123 -0
  259. package/dist/ir/native-own-assignment.js +529 -0
  260. package/dist/ir/native-property-coercibility.d.ts +3 -0
  261. package/dist/ir/native-property-coercibility.js +10 -0
  262. package/dist/ir/native-property-key-texts.d.ts +11 -0
  263. package/dist/ir/native-property-key-texts.js +41 -0
  264. package/dist/ir/native-property-presence-effects.d.ts +11 -0
  265. package/dist/ir/native-property-presence-effects.js +19 -0
  266. package/dist/ir/native-property-presence.d.ts +27 -0
  267. package/dist/ir/native-property-presence.js +275 -0
  268. package/dist/ir/native-prototype-calls.d.ts +19 -0
  269. package/dist/ir/native-prototype-calls.js +53 -0
  270. package/dist/ir/native-prototype-conversions.d.ts +5 -0
  271. package/dist/ir/native-prototype-conversions.js +46 -0
  272. package/dist/ir/native-prototype-presence-demand.d.ts +9 -0
  273. package/dist/ir/native-prototype-presence-demand.js +58 -0
  274. package/dist/ir/native-record-index.d.ts +1 -1
  275. package/dist/ir/native-union-method-targets.d.ts +8 -0
  276. package/dist/ir/native-union-method-targets.js +69 -0
  277. package/dist/ir/no-normal-call-completion.d.ts +15 -0
  278. package/dist/ir/no-normal-call-completion.js +184 -0
  279. package/dist/ir/non-normal-receiver.d.ts +39 -0
  280. package/dist/ir/non-normal-receiver.js +253 -0
  281. package/dist/ir/operation-conversions.d.ts +29 -0
  282. package/dist/ir/operation-conversions.js +484 -0
  283. package/dist/ir/operation-index.d.ts +1 -1
  284. package/dist/ir/presence-proof.d.ts +1 -1
  285. package/dist/ir/presence-proof.js +1 -0
  286. package/dist/ir/program-conversions.d.ts +48 -0
  287. package/dist/ir/program-conversions.js +221 -0
  288. package/dist/ir/program-facts.d.ts +4 -1
  289. package/dist/ir/program-facts.js +9 -7
  290. package/dist/ir/promise-reaction-conversions.d.ts +6 -0
  291. package/dist/ir/promise-reaction-conversions.js +92 -0
  292. package/dist/ir/property-read-conversions.d.ts +10 -0
  293. package/dist/ir/property-read-conversions.js +124 -0
  294. package/dist/ir/proven-branches.d.ts +2 -1
  295. package/dist/ir/proven-branches.js +97 -10
  296. package/dist/ir/publish-conversion-recipes.d.ts +27 -0
  297. package/dist/ir/publish-conversion-recipes.js +246 -0
  298. package/dist/ir/publish-native-field-view-facts.d.ts +17 -0
  299. package/dist/ir/publish-native-field-view-facts.js +119 -0
  300. package/dist/ir/queries.js +42 -4
  301. package/dist/ir/read-only-dictionary.d.ts +38 -0
  302. package/dist/ir/read-only-dictionary.js +281 -0
  303. package/dist/ir/reflection-demand.d.ts +2 -0
  304. package/dist/ir/reflection-demand.js +600 -44
  305. package/dist/ir/shake.d.ts +3 -0
  306. package/dist/ir/shake.js +24 -14
  307. package/dist/ir/shared-empty-records.js +1 -1
  308. package/dist/ir/short-circuit-threading.d.ts +23 -0
  309. package/dist/ir/short-circuit-threading.js +133 -0
  310. package/dist/ir/spread-conversions.d.ts +27 -0
  311. package/dist/ir/spread-conversions.js +134 -0
  312. package/dist/ir/spread-copy-elision.d.ts +2 -2
  313. package/dist/ir/spread-copy-elision.js +7 -4
  314. package/dist/ir/string-layout-reuse.d.ts +9 -8
  315. package/dist/ir/string-layout-reuse.js +8 -16
  316. package/dist/ir/string-length-reuse.d.ts +20 -4
  317. package/dist/ir/string-length-reuse.js +57 -13
  318. package/dist/ir/transfer.d.ts +5 -5
  319. package/dist/ir/transfer.js +53 -31
  320. package/dist/ir/typed-property-access.d.ts +2 -0
  321. package/dist/ir/typed-property-access.js +21 -8
  322. package/dist/ir/virtual-call-frames.d.ts +7 -0
  323. package/dist/ir/virtual-call-frames.js +8 -0
  324. package/dist/native-signatures.d.ts +45 -0
  325. package/dist/native-signatures.js +368 -0
  326. package/dist/plugins/gea/host.d.ts +6 -1
  327. package/dist/plugins/gea/host.js +30 -1
  328. package/dist/plugins/gea/lower.js +9 -3
  329. package/dist/plugins/gea/members.js +1 -1
  330. package/dist/plugins/gea/plugin.js +2 -1
  331. package/dist/plugins/gea/prelude.d.ts +1 -1
  332. package/dist/plugins/gea/prelude.js +1 -1
  333. package/dist/plugins/gea/reactive-slots.js +6 -6
  334. package/dist/plugins/gea/render-bridge.js +5 -6
  335. package/dist/plugins/gea/user-agent-styles.js +1 -1
  336. package/dist/plugins/installed.d.ts +2 -2
  337. package/dist/plugins/installed.js +2 -2
  338. package/dist/plugins/load.js +1 -1
  339. package/dist/plugins/model.d.ts +21 -36
  340. package/dist/plugins/webgl/host.d.ts +23 -23
  341. package/dist/plugins/webgl/host.js +25 -26
  342. package/dist/plugins/webgl/plugin.d.ts +16 -19
  343. package/dist/plugins/webgl/plugin.js +16 -23
  344. package/dist/project-preparation.js +12 -14
  345. package/dist/projection/abi.js +13 -10
  346. package/dist/projection/bindings.d.ts +8 -0
  347. package/dist/projection/bindings.js +36 -5
  348. package/dist/projection/callee.d.ts +17 -15
  349. package/dist/projection/callee.js +108 -81
  350. package/dist/projection/class-property-presence.d.ts +1 -1
  351. package/dist/projection/class-property-presence.js +1 -1
  352. package/dist/projection/classes.d.ts +2 -0
  353. package/dist/projection/classes.js +4 -1
  354. package/dist/projection/dispatch.d.ts +19 -3
  355. package/dist/projection/dispatch.js +39 -16
  356. package/dist/projection/fields.d.ts +14 -2
  357. package/dist/projection/fields.js +100 -38
  358. package/dist/projection/function-source.d.ts +5 -0
  359. package/dist/projection/function-source.js +15 -0
  360. package/dist/projection/immediate-callees.d.ts +12 -0
  361. package/dist/projection/immediate-callees.js +36 -0
  362. package/dist/projection/index-protocols.d.ts +12 -0
  363. package/dist/projection/index-protocols.js +39 -0
  364. package/dist/projection/instance-test.d.ts +8 -0
  365. package/dist/projection/instance-test.js +3 -1
  366. package/dist/projection/method-values.d.ts +7 -0
  367. package/dist/projection/method-values.js +29 -0
  368. package/dist/projection/native-accessor-access.d.ts +26 -0
  369. package/dist/projection/native-accessor-access.js +18 -0
  370. package/dist/projection/native-callable-data.d.ts +24 -0
  371. package/dist/projection/native-callable-data.js +101 -0
  372. package/dist/projection/native-expando.d.ts +3 -0
  373. package/dist/projection/native-expando.js +13 -0
  374. package/dist/projection/native-object-data.d.ts +47 -0
  375. package/dist/projection/native-object-data.js +203 -0
  376. package/dist/projection/native-prototype-methods.d.ts +22 -0
  377. package/dist/projection/native-prototype-methods.js +161 -0
  378. package/dist/projection/regexp-fields.d.ts +35 -0
  379. package/dist/projection/regexp-fields.js +80 -0
  380. package/dist/projection/slots.d.ts +5 -1
  381. package/dist/projection/slots.js +89 -10
  382. package/dist/representation/derive.d.ts +5 -7
  383. package/dist/representation/derive.js +78 -78
  384. package/dist/representation/difference.js +1 -1
  385. package/dist/representation/host-abi.d.ts +2 -2
  386. package/dist/representation/host-abi.js +4 -5
  387. package/dist/representation/host-templates.d.ts +6 -2
  388. package/dist/representation/host-templates.js +8 -2
  389. package/dist/representation/intersection.d.ts +3 -3
  390. package/dist/representation/intersection.js +3 -3
  391. package/dist/representation/merge.js +1 -1
  392. package/dist/representation/model.d.ts +27 -22
  393. package/dist/representation/model.js +35 -22
  394. package/dist/representation/native-callable-data-storage.d.ts +85 -0
  395. package/dist/representation/native-callable-data-storage.js +398 -0
  396. package/dist/representation/native-data-properties.d.ts +14 -0
  397. package/dist/representation/native-data-properties.js +52 -0
  398. package/dist/representation/native-logical-receiver.d.ts +36 -0
  399. package/dist/representation/native-logical-receiver.js +92 -0
  400. package/dist/representation/object-shape.d.ts +1 -1
  401. package/dist/representation/object-shape.js +1 -1
  402. package/dist/representation/optional.js +2 -2
  403. package/dist/representation/physical-carrier.d.ts +25 -0
  404. package/dist/representation/physical-carrier.js +153 -0
  405. package/dist/representation/policies.d.ts +16 -10
  406. package/dist/representation/policies.js +5 -1
  407. package/dist/representation/primitives.js +3 -0
  408. package/dist/representation/promise-resolution.d.ts +19 -0
  409. package/dist/representation/promise-resolution.js +50 -0
  410. package/dist/representation/prototype-domains.d.ts +43 -0
  411. package/dist/representation/prototype-domains.js +226 -0
  412. package/dist/representation/proxy-carriers.d.ts +3 -3
  413. package/dist/representation/proxy-carriers.js +2 -3
  414. package/dist/representation/publish.d.ts +4 -0
  415. package/dist/representation/publish.js +73 -42
  416. package/dist/representation/record-fields.d.ts +2 -2
  417. package/dist/representation/record-fields.js +2 -2
  418. package/dist/representation/static-field-cells.d.ts +1 -1
  419. package/dist/representation/structural-method-abi.d.ts +6 -0
  420. package/dist/representation/structural-method-abi.js +13 -0
  421. package/dist/representation/unassigned-binding-cells.d.ts +3 -3
  422. package/dist/representation/union.js +19 -4
  423. package/dist/representation/unwritten-record-members.d.ts +6 -6
  424. package/dist/representation/unwritten-record-members.js +1 -1
  425. package/dist/representation/value-records.js +77 -5
  426. package/dist/representation/verify.js +1 -1
  427. package/dist/representation/well-known-symbols.d.ts +3 -0
  428. package/dist/representation/well-known-symbols.js +11 -0
  429. package/dist/semantics/alias-this-field-declaration-transform.js +3 -3
  430. package/dist/semantics/ambient-type-realization-transform.d.ts +19 -20
  431. package/dist/semantics/ambient-type-realization-transform.js +20 -12
  432. package/dist/semantics/ambient.d.ts +13 -13
  433. package/dist/semantics/ambient.js +12 -12
  434. package/dist/semantics/borrowed-builtin-call-bind-source-transform.d.ts +5 -0
  435. package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +110 -52
  436. package/dist/semantics/borrowed-method-receiver-copy-source-transform.d.ts +4 -4
  437. package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +4 -4
  438. package/dist/semantics/call-invalidated-narrowing.js +2 -2
  439. package/dist/semantics/callable-origins.d.ts +49 -1
  440. package/dist/semantics/callable-origins.js +148 -32
  441. package/dist/semantics/callable-own-data-slots.d.ts +122 -0
  442. package/dist/semantics/callable-own-data-slots.js +421 -0
  443. package/dist/semantics/class-alias.d.ts +4 -4
  444. package/dist/semantics/class-alias.js +4 -4
  445. package/dist/semantics/class-heritage.d.ts +8 -7
  446. package/dist/semantics/class-heritage.js +8 -7
  447. package/dist/semantics/commonjs-wrapper.js +5 -2
  448. package/dist/semantics/constructor-function-class-source-transform.js +2 -3
  449. package/dist/semantics/constructor-slot-subclasses.d.ts +1 -1
  450. package/dist/semantics/constructor-slot-subclasses.js +5 -5
  451. package/dist/semantics/declaration-overlay-transform.d.ts +9 -12
  452. package/dist/semantics/declaration-overlay-transform.js +135 -142
  453. package/dist/semantics/declared-integers.d.ts +24 -0
  454. package/dist/semantics/declared-integers.js +34 -0
  455. package/dist/semantics/define-property-source-transform.js +21 -8
  456. package/dist/semantics/dynamic-fallback.d.ts +1 -1
  457. package/dist/semantics/dynamic-fallback.js +1 -1
  458. package/dist/semantics/frontend.d.ts +12 -16
  459. package/dist/semantics/frontend.js +187 -75
  460. package/dist/semantics/host-methods.d.ts +3 -3
  461. package/dist/semantics/host-methods.js +1 -1
  462. package/dist/semantics/host-protocols.d.ts +3 -3
  463. package/dist/semantics/host-protocols.js +26 -26
  464. package/dist/semantics/interface-families.d.ts +2 -2
  465. package/dist/semantics/interface-families.js +46 -47
  466. package/dist/semantics/interface-implementors.d.ts +12 -15
  467. package/dist/semantics/interface-implementors.js +12 -15
  468. package/dist/semantics/jsdoc-namepath-transform.js +7 -7
  469. package/dist/semantics/model/operands.d.ts +18 -3
  470. package/dist/semantics/model/operands.js +41 -0
  471. package/dist/semantics/model/operations.d.ts +82 -1
  472. package/dist/semantics/model/selected-signature.d.ts +24 -3
  473. package/dist/semantics/model/structural-type-table.js +24 -6
  474. package/dist/semantics/model/structural-types.d.ts +10 -8
  475. package/dist/semantics/model/structural-types.js +7 -5
  476. package/dist/semantics/module-resolution.js +3 -2
  477. package/dist/semantics/native-callable-readonly-set.d.ts +17 -0
  478. package/dist/semantics/native-callable-readonly-set.js +1 -0
  479. package/dist/semantics/native-function-signatures.d.ts +14 -0
  480. package/dist/semantics/native-function-signatures.js +96 -0
  481. package/dist/semantics/native-object-data-slots.d.ts +72 -0
  482. package/dist/semantics/native-object-data-slots.js +679 -0
  483. package/dist/semantics/native-own-assignment.d.ts +62 -0
  484. package/dist/semantics/native-own-assignment.js +1 -0
  485. package/dist/semantics/normalize/absent-globals.d.ts +8 -8
  486. package/dist/semantics/normalize/absent-globals.js +5 -5
  487. package/dist/semantics/normalize/arguments-objects.d.ts +3 -1
  488. package/dist/semantics/normalize/arguments-objects.js +1 -1
  489. package/dist/semantics/normalize/asserted-argument-arms.d.ts +7 -7
  490. package/dist/semantics/normalize/asserted-arm-absence.d.ts +1 -2
  491. package/dist/semantics/normalize/asserted-arm-absence.js +1 -2
  492. package/dist/semantics/normalize/binding-fixpoint.js +3 -3
  493. package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +2 -2
  494. package/dist/semantics/normalize/bivariant-slot-parameter.js +6 -6
  495. package/dist/semantics/normalize/callable-data-write.d.ts +46 -0
  496. package/dist/semantics/normalize/callable-data-write.js +182 -0
  497. package/dist/semantics/normalize/census.js +5 -5
  498. package/dist/semantics/normalize/class-instance-record-statement.d.ts +1 -1
  499. package/dist/semantics/normalize/class-instance-record-statement.js +1 -1
  500. package/dist/semantics/normalize/collection-bindings.d.ts +11 -13
  501. package/dist/semantics/normalize/collection-bindings.js +60 -33
  502. package/dist/semantics/normalize/commonjs-module-record.d.ts +7 -4
  503. package/dist/semantics/normalize/commonjs-module-record.js +93 -4
  504. package/dist/semantics/normalize/contribution.js +4 -4
  505. package/dist/semantics/normalize/dead-method-copies.d.ts +5 -5
  506. package/dist/semantics/normalize/dead-typeof-guards.d.ts +2 -2
  507. package/dist/semantics/normalize/dead-typeof-guards.js +6 -6
  508. package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +22 -13
  509. package/dist/semantics/normalize/deferred-intrinsic-protocols.js +85 -13
  510. package/dist/semantics/normalize/derived-expression-type.d.ts +129 -91
  511. package/dist/semantics/normalize/derived-expression-type.js +419 -192
  512. package/dist/semantics/normalize/field-bindings.d.ts +4 -4
  513. package/dist/semantics/normalize/field-bindings.js +334 -67
  514. package/dist/semantics/normalize/flow/array-element-continuation.d.ts +2 -2
  515. package/dist/semantics/normalize/flow/array-element-continuation.js +35 -18
  516. package/dist/semantics/normalize/flow/callable-array-origins.d.ts +1 -1
  517. package/dist/semantics/normalize/flow/callable-array-origins.js +3 -3
  518. package/dist/semantics/normalize/flow/callable-completions.d.ts +2 -2
  519. package/dist/semantics/normalize/flow/callable-completions.js +2 -2
  520. package/dist/semantics/normalize/flow/callable-reach.d.ts +19 -6
  521. package/dist/semantics/normalize/flow/callable-reach.js +722 -289
  522. package/dist/semantics/normalize/flow/class-family-member-read.js +24 -29
  523. package/dist/semantics/normalize/flow/collection-value-continuation.d.ts +2 -2
  524. package/dist/semantics/normalize/flow/collection-value-continuation.js +2 -2
  525. package/dist/semantics/normalize/flow/component-solver.d.ts +19 -16
  526. package/dist/semantics/normalize/flow/component-solver.js +138 -69
  527. package/dist/semantics/normalize/flow/computed-key-set.d.ts +6 -7
  528. package/dist/semantics/normalize/flow/computed-key-set.js +20 -1
  529. package/dist/semantics/normalize/flow/export-importers.js +4 -4
  530. package/dist/semantics/normalize/flow/host-text-sink.d.ts +3 -2
  531. package/dist/semantics/normalize/flow/host-text-sink.js +4 -3
  532. package/dist/semantics/normalize/flow/intrinsic-array-callback-frames.js +3 -2
  533. package/dist/semantics/normalize/flow/intrinsic-data-definition.d.ts +2 -2
  534. package/dist/semantics/normalize/flow/intrinsic-data-definition.js +3 -3
  535. package/dist/semantics/normalize/flow/invocation-facts.d.ts +3 -2
  536. package/dist/semantics/normalize/flow/invocation-facts.js +3 -3
  537. package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +12 -6
  538. package/dist/semantics/normalize/flow/member-call-forwarding.js +94 -21
  539. package/dist/semantics/normalize/flow/model.d.ts +5 -5
  540. package/dist/semantics/normalize/flow/model.js +11 -11
  541. package/dist/semantics/normalize/flow/node-path-token.js +3 -3
  542. package/dist/semantics/normalize/flow/origin-authority.d.ts +3 -3
  543. package/dist/semantics/normalize/flow/owned-class-receivers.js +8 -7
  544. package/dist/semantics/normalize/flow/parameter-values.js +6 -6
  545. package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +30 -4
  546. package/dist/semantics/normalize/flow/proof-hypotheses.js +56 -5
  547. package/dist/semantics/normalize/flow/proof-memo-settlement.d.ts +21 -0
  548. package/dist/semantics/normalize/flow/proof-memo-settlement.js +32 -0
  549. package/dist/semantics/normalize/flow/record-alias-closure.d.ts +1 -1
  550. package/dist/semantics/normalize/flow/record-alias-closure.js +1 -1
  551. package/dist/semantics/normalize/flow/seeded-origins.d.ts +4 -4
  552. package/dist/semantics/normalize/flow/seeded-origins.js +4 -4
  553. package/dist/semantics/normalize/flow/source-accessor-descriptor.d.ts +22 -0
  554. package/dist/semantics/normalize/flow/source-accessor-descriptor.js +210 -0
  555. package/dist/semantics/normalize/flow/source-callable-own-data.d.ts +33 -0
  556. package/dist/semantics/normalize/flow/source-callable-own-data.js +238 -0
  557. package/dist/semantics/normalize/flow/source-callable-readonly-set.d.ts +26 -0
  558. package/dist/semantics/normalize/flow/source-callable-readonly-set.js +337 -0
  559. package/dist/semantics/normalize/flow/source-class-data.d.ts +7 -7
  560. package/dist/semantics/normalize/flow/source-class-data.js +25 -26
  561. package/dist/semantics/normalize/flow/source-class-static-data.d.ts +2 -2
  562. package/dist/semantics/normalize/flow/source-class-static-data.js +2 -2
  563. package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +15 -0
  564. package/dist/semantics/normalize/flow/source-commonjs-exports.js +7 -0
  565. package/dist/semantics/normalize/flow/source-descriptor-protocol.d.ts +20 -0
  566. package/dist/semantics/normalize/flow/source-descriptor-protocol.js +75 -0
  567. package/dist/semantics/normalize/flow/source-executing-parameter-values.d.ts +8 -0
  568. package/dist/semantics/normalize/flow/source-executing-parameter-values.js +93 -0
  569. package/dist/semantics/normalize/flow/source-global-binding.d.ts +13 -0
  570. package/dist/semantics/normalize/flow/source-global-binding.js +42 -0
  571. package/dist/semantics/normalize/flow/source-intrinsic-member-data.d.ts +27 -0
  572. package/dist/semantics/normalize/flow/source-intrinsic-member-data.js +178 -0
  573. package/dist/semantics/normalize/flow/source-invocation-frame-layout.d.ts +1 -1
  574. package/dist/semantics/normalize/flow/source-invocation-frame-layout.js +31 -11
  575. package/dist/semantics/normalize/flow/source-invocation-receiver.d.ts +7 -3
  576. package/dist/semantics/normalize/flow/source-invocation-receiver.js +30 -2
  577. package/dist/semantics/normalize/flow/source-native-class-alias.d.ts +7 -0
  578. package/dist/semantics/normalize/flow/source-native-class-alias.js +91 -0
  579. package/dist/semantics/normalize/flow/source-normal-predecessor.d.ts +10 -0
  580. package/dist/semantics/normalize/flow/source-normal-predecessor.js +90 -0
  581. package/dist/semantics/normalize/flow/source-property-key.d.ts +3 -0
  582. package/dist/semantics/normalize/flow/source-property-key.js +7 -0
  583. package/dist/semantics/normalize/flow/source-read-protocol.d.ts +20 -0
  584. package/dist/semantics/normalize/flow/source-read-protocol.js +108 -0
  585. package/dist/semantics/normalize/flow/source-record-data.js +31 -30
  586. package/dist/semantics/normalize/flow/source-value-session.d.ts +106 -3
  587. package/dist/semantics/normalize/flow/source-value-session.js +1172 -218
  588. package/dist/semantics/normalize/flow/standard-prototype-method-source.d.ts +16 -0
  589. package/dist/semantics/normalize/flow/standard-prototype-method-source.js +64 -0
  590. package/dist/semantics/normalize/flow/targets.d.ts +13 -14
  591. package/dist/semantics/normalize/flow/targets.js +20 -23
  592. package/dist/semantics/normalize/flow/value-flow.d.ts +2 -4
  593. package/dist/semantics/normalize/flow/value-flow.js +4 -13
  594. package/dist/semantics/normalize/flow/value-provenance.d.ts +23 -3
  595. package/dist/semantics/normalize/flow/value-provenance.js +44 -4
  596. package/dist/semantics/normalize/fresh-dictionary-storage.d.ts +32 -0
  597. package/dist/semantics/normalize/fresh-dictionary-storage.js +530 -0
  598. package/dist/semantics/normalize/fresh-indexed-storage.d.ts +43 -0
  599. package/dist/semantics/normalize/fresh-indexed-storage.js +88 -0
  600. package/dist/semantics/normalize/fresh-ordinary-object.d.ts +8 -0
  601. package/dist/semantics/normalize/fresh-ordinary-object.js +27 -0
  602. package/dist/semantics/normalize/gating.js +2 -2
  603. package/dist/semantics/normalize/global-host-mutations.js +770 -261
  604. package/dist/semantics/normalize/host-effect-contracts.d.ts +1 -1
  605. package/dist/semantics/normalize/host-effect-contracts.js +1 -1
  606. package/dist/semantics/normalize/host-mutation-computed-keys.d.ts +2 -2
  607. package/dist/semantics/normalize/host-mutation-computed-keys.js +8 -0
  608. package/dist/semantics/normalize/host-mutation-key-reader.d.ts +6 -11
  609. package/dist/semantics/normalize/host-mutation-key-reader.js +11 -28
  610. package/dist/semantics/normalize/host-mutation-keys.d.ts +11 -7
  611. package/dist/semantics/normalize/host-mutation-keys.js +26 -15
  612. package/dist/semantics/normalize/identities.js +20 -17
  613. package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +8 -3
  614. package/dist/semantics/normalize/implicit-arguments-tuple.js +21 -4
  615. package/dist/semantics/normalize/installed-global-properties.d.ts +17 -0
  616. package/dist/semantics/normalize/installed-global-properties.js +214 -0
  617. package/dist/semantics/normalize/instantiation.js +6 -6
  618. package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +1 -1
  619. package/dist/semantics/normalize/intrinsic-property-call.d.ts +6 -1
  620. package/dist/semantics/normalize/intrinsic-property-call.js +19 -0
  621. package/dist/semantics/normalize/intrinsic-prototype.d.ts +7 -0
  622. package/dist/semantics/normalize/intrinsic-prototype.js +10 -0
  623. package/dist/semantics/normalize/intrinsic-return-identity.d.ts +5 -0
  624. package/dist/semantics/normalize/intrinsic-return-identity.js +29 -0
  625. package/dist/semantics/normalize/jsdoc-type-names.js +59 -63
  626. package/dist/semantics/normalize/keyof.js +3 -3
  627. package/dist/semantics/normalize/local-bindings.d.ts +4 -4
  628. package/dist/semantics/normalize/local-bindings.js +60 -61
  629. package/dist/semantics/normalize/logical-object-truthiness.d.ts +8 -0
  630. package/dist/semantics/normalize/logical-object-truthiness.js +20 -0
  631. package/dist/semantics/normalize/merged-declaration.d.ts +3 -3
  632. package/dist/semantics/normalize/merged-declaration.js +3 -3
  633. package/dist/semantics/normalize/never-override-result.d.ts +2 -3
  634. package/dist/semantics/normalize/never-override-result.js +2 -3
  635. package/dist/semantics/normalize/null-blind-parameter.d.ts +2 -2
  636. package/dist/semantics/normalize/null-blind-parameter.js +2 -2
  637. package/dist/semantics/normalize/object-bag-bindings.d.ts +19 -19
  638. package/dist/semantics/normalize/object-bag-bindings.js +334 -141
  639. package/dist/semantics/normalize/omitted-stated-parameter.d.ts +8 -8
  640. package/dist/semantics/normalize/omitted-stated-parameter.js +8 -9
  641. package/dist/semantics/normalize/override-field-arms.d.ts +3 -3
  642. package/dist/semantics/normalize/override-field-arms.js +15 -16
  643. package/dist/semantics/normalize/parameter-bindings.d.ts +13 -12
  644. package/dist/semantics/normalize/parameter-bindings.js +173 -139
  645. package/dist/semantics/normalize/parameter-slot.d.ts +9 -10
  646. package/dist/semantics/normalize/parameter-slot.js +16 -17
  647. package/dist/semantics/normalize/physical-overload-result.d.ts +8 -8
  648. package/dist/semantics/normalize/physical-overload-result.js +10 -10
  649. package/dist/semantics/normalize/producer-context.d.ts +27 -12
  650. package/dist/semantics/normalize/producers/allocations.js +5 -1
  651. package/dist/semantics/normalize/producers/bindings.js +8 -7
  652. package/dist/semantics/normalize/producers/class-lifecycle.js +52 -7
  653. package/dist/semantics/normalize/producers/computations.js +27 -3
  654. package/dist/semantics/normalize/producers/control.js +5 -5
  655. package/dist/semantics/normalize/producers/declaration-lifecycle.js +4 -4
  656. package/dist/semantics/normalize/producers/destructuring.js +10 -5
  657. package/dist/semantics/normalize/producers/erasure.d.ts +9 -0
  658. package/dist/semantics/normalize/producers/erasure.js +22 -0
  659. package/dist/semantics/normalize/producers/invocations.d.ts +1 -1
  660. package/dist/semantics/normalize/producers/invocations.js +200 -55
  661. package/dist/semantics/normalize/producers/logical-merge-type.d.ts +2 -2
  662. package/dist/semantics/normalize/producers/logical-merge-type.js +12 -12
  663. package/dist/semantics/normalize/producers/native-callable-readonly-set.d.ts +6 -0
  664. package/dist/semantics/normalize/producers/native-callable-readonly-set.js +24 -0
  665. package/dist/semantics/normalize/producers/native-own-assignment.d.ts +14 -0
  666. package/dist/semantics/normalize/producers/native-own-assignment.js +153 -0
  667. package/dist/semantics/normalize/producers/properties.js +153 -20
  668. package/dist/semantics/normalize/producers/protocol.js +4 -4
  669. package/dist/semantics/normalize/producers/references.js +21 -19
  670. package/dist/semantics/normalize/producers/shared.d.ts +1 -1
  671. package/dist/semantics/normalize/producers/shared.js +59 -58
  672. package/dist/semantics/normalize/producers/spread-arguments.js +7 -3
  673. package/dist/semantics/normalize/producers/tuple-spread.d.ts +2 -2
  674. package/dist/semantics/normalize/producers/tuple-spread.js +5 -5
  675. package/dist/semantics/normalize/property-key-domain.d.ts +6 -6
  676. package/dist/semantics/normalize/property-key-domain.js +7 -7
  677. package/dist/semantics/normalize/reachability.d.ts +6 -7
  678. package/dist/semantics/normalize/reachability.js +60 -62
  679. package/dist/semantics/normalize/record-home-arms.js +2 -3
  680. package/dist/semantics/normalize/record-link-families.d.ts +1 -1
  681. package/dist/semantics/normalize/record-link-families.js +1 -1
  682. package/dist/semantics/normalize/record-stand-in-arms.d.ts +4 -5
  683. package/dist/semantics/normalize/return-bindings.d.ts +19 -9
  684. package/dist/semantics/normalize/return-bindings.js +49 -41
  685. package/dist/semantics/normalize/script-global-redefinition.d.ts +1 -1
  686. package/dist/semantics/normalize/script-global-redefinition.js +1 -1
  687. package/dist/semantics/normalize/shared-array-storage.d.ts +4 -5
  688. package/dist/semantics/normalize/shared-array-storage.js +7 -8
  689. package/dist/semantics/normalize/sloppy-absence.d.ts +6 -3
  690. package/dist/semantics/normalize/sloppy-absence.js +7 -3
  691. package/dist/semantics/normalize/source-object-prototype-absence.d.ts +7 -0
  692. package/dist/semantics/normalize/source-object-prototype-absence.js +19 -0
  693. package/dist/semantics/normalize/specialization.d.ts +10 -10
  694. package/dist/semantics/normalize/specialization.js +107 -112
  695. package/dist/semantics/normalize/specialized-source-frames.d.ts +11 -0
  696. package/dist/semantics/normalize/specialized-source-frames.js +41 -0
  697. package/dist/semantics/normalize/structural-array-element.d.ts +5 -5
  698. package/dist/semantics/normalize/structural-array-element.js +40 -39
  699. package/dist/semantics/normalize/structural-array-read.js +3 -3
  700. package/dist/semantics/normalize/structural-callable.d.ts +15 -1
  701. package/dist/semantics/normalize/structural-callable.js +35 -3
  702. package/dist/semantics/normalize/structural-creation-order.d.ts +2 -2
  703. package/dist/semantics/normalize/structural-declarations.d.ts +22 -21
  704. package/dist/semantics/normalize/structural-declarations.js +42 -42
  705. package/dist/semantics/normalize/structural-declared-body.js +10 -11
  706. package/dist/semantics/normalize/structural-indexed-access.js +2 -2
  707. package/dist/semantics/normalize/structural-instantiated-member.d.ts +9 -10
  708. package/dist/semantics/normalize/structural-instantiated-member.js +43 -30
  709. package/dist/semantics/normalize/structural-joins.d.ts +4 -16
  710. package/dist/semantics/normalize/structural-joins.js +5 -65
  711. package/dist/semantics/normalize/structural-layout-relevance.d.ts +5 -5
  712. package/dist/semantics/normalize/structural-layout-relevance.js +22 -23
  713. package/dist/semantics/normalize/structural-layout-type.d.ts +1 -1
  714. package/dist/semantics/normalize/structural-layout-type.js +140 -107
  715. package/dist/semantics/normalize/structural-local-union.d.ts +1 -1
  716. package/dist/semantics/normalize/structural-local-union.js +38 -12
  717. package/dist/semantics/normalize/structural-mutable-field.d.ts +9 -0
  718. package/dist/semantics/normalize/structural-mutable-field.js +152 -0
  719. package/dist/semantics/normalize/structural-parts.d.ts +6 -0
  720. package/dist/semantics/normalize/structural-parts.js +35 -32
  721. package/dist/semantics/normalize/structural-receiver.d.ts +3 -3
  722. package/dist/semantics/normalize/structural-receiver.js +12 -13
  723. package/dist/semantics/normalize/structural-self-reference.d.ts +12 -11
  724. package/dist/semantics/normalize/structural-self-reference.js +24 -25
  725. package/dist/semantics/normalize/structural.d.ts +13 -3
  726. package/dist/semantics/normalize/structural.js +400 -201
  727. package/dist/semantics/normalize/suppressed-write-arms.d.ts +10 -11
  728. package/dist/semantics/normalize/symbol-keyed-this-slots.d.ts +6 -6
  729. package/dist/semantics/normalize/symbol-keyed-this-slots.js +4 -4
  730. package/dist/semantics/normalize/unresolvable-names.d.ts +2 -3
  731. package/dist/semantics/normalize/unresolvable-names.js +2 -2
  732. package/dist/semantics/normalize/unshared-array-result.d.ts +4 -4
  733. package/dist/semantics/normalize/unshared-array-result.js +4 -4
  734. package/dist/semantics/package-sources.js +2 -3
  735. package/dist/semantics/program.d.ts +10 -13
  736. package/dist/semantics/program.js +80 -26
  737. package/dist/semantics/property-key.d.ts +9 -0
  738. package/dist/semantics/property-key.js +25 -0
  739. package/dist/semantics/prototype-object-class-source-transform.js +2 -2
  740. package/dist/semantics/prototype-reparenting.d.ts +1 -1
  741. package/dist/semantics/prototype-reparenting.js +1 -1
  742. package/dist/semantics/shared-declaration-files.d.ts +6 -1
  743. package/dist/semantics/shared-declaration-files.js +2 -2
  744. package/dist/semantics/source-transform-protocol.d.ts +26 -0
  745. package/dist/semantics/source-transform-protocol.js +1 -0
  746. package/dist/semantics/stable-checker.js +9 -13
  747. package/dist/semantics/subclass-member-overlay-transform.d.ts +2 -2
  748. package/dist/semantics/subclass-member-overlay-transform.js +89 -88
  749. package/dist/semantics/this-constructor-source-transform.js +2 -2
  750. package/dist/semantics/unchecked-guard-argument-copies.d.ts +3 -3
  751. package/dist/semantics/unchecked-write-member-declarations.d.ts +9 -11
  752. package/dist/semantics/unchecked-write-member-declarations.js +11 -13
  753. package/dist/semantics/uninstantiable-classes.d.ts +1 -1
  754. package/dist/semantics/uninstantiable-classes.js +1 -1
  755. package/dist/targets/cpp/balanced-units.d.ts +1 -1
  756. package/dist/targets/cpp/balanced-units.js +1 -1
  757. package/dist/targets/cpp/borrowed-arm-projections.d.ts +2 -3
  758. package/dist/targets/cpp/borrowed-arm-projections.js +2 -3
  759. package/dist/targets/cpp/borrowed-call-entry.js +3 -3
  760. package/dist/targets/cpp/captures.d.ts +2 -2
  761. package/dist/targets/cpp/captures.js +4 -4
  762. package/dist/targets/cpp/char-code-buffers.d.ts +1 -1
  763. package/dist/targets/cpp/char-code-buffers.js +4 -1
  764. package/dist/targets/cpp/class-layout.d.ts +7 -17
  765. package/dist/targets/cpp/class-layout.js +6 -13
  766. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
  767. package/dist/targets/cpp/class-properties/computed-method-value.js +5 -27
  768. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +49 -59
  769. package/dist/targets/cpp/class-properties/emit-class-properties.js +68 -232
  770. package/dist/targets/cpp/class-properties/native-method-read.d.ts +5 -0
  771. package/dist/targets/cpp/class-properties/native-method-read.js +60 -0
  772. package/dist/targets/cpp/class-properties/native-prototype.d.ts +3 -1
  773. package/dist/targets/cpp/class-properties/native-prototype.js +5 -6
  774. package/dist/targets/cpp/class-ref-transport.d.ts +1 -11
  775. package/dist/targets/cpp/class-ref-transport.js +1 -9
  776. package/dist/targets/cpp/conversions.js +613 -252
  777. package/dist/targets/cpp/coroutine-bodies.d.ts +1 -97
  778. package/dist/targets/cpp/coroutine-bodies.js +1 -187
  779. package/dist/targets/cpp/document.js +1 -1
  780. package/dist/targets/cpp/emit-allocation.d.ts +0 -38
  781. package/dist/targets/cpp/emit-allocation.js +63 -88
  782. package/dist/targets/cpp/emit-array-view.d.ts +7 -0
  783. package/dist/targets/cpp/emit-array-view.js +47 -0
  784. package/dist/targets/cpp/emit-arrays.d.ts +9 -52
  785. package/dist/targets/cpp/emit-arrays.js +177 -113
  786. package/dist/targets/cpp/emit-binding-reference.d.ts +10 -0
  787. package/dist/targets/cpp/emit-binding-reference.js +19 -1
  788. package/dist/targets/cpp/emit-bindings.js +19 -24
  789. package/dist/targets/cpp/emit-buffers.d.ts +8 -4
  790. package/dist/targets/cpp/emit-buffers.js +88 -47
  791. package/dist/targets/cpp/emit-callable-view.d.ts +6 -0
  792. package/dist/targets/cpp/emit-callable-view.js +133 -0
  793. package/dist/targets/cpp/emit-callable.d.ts +11 -1
  794. package/dist/targets/cpp/emit-callable.js +225 -266
  795. package/dist/targets/cpp/emit-carrier-members.d.ts +2 -2
  796. package/dist/targets/cpp/emit-carrier-members.js +42 -35
  797. package/dist/targets/cpp/emit-certified-conversion.d.ts +7 -0
  798. package/dist/targets/cpp/emit-certified-conversion.js +27 -0
  799. package/dist/targets/cpp/emit-context.d.ts +123 -64
  800. package/dist/targets/cpp/emit-context.js +147 -44
  801. package/dist/targets/cpp/emit-descriptor-snapshot.d.ts +10 -0
  802. package/dist/targets/cpp/emit-descriptor-snapshot.js +60 -0
  803. package/dist/targets/cpp/emit-dictionary-view.d.ts +6 -0
  804. package/dist/targets/cpp/emit-dictionary-view.js +102 -0
  805. package/dist/targets/cpp/emit-document-record-view.d.ts +3 -0
  806. package/dist/targets/cpp/emit-document-record-view.js +104 -0
  807. package/dist/targets/cpp/emit-dynamic-properties.d.ts +42 -17
  808. package/dist/targets/cpp/emit-dynamic-properties.js +118 -72
  809. package/dist/targets/cpp/emit-equality.d.ts +2 -1
  810. package/dist/targets/cpp/emit-equality.js +65 -45
  811. package/dist/targets/cpp/emit-exceptions.js +1 -1
  812. package/dist/targets/cpp/emit-in.js +22 -11
  813. package/dist/targets/cpp/emit-instanceof.js +15 -14
  814. package/dist/targets/cpp/emit-integers.d.ts +40 -3
  815. package/dist/targets/cpp/emit-integers.js +76 -5
  816. package/dist/targets/cpp/emit-iterable-object-view.d.ts +2 -0
  817. package/dist/targets/cpp/emit-iterable-object-view.js +15 -11
  818. package/dist/targets/cpp/emit-iterator-object-view.d.ts +2 -0
  819. package/dist/targets/cpp/emit-iterator-object-view.js +24 -16
  820. package/dist/targets/cpp/emit-iterator.d.ts +2 -0
  821. package/dist/targets/cpp/emit-iterator.js +115 -43
  822. package/dist/targets/cpp/emit-json.js +6 -6
  823. package/dist/targets/cpp/emit-jsx.js +2 -2
  824. package/dist/targets/cpp/emit-live-field-view.d.ts +26 -0
  825. package/dist/targets/cpp/emit-live-field-view.js +50 -0
  826. package/dist/targets/cpp/emit-narrowing.d.ts +60 -139
  827. package/dist/targets/cpp/emit-narrowing.js +694 -624
  828. package/dist/targets/cpp/emit-native-accessor-definition.d.ts +10 -0
  829. package/dist/targets/cpp/emit-native-accessor-definition.js +94 -0
  830. package/dist/targets/cpp/emit-native-callable-data.d.ts +23 -0
  831. package/dist/targets/cpp/emit-native-callable-data.js +117 -0
  832. package/dist/targets/cpp/emit-native-document-entry.d.ts +4 -0
  833. package/dist/targets/cpp/emit-native-document-entry.js +52 -0
  834. package/dist/targets/cpp/emit-native-field-view.d.ts +26 -0
  835. package/dist/targets/cpp/emit-native-field-view.js +217 -0
  836. package/dist/targets/cpp/emit-native-method.d.ts +16 -0
  837. package/dist/targets/cpp/emit-native-method.js +90 -0
  838. package/dist/targets/cpp/emit-native-object-data.d.ts +7 -0
  839. package/dist/targets/cpp/emit-native-object-data.js +66 -0
  840. package/dist/targets/cpp/emit-native-object-sample.d.ts +8 -0
  841. package/dist/targets/cpp/emit-native-object-sample.js +34 -0
  842. package/dist/targets/cpp/emit-native-own-assignment.d.ts +7 -0
  843. package/dist/targets/cpp/emit-native-own-assignment.js +119 -0
  844. package/dist/targets/cpp/emit-native-selection.d.ts +2 -2
  845. package/dist/targets/cpp/emit-native-selection.js +14 -5
  846. package/dist/targets/cpp/emit-number-storage.d.ts +2 -0
  847. package/dist/targets/cpp/emit-number-storage.js +1 -0
  848. package/dist/targets/cpp/emit-presence.d.ts +3 -4
  849. package/dist/targets/cpp/emit-presence.js +43 -21
  850. package/dist/targets/cpp/emit-properties.js +224 -111
  851. package/dist/targets/cpp/emit-protocol-iterator.d.ts +2 -0
  852. package/dist/targets/cpp/emit-protocol-iterator.js +45 -23
  853. package/dist/targets/cpp/emit-record-view.d.ts +5 -10
  854. package/dist/targets/cpp/emit-record-view.js +223 -269
  855. package/dist/targets/cpp/emit-return.js +33 -8
  856. package/dist/targets/cpp/emit-scopes.d.ts +2 -2
  857. package/dist/targets/cpp/emit-sum-widening.js +13 -5
  858. package/dist/targets/cpp/emit-tonumber.d.ts +1 -1
  859. package/dist/targets/cpp/emit-tonumber.js +3 -3
  860. package/dist/targets/cpp/emit-tostring.d.ts +20 -2
  861. package/dist/targets/cpp/emit-tostring.js +131 -28
  862. package/dist/targets/cpp/emit-typeof.d.ts +4 -0
  863. package/dist/targets/cpp/emit-typeof.js +29 -1
  864. package/dist/targets/cpp/emit-union-properties.d.ts +6 -23
  865. package/dist/targets/cpp/emit-union-properties.js +127 -235
  866. package/dist/targets/cpp/emit.d.ts +4 -1
  867. package/dist/targets/cpp/emit.js +336 -119
  868. package/dist/targets/cpp/error-types.d.ts +1 -3
  869. package/dist/targets/cpp/error-types.js +1 -2
  870. package/dist/targets/cpp/evaluated-once.d.ts +4 -4
  871. package/dist/targets/cpp/evaluated-once.js +5 -5
  872. package/dist/targets/cpp/function-source-reads.d.ts +2 -15
  873. package/dist/targets/cpp/function-source-reads.js +3 -38
  874. package/dist/targets/cpp/host/core-globals.d.ts +5 -0
  875. package/dist/targets/cpp/host/core-globals.js +10 -0
  876. package/dist/targets/cpp/host/emit-host-arity.js +1 -1
  877. package/dist/targets/cpp/host/emit-host-invoke.js +73 -23
  878. package/dist/targets/cpp/host/emit-host-object.d.ts +2 -1
  879. package/dist/targets/cpp/host/emit-host-object.js +328 -145
  880. package/dist/targets/cpp/host/emit-host-properties.js +4 -6
  881. package/dist/targets/cpp/host/emit-host-reflect.js +29 -5
  882. package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
  883. package/dist/targets/cpp/host/emit-host-value.js +2 -2
  884. package/dist/targets/cpp/host/host-members.d.ts +11 -0
  885. package/dist/targets/cpp/host/host-members.js +27 -5
  886. package/dist/targets/cpp/host/host-method-aliases.d.ts +1 -30
  887. package/dist/targets/cpp/host/host-method-aliases.js +1 -76
  888. package/dist/targets/cpp/host/native-protocols.js +1 -1
  889. package/dist/targets/cpp/host/object-protocol.d.ts +1 -1
  890. package/dist/targets/cpp/host/object-protocol.js +24 -24
  891. package/dist/targets/cpp/host-namespace-reads.d.ts +1 -83
  892. package/dist/targets/cpp/host-namespace-reads.js +1 -113
  893. package/dist/targets/cpp/manifest/capabilities.js +33 -33
  894. package/dist/targets/cpp/manifest.d.ts +5 -0
  895. package/dist/targets/cpp/manifest.js +38 -14
  896. package/dist/targets/cpp/native-collection-base.js +7 -6
  897. package/dist/targets/cpp/native-debug-source.d.ts +15 -0
  898. package/dist/targets/cpp/native-debug-source.js +21 -0
  899. package/dist/targets/cpp/native-error-base.d.ts +1 -1
  900. package/dist/targets/cpp/native-error-base.js +1 -1
  901. package/dist/targets/cpp/native-narrowing-transport.d.ts +2 -0
  902. package/dist/targets/cpp/native-narrowing-transport.js +25 -5
  903. package/dist/targets/cpp/native-view-targets.d.ts +3 -0
  904. package/dist/targets/cpp/native-view-targets.js +5 -0
  905. package/dist/targets/cpp/prototype/emit-prototype-array.d.ts +3 -33
  906. package/dist/targets/cpp/prototype/emit-prototype-array.js +40 -22
  907. package/dist/targets/cpp/prototype/emit-prototype-date.d.ts +1 -58
  908. package/dist/targets/cpp/prototype/emit-prototype-date.js +14 -97
  909. package/dist/targets/cpp/prototype/emit-prototype-error.d.ts +20 -0
  910. package/dist/targets/cpp/prototype/emit-prototype-error.js +2 -2
  911. package/dist/targets/cpp/prototype/emit-prototype-invoke.d.ts +3 -27
  912. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +60 -52
  913. package/dist/targets/cpp/prototype/emit-prototype-iterator.d.ts +1 -41
  914. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +4 -43
  915. package/dist/targets/cpp/prototype/emit-prototype-promise.d.ts +2 -13
  916. package/dist/targets/cpp/prototype/emit-prototype-promise.js +10 -58
  917. package/dist/targets/cpp/prototype/emit-prototype-regexp.d.ts +4 -25
  918. package/dist/targets/cpp/prototype/emit-prototype-regexp.js +16 -81
  919. package/dist/targets/cpp/prototype/emit-prototype-string.d.ts +1 -1
  920. package/dist/targets/cpp/prototype/emit-prototype-string.js +17 -28
  921. package/dist/targets/cpp/prototype/prototype-method-reads.js +4 -80
  922. package/dist/targets/cpp/reactive-dependencies.d.ts +12 -6
  923. package/dist/targets/cpp/reactive-dependencies.js +62 -42
  924. package/dist/targets/cpp/reactive-origins.js +12 -0
  925. package/dist/targets/cpp/records.d.ts +133 -14
  926. package/dist/targets/cpp/records.js +345 -153
  927. package/dist/targets/cpp/regexp-types.d.ts +1 -26
  928. package/dist/targets/cpp/regexp-types.js +4 -29
  929. package/dist/targets/cpp/segment-scopes.d.ts +30 -0
  930. package/dist/targets/cpp/segment-scopes.js +294 -0
  931. package/dist/targets/cpp/translation-unit.d.ts +21 -2
  932. package/dist/targets/cpp/translation-unit.js +121 -276
  933. package/dist/targets/cpp/types.d.ts +8 -3
  934. package/dist/targets/cpp/types.js +30 -6
  935. package/dist/targets/cpp/virtual-callees.d.ts +18 -0
  936. package/dist/targets/cpp/virtual-callees.js +27 -0
  937. package/dist/targets/cpp/virtual-methods.d.ts +7 -7
  938. package/dist/targets/cpp/virtual-methods.js +213 -58
  939. package/package.json +8 -3
  940. package/src/targets/cpp/runtime/gea_dictionary_view.h +204 -0
  941. package/src/targets/cpp/runtime/gea_document_view.h +845 -0
  942. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +66 -23
  943. package/src/targets/cpp/runtime/gea_eval.h +6 -6
  944. package/src/targets/cpp/runtime/gea_runtime.h +7550 -1166
  945. package/dist/targets/cpp/direct-call-receivers.d.ts +0 -37
  946. package/dist/targets/cpp/direct-call-receivers.js +0 -79
@@ -1,28 +1,45 @@
1
1
  import { isNativeCallableCarrier } from '../../representation/callable-object.js';
2
+ import { numberStorageTarget } from '../../conversion/number-storage.js';
3
+ import { numberStorageText } from './emit-number-storage.js';
4
+ import { NATIVE_REFERENCE_ABSENCE, nativeReferenceAbsenceOf } from '../../conversion/native-absence.js';
2
5
  import { isNativeError } from './error-types.js';
3
6
  import { proxyArmWithoutHome } from '../../representation/proxy-carriers.js';
7
+ import { physicalCarrierKey, samePhysicalCarrier } from '../../representation/physical-carrier.js';
4
8
  import { cppRecordIndexSidecarName, tailAwareFieldReadText, tailAwareFieldWriteText, tailFieldsOf } from './records.js';
5
9
  import { classRefTransportKind, constructorFamilyUpcastMembers, constructorUpcastMember, nativeRecordBaseTransportKind, nativePromiseBaseOf } from './class-ref-transport.js';
6
- import { abiKey, arrayExtensionKey, containsUnresolved, isBooleanShapedMergeTarget, isCanonicalNumberPropertyKeyText, isOpenDocument, representationKey, standInRefuses, walkRepresentation, carriesUndefined } from '../../representation/model.js';
10
+ import { abiKey, arrayExtensionKey, containsUnresolved, isCanonicalNumberPropertyKeyText, isOpenDocument, representationKey, standInRefuses, walkRepresentation, carriesUndefined } from '../../representation/model.js';
11
+ import { programConversionKey } from '../../ir/program-conversions.js';
7
12
  import { transferOf } from '../../ir/transfer.js';
8
13
  import { coercionText } from './emit-coercion.js';
9
- import { ARM_VIEW_MATERIALIZER, ASSERTED_UNION_MATERIALIZER, ASSERTED_UNION_COPY_MATERIALIZER, EXACT_ARM_MATERIALIZER, FAMILY_MEMBER_VIEW_MATERIALIZER, CAUGHT_HANDOFF_MATERIALIZER, NULLISH_OPTIONAL_MATERIALIZER, NATIVE_BASE_VIEW_MATERIALIZER, exactArmIndexOf, isNativeCollectionUpcast } from '../../conversion/nodes.js';
10
- import { familyMemberViewText, structuralRecordViewText, unionRecastPlanOf, viewPlanFor } from './emit-record-view.js';
11
- import { PROTOCOL_ITERATOR, protocolIteratorText } from './emit-protocol-iterator.js';
12
- import { ITERABLE_OBJECT_VIEW, iterableObjectViewText } from './emit-iterable-object-view.js';
13
- import { ITERATOR_OBJECT_VIEW, iteratorObjectViewText } from './emit-iterator-object-view.js';
14
+ import { ARM_VIEW_MATERIALIZER, ASSERTED_UNION_MATERIALIZER, ASSERTED_UNION_COPY_MATERIALIZER, ASSERTED_VIEW_MATERIALIZER, EXACT_ARM_MATERIALIZER, FAMILY_MEMBER_VIEW_MATERIALIZER, CAUGHT_HANDOFF_MATERIALIZER, ASSERTED_CLASS_DOWNCAST_MATERIALIZER, NULLISH_OPTIONAL_MATERIALIZER, NATIVE_BASE_VIEW_MATERIALIZER, IMPOSSIBLE_INDEX_READ, exactArmIndexOf, isNativeCollectionUpcast } from '../../conversion/nodes.js';
15
+ import { certifiedRecordViewText, familyMemberViewText, structuralRecordViewText } from './emit-record-view.js';
16
+ import { documentRecordViewText } from './emit-document-record-view.js';
17
+ import { dynamicRecordLoadNeedsPlan } from '../../conversion/document-record-view.js';
18
+ import { IMPOSSIBLE_FIELD_READ } from '../../conversion/impossible-field-read.js';
19
+ import { checkedNativeFieldReadMismatchOf } from '../../conversion/checked-native-field-read.js';
20
+ import { callablePayloadText, callableViewText } from './emit-callable-view.js';
21
+ import { dictionaryReadText, dictionaryViewText } from './emit-dictionary-view.js';
22
+ import { nativeObjectSampleText } from './emit-native-object-sample.js';
23
+ import { nativeDescriptorSnapshotViewText } from './emit-descriptor-snapshot.js';
24
+ import { SIBLING_CLASS_ARGUMENT } from '../../conversion/sibling-class.js';
25
+ import { PROTOCOL_ITERATOR, protocolIteratorText, certifiedProtocolIteratorText } from './emit-protocol-iterator.js';
26
+ import { ITERABLE_OBJECT_VIEW, iterableObjectViewText, certifiedIterableObjectViewText } from './emit-iterable-object-view.js';
27
+ import { ITERATOR_OBJECT_VIEW, certifiedIteratorObjectViewText, iteratorObjectViewText } from './emit-iterator-object-view.js';
14
28
  import { CONSTRUCTOR_DISPATCH_FAMILY, CONSTRUCTOR_IDENTITY_FAMILY, constructorDispatchFamilyText, constructorIdentityFamilyText } from './emit-constructor-identity-family.js';
15
- import { recordViewDispatchesArms } from '../../conversion/record-view.js';
16
29
  import { createCppEmitBlockedError, cppConstructThunkName, cppThunkName, defineValue, isCppEmitBlockedError, isDeferredValue, operandText } from './emit-context.js';
17
30
  import { booleanTestText } from './emit-presence.js';
18
31
  import { recastedRecordToArrayText } from './emit-arrays.js';
19
- import { cppAbiParameterType, cppAbiType, cppClassName, cppConstantLiteral, cppRecordFieldName, cppRecordFieldKeyIsSymbol, cppRecordFieldPresenceName, cppRecordStructName, cppResultTypeOf, cppStringLiteral, cppTypeOf, cppNarrowedIntegerType, cppUndefinedIn, cppUndefinedValue, storageSlotIsNarrowed, unitFunctionName, withoutUnitFunctions } from './types.js';
32
+ import { cppAbiParameterType, cppCallableFrameArguments, cppClassName, cppConstantLiteral, cppRecordFieldName, cppRecordFieldKeyIsSymbol, cppRecordFieldPresenceName, cppRecordStructName, cppResultTypeOf, cppStringLiteral, cppTypeOf, cppNarrowedIntegerType, cppUndefinedIn, cppUndefinedValue, storageSlotIsNarrowed, unitFunctionName, withoutUnitFunctions } from './types.js';
20
33
  import { integerStorageSlot } from '../../ir/integer-storage.js';
21
34
  import { cppRegExpNativeTypes, cppStringObjectNativeType } from './regexp-types.js';
22
35
  import { widenedNativeSumText } from './emit-sum-widening.js';
23
36
  import { nativeSelectionText } from './emit-native-selection.js';
24
37
  import { narrowingReachesTarget } from '../../conversion/build.js';
25
38
  import { evaluatedOnceText } from './evaluated-once.js';
39
+ import { nativeCallReceiverText, nativeUnboundMethodText } from './emit-native-method.js';
40
+ import { dynamicWrapperPlanMatches } from '../../conversion/dynamic-wrapper.js';
41
+ import { nativeArrayViewText } from './emit-array-view.js';
42
+ import { nativeFieldPolicyType } from './records.js';
26
43
  /**
27
44
  * `native-record-ref` (the String WRAPPER OBJECT, `new String(x)`) -> `string`,
28
45
  * the one direction `convertedValueText` needs that neither `narrowedLoadText`
@@ -62,9 +79,9 @@ export const promisePayloadConvertible = (source, target) => {
62
79
  // unit pair reconciles by supplying or dropping the value, in either
63
80
  // direction. An unknown payload can also hold that undefined value; it must
64
81
  // receive the fulfillment value rather than a boxed source promise.
65
- // `@hono/node-server`'s `listener.ts` needs exactly this: `responseViaCache`
66
- // is declared `Promise<undefined | void>` and both callers `return` its
67
- // promise from an async function whose own result is `Promise<void>`.
82
+ // A function declared `Promise<undefined | void>` whose callers `return` its
83
+ // promise from an async function whose own result is `Promise<void>` needs
84
+ // exactly this.
68
85
  if (target.kind === 'void')
69
86
  return isUnitPromisePayload(source);
70
87
  if (source.kind === 'void')
@@ -149,8 +166,8 @@ export const classFamilyLoadText = (ctx, held, read, text) => {
149
166
  if (!arms.every((arm) => arm.kind === 'class-ref' && arm.ownership === source.ownership && arm.ancestors.includes(source.declaration)))
150
167
  return null;
151
168
  const classes = arms;
152
- // A target may retain both an ancestor and one of its descendants (Three's
153
- // WebGLRenderTarget | WebGLCubeRenderTarget flow does). JS unions do not
169
+ // A target may retain both an ancestor and one of its descendants (a
170
+ // `Base | Derived` union where `Derived extends Base`). JS unions do not
154
171
  // preserve which syntactic arm produced an object, so allocation identity
155
172
  // supplies the canonical answer: test the most-specific family first and
156
173
  // retain each arm's original target-union index when rebuilding it.
@@ -211,11 +228,11 @@ const taggedUnionArmText = (union, target, text, unhomed = 'refuse') => {
211
228
  // An arm that CONVERTS to the target answers too. An exact arm is the
212
229
  // cheapest answer for its own discriminant, but its existence cannot erase
213
230
  // a different live arm which is structurally assignable to the same target.
214
- // Hono's RegExpRouter exposed this: a truthy value is either `string[]` or
231
+ // A regex-driven router exposed this: a truthy value is either `string[]` or
215
232
  // `RegExpMatchArray`; both are `Array<string>`, yet preferring the exact arm
216
233
  // emitted an unconditional `get<0>()` and crashed on a match-result arm.
217
234
  //
218
- // Hono's `Hono.fetch` is another converting case: the cell is
235
+ // A method reading a boxed-or-optional cell is another converting case: the cell is
219
236
  // `dynamic | optional(record)` and the read is a
220
237
  // `native-record-ref`, so the live arm is the BOX and the load is the
221
238
  // unboxing check `unboxedLoadText` already renders. The narrowing that
@@ -241,9 +258,9 @@ const taggedUnionArmText = (union, target, text, unhomed = 'refuse') => {
241
258
  // arm needs its home or the read would rebuild a live arm as another.
242
259
  // Whatever the uncovered arm is: a class or a named record left without a
243
260
  // home is dropped just as surely as a structural one, and the chain then
244
- // reads the wrong arm's payload. mongodb's `resolveOptions(parent:
245
- // OperationParent)` handed a Collection to `resolveBSONOptions`'s
246
- // `Db | MongoClient | { bsonOptions? }` parameter and read it as a Db.
261
+ // reads the wrong arm's payload: an instance of one class handed to a
262
+ // `ClassA | ClassB | { option? }` parameter, of which it is none of the
263
+ // classes, was read as the first class.
247
264
  const partialWidening = target.kind === 'tagged-union' &&
248
265
  candidates.some((candidate) => !exact.includes(candidate)) &&
249
266
  union.arms.some((_, index) => !candidates.some((candidate) => candidate.index === index));
@@ -362,7 +379,7 @@ const narrowedUnionSubsetText = (inner, read, text) => {
362
379
  // this chain is what a NESTED union arm reaches through (`homeOf` there
363
380
  // asks `convertedValueText`, which lands here for an inner union narrowed
364
381
  // one level down), and it spelled the ~1.3KB target type and the source
365
- // expression once per arm -- 928 inner spellings on one three.js line after
382
+ // expression once per arm -- 928 inner spellings on one emitted line after
366
383
  // the outer recast alone was bound. A single-pair chain keeps the direct
367
384
  // spelling: there is nothing to share.
368
385
  const multiPair = pairs.length > 1;
@@ -412,14 +429,14 @@ export const narrowedLoadText = (held, read, text) => {
412
429
  held.native !== null &&
413
430
  held.native === read.native &&
414
431
  held.ownership === read.ownership &&
415
- cppTypeOf(held) === cppTypeOf(read))
432
+ samePhysicalCarrier(held, read))
416
433
  return text;
417
434
  const unwrapped = held.kind === 'optional' ? `(*${text})` : text;
418
435
  const inner = held.kind === 'optional' ? held.payload : held;
419
436
  if (representationKey(inner) === representationKey(read))
420
437
  return unwrapped;
421
438
  // The same array read as the interface that extends it (`elements` of
422
- // `readonly T[] | undefined`, proven present and then `isNodeArray`): one
439
+ // `readonly T[] | undefined`, proven present and then type-guarded): one
423
440
  // C++ type either way -- the fields an extension adds live beside the
424
441
  // elements -- so the load is the payload itself, exactly as
425
442
  // `conversions.ts`'s `gea::ArrayObject::identity` recast states for the
@@ -434,6 +451,9 @@ export const narrowedLoadText = (held, read, text) => {
434
451
  // `gea::Optional<T>` where a `std::nullptr_t` is declared.
435
452
  if (held.kind === 'optional' && read.kind === held.absence)
436
453
  return read.kind === 'null' ? 'nullptr' : cppUndefinedValue;
454
+ // A shared class reference carries its own absence (a null handle): the same proof, the same constant.
455
+ if (held.kind === 'class-ref' && held.ownership === 'shared-refcount' && read.kind === 'null')
456
+ return 'nullptr';
437
457
  // Reading a cell as `dynamic` is not a narrowing at all -- it is the box, and
438
458
  // the box accepts every carrier. Answered by the widening this file already
439
459
  // owns rather than by searching the arms for a `dynamic` one, which no union
@@ -447,9 +467,8 @@ export const narrowedLoadText = (held, read, text) => {
447
467
  // dynamic branch owns that (`has_value() ? box(payload) : box(absence)`).
448
468
  // Handing it the unwrapped payload boxed `(*cell)` unconditionally, so a
449
469
  // `number | null` holding `null` reached an `...args: any[]` listener as
450
- // `Tag::Number` over whatever the dereference found -- node-compat's
451
- // cluster 'exit' event reported `code=0 signal=` for a worker Node reports
452
- // as `code=null signal=SIGTERM`. Certified, compiled, wrong.
470
+ // `Tag::Number` over whatever the dereference found -- an event reporting
471
+ // `code=null` reported `code=0`. Certified, compiled, wrong.
453
472
  if (read.kind === 'dynamic')
454
473
  return widenedStoreText(read, held, text);
455
474
  // And the mirror: a cell the program declared `any` read at a place the
@@ -475,8 +494,8 @@ export const narrowedLoadText = (held, read, text) => {
475
494
  nativeRecordBaseTransportKind(inner, read) === 'upcast') {
476
495
  return `${cppTypeOf(read)}(${unwrapped})`;
477
496
  }
478
- // A program-class handle read at a DERIVED class -- `part instanceof Mesh`
479
- // then `part.castShadow = true` on a `traverse` callback's `Object3D`.
497
+ // A program-class handle read at a DERIVED class -- `node instanceof Derived`
498
+ // then `node.derivedField = true` on a callback parameter typed as the base.
480
499
  // `gea::Ref<Base>` and `gea::Ref<Derived>` are different C++ types, so the
481
500
  // narrowed read needs a cast even though nothing about the object changes:
482
501
  // `downcastClassRef` (gea_runtime.h) is `staticCast` plus the one thing this
@@ -499,7 +518,7 @@ export const narrowedLoadText = (held, read, text) => {
499
518
  return `gea::host::downcastClassRef<${cppClassName(read.declaration)}>(${unwrapped})`;
500
519
  }
501
520
  // A cell that provably holds nothing but absence, read at a place declared
502
- // wider. hono's `#dispatch` binds `env: E['Bindings']` -- an indexed access
521
+ // wider. A parameter typed `env: E['Bindings']` -- an indexed access
503
522
  // through a type parameter's constraint that this program never instantiates
504
523
  // -- so its cell is placed `undefined` while every read of it is the declared
505
524
  // optional. A read cannot be narrower than the cell here; it is a widening,
@@ -512,7 +531,7 @@ export const narrowedLoadText = (held, read, text) => {
512
531
  // Every arm search below SELECTS: it loads the arm the read names and
513
532
  // trusts the narrowing that licensed the load to have killed the rest. A
514
533
  // store into a declared slot has no such licence -- `const ctx:
515
- // AudioContextLike | null = Ctor ? new Ctor() : createNativeAudioContext()`
534
+ // SomeInterface | null = Ctor ? new Ctor() : createOther()`
516
535
  // converts a `record | class` into the interface's record, and the class
517
536
  // arm is as live as the record's. This chain cannot tell the two apart (a
518
537
  // class viewed as a record needs the program's layouts), so the census
@@ -564,10 +583,18 @@ export const narrowedLoadText = (held, read, text) => {
564
583
  const absentIndex = inner.arms.findIndex((arm) => arm.value.kind === read.absence);
565
584
  if (absentIndex >= 0) {
566
585
  const narrowed = cppTypeOf(read);
567
- return `(${unwrapped}.is<${absentIndex}>() ? ${narrowed}() : ${narrowed}(${taggedUnionArmText(inner, read.payload, unwrapped)}))`;
586
+ // The absent arm is tested first, so it never needs a home in the
587
+ // payload. Searching with `refuse` counted it as an unhomed arm of a
588
+ // union payload and refused, and the chain fell through to
589
+ // `optional-wrap-converted`, which loaded the present arm into a PRESENT
590
+ // optional unconditionally: `describe(holder.image)` over `A | B |
591
+ // undefined` passed into `A | B | C | null | undefined` read the
592
+ // undefined arm as the present union. Any other unhomed arm is proven
593
+ // dead by the narrowing that licensed this load, and is checked.
594
+ return `(${unwrapped}.is<${absentIndex}>() ? ${narrowed}() : ${narrowed}(${taggedUnionArmText(inner, read.payload, unwrapped, 'throw')}))`;
568
595
  }
569
596
  // No arm is the bare absent literal, because absence lives INSIDE another
570
- // arm's own optional. hono's `compose` binds `let handler` to a
597
+ // arm's own optional. A middleware composer binds `let handler` to a
571
598
  // `Function | (Next | undefined)` cell and reads it back as `Function |
572
599
  // undefined`: the union's arms are the record and an
573
600
  // `optional(callable)`, and the read's payload is the record alone.
@@ -597,7 +624,7 @@ export const narrowedLoadText = (held, read, text) => {
597
624
  // only ever shrink a union -- the cell's placement is the union of what the
598
625
  // program writes to it, and a read's carrier is the declared type at that
599
626
  // site, so a cell every writer narrows still gets read at its full declared
600
- // width. hono's `#newResponse` is the case: the cell holds
627
+ // width. A response-building method is the case: the cell holds
601
628
  // `Response | ResponseInit` and the read wants
602
629
  // `StatusCode | Response | ResponseInit`. Every arm the cell can hold is an
603
630
  // arm of the read, which is exactly what `recastedUnionText` proves, and
@@ -619,8 +646,8 @@ export const narrowedLoadText = (held, read, text) => {
619
646
  * refused with "narrows a tagged union to string, which none of its arms
620
647
  * carries" -- an accurate sentence about the outer union only.
621
648
  *
622
- * `node-compat`'s `new Request(url, init)` is the case: `typeof init.body ===
623
- * 'string'` narrows `BodyInit | null | undefined` to `string`.
649
+ * `typeof init.body === 'string'` over a nested `string | Blob | null |
650
+ * undefined` body field is the case: it narrows to `string`.
624
651
  *
625
652
  * The discriminant is tested whenever more than one arm can answer, exactly as
626
653
  * `taggedUnionArmText` does for the flat case, and for the same reason: with
@@ -633,7 +660,7 @@ const nestedArmLoadText = (inner, read, text) => {
633
660
  if (representationKey(held) === readKey)
634
661
  return at;
635
662
  // A leaf can satisfy a wider nested read through a real carrier
636
- // conversion. Hono's RegExpRouter reads an optional `Array<string>` from
663
+ // conversion. A regex-driven router reads an optional `Array<string>` from
637
664
  // an optional union whose leaves are `string[]` and `RegExpMatchArray`:
638
665
  // neither leaf equals the OPTIONAL target, but both convert to it. Looking
639
666
  // only for exact nested keys found the first leaf and emitted its `get`
@@ -774,8 +801,8 @@ export const dynamicTagFor = (representation) => {
774
801
  // ever one payload address to record, never one per element domain the
775
802
  // way `typed-array` needs). `Value::box` records that address as
776
803
  // `payloadType()` the identical way it does for every other `Ref<...>`
777
- // in this list. Missing here meant an `ArrayBuffer` value -- hono's
778
- // `Context.body`'s own `Data` union carries one -- could never widen
804
+ // in this list. Missing here meant an `ArrayBuffer` value -- a
805
+ // request-body data union carries one -- could never widen
779
806
  // into a `dynamic` cell, the same silent gap `typed-array`'s own
780
807
  // addition just above closed for typed arrays, blocking both this
781
808
  // widen and the reverse read (`unboxedLoadText`, below) for the
@@ -817,8 +844,8 @@ export const dynamicTagFor = (representation) => {
817
844
  // whichever `T` this instantiation closes over, one program-wide address
818
845
  // per payload type, exactly as it does for every other kind sharing this
819
846
  // tag. Missing here meant a value returned from a plain (non-async)
820
- // function -- `#cachedBody`'s `return (bodyCache[k] as Promise<BodyInit>)
821
- // .then(...)` in hono's `request.ts`, whose OWN inferred return type is a
847
+ // function -- a body cache's `return (bodyCache[k] as Promise<BodyInit>)
848
+ // .then(...)`, whose OWN inferred return type is a
822
849
  // real `Promise<unknown>` folding to `dynamic` only because its sibling
823
850
  // return arm reads a program-declared `any` -- could never widen into a
824
851
  // `dynamic` cell at all: `emit-narrowing.ts`'s own generic `held.kind ===
@@ -906,18 +933,18 @@ const restFromOf = (representation) => {
906
933
  * the packed array (10.2.11 binds a rest parameter to an Array of ALL the
907
934
  * remaining ones). The emitter is the only reader of the ABI, so it states the
908
935
  * position here and `gea::Value::boxCallable` records the matching thunk.
909
- * hono's `this[method] = (args1, ...args) => ...` is every `app.get(path,
910
- * handler)` in the program.
936
+ * A method table built as `this[method] = (args1, ...args) => ...` makes
937
+ * every call through it such a call.
911
938
  */
912
939
  export const boxedText = (representation, tag, text) => {
913
940
  const restFrom = restFromOf(representation);
914
941
  const value = `static_cast<${cppTypeOf(representation)}>(${text})`;
915
942
  const abi = representation.kind === 'function-and-constructor' ? representation.call : 'abi' in representation ? representation.abi : null;
916
943
  if (abi?.receiver)
917
- return `gea::Value::boxMethod<${restFrom === null ? -1 : restFrom + 1}>(${value})`;
944
+ return `gea::Value::boxMethod<${restFrom === null ? -1 : restFrom + 1}, ${abi.argumentsFrame === 'actual'}>(${value})`;
918
945
  if (restFrom === null)
919
946
  return `gea::Value::box(gea::Value::Tag::${tag}, ${value})`;
920
- return `gea::Value::boxCallable<${restFrom}>(${value})`;
947
+ return `gea::Value::boxCallable<${restFrom}, ${abi?.argumentsFrame === 'actual'}>(${value})`;
921
948
  };
922
949
  /**
923
950
  * How a native carrier boxes into a dynamic cell, rendered over an arbitrary
@@ -947,9 +974,9 @@ export const dynamicCarrierBoxText = (carrier, storage) => widenedStoreText({ ki
947
974
  */
948
975
  export const dynamicPromiseAdoptionText = (result, text, layouts) => {
949
976
  // A settled value read as a NAMED record is rebuilt from its layout, as a
950
- // plain `any -> T` read is (`dynamicNamedRecordText`): mongodb's
951
- // `tryOperation` returns `operation.handleOk(result)` -- typed `any`,
952
- // holding a Document -- from a body declared `Promise<InsertOneResult>`,
977
+ // plain `any -> T` read is (`dynamicNamedRecordText`): an async function
978
+ // returns a call typed `any` -- holding a plain object -- from a body
979
+ // declared `Promise<SomeResult>`,
953
980
  // and the layout-free load below would unbox it by identity only.
954
981
  if (layouts !== undefined && result.value.kind !== 'void') {
955
982
  const settledType = cppTypeOf(result.value);
@@ -1004,7 +1031,7 @@ const readOnlyMapViewStoreText = (held, written, text) => {
1004
1031
  return readOnlyMapViewText(written, held, text);
1005
1032
  // An arm the written map already IS, or shares a C++ type with, is its
1006
1033
  // home as it stands (`widenedStoreText`); a view is only for the rest.
1007
- if (held.arms.some((arm) => cppTypeOf(arm.value) === cppTypeOf(written)))
1034
+ if (held.arms.some((arm) => samePhysicalCarrier(arm.value, written)))
1008
1035
  return null;
1009
1036
  for (const [armIndex, arm] of held.arms.entries()) {
1010
1037
  const inner = readOnlyMapViewStoreText(arm.value, written, text);
@@ -1017,9 +1044,9 @@ const readOnlyMapViewStoreText = (held, written, text) => {
1017
1044
  * A typed `Map<K, V>` stored where a union holding `Map<unknown, unknown>` --
1018
1045
  * and no arm of the written map's own C++ type -- is declared: the SAME map,
1019
1046
  * boxed and read back through `unboxDynamicMap`'s `DynamicMapSource` view.
1020
- * bson's `serialize(object: Document)` walks such a parameter under
1047
+ * A serializer taking `object: Document` walks such a parameter under
1021
1048
  * `object instanceof Map`, so a copy would be a different object and would
1022
- * miss every later `set` (mongodb's client_metadata `LimitedSizeDocument`).
1049
+ * miss every later `set` (a `Map` subclass that keeps writing after the hand-off).
1023
1050
  */
1024
1051
  const dynamicMapArmViewStoreText = (held, written, text) => {
1025
1052
  if (written.kind !== 'keyed-collection' || written.family !== 'map' || written.ownership !== 'shared-refcount')
@@ -1028,7 +1055,7 @@ const dynamicMapArmViewStoreText = (held, written, text) => {
1028
1055
  return null;
1029
1056
  if (held.kind !== 'tagged-union')
1030
1057
  return null;
1031
- if (held.arms.some((arm) => cppTypeOf(arm.value) === cppTypeOf(written)))
1058
+ if (held.arms.some((arm) => samePhysicalCarrier(arm.value, written)))
1032
1059
  return null;
1033
1060
  for (const [armIndex, arm] of held.arms.entries()) {
1034
1061
  const target = arm.value;
@@ -1070,7 +1097,7 @@ const renderedWidenedStoreText = (held, written, text) => {
1070
1097
  if (held.kind === 'class-ref' && held.ownership === 'shared-refcount' && written.kind === 'null')
1071
1098
  return `${cppTypeOf(held)}()`;
1072
1099
  // A dynamic value returned where `Promise<T>` is declared may itself be a
1073
- // promise -- hono's `formData()` returns its `any`-typed `#cachedBody(...)`
1100
+ // promise -- an async method returning an `any`-typed call that yields one
1074
1101
  // -- and an async function's return adopts it (ECMA-262 27.2.1.3.2) rather
1075
1102
  // than fulfilling with the promise object.
1076
1103
  if (held.kind === 'promise' && written.kind === 'dynamic') {
@@ -1171,7 +1198,7 @@ const renderedWidenedStoreText = (held, written, text) => {
1171
1198
  // An arm that is itself a box is stored as-is, and cannot go through
1172
1199
  // the recursion below: this function's identity gate answers `null`
1173
1200
  // for a same-carrier pair -- "no widening needed", which the loop
1174
- // would read as a refusal. hono's `compose` carries its `handler` as
1201
+ // would read as a refusal. A middleware composer carries its `handler` as
1175
1202
  // `tagged-union(dynamic(untyped-callable) | optional(Next))`, and
1176
1203
  // reading that cell as `dynamic` asks exactly this of arm 0.
1177
1204
  if (arm.value.kind === 'dynamic') {
@@ -1188,7 +1215,7 @@ const renderedWidenedStoreText = (held, written, text) => {
1188
1215
  const armTag = dynamicTagFor(arm.value);
1189
1216
  // An arm with no tag is not a carrier this box cannot hold -- it is one
1190
1217
  // whose JavaScript type depends on something a level further in.
1191
- // `BodyInit | null | undefined` (hono's `createResponseInstance`) has a
1218
+ // `BodyInit | null | undefined` (a `Response` body parameter) has a
1192
1219
  // `present` arm that is ITSELF a union of seven, every one tagged. So
1193
1220
  // the arm recurses here -- this case and the optional one above answer
1194
1221
  // exactly the shapes `dynamicTagFor` returns `null` for -- and an arm
@@ -1204,8 +1231,8 @@ const renderedWidenedStoreText = (held, written, text) => {
1204
1231
  return tag === null ? null : boxedText(written, tag, text);
1205
1232
  }
1206
1233
  // A CALLABLE CELL whose held convention differs from the written one only in
1207
- // its RESULT -- `const slot: (n: number) => any = concrete`, and hono's
1208
- // `#addRoute(handler: H)` one union layer up. Asked before the tagged-union
1234
+ // its RESULT -- `const slot: (n: number) => any = concrete`, and a
1235
+ // `register(handler: A | B)` parameter one union layer up. Asked before the tagged-union
1209
1236
  // gate below because a bare callable cell never reaches the arm loop, and
1210
1237
  // `emitBindingWrite` renders a store through this function rather than
1211
1238
  // through `convertedValueText`, so the pair has no other way in.
@@ -1231,7 +1258,7 @@ const renderedWidenedStoreText = (held, written, text) => {
1231
1258
  if (written.kind === 'optional') {
1232
1259
  // An arm that IS this optional, whole. The deref below spends the
1233
1260
  // optional's own absence on the grounds that no arm ever wraps one -- and
1234
- // hono's `compose` disproves that: `let handler` is a `Function | (Next |
1261
+ // a middleware composer disproves that: `let handler` is a `Function | (Next |
1235
1262
  // undefined)` cell whose arms are the record and `optional(callable)`, so
1236
1263
  // writing `next || undefined` into it stores the optional AS the arm.
1237
1264
  // Dereferencing there would drop the absence the arm exists to hold.
@@ -1272,22 +1299,6 @@ const renderedWidenedStoreText = (held, written, text) => {
1272
1299
  const index = held.arms.findIndex((arm) => representationKey(arm.value) === writtenKey);
1273
1300
  if (index >= 0)
1274
1301
  return `${cppTypeOf(held)}::ofArm<${index}>(${text})`;
1275
- // An open Document into the ONE record arm it can be adopted as, beside a
1276
- // `dynamic` arm: mongodb's `decorateDecryptionResult(decrypted: Document & {
1277
- // [kDecoratedKeys]?: string[] })` takes the caller's Document and, through
1278
- // its own recursion, any `decrypted[k]`. The record arm is the Document's
1279
- // home -- adopted, the Document views it, so the symbol-keyed member the
1280
- // body defines is the one a later read through the Document finds -- while
1281
- // boxing it into the `dynamic` arm would leave that member nowhere to live.
1282
- if (isOpenDocument(written)) {
1283
- const adoptions = held.arms.flatMap((arm, armIndex) => {
1284
- const fields = arm.value.kind === 'record' || arm.value.kind === 'record-with-index' ? arm.value.fields : null;
1285
- const adopted = fields === null ? null : documentAdoptionText(written, arm.value, fields, text);
1286
- return adopted === null ? [] : [`${cppTypeOf(held)}::ofArm<${armIndex}>(${adopted})`];
1287
- });
1288
- if (adoptions.length === 1)
1289
- return adoptions[0];
1290
- }
1291
1302
  // A join can nest: `string | number | boolean | null | undefined` derives as
1292
1303
  // an outer union over the two absence arms and an *inner* union over the
1293
1304
  // three value arms, so a written `bool` is an arm of an arm and reaches its
@@ -1308,7 +1319,7 @@ const renderedWidenedStoreText = (held, written, text) => {
1308
1319
  // one of `gea::CallableObject`'s own implicit converting constructors,
1309
1320
  // which take the value as it stands and are what `convertedValueText`
1310
1321
  // already answers with for the identical pair when the target is not a
1311
- // union. hono's `H = Handler | MiddlewareHandler` is the case -- a
1322
+ // union. `H = Handler | MiddlewareHandler` is the case -- a
1312
1323
  // middleware `(c, next) => Promise<void>` is assignable to one arm and the
1313
1324
  // exact-key search above cannot see it, because assignability here is not
1314
1325
  // carrier equality.
@@ -1317,7 +1328,7 @@ const renderedWidenedStoreText = (held, written, text) => {
1317
1328
  // an arm chosen through a LOSSY widening would store something other than
1318
1329
  // what the program wrote, which is the same line the record recasts below
1319
1330
  // stay on.
1320
- if (cppTypeOf(written) === cppTypeOf(arm.value) ||
1331
+ if (samePhysicalCarrier(written, arm.value) ||
1321
1332
  dropsUnboundParameters(written, arm.value) ||
1322
1333
  dropsAllParametersIntoResultArm(written, arm.value) ||
1323
1334
  widensResultIntoArm(written, arm.value) ||
@@ -1335,7 +1346,7 @@ const renderedWidenedStoreText = (held, written, text) => {
1335
1346
  if (view !== null)
1336
1347
  return `${cppTypeOf(held)}::ofArm<${armIndex}>(${view})`;
1337
1348
  // The fifth pair is not an implicit constructor, so it wraps the text
1338
- // rather than passing it through -- see `resultAdapterOf`. hono's `H =
1349
+ // rather than passing it through -- see `resultAdapterOf`. `H =
1339
1350
  // Handler | MiddlewareHandler` reaches its arm exactly here: same frame,
1340
1351
  // a result the arm declares `any`.
1341
1352
  const adaptedArm = resultAdaptedCallableText(written, arm.value, text);
@@ -1343,21 +1354,15 @@ const renderedWidenedStoreText = (held, written, text) => {
1343
1354
  return `${cppTypeOf(held)}::ofArm<${armIndex}>(${adaptedArm})`;
1344
1355
  // A record recasts into a dictionary/array-object ARM the same way
1345
1356
  // `convertedValueText`'s own top level recasts it directly -- identity above never matches an object literal against either.
1346
- // A dictionary reaches a WIDER dictionary arm the same way (`dictionaryCastableToDictionary`);
1347
- // `conversions.ts` admits only a union with ONE such arm, so the first match is the match.
1348
1357
  const recast = written.kind === 'record'
1349
1358
  ? arm.value.kind === 'dictionary'
1350
1359
  ? recastedRecordToDictionaryText(written, arm.value, text)
1351
- : arm.value.kind === 'array-object'
1352
- ? recastedRecordToArrayText(written, arm.value, text)
1353
- : arm.value.kind === 'record'
1354
- ? recastedRecordText(written, arm.value, text)
1355
- : null
1356
- : written.kind === 'dictionary' && arm.value.kind === 'dictionary'
1357
- ? recastedDictionaryText(written, arm.value, text)
1358
- : written.kind === 'record-with-index' && arm.value.kind === 'dictionary'
1359
- ? recastedIndexedRecordToDictionaryText(written, arm.value, text)
1360
- : null;
1360
+ : arm.value.kind === 'record'
1361
+ ? recastedRecordText(written, arm.value, text)
1362
+ : null
1363
+ : written.kind === 'record-with-index' && arm.value.kind === 'dictionary'
1364
+ ? recastedIndexedRecordToDictionaryText(written, arm.value, text)
1365
+ : null;
1361
1366
  if (recast !== null)
1362
1367
  return `${cppTypeOf(held)}::ofArm<${armIndex}>(${recast})`;
1363
1368
  }
@@ -1385,8 +1390,8 @@ const renderedWidenedStoreText = (held, written, text) => {
1385
1390
  * A sum converted ARM BY ARM into one payload, or `null` when an arm has no
1386
1391
  * way there.
1387
1392
  *
1388
- * tsc's `visitEachChild<T>` returns `fn === undefined ? node : fn(node, ...)`
1389
- * where `fn` is a `VisitEachChildFunction<any>`: the conditional merges `T`
1393
+ * A generic visitor `visit<T>` returns `fn === undefined ? node : fn(node, ...)`
1394
+ * where `fn` is a visitor function typed over `any`: the conditional merges `T`
1390
1395
  * with a declared `any` into `tagged-union(native-record-ref | dynamic)`, and
1391
1396
  * the function returns `T | undefined`. The typed arm IS the payload; the
1392
1397
  * dynamic arm is the checked unbox every read of a declared-`any` value into
@@ -1463,15 +1468,15 @@ export const recastedUnionText = (source, target, text,
1463
1468
  // the representation -- `emit-callable.ts`'s `structuralRecordViewText` is
1464
1469
  // where both are in hand. `conversions.ts` already ADMITS that pair, so
1465
1470
  // without this the admission and the render disagree, which is the one
1466
- // failure mode this compiler exists to remove: hono's `c.json()` passes
1467
- // `ResponseOrInit<ContentfulStatusCode>` into `ResponseOrInit<StatusCode>`
1471
+ // failure mode this compiler exists to remove: a generic alias instantiated
1472
+ // at a narrower argument (`Init<Narrow>`) passed into `Init<Wide>`
1468
1473
  // -- two shape ids over identical field carriers -- and the arm had no home
1469
1474
  // here even though the conversion graph said it did.
1470
1475
  viaLayout) => {
1471
1476
  // A union with N arms otherwise interpolates BOTH the full target spelling
1472
1477
  // and the source expression at every arm -- and a nested inner-union arm
1473
- // repeats that again inside every outer arm. The three.js app's `NativeUniformValue
1474
- // | null | undefined` is a 3-arm outer union over a 32-arm inner one, and
1478
+ // repeats that again inside every outer arm. A `Value | null | undefined`
1479
+ // whose `Value` is itself a 32-arm union is a 3-arm outer union over a 32-arm inner one, and
1475
1480
  // one recast of it -- reached from several sibling call sites glued by the
1476
1481
  // caller's own `&&`/`||` -- emitted a single line over 1.29MB: 957
1477
1482
  // `::ofArm<` sites each re-spelling a ~1.3KB template type, because neither
@@ -1511,10 +1516,17 @@ viaLayout) => {
1511
1516
  }
1512
1517
  const homes = [];
1513
1518
  for (const [candidateIndex, candidate] of target.arms.entries()) {
1519
+ // An absence arm is never the home of a live value: the chain's
1520
+ // `unreachable-value` step would answer it by DISCARDING the value
1521
+ // (correct only for a flow-proved `undefined` read), and as the first
1522
+ // home found it silently turned every such arm into `undefined`.
1523
+ const absence = candidate.value.kind === 'undefined' || candidate.value.kind === 'null' || candidate.value.kind === 'void';
1524
+ if (absence && candidate.value.kind !== arm.value.kind)
1525
+ continue;
1514
1526
  // `convertedValueText` and not `widenedStoreText` alone: an arm can
1515
1527
  // reach its home by a recast rather than a widening -- two records that
1516
- // declare the same fields under two interned shapes, which is what
1517
- // hono's `Result<T>` is made of -- and only the superset tries all of
1528
+ // declare the same fields under two interned shapes, which is what a
1529
+ // generic result alias instantiated twice is made of -- and only the superset tries all of
1518
1530
  // them.
1519
1531
  const stored = tryCandidateText(() => convertedValueText(arm.value, candidate.value, armText));
1520
1532
  const home = stored ?? viaLayout?.(arm.value, candidate.value, armText) ?? null;
@@ -1606,8 +1618,8 @@ export const recastedUnionFromHomes = (source, target, text, homes) => {
1606
1618
  * The relation admitted is TypeScript's own structural one, not shape equality,
1607
1619
  * because that equality was never the question a return conversion asks.
1608
1620
  * `return this.options` out of a method declared to return a narrower options
1609
- * type is legal TypeScript and lowers to exactly this pair, and mongodb's
1610
- * driver is built out of it: every `CommandOptions` producer hands a record
1621
+ * type is legal TypeScript and lowers to exactly this pair, and options-heavy
1622
+ * programs are built out of it: every options producer hands a record
1611
1623
  * carrying dozens of fields to a slot declaring an overlapping, differently
1612
1624
  * ordered, differently optional subset. So:
1613
1625
  *
@@ -1632,8 +1644,8 @@ export const recastedUnionFromHomes = (source, target, text, homes) => {
1632
1644
  * performs it, and two optionals over one payload are one C++ type since
1633
1645
  * `cppTypeOf` never reads `.absence`), or by being the same recast one level
1634
1646
  * down. The nominal-identity split this exists for does not stop at the top:
1635
- * hono's pattern router hands `[Pattern, string, [Handler, ParamIndexMap]]` to
1636
- * a `Route<T>` slot whose innermost tuple interned under a second shape id with
1647
+ * a nested tuple like `[Pattern, string, [Handler, ParamIndexMap]]` handed to
1648
+ * a generic `Route<T>` slot whose innermost tuple interned under a second shape id with
1637
1649
  * a byte-identical field list, so the OUTER pair matched everywhere but there.
1638
1650
  * Refusing would refuse the identical question one level in.
1639
1651
  *
@@ -1647,7 +1659,7 @@ const absentFieldText = (value) => {
1647
1659
  // Remembered per carrier: an unspellable carrier answers by CATCHING a
1648
1660
  // thrown refusal, and the recast admission below asks about the same
1649
1661
  // absent target field once per candidate source -- thousands of throws
1650
- // for one field on TypeScript's own compiler.
1662
+ // for one field on a large program.
1651
1663
  const remembered = absentFieldTexts.get(value);
1652
1664
  if (remembered !== undefined)
1653
1665
  return remembered;
@@ -1660,7 +1672,7 @@ const absentFieldTextOf = (value) => {
1660
1672
  // absent AS, so the field is not recastable -- a refusal, not a throw. This
1661
1673
  // is asked from the conversion registry's ADMISSION (`conversions.ts`'s
1662
1674
  // `recasting`), whose own `cppTypeOf(target)` guard spells the record by
1663
- // shape id and never looks inside it: TypeScript's own compiler put an
1675
+ // shape id and never looks inside it: a large program put an
1664
1676
  // `optional(function(...))` whose ABI still carried an unmonomorphized type
1665
1677
  // parameter in a field here, and the throw took the whole compile down
1666
1678
  // instead of costing this one pair. Same idiom as `manifest.ts`'s
@@ -1734,10 +1746,9 @@ const recastableFieldValue = (from, to, seen) => {
1734
1746
  // same admission the bare tagged-union branch below makes, one presence
1735
1747
  // flag deeper -- and the same render, `recastFieldText`'s optional branch
1736
1748
  // already descends into its payload before spelling the arm. Without it
1737
- // tsc's `return evaluatorResult(0)` -- the copy `EvaluatorResult<number>`
1738
- // with `value: number`, returned where `EvaluatorResult` (default `T`,
1739
- // `value: string | number | undefined`) is declared -- had the renderer
1740
- // but not the admission: 19 rows across `checker.ts` and `utilities.ts`.
1749
+ // `return result(0)` -- the copy `Result<number>` with `value: number`,
1750
+ // returned where `Result` (default `T`, `value: string | number |
1751
+ // undefined`) is declared -- had the renderer but not the admission.
1741
1752
  if (to.payload.kind === 'tagged-union' && soleArmIndexFor(to.payload, fromPayload) !== null)
1742
1753
  return true;
1743
1754
  // A structural conversion does not stop at a presence flag. A required
@@ -1760,7 +1771,7 @@ const recastableFieldValue = (from, to, seen) => {
1760
1771
  if (from.kind === 'function-value-dispatch' && to.kind === 'function-value-dispatch')
1761
1772
  return !containsUnresolved(from) && !containsUnresolved(to) && resultAdapterOf(from, to) !== null;
1762
1773
  // Containers copy element by element (`array-copy-recast`,
1763
- // `dictionary-to-dictionary`), so a field holding one recasts when its
1774
+ // `record-to-dictionary`), so a field holding one recasts when its
1764
1775
  // elements convert.
1765
1776
  // A dynamic field is read out of its box the way any assertion reads one.
1766
1777
  if ((from.kind === 'array-object' && to.kind === 'array-object') ||
@@ -1795,7 +1806,7 @@ const recordRecastAnswers = new WeakMap();
1795
1806
  *
1796
1807
  * The guard's key and set exist only once a descent happens. The conversion
1797
1808
  * registry asks this about every ordered pair of record carriers a program
1798
- * has (`conversion/build.ts`), and TypeScript's own compiler has enough of
1809
+ * has (`conversion/build.ts`), and a large program has enough of
1799
1810
  * them, with enough fields each, that a key string, a fresh set and a linear
1800
1811
  * field scan per target field, per pair, WAS the representations stage (the
1801
1812
  * main thread sat at 100% for an hour past the previous run's total). Fields
@@ -1987,8 +1998,8 @@ const recastedRecordText = (source, target, text, depth = 0) => {
1987
1998
  // and makes a required bit a `static` member only when the program never
1988
1999
  // deletes/freezes a declared field -- so a positional list that skips the
1989
2000
  // required bits lands each optional bit on a REQUIRED one whenever that
1990
- // census says no. mongodb's `TimeoutContext.create` then saw
1991
- // `'serverSelectionTimeoutMS' in options` answer false. Left alone, every
2001
+ // census says no. An `'optionalKey' in options` check then answered
2002
+ // false for a key the program had set. Left alone, every
1992
2003
  // bit keeps its declared default (required present, optional absent).
1993
2004
  const target_ = target.ownership === 'shared-refcount' ? '->' : '.';
1994
2005
  const presences = target.fields.flatMap((field) => {
@@ -2092,7 +2103,7 @@ const recastedRecordToDictionaryText = (source, target, text, sourceType = cppTy
2092
2103
  return null;
2093
2104
  const insert = `gea_dict${dictArrow}operator[](${key}) = ${converted};`;
2094
2105
  // An optional field never written is no own property, and the dictionary
2095
- // must not gain the key: a BSON document would serialize it as `null`.
2106
+ // must not gain the key: a serializer walking it would write it as `null`.
2096
2107
  return field.required ? insert : `if (gea_from${fieldArrow}${cppRecordFieldPresenceName(field.key)}) ${insert}`;
2097
2108
  });
2098
2109
  if (inserts.some((insert) => insert === null))
@@ -2106,7 +2117,7 @@ const recastedRecordToDictionaryText = (source, target, text, sourceType = cppTy
2106
2117
  };
2107
2118
  /**
2108
2119
  * A record with an open string index poured into an open string dictionary:
2109
- * mongodb's `Filter<TSchema>` -- named query operators plus
2120
+ * a generic query type -- named operator fields plus
2110
2121
  * `[key: string]: any` -- handed to a `filter: Document` parameter. The named
2111
2122
  * fields go in as `recastedRecordToDictionaryText` puts them, and every
2112
2123
  * enumerable entry of the index sidecar after them, converted into the
@@ -2144,8 +2155,8 @@ export const recastedIndexedRecordToDictionaryText = (source, target, text, sour
2144
2155
  *
2145
2156
  * The static copy lists the named fields before the index entries, which is
2146
2157
  * the record's own order only until it has a key outside its layout -- a
2147
- * command document gains its options that way, and a BSON command's first key
2148
- * has to stay the command's name. The runtime then knows the order
2158
+ * command document gains its options that way, and a serialized command whose
2159
+ * first key is its name has to keep that key first. The runtime then knows the order
2149
2160
  * (`gea::copyOwnPropertiesInCreationOrder`); each value it hands over is a
2150
2161
  * property read through the record's own protocol, converted into the
2151
2162
  * dictionary's carrier.
@@ -2164,8 +2175,8 @@ const creationOrderedDictionaryCopyText = (source, target) => {
2164
2175
  };
2165
2176
  /**
2166
2177
  * The indexed record a carrier holds: itself, or the layout a named interface
2167
- * resolves to when that layout declares an index -- mongodb's `WithoutId<TSchema>`
2168
- * is a name. A named layout with NO index is the plain record recast's.
2178
+ * resolves to when that layout declares an index -- a mapped alias like
2179
+ * `WithoutId<TSchema>` is a name. A named layout with NO index is the plain record recast's.
2169
2180
  */
2170
2181
  export const indexedRecordViewOf = (source, layouts) => {
2171
2182
  if (source.kind === 'record-with-index')
@@ -2173,7 +2184,7 @@ export const indexedRecordViewOf = (source, layouts) => {
2173
2184
  if (source.kind !== 'native-record-ref' || source.native !== null || source.recursive)
2174
2185
  return null;
2175
2186
  const fields = layouts.forShape(source.shapeId);
2176
- const indexes = layouts.indexesForShape?.(source.shapeId) ?? [];
2187
+ const indexes = layouts.indexesForShape(source.shapeId);
2177
2188
  if (fields === null || indexes.length === 0)
2178
2189
  return null;
2179
2190
  return { kind: 'record-with-index', shapeId: source.shapeId, fields, indexes, ownership: source.ownership };
@@ -2187,67 +2198,14 @@ export const indexedRecordDictionaryArmOf = (source, target) => {
2187
2198
  const homes = target.arms.flatMap((arm, index) => arm.value.kind === 'dictionary' && indexedRecordCastableToDictionary(source, arm.value) ? [index] : []);
2188
2199
  return homes.length === 1 ? homes[0] : null;
2189
2200
  };
2190
- /**
2191
- * An open dictionary recast into another open dictionary over the same key
2192
- * domain whose VALUES it widens into -- `Record<string, string>` reaching a
2193
- * slot declared `OutgoingHttpHeaders` (`{ [name: string]: string | number |
2194
- * boolean | readonly string[] | undefined }`). TypeScript's `||` typing
2195
- * subtype-reduces the two into the wider one, so `@hono/node-server`'s `get
2196
- * headers()` -- `cache[2] || { 'content-type': defaultContentType }` where
2197
- * the slot is `Record<string, string> | [string, string][] |
2198
- * OutgoingHttpHeaders | undefined` -- publishes ONLY the wider dictionary as
2199
- * the merge's arm, and both the literal and the slot's own string-dictionary
2200
- * arm have to reach it. Nothing between the two carriers is a view: a
2201
- * `gea::Dictionary<std::string>` and a `gea::Dictionary<gea::Optional<...>>`
2202
- * are two template instantiations.
2203
- *
2204
- * One level out from `recordCastableToDictionary` above and admitted on the
2205
- * same terms: every value the source holds converts into the target's value
2206
- * carrier by the store it would have performed had the entry been written
2207
- * against the wider index signature in the first place, and the rebuild is a
2208
- * fresh table -- the same fresh table the record pour builds, with the same
2209
- * consequence, that a program which keeps writing the SOURCE afterwards and
2210
- * reads the widened copy does not see the write. The record pour already
2211
- * stands on that ground for the identical pair one shape narrower; this does
2212
- * not extend it further.
2213
- *
2214
- * String keys only. `gea::NumericDictionary` and `gea::SymbolDictionary` are
2215
- * different containers with their own iteration, and nothing has asked for
2216
- * them; a pair over either refuses by name rather than guessing a spelling.
2217
- */
2218
- export const dictionaryCastableToDictionary = (source, target) => {
2219
- // A number-keyed table is the same store under canonical numeric keys
2220
- // (`gea::NumericDictionary`), so it recasts into another number-keyed one
2221
- // exactly as a string-keyed table does: mongodb's `insertMany` returns the
2222
- // bulk result's `{ [key: number]: any }` id map as `InsertManyResult`'s
2223
- // `{ [key: number]: InferIdType<TSchema> }`.
2224
- if (source.key !== target.key || (source.key !== 'string' && source.key !== 'number'))
2225
- return false;
2226
- if (representationKey(source.value) === representationKey(target.value))
2227
- return false;
2228
- if (containsUnresolved(source) || containsUnresolved(target))
2229
- return false;
2230
- try {
2231
- return convertedValueText(source.value, target.value, 'gea_entry_value') !== null;
2232
- }
2233
- catch (error) {
2234
- // Queried while the conversion graph is being built, exactly as
2235
- // `recordCastableToDictionary` is: a nested recipe's named refusal means
2236
- // the value pair does not convert, not that graph construction failed.
2237
- if (isCppEmitBlockedError(error))
2238
- return false;
2239
- throw error;
2240
- }
2241
- };
2242
2201
  /**
2243
2202
  * A class instance handed where an open `{ [key: string]: any }` document is
2244
2203
  * declared, as a live VIEW of the instance (`gea::dictionary::aliasOf`): the
2245
2204
  * same object, read and written through its own property protocol.
2246
2205
  *
2247
- * Not a copy. mongodb's `RenameOperation.handleOk(): Document` returns a
2248
- * `Collection` its caller goes on to use as the collection, and
2249
- * `ClientBulkWriteResultsMerger` reads `document.insertedCount` -- a
2250
- * PROTOTYPE getter -- off a response class. A table of the instance's own
2206
+ * Not a copy. A method declared `(): Document` may return a class instance
2207
+ * its caller goes on to use as that class, and a consumer may read
2208
+ * `document.someCount` -- a PROTOTYPE getter -- off a response class. A table of the instance's own
2251
2209
  * fields answers neither, and loses every write made through either name
2252
2210
  * afterwards; the view answers all of it because it is the object. Only the
2253
2211
  * one dictionary whose values are already `any` can view: every value read
@@ -2256,71 +2214,65 @@ export const dictionaryCastableToDictionary = (source, target) => {
2256
2214
  */
2257
2215
  /**
2258
2216
  * Whether an open `any` Document can view `source` as the very object it is.
2259
- * A union of such objects is viewable too -- mongodb's `{ message; code } |
2260
- * WriteConcernError | AnyError` into `ErrorDescription` -- because its box
2217
+ * A union of such objects is viewable too -- `{ message; code } |
2218
+ * SomeError | OtherError` into an open description record -- because its box
2261
2219
  * names whichever arm is live; so is the intrinsic Error.
2262
2220
  */
2263
2221
  export const documentViewable = (source) => {
2222
+ // A `dynamic` arm beside them is the rest of the same declared Document --
2223
+ // already a box, so the view (`aliasOf(const Value&)`) boxes nothing typed.
2264
2224
  if (source.kind === 'tagged-union')
2265
- return source.arms.every((arm) => isOpenDocument(arm.value) || documentViewable(arm.value));
2225
+ return source.arms.every((arm) => arm.value.kind === 'dynamic' || isOpenDocument(arm.value) || documentViewable(arm.value));
2266
2226
  const viewable = source.kind === 'class-ref' ||
2267
2227
  source.kind === 'record' ||
2268
2228
  source.kind === 'record-with-index' ||
2269
2229
  (source.kind === 'native-record-ref' && !source.recursive) ||
2270
- // An Array or a Map is an object as well: bson's serializer and
2271
- // `calculate_size.ts` hold every nested value -- plain, array or Map -- in
2272
- // one `Document` frame field, then walk it by what it turned out to be.
2230
+ // An Array or a Map is an object as well: a recursive document serializer
2231
+ // holds every nested value -- plain, array or Map -- in one `Document`
2232
+ // frame field, then walks it by what it turned out to be.
2273
2233
  source.kind === 'array-object' ||
2274
2234
  (source.kind === 'keyed-collection' && source.family === 'map');
2275
2235
  return viewable && source.ownership === 'shared-refcount';
2276
2236
  };
2277
2237
  export const classDocumentViewText = (source, target, text) => {
2278
- // A shared record a copy could not be made of views the same way: mongodb's
2279
- // `session.clusterTime` (`ClusterTime`) handed to a `Document | null` slot.
2238
+ // A shared record a copy could not be made of views the same way: a
2239
+ // named interface-typed field handed to a `Document | null` slot.
2280
2240
  // A record a Document adopted (`gea::dictionary::adopt`) is that Document.
2281
2241
  if (!isOpenDocument(target) || !documentViewable(source))
2282
2242
  return null;
2283
- const boxed = dynamicCarrierBoxText(source, text);
2284
- return boxed === null ? null : `gea::dictionary::aliasOf(${boxed})`;
2285
- };
2286
- /**
2287
- * An open `any` Document read as a shared typed record: the record the
2288
- * Document's entries are checked into, after which the Document views it
2289
- * (`gea::dictionary::adopt`). A copy would give one JavaScript object two
2290
- * identities -- a write through the typed name would never reach the Document.
2291
- * A required symbol-keyed field cannot be in a string-keyed Document, so it
2292
- * refuses here rather than at run time.
2293
- */
2294
- export const documentAdoptionText = (source, target, fields, text) => {
2295
- if (!isOpenDocument(source))
2296
- return null;
2297
- if (target.kind !== 'record' && target.kind !== 'record-with-index' && target.kind !== 'native-record-ref')
2298
- return null;
2299
- if (target.ownership !== 'shared-refcount')
2300
- return null;
2301
- if (fields.some((field) => field.required && cppRecordFieldKeyIsSymbol(field.key)))
2302
- return null;
2303
- const keys = (required) => fields
2304
- .filter((field) => field.required === required && !cppRecordFieldKeyIsSymbol(field.key))
2305
- .map((field) => cppStringLiteral(field.key))
2306
- .join(', ');
2307
- return (`gea::dictionary::adopt<${cppRecordStructName(target.shapeId)}>(` +
2308
- `${text}, {${keys(true)}}, {${keys(false)}}, ${cppStringLiteral(assertionSite(target))})`);
2243
+ if (source.kind === 'tagged-union') {
2244
+ const entries = source.arms.map((arm, index) => {
2245
+ const value = `gea_source.template get<${index}>()`;
2246
+ if (arm.value.kind === 'dynamic')
2247
+ return `gea::dictionary::aliasOf(${value})`;
2248
+ return isOpenDocument(arm.value) ? value : classDocumentViewText(arm.value, target, value);
2249
+ });
2250
+ if (entries.some((entry) => entry === null))
2251
+ return null;
2252
+ const tail = entries[entries.length - 1];
2253
+ if (tail === undefined)
2254
+ return null;
2255
+ const selected = entries
2256
+ .slice(0, -1)
2257
+ .reduceRight((next, entry, index) => `gea_source.template is<${index}>() ? ${entry} : (${next})`, tail);
2258
+ return `[](const ${cppTypeOf(source)}& gea_source) -> ${cppTypeOf(target)} { return ${selected}; }(${text})`;
2259
+ }
2260
+ return `gea::dictionary::aliasOf(${text})`;
2309
2261
  };
2310
2262
  /**
2311
2263
  * An open `any` Document read as a class instance or a byte view: only the
2312
2264
  * object the Document views (`gea::dictionary::aliasOf`) can be one, so the
2313
2265
  * read is that object's checked unbox, and a Document holding its own entries
2314
- * refuses. mongodb reaches it under `Buffer.isBuffer(options.schemaMap)`.
2266
+ * refuses. A `Buffer.isBuffer(options.someDocument)` guard reaches it.
2315
2267
  */
2316
2268
  const documentViewedObjectText = (source, target, text) => {
2317
- // `options.schemaMap?: Document` is optional; the guard that narrows it to a
2269
+ // `options.someDocument?: Document` is optional; the guard that narrows it to a
2318
2270
  // Buffer has already proved it present, and an absent one refuses like any
2319
2271
  // other value that is not a Buffer.
2320
2272
  const optional = source.kind === 'optional' && isOpenDocument(source.payload);
2321
2273
  if (!optional && !isOpenDocument(source))
2322
2274
  return null;
2323
- // bson reads a frame's `Document` back `as unknown[]` under
2275
+ // A document serializer reads a frame's `Document` back `as unknown[]` under
2324
2276
  // `Array.isArray`, and `as Map<string, unknown>` under `instanceof Map`.
2325
2277
  const viewable = target.kind === 'typed-array' ||
2326
2278
  target.kind === 'class-ref' ||
@@ -2328,25 +2280,26 @@ const documentViewedObjectText = (source, target, text) => {
2328
2280
  (target.kind === 'keyed-collection' && target.family === 'map');
2329
2281
  if (!viewable)
2330
2282
  return null;
2331
- const viewed = 'gea_viewed';
2332
- const load = unboxedLoadText(target, viewed);
2333
- if (load === null)
2334
- return null;
2335
- const object = optional
2336
- ? `gea_document.has_value() ? gea::dictionary::aliasedObject(*gea_document) : gea::Value()`
2337
- : 'gea::dictionary::aliasedObject(gea_document)';
2283
+ const object = optional ? '*gea_document' : 'gea_document';
2284
+ const method = target.kind === 'keyed-collection' && target.family === 'map' && target.key.kind === 'dynamic' && target.value?.kind === 'dynamic'
2285
+ ? 'gea::dictionary::viewedDynamicMap'
2286
+ : `gea::dictionary::viewedObjectAs<${cppTypeOf(target)}>`;
2287
+ const load = `${method}(${object}, ${cppStringLiteral(assertionSite(target))})`;
2338
2288
  return (`[](const ${cppTypeOf(source)}& gea_document) -> ${cppTypeOf(target)} { ` +
2339
- `const gea::Value ${viewed} = ${object}; return ${load}; }(${text})`);
2289
+ (optional
2290
+ ? `if (!gea_document.has_value()) return ${cppTypeOf(target)}${source.kind === 'optional' && source.absence === 'undefined' ? '::undefined()' : '()'}; `
2291
+ : '') +
2292
+ `return ${load}; }(${text})`);
2340
2293
  };
2341
2294
  const dictionaryToRecordText = (source, target, text) => {
2342
2295
  if (source.kind !== 'dictionary' || source.key !== 'string' || source.value.kind !== 'dynamic' || source.ownership !== 'shared-refcount')
2343
2296
  return null;
2344
2297
  if (target.kind === 'record-with-index')
2345
- return documentAdoptionText(source, target, target.fields, text);
2298
+ return null;
2346
2299
  if (target.kind !== 'record' || target.accessors.length !== 0 || target.ownership === 'borrowed')
2347
2300
  return null;
2348
2301
  if (target.ownership === 'shared-refcount')
2349
- return documentAdoptionText(source, target, target.fields, text);
2302
+ return null;
2350
2303
  const boxed = dynamicCarrierBoxText(source, text);
2351
2304
  return boxed === null ? null : unboxedLoadText(target, boxed);
2352
2305
  };
@@ -2407,23 +2360,6 @@ export const dynamicDictionaryToNamedRecordAdmitted = (source, target, fields, i
2407
2360
  (!containsUnresolved(field.value) &&
2408
2361
  withoutUnitFunctions(() => tryCandidateText(() => unboxedLoadText(field.value, 'gea_value'))) !== null));
2409
2362
  };
2410
- const recastedDictionaryText = (source, target, text) => {
2411
- if (!dictionaryCastableToDictionary(source, target))
2412
- return null;
2413
- const converted = convertedValueText(source.value, target.value, 'gea_entry.second');
2414
- if (converted === null)
2415
- return null;
2416
- const storage = `gea::${target.key === 'number' ? 'NumericDictionary' : 'Dictionary'}<${cppTypeOf(target.value)}>`;
2417
- const construct = target.ownership === 'shared-refcount' ? `auto gea_dict = gea::makeRef<${storage}>();` : `${storage} gea_dict{};`;
2418
- const dictArrow = target.ownership === 'shared-refcount' ? '->' : '.';
2419
- // `gea::Dictionary`'s own `const_iterator` walks entries in creation order,
2420
- // which is the order the language enumerates them in and the order the copy
2421
- // must therefore insert them in.
2422
- const range = source.ownership === 'shared-refcount' ? '*gea_from' : 'gea_from';
2423
- return (`[](const ${cppTypeOf(source)}& gea_from) { ${construct} ` +
2424
- `for (const auto& gea_entry : ${range}) { gea_dict${dictArrow}operator[](gea_entry.first) = ${converted}; } ` +
2425
- `return gea_dict; }(${text})`);
2426
- };
2427
2363
  /**
2428
2364
  * The text a `convert` renders to, or `null` when nothing installed performs it.
2429
2365
  *
@@ -2503,7 +2439,7 @@ const callablePartText = (source, target, text) => {
2503
2439
  * field is refused for the same reason -- its absence is a presence flag the
2504
2440
  * caller must read, not a value.
2505
2441
  *
2506
- * `@hono/node-server`'s `RequestHeaders.forEach` is the measured case: it
2442
+ * A headers class's `forEach` is the measured case: it
2507
2443
  * forwards to the caller's `(value, key, parent) => void` through
2508
2444
  * `callback.call(thisArg, value, key, this)`.
2509
2445
  */
@@ -2513,7 +2449,7 @@ const restTupleFieldActual = (slot, restOrdinal, position, parameter) => {
2513
2449
  return null;
2514
2450
  const arrow = slot.ownership === 'shared-refcount' ? '->' : '.';
2515
2451
  const access = `${adapterFormalName(restOrdinal)}${arrow}${cppRecordFieldName(field.key)}`;
2516
- if (cppTypeOf(field.value) === cppTypeOf(parameter.value))
2452
+ if (samePhysicalCarrier(field.value, parameter.value))
2517
2453
  return access;
2518
2454
  try {
2519
2455
  return convertedValueText(field.value, parameter.value, access);
@@ -2543,8 +2479,8 @@ const restElementActual = (to, restOrdinal, position, parameter) => {
2543
2479
  const rest = adapterFormalName(restOrdinal);
2544
2480
  const elementType = cppTypeOf(element);
2545
2481
  const access = `(${rest}.get() == nullptr || ${rest}->size() <= static_cast<std::size_t>(${position}) ` +
2546
- `? ${elementType}() : ${rest}->at(${position}))`;
2547
- if (elementType === cppTypeOf(parameter.value))
2482
+ `? ${elementType}() : ${rest}->readElement(${position}))`;
2483
+ if (samePhysicalCarrier(element, parameter.value))
2548
2484
  return access;
2549
2485
  try {
2550
2486
  return convertedValueText(element, parameter.value, access);
@@ -2597,7 +2533,7 @@ export const boxedAssertionText = (source, target, text) => {
2597
2533
  *
2598
2534
  * Anything else is a box no arm reads back: the dispatch's final
2599
2535
  * `refusePayloadMismatch` is the only path it has, so every value, however
2600
- * well it satisfies the union's TypeScript type, aborts at run time. mongodb's
2536
+ * well it satisfies the union's TypeScript type, aborts at run time. A
2601
2537
  * named `[key: string]: any` interface handed to `Document | Document[]` was
2602
2538
  * the measured case, before its own recast existed. Refusing here turns that
2603
2539
  * certain abort into the missing-conversion row certify names.
@@ -2682,7 +2618,7 @@ const recastUnionAliasName = 'GeaRecastArm';
2682
2618
  * in `gea_runtime.h` is precisely the two-authorities defect this compiler
2683
2619
  * exists to avoid.
2684
2620
  *
2685
- * hono's `H = Handler | MiddlewareHandler` is the case that needs it:
2621
+ * A handler union `H = Handler | MiddlewareHandler` is the case that needs it:
2686
2622
  * `Handler<E, P, I, R = any>` defaults its result parameter to `any`, so both
2687
2623
  * arms take `(Context, Next)` and return `any`/`Promise<any>` while every
2688
2624
  * handler a program writes returns something concrete. Same frame, boxed
@@ -2719,14 +2655,16 @@ const resultAdapterOf = (source, target, viaView) => {
2719
2655
  const to = callableObjectAbi(target);
2720
2656
  if (!from || !to)
2721
2657
  return null;
2658
+ if (from.argumentsFrame !== to.argumentsFrame && !(from.restFrom === 0 && to.restFrom === 0))
2659
+ return null;
2722
2660
  if (from.receiver !== null && to.receiver === null)
2723
2661
  return null;
2724
2662
  const ignoresReceiver = from.receiver === null && to.receiver !== null;
2725
2663
  // A fixed-arity source filling a slot whose trailing frame is ONE rest array:
2726
2664
  // `(...args: any[]) => void`, JavaScript's "some function, arguments not my
2727
- // business" idiom. tsc's whole `Debug` family passes itself through it --
2728
- // `assertIsDefined(value, message, stackCrawlMark || checkDefined)` -- and
2729
- // every such argument refused to lower, 265 rows in `debug.ts` alone, because
2665
+ // business" idiom. A family of assertion helpers passes itself through it --
2666
+ // `assertDefined(value, message, mark || checkDefined)` -- and every such
2667
+ // argument refused to lower, hundreds of rows in one module, because
2730
2668
  // the rest placements did not match. They do not have to: the language
2731
2669
  // defines the call exactly, the slot binds one Array and the source reads its
2732
2670
  // own parameters positionally out of it. The rest ELEMENT is what makes this
@@ -2751,9 +2689,9 @@ const resultAdapterOf = (source, target, viaView) => {
2751
2689
  // So the refusal is not "the source frame is wider" but "a source formal
2752
2690
  // past the slot's frame cannot hold the absence", which `cppUndefinedIn`
2753
2691
  // (the one authority `paddedArguments` already asks at a direct call that
2754
- // omits a trailing argument) answers. hono's `utils/url.ts` is the measured
2755
- // case: `export const getQueryParam: (url, key?) => ... = _getQueryParam as
2756
- // (...)`, where `_getQueryParam` declares a third `multiple?: boolean`; the
2692
+ // omits a trailing argument) answers. The measured case is
2693
+ // `export const getParam: (url, key?) => ... = _getParam as
2694
+ // (...)`, where `_getParam` declares a third `multiple?: boolean`; the
2757
2695
  // slot is the only contract any caller has, so the third formal is
2758
2696
  // `Optional<bool>()` at every one of them.
2759
2697
  //
@@ -2785,7 +2723,7 @@ const resultAdapterOf = (source, target, viaView) => {
2785
2723
  let receiverActual = null;
2786
2724
  if (from.receiver !== null && to.receiver !== null) {
2787
2725
  const narrowedReceiver = receiverDowncastText(to.receiver, from.receiver, adapterReceiverName);
2788
- if (cppTypeOf(from.receiver) === cppTypeOf(to.receiver)) {
2726
+ if (samePhysicalCarrier(from.receiver, to.receiver)) {
2789
2727
  receiverActual = adapterReceiverName;
2790
2728
  }
2791
2729
  else if (narrowedReceiver !== null) {
@@ -2861,13 +2799,13 @@ const resultAdapterOf = (source, target, viaView) => {
2861
2799
  if (convertedResult === null)
2862
2800
  return null;
2863
2801
  }
2864
- else if (cppTypeOf(from.result) === cppTypeOf(to.result)) {
2802
+ else if (samePhysicalCarrier(from.result, to.result)) {
2865
2803
  convertedResult = adapterResultName;
2866
2804
  }
2867
2805
  else if (from.overloadJoined === true &&
2868
2806
  from.result.kind === 'optional' &&
2869
2807
  to.result.kind !== 'optional' &&
2870
- cppTypeOf(from.result.payload) === cppTypeOf(to.result)) {
2808
+ samePhysicalCarrier(from.result.payload, to.result)) {
2871
2809
  // A call naming one overload of a callback-joined set
2872
2810
  // (`host-abi.ts`'s `callbackOverloadJoinedAbi`): that overload answers
2873
2811
  // the value, so the joined frame's `undefined` is the OTHER overload's
@@ -2892,18 +2830,18 @@ const resultAdapterOf = (source, target, viaView) => {
2892
2830
  const nativeReceiverTransport = from.receiver !== null && to.receiver !== null && classRefTransportKind(to.receiver, from.receiver) !== null;
2893
2831
  const ignoresParameters = from.parameters.length < to.parameters.length;
2894
2832
  const parametersChange = actuals.some((actual, ordinal) => actual !== adapterFormalName(ordinal));
2895
- const resultChanges = from.result.kind !== to.result.kind || (from.result.kind !== 'void' && cppTypeOf(from.result) !== cppTypeOf(to.result));
2833
+ const resultChanges = from.result.kind !== to.result.kind || (from.result.kind !== 'void' && !samePhysicalCarrier(from.result, to.result));
2896
2834
  // A source whose fixed frame ends before the slot's rest reads no element
2897
2835
  // of that Array: nothing is unboxed and the Array itself is never passed.
2898
- // mongodb hands `() => new Topology(...)`-shaped thunks to `(...args: any[])
2899
- // => void` slots; counting that as a spread made the census publish the
2836
+ // A program handing `() => new SomeClass(...)`-shaped thunks to `(...args: any[])
2837
+ // => void` slots is the case; counting that as a spread made the census publish the
2900
2838
  // thunk's result class, and everything it reaches, to full reflection.
2901
2839
  const spreadsRest = restSpread && to.restFrom !== null && from.parameters.length > to.restFrom;
2902
2840
  const nativeFieldProtocolUnused = !spreadsRest &&
2903
2841
  !restPack &&
2904
2842
  (!receiverChanges || nativeReceiverTransport) &&
2905
2843
  !parametersChange &&
2906
- (from.result.kind === 'void' || to.result.kind === 'void' || cppTypeOf(from.result) === cppTypeOf(to.result));
2844
+ (from.result.kind === 'void' || to.result.kind === 'void' || samePhysicalCarrier(from.result, to.result));
2907
2845
  return ignoresReceiver || ignoresParameters || receiverChanges || parametersChange || resultChanges
2908
2846
  ? { from, to, receiverActual, actuals, convertedResult, nativeFieldProtocolUnused }
2909
2847
  : null;
@@ -2914,8 +2852,8 @@ const resultAdapterOf = (source, target, viaView) => {
2914
2852
  *
2915
2853
  * The checker admits a callable into such a slot only through an assertion:
2916
2854
  * a function's result must be assignable to its slot's, so the pair exists
2917
- * because the program wrote `f as (...) => Narrower`. hono's `utils/url.ts`
2918
- * is the measured case -- `_getQueryParam`'s `string | undefined |
2855
+ * because the program wrote `f as (...) => Narrower`. The measured case
2856
+ * is a helper whose `string | undefined |
2919
2857
  * Record<string, string> | string[] | Record<string, string[]>` asserted to
2920
2858
  * `string | undefined | Record<string, string>`, the two array arms reachable
2921
2859
  * only through the third parameter the slot omits. The assertion is checked
@@ -2942,8 +2880,8 @@ const assertedResultNarrowingText = (from, to, text) => {
2942
2880
  * A callable whose `this` is a descendant class (or the copies of a split
2943
2881
  * generic class, `derive.ts`'s `anyCopyFamilyOf`) filling a slot whose
2944
2882
  * receiver is an ancestor: node's `EventEmitter` calls every listener with
2945
- * `fn.apply(this, args)`, and the MongoDB driver registers `function
2946
- * removeActiveCursor(this: AbstractCursor)` on its own cursors. The function
2883
+ * `fn.apply(this, args)`, and a program may register `function
2884
+ * onClose(this: BaseClass)` on instances of its own subclasses. The function
2947
2885
  * only ever runs against the object that emitted, so the receiver narrows to
2948
2886
  * the arm whose class the allocation extends -- most specific arm first, read
2949
2887
  * off the allocation's own `classBase` chain, which is emitted only from
@@ -2987,8 +2925,8 @@ export const resultAdapterTransportOf = (source, target) => {
2987
2925
  };
2988
2926
  /**
2989
2927
  * The materializer id of a callable adapter one of whose PARAMETERS converts
2990
- * only through a structural view: bson's `ByteUtils.toLocalBufferType` slot
2991
- * `(Uint8Array | ArrayBufferView | ArrayBuffer) => Uint8Array` holding the web
2928
+ * only through a structural view: a platform-selected byte-utility slot
2929
+ * `(Uint8Array | ArrayBufferView | ArrayBuffer) => Uint8Array` holding an
2992
2930
  * implementation declared over `Uint8Array | (ArrayBufferView & { [Symbol.toStringTag]?: string })
2993
2931
  * | ArrayBuffer`. The slot's `ArrayBufferView` arm is a `native-record-ref`
2994
2932
  * reaching the method's intersection record by a record view; the chain's
@@ -3044,6 +2982,16 @@ const dynamicArrayRebuildText = (arm, target, text) => {
3044
2982
  * can be the target at all, which the printer refuses.
3045
2983
  */
3046
2984
  export const assertedUnionText = (source, target, text, copyAllowed) => {
2985
+ // An absent-capable union: the absence converts as its own constant, the
2986
+ // present payload dispatches per arm below.
2987
+ if (source.kind === 'optional' && source.payload.kind === 'tagged-union') {
2988
+ const payload = source.payload;
2989
+ return tryCandidateText(() => evaluatedOnceText(text, (operand) => {
2990
+ const present = assertedUnionText(payload, target, `(*${operand})`, copyAllowed);
2991
+ const absent = convertedValueText({ kind: source.absence }, target, source.absence === 'null' ? 'nullptr' : 'gea::Undefined{}');
2992
+ return present === null || absent === null ? null : `(${operand}.has_value() ? ${present} : ${absent})`;
2993
+ }));
2994
+ }
3047
2995
  if (source.kind !== 'tagged-union')
3048
2996
  return null;
3049
2997
  const targetKey = representationKey(target);
@@ -3066,6 +3014,32 @@ export const assertedUnionText = (source, target, text, copyAllowed) => {
3066
3014
  return `(${result})`;
3067
3015
  }));
3068
3016
  };
3017
+ /**
3018
+ * `nodes.ts`'s `assertedViewFor`: a record asserted into a slot whose object
3019
+ * homes are classes. Each class arm the plan names, descendant first, is tested
3020
+ * by the view's origin and loads that allocation through its cited node; no
3021
+ * origin is the assertion failing.
3022
+ */
3023
+ const assertedViewText = (ctx, node, plan, text) => {
3024
+ const { source, target } = node;
3025
+ return tryCandidateText(() => evaluatedOnceText(text, (operand) => {
3026
+ const held = source.kind === 'optional' ? `(*${operand})` : operand;
3027
+ let present = `gea::host::unhomedAssertedRecord<${cppTypeOf(target)}>()`;
3028
+ for (const arm of [...plan.arms].reverse()) {
3029
+ const name = cppClassName(arm.declaration);
3030
+ const home = recipeText(ctx, arm.load, `gea::record::viewOriginClassRef<${name}>(${held})`);
3031
+ if (home === null)
3032
+ return null;
3033
+ present = `(gea::record::viewOriginClassIs<${name}>(${held}) ? ${home} : ${present})`;
3034
+ }
3035
+ if (source.kind !== 'optional')
3036
+ return present;
3037
+ if (plan.absent === null)
3038
+ return null;
3039
+ const absent = recipeText(ctx, plan.absent, source.absence === 'null' ? 'nullptr' : 'gea::Undefined{}');
3040
+ return absent === null ? null : `(${operand}.has_value() ? ${present} : ${absent})`;
3041
+ }));
3042
+ };
3069
3043
  export const checkedArmNarrowingText = (source, target, text) => {
3070
3044
  if (source.kind !== 'tagged-union' || target.kind !== 'tagged-union')
3071
3045
  return null;
@@ -3091,18 +3065,29 @@ export const resultAdaptedCallableText = (source, target, text, viaView, knownFu
3091
3065
  const call = known === null
3092
3066
  ? `static_cast<${sourceType}*>(${adapterEnvironmentName})->call(${sourceActuals.join(', ')})`
3093
3067
  : `${known}(${[adapterEnvironmentName, ...sourceActuals].join(', ')})`;
3094
- const body = adapter.from.result.kind === 'void'
3095
- ? `${call};${adapter.convertedResult === null ? '' : ` return ${adapter.convertedResult};`}`
3068
+ const bodyOf = (invocation) => adapter.from.result.kind === 'void'
3069
+ ? `${invocation};${adapter.convertedResult === null ? '' : ` return ${adapter.convertedResult};`}`
3096
3070
  : adapter.to.result.kind === 'void'
3097
- ? `${call};`
3098
- : `${cppTypeOf(adapter.from.result)} ${adapterResultName} = ${call}; return ${adapter.convertedResult};`;
3099
- const adapt = known === null ? 'adaptSource' : `adaptSourceInPlace<&${known}>`;
3100
- return `${cppTypeOf(target)}::${adapt}(${sourceType}{${text}}, [](${formals.join(', ')}) -> ${cppResultTypeOf(adapter.to.result)} { ${body} })`;
3071
+ ? `${invocation};`
3072
+ : `${cppTypeOf(adapter.from.result)} ${adapterResultName} = ${invocation}; return ${adapter.convertedResult};`;
3073
+ if (known === null && adapter.from.receiver === null) {
3074
+ const receiverActual = adapter.to.receiver === null
3075
+ ? 'gea::NativeCallReceiver::undefined()'
3076
+ : nativeCallReceiverText(adapter.to.receiver, adapterReceiverName);
3077
+ const invokeWith = (receiver) => `static_cast<${sourceType}*>(${adapterEnvironmentName})->callWithReceiver(${[receiver, ...adapter.actuals].join(', ')})`;
3078
+ const receiverFormals = [`void* ${adapterEnvironmentName}`, 'const gea::NativeCallReceiver& gea_adapt_this', ...formals.slice(1)];
3079
+ return (`${cppTypeOf(target)}::adaptSourceWithReceiver<${cppCallableFrameArguments(adapter.to)}>(${sourceType}{${text}}, ` +
3080
+ `[](${formals.join(', ')}) -> ${cppResultTypeOf(adapter.to.result)} { ${bodyOf(invokeWith(receiverActual))} }, ` +
3081
+ `[](${receiverFormals.join(', ')}) -> ${cppResultTypeOf(adapter.to.result)} { ${bodyOf(invokeWith('gea_adapt_this'))} })`);
3082
+ }
3083
+ const frame = cppCallableFrameArguments(adapter.to);
3084
+ const adapt = known === null ? `adaptSource<${frame}>` : `adaptSourceInPlace<&${known}, ${frame}>`;
3085
+ return `${cppTypeOf(target)}::${adapt}(${sourceType}{${text}}, [](${formals.join(', ')}) -> ${cppResultTypeOf(adapter.to.result)} { ${bodyOf(call)} })`;
3101
3086
  };
3102
3087
  /**
3103
3088
  * A class stored into a construct-signature slot whose convention differs from
3104
- * the class's own -- `const bindings: { MongoCrypt: MongoCryptConstructor } =
3105
- * { MongoCrypt: NativeMongoCrypt }`, where the slot's `new` answers an
3089
+ * the class's own -- `const bindings: { Impl: ImplConstructor } =
3090
+ * { Impl: NativeImpl }`, where the slot's `new` answers an
3106
3091
  * interface and the class's answers its own instance.
3107
3092
  *
3108
3093
  * The adapter keeps the class evaluation as its environment, so the value is
@@ -3154,7 +3139,7 @@ const constructorDispatchAdapterText = (source, target, text) => {
3154
3139
  const [sole] = members;
3155
3140
  if (members.length === 1 && sole !== undefined) {
3156
3141
  const invocation = invocationOf(sole);
3157
- const result = cppTypeOf(from.result) === cppTypeOf(to.result)
3142
+ const result = samePhysicalCarrier(from.result, to.result)
3158
3143
  ? invocation
3159
3144
  : tryCandidateText(() => convertedValueText(from.result, to.result, invocation));
3160
3145
  if (result === null)
@@ -3184,7 +3169,7 @@ const constructorDispatchAdapterText = (source, target, text) => {
3184
3169
  /** Whether a class reaches a construct-signature slot through `constructorDispatchAdapterText`. Exported so `conversions.ts` asks the identical question the render answers. */
3185
3170
  export const adaptsConstructorIntoDispatch = (source, target) => source.kind === 'constructor-family' &&
3186
3171
  target.kind === 'constructor-value-dispatch' &&
3187
- cppTypeOf(source) !== cppTypeOf(target) &&
3172
+ !samePhysicalCarrier(source, target) &&
3188
3173
  constructorDispatchAdapterText(source, target, 'gea_probe') !== null;
3189
3174
  /**
3190
3175
  * A callable filling a slot that declares MORE parameters than it does, the
@@ -3194,7 +3179,7 @@ export const adaptsConstructorIntoDispatch = (source, target) => source.kind ===
3194
3179
  *
3195
3180
  * ECMA-262 does not bind the extra arguments, so `() => void` really is a
3196
3181
  * `(time: number) => void` and TypeScript accepts it everywhere, and the same
3197
- * is true one prefix over: hono's `Hono.getPath` merges two
3182
+ * is true one prefix over: a class field may merge two
3198
3183
  * `(request: Request) => string` values into a field declared
3199
3184
  * `(request: Request, options?: {env?}) => string` -- one shared leading
3200
3185
  * parameter, one trailing parameter neither physical function looks at.
@@ -3216,62 +3201,6 @@ export const adaptsConstructorIntoDispatch = (source, target) => source.kind ===
3216
3201
  * receiver must still agree exactly -- neither is dropped by a call, so a
3217
3202
  * difference in either is a real mismatch, not a binding the language elides.
3218
3203
  */
3219
- /**
3220
- * A method value -- its receiver first in its physical convention -- filling
3221
- * a slot that declares the same convention WITHOUT one: `gea_runtime.h`'s
3222
- * `CallableObject::bindReceiver`, which packs the receiver the property read
3223
- * went through in with the value. Everything but the receiver has to agree
3224
- * exactly, in the C++ spelling the runtime's own signature matching sees
3225
- * (`cppAbiType`, the one authority on that spelling), so the adapter's
3226
- * `Result(Receiver, Arguments...)` is the source's own type and nothing is
3227
- * coerced on the way through.
3228
- *
3229
- * Only the SHAPE is decided here; whether the pair can actually be rendered
3230
- * -- the read's receiver has to be recoverable at the site, and the body must
3231
- * never read `this` -- is `emit-callable.ts`'s `receiverBoundCallableText`'s
3232
- * question, a fact of the emitter's context and not of the two carriers.
3233
- */
3234
- /**
3235
- * A `this`-TYPED function value, stored in a field and read through the object
3236
- * whose `this` it names: `gea_runtime.h`'s `CallableObject::bindReceiver`
3237
- * again, but reached from a fact about the two DECLARATIONS rather than from a
3238
- * method body.
3239
- *
3240
- * hono's `RegExpRouter` writes `match: typeof match<Router<T>, T> = match`
3241
- * over `function match<R extends Router<T>, T>(this: R, method, path)`, while
3242
- * `TrieRouter` and `SmartRouter` declare `match` as an ordinary method -- and
3243
- * `Router<T>` itself declares it as a method, with no `this` at all. So the
3244
- * field's carrier names a receiver and every read through the interface (or
3245
- * through the union of the three implementors) publishes one that does not,
3246
- * and nothing converted between them.
3247
- *
3248
- * Binding the read's own receiver is the only call the language admits here,
3249
- * which is what makes this sound where the detached-METHOD case next door
3250
- * needs `readsReceiver` to hold: a `this` parameter is a parameter, and
3251
- * TypeScript refuses a call through the value that does not supply one
3252
- * (`The 'this' context of type 'void' is not assignable...`). A method has no
3253
- * such annotation, so a detached call really can reach it with `this`
3254
- * undefined, and binding there would answer where the program would have
3255
- * thrown.
3256
- */
3257
- export const receiverBoundFieldText = (ctx, stored, published, storedText, receiver, receiverText) => {
3258
- if (!bindsReceiver(stored, published))
3259
- return null;
3260
- const abi = callableObjectAbi(stored);
3261
- if (abi === null || abi.receiver === null)
3262
- return null;
3263
- const bound = alignedValueText(ctx, 'emit-narrowing.ts:receiver-bound-field', receiver, abi.receiver, receiverText);
3264
- if (bound === null)
3265
- return null;
3266
- return `${cppTypeOf(published)}::bindReceiver(${storedText}, ${bound})`;
3267
- };
3268
- export const bindsReceiver = (source, target) => {
3269
- const from = callableObjectAbi(source);
3270
- const to = callableObjectAbi(target);
3271
- if (!from || !to || from.receiver === null || to.receiver !== null)
3272
- return false;
3273
- return cppAbiType({ ...from, receiver: null }) === cppAbiType(to);
3274
- };
3275
3204
  export const dropsUnboundParameters = (source, target) => {
3276
3205
  const from = callableObjectAbi(source);
3277
3206
  const to = callableObjectAbi(target);
@@ -3297,8 +3226,8 @@ export const dropsUnboundParameters = (source, target) => {
3297
3226
  * `dropsUnboundParameters` requires an IDENTICAL result, and a bare `ofArm`
3298
3227
  * conversion has no arity adaptation of its own.
3299
3228
  *
3300
- * hono's `Context.notFound`: `this.#notFoundHandler ??=
3301
- * () => createResponseInstance()` merges a `() => Response` into a field
3229
+ * A lazily defaulted field: `this.#handler ??=
3230
+ * () => makeResponse()` merges a `() => Response` into a field
3302
3231
  * declared `(c: Context) => Response | Promise<Response>`.
3303
3232
  * `gea_runtime.h`'s `ResultWidensIntoArm` proves the identical pairing at
3304
3233
  * the type level; this re-asks the same two-part question so the two cannot
@@ -3338,7 +3267,7 @@ export const dropsAllParametersIntoResultArm = (source, target) => {
3338
3267
  * result -- `Array.prototype.forEach`'s callback contract is the textbook
3339
3268
  * case, and this port's own is `node:http`'s `RequestListener = (req, res)
3340
3269
  * => void`: `createServer(async (req, res) => { ... })` is an everyday Node
3341
- * idiom (`apps/hono-hello/server.ts` is one), and TypeScript accepts a
3270
+ * idiom, and TypeScript accepts a
3342
3271
  * `Promise<void>`-returning callback there for the identical reason -- a
3343
3272
  * `void`-returning function TYPE is satisfied by ANY return type, precisely
3344
3273
  * so a caller who ignores the result is never forced to wrap it.
@@ -3380,7 +3309,7 @@ export const dropsAllParametersIntoResultArm = (source, target) => {
3380
3309
  *
3381
3310
  * That predicate requires a ZERO-parameter source and `dropsUnboundParameters`
3382
3311
  * an IDENTICAL result, so a pair moving along only the result axis at a nonzero
3383
- * arity satisfies neither -- hono's `Hono.fetch` is one, a `(Context) =>
3312
+ * arity satisfies neither -- e.g. a `(Context) =>
3384
3313
  * Response` assigned into a field declared `(Context) => Response |
3385
3314
  * Promise<Response>`. Sound for exactly the reason `gea_runtime.h`'s
3386
3315
  * `ResultWidensIntoArm` states, and asked in the same terms so the two cannot
@@ -3397,7 +3326,7 @@ export const widensResultIntoArm = (source, target) => {
3397
3326
  return false;
3398
3327
  if (from.parameters.length === 0 || from.parameters.length !== to.parameters.length)
3399
3328
  return false;
3400
- if (from.restFrom !== to.restFrom || to.result.kind !== 'tagged-union')
3329
+ if (from.restFrom !== to.restFrom || from.argumentsFrame !== to.argumentsFrame || to.result.kind !== 'tagged-union')
3401
3330
  return false;
3402
3331
  if (!from.parameters.every((parameter, index) => representationKey(parameter.value) === representationKey(to.parameters[index].value)))
3403
3332
  return false;
@@ -3409,7 +3338,7 @@ export const widensResultIntoArm = (source, target) => {
3409
3338
  *
3410
3339
  * ECMAScript has one calling convention, so `(base?: string, sub?: string,
3411
3340
  * ...rest: string[]) => string` and `(...paths: string[]) => string` are the
3412
- * same function -- hono's `utils/url.ts` declares exactly that pair on one
3341
+ * same function -- a module may declare exactly that pair on one
3413
3342
  * `const mergePath`, the annotation stating the second and the initializer
3414
3343
  * being the first. C++ sees two unrelated function types, and the store
3415
3344
  * refused.
@@ -3432,6 +3361,8 @@ export const rebasesRestOverLeadingParameters = (source, target) => {
3432
3361
  const to = callableObjectAbi(target);
3433
3362
  if (!from || !to)
3434
3363
  return false;
3364
+ if (from.argumentsFrame === 'actual' || to.argumentsFrame === 'actual')
3365
+ return false;
3435
3366
  if (from.receiver !== null || to.receiver !== null)
3436
3367
  return false;
3437
3368
  if (representationKey(from.result) !== representationKey(to.result))
@@ -3459,6 +3390,8 @@ export const discardsResultIntoVoid = (source, target) => {
3459
3390
  const to = callableObjectAbi(target);
3460
3391
  if (!from || !to)
3461
3392
  return false;
3393
+ if (from.restFrom !== to.restFrom || from.argumentsFrame !== to.argumentsFrame)
3394
+ return false;
3462
3395
  if (from.receiver !== null || to.receiver !== null)
3463
3396
  return false;
3464
3397
  if (to.result.kind !== 'void')
@@ -3636,32 +3569,25 @@ const narrowedIntegerFromDynamicName = () => {
3636
3569
  const named = unitFunctionName('gea_narrowed_integer_from_dynamic', (name) => `${cppNarrowedIntegerType} ${name}(double gea_value)`, body);
3637
3570
  return named ?? `[](double gea_value) -> ${cppNarrowedIntegerType} { ${body} }`;
3638
3571
  };
3639
- export const unboxedLoadText = (target, text) => {
3572
+ /**
3573
+ * `freshObject`: the box holds an object the RUNTIME just built and nothing
3574
+ * else references (`Reflect.getOwnPropertyDescriptor`'s descriptor), so a
3575
+ * shared record is materialized field by field into a new allocation -- there
3576
+ * is no program identity for the rebuild to lose.
3577
+ */
3578
+ export const unboxedLoadText = (target, text, receiverFactory, freshObject = false) => {
3640
3579
  const formal = 'gea_unboxed';
3641
- const load = unboxedLoadTextAt(target, formal);
3580
+ const load = unboxedLoadTextAt(target, formal, receiverFactory, freshObject);
3642
3581
  if (load === null)
3643
3582
  return null;
3644
3583
  if (load.length <= unitLoadInlineLimit)
3645
- return unboxedLoadTextAt(target, text);
3584
+ return unboxedLoadTextAt(target, text, receiverFactory, freshObject);
3646
3585
  const named = unitFunctionName('gea_unbox', (name) => `${cppTypeOf(target)} ${name}(const gea::Value& ${formal})`, `return ${load};`);
3647
- return named === null ? unboxedLoadTextAt(target, text) : `${named}(${text})`;
3586
+ return named === null ? unboxedLoadTextAt(target, text, receiverFactory, freshObject) : `${named}(${text})`;
3648
3587
  };
3649
3588
  /** A load no longer than this stays inline: naming a unit function costs about as much as it saves. */
3650
3589
  const unitLoadInlineLimit = 64;
3651
- /**
3652
- * The load of a record member that is a plain receiverless callable, bound to
3653
- * the object it was read from -- or `null` when the member is anything else
3654
- * (the ordinary `unboxedLoadText` answers it).
3655
- */
3656
- const boundMethodLoadText = (target, text, holder) => {
3657
- if (target.kind !== 'function-value-dispatch')
3658
- return null;
3659
- const abi = callableObjectAbi(target);
3660
- if (abi === null || abi.receiver !== null || abi.restFrom !== null)
3661
- return null;
3662
- return `gea::detail::DynamicCarrier<${cppTypeOf(target)}>::inBound(${text}, 0, ${holder})`;
3663
- };
3664
- const unboxedLoadTextAt = (target, text) => {
3590
+ const unboxedLoadTextAt = (target, text, receiverFactory, freshObject = false) => {
3665
3591
  // A `Function` arm remains a Value because its ABI is unknown. Loading it
3666
3592
  // out of a broader dynamic boundary is an identity-preserving copy guarded
3667
3593
  // by the Function tag, not an adaptation to an invented signature.
@@ -3683,10 +3609,10 @@ const unboxedLoadTextAt = (target, text) => {
3683
3609
  const load = restFrom === null
3684
3610
  ? callableAbi.receiver === null
3685
3611
  ? `gea::detail::DynamicCarrier<${type}>::in(${value}, 0)`
3686
- : `gea::detail::DynamicCarrier<${type}>::inWithReceiver(${value}, 0)`
3612
+ : `gea::detail::DynamicCarrier<${type}>::inWithReceiver(${value}, 0${receiverFactory === undefined ? '' : `, ${receiverFactory}`})`
3687
3613
  : callableAbi.receiver === null
3688
- ? `gea::detail::DynamicCarrier<${type}>::template inWithRest<${restFrom}>(${value}, 0)`
3689
- : `gea::detail::DynamicCarrier<${type}>::template inWithReceiverAndRest<${restFrom + 1}>(${value}, 0)`;
3614
+ ? `gea::detail::DynamicCarrier<${type}>::template inWithRest<${restFrom}, ${callableAbi.argumentsFrame === 'actual'}>(${value}, 0)`
3615
+ : `gea::detail::DynamicCarrier<${type}>::template inWithReceiverAndRest<${restFrom + 1}, ${callableAbi.argumentsFrame === 'actual'}>(${value}, 0${receiverFactory === undefined ? '' : `, ${receiverFactory}`})`;
3690
3616
  const members = target.kind === 'function'
3691
3617
  ? [target.functionId]
3692
3618
  : target.kind === 'function-family' || target.kind === 'function-value-family'
@@ -3876,7 +3802,7 @@ const unboxedLoadTextAt = (target, text) => {
3876
3802
  return `(${text}.tag() == gea::Value::Tag::${absentTag} ? ${targetType}() : ${targetType}(${payload}))`;
3877
3803
  }
3878
3804
  // A dynamic container commonly carries dynamic elements even when the
3879
- // assertion names a typed Array. BSON deserialization is the concrete case:
3805
+ // assertion names a typed Array. A binary document decoder is the concrete case:
3880
3806
  // it builds `Array<Value>` because each element is decided by the wire type,
3881
3807
  // then its public result is asserted as `string[]`, `Document[]`, and so on.
3882
3808
  // The runtime bridge preserves an exact typed payload by identity and
@@ -3886,8 +3812,8 @@ const unboxedLoadTextAt = (target, text) => {
3886
3812
  if (target.kind === 'array-object') {
3887
3813
  // A record element is not a carrier `DynamicCarrier` can rebuild: which
3888
3814
  // struct is a record rather than a class is a compiler fact, and the
3889
- // runtime's `Ref<T>` rule reads a box back by identity alone -- so a JSON
3890
- // or BSON document element aborted. The element takes this function's own
3815
+ // runtime's `Ref<T>` rule reads a box back by identity alone -- so a
3816
+ // parsed or decoded document element aborted. The element takes this function's own
3891
3817
  // record conversion instead, the one every other `any -> record` read takes.
3892
3818
  if (adoptsDynamicRecord(target.element)) {
3893
3819
  const element = 'gea_dynamic_element';
@@ -3925,25 +3851,16 @@ const unboxedLoadTextAt = (target, text) => {
3925
3851
  if (target.kind === 'dictionary' && target.key === 'string' && target.ownership === 'shared-refcount') {
3926
3852
  return `gea::detail::unboxDynamicDictionary<${cppTypeOf(target.value)}>(${text}, ${cppStringLiteral(assertionSite(target))})`;
3927
3853
  }
3928
- // An open document deserializer cannot know the concrete interface a later
3929
- // assertion will name, so it stores a native `Dictionary<Value>`. Requiring
3930
- // that payload to already be the target record's C++ struct rejects valid
3931
- // BSON/JSON document assertions. Rebuild the declared record from checked
3932
- // dynamic field reads instead. The exact-payload branch preserves identity
3933
- // when the box already carries this record.
3934
- //
3935
- // A Document is then ADOPTED into the product (`gea::dictionary::
3936
- // adoptProduct`): it views the record, so a write through the typed name is
3937
- // a read through the `any` one, and the keys the record does not declare
3938
- // move with it -- into the index sidecar of a `record-with-index`, whose
3939
- // open half a field-by-field copy would otherwise drop. A value that is not
3940
- // this record is the program's contract violated, not the compiler's, so it
3941
- // is a TypeError the program may catch, as `exactArm` is.
3854
+ // A generic shared structural load requires the selected live field plan.
3855
+ // A context-free identity cast cannot stand in for that plan. Nominal and
3856
+ // accessor payload recovery below keep their independent exact contracts.
3942
3857
  if ((target.kind === 'record' && target.accessors.length === 0) || target.kind === 'record-with-index') {
3943
3858
  if (target.ownership === 'borrowed')
3944
3859
  return null;
3945
- const indexed = target.kind === 'record-with-index';
3946
- if (indexed && (target.ownership !== 'shared-refcount' || target.fields.some((field) => cppRecordFieldKeyIsSymbol(field.key))))
3860
+ const shared = target.ownership === 'shared-refcount';
3861
+ if (shared && !freshObject)
3862
+ return null;
3863
+ if (target.kind === 'record-with-index')
3947
3864
  return null;
3948
3865
  const targetType = cppTypeOf(target);
3949
3866
  const structName = cppRecordStructName(target.shapeId);
@@ -3951,10 +3868,7 @@ const unboxedLoadTextAt = (target, text) => {
3951
3868
  const fields = target.fields.map((field, index) => {
3952
3869
  const present = `gea_dynamic_record_present_${index}`;
3953
3870
  const value = `gea_dynamic_record_value_${index}`;
3954
- // A method read off the dynamic object is called as `object.method(...)`,
3955
- // so its adapter binds the object as `this` (`DynamicCarrier::inBound`).
3956
- const boundMember = boundMethodLoadText(field.value, value, holder);
3957
- const unboxed = field.value.kind === 'dynamic' ? value : (boundMember ?? unboxedLoadText(field.value, value));
3871
+ const unboxed = field.value.kind === 'dynamic' ? value : unboxedLoadText(field.value, value);
3958
3872
  // A member the integer census narrowed is a `long long`, and a braced
3959
3873
  // initializer refuses the `double` a box unboxes to. The census admitted
3960
3874
  // this rebuild because the box carries exactly this struct, which the
@@ -3983,52 +3897,32 @@ const unboxedLoadTextAt = (target, text) => {
3983
3897
  // A layout that moved fields behind its `RecordTail` no longer declares
3984
3898
  // them positionally, and storing an absent one would allocate the tail
3985
3899
  // for nothing, so it is filled by name, present fields only.
3986
- const tailed = !indexed && tailFieldsOf({ fields: target.fields }).size > 0;
3900
+ const tailed = tailFieldsOf({ fields: target.fields }).size > 0;
3987
3901
  const product = () => {
3988
- if (tailed) {
3989
- const access = target.ownership === 'shared-refcount' ? '->' : '.';
3902
+ if (shared) {
3990
3903
  const assignments = fields.map(({ field, present, load }) => {
3991
- const store = `gea_built${access}${tailAwareFieldWriteText(target.fields, field.key)} = ${load};`;
3992
- return field.required ? store : `if (${present}) { ${store} gea_built${access}${cppRecordFieldPresenceName(field.key)} = true; }`;
3904
+ const store = `gea_built->${tailAwareFieldWriteText(target.fields, field.key)} = ${load};`;
3905
+ return field.required ? store : `if (${present}) { ${store} gea_built->${cppRecordFieldPresenceName(field.key)} = true; }`;
3993
3906
  });
3994
- const built = target.ownership === 'shared-refcount' ? `auto gea_built = gea::makeRef<${structName}>();` : `${structName} gea_built{};`;
3995
- return `[&]() { ${built} ${assignments.join(' ')} return gea_built; }()`;
3907
+ return `[&]() { auto gea_built = gea::makeRef<${structName}>(); ${assignments.join(' ')} return gea_built; }()`;
3996
3908
  }
3997
- if (!indexed) {
3998
- const presences = fields.filter(({ field }) => !field.required).map(({ present }) => present);
3999
- const structure = `${structName}{${[...reads, ...presences].join(', ')}}`;
4000
- return target.ownership === 'shared-refcount' ? `gea::makeRef<${structName}>(${structure})` : structure;
3909
+ if (tailed) {
3910
+ const assignments = fields.map(({ field, present, load }) => {
3911
+ const store = `gea_built.${tailAwareFieldWriteText(target.fields, field.key)} = ${load};`;
3912
+ return field.required ? store : `if (${present}) { ${store} gea_built.${cppRecordFieldPresenceName(field.key)} = true; }`;
3913
+ });
3914
+ return `[&]() { ${structName} gea_built{}; ${assignments.join(' ')} return gea_built; }()`;
4001
3915
  }
4002
- // The index sidecar sits between the fields and their presence bits, so
4003
- // this layout is filled by name rather than by position.
4004
- const assignments = fields.map(({ field, present }, index) => {
4005
- const store = `gea_built->${cppRecordFieldName(field.key)} = ${reads[index]};`;
4006
- return field.required ? store : `${store} gea_built->${cppRecordFieldPresenceName(field.key)} = ${present};`;
4007
- });
4008
- return `[&]() { auto gea_built = gea::makeRef<${structName}>(); ${assignments.join(' ')} return gea_built; }()`;
3916
+ const presences = fields.filter(({ field }) => !field.required).map(({ present }) => present);
3917
+ return `${structName}{${[...reads, ...presences].join(', ')}}`;
4009
3918
  };
4010
- const adopted = target.ownership === 'shared-refcount'
4011
- ? `gea::dictionary::adoptProduct<${structName}>(${holder}, [&]() -> ${targetType} { return ${product()}; })`
4012
- : product();
4013
- const exactPayload = target.ownership === 'shared-refcount'
4014
- ? `if (${holder}.tag() == gea::Value::Tag::Object && ${holder}.payloadType() == gea::detail::payloadTypeTagFor<${targetType}>()) ` +
4015
- `return gea::detail::unboxValue<${targetType}>(${holder}, gea::Value::Tag::Object, ${cppStringLiteral(assertionSite(target))}); `
4016
- : '';
4017
- // An indexed record's open half has no source but a Document's entries:
4018
- // any other object would lose them, which a snapshot cast may not.
4019
- const documentOnly = indexed
4020
- ? `if (${holder}.payloadType() != gea::detail::payloadTypeTagFor<gea::Ref<gea::Dictionary<gea::Value>>>()) ` +
4021
- `gea::detail::refusePayloadMismatch(${cppStringLiteral(assertionSite(target))}); `
4022
- : '';
4023
- const body = exactPayload +
4024
- `if (${holder}.tag() != gea::Value::Tag::Object && ${holder}.tag() != gea::Value::Tag::Function) ` +
3919
+ const body = `if (${holder}.tag() != gea::Value::Tag::Object && ${holder}.tag() != gea::Value::Tag::Function) ` +
4025
3920
  `${refused('an assertion to a record requires an object')} ` +
4026
- documentOnly +
4027
3921
  `${fields.map(({ field, present }) => `const bool ${present} = gea::detail::dynamicRecordHasField(${holder}, ${cppStringLiteral(field.key)});`).join(' ')} ` +
4028
- `${checks.join(' ')} ${values.join(' ')} ${admissions.join(' ')} return ${adopted};`;
3922
+ `${checks.join(' ')} ${values.join(' ')} ${admissions.join(' ')} return ${product()};`;
4029
3923
  // The text depends on the target alone, so a unit defines it once and
4030
3924
  // every site calls it -- see `unitFunctionName`.
4031
- const named = unitFunctionName(`gea_from_dynamic_${structName}`, (name) => `${targetType} ${name}(const gea::Value& ${holder})`, body);
3925
+ const named = unitFunctionName(`gea_from_${shared ? 'fresh_' : ''}dynamic_${structName}`, (name) => `${targetType} ${name}(const gea::Value& ${holder})`, body);
4032
3926
  if (named !== null)
4033
3927
  return `${named}(${text})`;
4034
3928
  return `[](const gea::Value& ${holder}) -> ${targetType} { ${body} }(${text})`;
@@ -4065,6 +3959,10 @@ const unboxedLoadTextAt = (target, text) => {
4065
3959
  // the narrowing claimed refuses by name instead of reinterpreting bytes.
4066
3960
  // That is what makes reading an object out of a box safe here at all: the
4067
3961
  // tag alone says only "some object".
3962
+ if (target.kind === 'scalar' && target.integerWidth !== undefined) {
3963
+ const numeric = `gea::detail::unboxValue<double>(${text}, gea::Value::Tag::Number, ${cppStringLiteral(assertionSite(target))})`;
3964
+ return `gea::toDeclaredInteger<${cppTypeOf(target)}>(${numeric})`;
3965
+ }
4068
3966
  return `gea::detail::unboxValue<${cppTypeOf(target)}>(${text}, gea::Value::Tag::${tag}, ${cppStringLiteral(assertionSite(target))})`;
4069
3967
  };
4070
3968
  /**
@@ -4191,12 +4089,12 @@ const claimed = (text) => (text === null ? undefined : text);
4191
4089
  * what carries the payload (`IteratorResult<T>`'s arms are named interfaces a
4192
4090
  * `{ value, done: false }` literal reaches only by a view).
4193
4091
  *
4194
- * A source still PENDING links through `observe`: hono's `#cachedBody` is one
4092
+ * A source still PENDING links through `observe`: a request's body cache is one
4195
4093
  * callable returning `Promise<string | ArrayBuffer | Blob | ...>` that every
4196
4094
  * reader (`text()`, `json()`, `formData()`) adapts to its own `Promise<T>` at
4197
4095
  * the call, and the promise it hands back is the body read that has not
4198
4096
  * arrived yet. Snapshotting it (`if (!settled()) return Target()`) minted a
4199
- * target nothing ever settled -- every `await c.req.json()` hung and the POST
4097
+ * target nothing ever settled -- every `await request.json()` hung and the POST
4200
4098
  * never answered. The conversion runs when the value exists; a conversion that
4201
4099
  * throws (a dynamic arm not of the declared type) becomes the target's
4202
4100
  * rejection, which is what the same failure inside a `then` handler is.
@@ -4218,6 +4116,14 @@ const promiseAdoptionText = (source, target, text, payload) => {
4218
4116
  `{ ${promiseTargetName}.rejectInline(${promiseRejectionName}); }); ` +
4219
4117
  `return ${promiseTargetName}; }())`);
4220
4118
  };
4119
+ const promiseCompletionText = (source, target, text, plan, payload) => {
4120
+ if (plan.kind === 'payload-transfer')
4121
+ return promiseAdoptionText(source, target, text, (value) => payload(plan.conversion, value));
4122
+ const fulfillment = plan.kind === 'rejection-only'
4123
+ ? `gea::host::throwRuntimeError("TypeError", "a Promise<never> fulfilled"); co_return${target.value.kind === 'void' ? '' : ` gea::host::unreachableValue<${cppTypeOf(target.value)}>()`};`
4124
+ : `co_return${plan.fulfillment === 'void' ? '' : ` ${plan.fulfillment === 'dynamic' ? 'gea::Value()' : cppUndefinedValue}`};`;
4125
+ return `([](${cppTypeOf(source)} ${promiseSourceName}) -> ${cppTypeOf(target)} { co_await ${promiseSourceName}; ${fulfillment} }(${text}))`;
4126
+ };
4221
4127
  /**
4222
4128
  * The `rebuild: 'unshared-array'` conversion (`ir/model.ts`'s `ConvertOperation`):
4223
4129
  * a call result lowering proved no other reference holds, rebuilt once at the
@@ -4226,13 +4132,13 @@ const promiseAdoptionText = (source, target, text, payload) => {
4226
4132
  * for the instruction that carries the proof, never from the pair alone, and a
4227
4133
  * pending promise rebuilds when its array arrives (`promiseAdoptionText`).
4228
4134
  */
4229
- export const unsharedArrayRebuildText = (ctx, source, target, text) => {
4135
+ export const unsharedArrayRebuildText = (ctx, source, target, text, elementNode) => {
4230
4136
  if (source.kind === 'promise' && target.kind === 'promise') {
4231
- return promiseAdoptionText(source, target, text, (value) => unsharedArrayRebuildText(ctx, source.value, target.value, value));
4137
+ return promiseAdoptionText(source, target, text, (value) => unsharedArrayRebuildText(ctx, source.value, target.value, value, elementNode));
4232
4138
  }
4233
4139
  if (source.kind !== 'array-object' || target.kind !== 'array-object')
4234
4140
  return null;
4235
- const element = alignedValueText(ctx, 'emit-narrowing.ts:unshared-array', source.element, target.element, 'gea_element');
4141
+ const element = namedConversionText(ctx, 'emit-narrowing.ts:unshared-array', elementNode, 'gea_element');
4236
4142
  if (element === null)
4237
4143
  return null;
4238
4144
  return (`([&]() -> ${cppTypeOf(target)} { const auto& gea_fresh = ${text}; ` +
@@ -4247,14 +4153,23 @@ export const conversionChain = [
4247
4153
  // which would pass the SOURCE's index through unchanged -- both sets are one
4248
4154
  // `std::uint8_t`, and `0` means a different member in each.
4249
4155
  { id: 'generic-set-remap', apply: (source, target, text) => claimed(genericFunctionSetWideningText(source, target, text)) },
4250
- // Two carriers this backend spells identically convert by identity. The
4251
- // representation tells them apart for reasons the C++ type does not carry --
4156
+ // Two carriers with one physical storage convert by identity. The
4157
+ // representation tells them apart for reasons storage does not carry --
4252
4158
  // `constructor-family` names the class its `new` reaches and
4253
- // `constructor-value-dispatch` does not -- but both are one
4254
- // `gea::ConstructorObject<...>`, and a value of one already IS a value of the
4255
- // other. Checking the spelling rather than enumerating the pairs is what keeps
4256
- // this from becoming a second table that could disagree with `cppTypeOf`.
4257
- { id: 'same-cpp-type', apply: (source, target, text) => (cppTypeOf(source) === cppTypeOf(target) ? text : undefined) },
4159
+ // `constructor-value-dispatch` does not -- but a value of one already IS a
4160
+ // value of the other. `physicalCarrierKey` (representation/physical-carrier.ts)
4161
+ // states which distinctions are storage, callable packing frames included.
4162
+ {
4163
+ id: 'declared-integer-scalar',
4164
+ apply: (source, target, text) => {
4165
+ const numberTarget = numberStorageTarget(source, target);
4166
+ return numberTarget === null ? undefined : numberStorageText(numberTarget, text, cppTypeOf);
4167
+ }
4168
+ },
4169
+ {
4170
+ id: 'same-cpp-type',
4171
+ apply: (source, target, text) => (samePhysicalCarrier(source, target) ? text : undefined)
4172
+ },
4258
4173
  { id: 'empty-array-sentinel', apply: (source, target, text) => claimed(emptyArraySentinelText(source, target, text)) },
4259
4174
  { id: 'callable-identity', apply: (source, target, text) => claimed(callableIdentityText(source, target, text)) },
4260
4175
  { id: 'callable-construct-entry', apply: (source, target, text) => claimed(callableConstructEntryText(source, target, text)) },
@@ -4289,7 +4204,9 @@ export const conversionChain = [
4289
4204
  return undefined;
4290
4205
  if (source.abi.receiver !== null || target.abi.receiver !== null)
4291
4206
  return undefined;
4292
- if (source.abi.restFrom !== target.abi.restFrom || source.abi.parameters.length !== target.abi.parameters.length)
4207
+ if (source.abi.restFrom !== target.abi.restFrom ||
4208
+ source.abi.argumentsFrame !== target.abi.argumentsFrame ||
4209
+ source.abi.parameters.length !== target.abi.parameters.length)
4293
4210
  return undefined;
4294
4211
  if (classRefTransportKind(source.abi.result, target.abi.result) !== 'upcast')
4295
4212
  return undefined;
@@ -4353,7 +4270,7 @@ export const conversionChain = [
4353
4270
  },
4354
4271
  // The same one base over for a class extending the intrinsic `Error`: its
4355
4272
  // struct derives from `gea::runtime::Error` in place (`records.ts`'s native
4356
- // link), so `MongoError` stored where `Error` is declared is `Ref`'s own
4273
+ // link), so a subclass instance stored where `Error` is declared is `Ref`'s own
4357
4274
  // converting constructor. `nativeRecordBaseTransportKind` states when a
4358
4275
  // family's overrides refuse it.
4359
4276
  // An instance of a class extending the intrinsic `Promise` stored where a
@@ -4466,7 +4383,7 @@ export const conversionChain = [
4466
4383
  // an `Img | null` segfaulted on `null` having certified clean. It is the ONLY
4467
4384
  // answer for an optional source: a payload this cannot convert refuses rather
4468
4385
  // than falling through, because the fallthrough was that same unwrap one frame
4469
- // deeper (hono's `c.json` answered `HTTP/1.1 0 unknown` through it).
4386
+ // deeper (an HTTP response answered status `0` through it).
4470
4387
  {
4471
4388
  id: 'optional-payload-convert',
4472
4389
  apply: (source, target, text) => {
@@ -4599,14 +4516,8 @@ export const conversionChain = [
4599
4516
  ? claimed(recastedIndexedRecordToDictionaryText(source, target, text))
4600
4517
  : undefined
4601
4518
  },
4602
- // One shape wider: an open dictionary's values widened into another's
4603
- // (`dictionaryCastableToDictionary`).
4604
- {
4605
- id: 'dictionary-to-dictionary',
4606
- apply: (source, target, text) => source.kind === 'dictionary' && target.kind === 'dictionary' ? claimed(recastedDictionaryText(source, target, text)) : undefined
4607
- },
4608
4519
  // The mirror of `record-to-dictionary` for the one dictionary whose values
4609
- // are boxed: `globalThis as unknown as { AudioContext?: Ctor }` reads named
4520
+ // are boxed: `globalThis as unknown as { SomeGlobal?: Ctor }` reads named
4610
4521
  // fields out of the open string-keyed surface `references.ts` gives
4611
4522
  // `globalThis`. The closed field list comes from the TARGET, so this is not
4612
4523
  // the reconstruction `conversion/derive.ts` refuses (recovering a field list
@@ -4625,7 +4536,7 @@ export const conversionChain = [
4625
4536
  // An Array of one element carrier copied into an Array of another, each
4626
4537
  // element through its own conversion. A copy, so only for an array that is
4627
4538
  // not written through both names afterwards: a matcher table built once
4628
- // (hono's `[handlers.map(...), emptyParam]` literal) or a shared empty one.
4539
+ // (a `[handlers.map(...), emptyParam]` literal) or a shared empty one.
4629
4540
  {
4630
4541
  id: 'array-copy-recast',
4631
4542
  apply: (source, target, text) => {
@@ -4640,12 +4551,11 @@ export const conversionChain = [
4640
4551
  // `var array = []` whose pushes the census could not type -- and such an
4641
4552
  // array is a shared MUTABLE local passed by reference: copying it hands
4642
4553
  // the callee a twin, so its pushes never reach the caller
4643
- // (`test/runtime/array-object-call-argument-aliasing.ts`, and the
4644
- // three.js `getProgramCacheKey` glyph miscompile its `.runtime.js`
4645
- // sibling reproduces). Both polarities were live miscompiles that the
4554
+ // (`test/runtime/array-object-call-argument-aliasing.ts` and its
4555
+ // `.runtime.js` sibling reproduce it). Both polarities were live miscompiles that the
4646
4556
  // refusal fixed on 2026-09-12; re-admitting them here silently undid
4647
4557
  // that fix. The record- and union-element copies this recipe was added
4648
- // for (hono's matcher tables, built from literals) do not cross it --
4558
+ // for (router matcher tables, built from literals) do not cross it --
4649
4559
  // and the test is the ELEMENT's own carrier, not a field somewhere
4650
4560
  // inside a record element: a record field boxed on the way is a shape
4651
4561
  // change, not the census-refused evolving array this rule names.
@@ -4677,7 +4587,7 @@ export const conversionChain = [
4677
4587
  return undefined;
4678
4588
  const reads = [];
4679
4589
  for (const [index, field] of target.fields.entries()) {
4680
- const converted = tryCandidateText(() => convertedValueText(source.element, field.value, `gea_from->at(${index})`));
4590
+ const converted = tryCandidateText(() => convertedValueText(source.element, field.value, `gea_from->readElement(${index})`));
4681
4591
  if (converted === null)
4682
4592
  return null;
4683
4593
  reads.push(field.value.kind === 'scalar' && field.value.domain !== 'bigint'
@@ -4691,10 +4601,6 @@ export const conversionChain = [
4691
4601
  `return ${built}; }(${text})`);
4692
4602
  }
4693
4603
  },
4694
- {
4695
- id: 'record-to-array',
4696
- apply: (source, target, text) => source.kind === 'record' && target.kind === 'array-object' ? claimed(recastedRecordToArrayText(source, target, text)) : undefined
4697
- },
4698
4604
  // TWO PROMISES WHOSE PAYLOADS DIFFER. `widenedStoreText` reads a `promise`
4699
4605
  // target as "widen the written VALUE into a promise of it", correct for the
4700
4606
  // `return` terminator and wrong here, where the source is already a promise.
@@ -4710,8 +4616,8 @@ export const conversionChain = [
4710
4616
  // nothing with `undefined`, which `cppResultTypeOf` elides for `void`), so
4711
4617
  // the state crosses and the unit value is supplied or dropped. That recipe
4712
4618
  // awaits the source rather than snapshotting a settled state, because
4713
- // its source is routinely still PENDING -- `@hono/node-server`'s
4714
- // `responseViaCache` awaits inside -- and a snapshot of a pending promise is
4619
+ // its source is routinely still PENDING -- an async function that awaits
4620
+ // inside -- and a snapshot of a pending promise is
4715
4621
  // a target nothing ever settles.
4716
4622
  //
4717
4623
  // `Promise<never>` is the one void-payload SOURCE that does not refuse, and
@@ -4763,7 +4669,7 @@ export const conversionChain = [
4763
4669
  { id: 'dynamic-map-arm-view', apply: (source, target, text) => claimed(dynamicMapArmViewStoreText(target, source, text)) },
4764
4670
  { id: 'dynamic-unbox', apply: (source, target, text) => (source.kind === 'dynamic' ? unboxedLoadText(target, text) : undefined) },
4765
4671
  // A String OBJECT reconciled against the `string` primitive its alias widens
4766
- // to (hono's `HtmlEscapedString`). Before the two general paths for the same
4672
+ // to (a `String` object branded as a string alias). Before the two general paths for the same
4767
4673
  // reason the dynamic case is: `narrowedLoadText` would read this as a search
4768
4674
  // through a union's arms and refuse, and `widenedStoreText` reads it backwards.
4769
4675
  {
@@ -4792,8 +4698,8 @@ export const conversionChain = [
4792
4698
  // A sum holds an absence only through an arm that does: a
4793
4699
  // `tagged-union(array-buffer|typed-array|native-record-ref)` has no
4794
4700
  // arm for `undefined` to widen into, so an `undefined` reaching it is
4795
- // `never`'s (bson's `ObjectId` normalizes a view it already narrowed to
4796
- // `Uint8Array`, src/objectid.ts:226).
4701
+ // `never`'s (a constructor normalizing a view it already narrowed to
4702
+ // `Uint8Array`).
4797
4703
  const holdsAbsence = (carrier) => carrier.kind === 'optional' ||
4798
4704
  (carrier.kind === 'tagged-union' && carrier.arms.some((arm) => holdsAbsence(arm.value))) ||
4799
4705
  carrier.kind === 'dynamic' ||
@@ -4833,7 +4739,19 @@ export const alignedValueText = (ctx, site, source, target, text) => {
4833
4739
  sourceRepresentation: source,
4834
4740
  targetRepresentation: target
4835
4741
  });
4836
- return refused ? convertedValueText(source, target, text) : recipeText(ctx, node, text);
4742
+ return recipeText(ctx, node, text);
4743
+ };
4744
+ /** A native artifact consumes the exact pair published for its own physical slot. */
4745
+ export const programConversionText = (ctx, role, owner, slot, source, target, text) => {
4746
+ if (representationKey(source) === representationKey(target))
4747
+ return text;
4748
+ const key = programConversionKey({ role, owner, slot });
4749
+ const recipe = ctx.programConversionRecipes?.find((candidate) => programConversionKey(candidate) === key);
4750
+ if (recipe === undefined ||
4751
+ representationKey(recipe.source) !== representationKey(source) ||
4752
+ representationKey(recipe.target) !== representationKey(target))
4753
+ throw createCppEmitBlockedError('runtime-helper:program-conversion-recipes', `native artifact ${key} names no certified physical conversion`);
4754
+ return recipeText(ctx, recipe.conversion, text);
4837
4755
  };
4838
4756
  /**
4839
4757
  * A census node's recipe, rendered by one of the two renderers the census
@@ -4861,7 +4779,7 @@ export const alignedValueText = (ctx, site, source, target, text) => {
4861
4779
  * an Array: the layout is resolved here, where the layouts are in hand, and
4862
4780
  * the read is `unboxedLoadText`'s own record conversion (checked product,
4863
4781
  * Document adoption, TypeError). The ctx-free chain would otherwise read the
4864
- * name back by identity alone, which aborts on every JSON or BSON document.
4782
+ * name back by identity alone, which aborts on every parsed or decoded document.
4865
4783
  */
4866
4784
  const dynamicNamedRecordText = (layouts, source, target, text) => {
4867
4785
  if (source.kind !== 'dynamic' || source.reason === 'untyped-callable')
@@ -4871,17 +4789,29 @@ const dynamicNamedRecordText = (layouts, source, target, text) => {
4871
4789
  };
4872
4790
  /**
4873
4791
  * A declared `any` read into `target` where no conversion node was minted --
4874
- * a boxed struct's field dispatcher writing a member (`records.ts`). The same
4875
- * two recipes a census `dynamic -> target` node renders, in the same order: a
4876
- * named interface expands to its layout first, so a box that is not already
4877
- * the target's struct is rebuilt by the checked record product rather than
4878
- * refused by identity; everything else is the generic load.
4792
+ * a boxed struct's field dispatcher writing a member (`records.ts`). Shared
4793
+ * structural objects require an explicit canonical recipe. Exact nominal
4794
+ * payloads and owned copies retain their context-free native contracts.
4879
4795
  */
4880
- export const dynamicValueLoadText = (layouts, target, text) => dynamicNamedRecordText(layouts, { kind: 'dynamic', reason: 'declared-any-never-narrowed' }, target, text) ?? unboxedLoadText(target, text);
4796
+ export const dynamicValueLoadText = (layouts, target, text, selected) => {
4797
+ if (selected !== undefined) {
4798
+ const node = selected.conversion;
4799
+ if (node.source.kind !== 'dynamic' ||
4800
+ node.source.reason === 'untyped-callable' ||
4801
+ representationKey(node.target) !== representationKey(target) ||
4802
+ selected.site.conversions.nodeById(node.id) !== node)
4803
+ return null;
4804
+ return recipeText(selected.site, node, text);
4805
+ }
4806
+ if (dynamicRecordLoadNeedsPlan(target, layouts))
4807
+ return null;
4808
+ return (dynamicNamedRecordText(layouts, { kind: 'dynamic', reason: 'declared-any-never-narrowed' }, target, text) ??
4809
+ unboxedLoadText(target, text));
4810
+ };
4881
4811
  /**
4882
- * An `any` entering a union one arm of which is a native Proxy: mongodb's
4883
- * deps.ts `kerberos = require('kerberos')` into `Module | { kModuleError }`,
4884
- * a slot `makeErrorModule(...)`'s Proxy also fills. No box holds a native
4812
+ * An `any` entering a union one arm of which is a native Proxy: an optional
4813
+ * dependency `dep = require('dep')` into `Module | { kModuleError }`,
4814
+ * a slot an error-module Proxy also fills. No box holds a native
4885
4815
  * Proxy (`dynamicTagFor` refuses one, and `conversion/derive.ts` skips the
4886
4816
  * arm), so the proxy arm is never the destination. Every other arm must be a
4887
4817
  * record the checked dynamic record conversion builds: a box holding that
@@ -4969,7 +4899,7 @@ const expandedNamedRecords = (layouts, target, open) => {
4969
4899
  if (open.has(target.shapeId))
4970
4900
  return null;
4971
4901
  const fields = layouts.forShape(target.shapeId);
4972
- if (fields === null || (layouts.accessorsForShape?.(target.shapeId)?.length ?? 0) !== 0)
4902
+ if (fields === null || (layouts.accessorsForShape(target.shapeId)?.length ?? 0) !== 0)
4973
4903
  return null;
4974
4904
  open.add(target.shapeId);
4975
4905
  const expandedFields = fields.map((field) => {
@@ -4977,7 +4907,7 @@ const expandedNamedRecords = (layouts, target, open) => {
4977
4907
  return value === null ? field : { ...field, value };
4978
4908
  });
4979
4909
  open.delete(target.shapeId);
4980
- const indexes = layouts.indexesForShape?.(target.shapeId) ?? [];
4910
+ const indexes = layouts.indexesForShape(target.shapeId);
4981
4911
  return indexes.length === 0
4982
4912
  ? { kind: 'record', shapeId: target.shapeId, fields: expandedFields, accessors: [], ownership: target.ownership }
4983
4913
  : { kind: 'record-with-index', shapeId: target.shapeId, fields: expandedFields, indexes, ownership: target.ownership };
@@ -4986,12 +4916,240 @@ const expandedNamedRecords = (layouts, target, open) => {
4986
4916
  * The recipe's text with its source evaluated once, however many times the
4987
4917
  * recipe names it -- see `evaluated-once.ts`.
4988
4918
  */
4989
- export const recipeText = (ctx, node, text) => evaluatedOnceText(text, (operand) => renderedRecipeText(ctx, node, operand));
4919
+ export const recipeText = (ctx, node, text) => {
4920
+ if (ctx.conversionIsCertified !== undefined && (ctx.conversions.nodeById(node.id) !== node || !ctx.conversionIsCertified(node.id)))
4921
+ throw createCppEmitBlockedError(`conversion:${node.id}`, 'the conversion dispatcher requires the exact certified recipe');
4922
+ return evaluatedOnceText(text, (operand) => renderedRecipeText(ctx, node, operand));
4923
+ };
4924
+ const dynamicWrapperText = (ctx, plan, node, text) => {
4925
+ if (!dynamicWrapperPlanMatches(plan, node.source, node.target, ctx.conversions.nodeById))
4926
+ return null;
4927
+ const targetType = cppTypeOf(plan.target);
4928
+ if (plan.kind === 'optional') {
4929
+ const payload = recipeText(ctx, plan.payload, text);
4930
+ if (payload === null)
4931
+ return null;
4932
+ const absentTag = plan.target.absence === 'null' ? 'Null' : 'Undefined';
4933
+ return `(${text}.tag() == gea::Value::Tag::${absentTag} ? ${targetType}() : ${targetType}(${payload}))`;
4934
+ }
4935
+ if (plan.kind === 'promise') {
4936
+ const payload = recipeText(ctx, plan.payload, 'gea_settled');
4937
+ return payload === null
4938
+ ? null
4939
+ : `gea::detail::promiseFromDynamic<${cppTypeOf(plan.target.value)}>(${text}, [](const gea::Value& gea_settled) { return ${payload}; })`;
4940
+ }
4941
+ const test = (discriminant) => {
4942
+ if (discriminant.callableMembers !== null) {
4943
+ const membership = discriminant.callableMembers
4944
+ .map((member) => `${text}.callableDeclarationIdentity() == gea::detail::callableDeclarationTagFor<&${cppThunkName(member)}>()`)
4945
+ .join(' || ');
4946
+ return `(${text}.tag() == gea::Value::Tag::Function && (${membership}))`;
4947
+ }
4948
+ if (discriminant.nominal !== null)
4949
+ return (`(${text}.tag() == gea::Value::Tag::Object && ${text}.classObject() && ` +
4950
+ `gea::detail::classIdentityExtends(${text}.classIdentity(), &gea::detail::RefOperationsFor<${discriminant.nominal}>::table))`);
4951
+ return discriminant.payload === null
4952
+ ? `${text}.tag() == gea::Value::Tag::${discriminant.tag}`
4953
+ : `(${text}.tag() == gea::Value::Tag::${discriminant.tag} && ${text}.payloadType() == gea::detail::payloadTypeTagFor<${discriminant.payload}>())`;
4954
+ };
4955
+ const branch = (entry) => {
4956
+ const arm = plan.target.arms[entry.index];
4957
+ if (entry.classifier.id === 'gea::detail::nativeArrayViewAccepts') {
4958
+ if (entry.conversion.capability.kind !== 'atom' || !entry.conversion.capability.materializer.nativeArrayView)
4959
+ return null;
4960
+ const selected = entry.conversion.capability.materializer.nativeArrayView;
4961
+ if (entry.classifier !== entry.conversion.capability.classifier)
4962
+ return null;
4963
+ const value = recipeText(ctx, entry.conversion, text);
4964
+ return value === null
4965
+ ? null
4966
+ : {
4967
+ condition: `gea::detail::${entry.byElements ? 'nativeArrayViewAcceptsExact' : 'nativeArrayViewAccepts'}<${cppTypeOf(selected.target.element)}, ${nativeFieldPolicyType(selected.target.element)}>(${text})`,
4968
+ value: `${targetType}::ofArm<${entry.index}>(${value})`
4969
+ };
4970
+ }
4971
+ const discriminants = boxDiscriminantsOfArm(arm);
4972
+ if (!discriminants?.length)
4973
+ return null;
4974
+ const tagCondition = discriminants.map(test).join(' || ');
4975
+ let condition;
4976
+ if (entry.classifier.id === 'gea::detail::dynamicRecordDiscriminator') {
4977
+ const discriminator = arm.runtimeDiscriminator;
4978
+ const certified = entry.classifier.recordDiscriminator;
4979
+ if (discriminator.kind !== 'record-literal' ||
4980
+ certified === undefined ||
4981
+ certified.key !== discriminator.key ||
4982
+ certified.primitive !== discriminator.primitive ||
4983
+ certified.text !== discriminator.text)
4984
+ return null;
4985
+ const tag = discriminator.primitive === 'string' ? 'String' : discriminator.primitive === 'number' ? 'Number' : 'Boolean';
4986
+ const type = discriminator.primitive === 'string' ? 'std::string' : discriminator.primitive === 'number' ? 'double' : 'bool';
4987
+ const literal = discriminator.primitive === 'string' ? cppStringLiteral(discriminator.text) : discriminator.text;
4988
+ condition =
4989
+ `([](const gea::Value& object, bool nativeRecord) { if (object.tag() != gea::Value::Tag::Object) return false; ` +
4990
+ `const auto value = gea::detail::dynamicRecordDiscriminator(object, ${cppStringLiteral(discriminator.key)}, nativeRecord); ` +
4991
+ `return value.tag() == gea::Value::Tag::${tag} && ` +
4992
+ `gea::detail::unboxValue<${type}>(value, gea::Value::Tag::${tag}, "a union discriminator") == ${literal}; }(${text}, ${tagCondition}))`;
4993
+ }
4994
+ else if (entry.classifier.id === 'gea::Value::tag' ||
4995
+ entry.classifier.id === 'gea::Value::tagAnyOf' ||
4996
+ entry.classifier.id === 'gea::Value::tag+payloadType' ||
4997
+ entry.classifier.id === 'gea::Value::callableDeclarationIdentity' ||
4998
+ entry.classifier.id === 'gea::detail::classIdentityExtends')
4999
+ condition = tagCondition;
5000
+ else
5001
+ return null;
5002
+ const value = recipeText(ctx, entry.conversion, text);
5003
+ return value === null ? null : { condition, value: `${targetType}::ofArm<${entry.index}>(${value})` };
5004
+ };
5005
+ // A record arm read through a live view admits any object holding its
5006
+ // required keys: another instantiation's layout of the same interface, or a
5007
+ // Document. Those shape tests run after every exact test, and an object no
5008
+ // arm admits is the TypeError a program may catch, never an abort.
5009
+ const shaped = plan.arms.filter((entry) => entry.byShape);
5010
+ const elementwise = plan.arms.filter((entry) => entry.byElements);
5011
+ let result = shaped.length === 0 && elementwise.length === 0
5012
+ ? `([]() -> ${targetType} { gea::detail::refusePayloadMismatch("a dynamic value admitted by no union arm"); }())`
5013
+ : `([]() -> ${targetType} { gea::host::throwRuntimeError("TypeError", ${cppStringLiteral("a dynamic value is none of the union's object arms")}); }())`;
5014
+ for (let index = shaped.length - 1; index >= 0; index--) {
5015
+ const entry = shaped[index];
5016
+ const value = plan.target.arms[entry.index].value;
5017
+ const fields = value.kind === 'record' || value.kind === 'record-with-index'
5018
+ ? value.fields
5019
+ : value.kind === 'native-record-ref'
5020
+ ? ctx.layouts.forShape(value.shapeId)
5021
+ : null;
5022
+ if (fields === null || fields.some((field) => field.required && cppRecordFieldKeyIsSymbol(field.key)))
5023
+ return null;
5024
+ const payload = recipeText(ctx, entry.conversion, text);
5025
+ if (payload === null)
5026
+ return null;
5027
+ const condition = [
5028
+ `${text}.tag() == gea::Value::Tag::Object || ${text}.tag() == gea::Value::Tag::Function`,
5029
+ ...fields
5030
+ .filter((field) => field.required)
5031
+ .map((field) => `gea::detail::dynamicRecordHasField(${text}, ${cppStringLiteral(field.key)})`)
5032
+ ];
5033
+ result = `((${condition.join(') && (')}) ? ${targetType}::ofArm<${entry.index}>(${payload}) : ${result})`;
5034
+ }
5035
+ for (let index = elementwise.length - 1; index >= 0; index--) {
5036
+ const entry = elementwise[index];
5037
+ if (entry.conversion.capability.kind !== 'atom' || !entry.conversion.capability.materializer.nativeArrayView)
5038
+ return null;
5039
+ const element = entry.conversion.capability.materializer.nativeArrayView.target.element;
5040
+ const payload = recipeText(ctx, entry.conversion, text);
5041
+ if (payload === null)
5042
+ return null;
5043
+ result =
5044
+ `(gea::detail::nativeArrayViewElementsAccept<${cppTypeOf(element)}, ${nativeFieldPolicyType(element)}>(${text}) ? ` +
5045
+ `${targetType}::ofArm<${entry.index}>(${payload}) : ${result})`;
5046
+ }
5047
+ for (let index = plan.arms.length - 1; index >= 0; index--) {
5048
+ const arm = branch(plan.arms[index]);
5049
+ if (arm === null)
5050
+ return null;
5051
+ result = `(${arm.condition} ? ${arm.value} : ${result})`;
5052
+ }
5053
+ return result;
5054
+ };
4990
5055
  const renderedRecipeText = (ctx, node, text) => {
4991
5056
  if (node.capability.kind === 'identity')
4992
5057
  return text;
4993
5058
  if (node.capability.kind === 'never')
4994
5059
  return null;
5060
+ if (node.capability.kind === 'atom' || node.capability.kind === 'static') {
5061
+ const materializer = node.capability.materializer;
5062
+ if (materializer.nativeArrayView)
5063
+ return nativeArrayViewText(ctx, node, materializer.nativeArrayView, text);
5064
+ if (materializer.dynamicWrapper)
5065
+ return dynamicWrapperText(ctx, materializer.dynamicWrapper, node, text);
5066
+ if (node.source.kind === 'dynamic' &&
5067
+ node.target.kind === 'native-record-ref' &&
5068
+ node.capability.kind === 'atom' &&
5069
+ node.capability.classifier.id === 'gea::Value::payloadType' &&
5070
+ materializer.id === 'gea::detail::unboxValue' &&
5071
+ materializer.nativeFieldProtocol === 'unused' &&
5072
+ materializer.nativePayloadTransport === 'preserved' &&
5073
+ !materializer.allocates)
5074
+ return `gea::detail::unboxValue<${cppTypeOf(node.target)}>(${text}, gea::Value::Tag::Object, ${cppStringLiteral(assertionSite(node.target))})`;
5075
+ if (materializer.id === NATIVE_REFERENCE_ABSENCE) {
5076
+ const absence = nativeReferenceAbsenceOf(node.source, node.target);
5077
+ if (absence === null)
5078
+ return null;
5079
+ return `((void)(${text}), ${cppTypeOf(node.target)}${absence === 'undefined' ? '::undefined()' : '{}'})`;
5080
+ }
5081
+ if (materializer.nativeLogicalReceiver) {
5082
+ const receiver = materializer.nativeLogicalReceiver;
5083
+ const transport = nativeCallReceiverText(receiver.receiver, 'gea_physical_receiver', (source, value) => {
5084
+ const child = receiver.materializers.find((candidate) => representationKey(candidate.source) === representationKey(source));
5085
+ return child === undefined ? null : recipeText(ctx, child, value);
5086
+ });
5087
+ const factory = `+[](const ${cppTypeOf(receiver.receiver)}& gea_physical_receiver) -> gea::NativeCallReceiver { return ${transport}; }`;
5088
+ return unboxedLoadText(node.target, text, factory);
5089
+ }
5090
+ // A boxed constructor adapted to its construct frame: `new` runs through
5091
+ // the box and the census's reader converts what it built.
5092
+ if (materializer.constructedResult && node.target.kind === 'constructor-value-dispatch') {
5093
+ const result = node.target.abi.result;
5094
+ const read = recipeText(ctx, materializer.constructedResult, 'gea_constructed');
5095
+ if (read === null)
5096
+ return null;
5097
+ const reader = `+[](const gea::Value& gea_constructed) -> ${cppTypeOf(result)} { return ${read}; }`;
5098
+ return `gea::detail::DynamicCarrier<${cppTypeOf(node.target)}>::template readWith<${reader}>(${text})`;
5099
+ }
5100
+ if (materializer.dictionaryView)
5101
+ return dictionaryViewText(ctx, materializer.dictionaryView, text);
5102
+ if (materializer.dictionaryRead)
5103
+ return dictionaryReadText(materializer.dictionaryRead, text, (child, value) => recipeText(ctx, child, value));
5104
+ if (materializer.readOnlyDictionary)
5105
+ return dictionaryViewText(ctx, materializer.readOnlyDictionary, text);
5106
+ if (materializer.documentRecordView)
5107
+ return documentRecordViewText(ctx, materializer.documentRecordView, text);
5108
+ if (materializer.nativeDescriptorSnapshot)
5109
+ return nativeDescriptorSnapshotViewText(ctx, materializer.nativeDescriptorSnapshot, text);
5110
+ if (materializer.nativeObjectSample)
5111
+ return nativeObjectSampleText(materializer.nativeObjectSample, text, (child, value) => recipeText(ctx, child, value));
5112
+ if (materializer.recordView)
5113
+ return certifiedRecordViewText(ctx, materializer.recordView, text);
5114
+ if (materializer.recordToArray)
5115
+ return recastedRecordToArrayText(ctx, materializer.recordToArray, text);
5116
+ if (materializer.callableView)
5117
+ return callableViewText(ctx, materializer.callableView, text);
5118
+ if (materializer.callablePayload)
5119
+ return callablePayloadText(ctx, materializer.callablePayload, text);
5120
+ if (materializer.iteratorObjectView)
5121
+ return certifiedIteratorObjectViewText(ctx, materializer.iteratorObjectView, text);
5122
+ if (materializer.iterableObjectView)
5123
+ return certifiedIterableObjectViewText(ctx, materializer.iterableObjectView, text);
5124
+ if (materializer.protocolIterator)
5125
+ return certifiedProtocolIteratorText(ctx, materializer.protocolIterator, text);
5126
+ if (materializer.nativeMethod)
5127
+ return nativeUnboundMethodText(materializer.nativeMethod, text, (child, value) => recipeText(ctx, child, value));
5128
+ if (materializer.nativeMethodResult && node.source.kind === 'class-ref' && node.target.kind === 'class-ref') {
5129
+ const checked = recipeText(ctx, materializer.nativeMethodResult.checked, 'gea_native_method_result');
5130
+ if (checked === null)
5131
+ return null;
5132
+ const target = cppTypeOf(node.target);
5133
+ return (`[&](const ${cppTypeOf(node.source)}& gea_native_method_result) -> ${target} { ` +
5134
+ `if (gea_native_method_result.isUndefined()) return ${target}::undefined(); ` +
5135
+ `if (!gea_native_method_result) return ${target}{}; return ${checked}; }(${text})`);
5136
+ }
5137
+ if (materializer.checkedNativeFieldRead) {
5138
+ if (!checkedNativeFieldReadMismatchOf(node.source, node.target, materializer.checkedNativeFieldRead.checked))
5139
+ return null;
5140
+ return (`[&](const ${cppTypeOf(node.source)}& gea_checked_field) -> ${cppTypeOf(node.target)} { ` +
5141
+ `(void)gea_checked_field; gea::detail::refusePayloadMismatch(${cppStringLiteral(assertionSite(node.target))}); }(${text})`);
5142
+ }
5143
+ if (materializer.id === SIBLING_CLASS_ARGUMENT)
5144
+ return `((void)(${text}), []() -> ${cppTypeOf(node.target)} { gea::host::throwRuntimeError("TypeError", "a value of another instantiation of this generic class was passed"); }())`;
5145
+ if (materializer.id === 'gea::Promise::adopt-converted' && node.source.kind === 'promise' && node.target.kind === 'promise') {
5146
+ return materializer.promiseAdoption
5147
+ ? promiseCompletionText(node.source, node.target, text, materializer.promiseAdoption, (payload, value) => recipeText(ctx, payload, value))
5148
+ : null;
5149
+ }
5150
+ if (materializer.id === IMPOSSIBLE_FIELD_READ || materializer.id === IMPOSSIBLE_INDEX_READ)
5151
+ return `((void)(${text}), gea::host::unreachableValue<${cppTypeOf(node.target)}>())`;
5152
+ }
4995
5153
  if (node.capability.kind === 'coercion')
4996
5154
  return coercionText(node.capability.operation, text, node.source, ctx.layouts);
4997
5155
  if (node.capability.kind === 'class-family')
@@ -5000,7 +5158,8 @@ const renderedRecipeText = (ctx, node, text) => {
5000
5158
  if ((node.capability.kind === 'atom' || node.capability.kind === 'static') &&
5001
5159
  node.capability.materializer.id === 'gea::CallableObject::result-adapter') {
5002
5160
  const known = ctx.knownCallableEntry?.(text) ?? null;
5003
- if (known !== null) {
5161
+ const knownAbi = known === null ? null : ctx.abiOfCallable?.(known);
5162
+ if (known !== null && knownAbi && 'abi' in node.source && abiKey(knownAbi) === abiKey(node.source.abi)) {
5004
5163
  const adapted = resultAdaptedCallableText(node.source, node.target, text, undefined, known);
5005
5164
  if (adapted !== null)
5006
5165
  return adapted;
@@ -5026,6 +5185,9 @@ const renderedRecipeText = (ctx, node, text) => {
5026
5185
  return assertedUnionText(node.source, node.target, text, false);
5027
5186
  if (node.capability.kind === 'static' && node.capability.materializer.id === ASSERTED_UNION_COPY_MATERIALIZER)
5028
5187
  return assertedUnionText(node.source, node.target, text, true);
5188
+ // The census's asserted record-to-class view (`nodes.ts`'s `assertedViewFor`).
5189
+ if (node.capability.kind === 'static' && node.capability.materializer.id === ASSERTED_VIEW_MATERIALIZER)
5190
+ return node.capability.materializer.assertedView ? assertedViewText(ctx, node, node.capability.materializer.assertedView, text) : null;
5029
5191
  // The census's per-arm view (`nodes.ts`'s `armViewFor`).
5030
5192
  if (node.capability.kind === 'static' && node.capability.materializer.id === ARM_VIEW_MATERIALIZER)
5031
5193
  return armViewText(node.source, node.target, text);
@@ -5034,12 +5196,22 @@ const renderedRecipeText = (ctx, node, text) => {
5034
5196
  node.capability.materializer.id === NULLISH_OPTIONAL_MATERIALIZER &&
5035
5197
  node.target.kind === 'optional') {
5036
5198
  const optionalType = cppTypeOf(node.target);
5037
- const payload = dynamicValueLoadText(ctx.layouts, node.target.payload, 'gea_nullish');
5199
+ const payloadNode = node.capability.materializer.dependencies?.find((child) => representationKey(child.source) === representationKey(node.source) &&
5200
+ representationKey(child.target) === representationKey(node.target.kind === 'optional' ? node.target.payload : node.target));
5201
+ if (!payloadNode || ctx.conversions.nodeById(payloadNode.id) !== payloadNode)
5202
+ return null;
5203
+ const payload = recipeText(ctx, payloadNode, 'gea_nullish');
5038
5204
  if (payload === null)
5039
5205
  return null;
5040
5206
  return (`[](const gea::Value& gea_nullish) -> ${optionalType} { return gea_nullish.tag() == gea::Value::Tag::Null || ` +
5041
5207
  `gea_nullish.tag() == gea::Value::Tag::Undefined ? ${optionalType}() : ${optionalType}(${payload}); }(${text})`);
5042
5208
  }
5209
+ // The census's checked class downcast for an `as Derived` receiver
5210
+ // (`nodes.ts`'s `assertedClassDowncastFor`).
5211
+ if (node.capability.kind === 'static' &&
5212
+ node.capability.materializer.id === ASSERTED_CLASS_DOWNCAST_MATERIALIZER &&
5213
+ node.target.kind === 'class-ref')
5214
+ return `gea::host::assertedDowncastClassRef<${cppClassName(node.target.declaration)}>(${text})`;
5043
5215
  // The census's caught-value handoff (`nodes.ts`'s `caughtHandoffFor`).
5044
5216
  if (node.capability.kind === 'static' &&
5045
5217
  node.capability.materializer.id === CAUGHT_HANDOFF_MATERIALIZER &&
@@ -5050,15 +5222,20 @@ const renderedRecipeText = (ctx, node, text) => {
5050
5222
  return checkedArmNarrowingText(node.source, node.target, text);
5051
5223
  // `conversions.ts`'s callable adapter whose parameters need the layouts.
5052
5224
  if (node.capability.kind === 'static' && node.capability.materializer.id === VIEW_ADAPTED_CALLABLE)
5053
- return resultAdaptedCallableText(node.source, node.target, text, (source, target, value) => structuralRecordViewText(ctx, source, target, value));
5225
+ return node.capability.materializer.callableView ? callableViewText(ctx, node.capability.materializer.callableView, text) : null;
5054
5226
  // The census's family-member view (`nodes.ts`'s `familyMemberViewFor`).
5055
5227
  if (node.capability.kind === 'static' && node.capability.materializer.id === FAMILY_MEMBER_VIEW_MATERIALIZER)
5056
5228
  return node.familyMembers === undefined ? null : familyMemberViewText(ctx, node.source, node.target, node.familyMembers, text);
5057
- // `conversions.ts`'s read of a class instance's structural view as the class: the boxed origin, narrowed.
5058
- if (node.capability.kind === 'atom' && node.capability.materializer.id === 'gea::record::viewOrigin')
5059
- return narrowedLoadText({ kind: 'dynamic', reason: 'declared-any-never-narrowed' }, node.target, node.source.kind === 'optional'
5060
- ? `((${text}).has_value() ? gea::record::viewOrigin(*(${text})) : gea::Value())`
5061
- : `gea::record::viewOrigin(${text})`);
5229
+ // Recover the authenticated native class origin of a structural view.
5230
+ if (node.capability.kind === 'atom' &&
5231
+ node.capability.materializer.id === 'gea::record::viewOrigin' &&
5232
+ node.target.kind === 'class-ref') {
5233
+ const target = node.target;
5234
+ const load = (value) => `gea::record::viewOriginClassRef<${cppClassName(target.declaration)}>(${value})`;
5235
+ return node.source.kind === 'optional'
5236
+ ? `((${text}).has_value() ? ${load(`(*${text})`)} : ${cppTypeOf(target)}${node.source.absence === 'null' ? '()' : '::undefined()'})`
5237
+ : load(text);
5238
+ }
5062
5239
  if ((node.capability.kind === 'atom' || node.capability.kind === 'static') && node.capability.materializer.nativeSelection) {
5063
5240
  const helper = ctx.nativeSelectionHelpers?.get(node.id);
5064
5241
  return helper
@@ -5098,82 +5275,6 @@ const renderedRecipeText = (ctx, node, text) => {
5098
5275
  node.capability.materializer.id === CONSTRUCTOR_STATIC_VIEW) {
5099
5276
  return constructorStaticViewText(node.source, node.target, text);
5100
5277
  }
5101
- if ((node.capability.kind === 'static' || node.capability.kind === 'atom') &&
5102
- node.capability.materializer.id === DYNAMIC_DICTIONARY_TO_NAMED_RECORD) {
5103
- const named = node.target.kind === 'optional' ? node.target.payload : node.target;
5104
- if (named.kind !== 'native-record-ref')
5105
- return null;
5106
- const fields = ctx.layouts.forShape(named.shapeId);
5107
- if (fields === null)
5108
- return null;
5109
- // The census lifts the pair through an optional of the same absence
5110
- // (`conversions.ts`): the absent state stays absent, the present one adopts.
5111
- if (node.source.kind === 'optional') {
5112
- if (node.target.kind !== 'optional' || node.source.absence !== node.target.absence)
5113
- return null;
5114
- const present = documentAdoptionText(node.source.payload, named, fields, '(*gea_document)');
5115
- if (present === null)
5116
- return null;
5117
- const targetType = cppTypeOf(node.target);
5118
- return (`[](const ${cppTypeOf(node.source)}& gea_document) -> ${targetType} { ` +
5119
- `return gea_document.has_value() ? ${targetType}(${present}) : ${targetType}(); }(${text})`);
5120
- }
5121
- const adopted = documentAdoptionText(node.source, named, fields, text);
5122
- if (adopted === null || named === node.target)
5123
- return adopted;
5124
- return `${cppTypeOf(node.target)}(${adopted})`;
5125
- }
5126
- // A view that DISPATCHES on a sum's live arm is rendered ahead of the
5127
- // chain: the chain would select the exact arm and trust a narrowing that,
5128
- // at a store, never happened (`narrowedLoadText`'s arm search says why).
5129
- // `conversions.ts`'s `staticRecipe` installs the node in the same order.
5130
- if (node.capability.kind === 'static' && node.capability.materializer.id === 'view:structural-record') {
5131
- const view = viewPlanFor(ctx.layouts, node.source, node.target);
5132
- if (view !== null && recordViewDispatchesArms(view))
5133
- return structuralRecordViewText(ctx, node.source, node.target, text);
5134
- // A whole-sum recast the census chose over the chain: the chain declined
5135
- // the pair (some source arm only WIDENS into the target, so its
5136
- // arm-selecting load would drop that arm -- `taggedUnionArmText`'s
5137
- // `partialWidening`), and the view homes every arm. Rendering the chain
5138
- // here would contradict the node.
5139
- if (unionRecastPlanOf(ctx.layouts, node.source, node.target) !== null)
5140
- return structuralRecordViewText(ctx, node.source, node.target, text);
5141
- }
5142
- // A boxed fulfilment read as a NAMED interface: the layout is resolved here,
5143
- // where the layouts are, exactly as a plain `any -> T` read is
5144
- // (`dynamicNamedRecordText`). mongodb's `findOne` settles
5145
- // `Promise<WithId<TSchema> | null>` with a deserialized BSON Document, and
5146
- // the ctx-free chain read the interface back by identity alone, aborting on
5147
- // every document ("an assertion out of a dynamic value").
5148
- if (node.source.kind === 'promise' && node.target.kind === 'promise') {
5149
- const promiseSource = node.source;
5150
- const promiseTarget = node.target;
5151
- if (dynamicNamedRecordText(ctx.layouts, promiseSource.value, promiseTarget.value, promiseValueName) !== null)
5152
- return promiseAdoptionText(promiseSource, promiseTarget, text, (value) => dynamicNamedRecordText(ctx.layouts, promiseSource.value, promiseTarget.value, value));
5153
- }
5154
- // State adoption whose payload only a record view carries: the chain's own
5155
- // `promise-payload` step asks the ctx-free chain for the payload and cannot
5156
- // see the view, which needs the layouts (`conversions.ts`'s `recasting`
5157
- // admits the pair on the same plan).
5158
- if (node.capability.kind === 'atom' &&
5159
- node.capability.materializer.id === 'gea::Promise::adopt-converted' &&
5160
- node.source.kind === 'promise' &&
5161
- node.target.kind === 'promise') {
5162
- const promiseSource = node.source;
5163
- const promiseTarget = node.target;
5164
- const source = promiseSource.value;
5165
- const target = promiseTarget.value;
5166
- // A view that dispatches -- `IteratorResult`'s arm read off `done` -- wins
5167
- // over the chain, which would pick one arm statically.
5168
- const view = viewPlanFor(ctx.layouts, source, target);
5169
- const viewed = () => promiseAdoptionText(promiseSource, promiseTarget, text, (value) => structuralRecordViewText(ctx, source, target, value));
5170
- if (view !== null && recordViewDispatchesArms(view))
5171
- return viewed();
5172
- const chained = convertedValueText(node.source, node.target, text);
5173
- if (chained !== null)
5174
- return chained;
5175
- return view === null ? null : viewed();
5176
- }
5177
5278
  const adopted = dynamicNamedRecordText(ctx.layouts, node.source, node.target, text);
5178
5279
  if (adopted !== null)
5179
5280
  return adopted;
@@ -5201,16 +5302,19 @@ const renderedRecipeText = (ctx, node, text) => {
5201
5302
  */
5202
5303
  export const namedConversionText = (ctx, site, node, text) => {
5203
5304
  const refused = node.capability.kind === 'never';
5204
- ctx.printerDrift.push({
5205
- owner: String(ctx.owner),
5206
- site,
5207
- kind: refused ? 'refused' : 'converted',
5208
- source: representationKey(node.source),
5209
- target: representationKey(node.target),
5210
- reason: node.capability.kind === 'never' ? node.capability.reason : node.capability.kind,
5211
- sourceRepresentation: node.source,
5212
- targetRepresentation: node.target
5213
- });
5305
+ // A named, certified node is the IR's conversion decision. Drift records
5306
+ // decisions the printer supplies itself, including uncertified named nodes.
5307
+ if (ctx.conversionIsCertified?.(node.id) !== true)
5308
+ ctx.printerDrift.push({
5309
+ owner: String(ctx.owner),
5310
+ site,
5311
+ kind: refused ? 'refused' : 'converted',
5312
+ source: representationKey(node.source),
5313
+ target: representationKey(node.target),
5314
+ reason: node.capability.kind === 'never' ? node.capability.reason : node.capability.kind,
5315
+ sourceRepresentation: node.source,
5316
+ targetRepresentation: node.target
5317
+ });
5214
5318
  return recipeText(ctx, node, text);
5215
5319
  };
5216
5320
  export const convertedValueText = (source, target, text) => {
@@ -5237,33 +5341,17 @@ export const convertedValueText = (source, target, text) => {
5237
5341
  return evaluatedOnceText(text, (operand) => runConversionChain(source, target, operand).text);
5238
5342
  };
5239
5343
  /**
5240
- * Which chain step answers a pair, decided by running the chain on a
5241
- * placeholder: the steps decide from the two carriers alone and only thread
5242
- * the text through, so the answer is the one `convertedValueText` gives. A
5243
- * step that claims the pair but cannot render it is reported with
5244
- * `renders: false`; a pair no step claims is `null`.
5245
- */
5246
- /**
5247
- * Whether this backend can spell a carrier at all. Asked about every pair the
5248
- * registry is probed with -- spelling the same target ten thousand times,
5249
- * catching a throw each time it cannot be, was a measurable share of that
5250
- * loop -- so remembered by identity, as `representationKey`'s own memo is.
5251
- * The mapping's throw is still the answer; `manifest.ts`'s `isSpellable`
5252
- * reads it the same way.
5344
+ * Whether a carrier has physical storage at all: the representation's own
5345
+ * answer (`physicalCarrierKey`), so admissibility is never decided by trying
5346
+ * to print a type and catching the throw. Remembered by identity -- the
5347
+ * registry asks it of every pair it is probed with.
5253
5348
  */
5254
5349
  const spellability = new WeakMap();
5255
5350
  export const isSpellable = (representation) => {
5256
5351
  const known = spellability.get(representation);
5257
5352
  if (known !== undefined)
5258
5353
  return known;
5259
- let spellable;
5260
- try {
5261
- cppTypeOf(representation);
5262
- spellable = true;
5263
- }
5264
- catch {
5265
- spellable = false;
5266
- }
5354
+ const spellable = physicalCarrierKey(representation) !== null;
5267
5355
  spellability.set(representation, spellable);
5268
5356
  return spellable;
5269
5357
  };
@@ -5274,6 +5362,13 @@ export const isSpellable = (representation) => {
5274
5362
  * renders.
5275
5363
  */
5276
5364
  export const chainConverts = (source, target) => isSpellable(source) && isSpellable(target) && (conversionRecipeOf(source, target)?.renders ?? false);
5365
+ /**
5366
+ * Which chain step answers a pair, decided by running the chain on a
5367
+ * placeholder: the steps decide from the two carriers alone and only thread
5368
+ * the text through, so the answer is the one `convertedValueText` gives. A
5369
+ * step that claims the pair but cannot render it is reported with
5370
+ * `renders: false`; a pair no step claims is `null`.
5371
+ */
5277
5372
  export const conversionRecipeOf = (source, target) => {
5278
5373
  if (representationKey(source) === representationKey(target))
5279
5374
  return { id: 'identity', renders: true };
@@ -5301,7 +5396,7 @@ export const conversionRecipeOf = (source, target) => {
5301
5396
  *
5302
5397
  * An `optional` owns whatever its payload owns and nothing else --
5303
5398
  * `gea::Optional<gea::Ref<T>>` is a `Ref` plus a presence bit, and moving it
5304
- * moves the `Ref`. `binary_trees` is the case: `sum(node.left)` reads a
5399
+ * moves the `Ref`. A recursive binary-tree sum is the case: `sum(node.left)` reads a
5305
5400
  * `TreeNode | null` field into a temporary and passes it by value, which is an
5306
5401
  * increment on the way in and a decrement, a branch and an out-of-line
5307
5402
  * destructor on the way out, twice for every one of a million nodes. The
@@ -5312,7 +5407,7 @@ const ownsItsStorage = (carrier) => {
5312
5407
  return true;
5313
5408
  // A box is three counted handles (`gea::Value`'s function, class and held
5314
5409
  // payload references) plus a tag: copying one is three retain/release
5315
- // pairs, moving one is a 48-byte copy and three nulled sources. The bson
5410
+ // pairs, moving one is a 48-byte copy and three nulled sources. A document
5316
5411
  // serializer's per-key loop read each document value into a cell it never
5317
5412
  // read again, and paid the three pairs per key.
5318
5413
  if (carrier.kind === 'dynamic')
@@ -5322,8 +5417,8 @@ const ownsItsStorage = (carrier) => {
5322
5417
  // A sum owns whatever its live arm owns. `gea::TaggedUnion` has a real move
5323
5418
  // constructor (`TaggedUnionOps::moveConstruct`), so a dying union hands its
5324
5419
  // string or reference over instead of `copyConstruct`ing it and then
5325
- // destroying the original -- per header value, per request, in node-compat's
5326
- // `writeHead`, where this was three heap copies of one content-type string.
5420
+ // destroying the original -- per value, per call, where a header-writing hot
5421
+ // path paid three heap copies of one string.
5327
5422
  if (carrier.kind === 'tagged-union')
5328
5423
  return carrier.arms.some((arm) => ownsItsStorage(arm.value));
5329
5424
  // Every counted handle, not only a class instance: a record, an Array, a
@@ -5336,8 +5431,8 @@ const ownsItsStorage = (carrier) => {
5336
5431
  // identity handle each. Only `function` was listed, so a function
5337
5432
  // declaration that needs its identity (`function-value-dispatch`, what
5338
5433
  // `emitter.off(handler)` makes of a hoisted handler) was copied into its
5339
- // own cell -- two retain/release pairs per closure, per mongodb operation
5340
- // for every listener `onData` installs.
5434
+ // own cell -- two retain/release pairs per closure, per operation, for
5435
+ // every listener a hot path installs.
5341
5436
  if (isNativeCallableCarrier(carrier.kind))
5342
5437
  return true;
5343
5438
  return (carrier.kind === 'promise' ||
@@ -5382,7 +5477,7 @@ export const movedValueText = (ctx, value, held, text) => {
5382
5477
  // conversion produced is already a temporary.
5383
5478
  if (held !== null &&
5384
5479
  representationKey(held) !== representationKey(carrier) &&
5385
- !(text === operandText(ctx, value) && cppTypeOf(held) === cppTypeOf(carrier)))
5480
+ !(text === operandText(ctx, value) && samePhysicalCarrier(held, carrier)))
5386
5481
  return text;
5387
5482
  // Two renderers on one argument's path each ask this (a sum-widenable
5388
5483
  // argument is moved into its widening and then into the slot): the second
@@ -5410,20 +5505,9 @@ export const movedValueText = (ctx, value, held, text) => {
5410
5505
  * the held arm is one of them. The source's own absence (if it is optional)
5411
5506
  * reads the result's own absent value instead of testing any arm at all.
5412
5507
  *
5413
- * Each live arm converts into the result's carrier through `convertedValueText`
5414
- * (below) FIRST, unmodified, and only when that finds no installed load AND
5415
- * the result is boolean-shaped (`isBooleanShapedMergeTarget`) does it fall
5416
- * back to `ToBoolean` (`emit-presence.ts`'s `booleanTestText`) instead. That
5417
- * fallback is not a general "any carrier converts to boolean" capability -- it
5418
- * is not added to `convertedValueText`'s own representation-keyed dispatch,
5419
- * which would let it fire for any unrelated occurrence of the same
5420
- * representation pair. It fires only here, for an arm THIS merge's own
5421
- * partial-dead-arm proof already marked live, because a `&&` merge's own
5422
- * published type collapsing to `boolean | undefined` is the checker having
5423
- * already proven the kept contribution meaningful only as its truthiness:
5424
- * ECMA-262's `&&` picks its kept operand by `ToBoolean` in the first place, so
5425
- * restating that answer as a plain `bool` is not a new fact about the arm's
5426
- * carrier, it is the exact question this merge already asked of it.
5508
+ * The finalized plan names the exact recipe for every live arm and absence.
5509
+ * A contextual truthiness arm additionally cites ToBoolean's runtime helper;
5510
+ * certification authenticates its && split before this renderer can use it.
5427
5511
  */
5428
5512
  export const emitMergeLiveArmRebuild = (ctx, lines, operation) => {
5429
5513
  const sourceRepresentation = operation.source.representation;
@@ -5432,36 +5516,24 @@ export const emitMergeLiveArmRebuild = (ctx, lines, operation) => {
5432
5516
  throw createCppEmitBlockedError(`conversion:${representationKey(sourceRepresentation)}->tagged-union`, `rebuilds live arms of ${representationKey(sourceRepresentation)}, which is not a tagged union`);
5433
5517
  }
5434
5518
  const target = operation.result.representation;
5519
+ const plan = operation.mergeConversionPlan;
5520
+ if (!plan || plan.source !== representationKey(sourceRepresentation) || plan.target !== representationKey(target))
5521
+ throw createCppEmitBlockedError('runtime-helper:merge-live-arm-rebuild:conversion-plan', 'a merge has no matching certified arm plan');
5435
5522
  const sourceText = operandText(ctx, operation.source);
5436
5523
  const unwrapped = sourceRepresentation.kind === 'optional' ? `(*${sourceText})` : sourceText;
5437
- const booleanPayload = { kind: 'scalar', domain: 'boolean' };
5438
5524
  const armText = (index) => {
5439
5525
  const arm = payload.arms[index];
5440
5526
  if (!arm) {
5441
5527
  throw createCppEmitBlockedError(`conversion:${representationKey(sourceRepresentation)}->arm-${index}`, `cites live arm ${index} of ${representationKey(sourceRepresentation)}, which has no such arm`);
5442
5528
  }
5443
5529
  const loaded = `${unwrapped}.get<${index}>()`;
5444
- if (operation.nativeTransport) {
5445
- const citation = operation.nativeTransport.arms.find((entry) => entry.index === index);
5446
- const node = citation ? ctx.conversions.nodeById(citation.conversion) : null;
5447
- const text = node ? namedConversionText(ctx, 'emit-narrowing.ts:merge-native-arm', node, loaded) : null;
5448
- if (text !== null)
5449
- return text;
5450
- throw createCppEmitBlockedError(`conversion:${citation?.conversion ?? 'merge-native-arm'}`, 'a sealed native merge arm has no conversion spelling');
5451
- }
5452
- const converted = convertedValueText(arm.value, target, loaded);
5530
+ const citation = plan.arms.find((entry) => entry.index === index);
5531
+ const node = citation ? ctx.conversions.nodeById(citation.conversion) : null;
5532
+ const input = citation?.mode === 'truthiness' ? booleanTestText(loaded, arm.value) : loaded;
5533
+ const converted = node ? namedConversionText(ctx, 'emit-narrowing.ts:merge-arm', node, input) : null;
5453
5534
  if (converted !== null)
5454
5535
  return converted;
5455
- if (isBooleanShapedMergeTarget(target)) {
5456
- const boolText = booleanTestText(loaded, arm.value);
5457
- if (representationKey(target) === representationKey(booleanPayload))
5458
- return boolText;
5459
- const wrapped = convertedValueText(booleanPayload, target, boolText);
5460
- if (wrapped !== null)
5461
- return wrapped;
5462
- }
5463
- throw createCppEmitBlockedError(`conversion:${representationKey(arm.value)}->${representationKey(target)}`, `rebuilds live arm ${index} (${representationKey(arm.value)}) of ${representationKey(sourceRepresentation)} into ` +
5464
- `${representationKey(target)}, which no installed load performs`);
5536
+ throw createCppEmitBlockedError(`conversion:${citation?.conversion ?? 'merge-arm'}`, 'a sealed merge arm has no certified conversion spelling');
5465
5537
  };
5466
5538
  const indices = operation.liveArms;
5467
5539
  const last = indices[indices.length - 1];
@@ -5475,11 +5547,9 @@ export const emitMergeLiveArmRebuild = (ctx, lines, operation) => {
5475
5547
  if (indices.length > 1)
5476
5548
  dispatch = `(${dispatch})`;
5477
5549
  const absenceText = () => {
5478
- const citation = operation.nativeTransport?.absence;
5550
+ const citation = plan.absence;
5479
5551
  if (citation === undefined || sourceRepresentation.kind !== 'optional')
5480
- return sourceRepresentation.kind === 'optional'
5481
- ? cppConstantLiteral(sourceRepresentation.absence, sourceRepresentation.absence, target)
5482
- : '';
5552
+ throw createCppEmitBlockedError('runtime-helper:merge-live-arm-rebuild:conversion-plan', 'a live merge absence names no recipe');
5483
5553
  const node = ctx.conversions.nodeById(citation);
5484
5554
  const text = node
5485
5555
  ? namedConversionText(ctx, 'emit-narrowing.ts:merge-native-absence', node, cppConstantLiteral(sourceRepresentation.absence, sourceRepresentation.absence, { kind: sourceRepresentation.absence }))