@geastack/compiler 1.0.42 → 1.0.43

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 (44) hide show
  1. package/dist/conversion/nodes.js +5 -2
  2. package/dist/ir/certify.js +1 -1
  3. package/dist/ir/host-template-conversions.d.ts +2 -2
  4. package/dist/ir/host-template-conversions.js +73 -2
  5. package/dist/ir/lower-destructuring.js +22 -3
  6. package/dist/ir/lower-operands.js +24 -0
  7. package/dist/ir/native-field-view-facts.d.ts +8 -1
  8. package/dist/ir/native-field-view-facts.js +13 -3
  9. package/dist/ir/operation-conversions.js +1 -1
  10. package/dist/ir/program-conversions.d.ts +1 -1
  11. package/dist/ir/program-conversions.js +68 -1
  12. package/dist/ir/property-read-conversions.js +7 -1
  13. package/dist/ir/publish-native-field-view-facts.js +4 -0
  14. package/dist/ir/reflection-demand.js +29 -3
  15. package/dist/projection/dispatch.d.ts +19 -1
  16. package/dist/projection/dispatch.js +34 -0
  17. package/dist/representation/value-records.js +182 -13
  18. package/dist/semantics/normalize/collection-bindings.d.ts +7 -0
  19. package/dist/semantics/normalize/collection-bindings.js +35 -1
  20. package/dist/semantics/normalize/derived-expression-type.js +49 -0
  21. package/dist/semantics/normalize/field-bindings.js +6 -1
  22. package/dist/semantics/normalize/flow/source-value-session.d.ts +9 -2
  23. package/dist/semantics/normalize/flow/source-value-session.js +538 -94
  24. package/dist/semantics/normalize/local-bindings.js +23 -1
  25. package/dist/semantics/normalize/producers/references.js +26 -18
  26. package/dist/semantics/normalize/structural-array-element.d.ts +7 -0
  27. package/dist/semantics/normalize/structural-array-element.js +24 -1
  28. package/dist/semantics/normalize/structural-layout-type.js +5 -1
  29. package/dist/semantics/normalize/structural-parts.js +13 -8
  30. package/dist/semantics/normalize/structural.js +25 -1
  31. package/dist/targets/cpp/class-properties/emit-class-properties.js +5 -1
  32. package/dist/targets/cpp/emit-callable.js +19 -10
  33. package/dist/targets/cpp/emit-native-field-view.d.ts +2 -0
  34. package/dist/targets/cpp/emit-native-field-view.js +1 -1
  35. package/dist/targets/cpp/emit-properties.js +114 -12
  36. package/dist/targets/cpp/host/emit-host-invoke.js +16 -2
  37. package/dist/targets/cpp/host/host-members.js +4 -0
  38. package/dist/targets/cpp/prototype/emit-prototype-array.d.ts +42 -0
  39. package/dist/targets/cpp/prototype/emit-prototype-array.js +31 -9
  40. package/dist/targets/cpp/records.js +39 -16
  41. package/dist/targets/cpp/translation-unit.js +23 -2
  42. package/package.json +1 -1
  43. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +17 -1
  44. package/src/targets/cpp/runtime/gea_runtime.h +298 -51
