@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,7 +1,8 @@
1
1
  import { extendsClass, virtualDispatchKey, virtualMethodFamiliesOf } from '../../projection/dispatch.js';
2
2
  export { extendsClass, virtualDispatchKey, virtualMethodFamiliesOf };
3
3
  import { cppFormalName } from './emit-context.js';
4
- import { cppAbiParameterType, cppBodyName, cppClassName, cppRecordFieldName, cppResultTypeOf, cppStringLiteral, cppTypeOf, cppUndefinedIn } from './types.js';
4
+ import { wellKnownSymbolEnumNameOf } from './records.js';
5
+ import { cppAbiParameterType, cppBodyName, cppCallableDeclarationTagName, cppClassName, cppRecordFieldKeyIsSymbol, cppRecordFieldName, cppResultTypeOf, cppStringLiteral, cppTypeOf, cppUndefinedIn } from './types.js';
5
6
  import { alignedValueText, dynamicCarrierBoxText } from './emit-narrowing.js';
6
7
  /**
7
8
  * The C++ member one family dispatches through.
@@ -10,7 +11,21 @@ import { alignedValueText, dynamicCarrierBoxText } from './emit-narrowing.js';
10
11
  * and a method whose names would otherwise collide inside one struct, and the
11
12
  * field's spelling is already `cppRecordFieldName`'s.
12
13
  */
13
- export const cppVirtualMemberName = (key, role = 'call') => `${role === 'set' ? 'gea_vset_' : role === 'get' ? 'gea_vget_' : 'gea_vcall_'}${cppRecordFieldName(key)}`;
14
+ export const cppVirtualMemberName = (key, role = 'call', copy) => `${role === 'set' ? 'gea_vset_' : role === 'get' ? 'gea_vget_' : 'gea_vcall_'}${cppRecordFieldName(key)}${copy === undefined ? '' : `_c${copyTagOf(copy)}`}`;
15
+ /**
16
+ * A short, stable spelling of a generic-method copy's convention for its
17
+ * member name (`projection/dispatch.ts`'s `virtualCopyFamiliesOf`): FNV-1a over
18
+ * the receiverless ABI key, so the family and every call site derive the same
19
+ * name from the convention alone.
20
+ */
21
+ const copyTagOf = (copy) => {
22
+ let hash = 0x811c9dc5;
23
+ for (let index = 0; index < copy.length; index++) {
24
+ hash ^= copy.charCodeAt(index);
25
+ hash = Math.imul(hash, 0x01000193) >>> 0;
26
+ }
27
+ return hash.toString(16).padStart(8, '0');
28
+ };
14
29
  /** The parameter list a family's member takes: the body's ABI minus the receiver, which becomes `this`. */
15
30
  const memberFormalsOf = (abi) => abi.parameters.map((parameter, ordinal) => `${cppAbiParameterType(parameter)} ${cppFormalName(ordinal)}`);
16
31
  /**
@@ -87,6 +102,9 @@ const virtualMethodAdapterOf = (site, classes, family, implementor, rootAbi, act
87
102
  const result = virtualValueConversionText(site, classes, actualAbi.result, rootAbi.result, invocation) ?? drift('the result');
88
103
  return { result };
89
104
  };
105
+ const throwVirtualFieldDrift = (declaration, key) => {
106
+ throw new Error(`virtual field implementation ${declaration}.${key}: the dispatch verdict proved a conversion the emitter found none for`);
107
+ };
90
108
  const throwVirtualAdapterDrift = (family, implementor, reason) => {
91
109
  throw new Error(`virtual method adapter for ${implementor.declaration}.${family.key}: ${reason}`);
92
110
  };
@@ -104,9 +122,10 @@ const throwVirtualAdapterDrift = (family, implementor, reason) => {
104
122
  * capture index at render time the way `targets/cpp/captures.ts`'s
105
123
  * `buildCaptureIndex` used to require.
106
124
  */
