@eagleoutice/flowr 2.17.7 → 2.17.8
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/abstract-interpretation/branch-paths.d.ts +10 -0
- package/abstract-interpretation/branch-paths.js +104 -10
- package/config.js +3 -1
- package/control-flow/control-flow-graph.js +18 -2
- package/data/r-base-guards.generated.js +2 -2
- package/dataflow/environments/ambient-effect.js +4 -1
- package/dataflow/environments/built-in-props.d.ts +8 -2
- package/dataflow/environments/built-in-props.js +16 -5
- package/dataflow/environments/default-builtin-config/base-functions.js +1 -1
- package/dataflow/environments/default-builtin-config/guards.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/guards.js +28 -0
- package/dataflow/environments/default-builtin-config/index.d.ts +8 -4
- package/dataflow/environments/default-builtin-config/index.js +9 -5
- package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/parallel-execution.js +25 -0
- package/dataflow/environments/guard-facts.d.ts +28 -1
- package/dataflow/environments/pkg-name.d.ts +2 -0
- package/dataflow/environments/query-fn-props.d.ts +19 -15
- package/dataflow/environments/query-fn-props.js +46 -36
- package/dataflow/environments/removal-marker.d.ts +1 -1
- package/dataflow/environments/removal-marker.js +18 -3
- package/dataflow/environments/reserved-names.d.ts +6 -0
- package/dataflow/environments/reserved-names.js +14 -0
- package/dataflow/environments/resolve-by-name.js +5 -10
- package/dataflow/eval/resolve/alias-tracking.js +23 -6
- package/dataflow/extractor.js +103 -28
- package/dataflow/fn/argument-roles.d.ts +3 -0
- package/dataflow/fn/argument-roles.js +5 -5
- package/dataflow/fn/exceptions-of-function.d.ts +7 -0
- package/dataflow/fn/exceptions-of-function.js +15 -2
- package/dataflow/fn/function-props.d.ts +1 -1
- package/dataflow/fn/function-props.js +40 -18
- package/dataflow/fn/function-semantics.d.ts +3 -1
- package/dataflow/fn/function-semantics.js +2 -0
- package/dataflow/fn/guards/built-in-guards.js +2 -1
- package/dataflow/fn/guards/condition-grouping.d.ts +11 -0
- package/dataflow/fn/guards/condition-grouping.js +50 -3
- package/dataflow/fn/guards/function-guards.d.ts +10 -0
- package/dataflow/fn/guards/function-guards.js +130 -14
- package/dataflow/fn/guards/guard-claims.d.ts +2 -0
- package/dataflow/fn/guards/guard-claims.js +42 -2
- package/dataflow/fn/guards/guard-knowledge.d.ts +7 -1
- package/dataflow/fn/guards/guard-knowledge.js +50 -4
- package/dataflow/fn/guards/guard-term.js +10 -1
- package/dataflow/fn/higher-order-function.d.ts +15 -1
- package/dataflow/fn/higher-order-function.js +54 -10
- package/dataflow/graph/call-graph.d.ts +5 -0
- package/dataflow/graph/call-graph.js +51 -15
- package/dataflow/graph/df-helper.d.ts +2 -0
- package/dataflow/graph/df-helper.js +4 -2
- package/dataflow/graph/graph.d.ts +21 -0
- package/dataflow/graph/graph.js +63 -2
- package/dataflow/internal/linker.d.ts +20 -0
- package/dataflow/internal/linker.js +190 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +20 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +5 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +7 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +12 -5
- package/dataflow/internal/process/functions/call/deferred.d.ts +7 -2
- package/dataflow/internal/process/functions/call/deferred.js +63 -28
- package/dataflow/internal/process/functions/call/quoted.js +33 -7
- package/documentation/data/dfg/doc-ambient.js +3 -1
- package/documentation/wiki-normalized-ast.js +1 -1
- package/documentation/wiki-query.js +9 -3
- package/package.json +5 -3
- package/project/context/flowr-analyzer-context.d.ts +7 -4
- package/project/context/flowr-analyzer-context.js +8 -3
- package/project/context/flowr-analyzer-files-context.js +1 -0
- package/project/context/flowr-analyzer-functions-context.d.ts +2 -1
- package/project/context/flowr-analyzer-functions-context.js +9 -8
- package/project/flowr-analyzer.d.ts +7 -4
- package/project/flowr-analyzer.js +37 -8
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +22 -0
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +34 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -1
- package/project/sigdb/build.js +41 -2
- package/project/sigdb/decode.d.ts +3 -1
- package/project/sigdb/decode.js +45 -1
- package/project/sigdb/decompress.d.ts +5 -0
- package/project/sigdb/decompress.js +17 -1
- package/project/sigdb/manifest.d.ts +2 -1
- package/project/sigdb/manifest.js +12 -5
- package/project/sigdb/native-routines.d.ts +82 -0
- package/project/sigdb/native-routines.js +178 -0
- package/project/sigdb/reader.d.ts +21 -3
- package/project/sigdb/reader.js +35 -3
- package/project/sigdb/schema.d.ts +107 -3
- package/project/sigdb/schema.js +8 -2
- package/project/sigdb/sigdb-download.js +1 -1
- package/project/sigdb/sigdb-version.d.ts +7 -1
- package/project/sigdb/sigdb-version.js +12 -9
- package/project/sigdb/spec-query.d.ts +9 -4
- package/project/sigdb/spec-query.js +71 -45
- package/queries/catalog/call-context-query/call-context-query-executor.js +76 -29
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +1 -12
- package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.d.ts +3 -0
- package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.js +3 -2
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +3 -0
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +3 -2
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +3 -1
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +4 -2
- package/queries/catalog/signature-query/signature-query-executor.js +6 -2
- package/queries/catalog/signature-query/signature-query-format.d.ts +4 -0
- package/util/collections/bounded-map.d.ts +9 -0
- package/util/collections/bounded-map.js +22 -0
- package/util/collections/defaultmap.d.ts +5 -0
- package/util/collections/defaultmap.js +10 -0
- package/util/fixpoint.d.ts +6 -1
- package/util/fixpoint.js +45 -3
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/global-caches.d.ts +26 -0
- package/util/global-caches.js +43 -0
- package/util/monoid.js +2 -2
- package/util/quads.js +11 -3
- package/util/r-package-urls.d.ts +19 -0
- package/util/r-package-urls.js +41 -0
package/dataflow/graph/graph.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataflowGraph = exports.UnknownSideEffect = exports.NoEdges = exports.FunctionArgument = void 0;
|
|
3
|
+
exports.PendingEdges = exports.DataflowGraph = exports.UnknownSideEffect = exports.NoEdges = exports.FunctionArgument = void 0;
|
|
4
4
|
const assert_1 = require("../../util/assert");
|
|
5
5
|
const edge_1 = require("./edge");
|
|
6
6
|
const vertex_1 = require("./vertex");
|
|
7
7
|
const arrays_1 = require("../../util/collections/arrays");
|
|
8
|
+
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
8
9
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
9
10
|
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
10
11
|
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
@@ -56,6 +57,8 @@ exports.FunctionArgument = {
|
|
|
56
57
|
};
|
|
57
58
|
/** The shared answer for a vertex without edges. */
|
|
58
59
|
exports.NoEdges = new Map();
|
|
60
|
+
/** from this many edges leaving a vertex on, {@link DataflowGraph#edgesBeyondSideEffects} keeps those it hands out */
|
|
61
|
+
const ManyEdges = 64;
|
|
59
62
|
/**
|
|
60
63
|
* Helpers for the {@link UnknownSideEffect} union, which is either a plain {@link NodeId} or a `{ id, linkTo }` object.
|
|
61
64
|
* @helper dataflow
|
|
@@ -101,6 +104,8 @@ class DataflowGraph {
|
|
|
101
104
|
edgeInformation = new Map();
|
|
102
105
|
/* the reverse of `edgeInformation`, built on demand, then kept up to date by `addEdge` and dropped only on a bulk write (`mergeEdges`, `fromJson`): rebuilding it per lookup made every caller asking for the ingoing edges of many nodes scan the whole graph once per node */
|
|
103
106
|
incomingIndex;
|
|
107
|
+
/* per vertex with many edges leaving it, those carrying more than a side effect on a call, see `edgesBeyondSideEffects`; dropped for a vertex whenever its edges change */
|
|
108
|
+
beyondSideEffects = new Map();
|
|
104
109
|
/* tag to the ids carrying it; a lookup re-checks the vertex, as another graph may retag an object they share */
|
|
105
110
|
types = new Map();
|
|
106
111
|
/** The id list of `tag`, created on first use, so a caller adding many ids looks it up once. */
|
|
@@ -123,6 +128,16 @@ class DataflowGraph {
|
|
|
123
128
|
}
|
|
124
129
|
/* the qualified call names, built on demand and dropped on every change, as vertices and edges both decide them */
|
|
125
130
|
qualifiedNames;
|
|
131
|
+
/* what views of the graph derive from it, per key, dropped on every change like the qualified names */
|
|
132
|
+
derived;
|
|
133
|
+
/** What `create` derives from the graph, made once and kept under `key` until the graph changes. */
|
|
134
|
+
derivedUntilChanged(key, create) {
|
|
135
|
+
this.derived ??= new Map();
|
|
136
|
+
if (!this.derived.has(key)) {
|
|
137
|
+
this.derived.set(key, create());
|
|
138
|
+
}
|
|
139
|
+
return this.derived.get(key);
|
|
140
|
+
}
|
|
126
141
|
toJSON() {
|
|
127
142
|
return {
|
|
128
143
|
rootVertices: Array.from(this.rootVertices),
|
|
@@ -138,6 +153,7 @@ class DataflowGraph {
|
|
|
138
153
|
const graph = new DataflowGraph(this._idMap);
|
|
139
154
|
graph.rootVertices = this.rootVertices;
|
|
140
155
|
graph.edgeInformation = this.edgeInformation;
|
|
156
|
+
graph.beyondSideEffects = this.beyondSideEffects;
|
|
141
157
|
graph.types = this.types;
|
|
142
158
|
graph.vertexInformation = new Map(Array.from(this.vertexInformation, ([id, vertex]) => [id, (vertex_1.DfgVertex.isFunctionDefinition(vertex)
|
|
143
159
|
? { ...vertex, environment: undefined, subflow: { ...vertex.subflow, environment: undefined } }
|
|
@@ -163,12 +179,25 @@ class DataflowGraph {
|
|
|
163
179
|
* @useInstead {@link DataflowGraph#edgesFrom|edgesFrom()} - unless you mean to write into what you get back
|
|
164
180
|
*/
|
|
165
181
|
outgoingEdges(id) {
|
|
182
|
+
/* the caller may write into it */
|
|
183
|
+
this.beyondSideEffects.delete(id);
|
|
166
184
|
return this.edgeInformation.get(id);
|
|
167
185
|
}
|
|
168
186
|
/** The edges leaving `id`, i.e. what it depends on, as a map from target to edge. */
|
|
169
187
|
edgesFrom(id) {
|
|
170
188
|
return this.edgeInformation.get(id) ?? exports.NoEdges;
|
|
171
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* The edges leaving `id` but those that only state a {@link EdgeType.SideEffectOnCall}: a write escaping into thousands of calls
|
|
192
|
+
* has an edge to each, which a walk along the flow of values steps over every time it passes the write.
|
|
193
|
+
*/
|
|
194
|
+
edgesBeyondSideEffects(id) {
|
|
195
|
+
const edges = this.edgeInformation.get(id);
|
|
196
|
+
if (edges === undefined || edges.size < ManyEdges) {
|
|
197
|
+
return edges ?? exports.NoEdges;
|
|
198
|
+
}
|
|
199
|
+
return (0, defaultmap_1.getOrSet)(this.beyondSideEffects, id, () => edges.entries().filter(([, e]) => !edge_1.DfEdge.isOnlyType(e, edge_1.EdgeType.SideEffectOnCall)).toArray());
|
|
200
|
+
}
|
|
172
201
|
/** The edges arriving at `id`, i.e. what depends on it, as a map from source to edge. */
|
|
173
202
|
edgesTo(id) {
|
|
174
203
|
return this.ingoingEdges(id) ?? exports.NoEdges;
|
|
@@ -277,6 +306,7 @@ class DataflowGraph {
|
|
|
277
306
|
(0, assert_1.guard)(!this.consumed, 'this graph was consumed by a merge and must not be changed any more');
|
|
278
307
|
this.qualifiedNames = undefined;
|
|
279
308
|
this.targetWalks = undefined;
|
|
309
|
+
this.derived = undefined;
|
|
280
310
|
}
|
|
281
311
|
/** For a node of the normalized AST: `nodeId` if it is a DFG vertex itself, else the DFG vertices linked to it, else `undefined`. */
|
|
282
312
|
getLinked(nodeId) {
|
|
@@ -388,6 +418,7 @@ class DataflowGraph {
|
|
|
388
418
|
}
|
|
389
419
|
this.dropQualifications();
|
|
390
420
|
this.countRead(to, type);
|
|
421
|
+
this.beyondSideEffects.delete(from);
|
|
391
422
|
edge.types &= ~type;
|
|
392
423
|
if (edge_1.DfEdge.hasAnyType(edge)) {
|
|
393
424
|
/* the reverse index holds this very object, so a narrowed type is already visible through it */
|
|
@@ -444,10 +475,16 @@ class DataflowGraph {
|
|
|
444
475
|
if (fromId === toId) {
|
|
445
476
|
return this;
|
|
446
477
|
}
|
|
447
|
-
this.dropQualifications();
|
|
448
478
|
this.countRead(toId, type);
|
|
449
479
|
const fromEdges = this.edgeInformation.get(fromId);
|
|
450
480
|
const existing = fromEdges?.get(toId);
|
|
481
|
+
/* an edge the graph already has changes nothing, so what was resolved over the graph still holds */
|
|
482
|
+
if (existing !== undefined && data === undefined && (existing.types & type) === type) {
|
|
483
|
+
(0, assert_1.guard)(!this.consumed, 'this graph was consumed by a merge and must not be changed any more');
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
486
|
+
this.dropQualifications();
|
|
487
|
+
this.beyondSideEffects.delete(fromId);
|
|
451
488
|
if (existing !== undefined) {
|
|
452
489
|
/* the reverse index holds this very object, so a widened type is already visible through it */
|
|
453
490
|
existing.types |= type;
|
|
@@ -495,6 +532,7 @@ class DataflowGraph {
|
|
|
495
532
|
this.dropQualifications();
|
|
496
533
|
this.vertexInformation = otherGraph.vertexInformation;
|
|
497
534
|
this.edgeInformation = otherGraph.edgeInformation;
|
|
535
|
+
this.beyondSideEffects = otherGraph.beyondSideEffects;
|
|
498
536
|
this.types = otherGraph.types;
|
|
499
537
|
this.incomingIndex = undefined;
|
|
500
538
|
const takeRoots = mergeRootVertices && this.rootVertices.size === 0;
|
|
@@ -544,6 +582,7 @@ class DataflowGraph {
|
|
|
544
582
|
mergeEdges(otherGraph, consume = false) {
|
|
545
583
|
this.dropQualifications();
|
|
546
584
|
this.incomingIndex = undefined;
|
|
585
|
+
this.beyondSideEffects.clear();
|
|
547
586
|
for (const [id, edges] of otherGraph.edgeInformation) {
|
|
548
587
|
const existing = this.edgeInformation.get(id);
|
|
549
588
|
if (existing === undefined) {
|
|
@@ -667,4 +706,26 @@ function envFromJson(json) {
|
|
|
667
706
|
function renvFromJson(json) {
|
|
668
707
|
return { current: envFromJson(json.current), level: json.level };
|
|
669
708
|
}
|
|
709
|
+
/**
|
|
710
|
+
* Edges a pass collects while it still asks questions of the graph, added in one go at its end: every change to the graph drops
|
|
711
|
+
* what was resolved over it (the qualified call names, the shared target walks), so adding them as found would resolve the same
|
|
712
|
+
* calls again after each one. The same edge found twice is kept once.
|
|
713
|
+
*/
|
|
714
|
+
class PendingEdges {
|
|
715
|
+
edges = new Map();
|
|
716
|
+
/** Notes the edge `from -> to` of the given type. */
|
|
717
|
+
add(from, to, type) {
|
|
718
|
+
const targets = (0, defaultmap_1.getOrSet)(this.edges, from, () => new Map());
|
|
719
|
+
targets.set(to, (targets.get(to) ?? 0) | type);
|
|
720
|
+
}
|
|
721
|
+
/** Adds every noted edge to `graph`. */
|
|
722
|
+
applyTo(graph) {
|
|
723
|
+
for (const [from, targets] of this.edges) {
|
|
724
|
+
for (const [to, type] of targets) {
|
|
725
|
+
graph.addEdge(from, to, type);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
exports.PendingEdges = PendingEdges;
|
|
670
731
|
//# sourceMappingURL=graph.js.map
|
|
@@ -48,15 +48,33 @@ export declare class LinkedFunctionResolver {
|
|
|
48
48
|
private readonly graph;
|
|
49
49
|
/** the number of each state, by whether an access led to it, its vertex, and its call */
|
|
50
50
|
private readonly numbers;
|
|
51
|
+
/** a state of the walk, or (with `region`) the state of {@link LinkedFunctionResolver#regions} the walk is in under any call running the same bodies */
|
|
51
52
|
private readonly states;
|
|
52
53
|
/** the built-ins and function definitions the walk ends at, by their state */
|
|
53
54
|
private readonly ends;
|
|
54
55
|
private readonly scopes;
|
|
56
|
+
private readonly passedBy;
|
|
55
57
|
private readonly summaries;
|
|
58
|
+
/**
|
|
59
|
+
* Within the bodies a call runs, the walk goes the same way under every call running them, but for the parameters it binds:
|
|
60
|
+
* a function calling itself (as `[.data.table` does with each `x[...]`) would else have the walk visit its body once per call.
|
|
61
|
+
* So the walk in these bodies is done once per set of bodies, by `region`, with `scope` standing for any call running them, and
|
|
62
|
+
* leaves the parameters it reaches (`hit`) to each call.
|
|
63
|
+
*/
|
|
64
|
+
private readonly regions;
|
|
65
|
+
/** the region states whose parameters a walk from a region state reaches */
|
|
66
|
+
private readonly hits;
|
|
56
67
|
constructor(graph: DataflowGraph);
|
|
57
68
|
/** The function definitions and built-ins the reads with the given ids may evaluate to. */
|
|
58
69
|
resolve(reads: ReadonlySet<NodeId>): [Set<Required<DataflowGraphVertexFunctionDefinition>>, Set<BuiltIn>];
|
|
59
70
|
private state;
|
|
71
|
+
/** The scope standing for every call that runs the same bodies as `call`. */
|
|
72
|
+
private scopeOf;
|
|
73
|
+
private regionState;
|
|
74
|
+
/** The state of the walk that is `region`. */
|
|
75
|
+
private outerOf;
|
|
76
|
+
/** The steps from a region state, to the states of its scope it goes on to (`within`), and to the others (`leaving`). */
|
|
77
|
+
private expandRegion;
|
|
60
78
|
/** The states the walk goes on to from `state`, none for a built-in or function definition it ends at. */
|
|
61
79
|
private expand;
|
|
62
80
|
}
|
|
@@ -67,6 +85,8 @@ export declare class LinkedFunctionResolver {
|
|
|
67
85
|
export declare function linkExpressionIn<Info>(this: void, graph: DataflowGraph, expr: NodeId, environment: REnvironmentInformation, idMap: AstIdMap<Info & ParentInformation>): readonly IdentifierReference[];
|
|
68
86
|
/** Links the call `callId` to the functions the given definitions bind, which it did not know of when it was processed. */
|
|
69
87
|
export declare function linkCallToDefinitions(graph: DataflowGraph, callId: NodeId, definitions: readonly NodeId[], idMap: AstIdMap): void;
|
|
88
|
+
/** Links the call `callId` to the given functions, as {@link linkCallToDefinitions} does once it found them. */
|
|
89
|
+
export declare function linkCallToFunctions(graph: DataflowGraph, callId: NodeId, functions: Iterable<Required<DataflowGraphVertexFunctionDefinition>>, idMap: AstIdMap): void;
|
|
70
90
|
/** Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked (or links to built-ins only) is added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned. */
|
|
71
91
|
export declare function linkInputs(referencesToLinkAgainstEnvironment: readonly IdentifierReference[], environmentInformation: REnvironmentInformation, givenInputs: IdentifierReference[], graph: DataflowGraph, maybeForRemaining: boolean, alsoFrom?: NodeId): IdentifierReference[];
|
|
72
92
|
/** A loop variable read before its within-loop redefinition gets a maybe marker to that def (e.g. `x_2` may read the prior iteration's `x_1` in `for(...) { x_1 <- x_2 + 1 }`); with `environment`, this uses all defs live at loop exit, which the calls in the loop see as well (see {@link linkLoopCarriedCalls}). */
|
|
@@ -13,6 +13,7 @@ exports.getAllFunctionCallTargets = getAllFunctionCallTargets;
|
|
|
13
13
|
exports.getAllLinkedFunctionDefinitions = getAllLinkedFunctionDefinitions;
|
|
14
14
|
exports.linkExpressionIn = linkExpressionIn;
|
|
15
15
|
exports.linkCallToDefinitions = linkCallToDefinitions;
|
|
16
|
+
exports.linkCallToFunctions = linkCallToFunctions;
|
|
16
17
|
exports.linkInputs = linkInputs;
|
|
17
18
|
exports.linkCircularRedefinitionsWithinALoop = linkCircularRedefinitionsWithinALoop;
|
|
18
19
|
exports.linkWritesCarriedByLoop = linkWritesCarriedByLoop;
|
|
@@ -57,6 +58,7 @@ const closure_frames_1 = require("../graph/closure-frames");
|
|
|
57
58
|
const ambient_state_name_1 = require("../environments/ambient-state-name");
|
|
58
59
|
const class_declaration_1 = require("../fn/class-declaration");
|
|
59
60
|
const fixpoint_1 = require("../../util/fixpoint");
|
|
61
|
+
const monoid_1 = require("../../util/monoid");
|
|
60
62
|
const built_in_library_1 = require("./process/functions/call/built-in/built-in-library");
|
|
61
63
|
const ValueFlowBits = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall;
|
|
62
64
|
const FCallLinkReadBits = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall;
|
|
@@ -386,12 +388,68 @@ function mayBeFunctionSource(graph, info, target, e, unbound = false) {
|
|
|
386
388
|
if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall)) {
|
|
387
389
|
return true;
|
|
388
390
|
}
|
|
389
|
-
else if (isWithinArgumentOf(graph, info.id, target)) {
|
|
391
|
+
else if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns) || isWithinArgumentOf(graph, info.id, target)) {
|
|
392
|
+
/* what a call returns (a method a built-in runs, `message(cnd)` going on with `conditionMessage`) is its value, not its function */
|
|
390
393
|
return false;
|
|
391
394
|
}
|
|
392
395
|
const vertex = graph.getVertex(target);
|
|
393
|
-
|
|
394
|
-
|
|
396
|
+
if (vertex_1.DfgVertex.hasOrigin(info, built_in_proc_name_1.BuiltInProcName.Unnamed)) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
else if (info.environment === undefined) {
|
|
400
|
+
/*
|
|
401
|
+
* a call that only reached built-ins when it was processed keeps no environment, so its name is bound by a definition or a built-in call of its scope binding names (`library(dplyr)`);
|
|
402
|
+
* a use, a call of the code (what it lets escape is read at its definition) or a call elsewhere is what it waits for (an earlier call that may raise, a site signaling to a handler that leads to it),
|
|
403
|
+
* and a definition of another name is what it hands on (the parameters `NextMethod` passes to the next method)
|
|
404
|
+
*/
|
|
405
|
+
if (vertex_1.DfgVertex.isVariableDefinition(vertex)) {
|
|
406
|
+
const defined = graph.idMap === undefined ? undefined : node_id_1.NodeId.recoverBareName(target, graph.idMap);
|
|
407
|
+
return defined === undefined || info.name === undefined || defined === identifier_1.Identifier.getName(info.name);
|
|
408
|
+
}
|
|
409
|
+
return (!vertex_1.DfgVertex.isUse(vertex) || isWithinCall(graph, info.id, target)) && (!vertex_1.DfgVertex.isFunctionCall(vertex)
|
|
410
|
+
|| (vertex.origin !== 'unnamed' && vertex.origin.some(o => o !== built_in_proc_name_1.BuiltInProcName.Default) && !vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Function) && isInScopeOf(graph, info.id, target)));
|
|
411
|
+
}
|
|
412
|
+
/* a use outside the call is one it waits for (an earlier one forcing a promise that may raise), not one naming its function */
|
|
413
|
+
return (!vertex_1.DfgVertex.isUse(vertex) || isWithinCall(graph, info.id, target)) && (!vertex_1.DfgVertex.isFunctionCall(vertex) || (!unbound && (vertex.origin === 'unnamed' || vertex.origin.some(o => o !== built_in_proc_name_1.BuiltInProcName.Default))));
|
|
414
|
+
}
|
|
415
|
+
/** Whether `target` is part of `call` (true without the AST to tell). */
|
|
416
|
+
function isWithinCall(graph, call, target) {
|
|
417
|
+
const idMap = graph.idMap;
|
|
418
|
+
if (idMap === undefined) {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
for (let node = idMap.get(target); node !== undefined; node = model_1.RNode.directParent(node, idMap)) {
|
|
422
|
+
if (node.info.id === call) {
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
/** Whether `target` lies in the body of a function enclosing `call` (or at the top level), where a call may bind a name `call` sees. */
|
|
429
|
+
function isInScopeOf(graph, call, target) {
|
|
430
|
+
const idMap = graph.idMap;
|
|
431
|
+
if (idMap === undefined) {
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
const own = enclosingFunctionOf(target, idMap);
|
|
435
|
+
if (own === undefined) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
for (let fn = enclosingFunctionOf(call, idMap); fn !== undefined; fn = enclosingFunctionOf(fn, idMap)) {
|
|
439
|
+
if (fn === own) {
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
/** The nearest function definition `id` lies in, none at the top level. */
|
|
446
|
+
function enclosingFunctionOf(id, idMap) {
|
|
447
|
+
for (let node = idMap.get(id), parent = node && model_1.RNode.directParent(node, idMap); parent !== undefined; parent = model_1.RNode.directParent(parent, idMap)) {
|
|
448
|
+
if (r_function_definition_1.RFunctionDefinition.is(parent)) {
|
|
449
|
+
return parent.info.id;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return undefined;
|
|
395
453
|
}
|
|
396
454
|
/** Whether `target` lies within an argument of `call`, which the call reads when it forces that argument, not to find its function. */
|
|
397
455
|
function isWithinArgumentOf(graph, call, target) {
|
|
@@ -549,8 +607,11 @@ function getAllLinkedFunctionDefinitions(functionDefinitionReadIds, dataflowGrap
|
|
|
549
607
|
function subsets(node) {
|
|
550
608
|
return r_access_1.RAccess.is(node) && node.operator === '[';
|
|
551
609
|
}
|
|
552
|
-
/**
|
|
553
|
-
function
|
|
610
|
+
/**
|
|
611
|
+
* One step of the walk for the function definitions that reads may evaluate to: hands each state the walk goes on to from `id` to `next`, or returns `id` if the walk ends at it, being a built-in or a function definition.
|
|
612
|
+
* With `bindsLater`, the step leaves the parameters the call may bind to it: it gets the arguments a parameter at `id` may hold, whose states (without a call) the walk goes on to, and the call keeps just those it passes, if it passes any.
|
|
613
|
+
*/
|
|
614
|
+
function walkLinkedDefinitions(graph, id, viaAccess, call, scopes, next, bindsLater) {
|
|
554
615
|
if (node_id_1.NodeId.isBuiltIn(id)) {
|
|
555
616
|
return id;
|
|
556
617
|
}
|
|
@@ -577,7 +638,8 @@ function walkLinkedDefinitions(graph, id, viaAccess, call, scopes, next) {
|
|
|
577
638
|
const handedBack = !viaAccess && vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.List) ? edge_1.EdgeType.Returns | edge_1.EdgeType.Argument : edge_1.EdgeType.Returns;
|
|
578
639
|
/* only a call into a body binds parameters, a built-in hands back what it is given in the same context */
|
|
579
640
|
const returnedTo = vertex_1.DfgVertex.isFunctionCall(vertex) && !vertex.onlyBuiltin ? id : call;
|
|
580
|
-
|
|
641
|
+
/* an edge stating only a side effect on a call is neither handed back nor followed */
|
|
642
|
+
for (const [target, e] of graph.edgesBeyondSideEffects(id)) {
|
|
581
643
|
if (edge_1.DfEdge.includesType(e, handedBack)) {
|
|
582
644
|
hasReturnEdge = true;
|
|
583
645
|
next(target, nextViaAccess, returnedTo === call ? scopedTo(graph, scopes, call, target) : returnedTo);
|
|
@@ -587,6 +649,18 @@ function walkLinkedDefinitions(graph, id, viaAccess, call, scopes, next) {
|
|
|
587
649
|
}
|
|
588
650
|
}
|
|
589
651
|
if (!hasReturnEdge && followTargets) {
|
|
652
|
+
if (bindsLater !== undefined && call !== undefined) {
|
|
653
|
+
const bindable = followTargets.filter(([, onCall]) => onCall).map(([target]) => target);
|
|
654
|
+
if (bindable.length > 0) {
|
|
655
|
+
bindsLater(bindable, nextViaAccess);
|
|
656
|
+
}
|
|
657
|
+
for (const [target, onCall] of followTargets) {
|
|
658
|
+
if (!onCall) {
|
|
659
|
+
next(target, nextViaAccess, scopedTo(graph, scopes, call, target));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return undefined;
|
|
663
|
+
}
|
|
590
664
|
/* a parameter the call binds holds only what that call passes, the walk then goes on in the caller */
|
|
591
665
|
const passed = call === undefined ? undefined : new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Argument));
|
|
592
666
|
const bound = followTargets.some(([target, onCall]) => onCall && passed?.has(target));
|
|
@@ -598,6 +672,12 @@ function walkLinkedDefinitions(graph, id, viaAccess, call, scopes, next) {
|
|
|
598
672
|
}
|
|
599
673
|
return undefined;
|
|
600
674
|
}
|
|
675
|
+
/** The arguments a parameter may hold that `call` binds it to: those it passes, all of them if it passes none (see {@link walkLinkedDefinitions}). */
|
|
676
|
+
function boundBy(graph, call, arguments_, passedBy) {
|
|
677
|
+
const passed = (0, defaultmap_1.getOrSet)(passedBy, call, () => new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Argument)));
|
|
678
|
+
const bound = arguments_.filter(a => passed.has(a));
|
|
679
|
+
return bound.length > 0 ? bound : arguments_;
|
|
680
|
+
}
|
|
601
681
|
/** A string where a function is wanted names the function (`match.fun`, `do.call` and the apply family look it up), which is resolved where the string is written, by the environment of the call it is passed to. */
|
|
602
682
|
function functionsNamedBy(graph, id) {
|
|
603
683
|
const idMap = graph.idMap;
|
|
@@ -619,11 +699,7 @@ function scopedTo(graph, scopes, call, target) {
|
|
|
619
699
|
if (call === undefined || idMap === undefined) {
|
|
620
700
|
return call;
|
|
621
701
|
}
|
|
622
|
-
|
|
623
|
-
if (bodies === undefined) {
|
|
624
|
-
bodies = new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Calls | edge_1.EdgeType.Returns).map(t => model_1.RNode.findEnclosing(t, idMap, r_function_definition_1.RFunctionDefinition.is)).filter(assert_1.isNotUndefined));
|
|
625
|
-
scopes.set(call, bodies);
|
|
626
|
-
}
|
|
702
|
+
const bodies = bodiesRunBy(graph, scopes, call);
|
|
627
703
|
for (let node = idMap.get(target); node !== undefined; node = model_1.RNode.directParent(node, idMap)) {
|
|
628
704
|
if (bodies.has(node.info.id)) {
|
|
629
705
|
return call;
|
|
@@ -631,20 +707,48 @@ function scopedTo(graph, scopes, call, target) {
|
|
|
631
707
|
}
|
|
632
708
|
return undefined;
|
|
633
709
|
}
|
|
634
|
-
|
|
710
|
+
/** The function definitions whose bodies `call` runs, see {@link scopedTo}. */
|
|
711
|
+
function bodiesRunBy(graph, scopes, call) {
|
|
712
|
+
const idMap = graph.idMap;
|
|
713
|
+
return (0, defaultmap_1.getOrSet)(scopes, call, () => idMap === undefined ? new Set() : new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Calls | edge_1.EdgeType.Returns).map(t => model_1.RNode.findEnclosing(t, idMap, r_function_definition_1.RFunctionDefinition.is)).filter(assert_1.isNotUndefined)));
|
|
714
|
+
}
|
|
635
715
|
/** Finds the function definitions and built-ins that reads may evaluate to (see {@link getAllLinkedFunctionDefinitions}). */
|
|
636
716
|
class LinkedFunctionResolver {
|
|
637
717
|
graph;
|
|
638
718
|
/** the number of each state, by whether an access led to it, its vertex, and its call */
|
|
639
719
|
numbers = [new Map(), new Map()];
|
|
720
|
+
/** a state of the walk, or (with `region`) the state of {@link LinkedFunctionResolver#regions} the walk is in under any call running the same bodies */
|
|
640
721
|
states = [];
|
|
641
722
|
/** the built-ins and function definitions the walk ends at, by their state */
|
|
642
723
|
ends = new Map();
|
|
643
724
|
scopes = new Map();
|
|
725
|
+
passedBy = new Map();
|
|
644
726
|
summaries;
|
|
727
|
+
/**
|
|
728
|
+
* Within the bodies a call runs, the walk goes the same way under every call running them, but for the parameters it binds:
|
|
729
|
+
* a function calling itself (as `[.data.table` does with each `x[...]`) would else have the walk visit its body once per call.
|
|
730
|
+
* So the walk in these bodies is done once per set of bodies, by `region`, with `scope` standing for any call running them, and
|
|
731
|
+
* leaves the parameters it reaches (`hit`) to each call.
|
|
732
|
+
*/
|
|
733
|
+
regions = {
|
|
734
|
+
numbers: new Map(),
|
|
735
|
+
states: [],
|
|
736
|
+
/* by region state, filled once it is expanded */
|
|
737
|
+
within: [],
|
|
738
|
+
leaving: [],
|
|
739
|
+
hit: new Map(),
|
|
740
|
+
/** the region states, by their scope, that hold the outer state of the walk in them */
|
|
741
|
+
outer: new Map(),
|
|
742
|
+
/** the scope standing for each call, by the bodies it runs */
|
|
743
|
+
scopeOf: new Map(),
|
|
744
|
+
byBodies: new Map()
|
|
745
|
+
};
|
|
746
|
+
/** the region states whose parameters a walk from a region state reaches */
|
|
747
|
+
hits;
|
|
645
748
|
constructor(graph) {
|
|
646
749
|
this.graph = graph;
|
|
647
|
-
this.summaries = new fixpoint_1.ReachSummaries(state => this.expand(state), state => this.ends.get(state),
|
|
750
|
+
this.summaries = new fixpoint_1.ReachSummaries(state => this.expand(state), state => this.ends.get(state), monoid_1.Monoid.set());
|
|
751
|
+
this.hits = new fixpoint_1.ReachSummaries(region => this.expandRegion(region).within, region => this.regions.hit.has(region) ? new Set([region]) : undefined, monoid_1.Monoid.set());
|
|
648
752
|
}
|
|
649
753
|
/** The function definitions and built-ins the reads with the given ids may evaluate to. */
|
|
650
754
|
resolve(reads) {
|
|
@@ -663,20 +767,76 @@ class LinkedFunctionResolver {
|
|
|
663
767
|
return [definitions, builtIns];
|
|
664
768
|
}
|
|
665
769
|
state(id, viaAccess, call) {
|
|
666
|
-
const byCall = this.numbers[viaAccess ? 1 : 0]
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
770
|
+
const byCall = (0, defaultmap_1.getOrSet)(this.numbers[viaAccess ? 1 : 0], id, () => new Map());
|
|
771
|
+
return (0, defaultmap_1.getOrSet)(byCall, call, () => this.states.push([id, viaAccess, call]) - 1);
|
|
772
|
+
}
|
|
773
|
+
/** The scope standing for every call that runs the same bodies as `call`. */
|
|
774
|
+
scopeOf(call) {
|
|
775
|
+
return (0, defaultmap_1.getOrSet)(this.regions.scopeOf, call, () => {
|
|
776
|
+
const bodies = bodiesRunBy(this.graph, this.scopes, call);
|
|
777
|
+
const key = [...bodies].map(String).sort().join(',');
|
|
778
|
+
return (0, defaultmap_1.getOrSet)(this.regions.byBodies, key, () => {
|
|
779
|
+
/* no vertex has this id, the walk only asks the scopes for the bodies it runs */
|
|
780
|
+
const scope = `\u0000bodies:${key}`;
|
|
781
|
+
this.scopes.set(scope, bodies);
|
|
782
|
+
return scope;
|
|
783
|
+
});
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
regionState(id, viaAccess, scope) {
|
|
787
|
+
const byId = (0, defaultmap_1.getOrSet)(this.regions.numbers, scope, () => [new Map(), new Map()]);
|
|
788
|
+
return (0, defaultmap_1.getOrSet)(byId[viaAccess ? 1 : 0], id, () => this.regions.states.push([id, viaAccess, scope]) - 1);
|
|
789
|
+
}
|
|
790
|
+
/** The state of the walk that is `region`. */
|
|
791
|
+
outerOf(region) {
|
|
792
|
+
return (0, defaultmap_1.getOrSet)(this.regions.outer, region, () => {
|
|
793
|
+
const [id, viaAccess, scope] = this.regions.states[region];
|
|
794
|
+
return this.states.push([id, viaAccess, scope, region]) - 1;
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
/** The steps from a region state, to the states of its scope it goes on to (`within`), and to the others (`leaving`). */
|
|
798
|
+
expandRegion(region) {
|
|
799
|
+
const known = this.regions.within[region];
|
|
800
|
+
if (known !== undefined) {
|
|
801
|
+
return { within: known, leaving: this.regions.leaving[region] };
|
|
802
|
+
}
|
|
803
|
+
const [id, viaAccess, scope] = this.regions.states[region];
|
|
804
|
+
const within = [];
|
|
805
|
+
const leaving = [];
|
|
806
|
+
const end = walkLinkedDefinitions(this.graph, id, viaAccess, scope, this.scopes, (target, nextViaAccess, nextCall) => {
|
|
807
|
+
if (nextCall === scope) {
|
|
808
|
+
within.push(this.regionState(target, nextViaAccess, scope));
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
leaving.push(this.state(target, nextViaAccess, nextCall));
|
|
672
812
|
}
|
|
673
|
-
|
|
813
|
+
}, (arguments_, nextViaAccess) => this.regions.hit.set(region, [arguments_, nextViaAccess]));
|
|
814
|
+
if (end !== undefined) {
|
|
815
|
+
this.ends.set(this.outerOf(region), new Set([end]));
|
|
674
816
|
}
|
|
675
|
-
|
|
817
|
+
this.regions.within[region] = within;
|
|
818
|
+
this.regions.leaving[region] = leaving;
|
|
819
|
+
return { within, leaving };
|
|
676
820
|
}
|
|
677
821
|
/** The states the walk goes on to from `state`, none for a built-in or function definition it ends at. */
|
|
678
822
|
expand(state) {
|
|
679
|
-
const [id, viaAccess, call] = this.states[state];
|
|
823
|
+
const [id, viaAccess, call, region] = this.states[state];
|
|
824
|
+
if (region !== undefined) {
|
|
825
|
+
const { within, leaving } = this.expandRegion(region);
|
|
826
|
+
return [...within.map(r => this.outerOf(r)), ...leaving];
|
|
827
|
+
}
|
|
828
|
+
else if (call !== undefined) {
|
|
829
|
+
/* the walk in the bodies the call runs, and the arguments of the call the parameters it reaches there are bound to */
|
|
830
|
+
const entry = this.regionState(id, viaAccess, this.scopeOf(call));
|
|
831
|
+
const successors = [this.outerOf(entry)];
|
|
832
|
+
for (const hit of this.hits.of(entry)) {
|
|
833
|
+
const [arguments_, nextViaAccess] = this.regions.hit.get(hit);
|
|
834
|
+
for (const argument of boundBy(this.graph, call, arguments_, this.passedBy)) {
|
|
835
|
+
successors.push(this.state(argument, nextViaAccess, undefined));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return successors;
|
|
839
|
+
}
|
|
680
840
|
const successors = [];
|
|
681
841
|
const end = walkLinkedDefinitions(this.graph, id, viaAccess, call, this.scopes, (target, nextViaAccess, nextCall) => {
|
|
682
842
|
successors.push(this.state(target, nextViaAccess, nextCall));
|
|
@@ -724,11 +884,17 @@ function linkExpressionIn(graph, expr, environment, idMap) {
|
|
|
724
884
|
}
|
|
725
885
|
/** Links the call `callId` to the functions the given definitions bind, which it did not know of when it was processed. */
|
|
726
886
|
function linkCallToDefinitions(graph, callId, definitions, idMap) {
|
|
887
|
+
if (definitions.length > 0 && vertex_1.DfgVertex.isFunctionCall(graph.getVertex(callId))) {
|
|
888
|
+
linkCallToFunctions(graph, callId, getAllLinkedFunctionDefinitions(new Set(definitions), graph)[0], idMap);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
/** Links the call `callId` to the given functions, as {@link linkCallToDefinitions} does once it found them. */
|
|
892
|
+
function linkCallToFunctions(graph, callId, functions, idMap) {
|
|
727
893
|
const call = graph.getVertex(callId);
|
|
728
|
-
if (
|
|
894
|
+
if (!vertex_1.DfgVertex.isFunctionCall(call)) {
|
|
729
895
|
return;
|
|
730
896
|
}
|
|
731
|
-
for (const fn of
|
|
897
|
+
for (const fn of functions) {
|
|
732
898
|
if (!df_helper_1.Dataflow.hasEdge(graph, callId, fn.id, edge_1.EdgeType.Calls)) {
|
|
733
899
|
linkFunctionCallWithSingleTarget(graph, fn, call, idMap);
|
|
734
900
|
}
|
|
@@ -1258,24 +1258,30 @@ function unanalyzed(id, graph, data) {
|
|
|
1258
1258
|
}
|
|
1259
1259
|
/** what may warn when `root` runs, see {@link WarningSiteMode}, `bodies` holds what may in the bodies of the closures seen so far */
|
|
1260
1260
|
function warningSites(root, graph, data, bodies, mode) {
|
|
1261
|
-
|
|
1261
|
+
/* a set: a body called from many places would otherwise be listed once per call, and spreading such a list overflows the stack */
|
|
1262
|
+
const sites = new Set();
|
|
1263
|
+
const add = (more) => {
|
|
1264
|
+
for (const site of more) {
|
|
1265
|
+
sites.add(site);
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1262
1268
|
const { signal } = mode;
|
|
1263
1269
|
model_1.RNode.visitAst(root, node => {
|
|
1264
1270
|
if (r_function_definition_1.RFunctionDefinition.is(node) || unanalyzed(node.info.id, graph, data)) {
|
|
1265
1271
|
return true;
|
|
1266
1272
|
}
|
|
1267
1273
|
else if (r_binary_op_1.RBinaryOp.is(node) ? r_binary_op_1.RBinaryOp.getOperatorInfo(node)?.usedAs !== base_operators_1.OperatorUsedAs.Assignment : r_unary_op_1.RUnaryOp.is(node) || r_access_1.RAccess.is(node)) {
|
|
1268
|
-
sites.
|
|
1274
|
+
sites.add(node.info.id);
|
|
1269
1275
|
}
|
|
1270
1276
|
else if (signal !== undefined && (r_symbol_1.RSymbol.is(node) ? readMaySignal(node, graph, data.environment, data.completeAst.idMap) : testsValue(node))) {
|
|
1271
|
-
sites.
|
|
1277
|
+
sites.add(node.info.id);
|
|
1272
1278
|
}
|
|
1273
1279
|
else if (r_function_call_1.RFunctionCall.is(node)) {
|
|
1274
1280
|
const targets = node.named ? resolve_helper_1.Resolve.byNameAndType(node.functionName.content, data.environment, identifier_1.ReferenceType.Function) ?? [] : [];
|
|
1275
1281
|
const classes = signal === undefined ? undefined : signaledClasses(node, targets);
|
|
1276
1282
|
if (signal !== undefined && classes !== undefined) {
|
|
1277
1283
|
if (catches(signal, classes)) {
|
|
1278
|
-
sites.
|
|
1284
|
+
sites.add(node.info.id);
|
|
1279
1285
|
}
|
|
1280
1286
|
return false;
|
|
1281
1287
|
}
|
|
@@ -1284,35 +1290,37 @@ function warningSites(root, graph, data, bodies, mode) {
|
|
|
1284
1290
|
}
|
|
1285
1291
|
const handlers = mode.muffled ? muffledHandlers(node, graph, data) : undefined;
|
|
1286
1292
|
if (handlers !== undefined) {
|
|
1287
|
-
|
|
1293
|
+
for (const h of handlers) {
|
|
1294
|
+
add(warningSites(h, graph, data, bodies, mode));
|
|
1295
|
+
}
|
|
1288
1296
|
return true;
|
|
1289
1297
|
}
|
|
1290
1298
|
/* a name the construct does not see, as a global called in a function body, runs what the linker bound to the call */
|
|
1291
1299
|
const callees = targets.length === 0 ? df_helper_1.Dataflow.calleeIdsOf(graph, node.info.id).map(id => data.completeAst.idMap.get(id))
|
|
1292
1300
|
: targets.flatMap(t => hidesBody(t) ? [undefined] : t.value?.map(id => data.completeAst.idMap.get(id)) ?? [undefined]);
|
|
1293
1301
|
if (callees.length === 0 || !callees.every(r_function_definition_1.RFunctionDefinition.is)) {
|
|
1294
|
-
sites.
|
|
1302
|
+
sites.add(node.info.id);
|
|
1295
1303
|
return false;
|
|
1296
1304
|
}
|
|
1297
1305
|
if (signal !== undefined && ErrorClasses.includes(signal.condition) && callees.some(c => rejectsArguments(c, node))) {
|
|
1298
|
-
sites.
|
|
1306
|
+
sites.add(node.info.id);
|
|
1299
1307
|
}
|
|
1300
1308
|
/* the body runs in the function's own scope, we resolve what it calls where the construct is, which is where most functions live */
|
|
1301
|
-
const within = callees.flatMap(c => bodySites(c, graph, data, bodies, mode));
|
|
1309
|
+
const within = new Set(callees.flatMap(c => bodySites(c, graph, data, bodies, mode)));
|
|
1302
1310
|
if (!mode.link) {
|
|
1303
|
-
|
|
1311
|
+
add(within);
|
|
1304
1312
|
return false;
|
|
1305
1313
|
}
|
|
1306
1314
|
for (const site of within) {
|
|
1307
1315
|
graph.addEdge(node.info.id, site, edge_1.EdgeType.Reads);
|
|
1308
1316
|
}
|
|
1309
|
-
if (within.
|
|
1310
|
-
sites.
|
|
1317
|
+
if (within.size > 0) {
|
|
1318
|
+
sites.add(node.info.id);
|
|
1311
1319
|
}
|
|
1312
1320
|
}
|
|
1313
1321
|
return false;
|
|
1314
1322
|
});
|
|
1315
|
-
return sites;
|
|
1323
|
+
return [...sites];
|
|
1316
1324
|
}
|
|
1317
1325
|
/** Whether `node` branches or loops on a value R may reject: a condition that is not `TRUE` or `FALSE` (`if(NA)`, `if(logical(0))`) or a vector that is not a constant. */
|
|
1318
1326
|
function testsValue(node) {
|
|
@@ -538,13 +538,13 @@ function dispatchedS3Methods(call, name, methods, graph, environment, statement,
|
|
|
538
538
|
return { methods: [...callsNext ? pick(undefined) : picked], objects: dispatched };
|
|
539
539
|
}
|
|
540
540
|
/** The definitions `ingoing` resolves to, without those binding only methods the dispatch reading them rules out. */
|
|
541
|
-
function withoutExcludedMethods(ingoing, resolved, graph) {
|
|
541
|
+
function withoutExcludedMethods(ingoing, resolved, graph, methodsOf = (definition) => (0, dispatch_linking_1.linkedFunctionIds)(new Set([definition]), graph)) {
|
|
542
542
|
const excludes = graph.getVertex(ingoing.nodeId)?.ruledOut;
|
|
543
543
|
if (excludes === undefined) {
|
|
544
544
|
return resolved;
|
|
545
545
|
}
|
|
546
546
|
return resolved.filter(d => {
|
|
547
|
-
const methods = (
|
|
547
|
+
const methods = methodsOf(d.nodeId);
|
|
548
548
|
return methods.length === 0 || methods.some(m => !excludes.includes(m));
|
|
549
549
|
});
|
|
550
550
|
}
|
|
@@ -1020,9 +1020,11 @@ function linkLiftedReads(graph, lifted, enclosingOf, environmentAt, runsOnceAt)
|
|
|
1020
1020
|
graph.addEdge(read.nodeId, write, edge_1.EdgeType.Reads);
|
|
1021
1021
|
}
|
|
1022
1022
|
}
|
|
1023
|
+
/* every call sees bindings of the same few functions, and the edges added here leave from the read and the calls, which a walk for the functions a binding holds only passes through to what they return */
|
|
1024
|
+
const methodsOf = (0, defaultmap_1.memoize)((d) => (0, dispatch_linking_1.linkedFunctionIds)(new Set([d]), graph));
|
|
1023
1025
|
for (const call of topLevelCallsOf(definition)) {
|
|
1024
1026
|
const found = resolve_helper_1.Resolve.byNameAndType(read.name, environmentAt(call), read.type);
|
|
1025
|
-
const resolved = found && withoutExcludedMethods(read, found, graph);
|
|
1027
|
+
const resolved = found && withoutExcludedMethods(read, found, graph, methodsOf);
|
|
1026
1028
|
const target = graph.getVertex(holder);
|
|
1027
1029
|
if (resolved === undefined && vertex_1.DfgVertex.isFunctionDefinition(target) && !target.subflow.in.some(r => r.nodeId === read.nodeId)) {
|
|
1028
1030
|
target.subflow.in = [...target.subflow.in, read];
|
|
@@ -45,6 +45,7 @@ const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
|
45
45
|
const arrays_1 = require("../../../../../../util/collections/arrays");
|
|
46
46
|
const r_datasets_1 = require("../../../../../../util/r-datasets");
|
|
47
47
|
const built_in_load_1 = require("./built-in-load");
|
|
48
|
+
const global_caches_1 = require("../../../../../../util/global-caches");
|
|
48
49
|
/** Process a library call like `library` or `require` */
|
|
49
50
|
function processLibrary(name, args, rootId, data, config = {}) {
|
|
50
51
|
/* we do not really know what loading the library does and what side effects it causes, hence we mark it as an unknown side effect */
|
|
@@ -524,7 +525,7 @@ function attachedInEveryBranch(layer) {
|
|
|
524
525
|
return first.done === true || (layer.memory.get(first.value)?.every(d => (0, info_1.happensInEveryBranch)(d.cds)) ?? true);
|
|
525
526
|
}
|
|
526
527
|
/** Immutable base-layer chains, shared across analyses (layers clone before mutating); building one is O(N^2) in exports, so cache and reparent. */
|
|
527
|
-
const baseNamespaceLayerCache =
|
|
528
|
+
const baseNamespaceLayerCache = global_caches_1.GlobalCaches.map('base-namespace-layers', global_caches_1.CacheScope.Process, 8);
|
|
528
529
|
function baseNamespaceCacheKey(ctx, basePackages) {
|
|
529
530
|
return `${String(ctx.env.getCleanEnvFingerprint())}|${ctx.resolvedRVersion}|${basePackages.join(',')}|${ctx.deps.baseRSourceFingerprint()}`;
|
|
530
531
|
}
|
|
@@ -12,6 +12,8 @@ type Data<O> = DataflowProcessorInformation<O & ParentInformation>;
|
|
|
12
12
|
type Args<O> = readonly PotentiallyEmptyRArgument<O & ParentInformation>[];
|
|
13
13
|
/** The registry name of the S4 class `cls`, see {@link S4ClassMark}. */
|
|
14
14
|
export declare function s4ClassName(cls: ClassName): Identifier;
|
|
15
|
+
/** Whether the name is one of {@link s4ClassName}, an entry of the class registry rather than a variable. */
|
|
16
|
+
export declare function isS4ClassName(name: BrandedIdentifier): boolean;
|
|
15
17
|
/** Which arguments of a call name S4 registrations it depends on rather than declares. */
|
|
16
18
|
export interface S4UseConfig {
|
|
17
19
|
/** the argument naming the S4 generic the call answers or asks about (`f` in `setMethod`) */
|