@@ -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`
@@ -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;
@@ -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)
@@ -43,7 +43,7 @@ import { classesConstructedUnobservably, functionsIgnoringTheirReceiver } from '
43
43
  import { renderJsonStructDeclarations } from './emit-json.js';
44
44
  import { programConversionText } from './emit-narrowing.js';
45
45
  import { recordLayoutPolicyOf } from '../../projection/fields.js';
46
- import { cppAbiParameterType, cppAbiType, cppStringLiteral, cppBodyName, cppCallableDeclarationTagName, cppCommonJsModuleName, cppCommonJsRecordName, cppNarrowedIntegerType, cppRefcountedReceiver, cppBoxedType, cppClassName, cppConstructName, cppGlobalName, cppInitializeName, cppRecordFieldName, cppRecordStructName, cppResultTypeOf, cppTypeOf, publishNarrowedStorageSlots, sanitizeForCppIdentifier } from './types.js';
46
+ import { cppAbiParameterType, cppAbiType, cppStringLiteral, cppBodyName, cppCallableDeclarationTagName, cppCommonJsModuleName, cppCommonJsRecordName, cppNarrowedIntegerType, cppRefcountedReceiver, cppBoxedType, cppClassName, cppConstructName, cppGlobalName, cppInitializeName, cppRecordFieldName, cppRecordStructName, cppResultTypeOf, cppTypeOf, publishNarrowedStorageSlots, sanitizeForCppIdentifier, unitFunctionName } from './types.js';
47
47
  import { buildHostMethodAliasIndex } from './host/host-method-aliases.js';
48
48
  import { constructionOnlyFieldsOf, reflectiveFieldWritesOf } from '../../ir/construction-only-fields.js';
49
49
  import { cppRecursiveContainerDeclarations, cppRecursiveContainerTraceEdges } from './recursive-containers.js';
@@ -2185,7 +2185,27 @@ const renderTranslationUnitSession = (input) => {
2185
2185
  const unionAliasMarker = '// gea-union-aliases';
2186
2186
  const unitFunctionMarker = '// gea-unit-functions';
2187
2187
  const unitFunctionLinkage = perFile ? 'inline ' : '[[maybe_unused]] static ';
2188
+ // A boxed frame's record argument of another layout is read through the
2189
+ // certified live view (`dynamic-call-argument`, gea_runtime.h's
2190
+ // `DynamicArgumentView`). Each reader is a unit function, recorded while
2191
+ // the session is open and named by address, which needs only its
2192
+ // declaration: the struct it returns is incomplete where the hook is.
2193
+ const dynamicArgumentViews = () => (input.programConversionRecipes ?? []).flatMap((recipe) => {
2194
+ if (recipe.role !== 'dynamic-call-argument' || !('shapeId' in recipe.target))
2195
+ return [];
2196
+ const { role, owner, slot, source, target } = recipe;
2197
+ const load = programConversionText(programSite, role, owner, slot, source, target, 'gea_value');
2198
+ const name = unitFunctionName('gea_dynamic_argument', (named) => `${cppTypeOf(target)} ${named}(const gea::Value& gea_value)`, `return ${load};`);
2199
+ if (name === null)
2200
+ throw createCppEmitBlockedError('runtime-helper:program-conversion-recipes', `${owner} has no unit for its argument view`);
2201
+ const qualifier = isolate && namespaceName !== null ? `${namespaceName}::` : '';
2202
+ const struct = `${qualifier}${cppRecordStructName(target.shapeId)}`;
2203
+ return [
2204
+ `template <> struct DynamicArgumentView<${struct}> { static constexpr bool installed = true; static constexpr auto in = &${qualifier}${name}; };`
2205
+ ];
2206
+ });
2188
2207
  const spliceUnionAliases = (source) => {
2208
+ const argumentViews = dynamicArgumentViews();
2189
2209
  const { aliases, functions } = endUnionAliasing();
2190
2210
  const forwards = [...recursiveContainers, ...structs.declarations, ...jsonStructs.declarations].filter((declaration) => declaration.startsWith('struct ') && declaration.endsWith(';') && !declaration.includes('{'));
2191
2211
  // Spelled after the alias session ends, so each is its full type.
@@ -2194,12 +2214,13 @@ const renderTranslationUnitSession = (input) => {
2194
2214
  ...forwards,
2195
2215
  ...aliases.map(({ name, spelling }) => `using ${name} = ${spelling};`),
2196
2216
  ...functions.map(({ signature }) => `${unitFunctionLinkage}${signature};`),
2197
- ...(omitted.length === 0
2217
+ ...(omitted.length === 0 && argumentViews.length === 0
2198
2218
  ? []
2199
2219
  : [
2200
2220
  ...(isolate ? [namespaceClose] : []),
2201
2221
  'namespace gea::detail {',
2202
2222
  ...omitted.map((type) => `template <> inline constexpr bool dynamicProtocolOmitted<${type}> = true;`),
2223
+ ...argumentViews,
2203
2224
  '} // namespace gea::detail',
2204
2225
  ...(isolate ? [namespaceOpen] : [])
2205
2226
  ])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/compiler",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -361,7 +361,7 @@ inline Value dynamicStringPrototypeGet(const PropertyKey& key) {
361
361
  static const std::map<std::string, Value> methods = [] {
362
362
  std::map<std::string, Value> result;
363
363
  for (const char* name : {"toLowerCase", "toUpperCase", "toLocaleLowerCase", "toLocaleUpperCase", "trim", "trimStart", "trimEnd",
364
- "toString", "valueOf", "includes", "startsWith", "endsWith", "indexOf", "slice", "charAt"}) {
364
+ "toString", "valueOf", "includes", "startsWith", "endsWith", "indexOf", "slice", "charAt", "replace"}) {
365
365
  auto callable = Method(+[](void* environment, Value receiver, Args args) -> Value {
366
366
  alignas(void*) unsigned char slot[sizeof(void*)];
367
367
  const std::string& method = *gea::unpackEnvironment<std::string>(environment, slot);
@@ -384,6 +384,22 @@ inline Value dynamicStringPrototypeGet(const PropertyKey& key) {
384
384
  if (method == "toString" || method == "valueOf") return string(text);
385
385
  if (method == "slice") return string(runtime::string::slice(text, position(first, 0.0), position(second, std::numeric_limits<double>::infinity())));
386
386
  if (method == "charAt") return string(runtime::string::charAt(text, position(first, 0.0)));
387
+ if (method == "replace") {
388
+ // ECMA-262 22.1.3.19: a RegExp searchValue replaces through its own
389
+ // @@replace, the walk the typed path renders as `replaceByPattern`;
390
+ // any other searchValue and replaceValue are ToString'd, in that
391
+ // order, into the typed path's string/string `replace`. A callable
392
+ // replaceValue has no boxed-callback arm in either native replace,
393
+ // so it is refused by name rather than ToString'd into a wrong answer.
394
+ if (second.tag() == Value::Tag::Function)
395
+ host::throwRuntimeError("TypeError", "String.prototype.replace through a dynamic receiver does not take a callable replaceValue");
396
+ if (host::instanceOfRegExp(first)) {
397
+ const auto& pattern = detail::unboxAs<Ref<runtime::regex::Pattern>>(first, Value::Tag::Object, "String.prototype.replace's RegExp searchValue");
398
+ return string(runtime::string::replaceByPattern(text, *pattern, dynamicToString(second)));
399
+ }
400
+ const std::string searchValue = dynamicToString(first);
401
+ return string(runtime::string::replace(text, searchValue, dynamicToString(second)));
402
+ }
387
403
  const std::string needle = dynamicToString(first);
388
404
  if (method == "indexOf") return Value::box(Value::Tag::Number, runtime::string::indexOf(text, needle, position(second, 0.0)));
389
405
  if (method == "includes") return Value::box(Value::Tag::Boolean, runtime::string::includes(text, needle, position(second, 0.0)));