@geastack/compiler 1.0.29 → 1.0.31

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 (48) hide show
  1. package/dist/conversion/dictionary-view.js +18 -0
  2. package/dist/conversion/dynamic-wrapper.d.ts +5 -0
  3. package/dist/conversion/dynamic-wrapper.js +4 -1
  4. package/dist/conversion/structural-plan.js +8 -1
  5. package/dist/ir/absent-class-arm.d.ts +4 -0
  6. package/dist/ir/absent-class-arm.js +50 -2
  7. package/dist/ir/call-entry.js +9 -0
  8. package/dist/ir/callable-class-flow.js +1 -1
  9. package/dist/ir/certify.js +12 -1
  10. package/dist/ir/class-allocation-domain.js +64 -17
  11. package/dist/ir/key-order-observation.js +3 -0
  12. package/dist/ir/native-array-transport.js +37 -3
  13. package/dist/ir/native-field-view-domains.d.ts +7 -0
  14. package/dist/ir/native-field-view-domains.js +29 -4
  15. package/dist/ir/native-field-view-facts.js +17 -4
  16. package/dist/ir/native-key-query.js +5 -2
  17. package/dist/ir/operation-conversions.js +6 -0
  18. package/dist/ir/program-conversions.js +8 -0
  19. package/dist/ir/reflection-demand.js +249 -36
  20. package/dist/ir/shake.js +15 -1
  21. package/dist/representation/host-templates.d.ts +1 -1
  22. package/dist/representation/host-templates.js +5 -3
  23. package/dist/semantics/normalize/any-cast-member-call.d.ts +36 -0
  24. package/dist/semantics/normalize/any-cast-member-call.js +55 -0
  25. package/dist/semantics/normalize/derived-expression-type.js +40 -0
  26. package/dist/semantics/normalize/flow/callable-reach.js +56 -23
  27. package/dist/semantics/normalize/fresh-dictionary-storage.d.ts +2 -0
  28. package/dist/semantics/normalize/fresh-dictionary-storage.js +115 -8
  29. package/dist/semantics/normalize/local-bindings.js +8 -1
  30. package/dist/semantics/normalize/producers/boundary.js +3 -22
  31. package/dist/semantics/normalize/producers/cited-value-type.d.ts +19 -0
  32. package/dist/semantics/normalize/producers/cited-value-type.js +38 -0
  33. package/dist/semantics/normalize/producers/computations.js +32 -11
  34. package/dist/semantics/normalize/producers/invocations.js +10 -0
  35. package/dist/semantics/normalize/return-bindings.js +47 -1
  36. package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +34 -0
  37. package/dist/semantics/normalize/structural-any-binding-consumer.js +208 -0
  38. package/dist/semantics/normalize/structural-declarations.js +10 -1
  39. package/dist/semantics/normalize/structural.d.ts +2 -0
  40. package/dist/semantics/normalize/structural.js +42 -2
  41. package/dist/targets/cpp/conversions.js +21 -1
  42. package/dist/targets/cpp/emit-narrowing.js +22 -1
  43. package/dist/targets/cpp/emit-native-field-view.d.ts +1 -1
  44. package/dist/targets/cpp/emit-native-field-view.js +25 -7
  45. package/dist/targets/cpp/emit-union-properties.js +10 -3
  46. package/dist/targets/cpp/host/emit-host-object.js +1 -1
  47. package/package.json +1 -1
  48. package/src/targets/cpp/runtime/gea_runtime.h +50 -6
@@ -92,6 +92,22 @@ const checkedDynamicWrapperRead = (node, resolve) => {
92
92
  dynamicWrapperPlanMatches(plan, node.source, node.target, resolve) &&
93
93
  dynamicWrapperDependenciesOf(plan).every((child) => wrappedPayloadIsLive(child, resolve)));
94
94
  };
