@eagleoutice/flowr 2.15.10 → 2.16.0
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 +23 -26
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/control-flow/happens-before.d.ts +5 -0
- package/control-flow/happens-before.js +48 -34
- package/control-flow/useless-loop.d.ts +1 -1
- package/control-flow/useless-loop.js +29 -42
- package/dataflow/environments/built-in-props.d.ts +9 -0
- package/dataflow/environments/built-in-props.js +25 -19
- package/dataflow/environments/built-in.d.ts +2 -2
- package/dataflow/environments/built-in.js +41 -77
- package/dataflow/environments/default-builtin-config.d.ts +181 -29
- package/dataflow/environments/default-builtin-config.js +38 -24
- package/dataflow/environments/environment.d.ts +6 -4
- package/dataflow/environments/environment.js +54 -121
- package/dataflow/environments/identifier.d.ts +4 -2
- package/dataflow/environments/identifier.js +23 -69
- package/dataflow/environments/reference-to-maybe.d.ts +9 -0
- package/dataflow/environments/reference-to-maybe.js +23 -51
- package/dataflow/environments/resolve-by-name.js +37 -76
- package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
- package/dataflow/eval/resolve/resolve-argument.js +61 -64
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
- package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
- package/dataflow/eval/resolve/resolve.d.ts +4 -0
- package/dataflow/eval/resolve/resolve.js +23 -14
- package/dataflow/extractor.js +176 -59
- package/dataflow/fn/class-declaration.d.ts +8 -2
- package/dataflow/fn/class-declaration.js +96 -97
- package/dataflow/fn/exceptions-of-function.js +68 -37
- package/dataflow/fn/frame-reflection.d.ts +12 -4
- package/dataflow/fn/frame-reflection.js +51 -41
- package/dataflow/fn/function-props.js +15 -33
- package/dataflow/fn/function-semantics.d.ts +11 -3
- package/dataflow/fn/function-semantics.js +6 -0
- package/dataflow/fn/higher-order-function.js +13 -17
- package/dataflow/fn/strict-function.d.ts +13 -0
- package/dataflow/fn/strict-function.js +285 -122
- package/dataflow/graph/call-graph.d.ts +7 -6
- package/dataflow/graph/call-graph.js +35 -46
- package/dataflow/graph/graph.d.ts +6 -1
- package/dataflow/graph/graph.js +57 -66
- package/dataflow/info.d.ts +8 -1
- package/dataflow/info.js +24 -30
- package/dataflow/internal/control-flow.d.ts +31 -4
- package/dataflow/internal/control-flow.js +61 -39
- package/dataflow/internal/linker.d.ts +15 -9
- package/dataflow/internal/linker.js +253 -241
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +446 -78
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +289 -251
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
- package/dataflow/internal/process/functions/call/common.d.ts +1 -3
- package/dataflow/internal/process/functions/call/common.js +36 -76
- package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
- package/dataflow/internal/process/functions/call/deferred.js +54 -57
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
- package/dataflow/internal/process/functions/call/named-call-handling.js +35 -21
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +162 -172
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
- package/dataflow/internal/process/functions/process-parameter.js +25 -32
- package/dataflow/internal/process/process-symbol.js +3 -6
- package/dataflow/internal/program-order.d.ts +26 -0
- package/dataflow/internal/program-order.js +49 -0
- package/documentation/wiki-setup.js +23 -0
- package/linter/linter-rules.d.ts +17 -8
- package/linter/rules/absolute-path.js +63 -87
- package/linter/rules/file-path-validity.d.ts +4 -2
- package/linter/rules/file-path-validity.js +114 -80
- package/linter/rules/namespace-access.js +21 -33
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +60 -48
- package/linter/rules/network-functions.js +11 -7
- package/linter/rules/no-leaked-credentials.js +15 -18
- package/linter/rules/problematic-inputs.d.ts +2 -1
- package/linter/rules/problematic-inputs.js +39 -59
- package/linter/rules/roxygen-arguments.d.ts +9 -4
- package/linter/rules/roxygen-arguments.js +29 -48
- package/linter/rules/seeded-randomness.d.ts +7 -4
- package/linter/rules/seeded-randomness.js +128 -89
- package/linter/rules/stop-with-call-arg.d.ts +4 -2
- package/linter/rules/stop-with-call-arg.js +25 -22
- package/linter/rules/unclosed-connection.js +31 -24
- package/linter/rules/undefined-symbol.d.ts +4 -6
- package/linter/rules/undefined-symbol.js +58 -75
- package/linter/rules/unescaped-arguments.js +18 -44
- package/linter/rules/unused-definition.d.ts +6 -0
- package/linter/rules/unused-definition.js +105 -145
- package/linter/rules/unused-import.d.ts +3 -0
- package/linter/rules/unused-import.js +25 -43
- package/package.json +5 -2
- package/project/flowr-analyzer.js +6 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +16 -41
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
- package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
- package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
- package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
- package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
- package/r-bridge/lang-4.x/ast/model/model.js +19 -43
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/roxygen2/roxygen-parse.js +28 -42
- package/r-bridge/shell.js +6 -0
- package/search/search-executor/search-enrichers.js +25 -37
- package/slicing/static/slice-call.d.ts +4 -3
- package/slicing/static/slice-call.js +56 -88
- package/slicing/static/static-slicer.js +115 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/proc.js +2 -1
- package/util/r-base-packages.d.ts +2 -0
- package/util/r-base-packages.js +23 -13
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CallGraph = void 0;
|
|
4
|
+
exports.fallbackUntargetedCall = fallbackUntargetedCall;
|
|
4
5
|
const graph_1 = require("./graph");
|
|
5
6
|
const vertex_1 = require("./vertex");
|
|
6
7
|
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
@@ -25,10 +26,11 @@ function processCds(vtx, graph, result, state) {
|
|
|
25
26
|
const UntargetedCallFollow = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Returns;
|
|
26
27
|
const UntargetedCallAvoid = edge_1.EdgeType.NonStandardEvaluation | edge_1.EdgeType.Argument;
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
+
* The origins of what a call flowR found no target for calls, following its name back through reads and
|
|
30
|
+
* parameter bindings: `f(x)` within `apply_f <- function(f, x) f(x)` ends at what callers hand in as `f`.
|
|
29
31
|
*/
|
|
30
32
|
function fallbackUntargetedCall(vtx, graph) {
|
|
31
|
-
|
|
33
|
+
/* we track all aliases to their roots here, we know there is no known call target */
|
|
32
34
|
const collected = new Set();
|
|
33
35
|
const visited = new Set();
|
|
34
36
|
const toVisit = [vtx.id];
|
|
@@ -43,13 +45,16 @@ function fallbackUntargetedCall(vtx, graph) {
|
|
|
43
45
|
continue;
|
|
44
46
|
}
|
|
45
47
|
let addedNew = false;
|
|
48
|
+
/* past the call asked about, a call hands back what it returns; a plain read of another call is state it depends on, not its name */
|
|
49
|
+
const follow = currentId !== vtx.id && vertex_1.DfgVertex.isFunctionCall(currentVtx) ? edge_1.EdgeType.Returns : UntargetedCallFollow;
|
|
46
50
|
for (const [tar, e] of graph.edgesFrom(currentId)) {
|
|
47
|
-
if (edge_1.DfEdge.includesType(e,
|
|
51
|
+
if (edge_1.DfEdge.includesType(e, follow) && edge_1.DfEdge.doesNotIncludeType(e, UntargetedCallAvoid)
|
|
52
|
+
&& (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns) || !vertex_1.DfgVertex.isFunctionCall(graph.getVertex(tar)))) {
|
|
48
53
|
addedNew = true;
|
|
49
54
|
toVisit.push(tar);
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
|
-
|
|
57
|
+
/* we have reached our end(s) */
|
|
53
58
|
if (!addedNew && currentId !== vtx.id) {
|
|
54
59
|
collected.add(currentId);
|
|
55
60
|
}
|
|
@@ -67,23 +72,19 @@ function processCall(vtx, from, graph, result, state) {
|
|
|
67
72
|
state.visited.add(vid);
|
|
68
73
|
result.addVertex(vtx, undefined, true);
|
|
69
74
|
processCds(vtx, graph, result, state);
|
|
70
|
-
// for each call, resolve the targets
|
|
71
|
-
const tars = (0, linker_1.getAllFunctionCallTargets)(vid, graph, vtx.environment);
|
|
72
75
|
let addedTarget = false;
|
|
73
76
|
let addedBiTarget = false;
|
|
74
|
-
for (const tar of
|
|
77
|
+
for (const tar of (0, linker_1.getAllFunctionCallTargets)(vid, graph, vtx.environment)) {
|
|
78
|
+
const targetVtx = graph.getVertex(tar);
|
|
75
79
|
if (node_id_1.NodeId.isBuiltIn(tar)) {
|
|
76
80
|
result.addEdge(vid, tar, edge_1.EdgeType.Calls);
|
|
77
81
|
addedTarget = true;
|
|
78
82
|
addedBiTarget = true;
|
|
79
|
-
continue;
|
|
80
83
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
else if (vertex_1.DfgVertex.isFunctionDefinition(targetVtx)) {
|
|
85
|
+
addedTarget = true;
|
|
86
|
+
processFunctionDefinition(targetVtx, vid, graph, result, state);
|
|
84
87
|
}
|
|
85
|
-
addedTarget = true;
|
|
86
|
-
processFunctionDefinition(targetVtx, vid, graph, result, state);
|
|
87
88
|
}
|
|
88
89
|
if (!addedBiTarget && vtx.origin !== 'unnamed') {
|
|
89
90
|
for (const origs of vtx.origin) {
|
|
@@ -94,8 +95,7 @@ function processCall(vtx, from, graph, result, state) {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
if (!addedTarget) {
|
|
97
|
-
const
|
|
98
|
-
for (const ori of origs) {
|
|
98
|
+
for (const ori of fallbackUntargetedCall(vtx, graph)) {
|
|
99
99
|
const oriVtx = graph.getVertex(ori);
|
|
100
100
|
if (!oriVtx) {
|
|
101
101
|
continue;
|
|
@@ -114,30 +114,23 @@ function processCall(vtx, from, graph, result, state) {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
for (const [tar, e] of graph.edgesFrom(
|
|
117
|
+
/* handle arguments, traversing the 'reads' and the 'returns' edges */
|
|
118
|
+
for (const [tar, e] of graph.edgesFrom(vid)) {
|
|
119
119
|
if (edge_1.DfEdge.doesNotIncludeType(e, edge_1.EdgeType.Reads | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument)) {
|
|
120
120
|
continue;
|
|
121
121
|
}
|
|
122
122
|
const tVtx = graph.getVertex(tar);
|
|
123
|
-
if (
|
|
124
|
-
|
|
123
|
+
if (tVtx) {
|
|
124
|
+
processUnknown(tVtx, vid, graph, result, state);
|
|
125
125
|
}
|
|
126
|
-
processUnknown(tVtx, vtx.id, graph, result, state);
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
function processUnknown(vtx, from, graph, result, state) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (from) {
|
|
136
|
-
result.addEdge(from, node_id_1.NodeId.toBuiltIn('function'), edge_1.EdgeType.Calls);
|
|
137
|
-
}
|
|
138
|
-
return;
|
|
139
|
-
default:
|
|
140
|
-
return;
|
|
129
|
+
if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
|
|
130
|
+
processCall(vtx, from, graph, result, state);
|
|
131
|
+
}
|
|
132
|
+
else if (vertex_1.DfgVertex.isFunctionDefinition(vtx) && from) {
|
|
133
|
+
result.addEdge(from, node_id_1.NodeId.toBuiltIn('function'), edge_1.EdgeType.Calls);
|
|
141
134
|
}
|
|
142
135
|
}
|
|
143
136
|
function processFunctionDefinition(vtx, from, graph, result, state) {
|
|
@@ -183,6 +176,15 @@ function followCalls(graph, seeds, reached) {
|
|
|
183
176
|
}
|
|
184
177
|
}
|
|
185
178
|
}
|
|
179
|
+
/** Whether `name` is a `<generic>.<class>` of a generic that is called, as `print.foo` is when `print` is. */
|
|
180
|
+
function mayBeDispatchedTo(name, generics) {
|
|
181
|
+
for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
|
|
182
|
+
if (generics.has(name.slice(0, dot))) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
186
188
|
/** The names the reached calls go by, which are the generics a method of the program may be dispatched to for. */
|
|
187
189
|
function reachedCallNames(graph, reached) {
|
|
188
190
|
const names = new Set();
|
|
@@ -194,15 +196,6 @@ function reachedCallNames(graph, reached) {
|
|
|
194
196
|
}
|
|
195
197
|
return names;
|
|
196
198
|
}
|
|
197
|
-
/** Whether `name` is a `<generic>.<class>` of a generic that is called, as `print.foo` is when `print` is. */
|
|
198
|
-
function mayBeDispatchedTo(name, generics) {
|
|
199
|
-
for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
|
|
200
|
-
if (generics.has(name.slice(0, dot))) {
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
199
|
/**
|
|
207
200
|
* The unreached function definitions that may still run: one the code hands to another call (a callback, an
|
|
208
201
|
* S4 method, a shiny handler), and one bound to a `<generic>.<class>` name of a generic the program calls.
|
|
@@ -244,9 +237,7 @@ function mayRunAnyway(graph, reached) {
|
|
|
244
237
|
exports.CallGraph = {
|
|
245
238
|
...graph_helper_1.GraphHelper,
|
|
246
239
|
name: 'CallGraph',
|
|
247
|
-
/**
|
|
248
|
-
* Extracts the sub call graph from the given call graph, starting from the given entry points.
|
|
249
|
-
*/
|
|
240
|
+
/** Extracts the sub call graph from the given call graph, starting from the given entry points. */
|
|
250
241
|
computeSubCallGraph(graph, entryPoints) {
|
|
251
242
|
const result = new graph_1.DataflowGraph(graph.idMap);
|
|
252
243
|
const toVisit = Array.from(entryPoints);
|
|
@@ -301,9 +292,7 @@ exports.CallGraph = {
|
|
|
301
292
|
.map(([id]) => id)
|
|
302
293
|
.toArray();
|
|
303
294
|
},
|
|
304
|
-
/**
|
|
305
|
-
* Reduces the call graph by dropping all transitive edges.
|
|
306
|
-
*/
|
|
295
|
+
/** Reduces the call graph by dropping all transitive edges. */
|
|
307
296
|
dropTransitiveEdges(graph) {
|
|
308
297
|
const newCg = new graph_1.DataflowGraph(graph.idMap);
|
|
309
298
|
newCg.mergeVertices(graph);
|
|
@@ -142,7 +142,7 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
142
142
|
/** All edges in the complete graph (including those nested in function definition) */
|
|
143
143
|
private edgeInformation;
|
|
144
144
|
private incomingIndex?;
|
|
145
|
-
private
|
|
145
|
+
private types;
|
|
146
146
|
/** The id list of `tag`, created on first use, so a caller adding many ids looks it up once. */
|
|
147
147
|
private typeList;
|
|
148
148
|
private indexType;
|
|
@@ -150,6 +150,8 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
150
150
|
private unindexType;
|
|
151
151
|
private qualifiedNames?;
|
|
152
152
|
toJSON(): DataflowGraphJson;
|
|
153
|
+
/** A view of this graph without the environments of its vertices and subflows, sharing everything else. */
|
|
154
|
+
withoutEnvironments(): DataflowGraph<Vertex, Edge>;
|
|
153
155
|
/** Gets the {@link DataflowGraphVertexInfo} attached to `id` (searching function definitions too if `includeDefinedFunctions`) and its outgoing edges. */
|
|
154
156
|
get(id: NodeId, includeDefinedFunctions?: boolean): [Vertex, OutgoingEdges] | undefined;
|
|
155
157
|
/** Gets the {@link DataflowGraphVertexInfo} attached to `id`, see {@link DataflowGraph#getRootVertex}. */
|
|
@@ -256,6 +258,9 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
256
258
|
* `consume` takes `otherGraph`'s edge tables instead of copying them (perf). Pass it only for a graph that dies with the call.
|
|
257
259
|
*/
|
|
258
260
|
mergeWith(otherGraph: DataflowGraph<Vertex, Edge> | undefined, mergeRootVertices?: boolean, consume?: boolean): this;
|
|
261
|
+
/** An empty graph takes over the contents of a graph it consumes rather than copying them entry by entry. */
|
|
262
|
+
private adopt;
|
|
263
|
+
private mergeRootsAndUnknowns;
|
|
259
264
|
mergeVertices(otherGraph: DataflowGraph<Vertex, Edge>, mergeRootVertices?: boolean): void;
|
|
260
265
|
private mergeEdges;
|
|
261
266
|
/** Marks the vertex referenced by `reference` as a definition, with `sourceIds` as the source vertex ids of the def if known. */
|
package/dataflow/graph/graph.js
CHANGED
|
@@ -40,10 +40,7 @@ exports.FunctionArgument = {
|
|
|
40
40
|
},
|
|
41
41
|
/** The node id of a non-empty `arg`, e.g. of either `a` or `2` in `foo(a=3, 2)`. */
|
|
42
42
|
getId(arg) {
|
|
43
|
-
|
|
44
|
-
return arg?.nodeId;
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
43
|
+
return arg === r_function_call_1.EmptyArgument ? undefined : arg.nodeId;
|
|
47
44
|
},
|
|
48
45
|
/** The name of `arg` if named, `undefined` otherwise. */
|
|
49
46
|
getName(arg) {
|
|
@@ -54,10 +51,7 @@ exports.FunctionArgument = {
|
|
|
54
51
|
if (arg === r_function_call_1.EmptyArgument) {
|
|
55
52
|
return undefined;
|
|
56
53
|
}
|
|
57
|
-
|
|
58
|
-
return arg.nodeId;
|
|
59
|
-
}
|
|
60
|
-
return arg.valueId;
|
|
54
|
+
return arg.name === undefined ? arg.nodeId : arg.valueId;
|
|
61
55
|
},
|
|
62
56
|
/** Whether `arg` is named exactly `name` (textual match only, not R's argument-matching; see {@link FunctionSemantics.call.match.toSpec} for that). */
|
|
63
57
|
hasName(arg, name) {
|
|
@@ -139,10 +133,7 @@ class DataflowGraph {
|
|
|
139
133
|
}
|
|
140
134
|
/** Every write above keeps an id listed under one tag at most once, so a lookup never hands the same one out twice. */
|
|
141
135
|
unindexType(tag, id) {
|
|
142
|
-
const ids = this.types.get(tag);
|
|
143
|
-
if (ids === undefined) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
136
|
+
const ids = this.types.get(tag) ?? [];
|
|
146
137
|
for (let idx = ids.lastIndexOf(id); idx >= 0; idx = ids.lastIndexOf(id)) {
|
|
147
138
|
ids.splice(idx, 1);
|
|
148
139
|
}
|
|
@@ -158,9 +149,20 @@ class DataflowGraph {
|
|
|
158
149
|
_unknownSideEffects: Array.from(this._unknownSideEffects)
|
|
159
150
|
};
|
|
160
151
|
}
|
|
152
|
+
/** A view of this graph without the environments of its vertices and subflows, sharing everything else. */
|
|
153
|
+
withoutEnvironments() {
|
|
154
|
+
const graph = new DataflowGraph(this._idMap);
|
|
155
|
+
graph.rootVertices = this.rootVertices;
|
|
156
|
+
graph.edgeInformation = this.edgeInformation;
|
|
157
|
+
graph.types = this.types;
|
|
158
|
+
graph.vertexInformation = new Map(Array.from(this.vertexInformation, ([id, vertex]) => [id, (vertex_2.DfgVertex.isFunctionDefinition(vertex)
|
|
159
|
+
? { ...vertex, environment: undefined, subflow: { ...vertex.subflow, environment: undefined } }
|
|
160
|
+
: { ...vertex, environment: undefined })]));
|
|
161
|
+
graph.mergeRootsAndUnknowns(this, false);
|
|
162
|
+
return graph;
|
|
163
|
+
}
|
|
161
164
|
/** Gets the {@link DataflowGraphVertexInfo} attached to `id` (searching function definitions too if `includeDefinedFunctions`) and its outgoing edges. */
|
|
162
165
|
get(id, includeDefinedFunctions = true) {
|
|
163
|
-
// if we do not want to include function definitions, only retrieve the value if the id is part of the root vertices
|
|
164
166
|
const vertex = includeDefinedFunctions ? this.getVertex(id) : this.getRootVertex(id);
|
|
165
167
|
return vertex === undefined ? undefined : [vertex, this.outgoingEdges(id) ?? new Map()];
|
|
166
168
|
}
|
|
@@ -170,10 +172,7 @@ class DataflowGraph {
|
|
|
170
172
|
}
|
|
171
173
|
/** Gets the {@link DataflowGraphVertexInfo} attached to `id`, but only if it is a root-level vertex, see {@link DataflowGraph#getVertex}. */
|
|
172
174
|
getRootVertex(id) {
|
|
173
|
-
|
|
174
|
-
return undefined;
|
|
175
|
-
}
|
|
176
|
-
return this.vertexInformation.get(id);
|
|
175
|
+
return this.rootVertices.has(id) ? this.vertexInformation.get(id) : undefined;
|
|
177
176
|
}
|
|
178
177
|
/**
|
|
179
178
|
* The edges leaving `id`, the mutable map the graph stores, `undefined` for a vertex that has none.
|
|
@@ -212,7 +211,7 @@ class DataflowGraph {
|
|
|
212
211
|
ingoingEdges(id) {
|
|
213
212
|
if (this.incomingIndex === undefined) {
|
|
214
213
|
const index = new Map();
|
|
215
|
-
for (const [source, outgoing] of this.edgeInformation
|
|
214
|
+
for (const [source, outgoing] of this.edgeInformation) {
|
|
216
215
|
for (const [target, edge] of outgoing) {
|
|
217
216
|
const into = index.get(target);
|
|
218
217
|
if (into === undefined) {
|
|
@@ -236,10 +235,10 @@ class DataflowGraph {
|
|
|
236
235
|
isQuoted(id, withOutgoing = false) {
|
|
237
236
|
/* an nse edge quotes iff it does not originate from a loop marking its body */
|
|
238
237
|
const quotes = (source, e) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.NonStandardEvaluation) && !model_1.RLoopConstructs.is(this.idMap?.get(source));
|
|
239
|
-
if (this.
|
|
238
|
+
if (this.edgesTo(id).entries().some(([source, e]) => quotes(source, e))) {
|
|
240
239
|
return true;
|
|
241
240
|
}
|
|
242
|
-
return withOutgoing &&
|
|
241
|
+
return withOutgoing && this.edgesFrom(id).values().some(e => quotes(id, e));
|
|
243
242
|
}
|
|
244
243
|
/**
|
|
245
244
|
* The cached `pkg::fn` name of the call `id`, asking `resolve` only for a call the cache does not know yet.
|
|
@@ -287,9 +286,7 @@ class DataflowGraph {
|
|
|
287
286
|
/** Drops the cached qualifications, as the graph may no longer imply them. Every mutator runs through here, so the guard covers them all. */
|
|
288
287
|
dropQualifications() {
|
|
289
288
|
(0, assert_1.guard)(!this.consumed, 'this graph was consumed by a merge and must not be changed any more');
|
|
290
|
-
|
|
291
|
-
this.qualifiedNames = undefined;
|
|
292
|
-
}
|
|
289
|
+
this.qualifiedNames = undefined;
|
|
293
290
|
}
|
|
294
291
|
/** For a node of the normalized AST: `nodeId` if it is a DFG vertex itself, else the DFG vertices linked to it, else `undefined`. */
|
|
295
292
|
getLinked(nodeId) {
|
|
@@ -329,11 +326,7 @@ class DataflowGraph {
|
|
|
329
326
|
}
|
|
330
327
|
/** Every vertex carrying `type`, in the order the graph learned of them. */
|
|
331
328
|
*verticesOfType(type) {
|
|
332
|
-
const
|
|
333
|
-
if (ids === undefined) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
for (const id of ids) {
|
|
329
|
+
for (const id of this.types.get(type) ?? []) {
|
|
337
330
|
const vertex = this.vertexInformation.get(id);
|
|
338
331
|
/* a stale entry would hand out a vertex without the fields its tag promises */
|
|
339
332
|
if (vertex?.tag === type) {
|
|
@@ -343,11 +336,7 @@ class DataflowGraph {
|
|
|
343
336
|
}
|
|
344
337
|
/** The ids of {@link DataflowGraph#verticesOfType|verticesOfType}, as a fresh array the caller may keep. */
|
|
345
338
|
vertexIdsOfType(type) {
|
|
346
|
-
|
|
347
|
-
if (ids === undefined) {
|
|
348
|
-
return [];
|
|
349
|
-
}
|
|
350
|
-
return ids.filter(id => this.vertexInformation.get(id)?.tag === type);
|
|
339
|
+
return this.types.get(type)?.filter(id => this.vertexInformation.get(id)?.tag === type) ?? [];
|
|
351
340
|
}
|
|
352
341
|
/** Ids of all edges in the graph together with their edge information, see {@link DataflowGraph#vertices}. */
|
|
353
342
|
*edges() {
|
|
@@ -420,7 +409,7 @@ class DataflowGraph {
|
|
|
420
409
|
}
|
|
421
410
|
this.dropQualifications();
|
|
422
411
|
const vtag = vertex.tag;
|
|
423
|
-
|
|
412
|
+
/* keep a clone of the original environment, isolating the snapshot from later updates */
|
|
424
413
|
let environment;
|
|
425
414
|
if (vertex.environment) {
|
|
426
415
|
environment = (0, clone_1.cloneEnvironmentInformation)(vertex.environment);
|
|
@@ -431,9 +420,7 @@ class DataflowGraph {
|
|
|
431
420
|
}
|
|
432
421
|
vertex.environment = environment;
|
|
433
422
|
this.vertexInformation.set(vid, vertex);
|
|
434
|
-
|
|
435
|
-
gas_1.activeDataflowBudget.vertex();
|
|
436
|
-
}
|
|
423
|
+
gas_1.activeDataflowBudget?.vertex();
|
|
437
424
|
/* an overwrite keeping the tag is indexed already */
|
|
438
425
|
if (previous?.tag !== vtag) {
|
|
439
426
|
if (previous !== undefined) {
|
|
@@ -494,14 +481,30 @@ class DataflowGraph {
|
|
|
494
481
|
return this;
|
|
495
482
|
}
|
|
496
483
|
(0, assert_1.guard)(!otherGraph.consumed, 'a graph consumed by an earlier merge cannot be merged again');
|
|
497
|
-
this.
|
|
498
|
-
|
|
484
|
+
if (consume && this.vertexInformation.size === 0 && this.edgeInformation.size === 0) {
|
|
485
|
+
this.adopt(otherGraph, mergeRootVertices);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
this.mergeVertices(otherGraph, mergeRootVertices);
|
|
489
|
+
this.mergeEdges(otherGraph, consume);
|
|
490
|
+
}
|
|
499
491
|
otherGraph.consumed ||= consume;
|
|
500
492
|
return this;
|
|
501
493
|
}
|
|
502
|
-
|
|
494
|
+
/** An empty graph takes over the contents of a graph it consumes rather than copying them entry by entry. */
|
|
495
|
+
adopt(otherGraph, mergeRootVertices) {
|
|
503
496
|
this.dropQualifications();
|
|
504
|
-
|
|
497
|
+
this.vertexInformation = otherGraph.vertexInformation;
|
|
498
|
+
this.edgeInformation = otherGraph.edgeInformation;
|
|
499
|
+
this.types = otherGraph.types;
|
|
500
|
+
this.incomingIndex = undefined;
|
|
501
|
+
const takeRoots = mergeRootVertices && this.rootVertices.size === 0;
|
|
502
|
+
if (takeRoots) {
|
|
503
|
+
this.rootVertices = otherGraph.rootVertices;
|
|
504
|
+
}
|
|
505
|
+
this.mergeRootsAndUnknowns(otherGraph, mergeRootVertices && !takeRoots);
|
|
506
|
+
}
|
|
507
|
+
mergeRootsAndUnknowns(otherGraph, mergeRootVertices) {
|
|
505
508
|
if (mergeRootVertices) {
|
|
506
509
|
for (const root of otherGraph.rootVertices) {
|
|
507
510
|
this.rootVertices.add(root);
|
|
@@ -510,6 +513,10 @@ class DataflowGraph {
|
|
|
510
513
|
for (const unknown of otherGraph.unknownSideEffects) {
|
|
511
514
|
this._unknownSideEffects.add(unknown);
|
|
512
515
|
}
|
|
516
|
+
}
|
|
517
|
+
mergeVertices(otherGraph, mergeRootVertices = true) {
|
|
518
|
+
this.dropQualifications();
|
|
519
|
+
this.mergeRootsAndUnknowns(otherGraph, mergeRootVertices);
|
|
513
520
|
/* the tags of the vertices coming in repeat, so the list each goes on is looked up only when it changes */
|
|
514
521
|
let lastTag;
|
|
515
522
|
let lastIds = [];
|
|
@@ -602,14 +609,10 @@ class DataflowGraph {
|
|
|
602
609
|
}
|
|
603
610
|
/** Marks the given node as having unknown side effects */
|
|
604
611
|
markIdForUnknownSideEffects(id, target) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
});
|
|
610
|
-
return this;
|
|
611
|
-
}
|
|
612
|
-
this._unknownSideEffects.add(node_id_1.NodeId.normalize(id));
|
|
612
|
+
this._unknownSideEffects.add(target ? {
|
|
613
|
+
id: node_id_1.NodeId.normalize(id),
|
|
614
|
+
linkTo: typeof target.callName === 'string' ? { ...target, callName: new RegExp(target.callName) } : target
|
|
615
|
+
} : node_id_1.NodeId.normalize(id));
|
|
613
616
|
return this;
|
|
614
617
|
}
|
|
615
618
|
/** Constructs a dataflow graph instance from the given JSON data, e.g. as sent by the flowR server for further analysis. */
|
|
@@ -634,10 +637,7 @@ class DataflowGraph {
|
|
|
634
637
|
}
|
|
635
638
|
exports.DataflowGraph = DataflowGraph;
|
|
636
639
|
function mergeNodeInfos(current, next) {
|
|
637
|
-
if (current.tag
|
|
638
|
-
return current;
|
|
639
|
-
}
|
|
640
|
-
else if (vertex_2.DfgVertex.isFunctionDefinition(current)) {
|
|
640
|
+
if (current.tag === next.tag && vertex_2.DfgVertex.isFunctionDefinition(current)) {
|
|
641
641
|
const n = next;
|
|
642
642
|
current.exitPoints = (0, arrays_1.uniqueArrayMerge)(current.exitPoints, n.exitPoints);
|
|
643
643
|
if (n.mode && n.mode.length > 0) {
|
|
@@ -653,24 +653,15 @@ function mergeNodeInfos(current, next) {
|
|
|
653
653
|
}
|
|
654
654
|
function envFromJson(json) {
|
|
655
655
|
const parent = json.parent ? envFromJson(json.parent) : undefined;
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
}
|
|
660
|
-
const obj = new environment_1.Environment(parent, json.builtInEnv);
|
|
661
|
-
obj.id = json.id;
|
|
662
|
-
obj.adoptMap(memory);
|
|
663
|
-
const env = obj;
|
|
656
|
+
const env = new environment_1.Environment(parent, json.builtInEnv);
|
|
657
|
+
env.id = json.id;
|
|
658
|
+
env.adoptMap(new Map(Object.entries(json.memory)));
|
|
664
659
|
env.n = json.n;
|
|
665
660
|
env.t = json.t;
|
|
666
661
|
env.globalEnv = json.globalEnv;
|
|
667
662
|
return env;
|
|
668
663
|
}
|
|
669
664
|
function renvFromJson(json) {
|
|
670
|
-
|
|
671
|
-
return {
|
|
672
|
-
current,
|
|
673
|
-
level: json.level
|
|
674
|
-
};
|
|
665
|
+
return { current: envFromJson(json.current), level: json.level };
|
|
675
666
|
}
|
|
676
667
|
//# sourceMappingURL=graph.js.map
|
package/dataflow/info.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface ControlDependency {
|
|
|
21
21
|
readonly when?: boolean;
|
|
22
22
|
/** whether this control dependency was created due to iteration (e.g., a loop) */
|
|
23
23
|
readonly byIteration?: boolean;
|
|
24
|
+
/** whether this control dependency is a promise's: what stands under it runs only once the call `id` forces it, see {@link ControlFlow.withinPromise} */
|
|
25
|
+
readonly byPromise?: boolean;
|
|
24
26
|
/**
|
|
25
27
|
* any file-exist assumptions made
|
|
26
28
|
*/
|
|
@@ -93,6 +95,8 @@ export interface ExitPoint {
|
|
|
93
95
|
readonly type: ExitPointType;
|
|
94
96
|
/** The id of the node which causes the exit point! */
|
|
95
97
|
readonly nodeId: NodeId;
|
|
98
|
+
/** The jump this exit stands for, when {@link ExitPoint#nodeId|nodeId} is a construct it leaves through */
|
|
99
|
+
readonly jump?: NodeId;
|
|
96
100
|
/**
|
|
97
101
|
* Control dependencies which influence if the exit point triggers
|
|
98
102
|
* (e.g., if the `return` is contained within an `if` statement).
|
|
@@ -100,12 +104,15 @@ export interface ExitPoint {
|
|
|
100
104
|
*/
|
|
101
105
|
readonly cds?: ControlDependency[];
|
|
102
106
|
}
|
|
107
|
+
/** `exit` leaving through the construct `rootId`, which keeps the jump it stands for. */
|
|
108
|
+
export declare function leaveThrough(exit: ExitPoint, rootId: NodeId): ExitPoint;
|
|
103
109
|
/**
|
|
104
110
|
* Adds all non-default exit points to the existing list and updates the `invertExitCds` accordingly.
|
|
105
111
|
*/
|
|
106
112
|
export declare function addNonDefaultExitPoints(existing: ExitPoint[], invertExitCds: ControlDependency[], activeCds: ControlDependency[] | undefined, add: readonly ExitPoint[]): void;
|
|
107
113
|
/**
|
|
108
|
-
* Overwrites the existing exit points with the given ones, taking care of cds
|
|
114
|
+
* Overwrites the existing exit points with the given ones, taking care of cds:
|
|
115
|
+
* the existing ones stay if the replacements only happen in some branches.
|
|
109
116
|
*/
|
|
110
117
|
export declare function overwriteExitPoints(existing: readonly ExitPoint[], replace: ExitPoint[]): ExitPoint[];
|
|
111
118
|
/**
|
package/dataflow/info.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.appendCds = appendCds;
|
|
|
5
5
|
exports.withCds = withCds;
|
|
6
6
|
exports.negateControlDependency = negateControlDependency;
|
|
7
7
|
exports.doesExitPointPropagateCalls = doesExitPointPropagateCalls;
|
|
8
|
+
exports.leaveThrough = leaveThrough;
|
|
8
9
|
exports.addNonDefaultExitPoints = addNonDefaultExitPoints;
|
|
9
10
|
exports.overwriteExitPoints = overwriteExitPoints;
|
|
10
11
|
exports.happensInEveryBranch = happensInEveryBranch;
|
|
@@ -13,7 +14,6 @@ exports.filterOutLoopExitPoints = filterOutLoopExitPoints;
|
|
|
13
14
|
exports.diffControlDependency = diffControlDependency;
|
|
14
15
|
exports.diffControlDependencies = diffControlDependencies;
|
|
15
16
|
const graph_1 = require("./graph/graph");
|
|
16
|
-
const assert_1 = require("../util/assert");
|
|
17
17
|
const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
|
|
18
18
|
/** Whether the two control dependencies trigger on the same condition and branch. */
|
|
19
19
|
function sameControlDependency(a, b) {
|
|
@@ -48,10 +48,7 @@ exports.ControlDependency = {
|
|
|
48
48
|
};
|
|
49
49
|
/** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
|
|
50
50
|
function appendCds(target, toAdd) {
|
|
51
|
-
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
for (const add of toAdd) {
|
|
51
|
+
for (const add of toAdd ?? []) {
|
|
55
52
|
if (!target.some(have => sameControlDependency(have, add))) {
|
|
56
53
|
target.push(add);
|
|
57
54
|
}
|
|
@@ -59,7 +56,7 @@ function appendCds(target, toAdd) {
|
|
|
59
56
|
}
|
|
60
57
|
/** A copy of `base` with `toAdd` appended, skipping the control dependencies that are already in there. */
|
|
61
58
|
function withCds(base, toAdd) {
|
|
62
|
-
const result = base
|
|
59
|
+
const result = [...base ?? []];
|
|
63
60
|
appendCds(result, toAdd);
|
|
64
61
|
return result;
|
|
65
62
|
}
|
|
@@ -79,30 +76,29 @@ function negateControlDependency(cd) {
|
|
|
79
76
|
function doesExitPointPropagateCalls(type) {
|
|
80
77
|
return type === 4 /* ExitPointType.Error */;
|
|
81
78
|
}
|
|
79
|
+
/** `exit` leaving through the construct `rootId`, which keeps the jump it stands for. */
|
|
80
|
+
function leaveThrough(exit, rootId) {
|
|
81
|
+
return { ...exit, nodeId: rootId, jump: exit.jump ?? exit.nodeId };
|
|
82
|
+
}
|
|
82
83
|
/**
|
|
83
84
|
* Adds all non-default exit points to the existing list and updates the `invertExitCds` accordingly.
|
|
84
85
|
*/
|
|
85
86
|
function addNonDefaultExitPoints(existing, invertExitCds, activeCds, add) {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (const ep of toAdd) {
|
|
92
|
-
existing.push(ep);
|
|
93
|
-
}
|
|
94
|
-
for (const icd of invertedCds) {
|
|
95
|
-
if (!invertExitCds.some(e => e.id === icd.id && e.when === icd.when)) {
|
|
96
|
-
invertExitCds.push(icd);
|
|
87
|
+
for (const ep of add) {
|
|
88
|
+
if (ep.type !== 0 /* ExitPointType.Default */) {
|
|
89
|
+
existing.push(ep);
|
|
90
|
+
const ownCds = exports.ControlDependency.minus(ep.cds ?? [], activeCds ?? []);
|
|
91
|
+
appendCds(invertExitCds, ownCds.map(negateControlDependency));
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
94
|
}
|
|
100
95
|
/**
|
|
101
|
-
* Overwrites the existing exit points with the given ones, taking care of cds
|
|
96
|
+
* Overwrites the existing exit points with the given ones, taking care of cds:
|
|
97
|
+
* the existing ones stay if the replacements only happen in some branches.
|
|
102
98
|
*/
|
|
103
99
|
function overwriteExitPoints(existing, replace) {
|
|
104
100
|
const replaceCds = replace.flatMap(e => e.cds);
|
|
105
|
-
if (replaceCds.length === 0 || replaceCds.includes(undefined) || happensInEveryBranch(replaceCds
|
|
101
|
+
if (replaceCds.length === 0 || replaceCds.includes(undefined) || happensInEveryBranch(replaceCds)) {
|
|
106
102
|
return replace;
|
|
107
103
|
}
|
|
108
104
|
return existing.concat(replace);
|
|
@@ -149,22 +145,20 @@ function happensInEveryBranch(cds) {
|
|
|
149
145
|
function coversSet(cds) {
|
|
150
146
|
/* as deep as the surrounding branches, so the pairwise scan beats any set */
|
|
151
147
|
for (const { id, when } of cds) {
|
|
152
|
-
if (when !==
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
let counterpart = false;
|
|
156
|
-
for (const other of cds) {
|
|
157
|
-
if (other.id === id && other.when === !when) {
|
|
158
|
-
counterpart = true;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (!counterpart) {
|
|
148
|
+
if (when !== undefined && !hasCounterpart(cds, id, !when)) {
|
|
163
149
|
return false;
|
|
164
150
|
}
|
|
165
151
|
}
|
|
166
152
|
return true;
|
|
167
153
|
}
|
|
154
|
+
function hasCounterpart(cds, id, when) {
|
|
155
|
+
for (const other of cds) {
|
|
156
|
+
if (other.id === id && other.when === when) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
168
162
|
/** As {@link happensInEveryBranch}, but for a set of control dependencies. */
|
|
169
163
|
function happensInEveryBranchSet(cds) {
|
|
170
164
|
return cds === undefined || (cds.size !== 0 && coversSet(cds));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
2
2
|
import type { DataflowGraph } from '../graph/graph';
|
|
3
|
-
import type { DataflowCfgInformation } from '../info';
|
|
3
|
+
import type { DataflowCfgInformation, ExitPoint } from '../info';
|
|
4
4
|
import { ControlDependency, ExitPointType } from '../info';
|
|
5
|
+
import { Ternary } from '../../util/logic';
|
|
5
6
|
/**
|
|
6
7
|
* Records the control flow of a program in the {@link DataflowGraph} while the dataflow analysis walks it.
|
|
7
8
|
* The {@link ControlFlowGraph} is a view on what is recorded here.
|
|
@@ -41,7 +42,7 @@ export declare const ControlFlow: {
|
|
|
41
42
|
readonly isExpression: (this: void, graph: DataflowGraph, id: NodeId) => boolean;
|
|
42
43
|
/**
|
|
43
44
|
* Whether the subtree always jumps away instead of being left normally, i.e. whether a non-default exit
|
|
44
|
-
* point happens in every branch.
|
|
45
|
+
* point happens in every branch. The control dependencies in `context` (like a promise's) hold for the whole subtree.
|
|
45
46
|
* @see {@link ControlFlow#canComplete|canComplete()} - for whether it can be left normally at all
|
|
46
47
|
* @example
|
|
47
48
|
* ```r
|
|
@@ -49,7 +50,7 @@ export declare const ControlFlow: {
|
|
|
49
50
|
* { if(u) break } # only maybe
|
|
50
51
|
* ```
|
|
51
52
|
*/
|
|
52
|
-
readonly alwaysExits: (this: void, info: DataflowCfgInformation) => boolean;
|
|
53
|
+
readonly alwaysExits: (this: void, info: DataflowCfgInformation, context?: readonly ControlDependency[]) => boolean;
|
|
53
54
|
/**
|
|
54
55
|
* Whether the subtree can be left normally instead of always jumping away.
|
|
55
56
|
* @see {@link ControlFlow#alwaysExits|alwaysExits()} - for whether it always jumps away
|
|
@@ -80,13 +81,39 @@ export declare const ControlFlow: {
|
|
|
80
81
|
*/
|
|
81
82
|
readonly branchesTo: (this: void, graph: DataflowGraph, from: DataflowCfgInformation, target: NodeId, cd: ControlDependency) => void;
|
|
82
83
|
/**
|
|
83
|
-
* Every jump of the given kind within `from` lands on `target
|
|
84
|
+
* Every jump of the given kind within `from` lands on `target`, which reads a `break` as it decides how often a loop runs.
|
|
84
85
|
* @example
|
|
85
86
|
* ```r
|
|
86
87
|
* while(u) { break } # the `break` lands on the loop it leaves
|
|
87
88
|
* ```
|
|
88
89
|
*/
|
|
89
90
|
readonly jumpsTo: (this: void, graph: DataflowGraph, from: DataflowCfgInformation, kind: ExitPointType, target: NodeId) => void;
|
|
91
|
+
/**
|
|
92
|
+
* What is handed to `holder` runs only once `holder` forces it, so it is analyzed under that control
|
|
93
|
+
* dependency: a definition within a promise may not happen, and what it would overwrite stays visible.
|
|
94
|
+
* @see {@link ControlFlow#promise|promise()} - for the jumps within a promise
|
|
95
|
+
* @example
|
|
96
|
+
* ```r
|
|
97
|
+
* g(x <- 2) # `x` is 2 afterwards only if `g` forces its argument
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
readonly withinPromise: <Data extends {
|
|
101
|
+
readonly cds?: readonly ControlDependency[];
|
|
102
|
+
}>(this: void, data: Data, holder: NodeId) => Data;
|
|
103
|
+
/**
|
|
104
|
+
* The jumps within a promise, an argument or default R evaluates only if `holder` forces it. A jump
|
|
105
|
+
* - never runs if the promise is {@link Ternary#Never|never} forced, so control resumes at `holder`,
|
|
106
|
+
* - leaves whenever reached if it is {@link Ternary#Always|always} forced,
|
|
107
|
+
* - otherwise stays an exit under a `byPromise` dependency on `holder`, and control may resume at `holder` as well,
|
|
108
|
+
* until {@link FunctionSemantics.settleJumpsInPromises} settles it.
|
|
109
|
+
* @returns the exit points the holder takes over from the promise
|
|
110
|
+
* @example
|
|
111
|
+
* ```r
|
|
112
|
+
* g(return(1)) # whether this returns is up to `g`
|
|
113
|
+
* function(x = break) x # the `break` runs where `x` is first used
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
readonly promise: (this: void, graph: DataflowGraph, promise: DataflowCfgInformation | undefined, forcing: Ternary, holder: NodeId) => ExitPoint[];
|
|
90
117
|
/**
|
|
91
118
|
* The parts run one after the other and the last one continues with `last`, if it is given.
|
|
92
119
|
* Parts that are `undefined` are skipped, which keeps optional arguments cheap to handle.
|