@geastack/compiler 1.0.25 → 1.0.26

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.
@@ -172,7 +172,8 @@ valueRepresentation = boundMethodValueRepresentation(operation), receiverText =
172
172
  const heldReceiver = override === null ? receiverText : 'gea_method_receiver';
173
173
  const state = `${heldReceiver}->gea_method_state`;
174
174
  const bodyValue = `gea::nativeClassMethodValue<${cppClassName(owner.declaration)}, &${cppCallableDeclarationTagName(method.callable)}>(${state}, ${payload})`;
175
- const materialized = alignedValueText(ctx, 'class-properties/emit-class-properties.ts:212', bodyRepresentation, valueRepresentation, bodyValue) ??
175
+ const aligned = alignedValueText(ctx, 'class-properties/emit-class-properties.ts:212', bodyRepresentation, valueRepresentation, bodyValue);
176
+ const materialized = aligned ??
176
177
  // The published value declares no receiver while the body's convention
177
178
  // leads with one, so the receiver has to travel WITH the value
178
179
  // (`gea_runtime.h`'s `CallableObject::bindReceiver`). This is the arm half
@@ -196,7 +197,11 @@ valueRepresentation = boundMethodValueRepresentation(operation), receiverText =
196
197
  throw createCppEmitBlockedError(`conversion:${representationKey(bodyRepresentation)}->${representationKey(valueRepresentation)}`, `method "${key}" body convention cannot fill its published bound-method convention`);
197
198
  }
198
199
  const publicAbi = abiOfCallee(valueRepresentation);
199
- const originalValue = publicAbi !== null && abiKey(publicAbi) !== abiKey(bodyAbi)
200
+ // The adapter cache is per class evaluation, so it may only hold a value
201
+ // every instance shares. A receiver-bound value carries THIS read's
202
+ // receiver: cached, the second instance would call the first one's body
203
+ // (two hono `SmartRouter`s, the second matching against the first's routes).
204
+ const originalValue = aligned !== null && publicAbi !== null && abiKey(publicAbi) !== abiKey(bodyAbi)
200
205
  ? `gea::nativeClassAdaptedMethodValue<${cppClassName(owner.declaration)}, &${cppCallableDeclarationTagName(method.callable)}, ${valueType}>(${state}, [&]() { return ${materialized}; })`
201
206
  : materialized;
202
207
  const fallback = nativePrototypeMethodFallbackText(ctx, receiverRepresentation, key, owner, valueRepresentation, heldReceiver, originalValue, dispatchesStatically(ctx, operation.receiver));
