@geastack/compiler 1.0.32 → 1.0.34

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 (210) 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 +35 -28
  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 +22 -6
  37. package/dist/ir/model.d.ts +41 -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.d.ts +4 -3
  87. package/dist/representation/unassigned-binding-cells.js +19 -2
  88. package/dist/representation/union.js +6 -6
  89. package/dist/semantics/frontend.d.ts +2 -0
  90. package/dist/semantics/frontend.js +34 -5
  91. package/dist/semantics/host-methods.js +4 -1
  92. package/dist/semantics/jsx-runtime-provider.d.ts +5 -0
  93. package/dist/semantics/jsx-runtime-provider.js +16 -0
  94. package/dist/semantics/model/native-iterable.d.ts +14 -0
  95. package/dist/semantics/model/native-iterable.js +7 -0
  96. package/dist/semantics/model/operands.d.ts +30 -0
  97. package/dist/semantics/model/operations.d.ts +15 -0
  98. package/dist/semantics/model/primitive-domain.d.ts +15 -0
  99. package/dist/semantics/model/primitive-domain.js +27 -4
  100. package/dist/semantics/module-resolution.js +13 -2
  101. package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
  102. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +32 -4
  103. package/dist/semantics/normalize/callback-parameter-contracts.js +66 -6
  104. package/dist/semantics/normalize/census.d.ts +3 -0
  105. package/dist/semantics/normalize/census.js +17 -12
  106. package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +4 -1
  107. package/dist/semantics/normalize/deferred-intrinsic-protocols.js +29 -9
  108. package/dist/semantics/normalize/flow/callable-reach.js +94 -3
  109. package/dist/semantics/normalize/flow/component-solver.js +144 -55
  110. package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +9 -0
  111. package/dist/semantics/normalize/flow/member-call-forwarding.js +30 -4
  112. package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +2 -0
  113. package/dist/semantics/normalize/flow/proof-hypotheses.js +27 -0
  114. package/dist/semantics/normalize/flow/source-callable-own-data.js +87 -14
  115. package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +2 -0
  116. package/dist/semantics/normalize/flow/source-commonjs-exports.js +2 -0
  117. package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +17 -0
  118. package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +125 -0
  119. package/dist/semantics/normalize/flow/source-native-origin.d.ts +6 -0
  120. package/dist/semantics/normalize/flow/source-native-origin.js +38 -0
  121. package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +37 -0
  122. package/dist/semantics/normalize/flow/source-proxy-operation.js +201 -0
  123. package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +20 -0
  124. package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +73 -0
  125. package/dist/semantics/normalize/flow/source-value-session.d.ts +50 -1
  126. package/dist/semantics/normalize/flow/source-value-session.js +596 -57
  127. package/dist/semantics/normalize/flow/value-flow.d.ts +17 -0
  128. package/dist/semantics/normalize/flow/value-flow.js +84 -0
  129. package/dist/semantics/normalize/fresh-dictionary-storage.js +2 -2
  130. package/dist/semantics/normalize/fresh-table-last-use.d.ts +52 -0
  131. package/dist/semantics/normalize/fresh-table-last-use.js +129 -0
  132. package/dist/semantics/normalize/gating.js +5 -1
  133. package/dist/semantics/normalize/global-host-mutations.js +190 -13
  134. package/dist/semantics/normalize/identities.js +20 -1
  135. package/dist/semantics/normalize/local-bindings.js +2 -2
  136. package/dist/semantics/normalize/parameter-bindings.js +10 -1
  137. package/dist/semantics/normalize/producer-context.d.ts +5 -0
  138. package/dist/semantics/normalize/producers/binding-kind.js +2 -0
  139. package/dist/semantics/normalize/producers/cited-value-type.d.ts +2 -2
  140. package/dist/semantics/normalize/producers/cited-value-type.js +2 -2
  141. package/dist/semantics/normalize/producers/class-lifecycle.js +39 -9
  142. package/dist/semantics/normalize/producers/computations.js +36 -5
  143. package/dist/semantics/normalize/producers/conditional-guard.d.ts +6 -0
  144. package/dist/semantics/normalize/producers/conditional-guard.js +5 -0
  145. package/dist/semantics/normalize/producers/control.js +7 -1
  146. package/dist/semantics/normalize/producers/destructuring.js +8 -9
  147. package/dist/semantics/normalize/producers/invocations.js +55 -2
  148. package/dist/semantics/normalize/producers/properties.d.ts +13 -0
  149. package/dist/semantics/normalize/producers/properties.js +21 -3
  150. package/dist/semantics/normalize/producers/references.js +8 -4
  151. package/dist/semantics/normalize/reachability.d.ts +15 -3
  152. package/dist/semantics/normalize/reachability.js +128 -20
  153. package/dist/semantics/normalize/return-bindings.js +3 -3
  154. package/dist/semantics/normalize/source-native-iterable.d.ts +19 -0
  155. package/dist/semantics/normalize/source-native-iterable.js +74 -0
  156. package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
  157. package/dist/semantics/normalize/structural-declarations.js +1 -1
  158. package/dist/semantics/normalize/structural-indexed-access.js +9 -0
  159. package/dist/semantics/normalize/structural.js +11 -0
  160. package/dist/semantics/normalize/unshared-array-result.d.ts +42 -0
  161. package/dist/semantics/normalize/unshared-array-result.js +269 -0
  162. package/dist/semantics/package-sources.js +3 -2
  163. package/dist/semantics/program.d.ts +8 -0
  164. package/dist/semantics/program.js +55 -0
  165. package/dist/semantics/source-transform-exports.d.ts +8 -0
  166. package/dist/semantics/source-transform-exports.js +145 -0
  167. package/dist/semantics/source-transform-protocol.d.ts +22 -0
  168. package/dist/semantics/this-constructor-source-transform.js +19 -1
  169. package/dist/targets/cpp/class-layout.d.ts +2 -0
  170. package/dist/targets/cpp/class-layout.js +35 -1
  171. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +11 -1
  172. package/dist/targets/cpp/class-properties/emit-class-properties.js +33 -4
  173. package/dist/targets/cpp/conversions.js +6 -3
  174. package/dist/targets/cpp/emit-callable.js +73 -7
  175. package/dist/targets/cpp/emit-context.d.ts +23 -9
  176. package/dist/targets/cpp/emit-context.js +19 -8
  177. package/dist/targets/cpp/emit-equality.js +41 -1
  178. package/dist/targets/cpp/emit-exceptions.js +29 -11
  179. package/dist/targets/cpp/emit-iterator-object-view.js +2 -2
  180. package/dist/targets/cpp/emit-iterator.js +33 -9
  181. package/dist/targets/cpp/emit-live-field-view.js +6 -1
  182. package/dist/targets/cpp/emit-narrowing.d.ts +11 -3
  183. package/dist/targets/cpp/emit-narrowing.js +58 -18
  184. package/dist/targets/cpp/emit-native-field-view.d.ts +3 -1
  185. package/dist/targets/cpp/emit-native-field-view.js +84 -8
  186. package/dist/targets/cpp/emit-properties.d.ts +1 -0
  187. package/dist/targets/cpp/emit-properties.js +26 -7
  188. package/dist/targets/cpp/emit-protocol-iterator.js +5 -2
  189. package/dist/targets/cpp/emit-record-view.js +14 -2
  190. package/dist/targets/cpp/emit-tostring.js +23 -1
  191. package/dist/targets/cpp/emit-union-properties.js +1 -1
  192. package/dist/targets/cpp/emit.d.ts +1 -1
  193. package/dist/targets/cpp/emit.js +132 -21
  194. package/dist/targets/cpp/host/emit-host-invoke.js +2 -2
  195. package/dist/targets/cpp/host/emit-host-object.js +28 -2
  196. package/dist/targets/cpp/host/emit-host-properties.js +9 -1
  197. package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
  198. package/dist/targets/cpp/host/emit-host-value.js +8 -6
  199. package/dist/targets/cpp/host/host-members.js +2 -1
  200. package/dist/targets/cpp/prototype/emit-prototype-array.js +69 -5
  201. package/dist/targets/cpp/prototype/emit-prototype-invoke.js +9 -9
  202. package/dist/targets/cpp/prototype/emit-prototype-iterator.js +2 -2
  203. package/dist/targets/cpp/prototype/emit-prototype-promise.js +7 -7
  204. package/dist/targets/cpp/records.d.ts +1 -0
  205. package/dist/targets/cpp/records.js +16 -7
  206. package/dist/targets/cpp/translation-unit.js +30 -16
  207. package/package.json +8 -7
  208. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +42 -3
  209. package/src/targets/cpp/runtime/gea_eval.h +3 -0
  210. package/src/targets/cpp/runtime/gea_runtime.h +2407 -684
