@geastack/compiler 1.0.33 → 1.0.35

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 (215) hide show
  1. package/README.md +1 -1
  2. package/dist/cli-coverage.js +2 -4
  3. package/dist/cli-emit.js +1 -1
  4. package/dist/cli-module-graph.js +1 -1
  5. package/dist/cli.js +2 -1
  6. package/dist/compiler.js +14 -6
  7. package/dist/conversion/array-view.js +9 -0
  8. package/dist/conversion/build.js +15 -8
  9. package/dist/conversion/dictionary-view.js +2 -2
  10. package/dist/conversion/nodes.d.ts +7 -0
  11. package/dist/conversion/nodes.js +58 -11
  12. package/dist/identity/ids.d.ts +4 -0
  13. package/dist/identity/ids.js +4 -0
  14. package/dist/ir/build.d.ts +4 -3
  15. package/dist/ir/build.js +14 -5
  16. package/dist/ir/call-dispatch.js +67 -7
  17. package/dist/ir/call-entry.js +1 -1
  18. package/dist/ir/callable-class-flow.d.ts +4 -0
  19. package/dist/ir/callable-class-flow.js +123 -1
  20. package/dist/ir/certify/parallel-region.js +698 -20
  21. package/dist/ir/certify.d.ts +3 -0
  22. package/dist/ir/certify.js +44 -9
  23. package/dist/ir/class-allocation-domain.js +2 -2
  24. package/dist/ir/class-construction-status.d.ts +10 -0
  25. package/dist/ir/class-construction-status.js +36 -0
  26. package/dist/ir/convert-carriers.d.ts +10 -1
  27. package/dist/ir/convert-carriers.js +18 -1
  28. package/dist/ir/dynamic-constructor-conversions.js +4 -2
  29. package/dist/ir/finite-iterator-close.d.ts +14 -0
  30. package/dist/ir/finite-iterator-close.js +50 -0
  31. package/dist/ir/host-template-conversions.js +9 -0
  32. package/dist/ir/lower-allocation.js +1 -1
  33. package/dist/ir/lower-flow.js +24 -3
  34. package/dist/ir/lower-operands.js +88 -7
  35. package/dist/ir/lower-protocol.js +1 -1
  36. package/dist/ir/lower.js +9 -4
  37. package/dist/ir/model.d.ts +39 -1
  38. package/dist/ir/native-accessor-definition.d.ts +3 -2
  39. package/dist/ir/native-accessor-definition.js +29 -10
  40. package/dist/ir/native-array-transport.js +2 -2
  41. package/dist/ir/native-field-view-domains.d.ts +23 -0
  42. package/dist/ir/native-field-view-domains.js +115 -9
  43. package/dist/ir/native-field-view-facts.d.ts +46 -2
  44. package/dist/ir/native-field-view-facts.js +159 -4
  45. package/dist/ir/native-iterable.d.ts +17 -0
  46. package/dist/ir/native-iterable.js +72 -0
  47. package/dist/ir/native-key-query.js +1 -1
  48. package/dist/ir/operation-conversions.js +15 -3
  49. package/dist/ir/program-conversions.js +2 -2
  50. package/dist/ir/publish-native-field-view-facts.js +9 -4
  51. package/dist/ir/pure-conversion-reuse.d.ts +58 -0
  52. package/dist/ir/pure-conversion-reuse.js +263 -0
  53. package/dist/ir/queries.js +1 -0
  54. package/dist/ir/reflection-demand.js +70 -18
  55. package/dist/ir/shake.js +2 -2
  56. package/dist/ir/unobserved-callable-inputs.d.ts +37 -0
  57. package/dist/ir/unobserved-callable-inputs.js +111 -0
  58. package/dist/native-signatures.d.ts +1 -1
  59. package/dist/native-signatures.js +27 -2
  60. package/dist/plugins/gea/component-classes.d.ts +2 -1
  61. package/dist/plugins/gea/component-classes.js +3 -3
  62. package/dist/plugins/gea/contract.d.ts +26 -3
  63. package/dist/plugins/gea/contract.js +42 -43
  64. package/dist/plugins/gea/host.d.ts +9 -0
  65. package/dist/plugins/gea/host.js +25 -4
  66. package/dist/plugins/gea/plugin.js +12 -6
  67. package/dist/plugins/gea/producer.d.ts +2 -2
  68. package/dist/plugins/gea/producer.js +2 -2
  69. package/dist/plugins/load.js +18 -1
  70. package/dist/plugins/model.d.ts +5 -0
  71. package/dist/plugins/native-iterable-providers.d.ts +18 -0
  72. package/dist/plugins/native-iterable-providers.js +51 -0
  73. package/dist/project-preparation.d.ts +8 -0
  74. package/dist/project-preparation.js +49 -7
  75. package/dist/projection/bindings.d.ts +13 -0
  76. package/dist/projection/bindings.js +20 -1
  77. package/dist/projection/classes.d.ts +4 -2
  78. package/dist/projection/classes.js +12 -5
  79. package/dist/representation/collections.js +2 -0
  80. package/dist/representation/derive.js +1 -0
  81. package/dist/representation/model.d.ts +2 -0
  82. package/dist/representation/model.js +1 -0
  83. package/dist/representation/policies.d.ts +2 -0
  84. package/dist/representation/primitive-domain.d.ts +1 -1
  85. package/dist/representation/primitive-domain.js +1 -1
  86. package/dist/representation/unassigned-binding-cells.js +6 -1
  87. package/dist/representation/union.js +6 -6
  88. package/dist/semantics/frontend.d.ts +2 -0
  89. package/dist/semantics/frontend.js +34 -5
  90. package/dist/semantics/host-methods.js +4 -1
  91. package/dist/semantics/jsx-runtime-provider.d.ts +5 -0
  92. package/dist/semantics/jsx-runtime-provider.js +16 -0
  93. package/dist/semantics/model/native-iterable.d.ts +14 -0
  94. package/dist/semantics/model/native-iterable.js +7 -0
  95. package/dist/semantics/model/operands.d.ts +30 -0
  96. package/dist/semantics/model/operations.d.ts +15 -0
  97. package/dist/semantics/model/primitive-domain.d.ts +15 -0
  98. package/dist/semantics/model/primitive-domain.js +27 -4
  99. package/dist/semantics/module-resolution.js +13 -2
  100. package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
  101. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +32 -4
  102. package/dist/semantics/normalize/callback-parameter-contracts.js +66 -6
  103. package/dist/semantics/normalize/census.d.ts +3 -0
  104. package/dist/semantics/normalize/census.js +17 -12
  105. package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +4 -1
  106. package/dist/semantics/normalize/deferred-intrinsic-protocols.js +29 -9
  107. package/dist/semantics/normalize/flow/callable-reach.js +94 -3
  108. package/dist/semantics/normalize/flow/component-solver.js +144 -55
  109. package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +9 -0
  110. package/dist/semantics/normalize/flow/member-call-forwarding.js +30 -4
  111. package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +2 -0
  112. package/dist/semantics/normalize/flow/proof-hypotheses.js +27 -0
  113. package/dist/semantics/normalize/flow/source-callable-own-data.js +87 -14
  114. package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +2 -0
  115. package/dist/semantics/normalize/flow/source-commonjs-exports.js +2 -0
  116. package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +17 -0
  117. package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +125 -0
  118. package/dist/semantics/normalize/flow/source-native-origin.d.ts +6 -0
  119. package/dist/semantics/normalize/flow/source-native-origin.js +38 -0
  120. package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +37 -0
  121. package/dist/semantics/normalize/flow/source-proxy-operation.js +201 -0
  122. package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +20 -0
  123. package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +73 -0
  124. package/dist/semantics/normalize/flow/source-value-session.d.ts +50 -1
  125. package/dist/semantics/normalize/flow/source-value-session.js +596 -57
  126. package/dist/semantics/normalize/flow/value-flow.d.ts +17 -0
  127. package/dist/semantics/normalize/flow/value-flow.js +84 -0
  128. package/dist/semantics/normalize/fresh-dictionary-storage.js +2 -2
  129. package/dist/semantics/normalize/fresh-table-last-use.d.ts +52 -0
  130. package/dist/semantics/normalize/fresh-table-last-use.js +129 -0
  131. package/dist/semantics/normalize/gating.js +5 -1
  132. package/dist/semantics/normalize/global-host-mutations.js +190 -13
  133. package/dist/semantics/normalize/identities.js +20 -1
  134. package/dist/semantics/normalize/local-bindings.js +2 -2
  135. package/dist/semantics/normalize/parameter-bindings.js +10 -1
  136. package/dist/semantics/normalize/producer-context.d.ts +5 -0
  137. package/dist/semantics/normalize/producers/binding-kind.js +2 -0
  138. package/dist/semantics/normalize/producers/cited-value-type.d.ts +2 -2
  139. package/dist/semantics/normalize/producers/cited-value-type.js +2 -2
  140. package/dist/semantics/normalize/producers/class-lifecycle.js +39 -9
  141. package/dist/semantics/normalize/producers/computations.js +36 -5
  142. package/dist/semantics/normalize/producers/conditional-guard.d.ts +6 -0
  143. package/dist/semantics/normalize/producers/conditional-guard.js +5 -0
  144. package/dist/semantics/normalize/producers/control.js +7 -1
  145. package/dist/semantics/normalize/producers/destructuring.js +8 -9
  146. package/dist/semantics/normalize/producers/invocations.js +55 -2
  147. package/dist/semantics/normalize/producers/properties.d.ts +13 -0
  148. package/dist/semantics/normalize/producers/properties.js +21 -3
  149. package/dist/semantics/normalize/producers/references.js +8 -4
  150. package/dist/semantics/normalize/reachability.d.ts +15 -3
  151. package/dist/semantics/normalize/reachability.js +128 -20
  152. package/dist/semantics/normalize/return-bindings.js +3 -3
  153. package/dist/semantics/normalize/source-native-iterable.d.ts +19 -0
  154. package/dist/semantics/normalize/source-native-iterable.js +74 -0
  155. package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
  156. package/dist/semantics/normalize/structural-declarations.js +1 -1
  157. package/dist/semantics/normalize/structural-indexed-access.js +9 -0
  158. package/dist/semantics/normalize/structural.js +11 -0
  159. package/dist/semantics/normalize/unshared-array-result.d.ts +42 -0
  160. package/dist/semantics/normalize/unshared-array-result.js +269 -0
  161. package/dist/semantics/package-sources.js +3 -2
  162. package/dist/semantics/program.d.ts +8 -0
  163. package/dist/semantics/program.js +55 -0
  164. package/dist/semantics/source-transform-exports.d.ts +8 -0
  165. package/dist/semantics/source-transform-exports.js +145 -0
  166. package/dist/semantics/source-transform-protocol.d.ts +22 -0
  167. package/dist/semantics/this-constructor-source-transform.js +19 -1
  168. package/dist/targets/cpp/class-layout.d.ts +2 -0
  169. package/dist/targets/cpp/class-layout.js +35 -1
  170. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +11 -1
  171. package/dist/targets/cpp/class-properties/emit-class-properties.js +33 -4
  172. package/dist/targets/cpp/conversions.js +6 -3
  173. package/dist/targets/cpp/emit-callable.js +73 -7
  174. package/dist/targets/cpp/emit-context.d.ts +23 -9
  175. package/dist/targets/cpp/emit-context.js +19 -8
  176. package/dist/targets/cpp/emit-equality.js +41 -1
  177. package/dist/targets/cpp/emit-exceptions.js +29 -11
  178. package/dist/targets/cpp/emit-iterator-object-view.js +2 -2
  179. package/dist/targets/cpp/emit-iterator.js +33 -9
  180. package/dist/targets/cpp/emit-live-field-view.js +6 -1
  181. package/dist/targets/cpp/emit-narrowing.d.ts +11 -3
  182. package/dist/targets/cpp/emit-narrowing.js +58 -18
  183. package/dist/targets/cpp/emit-native-field-view.d.ts +3 -1
  184. package/dist/targets/cpp/emit-native-field-view.js +84 -8
  185. package/dist/targets/cpp/emit-properties.d.ts +1 -0
  186. package/dist/targets/cpp/emit-properties.js +26 -7
  187. package/dist/targets/cpp/emit-protocol-iterator.js +5 -2
  188. package/dist/targets/cpp/emit-record-view.js +14 -2
  189. package/dist/targets/cpp/emit-tostring.js +23 -1
  190. package/dist/targets/cpp/emit-union-properties.js +1 -1
  191. package/dist/targets/cpp/emit.d.ts +1 -1
  192. package/dist/targets/cpp/emit.js +99 -13
  193. package/dist/targets/cpp/host/emit-host-invoke.js +2 -2
  194. package/dist/targets/cpp/host/emit-host-object.js +28 -2
  195. package/dist/targets/cpp/host/emit-host-properties.js +9 -1
  196. package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
  197. package/dist/targets/cpp/host/emit-host-value.js +8 -6
  198. package/dist/targets/cpp/host/host-members.js +2 -1
  199. package/dist/targets/cpp/prototype/emit-prototype-array.js +69 -5
  200. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +9 -9
  201. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +2 -2
  202. package/dist/targets/cpp/prototype/emit-prototype-promise.js +7 -7
  203. package/dist/targets/cpp/records.d.ts +1 -0
  204. package/dist/targets/cpp/records.js +83 -22
  205. package/dist/targets/cpp/translation-unit.js +30 -16
  206. package/package.json +8 -7
  207. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +42 -3
  208. package/src/targets/cpp/runtime/gea_eval.h +3 -0
  209. package/src/targets/cpp/runtime/gea_runtime.h +2399 -676
  210. package/dist/representation/any-null-record-members.d.ts +0 -41
  211. package/dist/representation/any-null-record-members.js +0 -115
  212. package/dist/semantics/any-null-member-declarations.d.ts +0 -32
  213. package/dist/semantics/any-null-member-declarations.js +0 -90
  214. package/dist/semantics/normalize/fresh-array-result.d.ts +0 -32
  215. package/dist/semantics/normalize/fresh-array-result.js +0 -125