@@ -43,11 +43,11 @@ export const emitBindCallable = (ctx, lines, operation) => {
43
43
  if (operation.result.representation.kind !== 'function-value-dispatch') {
44
44
  throw createCppEmitBlockedError('call-abi:bind-callable', 'a bound Function result is not carried as an evaluated function-value dispatch');
45
45
  }
46
- const guarded = operation.unboxedMethod !== undefined && operation.unboxedMethodConfirmed !== true;
46
+ const guarded = (operation.unboxedMethod !== undefined && operation.unboxedMethodConfirmed !== true) || operation.builtinShadowGuard === 'bind';
47
47
  if (guarded && operation.detached !== false) {
48
- throw createCppEmitBlockedError('call-abi:bind-shadowable', `"${operation.unboxedMethod.key}" was bound as the builtin Function.prototype.bind on the assumption that no boxed ` +
48
+ throw createCppEmitBlockedError('call-abi:bind-shadowable', `"${operation.unboxedMethod?.key ?? 'method'}" was bound as the builtin Function.prototype.bind on the assumption that no boxed ` +
49
49
  `value holds its Function object, and the reflection census did not confirm it: an instance, prototype or ` +
50
- `constructor of ${String(operation.unboxedMethod.owner)} or a related class reaches dynamic code, where a ` +
50
+ `constructor of ${String(operation.unboxedMethod?.owner ?? 'its class')} or a related class reaches dynamic code, where a ` +
51
51
  `computed write can shadow "bind"`);
52
52
  }
53
53
  if (operation.detached) {
@@ -90,7 +90,7 @@ export const unionClassMethodValueReceiverClaim = (ctx, operation) => {
90
90
  const key = ctx.staticKeyTexts.get(operation.key.value);
91
91
  if (key === undefined || objectPrototypeMemberNames.has(key))
92
92
  return null;
93
- if (deferredUnionMethodClaim(ctx, operation.receiver, operation.key) !== null)
93
+ if (ctx.unionMethodReads.has(operation.result.id))
94
94
  return null;
95
95
  for (const leaf of unionPropertyLeaves(receiver, '')) {
96
96
  const arm = leaf.representation;
@@ -1193,7 +1193,7 @@ export const taggedUnionGetText = (ctx, lines, operation) => {
1193
1193
  // Recorded by the prototype-read walk, which asked the same claim.
1194
1194
  return '';
1195
1195
  }
1196
- if (deferredUnionMethodClaim(ctx, operation.receiver, operation.key) !== null) {
1196
+ if (ctx.unionMethodReads.has(operation.result.id)) {
1197
1197
  // Recorded by the prototype-read walk's sibling, which asked the same claim.
1198
1198
  return '';
1199
1199
  }
@@ -1610,9 +1610,24 @@ export const unionMemberTypeofReadsOf = (ctx, body) => {
1610
1610
  };
1611
1611
  export const unionMethodReadsOf = (ctx, body) => {
1612
1612
  const reads = new Map();
1613
+ // A claimed read renders nothing and its CALL renders the dispatch, so a
1614
+ // read anything else consumes -- `union.m.bind(union)`, hono's
1615
+ // `router.match.bind(router)` -- keeps the per-arm value walk instead of
1616
+ // naming a value that was never defined.
1617
+ const otherwiseConsumed = new Set();
1618
+ for (const block of body.blocks.values())
1619
+ for (const operation of allOperationsOf(block))
1620
+ for (const operand of operandsOfIrOperation(operation)) {
1621
+ if (operation.kind === 'call' &&
1622
+ operand.value === operation.callee.value &&
1623
+ operation.receiver?.value !== operand.value &&
1624
+ !operation.arguments.some((argument) => argument.value === operand.value))
1625
+ continue;
1626
+ otherwiseConsumed.add(operand.value);
1627
+ }
1613
1628
  for (const block of body.blocks.values()) {
1614
1629
  for (const operation of allOperationsOf(block)) {
1615
- if (operation.kind !== 'get')
1630
+ if (operation.kind !== 'get' || otherwiseConsumed.has(operation.result.id))
1616
1631
  continue;
1617
1632
  const claim = deferredUnionMethodClaim(ctx, operation.receiver, operation.key);
1618
1633
  if (claim !== null)
@@ -2321,12 +2321,14 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
2321
2321
  // The receiver every method-value read keeps for the call that consumes it,
2322
2322
  // asked of the class layout rather than recorded by whichever resolver
2323
2323
  // happened to spell the value.
2324
+ // Union method reads first: whether a read is deferred to its call decides
2325
+ // whether it publishes a receiver for that call to supply.
2326
+ for (const [value, read] of unionMethodReadsOf(ctx, body))
2327
+ prepass.unionMethodReads.set(value, read);
2324
2328
  for (const [value, receiver] of directCallReceiversOf(ctx, body))
2325
2329
  prepass.directCallReceivers.set(value, receiver);
2326
2330
  for (const [value, callee] of virtualCalleesOf(ctx, body))
2327
2331
  prepass.virtualCallees.set(value, callee);
2328
- for (const [value, read] of unionMethodReadsOf(ctx, body))
2329
- prepass.unionMethodReads.set(value, read);
2330
2332
  // A member read nothing but `typeof` consumes, off arms that disagree about
2331
2333
  // the member; the read renders nothing and the `typeof` renders the dispatch.
2332
2334
  for (const [value, read] of unionMemberTypeofReadsOf(ctx, body))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/compiler",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
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": {