@geastack/compiler 1.0.33 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli-coverage.js +2 -4
- package/dist/cli-emit.js +1 -1
- package/dist/cli-module-graph.js +1 -1
- package/dist/cli.js +2 -1
- package/dist/compiler.js +14 -6
- package/dist/conversion/array-view.js +9 -0
- package/dist/conversion/build.js +15 -8
- package/dist/conversion/dictionary-view.js +2 -2
- package/dist/conversion/nodes.d.ts +7 -0
- package/dist/conversion/nodes.js +58 -11
- package/dist/identity/ids.d.ts +4 -0
- package/dist/identity/ids.js +4 -0
- package/dist/ir/build.d.ts +4 -3
- package/dist/ir/build.js +14 -5
- package/dist/ir/call-dispatch.js +67 -7
- package/dist/ir/call-entry.js +1 -1
- package/dist/ir/callable-class-flow.d.ts +4 -0
- package/dist/ir/callable-class-flow.js +123 -1
- package/dist/ir/certify/parallel-region.js +698 -20
- package/dist/ir/certify.d.ts +3 -0
- package/dist/ir/certify.js +44 -9
- package/dist/ir/class-allocation-domain.js +2 -2
- package/dist/ir/class-construction-status.d.ts +10 -0
- package/dist/ir/class-construction-status.js +36 -0
- package/dist/ir/convert-carriers.d.ts +10 -1
- package/dist/ir/convert-carriers.js +18 -1
- package/dist/ir/dynamic-constructor-conversions.js +4 -2
- package/dist/ir/finite-iterator-close.d.ts +14 -0
- package/dist/ir/finite-iterator-close.js +50 -0
- package/dist/ir/host-template-conversions.js +9 -0
- package/dist/ir/lower-allocation.js +1 -1
- package/dist/ir/lower-flow.js +24 -3
- package/dist/ir/lower-operands.js +88 -7
- package/dist/ir/lower-protocol.js +1 -1
- package/dist/ir/lower.js +9 -4
- package/dist/ir/model.d.ts +39 -1
- package/dist/ir/native-accessor-definition.d.ts +3 -2
- package/dist/ir/native-accessor-definition.js +29 -10
- package/dist/ir/native-array-transport.js +2 -2
- package/dist/ir/native-field-view-domains.d.ts +23 -0
- package/dist/ir/native-field-view-domains.js +115 -9
- package/dist/ir/native-field-view-facts.d.ts +46 -2
- package/dist/ir/native-field-view-facts.js +159 -4
- package/dist/ir/native-iterable.d.ts +17 -0
- package/dist/ir/native-iterable.js +72 -0
- package/dist/ir/native-key-query.js +1 -1
- package/dist/ir/operation-conversions.js +15 -3
- package/dist/ir/program-conversions.js +2 -2
- package/dist/ir/publish-native-field-view-facts.js +9 -4
- package/dist/ir/pure-conversion-reuse.d.ts +58 -0
- package/dist/ir/pure-conversion-reuse.js +263 -0
- package/dist/ir/queries.js +1 -0
- package/dist/ir/reflection-demand.js +70 -18
- package/dist/ir/shake.js +2 -2
- package/dist/ir/unobserved-callable-inputs.d.ts +37 -0
- package/dist/ir/unobserved-callable-inputs.js +111 -0
- package/dist/native-signatures.d.ts +1 -1
- package/dist/native-signatures.js +27 -2
- package/dist/plugins/gea/component-classes.d.ts +2 -1
- package/dist/plugins/gea/component-classes.js +3 -3
- package/dist/plugins/gea/contract.d.ts +26 -3
- package/dist/plugins/gea/contract.js +42 -43
- package/dist/plugins/gea/host.d.ts +9 -0
- package/dist/plugins/gea/host.js +25 -4
- package/dist/plugins/gea/plugin.js +12 -6
- package/dist/plugins/gea/producer.d.ts +2 -2
- package/dist/plugins/gea/producer.js +2 -2
- package/dist/plugins/load.js +18 -1
- package/dist/plugins/model.d.ts +5 -0
- package/dist/plugins/native-iterable-providers.d.ts +18 -0
- package/dist/plugins/native-iterable-providers.js +51 -0
- package/dist/project-preparation.d.ts +8 -0
- package/dist/project-preparation.js +49 -7
- package/dist/projection/bindings.d.ts +13 -0
- package/dist/projection/bindings.js +20 -1
- package/dist/projection/classes.d.ts +4 -2
- package/dist/projection/classes.js +12 -5
- package/dist/representation/collections.js +2 -0
- package/dist/representation/derive.js +1 -0
- package/dist/representation/model.d.ts +2 -0
- package/dist/representation/model.js +1 -0
- package/dist/representation/policies.d.ts +2 -0
- package/dist/representation/primitive-domain.d.ts +1 -1
- package/dist/representation/primitive-domain.js +1 -1
- package/dist/representation/unassigned-binding-cells.js +6 -1
- package/dist/representation/union.js +6 -6
- package/dist/semantics/frontend.d.ts +2 -0
- package/dist/semantics/frontend.js +34 -5
- package/dist/semantics/host-methods.js +4 -1
- package/dist/semantics/jsx-runtime-provider.d.ts +5 -0
- package/dist/semantics/jsx-runtime-provider.js +16 -0
- package/dist/semantics/model/native-iterable.d.ts +14 -0
- package/dist/semantics/model/native-iterable.js +7 -0
- package/dist/semantics/model/operands.d.ts +30 -0
- package/dist/semantics/model/operations.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.js +27 -4
- package/dist/semantics/module-resolution.js +13 -2
- package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
- package/dist/semantics/normalize/callback-parameter-contracts.d.ts +32 -4
- package/dist/semantics/normalize/callback-parameter-contracts.js +66 -6
- package/dist/semantics/normalize/census.d.ts +3 -0
- package/dist/semantics/normalize/census.js +17 -12
- package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +4 -1
- package/dist/semantics/normalize/deferred-intrinsic-protocols.js +29 -9
- package/dist/semantics/normalize/flow/callable-reach.js +94 -3
- package/dist/semantics/normalize/flow/component-solver.js +144 -55
- package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +9 -0
- package/dist/semantics/normalize/flow/member-call-forwarding.js +30 -4
- package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +2 -0
- package/dist/semantics/normalize/flow/proof-hypotheses.js +27 -0
- package/dist/semantics/normalize/flow/source-callable-own-data.js +87 -14
- package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +2 -0
- package/dist/semantics/normalize/flow/source-commonjs-exports.js +2 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +17 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +125 -0
- package/dist/semantics/normalize/flow/source-native-origin.d.ts +6 -0
- package/dist/semantics/normalize/flow/source-native-origin.js +38 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +37 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.js +201 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +20 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +73 -0
- package/dist/semantics/normalize/flow/source-value-session.d.ts +50 -1
- package/dist/semantics/normalize/flow/source-value-session.js +596 -57
- package/dist/semantics/normalize/flow/value-flow.d.ts +17 -0
- package/dist/semantics/normalize/flow/value-flow.js +84 -0
- package/dist/semantics/normalize/fresh-dictionary-storage.js +2 -2
- package/dist/semantics/normalize/fresh-table-last-use.d.ts +52 -0
- package/dist/semantics/normalize/fresh-table-last-use.js +129 -0
- package/dist/semantics/normalize/gating.js +5 -1
- package/dist/semantics/normalize/global-host-mutations.js +190 -13
- package/dist/semantics/normalize/identities.js +20 -1
- package/dist/semantics/normalize/local-bindings.js +2 -2
- package/dist/semantics/normalize/parameter-bindings.js +10 -1
- package/dist/semantics/normalize/producer-context.d.ts +5 -0
- package/dist/semantics/normalize/producers/binding-kind.js +2 -0
- package/dist/semantics/normalize/producers/cited-value-type.d.ts +2 -2
- package/dist/semantics/normalize/producers/cited-value-type.js +2 -2
- package/dist/semantics/normalize/producers/class-lifecycle.js +39 -9
- package/dist/semantics/normalize/producers/computations.js +36 -5
- package/dist/semantics/normalize/producers/conditional-guard.d.ts +6 -0
- package/dist/semantics/normalize/producers/conditional-guard.js +5 -0
- package/dist/semantics/normalize/producers/control.js +7 -1
- package/dist/semantics/normalize/producers/destructuring.js +8 -9
- package/dist/semantics/normalize/producers/invocations.js +55 -2
- package/dist/semantics/normalize/producers/properties.d.ts +13 -0
- package/dist/semantics/normalize/producers/properties.js +21 -3
- package/dist/semantics/normalize/producers/references.js +8 -4
- package/dist/semantics/normalize/reachability.d.ts +15 -3
- package/dist/semantics/normalize/reachability.js +128 -20
- package/dist/semantics/normalize/return-bindings.js +3 -3
- package/dist/semantics/normalize/source-native-iterable.d.ts +19 -0
- package/dist/semantics/normalize/source-native-iterable.js +74 -0
- package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
- package/dist/semantics/normalize/structural-declarations.js +1 -1
- package/dist/semantics/normalize/structural-indexed-access.js +9 -0
- package/dist/semantics/normalize/structural.js +11 -0
- package/dist/semantics/normalize/unshared-array-result.d.ts +42 -0
- package/dist/semantics/normalize/unshared-array-result.js +269 -0
- package/dist/semantics/package-sources.js +3 -2
- package/dist/semantics/program.d.ts +8 -0
- package/dist/semantics/program.js +55 -0
- package/dist/semantics/source-transform-exports.d.ts +8 -0
- package/dist/semantics/source-transform-exports.js +145 -0
- package/dist/semantics/source-transform-protocol.d.ts +22 -0
- package/dist/semantics/this-constructor-source-transform.js +19 -1
- package/dist/targets/cpp/class-layout.d.ts +2 -0
- package/dist/targets/cpp/class-layout.js +35 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +11 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +33 -4
- package/dist/targets/cpp/conversions.js +6 -3
- package/dist/targets/cpp/emit-callable.js +73 -7
- package/dist/targets/cpp/emit-context.d.ts +23 -9
- package/dist/targets/cpp/emit-context.js +19 -8
- package/dist/targets/cpp/emit-equality.js +41 -1
- package/dist/targets/cpp/emit-exceptions.js +29 -11
- package/dist/targets/cpp/emit-iterator-object-view.js +2 -2
- package/dist/targets/cpp/emit-iterator.js +33 -9
- package/dist/targets/cpp/emit-live-field-view.js +6 -1
- package/dist/targets/cpp/emit-narrowing.d.ts +11 -3
- package/dist/targets/cpp/emit-narrowing.js +58 -18
- package/dist/targets/cpp/emit-native-field-view.d.ts +3 -1
- package/dist/targets/cpp/emit-native-field-view.js +84 -8
- package/dist/targets/cpp/emit-properties.d.ts +1 -0
- package/dist/targets/cpp/emit-properties.js +26 -7
- package/dist/targets/cpp/emit-protocol-iterator.js +5 -2
- package/dist/targets/cpp/emit-record-view.js +14 -2
- package/dist/targets/cpp/emit-tostring.js +23 -1
- package/dist/targets/cpp/emit-union-properties.js +1 -1
- package/dist/targets/cpp/emit.d.ts +1 -1
- package/dist/targets/cpp/emit.js +99 -13
- package/dist/targets/cpp/host/emit-host-invoke.js +2 -2
- package/dist/targets/cpp/host/emit-host-object.js +28 -2
- package/dist/targets/cpp/host/emit-host-properties.js +9 -1
- package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
- package/dist/targets/cpp/host/emit-host-value.js +8 -6
- package/dist/targets/cpp/host/host-members.js +2 -1
- package/dist/targets/cpp/prototype/emit-prototype-array.js +69 -5
- package/dist/targets/cpp/prototype/emit-prototype-invoke.js +9 -9
- package/dist/targets/cpp/prototype/emit-prototype-iterator.js +2 -2
- package/dist/targets/cpp/prototype/emit-prototype-promise.js +7 -7
- package/dist/targets/cpp/records.d.ts +1 -0
- package/dist/targets/cpp/records.js +16 -7
- package/dist/targets/cpp/translation-unit.js +30 -16
- package/package.json +8 -7
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +42 -3
- package/src/targets/cpp/runtime/gea_eval.h +3 -0
- package/src/targets/cpp/runtime/gea_runtime.h +2399 -676
- package/dist/representation/any-null-record-members.d.ts +0 -41
- package/dist/representation/any-null-record-members.js +0 -115
- package/dist/semantics/any-null-member-declarations.d.ts +0 -32
- package/dist/semantics/any-null-member-declarations.js +0 -90
- package/dist/semantics/normalize/fresh-array-result.d.ts +0 -32
- package/dist/semantics/normalize/fresh-array-result.js +0 -125
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { samePhysicalCarrier } from '../../representation/physical-carrier.js';
|
|
1
2
|
import { allOperationsOf } from '../../ir/model.js';
|
|
2
3
|
import { censusClassStaticFieldSlots, censusConstructorViewShapes, staticStorageOwnerOf } from '../../ir/class-static-fields.js';
|
|
3
4
|
import { operandsOfIrOperation } from '../../ir/queries.js';
|
|
@@ -600,11 +601,44 @@ export const censusClassStaticFieldStorage = (bodies, classes, realm = false) =>
|
|
|
600
601
|
key,
|
|
601
602
|
{
|
|
602
603
|
name: cppClassStaticFieldName(declaration, key) + (realm ? '()' : ''),
|
|
604
|
+
viewStruct: `${cppClassStaticFieldName(declaration, key)}_view`,
|
|
603
605
|
storageName: cppClassStaticFieldName(declaration, key),
|
|
604
606
|
representation
|
|
605
607
|
}
|
|
606
608
|
])));
|
|
607
|
-
|
|
609
|
+
// A typed own-property view is shared along one inheritance/property
|
|
610
|
+
// family, while each evaluated constructor owns a separate runtime record.
|
|
611
|
+
// Otherwise an inherited read would search Base with Derived's unrelated
|
|
612
|
+
// type tag and miss the base property before the first own write.
|
|
613
|
+
const conflicts = [...census.conflicts];
|
|
614
|
+
for (const [declaration, slots] of storage) {
|
|
615
|
+
for (const [key, slot] of slots) {
|
|
616
|
+
let viewStruct = slot.viewStruct;
|
|
617
|
+
const seen = new Set([declaration]);
|
|
618
|
+
let ancestor = classes.get(declaration)?.base ?? null;
|
|
619
|
+
while (ancestor !== null && !seen.has(ancestor)) {
|
|
620
|
+
seen.add(ancestor);
|
|
621
|
+
const inheritedLayout = classes.get(ancestor);
|
|
622
|
+
if (inheritedLayout?.staticAccessors.some((member) => member.key === key) ||
|
|
623
|
+
inheritedLayout?.staticMethods.some((member) => member.key === key)) {
|
|
624
|
+
conflicts.push(`${declaration}.${key}: inherited static method/accessor barrier needs property dispatch`);
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
const inherited = storage.get(staticStorageOwnerOf(classes, ancestor))?.get(key);
|
|
628
|
+
if (inherited) {
|
|
629
|
+
if (representationKey(inherited.representation) !== representationKey(slot.representation) ||
|
|
630
|
+
!samePhysicalCarrier(inherited.representation, slot.representation)) {
|
|
631
|
+
conflicts.push(`${declaration}.${key}: inherited static property carriers disagree`);
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
viewStruct = inherited.viewStruct;
|
|
635
|
+
}
|
|
636
|
+
ancestor = classes.get(ancestor)?.base ?? null;
|
|
637
|
+
}
|
|
638
|
+
slots.set(key, { ...slot, viewStruct });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return { storage, conflicts };
|
|
608
642
|
};
|
|
609
643
|
// `classFamilyOverridesOf` moved to `projection/dispatch.ts`: it is a pure
|
|
610
644
|
// function of `ClassLayout`, asked identically by the C++ target and, once a
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CallableAbi, RecordField, Representation } from '../../../representation/model.js';
|
|
2
2
|
import type { GetOperation } from '../../../ir/model.js';
|
|
3
|
-
import type { FunctionId } from '../../../identity/ids.js';
|
|
3
|
+
import type { DeclarationId, FunctionId } from '../../../identity/ids.js';
|
|
4
4
|
import { type ClassLayout } from '../../../projection/classes.js';
|
|
5
5
|
import { type EmitContext, type ReactiveRevisionOrigin } from '../emit-context.js';
|
|
6
6
|
import { type ClassStaticFieldStorage } from '../class-layout.js';
|
|
@@ -195,6 +195,16 @@ export interface ConstructorViewField {
|
|
|
195
195
|
export declare const constructorViewFieldFor: (ctx: EmitContext, key: string) => ConstructorViewField | null;
|
|
196
196
|
/** A constructor carrier's class evaluation, the state its own-property views hang off. */
|
|
197
197
|
export declare const constructorStateText: (receiver: Representation, text: string) => string | null;
|
|
198
|
+
/**
|
|
199
|
+
* The generic declaration whose layout copies all share one static side.
|
|
200
|
+
* JavaScript evaluates `class Box<T>` once, so `Box.count` is one property;
|
|
201
|
+
* the copies (`ClassLayout.staticOwner`) are each evaluated with their own
|
|
202
|
+
* constructor state, and the root name a program reads has no cell at all
|
|
203
|
+
* (`emit-bindings.ts`'s `classObjectReadsOf`).
|
|
204
|
+
*/
|
|
205
|
+
export declare const genericStaticOwnerOf: (ctx: EmitContext, receiver: Representation) => DeclarationId | null;
|
|
206
|
+
/** The runtime state a static own property lives on; a shared generic static side never renders the receiver. */
|
|
207
|
+
export declare const constructorStaticStateText: (ctx: EmitContext, receiver: Representation, text: () => string) => string | null;
|
|
198
208
|
export declare const classConstructorStaticFieldName: (ctx: EmitContext, receiver: Representation, key: string) => string | null;
|
|
199
209
|
/**
|
|
200
210
|
* `classMemberText`'s twin for the constructor side: `Point.fromPolar`,
|
|
@@ -7,7 +7,7 @@ import { classMethodOverrideOf, classPrototypeMethodMutableOf } from '../../../p
|
|
|
7
7
|
import { bindingReference, captureFieldText, cppEnvironmentStructName, cppThunkEntryText, createCppEmitBlockedError, frameHandleText, operandText } from '../emit-context.js';
|
|
8
8
|
import { classFamilyOverridesOf, classMemberOf, dispatchesStatically, reachableClassMethodsOf, classStaticFieldStorageOf, classStaticMemberOf, constructorViewShapesOf } from '../class-layout.js';
|
|
9
9
|
import { cppVirtualMemberName } from '../virtual-methods.js';
|
|
10
|
-
import { cppAbiParameterType, cppBodyName, cppCallableDeclarationTagName, cppClassName, cppConstructName, cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppResultTypeOf, cppStringLiteral, cppTypeOf, cppUndefinedIn } from '../types.js';
|
|
10
|
+
import { cppAbiParameterType, cppBodyName, cppCallableDeclarationTagName, cppClassName, cppConstructName, cppRecordFieldName, cppRecordFieldPresenceName, cppRecordStructName, cppResultTypeOf, cppStringLiteral, cppTypeOf, cppUndefinedIn, cppUndefinedValue } from '../types.js';
|
|
11
11
|
import { alignedValueText } from '../emit-narrowing.js';
|
|
12
12
|
import { operationConversionText } from '../emit-certified-conversion.js';
|
|
13
13
|
import { nativeMethodValueRecipeText } from '../emit-native-method.js';
|
|
@@ -240,7 +240,9 @@ const dynamicConstructorActualText = (ctx, target, actual, position) => {
|
|
|
240
240
|
return converted;
|
|
241
241
|
throw createCppEmitBlockedError(`conversion:${representationKey(source.value)}->${representationKey(parameter.value)}`, `dynamic constructor parameter ${position} is carried as "${representationKey(source.value)}", while the selected class expects "${representationKey(parameter.value)}"`);
|
|
242
242
|
}
|
|
243
|
-
|
|
243
|
+
// The omission `dynamicConstructorConversionsOf` certifies as `undefined` -> parameter.
|
|
244
|
+
const omitted = cppUndefinedIn(parameter.value) ??
|
|
245
|
+
alignedValueText(ctx, 'class-properties/emit-class-properties.ts:omitted', { kind: 'undefined' }, parameter.value, cppUndefinedValue);
|
|
244
246
|
if (omitted !== null)
|
|
245
247
|
return omitted;
|
|
246
248
|
throw createCppEmitBlockedError(`conversion:undefined->${representationKey(parameter.value)}`, `a dynamic constructor can omit candidate parameter ${position}, whose "${representationKey(parameter.value)}" carrier cannot hold undefined`);
|
|
@@ -709,6 +711,29 @@ export const constructorStateText = (receiver, text) => receiver.kind === 'const
|
|
|
709
711
|
: receiver.kind === 'constructor-family'
|
|
710
712
|
? `static_cast<gea::NativeClassMethodState*>((${text}).environment)`
|
|
711
713
|
: null;
|
|
714
|
+
/**
|
|
715
|
+
* The generic declaration whose layout copies all share one static side.
|
|
716
|
+
* JavaScript evaluates `class Box<T>` once, so `Box.count` is one property;
|
|
717
|
+
* the copies (`ClassLayout.staticOwner`) are each evaluated with their own
|
|
718
|
+
* constructor state, and the root name a program reads has no cell at all
|
|
719
|
+
* (`emit-bindings.ts`'s `classObjectReadsOf`).
|
|
720
|
+
*/
|
|
721
|
+
export const genericStaticOwnerOf = (ctx, receiver) => {
|
|
722
|
+
if (receiver.kind !== 'constructor-family')
|
|
723
|
+
return null;
|
|
724
|
+
const owner = sharedStaticOwnerOf(ctx.classes, receiver.members);
|
|
725
|
+
if (owner === null)
|
|
726
|
+
return null;
|
|
727
|
+
for (const [declaration, layout] of ctx.classes)
|
|
728
|
+
if (declaration !== owner && layout.staticOwner === owner)
|
|
729
|
+
return owner;
|
|
730
|
+
return null;
|
|
731
|
+
};
|
|
732
|
+
/** The runtime state a static own property lives on; a shared generic static side never renders the receiver. */
|
|
733
|
+
export const constructorStaticStateText = (ctx, receiver, text) => {
|
|
734
|
+
const shared = genericStaticOwnerOf(ctx, receiver);
|
|
735
|
+
return shared !== null ? `gea::sharedConstructorStaticState(${cppStringLiteral(shared)})` : constructorStateText(receiver, text());
|
|
736
|
+
};
|
|
712
737
|
export const classConstructorStaticFieldName = (ctx, receiver, key) => classConstructorStaticFieldStorage(ctx, receiver, key)?.name ?? null;
|
|
713
738
|
/**
|
|
714
739
|
* `classMemberText`'s twin for the constructor side: `Point.fromPolar`,
|
|
@@ -765,7 +790,7 @@ receiverText) => {
|
|
|
765
790
|
}
|
|
766
791
|
const viewed = constructorViewFieldFor(ctx, key);
|
|
767
792
|
if (viewed !== null) {
|
|
768
|
-
const state =
|
|
793
|
+
const state = constructorStaticStateText(ctx, receiver, receiverText);
|
|
769
794
|
if (state === null)
|
|
770
795
|
return null;
|
|
771
796
|
const presence = `&${viewed.struct}::${cppRecordFieldPresenceName(key)}`;
|
|
@@ -778,7 +803,11 @@ receiverText) => {
|
|
|
778
803
|
}
|
|
779
804
|
const censused = classConstructorStaticFieldStorage(ctx, receiver, key);
|
|
780
805
|
if (censused !== null) {
|
|
781
|
-
const
|
|
806
|
+
const state = constructorStaticStateText(ctx, receiver, receiverText);
|
|
807
|
+
if (state === null)
|
|
808
|
+
throw createCppEmitBlockedError('property-access:constructor-static-state', 'has no evaluated constructor identity');
|
|
809
|
+
const read = `gea::constructorStaticViewHolder(gea::constructorStaticView<${censused.viewStruct}>(${state}), &${censused.viewStruct}::present)->value`;
|
|
810
|
+
const converted = alignedValueText(ctx, 'class-properties/emit-class-properties.ts:713', censused.representation, result, read);
|
|
782
811
|
if (converted !== null)
|
|
783
812
|
return converted;
|
|
784
813
|
throw createCppEmitBlockedError(`conversion:${representationKey(censused.representation)}->${representationKey(result)}`, `static field "${key}" is stored as "${representationKey(censused.representation)}" and this read publishes ` +
|
|
@@ -13,7 +13,7 @@ import { chainFieldProtocolUnused, chainPayloadNeedsSourceGuard, nativeSumNarrow
|
|
|
13
13
|
import { classRefDomainsOverlap, classifierDomainsOverlap, conversionNeedsPriorSourceGuard, conversionRequiresSourceGuard, transfersNativeStorage } from '../../conversion/algebra.js';
|
|
14
14
|
import { emptyConversionRegistry, narrowingReachesTarget, narrowsToDescendantClassUnion } from '../../conversion/build.js';
|
|
15
15
|
import { defaultRecordLayoutPolicy } from '../../representation/policies.js';
|
|
16
|
-
import { abiKey, arrayExtensionKey, representationKey, carriesUndefined, containsUnresolved, isOpenDocument } from '../../representation/model.js';
|
|
16
|
+
import { abiKey, arrayExtensionKey, representationKey, carriesNativeUndefined, carriesUndefined, containsUnresolved, isOpenDocument } from '../../representation/model.js';
|
|
17
17
|
import { isSpellable, callableObjectAbi, resultAdapterTransportOf, adaptsConstructorIntoDispatch, boxDiscriminantsOfArm, conversionRecipeOf, boxedAssertionText, classDocumentViewText, documentViewable, dropsAllParametersIntoResultArm, dropsUnboundParameters, dynamicTagFor, promisePayloadConvertible, rebasesRestOverLeadingParameters, CONSTRUCTOR_STATIC_VIEW, constructorStaticViewAdmitted, DYNAMIC_DICTIONARY_TO_NAMED_RECORD, dynamicDictionaryToNamedRecordAdmitted, indexedRecordCastableToDictionary, indexedRecordDictionaryArmOf, indexedRecordViewOf, INDEXED_RECORD_INTO_DICTIONARY_ARM, INDEXED_RECORD_TO_DICTIONARY, recordCastableToDictionary, recordRecastCrossesDynamic, recordsRecastable, sameArrayUpToExtension, sumIntoPayloadText, widensResultIntoArm, resultAdaptedCallableText, tryCandidateText, VIEW_ADAPTED_CALLABLE, CHECKED_ARM_NARROWING, checkedArmNarrowingText } from './emit-narrowing.js';
|
|
18
18
|
import { NATIVE_SUM_CLASSIFIER, NATIVE_SUM_MATERIALIZER, nativeSumPlan, nativeSumPreservesPayload } from '../../conversion/native-sum.js';
|
|
19
19
|
import { NATIVE_REFERENCE_ABSENCE, nativeReferenceAbsenceOf } from '../../conversion/native-absence.js';
|
|
@@ -1955,13 +1955,16 @@ const cppConversionTables = (layouts, nativeNarrowing, nativeWrappedPayload) =>
|
|
|
1955
1955
|
// admits for `never[]` alone: an element that does not carry `undefined`
|
|
1956
1956
|
// (a genuine `undefined[]` is not assignable to it) and, for `any[]`, a
|
|
1957
1957
|
// runtime test -- empty is the sentinel, anything else is boxed element
|
|
1958
|
-
// by element, which is what a real `undefined[]` into `any[]` means.
|
|
1958
|
+
// by element, which is what a real `undefined[]` into `any[]` means. A
|
|
1959
|
+
// shared class or record reference element holds `undefined` natively,
|
|
1960
|
+
// so it is that same runtime test (`gea::emptyArraySentinelOrAbsent`):
|
|
1961
|
+
// a populated source becomes the array of `undefined` it really is.
|
|
1959
1962
|
if (source.kind === 'array-object' &&
|
|
1960
1963
|
target.kind === 'array-object' &&
|
|
1961
1964
|
source.element.kind === 'undefined' &&
|
|
1962
1965
|
source.ownership === 'shared-refcount' &&
|
|
1963
1966
|
target.ownership === 'shared-refcount' &&
|
|
1964
|
-
(target.element.kind === 'dynamic' || !carriesUndefined(target.element))) {
|
|
1967
|
+
(target.element.kind === 'dynamic' || carriesNativeUndefined(target.element) || !carriesUndefined(target.element))) {
|
|
1965
1968
|
return {
|
|
1966
1969
|
classifier: { id: 'gea::emptyArraySentinel', domain: `empty-array:${pairKey()}` },
|
|
1967
1970
|
materializer: { id: 'gea::emptyArraySentinel', domain: `empty-array:${pairKey()}`, allocates: false }
|
|
@@ -20,7 +20,7 @@ import { frameHandleText, sharedGroupMemberText } from './emit-binding-reference
|
|
|
20
20
|
import { restPacks } from '../../conversion/record-view.js';
|
|
21
21
|
import { abiOfCallee } from '../../projection/callee.js';
|
|
22
22
|
import { emitDateConstruct, isDateCarrier } from './prototype/emit-prototype-date.js';
|
|
23
|
-
import { unwrapPresentValue, bindingReference, cppConstructedThunkName, cppConstructThunkName, cppEnvironmentStructName, cppFrameLocalName, cppFrameStructName, cppReceiverName, cppSharedIdentityFieldName, cppStaticPrefixCallableText, cppThunkEntryText, cppThunkName, createCppEmitBlockedError, declareCell, defineValue, defineValueAlias, isCppEmitBlockedError, isIntegerStorageValue, operandText, paddedArguments, captureFieldText } from './emit-context.js';
|
|
23
|
+
import { unwrapPresentValue, bindingReference, cppConstructedThunkName, cppConstructThunkName, cppEnvironmentStructName, cppFrameLocalName, cppFrameStructName, cppReceiverName, cppSharedIdentityFieldName, cppStaticPrefixCallableText, cppThunkEntryText, cppThunkName, createCppEmitBlockedError, declareCell, defineValue, defineValueAlias, isCppEmitBlockedError, isDeferredValue, isIntegerStorageValue, operandText, paddedArguments, captureFieldText } from './emit-context.js';
|
|
24
24
|
import { classMemberOf, cppFieldInitializerStatements, lazyArrowFieldPlanOf } from './class-layout.js';
|
|
25
25
|
import { cellValueText } from './emit-bindings.js';
|
|
26
26
|
import { declaredRecordFieldOf } from './records.js';
|
|
@@ -40,7 +40,8 @@ import { nativeCollectionBaseInitializeStatements } from './native-collection-ba
|
|
|
40
40
|
import { nativePromiseBaseInitializeStatements } from './native-promise-base.js';
|
|
41
41
|
import { emitArrayBufferConstruct, emitSharedArrayBufferConstruct, emitTextCodecConstruct, emitDataViewConstruct, emitTypedArrayBufferConstruct, typedArrayTargetSpelling } from './emit-buffers.js';
|
|
42
42
|
import { armAt, armIs } from './emit-union-properties.js';
|
|
43
|
-
import {
|
|
43
|
+
import { constructorStateText, genericStaticOwnerOf } from './class-properties/emit-class-properties.js';
|
|
44
|
+
import { cppAbiType, cppBodyName, cppBoxedType, cppCallableDeclarationTagName, cppClassName, cppConstructName, cppInitializeName, cppRecordFieldName, cppRecordFieldPresenceName, cppRefcountedReceiver, cppStringLiteral, cppTypeOf, cppResultTypeOf, cppUndefinedValue } from './types.js';
|
|
44
45
|
/** `Function.prototype.bind` preserves the native call ABI and captures only evaluated prefix values. */
|
|
45
46
|
export const emitBindCallable = (ctx, lines, operation) => {
|
|
46
47
|
if (operation.result.representation.kind !== 'function-value-dispatch') {
|
|
@@ -1372,15 +1373,29 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
1372
1373
|
const potentiallyMovingArguments = new Set(operation.arguments
|
|
1373
1374
|
.filter((argument) => transferOf(ctx.dyingArguments, ctx.ownedValues, ctx.transferDyingValues, argument.value, ctx.receiverRenames) === 'move')
|
|
1374
1375
|
.map((argument) => argument.value));
|
|
1376
|
+
// `stableBorrowActualsOf` leaves out every value an operation computes, because
|
|
1377
|
+
// the printer may withhold one as an expression naming mutable storage. By the
|
|
1378
|
+
// time a call renders, every argument's own definition has rendered, so that
|
|
1379
|
+
// choice is settled: an owned SSA temporary the printer declared a local of its
|
|
1380
|
+
// own (`defineValue`) and did not withhold is a slot of this frame no callee can
|
|
1381
|
+
// name, exactly like a private cell. `setNativeUniformValue(u, gl, v.value, t)`
|
|
1382
|
+
// sent its freshly read uniform value through the owning wrapper, copying the
|
|
1383
|
+
// seq element union and the optional texture table into by-value formals per
|
|
1384
|
+
// uniform per draw.
|
|
1385
|
+
// A repeated conversion spelled as an earlier one's storage (`repeatedConversions`) is that storage.
|
|
1386
|
+
const storageOf = (value) => ctx.repeatedConversions.get(value) ?? value;
|
|
1387
|
+
const stableActuals = new Set(operation.arguments
|
|
1388
|
+
.map((argument) => argument.value)
|
|
1389
|
+
.filter((value) => ctx.stableBorrowActuals.has(value) || (ctx.ownedValues.has(storageOf(value)) && !isDeferredValue(ctx, storageOf(value)))));
|
|
1375
1390
|
const stableEntry = stableCandidate !== undefined &&
|
|
1376
|
-
stableBorrowEntryAccepts(stableCandidate, operation.arguments,
|
|
1391
|
+
stableBorrowEntryAccepts(stableCandidate, operation.arguments, stableActuals, potentiallyMovingArguments)
|
|
1377
1392
|
? stableCandidate
|
|
1378
1393
|
: undefined;
|
|
1379
1394
|
// A candidate's borrowed entry for this call, when it has one: the stable
|
|
1380
1395
|
// entry its arguments are accepted by, or its borrowable body.
|
|
1381
1396
|
const borrowedEntryOf = (target) => {
|
|
1382
1397
|
const stable = ctx.stableBorrowEntries.get(cppBodyName(target));
|
|
1383
|
-
if (stable !== undefined && stableBorrowEntryAccepts(stable, operation.arguments,
|
|
1398
|
+
if (stable !== undefined && stableBorrowEntryAccepts(stable, operation.arguments, stableActuals, potentiallyMovingArguments))
|
|
1384
1399
|
return stable.name;
|
|
1385
1400
|
return ctx.borrowableMemberBodies.has(target) ? cppBodyName(target) : undefined;
|
|
1386
1401
|
};
|
|
@@ -1428,13 +1443,54 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
1428
1443
|
`gea::host::throwRuntimeError("TypeError", ${cppStringLiteral(`an own "${operation.builtinShadowGuard}" written onto a natively carried callable is not rendered by this backend`)});`);
|
|
1429
1444
|
}
|
|
1430
1445
|
const logicalThis = genericNativeLogicalReceiverOf(operation);
|
|
1446
|
+
// `CallOperation.ownShadowGuard`: an instance that does not own the method key
|
|
1447
|
+
// runs the prototype body, which this call names directly; the method-value
|
|
1448
|
+
// read (rendered inline when deferred) and its adapter are then never built.
|
|
1449
|
+
// A null receiver takes the ordinary path, which raises the language's error.
|
|
1450
|
+
// The receiver argument is rendered once, as the parameter of an immediately
|
|
1451
|
+
// invoked lambda, because a deferred operand may be spelled at one use only.
|
|
1452
|
+
const guard = operation.ownShadowGuard;
|
|
1453
|
+
const guardable = guard !== undefined &&
|
|
1454
|
+
operation.receiver?.representation.kind === 'class-ref' &&
|
|
1455
|
+
dispatched === undefined &&
|
|
1456
|
+
direct === undefined &&
|
|
1457
|
+
candidate === undefined &&
|
|
1458
|
+
abi.receiver !== null &&
|
|
1459
|
+
padded.length > 0 &&
|
|
1460
|
+
operation.builtinShadowGuard === undefined &&
|
|
1461
|
+
calleeOperand.value === operation.callee.value;
|
|
1462
|
+
const guardedInvocation = () => {
|
|
1463
|
+
const [receiverArgument, ...rest] = padded;
|
|
1464
|
+
const self = 'gea_guard_receiver';
|
|
1465
|
+
// A typed (non-generic) parameter: a generic lambda would make every
|
|
1466
|
+
// member template the callee names a dependent name needing `template`.
|
|
1467
|
+
const forwarded = `std::move(${self})`;
|
|
1468
|
+
return (`[&](${cppTypeOf(abi.receiver)} ${self}) -> decltype(auto) { return (static_cast<bool>(${self}) && !${self}->${cppRecordFieldPresenceName(guard.key)}) ` +
|
|
1469
|
+
`? ${cppBodyName(guard.functionId)}(${[self, ...rest].join(', ')}) ` +
|
|
1470
|
+
`: ${operandText(ctx, calleeOperand)}.${callMember}(${[forwarded, ...rest].join(', ')}); }(${receiverArgument})`);
|
|
1471
|
+
};
|
|
1472
|
+
// A logical receiver that is a value this frame already holds (not withheld
|
|
1473
|
+
// as an expression) can be built inside the callee's dispatch, only for a
|
|
1474
|
+
// target that reads it (`CallableObject::callWithLazyReceiver`).
|
|
1475
|
+
// Not inside a C++ coroutine (a generator or an async body): the clang-cl LTO
|
|
1476
|
+
// jump threading (VS 18 toolchain) crashed on a coroutine resume function holding the builder
|
|
1477
|
+
// lambda (instance-culling's generator), and a coroutine frame gains nothing here.
|
|
1478
|
+
const lazyLogicalReceiver = (logical) => !ctx.generatorBody &&
|
|
1479
|
+
!ctx.asyncCoroutineBody &&
|
|
1480
|
+
!isDeferredValue(ctx, logical.value) &&
|
|
1481
|
+
calleeOperand.value === operation.callee.value &&
|
|
1482
|
+
isCallableObject(calleeOperand.representation);
|
|
1431
1483
|
const invocation = dispatched !== undefined
|
|
1432
1484
|
? `${virtualPadded[0]}->${dispatched.member}(${virtualPadded.slice(1).join(', ')})`
|
|
1433
1485
|
: direct !== undefined
|
|
1434
1486
|
? `${stableEntry?.name ?? direct}(${padded.join(', ')})`
|
|
1435
1487
|
: abi.receiver === null && logicalThis !== null
|
|
1436
|
-
?
|
|
1437
|
-
|
|
1488
|
+
? lazyLogicalReceiver(logicalThis)
|
|
1489
|
+
? `${operandText(ctx, calleeOperand)}.callWithLazyReceiver(${[`[&]() -> gea::NativeCallReceiver { return ${operationNativeCallReceiverText(ctx, operation, logicalThis.representation, operandText(ctx, logicalThis))}; }`, ...padded].join(', ')})`
|
|
1490
|
+
: `${operandText(ctx, calleeOperand)}.callWithReceiver(${[operationNativeCallReceiverText(ctx, operation, logicalThis.representation, operandText(ctx, logicalThis)), ...padded].join(', ')})`
|
|
1491
|
+
: guardable
|
|
1492
|
+
? guardedInvocation()
|
|
1493
|
+
: `${operandText(ctx, calleeOperand)}.${callMember}(${padded.join(', ')})`;
|
|
1438
1494
|
// A result the integer census narrowed from the candidate body's returns is
|
|
1439
1495
|
// checked where it lands, on every path the call can take: the guard above
|
|
1440
1496
|
// may miss and run whatever callable the member holds.
|
|
@@ -2708,5 +2764,15 @@ export const emitAllocateConstructor = (ctx, lines, operation) => {
|
|
|
2708
2764
|
? `gea::exactNativeClassHeritage<${cppClassName(exactBase)}>(${operandText(ctx, heritageOperand)}.environment)`
|
|
2709
2765
|
: `gea::nativeClassMethodStateFromEnvironment(${operandText(ctx, heritageOperand)}.environment)`;
|
|
2710
2766
|
const environment = `gea::allocateNativeClassMethodEnvironment<${cppClassName(operation.declaration)}>(${parent})`;
|
|
2711
|
-
|
|
2767
|
+
// Certification authenticates this definition-only status against the
|
|
2768
|
+
// semantic allocation. Its static receiver still owns this evaluation,
|
|
2769
|
+
// but no source construction can consume a construct entry.
|
|
2770
|
+
const construct = operation.constructionDeferred ? 'nullptr' : `&${cppConstructThunkName(operation.declaration)}`;
|
|
2771
|
+
lines.push(`${name} = ${cppTypeOf(operation.result.representation)}{${construct}, ${environment}};`);
|
|
2772
|
+
// A generic's layout copy is a separate evaluation of the one class
|
|
2773
|
+
// JavaScript evaluates once; its static own properties live on that class.
|
|
2774
|
+
const shared = genericStaticOwnerOf(ctx, operation.result.representation);
|
|
2775
|
+
const state = constructorStateText(operation.result.representation, name);
|
|
2776
|
+
if (shared !== null && state !== null)
|
|
2777
|
+
lines.push(`gea::shareConstructorStatics(${state}, ${cppStringLiteral(shared)});`);
|
|
2712
2778
|
};
|
|
@@ -729,6 +729,8 @@ export interface EmitBodyFacts {
|
|
|
729
729
|
readonly stableBorrowActuals: ReadonlySet<IrValueId>;
|
|
730
730
|
/** See `EmitContext.borrowedArmProjections`. */
|
|
731
731
|
readonly borrowedArmProjections: ReadonlyMap<IrValueId, BorrowedArmProjection>;
|
|
732
|
+
/** See `EmitContext.repeatedConversions`. */
|
|
733
|
+
readonly repeatedConversions: ReadonlyMap<IrValueId, IrValueId>;
|
|
732
734
|
/** See `EmitContext.computeOrigins`. */
|
|
733
735
|
readonly computeOrigins: ReadonlyMap<IrValueId, ComputeOperation>;
|
|
734
736
|
/** See `EmitContext.propertyReadOrigins`. */
|
|
@@ -880,6 +882,12 @@ export interface EmitContext {
|
|
|
880
882
|
* `cppThunkEntryText`, at the sites that mint a function object.
|
|
881
883
|
*/
|
|
882
884
|
readonly functionFacts: ReadonlyMap<FunctionId, CallableFactsSpelling>;
|
|
885
|
+
/**
|
|
886
|
+
* The functions with a `[[Construct]]` thunk, which every site minting a
|
|
887
|
+
* value of one publishes in the value's entry record (`cppThunkEntryText`,
|
|
888
|
+
* read back by `gea::withConstructEntry`).
|
|
889
|
+
*/
|
|
890
|
+
readonly constructEntries?: ReadonlySet<FunctionId>;
|
|
883
891
|
/** The execution context whose frame this body is, so a cell owned elsewhere is recognisable as one. */
|
|
884
892
|
readonly owner: FunctionId | RegionId;
|
|
885
893
|
/** See `emit-narrowing.ts`'s `PrinterDrift`; one program-wide list, shared by every body's context. */
|
|
@@ -1255,6 +1263,8 @@ export interface EmitContext {
|
|
|
1255
1263
|
readonly stableBorrowActuals: ReadonlySet<IrValueId>;
|
|
1256
1264
|
/** Converts rendered as a reference to one arm of a borrowed union formal (`borrowed-arm-projections.ts`). Each is also a stable actual. */
|
|
1257
1265
|
readonly borrowedArmProjections: ReadonlyMap<IrValueId, BorrowedArmProjection>;
|
|
1266
|
+
/** Pure conversions spelled as the storage of a dominating conversion of the same value (`ir/pure-conversion-reuse.ts`), later result -> earlier. */
|
|
1267
|
+
readonly repeatedConversions: ReadonlyMap<IrValueId, IrValueId>;
|
|
1258
1268
|
readonly callableMemberCandidates: ReadonlyMap<string, FunctionId>;
|
|
1259
1269
|
/** This body's guard candidates for calls through callable parameters, captures and fields (`callableFlowCandidatesOf`). */
|
|
1260
1270
|
readonly callableFlowCandidates: ReadonlyMap<IrValueId, CallableFlowCandidate>;
|
|
@@ -1959,7 +1969,7 @@ export declare const directCalleesOf: (body: IrBody, abiOfCallable: (callable: F
|
|
|
1959
1969
|
export declare const directCallableValuesOf: (body: IrBody, captureFree: (callable: FunctionId) => boolean) => ReadonlyMap<IrValueId, FunctionId>;
|
|
1960
1970
|
/** See `EmitContext.integerWidenings`. */
|
|
1961
1971
|
export declare const integerWideningsOf: (body: IrBody) => ReadonlyMap<IrValueId, IrOperand>;
|
|
1962
|
-
export declare const createEmitContext: (abi: CallableAbi | null, owner: FunctionId | RegionId, placements: ReadonlyMap<DeclarationId, BindingPlacement>, classes: ReadonlyMap<DeclarationId, ClassLayout>, hosts: HostSpellings, deriver: RepresentationDeriver, bodyFacts: EmitBodyFacts, wellKnownSymbols?: ReadonlyMap<DeclarationId, string>, captures?: CaptureIndex, symbolKeys?: Map<string, string>, templateObjects?: Map<string, TemplateObjectDefinition>, directCallableBindings?: ReadonlyMap<DeclarationId, FunctionId>, virtualDispatch?: ReadonlyMap<string, CallableAbi>, narrowedFormals?: ReadonlySet<number>, repeatedConstructors?: ReadonlyMap<DeclarationId, DeclarationId>, dyingArguments?: ReadonlySet<IrValueId>, instantiation?: InstantiationFacts, abiOfCallable?: (callable: FunctionId) => CallableAbi | null, functionFacts?: ReadonlyMap<FunctionId, CallableFactsSpelling>, hostMethodAliases?: ReadonlyMap<DeclarationId, HostMethodAlias>, callableMemberCandidates?: ReadonlyMap<string, FunctionId>, callableFlowCandidates?: ReadonlyMap<IrValueId, CallableFlowCandidate>, borrowableMemberBodies?: ReadonlySet<FunctionId>, stableBorrowEntries?: ReadonlyMap<string, StableBorrowEntry>, printerDrift?: PrinterDrift[], conversions?: ConversionCensus | null, nativeSelections?: ReadonlyMap<string, NativeSelectionHelper> | undefined, callableIdentityDemand?: CallableIdentityDemand, nativeIntegrityRestricted?: IntegrityRestrictions, fixedFieldStateConstant?: boolean, definitionCells?: ReadonlySet<DeclarationId>, keyOrderUnobserved?: ReadonlySet<string>, conversionIsCertified?: (id: string) => boolean, programConversionRecipes?: readonly ProgramConversionRecipe[], physicalIndexProtocols?: ReadonlyMap<DeclarationId, boolean>) => {
|
|
1972
|
+
export declare const createEmitContext: (abi: CallableAbi | null, owner: FunctionId | RegionId, placements: ReadonlyMap<DeclarationId, BindingPlacement>, classes: ReadonlyMap<DeclarationId, ClassLayout>, hosts: HostSpellings, deriver: RepresentationDeriver, bodyFacts: EmitBodyFacts, wellKnownSymbols?: ReadonlyMap<DeclarationId, string>, captures?: CaptureIndex, symbolKeys?: Map<string, string>, templateObjects?: Map<string, TemplateObjectDefinition>, directCallableBindings?: ReadonlyMap<DeclarationId, FunctionId>, virtualDispatch?: ReadonlyMap<string, CallableAbi>, narrowedFormals?: ReadonlySet<number>, repeatedConstructors?: ReadonlyMap<DeclarationId, DeclarationId>, dyingArguments?: ReadonlySet<IrValueId>, instantiation?: InstantiationFacts, abiOfCallable?: (callable: FunctionId) => CallableAbi | null, functionFacts?: ReadonlyMap<FunctionId, CallableFactsSpelling>, constructEntries?: ReadonlySet<FunctionId>, hostMethodAliases?: ReadonlyMap<DeclarationId, HostMethodAlias>, callableMemberCandidates?: ReadonlyMap<string, FunctionId>, callableFlowCandidates?: ReadonlyMap<IrValueId, CallableFlowCandidate>, borrowableMemberBodies?: ReadonlySet<FunctionId>, stableBorrowEntries?: ReadonlyMap<string, StableBorrowEntry>, printerDrift?: PrinterDrift[], conversions?: ConversionCensus | null, nativeSelections?: ReadonlyMap<string, NativeSelectionHelper> | undefined, callableIdentityDemand?: CallableIdentityDemand, nativeIntegrityRestricted?: IntegrityRestrictions, fixedFieldStateConstant?: boolean, definitionCells?: ReadonlySet<DeclarationId>, keyOrderUnobserved?: ReadonlySet<string>, conversionIsCertified?: (id: string) => boolean, programConversionRecipes?: readonly ProgramConversionRecipe[], physicalIndexProtocols?: ReadonlyMap<DeclarationId, boolean>) => {
|
|
1963
1973
|
readonly ctx: EmitContext;
|
|
1964
1974
|
readonly prepass: EmitBodyPrepassFacts;
|
|
1965
1975
|
};
|
|
@@ -2106,9 +2116,9 @@ export declare const cppReceiverName = "gea_this";
|
|
|
2106
2116
|
export declare const cppThunkName: (functionId: string) => string;
|
|
2107
2117
|
/**
|
|
2108
2118
|
* What one function object answers for `name`, `length` and
|
|
2109
|
-
* `Function.prototype.toString`, already spelled for the
|
|
2119
|
+
* `Function.prototype.toString`, already spelled for the publication call:
|
|
2110
2120
|
* `abiType` is `cppAbiType` of the thunk's own convention, which the
|
|
2111
|
-
*
|
|
2121
|
+
* runtime's `Invoke` template parameter must match exactly.
|
|
2112
2122
|
*/
|
|
2113
2123
|
export interface CallableFactsSpelling {
|
|
2114
2124
|
readonly abiType: string;
|
|
@@ -2117,12 +2127,16 @@ export interface CallableFactsSpelling {
|
|
|
2117
2127
|
readonly source: string;
|
|
2118
2128
|
}
|
|
2119
2129
|
/**
|
|
2120
|
-
* The
|
|
2121
|
-
*
|
|
2122
|
-
* `gea::CallableObject<Abi>::entryWithFacts<&thunk>(name, length,
|
|
2123
|
-
* which
|
|
2130
|
+
* The entry a minting site stores in a callable carrier: `&thunk`, or -- when
|
|
2131
|
+
* the program reads function facts -- `&thunk` with its entry record, handed
|
|
2132
|
+
* back by `gea::CallableObject<Abi>::entryWithFacts<&thunk>(name, length,
|
|
2133
|
+
* text)`, which publishes the facts in that record the first time any site
|
|
2134
|
+
* mints this function. A function with a `[[Construct]]` thunk publishes it in
|
|
2135
|
+
* the same record (`entryWithConstruct`). The runtime reads these from the
|
|
2136
|
+
* record, never by the thunk's address, which a release link may share with
|
|
2137
|
+
* another function of identical code.
|
|
2124
2138
|
*
|
|
2125
|
-
*
|
|
2139
|
+
* Publication lives HERE, at the mint, and not beside the thunk, because a
|
|
2126
2140
|
* namespace-scope `static const bool ... = registerSource<&thunk>(...)` is a
|
|
2127
2141
|
* static initializer that takes the thunk's address, and a static initializer
|
|
2128
2142
|
* with a side effect is a root the linker may not drop. Every emitted
|
|
@@ -2141,7 +2155,7 @@ export interface CallableFactsSpelling {
|
|
|
2141
2155
|
* `cppThunkEntryText` registers them on the thunk's own.
|
|
2142
2156
|
*/
|
|
2143
2157
|
export declare const cppStaticPrefixCallableText: (ctx: Pick<EmitContext, "functionFacts">, functionId: FunctionId, slotType: string, sourceType: string) => string;
|
|
2144
|
-
export declare const cppThunkEntryText: (ctx: Pick<EmitContext, "functionFacts" | "abiOfCallable">, functionId: FunctionId) => string;
|
|
2158
|
+
export declare const cppThunkEntryText: (ctx: Pick<EmitContext, "functionFacts" | "abiOfCallable" | "constructEntries">, functionId: FunctionId) => string;
|
|
2145
2159
|
/** The thunk that adapts one class's construct function to the environment-passing construct pointer a constructor carrier holds. */
|
|
2146
2160
|
export declare const cppConstructThunkName: (declaration: DeclarationId) => string;
|
|
2147
2161
|
/**
|
|
@@ -103,7 +103,7 @@ export const integerWideningsOf = (body) => {
|
|
|
103
103
|
}
|
|
104
104
|
return widenings;
|
|
105
105
|
};
|
|
106
|
-
export const createEmitContext = (abi, owner, placements, classes, hosts, deriver, bodyFacts, wellKnownSymbols = new Map(), captures = emptyCaptureIndex, symbolKeys = new Map(), templateObjects = new Map(), directCallableBindings = new Map(), virtualDispatch = new Map(), narrowedFormals = new Set(), repeatedConstructors = new Map(), dyingArguments = new Set(), instantiation = noInstantiationFacts, abiOfCallable = () => null, functionFacts = new Map(), hostMethodAliases = new Map(), callableMemberCandidates = new Map(), callableFlowCandidates = new Map(), borrowableMemberBodies = new Set(), stableBorrowEntries = new Map(), printerDrift = [],
|
|
106
|
+
export const createEmitContext = (abi, owner, placements, classes, hosts, deriver, bodyFacts, wellKnownSymbols = new Map(), captures = emptyCaptureIndex, symbolKeys = new Map(), templateObjects = new Map(), directCallableBindings = new Map(), virtualDispatch = new Map(), narrowedFormals = new Set(), repeatedConstructors = new Map(), dyingArguments = new Set(), instantiation = noInstantiationFacts, abiOfCallable = () => null, functionFacts = new Map(), constructEntries = new Set(), hostMethodAliases = new Map(), callableMemberCandidates = new Map(), callableFlowCandidates = new Map(), borrowableMemberBodies = new Set(), stableBorrowEntries = new Map(), printerDrift = [],
|
|
107
107
|
// A context built without the program's census (the value-contract
|
|
108
108
|
// checks) gets one over the same tables with nothing pre-minted: the
|
|
109
109
|
// registry answers every pair the eager graph would have, one node later.
|
|
@@ -166,6 +166,7 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
166
166
|
abiOfCallable,
|
|
167
167
|
methodEnvironment: (callable, what) => methodEnvironmentText(ctx, callable, what),
|
|
168
168
|
functionFacts,
|
|
169
|
+
constructEntries,
|
|
169
170
|
owner,
|
|
170
171
|
placements,
|
|
171
172
|
classes,
|
|
@@ -222,6 +223,7 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
222
223
|
stableBorrowEntries,
|
|
223
224
|
stableBorrowActuals: bodyFacts.stableBorrowActuals,
|
|
224
225
|
borrowedArmProjections: bodyFacts.borrowedArmProjections,
|
|
226
|
+
repeatedConversions: bodyFacts.repeatedConversions,
|
|
225
227
|
repeatedConstructors,
|
|
226
228
|
dyingArguments,
|
|
227
229
|
hostMethodAliases,
|
|
@@ -680,12 +682,16 @@ export const cppReceiverName = 'gea_this';
|
|
|
680
682
|
/** The thunk that adapts one function body to the environment-passing invoke pointer a callable carrier holds. */
|
|
681
683
|
export const cppThunkName = (functionId) => `${cppBodyName(functionId)}_thunk`;
|
|
682
684
|
/**
|
|
683
|
-
* The
|
|
684
|
-
*
|
|
685
|
-
* `gea::CallableObject<Abi>::entryWithFacts<&thunk>(name, length,
|
|
686
|
-
* which
|
|
685
|
+
* The entry a minting site stores in a callable carrier: `&thunk`, or -- when
|
|
686
|
+
* the program reads function facts -- `&thunk` with its entry record, handed
|
|
687
|
+
* back by `gea::CallableObject<Abi>::entryWithFacts<&thunk>(name, length,
|
|
688
|
+
* text)`, which publishes the facts in that record the first time any site
|
|
689
|
+
* mints this function. A function with a `[[Construct]]` thunk publishes it in
|
|
690
|
+
* the same record (`entryWithConstruct`). The runtime reads these from the
|
|
691
|
+
* record, never by the thunk's address, which a release link may share with
|
|
692
|
+
* another function of identical code.
|
|
687
693
|
*
|
|
688
|
-
*
|
|
694
|
+
* Publication lives HERE, at the mint, and not beside the thunk, because a
|
|
689
695
|
* namespace-scope `static const bool ... = registerSource<&thunk>(...)` is a
|
|
690
696
|
* static initializer that takes the thunk's address, and a static initializer
|
|
691
697
|
* with a side effect is a root the linker may not drop. Every emitted
|
|
@@ -716,9 +722,14 @@ export const cppStaticPrefixCallableText = (ctx, functionId, slotType, sourceTyp
|
|
|
716
722
|
export const cppThunkEntryText = (ctx, functionId) => {
|
|
717
723
|
const thunk = `&${cppThunkName(functionId)}`;
|
|
718
724
|
const abi = ctx.abiOfCallable(functionId);
|
|
719
|
-
|
|
720
|
-
|
|
725
|
+
// A function with a `[[Construct]]` thunk publishes it in the entry's
|
|
726
|
+
// record, so a later `gea::withConstructEntry` finds it from the value.
|
|
727
|
+
const construct = (entry) => abi !== null && ctx.constructEntries?.has(functionId) === true
|
|
728
|
+
? `gea::CallableObject<${cppAbiType(abi)}>::entryWithConstruct<${thunk}, &${cppConstructedThunkName(functionId)}>(${entry})`
|
|
721
729
|
: entry;
|
|
730
|
+
const frame = (entry) => construct(abi !== null && (abi.restFrom !== null || abi.receiver !== null)
|
|
731
|
+
? `gea::CallableObject<${cppAbiType(abi)}>::entryWithArgumentFrame<${thunk}, ${cppCallableFrameArguments(abi)}>(${entry})`
|
|
732
|
+
: entry);
|
|
722
733
|
const facts = ctx.functionFacts.get(functionId);
|
|
723
734
|
if (facts === undefined)
|
|
724
735
|
return frame(thunk);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { representationKey } from '../../representation/model.js';
|
|
1
|
+
import { carriesNativeUndefined, representationKey } from '../../representation/model.js';
|
|
2
|
+
import { hasReferenceIdentity } from '../../representation/collections.js';
|
|
2
3
|
import { absenceComparisonText } from './emit-presence.js';
|
|
3
4
|
import { emptyArraySentinelText } from './emit-narrowing.js';
|
|
4
5
|
import { typeofAnswersFor, typeofTextFor } from './emit-typeof.js';
|
|
@@ -63,6 +64,22 @@ const nativeRecordIdentityCarrier = (value) => (value.kind === 'class-ref' || va
|
|
|
63
64
|
value.ownership === 'shared-refcount';
|
|
64
65
|
const callableIdentityCarrier = (representation) => representation.kind === 'function-value-dispatch' || representation.kind === 'function-and-constructor';
|
|
65
66
|
const negate = (operator, text) => operator === '!==' ? (text === 'true' ? 'false' : text === 'false' ? 'true' : `!(${text})`) : text;
|
|
67
|
+
/** Only a host-declared owner identity permits comparison of native wrappers.
|
|
68
|
+
* Two views must also name the same native carrier; no host protocol names or
|
|
69
|
+
* C++ wrapper layout are inferred here. The runtime identity hook is the same
|
|
70
|
+
* one used by native weak keys, and does not box or copy either operand.
|
|
71
|
+
*/
|
|
72
|
+
const nativeHandleIdentityText = (left, right) => {
|
|
73
|
+
const a = left.representation;
|
|
74
|
+
const b = right.representation;
|
|
75
|
+
return a.kind === 'native-handle' &&
|
|
76
|
+
b.kind === 'native-handle' &&
|
|
77
|
+
a.native === b.native &&
|
|
78
|
+
hasReferenceIdentity(a) &&
|
|
79
|
+
hasReferenceIdentity(b)
|
|
80
|
+
? `gea::weakCollectionIdentity(${left.text}) == gea::weakCollectionIdentity(${right.text})`
|
|
81
|
+
: null;
|
|
82
|
+
};
|
|
66
83
|
/** One arm's comparison against a same-carrier value, or `null` when this backend cannot state it. */
|
|
67
84
|
/**
|
|
68
85
|
* The answer for two carriers that are not the same key, when neither is a sum
|
|
@@ -102,6 +119,9 @@ const foldedCarrierMismatchText = (left, right) => {
|
|
|
102
119
|
const armEqualityText = (arm, leftText, rightText, convert) => {
|
|
103
120
|
if (isAbsentArm(arm))
|
|
104
121
|
return 'true';
|
|
122
|
+
const native = nativeHandleIdentityText({ text: leftText, representation: arm }, { text: rightText, representation: arm });
|
|
123
|
+
if (native !== null)
|
|
124
|
+
return native;
|
|
105
125
|
const callable = callableIdentityEqualityText('===', { text: leftText, representation: arm }, { text: rightText, representation: arm });
|
|
106
126
|
if (callable !== null)
|
|
107
127
|
return callable;
|
|
@@ -348,6 +368,9 @@ export const strictEqualityText = (operator, left, right, convert) => {
|
|
|
348
368
|
const absent = absenceComparisonText(operator, left, right);
|
|
349
369
|
if (absent !== null)
|
|
350
370
|
return absent;
|
|
371
|
+
const native = nativeHandleIdentityText(left, right);
|
|
372
|
+
if (native !== null)
|
|
373
|
+
return negate(operator, native);
|
|
351
374
|
// The box on either side. Answered before the sums below because a
|
|
352
375
|
// `dynamic` operand settles the comparison whatever the other side is: the
|
|
353
376
|
// tag `Value` carries IS 7.2.16's Type(x), so step 1 is a runtime test
|
|
@@ -563,6 +586,23 @@ export const strictEqualityText = (operator, left, right, convert) => {
|
|
|
563
586
|
if (index < 0 || other.representation.kind === 'class-ref' || callableIdentityCarrier(other.representation)) {
|
|
564
587
|
const nested = [];
|
|
565
588
|
for (const [nestedIndex, arm] of union.arms.entries()) {
|
|
589
|
+
// An absent arm against a carrier that holds its own absence. `Ref<T>`
|
|
590
|
+
// is also the collapsed `T | null` and carries `undefined` as
|
|
591
|
+
// `Ref::undefined()`, so `null === null` is a live pairing here, not a
|
|
592
|
+
// carrier mismatch to skip. Skipping it answered three's
|
|
593
|
+
// `renderTargetProperties.__boundDepthTexture !== renderTarget.depthTexture`
|
|
594
|
+
// (`undefined | null | DepthTexture` against a null `Ref`) `true` on
|
|
595
|
+
// every call, so `setRenderTarget` re-ran `setupDepthRenderbuffer` each
|
|
596
|
+
// time and a cube target leaked six depth renderbuffers per face bound.
|
|
597
|
+
// `armPairEqualityText` already asks the same state test for two sums.
|
|
598
|
+
if (isAbsentArm(arm.value) && carriesNativeUndefined(other.representation)) {
|
|
599
|
+
const absent = absenceComparisonText('===', { text: `${unionText}.get<${nestedIndex}>()`, representation: arm.value }, other);
|
|
600
|
+
if (absent === null)
|
|
601
|
+
return null;
|
|
602
|
+
if (absent !== 'false')
|
|
603
|
+
nested.push(absent === 'true' ? `${unionText}.is<${nestedIndex}>()` : `(${unionText}.is<${nestedIndex}>() && ${absent})`);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
566
606
|
if (index < 0 && sameNumericType(arm.value, other.representation)) {
|
|
567
607
|
nested.push(`(${unionText}.is<${nestedIndex}>() && (${unionText}.get<${nestedIndex}>() == ${other.text}))`);
|
|
568
608
|
continue;
|
|
@@ -347,6 +347,18 @@ const preparePart = (body, rendering, region, entry, join, describe) => {
|
|
|
347
347
|
* one function never collide, and so the declarations are stable across builds.
|
|
348
348
|
*/
|
|
349
349
|
const finallyGuardType = 'const gea::ScopeExit';
|
|
350
|
+
/**
|
|
351
|
+
* The fences every native `try` statement is written with: nothing at all
|
|
352
|
+
* except under the MSVC ABI, where `gea_runtime.h`'s `GEA_EH_FENCED` makes
|
|
353
|
+
* them a scope of its own around the statement and a first statement inside
|
|
354
|
+
* the try block. That header's comment on `GEA_EH_FENCED` has the two LLVM
|
|
355
|
+
* defects they avoid. A handler that is not already record-only is written
|
|
356
|
+
* with `GEA_EH_TRY_*`/`GEA_EH_CATCH_*` instead, which add the fences and
|
|
357
|
+
* record the catch, running the handler after the statement.
|
|
358
|
+
*/
|
|
359
|
+
const ehFenceOpen = 'GEA_EH_FENCE_OPEN';
|
|
360
|
+
const ehBodyFence = 'GEA_EH_BODY_FENCE';
|
|
361
|
+
const ehFenceClose = 'GEA_EH_FENCE_CLOSE';
|
|
350
362
|
const finallyGuardName = (region) => cppFinallyGuardName(region.region);
|
|
351
363
|
const finallyPendingName = (region) => cppFinallyPendingName(region.region);
|
|
352
364
|
/**
|
|
@@ -523,11 +535,11 @@ export const renderTryRegion = (ctx, lines, body, region, rendering) => {
|
|
|
523
535
|
lines.push(`${finallyGuardType} ${finallyGuardName(region)}{[&]() {`);
|
|
524
536
|
lines.push(...renderPart(ctx, body, finallyRendering(rendering), finallyPart.order, finallyPart.owned, false, true));
|
|
525
537
|
lines.push('}};');
|
|
526
|
-
lines.push(
|
|
538
|
+
lines.push(`${ehFenceOpen} try { ${ehBodyFence}`);
|
|
527
539
|
}
|
|
528
540
|
lines.push(...renderTryAndCatch(ctx, body, region, rendering, tryPart, catchPart, binding, catchSuspends));
|
|
529
541
|
if (finallyPart) {
|
|
530
|
-
lines.push(`} catch (...) { ${finallyPendingName(region)} = std::current_exception(); }`);
|
|
542
|
+
lines.push(`} catch (...) { ${finallyPendingName(region)} = std::current_exception(); } ${ehFenceClose}`);
|
|
531
543
|
lines.push('}');
|
|
532
544
|
lines.push(`if (${finallyPendingName(region)}) std::rethrow_exception(${finallyPendingName(region)});`);
|
|
533
545
|
lines.push('}');
|
|
@@ -550,22 +562,28 @@ const renderTryAndCatch = (ctx, body, region, rendering, tryPart, catchPart, bin
|
|
|
550
562
|
if (catchPart === null)
|
|
551
563
|
return renderPart(ctx, body, rendering, tryPart.order, tryPart.owned, false, true);
|
|
552
564
|
if (!catchSuspends) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
565
|
+
// `GEA_EH_TRY_*`/`GEA_EH_CATCH_*` are the plain `try`/`catch` everywhere
|
|
566
|
+
// but the MSVC ABI, where they record the catch and run the handler after
|
|
567
|
+
// the statement -- see `ehFenceOpen`.
|
|
568
|
+
const slot = `${finallyPendingName(region)}_caught`;
|
|
569
|
+
// Named before the body renders, which numbers its own values after it.
|
|
570
|
+
const name = binding ? defineValueBoundElsewhere(ctx, binding.result) : null;
|
|
556
571
|
const tryText = renderPart(ctx, body, rendering, tryPart.order, tryPart.owned, false, true);
|
|
557
|
-
|
|
572
|
+
if (name !== null)
|
|
573
|
+
lines.push(`GEA_EH_TRY_VALUE(${slot}) {`, ...tryText, '}', `GEA_EH_CATCH_VALUE(${slot}, ${name}) {`);
|
|
574
|
+
else
|
|
575
|
+
lines.push(`GEA_EH_TRY_ANY(${slot}) {`, ...tryText, '}', `GEA_EH_CATCH_ANY(${slot}) {`);
|
|
558
576
|
lines.push(...renderPart(ctx, body, rendering, catchPart.order, catchPart.owned, binding !== null, false));
|
|
559
|
-
lines.push('}');
|
|
577
|
+
lines.push('}', 'GEA_EH_END');
|
|
560
578
|
return lines;
|
|
561
579
|
}
|
|
562
580
|
const tryText = renderPart(ctx, body, rendering, tryPart.order, tryPart.owned, false, true);
|
|
563
581
|
const caught = `${finallyPendingName(region)}_caught`;
|
|
564
582
|
const thrownType = cppTypeOf(thrownValueCarrier);
|
|
565
583
|
const record = binding
|
|
566
|
-
? `catch (const ${thrownType}& gea_thrown) { ${defineValue(ctx, binding.result, thrownType)}
|
|
584
|
+
? `catch (const ${thrownType}& gea_thrown) { GEA_EH_ASSIGN_THROWN(${defineValue(ctx, binding.result, thrownType)}, gea_thrown); ${caught} = true; }`
|
|
567
585
|
: `catch (...) { ${caught} = true; }`;
|
|
568
|
-
lines.push('{', `bool ${caught} = false;`,
|
|
586
|
+
lines.push('{', `bool ${caught} = false;`, `${ehFenceOpen} try { ${ehBodyFence}`, ...tryText, '}', `${record} ${ehFenceClose}`, `if (${caught}) {`);
|
|
569
587
|
lines.push(...renderPart(ctx, body, rendering, catchPart.order, catchPart.owned, binding !== null, false));
|
|
570
588
|
lines.push('}', '}');
|
|
571
589
|
return lines;
|
|
@@ -660,8 +678,8 @@ const renderSuspendingFinally = (ctx, lines, body, region, rendering, statementO
|
|
|
660
678
|
}
|
|
661
679
|
};
|
|
662
680
|
const statement = renderStatement(partRendering);
|
|
663
|
-
lines.push('{', `std::exception_ptr ${pending};`, `int ${completion} = 0;`,
|
|
664
|
-
lines.push(`catch (...) { ${pending} = std::current_exception(); }`, `goto ${run};`);
|
|
681
|
+
lines.push('{', `std::exception_ptr ${pending};`, `int ${completion} = 0;`, `${ehFenceOpen} try { ${ehBodyFence}`, ...statement, '}');
|
|
682
|
+
lines.push(`catch (...) { ${pending} = std::current_exception(); } ${ehFenceClose}`, `goto ${run};`);
|
|
665
683
|
exits.forEach((_, index) => lines.push(`${exitLabel(index)}: ${completion} = ${index + 1}; goto ${run};`));
|
|
666
684
|
lines.push(`${run}:`);
|
|
667
685
|
const clauseRendering = {
|