@geastack/compiler 1.0.19 → 1.0.21

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 (535) hide show
  1. package/dist/cli-emit.js +11 -1
  2. package/dist/cli-package-source.d.ts +0 -4
  3. package/dist/cli-package-source.js +8 -112
  4. package/dist/cli-refusal-location.d.ts +6 -0
  5. package/dist/cli-refusal-location.js +5 -0
  6. package/dist/cli.js +2 -1
  7. package/dist/compiler.d.ts +4 -0
  8. package/dist/compiler.js +118 -28
  9. package/dist/conversion/algebra.d.ts +16 -1
  10. package/dist/conversion/algebra.js +2 -0
  11. package/dist/conversion/build.js +16 -6
  12. package/dist/conversion/constructor-identity-family.d.ts +49 -0
  13. package/dist/conversion/constructor-identity-family.js +67 -0
  14. package/dist/conversion/derive.js +39 -6
  15. package/dist/conversion/iterable-object-view.d.ts +44 -0
  16. package/dist/conversion/iterable-object-view.js +55 -0
  17. package/dist/conversion/iterator-object-view.d.ts +77 -0
  18. package/dist/conversion/iterator-object-view.js +112 -0
  19. package/dist/conversion/nodes.d.ts +93 -0
  20. package/dist/conversion/nodes.js +262 -5
  21. package/dist/conversion/operand-view.js +41 -0
  22. package/dist/conversion/protocol-iterator.d.ts +84 -0
  23. package/dist/conversion/protocol-iterator.js +88 -0
  24. package/dist/conversion/record-view.d.ts +152 -8
  25. package/dist/conversion/record-view.js +518 -37
  26. package/dist/conversion/registry.d.ts +32 -0
  27. package/dist/ir/borrowed-call-arguments.d.ts +22 -1
  28. package/dist/ir/borrowed-call-arguments.js +102 -1
  29. package/dist/ir/borrowed-callable-uses.d.ts +62 -0
  30. package/dist/ir/borrowed-callable-uses.js +135 -0
  31. package/dist/ir/boxed-bind-assumptions.d.ts +24 -0
  32. package/dist/ir/boxed-bind-assumptions.js +93 -0
  33. package/dist/ir/build.d.ts +18 -7
  34. package/dist/ir/build.js +71 -13
  35. package/dist/ir/call-dispatch.js +474 -10
  36. package/dist/ir/call-entry.d.ts +24 -1
  37. package/dist/ir/call-entry.js +106 -1
  38. package/dist/ir/callable-class-flow.js +15 -5
  39. package/dist/ir/callable-identity-demand.d.ts +20 -1
  40. package/dist/ir/callable-identity-demand.js +157 -18
  41. package/dist/ir/callable-member-candidates.d.ts +11 -1
  42. package/dist/ir/callable-member-candidates.js +82 -3
  43. package/dist/ir/callable-records.js +2 -2
  44. package/dist/ir/callable-site-escape.d.ts +4 -0
  45. package/dist/ir/callable-site-escape.js +228 -0
  46. package/dist/ir/captures.d.ts +10 -1
  47. package/dist/ir/captures.js +219 -4
  48. package/dist/ir/certify/carrier-keys.d.ts +58 -1
  49. package/dist/ir/certify/carrier-keys.js +158 -6
  50. package/dist/ir/certify/property-access-keys.d.ts +17 -0
  51. package/dist/ir/certify/property-access-keys.js +36 -0
  52. package/dist/ir/certify/property-access.js +49 -4
  53. package/dist/ir/certify/runtime-helper.d.ts +4 -0
  54. package/dist/ir/certify/runtime-helper.js +17 -5
  55. package/dist/ir/certify.js +132 -79
  56. package/dist/ir/class-static-fields.d.ts +11 -0
  57. package/dist/ir/class-static-fields.js +28 -0
  58. package/dist/ir/construct-entry.d.ts +2 -1
  59. package/dist/ir/construct-entry.js +3 -2
  60. package/dist/ir/construction-only-fields.d.ts +73 -0
  61. package/dist/ir/construction-only-fields.js +211 -0
  62. package/dist/ir/dominance.d.ts +14 -0
  63. package/dist/ir/dominance.js +18 -4
  64. package/dist/ir/emission-representations.js +4 -1
  65. package/dist/ir/exception-edges.d.ts +17 -0
  66. package/dist/ir/exception-edges.js +75 -0
  67. package/dist/ir/facts.d.ts +54 -3
  68. package/dist/ir/facts.js +182 -5
  69. package/dist/ir/generator-split.js +2 -2
  70. package/dist/ir/instance-reparenting.d.ts +83 -0
  71. package/dist/ir/instance-reparenting.js +167 -0
  72. package/dist/ir/integer-storage.d.ts +29 -0
  73. package/dist/ir/integer-storage.js +188 -79
  74. package/dist/ir/integers.d.ts +16 -0
  75. package/dist/ir/integers.js +327 -8
  76. package/dist/ir/integrity-restrictions.d.ts +42 -9
  77. package/dist/ir/integrity-restrictions.js +335 -42
  78. package/dist/ir/key-order-observation.d.ts +38 -0
  79. package/dist/ir/key-order-observation.js +173 -0
  80. package/dist/ir/literal-set-membership.d.ts +30 -0
  81. package/dist/ir/literal-set-membership.js +277 -0
  82. package/dist/ir/lower-allocation.js +68 -8
  83. package/dist/ir/lower-completion.d.ts +0 -9
  84. package/dist/ir/lower-completion.js +14 -5
  85. package/dist/ir/lower-destructuring.js +24 -2
  86. package/dist/ir/lower-exceptions.js +4 -4
  87. package/dist/ir/lower-flow.d.ts +21 -0
  88. package/dist/ir/lower-flow.js +37 -3
  89. package/dist/ir/lower-graph.d.ts +19 -1
  90. package/dist/ir/lower-graph.js +91 -67
  91. package/dist/ir/lower-invocation.d.ts +16 -0
  92. package/dist/ir/lower-invocation.js +182 -28
  93. package/dist/ir/lower-narrow.d.ts +0 -46
  94. package/dist/ir/lower-narrow.js +63 -1
  95. package/dist/ir/lower-operands.d.ts +52 -2
  96. package/dist/ir/lower-operands.js +491 -8
  97. package/dist/ir/lower-property.d.ts +2 -1
  98. package/dist/ir/lower-property.js +140 -31
  99. package/dist/ir/lower-protocol.js +16 -4
  100. package/dist/ir/lower-proxy.d.ts +65 -0
  101. package/dist/ir/lower-proxy.js +181 -0
  102. package/dist/ir/lower.js +112 -17
  103. package/dist/ir/model.d.ts +228 -18
  104. package/dist/ir/native-class-accessor.d.ts +9 -2
  105. package/dist/ir/native-class-accessor.js +12 -3
  106. package/dist/ir/native-class-construction.d.ts +1 -1
  107. package/dist/ir/native-class-construction.js +2 -1
  108. package/dist/ir/native-class-initialization.js +2 -2
  109. package/dist/ir/object-value-conversions.js +20 -5
  110. package/dist/ir/operation-index.d.ts +16 -0
  111. package/dist/ir/operation-index.js +17 -0
  112. package/dist/ir/pcm-loops.d.ts +11 -0
  113. package/dist/ir/pcm-loops.js +284 -0
  114. package/dist/ir/presence-proof.js +5 -0
  115. package/dist/ir/program-facts.d.ts +10 -20
  116. package/dist/ir/program-facts.js +80 -6
  117. package/dist/ir/proven-branches.d.ts +2 -2
  118. package/dist/ir/proven-branches.js +196 -3
  119. package/dist/ir/queries.js +35 -1
  120. package/dist/ir/reflection-demand.d.ts +9 -4
  121. package/dist/ir/reflection-demand.js +400 -28
  122. package/dist/ir/refusal.d.ts +1 -0
  123. package/dist/ir/refusal.js +2 -1
  124. package/dist/ir/shake.d.ts +94 -1
  125. package/dist/ir/shake.js +209 -12
  126. package/dist/ir/shared-empty-records.d.ts +12 -0
  127. package/dist/ir/shared-empty-records.js +301 -0
  128. package/dist/ir/spread-copy-elision.d.ts +59 -0
  129. package/dist/ir/spread-copy-elision.js +431 -0
  130. package/dist/ir/stable-cell-reads.d.ts +40 -0
  131. package/dist/ir/stable-cell-reads.js +123 -0
  132. package/dist/ir/static-callables.js +50 -0
  133. package/dist/ir/string-layout-reuse.d.ts +16 -1
  134. package/dist/ir/string-layout-reuse.js +66 -0
  135. package/dist/ir/transfer.d.ts +72 -3
  136. package/dist/ir/transfer.js +511 -19
  137. package/dist/ir/typed-property-access.d.ts +18 -2
  138. package/dist/ir/typed-property-access.js +109 -12
  139. package/dist/ir/verify.js +2 -1
  140. package/dist/plugins/apple/plugin.js +3 -2
  141. package/dist/plugins/gea/host.d.ts +7 -0
  142. package/dist/plugins/gea/host.js +30 -1
  143. package/dist/plugins/gea/lower.js +6 -1
  144. package/dist/plugins/gea/plugin.js +7 -4
  145. package/dist/plugins/gea/prelude.js +5 -1
  146. package/dist/plugins/gea/render-bridge.d.ts +4 -2
  147. package/dist/plugins/gea/render-bridge.js +23 -7
  148. package/dist/plugins/model.d.ts +2 -0
  149. package/dist/project-preparation.d.ts +5 -1
  150. package/dist/project-preparation.js +164 -7
  151. package/dist/projection/bindings.d.ts +5 -2
  152. package/dist/projection/bindings.js +40 -1
  153. package/dist/projection/callee.d.ts +16 -0
  154. package/dist/projection/callee.js +35 -6
  155. package/dist/projection/class-prototype.js +5 -1
  156. package/dist/projection/classes.d.ts +65 -2
  157. package/dist/projection/classes.js +159 -2
  158. package/dist/projection/dispatch.d.ts +69 -18
  159. package/dist/projection/dispatch.js +391 -19
  160. package/dist/projection/fields.d.ts +4 -3
  161. package/dist/projection/fields.js +89 -21
  162. package/dist/projection/instance-test.d.ts +12 -0
  163. package/dist/projection/instance-test.js +40 -10
  164. package/dist/projection/method-value-escapes.d.ts +43 -0
  165. package/dist/projection/method-value-escapes.js +113 -0
  166. package/dist/projection/slots.d.ts +34 -1
  167. package/dist/projection/slots.js +82 -5
  168. package/dist/representation/any-null-record-members.d.ts +41 -0
  169. package/dist/representation/any-null-record-members.js +115 -0
  170. package/dist/representation/collections.d.ts +3 -1
  171. package/dist/representation/collections.js +5 -2
  172. package/dist/representation/derive.d.ts +9 -1
  173. package/dist/representation/derive.js +366 -25
  174. package/dist/representation/difference.js +14 -0
  175. package/dist/representation/embedded-carriers.js +1 -0
  176. package/dist/representation/host-abi.d.ts +15 -0
  177. package/dist/representation/host-abi.js +28 -0
  178. package/dist/representation/host-templates.d.ts +1 -1
  179. package/dist/representation/host-templates.js +7 -3
  180. package/dist/representation/intersection.js +22 -0
  181. package/dist/representation/json-nullable.d.ts +18 -0
  182. package/dist/representation/json-nullable.js +22 -0
  183. package/dist/representation/model.d.ts +141 -0
  184. package/dist/representation/model.js +47 -3
  185. package/dist/representation/object-shape.d.ts +5 -1
  186. package/dist/representation/object-shape.js +5 -2
  187. package/dist/representation/policies.d.ts +66 -1
  188. package/dist/representation/proxy-carriers.d.ts +71 -0
  189. package/dist/representation/proxy-carriers.js +330 -0
  190. package/dist/representation/publish.d.ts +9 -1
  191. package/dist/representation/publish.js +186 -18
  192. package/dist/representation/record-fields.d.ts +5 -0
  193. package/dist/representation/record-fields.js +7 -1
  194. package/dist/representation/static-field-cells.d.ts +61 -0
  195. package/dist/representation/static-field-cells.js +80 -0
  196. package/dist/representation/unassigned-binding-cells.d.ts +32 -0
  197. package/dist/representation/unassigned-binding-cells.js +44 -0
  198. package/dist/representation/union.js +17 -1
  199. package/dist/representation/unwritten-record-members.d.ts +54 -0
  200. package/dist/representation/unwritten-record-members.js +167 -0
  201. package/dist/representation/value-records.js +153 -11
  202. package/dist/semantics/ambient.d.ts +102 -0
  203. package/dist/semantics/ambient.js +183 -0
  204. package/dist/semantics/any-null-member-declarations.d.ts +32 -0
  205. package/dist/semantics/any-null-member-declarations.js +90 -0
  206. package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +14 -0
  207. package/dist/semantics/borrowed-method-receiver-copy-source-transform.d.ts +51 -0
  208. package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +367 -0
  209. package/dist/semantics/call-invalidated-narrowing.d.ts +3 -0
  210. package/dist/semantics/call-invalidated-narrowing.js +715 -0
  211. package/dist/semantics/callable-origins.d.ts +39 -0
  212. package/dist/semantics/callable-origins.js +73 -2
  213. package/dist/semantics/class-alias.d.ts +21 -0
  214. package/dist/semantics/class-alias.js +45 -14
  215. package/dist/semantics/class-heritage.d.ts +64 -0
  216. package/dist/semantics/class-heritage.js +278 -2
  217. package/dist/semantics/commonjs-wrapper.d.ts +1 -1
  218. package/dist/semantics/commonjs-wrapper.js +24 -7
  219. package/dist/semantics/constructor-function-class-source-transform.d.ts +4 -0
  220. package/dist/semantics/constructor-function-class-source-transform.js +327 -0
  221. package/dist/semantics/constructor-slot-subclasses.js +163 -4
  222. package/dist/semantics/declaration-overlay-transform.js +197 -3
  223. package/dist/semantics/frontend.d.ts +31 -0
  224. package/dist/semantics/frontend.js +177 -19
  225. package/dist/semantics/host-methods.d.ts +27 -2
  226. package/dist/semantics/host-methods.js +57 -4
  227. package/dist/semantics/host-protocols.d.ts +19 -8
  228. package/dist/semantics/host-protocols.js +145 -31
  229. package/dist/semantics/interface-families.d.ts +51 -2
  230. package/dist/semantics/interface-families.js +609 -23
  231. package/dist/semantics/interface-implementors.d.ts +20 -0
  232. package/dist/semantics/interface-implementors.js +130 -6
  233. package/dist/semantics/known-caller-predicate-parameters.d.ts +2 -0
  234. package/dist/semantics/known-caller-predicate-parameters.js +161 -0
  235. package/dist/semantics/model/intrinsic-accessor-getters.d.ts +10 -0
  236. package/dist/semantics/model/intrinsic-accessor-getters.js +4 -0
  237. package/dist/semantics/model/operands.d.ts +10 -0
  238. package/dist/semantics/model/operations.d.ts +107 -0
  239. package/dist/semantics/model/selected-signature.d.ts +33 -0
  240. package/dist/semantics/model/structural-type-table.d.ts +15 -0
  241. package/dist/semantics/model/structural-type-table.js +19 -1
  242. package/dist/semantics/model/structural-types.d.ts +99 -0
  243. package/dist/semantics/model/structural-types.js +31 -2
  244. package/dist/semantics/normalize/absent-globals.d.ts +1 -1
  245. package/dist/semantics/normalize/absent-globals.js +3 -3
  246. package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +46 -0
  247. package/dist/semantics/normalize/bivariant-slot-parameter.js +357 -0
  248. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +2 -0
  249. package/dist/semantics/normalize/callback-parameter-contracts.js +21 -0
  250. package/dist/semantics/normalize/census.d.ts +2 -1
  251. package/dist/semantics/normalize/census.js +25 -2
  252. package/dist/semantics/normalize/class-instance-record-statement.d.ts +37 -0
  253. package/dist/semantics/normalize/class-instance-record-statement.js +74 -0
  254. package/dist/semantics/normalize/collection-bindings.js +242 -5
  255. package/dist/semantics/normalize/commonjs-require.d.ts +26 -0
  256. package/dist/semantics/normalize/commonjs-require.js +355 -121
  257. package/dist/semantics/normalize/dead-event-emissions.d.ts +6 -0
  258. package/dist/semantics/normalize/dead-event-emissions.js +866 -0
  259. package/dist/semantics/normalize/dead-method-copies.d.ts +56 -0
  260. package/dist/semantics/normalize/dead-method-copies.js +239 -0
  261. package/dist/semantics/normalize/derived-expression-type.d.ts +149 -2
  262. package/dist/semantics/normalize/derived-expression-type.js +418 -14
  263. package/dist/semantics/normalize/field-bindings.js +139 -4
  264. package/dist/semantics/normalize/flow/callable-reach.js +162 -9
  265. package/dist/semantics/normalize/flow/member-call-forwarding.js +6 -0
  266. package/dist/semantics/normalize/flow/owned-class-receivers.js +40 -2
  267. package/dist/semantics/normalize/flow/source-class-data.d.ts +7 -1
  268. package/dist/semantics/normalize/flow/source-class-data.js +28 -9
  269. package/dist/semantics/normalize/flow/source-value-session.js +32 -13
  270. package/dist/semantics/normalize/flow/targets.d.ts +32 -0
  271. package/dist/semantics/normalize/flow/targets.js +65 -6
  272. package/dist/semantics/normalize/flow/value-flow.d.ts +7 -0
  273. package/dist/semantics/normalize/flow/value-flow.js +30 -2
  274. package/dist/semantics/normalize/fresh-array-result.d.ts +32 -0
  275. package/dist/semantics/normalize/fresh-array-result.js +125 -0
  276. package/dist/semantics/normalize/gating.js +2 -0
  277. package/dist/semantics/normalize/global-host-mutations.d.ts +11 -1
  278. package/dist/semantics/normalize/global-host-mutations.js +691 -27
  279. package/dist/semantics/normalize/host-effect-contracts.d.ts +43 -1
  280. package/dist/semantics/normalize/host-effect-contracts.js +60 -3
  281. package/dist/semantics/normalize/identities.js +49 -3
  282. package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +59 -0
  283. package/dist/semantics/normalize/intrinsic-accessor-getter.js +129 -0
  284. package/dist/semantics/normalize/local-bindings.js +117 -21
  285. package/dist/semantics/normalize/merged-declaration.d.ts +41 -0
  286. package/dist/semantics/normalize/merged-declaration.js +81 -0
  287. package/dist/semantics/normalize/never-override-result.d.ts +21 -0
  288. package/dist/semantics/normalize/never-override-result.js +64 -0
  289. package/dist/semantics/normalize/null-blind-parameter.d.ts +21 -0
  290. package/dist/semantics/normalize/null-blind-parameter.js +77 -0
  291. package/dist/semantics/normalize/object-bag-bindings.js +10 -0
  292. package/dist/semantics/normalize/override-field-arms.d.ts +33 -0
  293. package/dist/semantics/normalize/override-field-arms.js +362 -0
  294. package/dist/semantics/normalize/parameter-bindings.d.ts +64 -1
  295. package/dist/semantics/normalize/parameter-bindings.js +801 -81
  296. package/dist/semantics/normalize/parameter-slot.d.ts +1 -0
  297. package/dist/semantics/normalize/parameter-slot.js +69 -0
  298. package/dist/semantics/normalize/physical-overload-result.d.ts +45 -0
  299. package/dist/semantics/normalize/physical-overload-result.js +132 -0
  300. package/dist/semantics/normalize/producer-context.d.ts +23 -0
  301. package/dist/semantics/normalize/producers/allocations.d.ts +13 -0
  302. package/dist/semantics/normalize/producers/allocations.js +8 -15
  303. package/dist/semantics/normalize/producers/binding-kind.d.ts +11 -0
  304. package/dist/semantics/normalize/producers/binding-kind.js +31 -0
  305. package/dist/semantics/normalize/producers/bindings.js +16 -1
  306. package/dist/semantics/normalize/producers/boundary.js +21 -1
  307. package/dist/semantics/normalize/producers/class-lifecycle.js +23 -14
  308. package/dist/semantics/normalize/producers/computations.js +8 -67
  309. package/dist/semantics/normalize/producers/control-loops.d.ts +1 -1
  310. package/dist/semantics/normalize/producers/control-loops.js +25 -1
  311. package/dist/semantics/normalize/producers/control.js +87 -60
  312. package/dist/semantics/normalize/producers/declaration-lifecycle.js +5 -0
  313. package/dist/semantics/normalize/producers/enums.d.ts +10 -0
  314. package/dist/semantics/normalize/producers/enums.js +169 -0
  315. package/dist/semantics/normalize/producers/erasure.d.ts +10 -0
  316. package/dist/semantics/normalize/producers/erasure.js +23 -0
  317. package/dist/semantics/normalize/producers/intrinsic-accessor-getter.d.ts +15 -0
  318. package/dist/semantics/normalize/producers/intrinsic-accessor-getter.js +33 -0
  319. package/dist/semantics/normalize/producers/invocations.js +255 -18
  320. package/dist/semantics/normalize/producers/iteration-yield.js +6 -1
  321. package/dist/semantics/normalize/producers/logical-merge-type.d.ts +36 -0
  322. package/dist/semantics/normalize/producers/logical-merge-type.js +163 -0
  323. package/dist/semantics/normalize/producers/properties.js +207 -18
  324. package/dist/semantics/normalize/producers/protocol.d.ts +4 -0
  325. package/dist/semantics/normalize/producers/protocol.js +147 -12
  326. package/dist/semantics/normalize/producers/references.js +50 -9
  327. package/dist/semantics/normalize/producers/shared.d.ts +120 -0
  328. package/dist/semantics/normalize/producers/shared.js +359 -10
  329. package/dist/semantics/normalize/producers/spread-arguments.js +85 -4
  330. package/dist/semantics/normalize/producers/tuple-spread.d.ts +1 -0
  331. package/dist/semantics/normalize/producers/tuple-spread.js +1 -1
  332. package/dist/semantics/normalize/property-key-domain.js +6 -0
  333. package/dist/semantics/normalize/reachability.d.ts +7 -0
  334. package/dist/semantics/normalize/reachability.js +166 -9
  335. package/dist/semantics/normalize/record-home-arms.d.ts +25 -0
  336. package/dist/semantics/normalize/record-home-arms.js +87 -0
  337. package/dist/semantics/normalize/record-link-families.d.ts +74 -0
  338. package/dist/semantics/normalize/record-link-families.js +327 -0
  339. package/dist/semantics/normalize/record-stand-in-arms.d.ts +56 -0
  340. package/dist/semantics/normalize/record-stand-in-arms.js +484 -0
  341. package/dist/semantics/normalize/return-bindings.d.ts +6 -2
  342. package/dist/semantics/normalize/return-bindings.js +60 -7
  343. package/dist/semantics/normalize/script-global-redefinition.js +5 -0
  344. package/dist/semantics/normalize/shared-array-storage.d.ts +42 -0
  345. package/dist/semantics/normalize/shared-array-storage.js +373 -0
  346. package/dist/semantics/normalize/sloppy-absence.d.ts +41 -0
  347. package/dist/semantics/normalize/sloppy-absence.js +199 -0
  348. package/dist/semantics/normalize/specialization.d.ts +40 -0
  349. package/dist/semantics/normalize/specialization.js +770 -36
  350. package/dist/semantics/normalize/structural-array-element.js +196 -6
  351. package/dist/semantics/normalize/structural-array-read.js +12 -0
  352. package/dist/semantics/normalize/structural-creation-order.d.ts +15 -0
  353. package/dist/semantics/normalize/structural-creation-order.js +51 -48
  354. package/dist/semantics/normalize/structural-declarations.d.ts +16 -0
  355. package/dist/semantics/normalize/structural-declarations.js +43 -0
  356. package/dist/semantics/normalize/structural-generics.d.ts +13 -0
  357. package/dist/semantics/normalize/structural-generics.js +22 -0
  358. package/dist/semantics/normalize/structural-indexed-access.js +16 -0
  359. package/dist/semantics/normalize/structural-instantiated-member.js +68 -2
  360. package/dist/semantics/normalize/structural-joins.js +2 -0
  361. package/dist/semantics/normalize/structural-layout-relevance.d.ts +30 -0
  362. package/dist/semantics/normalize/structural-layout-relevance.js +164 -0
  363. package/dist/semantics/normalize/structural-layout-type.js +270 -14
  364. package/dist/semantics/normalize/structural-leaves.d.ts +1 -1
  365. package/dist/semantics/normalize/structural-leaves.js +17 -3
  366. package/dist/semantics/normalize/structural-mutable-method.js +5 -1
  367. package/dist/semantics/normalize/structural-parts.d.ts +18 -5
  368. package/dist/semantics/normalize/structural-parts.js +68 -19
  369. package/dist/semantics/normalize/structural-receiver.d.ts +1 -1
  370. package/dist/semantics/normalize/structural-receiver.js +23 -1
  371. package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
  372. package/dist/semantics/normalize/structural-self-reference.js +23 -2
  373. package/dist/semantics/normalize/structural.d.ts +12 -1
  374. package/dist/semantics/normalize/structural.js +1420 -53
  375. package/dist/semantics/normalize/suppressed-write-arms.d.ts +47 -0
  376. package/dist/semantics/normalize/suppressed-write-arms.js +393 -0
  377. package/dist/semantics/normalize/unresolvable-names.d.ts +15 -2
  378. package/dist/semantics/normalize/unresolvable-names.js +30 -6
  379. package/dist/semantics/normalize/unshared-array-result.d.ts +32 -0
  380. package/dist/semantics/normalize/unshared-array-result.js +125 -0
  381. package/dist/semantics/package-sources.d.ts +1 -1
  382. package/dist/semantics/package-sources.js +120 -8
  383. package/dist/semantics/program.d.ts +20 -0
  384. package/dist/semantics/program.js +145 -14
  385. package/dist/semantics/stable-checker.d.ts +1 -1
  386. package/dist/semantics/stable-checker.js +7 -2
  387. package/dist/semantics/unchecked-guard-argument-copies.d.ts +67 -0
  388. package/dist/semantics/unchecked-guard-argument-copies.js +163 -0
  389. package/dist/semantics/unchecked-write-member-declarations.d.ts +46 -0
  390. package/dist/semantics/unchecked-write-member-declarations.js +331 -0
  391. package/dist/targets/cpp/balanced-units.d.ts +31 -0
  392. package/dist/targets/cpp/balanced-units.js +57 -0
  393. package/dist/targets/cpp/borrowed-arm-projections.d.ts +31 -0
  394. package/dist/targets/cpp/borrowed-arm-projections.js +106 -0
  395. package/dist/targets/cpp/borrowed-call-entry.d.ts +1 -1
  396. package/dist/targets/cpp/borrowed-call-entry.js +24 -20
  397. package/dist/targets/cpp/captures.js +314 -8
  398. package/dist/targets/cpp/char-code-buffers.d.ts +36 -0
  399. package/dist/targets/cpp/char-code-buffers.js +214 -0
  400. package/dist/targets/cpp/class-layout.d.ts +7 -1
  401. package/dist/targets/cpp/class-layout.js +42 -17
  402. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +17 -2
  403. package/dist/targets/cpp/class-properties/computed-method-value.js +50 -4
  404. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +31 -1
  405. package/dist/targets/cpp/class-properties/emit-class-properties.js +174 -17
  406. package/dist/targets/cpp/class-ref-transport.d.ts +32 -0
  407. package/dist/targets/cpp/class-ref-transport.js +56 -1
  408. package/dist/targets/cpp/conversions.js +1827 -1502
  409. package/dist/targets/cpp/coroutine-bodies.d.ts +97 -0
  410. package/dist/targets/cpp/coroutine-bodies.js +187 -0
  411. package/dist/targets/cpp/document.js +11 -1
  412. package/dist/targets/cpp/emit-allocation.js +535 -21
  413. package/dist/targets/cpp/emit-arrays.d.ts +10 -0
  414. package/dist/targets/cpp/emit-arrays.js +147 -16
  415. package/dist/targets/cpp/emit-binding-reference.d.ts +26 -2
  416. package/dist/targets/cpp/emit-binding-reference.js +97 -5
  417. package/dist/targets/cpp/emit-bindings.d.ts +9 -1
  418. package/dist/targets/cpp/emit-bindings.js +108 -8
  419. package/dist/targets/cpp/emit-buffers.d.ts +2 -16
  420. package/dist/targets/cpp/emit-buffers.js +124 -25
  421. package/dist/targets/cpp/emit-callable.d.ts +35 -72
  422. package/dist/targets/cpp/emit-callable.js +647 -82
  423. package/dist/targets/cpp/emit-carrier-members.d.ts +13 -2
  424. package/dist/targets/cpp/emit-carrier-members.js +50 -9
  425. package/dist/targets/cpp/emit-constructor-identity-family.d.ts +20 -0
  426. package/dist/targets/cpp/emit-constructor-identity-family.js +45 -0
  427. package/dist/targets/cpp/emit-context.d.ts +329 -15
  428. package/dist/targets/cpp/emit-context.js +104 -13
  429. package/dist/targets/cpp/emit-dynamic-properties.d.ts +44 -0
  430. package/dist/targets/cpp/emit-dynamic-properties.js +256 -37
  431. package/dist/targets/cpp/emit-equality.js +117 -2
  432. package/dist/targets/cpp/emit-error-constructor.d.ts +19 -0
  433. package/dist/targets/cpp/emit-error-constructor.js +73 -0
  434. package/dist/targets/cpp/emit-exceptions.d.ts +25 -3
  435. package/dist/targets/cpp/emit-exceptions.js +215 -26
  436. package/dist/targets/cpp/emit-in.js +52 -5
  437. package/dist/targets/cpp/emit-instanceof.js +59 -11
  438. package/dist/targets/cpp/emit-integers.d.ts +6 -0
  439. package/dist/targets/cpp/emit-integers.js +10 -0
  440. package/dist/targets/cpp/emit-iterable-object-view.d.ts +15 -0
  441. package/dist/targets/cpp/emit-iterable-object-view.js +51 -0
  442. package/dist/targets/cpp/emit-iterator-object-view.d.ts +15 -0
  443. package/dist/targets/cpp/emit-iterator-object-view.js +125 -0
  444. package/dist/targets/cpp/emit-iterator.d.ts +7 -10
  445. package/dist/targets/cpp/emit-iterator.js +361 -24
  446. package/dist/targets/cpp/emit-json.d.ts +7 -1
  447. package/dist/targets/cpp/emit-json.js +594 -54
  448. package/dist/targets/cpp/emit-jsx.d.ts +0 -37
  449. package/dist/targets/cpp/emit-jsx.js +70 -8
  450. package/dist/targets/cpp/emit-narrowing.d.ts +192 -28
  451. package/dist/targets/cpp/emit-narrowing.js +1595 -120
  452. package/dist/targets/cpp/emit-native-selection.js +8 -2
  453. package/dist/targets/cpp/emit-presence.js +13 -0
  454. package/dist/targets/cpp/emit-properties.d.ts +3 -1
  455. package/dist/targets/cpp/emit-properties.js +303 -54
  456. package/dist/targets/cpp/emit-protocol-iterator.d.ts +14 -0
  457. package/dist/targets/cpp/emit-protocol-iterator.js +203 -0
  458. package/dist/targets/cpp/emit-proxy.d.ts +17 -0
  459. package/dist/targets/cpp/emit-proxy.js +35 -0
  460. package/dist/targets/cpp/emit-record-view.d.ts +12 -1
  461. package/dist/targets/cpp/emit-record-view.js +429 -18
  462. package/dist/targets/cpp/emit-return.d.ts +38 -0
  463. package/dist/targets/cpp/emit-return.js +143 -21
  464. package/dist/targets/cpp/emit-scopes.d.ts +78 -0
  465. package/dist/targets/cpp/emit-scopes.js +196 -0
  466. package/dist/targets/cpp/emit-sum-widening.js +6 -3
  467. package/dist/targets/cpp/emit-tonumber.d.ts +40 -1
  468. package/dist/targets/cpp/emit-tonumber.js +75 -4
  469. package/dist/targets/cpp/emit-tostring.d.ts +28 -2
  470. package/dist/targets/cpp/emit-tostring.js +115 -12
  471. package/dist/targets/cpp/emit-typeof.js +2 -2
  472. package/dist/targets/cpp/emit-union-properties.d.ts +9 -0
  473. package/dist/targets/cpp/emit-union-properties.js +375 -46
  474. package/dist/targets/cpp/emit.d.ts +3 -1
  475. package/dist/targets/cpp/emit.js +725 -90
  476. package/dist/targets/cpp/evaluated-once.d.ts +51 -0
  477. package/dist/targets/cpp/evaluated-once.js +140 -0
  478. package/dist/targets/cpp/host/core-globals.d.ts +0 -21
  479. package/dist/targets/cpp/host/core-globals.js +10 -2
  480. package/dist/targets/cpp/host/emit-host-invoke.d.ts +0 -10
  481. package/dist/targets/cpp/host/emit-host-invoke.js +454 -36
  482. package/dist/targets/cpp/host/emit-host-object.js +733 -88
  483. package/dist/targets/cpp/host/emit-host-properties.js +26 -2
  484. package/dist/targets/cpp/host/emit-host-reflect.d.ts +1 -0
  485. package/dist/targets/cpp/host/emit-host-reflect.js +26 -7
  486. package/dist/targets/cpp/host/emit-host-value.d.ts +13 -0
  487. package/dist/targets/cpp/host/emit-host-value.js +48 -4
  488. package/dist/targets/cpp/host/host-members.d.ts +11 -0
  489. package/dist/targets/cpp/host/host-members.js +50 -4
  490. package/dist/targets/cpp/host/native-protocols.js +3 -0
  491. package/dist/targets/cpp/host/object-protocol.d.ts +8 -0
  492. package/dist/targets/cpp/host/object-protocol.js +55 -13
  493. package/dist/targets/cpp/key-order-tracking.d.ts +11 -0
  494. package/dist/targets/cpp/key-order-tracking.js +18 -0
  495. package/dist/targets/cpp/manifest/capabilities.js +107 -8
  496. package/dist/targets/cpp/manifest.js +14 -0
  497. package/dist/targets/cpp/native-collection-base.d.ts +27 -0
  498. package/dist/targets/cpp/native-collection-base.js +202 -0
  499. package/dist/targets/cpp/native-error-base.d.ts +14 -0
  500. package/dist/targets/cpp/native-error-base.js +19 -4
  501. package/dist/targets/cpp/native-promise-base.d.ts +23 -0
  502. package/dist/targets/cpp/native-promise-base.js +30 -0
  503. package/dist/targets/cpp/native-symbol-keys.js +1 -1
  504. package/dist/targets/cpp/prototype/emit-prototype-array.js +258 -20
  505. package/dist/targets/cpp/prototype/emit-prototype-date.js +5 -4
  506. package/dist/targets/cpp/prototype/emit-prototype-invoke.d.ts +9 -1
  507. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +232 -26
  508. package/dist/targets/cpp/prototype/emit-prototype-iterator.d.ts +1 -1
  509. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +111 -13
  510. package/dist/targets/cpp/prototype/emit-prototype-promise.d.ts +33 -4
  511. package/dist/targets/cpp/prototype/emit-prototype-promise.js +218 -10
  512. package/dist/targets/cpp/prototype/emit-prototype-regexp.js +8 -5
  513. package/dist/targets/cpp/prototype/emit-prototype-string.js +24 -7
  514. package/dist/targets/cpp/prototype/prototype-method-reads.js +18 -3
  515. package/dist/targets/cpp/reactive-dependencies.d.ts +2 -0
  516. package/dist/targets/cpp/reactive-dependencies.js +94 -3
  517. package/dist/targets/cpp/realm-storage.d.ts +5 -0
  518. package/dist/targets/cpp/realm-storage.js +12 -0
  519. package/dist/targets/cpp/records.d.ts +151 -1
  520. package/dist/targets/cpp/records.js +1321 -122
  521. package/dist/targets/cpp/recursive-containers.d.ts +4 -1
  522. package/dist/targets/cpp/recursive-containers.js +28 -9
  523. package/dist/targets/cpp/translation-unit.d.ts +10 -0
  524. package/dist/targets/cpp/translation-unit.js +686 -140
  525. package/dist/targets/cpp/types.d.ts +56 -6
  526. package/dist/targets/cpp/types.js +218 -12
  527. package/dist/targets/cpp/virtual-methods.d.ts +3 -3
  528. package/dist/targets/cpp/virtual-methods.js +174 -17
  529. package/package.json +6 -5
  530. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +155 -25
  531. package/src/targets/cpp/runtime/gea_eval.h +3 -0
  532. package/src/targets/cpp/runtime/gea_pcm.h +116 -0
  533. package/src/targets/cpp/runtime/gea_runtime.h +18007 -4757
  534. package/src/targets/cpp/runtime/gea_runtime_builtins.cpp +7 -45
  535. package/src/targets/cpp/runtime/gea_runtime_rtc.h +247 -0
