@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
|
@@ -67,15 +67,14 @@ class QueryState extends FactState {
|
|
|
67
67
|
get root() {
|
|
68
68
|
return typeof this.first === 'object' ? undefined : this.second;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The computed writes whose receiver this query is. Held on the state
|
|
72
|
+
* rather than in a session map: `hasUnnamedWrite` and `computedWriteNames`
|
|
73
|
+
* ask it of every holder of a root, often thousands, and almost every
|
|
74
|
+
* answer is none -- a field read where a map lookup was most of their time.
|
|
75
|
+
*/
|
|
76
|
+
computedWriteEdges = undefined;
|
|
70
77
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Walk two lists as one without building a third.
|
|
73
|
-
*
|
|
74
|
-
* Every caller is inside a transfer, and a transfer runs once per
|
|
75
|
-
* re-evaluation of its node -- so a spread that reads as a convenience is an
|
|
76
|
-
* allocation and a copy priced per transfer, not per program.
|
|
77
|
-
*/
|
|
78
|
-
const both = (first, second) => first === undefined || first.length === 0 ? second : second.length === 0 ? first : [...first, ...second];
|
|
79
78
|
const refusalDebug = process.env['GEA_SESSION_REFUSALS'] !== undefined;
|
|
80
79
|
/** The query kinds whose facts are values and therefore need a grounding witness. */
|
|
81
80
|
const VALUE_CARRYING_KINDS = new Set([
|
|
@@ -105,6 +104,8 @@ const VALUE_ORIGIN = 'source-value-origin';
|
|
|
105
104
|
const VALUE_ORIGIN_DOMAIN = [VALUE_ORIGIN];
|
|
106
105
|
const NO_DOMAINS = [];
|
|
107
106
|
const NO_CAUSES = [];
|
|
107
|
+
const NO_ITERATION_WRITES = [];
|
|
108
|
+
const WIP_SOLVER_BASE = process.env['GEA_SOLVER_AB'] === 'base'; // WIP-SOLVER-TIMING: not for commit
|
|
108
109
|
const CARRIES_VALUE = 1;
|
|
109
110
|
const SEEDED = 2;
|
|
110
111
|
/**
|
|
@@ -294,6 +295,17 @@ const internIn = (outer, owner, key, keyOf, make) => {
|
|
|
294
295
|
};
|
|
295
296
|
const frameSubjectOf = (query) => query.subject;
|
|
296
297
|
const keyedQueryKey = (query) => query.key;
|
|
298
|
+
/** How many entries a holder answer has: its length or size when it carries one, which nearly every answer does. */
|
|
299
|
+
const iterableCount = (entries) => {
|
|
300
|
+
if (Array.isArray(entries))
|
|
301
|
+
return entries.length;
|
|
302
|
+
if (entries instanceof Set)
|
|
303
|
+
return entries.size;
|
|
304
|
+
let count = 0;
|
|
305
|
+
for (const _entry of entries)
|
|
306
|
+
count++;
|
|
307
|
+
return count;
|
|
308
|
+
};
|
|
297
309
|
const createSession = (checker, flow) => {
|
|
298
310
|
const isFreshOrdinaryObject = (node) => sourceFreshOrdinaryObjectOf(checker, node);
|
|
299
311
|
const isObjectRoot = (node) => isSpelledObjectRoot(node) || isFreshOrdinaryObject(node);
|
|
@@ -475,7 +487,7 @@ const createSession = (checker, flow) => {
|
|
|
475
487
|
}
|
|
476
488
|
}
|
|
477
489
|
const nodeQuery = (kind, node) => {
|
|
478
|
-
let nodes = unary.get(kind);
|
|
490
|
+
let nodes = kind === 'value' ? valueQueries : unary.get(kind);
|
|
479
491
|
if (!nodes)
|
|
480
492
|
unary.set(kind, (nodes = new Map()));
|
|
481
493
|
let query = nodes.get(node);
|
|
@@ -483,6 +495,9 @@ const createSession = (checker, flow) => {
|
|
|
483
495
|
nodes.set(node, (query = new QueryState(kind, node, undefined, undefined)));
|
|
484
496
|
return query;
|
|
485
497
|
};
|
|
498
|
+
// The `value` table held apart from the others: it is asked for far more
|
|
499
|
+
// than every other kind together, and this skips the lookup that finds it.
|
|
500
|
+
const valueQueries = new Map();
|
|
486
501
|
const value = (expression) => nodeQuery('value', unwrapErasedExpression(expression));
|
|
487
502
|
const frameQuery = (kind, call, body, subject = null) => {
|
|
488
503
|
let calls = frameQueries.get(kind);
|
|
@@ -867,6 +882,17 @@ const createSession = (checker, flow) => {
|
|
|
867
882
|
*/
|
|
868
883
|
const namedWrites = new Map();
|
|
869
884
|
const computedWrites = [];
|
|
885
|
+
/**
|
|
886
|
+
* The same writes, already resolved to the query that answers what their
|
|
887
|
+
* receiver holds.
|
|
888
|
+
*
|
|
889
|
+
* `value(access.expression)` is `unwrapErasedExpression` plus an interning
|
|
890
|
+
* lookup, and the answer is a property of the syntax: it cannot change. Asked
|
|
891
|
+
* per edge read it was a third of a large program's compile -- split
|
|
892
|
+
* between `nodeQuery` and `unwrapErased` -- for a value computed once and then recomputed
|
|
893
|
+
* millions of times. Resolving it with the index costs one pass over the
|
|
894
|
+
* writes and leaves the observation itself as the only per-edge work.
|
|
895
|
+
*/
|
|
870
896
|
const namedWriteReceivers = new Map();
|
|
871
897
|
/** The receiver queries of every computed write, for `hasUnnamedWrite`'s reverse lookup. */
|
|
872
898
|
const computedWriteReceiverQueries = new Set();
|
|
@@ -885,6 +911,7 @@ const createSession = (checker, flow) => {
|
|
|
885
911
|
const edges = computedWriteEdgesByReceiver.get(edge.receiver) ?? [];
|
|
886
912
|
edges.push(edge);
|
|
887
913
|
computedWriteEdgesByReceiver.set(edge.receiver, edges);
|
|
914
|
+
edge.receiver.computedWriteEdges = edges;
|
|
888
915
|
}
|
|
889
916
|
else {
|
|
890
917
|
let entries = namedWrites.get(key);
|
|
@@ -1073,6 +1100,47 @@ const createSession = (checker, flow) => {
|
|
|
1073
1100
|
return query;
|
|
1074
1101
|
};
|
|
1075
1102
|
/** The cell holding the object a binding element takes apart, as a query. */
|
|
1103
|
+
/**
|
|
1104
|
+
* Each pattern read of a list beside its binding container, worked out once
|
|
1105
|
+
* per list: `key-uses` walks these lists on every re-evaluation of every
|
|
1106
|
+
* container, and re-deriving the same container per element per walk was a
|
|
1107
|
+
* measurable share of the solve.
|
|
1108
|
+
*/
|
|
1109
|
+
const patternContainers = new Map();
|
|
1110
|
+
const patternContainersOf = (reads) => {
|
|
1111
|
+
let paired = patternContainers.get(reads);
|
|
1112
|
+
if (paired === undefined)
|
|
1113
|
+
patternContainers.set(reads, (paired = reads.map((element) => [element, bindingContainer(element)])));
|
|
1114
|
+
return paired;
|
|
1115
|
+
};
|
|
1116
|
+
/**
|
|
1117
|
+
* The same pairs filed under their binding container: `key-uses` asks
|
|
1118
|
+
* `holdersOf` for the containers that hold the object, as `key-reads` does
|
|
1119
|
+
* for named reads, instead of `observe`-ing the container of every
|
|
1120
|
+
* destructuring read of the key in the program on every re-evaluation of
|
|
1121
|
+
* every object it can hold. Positions keep the list's order, which is the
|
|
1122
|
+
* order the scan this replaces visited them in.
|
|
1123
|
+
*/
|
|
1124
|
+
const patternReadsByContainer = new Map();
|
|
1125
|
+
const patternReadsByContainerOf = (reads) => {
|
|
1126
|
+
let byContainer = patternReadsByContainer.get(reads);
|
|
1127
|
+
if (byContainer !== undefined)
|
|
1128
|
+
return byContainer;
|
|
1129
|
+
patternReadsByContainer.set(reads, (byContainer = new Map()));
|
|
1130
|
+
const paired = patternContainersOf(reads);
|
|
1131
|
+
for (let position = 0; position < paired.length; position++) {
|
|
1132
|
+
const holder = paired[position][1];
|
|
1133
|
+
if (holder === null)
|
|
1134
|
+
continue;
|
|
1135
|
+
let positions = byContainer.get(holder);
|
|
1136
|
+
if (positions === undefined)
|
|
1137
|
+
byContainer.set(holder, (positions = []));
|
|
1138
|
+
positions.push(position);
|
|
1139
|
+
// Found by `holdersOf` only once it exists, as `key-reads` seeds its receivers.
|
|
1140
|
+
seed(holder);
|
|
1141
|
+
}
|
|
1142
|
+
return byContainer;
|
|
1143
|
+
};
|
|
1076
1144
|
const bindingContainer = (element) => {
|
|
1077
1145
|
const holder = element.parent.parent;
|
|
1078
1146
|
if (ts.isParameter(holder))
|
|
@@ -1693,7 +1761,41 @@ const createSession = (checker, flow) => {
|
|
|
1693
1761
|
// the discovered calls alone would be complete over an open caller set.
|
|
1694
1762
|
const callersOf = (owner) => nodeQuery('callers', owner);
|
|
1695
1763
|
/** The writes a `for...of` binding receives from, out of every write the program makes; asked by each array literal's element publication on every re-evaluation. */
|
|
1764
|
+
// Each held beside its source's interned value query: the loop that reads
|
|
1765
|
+
// them runs once per array-literal re-evaluation over every such write, and
|
|
1766
|
+
// unwrapping and interning the same source again each time was most of it.
|
|
1696
1767
|
let valueIterationWrites = null;
|
|
1768
|
+
/**
|
|
1769
|
+
* The same writes filed under their source's value query, so an array
|
|
1770
|
+
* literal asks `holdersOf` for the sources that hold it instead of
|
|
1771
|
+
* `observe`-ing every `for...of` source in the program. Positions keep
|
|
1772
|
+
* `valueIterationWrites`' order, the order the scan this replaces used.
|
|
1773
|
+
*/
|
|
1774
|
+
let valueIterationsBySource = null;
|
|
1775
|
+
const valueIterationsHolding = (container, holdersOf) => {
|
|
1776
|
+
const writes = (valueIterationWrites ??= flow.allWrites
|
|
1777
|
+
.filter((write) => write.iterationOrigin?.mode === 'values')
|
|
1778
|
+
.map((write) => [write, value(write.iterationOrigin.source)]));
|
|
1779
|
+
if (valueIterationsBySource === null) {
|
|
1780
|
+
valueIterationsBySource = new Map();
|
|
1781
|
+
for (let position = 0; position < writes.length; position++) {
|
|
1782
|
+
const source = writes[position][1];
|
|
1783
|
+
let positions = valueIterationsBySource.get(source);
|
|
1784
|
+
if (positions === undefined)
|
|
1785
|
+
valueIterationsBySource.set(source, (positions = []));
|
|
1786
|
+
positions.push(position);
|
|
1787
|
+
seed(source);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
const found = [];
|
|
1791
|
+
for (const holder of holdersOf(container))
|
|
1792
|
+
for (const position of valueIterationsBySource.get(holder) ?? NO_POSITIONS)
|
|
1793
|
+
found.push(position);
|
|
1794
|
+
if (found.length === 0)
|
|
1795
|
+
return NO_ITERATION_WRITES;
|
|
1796
|
+
found.sort((a, b) => a - b);
|
|
1797
|
+
return found.map((position) => writes[position]);
|
|
1798
|
+
};
|
|
1697
1799
|
/**
|
|
1698
1800
|
* The part of `case 'callers'` that no fact can move: which candidate sites
|
|
1699
1801
|
* are syntax-and-checker matches for `owner`. `new Factory( state )` on a
|
|
@@ -2001,14 +2103,17 @@ const createSession = (checker, flow) => {
|
|
|
2001
2103
|
const observe = (dependency) => tested(observeFrom(dependency));
|
|
2002
2104
|
const holdersOf = (fact) => {
|
|
2003
2105
|
const found = holdersOfFrom(fact);
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2106
|
+
// Counted, not copied: a holder collection only grows in the solver's
|
|
2107
|
+
// `index`, after the transfer asking has returned (the solver hands out
|
|
2108
|
+
// the live set on that same footing), so its size now is what this
|
|
2109
|
+
// transfer iterates. Copying every holder set to take its length was a
|
|
2110
|
+
// quarter of everything the solve allocated.
|
|
2111
|
+
if (inputs !== null)
|
|
2112
|
+
inputs.holders.push([fact, iterableCount(found)]);
|
|
2113
|
+
return found;
|
|
2009
2114
|
};
|
|
2010
2115
|
const causes = [];
|
|
2011
|
-
|
|
2116
|
+
let grounding = null;
|
|
2012
2117
|
const fail = (reason, node = query.node) => {
|
|
2013
2118
|
causes.push(causeOf(reason, node));
|
|
2014
2119
|
if (refusalDebug) {
|
|
@@ -2028,7 +2133,8 @@ const createSession = (checker, flow) => {
|
|
|
2028
2133
|
/** A required edge whose facts this transfer does not look at: an input of its answer's completeness only. */
|
|
2029
2134
|
const need = (dependency) => void required(dependency);
|
|
2030
2135
|
const carry = (dependency) => {
|
|
2031
|
-
|
|
2136
|
+
;
|
|
2137
|
+
(grounding ??= new Set()).add(dependency);
|
|
2032
2138
|
return read(dependency);
|
|
2033
2139
|
};
|
|
2034
2140
|
/**
|
|
@@ -2046,7 +2152,8 @@ const createSession = (checker, flow) => {
|
|
|
2046
2152
|
add(held);
|
|
2047
2153
|
};
|
|
2048
2154
|
const joinCarried = (dependency) => {
|
|
2049
|
-
|
|
2155
|
+
;
|
|
2156
|
+
(grounding ??= new Set()).add(dependency);
|
|
2050
2157
|
join(dependency);
|
|
2051
2158
|
};
|
|
2052
2159
|
/** `join(use(root, reference))`, without minting the node for a use that does nothing (`inertUse`). */
|
|
@@ -2196,28 +2303,32 @@ const createSession = (checker, flow) => {
|
|
|
2196
2303
|
* subscribes this node to the root's future holders exactly as the
|
|
2197
2304
|
* observe edges did, and the receivers are seeded below so each exists.
|
|
2198
2305
|
*/
|
|
2199
|
-
|
|
2306
|
+
// Created on first use, like the other per-transfer tables below: most
|
|
2307
|
+
// transfers never ask, and an empty table still allocates its buckets.
|
|
2308
|
+
let unknownKeys = null;
|
|
2200
2309
|
const holderStampLists = [];
|
|
2201
2310
|
const hasUnnamedWrite = (root) => {
|
|
2202
|
-
const known = unknownKeys
|
|
2311
|
+
const known = unknownKeys?.get(root);
|
|
2203
2312
|
if (known !== undefined)
|
|
2204
2313
|
return known;
|
|
2205
2314
|
let found = false;
|
|
2206
2315
|
let count = 0;
|
|
2207
2316
|
for (const holder of holdersOf(root)) {
|
|
2208
2317
|
count++;
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2318
|
+
const edges = holder.computedWriteEdges;
|
|
2319
|
+
if (edges !== undefined)
|
|
2320
|
+
for (const write of edges)
|
|
2321
|
+
if (keysOf(write.access).length === 0)
|
|
2322
|
+
found = true;
|
|
2212
2323
|
}
|
|
2213
2324
|
for (const stamps of holderStampLists)
|
|
2214
2325
|
stamps.push([root, count]);
|
|
2215
|
-
unknownKeys.set(root, found);
|
|
2326
|
+
(unknownKeys ??= new Map()).set(root, found);
|
|
2216
2327
|
return found;
|
|
2217
2328
|
};
|
|
2218
2329
|
/** Every cell a root has: what it spells, plus what was written into it. */
|
|
2219
|
-
|
|
2220
|
-
|
|
2330
|
+
let ownKeys = null;
|
|
2331
|
+
let activeOwnKeys = null;
|
|
2221
2332
|
const stampLists = [];
|
|
2222
2333
|
const watched = (dependency) => {
|
|
2223
2334
|
const held = observe(dependency);
|
|
@@ -2226,23 +2337,19 @@ const createSession = (checker, flow) => {
|
|
|
2226
2337
|
return held;
|
|
2227
2338
|
};
|
|
2228
2339
|
const holdersUnchanged = (stamps) => {
|
|
2229
|
-
for (const [root, count] of stamps)
|
|
2230
|
-
|
|
2231
|
-
for (const _holder of holdersOf(root))
|
|
2232
|
-
now++;
|
|
2233
|
-
if (now !== count)
|
|
2340
|
+
for (const [root, count] of stamps)
|
|
2341
|
+
if (iterableCount(holdersOf(root)) !== count)
|
|
2234
2342
|
return false;
|
|
2235
|
-
}
|
|
2236
2343
|
return true;
|
|
2237
2344
|
};
|
|
2238
2345
|
const ownKeysOf = (root) => {
|
|
2239
|
-
const known = ownKeys
|
|
2346
|
+
const known = ownKeys?.get(root);
|
|
2240
2347
|
if (known !== undefined)
|
|
2241
2348
|
return known;
|
|
2242
2349
|
// A bulk assign whose source's keys come back to this root -- two
|
|
2243
2350
|
// records merged into each other -- names no finite set on the way
|
|
2244
2351
|
// round; the re-entry is unknown, and only the outer answer is kept.
|
|
2245
|
-
if (activeOwnKeys
|
|
2352
|
+
if (activeOwnKeys?.has(root))
|
|
2246
2353
|
return null;
|
|
2247
2354
|
const kept = ownKeysAnswers?.get(root);
|
|
2248
2355
|
if (kept !== undefined && kept.stamps.every(([held, size]) => held.size === size) && holdersUnchanged(kept.holderStamps)) {
|
|
@@ -2255,17 +2362,18 @@ const createSession = (checker, flow) => {
|
|
|
2255
2362
|
// `holdersUnchanged`).
|
|
2256
2363
|
for (const [held] of kept.stamps)
|
|
2257
2364
|
tested(held);
|
|
2258
|
-
ownKeys.set(root, kept.keys);
|
|
2365
|
+
(ownKeys ??= new Map()).set(root, kept.keys);
|
|
2259
2366
|
return kept.keys;
|
|
2260
2367
|
}
|
|
2261
|
-
|
|
2368
|
+
;
|
|
2369
|
+
(activeOwnKeys ??= new Set()).add(root);
|
|
2262
2370
|
const stamps = [];
|
|
2263
2371
|
const holderStamps = [];
|
|
2264
2372
|
stampLists.push(stamps);
|
|
2265
2373
|
holderStampLists.push(holderStamps);
|
|
2266
2374
|
try {
|
|
2267
2375
|
const answer = ownKeysUncached(root);
|
|
2268
|
-
ownKeys.set(root, answer);
|
|
2376
|
+
(ownKeys ??= new Map()).set(root, answer);
|
|
2269
2377
|
if (ownKeysAnswers === null)
|
|
2270
2378
|
ownKeysAnswersByQuery.set(query, (ownKeysAnswers = new Map()));
|
|
2271
2379
|
ownKeysAnswers.set(root, { keys: answer, stamps, holderStamps });
|
|
@@ -2274,7 +2382,7 @@ const createSession = (checker, flow) => {
|
|
|
2274
2382
|
finally {
|
|
2275
2383
|
stampLists.pop();
|
|
2276
2384
|
holderStampLists.pop();
|
|
2277
|
-
activeOwnKeys
|
|
2385
|
+
activeOwnKeys?.delete(root);
|
|
2278
2386
|
}
|
|
2279
2387
|
};
|
|
2280
2388
|
const ownKeysUncached = (root) => {
|
|
@@ -2318,9 +2426,20 @@ const createSession = (checker, flow) => {
|
|
|
2318
2426
|
const descriptorOf = (root, key) => descriptor(root, key) ||
|
|
2319
2427
|
(isSourceCallableObject(root) && sourceCallableOwnDataWriteOf(checker, flow, root, key) !== null) ||
|
|
2320
2428
|
((ts.isObjectLiteralExpression(root) || isFreshOrdinaryObject(root)) && writesTo(root, namedWriteReceivers.get(key) ?? [])) ||
|
|
2321
|
-
((ts.isObjectLiteralExpression(root) || isFreshOrdinaryObject(root)) &&
|
|
2322
|
-
[...holdersOf(root)].some((holder) => (computedWriteEdgesByReceiver.get(holder) ?? []).some((edge) => keysOf(edge.access).includes(key)))) ||
|
|
2429
|
+
((ts.isObjectLiteralExpression(root) || isFreshOrdinaryObject(root)) && computedWriteNames(root, key)) ||
|
|
2323
2430
|
writesTo(root, definitionReceivers.get(key) ?? []);
|
|
2431
|
+
/** Whether a computed write into a holder of `root` can name `key`; holders do not grow during a transfer (see `holdersOf`). */
|
|
2432
|
+
const computedWriteNames = (root, key) => {
|
|
2433
|
+
for (const holder of holdersOf(root)) {
|
|
2434
|
+
const edges = holder.computedWriteEdges;
|
|
2435
|
+
if (edges === undefined)
|
|
2436
|
+
continue;
|
|
2437
|
+
for (const edge of edges)
|
|
2438
|
+
if (keysOf(edge.access).includes(key))
|
|
2439
|
+
return true;
|
|
2440
|
+
}
|
|
2441
|
+
return false;
|
|
2442
|
+
};
|
|
2324
2443
|
/**
|
|
2325
2444
|
* Whether `descriptorOf` of a construction would ask which roots a
|
|
2326
2445
|
* `defineProperty` targets -- the one part of it that is not a fact of
|
|
@@ -2454,7 +2573,7 @@ const createSession = (checker, flow) => {
|
|
|
2454
2573
|
return [...keys];
|
|
2455
2574
|
};
|
|
2456
2575
|
/** The families whose slots this evaluation has read whole (`readSlotsOf`). */
|
|
2457
|
-
|
|
2576
|
+
let familiesRead = null;
|
|
2458
2577
|
/** The family whose every construction `receivers` holds, when `root` is one of them: its slots can be read whole. */
|
|
2459
2578
|
const coveringFamilyOf = (root, receivers) => {
|
|
2460
2579
|
if (!isFamilyMember(root))
|
|
@@ -2508,8 +2627,9 @@ const createSession = (checker, flow) => {
|
|
|
2508
2627
|
if (family === null)
|
|
2509
2628
|
for (const key of keys)
|
|
2510
2629
|
joinCarried(slot(root, key));
|
|
2511
|
-
else if (!familiesRead
|
|
2512
|
-
|
|
2630
|
+
else if (!familiesRead?.has(family)) {
|
|
2631
|
+
;
|
|
2632
|
+
(familiesRead ??= new Set()).add(family);
|
|
2513
2633
|
for (const key of keys)
|
|
2514
2634
|
joinCarried(familySlot(family, key));
|
|
2515
2635
|
}
|
|
@@ -2684,9 +2804,9 @@ const createSession = (checker, flow) => {
|
|
|
2684
2804
|
// facts of the program, but this runs inside every re-evaluation of every
|
|
2685
2805
|
// query on a class member: recomputing them was a walk of the construction
|
|
2686
2806
|
// index and of every opaque `new` each time. Only `fail` is per-evaluation.
|
|
2687
|
-
|
|
2807
|
+
let familyInstances = null;
|
|
2688
2808
|
const familyInstancesOf = (holder, reason) => {
|
|
2689
|
-
let known = familyInstances
|
|
2809
|
+
let known = familyInstances?.get(holder);
|
|
2690
2810
|
if (known === undefined) {
|
|
2691
2811
|
const family = sourceClassFamilyOf(checker, flow, new Set([holder]));
|
|
2692
2812
|
if (family === null)
|
|
@@ -2704,7 +2824,8 @@ const createSession = (checker, flow) => {
|
|
|
2704
2824
|
}
|
|
2705
2825
|
known = { instances: [...instances], opaque };
|
|
2706
2826
|
}
|
|
2707
|
-
|
|
2827
|
+
;
|
|
2828
|
+
(familyInstances ??= new Map()).set(holder, known);
|
|
2708
2829
|
}
|
|
2709
2830
|
if (known === null) {
|
|
2710
2831
|
fail(reason, holder);
|
|
@@ -4721,20 +4842,41 @@ const createSession = (checker, flow) => {
|
|
|
4721
4842
|
// of this container declares. Enumerating only `propertyAccesses`
|
|
4722
4843
|
// left `const { app } = p; sink(app)` out of the inventory, which is
|
|
4723
4844
|
// a hole in a closure proof, not a missing capability.
|
|
4724
|
-
for (const
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4845
|
+
for (const reads of [patternReadsByKey.get(key), unknownPatternReads])
|
|
4846
|
+
if (reads !== undefined && WIP_SOLVER_BASE)
|
|
4847
|
+
for (const [element, holder] of patternContainersOf(reads)) {
|
|
4848
|
+
if (holder === null || !observe(holder).has(container))
|
|
4849
|
+
continue;
|
|
4850
|
+
if (element.dotDotDotToken || bindingElementKey(element) === null)
|
|
4851
|
+
fail('unmodelled-container-read', element);
|
|
4852
|
+
else
|
|
4853
|
+
for (const reference of referencesOf(element))
|
|
4854
|
+
facts.add(reference);
|
|
4855
|
+
}
|
|
4856
|
+
else if (reads !== undefined && reads.length > 0) {
|
|
4857
|
+
const byContainer = patternReadsByContainerOf(reads);
|
|
4858
|
+
const found = [];
|
|
4859
|
+
for (const holder of holdersOf(container))
|
|
4860
|
+
for (const position of byContainer.get(holder) ?? NO_POSITIONS)
|
|
4861
|
+
found.push(position);
|
|
4862
|
+
found.sort((a, b) => a - b);
|
|
4863
|
+
for (const position of found) {
|
|
4864
|
+
const element = reads[position];
|
|
4865
|
+
if (element.dotDotDotToken || bindingElementKey(element) === null)
|
|
4866
|
+
fail('unmodelled-container-read', element);
|
|
4867
|
+
else
|
|
4868
|
+
for (const reference of referencesOf(element))
|
|
4869
|
+
facts.add(reference);
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4734
4872
|
if (ts.isArrayLiteralExpression(container) && (key === ELEMENT_KEY || isCanonicalIndex(key)))
|
|
4735
|
-
for (const write of
|
|
4873
|
+
for (const [write, source] of WIP_SOLVER_BASE
|
|
4874
|
+
? (valueIterationWrites ??= flow.allWrites
|
|
4875
|
+
.filter((write) => write.iterationOrigin?.mode === 'values')
|
|
4876
|
+
.map((write) => [write, value(write.iterationOrigin.source)]))
|
|
4877
|
+
: valueIterationsHolding(container, holdersOf)) {
|
|
4736
4878
|
const origin = write.iterationOrigin;
|
|
4737
|
-
if (!observe(
|
|
4879
|
+
if (WIP_SOLVER_BASE && !observe(source).has(container))
|
|
4738
4880
|
continue;
|
|
4739
4881
|
if (origin.asynchronous || deferredIntrinsicProtocolLedgerOf(flow)?.require('Array', origin.source) !== true) {
|
|
4740
4882
|
fail('unproven-array-iteration', write.site);
|
|
@@ -4761,7 +4903,11 @@ const createSession = (checker, flow) => {
|
|
|
4761
4903
|
// The dependencies alone, all in `VALUE_ORIGIN` (`DependencyGroundingKeys`):
|
|
4762
4904
|
// a lone one as itself, ~88K of a 48K-line app's seals keeping exactly one.
|
|
4763
4905
|
outcome.grounding =
|
|
4764
|
-
grounding
|
|
4906
|
+
grounding === null || grounding.size === 0
|
|
4907
|
+
? NO_GROUNDING
|
|
4908
|
+
: grounding.size === 1
|
|
4909
|
+
? grounding.values().next().value
|
|
4910
|
+
: exactListOf(grounding);
|
|
4765
4911
|
outcome.seeded = seeded;
|
|
4766
4912
|
}
|
|
4767
4913
|
// A node answering gates for its root keeps a gate log across its
|
|
@@ -4794,13 +4940,9 @@ const createSession = (checker, flow) => {
|
|
|
4794
4940
|
for (let index = 0; index < inputs.tested.length; index++)
|
|
4795
4941
|
if (inputs.tested[index].size !== inputs.testedSizes[index])
|
|
4796
4942
|
return null;
|
|
4797
|
-
for (const [fact, count] of inputs.holders)
|
|
4798
|
-
|
|
4799
|
-
for (const _holder of holdersOf(fact))
|
|
4800
|
-
now++;
|
|
4801
|
-
if (now !== count)
|
|
4943
|
+
for (const [fact, count] of inputs.holders)
|
|
4944
|
+
if (iterableCount(holdersOf(fact)) !== count)
|
|
4802
4945
|
return null;
|
|
4803
|
-
}
|
|
4804
4946
|
const facts = new Set();
|
|
4805
4947
|
let through = addedThrough.get(query);
|
|
4806
4948
|
for (let index = 0; index < inputs.joined.length; index++) {
|
|
@@ -4856,7 +4998,7 @@ const createSession = (checker, flow) => {
|
|
|
4856
4998
|
// needed is merely a stricter refusal, while a needed one gone missing
|
|
4857
4999
|
// is a wrong answer -- so if this invariant is ever broken again by a
|
|
4858
5000
|
// NEW transfer, union (not overwrite) is the direction that cannot lie:
|
|
4859
|
-
// `
|
|
5001
|
+
// the union of `requirements.get(query)` and `captured.requirements`.
|
|
4860
5002
|
// Absent reads as empty (`?? []` below); one entry per state was a map of
|
|
4861
5003
|
// mostly empty arrays.
|
|
4862
5004
|
// Copied to its exact length (the ledger builds it by `filter`, which
|