@geastack/compiler 1.0.42 → 1.0.43
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/conversion/nodes.js +5 -2
- package/dist/ir/certify.js +1 -1
- package/dist/ir/host-template-conversions.d.ts +2 -2
- package/dist/ir/host-template-conversions.js +73 -2
- package/dist/ir/lower-destructuring.js +22 -3
- package/dist/ir/lower-operands.js +24 -0
- package/dist/ir/native-field-view-facts.d.ts +8 -1
- package/dist/ir/native-field-view-facts.js +13 -3
- package/dist/ir/operation-conversions.js +1 -1
- package/dist/ir/program-conversions.d.ts +1 -1
- package/dist/ir/program-conversions.js +68 -1
- package/dist/ir/property-read-conversions.js +7 -1
- package/dist/ir/publish-native-field-view-facts.js +4 -0
- package/dist/ir/reflection-demand.js +29 -3
- package/dist/projection/dispatch.d.ts +19 -1
- package/dist/projection/dispatch.js +34 -0
- package/dist/representation/value-records.js +182 -13
- package/dist/semantics/normalize/collection-bindings.d.ts +7 -0
- package/dist/semantics/normalize/collection-bindings.js +35 -1
- package/dist/semantics/normalize/derived-expression-type.js +49 -0
- package/dist/semantics/normalize/field-bindings.js +6 -1
- package/dist/semantics/normalize/flow/source-value-session.d.ts +9 -2
- package/dist/semantics/normalize/flow/source-value-session.js +538 -94
- package/dist/semantics/normalize/local-bindings.js +23 -1
- package/dist/semantics/normalize/producers/references.js +26 -18
- package/dist/semantics/normalize/structural-array-element.d.ts +7 -0
- package/dist/semantics/normalize/structural-array-element.js +24 -1
- package/dist/semantics/normalize/structural-layout-type.js +5 -1
- package/dist/semantics/normalize/structural-parts.js +13 -8
- package/dist/semantics/normalize/structural.js +25 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +5 -1
- package/dist/targets/cpp/emit-callable.js +19 -10
- package/dist/targets/cpp/emit-native-field-view.d.ts +2 -0
- package/dist/targets/cpp/emit-native-field-view.js +1 -1
- package/dist/targets/cpp/emit-properties.js +114 -12
- package/dist/targets/cpp/host/emit-host-invoke.js +16 -2
- package/dist/targets/cpp/host/host-members.js +4 -0
- package/dist/targets/cpp/prototype/emit-prototype-array.d.ts +42 -0
- package/dist/targets/cpp/prototype/emit-prototype-array.js +31 -9
- package/dist/targets/cpp/records.js +39 -16
- package/dist/targets/cpp/translation-unit.js +23 -2
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +17 -1
- package/src/targets/cpp/runtime/gea_runtime.h +298 -51
|
@@ -157,6 +157,8 @@ const noArrayKeys = process.env['GEA_NO_ARRAY_KEYS'] !== undefined;
|
|
|
157
157
|
* read nothing, and every such array's elements were unresolvable.
|
|
158
158
|
*/
|
|
159
159
|
const ELEMENT_KEY = '[]';
|
|
160
|
+
/** Past this many facts a dependency's facts are added to a reader incrementally (`addedThrough`). */
|
|
161
|
+
const DELTA_MINIMUM = 8;
|
|
160
162
|
const CANONICAL_INDEX = /^(?:0|[1-9][0-9]*)$/;
|
|
161
163
|
const isCanonicalIndex = (key) => CANONICAL_INDEX.test(key);
|
|
162
164
|
/** Whether a store or read filed under `stored` can reach the slot `key` of `root`. */
|
|
@@ -304,7 +306,11 @@ const createSession = (checker, flow) => {
|
|
|
304
306
|
const slots = new Map();
|
|
305
307
|
const storedSlots = new Map();
|
|
306
308
|
const keyReadQueries = new Map();
|
|
309
|
+
const keyUseQueries = new Map();
|
|
307
310
|
const uses = new Map();
|
|
311
|
+
const rootUses = new Map();
|
|
312
|
+
const enumeratedSlotQueries = new Map();
|
|
313
|
+
const familySlotQueries = new Map();
|
|
308
314
|
const publications = new Map();
|
|
309
315
|
// Per call, the bodies and subjects it was asked about (see `frameQuery`).
|
|
310
316
|
const frameQueries = new Map();
|
|
@@ -347,6 +353,10 @@ const createSession = (checker, flow) => {
|
|
|
347
353
|
return null;
|
|
348
354
|
};
|
|
349
355
|
const arrayLengths = new Map();
|
|
356
|
+
// A callable's own `name` and `length`, one literal per (callable, key) for the same
|
|
357
|
+
// reason as `arrayLengths`: the solver compares facts by identity, so a literal minted
|
|
358
|
+
// per evaluation is a new fact every time and its slot never settles.
|
|
359
|
+
const callableOwnData = new Map();
|
|
350
360
|
const keyValues = new Map();
|
|
351
361
|
const keyValue = (root, key) => {
|
|
352
362
|
let keys = keyValues.get(root);
|
|
@@ -357,6 +367,29 @@ const createSession = (checker, flow) => {
|
|
|
357
367
|
keys.set(key, (literal = ts.factory.createStringLiteral(key)));
|
|
358
368
|
return literal;
|
|
359
369
|
};
|
|
370
|
+
// An `enumerated-keys` node's facts: one literal per key text, for the same
|
|
371
|
+
// identity reason as `keyValue`. They name keys and are no root's value.
|
|
372
|
+
const enumeratedKeyValues = new Map();
|
|
373
|
+
const enumeratedKeyValue = (key) => {
|
|
374
|
+
let literal = enumeratedKeyValues.get(key);
|
|
375
|
+
if (!literal)
|
|
376
|
+
enumeratedKeyValues.set(key, (literal = ts.factory.createStringLiteral(key)));
|
|
377
|
+
return literal;
|
|
378
|
+
};
|
|
379
|
+
// Each head's key list, rebuilt only when its node gained a key: facts only
|
|
380
|
+
// grow, so an unchanged size is an unchanged set, and the accesses that ask
|
|
381
|
+
// are many.
|
|
382
|
+
const enumeratedKeyLists = new Map();
|
|
383
|
+
const enumeratedKeyListOf = (query, held) => {
|
|
384
|
+
const known = enumeratedKeyLists.get(query);
|
|
385
|
+
if (known !== undefined && known.size === held.size)
|
|
386
|
+
return known.keys;
|
|
387
|
+
const keys = [];
|
|
388
|
+
for (const key of held)
|
|
389
|
+
keys.push(key.text);
|
|
390
|
+
enumeratedKeyLists.set(query, { size: held.size, keys });
|
|
391
|
+
return keys;
|
|
392
|
+
};
|
|
360
393
|
const sites = new Map(flow.calls.map((site) => [site.call, site]));
|
|
361
394
|
const ownInvocationEntries = new Map();
|
|
362
395
|
const candidateOrdinaryOwnCallableOperandsOf = (call) => {
|
|
@@ -531,6 +564,23 @@ const createSession = (checker, flow) => {
|
|
|
531
564
|
const keyReadsOf = (container, key) => {
|
|
532
565
|
return internIn(keyReadQueries, container, key, keyedQueryKey, () => new QueryState('key-reads', container, key, undefined));
|
|
533
566
|
};
|
|
567
|
+
/**
|
|
568
|
+
* Every reference a value stored under `key` of THIS container is used at
|
|
569
|
+
* next, whatever the value: the reads of the key (named and unspelled), the
|
|
570
|
+
* cells a destructuring of the container binds it to, the loop bindings
|
|
571
|
+
* iterating an array container, and the same for each container the key's
|
|
572
|
+
* value is copied into (`Object.assign`, a spread, a `defineProperty`
|
|
573
|
+
* descriptor's `value`).
|
|
574
|
+
*
|
|
575
|
+
* None of that depends on which value was stored, and a container's key
|
|
576
|
+
* receives many: every `publication` of a (value, container, key) used to
|
|
577
|
+
* re-derive it, scanning the container's whole closure twice per
|
|
578
|
+
* evaluation, so a class instance whose closure lists every store of its
|
|
579
|
+
* methods paid that scan once per value its slots were handed. Here it is
|
|
580
|
+
* one node per (container, key), and a publication only continues its own
|
|
581
|
+
* value at each reference this node names.
|
|
582
|
+
*/
|
|
583
|
+
const keyUsesOf = (container, key) => internIn(keyUseQueries, container, key, keyedQueryKey, () => new QueryState('key-uses', container, key, undefined));
|
|
534
584
|
const targets = (call) => nodeQuery('targets', call);
|
|
535
585
|
const superTargets = (call) => nodeQuery('super-targets', call);
|
|
536
586
|
/**
|
|
@@ -858,8 +908,123 @@ const createSession = (checker, flow) => {
|
|
|
858
908
|
};
|
|
859
909
|
const slot = (root, key) => internIn(slots, root, key, keyedQueryKey, () => new QueryState('slot', root, key, undefined));
|
|
860
910
|
const storedSlot = (root, key) => internIn(storedSlots, root, key, keyedQueryKey, () => new QueryState('stored-slot', root, key, undefined));
|
|
861
|
-
|
|
862
|
-
|
|
911
|
+
/**
|
|
912
|
+
* The value a use walk is keyed by: a class instance's family token, or the
|
|
913
|
+
* root itself.
|
|
914
|
+
*
|
|
915
|
+
* A walk of a `new` root through the program asks the root's identity in
|
|
916
|
+
* exactly two places -- whether a parameter rebinding stores it (`refs`)
|
|
917
|
+
* and whether a `defineProperty` gave it a key its classes do not declare
|
|
918
|
+
* (`descriptorOf`); everything else it asks is a fact of its construction,
|
|
919
|
+
* which names the same classes for every construction of them. So the
|
|
920
|
+
* walks of every `new Vector3( ... )` in a program were one walk repeated
|
|
921
|
+
* per construction site -- a node per (site, reference) through every
|
|
922
|
+
* method the vector reaches, and on a large program most of the solve.
|
|
923
|
+
*
|
|
924
|
+
* Constructions whose construction fact names the same classes share one
|
|
925
|
+
* token (the first of them met) and one walk. The two identity questions
|
|
926
|
+
* are not answered on the shared walk: it hands each back as a gate
|
|
927
|
+
* (`gateOf`), and each root's own `closure` answers it for that root
|
|
928
|
+
* (`resolveGates`), continuing the shared walk where the root continues.
|
|
929
|
+
* Every other root is its own token, walked exactly as before.
|
|
930
|
+
*/
|
|
931
|
+
const familyTokens = new Map();
|
|
932
|
+
const familyReps = new Set();
|
|
933
|
+
const tokens = new Map();
|
|
934
|
+
const classIds = new Map();
|
|
935
|
+
const classIdOf = (owner) => {
|
|
936
|
+
let id = classIds.get(owner);
|
|
937
|
+
if (id === undefined)
|
|
938
|
+
classIds.set(owner, (id = classIds.size));
|
|
939
|
+
return id;
|
|
940
|
+
};
|
|
941
|
+
const tokenOf = (root) => {
|
|
942
|
+
let token = tokens.get(root);
|
|
943
|
+
if (token !== undefined)
|
|
944
|
+
return token;
|
|
945
|
+
token = root;
|
|
946
|
+
if (ts.isNewExpression(root) && !isFreshOrdinaryObject(root)) {
|
|
947
|
+
const alternatives = construction(root)?.alternatives;
|
|
948
|
+
if (alternatives !== undefined && alternatives.length > 0) {
|
|
949
|
+
const signature = alternatives.map(classIdOf).join(',');
|
|
950
|
+
let representative = familyTokens.get(signature);
|
|
951
|
+
if (representative === undefined) {
|
|
952
|
+
familyTokens.set(signature, (representative = root));
|
|
953
|
+
familyReps.add(root);
|
|
954
|
+
}
|
|
955
|
+
token = representative;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
tokens.set(root, token);
|
|
959
|
+
return token;
|
|
960
|
+
};
|
|
961
|
+
const isFamilyMember = (root) => familyReps.has(tokenOf(root));
|
|
962
|
+
/**
|
|
963
|
+
* Every construction in the program a family token stands for, from the
|
|
964
|
+
* call index: what `family-slot` joins. Built once, and only when a slot
|
|
965
|
+
* summary is first asked for.
|
|
966
|
+
*/
|
|
967
|
+
let familyMembers = null;
|
|
968
|
+
const NO_MEMBERS = new Set();
|
|
969
|
+
const familyMembersOf = (token) => {
|
|
970
|
+
if (familyMembers === null) {
|
|
971
|
+
familyMembers = new Map();
|
|
972
|
+
for (const site of flow.calls) {
|
|
973
|
+
if (!ts.isNewExpression(site.call) || !isFamilyMember(site.call))
|
|
974
|
+
continue;
|
|
975
|
+
const token = tokenOf(site.call);
|
|
976
|
+
let members = familyMembers.get(token);
|
|
977
|
+
if (!members)
|
|
978
|
+
familyMembers.set(token, (members = new Set()));
|
|
979
|
+
members.add(site.call);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return familyMembers.get(token) ?? NO_MEMBERS;
|
|
983
|
+
};
|
|
984
|
+
/**
|
|
985
|
+
* One key's slots across every construction of a family: a read through a
|
|
986
|
+
* receiver that holds all of them -- `this.x` in a vector method, `v.x` of a
|
|
987
|
+
* parameter every vector reaches -- joins this one node instead of every
|
|
988
|
+
* construction's own slot. A large program's vectors and colors each hold
|
|
989
|
+
* every value their setters were ever passed, so each such read was N slots
|
|
990
|
+
* of hundreds of values, re-read as any of them grew. Like a row
|
|
991
|
+
* (`enumeratedSlots`) it carries its slots' grounding and owes none.
|
|
992
|
+
*/
|
|
993
|
+
const familySlot = (token, key) => internIn(familySlotQueries, token, key, keyedQueryKey, () => new QueryState('family-slot', token, key, undefined));
|
|
994
|
+
const gates = new Map();
|
|
995
|
+
const rebindingGates = new Map();
|
|
996
|
+
const rootGates = new Map();
|
|
997
|
+
const gateOf = (reference, declaration) => {
|
|
998
|
+
const held = declaration === null ? rootGates : rebindingGates;
|
|
999
|
+
let marker = held.get(reference);
|
|
1000
|
+
if (marker === undefined) {
|
|
1001
|
+
held.set(reference, (marker = ts.factory.createOmittedExpression()));
|
|
1002
|
+
gates.set(marker, { reference, declaration });
|
|
1003
|
+
}
|
|
1004
|
+
return marker;
|
|
1005
|
+
};
|
|
1006
|
+
const use = (root, reference) => {
|
|
1007
|
+
const token = tokenOf(root);
|
|
1008
|
+
return internIn(uses, token, reference, (query) => query.node, () => new QueryState('use', reference, undefined, token));
|
|
1009
|
+
};
|
|
1010
|
+
/**
|
|
1011
|
+
* Every slot of `root` a for-in head over `enumerated` binds a key of: one
|
|
1012
|
+
* row of a read like `src[ u ]`, which reads each root it can reach under
|
|
1013
|
+
* every key the head enumerates.
|
|
1014
|
+
*
|
|
1015
|
+
* Read inline, such an access joined roots x keys slots and re-read all of
|
|
1016
|
+
* them whenever any one grew -- three's `cloneUniforms` reading every
|
|
1017
|
+
* uniform group under every uniform name, thousands of slots per
|
|
1018
|
+
* evaluation. As a row per root, a slot that grows re-reads its row, and
|
|
1019
|
+
* the access re-reads only its rows. The row is not value-carrying: it
|
|
1020
|
+
* carries its slots' grounding through to the access and owes none of its
|
|
1021
|
+
* own, so a row of a root with no key yet is no unwitnessed cycle member.
|
|
1022
|
+
*/
|
|
1023
|
+
const enumeratedSlots = (enumerated, root) => internIn(enumeratedSlotQueries, root, enumerated, (query) => query.node, () => new QueryState('enumerated-slots', enumerated, undefined, root));
|
|
1024
|
+
/** `reference` walked with the root itself: a family walk's root gate. */
|
|
1025
|
+
const rootUse = (root, reference) => internIn(rootUses, root, reference, (query) => query.node, () => new QueryState('root-use', reference, undefined, root));
|
|
1026
|
+
const publication = (stored, container, key) => {
|
|
1027
|
+
const root = tokenOf(stored);
|
|
863
1028
|
let containers = publications.get(root);
|
|
864
1029
|
if (!containers)
|
|
865
1030
|
publications.set(root, (containers = new Map()));
|
|
@@ -1266,7 +1431,9 @@ const createSession = (checker, flow) => {
|
|
|
1266
1431
|
* only as the name it is declared or stored under: `value` of a property
|
|
1267
1432
|
* access reads `slot(root, key)`, and a store into that slot is spelled with
|
|
1268
1433
|
* the same key, so a callee spelling some OTHER name cannot produce this body
|
|
1269
|
-
* however the graph solves
|
|
1434
|
+
* however the graph solves -- unless a cell got it from another cell (`const
|
|
1435
|
+
* g = f`, an argument, an element): the body's closure lists those calls
|
|
1436
|
+
* for `case 'callers'` (`visitUse`). Three transfers -- a parameter's frame, a
|
|
1270
1437
|
* receiver's frame and a completion's use -- asked anyway, by observing
|
|
1271
1438
|
* `targets` of EVERY call in the program, per query. That forced the entire
|
|
1272
1439
|
* program's dispatch graph from each of them and was a large program's compile time:
|
|
@@ -1297,6 +1464,17 @@ const createSession = (checker, flow) => {
|
|
|
1297
1464
|
*/
|
|
1298
1465
|
let calleeNames = null;
|
|
1299
1466
|
let unspelledCallees = [];
|
|
1467
|
+
const calleeNameOf = (site) => {
|
|
1468
|
+
const own = ts.isCallExpression(site.call) ? candidateOrdinaryOwnCallableOperandsOf(site.call) : null;
|
|
1469
|
+
const callee = site.operands ? unwrapErasedExpression(own?.callee ?? site.operands.callee) : null;
|
|
1470
|
+
return callee
|
|
1471
|
+
? ts.isIdentifier(callee)
|
|
1472
|
+
? callee.text
|
|
1473
|
+
: ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)
|
|
1474
|
+
? accessKey(callee)
|
|
1475
|
+
: null
|
|
1476
|
+
: null;
|
|
1477
|
+
};
|
|
1300
1478
|
const buildCalleeIndex = () => {
|
|
1301
1479
|
if (calleeNames !== null)
|
|
1302
1480
|
return calleeNames;
|
|
@@ -1308,15 +1486,7 @@ const createSession = (checker, flow) => {
|
|
|
1308
1486
|
// never names.
|
|
1309
1487
|
if (!ts.isCallExpression(site.call) && !ts.isNewExpression(site.call))
|
|
1310
1488
|
continue;
|
|
1311
|
-
const
|
|
1312
|
-
const callee = site.operands ? unwrapErasedExpression(own?.callee ?? site.operands.callee) : null;
|
|
1313
|
-
const name = callee
|
|
1314
|
-
? ts.isIdentifier(callee)
|
|
1315
|
-
? callee.text
|
|
1316
|
-
: ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)
|
|
1317
|
-
? accessKey(callee)
|
|
1318
|
-
: null
|
|
1319
|
-
: null;
|
|
1489
|
+
const name = calleeNameOf(site);
|
|
1320
1490
|
if (name === null)
|
|
1321
1491
|
unspelled.push(site);
|
|
1322
1492
|
else {
|
|
@@ -1679,12 +1849,15 @@ const createSession = (checker, flow) => {
|
|
|
1679
1849
|
* head walks keys no root spells. That obligation is deferred to the ledger,
|
|
1680
1850
|
* exactly as the legacy key-set authority defers it; with no ledger to carry
|
|
1681
1851
|
* it there is nothing to discharge it later, so the enumeration refuses.
|
|
1852
|
+
*
|
|
1853
|
+
* This is the transfer of the head's own `enumerated-keys` node, never run
|
|
1854
|
+
* inline by an access: every `values[ key ]` and `this[ key ]` in the loop
|
|
1855
|
+
* body is asked once per root that reaches it, so an inline walk of every
|
|
1856
|
+
* enumerated root -- every options literal passed to any constructor of a
|
|
1857
|
+
* family -- made the work roots x roots, and each walk paid for every root's
|
|
1858
|
+
* own-key and holder checks again.
|
|
1682
1859
|
*/
|
|
1683
|
-
const enumeratedKeysOf = (
|
|
1684
|
-
if (!deferredIntrinsicProtocolLedgerOf(flow)?.require('Object', access)) {
|
|
1685
|
-
fail('undeferrable-enumeration-protocol', access);
|
|
1686
|
-
return [];
|
|
1687
|
-
}
|
|
1860
|
+
const enumeratedKeysOf = (enumerated, read, fail, sealing, ownKeysOf) => {
|
|
1688
1861
|
const keys = new Set();
|
|
1689
1862
|
const roots = read(value(enumerated));
|
|
1690
1863
|
for (const root of roots) {
|
|
@@ -1709,7 +1882,7 @@ const createSession = (checker, flow) => {
|
|
|
1709
1882
|
}
|
|
1710
1883
|
if (sealing && roots.size === 0)
|
|
1711
1884
|
fail('unresolved-enumeration', enumerated);
|
|
1712
|
-
return
|
|
1885
|
+
return keys;
|
|
1713
1886
|
};
|
|
1714
1887
|
// One object per (node, reason) for the whole session. The solver compares
|
|
1715
1888
|
// a re-seal's causes by identity, and a fresh literal per evaluation made
|
|
@@ -1754,6 +1927,25 @@ const createSession = (checker, flow) => {
|
|
|
1754
1927
|
// A node's map is allocated on its first answer: most nodes never ask an
|
|
1755
1928
|
// own-key question.
|
|
1756
1929
|
const ownKeysAnswersByQuery = new Map();
|
|
1930
|
+
/**
|
|
1931
|
+
* Per node, how many of each dependency's facts its transfers have already
|
|
1932
|
+
* returned (`add`). Only dependencies past `DELTA_MINIMUM` are tracked: a
|
|
1933
|
+
* small one costs less to re-add than to look up.
|
|
1934
|
+
*/
|
|
1935
|
+
const addedThrough = new Map();
|
|
1936
|
+
const gateLogs = new Map();
|
|
1937
|
+
/**
|
|
1938
|
+
* Per reader, each family it has found every construction of among its
|
|
1939
|
+
* receivers (`true`), or how many receivers it held when it last did not
|
|
1940
|
+
* (a receiver set only grows, so a family once covered stays covered).
|
|
1941
|
+
*/
|
|
1942
|
+
const familyCoverage = new Map();
|
|
1943
|
+
const gateLogOf = (query) => {
|
|
1944
|
+
let log = gateLogs.get(query);
|
|
1945
|
+
if (log === undefined)
|
|
1946
|
+
gateLogs.set(query, (log = { list: [], seen: new Set() }));
|
|
1947
|
+
return log;
|
|
1948
|
+
};
|
|
1757
1949
|
const evaluate = (query, required, observe, holdersOf, sealing, outcome) => {
|
|
1758
1950
|
let seeded = false;
|
|
1759
1951
|
let ownKeysAnswers = ownKeysAnswersByQuery.get(query) ?? null;
|
|
@@ -1782,9 +1974,82 @@ const createSession = (checker, flow) => {
|
|
|
1782
1974
|
};
|
|
1783
1975
|
/** `read(use(root, reference))`, without minting the node for a use that does nothing (`inertUse`). */
|
|
1784
1976
|
const readUse = (root, reference) => inertUse(reference) ? NO_VALUES : read(use(root, reference));
|
|
1977
|
+
/**
|
|
1978
|
+
* The gates this node answers for its own root (`resolveGates`), when it
|
|
1979
|
+
* is the closure of a family member or reads a family walk for one: a
|
|
1980
|
+
* gate it adds is kept here instead of becoming a fact.
|
|
1981
|
+
*/
|
|
1982
|
+
let gating = null;
|
|
1983
|
+
/** This node walks a family token: identity questions become gates. */
|
|
1984
|
+
let familyWalk = false;
|
|
1985
|
+
/** The reference a `use` node walks: a root gate re-walks it. */
|
|
1986
|
+
let walkedReference = null;
|
|
1785
1987
|
const add = (values) => {
|
|
1786
|
-
|
|
1787
|
-
|
|
1988
|
+
// A transfer only has to hand back what this node has not published
|
|
1989
|
+
// yet: the solver adds every fact a transfer returns to the node and
|
|
1990
|
+
// keeps it, and a dependency's facts only grow, in insertion order.
|
|
1991
|
+
// So a dependency read again is added from where this node's last
|
|
1992
|
+
// transfer stopped. Re-adding it whole made each re-evaluation of a
|
|
1993
|
+
// node joining many slots (`this.x` read across every instance of a
|
|
1994
|
+
// class, each slot holding every value its setters were passed) copy
|
|
1995
|
+
// and re-test every fact again -- ~95% of all facts added on a large
|
|
1996
|
+
// program. A seal still builds its full answer: it reads `facts`.
|
|
1997
|
+
const whole = outcome !== null || !(values instanceof FactState) || values.size <= DELTA_MINIMUM;
|
|
1998
|
+
if (whole && gating === null) {
|
|
1999
|
+
for (const held of values)
|
|
2000
|
+
facts.add(held);
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
let before = 0;
|
|
2004
|
+
if (!whole) {
|
|
2005
|
+
let through = addedThrough.get(query);
|
|
2006
|
+
if (through === undefined)
|
|
2007
|
+
addedThrough.set(query, (through = new Map()));
|
|
2008
|
+
before = through.get(values) ?? 0;
|
|
2009
|
+
const size = values.size;
|
|
2010
|
+
if (before === size)
|
|
2011
|
+
return;
|
|
2012
|
+
through.set(values, size);
|
|
2013
|
+
}
|
|
2014
|
+
let at = 0;
|
|
2015
|
+
if (gating === null) {
|
|
2016
|
+
for (const held of values)
|
|
2017
|
+
if (at++ >= before)
|
|
2018
|
+
facts.add(held);
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
for (const held of values) {
|
|
2022
|
+
if (at++ < before)
|
|
2023
|
+
continue;
|
|
2024
|
+
if (held.kind === ts.SyntaxKind.OmittedExpression && gates.has(held)) {
|
|
2025
|
+
if (!gating.seen.has(held)) {
|
|
2026
|
+
gating.seen.add(held);
|
|
2027
|
+
gating.list.push(held);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
else
|
|
2031
|
+
facts.add(held);
|
|
2032
|
+
}
|
|
2033
|
+
};
|
|
2034
|
+
/**
|
|
2035
|
+
* Answers every gate the family walks read by this node have handed back,
|
|
2036
|
+
* for `root`: a rebinding gate continues the walk past the rebinding when
|
|
2037
|
+
* one of the parameter's rebindings stores `root` (the test `refs` makes
|
|
2038
|
+
* on a root's own walk), and a root gate re-walks its reference with
|
|
2039
|
+
* `root` itself. What either reads can hand back further gates, answered
|
|
2040
|
+
* in the same pass. The log outlives the evaluation, because `add` hands
|
|
2041
|
+
* back only what a dependency gained, while every gate is asked again:
|
|
2042
|
+
* its answer can change as the rebindings' values grow.
|
|
2043
|
+
*/
|
|
2044
|
+
const resolveGates = (root) => {
|
|
2045
|
+
const log = gating;
|
|
2046
|
+
for (let at = 0; at < log.list.length; at++) {
|
|
2047
|
+
const gate = gates.get(log.list[at]);
|
|
2048
|
+
if (gate.declaration === null)
|
|
2049
|
+
add(read(rootUse(root, gate.reference)));
|
|
2050
|
+
else if (!parameterRebindingsOf(gate.declaration).every((write) => write.value !== null && !read(value(write.value)).has(root)))
|
|
2051
|
+
add(readUse(root, gate.reference));
|
|
2052
|
+
}
|
|
1788
2053
|
};
|
|
1789
2054
|
/**
|
|
1790
2055
|
* A member call whose receiver holds nothing but `null`/`undefined`
|
|
@@ -1969,6 +2234,13 @@ const createSession = (checker, flow) => {
|
|
|
1969
2234
|
((ts.isObjectLiteralExpression(root) || isFreshOrdinaryObject(root)) &&
|
|
1970
2235
|
[...holdersOf(root)].some((holder) => (computedWriteEdgesByReceiver.get(holder) ?? []).some((edge) => keysOf(edge.access).includes(key)))) ||
|
|
1971
2236
|
writesTo(root, definitionReceivers.get(key) ?? []);
|
|
2237
|
+
/**
|
|
2238
|
+
* Whether `descriptorOf` of a construction would ask which roots a
|
|
2239
|
+
* `defineProperty` targets -- the one part of it that is not a fact of
|
|
2240
|
+
* the construction's classes, and so the one a family walk cannot answer
|
|
2241
|
+
* for every member at once.
|
|
2242
|
+
*/
|
|
2243
|
+
const definitionDecides = (root, key) => isObjectRoot(root) && !descriptor(root, key) && (definitionReceivers.get(key)?.length ?? 0) > 0;
|
|
1972
2244
|
/**
|
|
1973
2245
|
* Every element key of the arrays an access could be reaching.
|
|
1974
2246
|
*
|
|
@@ -2020,8 +2292,14 @@ const createSession = (checker, flow) => {
|
|
|
2020
2292
|
if (!ts.isElementAccessExpression(access))
|
|
2021
2293
|
return [];
|
|
2022
2294
|
const enumerated = enumerationHeadOf(access.argumentExpression);
|
|
2023
|
-
if (enumerated !== null)
|
|
2024
|
-
|
|
2295
|
+
if (enumerated !== null) {
|
|
2296
|
+
if (!deferredIntrinsicProtocolLedgerOf(flow)?.require('Object', access)) {
|
|
2297
|
+
fail('undeferrable-enumeration-protocol', access);
|
|
2298
|
+
return [];
|
|
2299
|
+
}
|
|
2300
|
+
const head = nodeQuery('enumerated-keys', enumerated);
|
|
2301
|
+
return enumeratedKeyListOf(head, read(head));
|
|
2302
|
+
}
|
|
2025
2303
|
const keyReference = unwrapErasedExpression(access.argumentExpression);
|
|
2026
2304
|
const keyDeclaration = ts.isIdentifier(keyReference) ? flow.targetOf(keyReference)?.declaration : undefined;
|
|
2027
2305
|
if (keyDeclaration && ts.isVariableDeclaration(keyDeclaration)) {
|
|
@@ -2088,18 +2366,89 @@ const createSession = (checker, flow) => {
|
|
|
2088
2366
|
fail('unresolved-property-key', access);
|
|
2089
2367
|
return [...keys];
|
|
2090
2368
|
};
|
|
2369
|
+
/** The families whose slots this evaluation has read whole (`readSlotsOf`). */
|
|
2370
|
+
const familiesRead = new Set();
|
|
2371
|
+
/** The family whose every construction `receivers` holds, when `root` is one of them: its slots can be read whole. */
|
|
2372
|
+
const coveringFamilyOf = (root, receivers) => {
|
|
2373
|
+
if (!isFamilyMember(root))
|
|
2374
|
+
return null;
|
|
2375
|
+
const token = tokenOf(root);
|
|
2376
|
+
const members = familyMembersOf(token);
|
|
2377
|
+
if (!members.has(root))
|
|
2378
|
+
return null;
|
|
2379
|
+
let known = familyCoverage.get(query);
|
|
2380
|
+
const held = known?.get(token);
|
|
2381
|
+
if (held === true)
|
|
2382
|
+
return token;
|
|
2383
|
+
if (held === receivers.size)
|
|
2384
|
+
return null;
|
|
2385
|
+
let covered = members.size > 1;
|
|
2386
|
+
if (covered)
|
|
2387
|
+
for (const member of members)
|
|
2388
|
+
if (!receivers.has(member))
|
|
2389
|
+
covered = false;
|
|
2390
|
+
if (known === undefined)
|
|
2391
|
+
familyCoverage.set(query, (known = new Map()));
|
|
2392
|
+
known.set(token, covered ? true : receivers.size);
|
|
2393
|
+
return covered ? token : null;
|
|
2394
|
+
};
|
|
2395
|
+
/**
|
|
2396
|
+
* What `access` reads off `root`, one of `receivers`, under `keys` (its
|
|
2397
|
+
* `keysOf`): each slot; or, for a key bound by a for-in head, the
|
|
2398
|
+
* root's row of the head's keys (`enumeratedSlots`); or, when
|
|
2399
|
+
* `receivers` holds every construction of the root's family, the
|
|
2400
|
+
* family's slot (`familySlot`), once for all of them. A callable
|
|
2401
|
+
* object's own data is proven per read, so it is read key by key.
|
|
2402
|
+
*/
|
|
2403
|
+
const readSlotsOf = (root, receivers, keys, access) => {
|
|
2404
|
+
if (isSourceCallableObject(root)) {
|
|
2405
|
+
for (const key of keys) {
|
|
2406
|
+
if (key !== 'name' && key !== 'length' && sourceCallableOwnDataWriteOf(checker, flow, root, key, access) === null)
|
|
2407
|
+
fail('unproven-callable-data-read', access);
|
|
2408
|
+
else
|
|
2409
|
+
add(carry(slot(root, key)));
|
|
2410
|
+
}
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
const enumerated = keys.length > 0 && ts.isElementAccessExpression(access) && accessKey(access) === null
|
|
2414
|
+
? enumerationHeadOf(access.argumentExpression)
|
|
2415
|
+
: null;
|
|
2416
|
+
if (enumerated !== null) {
|
|
2417
|
+
add(carry(enumeratedSlots(enumerated, root)));
|
|
2418
|
+
return;
|
|
2419
|
+
}
|
|
2420
|
+
const family = coveringFamilyOf(root, receivers);
|
|
2421
|
+
if (family === null)
|
|
2422
|
+
for (const key of keys)
|
|
2423
|
+
add(carry(slot(root, key)));
|
|
2424
|
+
else if (!familiesRead.has(family)) {
|
|
2425
|
+
familiesRead.add(family);
|
|
2426
|
+
for (const key of keys)
|
|
2427
|
+
add(carry(familySlot(family, key)));
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
// A root this lane cannot read refuses the binding, and the literal
|
|
2431
|
+
// roots' entries are still returned. The solver keeps every fact a
|
|
2432
|
+
// transfer ever published, so answering null once such a root arrived
|
|
2433
|
+
// kept whatever entries had been read before it, and how many depended
|
|
2434
|
+
// on the schedule (sakura 55269dd's `for (const m of mats)`, where
|
|
2435
|
+
// `mats` also holds `o.material` itself). `readers` observes the
|
|
2436
|
+
// refused cell without requiring it, so a missing entry there was a
|
|
2437
|
+
// missing reader.
|
|
2091
2438
|
const iterationValuesAt = (source) => {
|
|
2092
2439
|
const elements = [];
|
|
2093
2440
|
for (const root of read(value(source))) {
|
|
2094
2441
|
if (!ts.isArrayLiteralExpression(root) ||
|
|
2095
2442
|
root.elements.some((element) => ts.isSpreadElement(element) || ts.isOmittedExpression(element)) ||
|
|
2096
|
-
deferredIntrinsicProtocolLedgerOf(flow)?.require('Array', source) !== true)
|
|
2097
|
-
|
|
2443
|
+
deferredIntrinsicProtocolLedgerOf(flow)?.require('Array', source) !== true) {
|
|
2444
|
+
fail('unmodelled-iteration-source', source);
|
|
2445
|
+
continue;
|
|
2446
|
+
}
|
|
2098
2447
|
// This bounded lane transports the original literal's entries.
|
|
2099
2448
|
// Mutating its contents/length needs the full indexed storage plan.
|
|
2100
2449
|
for (const use of read(closure(root)))
|
|
2101
2450
|
if ((ts.isPropertyAccessExpression(use) || ts.isElementAccessExpression(use)) && writeEdgeByAccess.has(use))
|
|
2102
|
-
|
|
2451
|
+
fail('unmodelled-iteration-source', use);
|
|
2103
2452
|
for (const element of root.elements)
|
|
2104
2453
|
if (!ts.isSpreadElement(element) && !ts.isOmittedExpression(element))
|
|
2105
2454
|
elements.push(element);
|
|
@@ -2133,17 +2482,32 @@ const createSession = (checker, flow) => {
|
|
|
2133
2482
|
return null;
|
|
2134
2483
|
return importerMentions(declaration) !== null ? null : 'export-importers-unenumerable';
|
|
2135
2484
|
};
|
|
2485
|
+
/** The references `refs` walks for a declaration no rebinding applies to: every read of the cell, and its importers' mentions. */
|
|
2486
|
+
const referencesOf = (declaration) => {
|
|
2487
|
+
const found = [];
|
|
2488
|
+
for (const reference of flow.referencesToDeclaration(declaration))
|
|
2489
|
+
if (reference !== ts.getNameOfDeclaration(declaration) && !isTypePositionReference(reference))
|
|
2490
|
+
found.push(reference);
|
|
2491
|
+
for (const reference of importerMentions(declaration) ?? [])
|
|
2492
|
+
found.push(reference);
|
|
2493
|
+
return found;
|
|
2494
|
+
};
|
|
2136
2495
|
const refs = (root, declaration) => {
|
|
2137
2496
|
for (const reference of flow.referencesToDeclaration(declaration)) {
|
|
2138
2497
|
if (reference === ts.getNameOfDeclaration(declaration) || isTypePositionReference(reference))
|
|
2139
2498
|
continue;
|
|
2140
2499
|
// Past an unconditional rebinding the cell holds only what a write
|
|
2141
2500
|
// after entry stored; a root none of those writes stores is no
|
|
2142
|
-
// longer reachable through it.
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2501
|
+
// longer reachable through it. Whether one stores it is a question
|
|
2502
|
+
// about the root, so a family walk leaves it to each root.
|
|
2503
|
+
if (ts.isParameter(declaration) && readsAfterRebinding(declaration, reference)) {
|
|
2504
|
+
if (familyWalk) {
|
|
2505
|
+
facts.add(gateOf(reference, declaration));
|
|
2506
|
+
continue;
|
|
2507
|
+
}
|
|
2508
|
+
if (parameterRebindingsOf(declaration).every((write) => write.value !== null && !read(value(write.value)).has(root)))
|
|
2509
|
+
continue;
|
|
2510
|
+
}
|
|
2147
2511
|
add(readUse(root, reference));
|
|
2148
2512
|
}
|
|
2149
2513
|
for (const reference of importerMentions(declaration) ?? [])
|
|
@@ -2166,6 +2530,16 @@ const createSession = (checker, flow) => {
|
|
|
2166
2530
|
fail('non-object-destructured-container', pattern);
|
|
2167
2531
|
return;
|
|
2168
2532
|
}
|
|
2533
|
+
if (familyWalk &&
|
|
2534
|
+
pattern.elements.some((element) => {
|
|
2535
|
+
if (ts.isOmittedExpression(element) || element.dotDotDotToken)
|
|
2536
|
+
return false;
|
|
2537
|
+
const key = bindingElementKey(element);
|
|
2538
|
+
return key !== null && definitionDecides(root, key);
|
|
2539
|
+
})) {
|
|
2540
|
+
facts.add(gateOf(walkedReference, null));
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2169
2543
|
for (const element of pattern.elements) {
|
|
2170
2544
|
if (ts.isOmittedExpression(element))
|
|
2171
2545
|
continue;
|
|
@@ -2710,6 +3084,10 @@ const createSession = (checker, flow) => {
|
|
|
2710
3084
|
}
|
|
2711
3085
|
return absentOwnKey(held, key, parent, descriptorOf, hasUnnamedWrite);
|
|
2712
3086
|
};
|
|
3087
|
+
if (familyWalk && keys.some((key) => definitionDecides(root, key))) {
|
|
3088
|
+
facts.add(gateOf(reference, null));
|
|
3089
|
+
return;
|
|
3090
|
+
}
|
|
2713
3091
|
// `instance.constructor` READS the class object off the prototype
|
|
2714
3092
|
// -- a value this graph does not carry, and one whose escape opens
|
|
2715
3093
|
// the family: `unknown( value.constructor )` can construct and
|
|
@@ -2744,6 +3122,15 @@ const createSession = (checker, flow) => {
|
|
|
2744
3122
|
}
|
|
2745
3123
|
if (!isBody(root))
|
|
2746
3124
|
fail('non-callable-use', reference);
|
|
3125
|
+
else if (ts.isCallExpression(parent)) {
|
|
3126
|
+
// A call through a cell none of the body's names spells -- `const g =
|
|
3127
|
+
// f; g()`, a parameter, an element, a destructured binding -- is a
|
|
3128
|
+
// caller `candidateCallersOf` cannot list. Hand it to `case 'callers'`.
|
|
3129
|
+
const site = sites.get(parent);
|
|
3130
|
+
const name = site ? calleeNameOf(site) : null;
|
|
3131
|
+
if (!site || (name !== null && namesOf(root)?.includes(name) === false))
|
|
3132
|
+
facts.add(parent);
|
|
3133
|
+
}
|
|
2747
3134
|
return;
|
|
2748
3135
|
}
|
|
2749
3136
|
if (ts.isCallExpression(parent)) {
|
|
@@ -3127,15 +3514,7 @@ const createSession = (checker, flow) => {
|
|
|
3127
3514
|
continue;
|
|
3128
3515
|
}
|
|
3129
3516
|
if (isObjectRoot(root))
|
|
3130
|
-
|
|
3131
|
-
if (isSourceCallableObject(root) &&
|
|
3132
|
-
key !== 'name' &&
|
|
3133
|
-
key !== 'length' &&
|
|
3134
|
-
sourceCallableOwnDataWriteOf(checker, flow, root, key, expression) === null)
|
|
3135
|
-
fail('unproven-callable-data-read', expression);
|
|
3136
|
-
else
|
|
3137
|
-
add(carry(slot(root, key)));
|
|
3138
|
-
}
|
|
3517
|
+
readSlotsOf(root, roots, keys, expression);
|
|
3139
3518
|
else if (!isNullish(root))
|
|
3140
3519
|
fail('non-object-receiver');
|
|
3141
3520
|
}
|
|
@@ -3231,9 +3610,16 @@ const createSession = (checker, flow) => {
|
|
|
3231
3610
|
const parameters = runtimeParametersOf(root);
|
|
3232
3611
|
const firstDefault = parameters.findIndex((parameter) => parameter.initializer !== undefined || parameter.dotDotDotToken !== undefined);
|
|
3233
3612
|
const named = (ts.isArrowFunction(root) ? undefined : root.name) ?? (ts.isVariableDeclaration(root.parent) ? root.parent.name : undefined);
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3613
|
+
let ownData = callableOwnData.get(root);
|
|
3614
|
+
if (!ownData)
|
|
3615
|
+
callableOwnData.set(root, (ownData = new Map()));
|
|
3616
|
+
let literal = ownData.get(key);
|
|
3617
|
+
if (!literal)
|
|
3618
|
+
ownData.set(key, (literal =
|
|
3619
|
+
key === 'name'
|
|
3620
|
+
? ts.factory.createStringLiteral(named && ts.isIdentifier(named) ? named.text : '')
|
|
3621
|
+
: ts.factory.createNumericLiteral(firstDefault < 0 ? parameters.length : firstDefault)));
|
|
3622
|
+
facts.add(literal);
|
|
3237
3623
|
seeded = true;
|
|
3238
3624
|
}
|
|
3239
3625
|
else {
|
|
@@ -3302,6 +3688,10 @@ const createSession = (checker, flow) => {
|
|
|
3302
3688
|
if (getterRead !== null) {
|
|
3303
3689
|
// The getter runs with this construction as its receiver, and
|
|
3304
3690
|
// the read yields what the getter's completions yield.
|
|
3691
|
+
// The receiver's walk through the getter is a family walk for a
|
|
3692
|
+
// family member, whose gates are this root's to answer.
|
|
3693
|
+
if (getterRead.getters.length > 0 && isFamilyMember(root))
|
|
3694
|
+
gating = gateLogOf(query);
|
|
3305
3695
|
for (const getter of getterRead.getters) {
|
|
3306
3696
|
for (const reference of flow.receiverReferencesToDeclaration(getter))
|
|
3307
3697
|
add(readUse(root, reference));
|
|
@@ -3317,6 +3707,10 @@ const createSession = (checker, flow) => {
|
|
|
3317
3707
|
}
|
|
3318
3708
|
}
|
|
3319
3709
|
}
|
|
3710
|
+
if (gating !== null) {
|
|
3711
|
+
resolveGates(root);
|
|
3712
|
+
gating = null;
|
|
3713
|
+
}
|
|
3320
3714
|
if (getterRead.absent) {
|
|
3321
3715
|
facts.add(undefinedValue);
|
|
3322
3716
|
seeded = true;
|
|
@@ -3800,17 +4194,10 @@ const createSession = (checker, flow) => {
|
|
|
3800
4194
|
}
|
|
3801
4195
|
else if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) {
|
|
3802
4196
|
const keys = keysOf(expression);
|
|
3803
|
-
|
|
4197
|
+
const receivers = read(contextual(expression.expression));
|
|
4198
|
+
for (const root of receivers) {
|
|
3804
4199
|
if (isObjectRoot(root))
|
|
3805
|
-
|
|
3806
|
-
if (isSourceCallableObject(root) &&
|
|
3807
|
-
key !== 'name' &&
|
|
3808
|
-
key !== 'length' &&
|
|
3809
|
-
sourceCallableOwnDataWriteOf(checker, flow, root, key, expression) === null)
|
|
3810
|
-
fail('unproven-callable-data-read', expression);
|
|
3811
|
-
else
|
|
3812
|
-
add(carry(slot(root, key)));
|
|
3813
|
-
}
|
|
4200
|
+
readSlotsOf(root, receivers, keys, expression);
|
|
3814
4201
|
else if (root.kind !== ts.SyntaxKind.NullKeyword && !ts.isVoidExpression(root))
|
|
3815
4202
|
fail('non-object-receiver');
|
|
3816
4203
|
}
|
|
@@ -3920,10 +4307,11 @@ const createSession = (checker, flow) => {
|
|
|
3920
4307
|
// is paid once per OWNER, not once per (owner, consumer) pair. See
|
|
3921
4308
|
// `callersOf`'s comment for the shape and the measured cost this
|
|
3922
4309
|
// replaces.
|
|
3923
|
-
// Discovery by name, soundness by CLOSURE. The spelled
|
|
3924
|
-
// resolve to this owner are its callers only while the owner
|
|
3925
|
-
// be reached from nowhere else: the body's own closure says where
|
|
3926
|
-
// the callable value goes
|
|
4310
|
+
// Discovery by name and by CLOSURE, soundness by CLOSURE. The spelled
|
|
4311
|
+
// calls that resolve to this owner are its callers only while the owner
|
|
4312
|
+
// can be reached from nowhere else: the body's own closure says where
|
|
4313
|
+
// the callable value goes -- including each call through an alias no
|
|
4314
|
+
// name of the owner spells, which it lists -- and for a class member each instance's
|
|
3927
4315
|
// closure says where the receivers go -- an instance handed to
|
|
3928
4316
|
// unknown code can be called through from there with arguments no
|
|
3929
4317
|
// site spells. A spelled call whose targets are opaque is then
|
|
@@ -3938,7 +4326,15 @@ const createSession = (checker, flow) => {
|
|
|
3938
4326
|
// construction domain, so it has no closure to read here.
|
|
3939
4327
|
if (ts.isConstructorDeclaration(owner))
|
|
3940
4328
|
break;
|
|
3941
|
-
|
|
4329
|
+
// `const g = f; g()` before this: `callers(f)` was a complete `[]`. Seeded
|
|
4330
|
+
// so `holdersOf` below finds the ones whose targets hold the owner; the
|
|
4331
|
+
// closure's other calls (a bulk assign or definition onto it) never do.
|
|
4332
|
+
const unnamed = [];
|
|
4333
|
+
for (const use of read(closure(owner)))
|
|
4334
|
+
if (ts.isCallExpression(use))
|
|
4335
|
+
unnamed.push(use);
|
|
4336
|
+
for (const call of unnamed)
|
|
4337
|
+
seed(targets(call));
|
|
3942
4338
|
if (ts.isClassElement(owner) && ts.isClassLike(owner.parent)) {
|
|
3943
4339
|
if ((ts.getCombinedModifierFlags(owner) & ts.ModifierFlags.Static) !== 0)
|
|
3944
4340
|
fail('static-member-callers-open', owner);
|
|
@@ -3992,10 +4388,23 @@ const createSession = (checker, flow) => {
|
|
|
3992
4388
|
for (const position of matched)
|
|
3993
4389
|
facts.add(sites.sites[position].call);
|
|
3994
4390
|
}
|
|
4391
|
+
// The calls through an alias the closure listed: a caller once its
|
|
4392
|
+
// seeded `targets` holds the owner, as for a named candidate above.
|
|
4393
|
+
if (unnamed.length > 0) {
|
|
4394
|
+
const heldTargets = new Set();
|
|
4395
|
+
for (const holder of holders)
|
|
4396
|
+
if (holder.kind === 'targets')
|
|
4397
|
+
heldTargets.add(holder.node);
|
|
4398
|
+
for (const call of unnamed)
|
|
4399
|
+
if (heldTargets.has(call))
|
|
4400
|
+
facts.add(call);
|
|
4401
|
+
}
|
|
3995
4402
|
break;
|
|
3996
4403
|
}
|
|
3997
4404
|
case 'closure': {
|
|
3998
4405
|
const root = query.node;
|
|
4406
|
+
if (isFamilyMember(root))
|
|
4407
|
+
gating = gateLogOf(query);
|
|
3999
4408
|
if (ts.isFunctionDeclaration(root)) {
|
|
4000
4409
|
// `refs` follows the same import inventory as stored cells. A
|
|
4001
4410
|
// factory imported by a source module is not an external escape.
|
|
@@ -4022,27 +4431,33 @@ const createSession = (checker, flow) => {
|
|
|
4022
4431
|
fail('unmodelled-root');
|
|
4023
4432
|
if (ts.isNewExpression(root) && !isFreshOrdinaryObject(root)) {
|
|
4024
4433
|
const owners = constructionFrames.receiverOwnersOf(root);
|
|
4025
|
-
if (!owners)
|
|
4434
|
+
if (!owners)
|
|
4026
4435
|
fail('opaque-construction');
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
for (const reference of flow.receiverReferencesToDeclaration(owner))
|
|
4032
|
-
add(readUse(root, reference));
|
|
4033
|
-
continue;
|
|
4034
|
-
}
|
|
4035
|
-
for (const member of owner.members) {
|
|
4036
|
-
if (ts.isConstructorDeclaration(member) ||
|
|
4037
|
-
(ts.isPropertyDeclaration(member) && (ts.getCombinedModifierFlags(member) & ts.ModifierFlags.Static) === 0))
|
|
4038
|
-
for (const reference of flow.receiverReferencesToDeclaration(member))
|
|
4436
|
+
else
|
|
4437
|
+
for (const owner of owners) {
|
|
4438
|
+
if (!isClassSpelledSourceClass(owner)) {
|
|
4439
|
+
for (const reference of flow.receiverReferencesToDeclaration(owner))
|
|
4039
4440
|
add(readUse(root, reference));
|
|
4441
|
+
continue;
|
|
4442
|
+
}
|
|
4443
|
+
for (const member of owner.members) {
|
|
4444
|
+
if (ts.isConstructorDeclaration(member) ||
|
|
4445
|
+
(ts.isPropertyDeclaration(member) && (ts.getCombinedModifierFlags(member) & ts.ModifierFlags.Static) === 0))
|
|
4446
|
+
for (const reference of flow.receiverReferencesToDeclaration(member))
|
|
4447
|
+
add(readUse(root, reference));
|
|
4448
|
+
}
|
|
4040
4449
|
}
|
|
4041
|
-
}
|
|
4042
4450
|
}
|
|
4451
|
+
if (gating !== null)
|
|
4452
|
+
resolveGates(root);
|
|
4043
4453
|
break;
|
|
4044
4454
|
}
|
|
4045
4455
|
case 'use':
|
|
4456
|
+
familyWalk = familyReps.has(query.root);
|
|
4457
|
+
walkedReference = query.node;
|
|
4458
|
+
visitUse(query.root, query.node);
|
|
4459
|
+
break;
|
|
4460
|
+
case 'root-use':
|
|
4046
4461
|
visitUse(query.root, query.node);
|
|
4047
4462
|
break;
|
|
4048
4463
|
case 'unknown-reads': {
|
|
@@ -4088,6 +4503,24 @@ const createSession = (checker, flow) => {
|
|
|
4088
4503
|
facts.add(flow.propertyAccesses[position]);
|
|
4089
4504
|
break;
|
|
4090
4505
|
}
|
|
4506
|
+
case 'family-slot': {
|
|
4507
|
+
for (const member of familyMembersOf(query.node))
|
|
4508
|
+
add(carry(slot(member, query.key)));
|
|
4509
|
+
break;
|
|
4510
|
+
}
|
|
4511
|
+
case 'enumerated-slots': {
|
|
4512
|
+
const root = query.root;
|
|
4513
|
+
const head = nodeQuery('enumerated-keys', query.node);
|
|
4514
|
+
for (const key of enumeratedKeyListOf(head, read(head)))
|
|
4515
|
+
add(carry(slot(root, key)));
|
|
4516
|
+
break;
|
|
4517
|
+
}
|
|
4518
|
+
case 'enumerated-keys': {
|
|
4519
|
+
for (const key of enumeratedKeysOf(query.node, read, fail, sealing, ownKeysOf))
|
|
4520
|
+
facts.add(enumeratedKeyValue(key));
|
|
4521
|
+
seeded = true;
|
|
4522
|
+
break;
|
|
4523
|
+
}
|
|
4091
4524
|
case 'own-keys': {
|
|
4092
4525
|
const root = query.node;
|
|
4093
4526
|
const keys = ownKeysOf(root);
|
|
@@ -4126,65 +4559,75 @@ const createSession = (checker, flow) => {
|
|
|
4126
4559
|
break;
|
|
4127
4560
|
}
|
|
4128
4561
|
case 'publication': {
|
|
4129
|
-
|
|
4562
|
+
// The value continues at every reference the container's key is used
|
|
4563
|
+
// at (`keyUsesOf`), which is the same for every value it holds.
|
|
4564
|
+
for (const reference of read(keyUsesOf(query.node, query.key)))
|
|
4565
|
+
add(readUse(query.root, reference));
|
|
4566
|
+
break;
|
|
4567
|
+
}
|
|
4568
|
+
case 'key-uses': {
|
|
4569
|
+
const container = query.node;
|
|
4570
|
+
const key = query.key;
|
|
4571
|
+
read(closure(container));
|
|
4130
4572
|
// A container merged into another by `Object.assign` hands this
|
|
4131
4573
|
// key's value to the target as well.
|
|
4132
|
-
for (const stored of read(closure(
|
|
4574
|
+
for (const stored of read(closure(container))) {
|
|
4133
4575
|
if (!ts.isCallExpression(stored))
|
|
4134
4576
|
continue;
|
|
4135
4577
|
const bulk = bulkAssignOf(stored);
|
|
4136
|
-
if (bulk === null || !bulk.sources.some((source) => read(value(source)).has(
|
|
4578
|
+
if (bulk === null || !bulk.sources.some((source) => read(value(source)).has(container)))
|
|
4137
4579
|
continue;
|
|
4138
4580
|
for (const held of read(value(bulk.target)))
|
|
4139
4581
|
if (isObjectRoot(held))
|
|
4140
|
-
add(read(
|
|
4582
|
+
add(read(keyUsesOf(held, key)));
|
|
4141
4583
|
}
|
|
4142
|
-
for (const stored of read(closure(
|
|
4584
|
+
for (const stored of read(closure(container))) {
|
|
4143
4585
|
const copied = ts.isExpression(stored) ? outermostErasureOf(stored).parent : undefined;
|
|
4144
|
-
if (copied && ts.isSpreadAssignment(copied) && read(value(copied.expression)).has(
|
|
4145
|
-
add(read(
|
|
4146
|
-
if (!ts.isCallExpression(stored) || !definitionPlans.has(stored) ||
|
|
4586
|
+
if (copied && ts.isSpreadAssignment(copied) && read(value(copied.expression)).has(container))
|
|
4587
|
+
add(read(keyUsesOf(copied.parent, key)));
|
|
4588
|
+
if (!ts.isCallExpression(stored) || !definitionPlans.has(stored) || key !== 'value')
|
|
4147
4589
|
continue;
|
|
4148
4590
|
const plan = definitionOf(stored);
|
|
4149
|
-
if (plan === null || !read(value(stored.arguments[2])).has(
|
|
4591
|
+
if (plan === null || !read(value(stored.arguments[2])).has(container))
|
|
4150
4592
|
continue;
|
|
4151
4593
|
for (const held of read(value(stored.arguments[0])))
|
|
4152
4594
|
if (isObjectRoot(held))
|
|
4153
|
-
for (const
|
|
4154
|
-
add(read(
|
|
4595
|
+
for (const defined of plan.keys)
|
|
4596
|
+
add(read(keyUsesOf(held, defined)));
|
|
4155
4597
|
}
|
|
4156
4598
|
// Discovery-only, as the per-read receiver test it replaces was.
|
|
4157
|
-
for (const access of observe(keyReadsOf(
|
|
4599
|
+
for (const access of observe(keyReadsOf(container, key))) {
|
|
4158
4600
|
if (!ts.isPropertyAccessExpression(access) && !ts.isElementAccessExpression(access))
|
|
4159
4601
|
continue;
|
|
4160
|
-
add(
|
|
4602
|
+
facts.add(access);
|
|
4161
4603
|
}
|
|
4162
4604
|
// Discovery-only, exactly as the receiver test it replaces was: a
|
|
4163
4605
|
// publication never required the unknown reads to have settled, it
|
|
4164
4606
|
// only had to see the ones that had.
|
|
4165
|
-
for (const access of observe(unknownReadsOf(
|
|
4607
|
+
for (const access of observe(unknownReadsOf(container))) {
|
|
4166
4608
|
if (!ts.isPropertyAccessExpression(access) && !ts.isElementAccessExpression(access))
|
|
4167
4609
|
continue;
|
|
4168
|
-
if (keyReaches(
|
|
4169
|
-
add(
|
|
4610
|
+
if (keyReaches(container, keysOf(access), key))
|
|
4611
|
+
facts.add(access);
|
|
4170
4612
|
}
|
|
4171
4613
|
// The value this key holds also reaches every cell a binding element
|
|
4172
4614
|
// of this container declares. Enumerating only `propertyAccesses`
|
|
4173
4615
|
// left `const { app } = p; sink(app)` out of the inventory, which is
|
|
4174
4616
|
// a hole in a closure proof, not a missing capability.
|
|
4175
|
-
for (const element of both(patternReadsByKey.get(
|
|
4176
|
-
const
|
|
4177
|
-
if (
|
|
4617
|
+
for (const element of both(patternReadsByKey.get(key), unknownPatternReads)) {
|
|
4618
|
+
const holder = bindingContainer(element);
|
|
4619
|
+
if (holder === null || !observe(holder).has(container))
|
|
4178
4620
|
continue;
|
|
4179
4621
|
if (element.dotDotDotToken || bindingElementKey(element) === null)
|
|
4180
4622
|
fail('unmodelled-container-read', element);
|
|
4181
4623
|
else
|
|
4182
|
-
|
|
4624
|
+
for (const reference of referencesOf(element))
|
|
4625
|
+
facts.add(reference);
|
|
4183
4626
|
}
|
|
4184
|
-
if (ts.isArrayLiteralExpression(
|
|
4627
|
+
if (ts.isArrayLiteralExpression(container) && (key === ELEMENT_KEY || isCanonicalIndex(key)))
|
|
4185
4628
|
for (const write of (valueIterationWrites ??= flow.allWrites.filter((write) => write.iterationOrigin?.mode === 'values'))) {
|
|
4186
4629
|
const origin = write.iterationOrigin;
|
|
4187
|
-
if (!observe(value(origin.source)).has(
|
|
4630
|
+
if (!observe(value(origin.source)).has(container))
|
|
4188
4631
|
continue;
|
|
4189
4632
|
if (origin.asynchronous || deferredIntrinsicProtocolLedgerOf(flow)?.require('Array', origin.source) !== true) {
|
|
4190
4633
|
fail('unproven-array-iteration', write.site);
|
|
@@ -4192,7 +4635,8 @@ const createSession = (checker, flow) => {
|
|
|
4192
4635
|
}
|
|
4193
4636
|
const declaration = write.target.declaration;
|
|
4194
4637
|
if (declaration && ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name))
|
|
4195
|
-
|
|
4638
|
+
for (const reference of referencesOf(declaration))
|
|
4639
|
+
facts.add(reference);
|
|
4196
4640
|
else
|
|
4197
4641
|
fail('unmodelled-iteration-binding', write.site);
|
|
4198
4642
|
}
|