@geastack/compiler 1.0.32 → 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 +35 -28
- 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 +22 -6
- package/dist/ir/model.d.ts +41 -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.d.ts +4 -3
- package/dist/representation/unassigned-binding-cells.js +19 -2
- 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 +132 -21
- 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 +2407 -684
|
@@ -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`.
|
|
@@ -1961,7 +2014,9 @@ const threadedFlowOf = (ctx, body, labels, hoists, mergeWrites) => {
|
|
|
1961
2014
|
const result = resultOfIrOperation(operation);
|
|
1962
2015
|
return result !== null && ctx.deadValues.has(result.id);
|
|
1963
2016
|
};
|
|
1964
|
-
const
|
|
2017
|
+
const lifetimeBlocks = new Set(body.bindingLifetimeOrigins?.values());
|
|
2018
|
+
const rendersNothing = (block) => !lifetimeBlocks.has(block.id) &&
|
|
2019
|
+
block.operations.every(rendersNothingAtOrigin) &&
|
|
1965
2020
|
(mergeWrites.get(block.id) ?? []).length === 0 &&
|
|
1966
2021
|
// A relocated operation renders here, in its destination block. Counting
|
|
1967
2022
|
// it as absent a second time lets the flow thread this block away and
|
|
@@ -2054,7 +2109,7 @@ const threadedFlowOf = (ctx, body, labels, hoists, mergeWrites) => {
|
|
|
2054
2109
|
* written in the same order, flat, with every declaration at the top -- the
|
|
2055
2110
|
* layout that needs no graph at all.
|
|
2056
2111
|
*/
|
|
2057
|
-
const nestedBlocksOf = (plan, rendered, labels, successors, declarations, rootText, facts, internalLabels = new Map(), restricted = new Map()) => {
|
|
2112
|
+
const nestedBlocksOf = (plan, rendered, labels, successors, declarations, rootText, facts, internalLabels = new Map(), restricted = new Map(), lifetimeOrigins = new Map()) => {
|
|
2058
2113
|
const flat = () => ({
|
|
2059
2114
|
top: declarations,
|
|
2060
2115
|
artifacts: plan.order.flatMap((id) => {
|
|
@@ -2075,7 +2130,7 @@ const nestedBlocksOf = (plan, rendered, labels, successors, declarations, rootTe
|
|
|
2075
2130
|
]);
|
|
2076
2131
|
if (gotoTargetsOf(block.artifact.text).some((target) => !allowed.has(target)))
|
|
2077
2132
|
return flat();
|
|
2078
|
-
mentions.set(id, identifiersOf(block.artifact.text));
|
|
2133
|
+
mentions.set(id, new Set([...identifiersOf(block.artifact.text), ...[...lifetimeOrigins].filter(([, origin]) => origin === id).map(([name]) => name)]));
|
|
2079
2134
|
}
|
|
2080
2135
|
const scopes = declarationScopesOf(plan, declarations, mentions, rootText);
|
|
2081
2136
|
const top = [];
|
|
@@ -2258,7 +2313,7 @@ const isBareIdentifier = (text) => {
|
|
|
2258
2313
|
* handler renders its blocks bare, and an outer jump into one of them cannot
|
|
2259
2314
|
* be re-nested), or when some chunk is unreachable along the spelled jumps.
|
|
2260
2315
|
*/
|
|
2261
|
-
const regionScopedBlocksOf = (entry, chunkIds, chunks, labels, declarations, rootText, facts) => {
|
|
2316
|
+
const regionScopedBlocksOf = (entry, chunkIds, chunks, labels, declarations, rootText, facts, lifetimeOrigins = new Map()) => {
|
|
2262
2317
|
if (chunkIds.length !== chunks.length)
|
|
2263
2318
|
return null;
|
|
2264
2319
|
const allLabels = new Set(labels.values());
|
|
@@ -2315,7 +2370,17 @@ const regionScopedBlocksOf = (entry, chunkIds, chunks, labels, declarations, roo
|
|
|
2315
2370
|
const rendered = new Map();
|
|
2316
2371
|
for (const [id, artifact] of texts)
|
|
2317
2372
|
rendered.set(id, { label: targeted.has(id) ? requireBlockLabel(labels, id) : null, artifact });
|
|
2318
|
-
|
|
2373
|
+
const chunkOrigins = new Map();
|
|
2374
|
+
const atRoot = [];
|
|
2375
|
+
for (const [name, origin] of lifetimeOrigins) {
|
|
2376
|
+
const label = labels.get(origin);
|
|
2377
|
+
const chunk = label === undefined ? undefined : (internalOf.get(label) ?? nodeOfLabel.get(label));
|
|
2378
|
+
if (chunk === undefined)
|
|
2379
|
+
atRoot.push(name);
|
|
2380
|
+
else
|
|
2381
|
+
chunkOrigins.set(name, chunk);
|
|
2382
|
+
}
|
|
2383
|
+
return nestedBlocksOf(plan, rendered, labels, successors, declarations, [rootText, ...atRoot].join('\n'), facts, internal, new Map(), chunkOrigins);
|
|
2319
2384
|
};
|
|
2320
2385
|
/** One `blockN` label per block, in `blockOrder`, so a forward jump (a loop back-edge included) always resolves before any block renders. */
|
|
2321
2386
|
const blockLabelsOf = (order) => {
|
|
@@ -2372,7 +2437,7 @@ export const emitBody = (body, placements, classes, hosts, deriver, wellKnownSym
|
|
|
2372
2437
|
symbolKeys, templateObjects, directCallableBindings = new Map(),
|
|
2373
2438
|
// `virtualDispatch` is every `class key` with a dispatch member (`virtual-methods.ts`);
|
|
2374
2439
|
// `narrowedStorage`/`narrowedFormals` are what the integer census settled here.
|
|
2375
|
-
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) => {
|
|
2376
2441
|
// Every fact this body settles before a single line renders, computed here
|
|
2377
2442
|
// -- from `body` and the plain, already-available inputs above -- and
|
|
2378
2443
|
// handed to `createEmitContext` as one argument instead of mutated onto the
|
|
@@ -2398,6 +2463,31 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2398
2463
|
const borrowedArmProjections = borrowedArmProjectionsOf(body, stableBorrowEntries.get(cppBodyName(body.sourceOwner)), conversions);
|
|
2399
2464
|
// Each such view is a reference into a borrowed formal, so it is as stable an actual as the formal.
|
|
2400
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
|
+
})();
|
|
2401
2491
|
// A read has to know what the REST of the body does to the cell it reads.
|
|
2402
2492
|
// `emit-bindings.ts` lets a host object's read name its cell rather than
|
|
2403
2493
|
// copy out of it, and that identity only holds while the cell keeps
|
|
@@ -2426,8 +2516,8 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2426
2516
|
? { layout: owningClass, derived: constructedBaseOf(owningClass) !== null || owningClass.nativeBase !== null, callsSuper }
|
|
2427
2517
|
: null;
|
|
2428
2518
|
const formalInputs = ownedFormalInputsOf(body);
|
|
2429
|
-
const ownedDyingValues = new Set([...ownedDyingValuesOf(body), ...ownedDyingMergeInputsOf(body), ...formalInputs.arguments]);
|
|
2430
|
-
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)]));
|
|
2431
2521
|
const layoutKeys = new Map();
|
|
2432
2522
|
const origins = bodyValueOriginsOf(body, (representation) => {
|
|
2433
2523
|
if (representation.kind !== 'native-record-ref' || representation.native !== null)
|
|
@@ -2455,7 +2545,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2455
2545
|
receiverValues,
|
|
2456
2546
|
bindingWriteCounts,
|
|
2457
2547
|
stableCellReads: stableCellReadsOf(body, (declaration) => placements.get(declaration)?.storage.kind === 'local'),
|
|
2458
|
-
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),
|
|
2459
2549
|
constructorOf,
|
|
2460
2550
|
ownedDyingValues,
|
|
2461
2551
|
transferDyingValues,
|
|
@@ -2464,6 +2554,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2464
2554
|
classTableRoots: classTableRootsOf(body),
|
|
2465
2555
|
stableBorrowActuals: stableWithProjections,
|
|
2466
2556
|
borrowedArmProjections,
|
|
2557
|
+
repeatedConversions,
|
|
2467
2558
|
computeOrigins: origins.computeOrigins,
|
|
2468
2559
|
propertyReadOrigins: origins.propertyReadOrigins,
|
|
2469
2560
|
bindingReadDeclarations: origins.bindingReadDeclarations,
|
|
@@ -2501,7 +2592,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2501
2592
|
integerWidenings: integerWideningsOf(body),
|
|
2502
2593
|
lazySplits: lazySplitsOf(body)
|
|
2503
2594
|
};
|
|
2504
|
-
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);
|
|
2505
2596
|
const ctx = debugSource === undefined ? baseCtx : { ...baseCtx, debugSource };
|
|
2506
2597
|
// `ownedValues` stays a genuine render-time OUTPUT buffer (`EmitContext`'s
|
|
2507
2598
|
// own doc: `defineValue` grows it as each operation's result is named) --
|
|
@@ -2863,6 +2954,9 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
2863
2954
|
for (const value of prepass.deferrable)
|
|
2864
2955
|
if (!census.deferrable.has(value))
|
|
2865
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);
|
|
2866
2960
|
const hoists = census.hoists;
|
|
2867
2961
|
// After the hoists: a fill loop's bound is as often a relocated invariant
|
|
2868
2962
|
// (`n * n`, re-read from its cells in the loop's own test) as a plain cell.
|
|
@@ -3082,13 +3176,26 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
3082
3176
|
// scope of a variable whose declaration initializes it.
|
|
3083
3177
|
const declarationFacts = { kind: 'materialized', representation: { kind: 'void' }, owner, lineage: null };
|
|
3084
3178
|
let topDeclarations = ctx.declarations;
|
|
3179
|
+
const lifetimeOrigins = new Map();
|
|
3180
|
+
const atEntry = [];
|
|
3181
|
+
for (const [declaration, origin] of body.bindingLifetimeOrigins ?? []) {
|
|
3182
|
+
const name = ctx.bindingNames.get(declaration);
|
|
3183
|
+
if (name === undefined)
|
|
3184
|
+
continue;
|
|
3185
|
+
const rendered = flow.rendered.find((id) => id === origin || labels.get(id) === labels.get(origin));
|
|
3186
|
+
if (origin === body.entry || rendered === undefined || rendered === body.entry)
|
|
3187
|
+
atEntry.push(name);
|
|
3188
|
+
else
|
|
3189
|
+
lifetimeOrigins.set(name, rendered);
|
|
3190
|
+
}
|
|
3191
|
+
const lifetimeRootText = [...entryPrologue, ...atEntry].join('\n');
|
|
3085
3192
|
if (plan !== null && flow.successors !== null) {
|
|
3086
|
-
const nested = nestedBlocksOf(plan, renderedBlocks, labels, flow.successors, ctx.declarations,
|
|
3193
|
+
const nested = nestedBlocksOf(plan, renderedBlocks, labels, flow.successors, ctx.declarations, lifetimeRootText, declarationFacts, new Map(), restrictedParametersOf(ctx), lifetimeOrigins);
|
|
3087
3194
|
topDeclarations = nested.top;
|
|
3088
3195
|
blocks.push(...nested.artifacts);
|
|
3089
3196
|
}
|
|
3090
3197
|
else if (!isSingleBlock && flow.successors === null) {
|
|
3091
|
-
const nested = regionScopedBlocksOf(body.entry, chunkIds, blocks, labels, ctx.declarations,
|
|
3198
|
+
const nested = regionScopedBlocksOf(body.entry, chunkIds, blocks, labels, ctx.declarations, lifetimeRootText, declarationFacts, lifetimeOrigins);
|
|
3092
3199
|
if (nested !== null) {
|
|
3093
3200
|
topDeclarations = nested.top;
|
|
3094
3201
|
blocks.splice(0, blocks.length, ...nested.artifacts);
|
|
@@ -3096,7 +3203,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
3096
3203
|
}
|
|
3097
3204
|
else if (isSingleBlock && blocks.length === 1) {
|
|
3098
3205
|
const only = blocks[0];
|
|
3099
|
-
const segmented = segmentScopedBodyOf(only.text, ctx.declarations,
|
|
3206
|
+
const segmented = segmentScopedBodyOf(only.text, ctx.declarations, lifetimeRootText);
|
|
3100
3207
|
if (segmented !== null) {
|
|
3101
3208
|
topDeclarations = segmented.top;
|
|
3102
3209
|
blocks.splice(0, 1, { text: segmented.text, facts: only.facts });
|
|
@@ -3126,9 +3233,13 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
3126
3233
|
return [
|
|
3127
3234
|
declarations,
|
|
3128
3235
|
...prologue,
|
|
3129
|
-
|
|
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 },
|
|
3130
3238
|
...blocks,
|
|
3131
|
-
{
|
|
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
|
+
}
|
|
3132
3243
|
];
|
|
3133
3244
|
}
|
|
3134
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`
|