@geastack/compiler 1.0.33 → 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 (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 +16 -7
  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
@@ -3,6 +3,8 @@ import { abiOfCallee } from '../projection/callee.js';
3
3
  import { representationKey } from '../representation/model.js';
4
4
  import { allOperationsOf } from './model.js';
5
5
  import { nativeFieldViewDynamicValueIsNative, nativeFieldViewPlansOf } from '../conversion/native-field-view.js';
6
+ import { nativeFieldViewForwardedWriteKey } from './native-field-view-domains.js';
7
+ import { nativeCallableDataCarrierHasStorageIdentity } from '../representation/native-callable-data-storage.js';
6
8
  /** Reachability follows exact published receipts, including recipes created by an earlier publication pass. */
7
9
  export const nativeFieldViewCitationsOf = (operation) => [
8
10
  ...(operation.kind === 'call' && operation.nativeArrayDescriptorSnapshot ? [operation.nativeArrayDescriptorSnapshot.conversion] : []),
@@ -99,8 +101,39 @@ export const nativeFieldViewOpenDocumentRead = (operation, constantKey, targets,
99
101
  * the path itself as a value. The census is the one authority on which
100
102
  * values are paths; publication and certification both ask it here.
101
103
  */
102
- export const nativeFieldViewOperationNeedsReceipt = (operation, targets, hostNamespaces) => !(hostNamespaces?.reads.has(operation.receiver.value) || hostNamespaces?.values.has(operation.receiver.value)) &&
103
- nativeFieldViewCarrierNeedsReceipt(operation.receiver.representation, targets);
104
+ export const nativeFieldViewOperationNeedsReceipt = (operation, targets, hostNamespaces,
105
+ /** The read's constant key, when it has one. */
106
+ key, layoutOf) => !(hostNamespaces?.reads.has(operation.receiver.value) || hostNamespaces?.values.has(operation.receiver.value)) &&
107
+ (operation.kind === 'get' && key !== null && key !== undefined && operation.receiver.representation.kind === 'tagged-union'
108
+ ? unionReadNeedsReceipt(operation.receiver.representation, key, targets, layoutOf)
109
+ : nativeFieldViewCarrierNeedsReceipt(operation.receiver.representation, targets));
110
+ /**
111
+ * A constant-key read off a union is the per-arm dispatch of
112
+ * `emit-union-properties.ts`, and only an arm read through its own C++ member
113
+ * can meet a live view's placeholder slot. A record arm whose layout declares
114
+ * no such key is read through `gea::nativeDynamicGet`, whose native [[Get]]
115
+ * asks a live view's original allocation -- its Document entry or its
116
+ * source's expando -- before anything else, so that arm needs no receipt.
117
+ * node-compat's `Request` reads `init.body.type` after a call that may write
118
+ * `init.body`, so the read is off the whole `BodyInit` union, and its
119
+ * Document-viewed `ArrayBufferView` arm declares no `type`.
120
+ */
121
+ const unionReadNeedsReceipt = (value, key, targets, layoutOf) => {
122
+ if (value.kind === 'optional')
123
+ return unionReadNeedsReceipt(value.payload, key, targets, layoutOf);
124
+ if (value.kind === 'tagged-union')
125
+ return value.arms.some((arm) => unionReadNeedsReceipt(arm.value, key, targets, layoutOf));
126
+ if (!nativeFieldViewCarrierNeedsReceipt(value, targets))
127
+ return false;
128
+ const layout = value.kind === 'record'
129
+ ? value
130
+ : value.kind === 'native-record-ref' && value.native === null
131
+ ? layoutOf?.layoutOf(value.shapeId)
132
+ : null;
133
+ return (layout?.kind !== 'record' ||
134
+ layout.fields.some((field) => field.key === key) ||
135
+ layout.accessors.some((accessor) => accessor.key === key));
136
+ };
104
137
  export const nativeFieldViewCarrierNeedsReceipt = (value, targets) => {
105
138
  if (value.kind === 'optional' || value.kind === 'borrowed-ref')
106
139
  return nativeFieldViewCarrierNeedsReceipt(value.kind === 'optional' ? value.payload : value.referent, targets);
@@ -287,6 +320,28 @@ export const nativeFieldViewWriteOf = (operation, key, flow, conversions) => {
287
320
  descriptors?.some((entry) => entry.originalAbsent === true || entry.dynamicGet === true || entry.nativeData === true))
288
321
  return null;
289
322
  const targets = new Map();
323
+ // A forwarded key no source declares has no setter-less descriptor to
324
+ // refuse with: its store creates the key on that source.
325
+ const forwarded = !data && !accessor && descriptors?.some((entry) => entry.sourceAbsent === true) === true;
326
+ let open;
327
+ if (forwarded) {
328
+ if (flow.nativeFieldViewForwardedWrites?.has(nativeFieldViewForwardedWriteKey(operation.receiver.value, key)) !== true)
329
+ return null;
330
+ const extension = nativeFieldViewExtensionOf(operation, conversions);
331
+ if (extension === null)
332
+ return null;
333
+ open = extension.open;
334
+ for (const target of extension.targets)
335
+ targets.set(representationKey(target.target), target);
336
+ // A plain allocation of the receiver's own record keeps the key in its slot.
337
+ const own = ownRecordFieldOf(operation.receiver.representation, key);
338
+ if (own !== null) {
339
+ const node = conversions.nodeFor(operation.value.representation, own);
340
+ if (!recipeIsMaterializableWithoutPriorSourceGuard(node, conversions.nodeById))
341
+ return null;
342
+ targets.set(representationKey(own), { target: own, conversion: node.id });
343
+ }
344
+ }
290
345
  for (const target of data ?? accessor?.map((entry) => entry.write) ?? descriptors.map((entry) => entry.write)) {
291
346
  if (target === null) {
292
347
  targets.set('no-setter', { target, conversion: null });
@@ -300,6 +355,9 @@ export const nativeFieldViewWriteOf = (operation, key, flow, conversions) => {
300
355
  const node = conversions.nodeFor(operation.value.representation, target);
301
356
  if (!recipeIsMaterializableWithoutPriorSourceGuard(node, conversions.nodeById))
302
357
  return null;
358
+ const previous = targets.get(representationKey(target));
359
+ if (previous !== undefined && previous.conversion !== node.id)
360
+ return null;
303
361
  targets.set(representationKey(target), { target, conversion: node.id });
304
362
  }
305
363
  return {
@@ -308,9 +366,17 @@ export const nativeFieldViewWriteOf = (operation, key, flow, conversions) => {
308
366
  key,
309
367
  value: operation.value.value,
310
368
  source: representationKey(operation.value.representation),
311
- targets: [...targets.values()]
369
+ targets: [...targets.values()],
370
+ ...(open === undefined ? {} : { open, forwardedKeys: [key] })
312
371
  };
313
372
  };
373
+ const ownRecordFieldOf = (receiver, key) => {
374
+ if (receiver.kind === 'optional' || receiver.kind === 'borrowed-ref')
375
+ return ownRecordFieldOf(receiver.kind === 'optional' ? receiver.payload : receiver.referent, key);
376
+ return receiver.kind === 'record' || receiver.kind === 'record-with-index'
377
+ ? (receiver.fields.find((field) => field.key === key)?.value ?? null)
378
+ : null;
379
+ };
314
380
  export const nativeFieldViewWriteSelectionOf = (operation, keys, flow, conversions) => {
315
381
  const keyDomain = [...new Set(keys)].sort();
316
382
  const writes = keyDomain.map((key) => nativeFieldViewWriteOf(operation, key, flow, conversions));
@@ -320,7 +386,89 @@ export const nativeFieldViewWriteSelectionOf = (operation, keys, flow, conversio
320
386
  for (const write of writes)
321
387
  for (const target of write.targets)
322
388
  targets.set(target.target === null ? 'no-setter' : representationKey(target.target), target);
323
- return { ...writes[0], keyDomain, targets: [...targets.values()] };
389
+ const forwardedKeys = writes.flatMap((write) => write.forwardedKeys ?? []);
390
+ const open = writes.find((write) => write.open !== undefined)?.open;
391
+ const { open: _open, forwardedKeys: _forwarded, ...first } = writes[0];
392
+ return {
393
+ ...first,
394
+ keyDomain,
395
+ targets: [...targets.values()],
396
+ ...(open === undefined ? {} : { open, forwardedKeys })
397
+ };
398
+ };
399
+ const dynamicValue = { kind: 'dynamic', reason: 'declared-any-never-narrowed' };
400
+ /**
401
+ * The carrier a store keeps on an allocation's own extension (its expando or
402
+ * a Document entry): the value's own, with its certified Value materializer.
403
+ * A carrier with no storage identity, or none a dynamic observer could
404
+ * materialize, has none.
405
+ */
406
+ const nativeFieldViewExtensionOf = (operation, conversions) => {
407
+ const carrier = operation.value.representation;
408
+ if (carrier.kind !== 'dynamic' && !nativeCallableDataCarrierHasStorageIdentity(carrier))
409
+ return null;
410
+ const materializer = conversions.nodeFor(carrier, dynamicValue);
411
+ if (!recipeIsMaterializableWithoutPriorSourceGuard(materializer, conversions.nodeById))
412
+ return null;
413
+ const stored = conversions.nodeFor(carrier, carrier);
414
+ if (!recipeIsMaterializableWithoutPriorSourceGuard(stored, conversions.nodeById))
415
+ return null;
416
+ return {
417
+ open: { carrier, materializer: materializer.id },
418
+ targets: [
419
+ { target: carrier, conversion: stored.id },
420
+ { target: dynamicValue, conversion: materializer.id }
421
+ ]
422
+ };
423
+ };
424
+ /**
425
+ * `for (const key in parameters) data[key] = parameters[key]` over a live view
426
+ * target (three's `BufferGeometry.toJSON`): the write counterpart of
427
+ * `nativeFieldViewOpenReadOf`. Every named key keeps its exact slot route; a
428
+ * key outside them is created or overwritten where JavaScript would put it
429
+ * -- the original source's own expando behind a record view, an installed
430
+ * Document's entry, or the plain allocation's expando or index sidecar --
431
+ * and only where every allocation the carrier can hold has such a home
432
+ * (`nativeFieldViewOpenWriteValues`). The value keeps its own carrier there,
433
+ * so a carrier with no storage identity or no certified Value materializer
434
+ * (what a dynamic observer of the key would need) is refused.
435
+ */
436
+ export const nativeFieldViewOpenWriteOf = (operation, flow, conversions,
437
+ /** A proven finite key set (`provenKeyTexts`): only its named members keep a slot route. */
438
+ proven) => {
439
+ if (flow.nativeFieldViewOpenWriteValues?.has(operation.receiver.value) !== true)
440
+ return null;
441
+ const named = flow.nativeFieldViewStorageValues?.get(operation.receiver.value);
442
+ if (named === undefined)
443
+ return null;
444
+ const keyDomain = (proven === undefined ? [...named.keys()] : [...new Set(proven)].filter((key) => named.has(key))).sort();
445
+ const fixed = keyDomain.length === 0 ? null : nativeFieldViewWriteSelectionOf(operation, keyDomain, flow, conversions);
446
+ if (keyDomain.length > 0 && fixed === null)
447
+ return null;
448
+ const extension = nativeFieldViewExtensionOf(operation, conversions);
449
+ if (extension === null)
450
+ return null;
451
+ const targets = new Map();
452
+ for (const target of fixed?.targets ?? [])
453
+ targets.set(target.target === null ? 'no-setter' : representationKey(target.target), target);
454
+ for (const target of extension.targets) {
455
+ const previous = targets.get(representationKey(target.target));
456
+ if (previous !== undefined && previous.conversion !== target.conversion)
457
+ return null;
458
+ targets.set(representationKey(target.target), target);
459
+ }
460
+ return {
461
+ receiver: operation.receiver.value,
462
+ carrier: representationKey(operation.receiver.representation),
463
+ key: '',
464
+ keyDomain,
465
+ value: operation.value.value,
466
+ source: representationKey(operation.value.representation),
467
+ targets: [...targets.values()],
468
+ openKeys: true,
469
+ open: extension.open,
470
+ ...(fixed?.forwardedKeys === undefined ? {} : { forwardedKeys: fixed.forwardedKeys })
471
+ };
324
472
  };
325
473
  /** Independent certification recalculates the complete slot set and each canonical leaf. */
326
474
  export const nativeFieldViewReceiptMatches = (expected, actual) => {
@@ -342,6 +490,13 @@ export const nativeFieldViewReceiptMatches = (expected, actual) => {
342
490
  if ('targets' in expected && 'targets' in actual)
343
491
  return (expected.value === actual.value &&
344
492
  expected.source === actual.source &&
493
+ expected.openKeys === actual.openKeys &&
494
+ JSON.stringify(expected.forwardedKeys ?? []) === JSON.stringify(actual.forwardedKeys ?? []) &&
495
+ (expected.open === undefined
496
+ ? actual.open === undefined
497
+ : actual.open !== undefined &&
498
+ expected.open.materializer === actual.open.materializer &&
499
+ representationKey(expected.open.carrier) === representationKey(actual.open.carrier)) &&
345
500
  expected.targets.length === actual.targets.length &&
346
501
  expected.targets.every((entry, index) => {
347
502
  const held = actual.targets[index];
@@ -0,0 +1,17 @@
1
+ import type { IrValueId, SemanticResultId } from '../identity/ids.js';
2
+ import type { NativeIterableProvider } from '../plugins/native-iterable-providers.js';
3
+ import type { RepresentationDeriver } from '../representation/derive.js';
4
+ import { type NativeIterableReceipt } from '../semantics/model/native-iterable.js';
5
+ import type { SemanticOperation } from '../semantics/model/operations.js';
6
+ import type { GetIteratorOperation, IrOperation } from './model.js';
7
+ export interface NativeIterableCertificationInput {
8
+ /** Independently retained source proofs, not reconstructed from IR receipts. */
9
+ readonly nativeIterableAuthorities?: ReadonlyMap<SemanticResultId, NativeIterableReceipt> | undefined;
10
+ readonly nativeIterableProviders?: ReadonlyMap<string, NativeIterableProvider> | undefined;
11
+ readonly deriver: Pick<RepresentationDeriver, 'derive'>;
12
+ readonly definitionOf: (value: IrValueId) => IrOperation | null;
13
+ }
14
+ /** An installed factory does not authorize a different operand or iterator ABI.
15
+ * No authority inventory is installed yet: source admission remains disabled.
16
+ */
17
+ export declare const nativeIterableReceiptMatches: (operation: GetIteratorOperation, semantic: SemanticOperation | null, input: NativeIterableCertificationInput) => boolean;
@@ -0,0 +1,72 @@
1
+ import { representationKey } from '../representation/model.js';
2
+ import { nativeIterableReceiptsEqual } from '../semantics/model/native-iterable.js';
3
+ import { resultOfIrOperation } from './queries.js';
4
+ /** First domain admits typed leaves; compound element protocols need their own
5
+ * recursive provenance receipt. Physical keys intentionally erase native names.
6
+ */
7
+ const elementMatches = (left, right) => {
8
+ if (left.kind === 'native-handle' || right.kind === 'native-handle')
9
+ return (left.kind === 'native-handle' &&
10
+ right.kind === 'native-handle' &&
11
+ left.native !== null &&
12
+ left.native === right.native &&
13
+ representationKey(left) === representationKey(right));
14
+ if (left.kind !== 'scalar' && left.kind !== 'string' && left.kind !== 'undefined' && left.kind !== 'null')
15
+ return false;
16
+ return representationKey(left) === representationKey(right);
17
+ };
18
+ /** An installed factory does not authorize a different operand or iterator ABI.
19
+ * No authority inventory is installed yet: source admission remains disabled.
20
+ */
21
+ export const nativeIterableReceiptMatches = (operation, semantic, input) => {
22
+ const stated = semantic?.family === 'protocol' ? semantic.nativeIterable : undefined;
23
+ const receipt = operation.nativeIterable;
24
+ const authority = input.nativeIterableAuthorities?.get(operation.lineage);
25
+ if (!receipt && !stated)
26
+ return authority === undefined;
27
+ if (!receipt || !stated || !nativeIterableReceiptsEqual(receipt, stated))
28
+ return false;
29
+ if (semantic?.family !== 'protocol' || semantic.protocol !== 'iterator' || semantic.step !== 'get-iterator')
30
+ return false;
31
+ if (operation.protocol !== 'iterator' || operation.method !== null)
32
+ return false;
33
+ if (!authority || !nativeIterableReceiptsEqual(receipt, authority))
34
+ return false;
35
+ const provider = input.nativeIterableProviders?.get(receipt.receiverNative);
36
+ if (!provider || provider.protocol !== receipt.protocol || provider.receiverNative !== receipt.receiverNative)
37
+ return false;
38
+ if (receipt.protocol !== 'host-sync-iterable@1' || receipt.returnMethod !== 'absent')
39
+ return false;
40
+ const target = semantic.operands.find((operand) => operand.role === 'target' && operand.ordinal === 0);
41
+ const result = semantic.results.find((result) => result.role === 'iterator-record');
42
+ if (!target || target.source.kind !== 'result' || target.source.result !== receipt.source || result?.type !== receipt.iterator)
43
+ return false;
44
+ const definition = input.definitionOf(operation.receiver.value);
45
+ if (!definition || definition.lineage !== receipt.source || resultOfIrOperation(definition)?.id !== operation.receiver.value)
46
+ return false;
47
+ const source = input.deriver.derive(target.type);
48
+ const receiver = operation.receiver.representation;
49
+ if (source.kind !== 'native-handle' ||
50
+ source.native !== receipt.receiverNative ||
51
+ receiver.kind !== 'native-handle' ||
52
+ receiver.native !== receipt.receiverNative)
53
+ return false;
54
+ if (representationKey(source) !== representationKey(receiver))
55
+ return false;
56
+ const iterator = input.deriver.derive(receipt.iterator);
57
+ const element = input.deriver.derive(receipt.element);
58
+ if (iterator.kind !== 'iterator' || iterator.source !== 'sequence')
59
+ return false;
60
+ if (element.kind === 'dynamic' || element.kind === 'unresolved')
61
+ return false;
62
+ if (!elementMatches(iterator.element, element))
63
+ return false;
64
+ const actual = operation.result.representation;
65
+ if (actual.kind !== 'iterator' || actual.source !== 'sequence')
66
+ return false;
67
+ if (iterator.resume.kind !== 'undefined' || iterator.completion.kind !== 'undefined')
68
+ return false;
69
+ if (actual.resume.kind !== 'undefined' || actual.completion.kind !== 'undefined')
70
+ return false;
71
+ return elementMatches(actual.element, element);
72
+ };
@@ -26,7 +26,7 @@ export const nativeKeyQueryOf = (operation, closedLayoutOf) => {
26
26
  // has no such contract and must retain its ordinary call effects. The
27
27
  // queried object is read through its carrier exactly as an enumeration's
28
28
  // receiver is: an absent arm makes `ToObject` throw a TypeError and runs no
29
- // user code (hono's `Object.keys(this.#routes!)` over an optional table).
29
+ // user code (a router's `Object.keys(this.#routes!)` over an optional table).
30
30
  if (queried === undefined || !closedReceiver(queried))
31
31
  return false;
32
32
  // `Object.hasOwn(o, key)` is the one member of this family that takes a
@@ -66,7 +66,7 @@ export const operationConversionInputsOf = (operation, keyText, deriver, classes
66
66
  role === 'field-read')
67
67
  return;
68
68
  if (operation.kind === 'set' &&
69
- (operation.nativeFieldViewWrite !== undefined ||
69
+ ((operation.nativeFieldViewWrite !== undefined && operation.nativeFieldViewWrite.openKeys !== true) ||
70
70
  operation.nativeObjectDataSlot !== undefined ||
71
71
  operation.nativeDocumentEntry !== undefined) &&
72
72
  role === 'field-write')
@@ -169,7 +169,7 @@ export const operationConversionInputsOf = (operation, keyText, deriver, classes
169
169
  add('index-read', { kind: 'undefined' }, result);
170
170
  // A `null`-absent result is not the hole's carrier, so the element is
171
171
  // aligned into the whole result (`reconciledElementText`), not into its
172
- // payload: hono's `...(args as Parameters<NewResponse>)` reads a rest
172
+ // payload: an HTTP framework's `...(args as Parameters<NewResponse>)` reads a rest
173
173
  // array of `any` into `Data | null`.
174
174
  if (result.kind === 'optional' && result.absence !== 'undefined')
175
175
  add('index-read', receiver.element, result);
@@ -204,8 +204,20 @@ export const operationConversionInputsOf = (operation, keyText, deriver, classes
204
204
  : canonicalIndexLiteral(keyText) !== null);
205
205
  if (declared)
206
206
  add('field-write', operation.value.representation, declared.value);
207
+ // A computed key stores into each declared field it can name. Two facts
208
+ // name them: the flow's proven key set, and the sealed closed-record
209
+ // recipe, whose every key the emitter renders as its own constant-key
210
+ // store (`emitTypedComputedWrite`). The recipe is bounded by the key's
211
+ // literal TYPE, the proof by its closed callers, so the recipe can name
212
+ // a key the proof excludes -- every key, when nothing calls the store
213
+ // (`update( object, key, value )` typed `keyof Bag` / `Bag[keyof Bag]`
214
+ // and never invoked). Each such arm still converts the value into its
215
+ // field, so its pair is published here like any proven key's.
207
216
  if (keyText === null)
208
- for (const key of (operation.kind === 'set' ? operation.provenKeyTexts : undefined) ?? []) {
217
+ for (const key of new Set([
218
+ ...((operation.kind === 'set' ? operation.provenKeyTexts : undefined) ?? []),
219
+ ...(operation.typedComputedWrite?.keys ?? [])
220
+ ])) {
209
221
  const field = declaredRecordFieldOf(deriver, receiver, key, classes);
210
222
  if (field)
211
223
  add('field-write', operation.value.representation, field.value);
@@ -103,8 +103,8 @@ export const programConversionInputsOf = (input) => {
103
103
  : null;
104
104
  for (const field of fields ?? []) {
105
105
  // A `#private` element is not a property: no dynamic write can name
106
- // it, and the reflected protocol leaves it out (`records.ts`). Hono's
107
- // Context keeps `#matchResult: Result<[H, RouterRoute]>`, whose
106
+ // it, and the reflected protocol leaves it out (`records.ts`). An HTTP
107
+ // framework's Context keeps `#matchResult: Result<[H, RouterRoute]>`, whose
108
108
  // handler arm no dynamic value can be read into -- demanding that
109
109
  // reader refused a class only full reflection had touched.
110
110
  if (isPrivateNameKey(field.key))
@@ -1,6 +1,6 @@
1
1
  import { nativeCallableFlowOf } from './callable-class-flow.js';
2
2
  import { allOperationsOf } from './model.js';
3
- import { nativeFieldViewLivePlansOf, nativeFieldViewTargetSetOf, nativeFieldViewCarrierNeedsReceipt, nativeFieldViewOperationNeedsReceipt, nativeFieldViewOpenDocumentRead, nativeFieldViewDocumentTargetSetOf, nativeFieldViewReadOf, nativeFieldViewWriteOf, nativeFieldViewReadSelectionOf, nativeFieldViewOpenReadOf, nativeFieldViewWriteSelectionOf } from './native-field-view-facts.js';
3
+ import { nativeFieldViewLivePlansOf, nativeFieldViewTargetSetOf, nativeFieldViewCarrierNeedsReceipt, nativeFieldViewOperationNeedsReceipt, nativeFieldViewOpenDocumentRead, nativeFieldViewDocumentTargetSetOf, nativeFieldViewReadOf, nativeFieldViewWriteOf, nativeFieldViewReadSelectionOf, nativeFieldViewOpenReadOf, nativeFieldViewOpenWriteOf, nativeFieldViewWriteSelectionOf } from './native-field-view-facts.js';
4
4
  import { nativeIteratorFieldReadOf } from './native-iterator-field-views.js';
5
5
  import { nativeEntryFieldReadsOf, nativeEntryFieldReadsRequired } from './native-entry-field-views.js';
6
6
  import { nativeDocumentEntryOf } from './native-document-entries.js';
@@ -61,7 +61,7 @@ export const publishNativeFieldViewFacts = (input) => {
61
61
  return nativeMethodRead === null ? ordinary : { ...ordinary, nativeMethodRead };
62
62
  }
63
63
  if ((operation.kind !== 'get' && operation.kind !== 'set') ||
64
- !nativeFieldViewOperationNeedsReceipt(operation, targets, body.hostNamespaceCensus))
64
+ !nativeFieldViewOperationNeedsReceipt(operation, targets, body.hostNamespaceCensus, keys.get(operation.key.value), input.deriver))
65
65
  return output;
66
66
  const key = keys.get(operation.key.value);
67
67
  if (nativeFieldViewOpenDocumentRead(operation, key, targets, documents)) {
@@ -85,13 +85,18 @@ export const publishNativeFieldViewFacts = (input) => {
85
85
  const { nativeDocumentEntry: previous, ...ordinary } = operation;
86
86
  const write = key !== undefined
87
87
  ? nativeFieldViewWriteOf(operation, key, flow, input.conversions)
88
- : nativeFieldViewWriteSelectionOf(operation, operation.provenKeyTexts ?? [], flow, input.conversions);
88
+ : (nativeFieldViewWriteSelectionOf(operation, operation.provenKeyTexts ?? [], flow, input.conversions) ??
89
+ nativeFieldViewOpenWriteOf(operation, flow, input.conversions, operation.provenKeyTexts));
90
+ // An open write's plain indexed allocation stores through the ordinary
91
+ // sidecar route, which keeps its own field-write recipes.
89
92
  return write === null
90
93
  ? ordinary
91
94
  : {
92
95
  ...ordinary,
93
96
  nativeFieldViewWrite: write,
94
- conversionRecipes: operation.conversionRecipes?.filter((recipe) => recipe.role !== 'field-write') ?? []
97
+ conversionRecipes: write.openKeys === true
98
+ ? (operation.conversionRecipes ?? [])
99
+ : (operation.conversionRecipes?.filter((recipe) => recipe.role !== 'field-write') ?? [])
95
100
  };
96
101
  };
97
102
  return [
@@ -0,0 +1,58 @@
1
+ import type { ConversionCensus } from '../conversion/nodes.js';
2
+ import type { DeclarationId, IrValueId, PhysicalBodyId } from '../identity/ids.js';
3
+ import type { ConvertOperation, IrBody } from './model.js';
4
+ /** A conversion that reads its source's tag and payload and nothing else, and makes no object. */
5
+ export declare const pureNativeConversion: (operation: ConvertOperation, conversions: Pick<ConversionCensus, "nodeById">) => boolean;
6
+ /**
7
+ * Deletes every pure conversion (`pureNativeConversion`) nothing reads.
8
+ *
9
+ * `call-dispatch.ts` tests `instanceof` on a selection's own source, which
10
+ * leaves the selection that only fed the test unread. The printer keeps an
11
+ * unread conversion of a non-primitive -- it cannot tell one that may abort
12
+ * from one that cannot; this pass can -- so such a selection would still copy
13
+ * the union and destroy the copy. Deleting an operation nothing names removes
14
+ * only its own certification demands; no other operation's provenance runs
15
+ * through it.
16
+ */
17
+ export declare const dropUnreadPureConversions: (bodies: ReadonlyMap<PhysicalBodyId, IrBody>, conversions: Pick<ConversionCensus, "nodeById">) => ReadonlyMap<PhysicalBodyId, IrBody>;
18
+ /**
19
+ * Conversions the printer may spell as the name of a dominating conversion of
20
+ * the same value, by result: later result -> the earlier one it repeats.
21
+ *
22
+ * Each member read of a narrowed union names the union again, and lowering
23
+ * converts it again: `WebGLAttributes.update` re-selected its `attribute`
24
+ * union into the same class-arm union once per member it read -- 21 native
25
+ * selections of 3 distinct pairs, each one a union copy out of the source and
26
+ * a destruction at the end of the scope, per attribute per draw. The C++
27
+ * compiler cannot merge them: every copy is a reference-count increment it
28
+ * must assume a later release observes.
29
+ *
30
+ * Only the RENDERING merges. The IR keeps both conversions, so every
31
+ * certification proof that walks an operand back to the semantic read it came
32
+ * from (`native-property-presence.ts` and its siblings) still finds its own
33
+ * read; the printer names the earlier conversion's storage for the later
34
+ * result instead of converting again. A later conversion is merged only when:
35
+ *
36
+ * - **Both convert the same value.** The same SSA value, or two reads of a
37
+ * cell that is this frame's own (`privateCell`: a local no closure shares,
38
+ * so no call can write it) written exactly once, by a write that dominates
39
+ * every read of it. Two such reads observe the same execution of the write
40
+ * -- see `string-length-reuse.ts`'s `stableStringReceiversOf`, whose
41
+ * argument this is.
42
+ * - **The conversion is a pure function of that value**
43
+ * (`pureNativeConversion`), cited by the same certified node. A selection
44
+ * keeps the identity of every reference it selects, so a value selected
45
+ * twice is the same object both times.
46
+ * - **The earlier one dominates the later one**, so its storage is assigned on
47
+ * every path to the later one and is in scope there (the printer's
48
+ * dominator-nested layout).
49
+ * - **The earlier one is read where it stands.** It has a use of its own and
50
+ * feeds no cell write, so it gets storage rather than being withheld into a
51
+ * forwarded binding.
52
+ *
53
+ * The caller pins both: neither may be withheld as an expression, and neither
54
+ * may be moved from, since one storage now answers both results' uses.
55
+ * Bodies with try or iterator-close regions, generators and async bodies are
56
+ * left alone: an exception edge is not a CFG edge.
57
+ */
58
+ export declare const redundantPureConversionsOf: (body: IrBody, conversions: Pick<ConversionCensus, "nodeById">, privateCell: (declaration: DeclarationId) => boolean) => ReadonlyMap<IrValueId, IrValueId>;