@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
|
@@ -632,10 +632,22 @@ const liveRecordFieldsText = (ctx, plan, live, text) => {
|
|
|
632
632
|
let write = null;
|
|
633
633
|
if (read.kind === 'held' || read.kind === 'view') {
|
|
634
634
|
const type = cppTypeOf(route.read);
|
|
635
|
-
|
|
635
|
+
// An optional source field the source object does not have reads
|
|
636
|
+
// `undefined`: the target's own absence for an `optional`, or the
|
|
637
|
+
// `undefined` arm of a union that states one (three's
|
|
638
|
+
// `options.internalFormat`, `string | null | undefined`, read through
|
|
639
|
+
// the view a render target builds over a caller's options literal that
|
|
640
|
+
// never named it -- the source has no own field to answer from).
|
|
641
|
+
const undefinedArm = route.read.kind === 'tagged-union' ? route.read.arms.findIndex((arm) => arm.value.kind === 'undefined') : -1;
|
|
642
|
+
const absentValue = route.read.kind === 'optional' && route.read.absence === 'undefined'
|
|
643
|
+
? `${type}{}`
|
|
644
|
+
: undefinedArm >= 0
|
|
645
|
+
? `${type}::ofArm<${undefinedArm}>(gea::Undefined{})`
|
|
646
|
+
: null;
|
|
647
|
+
const absence = !read.held.required && absentValue !== null
|
|
636
648
|
? `bool gea_origin_present = false; if (!${actual}->gea_ownFieldPresent(gea_key, gea_origin_present)) ` +
|
|
637
649
|
'gea::host::throwRuntimeError("TypeError", "a live native field has no source presence protocol"); ' +
|
|
638
|
-
`if (!gea_origin_present) return ${
|
|
650
|
+
`if (!gea_origin_present) return ${absentValue}; `
|
|
639
651
|
: '';
|
|
640
652
|
got =
|
|
641
653
|
`([&]() -> ${type} { ${absence}std::optional<${type}> gea_origin_field; gea::NativeFieldRead gea_origin_read(gea_origin_field); ` +
|
|
@@ -493,16 +493,38 @@ const joinedToStringText = (ctx, operands, separator) => {
|
|
|
493
493
|
* template assigned to a local. Anything else keeps `fallback`'s spelling.
|
|
494
494
|
*/
|
|
495
495
|
export const stringStoreText = (target, text, fallback) => {
|
|
496
|
+
// Building into the target is only sound while no piece reads the target
|
|
497
|
+
// itself: `prefix = defines.join( '\n' ) + '\n' + prefix` (three's
|
|
498
|
+
// WebGLProgram GLSL3 wrapping) adopted the head into `prefix` first and then
|
|
499
|
+
// appended the overwritten `prefix`, losing the original prefix and
|
|
500
|
+
// doubling the head. Such a store keeps `fallback`'s temporary. Appending
|
|
501
|
+
// to the target's own moved head (`a = a + x`) reads it before any write,
|
|
502
|
+
// so that one stays in place.
|
|
496
503
|
const appended = appendedPiecesOf(text);
|
|
497
504
|
if (appended !== null) {
|
|
498
|
-
const
|
|
505
|
+
const inPlace = appended.head === `std::move(${target})`;
|
|
506
|
+
// `gea::appendStrings` itself tolerates a piece aliasing the target; the
|
|
507
|
+
// adoption that precedes it does not.
|
|
508
|
+
if (!inPlace && (readsTarget(appended.pieces, target) || readsTarget(appended.head, target)))
|
|
509
|
+
return fallback;
|
|
510
|
+
const adopt = inPlace ? '' : `gea::detail::adoptString(${target}, ${appended.head}); `;
|
|
499
511
|
return `${adopt}gea::appendStrings(${target}, ${appended.pieces});`;
|
|
500
512
|
}
|
|
501
513
|
// The pieces as arguments rather than a list of views, so each keeps its type: a literal's size is a constant
|
|
502
514
|
// and a formatted number is stored from its register (`gea::concatStringsInto`'s variadic form).
|
|
503
515
|
const pieces = concatenationPiecesOf(text);
|
|
516
|
+
// `gea::concatStringsInto` detects a piece aliasing the target and builds aside (`concatStringsAliased`).
|
|
504
517
|
return pieces === null ? fallback : `gea::concatStringsInto(${target}, ${pieces});`;
|
|
505
518
|
};
|
|
519
|
+
/** Whether rendered C++ `text` names the expression `target` (bounded, so `m2` does not match `m20`). */
|
|
520
|
+
const readsTarget = (text, target) => {
|
|
521
|
+
for (let at = text.indexOf(target); at >= 0; at = text.indexOf(target, at + 1)) {
|
|
522
|
+
if (!isIdentifierCharacter(text[at - 1]) && !isIdentifierCharacter(text[at + target.length]))
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
525
|
+
return false;
|
|
526
|
+
};
|
|
527
|
+
const isIdentifierCharacter = (c) => c !== undefined && ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c === '_');
|
|
506
528
|
/** The moved head and appended pieces of a rendered `gea::appendedStrings(std::move(head), {...})`, or `null`. */
|
|
507
529
|
const appendedPiecesOf = (text) => {
|
|
508
530
|
let inner = text.trim();
|
|
@@ -103,7 +103,7 @@ const armFieldSite = (ctx, arm, armExprText, key, write = false) => {
|
|
|
103
103
|
return null;
|
|
104
104
|
if (arm.kind === 'class-ref') {
|
|
105
105
|
const member = classMemberOf(ctx.classes, arm.declaration, key);
|
|
106
|
-
// A method some write shadows with an own property (
|
|
106
|
+
// A method some write shadows with an own property (an HTTP framework's routers'
|
|
107
107
|
// `this.match = match`) has a physical override slot, and a STORE lands in
|
|
108
108
|
// it: that slot is the field `declaredRecordFieldOf` answers, the one the
|
|
109
109
|
// IR certified the store's conversion against, and a lone class receiver
|
|
@@ -20,5 +20,5 @@ import type { IntegerStorageFacts } from '../../ir/integers.js';
|
|
|
20
20
|
import { type InstantiationFacts } from '../../ir/instantiation.js';
|
|
21
21
|
import { type CallableIdentityDemand } from '../../ir/callable-identity-demand.js';
|
|
22
22
|
import type { HostMethodAlias } from './host/host-method-aliases.js';
|
|
23
|
-
export declare const emitBody: (body: IrBody, placements: ReadonlyMap<DeclarationId, BindingPlacement>, classes: ReadonlyMap<DeclarationId, ClassLayout>, hosts: HostSpellings, deriver: RepresentationDeriver, wellKnownSymbols: ReadonlyMap<DeclarationId, string> | undefined, captures: CaptureIndex | undefined, symbolKeys: Map<string, string>, templateObjects: Map<string, TemplateObjectDefinition>, directCallableBindings?: ReadonlyMap<DeclarationId, FunctionId>, virtualDispatch?: ReadonlyMap<string, CallableAbi>, narrowedStorage?: IntegerStorageFacts, narrowedFormals?: ReadonlySet<number>, repeatedConstructors?: ReadonlyMap<DeclarationId, DeclarationId>, dyingArguments?: ReadonlySet<IrValueId>, instantiation?: InstantiationFacts, abiOfCallable?: (callable: FunctionId) => IrBody["abi"], 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>, constructionOnlyFields?: ConstructionOnlyFields, keyOrderUnobserved?: ReadonlySet<string>, debugSource?: NativeDebugSource, borrowedFormals?: ReadonlySet<number>, taskResults?: ReadonlySet<IrValueId>, conversionIsCertified?: (id: string) => boolean, programConversionRecipes?: readonly ProgramConversionRecipe[], physicalIndexProtocols?: ReadonlyMap<DeclarationId, boolean>) => readonly CppArtifact[];
|
|
23
|
+
export declare const emitBody: (body: IrBody, placements: ReadonlyMap<DeclarationId, BindingPlacement>, classes: ReadonlyMap<DeclarationId, ClassLayout>, hosts: HostSpellings, deriver: RepresentationDeriver, wellKnownSymbols: ReadonlyMap<DeclarationId, string> | undefined, captures: CaptureIndex | undefined, symbolKeys: Map<string, string>, templateObjects: Map<string, TemplateObjectDefinition>, directCallableBindings?: ReadonlyMap<DeclarationId, FunctionId>, virtualDispatch?: ReadonlyMap<string, CallableAbi>, narrowedStorage?: IntegerStorageFacts, narrowedFormals?: ReadonlySet<number>, repeatedConstructors?: ReadonlyMap<DeclarationId, DeclarationId>, dyingArguments?: ReadonlySet<IrValueId>, instantiation?: InstantiationFacts, abiOfCallable?: (callable: FunctionId) => IrBody["abi"], 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>, constructionOnlyFields?: ConstructionOnlyFields, keyOrderUnobserved?: ReadonlySet<string>, debugSource?: NativeDebugSource, borrowedFormals?: ReadonlySet<number>, taskResults?: ReadonlySet<IrValueId>, conversionIsCertified?: (id: string) => boolean, programConversionRecipes?: readonly ProgramConversionRecipe[], physicalIndexProtocols?: ReadonlyMap<DeclarationId, boolean>) => readonly CppArtifact[];
|
|
24
24
|
export { cppConstructedThunkName, cppConstructThunkName, cppFormalName, cppReceiverName, cppThunkName, isCppEmitBlockedError } from './emit-context.js';
|
package/dist/targets/cpp/emit.js
CHANGED
|
@@ -8,6 +8,7 @@ import { intrinsicAccessorGetterOfOperator } from '../../semantics/model/intrins
|
|
|
8
8
|
import { stableBorrowActualsOf } from '../../ir/borrowed-call-arguments.js';
|
|
9
9
|
import { lazySplitsOf } from '../../ir/lazy-splits.js';
|
|
10
10
|
import { borrowedArmProjectionsOf } from './borrowed-arm-projections.js';
|
|
11
|
+
import { redundantPureConversionsOf } from '../../ir/pure-conversion-reuse.js';
|
|
11
12
|
import { owningConversionInputText } from './owning-conversion-input.js';
|
|
12
13
|
import { boxedValueText } from './emit-dynamic-properties.js';
|
|
13
14
|
import { stableCellReadsOf } from '../../ir/stable-cell-reads.js';
|
|
@@ -18,8 +19,9 @@ import { recordFieldsOfShape } from '../../projection/fields.js';
|
|
|
18
19
|
import { allOperationsOf } from '../../ir/model.js';
|
|
19
20
|
import { operandsOfIrOperation, resultOfIrOperation } from '../../ir/queries.js';
|
|
20
21
|
import { namesMoreThanOnce } from './evaluated-once.js';
|
|
21
|
-
import { isOpenDocument, representationKey } from '../../representation/model.js';
|
|
22
|
-
import {
|
|
22
|
+
import { carriesNativeUndefined, isOpenDocument, representationKey } from '../../representation/model.js';
|
|
23
|
+
import { classFamilyMayAllocate } from '../../projection/dispatch.js';
|
|
24
|
+
import { copiedCaptureName, cppFormalName, cppReceiverName, createCppEmitBlockedError, createEmitContext, defineValue, defineValueAlias, nameOfValue, directCalleesOf, directCallableValuesOf, integerWideningsOf, emptyCaptureIndex, isFloatStorageValue, isIntegerStorageValue, isCppEmitBlockedError, operandText, storageTypeOf, cppThunkEntryText, sealFactFieldsForRender, suspendsInPlace, cppDensePointerName, declaredIntegerTypeOf } from './emit-context.js';
|
|
23
25
|
import { hostMemberReadsOf } from './host/emit-host-properties.js';
|
|
24
26
|
import { functionSourceReadsOf } from './function-source-reads.js';
|
|
25
27
|
import { prototypeMethodReadsOf } from './prototype/prototype-method-reads.js';
|
|
@@ -31,7 +33,7 @@ import { declarationScopesOf, gotoTargetsOf, identifiersOf, scopePlanOf } from '
|
|
|
31
33
|
import { segmentScopedBodyOf } from './segment-scopes.js';
|
|
32
34
|
import { emitReturn } from './emit-return.js';
|
|
33
35
|
import { collectDirectBindingSinks, classObjectReadsOf, hostClassReadsOf, collectFormalCells, earlyCapturedCellPrologue, emitBindingRead, emitBindingRenew, emitBindingWrite } from './emit-bindings.js';
|
|
34
|
-
import { alignedValueText, unsharedArrayRebuildText, documentViewable, dynamicCarrierBoxText, emitMergeLiveArmRebuild, namedConversionText, movedValueText } from './emit-narrowing.js';
|
|
36
|
+
import { alignedValueText, unsharedArrayRebuildText, unsharedDictionaryRebuildText, documentViewable, dynamicCarrierBoxText, emitMergeLiveArmRebuild, namedConversionText, movedValueText } from './emit-narrowing.js';
|
|
35
37
|
import { operationConversionText } from './emit-certified-conversion.js';
|
|
36
38
|
import { collectCharCodeBuffers } from './char-code-buffers.js';
|
|
37
39
|
import { admitDenseWindows, collectCapacityHints, emitAllocateArrayObject, emitDenseSetup, emitFillLoop, isConstantExpression } from './emit-arrays.js';
|
|
@@ -1087,6 +1089,29 @@ const emitTest = (ctx, lines, operation) => {
|
|
|
1087
1089
|
: booleanTestText(text, carrier, isIntegerStorageValue(ctx, operation.value.value));
|
|
1088
1090
|
lines.push(`${name} = ${answer};`);
|
|
1089
1091
|
};
|
|
1092
|
+
/**
|
|
1093
|
+
* A class instance recast into a record view whose class family the
|
|
1094
|
+
* allocation census (`classFamilyMayAllocate`) proves never has an instance.
|
|
1095
|
+
*
|
|
1096
|
+
* A live view of a class is installed per allocated family member, so such a
|
|
1097
|
+
* family has none and its view renders nothing. The conversion still sits on a
|
|
1098
|
+
* path the program cannot take with an object -- node-compat's
|
|
1099
|
+
* `if (destination instanceof Duplex) streams[index].pipe(destination)` in a
|
|
1100
|
+
* program that constructs no `Duplex` -- so the handle can only be nullish
|
|
1101
|
+
* there. Nullish maps to the target's own nullish lanes, exactly as the view's
|
|
1102
|
+
* render does (`certifiedRecordViewText`); an object traps, at the published
|
|
1103
|
+
* carrier, as an abstract member read of such a family does.
|
|
1104
|
+
*/
|
|
1105
|
+
const unallocatedClassViewText = (ctx, source, target, text) => {
|
|
1106
|
+
if (source.kind !== 'class-ref' || classFamilyMayAllocate(ctx.classes, source.declaration))
|
|
1107
|
+
return null;
|
|
1108
|
+
if (!carriesNativeUndefined(source) || !carriesNativeUndefined(target))
|
|
1109
|
+
return null;
|
|
1110
|
+
const targetType = cppTypeOf(target);
|
|
1111
|
+
const failure = `std::fprintf(stderr, "gea: no instance of class ${String(source.declaration)}'s family exists to view\\n"); std::abort();`;
|
|
1112
|
+
return (`([&](const auto& gea_unallocated) -> ${targetType} { if (gea_unallocated.isUndefined()) return ${targetType}::undefined(); ` +
|
|
1113
|
+
`if (!gea_unallocated) return ${targetType}(); ${failure} })(${text})`);
|
|
1114
|
+
};
|
|
1090
1115
|
/**
|
|
1091
1116
|
* A conversion the graph made explicit, rendered by the one authority on what
|
|
1092
1117
|
* a narrowing loads.
|
|
@@ -1139,6 +1164,13 @@ const emitConvert = (ctx, lines, operation) => {
|
|
|
1139
1164
|
defineValueAlias(ctx, operation.result, '(void)0');
|
|
1140
1165
|
return;
|
|
1141
1166
|
}
|
|
1167
|
+
// A repeat of a dominating pure conversion of the same value names that
|
|
1168
|
+
// conversion's storage instead of converting again (`ir/pure-conversion-reuse.ts`).
|
|
1169
|
+
const repeated = ctx.repeatedConversions.get(operation.result.id);
|
|
1170
|
+
if (repeated !== undefined) {
|
|
1171
|
+
defineValueAlias(ctx, operation.result, nameOfValue(ctx, repeated));
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1142
1174
|
// A string arm of a borrowed union formal: name it where it is read instead of copying it out (`borrowed-arm-projections.ts`).
|
|
1143
1175
|
const projection = ctx.borrowedArmProjections.get(operation.result.id);
|
|
1144
1176
|
if (projection !== undefined && projection.arm !== null) {
|
|
@@ -1168,11 +1200,23 @@ const emitConvert = (ctx, lines, operation) => {
|
|
|
1168
1200
|
lines.push(`${defineValue(ctx, operation.result)} = ${sourceText};`);
|
|
1169
1201
|
return;
|
|
1170
1202
|
}
|
|
1203
|
+
if (operation.rebuild === 'unshared-dictionary') {
|
|
1204
|
+
const entryNode = ctx.conversions.nodeById(operation.conversionUse);
|
|
1205
|
+
const rebuilt = entryNode === null
|
|
1206
|
+
? null
|
|
1207
|
+
: unsharedDictionaryRebuildText(ctx, operation.source.representation, operation.result.representation, sourceText, entryNode);
|
|
1208
|
+
if (rebuilt === null) {
|
|
1209
|
+
throw createCppEmitBlockedError(`conversion:${representationKey(operation.source.representation)}->${representationKey(operation.result.representation)}`, `rebuilds a fresh ${representationKey(operation.source.representation)} at ${representationKey(operation.result.representation)}, ` +
|
|
1210
|
+
`whose entry conversion no installed load performs (conversion use ${operation.conversionUse})`);
|
|
1211
|
+
}
|
|
1212
|
+
lines.push(`${defineValue(ctx, operation.result)} = ${rebuilt};`);
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1171
1215
|
if (operation.rebuild === 'unshared-array') {
|
|
1172
1216
|
const elementNode = ctx.conversions.nodeById(operation.conversionUse);
|
|
1173
1217
|
const rebuilt = elementNode === null
|
|
1174
1218
|
? null
|
|
1175
|
-
: unsharedArrayRebuildText(ctx, operation.source.representation, operation.result.representation, sourceText, elementNode);
|
|
1219
|
+
: unsharedArrayRebuildText(ctx, operation.source.representation, operation.result.representation, sourceText, elementNode, operation.releasesSource === true);
|
|
1176
1220
|
if (rebuilt === null) {
|
|
1177
1221
|
throw createCppEmitBlockedError(`conversion:${representationKey(operation.source.representation)}->${representationKey(operation.result.representation)}`, `rebuilds a fresh ${representationKey(operation.source.representation)} at ${representationKey(operation.result.representation)}, ` +
|
|
1178
1222
|
`whose element conversion no installed load performs (conversion use ${operation.conversionUse})`);
|
|
@@ -1183,7 +1227,8 @@ const emitConvert = (ctx, lines, operation) => {
|
|
|
1183
1227
|
// An instruction cites one recipe, including contextual reads and native
|
|
1184
1228
|
// method views; re-looking up its pair would discard that authority.
|
|
1185
1229
|
const named = ctx.conversions.nodeById(operation.conversionUse);
|
|
1186
|
-
const text = named === null ? null : namedConversionText(ctx, 'emit.ts:conversion', named, sourceText)
|
|
1230
|
+
const text = (named === null ? null : namedConversionText(ctx, 'emit.ts:conversion', named, sourceText)) ??
|
|
1231
|
+
unallocatedClassViewText(ctx, operation.source.representation, operation.result.representation, sourceText);
|
|
1187
1232
|
if (text === null) {
|
|
1188
1233
|
throw createCppEmitBlockedError(`conversion:${representationKey(operation.source.representation)}->${representationKey(operation.result.representation)}`, `converts ${representationKey(operation.source.representation)} to ${representationKey(operation.result.representation)}, ` +
|
|
1189
1234
|
`which no installed load performs (conversion use ${operation.conversionUse})`);
|
|
@@ -1208,7 +1253,15 @@ const emitConvert = (ctx, lines, operation) => {
|
|
|
1208
1253
|
return;
|
|
1209
1254
|
}
|
|
1210
1255
|
}
|
|
1211
|
-
|
|
1256
|
+
// A conversion that renders as its source's own name is a copy of one local
|
|
1257
|
+
// into another of the same physical carrier, and a dying source can hand its
|
|
1258
|
+
// storage over instead: `const u = uniforms['ambientLightColor']` widened its
|
|
1259
|
+
// optional uniform record into the binding's identical carrier with a retain
|
|
1260
|
+
// here and a release at the end of the scope, per light uniform per refresh.
|
|
1261
|
+
const handedOver = consumed === text && (text === plain || text === `(${plain})`)
|
|
1262
|
+
? movedValueText(ctx, operation.source, operation.result.representation, plain)
|
|
1263
|
+
: consumed;
|
|
1264
|
+
lines.push(`${defineValue(ctx, operation.result)} = ${handedOver};`);
|
|
1212
1265
|
};
|
|
1213
1266
|
/**
|
|
1214
1267
|
* `await p`.
|
|
@@ -2384,7 +2437,7 @@ export const emitBody = (body, placements, classes, hosts, deriver, wellKnownSym
|
|
|
2384
2437
|
symbolKeys, templateObjects, directCallableBindings = new Map(),
|
|
2385
2438
|
// `virtualDispatch` is every `class key` with a dispatch member (`virtual-methods.ts`);
|
|
2386
2439
|
// `narrowedStorage`/`narrowedFormals` are what the integer census settled here.
|
|
2387
|
-
virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new Set(), magnitudes: 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 = [], conversions = null, nativeSelections = undefined, callableIdentityDemand = observesEveryCallableIdentity, nativeIntegrityRestricted = restrictsEveryCarrier, fixedFieldStateConstant = false, definitionCells = new Set(), constructionOnlyFields = noConstructionOnlyFields, keyOrderUnobserved = new Set(), debugSource, borrowedFormals = new Set(), taskResults = new Set(), conversionIsCertified, programConversionRecipes, physicalIndexProtocols) => {
|
|
2440
|
+
virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new Set(), magnitudes: 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 = [], conversions = null, nativeSelections = undefined, callableIdentityDemand = observesEveryCallableIdentity, nativeIntegrityRestricted = restrictsEveryCarrier, fixedFieldStateConstant = false, definitionCells = new Set(), constructionOnlyFields = noConstructionOnlyFields, keyOrderUnobserved = new Set(), debugSource, borrowedFormals = new Set(), taskResults = new Set(), conversionIsCertified, programConversionRecipes, physicalIndexProtocols) => {
|
|
2388
2441
|
// Every fact this body settles before a single line renders, computed here
|
|
2389
2442
|
// -- from `body` and the plain, already-available inputs above -- and
|
|
2390
2443
|
// handed to `createEmitContext` as one argument instead of mutated onto the
|
|
@@ -2410,6 +2463,31 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2410
2463
|
const borrowedArmProjections = borrowedArmProjectionsOf(body, stableBorrowEntries.get(cppBodyName(body.sourceOwner)), conversions);
|
|
2411
2464
|
// Each such view is a reference into a borrowed formal, so it is as stable an actual as the formal.
|
|
2412
2465
|
const stableWithProjections = new Set([...stableBorrowActuals, ...borrowedArmProjections.keys()]);
|
|
2466
|
+
// A pure conversion repeated under a dominating one of the same value names
|
|
2467
|
+
// the earlier one's storage (`ir/pure-conversion-reuse.ts`). That storage
|
|
2468
|
+
// then answers both results' uses, so neither may be moved from or withheld.
|
|
2469
|
+
const repeatedConversions = new Map(conversions === null
|
|
2470
|
+
? []
|
|
2471
|
+
: [
|
|
2472
|
+
...redundantPureConversionsOf(body, conversions, (declaration) => {
|
|
2473
|
+
const placement = placements.get(declaration);
|
|
2474
|
+
return placement?.storage.kind === 'local' && placement.storage.owner === body.sourceOwner && !captures.isBoxed(declaration);
|
|
2475
|
+
})
|
|
2476
|
+
].filter(([later, earlier]) => !borrowedArmProjections.has(later) && !borrowedArmProjections.has(earlier)));
|
|
2477
|
+
const pinnedConversions = new Set([...repeatedConversions.keys(), ...repeatedConversions.values()]);
|
|
2478
|
+
const pinnedOut = (values) => [...values].filter((value) => !pinnedConversions.has(value));
|
|
2479
|
+
const bodyDyingArguments = (() => {
|
|
2480
|
+
if (![...pinnedConversions].some((value) => dyingArguments.has(value)))
|
|
2481
|
+
return dyingArguments;
|
|
2482
|
+
const kept = new DyingArgumentSet();
|
|
2483
|
+
for (const value of dyingArguments)
|
|
2484
|
+
if (!pinnedConversions.has(value))
|
|
2485
|
+
kept.add(value);
|
|
2486
|
+
if (dyingArguments instanceof DyingArgumentSet)
|
|
2487
|
+
for (const [value, store] of dyingArguments.sunkStores)
|
|
2488
|
+
kept.sunkStores.set(value, store);
|
|
2489
|
+
return kept;
|
|
2490
|
+
})();
|
|
2413
2491
|
// A read has to know what the REST of the body does to the cell it reads.
|
|
2414
2492
|
// `emit-bindings.ts` lets a host object's read name its cell rather than
|
|
2415
2493
|
// copy out of it, and that identity only holds while the cell keeps
|
|
@@ -2438,8 +2516,8 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2438
2516
|
? { layout: owningClass, derived: constructedBaseOf(owningClass) !== null || owningClass.nativeBase !== null, callsSuper }
|
|
2439
2517
|
: null;
|
|
2440
2518
|
const formalInputs = ownedFormalInputsOf(body);
|
|
2441
|
-
const ownedDyingValues = new Set([...ownedDyingValuesOf(body), ...ownedDyingMergeInputsOf(body), ...formalInputs.arguments]);
|
|
2442
|
-
const transferDyingValues = new Set([...ownedDyingValues, ...dyingTransferUsesOf(body)]);
|
|
2519
|
+
const ownedDyingValues = new Set(pinnedOut([...ownedDyingValuesOf(body), ...ownedDyingMergeInputsOf(body), ...formalInputs.arguments]));
|
|
2520
|
+
const transferDyingValues = new Set(pinnedOut([...ownedDyingValues, ...dyingTransferUsesOf(body)]));
|
|
2443
2521
|
const layoutKeys = new Map();
|
|
2444
2522
|
const origins = bodyValueOriginsOf(body, (representation) => {
|
|
2445
2523
|
if (representation.kind !== 'native-record-ref' || representation.native !== null)
|
|
@@ -2467,7 +2545,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2467
2545
|
receiverValues,
|
|
2468
2546
|
bindingWriteCounts,
|
|
2469
2547
|
stableCellReads: stableCellReadsOf(body, (declaration) => placements.get(declaration)?.storage.kind === 'local'),
|
|
2470
|
-
stableFieldReads: stableFieldReadsOf(body, stableReceiversOf(body, receiverValues, borrowedFormals, bindingWriteCounts, (declaration) => captures.isBoxed(declaration)), constructionOnlyFields, nativeIntegrityRestricted,
|
|
2548
|
+
stableFieldReads: stableFieldReadsOf(body, stableReceiversOf(body, receiverValues, borrowedFormals, bindingWriteCounts, (declaration) => captures.isBoxed(declaration)), constructionOnlyFields, nativeIntegrityRestricted, bodyDyingArguments),
|
|
2471
2549
|
constructorOf,
|
|
2472
2550
|
ownedDyingValues,
|
|
2473
2551
|
transferDyingValues,
|
|
@@ -2476,6 +2554,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2476
2554
|
classTableRoots: classTableRootsOf(body),
|
|
2477
2555
|
stableBorrowActuals: stableWithProjections,
|
|
2478
2556
|
borrowedArmProjections,
|
|
2557
|
+
repeatedConversions,
|
|
2479
2558
|
computeOrigins: origins.computeOrigins,
|
|
2480
2559
|
propertyReadOrigins: origins.propertyReadOrigins,
|
|
2481
2560
|
bindingReadDeclarations: origins.bindingReadDeclarations,
|
|
@@ -2513,7 +2592,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2513
2592
|
integerWidenings: integerWideningsOf(body),
|
|
2514
2593
|
lazySplits: lazySplitsOf(body)
|
|
2515
2594
|
};
|
|
2516
|
-
const { ctx: baseCtx, prepass } = createEmitContext(body.abi, body.sourceOwner, placements, classes, hosts, deriver, bodyFacts, wellKnownSymbols, captures, symbolKeys, templateObjects, directCallableBindings, virtualDispatch, narrowedFormals, repeatedConstructors,
|
|
2595
|
+
const { ctx: baseCtx, prepass } = createEmitContext(body.abi, body.sourceOwner, placements, classes, hosts, deriver, bodyFacts, wellKnownSymbols, captures, symbolKeys, templateObjects, directCallableBindings, virtualDispatch, narrowedFormals, repeatedConstructors, bodyDyingArguments, instantiation, abiOfCallable, functionFacts, constructEntries, hostMethodAliases, callableMemberCandidates, callableFlowCandidates, borrowableMemberBodies, stableBorrowEntries, printerDrift, conversions, nativeSelections, callableIdentityDemand, nativeIntegrityRestricted, fixedFieldStateConstant, definitionCells, keyOrderUnobserved, conversionIsCertified, programConversionRecipes, physicalIndexProtocols);
|
|
2517
2596
|
const ctx = debugSource === undefined ? baseCtx : { ...baseCtx, debugSource };
|
|
2518
2597
|
// `ownedValues` stays a genuine render-time OUTPUT buffer (`EmitContext`'s
|
|
2519
2598
|
// own doc: `defineValue` grows it as each operation's result is named) --
|
|
@@ -2875,6 +2954,9 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2875
2954
|
for (const value of prepass.deferrable)
|
|
2876
2955
|
if (!census.deferrable.has(value))
|
|
2877
2956
|
prepass.deferrable.delete(value);
|
|
2957
|
+
// A repeated conversion's storage answers several results (`repeatedConversions`).
|
|
2958
|
+
for (const value of pinnedConversions)
|
|
2959
|
+
prepass.deferrable.delete(value);
|
|
2878
2960
|
const hoists = census.hoists;
|
|
2879
2961
|
// After the hoists: a fill loop's bound is as often a relocated invariant
|
|
2880
2962
|
// (`n * n`, re-read from its cells in the loop's own test) as a plain cell.
|
|
@@ -3151,9 +3233,13 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
3151
3233
|
return [
|
|
3152
3234
|
declarations,
|
|
3153
3235
|
...prologue,
|
|
3154
|
-
|
|
3236
|
+
// The plain `try`/`catch (...)` everywhere but the MSVC ABI (`GEA_EH_FENCED` in the runtime header).
|
|
3237
|
+
{ text: 'GEA_EH_TRY_ANY(gea_eh_failed) {', facts: declarationFacts },
|
|
3155
3238
|
...blocks,
|
|
3156
|
-
{
|
|
3239
|
+
{
|
|
3240
|
+
text: `} GEA_EH_CATCH_ANY(gea_eh_failed) { return ${result}::rejected_with(GEA_EH_CURRENT(gea_eh_failed)); } GEA_EH_END GEA_EH_UNREACHABLE`,
|
|
3241
|
+
facts: declarationFacts
|
|
3242
|
+
}
|
|
3157
3243
|
];
|
|
3158
3244
|
}
|
|
3159
3245
|
return [declarations, ...prologue, ...blocks];
|
|
@@ -524,8 +524,8 @@ const promiseAllOverIteratorText = (ctx, operation, argument, elements) => {
|
|
|
524
524
|
const resolver = promiseAllResolverText(ctx, 'host/emit-host-invoke.ts:promiseAllOverIteratorText', elements.element);
|
|
525
525
|
const resultType = cppTypeOf(result);
|
|
526
526
|
return (`[&]() -> ${resultType} { gea::Ref<gea::ArrayObject<${cppTypeOf(elements.element)}>> gea_elements; ` +
|
|
527
|
-
`
|
|
528
|
-
`
|
|
527
|
+
`GEA_EH_TRY_ANY(gea_eh_failed) { gea_elements = gea::runtime::array::fromIterator(${operandText(ctx, argument)}); } ` +
|
|
528
|
+
`GEA_EH_CATCH_ANY(gea_eh_failed) { ${resultType} gea_rejected; gea_rejected.reject(GEA_EH_CURRENT(gea_eh_failed)); return gea_rejected; } GEA_EH_END ` +
|
|
529
529
|
`return gea::host::PromiseConstructor::all(gea_elements, ${resolver}); }()`);
|
|
530
530
|
};
|
|
531
531
|
/**
|
|
@@ -1452,13 +1452,13 @@ const knownDescriptorText = (ctx, member, view, key, operation) => {
|
|
|
1452
1452
|
* `get`/`set` come across through `accessorHalvesOf`, the one bridge from a
|
|
1453
1453
|
* runtime descriptor's accessor halves to the record's callable fields.
|
|
1454
1454
|
*/
|
|
1455
|
-
const dynamicDescriptorConversionText = (ctx, member, receiver, key, operation) => {
|
|
1455
|
+
const dynamicDescriptorConversionText = (ctx, member, receiver, key, operation, nativeDescriptorCall) => {
|
|
1456
1456
|
const resultRepresentation = operation.result?.representation ?? null;
|
|
1457
1457
|
if (resultRepresentation === null) {
|
|
1458
1458
|
throw createCppEmitBlockedError(`host-member-call:Object.${member}`, `"Object.${member}" of a dynamic receiver published no result to build a descriptor into`);
|
|
1459
1459
|
}
|
|
1460
1460
|
const { resultType, someText, absentText, aggregateOf, attributeText, convertValueField, accessorHalvesOf } = descriptorAggregateBuilder(ctx, resultRepresentation, `"Object.${member}" of a dynamic receiver`, operation);
|
|
1461
|
-
const nativeCall = `gea::host::ObjectConstructor::${member}(${receiver}, ${propertyKeyText(ctx, member, key)})`;
|
|
1461
|
+
const nativeCall = nativeDescriptorCall ?? `gea::host::ObjectConstructor::${member}(${receiver}, ${propertyKeyText(ctx, member, key)})`;
|
|
1462
1462
|
const halves = accessorHalvesOf('static_cast<const gea::PropertyDescriptor&>(*__gea_native)');
|
|
1463
1463
|
const aggregate = aggregateOf({
|
|
1464
1464
|
// The runtime's own descriptor keeps `value` boxed (`gea::Value`) even
|
|
@@ -1608,6 +1608,19 @@ export const getOwnPropertyDescriptorText = (ctx, operation) => {
|
|
|
1608
1608
|
if (view.kind === 'dynamic')
|
|
1609
1609
|
return dynamicDescriptorConversionText(ctx, member, view.receiver, key, operation);
|
|
1610
1610
|
if (view.kind === 'dictionary') {
|
|
1611
|
+
if (representation.kind === 'dictionary' &&
|
|
1612
|
+
representation.key === 'string' &&
|
|
1613
|
+
representation.ownership === 'shared-refcount' &&
|
|
1614
|
+
representation.value.kind === 'dynamic' &&
|
|
1615
|
+
representation.value.reason === 'declared-any-never-narrowed' &&
|
|
1616
|
+
key.representation.kind === 'string') {
|
|
1617
|
+
// The original dictionary's document overlay owns accessor Functions;
|
|
1618
|
+
// project its descriptor through the same dynamic entry frame as any.
|
|
1619
|
+
const call = `([&]() -> gea::Optional<gea::PropertyDescriptor> { gea::PropertyDescriptor descriptor; ` +
|
|
1620
|
+
`if (!gea::detail::nativeDocumentDescriptor(${receiver}, ${propertyKeyText(ctx, member, key)}, descriptor)) return {}; ` +
|
|
1621
|
+
`return descriptor; })()`;
|
|
1622
|
+
return dynamicDescriptorConversionText(ctx, member, receiver, key, operation, call);
|
|
1623
|
+
}
|
|
1611
1624
|
return refuseDictionaryArm(member, view, 'what is missing is the same thing the known-shape arm is missing -- minting the `gea::PropertyDescriptor` result, ' +
|
|
1612
1625
|
'and the `undefined` a key the table does not hold answers with');
|
|
1613
1626
|
}
|
|
@@ -2711,6 +2724,19 @@ const definePropertyText = (ctx, operation) => {
|
|
|
2711
2724
|
if (key.representation.kind !== view.representation.key) {
|
|
2712
2725
|
return refuseDictionaryArm('defineProperty', view, `the key carries "${representationKey(key.representation)}" rather than the table's "${view.representation.key}" key domain`);
|
|
2713
2726
|
}
|
|
2727
|
+
if (view.representation.key === 'string' &&
|
|
2728
|
+
view.representation.ownership === 'shared-refcount' &&
|
|
2729
|
+
view.value.kind === 'dynamic' &&
|
|
2730
|
+
view.value.reason === 'declared-any-never-narrowed' &&
|
|
2731
|
+
operation.nativeAccessorDefinition !== undefined) {
|
|
2732
|
+
// Only the certified native accessor installation reaches this branch.
|
|
2733
|
+
// Reuse the dictionary's owned document overlay, including replacement
|
|
2734
|
+
// compatibility and retained native accessor invocation frames.
|
|
2735
|
+
const slot = '__gea_descriptor';
|
|
2736
|
+
return (`([&]() { ${defineDescriptorLines(ctx, operation, descriptor, slot)} ` +
|
|
2737
|
+
`if (!gea::detail::nativeDocumentDefine(${operandText(ctx, target)}, ${propertyKeyText(ctx, 'defineProperty', key)}, ${slot})) ` +
|
|
2738
|
+
`gea::host::throwRuntimeError("TypeError", "Cannot redefine property"); return ${operandText(ctx, target)}; })()`);
|
|
2739
|
+
}
|
|
2714
2740
|
const value = dictionaryDefinePropertyValue(ctx, descriptor);
|
|
2715
2741
|
const raw = operandText(ctx, value);
|
|
2716
2742
|
const stored = representationKey(value.representation) === representationKey(view.value)
|
|
@@ -486,7 +486,15 @@ export const hostMemberReadsOf = (body, hosts, staticKeyTexts, hostClassReads, h
|
|
|
486
486
|
const presentView = (receiver) => receiver.representation.kind === 'optional'
|
|
487
487
|
? { value: `${receiver.value}:present`, representation: receiver.representation.payload }
|
|
488
488
|
: receiver;
|
|
489
|
-
const receiverOf = (receiver) =>
|
|
489
|
+
const receiverOf = (receiver) => {
|
|
490
|
+
// A certified, present namespace is a host path, not a runtime receiver.
|
|
491
|
+
// Preserve the census's identity instead of asking operandText to invent
|
|
492
|
+
// an object for it when the deferred method is finally called. A row
|
|
493
|
+
// requiring {receiver} still fails closed against this null spelling.
|
|
494
|
+
const namespaces = body.hostNamespaceCensus;
|
|
495
|
+
const namespacePath = namespaces?.reads.has(receiver.value) && namespaces.definitelyPresent.has(receiver.value);
|
|
496
|
+
return hostClassReads.has(receiver.value) || namespacePath ? null : presentView(receiver);
|
|
497
|
+
};
|
|
490
498
|
for (const block of body.blocks.values()) {
|
|
491
499
|
for (const operation of allOperationsOf(block)) {
|
|
492
500
|
if (operation.kind === 'get') {
|
|
@@ -111,7 +111,7 @@ export declare const hostClassValueText: (representation: Representation, classN
|
|
|
111
111
|
* the TypeError the clause specifies. A member this backend has no runtime
|
|
112
112
|
* spelling for, and every non-Date prototype, keeps a throwing invoke, so a
|
|
113
113
|
* call reaching it is an honest refusal at run time rather than a wrong
|
|
114
|
-
* answer. Facts are
|
|
114
|
+
* answer. Facts are published in the entry's record so
|
|
115
115
|
* `Value::box(Tag::Function, ...)` installs the own `name`/`length` the same
|
|
116
116
|
* way it does for a program's own function. `signature` is the `R(A...)`
|
|
117
117
|
* spelling of the read's own ABI when the read is typed, `void()` when the
|
|
@@ -257,7 +257,10 @@ export const hostBuiltinFunctionIdentityText = (protocol, member, length) => `ge
|
|
|
257
257
|
* `new String(x)` is a different operation (a wrapper OBJECT) and is not this:
|
|
258
258
|
* a class read as a value is only ever the callable half.
|
|
259
259
|
*/
|
|
260
|
-
const hostClassCallPaths = new Map([
|
|
260
|
+
const hostClassCallPaths = new Map([
|
|
261
|
+
['String', 'gea::host::detail::toString'],
|
|
262
|
+
['Number', 'gea::host::detail::toNumber']
|
|
263
|
+
]);
|
|
261
264
|
export const hostClassValueText = (representation, className) => {
|
|
262
265
|
// A host class READ carries its own `native-handle`, whose `call` half is
|
|
263
266
|
// the convention the class object is callable under -- the same shape
|
|
@@ -302,7 +305,7 @@ export const hostClassValueText = (representation, className) => {
|
|
|
302
305
|
* the TypeError the clause specifies. A member this backend has no runtime
|
|
303
306
|
* spelling for, and every non-Date prototype, keeps a throwing invoke, so a
|
|
304
307
|
* call reaching it is an honest refusal at run time rather than a wrong
|
|
305
|
-
* answer. Facts are
|
|
308
|
+
* answer. Facts are published in the entry's record so
|
|
306
309
|
* `Value::box(Tag::Function, ...)` installs the own `name`/`length` the same
|
|
307
310
|
* way it does for a program's own function. `signature` is the `R(A...)`
|
|
308
311
|
* spelling of the read's own ABI when the read is typed, `void()` when the
|
|
@@ -323,7 +326,7 @@ export const hostPrototypeMethodValueText = (signature, protocol, member, arity)
|
|
|
323
326
|
/**
|
|
324
327
|
* A builtin function object over one `R(A...)` signature whose invoke is
|
|
325
328
|
* `body`, over formals `__gea_a0...`, with its `name`/`length`/source text
|
|
326
|
-
*
|
|
329
|
+
* published in the entry's record so every copy reflects as the builtin.
|
|
327
330
|
*/
|
|
328
331
|
const registeredBuiltinFunctionText = (signature, name, arity, body) => {
|
|
329
332
|
const parameters = signature.slice(signature.indexOf('(') + 1, -1);
|
|
@@ -333,9 +336,8 @@ const registeredBuiltinFunctionText = (signature, name, arity, body) => {
|
|
|
333
336
|
const signatureFormals = parameters.length === 0 ? '' : `, ${parameters}`;
|
|
334
337
|
const text = `function ${name}() { [native code] }`;
|
|
335
338
|
return (`([&]() { static constexpr ${result} (*__gea_invoke)(void*${signatureFormals}) = +[](void*${formals}) -> ${result} { ${body} }; ` +
|
|
336
|
-
`
|
|
337
|
-
`${cppStringLiteral(name)}, ${String(arity)}, ${cppStringLiteral(text)}); (
|
|
338
|
-
`return gea::CallableObject<${signature}>(__gea_invoke, nullptr); })()`);
|
|
339
|
+
`return gea::CallableObject<${signature}>(gea::CallableObject<${signature}>::entryWithFacts<__gea_invoke>(` +
|
|
340
|
+
`${cppStringLiteral(name)}, ${String(arity)}, ${cppStringLiteral(text)}), nullptr); })()`);
|
|
339
341
|
};
|
|
340
342
|
/**
|
|
341
343
|
* An intrinsic accessor's getter read as a value (`intrinsic-accessor-getter.ts`
|
|
@@ -211,7 +211,8 @@ export const coreHostMembers = new Map([
|
|
|
211
211
|
logicalReceiver: 'ignored'
|
|
212
212
|
}
|
|
213
213
|
],
|
|
214
|
-
|
|
214
|
+
// `hypot_invoke(void*, values)` never reads `this`, exactly like `max`/`min`.
|
|
215
|
+
['Math.hypot', { kind: 'property', store: null, emit: 'gea::host::Math::hypot', logicalReceiver: 'ignored' }],
|
|
215
216
|
// The sixteen `Math` members `gea_runtime.h` did not have. `cbrt` is v1's
|
|
216
217
|
// (`gea::runtime::math::cbrt`, stdlib.cpp); the other fifteen are written
|
|
217
218
|
// against ECMA-262 §21.3.2 there, because v1's own `gea::runtime::math`
|
|
@@ -303,10 +303,38 @@ const sortText = (ctx, receiverText, element, args) => {
|
|
|
303
303
|
// name, so the sort can inline it.
|
|
304
304
|
const comparator = args[0];
|
|
305
305
|
const direct = comparator === undefined ? undefined : ctx.directCallableValues.get(comparator.value);
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
306
|
+
if (comparator?.representation.kind === 'function-value-dispatch' && comparator.representation.abi.receiver === null) {
|
|
307
|
+
// SortCompare (23.1.3.30.2) calls the comparator with two elements, which
|
|
308
|
+
// the runtime hands over as the element's own C++ type. Only a comparator
|
|
309
|
+
// whose two parameters ARE that carrier takes them as they are; one
|
|
310
|
+
// declared otherwise (`lights.sort( byShadow )` with `any` parameters over
|
|
311
|
+
// a class-instance array) needs each element converted at this boundary,
|
|
312
|
+
// exactly as `elementAdaptedCallbackText` converts for the callback family
|
|
313
|
+
// -- C++ performs no such conversion, and the inlining `DirectCallable`
|
|
314
|
+
// finds no invocable arity at all.
|
|
315
|
+
const abi = comparator.representation.abi;
|
|
316
|
+
const compared = abi.parameters.slice(0, 2);
|
|
317
|
+
const exact = compared.every((parameter) => representationKey(parameter.value) === representationKey(element));
|
|
318
|
+
if (exact) {
|
|
319
|
+
if (direct !== undefined)
|
|
320
|
+
return `gea::runtime::array::sort(${receiverText}, gea::DirectCallable<&${cppThunkName(direct)}>{})`;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
const refuse = (detail) => {
|
|
324
|
+
throw createCppEmitBlockedError(`runtime-helper:callback:sort:${elementKey(element)}`, `"Array.prototype.sort" (ECMA-262 23.1.3.30) hands its comparator two elements "${elementKey(element)}"; ${detail}`);
|
|
325
|
+
};
|
|
326
|
+
if (abi.restFrom !== null && abi.restFrom < 2)
|
|
327
|
+
refuse('a comparator gathering them into a rest parameter has no runtime call shape');
|
|
328
|
+
const actuals = compared.map((parameter, position) => {
|
|
329
|
+
const converted = alignedValueText(ctx, 'prototype/emit-prototype-array.ts:sortText', element, parameter.value, `__gea_element_${position}`);
|
|
330
|
+
return (converted ??
|
|
331
|
+
refuse(`its parameter ${position} carries "${representationKey(parameter.value)}", and no installed conversion reconciles them`));
|
|
332
|
+
});
|
|
333
|
+
const formals = [0, 1].map((position) => `const ${cppTypeOf(element)}& __gea_element_${position}`);
|
|
334
|
+
const fn = direct !== undefined ? `gea::DirectCallable<&${cppThunkName(direct)}>{}` : operandText(ctx, comparator);
|
|
335
|
+
return `gea::runtime::array::sort(${receiverText}, [__gea_fn = ${fn}](${formals.join(', ')}) { return __gea_fn(${actuals.join(', ')}); })`;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
310
338
|
if (args.length === 1)
|
|
311
339
|
return call(ctx, 'sort', receiverText, args);
|
|
312
340
|
if (element.kind !== 'string' && element.kind !== 'scalar') {
|
|
@@ -579,13 +607,15 @@ const rangedMethodText = (member, clause, arities, elementOrdinal) => (ctx, rece
|
|
|
579
607
|
* against every element, which is a comparison between two VALUES and never a
|
|
580
608
|
* store: the search value is not written into the array, so it need not carry
|
|
581
609
|
* the element's own carrier, only one the comparison can be decided across.
|
|
582
|
-
*
|
|
610
|
+
* These cross-carrier pairs are rendered beyond the exact one `rangedMethodText` gates:
|
|
583
611
|
*
|
|
584
612
|
* - a DYNAMIC search value over a primitive element. 7.2.12 step 1 compares
|
|
585
613
|
* Types first, so the value can only match when its tag is the element's;
|
|
586
614
|
* the tag test decides that, and only then is it unboxed and compared
|
|
587
615
|
* natively. `Object.values(Enum).includes(value as any)` is the
|
|
588
616
|
* shape.
|
|
617
|
+
* - an optional primitive search over its payload element: absence compares
|
|
618
|
+
* equal only to a hole, while present payloads use SameValueZero.
|
|
589
619
|
* - a search value that is the PRESENT arm of an optional element
|
|
590
620
|
* (`(string | undefined)[]`'s `.includes(name)`): an absent element never
|
|
591
621
|
* equals a string, so only present payloads are compared
|
|
@@ -596,6 +626,24 @@ const includesText = (ctx, receiverText, element, args, result, operation) => {
|
|
|
596
626
|
if (search === undefined || elementKey(search.representation) === elementKey(element)) {
|
|
597
627
|
return rangedMethodText('includes', '23.1.3.16', [1, 2], 0)(ctx, receiverText, element, args, result);
|
|
598
628
|
}
|
|
629
|
+
// An optional search is still a value, never a store into the array.
|
|
630
|
+
// Undefined cannot equal a present primitive, but DOES equal a hole (Get
|
|
631
|
+
// returns undefined). Keep both carriers native and use the existing
|
|
632
|
+
// SameValueZero/relativeIndex authorities, evaluating each operand once.
|
|
633
|
+
if (search.representation.kind === 'optional' &&
|
|
634
|
+
search.representation.absence === 'undefined' &&
|
|
635
|
+
elementKey(search.representation.payload) === elementKey(element) &&
|
|
636
|
+
(element.kind === 'string' || (element.kind === 'scalar' && element.domain !== 'bigint'))) {
|
|
637
|
+
requireArity('includes', '23.1.3.16', [1, 2], args);
|
|
638
|
+
if (args[1] !== undefined)
|
|
639
|
+
requireNumber('includes', 1, args);
|
|
640
|
+
const from = args[1] === undefined ? '0.0' : operandText(ctx, args[1]);
|
|
641
|
+
return (`([&]() -> bool { const auto gea_array = ${receiverText}; const auto gea_search = ${operandText(ctx, search)}; ` +
|
|
642
|
+
`const double gea_from = ${from}; if (!gea_array) return false; const std::size_t gea_length = gea_array->size(); ` +
|
|
643
|
+
`for (std::size_t gea_index = gea::runtime::array::relativeIndex(gea_from, gea_length); gea_index < gea_length; ++gea_index) { ` +
|
|
644
|
+
`if (!gea_array->present(gea_index)) { if (!gea_search.has_value()) return true; continue; } ` +
|
|
645
|
+
`if (gea_search.has_value() && gea::sameValueZero(gea_array->readElement(gea_index), *gea_search)) return true; } return false; }())`);
|
|
646
|
+
}
|
|
599
647
|
if (args.length === 1 && search.representation.kind === 'dynamic') {
|
|
600
648
|
const cppElement = cppTypeOf(element);
|
|
601
649
|
// Each carrier here has exactly one C++ spelling (`cppScalarType`), which
|
|
@@ -620,6 +668,22 @@ const includesText = (ctx, receiverText, element, args, result, operation) => {
|
|
|
620
668
|
(element.payload.kind === 'string' || (element.payload.kind === 'scalar' && element.payload.domain !== 'bigint'))) {
|
|
621
669
|
return `gea::runtime::array::includesPresent(${receiverText}, ${operandText(ctx, search)})`;
|
|
622
670
|
}
|
|
671
|
+
// The mirror case: an OPTIONAL search value over the elements of its own
|
|
672
|
+
// payload (`(['a', 'b'] as string[]).includes(value as string)` with `value:
|
|
673
|
+
// string | null`, which a type assertion does not unwrap). A primitive
|
|
674
|
+
// element is never `null` or `undefined`, so an absent search value answers
|
|
675
|
+
// false; a present one compares its payload. The receiver and the search
|
|
676
|
+
// value are evaluated first, in that order, either way.
|
|
677
|
+
if (search.representation.kind === 'optional' &&
|
|
678
|
+
elementKey(search.representation.payload) === elementKey(element) &&
|
|
679
|
+
(element.kind === 'string' || (element.kind === 'scalar' && element.domain !== 'bigint'))) {
|
|
680
|
+
requireArity('includes', '23.1.3.16', [1, 2], args);
|
|
681
|
+
if (args[1] !== undefined)
|
|
682
|
+
requireNumber('includes', 1, args);
|
|
683
|
+
const from = args[1] === undefined ? '' : `, ${operandText(ctx, args[1])}`;
|
|
684
|
+
return (`([&]() -> bool { auto&& gea_receiver = ${receiverText}; const auto& gea_search = ${operandText(ctx, search)}; ` +
|
|
685
|
+
`return gea_search.has_value() && gea::runtime::array::includes(gea_receiver, *gea_search${from}); }())`);
|
|
686
|
+
}
|
|
623
687
|
// A search value whose every arm IS an arm of a union element -- the same
|
|
624
688
|
// arm set spelled in another order, or one member of it -- widens into the
|
|
625
689
|
// element exactly, so the comparison runs over the element's own carrier.
|