@eagleoutice/flowr 2.13.12 → 2.13.14
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 +29 -26
- package/benchmark/calibration.d.ts +18 -0
- package/benchmark/calibration.js +63 -0
- package/benchmark/slicer.d.ts +19 -0
- package/benchmark/slicer.js +84 -1
- package/benchmark/stats/feature-counts.d.ts +6 -0
- package/benchmark/stats/feature-counts.js +61 -0
- package/benchmark/stats/print.js +20 -0
- package/benchmark/stats/sigdb-counts.d.ts +7 -0
- package/benchmark/stats/sigdb-counts.js +219 -0
- package/benchmark/stats/size-of.d.ts +6 -0
- package/benchmark/stats/size-of.js +8 -0
- package/benchmark/stats/stats.d.ts +79 -0
- package/benchmark/stats/stats.js +7 -1
- package/benchmark/stopwatch.d.ts +4 -0
- package/benchmark/stopwatch.js +12 -1
- package/benchmark/summarizer/data.d.ts +17 -1
- package/benchmark/summarizer/first-phase/input.js +5 -0
- package/benchmark/summarizer/first-phase/process.js +12 -2
- package/benchmark/summarizer/second-phase/graph.d.ts +1 -1
- package/benchmark/summarizer/second-phase/graph.js +214 -16
- package/benchmark/summarizer/second-phase/process.js +56 -0
- package/benchmark/summarizer/summarizer.js +1 -2
- package/cli/benchmark-app.d.ts +1 -0
- package/cli/benchmark-app.js +2 -1
- package/cli/benchmark-helper-app.d.ts +1 -0
- package/cli/benchmark-helper-app.js +12 -2
- package/cli/common/options.d.ts +10 -0
- package/cli/common/options.js +3 -1
- package/cli/common/scripts-info.d.ts +10 -0
- package/config.js +13 -7
- package/control-flow/cfg-builder.d.ts +30 -0
- package/control-flow/cfg-builder.js +79 -0
- package/control-flow/extract-cfg.js +17 -10
- package/dataflow/environments/apply-kill.d.ts +3 -3
- package/dataflow/environments/apply-kill.js +60 -31
- package/dataflow/environments/reference-to-maybe.d.ts +5 -3
- package/dataflow/environments/reference-to-maybe.js +17 -52
- package/dataflow/environments/resolve-helper.d.ts +2 -1
- package/dataflow/environments/resolve-helper.js +2 -1
- package/dataflow/graph/df-helper.d.ts +2 -1
- package/dataflow/info.d.ts +7 -1
- package/dataflow/info.js +36 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +33 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +6 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +7 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +8 -1
- package/documentation/doc-readme.js +5 -2
- package/documentation/doc-util/doc-issue.d.ts +2 -0
- package/documentation/doc-util/doc-issue.js +3 -1
- package/documentation/wiki-analyzer.js +10 -4
- package/documentation/wiki-core.js +58 -0
- package/documentation/wiki-dataflow-graph.js +4 -0
- package/documentation/wiki-faq.js +6 -2
- package/documentation/wiki-onboarding.js +11 -1
- package/documentation/wiki-setup.js +2 -1
- package/gas.d.ts +56 -6
- package/package.json +9 -4
- package/project/cache/flowr-analyzer-cache.d.ts +1 -0
- package/project/cache/flowr-analyzer-cache.js +4 -0
- package/project/context/flowr-analyzer-context.js +5 -0
- package/project/context/flowr-analyzer-gas-context.d.ts +58 -4
- package/project/context/flowr-analyzer-gas-context.js +137 -15
- package/project/flowr-analyzer.d.ts +25 -7
- package/project/flowr-analyzer.js +6 -6
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -9
- package/slicing/static/slice-call.js +4 -4
- package/slicing/static/slicer-types.d.ts +13 -0
- package/slicing/static/static-slicer.d.ts +7 -1
- package/slicing/static/static-slicer.js +11 -5
- package/slicing/static/visiting-queue.d.ts +3 -1
- package/slicing/static/visiting-queue.js +4 -1
- package/util/node-version.d.ts +4 -0
- package/util/node-version.js +29 -0
- package/util/version.js +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CfgBuilder = void 0;
|
|
4
|
+
const control_flow_graph_1 = require("./control-flow-graph");
|
|
5
|
+
/**
|
|
6
|
+
* Records the vertices and edges of a control flow graph instead of building it, as the bottom-up fold would
|
|
7
|
+
* copy an eager graph once per nesting level. {@link CfgBuilder#mergeWith|mergeWith()} only references the other
|
|
8
|
+
* builder, {@link CfgBuilder#materialize|materialize()} replays everything once in recording order — the
|
|
9
|
+
* order an eager merge produced, which the vertex order of a function definition's children relies on.
|
|
10
|
+
*/
|
|
11
|
+
class CfgBuilder {
|
|
12
|
+
operations = [];
|
|
13
|
+
addVertex(vertex, rootVertex = true) {
|
|
14
|
+
this.operations.push({ kind: 0 /* BuilderOperationType.Vertex */, vertex, root: rootVertex });
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
addEdge(from, to, edge) {
|
|
18
|
+
this.operations.push({ kind: 1 /* BuilderOperationType.Edge */, from, to, edge });
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Record that the other builder is part of this one, it must not be modified afterwards.
|
|
23
|
+
* @param other - the builder to include
|
|
24
|
+
* @param forceNested - should its vertices count as nested (e.g., within a function definition)
|
|
25
|
+
*/
|
|
26
|
+
mergeWith(other, forceNested = false) {
|
|
27
|
+
this.operations.push({ kind: 2 /* BuilderOperationType.Merge */, other, nested: forceNested });
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/** The last vertex recorded for the given id, searching the merged builders only if we hold none. */
|
|
31
|
+
getVertex(id) {
|
|
32
|
+
for (let i = this.operations.length - 1; i >= 0; i--) {
|
|
33
|
+
const operation = this.operations[i];
|
|
34
|
+
if (operation.kind === 0 /* BuilderOperationType.Vertex */) {
|
|
35
|
+
if (control_flow_graph_1.CfgVertex.getId(operation.vertex) === id) {
|
|
36
|
+
return operation.vertex;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (operation.kind === 2 /* BuilderOperationType.Merge */) {
|
|
40
|
+
const found = operation.other.getVertex(id);
|
|
41
|
+
if (found !== undefined) {
|
|
42
|
+
return found;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
/** The ids of all vertices that are not nested, in insertion order. */
|
|
49
|
+
rootIds(collected = new Set()) {
|
|
50
|
+
for (const operation of this.operations) {
|
|
51
|
+
if (operation.kind === 0 /* BuilderOperationType.Vertex */) {
|
|
52
|
+
if (operation.root) {
|
|
53
|
+
collected.add(control_flow_graph_1.CfgVertex.getId(operation.vertex));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (operation.kind === 2 /* BuilderOperationType.Merge */ && !operation.nested) {
|
|
57
|
+
operation.other.rootIds(collected);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return collected;
|
|
61
|
+
}
|
|
62
|
+
/** Replays all recorded operations into a {@link ControlFlowGraph}. */
|
|
63
|
+
materialize(graph = new control_flow_graph_1.ControlFlowGraph(), nested = false) {
|
|
64
|
+
for (const operation of this.operations) {
|
|
65
|
+
if (operation.kind === 0 /* BuilderOperationType.Vertex */) {
|
|
66
|
+
graph.addVertex(operation.vertex, operation.root && !nested);
|
|
67
|
+
}
|
|
68
|
+
else if (operation.kind === 1 /* BuilderOperationType.Edge */) {
|
|
69
|
+
graph.addEdge(operation.from, operation.to, operation.edge);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
operation.other.materialize(graph, nested || operation.nested);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return graph;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.CfgBuilder = CfgBuilder;
|
|
79
|
+
//# sourceMappingURL=cfg-builder.js.map
|
|
@@ -12,12 +12,19 @@ const linker_1 = require("../dataflow/internal/linker");
|
|
|
12
12
|
const vertex_1 = require("../dataflow/graph/vertex");
|
|
13
13
|
const control_flow_graph_1 = require("./control-flow-graph");
|
|
14
14
|
const cfg_simplification_1 = require("./cfg-simplification");
|
|
15
|
+
const cfg_builder_1 = require("./cfg-builder");
|
|
15
16
|
const assert_1 = require("../util/assert");
|
|
16
17
|
const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
|
|
17
18
|
const stateful_fold_1 = require("../r-bridge/lang-4.x/ast/model/processing/stateful-fold");
|
|
18
19
|
const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
|
|
19
20
|
const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
|
|
20
21
|
const identifier_1 = require("../dataflow/environments/identifier");
|
|
22
|
+
function emptyCfgFoldInformation() {
|
|
23
|
+
return { graph: new cfg_builder_1.CfgBuilder(), breaks: [], nexts: [], returns: [], exitPoints: [], entryPoints: [] };
|
|
24
|
+
}
|
|
25
|
+
function materializeCfg(info) {
|
|
26
|
+
return { ...info, graph: info.graph.materialize() };
|
|
27
|
+
}
|
|
21
28
|
const cfgFolds = {
|
|
22
29
|
down: (n, down) => {
|
|
23
30
|
if (r_function_definition_1.RFunctionDefinition.is(n)) {
|
|
@@ -112,7 +119,7 @@ function cfgFoldProject(proj, folds) {
|
|
|
112
119
|
return (0, control_flow_graph_1.emptyControlFlowInformation)();
|
|
113
120
|
}
|
|
114
121
|
else if (proj.files.length === 1) {
|
|
115
|
-
return (0, stateful_fold_1.foldAstStateful)(proj.files[0].root, [false, false], folds);
|
|
122
|
+
return materializeCfg((0, stateful_fold_1.foldAstStateful)(proj.files[0].root, [false, false], folds));
|
|
116
123
|
}
|
|
117
124
|
/* for many files, it is too expensive to keep all asts at once, hence we create and merge them incrementally */
|
|
118
125
|
let exitPoints;
|
|
@@ -149,14 +156,14 @@ function cfgFoldProject(proj, folds) {
|
|
|
149
156
|
returns,
|
|
150
157
|
exitPoints,
|
|
151
158
|
entryPoints: firstEntryPoints,
|
|
152
|
-
graph: finalGraph
|
|
159
|
+
graph: finalGraph.materialize()
|
|
153
160
|
};
|
|
154
161
|
}
|
|
155
162
|
function cfgLeaf(type) {
|
|
156
163
|
return type === control_flow_graph_1.CfgVertexType.Expression ? ({ info: { id } }) => {
|
|
157
|
-
return { graph: new
|
|
164
|
+
return { graph: new cfg_builder_1.CfgBuilder().addVertex(control_flow_graph_1.CfgVertex.makeExpression(id)), breaks: [], nexts: [], returns: [], exitPoints: [id], entryPoints: [id] };
|
|
158
165
|
} : ({ info: { id } }) => {
|
|
159
|
-
return { graph: new
|
|
166
|
+
return { graph: new cfg_builder_1.CfgBuilder().addVertex(control_flow_graph_1.CfgVertex.makeStatement(id)), breaks: [], nexts: [], returns: [], exitPoints: [id], entryPoints: [id] };
|
|
160
167
|
};
|
|
161
168
|
}
|
|
162
169
|
const cfgLeafStatement = cfgLeaf(control_flow_graph_1.CfgVertexType.Statement);
|
|
@@ -173,14 +180,14 @@ function cfgNext(leaf, down) {
|
|
|
173
180
|
return { ...cfgLeafStatement(leaf), nexts: [leaf.info.id], exitPoints: [] };
|
|
174
181
|
}
|
|
175
182
|
function cfgIgnore(_leaf) {
|
|
176
|
-
return { graph: new
|
|
183
|
+
return { graph: new cfg_builder_1.CfgBuilder(), breaks: [], nexts: [], returns: [], exitPoints: [], entryPoints: [] };
|
|
177
184
|
}
|
|
178
185
|
function identifyMayStatementType(node) {
|
|
179
186
|
return node.info.role === "el-c" /* RoleInParent.ExpressionListChild */ ? control_flow_graph_1.CfgVertexType.Statement : control_flow_graph_1.CfgVertexType.Expression;
|
|
180
187
|
}
|
|
181
188
|
function cfgIfThenElse(ifNode, condition, then, otherwise) {
|
|
182
189
|
const ifId = ifNode.info.id;
|
|
183
|
-
const graph = new
|
|
190
|
+
const graph = new cfg_builder_1.CfgBuilder();
|
|
184
191
|
graph.addVertex(control_flow_graph_1.CfgVertex.makeExprOrStm(ifId, identifyMayStatementType(ifNode), { mid: condition.exitPoints, end: [control_flow_graph_1.CfgVertex.toExitId(ifId)] }));
|
|
185
192
|
graph.addVertex(control_flow_graph_1.CfgVertex.makeExitMarker(ifId));
|
|
186
193
|
graph.mergeWith(condition.graph);
|
|
@@ -302,7 +309,7 @@ function cfgFor(forLoop, variable, vector, body) {
|
|
|
302
309
|
}
|
|
303
310
|
function cfgFunctionDefinition(fn, params, body) {
|
|
304
311
|
const fnId = fn.info.id;
|
|
305
|
-
const graph = new
|
|
312
|
+
const graph = new cfg_builder_1.CfgBuilder();
|
|
306
313
|
let paramExits = params.flatMap(e => e.exitPoints);
|
|
307
314
|
const children = [...paramExits, control_flow_graph_1.CfgVertex.toExitId(fnId)];
|
|
308
315
|
graph.addVertex(control_flow_graph_1.CfgVertex.makeExitMarker(fnId), false);
|
|
@@ -456,7 +463,7 @@ const OriginToFoldTypeMap = {
|
|
|
456
463
|
[built_in_proc_name_1.BuiltInProcName.IfThenElse]: (folds, call, args, down) => {
|
|
457
464
|
// arguments are in order!
|
|
458
465
|
return folds.foldIfThenElse(call, // we will have to this more sophisticated if we rewrite the dfg based generation
|
|
459
|
-
args[0] === r_function_call_1.EmptyArgument ? (
|
|
466
|
+
args[0] === r_function_call_1.EmptyArgument ? emptyCfgFoldInformation() : args[0], args[1] === r_function_call_1.EmptyArgument ? emptyCfgFoldInformation() : args[1], args[2] === r_function_call_1.EmptyArgument ? emptyCfgFoldInformation() : args[2], down);
|
|
460
467
|
}
|
|
461
468
|
};
|
|
462
469
|
function cfgFunctionCallWithDataflow(graph, folds) {
|
|
@@ -513,7 +520,7 @@ function cfgFunctionCallWithDataflow(graph, folds) {
|
|
|
513
520
|
};
|
|
514
521
|
}
|
|
515
522
|
function cfgArgumentOrParameter(node, name, value) {
|
|
516
|
-
const graph = new
|
|
523
|
+
const graph = new cfg_builder_1.CfgBuilder();
|
|
517
524
|
const nodeId = node.info.id;
|
|
518
525
|
const info = { graph, breaks: [], nexts: [], returns: [], exitPoints: [control_flow_graph_1.CfgVertex.toExitId(nodeId)], entryPoints: [nodeId] };
|
|
519
526
|
let currentExitPoints = name?.exitPoints ?? [nodeId];
|
|
@@ -617,7 +624,7 @@ function cfgUnaryOp(unary, operand) {
|
|
|
617
624
|
function cfgExprList(node, _grouping, expressions) {
|
|
618
625
|
const nodeId = node.info.id;
|
|
619
626
|
const result = {
|
|
620
|
-
graph: new
|
|
627
|
+
graph: new cfg_builder_1.CfgBuilder(),
|
|
621
628
|
breaks: [],
|
|
622
629
|
nexts: [],
|
|
623
630
|
returns: [],
|
|
@@ -6,9 +6,9 @@ import type { ControlDependency, KillReference } from '../info';
|
|
|
6
6
|
import type { REnvironmentInformation } from './environment';
|
|
7
7
|
import type { IdentifierReference } from './identifier';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Accounts for the writes after a kill: a re-definition revives a `named` removal (dropping it), a conditional
|
|
10
|
+
* one only revives it in its branch, and a wholesale (`all`/`unknown`) removal stays but spares the names written
|
|
11
|
+
* after it.
|
|
12
12
|
*/
|
|
13
13
|
export declare function cancelRevivedKills(kills: readonly KillReference[], writes: readonly IdentifierReference[]): KillReference[];
|
|
14
14
|
/**
|
|
@@ -5,38 +5,64 @@ exports.applyKills = applyKills;
|
|
|
5
5
|
exports.makeKillsMaybe = makeKillsMaybe;
|
|
6
6
|
const info_1 = require("../info");
|
|
7
7
|
const identifier_1 = require("./identifier");
|
|
8
|
+
const reference_to_maybe_1 = require("./reference-to-maybe");
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Accounts for the writes after a kill: a re-definition revives a `named` removal (dropping it), a conditional
|
|
11
|
+
* one only revives it in its branch, and a wholesale (`all`/`unknown`) removal stays but spares the names written
|
|
12
|
+
* after it.
|
|
12
13
|
*/
|
|
13
14
|
function cancelRevivedKills(kills, writes) {
|
|
14
15
|
const written = new Set();
|
|
16
|
+
const writtenMaybe = new Map();
|
|
15
17
|
for (const w of writes) {
|
|
16
|
-
if (w.name
|
|
17
|
-
|
|
18
|
+
if (w.name === undefined) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const name = identifier_1.Identifier.getName(w.name);
|
|
22
|
+
written.add(name);
|
|
23
|
+
if (!(0, info_1.happensInEveryBranch)(w.cds)) {
|
|
24
|
+
const cds = writtenMaybe.get(name);
|
|
25
|
+
if (cds) {
|
|
26
|
+
cds.push(...w.cds);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
writtenMaybe.set(name, [...w.cds]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
writtenMaybe.delete(name);
|
|
18
34
|
}
|
|
19
35
|
}
|
|
20
36
|
if (written.size === 0) {
|
|
21
37
|
return kills;
|
|
22
38
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
function mergeCds(base, toAdd) {
|
|
29
|
-
const result = base ? Array.from(base) : [];
|
|
30
|
-
for (const c of toAdd) {
|
|
31
|
-
if (!result.some(e => e.id === c.id && e.when === c.when)) {
|
|
32
|
-
result.push(c);
|
|
39
|
+
/* conditional writes that cover every branch together revive the name just as an unconditional one does */
|
|
40
|
+
for (const [name, cds] of writtenMaybe) {
|
|
41
|
+
if ((0, info_1.happensInEveryBranch)(cds)) {
|
|
42
|
+
writtenMaybe.delete(name);
|
|
33
43
|
}
|
|
34
44
|
}
|
|
35
|
-
|
|
45
|
+
const remaining = [];
|
|
46
|
+
for (const kill of kills) {
|
|
47
|
+
if (kill.kind === 'named') {
|
|
48
|
+
const name = kill.reference.name === undefined ? undefined : identifier_1.Identifier.getName(kill.reference.name);
|
|
49
|
+
const maybeCds = name === undefined ? undefined : writtenMaybe.get(name);
|
|
50
|
+
if (maybeCds !== undefined) {
|
|
51
|
+
/* the removal still stands wherever the conditional re-definition did not happen */
|
|
52
|
+
remaining.push({ kind: 'named', reference: { ...kill.reference, cds: (0, info_1.withCds)(kill.reference.cds, maybeCds.map(info_1.negateControlDependency)) } });
|
|
53
|
+
}
|
|
54
|
+
else if (name === undefined || !written.has(name)) {
|
|
55
|
+
remaining.push(kill);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
remaining.push({ ...kill, except: kill.except ? written.union(kill.except) : written });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return remaining;
|
|
36
63
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return { ...def, cds: mergeCds(def.cds, cds) };
|
|
64
|
+
function isBuiltInDef(d) {
|
|
65
|
+
return d.type === identifier_1.ReferenceType.BuiltInFunction || d.type === identifier_1.ReferenceType.BuiltInConstant;
|
|
40
66
|
}
|
|
41
67
|
/** attaches `cds` to every user definition of `name` along the environment chain */
|
|
42
68
|
function weakenName(env, name, cds) {
|
|
@@ -46,32 +72,35 @@ function weakenName(env, name, cds) {
|
|
|
46
72
|
if (ns === undefined || current.n === ns) {
|
|
47
73
|
const defs = current.memory.get(plainName);
|
|
48
74
|
if (defs !== undefined && defs.some(d => !isBuiltInDef(d))) {
|
|
49
|
-
current.writableMemory.set(plainName, defs.map(d => isBuiltInDef(d) ? d :
|
|
75
|
+
current.writableMemory.set(plainName, defs.map(d => isBuiltInDef(d) ? d : (0, reference_to_maybe_1.withAppliedCds)(d, cds)));
|
|
50
76
|
current.cache?.delete(plainName);
|
|
51
77
|
}
|
|
52
78
|
}
|
|
53
79
|
current = current.parent;
|
|
54
80
|
}
|
|
55
81
|
}
|
|
56
|
-
/** attaches `cds` to every user definition in the current frame */
|
|
57
|
-
function weakenAll(env, cds) {
|
|
82
|
+
/** attaches `cds` to every user definition in the current frame, except the re-defined names */
|
|
83
|
+
function weakenAll(env, cds, except) {
|
|
58
84
|
if (env.builtInEnv) {
|
|
59
85
|
return;
|
|
60
86
|
}
|
|
61
87
|
for (const [key, defs] of env.memory) {
|
|
88
|
+
if (except?.has(key)) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
62
91
|
if (defs.some(d => !isBuiltInDef(d))) {
|
|
63
|
-
env.writableMemory.set(key, defs.map(d => isBuiltInDef(d) ? d :
|
|
92
|
+
env.writableMemory.set(key, defs.map(d => isBuiltInDef(d) ? d : (0, reference_to_maybe_1.withAppliedCds)(d, cds)));
|
|
64
93
|
}
|
|
65
94
|
}
|
|
66
95
|
env.cache?.clear();
|
|
67
96
|
}
|
|
68
|
-
/** removes every user definition from the current frame (e.g., `rm(list = ls())`) */
|
|
69
|
-
function removeAllInFrame(env) {
|
|
97
|
+
/** removes every user definition from the current frame (e.g., `rm(list = ls())`), except the re-defined names */
|
|
98
|
+
function removeAllInFrame(env, except) {
|
|
70
99
|
if (env.builtInEnv) {
|
|
71
100
|
return;
|
|
72
101
|
}
|
|
73
102
|
for (const [key, defs] of env.memory) {
|
|
74
|
-
if (defs.every(isBuiltInDef)) {
|
|
103
|
+
if (except?.has(key) || defs.every(isBuiltInDef)) {
|
|
75
104
|
continue;
|
|
76
105
|
}
|
|
77
106
|
const kept = defs.filter(isBuiltInDef);
|
|
@@ -124,14 +153,14 @@ function applyKills(env, kills) {
|
|
|
124
153
|
break;
|
|
125
154
|
case 'all':
|
|
126
155
|
if ((0, info_1.happensInEveryBranch)(kill.cds)) {
|
|
127
|
-
removeAllInFrame(current);
|
|
156
|
+
removeAllInFrame(current, kill.except);
|
|
128
157
|
}
|
|
129
158
|
else {
|
|
130
|
-
weakenAll(current, (kill.cds ?? []).map(info_1.negateControlDependency));
|
|
159
|
+
weakenAll(current, (kill.cds ?? []).map(info_1.negateControlDependency), kill.except);
|
|
131
160
|
}
|
|
132
161
|
break;
|
|
133
162
|
case 'unknown':
|
|
134
|
-
weakenAll(current, kill.cds ?? []);
|
|
163
|
+
weakenAll(current, kill.cds ?? [], kill.except);
|
|
135
164
|
break;
|
|
136
165
|
}
|
|
137
166
|
}
|
|
@@ -147,9 +176,9 @@ function makeKillsMaybe(kills, cds) {
|
|
|
147
176
|
}
|
|
148
177
|
return kills.map(k => {
|
|
149
178
|
if (k.kind === 'named') {
|
|
150
|
-
return { kind: 'named', reference: { ...k.reference, cds:
|
|
179
|
+
return { kind: 'named', reference: { ...k.reference, cds: (0, info_1.withCds)(k.reference.cds, cds) } };
|
|
151
180
|
}
|
|
152
|
-
return { ...k, cds:
|
|
181
|
+
return { ...k, cds: (0, info_1.withCds)(k.cds, cds) };
|
|
153
182
|
});
|
|
154
183
|
}
|
|
155
184
|
//# sourceMappingURL=apply-kill.js.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { IdentifierReference } from './identifier';
|
|
1
|
+
import type { IdentifierDefinition, IdentifierReference } from './identifier';
|
|
2
2
|
import type { DataflowGraph } from '../graph/graph';
|
|
3
3
|
import type { ControlDependency } from '../info';
|
|
4
4
|
import type { REnvironmentInformation } from './environment';
|
|
5
|
+
/** copy of the definition with the given cds attached, marking it as maybe */
|
|
6
|
+
export declare function withAppliedCds(definition: IdentifierDefinition, defaultCd: readonly ControlDependency[] | undefined): IdentifierDefinition;
|
|
5
7
|
/**
|
|
6
8
|
* Marks the reference as maybe (i.e., as controlled by a set of {@link IdentifierReference#cds|control dependencies}).
|
|
7
|
-
* With `includeDefs`, the cds are also attached (copy-on-write) to the
|
|
8
|
-
*
|
|
9
|
+
* With `includeDefs`, the cds are also attached (copy-on-write) to the definition the reference
|
|
10
|
+
* itself made, see {@link applyCdsToDefinitions}.
|
|
9
11
|
*/
|
|
10
12
|
export declare function makeReferenceMaybe(ref: IdentifierReference, graph: DataflowGraph, environments: REnvironmentInformation, includeDefs: boolean, defaultCd?: ControlDependency[] | undefined): IdentifierReference;
|
|
11
13
|
/**
|
|
@@ -1,55 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withAppliedCds = withAppliedCds;
|
|
3
4
|
exports.makeReferenceMaybe = makeReferenceMaybe;
|
|
4
5
|
exports.makeAllMaybe = makeAllMaybe;
|
|
5
6
|
exports.applyCdsToAllInGraphButConstants = applyCdsToAllInGraphButConstants;
|
|
6
7
|
exports.applyCdToReferences = applyCdToReferences;
|
|
7
8
|
const identifier_1 = require("./identifier");
|
|
9
|
+
const info_1 = require("../info");
|
|
8
10
|
const resolve_by_name_1 = require("./resolve-by-name");
|
|
9
11
|
const vertex_1 = require("../graph/vertex");
|
|
10
12
|
const built_in_s_seven_dispatch_1 = require("../internal/process/functions/call/built-in/built-in-s-seven-dispatch");
|
|
11
|
-
|
|
12
|
-
if (!toAdd) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
for (const c of toAdd) {
|
|
16
|
-
let found = false;
|
|
17
|
-
for (const tc of target) {
|
|
18
|
-
if (tc.id === c.id && tc.when === c.when) {
|
|
19
|
-
found = true;
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (!found) {
|
|
24
|
-
target.push(c);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function concatCdsUnique(target, toAdd) {
|
|
29
|
-
if (!toAdd) {
|
|
30
|
-
return target;
|
|
31
|
-
}
|
|
32
|
-
const result = Array.from(target);
|
|
33
|
-
for (const c of toAdd) {
|
|
34
|
-
let found = false;
|
|
35
|
-
for (const tc of target) {
|
|
36
|
-
if (tc.id === c.id && tc.when === c.when) {
|
|
37
|
-
found = true;
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!found) {
|
|
42
|
-
result.push(c);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
/** copy of the definition with the given cds attached */
|
|
13
|
+
/** copy of the definition with the given cds attached, marking it as maybe */
|
|
48
14
|
function withAppliedCds(definition, defaultCd) {
|
|
49
|
-
return {
|
|
50
|
-
...definition,
|
|
51
|
-
cds: definition.cds ? concatCdsUnique(definition.cds, defaultCd) : (defaultCd ? Array.from(defaultCd) : [])
|
|
52
|
-
};
|
|
15
|
+
return { ...definition, cds: (0, info_1.withCds)(definition.cds, defaultCd) };
|
|
53
16
|
}
|
|
54
17
|
/** replaces the definitions stored under the given key by copies carrying the additional cds */
|
|
55
18
|
function replaceDefinitions(env, key, toUpdate, defaultCd) {
|
|
@@ -60,14 +23,16 @@ function replaceDefinitions(env, key, toUpdate, defaultCd) {
|
|
|
60
23
|
env.cache?.delete(key);
|
|
61
24
|
}
|
|
62
25
|
/**
|
|
63
|
-
* Attaches the given control dependencies to the
|
|
26
|
+
* Attaches the given control dependencies to the definition made by `nodeId` within the environment chain.
|
|
27
|
+
* Definitions of the same name made elsewhere survive whenever the conditional definition does not happen.
|
|
64
28
|
* Copy-on-write: definitions are replaced, never mutated in place, so previously cloned
|
|
65
29
|
* environments (e.g., snapshots stored in the dataflow graph) keep their state.
|
|
66
30
|
*/
|
|
67
|
-
function applyCdsToDefinitions(environments, name, type, definitions, defaultCd) {
|
|
31
|
+
function applyCdsToDefinitions(environments, name, type, definitions, nodeId, defaultCd) {
|
|
68
32
|
const toUpdate = new Set();
|
|
69
33
|
for (const definition of definitions) {
|
|
70
|
-
if (definition.
|
|
34
|
+
if (definition.nodeId === nodeId
|
|
35
|
+
&& definition.type !== identifier_1.ReferenceType.BuiltInFunction && definition.type !== identifier_1.ReferenceType.BuiltInConstant
|
|
71
36
|
&& (defaultCd !== undefined || definition.cds === undefined)) {
|
|
72
37
|
toUpdate.add(definition);
|
|
73
38
|
}
|
|
@@ -95,20 +60,20 @@ function applyCdsToDefinitions(environments, name, type, definitions, defaultCd)
|
|
|
95
60
|
}
|
|
96
61
|
/**
|
|
97
62
|
* Marks the reference as maybe (i.e., as controlled by a set of {@link IdentifierReference#cds|control dependencies}).
|
|
98
|
-
* With `includeDefs`, the cds are also attached (copy-on-write) to the
|
|
99
|
-
*
|
|
63
|
+
* With `includeDefs`, the cds are also attached (copy-on-write) to the definition the reference
|
|
64
|
+
* itself made, see {@link applyCdsToDefinitions}.
|
|
100
65
|
*/
|
|
101
66
|
function makeReferenceMaybe(ref, graph, environments, includeDefs, defaultCd = undefined) {
|
|
102
67
|
if (includeDefs && ref.name) {
|
|
103
68
|
const definitions = (0, resolve_by_name_1.resolveByName)(ref.name, environments, ref.type);
|
|
104
69
|
if (definitions && definitions.length > 0) {
|
|
105
|
-
applyCdsToDefinitions(environments, ref.name, ref.type, definitions, defaultCd);
|
|
70
|
+
applyCdsToDefinitions(environments, ref.name, ref.type, definitions, ref.nodeId, defaultCd);
|
|
106
71
|
}
|
|
107
72
|
}
|
|
108
73
|
const node = graph.getVertex(ref.nodeId);
|
|
109
74
|
if (node) {
|
|
110
75
|
if (node.cds) {
|
|
111
|
-
|
|
76
|
+
(0, info_1.appendCds)(node.cds, defaultCd);
|
|
112
77
|
}
|
|
113
78
|
else {
|
|
114
79
|
node.cds = defaultCd ? Array.from(defaultCd) : [];
|
|
@@ -116,7 +81,7 @@ function makeReferenceMaybe(ref, graph, environments, includeDefs, defaultCd = u
|
|
|
116
81
|
}
|
|
117
82
|
if (ref.cds) {
|
|
118
83
|
if (defaultCd) {
|
|
119
|
-
return { ...ref, cds:
|
|
84
|
+
return { ...ref, cds: (0, info_1.withCds)(ref.cds, defaultCd) };
|
|
120
85
|
}
|
|
121
86
|
}
|
|
122
87
|
else {
|
|
@@ -143,7 +108,7 @@ function applyCdsToAllInGraphButConstants(graph, references, cds) {
|
|
|
143
108
|
continue;
|
|
144
109
|
}
|
|
145
110
|
if (v.cds) {
|
|
146
|
-
|
|
111
|
+
(0, info_1.appendCds)(v.cds, cds);
|
|
147
112
|
}
|
|
148
113
|
else {
|
|
149
114
|
v.cds = Array.from(cds);
|
|
@@ -151,7 +116,7 @@ function applyCdsToAllInGraphButConstants(graph, references, cds) {
|
|
|
151
116
|
}
|
|
152
117
|
for (const ref of references) {
|
|
153
118
|
if (ref.cds) {
|
|
154
|
-
|
|
119
|
+
(0, info_1.appendCds)(ref.cds, cds);
|
|
155
120
|
}
|
|
156
121
|
else {
|
|
157
122
|
ref.cds = Array.from(cds);
|
|
@@ -167,7 +132,7 @@ function applyCdToReferences(references, cds) {
|
|
|
167
132
|
}
|
|
168
133
|
for (const ref of references) {
|
|
169
134
|
if (ref.cds) {
|
|
170
|
-
|
|
135
|
+
(0, info_1.appendCds)(ref.cds, cds);
|
|
171
136
|
}
|
|
172
137
|
else {
|
|
173
138
|
ref.cds = Array.from(cds);
|
|
@@ -29,8 +29,9 @@ export declare const Resolve: {
|
|
|
29
29
|
readonly toSingleString: typeof resolveIdToSingleString;
|
|
30
30
|
/** The same, for the arguments of a call. */
|
|
31
31
|
readonly argument: {
|
|
32
|
+
readonly name: "argument";
|
|
32
33
|
/** The argument's name. */
|
|
33
|
-
readonly
|
|
34
|
+
readonly toName: typeof resolveIdToArgName;
|
|
34
35
|
/** The argument's value. */
|
|
35
36
|
readonly value: typeof resolveIdToArgValue;
|
|
36
37
|
/** The argument's value as a vector of strings. */
|
|
@@ -32,8 +32,9 @@ exports.Resolve = {
|
|
|
32
32
|
toSingleString: alias_tracking_1.resolveIdToSingleString,
|
|
33
33
|
/** The same, for the arguments of a call. */
|
|
34
34
|
argument: {
|
|
35
|
+
name: 'argument',
|
|
35
36
|
/** The argument's name. */
|
|
36
|
-
|
|
37
|
+
toName: resolve_args_1.resolveIdToArgName,
|
|
37
38
|
/** The argument's value. */
|
|
38
39
|
value: resolve_args_1.resolveIdToArgValue,
|
|
39
40
|
/** The argument's value as a vector of strings. */
|
|
@@ -101,7 +101,8 @@ export declare const Dataflow: {
|
|
|
101
101
|
readonly toValue: typeof import("../eval/resolve/alias-tracking").resolveIdToValue;
|
|
102
102
|
readonly toSingleString: typeof import("../eval/resolve/alias-tracking").resolveIdToSingleString;
|
|
103
103
|
readonly argument: {
|
|
104
|
-
readonly name:
|
|
104
|
+
readonly name: "argument";
|
|
105
|
+
readonly toName: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgName;
|
|
105
106
|
readonly value: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgValue;
|
|
106
107
|
readonly stringVector: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgStringVector;
|
|
107
108
|
readonly symbolName: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgValueSymbolName;
|
package/dataflow/info.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DataflowProcessorInformation } from './processor';
|
|
2
2
|
import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
3
|
-
import type { IdentifierReference } from './environments/identifier';
|
|
3
|
+
import type { BrandedIdentifier, IdentifierReference } from './environments/identifier';
|
|
4
4
|
import type { REnvironmentInformation } from './environments/environment';
|
|
5
5
|
import { DataflowGraph } from './graph/graph';
|
|
6
6
|
import type { GenericDifferenceInformation, WriteableDifferenceReport } from '../util/diff';
|
|
@@ -24,6 +24,10 @@ export interface ControlDependency {
|
|
|
24
24
|
*/
|
|
25
25
|
readonly file?: string;
|
|
26
26
|
}
|
|
27
|
+
/** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
|
|
28
|
+
export declare function appendCds(target: ControlDependency[], toAdd: readonly ControlDependency[] | undefined): void;
|
|
29
|
+
/** A copy of `base` with `toAdd` appended, skipping the control dependencies that are already in there. */
|
|
30
|
+
export declare function withCds(base: readonly ControlDependency[] | undefined, toAdd: readonly ControlDependency[] | undefined): ControlDependency[];
|
|
27
31
|
/**
|
|
28
32
|
* Negates the given control dependency (i.e., flips the `when` flag).
|
|
29
33
|
* This keeps undefined `when` values intact as undefined.
|
|
@@ -92,11 +96,13 @@ export type KillReference =
|
|
|
92
96
|
| {
|
|
93
97
|
readonly kind: 'all';
|
|
94
98
|
readonly cds?: readonly ControlDependency[];
|
|
99
|
+
readonly except?: ReadonlySet<BrandedIdentifier>;
|
|
95
100
|
}
|
|
96
101
|
/** a not statically resolvable set of names, e.g., `rm(list = someVector)` */
|
|
97
102
|
| {
|
|
98
103
|
readonly kind: 'unknown';
|
|
99
104
|
readonly cds?: readonly ControlDependency[];
|
|
105
|
+
readonly except?: ReadonlySet<BrandedIdentifier>;
|
|
100
106
|
};
|
|
101
107
|
/** The control flow information for the current DataflowInformation. */
|
|
102
108
|
export interface DataflowCfgInformation {
|
package/dataflow/info.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataflowInformation = void 0;
|
|
4
|
+
exports.appendCds = appendCds;
|
|
5
|
+
exports.withCds = withCds;
|
|
4
6
|
exports.negateControlDependency = negateControlDependency;
|
|
5
7
|
exports.doesExitPointPropagateCalls = doesExitPointPropagateCalls;
|
|
6
8
|
exports.addNonDefaultExitPoints = addNonDefaultExitPoints;
|
|
@@ -13,6 +15,27 @@ exports.diffControlDependency = diffControlDependency;
|
|
|
13
15
|
exports.diffControlDependencies = diffControlDependencies;
|
|
14
16
|
const graph_1 = require("./graph/graph");
|
|
15
17
|
const assert_1 = require("../util/assert");
|
|
18
|
+
/** Whether the two control dependencies trigger on the same condition and branch. */
|
|
19
|
+
function sameControlDependency(a, b) {
|
|
20
|
+
return a.id === b.id && a.when === b.when;
|
|
21
|
+
}
|
|
22
|
+
/** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
|
|
23
|
+
function appendCds(target, toAdd) {
|
|
24
|
+
if (!toAdd) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const add of toAdd) {
|
|
28
|
+
if (!target.some(have => sameControlDependency(have, add))) {
|
|
29
|
+
target.push(add);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A copy of `base` with `toAdd` appended, skipping the control dependencies that are already in there. */
|
|
34
|
+
function withCds(base, toAdd) {
|
|
35
|
+
const result = base ? Array.from(base) : [];
|
|
36
|
+
appendCds(result, toAdd);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
16
39
|
/**
|
|
17
40
|
* Negates the given control dependency (i.e., flips the `when` flag).
|
|
18
41
|
* This keeps undefined `when` values intact as undefined.
|
|
@@ -96,17 +119,23 @@ function happensInEveryBranch(cds) {
|
|
|
96
119
|
return cds === undefined || (cds.length !== 0 && coversSet(cds));
|
|
97
120
|
}
|
|
98
121
|
function coversSet(cds) {
|
|
99
|
-
|
|
100
|
-
const falses = new Set();
|
|
122
|
+
/* as deep as the surrounding branches, so the pairwise scan beats any set */
|
|
101
123
|
for (const { id, when } of cds) {
|
|
102
|
-
if (when) {
|
|
103
|
-
|
|
124
|
+
if (when !== true && when !== false) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
let counterpart = false;
|
|
128
|
+
for (const other of cds) {
|
|
129
|
+
if (other.id === id && other.when === !when) {
|
|
130
|
+
counterpart = true;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
104
133
|
}
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
if (!counterpart) {
|
|
135
|
+
return false;
|
|
107
136
|
}
|
|
108
137
|
}
|
|
109
|
-
return
|
|
138
|
+
return true;
|
|
110
139
|
}
|
|
111
140
|
/**
|
|
112
141
|
* Checks whether the given control dependencies are exhaustive (i.e. if for every control dependency on a boolean,
|