95
+ /**
96
+ * An entry read into the table's declared any/unknown carrier: `gea::Value::box`
97
+ * of a primitive keeps the ECMAScript value, and of a shared class reference
98
+ * holds that same object. The box allocates only its envelope, so the read is
99
+ * live -- `Record<string, Node>` reaching `Record<string, unknown>` (Hono's
100
+ * `hasChildren`) or `Record<string, number>` likewise.
101
+ */
102
+ const boxedEntryIsLive = (node) => {
103
+ if (node.target.kind !== 'dynamic' || node.target.reason === 'untyped-callable' || node.capability.kind !== 'atom')
104
+ return false;
105
+ const materializer = node.capability.materializer;
106
+ if (materializer.id !== 'gea::Value::box')
107
+ return false;
108
+ return (materializer.primitiveIdentityTransport === 'preserved' ||
109
+ (node.source.kind === 'class-ref' && node.source.ownership === 'shared-refcount'));
110
+ };
95
111
  export const dictionaryEntryReadIsLive = (node, resolve) => {
96
112
  if (!recipeIsMaterializableWithoutPriorSourceGuard(node, resolve))
97
113
  return false;
@@ -101,6 +117,8 @@ export const dictionaryEntryReadIsLive = (node, resolve) => {
101
117
  // identity or later write for a copy to lose.
102
118
  if (node.target.kind === 'record' && node.target.ownership === 'owned' && node.capability.kind === 'product')
103
119
  return true;
120
+ if (boxedEntryIsLive(node))
121
+ return true;
104
122
  if (!preservesReadValue(node.capability))
105
123
  return false;
106
124
  const needsCheck = (node.source.kind === 'dynamic' && node.target.kind !== 'dynamic') || conversionRequiresSourceGuard(node.capability, resolve);
@@ -39,6 +39,11 @@ export type DynamicWrapperPlan = {
39
39
  * selects it exactly; a dynamic Array is selected by its elements,
40
40
  * after every exact test, in arm order (`nativeArrayViewElementsAccept`). */
41
41
  readonly byElements?: true;
42
+ /** A string-keyed dictionary arm: its own native table selects it
43
+ * exactly; an ordinary dynamic object or open Document is selected by
44
+ * its values, after every exact test, in arm order
45
+ * (`dynamicDictionaryEntriesAccept`). */
46
+ readonly byEntries?: true;
42
47
  }[];
43
48
  };
44
49
  /** The installed wrapper owns its selection protocol; every future payload
@@ -51,11 +51,14 @@ export const dynamicWrapperPlanOf = (source, target, installed, nodeFor, resolve
51
51
  conversion.capability.kind === 'static' &&
52
52
  conversion.capability.materializer.documentRecordView !== undefined &&
53
53
  (armValue.kind === 'record' || armValue.kind === 'record-with-index' || armValue.kind === 'native-record-ref');
54
+ const byEntries = armValue.kind === 'dictionary' && armValue.key === 'string' && armValue.value.kind !== 'dynamic';
54
55
  arms.push(byShape
55
56
  ? { index, classifier, conversion, byShape }
56
57
  : byElements
57
58
  ? { index, classifier, conversion, byElements }
58
- : { index, classifier, conversion });
59
+ : byEntries
60
+ ? { index, classifier, conversion, byEntries }
61
+ : { index, classifier, conversion });
59
62
  }
60
63
  return arms.length === 0 ? null : { kind: 'union', source, target, arms };
61
64
  };
@@ -101,8 +101,15 @@ const recordArmsCarriedExactly = (source, target) => {
101
101
  if (source.kind !== 'tagged-union' || target.kind !== 'tagged-union')
102
102
  return false;
103
103
  const carried = new Set(unionLeavesOf(target).map(representationKey));
104
- return unionLeavesOf(source).every((leaf) => !hasRecordViewSource(leaf) || carried.has(representationKey(leaf)));
104
+ const homes = new Set(typedUnionLeavesOf(target).map((leaf) => leaf.semanticType));
105
+ // A record leaf whose type has no arm anywhere in the target was narrowed
106
+ // OUT by flow (`else if (body instanceof Blob)` leaves the later reads
107
+ // without the Blob arm): the selection's tag check discards it, so it has
108
+ // no layout to rebuild. A leaf whose type the target still holds at another
109
+ // carrier is a real recast and keeps needing the structural plan.
110
+ return typedUnionLeavesOf(source).every(({ value, semanticType }) => !hasRecordViewSource(value) || carried.has(representationKey(value)) || (semanticType !== undefined && !homes.has(semanticType)));
105
111
  };
112
+ const typedUnionLeavesOf = (value, semanticType) => value.kind === 'tagged-union' ? value.arms.flatMap((arm) => typedUnionLeavesOf(arm.value, arm.semanticType)) : [{ value, semanticType }];
106
113
  /** A value read as `undefined`/`null`/`void` is DISCARDED (`chain:unreachable-value`,
107
114
  * `chain:discard-into-void`): correct only where flow already proved the read
108
115
  * yields the absence, never as the home of a live union arm. Offered as one, a
@@ -32,10 +32,14 @@ import type { ReflectionExposure } from './reflection-demand.js';
32
32
  */
33
33
  /** Whether a `class-ref(declaration)` value can own or inherit `key` by any declaration in the program. */
34
34
  export declare const classFamilyLacksKey: (classes: ReadonlyMap<DeclarationId, ClassLayout>, declaration: DeclarationId, key: string) => boolean;
35
+ /** A result that holds `undefined` without a box, and nothing but primitives otherwise. */
36
+ export declare const holdsAbsentPrimitive: (representation: Representation) => boolean;
35
37
  /** The census half: `surface` is a class arm of the union `receiver` that answers this read with `undefined`. */
36
38
  export declare const absentClassArmRead: (receiver: Representation, surface: Representation, key: string, result: Representation, classes: ReadonlyMap<DeclarationId, ClassLayout>) => surface is Extract<Representation, {
37
39
  kind: "class-ref";
38
40
  }>;
41
+ /** Certification's check that a non-primitive read left no lacking arm on the expando fallback. */
42
+ export declare const requiredAbsentClassArmsStamped: (operation: GetOperation, key: string | null, classes: ReadonlyMap<DeclarationId, ClassLayout>) => boolean;
39
43
  /** Certification's re-check of a published stamp against the same proof and the closed exposure. */
40
44
  export declare const absentClassArmsHold: (operation: GetOperation, key: string | null, classes: ReadonlyMap<DeclarationId, ClassLayout>, exposure: ReflectionExposure | undefined) => boolean;
41
45
  /**
@@ -51,7 +51,7 @@ const primitiveLeaf = (representation) => representation.kind === 'undefined' ||
51
51
  representation.kind === 'scalar' ||
52
52
  representation.kind === 'string';
53
53
  /** A result that holds `undefined` without a box, and nothing but primitives otherwise. */
54
- const holdsAbsentPrimitive = (representation) => {
54
+ export const holdsAbsentPrimitive = (representation) => {
55
55
  if (representation.kind === 'undefined')
56
56
  return true;
57
57
  if (representation.kind === 'optional')
@@ -60,6 +60,26 @@ const holdsAbsentPrimitive = (representation) => {
60
60
  return representation.arms.some((arm) => arm.value.kind === 'undefined') && representation.arms.every((arm) => primitiveLeaf(arm.value));
61
61
  return false;
62
62
  };
63
+ /**
64
+ * A result that holds `undefined` without a box, whatever else it holds.
65
+ *
66
+ * An object-valued read -- a method read through an `as any` receiver
67
+ * (`semantics/normalize/any-cast-member-call.ts`) publishes `(() => R) |
68
+ * undefined` -- has no safe fallback: the expando read a full class keeps
69
+ * hands back a box, and unboxing it into a callable publishes the callable's
70
+ * inputs, which the census did not count. Such a read is admitted only on the
71
+ * condition `absentClassArmsRequired` names: every lacking arm must end up
72
+ * proven, or certification refuses the read.
73
+ */
74
+ const holdsAbsent = (representation) => {
75
+ if (representation.kind === 'undefined')
76
+ return true;
77
+ if (representation.kind === 'optional')
78
+ return representation.absence === 'undefined';
79
+ if (representation.kind === 'tagged-union')
80
+ return representation.arms.some((arm) => arm.value.kind === 'undefined');
81
+ return false;
82
+ };
63
83
  /**
64
84
  * The union a read dispatches over. A nullable union (`background &&` has not
65
85
  * stripped the carrier) still selects among the same arms once present; its
@@ -75,8 +95,36 @@ const unionOf = (receiver) => {
75
95
  /** The census half: `surface` is a class arm of the union `receiver` that answers this read with `undefined`. */
76
96
  export const absentClassArmRead = (receiver, surface, key, result, classes) => surface.kind === 'class-ref' &&
77
97
  (unionOf(receiver)?.arms.some((arm) => arm.value === surface) ?? false) &&
78
- holdsAbsentPrimitive(result) &&
98
+ holdsAbsent(result) &&
79
99
  classFamilyLacksKey(classes, surface.declaration, key);
100
+ /**
101
+ * The class arms a non-primitive read was admitted on the condition of
102
+ * proving absent (`holdsAbsent`), in arm order; empty for a primitive read,
103
+ * whose arms may keep the expando fallback.
104
+ */
105
+ const absentClassArmsRequired = (operation, key, classes) => {
106
+ const receiver = operation.receiver.representation;
107
+ const result = operation.result.representation;
108
+ if (holdsAbsentPrimitive(result))
109
+ return [];
110
+ const arms = [];
111
+ for (const arm of unionOf(receiver)?.arms ?? [])
112
+ if (absentClassArmRead(receiver, arm.value, key, result, classes) && !arms.includes(arm.value.declaration))
113
+ arms.push(arm.value.declaration);
114
+ return arms;
115
+ };
116
+ /** Certification's check that a non-primitive read left no lacking arm on the expando fallback. */
117
+ export const requiredAbsentClassArmsStamped = (operation, key, classes) => {
118
+ if (key === null || unionOf(operation.receiver.representation) === null)
119
+ return true;
120
+ // A read nothing stamped kept the expando fallback whole, and that read is
121
+ // certified on its own terms; only a read admitted by proving SOME arm
122
+ // absent has to have proven every lacking one.
123
+ const stamped = operation.absentClassArms ?? [];
124
+ if (stamped.length === 0)
125
+ return true;
126
+ return absentClassArmsRequired(operation, key, classes).every((declaration) => stamped.includes(declaration));
127
+ };
80
128
  /** A class the closed exposure left without a dynamic protocol. A class it never rowed is fail-closed full. */
81
129
  const withoutDynamicProtocol = (exposure, declaration) => {
82
130
  const demand = exposure.classes.get(declaration);
@@ -380,6 +380,15 @@ export const hostTemplateFrameOf = (operation, conversions, deriver, classes) =>
380
380
  };
381
381
  return dataTree(argument.representation);
382
382
  }
383
+ // `createText` renders only the one-argument null-prototype form, as the
384
+ // empty table or struct the result carrier states (or an empty box): a
385
+ // fresh object with no own property, which publishes nothing it could
386
+ // hand to dynamic code. Without this frame `Object.create(null)` was an
387
+ // unknown call whose result published every carrier its value type
388
+ // reaches -- hono's `Record<string, HandlerSet<T>>` made the router's
389
+ // handler tuples fully reflected.
390
+ if (template === 'object-create')
391
+ return operation.arguments.length === 1 && operation.arguments[0]?.representation.kind === 'null';
383
392
  if (template === 'typed-array-set') {
384
393
  const [source, offset] = operation.arguments;
385
394
  return (source !== undefined &&
@@ -2546,7 +2546,7 @@ const computeNativeCallableFlow = (bodies, placements, classes, conversions, tra
2546
2546
  // The selected heaps already prove each allocation's own slot or its
2547
2547
  // absence; a union arm's certified absence is the unknown-receiver
2548
2548
  // answer (`native-field-view-domains.ts`) and is no route behind them.
2549
- if (routes.some((route) => route.originalAbsent === true || route.dynamicGet === true))
2549
+ if (routes.some((route) => route.originalAbsent === true || route.dynamicGet === true || route.nativeData === true))
2550
2550
  continue;
2551
2551
  domains.set(name, [
2552
2552
  ...(domains.get(name) ?? []),
@@ -39,7 +39,7 @@ import { bufferReadNeedsLogicalReceiver, hostReadIgnoresLogicalReceiver, nativeL
39
39
  import { authenticatedTemplateCallEntry } from './call-entry.js';
40
40
  import { nativeCallableFlowOf } from './callable-class-flow.js';
41
41
  import { nativeFieldOwnerReadMatches } from './native-field-owner.js';
42
- import { absentClassArmsHold } from './absent-class-arm.js';
42
+ import { absentClassArmsHold, requiredAbsentClassArmsStamped } from './absent-class-arm.js';
43
43
  import { objectValueConversionInputsOf, objectValueConversionsMatch } from './object-value-conversions.js';
44
44
  import { operationConversionInputsOf, operationConversionsMatch } from './operation-conversions.js';
45
45
  import { methodConversionInputsOf, methodValueRecipesMatch } from './publish-conversion-recipes.js';
@@ -154,6 +154,17 @@ const abiDemands = (manifest, abi) => {
154
154
  });
155
155
  };
156
156
  const getDemandsOf = (operation, ctx) => {
157
+ {
158
+ const key = ctx.definitionOf(operation.key.value);
159
+ if (!requiredAbsentClassArmsStamped(operation, key?.kind === 'constant' && key.literal === 'string' ? key.text : null, ctx.classes))
160
+ return [
161
+ {
162
+ key: 'property-access:union:get:absent-class-arm',
163
+ verdict: 'missing',
164
+ detail: 'an object-valued read was admitted on proving a class arm absent, and the closed census did not prove it'
165
+ }
166
+ ];
167
+ }
157
168
  if (operation.absentClassArms !== undefined) {
158
169
  const key = ctx.definitionOf(operation.key.value);
159
170
  if (!absentClassArmsHold(operation, key?.kind === 'constant' && key.literal === 'string' ? key.text : null, ctx.classes, ctx.reflection))
@@ -1,7 +1,10 @@
1
1
  import { classLayoutOfCopy } from '../projection/classes.js';
2
- import { extendsClass } from '../projection/dispatch.js';
2
+ import { classFamilyOverridesOf, extendsClass } from '../projection/dispatch.js';
3
+ import { classMemberOf } from '../projection/fields.js';
3
4
  import { representationKey, walkRepresentation } from '../representation/model.js';
4
5
  import { allOperationsOf } from './model.js';
6
+ import { resultOfIrOperation } from './queries.js';
7
+ import { constantPropertyKeyTextOf } from './native-property-key-texts.js';
5
8
  /** Exact native allocations and allocations an unknown observer may create. Base initialization is a separate demand.
6
9
  * The caller supplies the one callable flow over exactly these bodies. */
7
10
  export const classAllocationDomainOf = (bodies, classes, placements, deriver, flow) => {
@@ -18,21 +21,25 @@ export const classAllocationDomainOf = (bodies, classes, placements, deriver, fl
18
21
  if (layout)
19
22
  allocations.add(layout.declaration);
20
23
  };
24
+ // An unknown observer can recover every constructor along an instance's
25
+ // prototype chain, including a bodyless base declaration's constructor --
26
+ // but only from an instance that exists. A value it receives whose type is
27
+ // a class names that class's family, not an allocation of it: hono's `Context`
28
+ // reaches an `executionCtx?: FetchEventLike` that nothing ever constructs,
29
+ // and treating the type as an instance made the abstract class allocatable
30
+ // and its bodyless `respondWith` an evaluated read. So a received class type
31
+ // records the family, and the chains are recovered once the construct sites
32
+ // are known (below).
33
+ const exposedFamilies = new Set();
21
34
  const exposeClass = (declaration) => {
22
35
  const layout = classLayoutOfCopy(classes, declaration);
23
- if (!layout)
24
- return;
25
- // An unknown observer can recover every constructor along an instance's
26
- // prototype chain, including a bodyless base declaration's constructor.
27
- for (const [allocation] of classes) {
28
- if (allocation !== layout.declaration && !extendsClass(classes, allocation, layout.declaration))
29
- continue;
30
- const seen = new Set();
31
- for (let current = allocation; current !== null && !seen.has(current); current = classes.get(current)?.base ?? null) {
32
- seen.add(current);
33
- addClass(current);
34
- }
35
- }
36
+ if (layout)
37
+ exposedFamilies.add(layout.declaration);
38
+ };
39
+ /** A constructor the observer is handed: it can construct that class itself. */
40
+ const exposeConstructor = (declaration) => {
41
+ addClass(declaration);
42
+ exposeClass(declaration);
36
43
  };
37
44
  const exposed = new Set();
38
45
  const expose = (representation) => {
@@ -52,7 +59,7 @@ export const classAllocationDomainOf = (bodies, classes, placements, deriver, fl
52
59
  }
53
60
  if (carrier.kind === 'constructor-family')
54
61
  for (const member of carrier.members)
55
- exposeClass(member);
62
+ exposeConstructor(member);
56
63
  if (carrier.kind === 'native-record-ref' && carrier.native === null) {
57
64
  const shape = deriver.layoutOf(carrier.shapeId);
58
65
  if (shape)
@@ -61,8 +68,30 @@ export const classAllocationDomainOf = (bodies, classes, placements, deriver, fl
61
68
  }
62
69
  }
63
70
  };
71
+ // A class's own declared data field read as the `any` it is declared --
72
+ // hono's `const { bodyCache } = this`, a `Partial<Body>` whose `json: any`
73
+ // makes the field dynamic -- is a load from the instance's slot. It hands
74
+ // no observer the instance: the Value it yields was exposed when stored.
75
+ let definitions = new Map();
76
+ const declaredDataFieldRead = (operation) => {
77
+ const receiver = operation.receiver.representation;
78
+ if (receiver.kind !== 'class-ref')
79
+ return false;
80
+ const key = constantPropertyKeyTextOf(definitions.get(operation.key.value));
81
+ if (key === null)
82
+ return false;
83
+ return (classMemberOf(classes, receiver.declaration, key)?.kind === 'field' &&
84
+ classFamilyOverridesOf(classes, receiver.declaration, key).length === 0);
85
+ };
64
86
  const dynamicReceivers = flow.dynamicReceiverValues;
65
- for (const body of bodies)
87
+ for (const body of bodies) {
88
+ definitions = new Map();
89
+ for (const block of body.blocks.values())
90
+ for (const operation of allOperationsOf(block)) {
91
+ const result = resultOfIrOperation(operation);
92
+ if (result !== null)
93
+ definitions.set(result.id, operation);
94
+ }
66
95
  for (const block of body.blocks.values())
67
96
  for (const operation of allOperationsOf(block)) {
68
97
  if (operation.kind === 'construct') {
@@ -91,7 +120,7 @@ export const classAllocationDomainOf = (bodies, classes, placements, deriver, fl
91
120
  if (operation.source.representation.kind === 'dynamic')
92
121
  expose(operation.result.representation);
93
122
  }
94
- if (operation.kind === 'get' && operation.result.representation.kind === 'dynamic')
123
+ if (operation.kind === 'get' && operation.result.representation.kind === 'dynamic' && !declaredDataFieldRead(operation))
95
124
  expose(operation.receiver.representation);
96
125
  if (operation.kind === 'call' &&
97
126
  (operation.callee.representation.kind === 'dynamic' || dynamicReceivers.has(operation.callee.value))) {
@@ -107,5 +136,23 @@ export const classAllocationDomainOf = (bodies, classes, placements, deriver, fl
107
136
  if (operation.kind === 'binding-read' && placements.get(operation.declaration)?.storage.kind === 'external')
108
137
  expose(operation.result.representation);
109
138
  }
139
+ }
140
+ for (let grown = true; grown;) {
141
+ grown = false;
142
+ for (const family of exposedFamilies)
143
+ for (const allocation of [...allocations]) {
144
+ if (allocation !== family && !extendsClass(classes, allocation, family))
145
+ continue;
146
+ const seen = new Set();
147
+ for (let current = classes.get(allocation)?.base ?? null; current !== null && !seen.has(current); current = classes.get(current)?.base ?? null) {
148
+ seen.add(current);
149
+ const layout = classLayoutOfCopy(classes, current);
150
+ if (layout && !allocations.has(layout.declaration)) {
151
+ allocations.add(layout.declaration);
152
+ grown = true;
153
+ }
154
+ }
155
+ }
156
+ }
110
157
  return allocations;
111
158
  };
@@ -130,6 +130,9 @@ export const keyOrderObservationOf = (bodies, reflection) => {
130
130
  feed(target.representation, source.representation);
131
131
  return;
132
132
  }
133
+ // A fresh null-prototype object has no key to read and none to order.
134
+ if (operation.hostTemplate === 'object-create' && !operation.argumentsAreSpread)
135
+ return;
133
136
  if (operation.intrinsicOwnKeys || operation.hostTemplate !== undefined || operation.argumentsAreSpread)
134
137
  observeAll(operation);
135
138
  return;
@@ -25,16 +25,23 @@ export const nativeArrayTransportOf = (operation, constantKey) => {
25
25
  if (operation.kind !== 'get' && operation.kind !== 'set')
26
26
  return false;
27
27
  const receiver = operation.receiver.representation;
28
+ if (receiver.kind === 'tagged-union')
29
+ return unionIndexReadOf(operation, receiver, constantKey);
28
30
  if (receiver.kind !== 'array-object')
29
31
  return false;
30
32
  const value = operation.kind === 'get' ? operation.result.representation : operation.value.representation;
31
33
  if (constantKey === 'length')
32
34
  return value.kind === 'scalar' && value.domain === 'number';
33
- // A string-shaped runtime key can name an ordinary property or method.
34
- // Only a known canonical index or an already numeric key enters this path.
35
+ // A constant key can name an ordinary property or method; only a canonical
36
+ // index enters this path. A runtime STRING key is rendered as an element
37
+ // access through CanonicalNumericIndexString (`arrayIndexFromKeyText` in
38
+ // `emit-carrier-members.ts`/`emit-properties.ts`) -- the `for (const i in
39
+ // array)` key hono's RegExpRouter indexes back with -- so it reaches no
40
+ // field protocol either.
35
41
  const indexed = constantKey !== null
36
42
  ? canonicalIndexLiteral(constantKey) !== null
37
- : operation.key.representation.kind === 'scalar' && operation.key.representation.domain === 'number';
43
+ : (operation.key.representation.kind === 'scalar' && operation.key.representation.domain === 'number') ||
44
+ operation.key.representation.kind === 'string';
38
45
  if (!indexed)
39
46
  return false;
40
47
  const element = representationKey(receiver.element);
@@ -44,3 +51,30 @@ export const nativeArrayTransportOf = (operation, constantKey) => {
44
51
  // from its existing native payload. It does not adapt or expose that payload.
45
52
  return (operation.kind === 'get' && value.kind === 'optional' && value.absence === 'undefined' && representationKey(value.payload) === element);
46
53
  };
54
+ /**
55
+ * A numeric index read off a union whose every arm is an Array reads each
56
+ * arm's own element storage, exactly as the single-Array read above does, and
57
+ * injects it into the result's arm for that element: no field protocol, no
58
+ * adaptation. Hono's `compose` reads `middleware[i]` off
59
+ * `[[Function, unknown], unknown][] | [[Function]][]`; as a computed key it
60
+ * published every handler tuple the router holds.
61
+ */
62
+ const unionIndexReadOf = (operation, receiver, constantKey) => {
63
+ if (operation.kind !== 'get')
64
+ return false;
65
+ const indexed = constantKey !== null
66
+ ? canonicalIndexLiteral(constantKey) !== null
67
+ : operation.key.representation.kind === 'scalar' && operation.key.representation.domain === 'number';
68
+ if (!indexed || receiver.arms.length === 0)
69
+ return false;
70
+ const elements = [];
71
+ for (const arm of receiver.arms) {
72
+ if (arm.value.kind !== 'array-object')
73
+ return false;
74
+ elements.push(representationKey(arm.value.element));
75
+ }
76
+ const value = operation.result.representation;
77
+ const present = value.kind === 'optional' && value.absence === 'undefined' ? value.payload : value;
78
+ const carried = new Set(present.kind === 'tagged-union' ? present.arms.map((arm) => representationKey(arm.value)) : [representationKey(present)]);
79
+ return elements.every((element) => carried.has(element));
80
+ };
@@ -18,6 +18,13 @@ export interface NativeFieldStorageDomain {
18
18
  readonly sourceAbsent?: true;
19
19
  /** A union's `dynamic` arm: the read is that `gea::Value`'s own [[Get]]. */
20
20
  readonly dynamicGet?: true;
21
+ /**
22
+ * A union's binary-view arm (`typed-array`, `data-view`, `array-buffer`):
23
+ * the read is that arm's own native data property (`nativeDataPropertyOf`),
24
+ * which no descriptor can replace -- `buffer`, `byteOffset` and
25
+ * `byteLength` are prototype accessors over the view's internal slots.
26
+ */
27
+ readonly nativeData?: true;
21
28
  }
22
29
  export interface NativeFieldViewDomains {
23
30
  (receiver: Representation): ReadonlyMap<string, readonly NativeFieldStorageDomain[]> | null;
@@ -3,6 +3,8 @@ import { representationKey } from '../representation/model.js';
3
3
  import { classMemberOf } from '../projection/fields.js';
4
4
  import { extendsClass } from '../projection/dispatch.js';
5
5
  import { abiOfCallee } from '../projection/callee.js';
6
+ import { nativeDataPropertyOf } from '../representation/native-data-properties.js';
7
+ const binaryViewDataKeys = ['buffer', 'byteLength', 'byteOffset', 'length', 'BYTES_PER_ELEMENT'];
6
8
  const isDocumentPlan = (plan) => plan.source.kind === 'dictionary' && plan.fields.every((field) => field.declaredAnyEntry === true);
7
9
  /**
8
10
  * A callback's physical descriptor remains fixed when its Function identity
@@ -120,6 +122,20 @@ expandoStoredOf = () => []) => {
120
122
  cache.set(identity, common);
121
123
  return common;
122
124
  }
125
+ // A binary view beside a live record view in one union -- node-compat's
126
+ // `BodyInit` holds `Buffer` and `ArrayBufferView<ArrayBuffer>`, and the
127
+ // latter is a live view of a Document a dynamic body was read as. Only as
128
+ // an ordinary union arm: a binary view is never itself a view target.
129
+ if (ordinaryArm && (receiver.kind === 'typed-array' || receiver.kind === 'data-view' || receiver.kind === 'array-buffer')) {
130
+ const fields = new Map();
131
+ for (const key of binaryViewDataKeys) {
132
+ const property = nativeDataPropertyOf(receiver, key);
133
+ if (property !== null)
134
+ fields.set(key, [{ read: property.result, write: null, nativeData: true }]);
135
+ }
136
+ cache.set(identity, fields);
137
+ return fields;
138
+ }
123
139
  if (receiver.kind === 'class-ref' && receiver.ownership === 'shared-refcount') {
124
140
  if (!classes.has(receiver.declaration))
125
141
  return null;
@@ -139,14 +155,23 @@ expandoStoredOf = () => []) => {
139
155
  continue;
140
156
  const getter = accessor.getter === null ? null : abiOf(accessor.getter);
141
157
  const setter = accessor.setter === null ? null : abiOf(accessor.setter);
158
+ // An accessor with no admitted ABI (a getter nothing calls has
159
+ // no body) states no route for ITS key; it does not void the
160
+ // class's other members. node-compat's `ResponseImpl` declares
161
+ // every WHATWG attribute as a getter and hono reads only
162
+ // `headers` off `Response | ResponseInit`.
142
163
  if (!getter ||
143
164
  getter.parameters.length !== 0 ||
144
165
  getter.restFrom !== null ||
145
- (accessor.setter !== null && (!setter || setter.parameters.length !== 1 || setter.restFrom !== null)))
146
- return null;
166
+ (accessor.setter !== null && (!setter || setter.parameters.length !== 1 || setter.restFrom !== null))) {
167
+ fields.delete(accessor.key);
168
+ continue;
169
+ }
147
170
  const read = getter.result.kind === 'void' ? accessor.representation && abiOfCallee(accessor.representation)?.result : getter.result;
148
- if (read === undefined || (getter.result.kind === 'void' && read.kind !== 'undefined'))
149
- return null;
171
+ if (read === undefined || (getter.result.kind === 'void' && read.kind !== 'undefined')) {
172
+ fields.delete(accessor.key);
173
+ continue;
174
+ }
150
175
  fields.set(accessor.key, [{ read, write: setter?.parameters[0]?.value ?? null }]);
151
176
  }
152
177
  }
@@ -127,7 +127,9 @@ const fieldSourcesOf = (flow, receiver, key, at) => {
127
127
  return carried ?? (at === undefined ? null : (flow.nativeFieldViewAbsentRoutesOf?.(receiver, key) ?? null));
128
128
  // Physical allocation slots are the whole answer where they exist; a union
129
129
  // arm's certified absence speaks only for a receiver with none.
130
- const domains = carried?.some((entry) => entry.originalAbsent === true || entry.dynamicGet === true) ? undefined : carried;
130
+ const domains = carried?.some((entry) => entry.originalAbsent === true || entry.dynamicGet === true || entry.nativeData === true)
131
+ ? undefined
132
+ : carried;
131
133
  const routes = physical.flatMap((read) => {
132
134
  const selected = domains?.filter((entry) => representationKey(entry.read) === representationKey(read));
133
135
  return selected?.length ? selected : [{ read }];
@@ -158,13 +160,22 @@ export const nativeFieldViewReadFor = (receiver, key, target, flow, conversions,
158
160
  const node = abiOfCallee(source) !== null && abiOfCallee(target) !== null
159
161
  ? (conversions.nativeMethodFor(source, target) ?? conversions.nodeFor(source, target))
160
162
  : conversions.nodeFor(source, target);
161
- const selected = (checkedRead === undefined
163
+ const unguarded = (checkedRead === undefined
162
164
  ? null
163
165
  : representationKey(checkedRead.source) === representationKey(source) &&
164
166
  representationKey(checkedRead.target) === representationKey(target)
165
167
  ? checkedRead
166
168
  : conversions.checkedFieldReadFor(source, target, checkedRead)) ?? node;
167
- if (!recipeIsMaterializableWithoutPriorSourceGuard(selected, conversions.nodeById))
169
+ // A read the program's flow narrowed (`arg.headers instanceof Headers ?
170
+ // arg.headers : ...` over `Response | ResponseInit`) selects an arm of
171
+ // the slot's union on the strength of a guard evaluated on an EARLIER
172
+ // read of the same member. Through a live view or a getter that read is
173
+ // a second [[Get]], so the selection is the checked dispatch: the arm the
174
+ // guard proved, a TypeError for any other -- never an unchecked `get<k>`.
175
+ const selected = recipeIsMaterializableWithoutPriorSourceGuard(unguarded, conversions.nodeById)
176
+ ? unguarded
177
+ : conversions.assertedUnionFor(source, target, false);
178
+ if (selected === null || !recipeIsMaterializableWithoutPriorSourceGuard(selected, conversions.nodeById))
168
179
  return null;
169
180
  const previous = sources.get(representationKey(source));
170
181
  if (previous !== undefined && previous.conversion !== selected.id) {
@@ -271,7 +282,9 @@ export const nativeFieldViewWriteOf = (operation, key, flow, conversions) => {
271
282
  return null;
272
283
  // A certified absence is a read route: storing the key on that arm creates
273
284
  // an expando property, which no setter-less descriptor route performs.
274
- if (!data && !accessor && descriptors?.some((entry) => entry.originalAbsent === true || entry.dynamicGet === true))
285
+ if (!data &&
286
+ !accessor &&
287
+ descriptors?.some((entry) => entry.originalAbsent === true || entry.dynamicGet === true || entry.nativeData === true))
275
288
  return null;
276
289
  const targets = new Map();
277
290
  for (const target of data ?? accessor?.map((entry) => entry.write) ?? descriptors.map((entry) => entry.write)) {
@@ -23,8 +23,11 @@ export const nativeKeyQueryOf = (operation, closedLayoutOf) => {
23
23
  return false;
24
24
  const queried = operation.arguments[0]?.representation;
25
25
  // Lowering authenticates this intrinsic. A same-shaped arbitrary callable
26
- // has no such contract and must retain its ordinary call effects.
27
- if (queried === undefined || !closedLayoutOf(queried))
26
+ // has no such contract and must retain its ordinary call effects. The
27
+ // queried object is read through its carrier exactly as an enumeration's
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).
30
+ if (queried === undefined || !closedReceiver(queried))
28
31
  return false;
29
32
  // `Object.hasOwn(o, key)` is the one member of this family that takes a
30
33
  // second argument -- the queried KEY, not a second object -- and
@@ -167,6 +167,12 @@ export const operationConversionInputsOf = (operation, keyText, deriver, classes
167
167
  // (`absentCapableElementText`), which a union spells as an arm.
168
168
  if (result.kind === 'tagged-union' && carriesUndefined(result))
169
169
  add('index-read', { kind: 'undefined' }, result);
170
+ // A `null`-absent result is not the hole's carrier, so the element is
171
+ // aligned into the whole result (`reconciledElementText`), not into its
172
+ // payload: hono's `...(args as Parameters<NewResponse>)` reads a rest
173
+ // array of `any` into `Data | null`.
174
+ if (result.kind === 'optional' && result.absence !== 'undefined')
175
+ add('index-read', receiver.element, result);
170
176
  }
171
177
  if (keyText === null || (!native && !field)) {
172
178
  const indexed = indexedValueOf(receiver, operation.key.representation, keyText, deriver);
@@ -9,6 +9,7 @@ import { asyncPromiseViewOf } from './coroutine-bodies.js';
9
9
  import { allOperationsOf } from './model.js';
10
10
  import { nativeConstructorPropertyClassesOf } from './native-constructor-reads.js';
11
11
  import { constantPropertyKeyTextOf } from './native-property-key-texts.js';
12
+ import { isPrivateNameKey } from '../semantics/model/structural-types.js';
12
13
  /**
13
14
  * A typed string table whose entries are records: a dynamic object stored into
14
15
  * it (`this[key] = value` landing on a `Record<string, R>` field) is viewed
@@ -101,6 +102,13 @@ export const programConversionInputsOf = (input) => {
101
102
  ? layouts.forShape(receiver.shapeId)
102
103
  : null;
103
104
  for (const field of fields ?? []) {
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
108
+ // handler arm no dynamic value can be read into -- demanding that
109
+ // reader refused a class only full reflection had touched.
110
+ if (isPrivateNameKey(field.key))
111
+ continue;
104
112
  const operations = demand.fieldOperations?.get(field.key);
105
113
  if (demand.fieldOperations !== undefined && !operations?.has('write') && !operations?.has('define'))
106
114
  continue;