@geastack/compiler 1.0.43 → 1.0.45
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/dist/cli.js +8 -2
- package/dist/ir/callable-class-flow.js +87 -29
- package/dist/ir/construction-only-fields.d.ts +1 -1
- package/dist/ir/construction-only-fields.js +3 -1
- package/dist/ir/lower-operands.js +6 -1
- package/dist/ir/native-callable-data-owner.js +13 -1
- package/dist/ir/native-callable-data-write.d.ts +0 -4
- package/dist/ir/native-callable-data-write.js +9 -0
- package/dist/ir/shake.js +21 -0
- package/dist/semantics/frontend.js +18 -14
- package/dist/semantics/normalize/field-bindings.d.ts +2 -0
- package/dist/semantics/normalize/field-bindings.js +669 -13
- package/dist/semantics/normalize/flow/component-solver.js +37 -2
- package/dist/semantics/normalize/flow/source-value-session.d.ts +3 -0
- package/dist/semantics/normalize/flow/source-value-session.js +343 -138
- package/dist/semantics/normalize/global-host-mutations.js +14 -6
- package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +11 -10
- package/dist/semantics/normalize/implicit-arguments-tuple.js +15 -3
- package/dist/semantics/normalize/parameter-bindings.js +18 -0
- package/dist/semantics/normalize/producers/object-assignment.js +7 -1
- package/dist/semantics/normalize/stated-dynamic-value.d.ts +11 -0
- package/dist/semantics/normalize/stated-dynamic-value.js +36 -0
- package/dist/semantics/normalize/structural-mutable-method.js +88 -2
- package/dist/targets/cpp/borrowed-call-entry.d.ts +41 -2
- package/dist/targets/cpp/borrowed-call-entry.js +91 -6
- package/dist/targets/cpp/emit-callable.js +62 -29
- package/dist/targets/cpp/emit.js +106 -10
- package/dist/targets/cpp/host/emit-host-object.js +69 -2
- package/dist/targets/cpp/records.d.ts +1 -0
- package/dist/targets/cpp/records.js +1 -1
- package/dist/targets/cpp/translation-unit.js +59 -22
- package/dist/targets/cpp/virtual-methods.js +9 -4
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +121 -0
- package/src/targets/cpp/runtime/gea_runtime.h +218 -28
package/dist/cli.js
CHANGED
|
@@ -10,15 +10,21 @@ import { preflightReportLines } from './preflight/report.js';
|
|
|
10
10
|
import { structuralShapeKey } from './semantics/model/structural-types.js';
|
|
11
11
|
import { closeSync, openSync, writeSync } from 'node:fs';
|
|
12
12
|
import { dirname } from 'node:path';
|
|
13
|
-
import { setFlagsFromString } from 'node:v8';
|
|
13
|
+
import { getHeapStatistics, setFlagsFromString } from 'node:v8';
|
|
14
14
|
// V8 grows the heap after each collection by up to four times what survived
|
|
15
15
|
// it, bounded only by the old-space limit -- which builds raise to 32 GB so a
|
|
16
16
|
// large program cannot fail on the default. A compile allocates fast and keeps
|
|
17
17
|
// a few GB live, so with that headroom a large app's compile held 15.8 GB of
|
|
18
18
|
// resident memory for 3.3 GB of live data. A 25% margin bounded it at 4.6 GB
|
|
19
19
|
// for 9% more wall time. A caller that states its own percentage keeps it.
|
|
20
|
+
//
|
|
21
|
+
// The margin is only for a heap that limit leaves unbounded. A process given a
|
|
22
|
+
// few gigabytes is bounded by them already, and a 25% margin under them only
|
|
23
|
+
// makes it collect more often: a large three.js program compiling under a 4 GB
|
|
24
|
+
// heap took 5% longer with it (406 s against 387 s) and peaked 0.5 GB lower.
|
|
20
25
|
const statedGrowth = [...process.execArgv, ...(process.env['NODE_OPTIONS'] ?? '').split(/\s+/)].some((flag) => /^--heap[-_]growing[-_]percent/.test(flag));
|
|
21
|
-
|
|
26
|
+
const boundedHeap = getHeapStatistics().heap_size_limit <= 8 * 1024 * 1024 * 1024;
|
|
27
|
+
if (!statedGrowth && !boundedHeap)
|
|
22
28
|
setFlagsFromString('--heap-growing-percent=25');
|
|
23
29
|
/**
|
|
24
30
|
* `--project <tsconfig.json>` names the project explicitly; `--no-project`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getHeapStatistics } from 'node:v8';
|
|
1
2
|
import { nativeBodyIgnoresLogicalReceiver } from './native-logical-receiver-body.js';
|
|
2
3
|
import { nativeConstructorMethodBodiesOf } from './native-constructor-reads.js';
|
|
3
4
|
import { classLayoutOfCopy, classLayoutsConstructedBy, constructedBaseOf } from '../projection/classes.js';
|
|
@@ -255,9 +256,12 @@ class ValueTable {
|
|
|
255
256
|
ordinal = ordinal * 10 + digit;
|
|
256
257
|
}
|
|
257
258
|
this.ordinal = ordinal;
|
|
258
|
-
|
|
259
|
-
|
|
259
|
+
// The body spelled out and compared whole: `id.startsWith(this.lastBody, 4)`
|
|
260
|
+
// asks the same, but took about eight times as long on these long ids, and
|
|
261
|
+
// this is asked millions of times a solve.
|
|
260
262
|
const body = id.slice(4, bar);
|
|
263
|
+
if (this.lastSlots !== null && body === this.lastBody)
|
|
264
|
+
return this.lastSlots;
|
|
261
265
|
let slots = this.byBody.get(body);
|
|
262
266
|
if (slots === undefined) {
|
|
263
267
|
if (!create)
|
|
@@ -577,7 +581,22 @@ const ownedOperationKinds = new Set([
|
|
|
577
581
|
'return',
|
|
578
582
|
'super-initialize'
|
|
579
583
|
]);
|
|
580
|
-
|
|
584
|
+
/**
|
|
585
|
+
* The conversion nodes whose field views the solve installs: the ones the
|
|
586
|
+
* bodies cite, the program-level recipes', and everything they reach. This is
|
|
587
|
+
* the only thing the solve reads of `programConversions` (`nativeCallableFlowOf`).
|
|
588
|
+
*/
|
|
589
|
+
const flowViewNodesOf = (bodies, conversions, programConversions) => {
|
|
590
|
+
const citedViewNodes = bodies
|
|
591
|
+
.flatMap((body) => nativeFieldViewBodyCitationsOf(body).map((id) => conversions?.nodeById(id)))
|
|
592
|
+
.filter((node) => node !== null && node !== undefined);
|
|
593
|
+
for (const recipe of programConversions ?? [])
|
|
594
|
+
if (conversions?.nodeById(recipe.conversion.id) === recipe.conversion)
|
|
595
|
+
citedViewNodes.push(recipe.conversion);
|
|
596
|
+
return [...recipeClosureOf(citedViewNodes, conversions?.nodeById).values()];
|
|
597
|
+
};
|
|
598
|
+
const computeNativeCallableFlow = (bodies, placements, classes, conversions, trace, deriver, programConversions, constructionTopology) => solveNativeCallableFlow(flowViewNodesOf(bodies, conversions, programConversions), bodies, placements, classes, conversions, trace, deriver, constructionTopology);
|
|
599
|
+
const solveNativeCallableFlow = (viewNodes, bodies, placements, classes, conversions, trace, deriver, constructionTopology) => {
|
|
581
600
|
const propertyLayoutCache = new Map();
|
|
582
601
|
const nativePropertyLayoutOf = (representation) => hasNativePropertyLayout(representation, deriver ?? null, classes, new Set(), propertyLayoutCache);
|
|
583
602
|
const cells = [];
|
|
@@ -865,13 +884,6 @@ const computeNativeCallableFlow = (bodies, placements, classes, conversions, tra
|
|
|
865
884
|
}
|
|
866
885
|
return [...found];
|
|
867
886
|
};
|
|
868
|
-
const citedViewNodes = bodies
|
|
869
|
-
.flatMap((body) => nativeFieldViewBodyCitationsOf(body).map((id) => conversions?.nodeById(id)))
|
|
870
|
-
.filter((node) => node !== null && node !== undefined);
|
|
871
|
-
for (const recipe of programConversions ?? [])
|
|
872
|
-
if (conversions?.nodeById(recipe.conversion.id) === recipe.conversion)
|
|
873
|
-
citedViewNodes.push(recipe.conversion);
|
|
874
|
-
const viewNodes = [...recipeClosureOf(citedViewNodes, conversions?.nodeById).values()];
|
|
875
887
|
const viewShapes = new Set(nativeFieldViewPlansOf(viewNodes).map((plan) => plan.target.shapeId));
|
|
876
888
|
const viewMethodFields = new Map();
|
|
877
889
|
for (const node of viewNodes) {
|
|
@@ -3395,31 +3407,34 @@ const repointed = (value, pairs, seen, fresh) => {
|
|
|
3395
3407
|
const partner = pairs.get(value);
|
|
3396
3408
|
if (partner !== undefined)
|
|
3397
3409
|
return partner;
|
|
3398
|
-
if (fresh.objects.has(value))
|
|
3399
|
-
fresh.reached = true;
|
|
3400
3410
|
if (seen.has(value))
|
|
3401
3411
|
return seen.get(value);
|
|
3412
|
+
// An object the new program holds that this answer allocated (`flowOverCopy`):
|
|
3413
|
+
// copied when asked to, so the answer holds its own as a solve's would.
|
|
3414
|
+
const copied = fresh.objects.has(value);
|
|
3415
|
+
if (copied && !fresh.copy)
|
|
3416
|
+
fresh.reached = true;
|
|
3402
3417
|
seen.set(value, value);
|
|
3403
3418
|
let result = value;
|
|
3404
3419
|
if (Array.isArray(value)) {
|
|
3405
3420
|
const items = value.map((item) => repointed(item, pairs, seen, fresh));
|
|
3406
|
-
if (items.some((item, index) => item !== value[index]))
|
|
3421
|
+
if (copied || items.some((item, index) => item !== value[index]))
|
|
3407
3422
|
result = items;
|
|
3408
3423
|
}
|
|
3409
3424
|
else if (value instanceof Map) {
|
|
3410
3425
|
const entries = [...value].map(([key, item]) => [repointed(key, pairs, seen, fresh), repointed(item, pairs, seen, fresh)]);
|
|
3411
|
-
if ([...value].some(([key, item], index) => entries[index][0] !== key || entries[index][1] !== item))
|
|
3426
|
+
if (copied || [...value].some(([key, item], index) => entries[index][0] !== key || entries[index][1] !== item))
|
|
3412
3427
|
result = new Map(entries);
|
|
3413
3428
|
}
|
|
3414
3429
|
else if (value instanceof Set) {
|
|
3415
3430
|
const items = [...value].map((item) => repointed(item, pairs, seen, fresh));
|
|
3416
|
-
if ([...value].some((item, index) => items[index] !== item))
|
|
3431
|
+
if (copied || [...value].some((item, index) => items[index] !== item))
|
|
3417
3432
|
result = new Set(items);
|
|
3418
3433
|
}
|
|
3419
3434
|
else {
|
|
3420
3435
|
const prototype = Object.getPrototypeOf(value);
|
|
3421
3436
|
if (prototype === Object.prototype || prototype === null) {
|
|
3422
|
-
let copy = null;
|
|
3437
|
+
let copy = copied ? { ...value } : null;
|
|
3423
3438
|
for (const key of Object.keys(value)) {
|
|
3424
3439
|
const item = value[key];
|
|
3425
3440
|
const moved = repointed(item, pairs, seen, fresh);
|
|
@@ -3429,6 +3444,8 @@ const repointed = (value, pairs, seen, fresh) => {
|
|
|
3429
3444
|
if (copy !== null)
|
|
3430
3445
|
result = copy;
|
|
3431
3446
|
}
|
|
3447
|
+
else if (copied)
|
|
3448
|
+
fresh.reached = true;
|
|
3432
3449
|
}
|
|
3433
3450
|
seen.set(value, result);
|
|
3434
3451
|
return result;
|
|
@@ -3437,9 +3454,9 @@ const repointed = (value, pairs, seen, fresh) => {
|
|
|
3437
3454
|
* A remembered answer re-pointed from the program it was solved over to a
|
|
3438
3455
|
* same-data copy of it, or null when it cannot stand for a solve of the copy.
|
|
3439
3456
|
*/
|
|
3440
|
-
const flowOverCopy = (flow, pairs) => {
|
|
3457
|
+
const flowOverCopy = (flow, pairs, copy = false) => {
|
|
3441
3458
|
const seen = new Map();
|
|
3442
|
-
const fresh = { objects: new Set(pairs.values()), reached: false };
|
|
3459
|
+
const fresh = { objects: new Set(pairs.values()), reached: false, copy };
|
|
3443
3460
|
const { nativeFieldViewAbsentRoutesOf: absentRoutesOf, callables, ...data } = flow;
|
|
3444
3461
|
const moved = repointed(data, pairs, seen, fresh);
|
|
3445
3462
|
// A solve allocates each callee identity afresh, and the dispatch passes then
|
|
@@ -3447,8 +3464,12 @@ const flowOverCopy = (flow, pairs) => {
|
|
|
3447
3464
|
// re-pointed: handed back as they are, the reused answer would share them
|
|
3448
3465
|
// with the bodies where a solve's never does.
|
|
3449
3466
|
const callees = new Map([...callables].map(([value, callee]) => [value, repointed({ ...callee }, pairs, seen, fresh)]));
|
|
3467
|
+
// An answer holding an object a pass wrote into the program after the solve
|
|
3468
|
+
// is re-pointed once more, copying each such object: a solve of the new
|
|
3469
|
+
// program would allocate its own, equal to the copy and shared with
|
|
3470
|
+
// nothing. Only a plain object, array, map or set can be copied.
|
|
3450
3471
|
if (fresh.reached)
|
|
3451
|
-
return null;
|
|
3472
|
+
return copy ? null : flowOverCopy(flow, pairs, true);
|
|
3452
3473
|
const answer = { ...moved, callables: callees };
|
|
3453
3474
|
if (absentRoutesOf === undefined)
|
|
3454
3475
|
return answer;
|
|
@@ -3609,7 +3630,12 @@ const releasePropagation = (cells) => {
|
|
|
3609
3630
|
}
|
|
3610
3631
|
}
|
|
3611
3632
|
};
|
|
3612
|
-
|
|
3633
|
+
// `id.substring(...) === owner` rather than `id.startsWith(owner, 4)`: the same
|
|
3634
|
+
// question, several times faster for a long owner (see `ValueTable.slotsOf`).
|
|
3635
|
+
const valueOwnedBy = (id, owner) => id.startsWith('ssa|') &&
|
|
3636
|
+
id.substring(4, 4 + owner.length) === owner &&
|
|
3637
|
+
id.charCodeAt(4 + owner.length) === 124 &&
|
|
3638
|
+
id.indexOf('|', 5 + owner.length) === -1;
|
|
3613
3639
|
/**
|
|
3614
3640
|
* Every SSA value's carrier, read through the bodies rather than copied into
|
|
3615
3641
|
* one table: a table of the program's every value, built at the solve's end,
|
|
@@ -3692,6 +3718,8 @@ let rememberedClasses = null;
|
|
|
3692
3718
|
* other kind. A newer answer of the same kind replaces the older one, which
|
|
3693
3719
|
* was solved over an earlier body generation and is only ever a worse match.
|
|
3694
3720
|
*/
|
|
3721
|
+
/** The heap limit from which a solve keeps the other kind's remembered answer (`nativeCallableFlowOf`). */
|
|
3722
|
+
const KEEP_OTHER_KIND_HEAP = 3 * 1024 * 1024 * 1024;
|
|
3695
3723
|
const flowKindOf = (programConversions, constructionTopology) => (programConversions == null ? 0 : 1) + (constructionTopology == null ? 0 : 2);
|
|
3696
3724
|
export const nativeCallableFlowOf = (...args) => {
|
|
3697
3725
|
const [bodies, placements, classes, conversions, trace, deriver, programConversions, constructionTopology] = args;
|
|
@@ -3707,7 +3735,11 @@ export const nativeCallableFlowOf = (...args) => {
|
|
|
3707
3735
|
if (held === undefined)
|
|
3708
3736
|
rememberedFlows.set(classes, (held = []));
|
|
3709
3737
|
const entries = held;
|
|
3710
|
-
|
|
3738
|
+
// The request's view nodes, built once and only when an answer is solved or a
|
|
3739
|
+
// remembered one differs from it only in its program conversions.
|
|
3740
|
+
let requestViewNodes = null;
|
|
3741
|
+
const viewNodesOfRequest = () => (requestViewNodes ??= flowViewNodesOf(bodies, conversions, programConversions));
|
|
3742
|
+
const remember = (flow, replaced, viewNodes) => {
|
|
3711
3743
|
if (replaced !== -1)
|
|
3712
3744
|
entries.splice(replaced, 1);
|
|
3713
3745
|
const kind = flowKindOf(programConversions, constructionTopology);
|
|
@@ -3721,6 +3753,7 @@ export const nativeCallableFlowOf = (...args) => {
|
|
|
3721
3753
|
deriver: deriver ?? null,
|
|
3722
3754
|
programConversions: programConversions ?? null,
|
|
3723
3755
|
constructionTopology: constructionTopology ?? null,
|
|
3756
|
+
viewNodes,
|
|
3724
3757
|
flow
|
|
3725
3758
|
});
|
|
3726
3759
|
return flow;
|
|
@@ -3745,15 +3778,23 @@ export const nativeCallableFlowOf = (...args) => {
|
|
|
3745
3778
|
(entry.programConversions === null) !== (programConversions === undefined) ||
|
|
3746
3779
|
(entry.constructionTopology === null) !== (constructionTopology === undefined))
|
|
3747
3780
|
continue;
|
|
3748
|
-
|
|
3749
|
-
if (!pairSameData(entry.bodies, bodies, pairs)
|
|
3750
|
-
|
|
3751
|
-
|
|
3781
|
+
let pairs = new Map();
|
|
3782
|
+
if (!pairSameData(entry.bodies, bodies, pairs))
|
|
3783
|
+
continue;
|
|
3784
|
+
// Program conversions reach the answer only through its view nodes
|
|
3785
|
+
// (`flowViewNodesOf`): recipes that differ but cite nodes already in the
|
|
3786
|
+
// closure leave the very same view nodes, and so the same answer.
|
|
3787
|
+
const withConversions = new Map(pairs);
|
|
3788
|
+
if (pairSameData(entry.programConversions, programConversions ?? null, withConversions))
|
|
3789
|
+
pairs = withConversions;
|
|
3790
|
+
else if (!sameNodeSequence(entry.viewNodes, viewNodesOfRequest()))
|
|
3791
|
+
continue;
|
|
3792
|
+
if (!pairSameData(entry.constructionTopology, constructionTopology ?? null, pairs))
|
|
3752
3793
|
continue;
|
|
3753
3794
|
const reused = flowOverCopy(entry.flow, pairs);
|
|
3754
3795
|
if (reused === null)
|
|
3755
3796
|
continue;
|
|
3756
|
-
return remember(reused, index);
|
|
3797
|
+
return remember(reused, index, entry.viewNodes);
|
|
3757
3798
|
}
|
|
3758
3799
|
return null;
|
|
3759
3800
|
})();
|
|
@@ -3765,9 +3806,26 @@ export const nativeCallableFlowOf = (...args) => {
|
|
|
3765
3806
|
// solve -- the compile's peak -- held beside its own state. An answer of the
|
|
3766
3807
|
// other kind is still reused when no solve comes between, which is most
|
|
3767
3808
|
// reuses; on a large program two more are solved.
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3809
|
+
//
|
|
3810
|
+
// Unless the heap is large enough to hold it: then only this kind's answer
|
|
3811
|
+
// goes, and the other kind's is kept for when the program comes back to it.
|
|
3812
|
+
// A large three.js program under a 4 GB heap asks again, after a solve of
|
|
3813
|
+
// the other kind, for the same data it last asked for of its own kind, and
|
|
3814
|
+
// each was a solve of several seconds. The choice follows the heap the
|
|
3815
|
+
// process was given, never what it holds at the moment: a reuse is the same
|
|
3816
|
+
// data either way, so it changes no answer.
|
|
3817
|
+
if (getHeapStatistics().heap_size_limit < KEEP_OTHER_KIND_HEAP)
|
|
3818
|
+
entries.length = 0;
|
|
3819
|
+
else {
|
|
3820
|
+
const kind = flowKindOf(programConversions, constructionTopology);
|
|
3821
|
+
for (let index = entries.length - 1; index >= 0; index--)
|
|
3822
|
+
if (flowKindOf(entries[index].programConversions, entries[index].constructionTopology) === kind)
|
|
3823
|
+
entries.splice(index, 1);
|
|
3824
|
+
}
|
|
3825
|
+
const viewNodes = viewNodesOfRequest();
|
|
3826
|
+
const flow = solveNativeCallableFlow(viewNodes, bodies, placements, classes, conversions, undefined, deriver, constructionTopology);
|
|
3827
|
+
return remember(flow, -1, viewNodes);
|
|
3771
3828
|
};
|
|
3829
|
+
const sameNodeSequence = (left, right) => left === right || (left.length === right.length && left.every((node, index) => node === right[index]));
|
|
3772
3830
|
/** Compatibility view of the same execution/escape census; no second analysis policy. */
|
|
3773
3831
|
export const closedClassFieldCallablesOf = (...args) => nativeCallableFlowOf(...args).callables;
|
|
@@ -89,7 +89,7 @@ export declare const stableReceiversOf: (body: IrBody, receivers: ReadonlySet<Ir
|
|
|
89
89
|
*/
|
|
90
90
|
export declare const stableFieldReadsOf: (body: IrBody, receivers: ReadonlySet<IrValueId>, fields: ConstructionOnlyFields, integrity: {
|
|
91
91
|
readonly restricts: (representation: Representation) => boolean;
|
|
92
|
-
}, dying: ReadonlySet<IrValueId>) => ReadonlySet<IrValueId>;
|
|
92
|
+
}, dying: Pick<ReadonlySet<IrValueId>, "has">) => ReadonlySet<IrValueId>;
|
|
93
93
|
/**
|
|
94
94
|
* Cells that may name the stable field read they are initialized with,
|
|
95
95
|
* instead of holding a counted copy of it.
|
|
@@ -385,7 +385,9 @@ export const stableFieldReadsAndCellsOf = (body, receivers, fields, integrity, d
|
|
|
385
385
|
written.set(operation.value.value, operation.declaration);
|
|
386
386
|
}
|
|
387
387
|
const intoCell = (value) => written.has(value) && uses.get(value) === 1;
|
|
388
|
-
|
|
388
|
+
// Asked of this body's values only, so the program's whole dying set is
|
|
389
|
+
// filtered as it is asked, not copied for every body rendered.
|
|
390
|
+
const candidates = stableFieldReadsOf(body, receivers, fields, integrity, { has: (value) => dying.has(value) && !intoCell(value) });
|
|
389
391
|
const cells = stableFieldCellsOf(body, candidates, admits);
|
|
390
392
|
const all = new Set(reads);
|
|
391
393
|
for (const value of candidates) {
|
|
@@ -1175,7 +1175,12 @@ export const packRestArguments = (ctx, block, lineage, operation, abi, passed) =
|
|
|
1175
1175
|
throw new IrLoweringBlockedError(`a tuple-shaped rest slot's required field ${index} has no matching trailing argument`);
|
|
1176
1176
|
return [];
|
|
1177
1177
|
}
|
|
1178
|
-
|
|
1178
|
+
// Converted here, as a packed array's element is below: a position
|
|
1179
|
+
// several call forms fill (a number in one, an image source in another)
|
|
1180
|
+
// carries their join, and the record's store is not where a conversion
|
|
1181
|
+
// into it can be certified.
|
|
1182
|
+
const actual = packingValueOf(entry);
|
|
1183
|
+
return [{ key: field.key, value: convertTo(ctx, block, lineage, actual, field.value) ?? actual }];
|
|
1179
1184
|
});
|
|
1180
1185
|
const packed = ctx.builder.allocateRecord(block, lineage, fields, slot.value);
|
|
1181
1186
|
return [...args.slice(0, abi.restFrom).map((entry) => entry.value), { value: packed, representation: slot.value }];
|
|
@@ -752,4 +752,16 @@ const createOwnerAuthority = (input, observedOperations) => {
|
|
|
752
752
|
}
|
|
753
753
|
};
|
|
754
754
|
};
|
|
755
|
-
|
|
755
|
+
/**
|
|
756
|
+
* One authority per input object: the slot discovery, its optional reads and
|
|
757
|
+
* the write census each asked for one over the same input within a single
|
|
758
|
+
* publication or certification, and each built the program-wide tables again.
|
|
759
|
+
* The authority is a function of the input alone, which nothing mutates.
|
|
760
|
+
*/
|
|
761
|
+
const ownerAuthorities = new WeakMap();
|
|
762
|
+
export const nativeCallableDataOwnerAuthorityOf = (input) => {
|
|
763
|
+
let authority = ownerAuthorities.get(input);
|
|
764
|
+
if (authority === undefined)
|
|
765
|
+
ownerAuthorities.set(input, (authority = createOwnerAuthority(input)));
|
|
766
|
+
return authority;
|
|
767
|
+
};
|
|
@@ -50,9 +50,5 @@ export interface NativeCallableDataWriteInput {
|
|
|
50
50
|
readonly callableFlow: NativeCallableFlow;
|
|
51
51
|
readonly nativeCallableData: NativeCallableDataPlan;
|
|
52
52
|
}
|
|
53
|
-
/** Actual evaluated operands, rather than a signature or source key spelling,
|
|
54
|
-
* authenticate a native write. The ordinary descriptor engine retains setter,
|
|
55
|
-
* inherited writable, extensibility and strict-assignment effects.
|
|
56
|
-
*/
|
|
57
53
|
export declare const nativeCallableDataWritesOf: (input: NativeCallableDataWriteInput) => ReadonlyMap<IrOperation, NativeCallableDataWrite>;
|
|
58
54
|
export declare const nativeCallableDataWriteMatches: (expected: NativeCallableDataWrite | undefined, actual: NativeCallableDataWrite | undefined) => boolean;
|
|
@@ -20,7 +20,16 @@ const supportedPayload = (value, callable = false) => value.kind === 'optional'
|
|
|
20
20
|
* authenticate a native write. The ordinary descriptor engine retains setter,
|
|
21
21
|
* inherited writable, extensibility and strict-assignment effects.
|
|
22
22
|
*/
|
|
23
|
+
// One census per input object (`nativeCallableDataOwnerAuthorityOf`): slot
|
|
24
|
+
// discovery's optional reads and its publication each asked for it again.
|
|
25
|
+
const writeCensuses = new WeakMap();
|
|
23
26
|
export const nativeCallableDataWritesOf = (input) => {
|
|
27
|
+
let census = writeCensuses.get(input);
|
|
28
|
+
if (census === undefined)
|
|
29
|
+
writeCensuses.set(input, (census = nativeCallableDataWritesUncached(input)));
|
|
30
|
+
return census;
|
|
31
|
+
};
|
|
32
|
+
const nativeCallableDataWritesUncached = (input) => {
|
|
24
33
|
const owners = nativeCallableDataOwnerAuthorityOf(input);
|
|
25
34
|
const definitions = new Map();
|
|
26
35
|
const operations = [];
|
package/dist/ir/shake.js
CHANGED
|
@@ -6,6 +6,7 @@ import { nativeCallableFlowOf } from './callable-class-flow.js';
|
|
|
6
6
|
import { allOperationsOf } from './model.js';
|
|
7
7
|
import { arrayAllocationDrainsDynamicIterator, operandsOfIrOperation, resultOfIrOperation } from './queries.js';
|
|
8
8
|
import { verifyIrBody } from './verify.js';
|
|
9
|
+
import { hostTemplateMemberOf } from './host-template-conversions.js';
|
|
9
10
|
/**
|
|
10
11
|
* Whether a carrier can put user code on the path of an otherwise arithmetic
|
|
11
12
|
* operation.
|
|
@@ -412,6 +413,26 @@ const sliceBody = (body, placements, liveCells, structuralViewScopes) => {
|
|
|
412
413
|
}
|
|
413
414
|
}
|
|
414
415
|
}
|
|
416
|
+
// `Object.values(x)`, `Object.entries(x)` and `Object.assign(t, x)` read
|
|
417
|
+
// every own field of `x` without spelling a key and without lowering to
|
|
418
|
+
// `own-property-keys`: they are host calls. Missed here, a field only
|
|
419
|
+
// ever observed through one of them had its initializer pruned, and the
|
|
420
|
+
// walk read the struct's default-constructed slot (`''`, `0`) instead.
|
|
421
|
+
if (operation.kind === 'call') {
|
|
422
|
+
const host = hostTemplateMemberOf(operation, (value) => definitions.get(value) ?? null);
|
|
423
|
+
if (host?.protocol === 'ObjectConstructor') {
|
|
424
|
+
const walked = host.member === 'values' || host.member === 'entries' || host.member === 'getOwnPropertyDescriptors'
|
|
425
|
+
? operation.arguments.slice(0, 1)
|
|
426
|
+
: host.member === 'assign'
|
|
427
|
+
? operation.arguments.slice(1)
|
|
428
|
+
: [];
|
|
429
|
+
if (operation.argumentsAreSpread && walked.length > 0)
|
|
430
|
+
fieldHazardScopes.add(anyClassScope);
|
|
431
|
+
for (const argument of walked)
|
|
432
|
+
for (const scope of receiverClassScopes(argument.representation, structuralViewScopes))
|
|
433
|
+
fieldHazardScopes.add(scope);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
415
436
|
// OrdinaryToPrimitive invokes `toString`/`valueOf` without an explicit
|
|
416
437
|
// property operation. Root those protocol members on the carrier being
|
|
417
438
|
// coerced, rather than keeping same-named methods on every class in the
|
|
@@ -625,14 +625,20 @@ export const runFrontend = (input) => {
|
|
|
625
625
|
// consumers now also see one set of write and call-site objects instead
|
|
626
626
|
// of two that are equal only field by field.
|
|
627
627
|
const valueFlow = contentEqual ? { ...contentEqual } : built;
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
//
|
|
631
|
-
//
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
628
|
+
if (contentEqual)
|
|
629
|
+
shareSourceValueSession(contentEqual, valueFlow);
|
|
630
|
+
// No round's solver is retired when the next round replaces it. Every
|
|
631
|
+
// round's census stays on the `upstream` chain of every later one, down
|
|
632
|
+
// to the settled census the structural censuses read, and a question it
|
|
633
|
+
// cannot answer itself falls through to an earlier round's census and
|
|
634
|
+
// that round's session. A retired session answers by solving the whole
|
|
635
|
+
// program again from nothing, and the rebuilt solver then lives as long
|
|
636
|
+
// as its index does: on a large three.js program the second round rebuilt
|
|
637
|
+
// the first round's solver and the structural censuses rebuilt the second
|
|
638
|
+
// and third rounds', three full solves (about a third of the frontend)
|
|
639
|
+
// to reach the very heap that keeping them reaches. The final round's
|
|
640
|
+
// solver is still released once the producers are done (`produced`
|
|
641
|
+
// below); an earlier one lives as long as its index, as a rebuilt one did.
|
|
636
642
|
roundFlows.push(valueFlow);
|
|
637
643
|
attachDeferredIntrinsicProtocolLedger(valueFlow, intrinsicProtocols);
|
|
638
644
|
commonJsModuleRecords.attachToFlow(valueFlow);
|
|
@@ -1436,10 +1442,9 @@ export const runFrontend = (input) => {
|
|
|
1436
1442
|
// mappers all agree on what "the same copy" means.
|
|
1437
1443
|
copyKey: (candidate) => identities.copyKeyOf(candidate.specialization),
|
|
1438
1444
|
// The final round's solver answers the producers and nothing after them.
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
},
|
|
1445
|
+
// Only the final round's: an earlier one stays as long as its index, as
|
|
1446
|
+
// it did when the structural censuses rebuilt it.
|
|
1447
|
+
produced: () => retireSourceValueSession(roundFlows[roundFlows.length - 1]),
|
|
1443
1448
|
gates: (operations) => gatingEdges({
|
|
1444
1449
|
files: compiled.sourceFiles,
|
|
1445
1450
|
identities,
|
|
@@ -1472,8 +1477,7 @@ export const runFrontend = (input) => {
|
|
|
1472
1477
|
const identity = fileIdentities.get(file.fileName);
|
|
1473
1478
|
return identity === undefined ? [] : [[identity, file]];
|
|
1474
1479
|
}));
|
|
1475
|
-
|
|
1476
|
-
retireSourceValueSession(flow);
|
|
1480
|
+
retireSourceValueSession(roundFlows[roundFlows.length - 1]);
|
|
1477
1481
|
return {
|
|
1478
1482
|
dynamicFallbackTypes,
|
|
1479
1483
|
dynamicWrittenTypes,
|
|
@@ -123,6 +123,8 @@ export interface FieldBindingCensus {
|
|
|
123
123
|
readonly statedTypeAt: (node: ts.Node) => ts.Type | null;
|
|
124
124
|
/** How many field symbols this census bound, for measurement. */
|
|
125
125
|
readonly boundCount: number;
|
|
126
|
+
/** How many unstated fields this census widened to `any` because a write stores a value nothing types -- see `widenDynamicallyWrittenFields`. */
|
|
127
|
+
readonly widenedCount: number;
|
|
126
128
|
/**
|
|
127
129
|
* Every field symbol this census could not bind, one `CensusRefusal` each --
|
|
128
130
|
* the owner is what makes this a list something downstream can act on,
|