@@ -481,8 +481,8 @@ const promiseReactionText = (ctx, family, receiverText, onFulfilled, onRejected,
481
481
  ? argumentText(abi, { kind: 'undefined' }, cppUndefinedValue, 'prototype/emit-prototype-invoke.ts:then-void-value', 'value')
482
482
  : argumentText(abi, receiverCarrier.value, caughtValueName, 'prototype/emit-prototype-invoke.ts:then-value', 'value');
483
483
  return (`[${catchResultName}, ${fulfilledHandlerName}](${fulfilledParameter}) mutable { ` +
484
- `try { ${settledText(abi, fulfilledHandlerName, argument)} } ` +
485
- `catch (...) { ${catchResultName}.reject(std::current_exception()); } }`);
484
+ `GEA_EH_TRY_ANY(gea_eh_failed) { ${settledText(abi, fulfilledHandlerName, argument)} } ` +
485
+ `GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END }`);
486
486
  }
487
487
  // 27.2.5.1 installs no fulfillment handler, so the receiver's fulfillment
488
488
  // value travels through unchanged -- unless nobody can read it, in which
@@ -515,9 +515,9 @@ const promiseReactionText = (ctx, family, receiverText, onFulfilled, onRejected,
515
515
  `${caughtSettledName}.observe(` +
516
516
  `${fulfilledArm}, ` +
517
517
  `[${catchResultName}, ${catchHandlerName}](const std::exception_ptr& gea_catch_rejection) mutable { ` +
518
- `try { std::rethrow_exception(gea_catch_rejection); } ` +
519
- `catch (const ${cppTypeOf(thrownValueCarrier)}& ${caughtReasonName}) { try { ${rejectedBody} } ` +
520
- `catch (...) { ${catchResultName}.reject(std::current_exception()); } } }); return ${catchResultName}; }())`);
518
+ `GEA_EH_TRY_VALUE(gea_catch_caught) { std::rethrow_exception(gea_catch_rejection); } ` +
519
+ `GEA_EH_CATCH_VALUE(gea_catch_caught, ${caughtReasonName}) { GEA_EH_TRY_ANY(gea_eh_failed) { ${rejectedBody} } ` +
520
+ `GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END } GEA_EH_END }); return ${catchResultName}; }())`);
521
521
  };