@@ -113,8 +113,8 @@ export const certifiedIteratorObjectViewText = (ctx, certified, text) => {
113
113
  // step that throws is that promise's rejection (ECMA-262 27.6.3.3), as
114
114
  // `prototype/emit-prototype-iterator.ts` answers a generator's own call.
115
115
  body = planned.awaited
116
- ? `try { return ${resultType}(([&]() -> ${settledType} { ${step} }())); } ` +
117
- `catch (...) { return ${resultType}::rejected_with(std::current_exception()); }`
116
+ ? `GEA_EH_TRY_ANY(gea_eh_failed) { return ${resultType}(([&]() -> ${settledType} { ${step} }())); } ` +
117
+ `GEA_EH_CATCH_ANY(gea_eh_failed) { return ${resultType}::rejected_with(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END GEA_EH_UNREACHABLE`
118
118
  : step;
119
119
  }
120
120
  callable =
@@ -1196,7 +1196,8 @@ const renderSuspendingIteratorCloseRegion = (ctx, lines, body, region, rendering
1196
1196
  lines.push(`bool ${guard}_returning = false;`);
1197
1197
  if (closingFlag !== null)
1198
1198
  lines.push(`bool ${closingFlag} = false;`);
1199
- lines.push('try {');
1199
+ // Fenced under the MSVC ABI (`GEA_EH_FENCED` in the runtime header); the handlers below only record.
1200
+ lines.push('GEA_EH_FENCE_OPEN try { GEA_EH_BODY_FENCE');
1200
1201
  const leaves = (target) => !selected.has(target) && !region.dismissTargets.includes(target);
1201
1202
  const scopedRendering = {
1202
1203
  ...rendering,
@@ -1271,9 +1272,10 @@ const renderSuspendingIteratorCloseRegion = (ctx, lines, body, region, rendering
1271
1272
  // synchronous region's scope guard makes.
1272
1273
  const returning = `${guard}_returning`;
1273
1274
  lines.push(`} catch (const gea::Value&) { ${thrown} = std::current_exception(); } ` +
1274
- `catch (...) { ${thrown} = std::current_exception(); ${returning} = true; }`);
1275
+ `catch (...) { ${thrown} = std::current_exception(); ${returning} = true; } GEA_EH_FENCE_CLOSE`);
1275
1276
  // Reached only through a handler: every block above ends in a terminator.
1276
- const closing = `if (${armed}) { ${armed} = false; if (${returning}) { ${close} } else { try { ${close} } catch (const gea::Value&) {} } }`;
1277
+ const closing = `if (${armed}) { ${armed} = false; if (${returning}) { ${close} } else ` +
1278
+ `{ GEA_EH_FENCE_OPEN try { GEA_EH_BODY_FENCE ${close} } catch (const gea::Value&) {} GEA_EH_FENCE_CLOSE } }`;
1277
1279
  lines.push(closingFlag === null ? closing : `if (${closingFlag}) { ${closing} }`);
1278
1280
  lines.push(`std::rethrow_exception(${thrown});`);
1279
1281
  lines.push('}');
@@ -1328,7 +1330,11 @@ export const renderIteratorCloseRegion = (ctx, lines, body, region, rendering) =
1328
1330
  const closingFlag = splitEntry === null ? null : `${guard}_in_body`;
1329
1331
  if (closingFlag !== null)
1330
1332
  lines.push(`bool ${closingFlag} = false;`);
1331
- lines.push('try {');
1333
+ // The plain `try`/`catch (const gea::Value&)` everywhere but the MSVC ABI,
1334
+ // where the handler records the throw and closes after the statement
1335
+ // (`GEA_EH_FENCED` in the runtime header).
1336
+ const caught = `${guard}_caught`;
1337
+ lines.push(`GEA_EH_TRY_VALUE(${caught}) {`);
1332
1338
  const scopedRendering = {
1333
1339
  ...rendering,
1334
1340
  emitTerminator: (inner, targetLines, labels, isSingleBlock, terminator) => {
@@ -1367,19 +1373,37 @@ export const renderIteratorCloseRegion = (ctx, lines, body, region, rendering) =
1367
1373
  lines.push(`${rendering.labelOf(rendering.labels, id)}:`);
1368
1374
  if (closingFlag !== null && id === splitEntry)
1369
1375
  lines.push(`${closingFlag} = true;`);
1370
- for (const operation of block.operations)
1376
+ for (const operation of block.operations) {
1377
+ const completesOnAbrupt = region.completeOnStepAbrupt === true && operation.kind === 'iterator-next' && operation.iterator.value === region.iterator.value;
1378
+ if (completesOnAbrupt)
1379
+ lines.push('try {');
1371
1380
  rendering.emitOperation(ctx, lines, operation, (targetLines, terminator) => scopedRendering.emitTerminator(ctx, targetLines, rendering.labels, rendering.isSingleBlock, terminator));
1381
+ if (completesOnAbrupt) {
1382
+ const iterator = region.iterator;
1383
+ const done = iterator.representation.kind === 'dynamic' ? ctx.dynamicIteratorDoneStates.get(iterator.value) : null;
1384
+ if (iterator.representation.kind === 'dynamic' && !done)
1385
+ throw createCppEmitBlockedError('call-abi:finite-iterator-close-state', 'has no dynamic iterator exhaustion state');
1386
+ if (iterator.representation.kind !== 'dynamic' && iterator.representation.kind !== 'iterator')
1387
+ throw createCppEmitBlockedError('call-abi:finite-iterator-close-state', 'has no mutable typed iterator exhaustion state');
1388
+ lines.push('} catch (const gea::Value&) {');
1389
+ lines.push(done ? `${done} = true;` : `${operandText(ctx, iterator)}.setDone(true);`);
1390
+ lines.push('throw;');
1391
+ lines.push('}');
1392
+ }
1393
+ }
1372
1394
  for (const write of rendering.mergeWrites.get(id) ?? [])
1373
1395
  lines.push(`${write.name} = ${operandText(ctx, write.value)};`);
1374
1396
  scopedRendering.emitTerminator(ctx, lines, rendering.labels, rendering.isSingleBlock, block.terminator);
1375
1397
  }
1376
- lines.push('} catch (const gea::Value&) {');
1398
+ lines.push(`} GEA_EH_CATCH_VALUE_UNNAMED(${caught}) {`);
1399
+ const closeQuietly = `GEA_EH_FENCE_OPEN try { GEA_EH_BODY_FENCE ${guard}.close(); } catch (const gea::Value&) {} GEA_EH_FENCE_CLOSE`;
1377
1400
  if (closingFlag === null)
1378
- lines.push(`try { ${guard}.close(); } catch (const gea::Value&) {}`);
1401
+ lines.push(closeQuietly);
1379
1402
  else
1380
- lines.push(`if (${closingFlag}) { try { ${guard}.close(); } catch (const gea::Value&) {} } else { ${guard}.dismiss(); }`);
1381
- lines.push('throw;');
1403
+ lines.push(`if (${closingFlag}) { ${closeQuietly} } else { ${guard}.dismiss(); }`);
1404
+ lines.push(`GEA_EH_RETHROW_VALUE(${caught});`);
1382
1405
  lines.push('}');
1406
+ lines.push('GEA_EH_END');
1383
1407
  lines.push('}');
1384
1408
  return order;
1385
1409
  };
@@ -17,7 +17,13 @@ export const liveFieldViewText = (plan, text, accesses) => {
17
17
  `if (!gea_read.accepts<${type}, ${policy}>()) ${declared === '' ? 'return false;' : `{ ${declared}return false; }`} ` +
18
18
  `return gea_read.assign<${policy}>(${access.read.text}); }`);
19
19
  });
