@geastack/compiler 1.0.49 → 1.0.63
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 +57 -19
- package/dist/cli.js +2 -1
- package/dist/compiler.js +8 -2
- package/dist/conversion/derive.js +5 -0
- package/dist/conversion/native-field-view.d.ts +7 -0
- package/dist/conversion/native-field-view.js +50 -0
- package/dist/conversion/native-record-products.js +1 -0
- package/dist/conversion/native-view-origins.d.ts +1 -1
- package/dist/conversion/native-view-origins.js +5 -4
- package/dist/conversion/nodes.d.ts +9 -0
- package/dist/conversion/nodes.js +18 -0
- package/dist/conversion/record-view.d.ts +25 -1
- package/dist/conversion/record-view.js +61 -2
- package/dist/conversion/structural-plan.js +7 -6
- package/dist/ir/borrowed-field-reads.d.ts +30 -0
- package/dist/ir/borrowed-field-reads.js +218 -0
- package/dist/ir/borrowed-window-cells.d.ts +35 -0
- package/dist/ir/borrowed-window-cells.js +117 -0
- package/dist/ir/call-dispatch.js +21 -4
- package/dist/ir/callable-class-flow.js +269 -43
- package/dist/ir/captures.js +18 -1
- package/dist/ir/certify.js +14 -1
- package/dist/ir/construction-only-fields.d.ts +15 -1
- package/dist/ir/construction-only-fields.js +71 -3
- package/dist/ir/dead-logical-merge.d.ts +4 -0
- package/dist/ir/dead-logical-merge.js +89 -18
- package/dist/ir/dense-loops.d.ts +38 -4
- package/dist/ir/dense-loops.js +120 -18
- package/dist/ir/dense-read-windows.d.ts +42 -0
- package/dist/ir/dense-read-windows.js +137 -0
- package/dist/ir/facts.d.ts +12 -0
- package/dist/ir/facts.js +18 -2
- package/dist/ir/field-read-reuse.d.ts +71 -0
- package/dist/ir/field-read-reuse.js +430 -0
- package/dist/ir/hoist.d.ts +19 -2
- package/dist/ir/hoist.js +143 -24
- package/dist/ir/lower-narrow.js +19 -1
- package/dist/ir/model.d.ts +19 -0
- package/dist/ir/native-field-view-domains.d.ts +12 -2
- package/dist/ir/native-field-view-domains.js +51 -15
- package/dist/ir/native-field-view-facts.js +5 -2
- package/dist/ir/native-method-frames.js +15 -2
- package/dist/ir/plain-field-read.d.ts +31 -0
- package/dist/ir/plain-field-read.js +51 -0
- package/dist/ir/program-facts.d.ts +14 -0
- package/dist/ir/program-facts.js +85 -2
- package/dist/ir/proven-branches.js +8 -1
- package/dist/ir/publish-conversion-recipes.js +5 -1
- package/dist/ir/short-circuit-threading.d.ts +12 -4
- package/dist/ir/short-circuit-threading.js +124 -12
- package/dist/ir/stable-cell-reads.d.ts +24 -1
- package/dist/ir/stable-cell-reads.js +65 -42
- package/dist/ir/write-effects.d.ts +42 -0
- package/dist/ir/write-effects.js +208 -0
- package/dist/plugins/gea/contract.d.ts +3 -2
- package/dist/plugins/gea/contract.js +3 -1
- package/dist/plugins/gea/host.d.ts +7 -2
- package/dist/plugins/gea/host.js +25 -5
- package/dist/project-preparation.d.ts +11 -0
- package/dist/project-preparation.js +44 -0
- package/dist/projection/classes.d.ts +8 -0
- package/dist/projection/classes.js +112 -12
- package/dist/projection/dispatch.d.ts +24 -4
- package/dist/projection/dispatch.js +71 -2
- package/dist/projection/fields.js +2 -2
- package/dist/representation/model.d.ts +3 -0
- package/dist/representation/model.js +3 -0
- package/dist/representation/value-records.js +22 -0
- package/dist/semantics/frontend-timing.d.ts +9 -0
- package/dist/semantics/frontend-timing.js +43 -2
- package/dist/semantics/frontend.js +103 -7
- package/dist/semantics/model/operations.d.ts +7 -0
- package/dist/semantics/normalize/binding-fixpoint.js +7 -2
- package/dist/semantics/normalize/callable-data-write.js +6 -2
- package/dist/semantics/normalize/field-bindings.js +151 -111
- package/dist/semantics/normalize/flow/callable-reach.js +27 -0
- package/dist/semantics/normalize/flow/component-solver.js +23 -5
- package/dist/semantics/normalize/flow/source-record-data.js +6 -2
- package/dist/semantics/normalize/flow/source-value-session.d.ts +13 -0
- package/dist/semantics/normalize/flow/source-value-session.js +207 -65
- package/dist/semantics/normalize/global-host-mutations.js +162 -1
- package/dist/semantics/normalize/parameter-bindings.js +16 -1
- package/dist/semantics/normalize/producers/class-lifecycle.js +2 -1
- package/dist/semantics/normalize/producers/erasure.js +13 -8
- package/dist/semantics/subclass-member-overlay-transform.js +17 -4
- package/dist/semantics/typescript-tsgo.d.ts +20 -0
- package/dist/semantics/typescript-tsgo.js +832 -0
- package/dist/semantics/typescript.d.ts +0 -9
- package/dist/semantics/typescript.js +4 -1
- package/dist/targets/cpp/borrowed-call-entry.d.ts +9 -0
- package/dist/targets/cpp/borrowed-call-entry.js +12 -2
- package/dist/targets/cpp/captures.js +4 -0
- package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
- package/dist/targets/cpp/class-properties/computed-method-value.js +17 -7
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +8 -0
- package/dist/targets/cpp/class-properties/emit-class-properties.js +62 -2
- package/dist/targets/cpp/class-properties/native-method-read.js +12 -1
- package/dist/targets/cpp/conversions.js +1 -0
- package/dist/targets/cpp/emit-arrays.d.ts +5 -0
- package/dist/targets/cpp/emit-arrays.js +60 -10
- package/dist/targets/cpp/emit-binding-reference.d.ts +19 -6
- package/dist/targets/cpp/emit-binding-reference.js +26 -8
- package/dist/targets/cpp/emit-bindings.js +22 -0
- package/dist/targets/cpp/emit-callable.js +133 -16
- package/dist/targets/cpp/emit-carrier-members.d.ts +6 -0
- package/dist/targets/cpp/emit-carrier-members.js +24 -2
- package/dist/targets/cpp/emit-context.d.ts +97 -1
- package/dist/targets/cpp/emit-context.js +52 -0
- package/dist/targets/cpp/emit-equality.js +3 -0
- package/dist/targets/cpp/emit-narrowing.js +9 -0
- package/dist/targets/cpp/emit-native-field-view.d.ts +24 -0
- package/dist/targets/cpp/emit-native-field-view.js +87 -8
- package/dist/targets/cpp/emit-properties.js +139 -16
- package/dist/targets/cpp/emit-record-view.js +49 -22
- package/dist/targets/cpp/emit-return.js +5 -1
- package/dist/targets/cpp/emit-tonumber.js +4 -1
- package/dist/targets/cpp/emit-union-properties.js +1 -1
- package/dist/targets/cpp/emit.d.ts +4 -1
- package/dist/targets/cpp/emit.js +148 -6
- package/dist/targets/cpp/reactive-dependencies.js +100 -28
- package/dist/targets/cpp/translation-unit.js +71 -17
- package/dist/targets/cpp/virtual-methods.d.ts +2 -2
- package/dist/targets/cpp/virtual-methods.js +11 -3
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_runtime.h +400 -21
|
@@ -10,7 +10,7 @@ import { functionConstructorArgumentKindOf } from '../../representation/function
|
|
|
10
10
|
import { nativeSumWidenable } from './emit-sum-widening.js';
|
|
11
11
|
import { nativeHeldFieldViewReadText } from './emit-native-field-view.js';
|
|
12
12
|
import { classLayoutsConstructedBy } from '../../projection/classes.js';
|
|
13
|
-
import { classFamilyOverridesOf, virtualDispatchKey } from '../../projection/dispatch.js';
|
|
13
|
+
import { classDynamicMethodShadowOf, classFamilyOverridesOf, virtualDispatchKey } from '../../projection/dispatch.js';
|
|
14
14
|
import { cppVirtualMemberName } from './virtual-methods.js';
|
|
15
15
|
import { abiKey, representationKey } from '../../representation/model.js';
|
|
16
16
|
import { alignedValueText, callableObjectAbi, movedValueText, namedConversionText, recipeText, unboxedLoadText } from './emit-narrowing.js';
|
|
@@ -40,7 +40,7 @@ import { nativeCollectionBaseInitializeStatements } from './native-collection-ba
|
|
|
40
40
|
import { nativePromiseBaseInitializeStatements } from './native-promise-base.js';
|
|
41
41
|
import { emitArrayBufferConstruct, emitSharedArrayBufferConstruct, emitTextCodecConstruct, emitDataViewConstruct, emitTypedArrayBufferConstruct, typedArrayTargetSpelling } from './emit-buffers.js';
|
|
42
42
|
import { armAt, armIs } from './emit-union-properties.js';
|
|
43
|
-
import { constructorStateText, genericStaticOwnerOf } from './class-properties/emit-class-properties.js';
|
|
43
|
+
import { abstractMissReadKeyOf, constructorStateText, genericStaticOwnerOf } from './class-properties/emit-class-properties.js';
|
|
44
44
|
import { cppAbiType, cppBodyName, cppBoxedType, cppCallableDeclarationTagName, cppClassName, cppConstructName, cppInitializeName, cppRecordFieldName, cppRecordFieldPresenceName, cppRefcountedReceiver, cppStringLiteral, cppAbiParameterType, cppTypeOf, cppResultTypeOf, cppUndefinedValue } from './types.js';
|
|
45
45
|
/** `Function.prototype.bind` preserves the native call ABI and captures only evaluated prefix values. */
|
|
46
46
|
export const emitBindCallable = (ctx, lines, operation) => {
|
|
@@ -274,6 +274,23 @@ export const staticPrefixCallableText = (ctx, source, slot) => {
|
|
|
274
274
|
return null;
|
|
275
275
|
return cppStaticPrefixCallableText(ctx, direct, slotType, sourceType);
|
|
276
276
|
};
|
|
277
|
+
/** An entry a call without the callee's environment may enter: every borrowed entry but a closure's. */
|
|
278
|
+
const environmentFreeEntry = (entry) => entry === undefined || entry.environment ? undefined : entry;
|
|
279
|
+
/**
|
|
280
|
+
* The borrowed entry of the closure a flow-known call reaches through the
|
|
281
|
+
* callable that holds it, when the callee is that closure's own carrier (no
|
|
282
|
+
* prefix adapter between the two ABIs): the callable has the environment the
|
|
283
|
+
* entry takes first (`CallableObject::callKnownBorrowedEnvironment`).
|
|
284
|
+
*/
|
|
285
|
+
const flowClosureEntryOf = (ctx, callee) => {
|
|
286
|
+
const candidate = ctx.callableFlowCandidates.get(callee.value);
|
|
287
|
+
if (candidate === undefined || !isCallableObject(callee.representation))
|
|
288
|
+
return undefined;
|
|
289
|
+
if (cppTypeOf(callee.representation) !== cppTypeOf(candidate.allocated))
|
|
290
|
+
return undefined;
|
|
291
|
+
const entry = ctx.stableBorrowEntries.get(cppBodyName(candidate.functionId));
|
|
292
|
+
return entry?.environment && !entry.narrowedNumericAbi ? entry : undefined;
|
|
293
|
+
};
|
|
277
294
|
/**
|
|
278
295
|
* The entry a callable parameter, capture or field was seen to hold
|
|
279
296
|
* (`callableFlowCandidatesOf`), for `callKnown`'s identity guard: the
|
|
@@ -454,6 +471,29 @@ const emitNullishInvocation = (ctx, lines, operation) => {
|
|
|
454
471
|
defineValueAlias(ctx, result, '(void)0');
|
|
455
472
|
return true;
|
|
456
473
|
};
|
|
474
|
+
/** A call of a method read that always misses (`abstractMissReadKeyOf`) is a call of `undefined`. */
|
|
475
|
+
const emitAbstractMissInvocation = (ctx, lines, operation) => {
|
|
476
|
+
const read = ctx.propertyReadOrigins.get(operation.callee.value);
|
|
477
|
+
const key = read === undefined ? null : abstractMissReadKeyOf(ctx, read);
|
|
478
|
+
if (key === null)
|
|
479
|
+
return false;
|
|
480
|
+
// A single-use argument may still be a deferred expression: it runs here,
|
|
481
|
+
// before the callee is found not callable (13.3.6.2 EvaluateCall).
|
|
482
|
+
for (const argument of operation.arguments)
|
|
483
|
+
lines.push(`(void)(${operandText(ctx, argument)});`);
|
|
484
|
+
const failure = `gea::host::throwRuntimeError("TypeError", ${JSON.stringify(`${key} is not a function`)})`;
|
|
485
|
+
const result = operation.result;
|
|
486
|
+
if (result && result.representation.kind !== 'void') {
|
|
487
|
+
const target = cppTypeOf(result.representation);
|
|
488
|
+
lines.push(`${defineValue(ctx, result)} = (${failure}, gea::host::unreachableValue<${target}>());`);
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
lines.push(`${failure};`);
|
|
492
|
+
if (result)
|
|
493
|
+
defineValueAlias(ctx, result, '(void)0');
|
|
494
|
+
}
|
|
495
|
+
return true;
|
|
496
|
+
};
|
|
457
497
|
const refusedPrimitiveValueOf = (primitive, result) => {
|
|
458
498
|
throw createCppEmitBlockedError(`conversion:${representationKey(primitive)}->${representationKey(result)}`, `a "${representationKey(primitive)}" arm's valueOf answers the primitive itself, which this call's "${representationKey(result)}" result cannot hold`);
|
|
459
499
|
};
|
|
@@ -541,6 +581,11 @@ const emitUnionMethodCall = (ctx, lines, operation) => {
|
|
|
541
581
|
// turn them into text against a receiver that has a name by now.
|
|
542
582
|
const receiverText = operandText(ctx, read.receiver);
|
|
543
583
|
const evidence = borrowEvidenceOf(ctx, operation);
|
|
584
|
+
// The member key, for an arm whose class a dynamic write may shadow
|
|
585
|
+
// (`ClassLayout.dynamicMethodShadows`): that arm checks the instance's
|
|
586
|
+
// expando table before calling its body.
|
|
587
|
+
const memberRead = ctx.propertyReadOrigins.get(operation.callee.value);
|
|
588
|
+
const memberKey = memberRead === undefined ? undefined : ctx.staticKeyTexts.get(memberRead.key.value);
|
|
544
589
|
const branches = arms.map((arm, index) => {
|
|
545
590
|
const tests = [];
|
|
546
591
|
let armText = receiverText;
|
|
@@ -582,13 +627,27 @@ const emitUnionMethodCall = (ctx, lines, operation) => {
|
|
|
582
627
|
const padded = paddedArguments(abi, [...(receiver === null ? [] : [receiver]), ...supplied], 'union method call');
|
|
583
628
|
// Each arm names its body, so it may enter that body's borrowed entry on the
|
|
584
629
|
// same evidence a direct call does.
|
|
585
|
-
const entry = packed === null ? ctx.stableBorrowEntries.get(cppBodyName(arm.callable)) : undefined;
|
|
630
|
+
const entry = packed === null ? environmentFreeEntry(ctx.stableBorrowEntries.get(cppBodyName(arm.callable))) : undefined;
|
|
586
631
|
const copies = entry === undefined
|
|
587
632
|
? null
|
|
588
633
|
: stableBorrowEntryCopies(entry, operation.arguments, evidence.stableActuals, evidence.potentiallyMovingArguments);
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
|
|
634
|
+
const shadowed = memberKey !== undefined &&
|
|
635
|
+
receiver !== null &&
|
|
636
|
+
arm.receiverRepresentation.kind === 'class-ref' &&
|
|
637
|
+
classDynamicMethodShadowOf(ctx.classes, arm.receiverRepresentation.declaration, memberKey);
|
|
638
|
+
const self = 'gea_shadow_receiver';
|
|
639
|
+
const called = shadowed ? [self, ...padded.slice(1)] : padded;
|
|
640
|
+
const direct = entry === undefined || copies === null
|
|
641
|
+
? `${cppBodyName(arm.callable)}(${called.join(', ')})`
|
|
642
|
+
: `${entry.name}(${copiedBorrowArguments(called, receiver === null ? 0 : 1, entry, copies).join(', ')})`;
|
|
643
|
+
const shadowCall = `gea_shadow_callable.callWithReceiver(${['gea::NativeCallReceiver::object(' + self + ')', ...padded.slice(1)].join(', ')})`;
|
|
644
|
+
const invocation = !shadowed
|
|
645
|
+
? direct
|
|
646
|
+
: `[&](const auto& ${self}) { using gea_shadow_result = std::remove_cvref_t<decltype(${direct})>; ` +
|
|
647
|
+
`if (gea::detail::nativeExpandoPresent(${self})) [[unlikely]] { if (const auto gea_shadow = gea::detail::nativeExpandoOwnValue(${self}, ${cppStringLiteral(memberKey)})) { ` +
|
|
648
|
+
`auto gea_shadow_callable = gea::detail::DynamicCarrier<${cppTypeOf({ kind: 'function-value-dispatch', abi: { ...abi, receiver: null } })}>::in(*gea_shadow, 0); ` +
|
|
649
|
+
`if constexpr (std::is_void_v<gea_shadow_result>) { ${shadowCall}; return; } else return static_cast<gea_shadow_result>(${shadowCall}); } } ` +
|
|
650
|
+
`return ${direct}; }(${receiver})`;
|
|
592
651
|
let body;
|
|
593
652
|
if (operation.result === null || operation.result.representation.kind === 'void') {
|
|
594
653
|
body = `${invocation}; return;`;
|
|
@@ -955,6 +1014,8 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
955
1014
|
return;
|
|
956
1015
|
if (emitNullishInvocation(ctx, lines, operation))
|
|
957
1016
|
return;
|
|
1017
|
+
if (emitAbstractMissInvocation(ctx, lines, operation))
|
|
1018
|
+
return;
|
|
958
1019
|
if (operation.callee.representation.kind === 'native-handle' && operation.callee.representation.protocol === 'FunctionConstructor') {
|
|
959
1020
|
if (!ctx.deriver.dynamicFallback)
|
|
960
1021
|
throw createCppEmitBlockedError('call-abi:function-constructor', 'Function construction requires --dynamic-fallback');
|
|
@@ -1409,7 +1470,7 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
1409
1470
|
: callableMemberSlot(memberRead.receiver.representation, memberKey);
|
|
1410
1471
|
const candidate = memberSlot === undefined ? undefined : ctx.callableMemberCandidates.get(memberSlot);
|
|
1411
1472
|
const alternate = memberSlot === undefined ? undefined : ctx.callableMemberCandidates.get(callableMemberAlternateSlot(memberSlot));
|
|
1412
|
-
const stableCandidate = ctx.stableBorrowEntries.get(direct ?? (candidate === undefined ? '' : cppBodyName(candidate)));
|
|
1473
|
+
const stableCandidate = environmentFreeEntry(ctx.stableBorrowEntries.get(direct ?? (candidate === undefined ? '' : cppBodyName(candidate))));
|
|
1413
1474
|
const { potentiallyMovingArguments, stableActuals } = borrowEvidenceOf(ctx, operation);
|
|
1414
1475
|
// A narrowed integer formal is spelled alike by both entries only for a call
|
|
1415
1476
|
// that names the body; a carrier adapter passes the unnarrowed ABI.
|
|
@@ -1421,7 +1482,7 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
1421
1482
|
// A candidate's borrowed entry for this call, when it has one: the stable
|
|
1422
1483
|
// entry its arguments are accepted by, or its borrowable body.
|
|
1423
1484
|
const borrowedEntryOf = (target) => {
|
|
1424
|
-
const stable = ctx.stableBorrowEntries.get(cppBodyName(target));
|
|
1485
|
+
const stable = environmentFreeEntry(ctx.stableBorrowEntries.get(cppBodyName(target)));
|
|
1425
1486
|
if (stable !== undefined &&
|
|
1426
1487
|
!stable.narrowedNumericAbi &&
|
|
1427
1488
|
stableBorrowEntryAccepts(stable, operation.arguments, stableActuals, potentiallyMovingArguments))
|
|
@@ -1445,13 +1506,19 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
1445
1506
|
const flowKnown = candidate === undefined && direct === undefined && dispatched === undefined && calleeOperand.value === operation.callee.value
|
|
1446
1507
|
? flowKnownText(ctx, operation.callee)
|
|
1447
1508
|
: null;
|
|
1509
|
+
const flowEntry = flowKnown === null ? undefined : flowClosureEntryOf(ctx, operation.callee);
|
|
1510
|
+
const flowCopies = flowEntry === undefined ? null : stableBorrowEntryCopies(flowEntry, operation.arguments, stableActuals, potentiallyMovingArguments);
|
|
1511
|
+
const flowBorrowed = flowCopies === null ? undefined : flowEntry;
|
|
1512
|
+
const flowArguments = copiedBorrowArguments(padded, declaredReceiverOperand ? 1 : 0, flowBorrowed, flowCopies);
|
|
1448
1513
|
const candidateEntersStableEntry = candidate !== undefined &&
|
|
1449
1514
|
!(firstEntry !== undefined && alternate !== undefined && alternateEntry !== undefined) &&
|
|
1450
1515
|
!alternateOnly &&
|
|
1451
1516
|
stableEntry !== undefined;
|
|
1452
1517
|
const callMember = candidate === undefined
|
|
1453
1518
|
? flowKnown !== null
|
|
1454
|
-
?
|
|
1519
|
+
? flowBorrowed !== undefined
|
|
1520
|
+
? `${stableCallee ? 'callStableKnownBorrowedEnvironment' : 'callKnownBorrowedEnvironment'}<${flowKnown}, &${flowBorrowed.name}>`
|
|
1521
|
+
: `${stableCallee ? 'callStableKnown' : 'callKnown'}<${flowKnown}>`
|
|
1455
1522
|
: stableCallee
|
|
1456
1523
|
? 'callStable'
|
|
1457
1524
|
: 'call'
|
|
@@ -1495,12 +1562,23 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
1495
1562
|
const guardedInvocation = () => {
|
|
1496
1563
|
const [receiverArgument, ...rest] = padded;
|
|
1497
1564
|
const self = 'gea_guard_receiver';
|
|
1565
|
+
const receiverType = cppTypeOf(abi.receiver);
|
|
1566
|
+
// The receiver is taken by reference and handed to the prototype body as
|
|
1567
|
+
// its direct call would hand it (a body that borrows its receiver gets no
|
|
1568
|
+
// retain at all), where a by-value parameter copied it on every call of a
|
|
1569
|
+
// guarded method -- every Vector3 call, once a dynamic write may shadow
|
|
1570
|
+
// its methods. The body's borrowed entry is used when it admits these
|
|
1571
|
+
// arguments, exactly as a direct call admits it. Only the shadowed path,
|
|
1572
|
+
// which calls through the own property, takes a handle of its own.
|
|
1498
1573
|
// A typed (non-generic) parameter: a generic lambda would make every
|
|
1499
1574
|
// member template the callee names a dependent name needing `template`.
|
|
1500
|
-
const
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1575
|
+
const borrowed = environmentFreeEntry(ctx.stableBorrowEntries.get(cppBodyName(guard.functionId)));
|
|
1576
|
+
const borrowedCopies = borrowed === undefined ? null : stableBorrowEntryCopies(borrowed, operation.arguments, stableActuals, potentiallyMovingArguments);
|
|
1577
|
+
const body = borrowed !== undefined && borrowedCopies !== null
|
|
1578
|
+
? `${borrowed.name}(${copiedBorrowArguments([self, ...rest], 1, borrowed, borrowedCopies).join(', ')})`
|
|
1579
|
+
: `${cppBodyName(guard.functionId)}(${[self, ...rest].join(', ')})`;
|
|
1580
|
+
return (`[&](const ${receiverType}& ${self}) -> decltype(auto) { return (static_cast<bool>(${self}) && !${self}->${cppRecordFieldPresenceName(guard.key)}) ` +
|
|
1581
|
+
`? ${body} : ${operandText(ctx, calleeOperand)}.${callMember}(${[`${receiverType}(${self})`, ...rest].join(', ')}); }(${receiverArgument})`);
|
|
1504
1582
|
};
|
|
1505
1583
|
// A logical receiver that is a value this frame already holds (not withheld
|
|
1506
1584
|
// as an expression) can be built inside the callee's dispatch, only for a
|
|
@@ -1513,17 +1591,56 @@ export const emitCall = (ctx, lines, operation) => {
|
|
|
1513
1591
|
!isDeferredValue(ctx, logical.value) &&
|
|
1514
1592
|
calleeOperand.value === operation.callee.value &&
|
|
1515
1593
|
isCallableObject(calleeOperand.representation);
|
|
1594
|
+
// `CallOperation.expandoShadowGuard`: a write through a dynamic receiver may
|
|
1595
|
+
// have installed an own function over this method, and such a shadow lives
|
|
1596
|
+
// in the instance's expando table rather than in a slot. The call runs as
|
|
1597
|
+
// resolved unless the instance has a table holding the key; the receiver
|
|
1598
|
+
// and the converted arguments are the lambda's arguments, so each is
|
|
1599
|
+
// evaluated once whichever path runs.
|
|
1600
|
+
const shadowGuard = operation.expandoShadowGuard;
|
|
1601
|
+
const shadowedInvocation = (receiverText, argumentTexts, normal,
|
|
1602
|
+
// The convention the arguments were converted to. A virtual call converts
|
|
1603
|
+
// them to the slot's own, which a family widens past the resolved
|
|
1604
|
+
// method's (`removeListener(event: string)` under a base taking
|
|
1605
|
+
// `string | symbol`), and the shadow is handed those same arguments.
|
|
1606
|
+
convention = abiOfCallee(operation.callee.representation)) => {
|
|
1607
|
+
const held = convention;
|
|
1608
|
+
if (shadowGuard === undefined || held === null || held.receiver === null)
|
|
1609
|
+
throw createCppEmitBlockedError('call-abi:expando-shadow', 'a call a dynamic write may shadow has no receiver-taking method convention');
|
|
1610
|
+
const self = 'gea_shadow_receiver';
|
|
1611
|
+
const names = argumentTexts.map((_, index) => `gea_shadow_argument_${index}`);
|
|
1612
|
+
const forwarded = names.map((name) => `std::forward<decltype(${name})>(${name})`);
|
|
1613
|
+
const shadow = cppTypeOf({ kind: 'function-value-dispatch', abi: { ...held, receiver: null } });
|
|
1614
|
+
const shadowCall = `gea_shadow_callable.callWithReceiver(${['gea::NativeCallReceiver::object(' + self + ')', ...forwarded].join(', ')})`;
|
|
1615
|
+
return (`[&](const auto& ${self}${names.map((name) => `, auto&& ${name}`).join('')}) { ` +
|
|
1616
|
+
`auto gea_shadow_normal = [&]() -> decltype(auto) { return ${normal(self, forwarded)}; }; ` +
|
|
1617
|
+
'using gea_shadow_result = std::remove_cvref_t<decltype(gea_shadow_normal())>; ' +
|
|
1618
|
+
`if (gea::detail::nativeExpandoPresent(${self})) [[unlikely]] { ` +
|
|
1619
|
+
`if (const auto gea_shadow = gea::detail::nativeExpandoOwnValue(${self}, ${cppStringLiteral(shadowGuard.key)})) { ` +
|
|
1620
|
+
`auto gea_shadow_callable = gea::detail::DynamicCarrier<${shadow}>::in(*gea_shadow, 0); ` +
|
|
1621
|
+
`if constexpr (std::is_void_v<gea_shadow_result>) { ${shadowCall}; return; } else return static_cast<gea_shadow_result>(${shadowCall}); } } ` +
|
|
1622
|
+
`return gea_shadow_normal(); }(${[receiverText, ...argumentTexts].join(', ')})`);
|
|
1623
|
+
};
|
|
1624
|
+
const genericArguments = candidateEntersStableEntry ? stableArguments : flowBorrowed !== undefined ? flowArguments : padded;
|
|
1625
|
+
if (shadowGuard !== undefined && ((dispatched === undefined && direct === undefined && abi.receiver === null) || guardable))
|
|
1626
|
+
throw createCppEmitBlockedError('call-abi:expando-shadow', 'a call a dynamic write may shadow is spelled without its receiver');
|
|
1516
1627
|
const invocation = dispatched !== undefined
|
|
1517
|
-
?
|
|
1628
|
+
? shadowGuard !== undefined
|
|
1629
|
+
? shadowedInvocation(virtualPadded[0], virtualPadded.slice(1), (self, args) => `${self}->${dispatched.member}(${args.join(', ')})`, dispatched.abi)
|
|
1630
|
+
: `${virtualPadded[0]}->${dispatched.member}(${virtualPadded.slice(1).join(', ')})`
|
|
1518
1631
|
: direct !== undefined
|
|
1519
|
-
?
|
|
1632
|
+
? shadowGuard !== undefined
|
|
1633
|
+
? shadowedInvocation(stableArguments[0], stableArguments.slice(1), (self, args) => `${stableEntry?.name ?? direct}(${[self, ...args].join(', ')})`)
|
|
1634
|
+
: `${stableEntry?.name ?? direct}(${stableArguments.join(', ')})`
|
|
1520
1635
|
: abi.receiver === null && logicalThis !== null
|
|
1521
1636
|
? lazyLogicalReceiver(logicalThis)
|
|
1522
1637
|
? `${operandText(ctx, calleeOperand)}.callWithLazyReceiver(${[`[&]() -> gea::NativeCallReceiver { return ${operationNativeCallReceiverText(ctx, operation, logicalThis.representation, operandText(ctx, logicalThis))}; }`, ...padded].join(', ')})`
|
|
1523
1638
|
: `${operandText(ctx, calleeOperand)}.callWithReceiver(${[operationNativeCallReceiverText(ctx, operation, logicalThis.representation, operandText(ctx, logicalThis)), ...padded].join(', ')})`
|
|
1524
1639
|
: guardable
|
|
1525
1640
|
? guardedInvocation()
|
|
1526
|
-
:
|
|
1641
|
+
: shadowGuard !== undefined
|
|
1642
|
+
? shadowedInvocation(genericArguments[0], genericArguments.slice(1), (self, args) => `${operandText(ctx, calleeOperand)}.${callMember}(${[self, ...args].join(', ')})`)
|
|
1643
|
+
: `${operandText(ctx, calleeOperand)}.${callMember}(${genericArguments.join(', ')})`;
|
|
1527
1644
|
// A result the integer census narrowed from the candidate body's returns is
|
|
1528
1645
|
// checked where it lands, on every path the call can take: the guard above
|
|
1529
1646
|
// may miss and run whatever callable the member holds.
|
|
@@ -417,3 +417,9 @@ export declare const scalarMemberText: (ctx: EmitContext, receiver: IrOperand, k
|
|
|
417
417
|
export declare const positionalRecordArityText: (representation: Extract<Representation, {
|
|
418
418
|
kind: "record";
|
|
419
419
|
}>, receiverText: () => string) => string | null;
|
|
420
|
+
/**
|
|
421
|
+
* Declares a run's window (`ir/dense-read-windows.ts`) at whichever member
|
|
422
|
+
* renders first. The run's first access takes it; a member that renders on
|
|
423
|
+
* another path leaves it null, and a null window reads and stores the plain way.
|
|
424
|
+
*/
|
|
425
|
+
export declare const declareDenseWindow: (ctx: EmitContext, name: string, array: Representation) => void;
|
|
@@ -234,8 +234,21 @@ export const arrayAccessText = (ctx, receiver, key, result) => {
|
|
|
234
234
|
// and proved it canonical again on every read, which on a core without a
|
|
235
235
|
// double FPU is a chain of soft-float calls per `m.elements[k]`.
|
|
236
236
|
if (index !== null) {
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
const absentCapable = absentCapableElementText(ctx, receiverText, 'elementAtIndex', index, receiver.representation.element, result);
|
|
238
|
+
if (absentCapable !== null)
|
|
239
|
+
return absentCapable;
|
|
240
|
+
const plain = `${receiverText}->readElementAtIndex(${index})`;
|
|
241
|
+
// One of a run of constant-index reads of this array (`ir/dense-read-windows.ts`):
|
|
242
|
+
// the first takes the window for the run's highest index, and every
|
|
243
|
+
// member reads the cells while it holds, the plain read otherwise.
|
|
244
|
+
const window = result === null ? undefined : ctx.denseReadWindows.get(result.id);
|
|
245
|
+
if (window === undefined)
|
|
246
|
+
return reconciledElementText(ctx, receiver.representation.element, result, plain);
|
|
247
|
+
const name = `gea_read_window_${window.ordinal}`;
|
|
248
|
+
declareDenseWindow(ctx, name, receiver.representation);
|
|
249
|
+
const take = window.mutable ? 'gea::denseWindowCellsMutable' : 'gea::denseWindowCells';
|
|
250
|
+
const cells = window.initialize ? `(${name}.cells = ${take}(${receiverText}, ${window.last}))` : `${name}.cells`;
|
|
251
|
+
return reconciledElementText(ctx, receiver.representation.element, result, `(${cells} ? ${name}.cells[${index}].value : ${plain})`);
|
|
239
252
|
}
|
|
240
253
|
if (deferredArrayMethodClaim(ctx.staticKeyTexts, receiver, key) !== null) {
|
|
241
254
|
if (result === null) {
|
|
@@ -1286,3 +1299,12 @@ export const positionalRecordArityText = (representation, receiverText) => {
|
|
|
1286
1299
|
const accessor = memberAccessOperator(representation.ownership);
|
|
1287
1300
|
return positionalArityText(representation.fields, (key) => `${receiverText()}${accessor}${cppRecordFieldPresenceName(key)}`);
|
|
1288
1301
|
};
|
|
1302
|
+
/**
|
|
1303
|
+
* Declares a run's window (`ir/dense-read-windows.ts`) at whichever member
|
|
1304
|
+
* renders first. The run's first access takes it; a member that renders on
|
|
1305
|
+
* another path leaves it null, and a null window reads and stores the plain way.
|
|
1306
|
+
*/
|
|
1307
|
+
export const declareDenseWindow = (ctx, name, array) => {
|
|
1308
|
+
if (!ctx.declarations.some((declaration) => declaration.name === name))
|
|
1309
|
+
ctx.declarations.push({ name, type: `gea::DenseReadWindow<${cppTypeOf(array)}>` });
|
|
1310
|
+
};
|
|
@@ -6,6 +6,7 @@ import { type IntegrityRestrictions } from '../../ir/integrity-restrictions.js';
|
|
|
6
6
|
import type { BorrowedArmProjection } from './borrowed-arm-projections.js';
|
|
7
7
|
import type { StableBorrowEntry } from './borrowed-call-entry.js';
|
|
8
8
|
import type { SharedStringLayout } from '../../ir/string-layout-reuse.js';
|
|
9
|
+
import type { DenseReadWindow } from '../../ir/dense-read-windows.js';
|
|
9
10
|
import type { LazySplit } from '../../ir/lazy-splits.js';
|
|
10
11
|
import type { CapabilityKey } from '../../ir/certify.js';
|
|
11
12
|
import type { DeclarationId, FunctionId, IrValueId, RegionId, SemanticResultId } from '../../identity/ids.js';
|
|
@@ -14,7 +15,7 @@ import type { DeclaredIntegerWidth } from '../../ir/integers.js';
|
|
|
14
15
|
import type { BindingPlacement } from '../../projection/bindings.js';
|
|
15
16
|
import type { ClassLayout } from '../../projection/classes.js';
|
|
16
17
|
import type { RecordLayoutPolicy } from '../../representation/policies.js';
|
|
17
|
-
import type { CallOperation, ComputeOperation, GetOperation, IrBlockId, IrBody, IrCaptureGroup, IrNonTerminatorOperation, IrOperand, IrOperation, IrResult } from '../../ir/model.js';
|
|
18
|
+
import type { CallOperation, ComputeOperation, GetOperation, SetOperation, IrBlockId, IrBody, IrCaptureGroup, IrNonTerminatorOperation, IrOperand, IrOperation, IrResult } from '../../ir/model.js';
|
|
18
19
|
import type { NumericIntrinsic } from '../../ir/numeric-intrinsics.js';
|
|
19
20
|
import type { DenseAccess, DenseArray, DenseGroup, DenseRegion } from '../../ir/dense-loops.js';
|
|
20
21
|
import type { TypeQueryComparison } from '../../ir/type-query-results.js';
|
|
@@ -211,6 +212,8 @@ export interface CaptureIndex {
|
|
|
211
212
|
* to render first leaves the other branch dereferencing an empty handle.
|
|
212
213
|
*/
|
|
213
214
|
readonly requiresEarlyBox: (declaration: DeclarationId) => boolean;
|
|
215
|
+
/** Whether a boxed declaration is written exactly once (`IrBodyFacts.settledBoxes`). */
|
|
216
|
+
readonly isSettledBox: (declaration: DeclarationId) => boolean;
|
|
214
217
|
/**
|
|
215
218
|
* Whether this body reads `this` -- in its own operations, or in a closure
|
|
216
219
|
* it allocates that has no receiver of its own and so reads this one.
|
|
@@ -701,6 +704,16 @@ export interface EmitBodyFacts {
|
|
|
701
704
|
readonly asyncCoroutineBody: boolean;
|
|
702
705
|
/** See `EmitContext.returnsUnderFinallyGuard`. */
|
|
703
706
|
readonly returnsUnderFinallyGuard: boolean;
|
|
707
|
+
/** See `EmitContext.returnsOwnReceiver`. */
|
|
708
|
+
readonly returnsOwnReceiver: boolean;
|
|
709
|
+
/** See `EmitContext.plainAllocationValues`. */
|
|
710
|
+
readonly plainAllocationValues: ReadonlySet<IrValueId>;
|
|
711
|
+
/** See `EmitContext.allocationFieldKeys`. */
|
|
712
|
+
readonly allocationFieldKeys: ReadonlyMap<IrValueId, ReadonlySet<string>>;
|
|
713
|
+
/** See `EmitContext.borrowedFieldReads`. */
|
|
714
|
+
readonly borrowedFieldReads: ReadonlySet<IrValueId>;
|
|
715
|
+
/** See `EmitContext.deferredMethodValues`. */
|
|
716
|
+
readonly deferredMethodValues: ReadonlySet<IrValueId>;
|
|
704
717
|
/** See `EmitContext.receiverValues`. */
|
|
705
718
|
readonly receiverValues: ReadonlySet<IrValueId>;
|
|
706
719
|
/** See `EmitContext.bindingWriteCounts`. */
|
|
@@ -874,6 +887,36 @@ export interface EmitContext {
|
|
|
874
887
|
* still reads it (`runtime/gea_runtime.h`'s `detail::returnCopy`).
|
|
875
888
|
*/
|
|
876
889
|
readonly returnsUnderFinallyGuard: boolean;
|
|
890
|
+
/**
|
|
891
|
+
* Whether every return hands back the receiver, which the signature then
|
|
892
|
+
* returns by reference (`translation-unit.ts`'s `returnsOwnReceiver`): each
|
|
893
|
+
* return names the receiver formal itself, never a copy or a temporary.
|
|
894
|
+
*/
|
|
895
|
+
readonly returnsOwnReceiver: boolean;
|
|
896
|
+
/**
|
|
897
|
+
* Values read from a cell that holds one plain allocation for the whole
|
|
898
|
+
* program (`ir/program-facts.ts`'s `allocationCells`). A field-view read off
|
|
899
|
+
* one is the allocation's own member: no live view can stand in for it.
|
|
900
|
+
*/
|
|
901
|
+
readonly plainAllocationValues: ReadonlySet<IrValueId>;
|
|
902
|
+
/**
|
|
903
|
+
* For each of those reads held in the very carrier its allocation was
|
|
904
|
+
* written as, the keys that allocation defined (`AllocationCell.keys`): each
|
|
905
|
+
* field's presence bit was raised there, so it stays up wherever nothing can
|
|
906
|
+
* delete that key (`emit-properties.ts`'s `allocationKeepsField`).
|
|
907
|
+
*/
|
|
908
|
+
readonly allocationFieldKeys: ReadonlyMap<IrValueId, ReadonlySet<string>>;
|
|
909
|
+
/**
|
|
910
|
+
* Field reads whose one use is the receiver of another member read: the
|
|
911
|
+
* read can hand that read a reference instead of a retained handle.
|
|
912
|
+
*/
|
|
913
|
+
readonly borrowedFieldReads: ReadonlySet<IrValueId>;
|
|
914
|
+
/**
|
|
915
|
+
* Method reads consumed only as the callee of a resolved call
|
|
916
|
+
* (`ir/native-method-frames.ts`'s `deferredMethodValuesOf`): no Function
|
|
917
|
+
* object is published for them, and the call settles any shadow itself.
|
|
918
|
+
*/
|
|
919
|
+
readonly deferredMethodValues: ReadonlySet<IrValueId>;
|
|
877
920
|
/** The conventions of emitted bodies, shared with their signature renderer. */
|
|
878
921
|
readonly abiOfCallable: (callable: FunctionId) => CallableAbi | null;
|
|
879
922
|
readonly methodEnvironment: (callable: FunctionId, what: string) => string;
|
|
@@ -1453,6 +1496,10 @@ export interface EmitContext {
|
|
|
1453
1496
|
readonly hoistedResults: ReadonlySet<IrValueId>;
|
|
1454
1497
|
/** See `hoistedResults`'s doc for why this is settled the same way. */
|
|
1455
1498
|
readonly sharedStringLayouts: ReadonlyMap<IrValueId, SharedStringLayout>;
|
|
1499
|
+
/** Constant-index element reads sharing one dense window (`ir/dense-read-windows.ts`), settled like `sharedStringLayouts`. */
|
|
1500
|
+
readonly denseReadWindows: ReadonlyMap<IrValueId, DenseReadWindow>;
|
|
1501
|
+
/** The stores of those runs (`denseReadWindows`), keyed by operation. */
|
|
1502
|
+
readonly denseWriteWindows: ReadonlyMap<SetOperation, DenseReadWindow>;
|
|
1456
1503
|
readonly prototypeMethodReads: ReadonlyMap<IrValueId, PrototypeMethodRead>;
|
|
1457
1504
|
/**
|
|
1458
1505
|
* Lazy-arrow-field GETs whose one reader is the call that reads them as its
|
|
@@ -1553,6 +1600,21 @@ export interface EmitContext {
|
|
|
1553
1600
|
readonly aliasedStableFieldReads: Set<IrValueId>;
|
|
1554
1601
|
/** The field text each admitted cell names, set by its one write before any read renders. */
|
|
1555
1602
|
readonly stableFieldCellTexts: Map<DeclarationId, string>;
|
|
1603
|
+
/** Dense window reads that rendered as the window's cell itself, an lvalue (`denseElementText`). Filled as the body renders. */
|
|
1604
|
+
readonly denseCellReads: Set<IrValueId>;
|
|
1605
|
+
/**
|
|
1606
|
+
* The pointer each borrowed window cell (`borrowedWindowCells`) was declared
|
|
1607
|
+
* as, set by its one write when that write's read rendered as the cell, before
|
|
1608
|
+
* any read of it renders.
|
|
1609
|
+
*/
|
|
1610
|
+
readonly borrowedWindowCellNames: Map<DeclarationId, string>;
|
|
1611
|
+
/**
|
|
1612
|
+
* The pointer expression each field pointer (`fieldPointerValues`) rendered
|
|
1613
|
+
* as: its own `const T*` for a borrowed read or merge, or the address of the
|
|
1614
|
+
* frame slot a read that could not borrow was copied into. Filled as the body
|
|
1615
|
+
* renders; a merge's edge writes read it.
|
|
1616
|
+
*/
|
|
1617
|
+
readonly fieldPointerTexts: Map<IrValueId, string>;
|
|
1556
1618
|
/** Dominating native length results, selected by the IR reuse proof. Settled the same way as `hoistedResults`. */
|
|
1557
1619
|
readonly reusedStringLengths: ReadonlyMap<IrValueId, IrOperand>;
|
|
1558
1620
|
/** Withheld values whose single reader is a call, and which therefore reach exactly one operand position -- see `emit.ts`'s `consumedByCall`. Settled the same way as `hoistedResults`. */
|
|
@@ -1640,6 +1702,13 @@ export interface EmitContext {
|
|
|
1640
1702
|
* ts`) through `ctx` directly -- same follow-up as `formalCells`.
|
|
1641
1703
|
*/
|
|
1642
1704
|
readonly capacityHints: ReadonlyMap<IrValueId, CapacitySource>;
|
|
1705
|
+
/**
|
|
1706
|
+
* The array literals whose element stores are spelled as calls rather than
|
|
1707
|
+
* inlined `push`es, because their body holds too many of them for the C++
|
|
1708
|
+
* compiler's per-function passes; see `collectOutOfLineLiteralPushes`
|
|
1709
|
+
* (`emit-arrays.ts`).
|
|
1710
|
+
*/
|
|
1711
|
+
readonly outOfLineLiteralPushes: ReadonlySet<IrValueId>;
|
|
1643
1712
|
/** The local arrays proved to be nothing but a `String.fromCharCode` argument list; see `char-code-buffers.ts`. */
|
|
1644
1713
|
readonly charCodeBuffers: CharCodeBufferFacts;
|
|
1645
1714
|
/**
|
|
@@ -1738,6 +1807,19 @@ export interface EmitContext {
|
|
|
1738
1807
|
* distinct objects. Decided once the scope plan exists, before rendering.
|
|
1739
1808
|
*/
|
|
1740
1809
|
readonly denseOutlined: ReadonlyMap<number, DenseRegion>;
|
|
1810
|
+
/**
|
|
1811
|
+
* Cells that hold the address of the window cell they are written from
|
|
1812
|
+
* (`ir/borrowed-window-cells.ts`), decided by `emitBody` once the windows
|
|
1813
|
+
* are admitted.
|
|
1814
|
+
*/
|
|
1815
|
+
readonly borrowedWindowCells: ReadonlySet<DeclarationId>;
|
|
1816
|
+
/**
|
|
1817
|
+
* Field reads, and the merges of them, that render as a pointer to the field
|
|
1818
|
+
* (`ir/borrowed-field-reads.ts`), decided by `emitBody` before rendering.
|
|
1819
|
+
*/
|
|
1820
|
+
readonly fieldPointerValues: ReadonlySet<IrValueId>;
|
|
1821
|
+
/** The field pointers some pointer merge takes on an edge: each needs a pointer even when its read could not borrow. */
|
|
1822
|
+
readonly fieldPointerMergeInputs: ReadonlySet<IrValueId>;
|
|
1741
1823
|
/** Reads of a wrapped window's `length` that the preheader already took, by the window's ordinal. */
|
|
1742
1824
|
readonly denseLengths: ReadonlyMap<IrValueId, number>;
|
|
1743
1825
|
/** Subscripts a wrapped window may take in the integers -- see `denseRemainderCompanion`. */
|
|
@@ -1926,6 +2008,8 @@ export declare const effectiveAbiOf: (abi: CallableAbi | null, admission: Captur
|
|
|
1926
2008
|
export interface EmitBodyPrepassFacts {
|
|
1927
2009
|
readonly hoistedResults: Set<IrValueId>;
|
|
1928
2010
|
readonly sharedStringLayouts: Map<IrValueId, SharedStringLayout>;
|
|
2011
|
+
readonly denseReadWindows: Map<IrValueId, DenseReadWindow>;
|
|
2012
|
+
readonly denseWriteWindows: Map<SetOperation, DenseReadWindow>;
|
|
1929
2013
|
readonly reusedStringLengths: Map<IrValueId, IrOperand>;
|
|
1930
2014
|
readonly loopInvariantValues: Set<IrValueId>;
|
|
1931
2015
|
readonly numericCalls: Map<CallOperation, NumericIntrinsic>;
|
|
@@ -1966,6 +2050,7 @@ export interface EmitBodyPrepassFacts {
|
|
|
1966
2050
|
readonly directBindingSinks: Map<IrValueId, DeclarationId>;
|
|
1967
2051
|
readonly forwardedBindings: Map<DeclarationId, ForwardedBinding>;
|
|
1968
2052
|
readonly capacityHints: Map<IrValueId, CapacitySource>;
|
|
2053
|
+
readonly outOfLineLiteralPushes: Set<IrValueId>;
|
|
1969
2054
|
readonly charCodeBuffers: CharCodeBufferFacts;
|
|
1970
2055
|
readonly fillLoops: Map<IrBlockId, FillLoop>;
|
|
1971
2056
|
readonly denseArrays: DenseArray[];
|
|
@@ -1973,6 +2058,9 @@ export interface EmitBodyPrepassFacts {
|
|
|
1973
2058
|
readonly denseGroups: Map<number, DenseGroup>;
|
|
1974
2059
|
readonly denseRegions: DenseRegion[];
|
|
1975
2060
|
readonly denseOutlined: Map<number, DenseRegion>;
|
|
2061
|
+
readonly borrowedWindowCells: Set<DeclarationId>;
|
|
2062
|
+
readonly fieldPointerValues: Set<IrValueId>;
|
|
2063
|
+
readonly fieldPointerMergeInputs: Set<IrValueId>;
|
|
1976
2064
|
readonly denseLengths: Map<IrValueId, number>;
|
|
1977
2065
|
readonly deferrable: Set<IrValueId>;
|
|
1978
2066
|
}
|
|
@@ -2044,6 +2132,12 @@ export declare const isIntegerKeyValue: (ctx: EmitContext, key: IrOperand) => bo
|
|
|
2044
2132
|
*/
|
|
2045
2133
|
export declare const captureFieldText: (ctx: EmitContext, declaration: DeclarationId, representation: Representation, text: string) => string;
|
|
2046
2134
|
export declare const defineValue: (ctx: EmitContext, result: IrResult, spelling?: string) => string;
|
|
2135
|
+
/**
|
|
2136
|
+
* Declares this result as a `const T*` and publishes it as the value it points
|
|
2137
|
+
* at, read-only (`EmitContext.fieldPointerValues`): a consumer that moves
|
|
2138
|
+
* copies. Returns the pointer's own name, which a merge's edge writes assign.
|
|
2139
|
+
*/
|
|
2140
|
+
export declare const defineFieldPointer: (ctx: EmitContext, result: IrResult) => string;
|
|
2047
2141
|
/**
|
|
2048
2142
|
* Mints this result's name without hoisting a declaration for it.
|
|
2049
2143
|
*
|
|
@@ -2120,6 +2214,8 @@ export declare const cppDenseRowName: (ordinal: number) => string;
|
|
|
2120
2214
|
export declare const cppDenseRowsName: (ordinal: number) => string;
|
|
2121
2215
|
/** One loop's dense-window condition. Loop-invariant by construction, which is what lets the backend version the loop on it. */
|
|
2122
2216
|
export declare const cppDenseFlagName: (group: number) => string;
|
|
2217
|
+
/** A checked typed window's element count, read once at the preheader -- see `DenseArray.checked`. */
|
|
2218
|
+
export declare const cppDenseExtentName: (ordinal: number) => string;
|
|
2123
2219
|
/** A wrapped window's own length, read once at the preheader -- see `DenseLoopPlan.lengths`. */
|
|
2124
2220
|
export declare const cppDenseLengthName: (ordinal: number) => string;
|
|
2125
2221
|
/** The reciprocal of that length, built once at the preheader rather than re-checked by `gea::preparedDivisor` on every turn. */
|
|
@@ -29,6 +29,7 @@ export const emptyCaptureIndex = {
|
|
|
29
29
|
isBoxed: () => false,
|
|
30
30
|
isCaptured: () => false,
|
|
31
31
|
requiresEarlyBox: () => false,
|
|
32
|
+
isSettledBox: () => false,
|
|
32
33
|
readsReceiver: () => false,
|
|
33
34
|
groupOf: () => null,
|
|
34
35
|
isAccessorEnvironment: () => false,
|
|
@@ -116,6 +117,8 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
116
117
|
// still needs a mutable handle at all.
|
|
117
118
|
const hoistedResults = new Set();
|
|
118
119
|
const sharedStringLayouts = new Map();
|
|
120
|
+
const denseReadWindows = new Map();
|
|
121
|
+
const denseWriteWindows = new Map();
|
|
119
122
|
const reusedStringLengths = new Map();
|
|
120
123
|
const loopInvariantValues = new Set();
|
|
121
124
|
const numericCalls = new Map();
|
|
@@ -153,6 +156,7 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
153
156
|
const directBindingSinks = new Map();
|
|
154
157
|
const forwardedBindings = new Map();
|
|
155
158
|
const capacityHints = new Map();
|
|
159
|
+
const outOfLineLiteralPushes = new Set();
|
|
156
160
|
const charCodeBuffers = createCharCodeBufferFacts();
|
|
157
161
|
const fillLoops = new Map();
|
|
158
162
|
const denseArrays = [];
|
|
@@ -160,6 +164,9 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
160
164
|
const denseGroups = new Map();
|
|
161
165
|
const denseRegions = [];
|
|
162
166
|
const denseOutlined = new Map();
|
|
167
|
+
const borrowedWindowCells = new Set();
|
|
168
|
+
const fieldPointerValues = new Set();
|
|
169
|
+
const fieldPointerMergeInputs = new Set();
|
|
163
170
|
const denseLengths = new Map();
|
|
164
171
|
const deferrable = new Set();
|
|
165
172
|
const ctx = {
|
|
@@ -216,6 +223,11 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
216
223
|
generatorBody: bodyFacts.generatorBody,
|
|
217
224
|
asyncCoroutineBody: bodyFacts.asyncCoroutineBody,
|
|
218
225
|
returnsUnderFinallyGuard: bodyFacts.returnsUnderFinallyGuard,
|
|
226
|
+
returnsOwnReceiver: bodyFacts.returnsOwnReceiver,
|
|
227
|
+
plainAllocationValues: bodyFacts.plainAllocationValues,
|
|
228
|
+
allocationFieldKeys: bodyFacts.allocationFieldKeys,
|
|
229
|
+
borrowedFieldReads: bodyFacts.borrowedFieldReads,
|
|
230
|
+
deferredMethodValues: bodyFacts.deferredMethodValues,
|
|
219
231
|
virtualDispatch,
|
|
220
232
|
directCallableBindings,
|
|
221
233
|
callableMemberCandidates,
|
|
@@ -252,6 +264,8 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
252
264
|
hostNamespaceDefinitelyPresent: bodyFacts.hostNamespaceDefinitelyPresent,
|
|
253
265
|
hoistedResults,
|
|
254
266
|
sharedStringLayouts,
|
|
267
|
+
denseReadWindows,
|
|
268
|
+
denseWriteWindows,
|
|
255
269
|
prototypeMethodReads,
|
|
256
270
|
lazyCalleeReads,
|
|
257
271
|
bindingNames: new Map(),
|
|
@@ -268,6 +282,9 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
268
282
|
stableFieldCells: bodyFacts.stableFieldCells,
|
|
269
283
|
aliasedStableFieldReads: new Set(),
|
|
270
284
|
stableFieldCellTexts: new Map(),
|
|
285
|
+
denseCellReads: new Set(),
|
|
286
|
+
borrowedWindowCellNames: new Map(),
|
|
287
|
+
fieldPointerTexts: new Map(),
|
|
271
288
|
reusedStringLengths,
|
|
272
289
|
callArgumentOnly,
|
|
273
290
|
classTableRoots: bodyFacts.classTableRoots,
|
|
@@ -275,6 +292,7 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
275
292
|
deferredTexts: new Map(),
|
|
276
293
|
pendingPacks: new Map(),
|
|
277
294
|
capacityHints,
|
|
295
|
+
outOfLineLiteralPushes,
|
|
278
296
|
charCodeBuffers,
|
|
279
297
|
fillLoops,
|
|
280
298
|
narrowedFormals,
|
|
@@ -303,6 +321,9 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
303
321
|
denseIndices: new Map(),
|
|
304
322
|
denseGroups,
|
|
305
323
|
denseOutlined,
|
|
324
|
+
borrowedWindowCells,
|
|
325
|
+
fieldPointerValues,
|
|
326
|
+
fieldPointerMergeInputs,
|
|
306
327
|
computeOrigins: bodyFacts.computeOrigins,
|
|
307
328
|
freshReceiverStores: bodyFacts.freshReceiverStores,
|
|
308
329
|
outOfOrderFreshStores: bodyFacts.outOfOrderFreshStores,
|
|
@@ -325,6 +346,8 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
325
346
|
prepass: {
|
|
326
347
|
hoistedResults,
|
|
327
348
|
sharedStringLayouts,
|
|
349
|
+
denseReadWindows,
|
|
350
|
+
denseWriteWindows,
|
|
328
351
|
reusedStringLengths,
|
|
329
352
|
loopInvariantValues,
|
|
330
353
|
numericCalls,
|
|
@@ -361,6 +384,7 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
361
384
|
directBindingSinks,
|
|
362
385
|
forwardedBindings,
|
|
363
386
|
capacityHints,
|
|
387
|
+
outOfLineLiteralPushes,
|
|
364
388
|
charCodeBuffers,
|
|
365
389
|
fillLoops,
|
|
366
390
|
denseArrays,
|
|
@@ -368,6 +392,9 @@ conversions = null, nativeSelections = undefined, callableIdentityDemand = obser
|
|
|
368
392
|
denseGroups,
|
|
369
393
|
denseRegions,
|
|
370
394
|
denseOutlined,
|
|
395
|
+
borrowedWindowCells,
|
|
396
|
+
fieldPointerValues,
|
|
397
|
+
fieldPointerMergeInputs,
|
|
371
398
|
denseLengths,
|
|
372
399
|
deferrable
|
|
373
400
|
}
|
|
@@ -467,6 +494,21 @@ export const defineValue = (ctx, result, spelling) => {
|
|
|
467
494
|
ctx.ownedValues.add(result.id);
|
|
468
495
|
return name;
|
|
469
496
|
};
|
|
497
|
+
/**
|
|
498
|
+
* Declares this result as a `const T*` and publishes it as the value it points
|
|
499
|
+
* at, read-only (`EmitContext.fieldPointerValues`): a consumer that moves
|
|
500
|
+
* copies. Returns the pointer's own name, which a merge's edge writes assign.
|
|
501
|
+
*/
|
|
502
|
+
export const defineFieldPointer = (ctx, result) => {
|
|
503
|
+
if (ctx.valueNames.has(result.id))
|
|
504
|
+
throw new Error(`ir value ${result.id} is defined twice in one body, which SSA form forbids`);
|
|
505
|
+
const name = `v${ctx.nextValueOrdinal}`;
|
|
506
|
+
ctx.nextValueOrdinal += 1;
|
|
507
|
+
ctx.declarations.push({ name, type: `const ${storageTypeOf(ctx, result.id, result.representation)}*` });
|
|
508
|
+
ctx.valueNames.set(result.id, `std::as_const(*${name})`);
|
|
509
|
+
ctx.fieldPointerTexts.set(result.id, name);
|
|
510
|
+
return name;
|
|
511
|
+
};
|
|
470
512
|
/**
|
|
471
513
|
* Mints this result's name without hoisting a declaration for it.
|
|
472
514
|
*
|
|
@@ -677,6 +719,8 @@ export const cppDenseRowName = (ordinal) => `gea_dense_row_${ordinal}`;
|
|
|
677
719
|
export const cppDenseRowsName = (ordinal) => `gea_dense_rows_${ordinal}`;
|
|
678
720
|
/** One loop's dense-window condition. Loop-invariant by construction, which is what lets the backend version the loop on it. */
|
|
679
721
|
export const cppDenseFlagName = (group) => `gea_dense_ok_${group}`;
|
|
722
|
+
/** A checked typed window's element count, read once at the preheader -- see `DenseArray.checked`. */
|
|
723
|
+
export const cppDenseExtentName = (ordinal) => `gea_dense_extent_${ordinal}`;
|
|
680
724
|
/** A wrapped window's own length, read once at the preheader -- see `DenseLoopPlan.lengths`. */
|
|
681
725
|
export const cppDenseLengthName = (ordinal) => `gea_dense_len_${ordinal}`;
|
|
682
726
|
/** The reciprocal of that length, built once at the preheader rather than re-checked by `gea::preparedDivisor` on every turn. */
|
|
@@ -1092,6 +1136,14 @@ const renderMutableEmitContextFields = new Set([
|
|
|
1092
1136
|
// that, and the field text its later reads print in place of the cell.
|
|
1093
1137
|
'aliasedStableFieldReads',
|
|
1094
1138
|
'stableFieldCellTexts',
|
|
1139
|
+
// The same test for window cells: WHICH cells may hold a window cell's
|
|
1140
|
+
// address is the prepass's `borrowedWindowCells`; whether the one write's
|
|
1141
|
+
// read printed as the cell is decided where `emitGet` spells it.
|
|
1142
|
+
'denseCellReads',
|
|
1143
|
+
'borrowedWindowCellNames',
|
|
1144
|
+
// And for field pointers: WHICH values are pointers is the prepass's
|
|
1145
|
+
// `fieldPointerValues`; this is the pointer each one was declared as.
|
|
1146
|
+
'fieldPointerTexts',
|
|
1095
1147
|
// A wrapped dense window's subscript companion, minted and declared beside
|
|
1096
1148
|
// the read that needed it (`denseRemainderCompanion`). WHICH accesses a
|
|
1097
1149
|
// window admits is `admitDenseWindows`' prepass answer; this is only what
|