@@ -1,17 +1,24 @@
1
1
  import { passingOf, representationKey } from '../../../representation/model.js';
2
2
  import { hostMemberTemplateOf } from '../../../representation/host-templates.js';
3
- import { createCppEmitBlockedError, operandText } from '../emit-context.js';
3
+ import { instanceReparentVerdictOf, isClassConstructorCarrier } from '../../../ir/instance-reparenting.js';
4
+ import { createCppEmitBlockedError, isCppEmitBlockedError, operandText } from '../emit-context.js';
5
+ import { evaluatedOnceText } from '../evaluated-once.js';
4
6
  import { canonicalIndexLiteral, memberAccessOperator } from '../emit-carrier-members.js';
5
7
  import { classMemberOf, lazyArrowFieldPlanOf } from '../class-layout.js';
6
- import { alignedValueText, recipeText } from '../emit-narrowing.js';
7
- import { getOwnValue, objectViewFrom, objectViewOf, ownEnumerableKeysText, ownKeyFields, ownKeyPresenceText, refuseDictionaryArm, refuseObjectCarrier, setOwnCallableText, setOwnText } from './object-protocol.js';
8
+ import { alignedValueText, dynamicCarrierBoxText, recipeText } from '../emit-narrowing.js';
9
+ import { getOwnValue, isDynamicCarrier, objectViewFrom, objectViewOf, ownEnumerableKeysText, ownKeyFields, ownKeyPresenceText, refuseDictionaryArm, refuseObjectCarrier, runtimeOwnKeyText, setOwnCallableText, setOwnText } from './object-protocol.js';
8
10
  import { hostIntrinsicLengthOf, hostMemberOf } from './host-members.js';