107
- export const virtualMethodEmission = (site, classes, abiOf, verdict) => {
125
+ export const virtualMethodEmission = (site, classes, abiOf, verdict, reparentTargets = new Map()) => {
108
126
  const membersByStruct = new Map();
109
127
  const definitions = [];
128
+ const reparented = reparentedAllocationsOf(reparentTargets);
110
129
  for (const { family, rootAbi } of verdict.families) {
111
130
  const adapters = new Map();
112
131
  for (const implementor of family.implementors) {
@@ -127,20 +146,39 @@ export const virtualMethodEmission = (site, classes, abiOf, verdict) => {
127
146
  const failure = `std::fprintf(stderr, "gea: abstract method ${String(family.root)}.${family.key} has no implementation\\n"); std::abort();`;
128
147
  membersByStruct.set(cppClassName(family.root), [
129
148
  ...(membersByStruct.get(cppClassName(family.root)) ?? []),
130
- ` virtual ${result} ${cppVirtualMemberName(family.key, family.role)}(${formals});`
149
+ ` virtual ${result} ${cppVirtualMemberName(family.key, family.role, family.copy)}(${formals});`
131
150
  ]);
132
- definitions.push(`${result} ${cppClassName(family.root)}::${cppVirtualMemberName(family.key, family.role)}(${formals}) { ${failure} }`);
151
+ definitions.push(`${result} ${cppClassName(family.root)}::${cppVirtualMemberName(family.key, family.role, family.copy)}(${formals}) { ${failure} }`);
133
152
  }
134
153
  for (const implementor of family.implementors) {
135
154
  const structName = cppClassName(implementor.declaration);
136
155
  const isRoot = implementor.declaration === family.root && !family.abstractRoot;
137
156
  const members = membersByStruct.get(structName) ?? [];
138
- members.push(` ${isRoot ? 'virtual ' : ''}${result} ${cppVirtualMemberName(family.key, family.role)}(${formals})${isRoot ? '' : ' override'};`);
157
+ members.push(` ${isRoot ? 'virtual ' : ''}${result} ${cppVirtualMemberName(family.key, family.role, family.copy)}(${formals})${isRoot ? '' : ' override'};`);
139
158
  membersByStruct.set(structName, members);
140
159
  const adapter = adapters.get(implementor.declaration);
141
160
  if (adapter === undefined)
142
161
  throw new Error(`virtual method adapter for ${implementor.declaration}.${family.key} was not retained`);
143
- definitions.push(`${result} ${structName}::${cppVirtualMemberName(family.key, family.role)}(${formals}) { ${result === 'void' ? '' : 'return '}${adapter.result}; }`);
162
+ const prefix = reparentPrefixOf(classes, family, implementor.declaration, reparented, rootAbi.parameters.length);
163
+ definitions.push(`${result} ${structName}::${cppVirtualMemberName(family.key, family.role, family.copy)}(${formals}) { ${prefix}${result === 'void' ? '' : 'return '}${adapter.result}; }`);
164
+ }
165
+ // A derived class whose own data field implements the accessor: the
166
+ // override reads (or writes) that field, which is what the property is
167
+ // on such an instance (`VirtualMethodFamily.fieldImplementors`).
168
+ for (const { declaration, field } of family.fieldImplementors ?? []) {
169
+ const structName = cppClassName(declaration);
170
+ const stored = field.representation;
171
+ if (stored === null)
172
+ throw new Error(`virtual field implementation ${declaration}.${family.key} has no carrier`);
173
+ const member = cppVirtualMemberName(family.key, family.role, family.copy);
174
+ const slot = `this->${cppRecordFieldName(family.key)}`;
175
+ const written = rootAbi.parameters[0]?.value;
176
+ const body = family.role === 'get'
177
+ ? `return ${virtualValueConversionText(site, classes, stored, rootAbi.result, slot) ?? throwVirtualFieldDrift(declaration, family.key)};`
178
+ : `${slot} = ${(written && virtualValueConversionText(site, classes, written, stored, cppFormalName(0))) ?? throwVirtualFieldDrift(declaration, family.key)};` +
179
+ (result === 'void' ? '' : ` return ${cppUndefinedIn(rootAbi.result) ?? throwVirtualFieldDrift(declaration, family.key)};`);
180
+ membersByStruct.set(structName, [...(membersByStruct.get(structName) ?? []), ` ${result} ${member}(${formals}) override;`]);
181
+ definitions.push(`${result} ${structName}::${member}(${formals}) { ${body} }`);
144
182
  }
145
183
  }
146
184
  return {
@@ -150,6 +188,84 @@ export const virtualMethodEmission = (site, classes, abiOf, verdict) => {
150
188
  dispatched: new Map([...verdict.dispatched].map(([key, entry]) => [key, entry.rootAbi]))
151
189
  };
152
190
  };
191
+ /**
192
+ * Which classes an instance ALLOCATED as each class may be re-classed onto,
193
+ * closed over chains: an instance re-classed S -> M and then M -> M2 still
194
+ * carries S's vtable, so S's members must know M2 as well.
195
+ */
196
+ const reparentedAllocationsOf = (targets) => {
197
+ const allocations = new Map();
198
+ for (const [target, sources] of targets)
199
+ allocations.set(target, new Set(sources));
200
+ let changed = true;
201
+ while (changed) {
202
+ changed = false;
203
+ for (const [target, sources] of allocations) {
204
+ for (const source of [...sources]) {
205
+ for (const inherited of allocations.get(source) ?? []) {
206
+ if (inherited === target || sources.has(inherited))
207
+ continue;
208
+ sources.add(inherited);
209
+ changed = true;
210
+ }
211
+ }
212
+ }
213
+ }
214
+ const byAllocation = new Map();
215
+ for (const [target, sources] of allocations) {
216
+ for (const source of sources)
217
+ byAllocation.set(source, (byAllocation.get(source) ?? new Set()).add(target));
218
+ }
219
+ return byAllocation;
220
+ };
221
+ /** The class whose body a `key` call on an exact `declaration` instance runs: the nearest along its chain that implements it. */
222
+ const implementorFor = (classes, family, declaration) => {
223
+ const implementors = new Set(family.implementors.map((implementor) => implementor.declaration));
224
+ const walked = new Set();
225
+ for (let current = declaration; current !== null && !walked.has(current); current = classes.get(current)?.base ?? null) {
226
+ walked.add(current);
227
+ if (implementors.has(current))
228
+ return current;
229
+ }
230
+ return null;
231
+ };
232
+ /**
233
+ * The re-class test a virtual member's definition runs first, when an
234
+ * instance whose vtable leads here may have been re-classed
235
+ * (`gea::reparentInstance`) onto a class that answers this key with a
236
+ * different body.
237
+ *
238
+ * A re-classed object keeps the vtable of the class it was allocated as --
239
+ * C++ gives no way to change it -- while its ref header now names the new
240
+ * class. So the definition every such vtable resolves to asks the header, and
241
+ * forwards to the new class's own definition by a QUALIFIED (non-virtual)
242
+ * call. The static downcast is sound only because the target adds no storage,
243
+ * which `ir/instance-reparenting.ts` proves and `gea::reparentInstance`
244
+ * re-asserts: the object is laid out exactly as the target is.
245
+ *
246
+ * Only definitions some allocated class's vtable reaches for a proven
247
+ * re-parent get a test; every other class pays nothing.
248
+ */
249
+ const reparentPrefixOf = (classes, family, definer, reparented, arity) => {
250
+ const forwards = [];
251
+ const seenTargets = new Set();
252
+ const actuals = Array.from({ length: arity }, (_, ordinal) => `std::move(${cppFormalName(ordinal)})`).join(', ');
253
+ for (const [allocated, targets] of [...reparented].sort(([left], [right]) => (left < right ? -1 : 1))) {
254
+ if (implementorFor(classes, family, allocated) !== definer)
255
+ continue;
256
+ for (const target of [...targets].sort()) {
257
+ if (seenTargets.has(target))
258
+ continue;
259
+ const answering = implementorFor(classes, family, target);
260
+ if (answering === null || answering === definer)
261
+ continue;
262
+ seenTargets.add(target);
263
+ forwards.push(`if (gea::detail::refHeaderOf(static_cast<void*>(this))->operations == &gea::detail::RefOperationsFor<${cppClassName(target)}>::table) ` +
264
+ `return static_cast<${cppClassName(target)}*>(this)->${cppClassName(answering)}::${cppVirtualMemberName(family.key, family.role, family.copy)}(${actuals}); `);
265
+ }
266
+ }
267
+ return forwards.join('');
268
+ };
153
269
  /**
154
270
  * The runtime's `NativePrototypeTable` hooks for every class that declares a
155
271
  * getter or method, so a boxed instance answers a dynamic read of either.
@@ -174,15 +290,24 @@ export const virtualMethodEmission = (site, classes, abiOf, verdict) => {
174
290
  * dynamic carrier must not spell at all (`test/stored-listener-native-flow`,
175
291
  * `native-method-overrides`' `emitted-lacks: gea::Value::box`).
176
292
  */
177
- export const prototypeReadHooks = (classes, abiOf, capturesNothing, readDynamically) => {
178
- // A method read yields a fresh function object over the body: a dynamic
179
- // read is followed by a call, and nothing on that path compares identities.
293
+ export const prototypeReadHooks = (classes, abiOf, capturesNothing, readDynamically, wellKnownSymbols = new Map()) => {
294
+ // A method read yields the ONE function object its class evaluation holds
295
+ // for that method (`gea::nativeClassMethodValue`), the object a native read
296
+ // of it yields too. A fresh object per read made `box.m === box.m` false and
297
+ // dropped every write through it: mongodb-shaped code that patches a
298
+ // method's `bind` through a boxed instance wrote onto a throwaway, and a
299
+ // native `this.m.bind(this)` guarded on that object's own `bind`
300
+ // (`emit-callable.ts`'s `guardedBindLines`) could not see the write.
180
301
  const methods = (layout) => layout.methods.flatMap((method) => {
181
302
  if (method.callable === null || !capturesNothing(method.callable))
182
303
  return [];
183
304
  const abi = abiOf(method.callable);
184
305
  if (abi === null || abi.receiver === null)
185
306
  return [];
307
+ const callable = method.callable;
308
+ const owner = [...classes.values()].find((candidate) => candidate.methods.some((entry) => entry.callable === callable && entry.key === method.key));
309
+ if (owner === undefined)
310
+ return [];
186
311
  const value = { kind: 'function-value-dispatch', abi };
187
312
  const receiver = abi.receiver;
188
313
  const formals = [
@@ -191,7 +316,9 @@ export const prototypeReadHooks = (classes, abiOf, capturesNothing, readDynamica
191
316
  ];
192
317
  const actuals = ['gea_receiver', ...abi.parameters.map((_, i) => cppFormalName(i))];
193
318
  const thunk = `+[](void*, ${formals.join(', ')}) -> ${cppResultTypeOf(abi.result)} { return ${cppBodyName(method.callable)}(${actuals.join(', ')}); }`;
194
- const boxed = dynamicCarrierBoxText(value, `${cppTypeOf(value)}{${thunk}, nullptr}`);
319
+ const identified = `gea::nativeClassMethodValue<${cppClassName(owner.declaration)}, &${cppCallableDeclarationTagName(callable)}>` +
320
+ `(this->gea_method_state, ${cppTypeOf(value)}{${thunk}, nullptr})`;
321
+ const boxed = dynamicCarrierBoxText(value, identified);
195
322
  return boxed === null ? [] : [{ key: method.key, text: boxed }];
196
323
  });
197
324
  const readable = (layout) => [
@@ -241,17 +368,47 @@ export const prototypeReadHooks = (classes, abiOf, capturesNothing, readDynamica
241
368
  ` ${lead}gea::detail::NativePrototypeOps::SetResult gea_setPrototypeProperty(const gea::PropertyKey& gea_key, const gea::Value& gea_value, const gea::Value& gea_receiver)${tail};`
242
369
  ]);
243
370
  const inherited = ancestor === null ? null : cppClassName(ancestor);
244
- const names = getters.map((getter) => cppStringLiteral(getter.key));
371
+ // A symbol-keyed member (`get [BSON_VERSION_SYMBOL]()` on bson's
372
+ // `BSONValue`) is laid out under its `sym(<declaration>)` marker, which no
373
+ // text key ever equals: it matches by the symbol's runtime id -- a
374
+ // well-known symbol's fixed one, or the id the program's own symbol cell
375
+ // registered (`gea::detail::registerDeclaredSymbol`), exactly as the
376
+ // record field dispatcher compares them (`records.ts`).
377
+ const texts = getters.filter((getter) => !cppRecordFieldKeyIsSymbol(getter.key));
378
+ const symbols = getters.filter((getter) => cppRecordFieldKeyIsSymbol(getter.key));
379
+ const symbolTest = (key) => {
380
+ const wellKnown = wellKnownSymbolEnumNameOf(wellKnownSymbols, key);
381
+ return wellKnown === null
382
+ ? `gea_key.symbolId() == gea::detail::declaredSymbolId<${cppStringLiteral(key)}>()`
383
+ : `gea_key.symbolId() == static_cast<std::uint32_t>(gea::detail::WellKnownSymbol::${wellKnown})`;
384
+ };
385
+ const has = [
386
+ ...(texts.length === 0
387
+ ? []
388
+ : [`(!gea_key.isSymbol() && (${texts.map((getter) => `gea_key.text() == ${cppStringLiteral(getter.key)}`).join(' || ')}))`]),
389
+ ...(symbols.length === 0 ? [] : [`(gea_key.isSymbol() && (${symbols.map((getter) => symbolTest(getter.key)).join(' || ')}))`])
390
+ ];
245
391
  definitions.push([
246
392
  `bool ${struct}::gea_readPrototypeProperty(const gea::PropertyKey& gea_key, gea::Value& gea_out) const {`,
247
- ' if (!gea_key.isSymbol()) {',
248
- ' const std::string& gea_name = gea_key.text();',
249
- ...getters.map((getter, index) => ` if (gea_name == ${names[index]}) { gea_out = ${getter.text}; return true; }`),
250
- ' }',
393
+ ...(texts.length === 0
394
+ ? []
395
+ : [
396
+ ' if (!gea_key.isSymbol()) {',
397
+ ' const std::string& gea_name = gea_key.text();',
398
+ ...texts.map((getter) => ` if (gea_name == ${cppStringLiteral(getter.key)}) { gea_out = ${getter.text}; return true; }`),
399
+ ' }'
400
+ ]),
401
+ ...(symbols.length === 0
402
+ ? []
403
+ : [
404
+ ' if (gea_key.isSymbol()) {',
405
+ ...symbols.map((getter) => ` if (${symbolTest(getter.key)}) { gea_out = ${getter.text}; return true; }`),
406
+ ' }'
407
+ ]),
251
408
  ` return ${inherited === null ? 'false' : `${inherited}::gea_readPrototypeProperty(gea_key, gea_out)`};`,
252
409
  '}',
253
410
  `bool ${struct}::gea_hasPrototypeProperty(const gea::PropertyKey& gea_key) const {`,
254
- ` if (!gea_key.isSymbol() && (${names.map((name) => `gea_key.text() == ${name}`).join(' || ')})) return true;`,
411
+ ` if (${has.join(' || ')}) return true;`,
255
412
  ` return ${inherited === null ? 'false' : `${inherited}::gea_hasPrototypeProperty(gea_key)`};`,
256
413
  '}',
257
414
  // Setters stay on the static paths; a dynamic write falls through to the payload's own fields.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/compiler",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -49,6 +49,7 @@
49
49
  "test:compact-runtime": "node test/compact-runtime.mjs",
50
50
  "test:stored-listener-native-flow": "node test/stored-listener-native-flow.mjs",
51
51
  "test:native-typed-field-read": "node test/native-typed-field-read.mjs",
52
+ "test:native-tail-conversion-never-allocated": "node test/native-tail-conversion-never-allocated.mjs",
52
53
  "test:native-method-overrides": "node test/native-method-overrides.mjs",
53
54
  "architecture": "node scripts/architecture.mjs && node scripts/refusal-keys.mjs",
54
55
  "typecheck": "tsc -p tsconfig.json --noEmit",
@@ -78,10 +79,10 @@
78
79
  "fastify": "^5.0.0",
79
80
  "find-my-way": "9.6.0",
80
81
  "prettier": "^3.8.3",
81
- "@geastack/core": "0.1.23",
82
- "@geastack/host": "0.1.8",
83
- "@geastack/engine": "0.1.6",
84
- "@geastack/elements": "0.1.2",
82
+ "@geastack/core": "0.1.35",
83
+ "@geastack/host": "0.1.12",
84
+ "@geastack/engine": "0.1.11",
85
+ "@geastack/elements": "0.1.4",
85
86
  "@geastack/geaos": "0.1.3",
86
87
  "@geastack/apple": "0.2.8",
87
88
  "@geastack/geatsc-plugin-gea": "0.1.6",
@@ -75,7 +75,8 @@ inline Value ordinaryToPrimitive(const Value& value, ToPrimitiveHint hint) {
75
75
  return Value::box(Value::Tag::String, value.functionSourceText());
76
76
  const bool present = value.hasProperty(key);
77
77
  if (!present && isToString &&
78
- (value.isDynamicObject() || value.isProxy() || value.isDynamicDictionaryPayload())) {
78
+ (value.isDynamicObject() || value.isProxy() || value.isDynamicDictionaryPayload() ||
79
+ (value.isNativeFieldPayload() && !value.isArrayPayload()))) {
79
80
  const Value tag = value.getProperty(PropertyKey::symbol(wellKnownSymbol(detail::WellKnownSymbol::ToStringTag)));
80
81
  const std::string tagText = tag.tag() == Value::Tag::String ? tag.as<std::string>() : std::string("Object");
81
82
  return Value::box(Value::Tag::String, std::string("[object ") + tagText + "]");
@@ -145,6 +146,49 @@ inline std::string dynamicToString(const Value& input) {
145
146
  return host::detail::toString(primitive);
146
147
  }
147
148
 
149
+ /**
150
+ * ECMA-262 7.1.17 ToString of a string-keyed table (`{ [key: string]: T }`),
151
+ * read off the table itself rather than through a box of it.
152
+ *
153
+ * A table holds only string keys, so it has no `@@toPrimitive` of its own and
154
+ * ToPrimitive(hint string) is OrdinaryToPrimitive (7.1.1.1): `toString`, then
155
+ * `valueOf`, each called when it is callable and answering when it returns a
156
+ * primitive. A table has no prototype of its own -- it is an ordinary object
157
+ * over `Object.prototype` -- so a missing `toString` is
158
+ * `Object.prototype.toString`, whose tag walk (20.1.3.6) answers
159
+ * "[object Object]", and a missing `valueOf` returns the object and is passed.
160
+ *
161
+ * The receiver a stored function is called with is the table as a `Value`:
162
+ * the callee is itself an `any` function whose `this` is dynamic by ABI. A
163
+ * VIEW of another object (`gea::dictionary::aliasOf`) answers with that
164
+ * object's own ToString, `@@toPrimitive` and prototype chain included.
165
+ *
166
+ * A table whose values can hold no callable (`Record<string, number>`) finds
167
+ * no method to call: an own `toString` or `valueOf` key shadows the inherited
168
+ * method with a non-callable, and nothing then yields a primitive.
169
+ */
170
+ template <typename V>
171
+ inline std::string dictionaryToString(const Ref<Dictionary<V>>& table) {
172
+ if constexpr (std::is_same_v<V, Value>) {
173
+ if (const auto* alias = table->alias()) return dynamicToString(alias->object);
174
+ for (const char* name : {"toString", "valueOf"}) {
175
+ if (!table->has(name)) {
176
+ if (name[0] == 't') return "[object Object]";
177
+ continue;
178
+ }
179
+ const Value method = table->read(name);
180
+ if (method.tag() != Value::Tag::Function) continue;
181
+ const Value result = method.callWithReceiver(Value::box(Value::Tag::Object, table), {});
182
+ if (isObjectValue(result)) continue;
183
+ if (result.tag() == Value::Tag::Symbol) host::throwRuntimeError("TypeError", "Cannot convert a Symbol value to a string");
184
+ return host::detail::toString(result);
185
+ }
186
+ } else {
187
+ if (!table->has("toString")) return "[object Object]";
188
+ }
189
+ host::throwRuntimeError("TypeError", "Cannot convert object to primitive value");
190
+ }
191
+
148
192
  inline double dynamicToNumber(const Value& input) {
149
193
  const Value value = dynamicToPrimitive(input, ToPrimitiveHint::Number);
150
194
  switch (value.tag()) {
@@ -255,6 +299,59 @@ inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
255
299
  return Value();
256
300
  }
257
301
 
302
+ /**
303
+ * `String.prototype`'s methods read off a string the program declared `any`
304
+ * (`name.toLowerCase()` after `name = \`${name}\``). Each is the native
305
+ * string function the typed path already calls, reached through the boxed
306
+ * receiver; the receiver is converted with ToString, which for the string
307
+ * primitive these are read off is the string itself. A method not listed
308
+ * reads `undefined`, so calling it is the language's own TypeError rather
309
+ * than an answer this table invented.
310
+ */
311
+ inline Value dynamicStringPrototypeGet(const PropertyKey& key) {
312
+ if (key.isSymbol()) return Value();
313
+ using Args = gea::Ref<ArrayObject<Value>>;
314
+ using Method = CallableObject<Value(Value, Args)>;
315
+ static const std::map<std::string, Value> methods = [] {
316
+ std::map<std::string, Value> result;
317
+ for (const char* name : {"toLowerCase", "toUpperCase", "toLocaleLowerCase", "toLocaleUpperCase", "trim", "trimStart", "trimEnd",
318
+ "toString", "valueOf", "includes", "startsWith", "endsWith", "indexOf", "slice", "charAt"}) {
319
+ auto callable = Method(+[](void* environment, Value receiver, Args args) -> Value {
320
+ alignas(void*) unsigned char slot[sizeof(void*)];
321
+ const std::string& method = *gea::unpackEnvironment<std::string>(environment, slot);
322
+ if (receiver.tag() == Value::Tag::Null || receiver.tag() == Value::Tag::Undefined)
323
+ host::throwRuntimeError("TypeError", "String.prototype method called on null or undefined");
324
+ const std::string text = dynamicToString(receiver);
325
+ const Value first = args->size() ? args->at(0) : Value();
326
+ const Value second = args->size() > 1 ? args->at(1) : Value();
327
+ const auto string = [](std::string value) { return Value::box(Value::Tag::String, std::move(value)); };
328
+ const auto position = [](const Value& value, double fallback) {
329
+ if (value.tag() == Value::Tag::Undefined) return fallback;
330
+ const double number = dynamicToNumber(value);
331
+ return std::isnan(number) ? 0.0 : std::trunc(number);
332
+ };
333
+ if (method == "toLowerCase" || method == "toLocaleLowerCase") return string(runtime::string::toLowerCase(text));
334
+ if (method == "toUpperCase" || method == "toLocaleUpperCase") return string(runtime::string::toUpperCase(text));
335
+ if (method == "trim") return string(runtime::string::trim(text));
336
+ if (method == "trimStart") return string(runtime::string::trimStart(text));
337
+ if (method == "trimEnd") return string(runtime::string::trimEnd(text));
338
+ if (method == "toString" || method == "valueOf") return string(text);
339
+ if (method == "slice") return string(runtime::string::slice(text, position(first, 0.0), position(second, std::numeric_limits<double>::infinity())));
340
+ if (method == "charAt") return string(runtime::string::charAt(text, position(first, 0.0)));
341
+ const std::string needle = dynamicToString(first);
342
+ if (method == "indexOf") return Value::box(Value::Tag::Number, runtime::string::indexOf(text, needle, position(second, 0.0)));
343
+ if (method == "includes") return Value::box(Value::Tag::Boolean, runtime::string::includes(text, needle, position(second, 0.0)));
344
+ if (method == "startsWith") return Value::box(Value::Tag::Boolean, runtime::string::startsWith(text, needle, position(second, 0.0)));
345
+ return Value::box(Value::Tag::Boolean, runtime::string::endsWith(text, needle, position(second, std::numeric_limits<double>::infinity())));
346
+ }, gea::packEnvironment<std::string>(std::string(name)));
347
+ result.emplace(name, Value::boxMethod<1>(callable));
348
+ }
349
+ return result;
350
+ }();
351
+ const auto found = methods.find(key.text());
352
+ return found == methods.end() ? Value() : found->second;
353
+ }
354
+
258
355
  // The intrinsic is one ordinary native array with its own method properties.
259
356
  // Identity sidecars already carry descriptors on arrays; a new representation
260
357
  // or a boxed array would lose that existing native ownership for no reason.
@@ -356,8 +453,8 @@ inline void Value::freezeIntegrity() const {
356
453
  return;
357
454
  }
358
455
  if (tag_ != Tag::Object) return;
359
- if (metadata_->fields != nullptr) metadata_->fields->freezeIndex(const_cast<void*>(held_.get()));
360
- if (metadata_->elements != nullptr) metadata_->elements->freeze(const_cast<void*>(held_.get()));
456
+ if (metadata_->fields != nullptr) metadata_->fields->freezeIndex(payload());
457
+ if (metadata_->elements != nullptr) metadata_->elements->freeze(payload());
361
458
  detail::expandoFor(expandoAnchor(), true)->freezeIntegrity();
362
459
  }
363
460
 
@@ -370,7 +467,7 @@ inline bool Value::hasFrozenIntegrity() const {
370
467
  if (tag_ != Tag::Object) return true;
371
468
  const auto expando = detail::expandoFor(expandoAnchor(), false);
372
469
  if (!expando || !expando->hasFrozenIntegrity()) return false;
373
- return metadata_->elements == nullptr || metadata_->elements->frozen(held_.get());
470
+ return metadata_->elements == nullptr || metadata_->elements->frozen(payload());
374
471
  }
375
472
 
376
473
  inline bool Value::isExtensible() const {
@@ -384,8 +481,8 @@ inline bool Value::isExtensible() const {
384
481
  return result;
385
482
  }
386
483
  if (dynamic_) return asDynamicObject()->extensible();
387
- if (metadata_->fields != nullptr && !metadata_->fields->extensible(held_.get())) return false;
388
- if (metadata_->elements != nullptr && metadata_->elements->frozen(held_.get())) return false;
484
+ if (metadata_->fields != nullptr && !metadata_->fields->extensible(payload())) return false;
485
+ if (metadata_->elements != nullptr && metadata_->elements->frozen(payload())) return false;
389
486
  const auto expando = detail::expandoFor(expandoAnchor(), false);
390
487
  return !expando || expando->extensible();
391
488
  }
@@ -428,17 +525,28 @@ inline std::vector<PropertyKey> Value::ownPropertyKeys() const {
428
525
  keys.push_back(PropertyKey::string("length"));
429
526
  return keys;
430
527
  }
431
- if (metadata_->fields) metadata_->fields->ownKeys(held_.get(), keys);
528
+ // `Dictionary<Value>` has no `metadata_->fields`, so without this arm a boxed
529
+ // table reported no keys at all: `Object.keys` of a record read back out of a
530
+ // `Map<string, unknown>` came out empty while `ownDescriptor` still answered
531
+ // for every entry.
532
+ if (metadata_->payloadType == detail::payloadTypeTagFor<gea::Ref<gea::Dictionary<gea::Value>>>()) {
533
+ if (const gea::Value* gea_viewed = gea::dictionary::viewedObjectOf(*this)) return gea_viewed->ownPropertyKeys();
534
+ const gea::Ref<gea::Dictionary<gea::Value>>& dictionary = as<gea::Ref<gea::Dictionary<gea::Value>>>();
535
+ if (dictionary) for (const auto& key : dictionary->enumerableKeys()) keys.push_back(PropertyKey::string(key));
536
+ return detail::ordinaryOwnPropertyKeyOrder(std::move(keys));
537
+ }
538
+ if (metadata_->fields) metadata_->fields->ownKeys(payload(), keys);
432
539
  if (metadata_->elements) {
433
- for (std::size_t i = 0; i < metadata_->elements->length(held_.get()); ++i) {
540
+ for (std::size_t i = 0; i < metadata_->elements->length(payload()); ++i) {
434
541
  Value ignored;
435
- if (metadata_->elements->element(held_.get(), i, ignored)) keys.push_back(PropertyKey::string(std::to_string(i)));
542
+ if (metadata_->elements->element(payload(), i, ignored)) keys.push_back(PropertyKey::string(std::to_string(i)));
436
543
  }
437
544
  keys.push_back(PropertyKey::string("length"));
438
545
  }
439
- const auto expando = detail::expandoFor(expandoAnchor(), false);
546
+ const gea::Ref<void> anchor = expandoAnchor();
547
+ const auto expando = detail::expandoFor(anchor, false);
440
548
  if (expando) for (const auto& key : expando->ownKeys()) keys.push_back(key);
441
- return detail::ordinaryOwnPropertyKeyOrder(std::move(keys));
549
+ return detail::nativeOwnKeysInCreationOrder(anchor.get(), std::move(keys));
442
550
  }
443
551
 
444
552
  inline bool Value::defineProperty(const PropertyKey& key, const PropertyDescriptor& descriptor) const {
@@ -493,6 +601,7 @@ inline bool Value::defineProperty(const PropertyKey& key, const PropertyDescript
493
601
  // through here) silently wrote a key nothing else ever reads: a direct
494
602
  // `dictionary->read(key)` afterwards still saw the old table, unmodified.
495
603
  if (metadata_->payloadType == detail::payloadTypeTagFor<gea::Ref<gea::Dictionary<gea::Value>>>()) {
604
+ if (const gea::Value* gea_viewed = gea::dictionary::viewedObjectOf(*this)) return gea_viewed->defineProperty(key, descriptor);
496
605
  if (key.isSymbol() || descriptor.isAccessor()) return false;
497
606
  const gea::Ref<gea::Dictionary<gea::Value>>& dictionary = as<gea::Ref<gea::Dictionary<gea::Value>>>();
498
607
  if (!dictionary) return false;
@@ -507,11 +616,11 @@ inline bool Value::defineProperty(const PropertyKey& key, const PropertyDescript
507
616
  // payload that states the whole own-field protocol installs this hook, so
508
617
  // for every other native the next two branches are unchanged.
509
618
  if (metadata_->fields != nullptr && metadata_->fields->matchesField != nullptr &&
510
- metadata_->fields->matchesField(held_.get(), key)) {
511
- return metadata_->fields->defineField(const_cast<void*>(held_.get()), key, descriptor, isExtensible());
619
+ metadata_->fields->matchesField(payload(), key)) {
620
+ return metadata_->fields->defineField(payload(), key, descriptor, isExtensible());
512
621
  }
513
- if (metadata_->fields != nullptr && metadata_->fields->matchesIndex(held_.get(), key)) {
514
- return metadata_->fields->defineIndex(const_cast<void*>(held_.get()), key, descriptor, isExtensible());
622
+ if (metadata_->fields != nullptr && metadata_->fields->matchesIndex(payload(), key)) {
623
+ return metadata_->fields->defineIndex(payload(), key, descriptor, isExtensible());
515
624
  }
516
625
  PropertyDescriptor current;
517
626
  if (ownDescriptor(key, current)) {
@@ -529,10 +638,14 @@ inline bool Value::defineProperty(const PropertyKey& key, const PropertyDescript
529
638
  if (detail::arrayIndexOfKey(key, index)) {
530
639
  if (!descriptor.hasValue || !descriptor.hasWritable || !descriptor.writable || !descriptor.hasEnumerable ||
531
640
  !descriptor.enumerable || !descriptor.hasConfigurable || !descriptor.configurable) return false;
532
- return metadata_->elements->setElement(const_cast<void*>(held_.get()), index, descriptor.value);
641
+ return metadata_->elements->setElement(payload(), index, descriptor.value);
533
642
  }
534
643
  }
535
- return detail::expandoFor(expandoAnchor(), true)->defineOwnProperty(key, descriptor);
644
+ const gea::Ref<void> anchor = expandoAnchor();
645
+ if (!detail::expandoFor(anchor, true)->defineOwnProperty(key, descriptor)) return false;
646
+ if (metadata_->fields)
647
+ detail::noteNativeOwnKeyCreated(anchor, key, [&](std::vector<PropertyKey>& keys) { metadata_->fields->ownKeys(payload(), keys); });
648
+ return true;
536
649
  }
537
650
 
538
651
  inline bool Value::ownDescriptor(const PropertyKey& key, PropertyDescriptor& out) const {
@@ -554,6 +667,7 @@ inline bool Value::ownDescriptor(const PropertyKey& key, PropertyDescriptor& out
554
667
  // have or `Reflect.set`'s existence check (and `for`-`in`/`Object.keys`,
555
668
  // which filter through `ownDescriptor`) never see what the table holds.
556
669
  if (metadata_->payloadType == detail::payloadTypeTagFor<gea::Ref<gea::Dictionary<gea::Value>>>()) {
670
+ if (const gea::Value* gea_viewed = gea::dictionary::viewedObjectOf(*this)) return gea_viewed->ownDescriptor(key, out);
557
671
  if (key.isSymbol()) return false;
558
672
  const gea::Ref<gea::Dictionary<gea::Value>>& dictionary = as<gea::Ref<gea::Dictionary<gea::Value>>>();
559
673
  if (!dictionary || !dictionary->has(key.text())) return false;
@@ -562,26 +676,26 @@ inline bool Value::ownDescriptor(const PropertyKey& key, PropertyDescriptor& out
562
676
  }
563
677
  if (tag_ == Tag::String && detail::stringOwnDescriptor(as<std::string>(), key, out)) return true;
564
678
  if (metadata_->fields) {
565
- if (metadata_->fields->ownDescriptor(held_.get(), key, out)) {
679
+ if (metadata_->fields->ownDescriptor(payload(), key, out)) {
566
680
  const auto integrity = detail::expandoFor(expandoAnchor(), false);
567
681
  if (integrity && integrity->nativeFieldsFrozen()) out.writable = false;
568
682
  return true;
569
683
  }
570
- if (metadata_->fields->ownIndexDescriptor(held_.get(), key, out)) return true;
571
- if (metadata_->fields->matchesIndex(held_.get(), key)) return false;
684
+ if (metadata_->fields->ownIndexDescriptor(payload(), key, out)) return true;
685
+ if (metadata_->fields->matchesIndex(payload(), key)) return false;
572
686
  }
573
687
  if (metadata_->elements) {
574
688
  const auto integrity = detail::expandoFor(expandoAnchor(), false);
575
689
  const bool frozen = integrity && integrity->hasFrozenIntegrity();
576
690
  if (!key.isSymbol() && key.text() == "length") {
577
- out = PropertyDescriptor::assignment(Value::box(Tag::Number, static_cast<double>(metadata_->elements->length(held_.get()))));
691
+ out = PropertyDescriptor::assignment(Value::box(Tag::Number, static_cast<double>(metadata_->elements->length(payload()))));
578
692
  out.enumerable = out.configurable = false;
579
693
  out.writable = !frozen;
580
694
  return true;
581
695
  }
582
696
  std::size_t index = 0;
583
697
  Value found;
584
- if (detail::arrayIndexOfKey(key, index) && metadata_->elements->element(held_.get(), index, found)) {
698
+ if (detail::arrayIndexOfKey(key, index) && metadata_->elements->element(payload(), index, found)) {
585
699
  out = PropertyDescriptor::assignment(found);
586
700
  if (frozen) out.writable = out.configurable = false;
587
701
  return true;
@@ -668,7 +782,7 @@ inline bool Value::reflectSet(const PropertyKey& key, const Value& value, const
668
782
  return parent.reflectSet(key, value, receiver);
669
783
  }
670
784
  if (!exists && metadata_->prototype != nullptr) {
671
- const auto result = metadata_->prototype->set(const_cast<void*>(held_.get()), key, value, receiver);
785
+ const auto result = metadata_->prototype->set(payload(), key, value, receiver);
672
786
  if (result != detail::NativePrototypeOps::SetResult::Absent) {
673
787
  return result == detail::NativePrototypeOps::SetResult::Accepted;
674
788
  }
@@ -757,7 +871,14 @@ inline bool reflectDelete(const T& target, const K& key) {
757
871
  }
758
872
 
759
873
  inline std::string objectTagText(const char* tag) {
760
- return std::string("[object ") + tag + "]";
874
+ // One sized construction instead of `"[object " + tag + "]"`, which builds a
875
+ // temporary from the prefix and then appends twice (three strlen/copies).
876
+ constexpr std::size_t prefix = 8;
877
+ const std::size_t length = std::char_traits<char>::length(tag);
878
+ std::string text(prefix + length + 1, ']');
879
+ std::memcpy(text.data(), "[object ", prefix);
880
+ std::memcpy(text.data() + prefix, tag, length);
881
+ return text;
761
882
  }
762
883
 
763
884
  inline std::string objectTagWithOverride(const Value& tag, const char* builtinTag) {
@@ -830,6 +951,12 @@ inline std::string dynamicIntrinsicObjectTag(const Value& value, const char* bui
830
951
  }
831
952
 
832
953
  inline std::string objectTag(const Value& value, const char* = "Object", const char* = nullptr) {
954
+ // BSONPERF-objecttag-document: a plain open document (a `Dictionary<Value>` that views nothing) is no Array, Date, RegExp, Error, Map or
955
+ // ArrayBuffer, and its symbol-keyed read is always `undefined` (`getProperty` stores no symbols in it), so its tag is "Object".
956
+ // bson's isDate/isRegExp ask this of every nested document it serializes.
957
+ if (value.tag() == Value::Tag::Object && !value.isProxy() && !value.isDynamicObject() &&
958
+ value.payloadType() == detail::payloadTypeTagFor<gea::Ref<gea::Dictionary<Value>>>() && gea::dictionary::viewedObjectOf(value) == nullptr)
959
+ return objectTagText("Object");
833
960
  const char* builtinTag = "Object";
834
961
  switch (value.tag()) {
835
962
  case Value::Tag::Undefined: return objectTagText("Undefined");
@@ -852,7 +979,10 @@ inline std::string objectTag(const Value& value, const char* = "Object", const c
852
979
  else if (value.isMapPayload()) return dynamicIntrinsicObjectTag(value, "Object", "Map");
853
980
  else if (host::instanceOfArrayBuffer(value)) return dynamicIntrinsicObjectTag(value, "Object", "ArrayBuffer");
854
981
  }
855
- return objectTagWithOverride(value.getProperty(PropertyKey::symbol(wellKnownSymbol(detail::WellKnownSymbol::ToStringTag))), builtinTag);
982
+ // BSONPERF-tag-literal: the @@toStringTag read of a native record or class instance is a remembered miss like any literal-keyed read.
983
+ static const PropertyKey toStringTagKey = PropertyKey::symbol(wellKnownSymbol(detail::WellKnownSymbol::ToStringTag));
984
+ static detail::LiteralReadCache toStringTagCache;
985
+ return objectTagWithOverride(value.getLiteralProperty(toStringTagKey, toStringTagCache), builtinTag);
856
986
  }
857
987
 
858
988
  inline std::string objectTag(const FunctionValue& value, const char* builtinTag = "Function", const char* defaultTag = nullptr) {
@@ -1,5 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #pragma once
3
+ #ifndef GEA_EVAL_H_INCLUDED
4
+ #define GEA_EVAL_H_INCLUDED
3
5
  #include <cctype>
4
6
  #include <memory>
5
7
  #include <unordered_map>
@@ -1374,3 +1376,4 @@ class Eval {
1374
1376
  namespace gea {
1375
1377
  inline Value dynamicFunctionPrototypeGet(const PropertyKey& key) { return eval_detail::functionPrototype(key); }
1376
1378
  } // namespace gea
1379
+ #endif // GEA_EVAL_H_INCLUDED