@eagleoutice/flowr 2.15.9 → 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 +47 -41
- package/abstract-interpretation/absint-inference.d.ts +2 -2
- package/abstract-interpretation/absint-inference.js +32 -79
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/benchmark/slicer.d.ts +0 -1
- package/benchmark/slicer.js +1 -2
- package/cli/repl/commands/repl-signature.js +12 -3
- package/config.d.ts +5 -1
- package/control-flow/cfg-properties.js +0 -22
- package/control-flow/happens-before.d.ts +7 -2
- package/control-flow/happens-before.js +55 -31
- package/control-flow/useless-loop.d.ts +1 -1
- package/control-flow/useless-loop.js +29 -42
- package/dataflow/environments/apply-kill.js +6 -2
- package/dataflow/environments/built-in-config.d.ts +2 -0
- package/dataflow/environments/built-in-props.d.ts +16 -1
- package/dataflow/environments/built-in-props.js +33 -20
- package/dataflow/environments/built-in.d.ts +8 -3
- package/dataflow/environments/built-in.js +52 -82
- package/dataflow/environments/default-builtin-config.d.ts +551 -21
- package/dataflow/environments/default-builtin-config.js +121 -45
- package/dataflow/environments/define.d.ts +3 -2
- package/dataflow/environments/define.js +4 -3
- package/dataflow/environments/deprecation-info.d.ts +45 -0
- package/dataflow/environments/deprecation-info.js +13 -0
- package/dataflow/environments/environment.d.ts +7 -5
- package/dataflow/environments/environment.js +55 -121
- package/dataflow/environments/identifier.d.ts +6 -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 +180 -58
- package/dataflow/fn/class-declaration.d.ts +8 -13
- package/dataflow/fn/class-declaration.js +95 -116
- 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.d.ts +9 -1
- package/dataflow/fn/higher-order-function.js +27 -24
- package/dataflow/fn/strict-function.d.ts +13 -0
- package/dataflow/fn/strict-function.js +291 -123
- package/dataflow/graph/call-graph.d.ts +7 -6
- package/dataflow/graph/call-graph.js +35 -46
- package/dataflow/graph/graph.d.ts +13 -1
- package/dataflow/graph/graph.js +74 -66
- package/dataflow/graph/vertex.d.ts +1 -1
- 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 +17 -8
- package/dataflow/internal/linker.js +286 -213
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
- 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 +60 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
- 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-envir-utils.d.ts +5 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
- 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 +141 -146
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
- 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 +91 -129
- 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 +16 -12
- 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-repeat-loop.js +2 -0
- 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 +5 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
- 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 +42 -119
- 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 +21 -21
- 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 +23 -26
- 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 +4 -4
- package/dataflow/internal/process/functions/call/common.js +49 -71
- package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
- package/dataflow/internal/process/functions/call/deferred.js +81 -63
- 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 +48 -19
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +257 -154
- 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 +4 -3
- package/dataflow/internal/program-order.d.ts +26 -0
- package/dataflow/internal/program-order.js +49 -0
- package/documentation/data/faq/faqs.js +3 -3
- package/documentation/data/interface/doc-writing-code.js +1 -2
- package/documentation/data/server/doc-data-server-messages.js +7 -7
- package/documentation/doc-capabilities.js +80 -34
- package/documentation/doc-util/doc-query.d.ts +0 -3
- package/documentation/doc-util/doc-query.js +4 -3
- package/documentation/wiki-analyzer.js +1 -1
- package/documentation/wiki-cfg.js +5 -6
- package/documentation/wiki-core.js +8 -8
- package/documentation/wiki-dataflow-graph.js +10 -11
- package/documentation/wiki-interface.js +2 -2
- package/documentation/wiki-linting-and-testing.js +3 -3
- package/documentation/wiki-overview.js +6 -6
- package/documentation/wiki-query.js +9 -101
- package/documentation/wiki-setup.js +23 -0
- package/documentation/wiki-signature-database.js +1 -1
- package/linter/linter-rules.d.ts +18 -9
- package/linter/rules/absolute-path.js +63 -87
- package/linter/rules/deprecated-functions.d.ts +1 -45
- package/linter/rules/deprecated-functions.js +24 -33
- 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.d.ts +2 -0
- package/project/flowr-analyzer.js +28 -1
- 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 +0 -2
- package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
- 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/file-plugins/flowr-analyzer-file-plugin.js +2 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
- package/project/sigdb/build.js +4 -0
- package/project/sigdb/manifest.d.ts +2 -0
- package/project/sigdb/manifest.js +10 -1
- package/project/sigdb/reader.js +23 -61
- package/project/sigdb/sigdb-download.d.ts +29 -6
- package/project/sigdb/sigdb-download.js +212 -64
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
- package/queries/catalog/call-context-query/cascade-action.js +2 -0
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
- 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/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
- package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
- package/queries/catalog/origin-query/origin-query-executor.js +2 -2
- package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
- package/queries/catalog/origin-query/origin-query-format.js +1 -1
- package/queries/query.d.ts +1 -1
- package/r-bridge/data/data.d.ts +21 -14
- package/r-bridge/data/data.js +28 -20
- 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/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
- 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/files.d.ts +2 -0
- package/util/files.js +3 -1
- package/util/mermaid/mermaid.js +6 -2
- 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
|
@@ -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) {
|
|
@@ -10,10 +10,14 @@ const visiting_queue_1 = require("./visiting-queue");
|
|
|
10
10
|
const slice_call_1 = require("./slice-call");
|
|
11
11
|
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
12
12
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
13
|
+
const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
|
|
14
|
+
const function_semantics_1 = require("../../dataflow/fn/function-semantics");
|
|
13
15
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
14
16
|
const df_helper_1 = require("../../dataflow/graph/df-helper");
|
|
15
17
|
const slice_direction_1 = require("../../util/slice-direction");
|
|
16
18
|
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
19
|
+
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
20
|
+
const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
17
21
|
exports.slicerLogger = log_1.log.getSubLogger({ name: 'slicer' });
|
|
18
22
|
/**
|
|
19
23
|
* Computes the node ids to include in a static slice, starting from the given seed ids.
|
|
@@ -23,53 +27,56 @@ function staticSlice(options) {
|
|
|
23
27
|
const { ctx, info, ids, cache, sliceGraph } = options;
|
|
24
28
|
const { idMap } = options.ast;
|
|
25
29
|
const direction = options.direction ?? slice_direction_1.SliceDirection.Backward;
|
|
26
|
-
const threshold = options.threshold ?? 75;
|
|
27
30
|
(0, assert_1.guard)(ids.length > 0, 'must have at least one seed id to calculate slice');
|
|
28
31
|
// includeCallees only makes sense on the original (non-reduced) graph, backward
|
|
29
32
|
const trackCallees = (options.includeCallees ?? false) && direction === slice_direction_1.SliceDirection.Backward && sliceGraph === undefined;
|
|
30
33
|
// enclosing function definitions whose callees still need to be considered, mapped to the env to enqueue them in
|
|
31
34
|
const pendingCalleeBoundaries = new Map();
|
|
32
35
|
const resolvedCalleeBoundaries = new Set();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
graph = info.graph;
|
|
39
|
-
if (direction === slice_direction_1.SliceDirection.Forward) {
|
|
40
|
-
graph = df_helper_1.Dataflow.invertGraph(graph, ctx.env.makeCleanEnv());
|
|
36
|
+
/* a body entered through a call gets its arguments from that call, so only bodies the slice starts in open their callers */
|
|
37
|
+
const openedBodies = new Set();
|
|
38
|
+
const openBodiesAround = (from) => {
|
|
39
|
+
for (let fn = model_1.RNode.findEnclosing(from, idMap, r_function_definition_1.RFunctionDefinition.is); fn !== undefined; fn = model_1.RNode.strictlyEnclosingFunction(fn, idMap)) {
|
|
40
|
+
openedBodies.add(fn);
|
|
41
41
|
}
|
|
42
|
-
}
|
|
43
|
-
const
|
|
42
|
+
};
|
|
43
|
+
const graph = sliceGraph ?? (direction === slice_direction_1.SliceDirection.Forward ? df_helper_1.Dataflow.invertGraph(info.graph, ctx.env.makeCleanEnv()) : info.graph);
|
|
44
|
+
const emptyEnv = ctx.env.makeCleanEnv();
|
|
45
|
+
const basePrint = ctx.env.getCleanEnvFingerprint();
|
|
46
|
+
const queue = new visiting_queue_1.VisitingQueue(options.threshold ?? 75, cache, graph, ctx.gas.scope(options.gas), [emptyEnv, basePrint]);
|
|
47
|
+
const enclosingHandled = new Set();
|
|
48
|
+
const enqueue = (id, env, print) => {
|
|
49
|
+
if (!queue.hasId(id)) {
|
|
50
|
+
queue.add(id, env, print, true);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
44
53
|
let minNesting = Number.MAX_SAFE_INTEGER;
|
|
45
54
|
const sliceSeedIds = new Set();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
minNesting = Math.min(minNesting, idMap.get(startId)?.info.nest ?? minNesting);
|
|
54
|
-
sliceSeedIds.add(startId);
|
|
55
|
-
}
|
|
56
|
-
/* additionally,
|
|
57
|
-
* include all the implicit side effects that we have to consider as we are unable to narrow them down
|
|
58
|
-
*/
|
|
59
|
-
for (const id of graph.unknownSideEffects) {
|
|
60
|
-
if (typeof id !== 'object') {
|
|
61
|
-
/* otherwise, their target is just missing */
|
|
62
|
-
queue.add(id, emptyEnv, basePrint, true);
|
|
63
|
-
}
|
|
55
|
+
for (const startId of ids) {
|
|
56
|
+
queue.add(startId, emptyEnv, basePrint, false);
|
|
57
|
+
// retrieve the minimum nesting of all nodes to only add control dependencies if they are "part" of the current execution
|
|
58
|
+
minNesting = Math.min(minNesting, idMap.get(startId)?.info.nest ?? minNesting);
|
|
59
|
+
sliceSeedIds.add(startId);
|
|
60
|
+
if (trackCallees) {
|
|
61
|
+
openBodiesAround(startId);
|
|
64
62
|
}
|
|
65
63
|
}
|
|
64
|
+
/* include all the implicit side effects that we have to consider as we are unable to narrow them down */
|
|
65
|
+
for (const id of graph.unknownSideEffects) {
|
|
66
|
+
/* a linked side effect is no vertex of its own, its target is just missing */
|
|
67
|
+
if (typeof id !== 'object') {
|
|
68
|
+
queue.add(id, emptyEnv, basePrint, true);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/* a call asked about does what the functions it runs do, which includes what they print */
|
|
72
|
+
for (const id of outputWithinCallees(ids, graph)) {
|
|
73
|
+
queue.add(id, emptyEnv, basePrint, false);
|
|
74
|
+
}
|
|
75
|
+
/* a drained queue completes the body slice, only then can a boundary decide whether its callers matter */
|
|
66
76
|
do {
|
|
67
77
|
while (queue.nonEmpty()) {
|
|
68
78
|
processNode();
|
|
69
79
|
}
|
|
70
|
-
// the queue drained: only now do we know the full body slice, so decide per boundary whether the callers
|
|
71
|
-
// can actually influence the result (i.e., the slice reaches a parameter or a captured scope variable).
|
|
72
|
-
// resolving a boundary may enqueue new nodes, hence the surrounding do-while re-enters the traversal.
|
|
73
80
|
resolveCalleeBoundaries();
|
|
74
81
|
} while (queue.nonEmpty());
|
|
75
82
|
function processNode() {
|
|
@@ -81,31 +88,41 @@ function staticSlice(options) {
|
|
|
81
88
|
return;
|
|
82
89
|
}
|
|
83
90
|
const [currentVertex, currentEdges] = currentInfo;
|
|
91
|
+
const strictlyEnclosing = model_1.RNode.strictlyEnclosingFunction(id, idMap);
|
|
92
|
+
if (!enclosingHandled.has(strictlyEnclosing)) {
|
|
93
|
+
enclosingHandled.add(strictlyEnclosing);
|
|
94
|
+
definitionWithHolders(strictlyEnclosing, idMap, graph).forEach(outer => enqueue(outer, emptyEnv, basePrint));
|
|
95
|
+
}
|
|
84
96
|
// includeCallees: note the enclosing function definition (if any) so its callees can be considered once the body slice is complete
|
|
85
97
|
if (trackCallees) {
|
|
86
|
-
const enclosingFnDef = (
|
|
87
|
-
if (enclosingFnDef !== undefined && !resolvedCalleeBoundaries.has(enclosingFnDef) && !pendingCalleeBoundaries.has(enclosingFnDef)) {
|
|
98
|
+
const enclosingFnDef = r_function_definition_1.RFunctionDefinition.is(idMap.get(id)) ? id : strictlyEnclosing;
|
|
99
|
+
if (enclosingFnDef !== undefined && openedBodies.has(enclosingFnDef) && !resolvedCalleeBoundaries.has(enclosingFnDef) && !pendingCalleeBoundaries.has(enclosingFnDef)) {
|
|
88
100
|
pendingCalleeBoundaries.set(enclosingFnDef, [baseEnvironment, baseEnvFingerprint]);
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
queue.add(cd.id, baseEnvironment, baseEnvFingerprint, false);
|
|
97
|
-
}
|
|
103
|
+
/* control dependencies count only in a different call or at least at the nesting of the seeds */
|
|
104
|
+
const topLevel = graph.isRoot(id) || sliceSeedIds.has(id);
|
|
105
|
+
for (const cd of currentVertex.cds?.filter(({ id }) => !queue.hasId(id)) ?? []) {
|
|
106
|
+
if (!topLevel || (idMap.get(cd.id)?.info.nest ?? 0) >= minNesting) {
|
|
107
|
+
queue.add(cd.id, baseEnvironment, baseEnvFingerprint, false);
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
/* a call or a definition within a promise runs only when the promise is forced, within captured code only when it is evaluated */
|
|
111
|
+
if (vertex_1.DfgVertex.isFunctionCall(currentVertex) || vertex_1.DfgVertex.isVariableDefinition(currentVertex)) {
|
|
112
|
+
const dependencies = function_semantics_1.FunctionSemantics.promiseDependencies(id, graph);
|
|
113
|
+
if (graph.isQuoted(id)) {
|
|
114
|
+
dependencies.push(...function_semantics_1.FunctionSemantics.call.quoted.evaluationDependencies(graph, id));
|
|
103
115
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
return;
|
|
116
|
+
for (const dep of dependencies) {
|
|
117
|
+
enqueue(dep, baseEnvironment, baseEnvFingerprint);
|
|
107
118
|
}
|
|
108
119
|
}
|
|
120
|
+
if (vertex_1.DfgVertex.isFunctionCall(currentVertex)) {
|
|
121
|
+
(0, slice_call_1.sliceForCall)(current, currentVertex, info, queue, ctx);
|
|
122
|
+
}
|
|
123
|
+
if (!onlyForSideEffects && (0, slice_call_1.handleReturns)(id, queue, currentEdges, baseEnvFingerprint, baseEnvironment)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
109
126
|
for (const [target, e] of currentEdges) {
|
|
110
127
|
const t = (0, edge_1.shouldTraverseEdge)(e);
|
|
111
128
|
switch (t) {
|
|
@@ -126,16 +143,13 @@ function staticSlice(options) {
|
|
|
126
143
|
}
|
|
127
144
|
}
|
|
128
145
|
function resolveCalleeBoundaries() {
|
|
129
|
-
if (pendingCalleeBoundaries.size === 0) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
146
|
const boundaries = [...pendingCalleeBoundaries];
|
|
133
147
|
pendingCalleeBoundaries.clear();
|
|
134
148
|
for (const [fnDefId, [env, fingerprint]] of boundaries) {
|
|
135
149
|
resolvedCalleeBoundaries.add(fnDefId);
|
|
136
150
|
// only continue past the boundary if the callers can actually influence the sliced result
|
|
137
151
|
if ((0, slice_call_1.sliceReachesFunctionInterface)(fnDefId, info.graph, queue, idMap, ctx)) {
|
|
138
|
-
(0, slice_call_1.includeCalleesOfDefinition)(fnDefId, info.graph, queue, env, fingerprint);
|
|
152
|
+
(0, slice_call_1.includeCalleesOfDefinition)(fnDefId, info.graph, queue, env, fingerprint).forEach(openBodiesAround);
|
|
139
153
|
}
|
|
140
154
|
}
|
|
141
155
|
}
|
|
@@ -143,6 +157,47 @@ function staticSlice(options) {
|
|
|
143
157
|
const result = ctx.config.solver.slicer?.autoExtend ? extendSlices(status.result, idMap) : status.result;
|
|
144
158
|
return { ...status, slicedFor: ids, result, freeNames: freeNamesOf(result, info.graph) };
|
|
145
159
|
}
|
|
160
|
+
/** The calls writing output (`cat`, `print`, ...: a side effect linked to `sink`) within the functions the call `seeds` run, transitively. */
|
|
161
|
+
function outputWithinCallees(seeds, graph) {
|
|
162
|
+
const writers = new Set();
|
|
163
|
+
for (const effect of graph.unknownSideEffects) {
|
|
164
|
+
if (typeof effect === 'object') {
|
|
165
|
+
writers.add(effect.id);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (writers.size === 0) {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
const found = [];
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
const calls = [...seeds].filter(id => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(id)));
|
|
174
|
+
while (calls.length > 0) {
|
|
175
|
+
for (const target of (0, frame_reflection_1.calledDefinitions)(graph, calls.pop()).filter(t => !seen.has(t))) {
|
|
176
|
+
seen.add(target);
|
|
177
|
+
const callee = graph.getVertex(target);
|
|
178
|
+
found.push(...[...callee.subflow.graph].filter(inner => writers.has(inner)));
|
|
179
|
+
calls.push(...[...(0, frame_reflection_1.callsIn)(callee, graph)].map(([inner]) => inner));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return found;
|
|
183
|
+
}
|
|
184
|
+
/** The function `definition` and what holds it, up to its statement, as a body only runs as part of its definition. */
|
|
185
|
+
function definitionWithHolders(definition, idMap, graph) {
|
|
186
|
+
const definitionNode = definition === undefined ? undefined : idMap.get(definition);
|
|
187
|
+
if (definitionNode === undefined) {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
const outer = [definitionNode.info.id];
|
|
191
|
+
for (const node of model_1.RNode.iterateParents(definitionNode, idMap)) {
|
|
192
|
+
if (r_function_definition_1.RFunctionDefinition.is(node) || (r_expression_list_1.RExpressionList.is(node) && node.grouping?.[0].lexeme !== '(')) {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (graph.hasVertex(node.info.id)) {
|
|
196
|
+
outer.push(node.info.id);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return outer;
|
|
200
|
+
}
|
|
146
201
|
/**
|
|
147
202
|
* The names the slice reads without defining them: a use whose definitions all stayed outside meets that name
|
|
148
203
|
* undefined, and so does one that reads nothing at all (a name the program never defines). Reading a built-in
|
|
@@ -154,13 +209,7 @@ function freeNamesOf(slice, graph) {
|
|
|
154
209
|
if (!vertex_1.DfgVertex.isUse(graph.getVertex(id))) {
|
|
155
210
|
continue;
|
|
156
211
|
}
|
|
157
|
-
|
|
158
|
-
for (const [target, edge] of graph.edgesFrom(id)) {
|
|
159
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && (slice.has(target) || node_id_1.NodeId.isBuiltIn(target))) {
|
|
160
|
-
defined = true;
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
212
|
+
const defined = (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads).some(t => slice.has(t) || node_id_1.NodeId.isBuiltIn(t));
|
|
164
213
|
const name = defined ? undefined : node_id_1.NodeId.recoverName(id, graph.idMap);
|
|
165
214
|
if (name !== undefined) {
|
|
166
215
|
free.add(name);
|
|
@@ -180,18 +229,12 @@ function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCal
|
|
|
180
229
|
(0, assert_1.guard)(startIds.length > 0 && endIds.length > 0, 'must have at least one start and one end id for dicing');
|
|
181
230
|
const backward = staticSlice({ ctx, info, ast, ids: endIds, direction: slice_direction_1.SliceDirection.Backward, threshold, includeCallees, gas });
|
|
182
231
|
// reduce to backward result and invert edges in one pass; original info kept for sliceForCall
|
|
183
|
-
const
|
|
184
|
-
const forward = staticSlice({ ctx, info, ast, ids: startIds, direction: slice_direction_1.SliceDirection.Backward, threshold, sliceGraph
|
|
185
|
-
// explicit intersection handles seed nodes that landed outside the reduced graph
|
|
186
|
-
const result = new Set();
|
|
187
|
-
for (const id of forward.result) {
|
|
188
|
-
if (backward.result.has(id)) {
|
|
189
|
-
result.add(id);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
232
|
+
const sliceGraph = df_helper_1.Dataflow.reduceAndInvertGraph(info.graph, backward.result, ctx.env.makeCleanEnv());
|
|
233
|
+
const forward = staticSlice({ ctx, info, ast, ids: startIds, direction: slice_direction_1.SliceDirection.Backward, threshold, sliceGraph, gas });
|
|
192
234
|
return {
|
|
193
235
|
timesHitThreshold: forward.timesHitThreshold + backward.timesHitThreshold,
|
|
194
|
-
|
|
236
|
+
// explicit intersection handles seed nodes that landed outside the reduced graph
|
|
237
|
+
result: new Set([...forward.result].filter(id => backward.result.has(id))),
|
|
195
238
|
slicedFor: [...startIds, ...endIds],
|
|
196
239
|
...(forward.stoppedEarly || backward.stoppedEarly ? {
|
|
197
240
|
stoppedEarly: true,
|
|
@@ -203,18 +246,11 @@ function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCal
|
|
|
203
246
|
};
|
|
204
247
|
}
|
|
205
248
|
function extendSlices(results, ast) {
|
|
206
|
-
const res = new Set();
|
|
249
|
+
const res = new Set(results);
|
|
207
250
|
for (const id of results) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
parent = parent.info.parent ? ast.get(parent.info.parent) : undefined;
|
|
212
|
-
}
|
|
213
|
-
if (!parent) {
|
|
214
|
-
continue; // no parent, no need to extend
|
|
215
|
-
}
|
|
216
|
-
for (const id of model_1.RNode.collectAllIds(parent)) {
|
|
217
|
-
res.add(id);
|
|
251
|
+
const statement = model_1.RNode.findEnclosing(id, ast, n => n.info.role === "root" /* RoleInParent.Root */ || n.info.role === "el-c" /* RoleInParent.ExpressionListChild */);
|
|
252
|
+
for (const inner of statement === undefined ? [] : model_1.RNode.collectAllIds(ast.get(statement))) {
|
|
253
|
+
res.add(inner);
|
|
218
254
|
}
|
|
219
255
|
}
|
|
220
256
|
return res;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Fingerprint } from './fingerprint';
|
|
2
2
|
import type { NodeToSlice, SliceResult } from './slicer-types';
|
|
3
3
|
import type { REnvironmentInformation } from '../../dataflow/environments/environment';
|
|
4
|
+
import type { DataflowGraph } from '../../dataflow/graph/graph';
|
|
4
5
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
5
|
-
import type { DataflowGraphVertexInfo } from '../../dataflow/graph/vertex';
|
|
6
6
|
import type { ReadOnlyFlowrAnalyzerGasContext } from '../../project/context/flowr-analyzer-gas-context';
|
|
7
7
|
export declare class VisitingQueue {
|
|
8
8
|
private readonly threshold;
|
|
@@ -13,9 +13,8 @@ export declare class VisitingQueue {
|
|
|
13
13
|
private readonly queue;
|
|
14
14
|
private readonly cache?;
|
|
15
15
|
potentialAdditions: Map<NodeId, [NodeId, NodeToSlice]>;
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
private readonly isGraphVertex?;
|
|
16
|
+
private readonly graph?;
|
|
17
|
+
private readonly global?;
|
|
19
18
|
private readonly gas?;
|
|
20
19
|
private stoppedEarly;
|
|
21
20
|
/** how many nodes pass between two gas checks, see {@link ReadOnlyFlowrAnalyzerGasContext#checkEvery} */
|
|
@@ -23,7 +22,7 @@ export declare class VisitingQueue {
|
|
|
23
22
|
private untilGasCheck;
|
|
24
23
|
/** entries dequeued, see {@link SliceProgress} */
|
|
25
24
|
private visited;
|
|
26
|
-
constructor(threshold: number, cache?: Map<Fingerprint, Set<NodeId>>,
|
|
25
|
+
constructor(threshold: number, cache?: Map<Fingerprint, Set<NodeId>>, graph?: Pick<DataflowGraph, 'hasVertex' | 'isRoot'>, gas?: ReadOnlyFlowrAnalyzerGasContext, global?: readonly [REnvironmentInformation, Fingerprint]);
|
|
27
26
|
/**
|
|
28
27
|
* Adds a node to the queue if it has not been seen before.
|
|
29
28
|
* @param target - the node to add
|
|
@@ -41,6 +40,5 @@ export declare class VisitingQueue {
|
|
|
41
40
|
*/
|
|
42
41
|
private outOfGas;
|
|
43
42
|
hasId(id: NodeId): boolean;
|
|
44
|
-
memoizeCallTargets(id: NodeId, targets: () => Set<DataflowGraphVertexInfo>): Set<DataflowGraphVertexInfo>;
|
|
45
43
|
status(): Readonly<Pick<SliceResult, 'timesHitThreshold' | 'result' | 'stoppedEarly' | 'progress'>>;
|
|
46
44
|
}
|
|
@@ -16,9 +16,8 @@ class VisitingQueue {
|
|
|
16
16
|
// the set of potential additions holds nodes which may be added if a second edge deems them relevant (e.g., found with the `defined-by-on-call` edge)
|
|
17
17
|
// additionally it holds which node id added the addition so we can separate their inclusion on the structure
|
|
18
18
|
potentialAdditions = new Map();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
isGraphVertex;
|
|
19
|
+
graph;
|
|
20
|
+
global;
|
|
22
21
|
gas;
|
|
23
22
|
stoppedEarly = false;
|
|
24
23
|
/** how many nodes pass between two gas checks, see {@link ReadOnlyFlowrAnalyzerGasContext#checkEvery} */
|
|
@@ -26,10 +25,11 @@ class VisitingQueue {
|
|
|
26
25
|
untilGasCheck = 0;
|
|
27
26
|
/** entries dequeued, see {@link SliceProgress} */
|
|
28
27
|
visited = 0;
|
|
29
|
-
constructor(threshold, cache,
|
|
28
|
+
constructor(threshold, cache, graph, gas, global) {
|
|
30
29
|
this.threshold = threshold;
|
|
31
30
|
this.cache = cache;
|
|
32
|
-
this.
|
|
31
|
+
this.graph = graph;
|
|
32
|
+
this.global = global;
|
|
33
33
|
this.gas = gas;
|
|
34
34
|
this.gasCheckEvery = gas?.checkEvery() ?? 0;
|
|
35
35
|
}
|
|
@@ -43,9 +43,12 @@ class VisitingQueue {
|
|
|
43
43
|
add(target, env, envFingerprint, onlyForSideEffects) {
|
|
44
44
|
/* a built-in without a vertex is R's own definition (`x <- 1` reads `built-in:<-`), a dead end the traversal
|
|
45
45
|
* would drop right back out of, so it only ever widened the result */
|
|
46
|
-
if (node_id_1.NodeId.isBuiltIn(target) && this.
|
|
46
|
+
if (node_id_1.NodeId.isBuiltIn(target) && this.graph?.hasVertex(target) === false) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
+
if (this.global !== undefined && this.graph?.isRoot(target)) {
|
|
50
|
+
[env, envFingerprint] = this.global;
|
|
51
|
+
}
|
|
49
52
|
const idCounter = this.idThreshold.get(target) ?? 0;
|
|
50
53
|
if (idCounter > this.threshold) {
|
|
51
54
|
this.timesHitThreshold++;
|
|
@@ -101,13 +104,6 @@ class VisitingQueue {
|
|
|
101
104
|
hasId(id) {
|
|
102
105
|
return this.idThreshold.has(id);
|
|
103
106
|
}
|
|
104
|
-
memoizeCallTargets(id, targets) {
|
|
105
|
-
let known = this.cachedCallTargets.get(id);
|
|
106
|
-
if (known === undefined) {
|
|
107
|
-
this.cachedCallTargets.set(id, known = targets());
|
|
108
|
-
}
|
|
109
|
-
return known;
|
|
110
|
-
}
|
|
111
107
|
status() {
|
|
112
108
|
return {
|
|
113
109
|
timesHitThreshold: this.timesHitThreshold,
|
package/util/files.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export declare function getAllFiles(dir: string, suffix?: RegExp, throwOnError?:
|
|
|
20
20
|
* @see {@link getAllFiles} - for an asynchronous version.
|
|
21
21
|
*/
|
|
22
22
|
export declare function getAllFilesSync(dir: string, suffix?: RegExp, ignoreDirs?: RegExp | undefined, relativeTo?: string, throwOnError?: boolean): Generator<string>;
|
|
23
|
+
/** The code files directly below a package's `R/` directory: besides `.R` and `.r`, R accepts `.S`, `.s`, and `.q` there (and nowhere else, `src/*.s` is assembler). */
|
|
24
|
+
export declare const rPackageSourceRegex: RegExp;
|
|
23
25
|
/**
|
|
24
26
|
* Retrieves all R files in a given directory (asynchronously)
|
|
25
27
|
* @param input - directory-path to start the search from, can be a file as well. Will just return the file then.
|
package/util/files.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.RPath = void 0;
|
|
39
|
+
exports.RPath = exports.rPackageSourceRegex = void 0;
|
|
40
40
|
exports.getAllFiles = getAllFiles;
|
|
41
41
|
exports.getAllFilesSync = getAllFilesSync;
|
|
42
42
|
exports.allRFiles = allRFiles;
|
|
@@ -116,6 +116,8 @@ function* getAllFilesSync(dir, suffix = /.*/, ignoreDirs = undefined, relativeTo
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
const rFileRegex = /\.[rR]$/;
|
|
119
|
+
/** The code files directly below a package's `R/` directory: besides `.R` and `.r`, R accepts `.S`, `.s`, and `.q` there (and nowhere else, `src/*.s` is assembler). */
|
|
120
|
+
exports.rPackageSourceRegex = /(^|[\\/])R[\\/][^\\/]+\.(r|s|q)$/i;
|
|
119
121
|
/**
|
|
120
122
|
* Retrieves all R files in a given directory (asynchronously)
|
|
121
123
|
* @param input - directory-path to start the search from, can be a file as well. Will just return the file then.
|
package/util/mermaid/mermaid.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Mermaid = void 0;
|
|
4
4
|
const url_encoding_1 = require("../text/url-encoding");
|
|
5
|
+
function charCode(c) {
|
|
6
|
+
return `_${c.codePointAt(0)}_`;
|
|
7
|
+
}
|
|
5
8
|
/**
|
|
6
9
|
* Global mermaid helper object with useful functions.
|
|
7
10
|
* @helper output
|
|
@@ -68,9 +71,10 @@ exports.Mermaid = {
|
|
|
68
71
|
* Escapes a string or number to be used as a mermaid node id.
|
|
69
72
|
*/
|
|
70
73
|
escapeId(text) {
|
|
71
|
-
|
|
74
|
+
/* each character is spelled by its code, so `built-in:{` and `built-in:+` stay apart */
|
|
75
|
+
text = String(text).replace(/[^\w:\-./]/g, charCode);
|
|
72
76
|
/* a dash before a dash or a dot reads as the start of a link, e.g. the id of `$<-.grouped_df` would cut the line in two */
|
|
73
|
-
text = text.replace(/-(?=[-.])/g,
|
|
77
|
+
text = text.replace(/-(?=[-.])/g, charCode);
|
|
74
78
|
return text.replace(/(^|[:\-./])([a-zA-Z0-9_]+)/g, (_m, sep, tok) => sep + (exports.Mermaid.reservedIds.has(tok) ? tok + '_' : tok));
|
|
75
79
|
},
|
|
76
80
|
/**
|