@eagleoutice/flowr 2.15.10 → 2.16.1
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/cli/flowr-main-options.d.ts +15 -0
- package/cli/flowr-main-options.js +18 -0
- package/cli/flowr.d.ts +18 -0
- package/cli/flowr.js +13 -2
- package/cli/repl/commands/repl-clipboard.js +2 -1
- package/cli/repl/commands/repl-commands.js +2 -0
- package/cli/repl/commands/repl-main.d.ts +5 -0
- package/cli/repl/commands/repl-signature.js +2 -0
- package/cli/repl/core.d.ts +7 -1
- package/cli/repl/core.js +17 -8
- package/cli/repl/execute.js +2 -0
- package/cli/repl/server/connection.js +2 -1
- package/cli/repl/server/net.d.ts +10 -0
- package/cli/repl/server/net.js +34 -1
- package/cli/slicer-app.js +2 -1
- package/config.d.ts +12 -2
- package/config.js +91 -14
- 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 +185 -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 +64 -42
- 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 +42 -4
- package/dataflow/internal/control-flow.js +76 -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 +441 -79
- 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 +290 -252
- 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 +120 -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 +60 -58
- 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 +44 -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/doc-capabilities.js +4 -1
- package/documentation/wiki-interface.js +4 -0
- package/documentation/wiki-setup.js +23 -0
- package/engines.js +11 -3
- package/linter/linter-executor.js +19 -1
- 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 +117 -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 +130 -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-rda-file.d.ts +14 -5
- package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
- 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 +18 -42
- package/project/sigdb/decompress.js +3 -1
- package/project/sigdb/sigdb-download.js +9 -6
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/config-query/config-query-executor.js +9 -2
- 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-executor.js +2 -0
- package/r-bridge/shell.js +8 -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 +120 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/files.d.ts +6 -0
- package/util/files.js +12 -0
- package/util/parallel.js +2 -0
- 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/secure-mode.d.ts +42 -0
- package/util/secure-mode.js +70 -0
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
package/r-bridge/shell.js
CHANGED
|
@@ -48,6 +48,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
48
48
|
const init_1 = require("./init");
|
|
49
49
|
const convert_values_1 = require("./lang-4.x/convert-values");
|
|
50
50
|
const retriever_1 = require("./retriever");
|
|
51
|
+
const secure_mode_1 = require("../util/secure-mode");
|
|
51
52
|
exports.DEFAULT_OUTPUT_COLLECTOR_CONFIGURATION = {
|
|
52
53
|
from: 'stdout',
|
|
53
54
|
postamble: `🐧${'-'.repeat(5)}🐧`,
|
|
@@ -302,6 +303,7 @@ class RShellSession {
|
|
|
302
303
|
collectionTimeout;
|
|
303
304
|
requestQueue = Promise.resolve();
|
|
304
305
|
constructor(options, log) {
|
|
306
|
+
secure_mode_1.SecureMode.guard('starting R', options.pathToRExecutable);
|
|
305
307
|
this.bareSession = (0, child_process_1.spawn)(options.pathToRExecutable, options.commandLineOptions, {
|
|
306
308
|
env: options.env,
|
|
307
309
|
cwd: options.cwd,
|
|
@@ -380,6 +382,12 @@ class RShellSession {
|
|
|
380
382
|
onDrained();
|
|
381
383
|
};
|
|
382
384
|
return new Promise((resolve, reject) => {
|
|
385
|
+
if (this.bareSession.exitCode !== null || this.bareSession.signalCode !== null) {
|
|
386
|
+
reject(new Error(`the R session has exited (${this.bareSession.exitCode ?? this.bareSession.signalCode}), it cannot answer anymore`));
|
|
387
|
+
drained = true;
|
|
388
|
+
onDrained();
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
383
391
|
const makeTimer = () => setTimeout(() => {
|
|
384
392
|
if (timeout.onTimeout) {
|
|
385
393
|
timeout.onTimeout(resolve, reject, result);
|
|
@@ -40,10 +40,8 @@ const StructuralRoles = new Set([
|
|
|
40
40
|
function collectAliveNodes(ast, reachable) {
|
|
41
41
|
const alive = new Set();
|
|
42
42
|
for (const id of reachable) {
|
|
43
|
-
let node = ast.idMap.get(id);
|
|
44
|
-
while (node !== undefined && !alive.has(node.info.id)) {
|
|
43
|
+
for (let node = ast.idMap.get(id); node !== undefined && !alive.has(node.info.id); node = model_1.RNode.directParent(node, ast.idMap)) {
|
|
45
44
|
alive.add(node.info.id);
|
|
46
|
-
node = node.info.parent === undefined ? undefined : ast.idMap.get(node.info.parent);
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
return alive;
|
|
@@ -58,10 +56,7 @@ function isReachedByControlFlow(node, alive) {
|
|
|
58
56
|
if (alive.has(node.info.id)) {
|
|
59
57
|
return true;
|
|
60
58
|
}
|
|
61
|
-
|
|
62
|
-
return node.info.parent !== undefined && alive.has(node.info.parent);
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
59
|
+
return StructuralRoles.has(node.info.role) && node.info.parent !== undefined && alive.has(node.info.parent);
|
|
65
60
|
}
|
|
66
61
|
/**
|
|
67
62
|
* One entry per distinct call target. A call to a package export is modelled by the built-in flowR states for
|
|
@@ -107,37 +102,15 @@ exports.Enrichments = {
|
|
|
107
102
|
const n = shared?.ast ?? await analyzer.normalize();
|
|
108
103
|
const callVertex = df.graph.getVertex(e.node.info.id);
|
|
109
104
|
if (vertex_1.DfgVertex.isFunctionCall(callVertex)) {
|
|
110
|
-
const origins = df_helper_1.Dataflow.origin(df.graph, callVertex.id);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
content.targets =
|
|
105
|
+
const origins = df_helper_1.Dataflow.origin(df.graph, callVertex.id) ?? [];
|
|
106
|
+
// find call targets in user code (which have ids!)
|
|
107
|
+
const targets = origins.map(targetOf).filter(assert_1.isNotUndefined);
|
|
108
|
+
if (targets.length > 0) {
|
|
109
|
+
content.targets = targets;
|
|
115
110
|
}
|
|
116
111
|
else {
|
|
117
|
-
|
|
118
|
-
content.targets = origins
|
|
119
|
-
switch (o.type) {
|
|
120
|
-
case 2 /* OriginType.FunctionCallOrigin */: {
|
|
121
|
-
if (node_id_1.NodeId.isBuiltIn(o.id)) {
|
|
122
|
-
// a built-in target (e.g. a materialized package export from `library()`) has no
|
|
123
|
-
// user-code node, so surface it as a built-in identifier (see `onlyBuiltin` below)
|
|
124
|
-
const name = node_id_1.NodeId.recoverName(o.id, n.idMap);
|
|
125
|
-
return qualifyIdentifier([o], name) ?? String(o.id);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return { node: n.idMap.get(o.id) };
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
case 3 /* OriginType.BuiltInFunctionOrigin */:
|
|
132
|
-
return qualifyIdentifier([o], o.fn.name);
|
|
133
|
-
default:
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
}).filter(assert_1.isNotUndefined);
|
|
137
|
-
if (content.targets.length === 0) {
|
|
138
|
-
const name = node_id_1.NodeId.recoverName(callVertex.id, n.idMap);
|
|
139
|
-
content.targets = [qualifyIdentifier(origins, name)];
|
|
140
|
-
}
|
|
112
|
+
const name = node_id_1.NodeId.recoverName(callVertex.id, n.idMap);
|
|
113
|
+
content.targets = [qualifyIdentifier(origins, name)];
|
|
141
114
|
}
|
|
142
115
|
}
|
|
143
116
|
/* a package export and the built-in flowR models it with are one target seen twice, so keep the
|
|
@@ -152,6 +125,21 @@ exports.Enrichments = {
|
|
|
152
125
|
content.targets.push(...prev.targets);
|
|
153
126
|
}
|
|
154
127
|
return content;
|
|
128
|
+
function targetOf(o) {
|
|
129
|
+
switch (o.type) {
|
|
130
|
+
case 2 /* OriginType.FunctionCallOrigin */:
|
|
131
|
+
if (node_id_1.NodeId.isBuiltIn(o.id)) {
|
|
132
|
+
// a built-in target (e.g. a materialized package export from `library()`) has no
|
|
133
|
+
// user-code node, so surface it as a built-in identifier (see `onlyBuiltin` above)
|
|
134
|
+
return qualifyIdentifier([o], node_id_1.NodeId.recoverName(o.id, n.idMap)) ?? String(o.id);
|
|
135
|
+
}
|
|
136
|
+
return { node: n.idMap.get(o.id) };
|
|
137
|
+
case 3 /* OriginType.BuiltInFunctionOrigin */:
|
|
138
|
+
return qualifyIdentifier([o], o.fn.name);
|
|
139
|
+
default:
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
155
143
|
function qualifyIdentifier(origins, name) {
|
|
156
144
|
if (args?.qualifyNames === undefined || args.qualifyNames) {
|
|
157
145
|
const qualified = identifier_1.Identifier.toQualified(origins, name);
|
|
@@ -159,7 +147,7 @@ exports.Enrichments = {
|
|
|
159
147
|
return identifier_1.Identifier.toString(qualified);
|
|
160
148
|
}
|
|
161
149
|
}
|
|
162
|
-
return name;
|
|
150
|
+
return name === undefined ? undefined : identifier_1.Identifier.toString(name);
|
|
163
151
|
}
|
|
164
152
|
},
|
|
165
153
|
// as built-in call target enrichments are not nodes, we don't return them as part of the mapper!
|
|
@@ -11,8 +11,8 @@ import type { AstIdMap } from '../../r-bridge/lang-4.x/ast/model/processing/deco
|
|
|
11
11
|
/**
|
|
12
12
|
* Returns the function call targets (definitions) by the given caller
|
|
13
13
|
*/
|
|
14
|
-
export declare function getAllFunctionCallTargetsForSlice(dataflowGraph: DataflowGraph, callerInfo: DataflowGraphVertexFunctionCall, baseEnvironment: REnvironmentInformation,
|
|
15
|
-
/**
|
|
14
|
+
export declare function getAllFunctionCallTargetsForSlice(dataflowGraph: DataflowGraph, callerInfo: DataflowGraphVertexFunctionCall, baseEnvironment: REnvironmentInformation, ctx: ReadOnlyFlowrAnalyzerContext): [ReadonlySet<DataflowGraphVertexInfo>, REnvironmentInformation];
|
|
15
|
+
/** Links the call `callerInfo` to the definitions it resolves to, or to the closures of its arguments if it resolves to none. */
|
|
16
16
|
export declare function sliceForCall(current: NodeToSlice, callerInfo: DataflowGraphVertexFunctionCall, { graph }: DataflowInformation, queue: VisitingQueue, ctx: ReadOnlyFlowrAnalyzerContext): void;
|
|
17
17
|
/**
|
|
18
18
|
* Finds the nearest enclosing function-definition node for the given id by walking up the AST parent chain.
|
|
@@ -34,7 +34,8 @@ export declare function sliceReachesFunctionInterface(fnDefId: NodeId, graph: Da
|
|
|
34
34
|
* `calls` edges). Call site arguments are picked up automatically once the call vertex is processed normally,
|
|
35
35
|
* as `argument` edges are always traversed.
|
|
36
36
|
* This is the reverse of what {@link sliceForCall} does for call -\> definition linking.
|
|
37
|
+
* @returns the enqueued ids
|
|
37
38
|
*/
|
|
38
|
-
export declare function includeCalleesOfDefinition(fnDefId: NodeId, graph: DataflowGraph, queue: VisitingQueue, baseEnvironment: REnvironmentInformation, baseEnvFingerprint: Fingerprint):
|
|
39
|
+
export declare function includeCalleesOfDefinition(fnDefId: NodeId, graph: DataflowGraph, queue: VisitingQueue, baseEnvironment: REnvironmentInformation, baseEnvFingerprint: Fingerprint): NodeId[];
|
|
39
40
|
/** Returns true if we found at least one return edge */
|
|
40
41
|
export declare function handleReturns(from: NodeId, queue: VisitingQueue, currentEdges: OutgoingEdges, baseEnvFingerprint: Fingerprint, baseEnvironment: REnvironmentInformation): boolean;
|
|
@@ -18,87 +18,73 @@ const built_in_function_definition_1 = require("../../dataflow/internal/process/
|
|
|
18
18
|
const static_slicer_1 = require("./static-slicer");
|
|
19
19
|
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
20
20
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
21
|
+
const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
|
|
21
22
|
const built_in_proc_name_1 = require("../../dataflow/environments/built-in-proc-name");
|
|
22
23
|
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
23
24
|
const NoCallTargets = new Set();
|
|
25
|
+
const linkedByGraph = new WeakMap();
|
|
26
|
+
function linkedDefinitions(defs, graph) {
|
|
27
|
+
let known = linkedByGraph.get(graph);
|
|
28
|
+
if (known === undefined) {
|
|
29
|
+
linkedByGraph.set(graph, known = new Map());
|
|
30
|
+
}
|
|
31
|
+
const key = defs.join(';');
|
|
32
|
+
let linked = known.get(key);
|
|
33
|
+
if (linked === undefined) {
|
|
34
|
+
known.set(key, linked = (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(defs), graph)[0]);
|
|
35
|
+
}
|
|
36
|
+
return linked;
|
|
37
|
+
}
|
|
24
38
|
/**
|
|
25
39
|
* Returns the function call targets (definitions) by the given caller
|
|
26
40
|
*/
|
|
27
|
-
function getAllFunctionCallTargetsForSlice(dataflowGraph, callerInfo, baseEnvironment,
|
|
41
|
+
function getAllFunctionCallTargetsForSlice(dataflowGraph, callerInfo, baseEnvironment, ctx) {
|
|
42
|
+
(0, assert_1.guard)(dataflowGraph.hasVertex(callerInfo.id), () => `outgoing edges of id: ${callerInfo.id} must be in graph but can not be found, keep in slice to be sure`);
|
|
28
43
|
// bind with call-local environments during slicing
|
|
29
|
-
const outgoingEdges = dataflowGraph.get(callerInfo.id, true);
|
|
30
|
-
(0, assert_1.guard)(outgoingEdges !== undefined, () => `outgoing edges of id: ${callerInfo.id} must be in graph but can not be found, keep in slice to be sure`);
|
|
31
|
-
// lift baseEnv on the same level
|
|
32
44
|
const activeEnvironment = callerInfo.environment === undefined ? baseEnvironment : (0, built_in_function_definition_1.retrieveActiveEnvironment)(callerInfo.environment, baseEnvironment, ctx);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
for (const d of resolve_helper_1.Resolve.byName(name, activeEnvironment) ?? []) {
|
|
37
|
-
if (!node_id_1.NodeId.isBuiltIn(d.definedAt)) {
|
|
38
|
-
functionCallDefs.push(d.nodeId);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
for (const [target, outgoingEdge] of outgoingEdges[1].entries()) {
|
|
42
|
-
if (edge_1.DfEdge.includesType(outgoingEdge, edge_1.EdgeType.Calls)) {
|
|
43
|
-
functionCallDefs.push(target);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const functionCallTargets = functionCallDefs.length === 0 ? NoCallTargets :
|
|
47
|
-
queue.memoizeCallTargets(functionCallDefs.join(';'), () => (0, linker_1.getAllLinkedFunctionDefinitions)(new Set(functionCallDefs), dataflowGraph)[0]);
|
|
45
|
+
const resolved = (resolve_helper_1.Resolve.byName(callerInfo.name, activeEnvironment) ?? []).filter(d => !node_id_1.NodeId.isBuiltIn(d.definedAt));
|
|
46
|
+
const functionCallDefs = [...resolved.map(d => d.nodeId), ...(0, frame_reflection_1.edgeTargets)(dataflowGraph, callerInfo.id, edge_1.EdgeType.Calls)];
|
|
47
|
+
const functionCallTargets = functionCallDefs.length === 0 ? NoCallTargets : linkedDefinitions(functionCallDefs, dataflowGraph);
|
|
48
48
|
return [functionCallTargets, activeEnvironment];
|
|
49
49
|
}
|
|
50
|
-
function includeArgumentFunctionCallClosure(arg, activeEnvironment, activeEnvironmentFingerprint, queue, dataflowGraph) {
|
|
51
|
-
const valueRoot = graph_1.FunctionArgument.getReference(arg);
|
|
52
|
-
if (!valueRoot) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const callTargets = queue.memoizeCallTargets(valueRoot, () => (0, linker_1.getAllLinkedFunctionDefinitions)(new Set([valueRoot]), dataflowGraph)[0]);
|
|
56
|
-
linkCallTargets(false, callTargets, activeEnvironment, activeEnvironmentFingerprint, queue);
|
|
57
|
-
}
|
|
58
50
|
function linkCallTargets(onlyForSideEffects, functionCallTargets, activeEnvironment, activeEnvironmentFingerprint, queue) {
|
|
59
51
|
for (const functionCallTarget of functionCallTargets) {
|
|
60
|
-
for
|
|
61
|
-
|
|
52
|
+
/* a call kept only for what it does needs what its function reads, not what it returns */
|
|
53
|
+
for (const exitPoint of onlyForSideEffects ? [] : functionCallTarget.exitPoints) {
|
|
54
|
+
queue.add(exitPoint.nodeId, activeEnvironment, activeEnvironmentFingerprint(), false);
|
|
62
55
|
}
|
|
63
|
-
// handle open reads
|
|
64
56
|
for (const openIn of functionCallTarget.subflow.in) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const resolved = resolve_helper_1.Resolve.byName(openIn.name, activeEnvironment);
|
|
68
|
-
for (const res of resolved ?? []) {
|
|
69
|
-
(0, static_slicer_1.updatePotentialAddition)(queue, functionCallTarget.id, res.nodeId, activeEnvironment, activeEnvironmentFingerprint());
|
|
70
|
-
}
|
|
57
|
+
for (const res of openIn.name ? resolve_helper_1.Resolve.byName(openIn.name, activeEnvironment) ?? [] : []) {
|
|
58
|
+
(0, static_slicer_1.updatePotentialAddition)(queue, functionCallTarget.id, res.nodeId, activeEnvironment, activeEnvironmentFingerprint());
|
|
71
59
|
}
|
|
72
60
|
}
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
|
-
/**
|
|
63
|
+
/** Links the call `callerInfo` to the definitions it resolves to, or to the closures of its arguments if it resolves to none. */
|
|
76
64
|
function sliceForCall(current, callerInfo, { graph }, queue, ctx) {
|
|
77
|
-
const [functionCallTargets, activeEnvironment] = getAllFunctionCallTargetsForSlice(graph, callerInfo, current.baseEnvironment,
|
|
65
|
+
const [functionCallTargets, activeEnvironment] = getAllFunctionCallTargetsForSlice(graph, callerInfo, current.baseEnvironment, ctx);
|
|
78
66
|
/* hashing the environment is expensive, so only a call that links something pays for it */
|
|
79
67
|
let fingerprint;
|
|
80
68
|
const activeEnvironmentFingerprint = () => fingerprint ??= activeEnvironment === current.baseEnvironment ? current.envFingerprint : (0, fingerprint_1.envFingerprint)(activeEnvironment);
|
|
81
|
-
if (functionCallTargets.size
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for (const arg of callerInfo.args) {
|
|
93
|
-
const reference = graph_1.FunctionArgument.getReference(arg);
|
|
94
|
-
const edge = reference === undefined ? undefined : outgoing?.get(reference);
|
|
95
|
-
if (edge === undefined || !edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
|
|
96
|
-
includeArgumentFunctionCallClosure(arg, activeEnvironment, activeEnvironmentFingerprint, queue, graph);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
69
|
+
if (functionCallTargets.size > 0) {
|
|
70
|
+
linkCallTargets(current.onlyForSideEffects, functionCallTargets, activeEnvironment, activeEnvironmentFingerprint, queue);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
/*
|
|
74
|
+
* if we do not have any call to resolve this function, we have to assume that every function passed is actually called!
|
|
75
|
+
* hence, we add all argument values to the queue causing directly
|
|
76
|
+
* (an assignment only stores the function, and a call handing an argument back unchanged, like `return(f)`,
|
|
77
|
+
* did not call it either: what it is bound to is called later, or never)
|
|
78
|
+
*/
|
|
79
|
+
if (vertex_1.DfgVertex.hasOrigin(callerInfo, built_in_proc_name_1.BuiltInProcName.Assignment)) {
|
|
99
80
|
return;
|
|
100
81
|
}
|
|
101
|
-
|
|
82
|
+
for (const arg of callerInfo.args) {
|
|
83
|
+
const reference = graph_1.FunctionArgument.getReference(arg);
|
|
84
|
+
if (reference && !(0, frame_reflection_1.hasEdgeOfType)(graph, callerInfo.id, reference, edge_1.EdgeType.Returns)) {
|
|
85
|
+
linkCallTargets(false, linkedDefinitions([reference], graph), activeEnvironment, activeEnvironmentFingerprint, queue);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
102
88
|
}
|
|
103
89
|
/**
|
|
104
90
|
* Finds the nearest enclosing function-definition node for the given id by walking up the AST parent chain.
|
|
@@ -117,31 +103,23 @@ function findEnclosingFunctionDefinition(id, idMap) {
|
|
|
117
103
|
*/
|
|
118
104
|
function sliceReachesFunctionInterface(fnDefId, graph, queue, idMap, ctx) {
|
|
119
105
|
const vertex = graph.getVertex(fnDefId);
|
|
120
|
-
if (
|
|
106
|
+
if (!vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
|
|
121
107
|
return false;
|
|
122
108
|
}
|
|
123
109
|
// (a) the slice reaches a parameter of this definition
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
110
|
+
if (Object.keys(vertex.params).some(paramId => queue.hasId(node_id_1.NodeId.normalize(paramId)))) {
|
|
111
|
+
return true;
|
|
128
112
|
}
|
|
129
113
|
// (b) a sliced body node captures a variable from the enclosing scope: it links (via `defined-by-on-call`, the
|
|
130
114
|
// closure/argument binding resolved at the call site) to a non-builtin definition that lives outside this body.
|
|
131
|
-
const
|
|
132
|
-
const bodyIds = fnNode ? new Set(model_1.RNode.collectAllIds(fnNode)) : new Set();
|
|
115
|
+
const bodyIds = model_1.RNode.collectAllIds(idMap.get(fnDefId));
|
|
133
116
|
for (const bodyId of bodyIds) {
|
|
134
117
|
if (!queue.hasId(bodyId)) {
|
|
135
118
|
continue;
|
|
136
119
|
}
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
for (const [target, edge] of outgoing) {
|
|
142
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedByOnCall) && !node_id_1.NodeId.isBuiltIn(target) && !bodyIds.has(target)) {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
120
|
+
const captures = (0, frame_reflection_1.edgeTargets)(graph, bodyId, edge_1.EdgeType.DefinedByOnCall);
|
|
121
|
+
if (captures.some(target => !node_id_1.NodeId.isBuiltIn(target) && !bodyIds.has(target))) {
|
|
122
|
+
return true;
|
|
145
123
|
}
|
|
146
124
|
}
|
|
147
125
|
// (c) fallback for captures that could not be resolved at definition time: an open in-reference that is in the
|
|
@@ -165,29 +143,19 @@ const CalleeBoundaryEdges = edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Calls;
|
|
|
165
143
|
* `calls` edges). Call site arguments are picked up automatically once the call vertex is processed normally,
|
|
166
144
|
* as `argument` edges are always traversed.
|
|
167
145
|
* This is the reverse of what {@link sliceForCall} does for call -\> definition linking.
|
|
146
|
+
* @returns the enqueued ids
|
|
168
147
|
*/
|
|
169
148
|
function includeCalleesOfDefinition(fnDefId, graph, queue, baseEnvironment, baseEnvFingerprint) {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
for (const [source, edge] of ingoing) {
|
|
175
|
-
if (edge_1.DfEdge.includesType(edge, CalleeBoundaryEdges)) {
|
|
176
|
-
queue.add(source, baseEnvironment, baseEnvFingerprint, false);
|
|
177
|
-
}
|
|
149
|
+
const added = (0, frame_reflection_1.edgeSources)(graph, fnDefId, CalleeBoundaryEdges);
|
|
150
|
+
for (const source of added) {
|
|
151
|
+
queue.add(source, baseEnvironment, baseEnvFingerprint, false);
|
|
178
152
|
}
|
|
153
|
+
return added;
|
|
179
154
|
}
|
|
180
155
|
const PotentialFollowOnReturn = edge_1.EdgeType.DefinesOnCall | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Argument;
|
|
181
156
|
/** Returns true if we found at least one return edge */
|
|
182
157
|
function handleReturns(from, queue, currentEdges, baseEnvFingerprint, baseEnvironment) {
|
|
183
|
-
|
|
184
|
-
for (const edge of currentEdges.values()) {
|
|
185
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
|
|
186
|
-
returns = true;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (!returns) {
|
|
158
|
+
if (![...currentEdges.values()].some(edge => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns))) {
|
|
191
159
|
return false;
|
|
192
160
|
}
|
|
193
161
|
for (const [target, edge] of currentEdges) {
|