@geastack/compiler 1.0.42 → 1.0.44

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 (58) hide show
  1. package/dist/cli.js +8 -2
  2. package/dist/conversion/nodes.js +5 -2
  3. package/dist/ir/callable-class-flow.js +48 -13
  4. package/dist/ir/certify.js +1 -1
  5. package/dist/ir/host-template-conversions.d.ts +2 -2
  6. package/dist/ir/host-template-conversions.js +73 -2
  7. package/dist/ir/lower-destructuring.js +22 -3
  8. package/dist/ir/lower-operands.js +30 -1
  9. package/dist/ir/native-field-view-facts.d.ts +8 -1
  10. package/dist/ir/native-field-view-facts.js +13 -3
  11. package/dist/ir/operation-conversions.js +1 -1
  12. package/dist/ir/program-conversions.d.ts +1 -1
  13. package/dist/ir/program-conversions.js +68 -1
  14. package/dist/ir/property-read-conversions.js +7 -1
  15. package/dist/ir/publish-native-field-view-facts.js +4 -0
  16. package/dist/ir/reflection-demand.js +29 -3
  17. package/dist/ir/shake.js +21 -0
  18. package/dist/projection/dispatch.d.ts +19 -1
  19. package/dist/projection/dispatch.js +34 -0
  20. package/dist/representation/value-records.js +182 -13
  21. package/dist/semantics/frontend.js +18 -14
  22. package/dist/semantics/normalize/collection-bindings.d.ts +7 -0
  23. package/dist/semantics/normalize/collection-bindings.js +35 -1
  24. package/dist/semantics/normalize/derived-expression-type.js +49 -0
  25. package/dist/semantics/normalize/field-bindings.js +6 -1
  26. package/dist/semantics/normalize/flow/component-solver.js +37 -2
  27. package/dist/semantics/normalize/flow/source-value-session.d.ts +12 -2
  28. package/dist/semantics/normalize/flow/source-value-session.js +861 -212
  29. package/dist/semantics/normalize/global-host-mutations.js +14 -6
  30. package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +11 -10
  31. package/dist/semantics/normalize/implicit-arguments-tuple.js +15 -3
  32. package/dist/semantics/normalize/local-bindings.js +23 -1
  33. package/dist/semantics/normalize/producers/references.js +26 -18
  34. package/dist/semantics/normalize/structural-array-element.d.ts +7 -0
  35. package/dist/semantics/normalize/structural-array-element.js +24 -1
  36. package/dist/semantics/normalize/structural-layout-type.js +5 -1
  37. package/dist/semantics/normalize/structural-mutable-method.js +88 -2
  38. package/dist/semantics/normalize/structural-parts.js +13 -8
  39. package/dist/semantics/normalize/structural.js +25 -1
  40. package/dist/targets/cpp/borrowed-call-entry.d.ts +41 -2
  41. package/dist/targets/cpp/borrowed-call-entry.js +91 -6
  42. package/dist/targets/cpp/class-properties/emit-class-properties.js +5 -1
  43. package/dist/targets/cpp/emit-callable.js +81 -39
  44. package/dist/targets/cpp/emit-native-field-view.d.ts +2 -0
  45. package/dist/targets/cpp/emit-native-field-view.js +1 -1
  46. package/dist/targets/cpp/emit-properties.js +114 -12
  47. package/dist/targets/cpp/host/emit-host-invoke.js +16 -2
  48. package/dist/targets/cpp/host/emit-host-object.js +69 -2
  49. package/dist/targets/cpp/host/host-members.js +4 -0
  50. package/dist/targets/cpp/prototype/emit-prototype-array.d.ts +42 -0
  51. package/dist/targets/cpp/prototype/emit-prototype-array.js +31 -9
  52. package/dist/targets/cpp/records.d.ts +1 -0
  53. package/dist/targets/cpp/records.js +40 -17
  54. package/dist/targets/cpp/translation-unit.js +82 -24
  55. package/dist/targets/cpp/virtual-methods.js +9 -4
  56. package/package.json +1 -1
  57. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +17 -1
  58. package/src/targets/cpp/runtime/gea_runtime.h +485 -64
@@ -246,6 +246,16 @@ const valuesOfView = (ctx, operation, view) => {
246
246
  throw createCppEmitBlockedError('host-member-call:Object.values', `"Object.values" of a known shape mints an array, and this call's result carries ` +
247
247
  `"${result === undefined ? 'nothing' : representationKey(result)}"`);
248
248
  }