522
522
  const promiseCatchText = (ctx, receiverText, args, result, receiverCarrier, operation) => {
523
523
  const onRejected = args[0];
@@ -593,11 +593,11 @@ const promiseFinallyText = (ctx, receiverText, args, result, receiverCarrier, op
593
593
  `const auto ${finallyHandlerName} = ${operandText(ctx, onFinally)}; ` +
594
594
  `${caughtSettledName}.observe(` +
595
595
  `[${catchResultName}, ${finallyHandlerName}](${fulfilledParameter}) mutable { ` +
596
- `try { ${finallyHandlerName}.call(); ${catchResultName}.resolve(${passThrough}); } ` +
597
- `catch (...) { ${catchResultName}.reject(std::current_exception()); } }, ` +
596
+ `GEA_EH_TRY_ANY(gea_eh_failed) { ${finallyHandlerName}.call(); ${catchResultName}.resolve(${passThrough}); } ` +
597
+ `GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END }, ` +
598
598
  `[${catchResultName}, ${finallyHandlerName}](const std::exception_ptr& gea_finally_rejection) mutable { ` +
599
- `try { ${finallyHandlerName}.call(); ${catchResultName}.reject(gea_finally_rejection); } ` +
600
- `catch (...) { ${catchResultName}.reject(std::current_exception()); } }); return ${catchResultName}; }())`);
599
+ `GEA_EH_TRY_ANY(gea_eh_failed) { ${finallyHandlerName}.call(); ${catchResultName}.reject(gea_finally_rejection); } ` +
600
+ `GEA_EH_CATCH_ANY(gea_eh_failed) { ${catchResultName}.reject(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END }); return ${catchResultName}; }())`);
601
601
  };
602
602
  /**
603
603
  * `p.toString()`.
@@ -53,8 +53,8 @@ const iteratorResultText = (ctx, receiverText, carrier, result, stepText) => {
53
53
  if (result.representation.kind === 'promise' && result.representation.value.kind === 'tagged-union') {
54
54
  const promiseType = cppTypeOf(result.representation);
55
55
  const settled = iteratorResultText(ctx, receiverText, carrier, { ...result, representation: result.representation.value }, stepText);
56
- return (`([&]() -> ${promiseType} { try { return ${promiseType}(${settled}); } ` +
57
- `catch (...) { return ${promiseType}::rejected_with(std::current_exception()); } }())`);
56
+ return (`([&]() -> ${promiseType} { GEA_EH_TRY_ANY(gea_eh_failed) { return ${promiseType}(${settled}); } ` +
57
+ `GEA_EH_CATCH_ANY(gea_eh_failed) { return ${promiseType}::rejected_with(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END GEA_EH_UNREACHABLE }())`);
58
58
  }
59
59
  const union = iteratorResultUnionOf(carrier, result.representation);
60
60
  const arms = iteratorResultArmsText(ctx, carrier, union, {
@@ -194,13 +194,13 @@ const awaitedOptionalText = (ctx, site, carrier, text, target) => {
194
194
  */