9
11
  import { hostFunctionValueText, hostPrototypeMethodValueText } from './emit-host-value.js';
10
12
  import { armAt, armIs } from '../emit-union-properties.js';
11
- import { recordFieldsOfShape, recordIndexesOfShape } from '../records.js';
12
- import { cppArrayExtensionStructName, cppBodyName, cppRecordFieldAttributesName, cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppStringLiteral, cppTypeOf, cppUndefinedValue } from '../types.js';
13
- import { isNativeCallableCarrier, propertyKeyText as propertyKeyOperandText, stringKeyPreludeText } from '../emit-dynamic-properties.js';
13
+ import { constructorStateText, constructorViewFieldFor } from '../class-properties/emit-class-properties.js';
14
+ import { isNativeError } from '../error-types.js';
15
+ import { nativeBaseFieldOf, recordFieldsOfShape, recordIndexesOfShape } from '../records.js';
16
+ import { keyOrderUnobservedIn } from '../key-order-tracking.js';
17
+ import { indexedRecordViewOf } from '../../../ir/certify/carrier-keys.js';
18
+ import { cppArrayExtensionStructName, cppBodyName, cppClassName, cppRecordFieldAttributesName, cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppStringLiteral, cppTypeOf, cppUndefinedValue, unitFunctionName } from '../types.js';
19
+ import { isNativeCallableCarrier, ownershipOfGeneratedCarrier, propertyKeyText as propertyKeyOperandText, stringKeyPreludeText } from '../emit-dynamic-properties.js';
14
20
  import { regexpRoleOf } from '../prototype/emit-prototype-regexp.js';
21
+ import { ownPropertySymbolsText } from './emit-host-reflect.js';
15
22
  /**
16
23
  * `Object`'s statics -- the call-site half of the `ObjectConstructor@1`
17
24
  * boundary.
@@ -56,7 +63,8 @@ const objectValueConversionText = (ctx, operation, role, argument, field, source
56
63
  const citation = operation.objectValueConversions?.find((value) => value.role === role && value.argument === argument && value.field === field);
57
64
  const node = citation && ctx.conversions.nodeById(citation.conversion);
58
65
  if (!citation || !node || representationKey(citation.source) !== representationKey(source))
59
- throw createCppEmitBlockedError('call-abi:object-value-conversions', 'Object field value has no matching certified conversion citation');
66
+ throw createCppEmitBlockedError('call-abi:object-value-conversions', `Object field value "${field}" carried as "${representationKey(source)}" has no matching certified conversion citation ` +
67
+ `(cited: ${(operation.objectValueConversions ?? []).map((value) => `${value.field}:${representationKey(value.source)}`).join(', ') || 'none'})`);
60
68
  const rendered = recipeText(ctx, node, text);
61
69
  if (rendered === null)
62
70
  throw createCppEmitBlockedError(`conversion:${citation.conversion}`, 'Object field value conversion has no rendering');
@@ -114,13 +122,34 @@ const targetOf = (ctx, member, operation) => {
114
122
  * An arm that CANNOT be enumerated still refuses, and now says which arm and
115
123
  * why rather than reporting the union as one unenumerable carrier.
116
124
  */