249
+ if (!classOwnKeysAreStatic(ctx, view.representation)) {
250
+ const walked = creationOrderedOwnCopyText(ctx, view, 'values', (_key, value, walkCtx) => {
251
+ const converted = alignedValueText(walkCtx, 'host/emit-host-object.ts:values-of-class-instance', dynamicCarrier, result.element, value);
252
+ return converted === null ? null : `__gea_values.push_back(${converted});`;
253
+ }, null, true);
254
+ if (walked === null)
255
+ return refuseClassInstanceWalk('values', view.representation);
256
+ return (`([&]() { ${classWalkProtocolAssertion(view)} std::vector<${cppTypeOf(result.element)}> __gea_values; ${walked}; ` +
257
+ `return gea::detail::hostArrayResult(std::move(__gea_values)); })()`);
258
+ }
249
259
  const element = representationKey(result.element);
250
260
  const ordered = ownKeyFields(view);
251
261
  // A field whose carrier differs from the element (`{ on: true, none: 'none' }`
@@ -448,6 +458,16 @@ const entriesOfView = (ctx, operation, view) => {
448
458
  return (`gea::host::ObjectConstructor::entriesOf<${cppTypeOf(entry.element)}>(${view.receiver}, ` +
449
459
  `[](std::string __gea_key, ${cppTypeOf(view.value)} __gea_value) { ${entryText(entry, '__gea_key', value)} })`);
450
460
  }
461
+ if (!classOwnKeysAreStatic(ctx, view.representation)) {
462
+ const walked = creationOrderedOwnCopyText(ctx, view, 'entries', (key, value, walkCtx) => {
463
+ const converted = alignedValueText(walkCtx, 'host/emit-host-object.ts:entries-of-class-instance', dynamicCarrier, entry.value, value);
464
+ return converted === null ? null : `__gea_entries.push_back([&]() { ${entryText(entry, key, converted)} }());`;
465
+ }, null, true);
466
+ if (walked === null)
467
+ return refuseClassInstanceWalk('entries', view.representation);
468
+ return (`([&]() { ${classWalkProtocolAssertion(view)} std::vector<${cppTypeOf(entry.element)}> __gea_entries; ${walked}; ` +
469
+ `return gea::detail::hostArrayResult(std::move(__gea_entries)); })()`);
470
+ }
451
471
  const ordered = ownKeyFields(view);