195
195
  export const coroutineAwaitStatements = (ctx, site, carrier, text, target, into) => {
196
196
  const cell = into === null || target === null || target.kind === 'void' ? null : { name: into, carrier: target };
197
- // The top level keeps the plain assignment `awaitedText` makes: the result
198
- // cell holds the payload carrier the plan published for this `await`.
199
- if (carrier.kind === 'promise') {
200
- if (carrier.value.kind === 'void')
201
- return settleInto(ctx, site, `${text}`, carrier.value, cell);
202
- return cell === null ? [`co_await ${text};`] : [`${cell.name} = co_await ${text};`];
203
- }
197
+ // The result cell holds the payload carrier the plan published for this
198
+ // `await` -- except where the operand is narrower than the checker's type:
199
+ // `await value` over an `unknown` parameter every caller passes a
200
+ // `Promise<number>` settles a `double` into the `gea::Value` cell `unknown`
201
+ // keeps, and only the conversion census can enter one into the other.
202
+ if (carrier.kind === 'promise')
203
+ return settleInto(ctx, site, text, carrier.value, cell);
204
204
  const nativePromise = nativePromiseCoroutineText(carrier, text);
205
205
  if (nativePromise !== null)
206
206
  return settleInto(ctx, site, nativePromise.text, nativePromise.payload, cell);
@@ -545,4 +545,5 @@ export declare const classStaticFieldStorageRows: (storage: ReadonlyMap<Declarat
545
545
  readonly type: string;
546
546
  readonly name: string;
547
547
  readonly storageName: string;
548
+ readonly viewStruct: string;
548
549
  }[];
@@ -450,15 +450,30 @@ const isRepresentationNode = (value) => typeof value === 'object' && value !== n
450
450
  * this walk automatically instead of silently falling out of it, which is the
451
451
  * failure mode a `switch` over kinds would have. The walk stops at each struct
452
452
  * it names -- that struct's own dependencies are placed when IT is ordered.
453
- */
454
- const valueHeldStructNames = (representation, into, seen) => {
453
+ *
454
+ * `probed` widens the first stopping rule for the one question that looks
455
+ * through a `Ref`: a struct's `geaTraceRefs` signature asks
456
+ * `TraceEdges<decltype(field)>::supported`, and `gea_runtime.h`'s
457
+ * `RefTargetIsLeaf` answers that for a `Ref<ArrayObject<E>>` by asking the
458
+ * ELEMENT. An `Optional<Record>` element is then instantiated and needs
459
+ * `Record` complete (a hard error), and a bare record element is asked for a
460
+ * `geaTraceRefs` friend an incomplete record does not have yet (a silently
461
+ * wrong "leaf"). A recursive container is a named wrapper the probe stops at,
462
+ * so it is never looked into. Dictionaries answer without their value, so
463
+ * they impose nothing here.
464
+ */
465
+ const valueHeldStructNames = (representation, into, seen, probed = false) => {
455
466
  if (seen.has(representation))
456
467
  return;
457
468
  seen.add(representation);
458
469
  const node = representation;
459
470
  const ownership = node['ownership'];
460
- if (typeof ownership === 'string' && ownership !== 'owned')
471
+ if (typeof ownership === 'string' && ownership !== 'owned') {
472
+ const element = probed && ownership === 'shared-refcount' ? traceProbedElementOf(representation) : null;
473
+ if (element !== null)
474
+ valueHeldStructNames(element, into, seen, probed);
461
475
  return;
476
+ }
462
477
  if (node['abi'] !== undefined) {
463
478
  // A bare record in a function-pointer signature may remain incomplete,
464
479
  // but a by-value carrier BUILT AROUND that record may not. In
@@ -470,7 +485,7 @@ const valueHeldStructNames = (representation, into, seen) => {
470
485
  const nested = [...abi.parameters.map((parameter) => parameter.value), abi.result, ...(abi.receiver ? [abi.receiver] : [])];
471
486
  for (const value of nested) {
472
487
  if (cppStructNameOf(value) === null)
473
- valueHeldStructNames(value, into, seen);
488
+ valueHeldStructNames(value, into, seen, probed);
474
489
  }
475
490
  return;
476
491
  }
@@ -481,7 +496,7 @@ const valueHeldStructNames = (representation, into, seen) => {
481
496
  }
482
497
  const descend = (value) => {
483
498
  if (isRepresentationNode(value)) {
484
- valueHeldStructNames(value, into, seen);
499
+ valueHeldStructNames(value, into, seen, probed);
485
500
  return;
486
501
  }
487
502
  if (Array.isArray(value)) {
@@ -501,14 +516,20 @@ const valueHeldStructNames = (representation, into, seen) => {
501
516
  for (const value of Object.values(node))
502
517
  descend(value);
503
518
  };
504
- /** Every struct one struct's own storage embeds by value. */
505
- const structValueDependencies = (layout) => {
519
+ /** The element `RefTargetIsLeaf` judges a `Ref` to this container by, or `null` when it judges the container without one. */
520
+ const traceProbedElementOf = (representation) => {
521
+ if (representation.kind === 'array-object')
522
+ return representation.recursive === undefined ? representation.element : null;
523
+ return null;
524
+ };
525
+ /** Every struct one struct's own storage embeds by value -- or, `probed`, every struct its trace signature needs complete. */
526
+ const structValueDependencies = (layout, probed = false) => {
506
527
  const into = new Set();
507
528
  const seen = new Set();
508
529
  for (const field of layout.fields)
509
- valueHeldStructNames(field.value, into, seen);
530
+ valueHeldStructNames(field.value, into, seen, probed);
510
531
  for (const index of layout.indexes)
511
- valueHeldStructNames(index.value, into, seen);
532
+ valueHeldStructNames(index.value, into, seen, probed);
512
533
  return into;
513
534
  };
514
535
  /**
@@ -776,11 +797,34 @@ const immortalMethodStateRoots = (classStructNames, baseStructNames, links, eval
776
797
  * name the incomplete type rather than this walk running forever. That is
777
798
  * exactly what the previous name sort did for every struct, so a cycle is no
778
799
  * worse than before and everything else is now right.
779
- */
780
- const definitionOrder = (structNames, bases, valueDependencies) => {
800
+ *
801
+ * `traceDependencies` are the structs only a definition's trace signature
802
+ * needs complete (`valueHeldStructNames`' `probed` walk). They are placed
803
+ * after the hard ones, and only where placing one cannot break a hard one: a
804
+ * trace dependency whose own base/by-value closure reaches back into the chain
805
+ * is skipped, because emitting it first would emit a struct before something
806
+ * it embeds -- trading a certain error for a possible one.
807
+ */
808
+ const definitionOrder = (structNames, bases, valueDependencies, traceDependencies) => {
781
809
  const ordered = [];
782
810
  const emitted = new Set();
783
811
  const placeable = new Set(structNames);
812
+ const hardClosureMeetsChain = (from, chain) => {
813
+ const walked = new Set();
814
+ const pending = [from];
815
+ for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
816
+ if (chain.has(next))
817
+ return true;
818
+ if (walked.has(next) || emitted.has(next) || !placeable.has(next))
819
+ continue;
820
+ walked.add(next);
821
+ const base = bases.get(next);
822
+ if (base)
823
+ pending.push(base.structName);
824
+ pending.push(...(valueDependencies.get(next) ?? []));
825
+ }
826
+ return false;
827
+ };
784
828
  const visit = (structName, chain) => {
785
829
  if (emitted.has(structName) || chain.has(structName))
786
830
  return;
@@ -794,6 +838,10 @@ const definitionOrder = (structNames, bases, valueDependencies) => {
794
838
  if (placeable.has(dependency))
795
839
  visit(dependency, deeper);
796
840
  }
841
+ for (const dependency of traceDependencies.get(structName) ?? []) {
842
+ if (placeable.has(dependency) && !hardClosureMeetsChain(dependency, deeper))
843
+ visit(dependency, deeper);
844
+ }
797
845
  if (emitted.has(structName))
798
846
  return;
799
847
  emitted.add(structName);
@@ -927,7 +975,7 @@ const renderableAccessors = (layout) => layout.accessors.filter((accessor) => !c
927
975
  * a boxed read answers `undefined`: exactly what an unaddressable FIELD
928
976
  * already does, rather than a new refusal for a shape that compiles today.
929
977
  */
930
- const accessorBoxedText = (accessor, call) => {
978
+ const accessorBoxedText = (accessor, structName, call) => {
931
979
  if (accessor.value.kind === 'dynamic')
932
980
  return call;
933
981
  // A member the checker types `undefined` (a getter that only ever throws
@@ -939,9 +987,10 @@ const accessorBoxedText = (accessor, call) => {
939
987
  // The three carriers a FIELD reaches through the runtime's typed adapter
940
988
  // rather than through a box (`dynamicFieldAccessOf`'s `dynamicCarrier` arm).
941
989
  // `boxedText` would `static_cast` them into a payload no reader can name, so
942
- // this refuses instead and the dispatcher emits a named runtime refusal.
990
+ // the getter's result crosses through the same adapter a field's storage
991
+ // does -- bound once, because the call is the getter's observable effect.
943
992
  if (accessor.value.kind === 'optional' || accessor.value.kind === 'tagged-union' || accessor.value.kind === 'dictionary')
944
- return null;
993
+ return `gea::detail::readDynamicField(${call}, ${cppStringLiteral(structName)}, ${cppStringLiteral(accessor.key)})`;
945
994
  const tag = dynamicTagFor(accessor.value);
946
995
  if (tag === null)
947
996
  return null;
@@ -955,7 +1004,7 @@ const accessorUnboxText = (accessor, structName, text) => {
955
1004
  if (accessor.value.kind === 'dynamic')
956
1005
  return text;
957
1006
  if (accessor.value.kind === 'optional' || accessor.value.kind === 'tagged-union' || accessor.value.kind === 'dictionary')
958
- return null;
1007
+ return `gea::detail::unboxDynamicField<${cppTypeOf(accessor.value)}>(${text}, ${cppStringLiteral(structName)}, ${cppStringLiteral(accessor.key)})`;
959
1008
  const tag = dynamicTagFor(accessor.value);
960
1009
  if (tag === null)
961
1010
  return null;
@@ -2029,7 +2078,9 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2029
2078
  const setEnvironment = environmentOf('setter', accessor.setter, '');
2030
2079
  const descriptorGetEnvironment = environmentOf('getter', accessor.getter, 'gea_self->');
2031
2080
  const descriptorSetEnvironment = environmentOf('setter', accessor.setter, 'gea_self->');
2032
- const getText = (receiver, environment) => accessor.getter === null ? 'gea::Value()' : accessorBoxedText(accessor, `${cppBodyName(accessor.getter)}(${environment}${receiver})`);
2081
+ const getText = (receiver, environment) => accessor.getter === null
2082
+ ? 'gea::Value()'
2083
+ : accessorBoxedText(accessor, structName, `${cppBodyName(accessor.getter)}(${environment}${receiver})`);
2033
2084
  const setText = (receiver, written, environment) => {
2034
2085
  if (accessor.setter === null)
2035
2086
  return null;
@@ -3555,8 +3606,12 @@ conversionSite) => {
3555
3606
  // deterministic where nothing constrains it.
3556
3607
  const forwardDeclarations = structNames.map((structName) => `struct ${structName};`);
3557
3608
  const valueDependencies = new Map();
3558
- for (const [structName, layout] of fieldsByStruct)
3559
- valueDependencies.set(structName, structValueDependencies(layout));
3609
+ const traceDependencies = new Map();
3610
+ for (const [structName, layout] of fieldsByStruct) {
3611
+ const held = structValueDependencies(layout);
3612
+ valueDependencies.set(structName, held);
3613
+ traceDependencies.set(structName, new Set([...structValueDependencies(layout, true)].filter((name) => !held.has(name))));
3614
+ }
3560
3615
  const fieldDefinitionsByStruct = new Map();
3561
3616
  const dynamicProtocolByStruct = new Map();
3562
3617
  const fieldOperationsByStruct = new Map();
@@ -3602,7 +3657,7 @@ conversionSite) => {
3602
3657
  }
3603
3658
  const virtualDeclarations = new Map();
3604
3659
  const layouts = recordLayoutPolicyOf(deriver, classes, wellKnownSymbols, accessorAbiOf);
3605
- const ordered = definitionOrder(structNames, links, valueDependencies);
3660
+ const ordered = definitionOrder(structNames, links, valueDependencies, traceDependencies);
3606
3661
  const evaluatedOnce = (structName) => {
3607
3662
  const declaration = declarationByStruct.get(structName);
3608
3663
  return declaration !== undefined && singleEvaluationClasses.has(declaration);
@@ -3703,7 +3758,7 @@ conversionSite) => {
3703
3758
  // nominal target a caught value asserted `as Error` projects to
3704
3759
  // (`unboxValue<Ref<gea::runtime::Error>>`), so the link is as authenticated
3705
3760
  // as a program base's.
3706
- const runtimeClassBases = definitionOrder(structNames, links, valueDependencies).flatMap((structName) => {
3761
+ const runtimeClassBases = ordered.flatMap((structName) => {
3707
3762
  const link = links.get(structName);
3708
3763
  if (!classStructNames.has(structName) || !link)
3709
3764
  return [];
@@ -3821,8 +3876,14 @@ export const classStaticFieldStorageRows = (storage) => {
3821
3876
  const rows = [];
3822
3877
  for (const perClass of storage.values())
3823
3878
  rows.push(...perClass.values());
3824
- return rows
3879
+ const uniqueViews = new Map(rows.map((entry) => [entry.viewStruct, entry]));
3880
+ return [...uniqueViews.values()]
3825
3881
  .filter((entry) => entry.representation.kind !== 'unresolved' && entry.representation.kind !== 'void')
3826
3882
  .sort((left, right) => left.name.localeCompare(right.name))
3827
- .map((entry) => ({ type: cppTypeOf(entry.representation), name: entry.name, storageName: entry.storageName ?? entry.name }));
3883
+ .map((entry) => ({
3884
+ type: cppTypeOf(entry.representation),
3885
+ name: entry.name,
3886
+ storageName: entry.storageName ?? entry.name,
3887
+ viewStruct: entry.viewStruct
3888
+ }));
3828
3889
  };
@@ -616,6 +616,10 @@ staticMethodStateClasses = new Set(), parallelRegions = false) => {
616
616
  const extended = new Set(ordered.flatMap((layout) => (layout.base === null ? [] : [layout.base])));
617
617
  const constructions = [];
618
618
  for (const layout of ordered) {
619
+ // Definition effects and static storage remain live independently of any
620
+ // source construction. An absent recipe without this fact still refuses.
621
+ if (layout.constructionDeferred)
622
+ continue;
619
623
  const abi = layout.construct;
620
624
  const instance = layout.instance;
621
625
  if (!abi || !instance || instance.kind !== 'class-ref') {
@@ -800,6 +804,7 @@ const thunkOf = (body, captures, narrowed, narrowedResult, linkage, taskResult =
800
804
  const signature = `${linkagePrefix(linkage)}${cppResultTypeOf(abi.result)} ${cppThunkName(body.sourceOwner)}(${formals.join(', ')})`;
801
805
  const construct = constructThunkOf(body, abi, hasEnvironment, linkage);
802
806
  return {
807
+ ...(construct?.publishesConstruct ? { publishesConstruct: true } : {}),
803
808
  prototype: [`${signature};`, ...(construct === null ? [] : [construct.prototype])].join('\n'),
804
809
  // No `registerSource` beside the thunk any more: the function's
805
810
  // `name`/`length`/source text register at the sites that mint a function
@@ -874,18 +879,20 @@ const constructThunkOf = (body, abi, hasEnvironment, linkage) => {
874
879
  // question. A body with no environment is called through it just the same,
875
880
  // with the `void*` the signature carries either way.
876
881
  const entry = `${cppThunkName(body.sourceOwner)}(${actuals.join(', ')});`;
877
- // Published against the INVOKE pointer, beside the `name`/`length`/source
878
- // text `registerSource` publishes against the same key. A value that is
879
- // later viewed under a type naming its `[[Construct]]` -- `Factory as typeof
880
- // Factory & (new (v: number) => T)` -- carries that pointer and nothing
881
- // else about its declaration, so this is what lets the conversion stay a
882
- // property of the VALUE rather than a guess about which declaration a cell
883
- // holds (`gea::withConstructEntry`, gea_runtime.h).
884
- const registration = `[[maybe_unused]] static const bool ${cppConstructedThunkName(body.sourceOwner)}_entry = ` +
885
- `gea::registerConstructEntry(&${cppThunkName(body.sourceOwner)}, &${cppConstructedThunkName(body.sourceOwner)});`;
882
+ // No registration beside the thunk: every site that mints a value of this
883
+ // function publishes this construct thunk in the value's entry record
884
+ // (`emit-context.ts`'s `cppThunkEntryText`). A value that is later viewed
885
+ // under a type naming its `[[Construct]]` -- `Factory as typeof Factory &
886
+ // (new (v: number) => T)` -- carries that record and nothing else about its
887
+ // declaration, so this is what lets the conversion stay a property of the
888
+ // VALUE rather than a guess about which declaration a cell holds
889
+ // (`gea::withConstructEntry`, gea_runtime.h). Not keyed by the invoke
890
+ // pointer: a release link may fold two declarations' identical invoke
891
+ // thunks into one address.
886
892
  return {
887
893
  prototype: `${signature};`,
888
- definition: `${signature} { ${allocation} ${entry} return ${cppReceiverName}; }\n${registration}`
894
+ definition: `${signature} { ${allocation} ${entry} return ${cppReceiverName}; }`,
895
+ publishesConstruct: true
889
896
  };
890
897
  };
891
898
  /**
@@ -1120,8 +1127,9 @@ const commonJsDefinitionsOf = (bodies, realm = false) => {
1120
1127
  ` auto& state = ${stateAccessor}();`,
1121
1128
  ` if (state.phase != ${stateName}::Phase::fresh) return state.module->${exportField};`,
1122
1129
  ` state.phase = ${stateName}::Phase::loading;`,
1123
- ` try { ${cppBodyName(target)}(); state.phase = ${stateName}::Phase::loaded; return state.module->${exportField}; }`,
1124
- ` catch (...) { state.phase = ${stateName}::Phase::fresh; state.module = ${recordInit}; throw; }`,
1130
+ ` GEA_EH_TRY_ANY(gea_eh_failed) { ${cppBodyName(target)}(); state.phase = ${stateName}::Phase::loaded; return state.module->${exportField}; }`,
1131
+ ` GEA_EH_CATCH_ANY(gea_eh_failed) { state.phase = ${stateName}::Phase::fresh; state.module = ${recordInit}; GEA_EH_RETHROW_ANY(gea_eh_failed); } GEA_EH_END`,
1132
+ ` GEA_EH_UNREACHABLE`,
1125
1133
  '}'
1126
1134
  ].join('\n'));
1127
1135
  }
@@ -1735,7 +1743,10 @@ const renderTranslationUnitSession = (input) => {
1735
1743
  const classStaticFields = censusClassStaticFieldStorage(input.bodies, input.classes, input.realmStorage);
1736
1744
  publishClassStaticFieldStorage(input.classes, classStaticFields.storage);
1737
1745
  publishConstructorViewShapes(input.classes, input.bodies);
1738
- const classStatics = classStaticFieldStorageRows(classStaticFields.storage).map((row) => storageSpelling(row.type, row.storageName, input.realmStorage));
1746
+ const classStatics = classStaticFieldStorageRows(classStaticFields.storage).map((row) => ({
1747
+ declaration: `struct ${row.viewStruct} final { ${row.type} value{}; bool present = false; };`,
1748
+ definition: `struct ${row.viewStruct} final { ${row.type} value{}; bool present = false; };`
1749
+ }));
1739
1750
  // The reactive plan, completed with the two answers only this stage has.
1740
1751
  //
1741
1752
  // `revisions` is the struct renderer's own decision about which reactive
@@ -1980,10 +1991,14 @@ const renderTranslationUnitSession = (input) => {
1980
1991
  return entry === undefined ? [original] : [original, `${signatureOf(body, captures, new Set(), false, entry.formals, entry.name)};`];
1981
1992
  });
1982
1993
  const thunks = new Map();
1994
+ // The functions whose minted values publish a `[[Construct]]` entry.
1995
+ const constructEntries = new Set();
1983
1996
  for (const body of input.bodies) {
1984
1997
  const thunk = thunkOf(body, captures, formalsNarrowedIn(body.sourceOwner), resultNarrowedIn(body.sourceOwner), linkage, taskResultOf(body));
1985
1998
  if (thunk)
1986
1999
  thunks.set(body, thunk);
2000
+ if (thunk?.publishesConstruct && !isRegionId(body.sourceOwner))
2001
+ constructEntries.add(body.sourceOwner);
1987
2002
  }
1988
2003
  // ONE tag object per source declaration, shared by every monomorphic copy of
1989
2004
  // it. `gea::identifyCallable<&tag>` instantiates
@@ -2059,7 +2074,7 @@ const renderTranslationUnitSession = (input) => {
2059
2074
  // The formals this body's signature takes by reference: their objects
2060
2075
  // outlive the call, which `emit.ts`'s stable field reads rely on.
2061
2076
  const borrowed = stableEntry?.formals ?? formalsBorrowedIn(body.sourceOwner);
2062
- const sections = emitBody(promiseView ?? body, input.placements, input.classes, hosts, deriver, input.wellKnownSymbols, captures, symbolKeys, templateObjects, directCallables, virtuals.dispatched, narrowedStorage.factsOf(body.sourceOwner), formalsNarrowedIn(body.sourceOwner), repeatedConstructors, dyingArguments, instantiation, (callable) => abiByBody.get(String(callable)) ?? null, functionFacts, hostMethodAliases, callableMemberCandidates, callableFlowCandidates.get(body.owner) ?? new Map(), borrowableMemberBodies, stableBorrowEntries, printerDrift, input.conversions, selectionHelpers, callableIdentityDemand, nativeIntegrityRestricted, fixedFieldStateConstant, definitionCells, constructionOnlyFields, keyOrderUnobserved, debugSource, borrowed, asyncResults.taskResults, programSite.conversionIsCertified, input.programConversionRecipes, structs.classIndexProtocols);
2077
+ const sections = emitBody(promiseView ?? body, input.placements, input.classes, hosts, deriver, input.wellKnownSymbols, captures, symbolKeys, templateObjects, directCallables, virtuals.dispatched, narrowedStorage.factsOf(body.sourceOwner), formalsNarrowedIn(body.sourceOwner), repeatedConstructors, dyingArguments, instantiation, (callable) => abiByBody.get(String(callable)) ?? null, functionFacts, constructEntries, hostMethodAliases, callableMemberCandidates, callableFlowCandidates.get(body.owner) ?? new Map(), borrowableMemberBodies, stableBorrowEntries, printerDrift, input.conversions, selectionHelpers, callableIdentityDemand, nativeIntegrityRestricted, fixedFieldStateConstant, definitionCells, constructionOnlyFields, keyOrderUnobserved, debugSource, borrowed, asyncResults.taskResults, programSite.conversionIsCertified, input.programConversionRecipes, structs.classIndexProtocols);
2063
2078
  const commonJsScope = [
2064
2079
  ...coroutineEnvironmentPrologueOf(promiseView ?? body, captures),
2065
2080
  ...(commonJsOwner === null || commonJsOwner.nativeRecord
@@ -2414,8 +2429,7 @@ const renderTranslationUnitSession = (input) => {
2414
2429
  program.append(plain(definition.text));
2415
2430
  if (isolate)
2416
2431
  program.append(plain(namespaceOpen));
2417
- for (const spelling of classStatics)
2418
- program.append(plain(spelling.definition));
2432
+ // Static own-property view structs are declared once in the shared header.
2419
2433
  for (const spelling of globals)
2420
2434
  program.append(plain(spelling.definition));
2421
2435
  for (const helper of selectionHelpers?.values() ?? [])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/compiler",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
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": {
@@ -45,8 +45,9 @@
45
45
  },
46
46
  "scripts": {
47
47
  "test:cli-plugins": "node --test test/cli-plugins.mjs",
48
- "test:gea-host-namespace-members": "node --test test/gea-host-namespace-members.mjs",
48
+ "test:gea-host-namespace-members": "node --test test/gea-host-namespace-members.mjs test/host-member-namespace-receiver.mjs",
49
49
  "test:allocation-runtime": "node test/allocation-runtime.mjs",
50
+ "test:native-microtask-lifetime": "node test/native-microtask-lifetime.mjs",
50
51
  "test:compact-runtime": "node test/compact-runtime.mjs",
51
52
  "test:stored-listener-native-flow": "node test/stored-listener-native-flow.mjs",
52
53
  "test:native-typed-field-read": "node test/native-typed-field-read.mjs",
@@ -60,7 +61,7 @@
60
61
  "test:declared-integers": "node --test dist/conversion/native-selection.test.js && node test/declared-integer-contracts.mjs",
61
62
  "test:dynamic-value-metadata": "node test/dynamic-value-metadata.mjs",
62
63
  "test:native-field-descriptors": "node test/native-field-descriptors.mjs",
63
- "test:declaration-overlays": "node --test dist/semantics/declaration-overlay-transform.test.js",
64
+ "test:declaration-overlays": "node --import ./scripts/host-toolchain.mjs --test dist/semantics/declaration-overlay-transform.test.js",
64
65
  "test:recursive-native-carriers": "node test/recursive-native-carriers.mjs",
65
66
  "test:hot-path-shapes": "node test/hot-path-shapes.mjs",
66
67
  "build": "npm run architecture && tsc -p tsconfig.json && node scripts/mark-bins-executable.mjs && node scripts/build-checks.mjs",
@@ -84,13 +85,13 @@
84
85
  "fastify": "^5.0.0",
85
86
  "find-my-way": "9.6.0",
86
87
  "prettier": "^3.8.3",
87
- "@geastack/core": "0.1.37",
88
- "@geastack/host": "0.1.14",
89
- "@geastack/engine": "0.1.13",
88
+ "@geastack/core": "0.1.43",
89
+ "@geastack/host": "0.1.18",
90
+ "@geastack/engine": "0.1.18",
90
91
  "@geastack/elements": "0.1.5",
91
92
  "@geastack/geaos": "0.1.3",
92
93
  "@geastack/apple": "0.2.14",
93
- "@geastack/geatsc-plugin-gea": "0.1.19",
94
+ "@geastack/geatsc-plugin-gea": "0.1.24",
94
95
  "@geastack/geatsc-plugin-apple-native": "0.1.4",
95
96
  "@geastack/native-webgl-angle": "0.1.9"
96
97
  },
@@ -215,13 +215,23 @@ inline Value dynamicAdd(const Value& left, const Value& right) {
215
215
 
216
216
  inline bool dynamicArrayPrototypeHas(const PropertyKey& key) {
217
217
  if (key.isSymbol()) return false;
218
- for (const char* name : {"push", "pop", "join", "toString", "map", "filter", "forEach", "slice"})
218
+ std::size_t index = 0;
219
+ if (detail::arrayIndexOfKey(key, index)) return arrayPrototypeObject()->present(index);
220
+ for (const char* name : {"push", "pop", "join", "toString", "map", "filter", "forEach", "slice", "some"})
219
221
  if (key.text() == name) return true;
220
222
  return false;
221
223
  }
222
224
 
223
- inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
225
+ inline Value dynamicArrayPrototypeGet(const PropertyKey& key, const Value& receiver) {
224
226
  if (key.isSymbol()) return Value();
227
+ std::size_t index = 0;
228
+ if (detail::arrayIndexOfKey(key, index)) {
229
+ const auto prototype = arrayPrototypeObject();
230
+ if (!prototype->present(index)) return Value();
231
+ if (prototype->indexedDescriptors && arrayIndexedDescriptorContains(prototype->indexedDescriptors, index))
232
+ return prototype->indexedDescriptors->getWithNativeReceiver(key, NativeCallReceiver::fromValue(receiver));
233
+ return prototype->readElement(index);
234
+ }
225
235
  using Args = gea::Ref<ArrayObject<Value>>;
226
236
  using Method = CallableObject<Value(Value, Args)>;
227
237
  if (key.text() == "push") {
@@ -233,6 +243,31 @@ inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
233
243
  }, nullptr));
234
244
  return method;
235
245
  }
246
+ if (key.text() == "some") {
247
+ static const Value method = Value::boxMethod<1>(Method(+[](void*, Value receiver, Args args) -> Value {
248
+ if (receiver.tag() == Value::Tag::Null || receiver.tag() == Value::Tag::Undefined)
249
+ host::throwRuntimeError("TypeError", "Array.prototype.some called on null or undefined");
250
+ if (receiver.tag() != Value::Tag::Object && receiver.tag() != Value::Tag::Function)
251
+ host::throwRuntimeError("TypeError", "Native Array.prototype.some does not support primitive wrappers");
252
+ const double rawLength = dynamicToNumber(receiver.getProperty(PropertyKey::string("length")));
253
+ const std::uint64_t length = rawLength > 0
254
+ ? static_cast<std::uint64_t>(std::min(std::floor(rawLength), 9007199254740991.0)) : 0;
255
+ const Value callback = args->size() ? args->readElement(0) : Value();
256
+ if (callback.tag() != Value::Tag::Function)
257
+ host::throwRuntimeError("TypeError", "Array callback must be callable");
258
+ const Value thisArg = args->size() > 1 ? args->readElement(1) : Value();
259
+ for (std::uint64_t i = 0; i < length; ++i) {
260
+ const auto index = PropertyKey::string(std::to_string(i));
261
+ if (!receiver.hasProperty(index)) continue;
262
+ const Value item = receiver.getProperty(index);
263
+ if (host::detail::toBoolean(callback.callWithReceiver(thisArg,
264
+ {item, Value::box(Value::Tag::Number, static_cast<double>(i)), receiver})))
265
+ return Value::box(Value::Tag::Boolean, true);
266
+ }
267
+ return Value::box(Value::Tag::Boolean, false);
268
+ }, nullptr));
269
+ return method;
270
+ }
236
271
  if (key.text() == "pop") {
237
272
  static const Value method = Value::boxMethod<1>(Method(+[](void*, Value receiver, Args) -> Value {
238
273
  double length = dynamicToNumber(receiver.getProperty(PropertyKey::string("length")));
@@ -306,6 +341,10 @@ inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
306
341
  return Value();
307
342
  }
308
343
 
344
+ inline Value dynamicArrayPrototypeGet(const PropertyKey& key) {
345
+ return dynamicArrayPrototypeGet(key, Value());
346
+ }
347
+
309
348
  /**
310
349
  * `String.prototype`'s methods read off a string the program declared `any`
311
350
  * (`name.toLowerCase()` after `name = \`${name}\``). Each is the native
@@ -365,7 +404,7 @@ inline Value dynamicStringPrototypeGet(const PropertyKey& key) {
365
404
  inline Ref<ArrayObject<Value>> arrayPrototypeObject() {
366
405
  static const Ref<ArrayObject<Value>> prototype = [] {
367
406
  auto object = makeRef<ArrayObject<Value>>();
368
- for (const char* name : {"push", "pop", "join", "toString", "map", "filter", "forEach", "slice"}) {
407
+ for (const char* name : {"push", "pop", "join", "toString", "map", "filter", "forEach", "slice", "some"}) {
369
408
  const auto key = PropertyKey::string(name);
370
409
  auto descriptor = PropertyDescriptor::assignment(dynamicArrayPrototypeGet(key));
371
410
  descriptor.enumerable = false;
@@ -916,6 +916,9 @@ struct Machine {
916
916
  for (std::size_t i = 1; i < tree->children.size(); ++i) args.push_back(eval(tree->children[i]));
917
917
  if (tree->kind == Node::Construct) {
918
918
  if (callee.tag() != Value::Tag::Function) error("TypeError", "Value is not a constructor");
919
+ // An entry comparison that folding cannot mislead: a function the
920
+ // linker folded into this interpreter entry has its code, so it is
921
+ // an eval closure in every respect this construction relies on.
919
922
  if (callee.payloadType() != detail::payloadTypeTagFor<Function>() || callee.as<Function>().invoke != invoke)
920
923
  unsupported("Constructing an external callable requires a native construct adapter");
921
924
  self = Value::object();