117
- const overCarrier = (ctx, member, operation, render) => {
125
+ const overCarrier = (ctx, member, operation, render, renderArray) => {
118
126
  const target = targetOf(ctx, member, operation);
119
- const representation = target.representation;
127
+ return evaluatedOnce(ctx, target, (receiver) => overCarrierAt(ctx, member, target.representation, receiver, render, renderArray));
128
+ };
129
+ /**
130
+ * The receiver's text, evaluated once however many times the rendering names it.
131
+ *
132
+ * A deferred value's text IS the expression that computes it
133
+ * (`isDeferredValue`), and the static arms of `entries`, `values` and `keys`
134
+ * name the receiver once per field -- in the read, the presence test, the
135
+ * `[[Enumerable]]` test and the creation-order walk. mongodb's
136
+ * `Object.entries(this.options)` reads a class's options through a record
137
+ * conversion, and pasting that conversion 188 times made one 8 MB statement
138
+ * (`CreateCollectionOperation.execute`) that no C++ compiler finishes, and
139
+ * evaluated the options' sidecar reads 188 times at run time. A named value is
140
+ * already evaluated once and renders unchanged; `evaluated-once.ts` is the one
141
+ * binding rule, shared with the conversion printer.
142
+ */
143
+ const evaluatedOnce = (ctx, target, render) => evaluatedOnceText(operandText(ctx, target), render);
144
+ const overCarrierAt = (ctx, member, representation, receiver, render, renderArray) => {
145
+ // An Array is an object whose own keys are its present indices then its
146
+ // sidecar's; a member that can enumerate one states how.
147
+ const one = (value, text) => value.kind === 'array-object' && renderArray !== undefined
148
+ ? renderArray(value, text)
149
+ : render(objectViewFrom(ctx, member, value, text, 'object'));
120
150
  if (representation.kind !== 'tagged-union')
121
- return render(objectViewOf(ctx, member, target, 'object'));
122
- const receiver = operandText(ctx, target);
123
- const arms = representation.arms.map((arm, index) => render(objectViewFrom(ctx, member, arm.value, armAt(receiver, index), 'object')));
151
+ return one(representation, receiver);
152
+ const arms = representation.arms.map((arm, index) => one(arm.value, armAt(receiver, index)));
124
153
  const dispatched = arms.reduceRight((rest, text, index) => (rest === null ? text : `${armIs(receiver, index)} ? ${text} : (${rest})`), null);
125
154
  if (dispatched === null) {
126
155
  throw createCppEmitBlockedError(`host-member-call:Object.${member}`, `"Object.${member}" of a tagged union with no arms has nothing to enumerate`);
@@ -157,10 +186,12 @@ const keysText = (ctx, member, operation) => {
157
186
  }
158
187
  return ownEnumerableKeysText(member, objectViewFrom(ctx, member, representation, receiver, 'object'), member === 'keys' ? 'keys' : 'getOwnPropertyNames');
159
188
  };
160
- if (target.representation.kind !== 'tagged-union')
161
- return keysOf(target.representation, operandText(ctx, target));
162
- const receiver = operandText(ctx, target);
163
- const arms = target.representation.arms.map((arm, index) => keysOf(arm.value, armAt(receiver, index)));
189
+ return evaluatedOnce(ctx, target, (receiver) => keysOverCarrier(member, target.representation, receiver, keysOf));
190
+ };
191
+ const keysOverCarrier = (member, representation, receiver, keysOf) => {
192
+ if (representation.kind !== 'tagged-union')
193
+ return keysOf(representation, receiver);
194
+ const arms = representation.arms.map((arm, index) => keysOf(arm.value, armAt(receiver, index)));
164
195
  const dispatched = arms.reduceRight((rest, text, index) => (rest === null ? text : `${armIs(receiver, index)} ? ${text} : (${rest})`), null);
165
196
  if (dispatched === null)
166
197
  throw createCppEmitBlockedError(`host-member-call:Object.${member}`, `"Object.${member}" of a tagged union with no arms has nothing to enumerate`);
@@ -214,14 +245,33 @@ const valuesOfView = (ctx, operation, view) => {
214
245
  throw createCppEmitBlockedError('host-member-call:Object.values', `"Object.values" cannot include the optional field "${field.key}": an absent field contributes no element, and ` +
215
246
  'the length of the array would then depend on a presence flag this arm does not test');
216
247
  }
217
- if (representationKey(field.value) !== element) {
248
+ }
249
+ // A field whose carrier differs from the element (`{ on: true, none: 'none' }`
250
+ // read as `(boolean | string)[]`) widens into it through the conversion
251
+ // census, the same authority every other slot write uses; a pair the census
252
+ // refuses keeps the refusal, naming the field.
253
+ const reads = ordered.map((field) => {
254
+ const read = getOwnValue(ctx, view, field).text;
255
+ if (representationKey(field.value) === element)
256
+ return read;
257
+ const converted = alignedValueText(ctx, 'host/emit-host-object.ts:values', field.value, result.element, read);
258
+ if (converted === null) {
218
259
  throw createCppEmitBlockedError('host-member-call:Object.values', `"Object.values" would build a std::vector<${cppTypeOf(result.element)}> from the field "${field.key}", which ` +
219
- `carries "${representationKey(field.value)}" -- one array has one element type, and converting each field into ` +
220
- "the result's element carrier is a per-field conversion this arm does not write");
260
+ `carries "${representationKey(field.value)}", and no conversion into the element carrier exists`);
221
261
  }
222
- }
223
- const reads = ordered.map((field) => getOwnValue(ctx, view, field).text);
224
- return `gea::detail::hostArrayResult(std::vector<${cppTypeOf(result.element)}>{${reads.join(', ')}})`;
262
+ return converted;
263
+ });
264
+ const fixed = `gea::detail::hostArrayResult(std::vector<${cppTypeOf(result.element)}>{${reads.join(', ')}})`;
265
+ // The one own-key order `keys` and `entries` also take: a key outside the
266
+ // layout contributes its value, where it was created.
267
+ const creationOrdered = creationOrderedOwnCopyText(ctx, view, (_key, value) => {
268
+ const converted = alignedValueText(ctx, 'host/emit-host-object.ts:values-in-creation-order', dynamicCarrier, result.element, value);
269
+ return converted === null ? null : `__gea_values.push_back(${converted});`;
270
+ });
271
+ if (creationOrdered === null)
272
+ return fixed;
273
+ return (`([&]() { std::vector<${cppTypeOf(result.element)}> __gea_values; ` +
274
+ `if (${creationOrdered}) return gea::detail::hostArrayResult(std::move(__gea_values)); return ${fixed}; })()`);
225
275
  };
226
276
  /** Consume the representation already selected for the entry's [string, T] tuple. */