452
472
  const entryOf = (field) => {
453
473
  const read = getOwnValue(ctx, view, field);
@@ -476,7 +496,54 @@ const entriesOfView = (ctx, operation, view) => {
476
496
  return (`([&]() { std::vector<${cppTypeOf(entry.element)}> __gea_entries; ${walked} ` +
477
497
  `return gea::detail::hostArrayResult(std::move(__gea_entries)); })()`);
478
498
  };
479
- const creationOrderedOwnCopyText = (ctx, view, destination, each, assigned = null) => {
499
+ /**
500
+ * Whether a class instance's own keys are exactly the field list its carrier's
501
+ * shape names, in that order, so the static arms of `values` and `entries`
502
+ * may list them.
503
+ *
504
+ * A `class-ref` names the class its handle is DECLARED at, and the object
505
+ * behind it can be any subclass: a `Material`-typed handle holding a
506
+ * `DashedMaterial` owns `dashSize`, which no struct the handle can name has.
507
+ * Its carrier's shape need not even be the class's own -- the struct is
508
+ * rendered from the class's instance shape, a use site's handle may carry a
509
+ * wider one (`model.ts`'s `class-ref`), and listing that shape's fields
510
+ * read members the struct does not have. And with a base class, the base's
511
+ * fields are created first while the shape lists the derived class's own
512
+ * first. Each of those is a run-time or chain-order fact the struct's own
513
+ * field dispatcher already answers (`nativeEnumerableStringKeys`), which is
514
+ * how `keys` enumerates every shared object, so only a class with no base,
515
+ * no subclass and its own instance shape keeps the static list.
516
+ */
517
+ const classOwnKeysAreStatic = (ctx, representation) => {
518
+ if (representation.kind !== 'class-ref')
519
+ return true;
520
+ if (representation.ancestors.length > 0 || representation.nativeBase !== undefined)
521
+ return false;
522
+ const layout = ctx.classes.get(representation.declaration);
523
+ const instance = layout?.instance;
524
+ if (layout === undefined || layout.base !== null || instance === null || instance === undefined)
525
+ return false;
526
+ if (!('shapeId' in instance) || instance.shapeId !== representation.shapeId)
527
+ return false;
528
+ for (const other of ctx.classes.values())
529
+ if (other.base === representation.declaration)
530
+ return false;
531
+ return true;
532
+ };
533
+ /**
534
+ * The runtime walk is the only arm a class instance gets, and without the
535
+ * struct's property protocol it answers false and copies nothing -- an empty
536
+ * array where the instance has keys. Stated to the C++ compiler, so that case
537
+ * cannot build at all.
538
+ */
539
+ const classWalkProtocolAssertion = (view) => `static_assert(gea::detail::NativeFieldTable<typename std::remove_cvref_t<decltype(${view.receiver})>::element_type>, ` +
540
+ '"the own properties of a class instance are walked through its property protocol");';
541
+ const refuseClassInstanceWalk = (member, representation) => {
542
+ throw createCppEmitBlockedError(`host-member-call:Object.${member}`, `"Object.${member}" of a "${representationKey(representation)}" handle enumerates whatever class the instance really is, ` +
543
+ "which only the runtime's creation-order walk can see, and no conversion from its dynamic values into this call's " +
544
+ 'result was admitted for that walk');
545
+ };
546
+ const creationOrderedOwnCopyText = (ctx, view, destination, each, assigned = null, always = false) => {
480
547
  const indexed = indexedRecordViewOf(ctx.deriver, view.representation);
481
548
  const ownership = indexed !== null ? indexed.ownership : ownershipOfGeneratedCarrier(view.representation);
482
549
  if (ownership !== 'shared-refcount')
@@ -506,7 +573,7 @@ const creationOrderedOwnCopyText = (ctx, view, destination, each, assigned = nul
506
573
  return (`gea::${assigned.orderless === true ? 'assignOwnPropertiesUnorderedWith' : 'assignOwnPropertiesInCreationOrderWith'}(${view.receiver}, ${assigned.target}, ` +
507
574
  `[&](const std::string& __gea_ordered_key, const gea::Value& __gea_ordered_value) { ${body} }, ${assigned.staticCopy})`);
508
575
  return (`gea::copyOwnPropertiesInCreationOrder(${view.receiver}, ` +
509
- `[&](const std::string& __gea_ordered_key, const gea::Value& __gea_ordered_value) { ${body} }${indexed !== null ? ', true' : ''})`);
576
+ `[&](const std::string& __gea_ordered_key, const gea::Value& __gea_ordered_value) { ${body} }${indexed !== null || always ? ', true' : ''})`);
510
577
  };
511
578
  /**
512
579
  * A property key argument, as `gea::PropertyKey`.
@@ -110,6 +110,10 @@ export const coreHostMembers = new Map([
110
110
  // than a second severity: a server adapter writes one on the recoverable
111
111
  // client-abort path and refused by name until it existed.
112
112
  ['Console.info', { kind: 'method', emit: 'gea::host::console::info({args})', arity: 'variadic' }],
113
+ // `console.warn` writes what `console.error` writes, to stderr (see the
114
+ // runtime's `warn` overloads). An app's recoverable load-failure paths call
115
+ // it, and each call refused by name until this row existed.
116
+ ['Console.warn', { kind: 'method', emit: 'gea::host::console::warn({args})', arity: 'variadic' }],
113
117
  // `localStorage`. `gea::host::storage` is a singleton table rather than a
114
118
  // per-handle one, so no template here names a `{receiver}`.
115
119
  ['Storage.getItem', { kind: 'method', emit: 'gea::host::storage::getItem({arg0})', arity: 1 }],
@@ -44,6 +44,48 @@ import { type EmitContext } from '../emit-context.js';
44
44
  */
45
45
  /** The one signature every member's renderer has. `element` is the receiver's own element carrier; `result` is read by the members whose ECMA-262 result can be `undefined`. */
46
46
  export type ArrayCallRenderer = (ctx: EmitContext, receiverText: string, element: Representation, args: readonly IrOperand[], result: IrResult | null, operation?: CallOperation) => string;
47
+ /**
48
+ * The callback, as the runtime's per-element call can invoke it.
49
+ *
50
+ * `gea::runtime::array`'s `mapCall` (and its siblings) hand the callable the
51
+ * element AS the element's own C++ type, at whichever arity the callable takes.
52
+ * That is exact while the callback's first parameter IS the element carrier. A
53
+ * callback declared WIDER than the element -- `nums.map(label)` with `label:
54
+ * (x: number | string) => string`, or `pairs.map(([[, value]]) => value)` over
55
+ * a union of two tuple-array arms, whose parameter is the union of the two arms' tuple elements
56
+ * while each arm's array holds exactly one of them -- is a call whose argument
57
+ * needs the conversion any direct call renders at its call site, except that
58
+ * this call site is inside the runtime template. C++ does not perform it:
59
+ * `gea::TaggedUnion` has no converting constructor (arm injection is
60
+ * `ofArm<i>`, spelled by the emitter), so `is_invocable` fails at every arity
61
+ * and the template falls through to its last resort and does not compile --
62
+ * an error at the C++ step, after certification, about a program this backend
63
+ * had already accepted.
64
+ *
65
+ * So the conversion is rendered here, at the one boundary the emitter owns: a
66
+ * lambda of EXACTLY the callback's own arity that converts the element into
67
+ * the first parameter's carrier through `alignedValueText` -- the one authority
68
+ * on which pairs convert -- and forwards the index and the array untouched.
69
+ * Exactly the arity, never a variadic forwarder: `mapCall` picks its call by
70
+ * `is_invocable`, and a lambda that accepted anything would be picked at the
71
+ * three-argument arity and then fail to call a one-parameter callback inside
72
+ * its own body. The callable is init-captured by value so an rvalue callback
73
+ * expression is evaluated once, not once per element.
74
+ *
75
+ * Untouched when the first parameter already carries the element -- the text
76
+ * is exactly what it was, so nothing that emitted before moves -- and untouched
77
+ * for a callable that is not a `function-value-dispatch` or that declares a
78
+ * receiver, which the runtime passes `Undefined{}` for ahead of the element.
79
+ * Refused BY NAME when the pair has no conversion, when the index or array
80
+ * parameter is not the one the runtime hands over, or when the callback is
81
+ * variadic: a refusal at emission is the fail-closed answer the C++ error was
82
+ * standing in for.
83
+ *
84
+ * `Array.from`'s mapper crosses the same boundary inside `fromCall`, which
85
+ * hands it `(kValue, k)` and no array (23.1.2.1), so `handsArray` is false
86
+ * there and a third parameter is refused rather than declared.
87
+ */
88
+ export declare const elementAdaptedCallbackText: (ctx: EmitContext, member: string, clause: string, element: Representation, callback: IrOperand, result?: IrResult | null, operation?: CallOperation, handsArray?: boolean) => string;
47
89
  /** `emit-carrier-members.ts`'s `arrayAccessText` defers exactly these keys off an `array-object` receiver -- one authority for "is this method implemented". */
48
90
  export declare const arrayMethods: ReadonlyMap<string, ArrayCallRenderer>;
49
91
  /**
@@ -1,6 +1,7 @@
1
1
  import { arrayBulkAppendMethodName } from '../../../representation/prototype-domains.js';
2
2
  export { arrayBulkAppendMethodName, arrayPrototypeMethods } from '../../../representation/prototype-domains.js';
3
3
  import { operationConversionText } from '../emit-certified-conversion.js';
4
+ import { storedCarrier } from '../../../representation/primitives.js';
4
5
  import { representationKey } from '../../../representation/model.js';
5
6
  import { createCppEmitBlockedError, cppThunkName, operandText } from '../emit-context.js';
6
7
  import { alignedValueText } from '../emit-narrowing.js';
@@ -124,17 +125,19 @@ const bulkInsertText = (member, clause, spelling) => (ctx, receiverText, element
124
125
  * missing feature.
125
126
  *
126
127
  * The result's element type is the callback's own return type, deduced in the
127
- * runtime template rather than spelled here: the emitter would have to
128
- * re-derive it from the plan's carrier for the call's result, which is a
129
- * second authority for a fact the C++ type system already holds exactly.
128
+ * runtime template rather than spelled here. That equals the plan's element
129
+ * only while the callback's carrier is the checker's `U`. A JavaScript closure
130
+ * over a parameter narrowed from its call sites returns a narrower carrier
131
+ * than the `any` the checker gave `U`, so `map` converts each result through
132
+ * its certified `prototype-result` recipe (`elementAdaptedCallbackText`).
130
133
  */
131
- const callbackMethodText = (member, clause) => (ctx, receiverText, _element, args) => {
134
+ const callbackMethodText = (member, clause) => (ctx, receiverText, _element, args, result, operation) => {
132
135
  const callback = args[0];
133
136
  if (args.length !== 1 || !callback) {
134
137
  throw createCppEmitBlockedError(`runtime-helper:element:${member}:${elementKey(_element)}`, `"Array.prototype.${member}" is spelled for its one callback argument (ECMA-262 ${clause}); this call passes ${args.length}` +
135
138
  (args.length > 1 ? `, and ECMA-262 ${clause}'s second parameter is a thisArg a CallableObject has nothing to bind` : ''));
136
139
  }
137
- return `gea::runtime::array::${member}(${receiverText}, ${elementAdaptedCallbackText(ctx, member, clause, _element, callback)})`;
140
+ return `gea::runtime::array::${member}(${receiverText}, ${elementAdaptedCallbackText(ctx, member, clause, _element, callback, result, operation)})`;
138
141
  };
139
142
  /**
140
143
  * The callback, as the runtime's per-element call can invoke it.
@@ -172,23 +175,34 @@ const callbackMethodText = (member, clause) => (ctx, receiverText, _element, arg
172
175
  * parameter is not the one the runtime hands over, or when the callback is
173
176
  * variadic: a refusal at emission is the fail-closed answer the C++ error was
174
177
  * standing in for.
178
+ *
179
+ * `Array.from`'s mapper crosses the same boundary inside `fromCall`, which
180
+ * hands it `(kValue, k)` and no array (23.1.2.1), so `handsArray` is false
181
+ * there and a third parameter is refused rather than declared.
175
182
  */
176
- const elementAdaptedCallbackText = (ctx, member, clause, element, callback) => {
183
+ export const elementAdaptedCallbackText = (ctx, member, clause, element, callback, result, operation, handsArray = true) => {
177
184
  const text = operandText(ctx, callback);
178
185
  const carrier = callback.representation;
179
186
  if (carrier.kind !== 'function-value-dispatch' || carrier.abi.receiver !== null)
180
187
  return text;
181
188
  const [first, index, array, ...beyond] = carrier.abi.parameters;
182
189
  const adaptsElement = first !== undefined && representationKey(first.value) !== representationKey(element);
183
- const adaptsResult = predicateMembers.has(member) && representationKey(carrier.abi.result) !== 'scalar(boolean)';
190
+ const produced = storedCarrier(carrier.abi.result);
191
+ const minted = member === 'map' && result?.representation.kind === 'array-object' ? result.representation.element : null;
192
+ const mapped = minted !== null && representationKey(minted) !== representationKey(produced) ? minted : null;
193
+ const adaptsResult = (predicateMembers.has(member) && representationKey(carrier.abi.result) !== 'scalar(boolean)') || mapped !== null;
184
194
  if (!adaptsElement && !adaptsResult)
185
195
  return text;
186
196
  const refuse = (detail) => {
187
- throw createCppEmitBlockedError(`runtime-helper:callback:${member}:${elementKey(element)}`, `"Array.prototype.${member}" (ECMA-262 ${clause}) hands its callback the receiver's element "${elementKey(element)}" and the callback's ` +
188
- `first parameter carries "${first ? representationKey(first.value) : 'nothing'}"; ${detail}`);
197
+ throw createCppEmitBlockedError(`runtime-helper:callback:${member}:${elementKey(element)}`, (handsArray
198
+ ? `"Array.prototype.${member}" (ECMA-262 ${clause}) hands its callback the receiver's element`
199
+ : `"Array.${member}" (ECMA-262 ${clause}) hands its callback the source's element`) +
200
+ ` "${elementKey(element)}" and the callback's first parameter carries "${first ? representationKey(first.value) : 'nothing'}"; ${detail}`);
189
201
  };
190
202
  if (carrier.abi.restFrom !== null || beyond.length > 0)
191
203
  refuse('a callback with more parameters than element, index and array has no runtime call shape');
204
+ if (array && !handsArray)
205
+ refuse('a callback with more parameters than element and index has no runtime call shape');
192
206
  const converted = !first
193
207
  ? null
194
208
  : adaptsElement
@@ -217,6 +231,14 @@ const elementAdaptedCallbackText = (ctx, member, clause, element, callback) => {
217
231
  const call = `__gea_fn(${actuals.join(', ')})`;
218
232
  if (!adaptsResult)
219
233
  return `[__gea_fn = ${text}](${formals.join(', ')}) { return ${call}; }`;
234
+ if (mapped !== null) {
235
+ const stored = carrier.abi.result.kind === 'void' ? `(${call}, gea::Undefined{})` : call;
236
+ const converted = operation ? operationConversionText(ctx, operation, 'prototype-result', produced, mapped, '__gea_mapped') : null;
237
+ if (converted === null)
238
+ throw createCppEmitBlockedError(`runtime-helper:callback:${member}:${elementKey(element)}`, `"Array.prototype.${member}" (ECMA-262 ${clause}) stores its callback's "${representationKey(produced)}" into an array of ` +
239
+ `"${representationKey(mapped)}", and the call cites no conversion between them`);
240
+ return `[__gea_fn = ${text}](${formals.join(', ')}) -> ${cppTypeOf(mapped)} { auto __gea_mapped = ${stored}; return ${converted}; }`;
241
+ }
220
242
  // A predicate member's step "If ToBoolean(testResult) is true" (23.1.3.8
221
243
  // step 5.c.iii and its siblings): the callback may return anything --
222
244
  // `names.filter(m => m.match(re))` returns a match or `null`
@@ -256,6 +256,7 @@ export declare const enumerationOrdered: <T>(entries: readonly T[], keyOf: (entr
256
256
  * this file did not name is left exactly as written.
257
257
  */
258
258
  export declare const withUnreadParametersUnnamed: (declaration: string, body: readonly string[]) => string;
259
+ export declare const switchedByKeyLength: (body: readonly string[]) => readonly string[];
259
260
  /**
260
261
  * The C++ storage one field of this struct occupies.
261
262
  *
@@ -14,6 +14,7 @@ import { dynamicFieldConversionOwnerOf, programConversionKey, prototypeSetterVal
14
14
  import { recordLayoutPolicyOf, recordLayoutOfShapeId } from '../../projection/fields.js';
15
15
  import { classIndexProtocolsOf } from '../../projection/index-protocols.js';
16
16
  import { nativeAccessorAccessOf } from '../../projection/native-accessor-access.js';
17
+ import { classAccessorShadowedFieldKeysOf } from '../../projection/dispatch.js';
17
18
  /**
18
19
  * The physical Optional carrier does not remember whether its empty state is
19
20
  * JavaScript null or undefined. NativeFieldWrite therefore carries the
@@ -1121,10 +1122,10 @@ const dynamicFieldAccessOf = (field, storageType, isTailField = false, cellPaylo
1121
1122
  };
1122
1123
  };
1123
1124
  const objectFieldWriteLoadText = (layouts, value, access, selected) => {
1124
- if (layouts === undefined || access.tag !== 'Object' || cppTypeOf(value) !== access.type)
1125
+ if (layouts === undefined || (access.tag !== 'Object' && access.tag !== 'Function') || cppTypeOf(value) !== access.type)
1125
1126
  return null;
1126
1127
  const planned = selected?.(access.key, value) ?? null;
1127
- if (planned !== null)
1128
+ if (planned !== null || access.tag === 'Function')
1128
1129
  return planned;
1129
1130
  if (withoutUnitFunctions(() => dynamicValueLoadText(layouts, value, 'gea_value')) === null)
1130
1131
  return null;
@@ -1443,7 +1444,7 @@ const keyByteLengthOfBranch = (line) => {
1443
1444
  * it skips.
1444
1445
  */
1445
1446
  const switchedKeyBranches = 6;
1446
- const switchedByKeyLength = (body) => {
1447
+ export const switchedByKeyLength = (body) => {
1447
1448
  const out = [];
1448
1449
  let run = [];
1449
1450
  const flush = () => {
@@ -1513,7 +1514,14 @@ virtualDeclarations = new Map(),
1513
1514
  /** The program's record layouts, which name the checked conversion a boxed write into an object-carrying field takes (`objectFieldWriteLoadText`). */
1514
1515
  layouts = undefined,
1515
1516
  /** Filled with every field operation a sealed demand names whose arm can only refuse -- see `record` below. */
1516
- unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPayloadTypeOf = () => undefined) => {
1517
+ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPayloadTypeOf = () => undefined,
1518
+ /**
1519
+ * Keys this class's own accessors redeclare over an inherited data field
1520
+ * (`classAccessorShadowedFieldKeysOf`). OrdinaryGet/OrdinarySet on such an
1521
+ * instance reach the prototype accessor, so the base slot answers for none
1522
+ * of its own-property hooks.
1523
+ */
1524
+ shadowedKeys = []) => {
1517
1525
  // A write through the property protocol that creates a declared field of a
1518
1526
  // record creates its key now, after every key already present, the same
1519
1527
  // fact a static store states (`declaredFieldCreationText`). A class's
@@ -2276,6 +2284,9 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2276
2284
  // (the literal's is folded at compile time) before it touches memory: a
2277
2285
  // 134-field options record answered a miss with 134 `strlen`+`memcmp`s.
2278
2286
  body.length > 0 ? [' const std::string_view gea_name = gea_key.text();'] : [];
2287
+ const shadows = shadowedKeys
2288
+ .filter((key) => !cppRecordFieldKeyIsSymbol(key))
2289
+ .map((key) => ` if (gea_name == ${cppStringLiteral(key)}) return false;`);
2279
2290
  const accessorDescriptors = descriptors.slice(dataDescriptorCount);
2280
2291
  const accessorReads = reads.slice(dataReadCount);
2281
2292
  // A group of ONE is not a group: its block spends a slot declaration and a
@@ -2373,14 +2384,16 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2373
2384
  // This struct's declared fields, as a boxed `gea::Value` reads them. `false` means the struct does not declare the key, which sends it to the box's expando table.
2374
2385
  ...classMember('bool gea_ownFieldPresent(const gea::PropertyKey& gea_key, bool& gea_out) const', [
2375
2386
  ...symbolBranchFor('gea_ownFieldPresent(gea_key, gea_out)', true),
2376
- ...nameOf(presentFields),
2387
+ ...nameOf([...shadows, ...presentFields]),
2388
+ ...shadows,
2377
2389
  ...viaTable(presentFields, 'if (gea::detail::nativeOwnFieldPresent(*this, gea_name, gea_out)) return true;'),
2378
2390
  ...(base && !base.native ? [` if (this->${base.structName}::gea_ownFieldPresent(gea_key, gea_out)) return true;`] : []),
2379
2391
  ' return false;'
2380
2392
  ]),
2381
2393
  ...classMember('bool gea_ownFieldEnumerable(const gea::PropertyKey& gea_key, bool& gea_out) const', [
2382
2394
  ...symbolBranchFor('gea_ownFieldEnumerable(gea_key, gea_out)', true),
2383
- ...nameOf(enumerableFields),
2395
+ ...nameOf([...shadows, ...enumerableFields]),
2396
+ ...shadows,
2384
2397
  ...viaTable(enumerableFields, 'if (gea::detail::nativeOwnFieldEnumerable(*this, gea_name, gea_out)) return true;'),
2385
2398
  ...(base && !base.native ? [` if (this->${base.structName}::gea_ownFieldEnumerable(gea_key, gea_out)) return true;`] : []),
2386
2399
  ' return false;'
@@ -2397,7 +2410,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2397
2410
  ]),
2398
2411
  ...dynamicMember('bool gea_readOwnField(const gea::PropertyKey& gea_key, gea::Value& gea_out) const', [
2399
2412
  ...symbolBranchFor('gea_readOwnField(gea_key, gea_out)'),
2400
- ...nameOf(reads),
2413
+ ...nameOf([...shadows, ...reads]),
2414
+ ...shadows,
2401
2415
  ...readGroupBlocks,
2402
2416
  ...ungroupedDataReads,
2403
2417
  ...accessorReads,
@@ -2406,7 +2420,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2406
2420
  ]),
2407
2421
  ...dynamicMember('bool gea_readOwnFieldNative(const gea::PropertyKey& gea_key, gea::NativeFieldRead& gea_out) const', [
2408
2422
  ...symbolBranchFor('gea_readOwnFieldNative(gea_key, gea_out)', true),
2409
- ...nameOf([...nativeReads, ...accessors.map((accessor) => accessor.key)]),
2423
+ ...nameOf([...shadows, ...nativeReads, ...accessors.map((accessor) => accessor.key)]),
2424
+ ...shadows,
2410
2425
  ...nativeReads,
2411
2426
  // A demand without an actual getter ABI cannot name a native leaf.
2412
2427
  // An accessor still shadows a base data field of the same name.
@@ -2415,7 +2430,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2415
2430
  ]),
2416
2431
  ...nativeIndexMember('bool gea_writeOwnFieldNative(const gea::PropertyKey& gea_key, const gea::NativeFieldWrite& gea_value, bool gea_extensible = true)', [
2417
2432
  ...symbolBranchFor('gea_writeOwnFieldNative(gea_key, gea_value, gea_extensible)', true),
2418
- ...nameOf([...nativeFieldWrites, ...accessors.map((accessor) => accessor.key)]),
2433
+ ...nameOf([...shadows, ...nativeFieldWrites, ...accessors.map((accessor) => accessor.key)]),
2434
+ ...shadows,
2419
2435
  ...nativeFieldWrites,
2420
2436
  ...accessors.map((accessor) => ` if (gea_name == ${cppStringLiteral(accessor.key)}) return false;`),
2421
2437
  ...(base && !base.native
@@ -2427,7 +2443,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2427
2443
  // Descriptor hooks belong to generated bases, just like the text-key chain
2428
2444
  // below. A native base's field reader is not a descriptor hook.
2429
2445
  ...symbolBranchFor('gea_ownFieldDescriptor(gea_key, gea_out)', true),
2430
- ...nameOf(descriptorsComposed ? [...descriptorAttributes, ...accessorDescriptors] : descriptors),
2446
+ ...nameOf([...shadows, ...(descriptorsComposed ? [...descriptorAttributes, ...accessorDescriptors] : descriptors)]),
2447
+ ...shadows,
2431
2448
  ...(descriptorsComposed
2432
2449
  ? [
2433
2450
  ...(descriptorAttributes.length === 0
@@ -2460,7 +2477,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2460
2477
  // The same, for a write. A declared field is written IN PLACE, so every native read of it sees the change.
2461
2478
  ...dynamicMember('bool gea_writeOwnField(const gea::PropertyKey& gea_key, const gea::Value& gea_value, bool gea_extensible = true)', [
2462
2479
  ...symbolBranchFor('gea_writeOwnField(gea_key, gea_value, gea_extensible)'),
2463
- ...nameOf(writes),
2480
+ ...nameOf([...shadows, ...writes]),
2481
+ ...shadows,
2464
2482
  ...writes,
2465
2483
  ...baseWrite,
2466
2484
  ' return false;'
@@ -2468,7 +2486,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2468
2486
  // ValidateAndApplyPropertyDescriptor for a fixed native data property.
2469
2487
  ...nativeIndexMember('bool gea_defineOwnField(const gea::PropertyKey& gea_key, const gea::PropertyDescriptor& gea_descriptor, bool gea_extensible = true)', [
2470
2488
  ...symbolBranchFor('gea_defineOwnField(gea_key, gea_descriptor, gea_extensible)', true),
2471
- ...nameOf(defines),
2489
+ ...nameOf([...shadows, ...defines]),
2490
+ ...shadows,
2472
2491
  ...defines,
2473
2492
  ...(base && !base.native
2474
2493
  ? [
@@ -2481,7 +2500,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2481
2500
  // A field may be declared by the native layout but currently absent after delete.
2482
2501
  ...nativeIndexMember('bool gea_matchesOwnField(const gea::PropertyKey& gea_key) const', [
2483
2502
  ...symbolBranchFor('gea_matchesOwnField(gea_key)', true),
2484
- ...nameOf(matches),
2503
+ ...nameOf([...shadows, ...matches]),
2504
+ ...shadows,
2485
2505
  ...viaTable(matches, 'if (gea::detail::nativeOwnFieldMatches(*this, gea_name)) return true;'),
2486
2506
  ...baseMatches,
2487
2507
  ' return false;'
@@ -2495,7 +2515,8 @@ unaddressableDemands = undefined, indexProtocol = true, dynamicFieldLoad, cellPa
2495
2515
  // OrdinaryDelete for one declared data property; false preserves a non-configurable field.
2496
2516
  ...nativeIndexMember('bool gea_deleteOwnField(const gea::PropertyKey& gea_key)', [
2497
2517
  ...symbolBranchFor('gea_deleteOwnField(gea_key)', true),
2498
- ...nameOf(deletes),
2518
+ ...nameOf([...shadows, ...deletes]),
2519
+ ...shadows,
2499
2520
  ...viaTable(deletes, 'if (const std::optional<bool> gea_deleted = gea::detail::nativeDeleteOwnField(*this, gea_name)) return *gea_deleted;'),
2500
2521
  ...baseDelete,
2501
2522
  ' return false;'
@@ -3156,7 +3177,9 @@ attributesConstant = false,
3156
3177
  * exactly once (`immortalMethodStateRoots`): its per-instance method-state
3157
3178
  * handle is then not an edge the collector follows -- see there.
3158
3179
  */
3159
- methodStateUntraced = false, indexProtocol = true, dynamicFieldLoad) => {
3180
+ methodStateUntraced = false, indexProtocol = true, dynamicFieldLoad,
3181
+ /** See `renderFieldDispatcher`'s parameter of the same name. */
3182
+ shadowedKeys = []) => {
3160
3183
  const isNarrowed = (field) => narrowedSlots.has(integerStorageSlot(structName, field.key));
3161
3184
  // A class keeps every field inline. Its fields are stored by the
3162
3185
  // constructor views, the property-store emitter and callable frames, which
@@ -3392,7 +3415,7 @@ methodStateUntraced = false, indexProtocol = true, dynamicFieldLoad) => {
3392
3415
  lines.push(' }');
3393
3416
  }
3394
3417
  const unaddressableDemands = [];
3395
- for (const line of renderFieldDispatcher(structName, classDispatch ? reflectedClassLayout(layout) : layout, base?.hookless ? undefined : base, classDispatch, (field) => fieldStorageType(field, reactive, celled, isNarrowed(field)), tailFields, wellKnownSymbols, definitions, dynamicProtocol, fieldOperations, accessorCarriesEnvironment, isFinal && base === undefined, lazyArrowFields, virtualDeclarations, layouts, unaddressableDemands, indexProtocol, dynamicFieldLoad, (field) => fieldCellPayloadType(field, reactive, celled, isNarrowed(field))))
3418
+ for (const line of renderFieldDispatcher(structName, classDispatch ? reflectedClassLayout(layout) : layout, base?.hookless ? undefined : base, classDispatch, (field) => fieldStorageType(field, reactive, celled, isNarrowed(field)), tailFields, wellKnownSymbols, definitions, dynamicProtocol, fieldOperations, accessorCarriesEnvironment, isFinal && base === undefined, lazyArrowFields, virtualDeclarations, layouts, unaddressableDemands, indexProtocol, dynamicFieldLoad, (field) => fieldCellPayloadType(field, reactive, celled, isNarrowed(field)), shadowedKeys))
3396
3419
  lines.push(line);
3397
3420
  if (unaddressableDemands.length > 0)
3398
3421
  return {
@@ -3730,7 +3753,7 @@ conversionSite) => {
3730
3753
  !links.has(structName) &&
3731
3754
  !baseStructNames.has(structName) &&
3732
3755
  [...(shapesByStruct.get(structName) ?? [])].every((shapeId) => !recordShapeRestricted(shapeId, layout.fields.some((field) => cppRecordFieldKeyIsSymbol(field.key)))) &&
3733
- (shapesByStruct.get(structName)?.size ?? 0) > 0, immortalStateRoots.has(structName), declaration === undefined ? layout.indexes.length > 0 : classIndexProtocols.get(declaration) !== false, dynamicFieldLoad);
3756
+ (shapesByStruct.get(structName)?.size ?? 0) > 0, immortalStateRoots.has(structName), declaration === undefined ? layout.indexes.length > 0 : classIndexProtocols.get(declaration) !== false, dynamicFieldLoad, declaration === undefined ? [] : classAccessorShadowedFieldKeysOf(classes, declaration));
3734
3757
  });
3735
3758
  const refused = rendered.filter((entry) => typeof entry !== 'string');
3736
3759
  if (refused.length > 0)