@geastack/compiler 1.0.32 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli-coverage.js +2 -4
- package/dist/cli-emit.js +1 -1
- package/dist/cli-module-graph.js +1 -1
- package/dist/cli.js +2 -1
- package/dist/compiler.js +35 -28
- package/dist/conversion/array-view.js +9 -0
- package/dist/conversion/build.js +15 -8
- package/dist/conversion/dictionary-view.js +2 -2
- package/dist/conversion/nodes.d.ts +7 -0
- package/dist/conversion/nodes.js +58 -11
- package/dist/identity/ids.d.ts +4 -0
- package/dist/identity/ids.js +4 -0
- package/dist/ir/build.d.ts +4 -3
- package/dist/ir/build.js +14 -5
- package/dist/ir/call-dispatch.js +67 -7
- package/dist/ir/call-entry.js +1 -1
- package/dist/ir/callable-class-flow.d.ts +4 -0
- package/dist/ir/callable-class-flow.js +123 -1
- package/dist/ir/certify/parallel-region.js +698 -20
- package/dist/ir/certify.d.ts +3 -0
- package/dist/ir/certify.js +44 -9
- package/dist/ir/class-allocation-domain.js +2 -2
- package/dist/ir/class-construction-status.d.ts +10 -0
- package/dist/ir/class-construction-status.js +36 -0
- package/dist/ir/convert-carriers.d.ts +10 -1
- package/dist/ir/convert-carriers.js +18 -1
- package/dist/ir/dynamic-constructor-conversions.js +4 -2
- package/dist/ir/finite-iterator-close.d.ts +14 -0
- package/dist/ir/finite-iterator-close.js +50 -0
- package/dist/ir/host-template-conversions.js +9 -0
- package/dist/ir/lower-allocation.js +1 -1
- package/dist/ir/lower-flow.js +24 -3
- package/dist/ir/lower-operands.js +88 -7
- package/dist/ir/lower-protocol.js +1 -1
- package/dist/ir/lower.js +22 -6
- package/dist/ir/model.d.ts +41 -1
- package/dist/ir/native-accessor-definition.d.ts +3 -2
- package/dist/ir/native-accessor-definition.js +29 -10
- package/dist/ir/native-array-transport.js +2 -2
- package/dist/ir/native-field-view-domains.d.ts +23 -0
- package/dist/ir/native-field-view-domains.js +115 -9
- package/dist/ir/native-field-view-facts.d.ts +46 -2
- package/dist/ir/native-field-view-facts.js +159 -4
- package/dist/ir/native-iterable.d.ts +17 -0
- package/dist/ir/native-iterable.js +72 -0
- package/dist/ir/native-key-query.js +1 -1
- package/dist/ir/operation-conversions.js +15 -3
- package/dist/ir/program-conversions.js +2 -2
- package/dist/ir/publish-native-field-view-facts.js +9 -4
- package/dist/ir/pure-conversion-reuse.d.ts +58 -0
- package/dist/ir/pure-conversion-reuse.js +263 -0
- package/dist/ir/queries.js +1 -0
- package/dist/ir/reflection-demand.js +70 -18
- package/dist/ir/shake.js +2 -2
- package/dist/ir/unobserved-callable-inputs.d.ts +37 -0
- package/dist/ir/unobserved-callable-inputs.js +111 -0
- package/dist/native-signatures.d.ts +1 -1
- package/dist/native-signatures.js +27 -2
- package/dist/plugins/gea/component-classes.d.ts +2 -1
- package/dist/plugins/gea/component-classes.js +3 -3
- package/dist/plugins/gea/contract.d.ts +26 -3
- package/dist/plugins/gea/contract.js +42 -43
- package/dist/plugins/gea/host.d.ts +9 -0
- package/dist/plugins/gea/host.js +25 -4
- package/dist/plugins/gea/plugin.js +12 -6
- package/dist/plugins/gea/producer.d.ts +2 -2
- package/dist/plugins/gea/producer.js +2 -2
- package/dist/plugins/load.js +18 -1
- package/dist/plugins/model.d.ts +5 -0
- package/dist/plugins/native-iterable-providers.d.ts +18 -0
- package/dist/plugins/native-iterable-providers.js +51 -0
- package/dist/project-preparation.d.ts +8 -0
- package/dist/project-preparation.js +49 -7
- package/dist/projection/bindings.d.ts +13 -0
- package/dist/projection/bindings.js +20 -1
- package/dist/projection/classes.d.ts +4 -2
- package/dist/projection/classes.js +12 -5
- package/dist/representation/collections.js +2 -0
- package/dist/representation/derive.js +1 -0
- package/dist/representation/model.d.ts +2 -0
- package/dist/representation/model.js +1 -0
- package/dist/representation/policies.d.ts +2 -0
- package/dist/representation/primitive-domain.d.ts +1 -1
- package/dist/representation/primitive-domain.js +1 -1
- package/dist/representation/unassigned-binding-cells.d.ts +4 -3
- package/dist/representation/unassigned-binding-cells.js +19 -2
- package/dist/representation/union.js +6 -6
- package/dist/semantics/frontend.d.ts +2 -0
- package/dist/semantics/frontend.js +34 -5
- package/dist/semantics/host-methods.js +4 -1
- package/dist/semantics/jsx-runtime-provider.d.ts +5 -0
- package/dist/semantics/jsx-runtime-provider.js +16 -0
- package/dist/semantics/model/native-iterable.d.ts +14 -0
- package/dist/semantics/model/native-iterable.js +7 -0
- package/dist/semantics/model/operands.d.ts +30 -0
- package/dist/semantics/model/operations.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.d.ts +15 -0
- package/dist/semantics/model/primitive-domain.js +27 -4
- package/dist/semantics/module-resolution.js +13 -2
- package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
- package/dist/semantics/normalize/callback-parameter-contracts.d.ts +32 -4
- package/dist/semantics/normalize/callback-parameter-contracts.js +66 -6
- package/dist/semantics/normalize/census.d.ts +3 -0
- package/dist/semantics/normalize/census.js +17 -12
- package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +4 -1
- package/dist/semantics/normalize/deferred-intrinsic-protocols.js +29 -9
- package/dist/semantics/normalize/flow/callable-reach.js +94 -3
- package/dist/semantics/normalize/flow/component-solver.js +144 -55
- package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +9 -0
- package/dist/semantics/normalize/flow/member-call-forwarding.js +30 -4
- package/dist/semantics/normalize/flow/proof-hypotheses.d.ts +2 -0
- package/dist/semantics/normalize/flow/proof-hypotheses.js +27 -0
- package/dist/semantics/normalize/flow/source-callable-own-data.js +87 -14
- package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +2 -0
- package/dist/semantics/normalize/flow/source-commonjs-exports.js +2 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +17 -0
- package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +125 -0
- package/dist/semantics/normalize/flow/source-native-origin.d.ts +6 -0
- package/dist/semantics/normalize/flow/source-native-origin.js +38 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +37 -0
- package/dist/semantics/normalize/flow/source-proxy-operation.js +201 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +20 -0
- package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +73 -0
- package/dist/semantics/normalize/flow/source-value-session.d.ts +50 -1
- package/dist/semantics/normalize/flow/source-value-session.js +596 -57
- package/dist/semantics/normalize/flow/value-flow.d.ts +17 -0
- package/dist/semantics/normalize/flow/value-flow.js +84 -0
- package/dist/semantics/normalize/fresh-dictionary-storage.js +2 -2
- package/dist/semantics/normalize/fresh-table-last-use.d.ts +52 -0
- package/dist/semantics/normalize/fresh-table-last-use.js +129 -0
- package/dist/semantics/normalize/gating.js +5 -1
- package/dist/semantics/normalize/global-host-mutations.js +190 -13
- package/dist/semantics/normalize/identities.js +20 -1
- package/dist/semantics/normalize/local-bindings.js +2 -2
- package/dist/semantics/normalize/parameter-bindings.js +10 -1
- package/dist/semantics/normalize/producer-context.d.ts +5 -0
- package/dist/semantics/normalize/producers/binding-kind.js +2 -0
- package/dist/semantics/normalize/producers/cited-value-type.d.ts +2 -2
- package/dist/semantics/normalize/producers/cited-value-type.js +2 -2
- package/dist/semantics/normalize/producers/class-lifecycle.js +39 -9
- package/dist/semantics/normalize/producers/computations.js +36 -5
- package/dist/semantics/normalize/producers/conditional-guard.d.ts +6 -0
- package/dist/semantics/normalize/producers/conditional-guard.js +5 -0
- package/dist/semantics/normalize/producers/control.js +7 -1
- package/dist/semantics/normalize/producers/destructuring.js +8 -9
- package/dist/semantics/normalize/producers/invocations.js +55 -2
- package/dist/semantics/normalize/producers/properties.d.ts +13 -0
- package/dist/semantics/normalize/producers/properties.js +21 -3
- package/dist/semantics/normalize/producers/references.js +8 -4
- package/dist/semantics/normalize/reachability.d.ts +15 -3
- package/dist/semantics/normalize/reachability.js +128 -20
- package/dist/semantics/normalize/return-bindings.js +3 -3
- package/dist/semantics/normalize/source-native-iterable.d.ts +19 -0
- package/dist/semantics/normalize/source-native-iterable.js +74 -0
- package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
- package/dist/semantics/normalize/structural-declarations.js +1 -1
- package/dist/semantics/normalize/structural-indexed-access.js +9 -0
- package/dist/semantics/normalize/structural.js +11 -0
- package/dist/semantics/normalize/unshared-array-result.d.ts +42 -0
- package/dist/semantics/normalize/unshared-array-result.js +269 -0
- package/dist/semantics/package-sources.js +3 -2
- package/dist/semantics/program.d.ts +8 -0
- package/dist/semantics/program.js +55 -0
- package/dist/semantics/source-transform-exports.d.ts +8 -0
- package/dist/semantics/source-transform-exports.js +145 -0
- package/dist/semantics/source-transform-protocol.d.ts +22 -0
- package/dist/semantics/this-constructor-source-transform.js +19 -1
- package/dist/targets/cpp/class-layout.d.ts +2 -0
- package/dist/targets/cpp/class-layout.js +35 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +11 -1
- package/dist/targets/cpp/class-properties/emit-class-properties.js +33 -4
- package/dist/targets/cpp/conversions.js +6 -3
- package/dist/targets/cpp/emit-callable.js +73 -7
- package/dist/targets/cpp/emit-context.d.ts +23 -9
- package/dist/targets/cpp/emit-context.js +19 -8
- package/dist/targets/cpp/emit-equality.js +41 -1
- package/dist/targets/cpp/emit-exceptions.js +29 -11
- package/dist/targets/cpp/emit-iterator-object-view.js +2 -2
- package/dist/targets/cpp/emit-iterator.js +33 -9
- package/dist/targets/cpp/emit-live-field-view.js +6 -1
- package/dist/targets/cpp/emit-narrowing.d.ts +11 -3
- package/dist/targets/cpp/emit-narrowing.js +58 -18
- package/dist/targets/cpp/emit-native-field-view.d.ts +3 -1
- package/dist/targets/cpp/emit-native-field-view.js +84 -8
- package/dist/targets/cpp/emit-properties.d.ts +1 -0
- package/dist/targets/cpp/emit-properties.js +26 -7
- package/dist/targets/cpp/emit-protocol-iterator.js +5 -2
- package/dist/targets/cpp/emit-record-view.js +14 -2
- package/dist/targets/cpp/emit-tostring.js +23 -1
- package/dist/targets/cpp/emit-union-properties.js +1 -1
- package/dist/targets/cpp/emit.d.ts +1 -1
- package/dist/targets/cpp/emit.js +132 -21
- package/dist/targets/cpp/host/emit-host-invoke.js +2 -2
- package/dist/targets/cpp/host/emit-host-object.js +28 -2
- package/dist/targets/cpp/host/emit-host-properties.js +9 -1
- package/dist/targets/cpp/host/emit-host-value.d.ts +1 -1
- package/dist/targets/cpp/host/emit-host-value.js +8 -6
- package/dist/targets/cpp/host/host-members.js +2 -1
- package/dist/targets/cpp/prototype/emit-prototype-array.js +69 -5
- package/dist/targets/cpp/prototype/emit-prototype-invoke.js +9 -9
- package/dist/targets/cpp/prototype/emit-prototype-iterator.js +2 -2
- package/dist/targets/cpp/prototype/emit-prototype-promise.js +7 -7
- package/dist/targets/cpp/records.d.ts +1 -0
- package/dist/targets/cpp/records.js +16 -7
- package/dist/targets/cpp/translation-unit.js +30 -16
- package/package.json +8 -7
- package/src/targets/cpp/runtime/gea_dynamic_proxy.h +42 -3
- package/src/targets/cpp/runtime/gea_eval.h +3 -0
- package/src/targets/cpp/runtime/gea_runtime.h +2407 -684
|
@@ -1,13 +1,423 @@
|
|
|
1
1
|
import { operationOfResult } from '../../identity/ids.js';
|
|
2
2
|
import { classFamilyOverridesOf } from '../../projection/dispatch.js';
|
|
3
|
-
import { classMemberOf } from '../../projection/fields.js';
|
|
3
|
+
import { classMemberOf, classPrototypeMethodFamilyMutableOf } from '../../projection/fields.js';
|
|
4
4
|
import { allOperationsOf } from '../model.js';
|
|
5
5
|
const top = 'TOP';
|
|
6
6
|
const shared = 'SHARED';
|
|
7
7
|
const allFields = '#';
|
|
8
8
|
const unknownField = '*';
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The same monotone set-constraint solver, scaled to a whole program.
|
|
11
|
+
*
|
|
12
|
+
* The answer is the least fixed point of the constraints `add`, `copy` and
|
|
13
|
+
* `on` state, and that does not depend on the order facts propagate in, so
|
|
14
|
+
* everything here is about cost. The straightforward solver (kept below as
|
|
15
|
+
* `NaivePointsTo`, behind `GEA_PARALLEL_NAIVE_POINTS_TO=1`) queued one entry
|
|
16
|
+
* per (node, object) insertion and gave every node its own full set. On a
|
|
17
|
+
* large program the whole-program pass copies the escaped set `ESC` into
|
|
18
|
+
* every value that reads an unknown object -- tens of thousands of nodes, each
|
|
19
|
+
* holding the same couple of thousand objects: a hundred million set entries,
|
|
20
|
+
* a worklist past the engine's maximum array length, and a heap over 20 GB.
|
|
21
|
+
*
|
|
22
|
+
* - The hub. A copy FROM the hub node (`ESC`) does not copy its objects: the
|
|
23
|
+
* target subscribes to it instead. A subscribed node's set is its own
|
|
24
|
+
* objects plus the hub's, read as a union (`of`); its watchers see every hub
|
|
25
|
+
* object, the ones the hub already holds when it subscribes and every one it
|
|
26
|
+
* gains later; and whatever it copies to subscribes too, since a superset of
|
|
27
|
+
* a superset of the hub is one. Every observable answer -- `of`, and each
|
|
28
|
+
* watcher call -- is the one the materialised copy gave.
|
|
29
|
+
* - Difference propagation: a node is queued once, with the objects it gained
|
|
30
|
+
* since it was last processed, and those go along its edges and to its
|
|
31
|
+
* watchers together.
|
|
32
|
+
* - Cycle collapse: every node of a strongly connected copy component holds
|
|
33
|
+
* the same set at the fixed point, so the component is merged into one node
|
|
34
|
+
* (union-find). Components are found periodically with an iterative Tarjan
|
|
35
|
+
* pass over the current edges, since `on` keeps adding edges while the
|
|
36
|
+
* solve runs. The hub has no copy edges out of it, so it is in no cycle.
|
|
37
|
+
*
|
|
38
|
+
* A merge keeps every obligation of both nodes: each node's watchers see the
|
|
39
|
+
* other's objects (the hub's too, when only one was subscribed), each node's
|
|
40
|
+
* targets receive the other's objects, and a delta still pending on the
|
|
41
|
+
* absorbed node is delivered again from the merged one. Watchers and edges are
|
|
42
|
+
* idempotent, so a repeated delivery changes nothing.
|
|
43
|
+
*/
|
|
10
44
|
class PointsTo {
|
|
45
|
+
ids = new Map();
|
|
46
|
+
parent = [];
|
|
47
|
+
sets = [];
|
|
48
|
+
edges = [];
|
|
49
|
+
watchers = [];
|
|
50
|
+
pending = [];
|
|
51
|
+
queued = [];
|
|
52
|
+
subscribed = [];
|
|
53
|
+
subscribers = new Set();
|
|
54
|
+
fieldWatchers = new WeakSet();
|
|
55
|
+
/** The subscribers with a watcher: the only ones a hub delta has to visit. */
|
|
56
|
+
watchedSubscribers = new Set();
|
|
57
|
+
queue = [];
|
|
58
|
+
head = 0;
|
|
59
|
+
sinceCollapse = 0;
|
|
60
|
+
insertions = 0;
|
|
61
|
+
merges = 0;
|
|
62
|
+
hub;
|
|
63
|
+
static EMPTY = new Set();
|
|
64
|
+
static statsEnabled = process.env['GEA_PARALLEL_STATS'] !== undefined;
|
|
65
|
+
constructor(hubName = null) {
|
|
66
|
+
this.hub = hubName === null ? null : this.idOf(hubName);
|
|
67
|
+
}
|
|
68
|
+
/** `GEA_PARALLEL_STATS=1`: where the solve's sets and edges are. */
|
|
69
|
+
report(label) {
|
|
70
|
+
let reps = 0;
|
|
71
|
+
let entries = 0;
|
|
72
|
+
let edges = 0;
|
|
73
|
+
let topHolders = 0;
|
|
74
|
+
const largest = [];
|
|
75
|
+
const names = new Map();
|
|
76
|
+
for (const [name, id] of this.ids)
|
|
77
|
+
if (!names.has(id))
|
|
78
|
+
names.set(id, name);
|
|
79
|
+
for (let id = 0; id < this.parent.length; id++) {
|
|
80
|
+
if (this.parent[id] !== id)
|
|
81
|
+
continue;
|
|
82
|
+
reps++;
|
|
83
|
+
const size = this.sets[id].size;
|
|
84
|
+
entries += size;
|
|
85
|
+
edges += this.edges[id].size;
|
|
86
|
+
if (this.sets[id].has(top))
|
|
87
|
+
topHolders++;
|
|
88
|
+
largest.push([size, names.get(id) ?? String(id)]);
|
|
89
|
+
}
|
|
90
|
+
largest.sort((a, b) => b[0] - a[0]);
|
|
91
|
+
process.stderr.write(`[POINTS-TO ${label}] nodes=${this.parent.length} reps=${reps} entries=${entries} edges=${edges} topHolders=${topHolders} ` +
|
|
92
|
+
`subscribers=${this.subscribers.size} insertions=${this.insertions} merges=${this.merges} largest=${largest
|
|
93
|
+
.slice(0, 6)
|
|
94
|
+
.map(([size, name]) => `${name.slice(0, 40)}:${size}`)
|
|
95
|
+
.join(' ')}\n`);
|
|
96
|
+
}
|
|
97
|
+
idOf(node) {
|
|
98
|
+
let id = this.ids.get(node);
|
|
99
|
+
if (id === undefined) {
|
|
100
|
+
id = this.parent.length;
|
|
101
|
+
this.ids.set(node, id);
|
|
102
|
+
this.parent.push(id);
|
|
103
|
+
this.sets.push(new Set());
|
|
104
|
+
this.edges.push(new Set());
|
|
105
|
+
this.watchers.push([]);
|
|
106
|
+
this.pending.push(null);
|
|
107
|
+
this.queued.push(false);
|
|
108
|
+
this.subscribed.push(false);
|
|
109
|
+
}
|
|
110
|
+
return id;
|
|
111
|
+
}
|
|
112
|
+
find(id) {
|
|
113
|
+
let root = id;
|
|
114
|
+
while (this.parent[root] !== root)
|
|
115
|
+
root = this.parent[root];
|
|
116
|
+
while (this.parent[id] !== root) {
|
|
117
|
+
const next = this.parent[id];
|
|
118
|
+
this.parent[id] = root;
|
|
119
|
+
id = next;
|
|
120
|
+
}
|
|
121
|
+
return root;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Hand hub objects to a watcher of a subscribed node. A field watcher gets
|
|
125
|
+
* only `TOP`: a subscribed node holds `TOP` and every escaped object, and a
|
|
126
|
+
* store or load through an escaped object is subsumed by the same store or
|
|
127
|
+
* load through `TOP` (see the class comment), so expanding it per escaped
|
|
128
|
+
* object only builds field nodes the answer never reads.
|
|
129
|
+
*/
|
|
130
|
+
deliverHub(watcher, objects) {
|
|
131
|
+
if (this.fieldWatchers.has(watcher)) {
|
|
132
|
+
for (const object of objects)
|
|
133
|
+
if (object === top) {
|
|
134
|
+
watcher(object);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
for (const object of objects)
|
|
140
|
+
watcher(object);
|
|
141
|
+
}
|
|
142
|
+
enqueue(id) {
|
|
143
|
+
if (this.queued[id])
|
|
144
|
+
return;
|
|
145
|
+
this.queued[id] = true;
|
|
146
|
+
this.queue.push(id);
|
|
147
|
+
}
|
|
148
|
+
addTo(id, object) {
|
|
149
|
+
const set = this.sets[id];
|
|
150
|
+
if (set.has(object))
|
|
151
|
+
return;
|
|
152
|
+
// Already in a subscribed node through the hub, and its watchers saw it there.
|
|
153
|
+
if (this.subscribed[id] && this.sets[this.hub].has(object))
|
|
154
|
+
return;
|
|
155
|
+
set.add(object);
|
|
156
|
+
const delta = this.pending[id];
|
|
157
|
+
if (delta)
|
|
158
|
+
delta.push(object);
|
|
159
|
+
else
|
|
160
|
+
this.pending[id] = [object];
|
|
161
|
+
this.sinceCollapse++;
|
|
162
|
+
this.insertions++;
|
|
163
|
+
if (PointsTo.statsEnabled && this.insertions % 2_000_000 === 0)
|
|
164
|
+
this.report('progress');
|
|
165
|
+
this.enqueue(id);
|
|
166
|
+
}
|
|
167
|
+
/** Subscribe `start` and everything it copies to: each is a superset of the hub. */
|
|
168
|
+
subscribe(start) {
|
|
169
|
+
const work = [start];
|
|
170
|
+
while (work.length > 0) {
|
|
171
|
+
const id = this.find(work.pop());
|
|
172
|
+
if (this.subscribed[id])
|
|
173
|
+
continue;
|
|
174
|
+
this.subscribed[id] = true;
|
|
175
|
+
this.subscribers.add(id);
|
|
176
|
+
if (this.watchers[id].length > 0)
|
|
177
|
+
this.watchedSubscribers.add(id);
|
|
178
|
+
const hubObjects = [...this.sets[this.hub]];
|
|
179
|
+
const watching = this.watchers[id];
|
|
180
|
+
for (let index = 0; index < watching.length; index++)
|
|
181
|
+
this.deliverHub(watching[index], hubObjects);
|
|
182
|
+
for (const target of this.edges[id])
|
|
183
|
+
work.push(target);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
of(node) {
|
|
187
|
+
const id = this.ids.get(node);
|
|
188
|
+
if (id === undefined)
|
|
189
|
+
return PointsTo.EMPTY;
|
|
190
|
+
const rep = this.find(id);
|
|
191
|
+
if (!this.subscribed[rep])
|
|
192
|
+
return this.sets[rep];
|
|
193
|
+
const union = new Set(this.sets[this.hub]);
|
|
194
|
+
for (const object of this.sets[rep])
|
|
195
|
+
union.add(object);
|
|
196
|
+
return union;
|
|
197
|
+
}
|
|
198
|
+
add(node, object) {
|
|
199
|
+
this.addTo(this.find(this.idOf(node)), object);
|
|
200
|
+
}
|
|
201
|
+
copy(from, to) {
|
|
202
|
+
const source = this.find(this.idOf(from));
|
|
203
|
+
const target = this.find(this.idOf(to));
|
|
204
|
+
if (source === target)
|
|
205
|
+
return;
|
|
206
|
+
if (source === this.hub) {
|
|
207
|
+
this.subscribe(target);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const targets = this.edges[source];
|
|
211
|
+
if (targets.has(target))
|
|
212
|
+
return;
|
|
213
|
+
targets.add(target);
|
|
214
|
+
for (const object of this.sets[source])
|
|
215
|
+
this.addTo(target, object);
|
|
216
|
+
if (this.subscribed[source])
|
|
217
|
+
this.subscribe(target);
|
|
218
|
+
}
|
|
219
|
+
on(node, watcher, kind) {
|
|
220
|
+
const id = this.find(this.idOf(node));
|
|
221
|
+
if (kind === 'field')
|
|
222
|
+
this.fieldWatchers.add(watcher);
|
|
223
|
+
this.watchers[id].push(watcher);
|
|
224
|
+
if (this.subscribed[id])
|
|
225
|
+
this.watchedSubscribers.add(id);
|
|
226
|
+
const own = [...this.sets[id]];
|
|
227
|
+
const hubObjects = this.subscribed[id] ? [...this.sets[this.hub]] : [];
|
|
228
|
+
for (const object of own)
|
|
229
|
+
watcher(object);
|
|
230
|
+
this.deliverHub(watcher, hubObjects);
|
|
231
|
+
}
|
|
232
|
+
get busy() {
|
|
233
|
+
return this.head < this.queue.length;
|
|
234
|
+
}
|
|
235
|
+
solve() {
|
|
236
|
+
while (this.head < this.queue.length) {
|
|
237
|
+
const id = this.queue[this.head++];
|
|
238
|
+
this.queued[id] = false;
|
|
239
|
+
if (this.head > 65536 && this.head * 2 > this.queue.length) {
|
|
240
|
+
this.queue = this.queue.slice(this.head);
|
|
241
|
+
this.head = 0;
|
|
242
|
+
}
|
|
243
|
+
if (this.parent[id] !== id)
|
|
244
|
+
continue;
|
|
245
|
+
const delta = this.pending[id];
|
|
246
|
+
if (!delta)
|
|
247
|
+
continue;
|
|
248
|
+
this.pending[id] = null;
|
|
249
|
+
for (const raw of [...this.edges[id]]) {
|
|
250
|
+
const target = this.find(raw);
|
|
251
|
+
if (target === id)
|
|
252
|
+
continue;
|
|
253
|
+
for (const object of delta)
|
|
254
|
+
this.addTo(target, object);
|
|
255
|
+
}
|
|
256
|
+
const watching = this.watchers[id];
|
|
257
|
+
for (let index = 0; index < watching.length; index++)
|
|
258
|
+
for (const object of delta)
|
|
259
|
+
watching[index](object);
|
|
260
|
+
// What the hub gains, every subscriber holds: its watchers see it.
|
|
261
|
+
if (id === this.hub)
|
|
262
|
+
for (const subscriber of [...this.watchedSubscribers]) {
|
|
263
|
+
if (this.parent[subscriber] !== subscriber)
|
|
264
|
+
continue;
|
|
265
|
+
const subscribedWatchers = this.watchers[subscriber];
|
|
266
|
+
for (let index = 0; index < subscribedWatchers.length; index++)
|
|
267
|
+
this.deliverHub(subscribedWatchers[index], delta);
|
|
268
|
+
}
|
|
269
|
+
if (this.sinceCollapse > 4_000_000) {
|
|
270
|
+
this.sinceCollapse = 0;
|
|
271
|
+
this.collapseCycles();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (PointsTo.statsEnabled)
|
|
275
|
+
this.report('solved');
|
|
276
|
+
}
|
|
277
|
+
/** Merge every strongly connected copy component into one node (iterative Tarjan). */
|
|
278
|
+
collapseCycles() {
|
|
279
|
+
const count = this.parent.length;
|
|
280
|
+
const index = new Int32Array(count).fill(-1);
|
|
281
|
+
const low = new Int32Array(count);
|
|
282
|
+
const onStack = new Uint8Array(count);
|
|
283
|
+
const stack = [];
|
|
284
|
+
let next = 0;
|
|
285
|
+
const successors = (id) => {
|
|
286
|
+
const canonical = new Set();
|
|
287
|
+
for (const raw of this.edges[id]) {
|
|
288
|
+
const target = this.find(raw);
|
|
289
|
+
if (target !== id)
|
|
290
|
+
canonical.add(target);
|
|
291
|
+
}
|
|
292
|
+
// Canonicalize the edge set while walking it: merged targets collapse.
|
|
293
|
+
this.edges[id] = canonical;
|
|
294
|
+
return [...canonical];
|
|
295
|
+
};
|
|
296
|
+
for (let start = 0; start < count; start++) {
|
|
297
|
+
if (this.parent[start] !== start || index[start] !== -1 || this.edges[start].size === 0)
|
|
298
|
+
continue;
|
|
299
|
+
const frames = [];
|
|
300
|
+
const open = (id) => {
|
|
301
|
+
index[id] = low[id] = next++;
|
|
302
|
+
stack.push(id);
|
|
303
|
+
onStack[id] = 1;
|
|
304
|
+
frames.push({ id, out: successors(id), at: 0 });
|
|
305
|
+
};
|
|
306
|
+
open(start);
|
|
307
|
+
while (frames.length > 0) {
|
|
308
|
+
const frame = frames[frames.length - 1];
|
|
309
|
+
if (frame.at < frame.out.length) {
|
|
310
|
+
const target = frame.out[frame.at++];
|
|
311
|
+
if (index[target] === -1)
|
|
312
|
+
open(target);
|
|
313
|
+
else if (onStack[target])
|
|
314
|
+
low[frame.id] = Math.min(low[frame.id], index[target]);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
frames.pop();
|
|
318
|
+
if (frames.length > 0) {
|
|
319
|
+
const caller = frames[frames.length - 1];
|
|
320
|
+
low[caller.id] = Math.min(low[caller.id], low[frame.id]);
|
|
321
|
+
}
|
|
322
|
+
if (low[frame.id] !== index[frame.id])
|
|
323
|
+
continue;
|
|
324
|
+
const members = [];
|
|
325
|
+
let member;
|
|
326
|
+
do {
|
|
327
|
+
member = stack.pop();
|
|
328
|
+
onStack[member] = 0;
|
|
329
|
+
members.push(member);
|
|
330
|
+
} while (member !== frame.id);
|
|
331
|
+
if (members.length > 1)
|
|
332
|
+
this.mergeAll(members);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
mergeAll(members) {
|
|
337
|
+
// The hub is never absorbed; otherwise the member holding the largest set
|
|
338
|
+
// absorbs the rest: the fewest copies.
|
|
339
|
+
let into = members[0];
|
|
340
|
+
for (const member of members)
|
|
341
|
+
if (this.sets[member].size > this.sets[into].size)
|
|
342
|
+
into = member;
|
|
343
|
+
if (this.hub !== null && members.includes(this.hub))
|
|
344
|
+
into = this.hub;
|
|
345
|
+
for (const member of members)
|
|
346
|
+
if (member !== into)
|
|
347
|
+
this.merge(member, into);
|
|
348
|
+
}
|
|
349
|
+
merge(from, into) {
|
|
350
|
+
this.merges++;
|
|
351
|
+
const absorbed = this.sets[from];
|
|
352
|
+
const kept = this.sets[into];
|
|
353
|
+
const hubObjects = this.hub === null ? PointsTo.EMPTY : this.sets[this.hub];
|
|
354
|
+
// `from`'s watchers have seen `from`'s objects; they owe `into`'s others,
|
|
355
|
+
// and the hub's when only `into` was subscribed.
|
|
356
|
+
const owedToAbsorbed = [...kept].filter((object) => !absorbed.has(object));
|
|
357
|
+
const hubSnapshot = [...hubObjects];
|
|
358
|
+
for (const watcher of this.watchers[from]) {
|
|
359
|
+
for (const object of owedToAbsorbed)
|
|
360
|
+
watcher(object);
|
|
361
|
+
if (this.subscribed[into] && !this.subscribed[from])
|
|
362
|
+
this.deliverHub(watcher, hubSnapshot);
|
|
363
|
+
}
|
|
364
|
+
// Likewise `into`'s watchers owe the hub when only `from` was subscribed.
|
|
365
|
+
if (this.subscribed[from] && !this.subscribed[into])
|
|
366
|
+
for (const watcher of this.watchers[into])
|
|
367
|
+
this.deliverHub(watcher, hubSnapshot);
|
|
368
|
+
const subscribed = this.subscribed[from] || this.subscribed[into];
|
|
369
|
+
// `from`'s targets have `from`'s objects; they owe `into`'s too.
|
|
370
|
+
for (const raw of this.edges[from]) {
|
|
371
|
+
const target = this.find(raw);
|
|
372
|
+
if (target === from || target === into)
|
|
373
|
+
continue;
|
|
374
|
+
if (!this.edges[into].has(target))
|
|
375
|
+
for (const object of kept)
|
|
376
|
+
this.addTo(target, object);
|
|
377
|
+
this.edges[into].add(target);
|
|
378
|
+
}
|
|
379
|
+
this.parent[from] = into;
|
|
380
|
+
this.subscribed[from] = false;
|
|
381
|
+
this.subscribers.delete(from);
|
|
382
|
+
this.watchedSubscribers.delete(from);
|
|
383
|
+
if (subscribed && !this.subscribed[into]) {
|
|
384
|
+
this.subscribed[into] = true;
|
|
385
|
+
this.subscribers.add(into);
|
|
386
|
+
}
|
|
387
|
+
// `into`'s targets and watchers owe `from`'s objects: new to `into`, they
|
|
388
|
+
// propagate as its delta. `from`'s undelivered delta is delivered again
|
|
389
|
+
// from `into`, to `from`'s former targets and watchers among the rest.
|
|
390
|
+
for (const object of absorbed)
|
|
391
|
+
this.addTo(into, object);
|
|
392
|
+
const undelivered = this.pending[from];
|
|
393
|
+
if (undelivered) {
|
|
394
|
+
let delta = this.pending[into];
|
|
395
|
+
if (!delta)
|
|
396
|
+
this.pending[into] = delta = [];
|
|
397
|
+
for (const object of undelivered)
|
|
398
|
+
delta.push(object);
|
|
399
|
+
this.enqueue(into);
|
|
400
|
+
}
|
|
401
|
+
for (const watcher of this.watchers[from])
|
|
402
|
+
this.watchers[into].push(watcher);
|
|
403
|
+
if (subscribed && this.watchers[into].length > 0)
|
|
404
|
+
this.watchedSubscribers.add(into);
|
|
405
|
+
this.edges[into].delete(into);
|
|
406
|
+
this.edges[into].delete(from);
|
|
407
|
+
this.sets[from] = new Set();
|
|
408
|
+
this.edges[from] = new Set();
|
|
409
|
+
this.watchers[from] = [];
|
|
410
|
+
this.pending[from] = null;
|
|
411
|
+
// A subscribed node's targets are subscribed, the merged ones included.
|
|
412
|
+
if (subscribed)
|
|
413
|
+
for (const target of [...this.edges[into]])
|
|
414
|
+
this.subscribe(target);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/** `GEA_PARALLEL_NAIVE_POINTS_TO=1` runs the original solver, to compare verdicts. */
|
|
418
|
+
const newPointsTo = (hub = null) => process.env['GEA_PARALLEL_NAIVE_POINTS_TO'] === '1' ? new NaivePointsTo() : new PointsTo(hub);
|
|
419
|
+
/** Monotone set-constraint solver: nodes hold sets of abstract objects; edges and watchers propagate. */
|
|
420
|
+
class NaivePointsTo {
|
|
11
421
|
sets = new Map();
|
|
12
422
|
edges = new Map();
|
|
13
423
|
watchers = new Map();
|
|
@@ -36,7 +446,7 @@ class PointsTo {
|
|
|
36
446
|
for (const object of this.of(from))
|
|
37
447
|
this.add(to, object);
|
|
38
448
|
}
|
|
39
|
-
on(node, watcher) {
|
|
449
|
+
on(node, watcher, _kind) {
|
|
40
450
|
let list = this.watchers.get(node);
|
|
41
451
|
if (!list)
|
|
42
452
|
this.watchers.set(node, (list = []));
|
|
@@ -66,6 +476,18 @@ const returnNode = (functionId) => `r|${functionId}`;
|
|
|
66
476
|
const fieldNode = (object, key) => `f|${object}|${key}`;
|
|
67
477
|
const functionObject = (functionId) => `F|${functionId}`;
|
|
68
478
|
const functionOf = (object) => (object.startsWith('F|') ? object.slice(2) : null);
|
|
479
|
+
/**
|
|
480
|
+
* In a region run, a program function's own object (a prototype method read
|
|
481
|
+
* off a class instance) existed before the region exactly as `SHARED` did: it
|
|
482
|
+
* is named so the call can enter it, and is shared for every other purpose.
|
|
483
|
+
*/
|
|
484
|
+
const preexisting = (object) => object === shared || object.startsWith('F|');
|
|
485
|
+
const holdsPreexisting = (objects) => {
|
|
486
|
+
for (const object of objects)
|
|
487
|
+
if (preexisting(object))
|
|
488
|
+
return true;
|
|
489
|
+
return false;
|
|
490
|
+
};
|
|
69
491
|
/** The carrier under any presence or borrow wrapper: what a member read on the value dispatches on. */
|
|
70
492
|
const carrierOf = (representation) => representation.kind === 'optional'
|
|
71
493
|
? carrierOf(representation.payload)
|
|
@@ -149,6 +571,54 @@ const hostDetail = (protocol, member) => protocol === 'Console'
|
|
|
149
571
|
: protocol === 'Math' && member === 'random'
|
|
150
572
|
? 'calls Math.random, whose answer depends on how many draws other tasks made first'
|
|
151
573
|
: `calls ${protocol}.${member}, which is not known to be free of shared effects`;
|
|
574
|
+
/** A class id without its specialization suffix (`373@0` is a copy of `373`). */
|
|
575
|
+
const genericRootOf = (declaration) => {
|
|
576
|
+
const at = declaration.indexOf('@');
|
|
577
|
+
return at === -1 ? declaration : declaration.slice(0, at);
|
|
578
|
+
};
|
|
579
|
+
/** The classes a carrier may hold an instance of, through presence, borrow and union wrappers (as `projection/classes.ts` marks them). */
|
|
580
|
+
const classRefsOf = (representation, into = new Set()) => {
|
|
581
|
+
if (representation.kind === 'optional')
|
|
582
|
+
return classRefsOf(representation.payload, into);
|
|
583
|
+
if (representation.kind === 'borrowed-ref')
|
|
584
|
+
return classRefsOf(representation.referent, into);
|
|
585
|
+
if (representation.kind === 'tagged-union')
|
|
586
|
+
for (const arm of representation.arms)
|
|
587
|
+
classRefsOf(arm.value, into);
|
|
588
|
+
else if (representation.kind === 'class-ref')
|
|
589
|
+
into.add(genericRootOf(representation.declaration));
|
|
590
|
+
return into;
|
|
591
|
+
};
|
|
592
|
+
/** Carriers that never hold a callable: primitives and objects with no [[Call]]. Everything else may. */
|
|
593
|
+
const nonCallableKinds = new Set([
|
|
594
|
+
'scalar',
|
|
595
|
+
'string',
|
|
596
|
+
'null',
|
|
597
|
+
'undefined',
|
|
598
|
+
'void',
|
|
599
|
+
'symbol',
|
|
600
|
+
'array-object',
|
|
601
|
+
'typed-array',
|
|
602
|
+
'array-buffer',
|
|
603
|
+
'shared-array-buffer',
|
|
604
|
+
'data-view',
|
|
605
|
+
'dense-buffer',
|
|
606
|
+
'keyed-collection',
|
|
607
|
+
'record',
|
|
608
|
+
'record-with-index',
|
|
609
|
+
'class-ref',
|
|
610
|
+
'native-record-ref',
|
|
611
|
+
'native-sequence',
|
|
612
|
+
'iterator',
|
|
613
|
+
'promise'
|
|
614
|
+
]);
|
|
615
|
+
const neverCallable = (representation) => representation.kind === 'optional'
|
|
616
|
+
? neverCallable(representation.payload)
|
|
617
|
+
: representation.kind === 'borrowed-ref'
|
|
618
|
+
? neverCallable(representation.referent)
|
|
619
|
+
: representation.kind === 'tagged-union'
|
|
620
|
+
? representation.arms.every((arm) => neverCallable(arm.value))
|
|
621
|
+
: nonCallableKinds.has(representation.kind);
|
|
152
622
|
/** The host function or external a binding renders as, or `null` for a program binding. */
|
|
153
623
|
const hostNameOf = (placement) => {
|
|
154
624
|
const storage = placement?.storage;
|
|
@@ -162,6 +632,12 @@ const hostNameOf = (placement) => {
|
|
|
162
632
|
};
|
|
163
633
|
const errorProtocol = (protocol) => /^[A-Za-z]*ErrorConstructor$/.test(protocol);
|
|
164
634
|
const hostErrorClasses = /^(Eval|Range|Reference|Syntax|Type|URI)?Error$/;
|
|
635
|
+
/** Host constructors whose result is a new buffer: they read a length (and an options record) and nothing else. */
|
|
636
|
+
const bufferConstructors = /^(Shared)?ArrayBufferConstructor$/;
|
|
637
|
+
/** Host constructors whose result is a view: of a buffer argument, or of a fresh buffer copied from or sized by the argument. */
|
|
638
|
+
const viewConstructors = /^((Int|Uint)(8|16|32)|Uint8Clamped|Float(16|32|64)|Big(Int|Uint)64)ArrayConstructor$|^DataViewConstructor$/;
|
|
639
|
+
/** The argument carriers a view constructor copies its elements out of, or reads as a length, rather than viewing. */
|
|
640
|
+
const copiedViewSources = new Set(['scalar', 'array-object', 'typed-array']);
|
|
165
641
|
/**
|
|
166
642
|
* Operations that only move a value: a boxed one passes through them without
|
|
167
643
|
* any of its dynamic operations running. A thrown value is boxed into the
|
|
@@ -178,6 +654,7 @@ const programOf = (input) => {
|
|
|
178
654
|
const definitions = new Map();
|
|
179
655
|
const owners = new Map();
|
|
180
656
|
const writers = new Map();
|
|
657
|
+
const writtenValues = new Map();
|
|
181
658
|
for (const body of input.bodies.values()) {
|
|
182
659
|
const list = byFunction.get(body.sourceOwner) ?? [];
|
|
183
660
|
list.push(body);
|
|
@@ -191,6 +668,9 @@ const programOf = (input) => {
|
|
|
191
668
|
const set = writers.get(operation.declaration) ?? new Set();
|
|
192
669
|
set.add(body);
|
|
193
670
|
writers.set(operation.declaration, set);
|
|
671
|
+
const values = writtenValues.get(operation.declaration) ?? [];
|
|
672
|
+
values.push(operation.value.value);
|
|
673
|
+
writtenValues.set(operation.declaration, values);
|
|
194
674
|
}
|
|
195
675
|
}
|
|
196
676
|
}
|
|
@@ -263,10 +743,39 @@ const programOf = (input) => {
|
|
|
263
743
|
const explicit = chain.find((layout) => layout.constructor !== null);
|
|
264
744
|
return explicit?.constructor ? [explicit.constructor] : [];
|
|
265
745
|
};
|
|
266
|
-
|
|
267
|
-
|
|
746
|
+
/**
|
|
747
|
+
* The class `new` constructs when normalization published no target proof
|
|
748
|
+
* but the callee is a read of the class's own binding: `new T.Vector3()`
|
|
749
|
+
* through a module namespace import, which the IR resolves to the class
|
|
750
|
+
* declaration's cell while the proof only follows bare identifiers and
|
|
751
|
+
* source namespaces. The binding is the proof here: every write to it
|
|
752
|
+
* anywhere in the program stores that class's constructor (its own
|
|
753
|
+
* declaration evaluating), so the read can only be that constructor, and
|
|
754
|
+
* `new.target` is the same value.
|
|
755
|
+
*/
|
|
756
|
+
const classNamedByCallee = (operation) => {
|
|
757
|
+
if (operation.newTarget.value !== operation.callee.value)
|
|
758
|
+
return null;
|
|
759
|
+
const callee = definitions.get(operation.callee.value);
|
|
760
|
+
if (callee?.kind !== 'binding-read' || !input.classes.has(callee.declaration))
|
|
761
|
+
return null;
|
|
762
|
+
if (hostNameOf(input.placements.get(callee.declaration)) !== null)
|
|
268
763
|
return null;
|
|
269
|
-
const
|
|
764
|
+
for (const value of writtenValues.get(callee.declaration) ?? []) {
|
|
765
|
+
const written = definitions.get(value);
|
|
766
|
+
if (written?.kind !== 'allocate-constructor' || written.declaration !== callee.declaration)
|
|
767
|
+
return null;
|
|
768
|
+
}
|
|
769
|
+
return callee.declaration;
|
|
770
|
+
};
|
|
771
|
+
const constructionOf = (operation) => {
|
|
772
|
+
if (operation.target.kind === 'open') {
|
|
773
|
+
const named = classNamedByCallee(operation);
|
|
774
|
+
return named === null ? null : constructionOfTargets([{ kind: 'implicit-source-constructor', classDeclaration: named }]);
|
|
775
|
+
}
|
|
776
|
+
return constructionOfTargets(operation.target.kind === 'exact' ? [operation.target.target] : operation.target.targets);
|
|
777
|
+
};
|
|
778
|
+
const constructionOfTargets = (targets) => {
|
|
270
779
|
const constructors = [];
|
|
271
780
|
const initializers = [];
|
|
272
781
|
for (const target of targets) {
|
|
@@ -303,10 +812,145 @@ const programOf = (input) => {
|
|
|
303
812
|
const storage = callee?.kind === 'binding-read' ? input.placements.get(callee.declaration)?.storage : undefined;
|
|
304
813
|
return storage?.kind === 'host-class' && hostErrorClasses.test(storage.linkageName);
|
|
305
814
|
};
|
|
815
|
+
const hostConstructionOf = (operation) => {
|
|
816
|
+
const callee = carrierOf(operation.callee.representation);
|
|
817
|
+
const protocols = callee.kind === 'native-handle' ? [callee.protocol, callee.native ?? ''] : [];
|
|
818
|
+
const view = protocols.some((protocol) => viewConstructors.test(protocol));
|
|
819
|
+
const definition = definitions.get(operation.callee.value);
|
|
820
|
+
// A buffer or view constructor read straight from its host binding: a
|
|
821
|
+
// program value typed as one may be a subclass whose constructor is code.
|
|
822
|
+
const freshHost = operation.newTarget.value === operation.callee.value &&
|
|
823
|
+
definition !== undefined &&
|
|
824
|
+
externalOf(definition) !== null &&
|
|
825
|
+
protocols.some((protocol) => bufferConstructors.test(protocol) || viewConstructors.test(protocol));
|
|
826
|
+
if (!operation.hostFrame && !constructsHostError(operation) && !freshHost)
|
|
827
|
+
return null;
|
|
828
|
+
// A view over a buffer shares the buffer's storage. Only a scalar
|
|
829
|
+
// (a length), an array or another typed array is copied rather than viewed.
|
|
830
|
+
const aliasing = operation.arguments
|
|
831
|
+
.filter((argument) => {
|
|
832
|
+
const kind = carrierOf(argument.representation).kind;
|
|
833
|
+
return kind === 'array-buffer' || kind === 'shared-array-buffer' || (view && !copiedViewSources.has(kind));
|
|
834
|
+
})
|
|
835
|
+
.map((argument) => argument.value);
|
|
836
|
+
return { aliasing };
|
|
837
|
+
};
|
|
838
|
+
/** `declaration`, its bases, and every class extending it: the classes whose instances a receiver of it may share an own property with. */
|
|
839
|
+
const relatives = new Map();
|
|
840
|
+
const relativesOf = (declaration) => {
|
|
841
|
+
const known = relatives.get(declaration);
|
|
842
|
+
if (known)
|
|
843
|
+
return known;
|
|
844
|
+
const chainOf = (start) => {
|
|
845
|
+
const chain = [];
|
|
846
|
+
for (let current = start; current !== null && !chain.includes(current); current = input.classes.get(current)?.base ?? null)
|
|
847
|
+
chain.push(current);
|
|
848
|
+
return chain;
|
|
849
|
+
};
|
|
850
|
+
const root = genericRootOf(declaration);
|
|
851
|
+
const related = new Set(chainOf(declaration).map(genericRootOf));
|
|
852
|
+
for (const candidate of input.classes.keys())
|
|
853
|
+
if (chainOf(candidate).some((member) => genericRootOf(member) === root))
|
|
854
|
+
related.add(genericRootOf(candidate));
|
|
855
|
+
relatives.set(declaration, related);
|
|
856
|
+
return related;
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* Every operation that may give a class instance an own property, the way
|
|
860
|
+
* `projection/classes.ts` finds the writes that shadow a prototype method:
|
|
861
|
+
* a property write or definition on a class-typed receiver, an object
|
|
862
|
+
* literal laid out as a class, a spread into one, and the intrinsic
|
|
863
|
+
* mutations (`Object.assign`, `Reflect.set`, ...) on a class-typed target.
|
|
864
|
+
* `key` is `null` when the write may name any key; `callable` whether the
|
|
865
|
+
* value written may be a function.
|
|
866
|
+
*/
|
|
867
|
+
let ownWrites = null;
|
|
868
|
+
const ownWritesOf = () => {
|
|
869
|
+
if (ownWrites)
|
|
870
|
+
return ownWrites;
|
|
871
|
+
const writes = [];
|
|
872
|
+
const constantKey = (key) => {
|
|
873
|
+
const definition = definitions.get(key.value);
|
|
874
|
+
return definition?.kind === 'constant' && (definition.literal === 'string' || definition.literal === 'number')
|
|
875
|
+
? definition.text
|
|
876
|
+
: null;
|
|
877
|
+
};
|
|
878
|
+
for (const body of input.bodies.values())
|
|
879
|
+
for (const operation of operationsOf(body)) {
|
|
880
|
+
if (operation.kind === 'set' || operation.kind === 'define-own-property') {
|
|
881
|
+
const classes = classRefsOf(operation.receiver.representation);
|
|
882
|
+
if (classes.size > 0)
|
|
883
|
+
writes.push({ classes, key: constantKey(operation.key), callable: !neverCallable(operation.value.representation) });
|
|
884
|
+
}
|
|
885
|
+
else if (operation.kind === 'allocate-record') {
|
|
886
|
+
const classes = classRefsOf(operation.result.representation);
|
|
887
|
+
if (classes.size > 0)
|
|
888
|
+
for (const field of operation.fields)
|
|
889
|
+
writes.push({ classes, key: field.key, callable: !neverCallable(field.value.representation) });
|
|
890
|
+
}
|
|
891
|
+
else if (operation.kind === 'spread-copy') {
|
|
892
|
+
const classes = classRefsOf(operation.receiver.representation);
|
|
893
|
+
if (classes.size > 0)
|
|
894
|
+
writes.push({ classes, key: null, callable: true });
|
|
895
|
+
}
|
|
896
|
+
else if (operation.kind === 'call' && operation.lineage !== null) {
|
|
897
|
+
const semantic = input.graph.operations.get(operationOfResult(operation.lineage));
|
|
898
|
+
const target = operation.arguments[0];
|
|
899
|
+
if (semantic?.family === 'invocation' && semantic.intrinsicMutation && target) {
|
|
900
|
+
const classes = classRefsOf(target.representation);
|
|
901
|
+
if (classes.size > 0)
|
|
902
|
+
writes.push({ classes, key: null, callable: true });
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
ownWrites = writes;
|
|
907
|
+
return writes;
|
|
908
|
+
};
|
|
909
|
+
const prototypeMethods = new Map();
|
|
910
|
+
const prototypeMethodsOf = (operation) => {
|
|
911
|
+
const known = prototypeMethods.get(operation);
|
|
912
|
+
if (known !== undefined)
|
|
913
|
+
return known;
|
|
914
|
+
const answer = (() => {
|
|
915
|
+
// The IR's dispatch census already named this read: its sealed fact wins.
|
|
916
|
+
if (operation.closedCallable)
|
|
917
|
+
return null;
|
|
918
|
+
const key = definitions.get(operation.key.value);
|
|
919
|
+
if (key?.kind !== 'constant' || key.literal !== 'string')
|
|
920
|
+
return null;
|
|
921
|
+
const receiver = carrierOf(operation.receiver.representation);
|
|
922
|
+
if (receiver.kind !== 'class-ref')
|
|
923
|
+
return null;
|
|
924
|
+
const site = classMemberOf(input.classes, receiver.declaration, key.text);
|
|
925
|
+
if (site?.kind !== 'method' || site.method.callable === null)
|
|
926
|
+
return null;
|
|
927
|
+
// A subclass override, a replaced prototype method, or a prototype the
|
|
928
|
+
// program uses outside the typed method protocol: the prototype a
|
|
929
|
+
// receiver reaches is not this one method.
|
|
930
|
+
if (classFamilyOverridesOf(input.classes, receiver.declaration, key.text).length > 0)
|
|
931
|
+
return null;
|
|
932
|
+
if (classPrototypeMethodFamilyMutableOf(input.classes, receiver.declaration, key.text))
|
|
933
|
+
return null;
|
|
934
|
+
const related = relativesOf(receiver.declaration);
|
|
935
|
+
for (const declaration of input.classes.keys())
|
|
936
|
+
if (related.has(genericRootOf(declaration)) && (input.classes.get(declaration)?.prototypeUnsupportedUses?.length ?? 0) > 0)
|
|
937
|
+
return null;
|
|
938
|
+
// Complete when no own property of this key on any related instance can
|
|
939
|
+
// be a function: then calling the read can only run the method (or
|
|
940
|
+
// throw on a non-callable shadow, which runs nothing).
|
|
941
|
+
const complete = !ownWritesOf().some((write) => write.callable &&
|
|
942
|
+
(write.key === null || write.key === key.text) &&
|
|
943
|
+
[...write.classes].some((declaration) => related.has(declaration)));
|
|
944
|
+
return { functions: [site.method.callable.replace(/@[^|]*$/, '')], complete };
|
|
945
|
+
})();
|
|
946
|
+
prototypeMethods.set(operation, answer);
|
|
947
|
+
return answer;
|
|
948
|
+
};
|
|
306
949
|
return {
|
|
307
950
|
constructionOf,
|
|
308
951
|
superConstructorOf,
|
|
309
|
-
|
|
952
|
+
hostConstructionOf,
|
|
953
|
+
prototypeMethodsOf,
|
|
310
954
|
bodiesOf,
|
|
311
955
|
definitionOf: (value) => definitions.get(value),
|
|
312
956
|
bodyOfValue: (value) => owners.get(value),
|
|
@@ -344,6 +988,14 @@ const statedCallees = (call, program) => {
|
|
|
344
988
|
named.add(member.functionId);
|
|
345
989
|
for (const id of proofFunctions(program.targetProofOf(call)))
|
|
346
990
|
named.add(id);
|
|
991
|
+
// `v.method()` where no instance can hold a callable own `method`.
|
|
992
|
+
const callee = program.definitionOf(call.callee.value);
|
|
993
|
+
if (callee?.kind === 'get') {
|
|
994
|
+
const methods = program.prototypeMethodsOf(callee);
|
|
995
|
+
if (methods?.complete)
|
|
996
|
+
for (const id of methods.functions)
|
|
997
|
+
named.add(id);
|
|
998
|
+
}
|
|
347
999
|
return [...named];
|
|
348
1000
|
};
|
|
349
1001
|
const fieldKeyOf = (program, key) => {
|
|
@@ -359,14 +1011,16 @@ const fieldKeyOf = (program, key) => {
|
|
|
359
1011
|
* the escaped set too.
|
|
360
1012
|
*/
|
|
361
1013
|
const globalPointsTo = (input, program) => {
|
|
362
|
-
const solver = new PointsTo();
|
|
363
1014
|
const escaped = 'ESC';
|
|
1015
|
+
const solver = newPointsTo(escaped);
|
|
1016
|
+
// `field` watchers: through an escaped object they do what they do through
|
|
1017
|
+
// `TOP` (see `PointsTo`), so a node holding both needs only the `TOP` call.
|
|
364
1018
|
const store = (receiver, key, value) => solver.on(receiver, (object) => {
|
|
365
1019
|
if (object === top)
|
|
366
1020
|
return solver.copy(value, escaped);
|
|
367
1021
|
solver.copy(value, fieldNode(object, key));
|
|
368
1022
|
solver.copy(value, fieldNode(object, allFields));
|
|
369
|
-
});
|
|
1023
|
+
}, 'field');
|
|
370
1024
|
const load = (receiver, key, result) => solver.on(receiver, (object) => {
|
|
371
1025
|
if (object === top) {
|
|
372
1026
|
solver.add(result, top);
|
|
@@ -376,7 +1030,7 @@ const globalPointsTo = (input, program) => {
|
|
|
376
1030
|
return solver.copy(fieldNode(object, allFields), result);
|
|
377
1031
|
solver.copy(fieldNode(object, key), result);
|
|
378
1032
|
solver.copy(fieldNode(object, unknownField), result);
|
|
379
|
-
});
|
|
1033
|
+
}, 'field');
|
|
380
1034
|
const enter = (functionId, call) => {
|
|
381
1035
|
call.args.forEach((argument, ordinal) => solver.copy(argument, parameterNode(functionId, call.spread ? '*' : ordinal)));
|
|
382
1036
|
if (call.spread && call.args[0])
|
|
@@ -399,6 +1053,14 @@ const globalPointsTo = (input, program) => {
|
|
|
399
1053
|
solver.add(fieldNode(object, unknownField), top);
|
|
400
1054
|
solver.copy(escaped, fieldNode(object, unknownField));
|
|
401
1055
|
solver.copy(fieldNode(object, allFields), escaped);
|
|
1056
|
+
// An escaped object's unknown-key field is readable by the code it escaped
|
|
1057
|
+
// to, so what it holds escapes too. Every ordinary store files its value
|
|
1058
|
+
// under `#` as well, which the line above already covers; but an iterator
|
|
1059
|
+
// (`get-iterator`) and a builtin method's result are filled straight into
|
|
1060
|
+
// `*`, and without this an escaped iterator handed out the elements it
|
|
1061
|
+
// walks while they stayed unescaped -- and a read of one of them through
|
|
1062
|
+
// an unknown value could not see a race on it.
|
|
1063
|
+
solver.copy(fieldNode(object, unknownField), escaped);
|
|
402
1064
|
});
|
|
403
1065
|
for (const body of input.bodies.values()) {
|
|
404
1066
|
const self = body.sourceOwner;
|
|
@@ -479,6 +1141,9 @@ const globalPointsTo = (input, program) => {
|
|
|
479
1141
|
? [operation.closedCallable.functionId]
|
|
480
1142
|
: operation.closedCallable.functionIds)
|
|
481
1143
|
solver.add(out, functionObject(id));
|
|
1144
|
+
// The prototype method, beside whatever own property the load found.
|
|
1145
|
+
for (const id of program.prototypeMethodsOf(operation)?.functions ?? [])
|
|
1146
|
+
solver.add(out, functionObject(id));
|
|
482
1147
|
break;
|
|
483
1148
|
case 'set':
|
|
484
1149
|
case 'define-own-property':
|
|
@@ -513,7 +1178,8 @@ const globalPointsTo = (input, program) => {
|
|
|
513
1178
|
case 'construct': {
|
|
514
1179
|
const args = operation.arguments.map((argument) => valueNode(argument.value));
|
|
515
1180
|
const targets = proofFunctions(operation.target);
|
|
516
|
-
|
|
1181
|
+
const construction = program.constructionOf(operation);
|
|
1182
|
+
if ((operation.target.kind === 'open' && !construction) || operation.hostFrame) {
|
|
517
1183
|
for (const argument of args)
|
|
518
1184
|
solver.copy(argument, escaped);
|
|
519
1185
|
fresh();
|
|
@@ -524,7 +1190,6 @@ const globalPointsTo = (input, program) => {
|
|
|
524
1190
|
break;
|
|
525
1191
|
}
|
|
526
1192
|
fresh();
|
|
527
|
-
const construction = program.constructionOf(operation);
|
|
528
1193
|
if (!construction) {
|
|
529
1194
|
for (const argument of args)
|
|
530
1195
|
solver.copy(argument, escaped);
|
|
@@ -692,7 +1357,7 @@ const operandValues = (operation) => {
|
|
|
692
1357
|
* the region itself activated is that task's, not shared.
|
|
693
1358
|
*/
|
|
694
1359
|
const runRegion = (input, program, global, entry, localCaptures) => {
|
|
695
|
-
const solver =
|
|
1360
|
+
const solver = newPointsTo();
|
|
696
1361
|
const refusals = [];
|
|
697
1362
|
const refused = new Set();
|
|
698
1363
|
const entries = new Map();
|
|
@@ -709,13 +1374,13 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
709
1374
|
refusals.push({ owner: String(body.sourceOwner), site: operation, detail });
|
|
710
1375
|
};
|
|
711
1376
|
const store = (receiver, key, value) => solver.on(receiver, (object) => {
|
|
712
|
-
if (object
|
|
1377
|
+
if (preexisting(object))
|
|
713
1378
|
return;
|
|
714
1379
|
solver.copy(value, fieldNode(object, key));
|
|
715
1380
|
solver.copy(value, fieldNode(object, allFields));
|
|
716
1381
|
});
|
|
717
1382
|
const load = (receiver, key, result) => solver.on(receiver, (object) => {
|
|
718
|
-
if (object
|
|
1383
|
+
if (preexisting(object))
|
|
719
1384
|
return solver.add(result, shared);
|
|
720
1385
|
if (key === allFields)
|
|
721
1386
|
return solver.copy(fieldNode(object, allFields), result);
|
|
@@ -772,6 +1437,9 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
772
1437
|
const site = closureSites.get(object);
|
|
773
1438
|
if (site)
|
|
774
1439
|
return enter(site.functionId, { kind: 'closure', allocator: site.allocator }, call);
|
|
1440
|
+
const functionId = functionOf(object);
|
|
1441
|
+
if (functionId)
|
|
1442
|
+
return enter(functionId, { kind: 'outside' }, call);
|
|
775
1443
|
if (object !== shared)
|
|
776
1444
|
return;
|
|
777
1445
|
const resolved = globalFunctions(callee);
|
|
@@ -910,6 +1578,10 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
910
1578
|
case 'get': {
|
|
911
1579
|
const key = fieldKeyOf(program, operation.key);
|
|
912
1580
|
load(valueNode(operation.receiver.value), key === unknownField ? allFields : key, out);
|
|
1581
|
+
// No own property of the key means the prototype method: the load
|
|
1582
|
+
// above holds every own property the region could have stored.
|
|
1583
|
+
for (const id of program.prototypeMethodsOf(operation)?.functions ?? [])
|
|
1584
|
+
solver.add(out, functionObject(id));
|
|
913
1585
|
if (key !== 'length')
|
|
914
1586
|
contentReads.push({ body, operation, operand: operation.receiver.value });
|
|
915
1587
|
if (key !== unknownField) {
|
|
@@ -984,7 +1656,8 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
984
1656
|
case 'construct': {
|
|
985
1657
|
const args = operation.arguments.map((argument) => valueNode(argument.value));
|
|
986
1658
|
fresh();
|
|
987
|
-
|
|
1659
|
+
const host = program.hostConstructionOf(operation);
|
|
1660
|
+
if (host) {
|
|
988
1661
|
for (const argument of operation.arguments)
|
|
989
1662
|
contentReads.push({ body, operation, operand: argument.value });
|
|
990
1663
|
const fields = fieldNode(`L|${result}`, unknownField);
|
|
@@ -992,6 +1665,10 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
992
1665
|
solver.copy(argument, fields);
|
|
993
1666
|
load(argument, allFields, fields);
|
|
994
1667
|
}
|
|
1668
|
+
// A view IS its buffer for every write through it: a view of a
|
|
1669
|
+
// buffer from before the region writes that buffer.
|
|
1670
|
+
for (const value of host.aliasing)
|
|
1671
|
+
solver.copy(valueNode(value), out);
|
|
995
1672
|
break;
|
|
996
1673
|
}
|
|
997
1674
|
const construction = program.constructionOf(operation);
|
|
@@ -1095,7 +1772,8 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
1095
1772
|
callChecks.push({ body, operation, value: argument.value, what: `passes ${builtin.member} a callback the compiler cannot name` });
|
|
1096
1773
|
solver.on(valueNode(argument.value), (object) => {
|
|
1097
1774
|
const site = closureSites.get(object);
|
|
1098
|
-
const
|
|
1775
|
+
const named = functionOf(object);
|
|
1776
|
+
const functions = site ? [site.functionId] : named ? [named] : object === shared ? globalFunctions(argument.value).functions : [];
|
|
1099
1777
|
if (object === shared && globalFunctions(argument.value).unknown)
|
|
1100
1778
|
return refuse(body, operation, `passes ${builtin.member} a callback the compiler cannot trace to its definitions`);
|
|
1101
1779
|
const how = site ? { kind: 'closure', allocator: site.allocator } : { kind: 'outside' };
|
|
@@ -1146,7 +1824,7 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
1146
1824
|
const objects = solver.of(valueNode(check.value));
|
|
1147
1825
|
if (objects.size === 0)
|
|
1148
1826
|
refuse(check.body, check.operation, `${check.what} an object the compiler cannot trace`);
|
|
1149
|
-
else if (objects
|
|
1827
|
+
else if (holdsPreexisting(objects))
|
|
1150
1828
|
refuse(check.body, check.operation, `${check.what} an object that existed before the parallel region`);
|
|
1151
1829
|
}
|
|
1152
1830
|
for (const check of callChecks)
|
|
@@ -1154,7 +1832,7 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
1154
1832
|
refuse(check.body, check.operation, check.what);
|
|
1155
1833
|
for (const check of enumerations) {
|
|
1156
1834
|
const objects = solver.of(valueNode(check.value));
|
|
1157
|
-
if (objects.size === 0 || objects
|
|
1835
|
+
if (objects.size === 0 || holdsPreexisting(objects))
|
|
1158
1836
|
refuse(check.body, check.operation, 'enumerates the keys of an object that existed before the parallel region');
|
|
1159
1837
|
}
|
|
1160
1838
|
// The disjoint-slot write is sound only if no task reads the array another
|
|
@@ -1173,7 +1851,7 @@ const runRegion = (input, program, global, entry, localCaptures) => {
|
|
|
1173
1851
|
if (targets.size > 0)
|
|
1174
1852
|
for (const read of contentReads) {
|
|
1175
1853
|
const region = solver.of(valueNode(read.operand));
|
|
1176
|
-
if (writeReceivers.has(read.operand) || (region.size > 0 && !region
|
|
1854
|
+
if (writeReceivers.has(read.operand) || (region.size > 0 && !holdsPreexisting(region)))
|
|
1177
1855
|
continue;
|
|
1178
1856
|
const objects = global.of(valueNode(read.operand));
|
|
1179
1857
|
// `TOP` is an object only code the analysis cannot see holds, and such
|