227
277
  const entryCarrierOf = (ctx, operation) => {
@@ -293,7 +343,10 @@ const entryText = (entry, key, value) => {
293
343
  // would take.
294
344
  const allocate = entry.shared ? `auto __gea_entry = gea::makeRef<${entry.name}>();` : `${entry.name} __gea_entry{};`;
295
345
  const write = entry.shared ? '__gea_entry->' : '__gea_entry.';
296
- return `${allocate} ${write}${cppRecordFieldName('0')} = ${key}; ${write}${cppRecordFieldName('1')} = ${value}; return __gea_entry;`;
346
+ // Both makers take `__gea_key`/`__gea_value` by value, so the entry's slots can
347
+ // take them over instead of copying a second time.
348
+ const take = (text) => (text === '__gea_key' || text === '__gea_value' ? `std::move(${text})` : text);
349
+ return `${allocate} ${write}${cppRecordFieldName('0')} = ${take(key)}; ${write}${cppRecordFieldName('1')} = ${take(value)}; return __gea_entry;`;
297
350
  };
298
351
  /**
299
352
  * `Object.entries` -- primitive 1 for the keys, primitive 2 for each value.
@@ -304,12 +357,49 @@ const entryText = (entry, key, value) => {
304
357
  * target the program declared `any`), an arm store where the source's values
305
358
  * have a type of their own, and a refusal by name where neither is licensed.
306
359
  *
307
- * An optional field refuses for the same reason it does in `values`: an absent
308
- * key contributes no entry, so the array's LENGTH would depend on a presence
309
- * flag, and a `std::vector` built from a brace list has its length fixed
310
- * before any flag is read.
360
+ * An optional field makes the array's LENGTH a run-time fact -- an absent key
361
+ * contributes no entry -- so a view with one renders as a push loop gated on
362
+ * each field's presence bit rather than as a braced vector.
363
+ */
364
+ const entriesText = (ctx, operation) => overCarrier(ctx, 'entries', operation, (view) => entriesOfKnownView(ctx, operation, view), (array, receiver) => arrayEntriesText(ctx, operation, array, receiver));
365
+ /**
366
+ * A known view's entries depend on nothing at the site but the receiver: a
367
+ * push per declared field behind its presence and `[[Enumerable]]` tests,
368
+ * after the creation-order walk. Over mongodb's options family that is a
369
+ * 60 KB expression per call, so a unit defines it once per receiver carrier
370
+ * and entry carrier and every site calls it (`unitFunctionName`).
311
371
  */
312
- const entriesText = (ctx, operation) => overCarrier(ctx, 'entries', operation, (view) => entriesOfView(ctx, operation, view));
372
+ const entriesOfKnownView = (ctx, operation, view) => {
373
+ if (view.kind !== 'known')
374
+ return entriesOfView(ctx, operation, view);
375
+ const formal = 'gea_entries_source';
376
+ const body = entriesOfView(ctx, operation, { ...view, receiver: formal });
377
+ const element = cppTypeOf(entryCarrierOf(ctx, operation).element);
378
+ const named = unitFunctionName('gea_entries_of', (name) => `gea::Ref<gea::ArrayObject<${element}>> ${name}(const ${cppTypeOf(view.representation)}& ${formal})`, `return ${body};`);
379
+ return named === null ? entriesOfView(ctx, operation, view) : `${named}(${view.receiver})`;
380
+ };
381
+ /**
382
+ * `Object.entries` of an Array: one entry per present index, then one per
383
+ * enumerable sidecar key (`gea::host::ObjectConstructor::arrayEntriesOf`).
384
+ * mongodb's `constructIndexDescriptionMap` reaches it through a union whose
385
+ * `ReadonlyArray` arm `Array.isArray` has already excluded -- the checker
386
+ * keeps the arm, so the dispatch must still be able to spell it.
387
+ */
388
+ const arrayEntriesText = (ctx, operation, array, receiver) => {
389
+ const entry = entryCarrierOf(ctx, operation);
390
+ const intoSlot = (source, text, describe) => {
391
+ const converted = alignedValueText(ctx, 'host/emit-host-object.ts:array-entries', source, entry.value, text);
392
+ if (converted !== null)
393
+ return converted;
394
+ throw createCppEmitBlockedError('host-member-call:Object.entries', `"Object.entries" would put ${describe}, carried as "${representationKey(source)}", into an entry's value slot ` +
395
+ `carried as "${representationKey(entry.value)}", and no conversion between those is licensed`);
396
+ };
397
+ const element = intoSlot(array.element, '__gea_value', 'an array element');
398
+ const property = intoSlot(dynamicCarrier, '__gea_value', 'an array sidecar property');
399
+ return (`gea::host::ObjectConstructor::arrayEntriesOf<${cppTypeOf(entry.element)}>(${receiver}, ` +
400
+ `[&](std::string __gea_key, const ${cppTypeOf(array.element)}& __gea_value) { ${entryText(entry, '__gea_key', element)} }, ` +
401
+ `[&](std::string __gea_key, gea::Value __gea_value) { ${entryText(entry, '__gea_key', property)} })`);
402
+ };
313
403
  const entriesOfView = (ctx, operation, view) => {
314
404
  const entry = entryCarrierOf(ctx, operation);
315
405
  /**
@@ -343,16 +433,74 @@ const entriesOfView = (ctx, operation, view) => {
343
433
  return (`gea::host::ObjectConstructor::entriesOf<${cppTypeOf(entry.element)}>(${view.receiver}, ` +
344
434
  `[](std::string __gea_key, ${cppTypeOf(view.value)} __gea_value) { ${entryText(entry, '__gea_key', value)} })`);
345
435
  }
346
- const built = ownKeyFields(view).map((field) => {
347
- if (!field.required) {
348
- throw createCppEmitBlockedError('host-member-call:Object.entries', `"Object.entries" cannot include the optional field "${field.key}": an absent key contributes no entry, and the ` +
349
- 'length of the array would then depend on a presence flag a braced vector has already fixed');
350
- }
436
+ const ordered = ownKeyFields(view);
437
+ const entryOf = (field) => {
351
438
  const read = getOwnValue(ctx, view, field);
352
439
  const value = intoSlot(read.representation, read.text, `the field "${field.key}"`);
353
440
  return `[&]() { ${entryText(entry, cppStringLiteral(field.key), value)} }()`;
441
+ };
442
+ const creationOrdered = creationOrderedOwnCopyText(ctx, view, (key, value) => {
443
+ const converted = alignedValueText(ctx, 'host/emit-host-object.ts:entries-in-creation-order', dynamicCarrier, entry.value, value);
444
+ return converted === null ? null : `__gea_entries.push_back([&]() { ${entryText(entry, key, converted)} }());`;
354
445
  });
355
- return `gea::detail::hostArrayResult(std::vector<${cppTypeOf(entry.element)}>{${built.join(', ')}})`;
446
+ if (creationOrdered === null && ordered.every((field) => field.required)) {
447
+ return `gea::detail::hostArrayResult(std::vector<${cppTypeOf(entry.element)}>{${ordered.map(entryOf).join(', ')}})`;
448
+ }
449
+ // An optional field is an own key only while its presence bit says so, so
450
+ // the array's LENGTH is a run-time fact: the push loop over the one
451
+ // enumeration order `ownEnumerableKeysText` also walks, gated on the same
452
+ // `[[Enumerable]]`-and-present test, so `Object.keys(o)` and the keys of
453
+ // `Object.entries(o)` cannot disagree (20.1.2.5 / 7.3.23 EnumerableOwnProperties).
454
+ const pushes = ordered.map((field) => {
455
+ const present = ownKeyPresenceText('entries', view, field);
456
+ const enumerable = `${view.receiver}${view.accessor}${cppRecordFieldAttributesName(field.key)}.enumerable`;
457
+ const test = present === null ? enumerable : `(${present} && ${enumerable})`;
458
+ return `if (${test}) __gea_entries.push_back(${entryOf(field)});`;
459
+ });
460
+ const walked = creationOrdered === null ? pushes.join(' ') : `if (!${creationOrdered}) { ${pushes.join(' ')} }`;
461
+ return (`([&]() { std::vector<${cppTypeOf(entry.element)}> __gea_entries; ${walked} ` +
462
+ `return gea::detail::hostArrayResult(std::move(__gea_entries)); })()`);
463
+ };
464
+ /**
465
+ * The own enumerable properties of a shared record, walked by the runtime in
466
+ * creation order, as a call answering whether it walked them.
467
+ *
468
+ * The static arms of `entries`, `values` and `assign` list a known view's
469
+ * declared fields, and a record can have more own keys than that -- its index
470
+ * sidecar's entries, or the expando keys any shared record gains through a
471
+ * dynamic write -- in an order interleaved with the fields once a key outside
472
+ * the layout exists (`gea::copyOwnPropertiesInCreationOrder`). An indexed
473
+ * record is walked whenever it has a property protocol, since the static arm
474
+ * never sees its sidecar; any other only once it has such a key, since until
475
+ * then the static arm is exactly its own keys. The call answers false where
476
+ * it does not walk, so the static arm still runs. `each` renders the store of
477
+ * one key and its property value, or null when that value has no conversion
478
+ * into the destination; there is then no runtime walk.
479
+ */
480
+ const creationOrderedOwnCopyText = (ctx, view, each, assigned = null) => {
481
+ const indexed = indexedRecordViewOf(ctx.deriver, view.representation);
482
+ const ownership = indexed !== null ? indexed.ownership : ownershipOfGeneratedCarrier(view.representation);
483
+ if (ownership !== 'shared-refcount')
484
+ return null;
485
+ let body;
486
+ try {
487
+ body = each('__gea_ordered_key', '__gea_ordered_value');
488
+ }
489
+ catch (error) {
490
+ if (isCppEmitBlockedError(error))
491
+ return null;
492
+ throw error;
493
+ }
494
+ if (body === null)
495
+ return null;
496
+ // A copy into a known target with its static copy in hand: the runtime runs
497
+ // that copy itself when the source's keys only left layout order
498
+ // (`gea::assignOwnPropertiesInCreationOrderWith`).
499
+ if (assigned !== null && indexed === null)
500
+ return (`gea::${assigned.orderless === true ? 'assignOwnPropertiesUnorderedWith' : 'assignOwnPropertiesInCreationOrderWith'}(${view.receiver}, ${assigned.target}, ` +
501
+ `[&](const std::string& __gea_ordered_key, const gea::Value& __gea_ordered_value) { ${body} }, ${assigned.staticCopy})`);
502
+ return (`gea::copyOwnPropertiesInCreationOrder(${view.receiver}, ` +
503
+ `[&](const std::string& __gea_ordered_key, const gea::Value& __gea_ordered_value) { ${body} }${indexed !== null ? ', true' : ''})`);
356
504
  };
357
505
  /**
358
506
  * A property key argument, as `gea::PropertyKey`.
@@ -524,6 +672,18 @@ const integrityText = (ctx, member, operation, call) => {
524
672
  'if (!__gea_sidecar || __gea_sidecar->extensible()) return false; for (const auto& __gea_key : __gea_sidecar->ownKeys()) { ' +
525
673
  'const gea::PropertyDescriptor* __gea_descriptor = __gea_sidecar->ownProperty(__gea_key); if (__gea_descriptor != nullptr && __gea_descriptor->configurable) return false; } return true; })()');
526
674
  }
675
+ // A shared Document (the `{ ...command }` a driver freezes before handing it
676
+ // on) has identity; its frozen state lives in the object the table migrates
677
+ // into, see `gea::dictionary::freeze`. seal/preventExtensions are not wired.
678
+ if (view.kind === 'dictionary' &&
679
+ target.representation.kind === 'dictionary' &&
680
+ target.representation.ownership === 'shared-refcount' &&
681
+ isDynamicCarrier(view.value) &&
682
+ (call === 'freeze' || call === 'isFrozen' || call === 'isExtensible')) {
683
+ // The helper takes the `gea::Ref` itself: `migrateTo` swaps the table's
684
+ // storage in place, which every alias of that Ref observes.
685
+ return `gea::dictionary::${call}(${operandText(ctx, target)})`;
686
+ }
527
687
  return refuseObjectCarrier(member, view.representation, 'an integrity level needs a stable object identity; this carrier is held by value, so no identity-keyed native ' +
528
688
  'sidecar can preserve the state across aliases');
529
689
  };
@@ -549,6 +709,30 @@ const getPrototypeOfText = (ctx, operation) => {
549
709
  return refuseObjectCarrier(member, view.representation, 'this backend gives no statically typed carrier a runtime [[Prototype]] slot -- only a value the program itself ' +
550
710
  'declared dynamic carries one');
551
711
  };
712
+ /**
713
+ * `Object.setPrototypeOf(instance, M.prototype)` -- the one form certification
714
+ * admits (`ir/instance-reparenting.ts`), re-derived here from the printer's
715
+ * own origin maps so a plan certification did not state is refused rather
716
+ * than spelled. The call's value is the object itself, unchanged in carrier:
717
+ * re-classing moves identity, not storage.
718
+ */
719
+ const setPrototypeOfText = (ctx, operation) => {
720
+ const reads = {
721
+ convertSourceOf: (value) => ctx.conversionSources.get(value) ?? null,
722
+ readsClassPrototype: (value) => {
723
+ const read = ctx.propertyReadOrigins.get(value);
724
+ return (read !== undefined &&
725
+ isClassConstructorCarrier(read.receiver.representation) &&
726
+ ctx.staticKeyTexts.get(read.key.value) === 'prototype');
727
+ }
728
+ };
729
+ const verdict = instanceReparentVerdictOf(ctx.classes, reads, operation.arguments);
730
+ if (verdict.kind === 'refused')
731
+ throw createCppEmitBlockedError('host-member-call:Object.setPrototypeOf', verdict.reason);
732
+ const { plan } = verdict;
733
+ const classes = [plan.target, ...plan.sources.filter((source) => source !== plan.target)].map(cppClassName).join(', ');
734
+ return `gea::reparentInstance<${classes}>(${operandText(ctx, plan.instance)}, ${operandText(ctx, plan.prototype)})`;
735
+ };
552
736
  /**
553
737
  * `Object.hasOwn(array, key)` for an Array exotic receiver -- its own
554
738
  * dedicated arm for the same reason `keysText` has one: an Array's own keys
@@ -622,17 +806,20 @@ const hasOwnText = (ctx, operation) => {
622
806
  if (!matches) {
623
807
  return refuseDictionaryArm('hasOwn', view, `the key carries "${representationKey(key.representation)}" rather than the table's "${view.representation.key}" key domain`);
624
808
  }
625
- return `${view.receiver}.has(${operandText(ctx, key)})`;
809
+ // A string table may be a Document viewing an instance, whose inherited
810
+ // getters `has` (the `in` operator's question) sees and `hasOwn` does not.
811
+ return `${view.receiver}.${view.representation.key === 'string' ? 'hasOwn' : 'has'}(${operandText(ctx, key)})`;
626
812
  }
627
813
  // A claim, not a fold: this decides whether the key is a name this backend
628
814
  // can resolve at compile time or must refuse below, so it must not see a
629
815
  // key text `constantTexts` only holds because the render minted it (e.g. a
630
816
  // folded `typeof` result reaching here as the tested key).
631
817
  const spelled = ctx.staticKeyTexts.get(key.value);
632
- if (spelled === undefined) {
633
- return refuseObjectCarrier('hasOwn', view.representation, "the key is not a constant this program spells, so the answer is a search over the struct's own key set -- which " +
634
- 'its `gea_readOwnField` dispatcher performs, and reaching that needs the receiver to be the dynamic value it is not');
635
- }
818
+ // A key only known at runtime is a search over the struct's own key set,
819
+ // which is finite and declared: the same switch `hasOwnProperty` renders
820
+ // for it, so the two spellings of one question give one answer.
821
+ if (spelled === undefined)
822
+ return runtimeOwnKeyText(ctx, 'Object.hasOwn', key, view.fields, (field) => ownKeyPresenceText('hasOwn', view, field) ?? 'true');
636
823
  const field = view.fields.find((candidate) => candidate.key === spelled);
637
824
  if (field === undefined)
638
825
  return 'false';
@@ -842,7 +1029,39 @@ const descriptorAggregateBuilder = (ctx, resultRepresentation, contextLabel) =>
842
1029
  }
843
1030
  return converted;
844
1031
  };
845
- return { resultType, someText, absentText, aggregateOf, convertValueField, attributeText, valueFieldRepresentation };
1032
+ /**
1033
+ * The `get`/`set` halves of a runtime `gea::PropertyDescriptor` (`object`
1034
+ * names a `const gea::PropertyDescriptor&`), as the record's callable
1035
+ * fields and their presence bits. An accessor property's descriptor states
1036
+ * no `value`, so a reader of `typeof desc.get` would otherwise find nothing.
1037
+ * A record whose half is carried as some other callable type has no
1038
+ * spelling here and keeps the half absent, exactly as before.
1039
+ */
1040
+ const accessorHalvesOf = (object) => {
1041
+ const overrides = {};
1042
+ const present = {};
1043
+ const halves = [
1044
+ { key: 'get', has: 'hasGet', helper: 'descriptorGetCallable', type: 'gea::CallableObject<gea::Value()>' },
1045
+ { key: 'set', has: 'hasSet', helper: 'descriptorSetCallable', type: 'gea::CallableObject<void(gea::Value)>' }
1046
+ ];
1047
+ for (const half of halves) {
1048
+ const field = fields.find((candidate) => candidate.key === half.key);
1049
+ if (field === undefined)
1050
+ continue;
1051
+ const carried = field.value.kind === 'optional' ? field.value.payload : field.value;
1052
+ if (cppTypeOf(carried) !== half.type)
1053
+ continue;
1054
+ const built = `gea::${half.helper}(${object})`;
1055
+ const fieldType = cppTypeOf(field.value);
1056
+ // A complete accessor property states both halves, and a missing one is
1057
+ // present as `undefined` (10.1.6.3): the key is there, the callable is not.
1058
+ const callable = `(${object}.${half.has} && static_cast<bool>(${object}.${half.key}))`;
1059
+ overrides[half.key] = field.value.kind === 'optional' ? `(${callable} ? ${fieldType}(${built}) : ${fieldType}())` : built;
1060
+ present[half.key] = `${object}.${half.has}`;
1061
+ }
1062
+ return { overrides, present };
1063
+ };
1064
+ return { resultType, someText, absentText, aggregateOf, convertValueField, attributeText, valueFieldRepresentation, accessorHalvesOf };
846
1065
  };
847
1066
  export const intrinsicMemberValueOf = (ctx, protocol, found, site) => {
848
1067
  const host = hostMemberOf(ctx.hosts.members, protocol, found.name);
@@ -1069,7 +1288,7 @@ const knownDescriptorText = (ctx, member, view, key, operation) => {
1069
1288
  if (resultRepresentation === null) {
1070
1289
  throw createCppEmitBlockedError(`host-member-call:Object.${member}`, `"Object.${member}" published no result to build a descriptor into`);
1071
1290
  }
1072
- const { resultType, someText, absentText, aggregateOf, convertValueField, attributeText } = descriptorAggregateBuilder(ctx, resultRepresentation, `"Object.${member}" of a known receiver`);
1291
+ const { resultType, someText, absentText, aggregateOf, convertValueField, attributeText, accessorHalvesOf } = descriptorAggregateBuilder(ctx, resultRepresentation, `"Object.${member}" of a known receiver`);
1073
1292
  const aggregateFor = (valueSource, valueText, attributes) => aggregateOf({
1074
1293
  value: convertValueField(valueSource, valueText),
1075
1294
  writable: attributeText('writable', 'true', `${attributes}.writable`),
@@ -1082,23 +1301,36 @@ const knownDescriptorText = (ctx, member, view, key, operation) => {
1082
1301
  // from (`definePropertyText`'s "known" arm), so a boxed carrier is this
1083
1302
  // path's genuinely correct, bounded source.
1084
1303
  const dynamicValueRepresentation = { kind: 'dynamic', reason: 'declared-any-never-narrowed' };
1304
+ const ownAccessorKeys = view.representation.kind === 'record' ? view.representation.accessors.map((accessor) => accessor.key) : [];
1085
1305
  const sidecarText = () => {
1086
1306
  if (view.accessor !== '->') {
1087
1307
  throw createCppEmitBlockedError(`host-member-call:Object.${member}`, `"Object.${member}" of a "${representationKey(view.representation)}" carrier has an "owned" receiver; a ` +
1088
1308
  "dynamic-property sidecar needs the object's own shared identity to key on");
1089
1309
  }
1090
1310
  const propertyKey = propertyKeyText(ctx, member, key);
1311
+ const halves = accessorHalvesOf('(*__gea_desc)');
1091
1312
  const fromDescriptor = aggregateOf({
1092
1313
  value: convertValueField(dynamicValueRepresentation, '__gea_desc->value'),
1093
1314
  writable: attributeText('writable', '__gea_desc->hasWritable', '__gea_desc->writable'),
1094
1315
  enumerable: attributeText('enumerable', '__gea_desc->hasEnumerable', '__gea_desc->enumerable'),
1095
- configurable: attributeText('configurable', '__gea_desc->hasConfigurable', '__gea_desc->configurable')
1316
+ configurable: attributeText('configurable', '__gea_desc->hasConfigurable', '__gea_desc->configurable'),
1317
+ ...halves.overrides
1096
1318
  }, {
1097
1319
  value: '__gea_desc->hasValue',
1098
1320
  writable: '__gea_desc->hasWritable',
1099
1321
  enumerable: '__gea_desc->hasEnumerable',
1100
- configurable: '__gea_desc->hasConfigurable'
1322
+ configurable: '__gea_desc->hasConfigurable',
1323
+ ...halves.present
1101
1324
  });
1325
+ // A literal's own accessor is an own property with no field and no
1326
+ // sidecar entry; the struct's own descriptor hook answers it, with the
1327
+ // expando consulted after, which is `nativeOwnPropertyDescriptor`'s order.
1328
+ if (ownAccessorKeys.length > 0) {
1329
+ return (`([&]() -> ${resultType} { const auto __gea_found = gea::nativeOwnPropertyDescriptor(${view.receiver}, ${propertyKey}); ` +
1330
+ `if (!__gea_found.has_value()) return ${absentText()}; ` +
1331
+ `const gea::PropertyDescriptor* __gea_desc = &*__gea_found; ` +
1332
+ `return ${someText(fromDescriptor)}; })()`);
1333
+ }
1102
1334
  return (`([&]() -> ${resultType} { const auto __gea_expando = gea::detail::expandoFor(gea::refCastToVoid(${view.receiver}), false); ` +
1103
1335
  `if (!__gea_expando) return ${absentText()}; ` +
1104
1336
  `const gea::PropertyDescriptor* __gea_desc = __gea_expando->ownProperty(${propertyKey}); ` +
@@ -1158,18 +1390,17 @@ const knownDescriptorText = (ctx, member, view, key, operation) => {
1158
1390
  * "states false" and "states nothing" are different, so a bare `bool` read
1159
1391
  * would silently invent an attribute the descriptor never claimed).
1160
1392
  *
1161
- * `get`/`set` are left at their default absent: converting a native
1162
- * `std::function` accessor into this record's `Optional<CallableObject<...>>`
1163
- * field needs a std::function-to-CallableObject bridge this arm does not
1164
- * build, and no consumer in this probe reads a descriptor's accessors.
1393
+ * `get`/`set` come across through `accessorHalvesOf`, the one bridge from a
1394
+ * runtime descriptor's accessor halves to the record's callable fields.
1165
1395
  */
1166
1396
  const dynamicDescriptorConversionText = (ctx, member, receiver, key, operation) => {
1167
1397
  const resultRepresentation = operation.result?.representation ?? null;
1168
1398
  if (resultRepresentation === null) {
1169
1399
  throw createCppEmitBlockedError(`host-member-call:Object.${member}`, `"Object.${member}" of a dynamic receiver published no result to build a descriptor into`);
1170
1400
  }
1171
- const { resultType, someText, absentText, aggregateOf, attributeText, convertValueField } = descriptorAggregateBuilder(ctx, resultRepresentation, `"Object.${member}" of a dynamic receiver`);
1401
+ const { resultType, someText, absentText, aggregateOf, attributeText, convertValueField, accessorHalvesOf } = descriptorAggregateBuilder(ctx, resultRepresentation, `"Object.${member}" of a dynamic receiver`);
1172
1402
  const nativeCall = `gea::host::ObjectConstructor::${member}(${receiver}, ${propertyKeyText(ctx, member, key)})`;
1403
+ const halves = accessorHalvesOf('static_cast<const gea::PropertyDescriptor&>(*__gea_native)');
1173
1404
  const aggregate = aggregateOf({
1174
1405
  // The runtime's own descriptor keeps `value` boxed (`gea::Value`) even
1175
1406
  // though the call-site result may have narrowed the field to a typed
@@ -1180,12 +1411,14 @@ const dynamicDescriptorConversionText = (ctx, member, receiver, key, operation)
1180
1411
  value: convertValueField(dynamicCarrier, '__gea_native->value'),
1181
1412
  writable: attributeText('writable', '__gea_native->hasWritable', '__gea_native->writable'),
1182
1413
  enumerable: attributeText('enumerable', '__gea_native->hasEnumerable', '__gea_native->enumerable'),
1183
- configurable: attributeText('configurable', '__gea_native->hasConfigurable', '__gea_native->configurable')
1414
+ configurable: attributeText('configurable', '__gea_native->hasConfigurable', '__gea_native->configurable'),
1415
+ ...halves.overrides
1184
1416
  }, {
1185
1417
  value: '__gea_native->hasValue',
1186
1418
  writable: '__gea_native->hasWritable',
1187
1419
  enumerable: '__gea_native->hasEnumerable',
1188
- configurable: '__gea_native->hasConfigurable'
1420
+ configurable: '__gea_native->hasConfigurable',
1421
+ ...halves.present
1189
1422
  });
1190
1423
  return (`([&]() -> ${resultType} { const auto __gea_native = ${nativeCall}; ` +
1191
1424
  `if (!__gea_native.has_value()) return ${absentText()}; ` +
@@ -1376,10 +1609,19 @@ const createText = (operation) => {
1376
1609
  // payload of a different C++ type and refuses at runtime -- a program that
1377
1610
  // aborts on its first statement, which is what `const emptyParams: Params =
1378
1611
  // Object.create(null)` did (hono's pattern router).
1379
- if (result !== null && (result.kind === 'dictionary' || result.kind === 'record')) {
1612
+ if (result !== null && (result.kind === 'dictionary' || result.kind === 'record' || result.kind === 'record-with-index')) {
1380
1613
  const storage = cppTypeOf(result, 'owned');
1381
1614
  return result.ownership === 'shared-refcount' ? `gea::makeRef<${storage}>()` : `${storage}{}`;
1382
1615
  }
1616
+ // A NAMED shape is the same empty struct: mongodb's `parseOptions` fills
1617
+ // `const mongoOptions = Object.create(null)` and returns it as the
1618
+ // `MongoOptions` interface, so the census gives the call that interface's
1619
+ // carrier. Spelled the way `emitAllocateRecord` spells the same carrier --
1620
+ // the host's own struct when one is stated -- since `gea::Value::object()`
1621
+ // is not a value of it at all.
1622
+ if (result !== null && result.kind === 'native-record-ref' && result.ownership === 'shared-refcount') {
1623
+ return `gea::makeRef<${result.native ?? cppRecordStructName(result.shapeId)}>()`;
1624
+ }
1383
1625
  return 'gea::Value::object()';
1384
1626
  };
1385
1627
  /**
@@ -1408,7 +1650,44 @@ const createText = (operation) => {
1408
1650
  * store, so a source with a getter or a target with a setter is refused by
1409
1651
  * `setOwnText` naming the accessor rather than copied around it.
1410
1652
  */
1653
+ /**
1654
+ * The source fields `Object.assign` copies.
1655
+ *
1656
+ * A class extending `Error` inherits `name`/`message`/`stack`/`cause` from
1657
+ * `gea::runtime::Error`, the only record a class can take as a native base.
1658
+ * JavaScript has them as non-enumerable own properties (or, for `name`, a
1659
+ * prototype one), so 7.3.25 never copies them -- and the struct has no
1660
+ * presence bit or attribute triple to test for them either.
1661
+ */
1662
+ const assignedKeyFields = (ctx, view) => ownKeyFields(view).filter((field) => !nativeBaseFieldOf(ctx.deriver, view.representation, field.key, ctx.classes));
1663
+ /**
1664
+ * One source's copy, as a call to the unit function that copies this pair of
1665
+ * carriers.
1666
+ *
1667
+ * Between two known shapes the copy's text depends on nothing but the two
1668
+ * carriers and the two receivers: a static store per source field, then the
1669
+ * creation-order walk, whose callback routes every run-time key through the
1670
+ * target's own field list. Into mongodb's 131-field options family that walk
1671
+ * alone is a 131-branch chain, and `Object.assign({}, a, b)` over the same
1672
+ * pair recurs at dozens of sites -- 3.6 MB of the ping driver's unit in chains
1673
+ * that differed only in which local named the target. Rendered over the
1674
+ * function's own formals, the pair is defined once and every site calls it
1675
+ * (`unitFunctionName`). The target is shared, so the stores the function
1676
+ * makes through its formal are stores into the site's object.
1677
+ */
1411
1678
  const assignSourceText = (ctx, targetView, sourceView) => {
1679
+ if (targetView.kind !== 'known' ||
1680
+ sourceView.kind !== 'known' ||
1681
+ ownershipOfGeneratedCarrier(targetView.representation) !== 'shared-refcount') {
1682
+ return assignSourceTextAt(ctx, targetView, sourceView);
1683
+ }
1684
+ const target = 'gea_assign_target';
1685
+ const source = 'gea_assign_source';
1686
+ const body = assignSourceTextAt(ctx, { ...targetView, receiver: target }, { ...sourceView, receiver: source });
1687
+ const named = unitFunctionName('gea_assign', (name) => `void ${name}(const ${cppTypeOf(targetView.representation)}& ${target}, const ${cppTypeOf(sourceView.representation)}& ${source})`, body);
1688
+ return named === null ? assignSourceTextAt(ctx, targetView, sourceView) : `${named}(${targetView.receiver}, ${sourceView.receiver});`;
1689
+ };
1690
+ const assignSourceTextAt = (ctx, targetView, sourceView) => {
1412
1691
  if (targetView.kind === 'dynamic' && sourceView.kind === 'dynamic') {
1413
1692
  return `gea::host::ObjectConstructor::assign(${targetView.receiver}, ${sourceView.receiver});`;
1414
1693
  }
@@ -1447,7 +1726,7 @@ const assignSourceText = (ctx, targetView, sourceView) => {
1447
1726
  if (targetView.representation.key === 'symbol') {
1448
1727
  return refuseDictionaryArm('assign', targetView, 'a statically named source field is a string PropertyKey and cannot be inserted into a symbol-keyed target');
1449
1728
  }
1450
- const stores = ownKeyFields(sourceView).map((field) => {
1729
+ const stores = assignedKeyFields(ctx, sourceView).map((field) => {
1451
1730
  const value = getOwnValue(ctx, sourceView, field);
1452
1731
  const converted = alignedValueText(ctx, 'host/emit-host-object.ts:1660', value.representation, targetView.value, value.text);
1453
1732
  if (converted === null) {
@@ -1464,7 +1743,13 @@ const assignSourceText = (ctx, targetView, sourceView) => {
1464
1743
  const presence = ownKeyPresenceText('assign', sourceView, field);
1465
1744
  return presence === null ? store : `if (${presence}) ${store}`;
1466
1745
  });
1467
- return stores.join(' ');
1746
+ const creationOrdered = creationOrderedOwnCopyText(ctx, sourceView, (key, value) => {
1747
+ const converted = alignedValueText(ctx, 'host/emit-host-object.ts:assign-in-creation-order', dynamicCarrier, targetView.value, value);
1748
+ return converted === null
1749
+ ? null
1750
+ : `if (!${targetView.receiver}.setProperty(${key}, ${converted})) gea::host::throwRuntimeError("TypeError", "Cannot assign to read only property");`;
1751
+ });
1752
+ return creationOrdered === null ? stores.join(' ') : `if (!${creationOrdered}) { ${stores.join(' ')} }`;
1468
1753
  }
1469
1754
  if (targetView.kind === 'dictionary' &&
1470
1755
  targetView.representation.key === 'string' &&
@@ -1472,6 +1757,28 @@ const assignSourceText = (ctx, targetView, sourceView) => {
1472
1757
  targetView.value.kind === 'dynamic') {
1473
1758
  return `gea::host::ObjectConstructor::assignInto(${targetView.receiver}, ${sourceView.receiver});`;
1474
1759
  }
1760
+ // A dynamic source into a string-keyed dictionary whose values are typed
1761
+ // (three's `Object.assign( this.spaces, colorSpaces )` with an untyped
1762
+ // `colorSpaces`). The source's keys exist only at runtime, so each
1763
+ // enumerable own string key is read as a `gea::Value` and stored through the
1764
+ // same checked per-value conversion a typed dictionary store uses -- an
1765
+ // entry the target's value type cannot hold is refused at run time by that
1766
+ // conversion, never boxed into the table.
1767
+ if (targetView.kind === 'dictionary' &&
1768
+ targetView.representation.key === 'string' &&
1769
+ sourceView.kind === 'dynamic' &&
1770
+ targetView.value.kind !== 'dynamic') {
1771
+ const converted = alignedValueText(ctx, 'host/emit-host-object.ts:assign-dynamic-into-typed-dictionary', dynamicCarrier, targetView.value, '__gea_value');
1772
+ if (converted === null) {
1773
+ return refuseObjectCarrier('assign', targetView.representation, `a dynamic source's entries are stored into a dictionary of "${representationKey(targetView.value)}" values, ` +
1774
+ 'and no installed conversion unboxes a dynamic value into that type');
1775
+ }
1776
+ return (`{ const auto& __gea_source = ${sourceView.receiver}; ` +
1777
+ `for (const std::string& __gea_key : __gea_source.ownEnumerableStringKeys()) { ` +
1778
+ `const gea::Value __gea_value = __gea_source.getProperty(gea::PropertyKey::string(__gea_key)); ` +
1779
+ `if (!${targetView.receiver}.setProperty(__gea_key, ${converted})) ` +
1780
+ 'gea::host::throwRuntimeError("TypeError", "Cannot assign to read only property"); } }');
1781
+ }
1475
1782
  if (targetView.kind === 'dictionary' || sourceView.kind === 'dictionary') {
1476
1783
  if (sourceView.kind === 'dictionary' &&
1477
1784
  // `assignDynamicProperties` (gea_runtime.h) takes its source as
@@ -1525,6 +1832,30 @@ const assignSourceText = (ctx, targetView, sourceView) => {
1525
1832
  `gea::nativeDynamicSet(${targetView.receiver}, gea::PropertyKey::string(__gea_key), ` +
1526
1833
  `__gea_source.getProperty(gea::PropertyKey::string(__gea_key))); }`);
1527
1834
  }
1835
+ if (targetView.kind === 'dynamic' && sourceView.kind === 'known') {
1836
+ // The source's keys are known here and the target is an object the
1837
+ // program declared `any` and never narrowed -- mongodb's
1838
+ // `Object.assign(command.readConcern, { afterClusterTime })` over a
1839
+ // `Document`. 7.3.25 is then one `[[Set]]` per present source field on
1840
+ // the dynamic object; each value is boxed because the dynamic object is
1841
+ // where it lands, not because the source is. The target is bound once:
1842
+ // an operand may be a deferred expression.
1843
+ const stores = [];
1844
+ for (const field of assignedKeyFields(ctx, sourceView)) {
1845
+ const value = getOwnValue(ctx, sourceView, field);
1846
+ const boxed = alignedValueText(ctx, 'host/emit-host-object.ts:assign-into-dynamic', value.representation, { kind: 'dynamic', reason: 'declared-any-never-narrowed' }, value.text);
1847
+ if (boxed === null) {
1848
+ return refuseObjectCarrier('assign', sourceView.representation, `the source field "${field.key}" carries "${representationKey(value.representation)}", which has no store into ` +
1849
+ 'the dynamic target this call copies into');
1850
+ }
1851
+ const store = `__gea_target.setProperty(gea::PropertyKey::string(${cppStringLiteral(field.key)}), ${boxed});`;
1852
+ const presence = ownKeyPresenceText('assign', sourceView, field);
1853
+ stores.push(presence === null ? store : `if (${presence}) ${store}`);
1854
+ }
1855
+ const creationOrdered = creationOrderedOwnCopyText(ctx, sourceView, (key, value) => `__gea_target.setProperty(gea::PropertyKey::string(${key}), ${value});`);
1856
+ const walked = creationOrdered === null ? stores.join(' ') : `if (!${creationOrdered}) { ${stores.join(' ')} }`;
1857
+ return `{ gea::Value __gea_target = ${targetView.receiver}; ${walked} }`;
1858
+ }
1528
1859
  if (targetView.kind === 'dynamic' || sourceView.kind === 'dynamic') {
1529
1860
  const known = targetView.kind === 'known' ? targetView : sourceView;
1530
1861
  if (known.kind !== 'known')
@@ -1533,18 +1864,127 @@ const assignSourceText = (ctx, targetView, sourceView) => {
1533
1864
  "and the two arms render the loop on different sides -- bridging them means walking one object's runtime key " +
1534
1865
  "table against the other's compile-time one, which is the struct dispatcher's job and not this call's");
1535
1866
  }
1536
- const stores = ownKeyFields(sourceView).map((field) => {
1537
- const store = setOwnText(ctx, 'assign', targetView, field.key, getOwnValue(ctx, sourceView, field));
1538
- const presence = ownKeyPresenceText('assign', sourceView, field);
1539
- return presence === null ? store : `if (${presence}) ${store}`;
1867
+ const stepped = steppedAssignText(ctx, targetView, sourceView);
1868
+ const stores = stepped !== null
1869
+ ? []
1870
+ : assignedKeyFields(ctx, sourceView).map((field) => {
1871
+ const store = setOwnText(ctx, 'assign', targetView, field.key, getOwnValue(ctx, sourceView, field));
1872
+ const presence = ownKeyPresenceText('assign', sourceView, field);
1873
+ return presence === null ? store : `if (${presence}) ${store}`;
1874
+ });
1875
+ // A source key outside its layout is copied too, in creation order: one the
1876
+ // target declares takes that field's own checked store, and any other is
1877
+ // created on the target's expando, as `[[Set]]` creates it.
1878
+ const targetShared = ownershipOfGeneratedCarrier(targetView.representation) === 'shared-refcount';
1879
+ const staticCopy = '__gea_assign_static_copy';
1880
+ const handsOver = targetShared && indexedRecordViewOf(ctx.deriver, sourceView.representation) === null;
1881
+ const creationOrdered = !targetShared
1882
+ ? null
1883
+ : creationOrderedOwnCopyText(ctx, sourceView, (key, value) => {
1884
+ // The routing depends on the target alone, whichever source is being
1885
+ // walked, so it is one unit function per target carrier.
1886
+ const at = (target, name, property) => {
1887
+ const view = { ...targetView, receiver: target };
1888
+ const declared = view.fields.filter((field) => !field.key.startsWith('sym('));
1889
+ const branches = declared.map((field) => `if (${name} == ${cppStringLiteral(field.key)}) { ` +
1890
+ `${setOwnText(ctx, 'assign', view, field.key, { text: property, representation: dynamicCarrier })} }`);
1891
+ const created = `{ if (!gea::nativeDynamicSet(${target}, gea::PropertyKey::string(${name}), ${property})) ` +
1892
+ 'gea::host::throwRuntimeError("TypeError", "Cannot assign to read only property"); }';
1893
+ return [...branches, created].join(' else ');
1894
+ };
1895
+ const routed = unitFunctionName('gea_assign_key_into', (name) => `void ${name}(const ${cppTypeOf(targetView.representation)}& gea_set_target, const std::string& gea_set_key, const gea::Value& gea_set_value)`, at('gea_set_target', 'gea_set_key', 'gea_set_value'));
1896
+ return routed === null ? at(targetView.receiver, key, value) : `${routed}(${targetView.receiver}, ${key}, ${value});`;
1897
+ }, handsOver ? { target: targetView.receiver, staticCopy, orderless: keyOrderUnobservedIn(ctx, targetView.representation) } : null);
1898
+ const copied = stepped ?? stores.join(' ');
1899
+ if (creationOrdered === null)
1900
+ return copied;
1901
+ if (handsOver)
1902
+ return `{ const auto ${staticCopy} = [&]() { ${copied} }; if (!${creationOrdered}) ${staticCopy}(); }`;
1903
+ return `if (!${creationOrdered}) { ${copied} }`;
1904
+ };
1905
+ /**
1906
+ * The static stores of a copy between two refcounted known shapes as a table
1907
+ * walk (`gea::record::assignSteps`), or `null` where the unrolled stores are
1908
+ * the better rendering.
1909
+ *
1910
+ * Each step is the SAME store `setOwnText` renders inline, as a captureless
1911
+ * lambda over the two receivers, beside the source field's presence member.
1912
+ * The loop tests presence from the table and calls only the present fields'
1913
+ * stores, so the code the copy executes is proportional to the fields the
1914
+ * source has rather than to the fields the layout declares: mongodb's
1915
+ * `Object.assign({}, options, resolveBSONOptions(...))` copied one 134-field
1916
+ * family struct into another as 26 KB of straight-line code per call, 2% of
1917
+ * the driver's CPU spent in the front end on tests that nearly all failed.
1918
+ * Below `steppedAssignFields` the unrolled stores are shorter than the table
1919
+ * and its indirect calls, so a small record keeps them.
1920
+ */
1921
+ const steppedAssignFields = 24;
1922
+ const steppedAssignText = (ctx, targetView, sourceView) => {
1923
+ const fields = assignedKeyFields(ctx, sourceView);
1924
+ if (fields.length < steppedAssignFields)
1925
+ return null;
1926
+ if (ownershipOfGeneratedCarrier(targetView.representation) !== 'shared-refcount' ||
1927
+ ownershipOfGeneratedCarrier(sourceView.representation) !== 'shared-refcount' ||
1928
+ targetView.accessor !== '->' ||
1929
+ sourceView.accessor !== '->') {
1930
+ return null;
1931
+ }
1932
+ const targetType = cppTypeOf(targetView.representation);
1933
+ const sourceType = cppTypeOf(sourceView.representation);
1934
+ const target = { ...targetView, receiver: 'gea_assign_target' };
1935
+ const source = { ...sourceView, receiver: 'gea_assign_source' };
1936
+ const steps = fields.map((field) => {
1937
+ const store = setOwnText(ctx, 'assign', target, field.key, getOwnValue(ctx, source, field));
1938
+ // A required field's bit is a `static` member of the struct when the
1939
+ // program-wide census made it constant (`records.ts`'s `constantPresence`),
1940
+ // and `&T::bit` is then a plain `bool*` no pointer-to-member can hold: the
1941
+ // step says "always present" instead, which is what that bit means.
1942
+ const present = field.required && ctx.fixedFieldStateConstant
1943
+ ? 'nullptr'
1944
+ : `&gea::record::RecordStructOf<${sourceType}>::type::${cppRecordFieldPresenceName(field.key)}`;
1945
+ return `{ ${present}, [](const ${targetType}& gea_assign_target, const ${sourceType}& gea_assign_source) { ${store} } }`;
1540
1946
  });
1541
- return stores.join(' ');
1947
+ return (`{ static constexpr gea::record::AssignStep<${targetType}, ${sourceType}> gea_assign_steps[] = { ${steps.join(', ')} }; ` +
1948
+ `static const auto gea_assign_runs = gea::record::assignRunsOf<${targetType}>(${sourceView.receiver}, gea_assign_steps); ` +
1949
+ `gea::record::assignSteps(${targetView.receiver}, ${sourceView.receiver}, gea_assign_steps, gea_assign_runs); }`);
1950
+ };
1951
+ /**
1952
+ * A native `Error` source copied into a struct target.
1953
+ *
1954
+ * mongodb's `MongoBulkWriteError` constructor ends in `Object.assign(this,
1955
+ * error)` over `AnyError`, one of whose arms is a plain `Error`. An Error's
1956
+ * own `name`/`message`/`stack` are non-enumerable (20.5.6.3), so its
1957
+ * enumerable own keys are exactly what the program added to its expando
1958
+ * sidecar -- a set that exists only at runtime, which `gea::nativeDynamicKeys`
1959
+ * already answers through the struct's own descriptor hooks. Each value lands
1960
+ * through the target's field dispatcher or its sidecar, the same `[[Set]]` the
1961
+ * dynamic-source arm uses, so neither object is boxed. Only `Error` is
1962
+ * admitted: other host structs (typed arrays, say) have enumerable own keys
1963
+ * the runtime's field table does not list, so the same loop would copy too few.
1964
+ */
1965
+ const nativeErrorSourceText = (targetView, source, receiver) => {
1966
+ if (!isNativeError(source) || targetView.kind !== 'known')
1967
+ return null;
1968
+ const target = targetView.representation;
1969
+ if ((target.kind !== 'record' && target.kind !== 'native-record-ref' && target.kind !== 'class-ref') ||
1970
+ target.ownership !== 'shared-refcount') {
1971
+ return null;
1972
+ }
1973
+ // 7.3.25 8.c.ii is `Set(to, key, value, true)`: a refused store throws.
1974
+ return (`{ const auto& __gea_source = ${receiver}; ` +
1975
+ 'for (const std::string& __gea_key : gea::nativeDynamicKeys(__gea_source)) ' +
1976
+ `if (!gea::nativeDynamicSet(${targetView.receiver}, gea::PropertyKey::string(__gea_key), ` +
1977
+ 'gea::nativeDynamicGet(__gea_source, gea::PropertyKey::string(__gea_key)))) ' +
1978
+ 'gea::host::throwRuntimeError("TypeError", "Cannot assign to read only property"); }');
1542
1979
  };
1543
1980
  /** Copy one source, including the spec's null/undefined skip and a union's live arm. */
1544
1981
  const assignOperandText = (ctx, targetView, source) => {
1545
1982
  const representation = source.representation;
1546
1983
  if (representation.kind === 'null' || representation.kind === 'undefined')
1547
1984
  return '';
1985
+ const nativeError = nativeErrorSourceText(targetView, representation, operandText(ctx, source));
1986
+ if (nativeError !== null)
1987
+ return nativeError;
1548
1988
  if (representation.kind === 'optional') {
1549
1989
  const receiver = operandText(ctx, source);
1550
1990
  const payload = objectViewFrom(ctx, 'assign', representation.payload, `(*(${receiver}))`, 'source');
@@ -1557,7 +1997,8 @@ const assignOperandText = (ctx, targetView, source) => {
1557
1997
  const branches = representation.arms.map((arm, index) => {
1558
1998
  const body = arm.value.kind === 'null' || arm.value.kind === 'undefined'
1559
1999
  ? ''
1560
- : assignSourceText(ctx, targetView, objectViewFrom(ctx, 'assign', arm.value, armAt(receiver, index), 'source'));
2000
+ : (nativeErrorSourceText(targetView, arm.value, armAt(receiver, index)) ??
2001
+ assignSourceText(ctx, targetView, objectViewFrom(ctx, 'assign', arm.value, armAt(receiver, index), 'source')));
1561
2002
  return `${index === 0 ? 'if' : 'else if'} (${armIs(receiver, index)}) { ${body} }`;
1562
2003
  });
1563
2004
  return branches.join(' ');
@@ -1591,7 +2032,7 @@ const assignIntoCallableText = (ctx, operation, target) => {
1591
2032
  return refuseObjectCarrier('assign', source.representation, "the target is a Function object, whose own properties this backend writes one key at a time, and the source's key " +
1592
2033
  'set is only known at run time -- walking it needs the runtime key loop the struct target has and a Function object ' +
1593
2034
  'does not');
1594
- return ownKeyFields(sourceView)
2035
+ return assignedKeyFields(ctx, sourceView)
1595
2036
  .map((field) => {
1596
2037
  const value = getOwnValue(ctx, sourceView, field);
1597
2038
  const converted = objectValueConversionText(ctx, operation, 'callable-property', sourceIndex + 1, field.key, value.representation, value.text);
@@ -1717,13 +2158,14 @@ const descriptorSlotLines = (ctx, operation, representation, text, slot) => {
1717
2158
  push(field, stated(`gea::host::throwRuntimeError("TypeError", "Object.defineProperty with an accessor descriptor (${field.key}) is not rendered by this backend");`));
1718
2159
  continue;
1719
2160
  }
1720
- // A literal accessor descriptor refuses the same way, at the call rather
1721
- // than the compile: installing it would have to decide how the receiver
1722
- // reaches the compiled getter, and a wrong answer reads the wrong object.
1723
- // `@hono/node-server` installs one only on its TRACE path, so the program
1724
- // runs and that path throws by name.
2161
+ // A literal's accessor half is the program's own function, boxed as a
2162
+ // data property's `value` is (the cited conversion keeps its receiver
2163
+ // convention) and installed as the half the object model calls with the
2164
+ // receiver of each [[Get]]/[[Set]]. ToPropertyDescriptor's own check that
2165
+ // a descriptor is not both kinds runs after every field is read, below.
1725
2166
  if (field.key === 'get' || field.key === 'set') {
1726
- push(field, `gea::host::throwRuntimeError("TypeError", "Object.defineProperty with an accessor descriptor (${field.key}) is not rendered by this backend");`);
2167
+ const boxed = carried.kind === 'dynamic' ? held : objectValueConversionText(ctx, operation, 'descriptor-value', 2, field.key, carried, held);
2168
+ push(field, `gea::${field.key === 'get' ? 'installDescriptorGetter' : 'installDescriptorSetter'}(${slot}, ${boxed});`);
1727
2169
  continue;
1728
2170
  }
1729
2171
  if (field.key === 'value') {
@@ -1763,7 +2205,10 @@ const descriptorSlotLines = (ctx, operation, representation, text, slot) => {
1763
2205
  throw createCppEmitBlockedError('host-member-call:ObjectConstructor.defineProperty', `"Object.defineProperty" was passed a descriptor with a field "${field.key}", which ECMA-262 6.1.7.1 does not define; ` +
1764
2206
  'a descriptor field this backend ignored would silently drop what the program asked for');
1765
2207
  }
1766
- return `gea::PropertyDescriptor ${slot}; ${assignments.join(' ')}`;
2208
+ const mixed = fields.some((field) => field.key === 'get' || field.key === 'set')
2209
+ ? ` if (${slot}.isAccessor() && ${slot}.isData()) gea::host::throwRuntimeError("TypeError", "Invalid property descriptor. Cannot both specify accessors and a value or writable attribute");`
2210
+ : '';
2211
+ return `gea::PropertyDescriptor ${slot}; ${assignments.join(' ')}${mixed}`;
1767
2212
  };
1768
2213
  /**
1769
2214
  * The descriptor's `value`, still in the carrier the program wrote it in.
@@ -1943,6 +2388,65 @@ const fixedFieldDefinePropertyText = (ctx, view, recipe, descriptor, targetOpera
1943
2388
  `${hasWritable}, ${writable}, ${hasEnumerable}, ${enumerable}, ${hasConfigurable}, ${configurable})) ` +
1944
2389
  `gea::host::throwRuntimeError("TypeError", "Cannot redefine property: ${field.key}");${publish} return ${target}; })()`);
1945
2390
  };
2391
+ /**
2392
+ * `Object.defineProperty` of a union whose every arm is a generated shared
2393
+ * record or a box: the live arm defines the key through its own protocol, as
2394
+ * the two single-carrier arms of `definePropertyText` below do. mongodb's
2395
+ * `decorateDecryptionResult` holds the caller's adopted Document in the record
2396
+ * arm and every nested `decrypted[k]` its recursion passes in the box arm.
2397
+ * `null` for any other receiver.
2398
+ */
2399
+ const unionDefinePropertyText = (ctx, operation, target, key, descriptor) => {
2400
+ const union = target.representation;
2401
+ if (union.kind !== 'tagged-union')
2402
+ return null;
2403
+ const slot = '__gea_descriptor';
2404
+ const receiver = '__gea_target';
2405
+ const propertyKey = propertyKeyOperandText(ctx, key, '"Object.defineProperty" of a union');
2406
+ const arms = [];
2407
+ for (const [index, arm] of union.arms.entries()) {
2408
+ const generated = generatedRecordReceiver(arm.value, armAt(receiver, index));
2409
+ if (generated !== null)
2410
+ arms.push(`if (!${generatedDefineOwnText(generated, propertyKey, slot)}) ` +
2411
+ 'gea::host::throwRuntimeError("TypeError", "Cannot define native record property");');
2412
+ else if (arm.value.kind === 'dynamic')
2413
+ arms.push(`gea::host::ObjectConstructor::defineProperty(${armAt(receiver, index)}, ${propertyKey}, ${slot});`);
2414
+ else {
2415
+ const constructorArm = constructorViewDefineText(ctx, arm.value, armAt(receiver, index), key, propertyKey, slot);
2416
+ if (constructorArm === null)
2417
+ return null;
2418
+ arms.push(constructorArm);
2419
+ }
2420
+ }
2421
+ const dispatched = arms.map((text, index) => (index === arms.length - 1 ? `{ ${text} }` : `if (${armIs(receiver, index)}) { ${text} }`));
2422
+ return (`([&]() { ${defineDescriptorLines(ctx, operation, descriptor, slot)} const auto& ${receiver} = ${operandText(ctx, target)}; ` +
2423
+ `${dispatched.join(' else ')} return ${receiver}; })()`);
2424
+ };
2425
+ /**
2426
+ * A class constructor arm of such a union, defining a key some record shape
2427
+ * class constructors are viewed as declares: the constructor's own property
2428
+ * lives in its view record (`constructorViewFieldFor`), the storage
2429
+ * `C.key = v` writes and `(this.constructor as { key?: T }).key` reads, so the
2430
+ * define goes through that record's own [[DefineOwnProperty]]. mongodb's
2431
+ * `defineAspects(operation: { aspects?: Set<symbol> }, ...)` receives each
2432
+ * operation class. `null` for any other arm, or a key no view declares.
2433
+ */
2434
+ const constructorViewDefineText = (ctx, arm, armText, key, propertyKey, slot) => {
2435
+ if (arm.kind !== 'constructor-family' && arm.kind !== 'constructor-identity')
2436
+ return null;
2437
+ if (arm.kind === 'constructor-family' && arm.members.some((member) => member.includes('@')))
2438
+ return null;
2439
+ const literalKey = ctx.staticKeyTexts.get(key.value);
2440
+ if (literalKey === undefined)
2441
+ return null;
2442
+ const viewed = constructorViewFieldFor(ctx, literalKey);
2443
+ const state = constructorStateText(arm, armText);
2444
+ if (viewed === null || state === null)
2445
+ return null;
2446
+ return (`auto __gea_view = gea::constructorStaticView<${viewed.struct}>(${state}); ` +
2447
+ `if (!${generatedDefineOwnText('__gea_view', propertyKey, slot)}) ` +
2448
+ 'gea::host::throwRuntimeError("TypeError", "Cannot define class constructor property");');
2449
+ };
1946
2450
  const definePropertyText = (ctx, operation) => {
1947
2451
  const target = targetOf(ctx, 'defineProperty', operation);
1948
2452
  const key = operation.arguments[1];
@@ -1956,6 +2460,9 @@ const definePropertyText = (ctx, operation) => {
1956
2460
  throw createCppEmitBlockedError('host-member-call:ObjectConstructor.defineProperty', 'fixed data definition requires native storage');
1957
2461
  return fixedFieldDefinePropertyText(ctx, view, operation.fixedDataDefinition, descriptor, target);
1958
2462
  }
2463
+ const overArms = unionDefinePropertyText(ctx, operation, target, key, descriptor);
2464
+ if (overArms !== null)
2465
+ return overArms;
1959
2466
  const intrinsic = nativeHandleDefinePropertyText(ctx, operation, target, key, descriptor);
1960
2467
  if (intrinsic !== null)
1961
2468
  return intrinsic;
@@ -2111,9 +2618,96 @@ const definePropertyText = (ctx, operation) => {
2111
2618
  * protocol, so reaching a Map overload with one would be a wrong answer rather
2112
2619
  * than a missing one.
2113
2620
  */
2621
+ /**
2622
+ * `Object.fromEntries` over an Array of `[key, value]` pairs or a native cursor
2623
+ * of them (`map.entries()`, a generator): 20.1.2.7 drains the iterable and, per
2624
+ * entry, reads `entry[0]`/`entry[1]` and `CreateDataPropertyOrThrow`s the pair
2625
+ * onto a fresh ordinary object -- a later duplicate key overwrites an earlier
2626
+ * one in place, keeping its first insertion position, which is `Dictionary`'s
2627
+ * own `operator[]`. A tuple is a positional record, so the pair's halves are
2628
+ * its "0"/"1" fields. Only a string key is admitted: ToPropertyKey of anything
2629
+ * else is a conversion this renderer does not spell. A hole is `undefined`,
2630
+ * which is not an entry object -- the TypeError AddEntriesFromIterable (24.1.1.2)
2631
+ * raises. `null` when the source is neither shape, so the caller keeps its Map
2632
+ * arm and its refusal.
2633
+ */
2634
+ const pairWalkFromEntriesText = (ctx, operation, source) => {
2635
+ const carrier = source.representation;
2636
+ const pair = carrier.kind === 'array-object' ? carrier.element : carrier.kind === 'iterator' ? carrier.element : null;
2637
+ if (pair === null)
2638
+ return null;
2639
+ const refuse = (detail) => {
2640
+ throw createCppEmitBlockedError('host-member-call:Object.fromEntries', `Object.fromEntries over a "${representationKey(carrier)}" source: ${detail}`);
2641
+ };
2642
+ if (carrier.kind === 'array-object' && carrier.ownership !== 'shared-refcount')
2643
+ refuse('the source Array is not shared-refcount');
2644
+ const result = operation.result?.representation;
2645
+ if (result === undefined || result.kind !== 'dictionary' || result.key !== 'string' || result.ownership !== 'shared-refcount') {
2646
+ return refuse(`the result carries "${result === undefined ? 'nothing' : representationKey(result)}", and only a fresh shared string-keyed ` +
2647
+ 'dictionary is the ordinary object 20.1.2.7 creates here');
2648
+ }
2649
+ // A pair whose two halves share one carrier (`[string, string]`, what a
2650
+ // `Map<string, string>`'s entries are) is laid out as an Array rather than a
2651
+ // record; its halves are its elements 0 and 1, and a missing one aborts by
2652
+ // name rather than being read as a default.
2653
+ const halves = (() => {
2654
+ if (pair.kind === 'array-object' && pair.ownership === 'shared-refcount') {
2655
+ const read = (index) => `gea::runtime::array::elementOrRefuse(gea_pair, ${index}, "Object.fromEntries")`;
2656
+ return { key: pair.element, value: pair.element, keyText: read(0), valueText: read(1) };
2657
+ }
2658
+ const fields = pair.kind === 'record'
2659
+ ? pair.fields
2660
+ : pair.kind === 'native-record-ref' && pair.native === null
2661
+ ? recordFieldsOfShape(ctx.deriver, pair.shapeId)
2662
+ : null;
2663
+ if (fields === null || fields.length !== 2)
2664
+ return null;
2665
+ const [first, second] = fields;
2666
+ if (first?.key !== '0' || second?.key !== '1' || !first.required || !second.required)
2667
+ return null;
2668
+ const access = memberAccessOperator(pair.kind === 'record' || pair.kind === 'native-record-ref' ? pair.ownership : 'owned');
2669
+ return {
2670
+ key: first.value,
2671
+ value: second.value,
2672
+ keyText: `gea_pair${access}${cppRecordFieldName('0')}`,
2673
+ valueText: `gea_pair${access}${cppRecordFieldName('1')}`
2674
+ };
2675
+ })();
2676
+ if (halves === null)
2677
+ return refuse(`its entry "${representationKey(pair)}" is not a two-position [key, value] pair`);
2678
+ // ToPropertyKey of an absent key is its ToString: an entry whose key is
2679
+ // `undefined` (the mongodb driver's optional index `name`) lands under
2680
+ // "undefined", exactly as node stores it.
2681
+ const keyCarrier = halves.key;
2682
+ const keyText = keyCarrier.kind === 'string'
2683
+ ? halves.keyText
2684
+ : keyCarrier.kind === 'optional' && keyCarrier.payload.kind === 'string'
2685
+ ? `([&](const auto& gea_key) { return gea_key.has_value() ? std::string(*gea_key) : std::string(${cppStringLiteral(keyCarrier.absence)}); })(${halves.keyText})`
2686
+ : null;
2687
+ if (keyText === null) {
2688
+ return refuse(`its keys carry "${representationKey(halves.key)}", and ToPropertyKey of anything but a string is not spelled here`);
2689
+ }
2690
+ const value = alignedValueText(ctx, 'host/emit-host-object.ts:fromEntries-pair', halves.value, result.value, halves.valueText);
2691
+ if (value === null) {
2692
+ return refuse(`its values carry "${representationKey(halves.value)}" and no conversion is installed into the result's own value ` +
2693
+ `carrier "${representationKey(result.value)}"`);
2694
+ }
2695
+ const store = `(*gea_object)[${keyText}] = ${value};`;
2696
+ const dictionaryType = cppTypeOf({ ...result, ownership: 'owned' });
2697
+ const walk = carrier.kind === 'array-object'
2698
+ ? `if (gea_source) for (const auto& gea_slot : gea_source->slots()) { ` +
2699
+ `if (!gea_slot.present) gea::host::throwRuntimeError("TypeError", "Iterator value undefined is not an entry object"); ` +
2700
+ `const auto& gea_pair = gea_slot.value; ${store} }`
2701
+ : `auto gea_cursor = gea_source; while (true) { auto gea_pair = gea_cursor.arrayNext(); if (gea_cursor.done()) break; ${store} }`;
2702
+ return (`([&](const ${cppTypeOf(carrier)}& gea_source) { auto gea_object = gea::makeRef<${dictionaryType}>(); ${walk} ` +
2703
+ `return gea_object; })(${operandText(ctx, source)})`);
2704
+ };
2114
2705
  const fromEntriesText = (ctx, operation) => {
2115
2706
  const source = targetOf(ctx, 'fromEntries', operation);
2116
2707
  const representation = source.representation;
2708
+ const walked = pairWalkFromEntriesText(ctx, operation, source);
2709
+ if (walked !== null)
2710
+ return walked;
2117
2711
  if (representation.kind !== 'keyed-collection' || representation.family !== 'map') {
2118
2712
  throw createCppEmitBlockedError('host-member-call:Object.fromEntries', `Object.fromEntries over a "${representationKey(representation)}" source is not rendered: 20.1.2.7 walks any iterable of ` +
2119
2713
  'entries, and only the Map family has a stated iteration here -- an array of pairs or a generator needs its own');
@@ -2138,37 +2732,86 @@ const isText = (ctx, operation) => {
2138
2732
  if (left === undefined || right === undefined) {
2139
2733
  throw createCppEmitBlockedError('host-member-call:Object.is', `"Object.is" takes two values, and this call passes ${operation.arguments.length}`);
2140
2734
  }
2141
- const leftText = operandText(ctx, left);
2142
- const rightText = operandText(ctx, right);
2143
- const leftCarrier = left.representation;
2144
- const rightCarrier = right.representation;
2145
- const isNumber = (carrier) => carrier.kind === 'scalar' && carrier.domain !== 'boolean' && carrier.domain !== 'bigint';
2146
- if (isNumber(leftCarrier) && isNumber(rightCarrier)) {
2147
- return `gea::sameNumberValue(static_cast<double>(${leftText}), static_cast<double>(${rightText}))`;
2735
+ return sameValueText(left.representation, operandText(ctx, left), right.representation, operandText(ctx, right));
2736
+ };
2737
+ /** The primitive type a leaf carrier holds, or null for an object carrier. */
2738
+ const primitiveTypeOf = (carrier) => {
2739
+ switch (carrier.kind) {
2740
+ case 'null':
2741
+ case 'undefined':
2742
+ case 'string':
2743
+ case 'symbol':
2744
+ return carrier.kind;
2745
+ case 'void':
2746
+ return 'undefined';
2747
+ case 'scalar':
2748
+ return carrier.domain === 'boolean' || carrier.domain === 'bigint' ? carrier.domain : 'number';
2749
+ default:
2750
+ return null;
2148
2751
  }
2149
- if (leftCarrier.kind === 'dynamic' && rightCarrier.kind === 'dynamic') {
2150
- return `gea::Value::sameValue(${leftText}, ${rightText})`;
2752
+ };
2753
+ /**
2754
+ * ECMA-262 7.2.10 SameValue over two carriers.
2755
+ *
2756
+ * A composite carrier is taken apart before anything is compared: a union
2757
+ * holding `0` and a `number` holding `0` are the same value, and deciding by
2758
+ * the two carriers' spellings answered `false` for it -- constant-folded, with
2759
+ * no diagnostic (`Object.is(xs[0], 0)` over a `(string | number)[]`). Only a
2760
+ * pair of leaves is compared, and leaves of different primitive types are
2761
+ * different values by definition (step 1).
2762
+ */
2763
+ const sameValueText = (leftCarrier, leftText, rightCarrier, rightText, depth = 0) => {
2764
+ if (leftCarrier.kind === 'dynamic' || rightCarrier.kind === 'dynamic') {
2765
+ const leftBox = leftCarrier.kind === 'dynamic' ? leftText : dynamicCarrierBoxText(leftCarrier, leftText);
2766
+ const rightBox = rightCarrier.kind === 'dynamic' ? rightText : dynamicCarrierBoxText(rightCarrier, rightText);
2767
+ if (leftBox === null || rightBox === null) {
2768
+ throw createCppEmitBlockedError('host-member-call:Object.is', `"Object.is" of "${representationKey(leftCarrier)}" and "${representationKey(rightCarrier)}" cannot box the typed side to compare`);
2769
+ }
2770
+ return `gea::Value::sameValue(${leftBox}, ${rightBox})`;
2151
2771
  }
2152
- if (leftCarrier.kind === 'null' || leftCarrier.kind === 'undefined') {
2153
- return leftCarrier.kind === rightCarrier.kind ? 'true' : 'false';
2772
+ if (leftCarrier.kind === 'tagged-union' || leftCarrier.kind === 'optional') {
2773
+ // Named after the nesting depth: every composite opens a lambda inside the
2774
+ // last one, and a leaf's text names the outer lambdas' values, so no two
2775
+ // may share a name.
2776
+ const name = `gea_same_${depth}`;
2777
+ return `([&](const ${cppTypeOf(leftCarrier)}& ${name}) -> bool { ${composite(leftCarrier, name, (arm, text) => sameValueText(arm, text, rightCarrier, rightText, depth + 1))} }(${leftText}))`;
2154
2778
  }
2155
- if (representationKey(leftCarrier) !== representationKey(rightCarrier))
2779
+ if (rightCarrier.kind === 'tagged-union' || rightCarrier.kind === 'optional') {
2780
+ return sameValueText(rightCarrier, rightText, leftCarrier, leftText, depth);
2781
+ }
2782
+ const leftType = primitiveTypeOf(leftCarrier);
2783
+ const rightType = primitiveTypeOf(rightCarrier);
2784
+ if (leftType !== rightType && (leftType !== null || rightType !== null))
2156
2785
  return 'false';
2157
- if (leftCarrier.kind === 'string' ||
2158
- leftCarrier.kind === 'symbol' ||
2159
- leftCarrier.kind === 'scalar' ||
2160
- leftCarrier.kind === 'array-buffer' ||
2161
- leftCarrier.kind === 'shared-array-buffer' ||
2162
- leftCarrier.kind === 'data-view' ||
2163
- ('ownership' in leftCarrier && leftCarrier.ownership === 'shared-refcount')) {
2786
+ if (leftType === 'null' || leftType === 'undefined')
2787
+ return 'true';
2788
+ if (leftType === 'number')
2789
+ return `gea::sameNumberValue(static_cast<double>(${leftText}), static_cast<double>(${rightText}))`;
2790
+ if (leftType !== null)
2791
+ return `${leftText} == ${rightText}`;
2792
+ if (representationKey(leftCarrier) === representationKey(rightCarrier) &&
2793
+ (leftCarrier.kind === 'array-buffer' ||
2794
+ leftCarrier.kind === 'shared-array-buffer' ||
2795
+ leftCarrier.kind === 'data-view' ||
2796
+ ('ownership' in leftCarrier && leftCarrier.ownership === 'shared-refcount'))) {
2164
2797
  return `${leftText} == ${rightText}`;
2165
2798
  }
2166
- throw createCppEmitBlockedError('host-member-call:Object.is', `"Object.is" over two "${representationKey(leftCarrier)}" carriers has no SameValue comparison; the backend will not ` +
2167
- 'substitute storage equality for JavaScript value or object identity');
2799
+ throw createCppEmitBlockedError('host-member-call:Object.is', `"Object.is" over "${representationKey(leftCarrier)}" and "${representationKey(rightCarrier)}" carriers has no SameValue comparison; ` +
2800
+ 'the backend will not substitute storage equality for JavaScript value or object identity');
2801
+ };
2802
+ /** The statements of a lambda body answering `leaf` for whichever arm of `carrier` the value named `name` holds. */
2803
+ const composite = (carrier, name, leaf) => {
2804
+ if (carrier.kind === 'optional') {
2805
+ return `return ${name}.has_value() ? (${leaf(carrier.payload, `(*${name})`)}) : (${leaf({ kind: carrier.absence }, '')});`;
2806
+ }
2807
+ const arms = carrier.arms.map((arm, index) => `if (${armIs(name, index)}) return ${leaf(arm.value, armAt(name, index))};`);
2808
+ return `${arms.join(' ')} return false;`;
2168
2809
  };
2169
2810
  export const objectMemberText = (ctx, member, operation) => {
2170
2811
  if (member === 'keys' || member === 'getOwnPropertyNames')
2171
2812
  return keysText(ctx, member, operation);
2813
+ if (member === 'getOwnPropertySymbols')
2814
+ return ownPropertySymbolsText(ctx, operation);
2172
2815
  if (member === 'values')
2173
2816
  return valuesText(ctx, operation);
2174
2817
  if (member === 'entries')
@@ -2189,6 +2832,8 @@ export const objectMemberText = (ctx, member, operation) => {
2189
2832
  return hasOwnText(ctx, operation);
2190
2833
  if (member === 'getPrototypeOf')
2191
2834
  return getPrototypeOfText(ctx, operation);
2835
+ if (member === 'setPrototypeOf')
2836
+ return setPrototypeOfText(ctx, operation);
2192
2837
  if (member === 'is')
2193
2838
  return isText(ctx, operation);
2194
2839
  if (member === 'getOwnPropertyDescriptor')