20
+ const nativeExtensions = plan.source.kind === 'record' || (plan.source.kind === 'native-record-ref' && plan.source.native === null);
20
21
  const writeArms = accesses.map((access) => {
22
+ // A forwarded key the record source does not declare is created on that
23
+ // source by a write naming its carrier (`nativeLiveViewForwardedWrite`),
24
+ // as its read already answers from the source's expando.
25
+ if (access.write === null && access.descriptorForward && nativeExtensions)
26
+ return `if (gea_key.text() == ${cppStringLiteral(access.key)}) return gea::nativeLiveViewForwardedWrite(gea_live_source, gea_key, gea_write);`;
21
27
  if (access.write === null)
22
28
  return `if (gea_key.text() == ${cppStringLiteral(access.key)}) return false;`;
23
29
  const type = cppTypeOf(access.write.value);
@@ -27,7 +33,6 @@ export const liveFieldViewText = (plan, text, accesses) => {
27
33
  });
28
34
  const sourceType = cppTypeOf(plan.source);
29
35
  const source = `const auto gea_live_source = gea_immediate.staticCast<typename ${sourceType}::element_type>();`;
30
- const nativeExtensions = plan.source.kind === 'record' || (plan.source.kind === 'native-record-ref' && plan.source.native === null);
31
36
  const ordinaryRead = `return gea::nativeLiveViewSourceRead<${nativeExtensions}>(gea_live_source, gea_key, gea_read);`;
32
37
  const ordinaryWrite = 'return gea::nativeLiveViewSourceWrite(gea_live_source, gea_key, gea_write);';
33
38
  const read = '+[](const gea::Ref<void>& gea_immediate, const gea::PropertyKey& gea_key, const gea::NativeFieldRead& gea_read) -> bool { ' +
@@ -424,7 +424,7 @@ export declare const CHECKED_ARM_NARROWING = "view:checked-arm-narrowing";
424
424
  * (or may not be copied) is a `TypeError` (`gea::host::unhomedUnionArm`). `null` when no arm
425
425
  * can be the target at all, which the printer refuses.
426
426
  */
427
- export declare const assertedUnionText: (source: Representation, target: Representation, text: string, copyAllowed: boolean) => string | null;
427
+ export declare const assertedUnionText: (source: Representation, target: Representation, text: string, copyAllowed: boolean, frameArgument?: boolean) => string | null;
428
428
  export declare const checkedArmNarrowingText: (source: Representation, target: Representation, text: string) => string | null;
429
429
  export declare const resultAdaptedCallableText: (source: Representation, target: Representation, text: string, viaView?: LayoutConversion, knownFunction?: FunctionId) => string | null;
430
430
  /** Whether a class reaches a construct-signature slot through `constructorDispatchAdapterText`. Exported so `conversions.ts` asks the identical question the render answers. */
@@ -652,7 +652,7 @@ export declare const genericFunctionSetWideningText: (source: Representation, ta
652
652
  * sentinel, a populated one -- a real `undefined[]`, which the carrier cannot
653
653
  * tell apart -- is boxed element by element.
654
654
  */
655
- export declare const emptyArraySentinelText: (source: Representation, target: Representation, text: string) => string | null;
655
+ export declare const emptyArraySentinelText: (source: Representation, target: Representation, text: string, consumed?: boolean) => string | null;
656
656
  /**
657
657
  * One step of the conversion chain. `undefined` means the step does not
658
658
  * claim the pair and the chain continues; `null` means it claims the pair
@@ -671,7 +671,15 @@ export interface ConversionStep {
671
671
  * for the instruction that carries the proof, never from the pair alone, and a
672
672
  * pending promise rebuilds when its array arrives (`promiseAdoptionText`).
673
673
  */
674
- export declare const unsharedArrayRebuildText: (ctx: ConversionSite, source: Representation, target: Representation, text: string, elementNode: ConversionNode) => string | null;
674
+ export declare const unsharedArrayRebuildText: (ctx: ConversionSite, source: Representation, target: Representation, text: string, elementNode: ConversionNode, releasesSource?: boolean) => string | null;
675
+ /**
676
+ * The `rebuild: 'unshared-dictionary'` conversion (`ir/model.ts`'s
677
+ * `ConvertOperation`): a fresh local table stored as its last use, rebuilt
678
+ * once at the slot's entry carrier -- its enumerable entries in creation
679
+ * order, the way `{ ...table }` copies them -- and wrapped when the slot is
680
+ * an optional. Rendered only for the instruction carrying the proof.
681
+ */
682
+ export declare const unsharedDictionaryRebuildText: (ctx: ConversionSite, source: Representation, target: Representation, text: string, entryNode: ConversionNode) => string | null;
675
683
  export declare const conversionChain: readonly ConversionStep[];
676
684
  /**
677
685
  * One chain call the printer still makes on a pair the IR did not already
@@ -1,4 +1,5 @@
1
1
  import { isNativeCallableCarrier } from '../../representation/callable-object.js';
2
+ import { unsharedDictionaryPairOf } from '../../ir/convert-carriers.js';
2
3
  import { numberStorageTarget } from '../../conversion/number-storage.js';
3
4
  import { numberStorageText } from './emit-number-storage.js';
4
5
  import { NATIVE_REFERENCE_ABSENCE, nativeReferenceAbsenceOf } from '../../conversion/native-absence.js';
@@ -7,11 +8,11 @@ import { proxyArmWithoutHome } from '../../representation/proxy-carriers.js';
7
8
  import { physicalCarrierKey, samePhysicalCarrier } from '../../representation/physical-carrier.js';
8
9
  import { cppRecordIndexSidecarName, tailAwareFieldReadText, tailAwareFieldWriteText, tailFieldsOf } from './records.js';
9
10
  import { classRefTransportKind, constructorFamilyUpcastMembers, constructorUpcastMember, nativeRecordBaseTransportKind, nativePromiseBaseOf } from './class-ref-transport.js';
10
- import { abiKey, arrayExtensionKey, containsUnresolved, isCanonicalNumberPropertyKeyText, isOpenDocument, representationKey, standInRefuses, walkRepresentation, carriesUndefined } from '../../representation/model.js';
11
+ import { abiKey, arrayExtensionKey, containsUnresolved, isCanonicalNumberPropertyKeyText, isOpenDocument, representationKey, standInRefuses, walkRepresentation, carriesNativeUndefined, carriesUndefined } from '../../representation/model.js';
11
12
  import { programConversionKey } from '../../ir/program-conversions.js';
12
13
  import { transferOf } from '../../ir/transfer.js';
13
14
  import { coercionText } from './emit-coercion.js';
14
- import { ARM_VIEW_MATERIALIZER, ASSERTED_UNION_MATERIALIZER, ASSERTED_UNION_COPY_MATERIALIZER, ASSERTED_VIEW_MATERIALIZER, EXACT_ARM_MATERIALIZER, FAMILY_MEMBER_VIEW_MATERIALIZER, CAUGHT_HANDOFF_MATERIALIZER, ASSERTED_CLASS_DOWNCAST_MATERIALIZER, NULLISH_OPTIONAL_MATERIALIZER, NATIVE_BASE_VIEW_MATERIALIZER, IMPOSSIBLE_INDEX_READ, exactArmIndexOf, isNativeCollectionUpcast } from '../../conversion/nodes.js';
15
+ import { ARM_VIEW_MATERIALIZER, ASSERTED_UNION_MATERIALIZER, ASSERTED_UNION_COPY_MATERIALIZER, FRAME_ARGUMENT_UNION_MATERIALIZER, ASSERTED_VIEW_MATERIALIZER, EXACT_ARM_MATERIALIZER, FAMILY_MEMBER_VIEW_MATERIALIZER, CAUGHT_HANDOFF_MATERIALIZER, ASSERTED_CLASS_DOWNCAST_MATERIALIZER, NULLISH_OPTIONAL_MATERIALIZER, NATIVE_BASE_VIEW_MATERIALIZER, IMPOSSIBLE_INDEX_READ, exactArmIndexOf, isNativeCollectionUpcast } from '../../conversion/nodes.js';
15
16
  import { certifiedRecordViewText, familyMemberViewText, structuralRecordViewText } from './emit-record-view.js';
16
17
  import { documentRecordViewText } from './emit-document-record-view.js';
17
18
  import { dynamicRecordLoadNeedsPlan } from '../../conversion/document-record-view.js';
@@ -2416,7 +2417,7 @@ const callablePartText = (source, target, text) => {
2416
2417
  const sourceType = cppTypeOf(source);
2417
2418
  const targetType = cppTypeOf(target);
2418
2419
  return (`[](const ${sourceType}& gea_from) { ${targetType} gea_callable{}; ` +
2419
- `gea_callable.invoke = gea_from.invoke; gea_callable.environment = gea_from.environment; ` +
2420
+ `gea_callable.invoke = gea_from.invoke; gea_callable.record = gea_from.record; gea_callable.environment = gea_from.environment; ` +
2420
2421
  `gea_callable.environmentOwner = gea_from.environmentOwner; gea_callable.functionObject = gea_from.functionObject; return gea_callable; }(${text})`);
2421
2422
  };
2422
2423
  /**
@@ -2981,13 +2982,13 @@ const dynamicArrayRebuildText = (arm, target, text) => {
2981
2982
  * (or may not be copied) is a `TypeError` (`gea::host::unhomedUnionArm`). `null` when no arm
2982
2983
  * can be the target at all, which the printer refuses.
2983
2984
  */
2984
- export const assertedUnionText = (source, target, text, copyAllowed) => {
2985
+ export const assertedUnionText = (source, target, text, copyAllowed, frameArgument = false) => {
2985
2986
  // An absent-capable union: the absence converts as its own constant, the
2986
2987
  // present payload dispatches per arm below.
2987
2988
  if (source.kind === 'optional' && source.payload.kind === 'tagged-union') {
2988
2989
  const payload = source.payload;
2989
2990
  return tryCandidateText(() => evaluatedOnceText(text, (operand) => {
2990
- const present = assertedUnionText(payload, target, `(*${operand})`, copyAllowed);
2991
+ const present = assertedUnionText(payload, target, `(*${operand})`, copyAllowed, frameArgument);
2991
2992
  const absent = convertedValueText({ kind: source.absence }, target, source.absence === 'null' ? 'nullptr' : 'gea::Undefined{}');
2992
2993
  return present === null || absent === null ? null : `(${operand}.has_value() ? ${present} : ${absent})`;
2993
2994
  }));
@@ -3000,6 +3001,10 @@ export const assertedUnionText = (source, target, text, copyAllowed) => {
3000
3001
  const slot = `${operand}.get<${index}>()`;
3001
3002
  if (representationKey(arm.value) === targetKey)
3002
3003
  return slot;
3004
+ // A frame argument's boxed arm: the class check first, so a value that
3005
+ // is no instance is a catchable TypeError rather than the unbox's abort.
3006
+ if (frameArgument && arm.value.kind === 'dynamic' && target.kind === 'class-ref' && target.ownership === 'shared-refcount')
3007
+ return `gea::host::frameArgumentClassRef<${cppClassName(target.declaration)}>(${slot})`;
3003
3008
  return (tryCandidateText(() => convertedValueText(arm.value, target, slot) ?? narrowedLoadText(arm.value, target, slot)) ??
3004
3009
  (copyAllowed ? dynamicArrayRebuildText(arm.value, target, slot) : null));
3005
3010
  });
@@ -4012,16 +4017,22 @@ export const genericFunctionSetWideningText = (source, target, text) => {
4012
4017
  * sentinel, a populated one -- a real `undefined[]`, which the carrier cannot
4013
4018
  * tell apart -- is boxed element by element.
4014
4019
  */
4015
- export const emptyArraySentinelText = (source, target, text) => {
4020
+ export const emptyArraySentinelText = (source, target, text, consumed = false) => {
4016
4021
  if (source.kind !== 'array-object' || target.kind !== 'array-object' || source.element.kind !== 'undefined')
4017
4022
  return null;
4018
4023
  if (source.ownership !== 'shared-refcount' || target.ownership !== 'shared-refcount')
4019
4024
  return null;
4025
+ // `consumed`: an element an unshared rebuild released (`unsharedArrayRebuildText`).
4026
+ const argument = consumed ? `${text}, gea::consumedSource` : text;
4020
4027
  if (target.element.kind === 'dynamic')
4021
- return `gea::emptyArraySentinelOrBoxed(${text})`;
4028
+ return `gea::emptyArraySentinelOrBoxed(${argument})`;
4029
+ // A shared class or record reference holds `undefined` natively, so a
4030
+ // populated source is the same real `undefined[]` as for `any[]`.
4031
+ if (carriesNativeUndefined(target.element))
4032
+ return `gea::emptyArraySentinelOrAbsent<${cppTypeOf(target.element)}>(${argument})`;
4022
4033
  if (carriesUndefined(target.element))
4023
4034
  return null;
4024
- return `gea::emptyArraySentinel<${cppTypeOf(target.element)}>(${text})`;
4035
+ return `gea::emptyArraySentinel<${cppTypeOf(target.element)}>(${argument})`;
4025
4036
  };
4026
4037
  /**
4027
4038
  * Any callable read where a function IDENTITY is wanted -- the carrier of
@@ -4062,9 +4073,9 @@ const callableIdentityText = (source, target, text) => {
4062
4073
  * environment, its owner and its `FunctionObjectIdentity` -- one own-property
4063
4074
  * table, one `===` answer. `gea::withConstructEntry` is that one step.
4064
4075
  *
4065
- * The construct entry is looked up at run time by the source's own invoke
4066
- * pointer, published beside the construct thunk
4067
- * (`translation-unit.ts`'s `constructThunkOf`). That keeps the conversion a
4076
+ * The construct entry is read at run time from the source's own entry record,
4077
+ * where every site minting the function published it (`emit-context.ts`'s
4078
+ * `cppThunkEntryText`). That keeps the conversion a
4068
4079
  * property of the VALUE: this step never has to decide which declaration a
4069
4080
  * cell holds, and a function whose declaration published no such entry refuses
4070
4081
  * by name instead of constructing through another body.
@@ -4121,7 +4132,8 @@ const promiseAdoptionText = (source, target, text, payload) => {
4121
4132
  `if (${promiseSourceName}.settled()) return ${cppTypeOf(target)}(${settledPayload}); ` +
4122
4133
  `${cppTypeOf(target)} ${promiseTargetName}; ` +
4123
4134
  `${promiseSourceName}.observe([${promiseTargetName}](const ${cppTypeOf(source.value)}& ${promiseValueName}) mutable ` +
4124
- `{ try { ${promiseTargetName}.resolveInline(${pendingPayload}); } catch (...) { ${promiseTargetName}.rejectInline(std::current_exception()); } }, ` +
4135
+ `{ GEA_EH_TRY_ANY(gea_eh_failed) { ${promiseTargetName}.resolveInline(${pendingPayload}); } ` +
4136
+ `GEA_EH_CATCH_ANY(gea_eh_failed) { ${promiseTargetName}.rejectInline(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END }, ` +
4125
4137
  `[${promiseTargetName}](const std::exception_ptr& ${promiseRejectionName}) mutable ` +
4126
4138
  `{ ${promiseTargetName}.rejectInline(${promiseRejectionName}); }); ` +
4127
4139
  `return ${promiseTargetName}; }())`);
@@ -4142,20 +4154,46 @@ const promiseCompletionText = (source, target, text, plan, payload) => {
4142
4154
  * for the instruction that carries the proof, never from the pair alone, and a
4143
4155
  * pending promise rebuilds when its array arrives (`promiseAdoptionText`).
4144
4156
  */
4145
- export const unsharedArrayRebuildText = (ctx, source, target, text, elementNode) => {
4157
+ export const unsharedArrayRebuildText = (ctx, source, target, text, elementNode, releasesSource = false) => {
4146
4158
  if (source.kind === 'promise' && target.kind === 'promise') {
4147
- return promiseAdoptionText(source, target, text, (value) => unsharedArrayRebuildText(ctx, source.value, target.value, value, elementNode));
4159
+ return promiseAdoptionText(source, target, text, (value) => unsharedArrayRebuildText(ctx, source.value, target.value, value, elementNode, releasesSource));
4148
4160
  }
4149
4161
  if (source.kind !== 'array-object' || target.kind !== 'array-object')
4150
4162
  return null;
4151
- const element = namedConversionText(ctx, 'emit-narrowing.ts:unshared-array', elementNode, 'gea_element');
4152
- if (element === null)
4163
+ const named = namedConversionText(ctx, 'emit-narrowing.ts:unshared-array', elementNode, 'gea_element');
4164
+ if (named === null)
4153
4165
  return null;
4166
+ // A released inner `never[]` is told apart from a binding read by the
4167
+ // `gea::consumedSource` tag, which only this rebuild can pass.
4168
+ const element = releasesSource && materializerIdOf(elementNode) === 'gea::emptyArraySentinel'
4169
+ ? (emptyArraySentinelText(source.element, target.element, 'gea_element', true) ?? named)
4170
+ : named;
4171
+ const append = releasesSource ? 'appendRangeConvertedReleasing' : 'appendRangeConverted';
4154
4172
  return (`([&]() -> ${cppTypeOf(target)} { const auto& gea_fresh = ${text}; ` +
4155
4173
  `auto gea_rebuilt = gea::makeRef<${cppTypeOf(target, 'owned')}>(); ` +
4156
- `gea_rebuilt->appendRangeConverted(*gea_fresh, 0, [&](const ${cppTypeOf(source.element)}& gea_element) { return ${element}; }); ` +
4174
+ `gea_rebuilt->${append}(*gea_fresh, 0, [&](const ${cppTypeOf(source.element)}& gea_element) { return ${element}; }); ` +
4157
4175
  `return gea_rebuilt; }())`);
4158
4176
  };
4177
+ const materializerIdOf = (node) => node.capability.kind === 'atom' || node.capability.kind === 'static' ? node.capability.materializer.id : null;
4178
+ /**
4179
+ * The `rebuild: 'unshared-dictionary'` conversion (`ir/model.ts`'s
4180
+ * `ConvertOperation`): a fresh local table stored as its last use, rebuilt
4181
+ * once at the slot's entry carrier -- its enumerable entries in creation
4182
+ * order, the way `{ ...table }` copies them -- and wrapped when the slot is
4183
+ * an optional. Rendered only for the instruction carrying the proof.
4184
+ */
4185
+ export const unsharedDictionaryRebuildText = (ctx, source, target, text, entryNode) => {
4186
+ const pair = unsharedDictionaryPairOf(source, target);
4187
+ if (pair === null)
4188
+ return null;
4189
+ const entry = namedConversionText(ctx, 'emit-narrowing.ts:unshared-dictionary', entryNode, 'gea_entry');
4190
+ if (entry === null)
4191
+ return null;
4192
+ return (`([&]() -> ${cppTypeOf(target)} { const auto& gea_fresh = ${text}; ` +
4193
+ `auto gea_rebuilt = gea::makeRef<${cppTypeOf(pair.target, 'owned')}>(); ` +
4194
+ `gea_fresh->copyInto(*gea_rebuilt, [&](const ${cppTypeOf(pair.source.value)}& gea_entry) -> ${cppTypeOf(pair.target.value)} { return ${entry}; }); ` +
4195
+ `return ${target.kind === 'optional' ? `${cppTypeOf(target)}(gea_rebuilt)` : 'gea_rebuilt'}; }())`);
4196
+ };
4159
4197
  export const conversionChain = [
4160
4198
  { id: 'native-sum-widening', apply: (source, target, text) => claimed(widenedNativeSumText(source, target, text)) },
4161
4199
  // A choice among generic functions widening into a superset: the index is
@@ -4934,7 +4972,7 @@ export const recipeText = (ctx, node, text) => {
4934
4972
  /**
4935
4973
  * A union read out of a box depends on its plan alone, so a unit defines it
4936
4974
  * once and every site calls it by name (`unitFunctionName`). Spelled inline it
4937
- * was re-emitted at every read: one `Headers`-or-record union in hono tests
4975
+ * was re-emitted at every read: one `Headers`-or-record union in an HTTP framework tests
4938
4976
  * some seventy required keys, ~46 KB of machine code per copy.
4939
4977
  */
4940
4978
  const dynamicWrapperText = (ctx, plan, node, text) => {
@@ -5223,6 +5261,8 @@ const renderedRecipeText = (ctx, node, text) => {
5223
5261
  return assertedUnionText(node.source, node.target, text, false);
5224
5262
  if (node.capability.kind === 'static' && node.capability.materializer.id === ASSERTED_UNION_COPY_MATERIALIZER)
5225
5263
  return assertedUnionText(node.source, node.target, text, true);
5264
+ if (node.capability.kind === 'static' && node.capability.materializer.id === FRAME_ARGUMENT_UNION_MATERIALIZER)
5265
+ return assertedUnionText(node.source, node.target, text, false, true);
5226
5266
  // The census's asserted record-to-class view (`nodes.ts`'s `assertedViewFor`).
5227
5267
  if (node.capability.kind === 'static' && node.capability.materializer.id === ASSERTED_VIEW_MATERIALIZER)
5228
5268
  return node.capability.materializer.assertedView ? assertedViewText(ctx, node, node.capability.materializer.assertedView, text) : null;
@@ -16,7 +16,9 @@ export declare const nativeFieldViewReadText: (ctx: EmitContext, operation: GetO
16
16
  readonly text: string;
17
17
  readonly accessor?: true;
18
18
  } | null) => string | null;
19
- export declare const nativeFieldViewWriteText: (ctx: EmitContext, operation: SetOperation) => string | null;
19
+ export declare const nativeFieldViewWriteText: (ctx: EmitContext, operation: SetOperation,
20
+ /** The receiver's ordinary store of `operation`, rendered in `bound`: what an open write's plain indexed allocation runs. */
21
+ ordinaryStore?: (bound: EmitContext, receiver?: IrOperand) => readonly string[]) => string | null;
20
22
  /**
21
23
  * One fixed-key read of an entry the caller already holds as `receiver`: a
22
24
  * live view answers through its certified routes, any other allocation with
@@ -7,10 +7,20 @@ import { cppTypeOf, cppStringLiteral, cppRecordFieldKeyIsSymbol, fieldPropertyKe
7
7
  import { propertyKeyText } from './emit-dynamic-properties.js';
8
8
  import { nativeDataPropertyText } from './emit-buffers.js';
9
9
  import { nativeDataPropertyOf } from '../../representation/native-data-properties.js';
10
+ import { staticOwnFieldsOf } from '../../representation/record-fields.js';
10
11
  const tokenOf = (type) => `gea::detail::payloadTypeTagFor<${type}>()`;
11
12
  const routeTokenOf = (value) => `gea_type == ${tokenOf(cppTypeOf(value))} && gea_policy == ${tokenOf(nativeFieldPolicyType(value))}`;
12
13
  /** A static symbol member reaches the IR as its `sym(decl|...)` key text, never as a string property. */
13
14
  const viewKeyText = (key) => cppRecordFieldKeyIsSymbol(key) ? fieldPropertyKeyText(key) : `gea::PropertyKey::string(${cppStringLiteral(key)})`;
15
+ /**
16
+ * The key a `readLiveField`/`writeLiveField` call names: a string key travels
17
+ * as a literal (`gea::record::LiteralFieldKey`) the runtime turns into a
18
+ * `PropertyKey` only for a receiver that is a live view, so the plain
19
+ * allocation every hot read and write takes builds no key at all.
20
+ */
21
+ const liveKeyText = (key) => cppRecordFieldKeyIsSymbol(key)
22
+ ? fieldPropertyKeyText(key)
23
+ : `gea::record::LiteralFieldKey{${cppStringLiteral(key)}, ${new TextEncoder().encode(key).length}}`;
14
24
  const renderedLeaf = (ctx, id, text) => {
15
25
  const node = ctx.conversions.nodeById(id);
16
26
  const rendered = node === null ? null : recipeText(ctx, node, text);
@@ -89,7 +99,16 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
89
99
  // `.is<N>()` on it does not parse. Read through the source's own
90
100
  // carrier type and the recipe sees a concrete value.
91
101
  const concrete = actual ? `static_cast<const ${cppTypeOf(actual.source)}&>(${actual.text})` : '';
92
- const getterAnswer = ordinary && actual?.accessor === true ? `return ${renderedLeaf(ctx, ordinary.conversion, concrete)};` : null;
102
+ // A declared, always-present field (not optional, no absent-descriptor
103
+ // route) is the plain allocation's own C++ member: read it the way an
104
+ // ordinary receipt-free read does, rather than through the string-keyed
105
+ // own-field protocol. A program-wide view target (any record a dynamic
106
+ // writer may store a view into) otherwise sends every plain read of the
107
+ // type through `gea_readOwnFieldNative`.
108
+ const memberAnswer = ordinary && actual && actual.accessor !== true && actual.source.kind !== 'optional' && receipt.originalAbsent !== true
109
+ ? `return ${renderedLeaf(ctx, ordinary.conversion, concrete)};`
110
+ : null;
111
+ const getterAnswer = ordinary && actual?.accessor === true ? `return ${renderedLeaf(ctx, ordinary.conversion, concrete)};` : memberAnswer;
93
112
  const plain = ordinary && actual && actual.source.kind === 'optional'
94
113
  ? `return ${renderedLeaf(ctx, ordinary.conversion, concrete)};`
95
114
  : 'gea::host::throwRuntimeError("TypeError", "a native view receiver has no admitted plain allocation");';
@@ -111,7 +130,7 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
111
130
  'bool gea_plain_present = false; ' +
112
131
  `if (!gea_field_receiver->gea_ownFieldPresent(${property}, gea_plain_present) || gea_plain_present) ` +
113
132
  'gea::host::throwRuntimeError("TypeError", "a native allocation read has no certified carrier route"); ';
114
- return (`return gea::record::readLiveField<${result}>(gea_field_receiver, ${property}, ` +
133
+ return (`return gea::record::readLiveField<${result}>(gea_field_receiver, ${liveKeyText(key)}, ` +
115
134
  `${adapter}, ${accepted}, [&]() -> ${result} { ${getterAnswer ?? `${native}${plain}`} });`);
116
135
  }, dynamicRead(key), nativeDataRead(key));
117
136
  // The receiver is the statement-lambda's ARGUMENT, not a local bound inside
@@ -162,7 +181,9 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
162
181
  export const nativeFieldViewReadText = (ctx, operation, ordinaryReadOf) => operation.nativeFieldViewRead === undefined
163
182
  ? null
164
183
  : nativeFieldViewReadForText(ctx, operation.receiver, operation.result.representation, operation.nativeFieldViewRead, ordinaryReadOf, operation.key);
165
- export const nativeFieldViewWriteText = (ctx, operation) => {
184
+ export const nativeFieldViewWriteText = (ctx, operation,
185
+ /** The receiver's ordinary store of `operation`, rendered in `bound`: what an open write's plain indexed allocation runs. */
186
+ ordinaryStore) => {
166
187
  const receipt = operation.nativeFieldViewWrite;
167
188
  if (!receipt)
168
189
  return null;
@@ -174,14 +195,49 @@ export const nativeFieldViewWriteText = (ctx, operation) => {
174
195
  return [`if (${routeTokenOf(target)}) { static_cast<std::optional<${result}>*>(gea_out)->emplace(${converted}); return true; }`];
175
196
  });
176
197
  const adapter = '[&](const void* gea_type, const void* gea_policy, void* gea_out) -> bool { ' + `${arms.join(' ')} return false; }`;
177
- const forKey = (key) => withFieldReceiver(operation.receiver.representation, 'gea_field_input', () => {
198
+ // The carrier and materializer an extension store keeps (`receipt.open`).
199
+ const openMaterializer = (open) => `+[](const ${cppTypeOf(open.carrier)}& gea_data) -> gea::Value { return ${renderedLeaf(ctx, open.materializer, 'gea_data')}; }`;
200
+ // A declared, always-present member of the receiver's own record layout:
201
+ // the write counterpart of the read side's member answer. The plain
202
+ // allocation takes exactly the store a receiver that is no view target
203
+ // renders (`ordinaryStore`), instead of the string-keyed own-field protocol
204
+ // and its per-write policy dispatch. A program-wide view target -- a record
205
+ // a dynamic writer may store a view into, such as three's uniform
206
+ // `{ value }` -- otherwise sends every plain store of the type, every
207
+ // frame, through `gea_writeOwnFieldNative`.
208
+ const memberStore = (carrier, key) => {
209
+ // The receiver as `withFieldReceiver` binds it: presence and borrowing
210
+ // peeled, never a union arm (an arm's member store is that arm's own).
211
+ let held = operation.receiver.representation;
212
+ while (held.kind === 'optional' || held.kind === 'borrowed-ref')
213
+ held = held.kind === 'optional' ? held.payload : held.referent;
214
+ if (ordinaryStore === undefined || representationKey(carrier) !== representationKey(held))
215
+ return false;
216
+ if (carrier.kind !== 'record' && carrier.kind !== 'native-record-ref')
217
+ return false;
218
+ if (carrier.kind === 'record' && carrier.accessors.some((accessor) => accessor.key === key))
219
+ return false;
220
+ return (staticOwnFieldsOf(ctx.deriver, carrier) ?? []).some((field) => field.key === key && field.required);
221
+ };
222
+ const forKey = (key) => withFieldReceiver(operation.receiver.representation, 'gea_field_input', (carrier) => {
223
+ // A forwarded key no source behind a view declares is created on that
224
+ // source: the write names its carrier, as an open key's does. A plain
225
+ // allocation keeps it in its own slot.
226
+ if (receipt.open !== undefined && receipt.forwardedKeys?.includes(key))
227
+ return (`return gea::record::writeLiveOpenField<${nativeFieldPolicyType(receipt.open.carrier)}>(gea_field_receiver, ${viewKeyText(key)}, ` +
228
+ `gea_field_value, ${adapter}, ${openMaterializer(receipt.open)}, [&](const gea::NativeFieldWrite& gea_open_write) -> bool { ` +
229
+ `return gea_field_receiver->gea_writeOwnFieldNative(${viewKeyText(key)}, gea_open_write, gea::nativeIsExtensible(gea_field_receiver)); });`);
230
+ if (receipt.keyDomain === undefined && memberStore(carrier, key))
231
+ return (`return gea::record::writeLiveField(gea_field_receiver, ${liveKeyText(key)}, ` +
232
+ `gea_field_value, ${adapter}, [&]() -> bool { ` +
233
+ `${ordinaryStore(bound, { value: operation.receiver.value, representation: carrier }).join(' ')} return true; });`);
178
234
  const plain = `auto gea_plain_adapter = ${adapter}; auto gea_plain_write = gea::NativeFieldWrite::exact(gea_field_value); ` +
179
235
  'gea_plain_write.exactOnly = false; gea_plain_write.slot = &gea_plain_adapter; ' +
180
236
  'gea_plain_write.readFn = +[](const void* slot, const void* type, const void* policy, void* answer) -> bool { ' +
181
237
  'return (*static_cast<const decltype(gea_plain_adapter)*>(slot))(type, policy, answer); }; ' +
182
238
  `return gea_field_receiver->gea_writeOwnFieldNative(${viewKeyText(key)}, ` +
183
239
  'gea_plain_write, gea::nativeIsExtensible(gea_field_receiver));';
184
- return (`return gea::record::writeLiveField(gea_field_receiver, ${viewKeyText(key)}, ` +
240
+ return (`return gea::record::writeLiveField(gea_field_receiver, ${liveKeyText(key)}, ` +
185
241
  `gea_field_value, ${adapter}, [&]() -> bool { ${plain} });`);
186
242
  });
187
243
  // A fresh record's out-of-layout-order store states the order its literal
@@ -198,10 +254,30 @@ export const nativeFieldViewWriteText = (ctx, operation) => {
198
254
  ? ''
199
255
  : `const auto& gea_field_key_input = ${operandText(ctx, operation.key)}; ` +
200
256
  `const gea::PropertyKey gea_field_key = ${propertyKeyText(bound, operation.key, 'a computed native field-view write')}; `;
257
+ // Any other runtime key of an open write: a live view takes it through its
258
+ // own routes to the original allocation (`nativeLiveViewSourceWrite` or a
259
+ // Document entry), carrying the receipt's value carrier and materializer as
260
+ // the typed policy an expando store needs. A plain allocation stores it in
261
+ // its own expando, or -- an indexed record -- through exactly the ordinary
262
+ // sidecar store a receiver that is no view target renders.
263
+ const open = receipt.open;
264
+ const otherKey = receipt.openKeys !== true || open === undefined
265
+ ? ' gea::host::throwRuntimeError("TypeError", "No admitted native field-view key");'
266
+ : ` ${withFieldReceiver(operation.receiver.representation, 'gea_field_input', (carrier) => {
267
+ const materializer = openMaterializer(open);
268
+ let plain = '[&](const gea::NativeFieldWrite& gea_open_write) -> bool { return gea::nativeObjectDataExtend(gea_field_receiver, gea_field_key, gea_open_write); }';
269
+ if (carrier.kind === 'record-with-index') {
270
+ if (ordinaryStore === undefined)
271
+ throw new Error('an open indexed field-view write has no ordinary sidecar store');
272
+ const plainContext = { ...bound, valueNames: new Map(bound.valueNames).set(operation.receiver.value, 'gea_field_input') };
273
+ plain = `[&](const gea::NativeFieldWrite&) -> bool { ${ordinaryStore(plainContext).join(' ')} return true; }`;
274
+ }
275
+ return (`return gea::record::writeLiveOpenField<${nativeFieldPolicyType(open.carrier)}>(gea_field_receiver, gea_field_key, ` +
276
+ `gea_field_value, ${adapter}, ${materializer}, ${plain});`);
277
+ })}`;
201
278
  const selected = receipt.keyDomain === undefined
202
279
  ? forKey(receipt.key)
203
- : receipt.keyDomain.map((key) => `if (gea_field_key == ${viewKeyText(key)}) { ${forKey(key)} }`).join(' ') +
204
- ' gea::host::throwRuntimeError("TypeError", "No admitted native field-view key");';
280
+ : receipt.keyDomain.map((key) => `if (gea_field_key == ${viewKeyText(key)}) { ${forKey(key)} }`).join(' ') + otherKey;
205
281
  return (`([&](const auto& gea_field_input) -> bool { ` +
206
282
  computedKey +
207
283
  `const ${cppTypeOf(operation.value.representation)} gea_field_value = ${operandText(ctx, operation.value)}; ` +
@@ -217,7 +293,7 @@ export const nativeFieldViewWriteText = (ctx, operation) => {
217
293
  export const nativeHeldFieldViewReadText = (ctx, receipt, target, receiver, plain) => {
218
294
  const result = cppTypeOf(target);
219
295
  const { adapter, accepted } = fieldViewRoutesText(ctx, receipt, result);
220
- return `gea::record::readLiveField<${result}>(${receiver}, ${viewKeyText(receipt.key)}, ${adapter}, ${accepted}, [&]() -> ${result} { return ${plain}; })`;
296
+ return `gea::record::readLiveField<${result}>(${receiver}, ${liveKeyText(receipt.key)}, ${adapter}, ${accepted}, [&]() -> ${result} { return ${plain}; })`;
221
297
  };
222
298
  /**
223
299
  * The adapter a live view's certified routes answer through, and the policy
@@ -46,6 +46,7 @@ view?: boolean) => {
46
46
  readonly member: string;
47
47
  readonly subscript: string;
48
48
  readonly key: string;
49
+ readonly table: string;
49
50
  } | null;
50
51
  /**
51
52
  * The emitted body behind an accessor-backed *record* member, or `null` when
@@ -18,7 +18,7 @@ import { tracksKeyOrder } from './key-order-tracking.js';
18
18
  import { recordLayoutOfShapeId } from '../../projection/fields.js';
19
19
  import { nativeErrorMemberText } from './prototype/emit-prototype-error.js';
20
20
  import { structuralRecordViewText } from './emit-record-view.js';
21
- import { classMemberText, classConstructorStaticFieldStorage, constructorStateText, constructorViewFieldFor, classConstructorStaticMemberText, constructorIdentityMemberText } from './class-properties/emit-class-properties.js';
21
+ import { classMemberText, classConstructorStaticFieldStorage, constructorStaticStateText, constructorViewFieldFor, classConstructorStaticMemberText, constructorIdentityMemberText } from './class-properties/emit-class-properties.js';
22
22
  import { alignedValueText, movedValueText } from './emit-narrowing.js';
23
23
  import { operationConversionText } from './emit-certified-conversion.js';
24
24
  import { namespaceMemberStore } from './emit-namespaces.js';
@@ -121,7 +121,8 @@ view = false) => {
121
121
  return {
122
122
  member: `${receiverText}${memberAccessOperator(representation.ownership)}`,
123
123
  subscript: `${indexed}[${keyText}]`,
124
- key: keyText
124
+ key: keyText,
125
+ table: indexed
125
126
  };
126
127
  };
127
128
  /**
@@ -157,12 +158,23 @@ const dictionaryReadText = (ctx, operation) => {
157
158
  return null;
158
159
  const source = operation.receiver.representation.value;
159
160
  const read = operation.result.representation;
160
- const raw = `${table.member}read(${table.key})`;
161
+ // A constant string key reads with its own site's position hint
162
+ // (`Dictionary::hintedPosition`): the static lives in a lambda unique to the
163
+ // site, so each read site remembers where it last found its key.
164
+ const hinted = operation.receiver.representation.key === 'string' && ctx.staticKeyTexts.get(operation.key.value) !== undefined;
165
+ const withHint = (text) => `([&]() -> decltype(auto) { static constinit std::atomic<std::uint32_t> gea_key_hint{0}; return ${text}; }())`;
166
+ const raw = hinted
167
+ ? withHint(`gea::dictionary::readHinted(${table.table}, ${table.key}, gea_key_hint)`)
168
+ : `${table.member}read(${table.key})`;
161
169
  if (representationKey(source) === representationKey(read))
162
170
  return raw;
163
171
  if (read.kind === 'optional' && representationKey(source) === representationKey(read.payload)) {
172
+ // One lookup where the table can answer presence and value together
173
+ // (`gea::dictionary::readIfPresent`); otherwise its own `has` and `read`.
164
174
  const carrier = cppTypeOf(read);
165
- return `(${table.member}has(${table.key}) ? ${carrier}(${raw}) : ${carrier}())`;
175
+ return hinted
176
+ ? withHint(`gea::dictionary::readIfPresentHinted<${carrier}>(${table.table}, ${table.key}, gea_key_hint)`)
177
+ : `gea::dictionary::readIfPresent<${carrier}>(${table.table}, ${table.key})`;
166
178
  }
167
179
  const converted = alignedValueText(ctx, 'emit-properties.ts:213', source, read, raw);
168
180
  if (converted !== null)
@@ -1070,7 +1082,7 @@ const constructorViewStaticStoreText = (ctx, receiver, key, value) => {
1070
1082
  const viewed = constructorViewFieldFor(ctx, key);
1071
1083
  if (viewed === null)
1072
1084
  return null;
1073
- const state = constructorStateText(representation, operandText(ctx, receiver));
1085
+ const state = constructorStaticStateText(ctx, representation, () => operandText(ctx, receiver));
1074
1086
  const converted = alignedValueText(ctx, 'emit-properties.ts:constructor-view', value.representation, viewed.field.value, operandText(ctx, value));
1075
1087
  if (state === null || converted === null) {
1076
1088
  throw createCppEmitBlockedError(`conversion:${representationKey(value.representation)}->${representationKey(viewed.field.value)}`, `static "${key}" is a constructor's own property stored as "${representationKey(viewed.field.value)}" and this write carries ` +
@@ -1389,7 +1401,11 @@ export const emitFieldStore = (ctx, lines, operation, label) => {
1389
1401
  pendingPacks
1390
1402
  };
1391
1403
  }
1392
- const rendered = nativeFieldViewWriteText(viewContext, operation);
1404
+ const rendered = nativeFieldViewWriteText(viewContext, operation, (bound, receiver) => {
1405
+ const ordinary = [];
1406
+ emitFieldStoreLines(bound, ordinary, { ...operation, ...(receiver === undefined ? {} : { receiver }), result: null }, label);
1407
+ return ordinary;
1408
+ });
1393
1409
  if (rendered === null)
1394
1410
  throw new Error('a published field-view write lost its receipt');
1395
1411
  lines.push(operation.strict
@@ -1567,7 +1583,10 @@ const emitFieldStoreLines = (ctx, lines, operation, label) => {
1567
1583
  throw createCppEmitBlockedError(`conversion:${representationKey(operation.value.representation)}->${representationKey(staticField.representation)}`, `static field "${staticFieldKey}" is stored as "${representationKey(staticField.representation)}" and this write carries ` +
1568
1584
  `"${representationKey(operation.value.representation)}"; no conversion is installed between them`);
1569
1585
  }
1570
- lines.push(`${staticField.name} = ${movedValueText(ctx, operation.value, staticField.representation, converted)};`);
1586
+ const state = constructorStaticStateText(ctx, operation.receiver.representation, () => operandText(ctx, operation.receiver));
1587
+ if (state === null)
1588
+ throw createCppEmitBlockedError('property-access:constructor-static-state', 'has no evaluated constructor identity');
1589
+ lines.push(`{ auto gea_static = gea::constructorStaticView<${staticField.viewStruct}>(${state}); gea_static->value = ${movedValueText(ctx, operation.value, staticField.representation, converted)}; gea_static->present = true; }`);
1571
1590
  // A store's result is the receiver threaded onward, exactly as the record
1572
1591
  // branch below explains -- here that receiver is the class value itself.
1573
1592
  if (operation.result)
@@ -151,7 +151,8 @@ export const certifiedProtocolIteratorText = (ctx, certified, text) => {
151
151
  steps.push(`gea_protocol_steps->raise = [${holder}](std::exception_ptr gea_protocol_thrown, ${element}& ${out}, ${storage}& ${completion}) -> bool { ` +
152
152
  (present === null ? '' : `if (!(${present})) std::rethrow_exception(gea_protocol_thrown); `) +
153
153
  `${thrownType} gea_protocol_error; ` +
154
- `try { std::rethrow_exception(gea_protocol_thrown); } catch (const ${thrownType}& gea_protocol_caught) { gea_protocol_error = gea_protocol_caught; } ` +
154
+ `GEA_EH_TRY_VALUE(gea_protocol_slot) { std::rethrow_exception(gea_protocol_thrown); } ` +
155
+ `GEA_EH_CATCH_VALUE(gea_protocol_slot, gea_protocol_caught) { gea_protocol_error = gea_protocol_caught; } GEA_EH_END ` +
155
156
  `auto ${result} = ${raiseCall}; (void)${completion}; return ${raiseStep}; };`);
156
157
  }
157
158
  return wrap(`([&]() -> ${cursor} { ${holderType} ${holder} = ${text}; ` +
@@ -216,7 +217,9 @@ const asyncProtocolText = (ctx, plan, text) => {
216
217
  steps.push(`gea_protocol_steps->raise = [&${holder}](std::exception_ptr gea_protocol_thrown) -> gea::Promise<${step}> { ` +
217
218
  (present === null ? '' : `if (!(${present})) ${rejected} `) +
218
219
  `${thrownType} gea_protocol_error; ` +
219
- `try { std::rethrow_exception(gea_protocol_thrown); } catch (const ${thrownType}& gea_protocol_caught) { gea_protocol_error = gea_protocol_caught; } catch (...) ${rejected} ` +
220
+ `GEA_EH_TRY_VALUE_OR_ANY(gea_protocol_slot, gea_protocol_other) { std::rethrow_exception(gea_protocol_thrown); } ` +
221
+ `GEA_EH_CATCH_VALUE_OR_ANY(gea_protocol_slot, gea_protocol_other, gea_protocol_caught) { gea_protocol_error = gea_protocol_caught; } ` +
222
+ `GEA_EH_CATCH_REMAINDER(gea_protocol_slot, gea_protocol_other) ${rejected} GEA_EH_END ` +
220
223
  `return ${mapped(plan.raise, raiseCall, raiseStep)}; };`);
221
224
  }
222
225
  return (`([&]() -> ${cursor} { auto gea_protocol_owner = std::make_shared<${holderType}>(${text}); ${holderType}& ${holder} = *gea_protocol_owner; ` +