@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/dataflow/extractor.js
CHANGED
|
@@ -23,16 +23,22 @@ const edge_1 = require("./graph/edge");
|
|
|
23
23
|
const identify_link_to_last_call_relation_1 = require("../queries/catalog/call-context-query/identify-link-to-last-call-relation");
|
|
24
24
|
const built_in_function_definition_1 = require("./internal/process/functions/call/built-in/built-in-function-definition");
|
|
25
25
|
const transitive_side_effects_1 = require("./internal/process/functions/call/built-in/transitive-side-effects");
|
|
26
|
+
const built_in_try_catch_1 = require("./internal/process/functions/call/built-in/built-in-try-catch");
|
|
27
|
+
const linker_1 = require("./internal/linker");
|
|
26
28
|
const flowr_file_1 = require("../project/context/flowr-file");
|
|
29
|
+
const node_id_1 = require("../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
27
30
|
const vertex_1 = require("./graph/vertex");
|
|
28
31
|
const identifier_1 = require("./environments/identifier");
|
|
29
32
|
const r_symbol_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
30
|
-
const
|
|
33
|
+
const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
|
|
34
|
+
const r_function_definition_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
31
35
|
const range_1 = require("../util/range");
|
|
32
36
|
const logger_1 = require("./logger");
|
|
33
37
|
const gas_1 = require("../gas");
|
|
34
38
|
const config_1 = require("../config");
|
|
35
39
|
const df_helper_1 = require("./graph/df-helper");
|
|
40
|
+
const built_in_ambient_state_1 = require("./internal/process/functions/call/built-in/built-in-ambient-state");
|
|
41
|
+
const unnamed_call_handling_1 = require("./internal/process/functions/call/unnamed-call-handling");
|
|
36
42
|
const built_in_proc_name_1 = require("./environments/built-in-proc-name");
|
|
37
43
|
const arrays_1 = require("../util/collections/arrays");
|
|
38
44
|
const defaultmap_1 = require("../util/collections/defaultmap");
|
|
@@ -42,6 +48,7 @@ const query_fn_props_1 = require("./environments/query-fn-props");
|
|
|
42
48
|
const resolve_helper_1 = require("./environments/resolve-helper");
|
|
43
49
|
const happens_before_1 = require("../control-flow/happens-before");
|
|
44
50
|
const assert_1 = require("../util/assert");
|
|
51
|
+
const frame_reflection_1 = require("./fn/frame-reflection");
|
|
45
52
|
/**
|
|
46
53
|
* The best friend of {@link produceDataFlowGraph} and {@link processDataflowFor}.
|
|
47
54
|
* Maps every {@link RType} in the normalized AST to a processor.
|
|
@@ -95,10 +102,7 @@ function linkEnvironmentArgumentsWrittenByCallee(graph, environment) {
|
|
|
95
102
|
if (!holdsEnvironment(graph, argument, environment)) {
|
|
96
103
|
continue;
|
|
97
104
|
}
|
|
98
|
-
for (const
|
|
99
|
-
if (!edge_1.DfEdge.includesType(handed, edge_1.EdgeType.Argument) || !vertex_1.DfgVertex.isFunctionCall(graph.getVertex(call))) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
105
|
+
for (const call of (0, frame_reflection_1.edgeSources)(graph, argument, edge_1.EdgeType.Argument).filter(c => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(c)))) {
|
|
102
106
|
(0, unknown_side_effect_1.handleUnknownSideEffect)(graph, environment, call);
|
|
103
107
|
for (const write of writes) {
|
|
104
108
|
graph.addEdge(call, write, edge_1.EdgeType.Reads);
|
|
@@ -110,76 +114,160 @@ function linkEnvironmentArgumentsWrittenByCallee(graph, environment) {
|
|
|
110
114
|
}
|
|
111
115
|
function tracksAnyEnvironment(environment) {
|
|
112
116
|
for (let e = environment.current; e !== undefined && !e.builtInEnv; e = e.parent) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if ((0, identifier_1.hasEnvState)(def)) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
117
|
+
if (e.memory.values().some(defs => defs.some(identifier_1.hasEnvState))) {
|
|
118
|
+
return true;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
return false;
|
|
122
122
|
}
|
|
123
|
+
/** Collects, per parameter of `definition`, the replacements (`x$f <- v`) and the side-effecting calls in its body that write into it. */
|
|
123
124
|
function writesOfParameters(graph, definition, parameters, written, environment) {
|
|
124
125
|
for (const node of definition.subflow.graph) {
|
|
125
126
|
const vertex = graph.getVertex(node);
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
if (vertex_1.DfgVertex.isVariableDefinition(vertex) && vertex.par) {
|
|
128
|
+
const replacements = (0, frame_reflection_1.edgeTargets)(graph, node, edge_1.EdgeType.DefinedBy).filter(t => vertex_1.DfgVertex.hasOrigin(graph.getVertex(t), built_in_proc_name_1.BuiltInProcName.Replacement));
|
|
129
|
+
for (const parameter of (0, frame_reflection_1.edgeTargets)(graph, node, edge_1.EdgeType.Reads).filter(t => parameters.has(t))) {
|
|
130
|
+
written.get(parameter).push(...replacements);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (vertex_1.DfgVertex.isFunctionCall(vertex) && graph.unknownSideEffects.has(node_id_1.NodeId.normalize(node))) {
|
|
134
|
+
for (const target of argsWithProp(vertex, (0, query_fn_props_1.callFnProps)(node, { graph, environment }), built_in_props_1.ArgProp.Written)) {
|
|
135
|
+
for (const reached of definitionsReachedBy(target, graph)) {
|
|
136
|
+
if (parameters.has(reached)) {
|
|
137
|
+
written.get(reached).push(node);
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function holdsEnvironment(graph, argument, environment) {
|
|
145
|
+
const node = graph.idMap?.get(argument);
|
|
146
|
+
return r_symbol_1.RSymbol.is(node) && (resolve_helper_1.Resolve.byName(node.content, environment)?.some(identifier_1.hasEnvState) ?? false);
|
|
147
|
+
}
|
|
148
|
+
function openReadsOfCalledFunctions(graph) {
|
|
149
|
+
const reads = new Map();
|
|
150
|
+
for (const [id, definition] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
151
|
+
if ((0, frame_reflection_1.edgeSources)(graph, id, edge_1.EdgeType.Calls).length > 0) {
|
|
152
|
+
for (const read of definition.subflow.in) {
|
|
153
|
+
if (read.name !== undefined && !built_in_ambient_state_1.AmbientStateName.is(read.name) && !identifier_1.Identifier.getName(read.name).startsWith(unnamed_call_handling_1.UnnamedFunctionCallPrefix)) {
|
|
154
|
+
reads.set(read.nodeId, read);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return [...reads.values()];
|
|
160
|
+
}
|
|
161
|
+
/** An active binding (`makeActiveBinding`) runs its function on every assignment to and read of the name, so each becomes a call of it. */
|
|
162
|
+
function callActiveBindings(graph) {
|
|
163
|
+
/* the definitions that call something are the bindings, and most scripts have none, so nothing else is walked then */
|
|
164
|
+
const active = new Set();
|
|
165
|
+
const bindings = new Map();
|
|
166
|
+
for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
|
|
167
|
+
const called = (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Calls);
|
|
168
|
+
if (called.length > 0) {
|
|
169
|
+
active.add(id);
|
|
170
|
+
const fns = called.filter(t => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)));
|
|
171
|
+
if (fns.length > 0) {
|
|
172
|
+
bindings.set(id, fns);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (active.size === 0) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
for (const [, ids] of bindings.size === 0 ? [] : (0, frame_reflection_1.definitionsByName)(graph).entries()) {
|
|
180
|
+
const fns = ids.flatMap(id => bindings.get(id) ?? []);
|
|
181
|
+
for (const id of fns.length === 0 ? [] : ids.filter(id => !bindings.has(id))) {
|
|
182
|
+
for (const assignment of (0, frame_reflection_1.edgeSources)(graph, id, edge_1.EdgeType.Returns).filter(a => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(a)))) {
|
|
183
|
+
active.add(id);
|
|
184
|
+
for (const fn of fns) {
|
|
185
|
+
graph.addEdge(assignment, fn, edge_1.EdgeType.Calls);
|
|
186
|
+
graph.addEdge(id, fn, edge_1.EdgeType.Calls);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const id of graph.vertexIdsOfType(vertex_1.VertexType.Use)) {
|
|
192
|
+
const node = graph.idMap?.get(id);
|
|
193
|
+
if (r_symbol_1.RSymbol.is(node) && (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads).some(def => active.has(def))) {
|
|
194
|
+
graph.updateToFunctionCall({ tag: vertex_1.VertexType.FunctionCall, id, name: node.content, args: [], environment: undefined, onlyBuiltin: false, cds: graph.getVertex(id)?.cds, origin: [built_in_proc_name_1.BuiltInProcName.Function] });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** A call of what a closure returned that we could not link (`h2 <- h()` with `h` returning `sys.function()`) may run anything. */
|
|
199
|
+
function markCallsOfUnknownValues(graph, environment) {
|
|
200
|
+
const fromClosure = (def) => vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(def))
|
|
201
|
+
&& (0, frame_reflection_1.edgeTargets)(graph, def, edge_1.EdgeType.DefinedBy).some(c => (0, frame_reflection_1.calledDefinitions)(graph, c).length > 0);
|
|
202
|
+
for (const [id, call] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
203
|
+
if (!call.onlyBuiltin && (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Calls).length === 0 && (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads).some(fromClosure)) {
|
|
204
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(graph, environment, id);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** `environment()` hands out the function's frame by reference, so the call reads every definition of the frame, a closure's `<<-` included. */
|
|
209
|
+
function readFramesThroughEnvironment(graph) {
|
|
210
|
+
const idMap = graph.idMap;
|
|
211
|
+
if (idMap === undefined) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const environmentCall = node_id_1.NodeId.toBuiltIn('environment');
|
|
215
|
+
const callsEnvironment = (id) => (0, frame_reflection_1.hasEdgeOfType)(graph, id, environmentCall, edge_1.EdgeType.Calls);
|
|
216
|
+
/* `environment(fn)` hands out the frame `fn` was created in */
|
|
217
|
+
const ofClosures = new defaultmap_1.DefaultMap(() => []);
|
|
218
|
+
for (const [id, call] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
219
|
+
const fn = call.args.length === 1 && callsEnvironment(id) ? graph_1.FunctionArgument.getReference(call.args[0]) : undefined;
|
|
220
|
+
for (const closure of fn === undefined ? [] : (0, linker_1.getAllLinkedFunctionDefinitions)(new Set([fn]), graph)[0]) {
|
|
221
|
+
const creator = model_1.RNode.strictlyEnclosingFunction(closure.id, idMap);
|
|
222
|
+
if (creator !== undefined) {
|
|
223
|
+
ofClosures.get(creator).push(id);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (const [, definition] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
228
|
+
const frameCalls = ofClosures.get(definition.id);
|
|
229
|
+
if (frameCalls.length === 0 && !definition.subflow.graph.values().some(callsEnvironment)) {
|
|
136
230
|
continue;
|
|
137
231
|
}
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
for (const
|
|
141
|
-
|
|
142
|
-
|
|
232
|
+
/* the nested functions' bodies, too, where a closure may write the frame */
|
|
233
|
+
const within = [...definition.subflow.graph];
|
|
234
|
+
for (const id of within) {
|
|
235
|
+
const vertex = graph.getVertex(id);
|
|
236
|
+
if (vertex_1.DfgVertex.isFunctionDefinition(vertex) && vertex.id !== definition.id) {
|
|
237
|
+
within.push(...vertex.subflow.graph);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const definitions = [];
|
|
241
|
+
for (const id of new Set(within)) {
|
|
242
|
+
const vertex = graph.getVertex(id);
|
|
243
|
+
const own = model_1.RNode.findEnclosing(id, idMap, r_function_definition_1.RFunctionDefinition.is) === definition.id;
|
|
244
|
+
if (own && vertex_1.DfgVertex.isFunctionCall(vertex) && vertex.args.length === 0 && callsEnvironment(id)) {
|
|
245
|
+
frameCalls.push(id);
|
|
143
246
|
}
|
|
144
|
-
else if (
|
|
145
|
-
|
|
247
|
+
else if (vertex_1.DfgVertex.isVariableDefinition(vertex) && !(id in definition.params)) {
|
|
248
|
+
/* a parameter is what the call binds, which reflecting on the frame already accounts for */
|
|
249
|
+
definitions.push({ id, own, name: node_id_1.NodeId.recoverName(id, idMap) });
|
|
146
250
|
}
|
|
147
251
|
}
|
|
148
|
-
|
|
149
|
-
|
|
252
|
+
const local = new Set(definitions.filter(d => d.own && d.name !== undefined).map(d => d.name));
|
|
253
|
+
/* a nested definition writes this frame only by `<<-` to a name it binds */
|
|
254
|
+
const bySuperAssignment = (id) => vertex_1.DfgVertex.hasOrigin(graph.getVertex(idMap.get(id)?.info.parent ?? ''), built_in_proc_name_1.BuiltInProcName.SuperAssignment);
|
|
255
|
+
for (const d of definitions.filter(d => local.has(d.name ?? '') && (d.own || bySuperAssignment(d.id)))) {
|
|
256
|
+
for (const call of frameCalls) {
|
|
257
|
+
graph.addEdge(call, d.id, edge_1.EdgeType.Reads);
|
|
258
|
+
}
|
|
150
259
|
}
|
|
151
260
|
}
|
|
152
261
|
}
|
|
153
262
|
function argsWithProp(vertex, info, prop) {
|
|
154
263
|
return info?.sig === undefined ? [] : match_args_1.MatchArgs.findWithProps(vertex.args, info.sig, prop);
|
|
155
264
|
}
|
|
156
|
-
function holdsEnvironment(graph, argument, environment) {
|
|
157
|
-
const node = graph.idMap?.get(argument);
|
|
158
|
-
if (!r_symbol_1.RSymbol.is(node)) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
return (resolve_helper_1.Resolve.byName(node.content, environment) ?? [])
|
|
162
|
-
.some(identifier_1.hasEnvState);
|
|
163
|
-
}
|
|
164
265
|
function definitionsReachedBy(node, graph) {
|
|
165
266
|
return df_helper_1.Dataflow.reachable(graph, node, {
|
|
166
267
|
follow: edge_1.EdgeType.Reads,
|
|
167
268
|
stopAt: id => vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(id))
|
|
168
269
|
});
|
|
169
270
|
}
|
|
170
|
-
function sameResource(a, b, reachedBy, pathOf) {
|
|
171
|
-
if (a === b) {
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
const reachedByA = reachedBy(a);
|
|
175
|
-
for (const t of reachedBy(b)) {
|
|
176
|
-
if (reachedByA.has(t)) {
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const path = pathOf(a);
|
|
181
|
-
return path !== undefined && path === pathOf(b);
|
|
182
|
-
}
|
|
183
271
|
function fileCallNames(index) {
|
|
184
272
|
return new Set(index.with(built_in_props_1.SemanticCallTag.File).map(identifier_1.Identifier.getName));
|
|
185
273
|
}
|
|
@@ -211,10 +299,10 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
211
299
|
continue;
|
|
212
300
|
}
|
|
213
301
|
const resource = argsWithProp(vertex, info, built_in_props_1.ArgProp.Resource)[0];
|
|
214
|
-
|
|
215
|
-
|
|
302
|
+
/* writing to the console names no file, and neither does a reader we cannot pin down */
|
|
303
|
+
if (resource !== undefined) {
|
|
304
|
+
(reads ? readers : writers).push({ id, resource });
|
|
216
305
|
}
|
|
217
|
-
(reads ? readers : writers).push({ id, resource });
|
|
218
306
|
}
|
|
219
307
|
if (readers.length === 0 || writers.length === 0) {
|
|
220
308
|
return;
|
|
@@ -222,35 +310,63 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
222
310
|
const reachedBy = (0, defaultmap_1.memoize)((id) => definitionsReachedBy(id, graph));
|
|
223
311
|
const where = { graph, idMap: graph.idMap, resolve: ctx.config.solver.variables, ctx, environment };
|
|
224
312
|
const pathOf = (0, defaultmap_1.memoize)((id) => resolve_helper_1.Resolve.toSingleString(id, where));
|
|
313
|
+
const sameResource = (a, b) => {
|
|
314
|
+
if (a === b || reachedBy(b).values().some(t => reachedBy(a).has(t))) {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
const path = pathOf(a);
|
|
318
|
+
return path !== undefined && path === pathOf(b);
|
|
319
|
+
};
|
|
225
320
|
let cfg;
|
|
226
321
|
for (const reader of readers) {
|
|
227
322
|
let before;
|
|
228
323
|
for (const writer of writers) {
|
|
229
|
-
if (reader.id === writer.id || !sameResource(reader.resource, writer.resource
|
|
324
|
+
if (reader.id === writer.id || !sameResource(reader.resource, writer.resource)) {
|
|
230
325
|
continue;
|
|
231
326
|
}
|
|
232
327
|
before ??= (0, happens_before_1.reachableTo)(cfg ??= new control_flow_graph_1.ControlFlowGraph(graph), [reader.id]);
|
|
233
328
|
if (before.has(writer.id)) {
|
|
234
329
|
graph.addEdge(reader.id, writer.id, edge_1.EdgeType.Reads);
|
|
235
330
|
/* whatever is linked to a diverting writer (`print` after `sink(file)`) writes to the resource as well */
|
|
236
|
-
const
|
|
237
|
-
for (const id of diverted) {
|
|
331
|
+
for (const id of (0, frame_reflection_1.edgeSources)(graph, writer.id, edge_1.EdgeType.Reads)) {
|
|
238
332
|
graph.addEdge(reader.id, id, edge_1.EdgeType.Reads);
|
|
239
333
|
}
|
|
240
334
|
}
|
|
241
335
|
}
|
|
242
336
|
}
|
|
243
337
|
}
|
|
338
|
+
/** A variable read linked to a call diverting the output (`sink(con)`, see `AmbientStateName.textConnection`) also reads what that call diverts. */
|
|
339
|
+
function linkReadsOfDivertedOutput(graph, environment) {
|
|
340
|
+
if (!(0, built_in_ambient_state_1.mayForce)(environment)) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const printsOf = (0, defaultmap_1.memoize)((id) => function_semantics_1.FunctionSemantics.call.props.hasAll((0, query_fn_props_1.callFnProps)(id, { graph, environment }), [built_in_props_1.SemanticCallTag.Prints]));
|
|
344
|
+
const printingCall = (writer) => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(writer)) && printsOf(writer);
|
|
345
|
+
const writersOf = (0, defaultmap_1.memoize)((target) => (0, frame_reflection_1.edgeSources)(graph, target, edge_1.EdgeType.Reads).filter(printingCall));
|
|
346
|
+
for (const [id] of graph.verticesOfType(vertex_1.VertexType.Use)) {
|
|
347
|
+
for (const target of (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads)) {
|
|
348
|
+
const diverting = graph.getVertex(target);
|
|
349
|
+
if (!vertex_1.DfgVertex.isFunctionCall(diverting) || diverting.args.length === 0) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
for (const writer of writersOf(target)) {
|
|
353
|
+
if (writer !== id) {
|
|
354
|
+
graph.addEdge(id, writer, edge_1.EdgeType.Reads);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
244
360
|
function resolveLinkToSideEffects(graph, ctx) {
|
|
245
361
|
const gasLevel = ctx.gas.checkGas(gas_1.GasFeatureKey.SideEffectLinking);
|
|
246
362
|
if (gasLevel >= 2 /* GasLevel.Critical */) {
|
|
247
363
|
logger_1.dataflowLogger.warn('Skipping side-effect link resolution due to resource pressure (gas: critical). See ' + gas_1.GasWikiRef);
|
|
248
|
-
return
|
|
364
|
+
return;
|
|
249
365
|
}
|
|
250
366
|
else if (gasLevel >= 1 /* GasLevel.Problematic */) {
|
|
251
367
|
logger_1.dataflowLogger.warn('Approaching resource limits during side-effect link resolution (gas: problematic). See ' + gas_1.GasWikiRef);
|
|
252
368
|
}
|
|
253
|
-
let cf
|
|
369
|
+
let cf;
|
|
254
370
|
let knownCalls;
|
|
255
371
|
let allCallNames = [];
|
|
256
372
|
const killedRegexes = new Set();
|
|
@@ -273,11 +389,10 @@ function resolveLinkToSideEffects(graph, ctx) {
|
|
|
273
389
|
handled.add(s.id);
|
|
274
390
|
const regexKey = s.linkTo.callName.source + '//' + s.linkTo.callName.flags;
|
|
275
391
|
if (killedRegexes.has(regexKey)) {
|
|
276
|
-
// we already know we will not find it!
|
|
277
392
|
continue;
|
|
278
393
|
}
|
|
279
394
|
else if (allCallNames.length > 0 && !allCallNames.some(name => s.linkTo.callName.test(name))) {
|
|
280
|
-
|
|
395
|
+
/* we know no call matches the regex */
|
|
281
396
|
killedRegexes.add(regexKey);
|
|
282
397
|
continue;
|
|
283
398
|
}
|
|
@@ -331,13 +446,17 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
|
331
446
|
df = (0, built_in_source_1.standaloneSourceFile)(i, files[i], dfData, df);
|
|
332
447
|
}
|
|
333
448
|
// resolve linkages and propagate transitive side effects across calls to a fixpoint
|
|
449
|
+
callActiveBindings(df.graph);
|
|
450
|
+
readFramesThroughEnvironment(df.graph);
|
|
334
451
|
(0, built_in_function_definition_1.updateNestedFunctionCalls)(df.graph, df.environment, ctx);
|
|
335
452
|
const escapedNames = new Set();
|
|
336
453
|
/* carried across the rounds, so a definition already folded in does not read as growth again */
|
|
337
454
|
const foldedIn = new Set();
|
|
338
455
|
const rounds = ctx.config.solver.transitiveSideEffectRounds ?? config_1.DefaultTransitiveSideEffectRounds;
|
|
456
|
+
/* a read of the options or graphics state nothing set reads the state R starts with, unless a write escaping a call replaces it */
|
|
457
|
+
const [initialState, open] = (0, arrays_1.partitionArray)(df.in, r => built_in_ambient_state_1.AmbientStateName.is(r.name));
|
|
339
458
|
for (let round = 0; round < rounds; round++) {
|
|
340
|
-
const { environment, grew, escapedNames: roundNames } = df_helper_1.Dataflow.sideEffects.propagateTransitive(df.graph, df.environment, ctx, foldedIn);
|
|
459
|
+
const { environment, grew, escapedNames: roundNames } = df_helper_1.Dataflow.sideEffects.propagateTransitive(df.graph, df.environment, ctx, foldedIn, initialState);
|
|
341
460
|
df.environment = environment;
|
|
342
461
|
for (const n of roundNames) {
|
|
343
462
|
escapedNames.add(n);
|
|
@@ -347,16 +466,23 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
|
347
466
|
}
|
|
348
467
|
(0, built_in_function_definition_1.updateNestedFunctionCalls)(df.graph, df.environment, ctx);
|
|
349
468
|
}
|
|
469
|
+
markCallsOfUnknownValues(df.graph, df.environment);
|
|
470
|
+
df.in = open.concat(openReadsOfCalledFunctions(df.graph));
|
|
350
471
|
// resolve top-level reads that now see the escaped `<<-` definitions folded in above
|
|
351
472
|
if (escapedNames.size > 0) {
|
|
352
473
|
(0, transitive_side_effects_1.reResolveOpenReferences)(df.graph, df.environment, [...df.in, ...df.unknownReferences], escapedNames);
|
|
353
474
|
}
|
|
354
475
|
// link on-demand-materialized package exports back to their `library()` loaders
|
|
355
476
|
(0, transitive_side_effects_1.linkMaterializedExportsToLoaders)(df.graph, df.environment);
|
|
477
|
+
const cleanEnvironment = ctx.env.makeCleanEnv();
|
|
478
|
+
(0, linker_1.separateClosureInstances)(df.graph, name => (0, query_fn_props_1.queryFnProps)(name, { environment: cleanEnvironment }));
|
|
356
479
|
function_semantics_1.FunctionSemantics.call.quoted.finalize(df.graph, df.environment, completeAst.idMap, () => new control_flow_graph_1.ControlFlowGraph(df.graph));
|
|
480
|
+
(0, built_in_try_catch_1.orderRaisingBodies)(df.graph, completeAst.idMap, ctx);
|
|
481
|
+
function_semantics_1.FunctionSemantics.settleJumpsInPromises(df.graph, df.exitPoints, { ctx });
|
|
357
482
|
linkEnvironmentArgumentsWrittenByCallee(df.graph, df.environment);
|
|
358
483
|
resolveLinkToSideEffects(df.graph, ctx);
|
|
359
484
|
linkResourceReadersToWriters(df.graph, df.environment, ctx);
|
|
485
|
+
linkReadsOfDivertedOutput(df.graph, df.environment);
|
|
360
486
|
return df;
|
|
361
487
|
}
|
|
362
488
|
//# sourceMappingURL=extractor.js.map
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* which argument means what is configured per built-in in {@link ClassDeclarationConfig}, not guessed.
|
|
4
4
|
*/
|
|
5
5
|
import type { RNode } from '../../r-bridge/lang-4.x/ast/model/model';
|
|
6
|
-
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
7
|
-
import
|
|
6
|
+
import type { AstIdMap, ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
7
|
+
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
8
8
|
import { type PotentiallyEmptyRArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
9
9
|
import type { DataflowGraph } from '../graph/graph';
|
|
10
10
|
import type { SigClassInfo } from '../../project/sigdb/schema';
|
|
11
|
+
import type { ResolveInfo } from '../eval/resolve/alias-tracking';
|
|
11
12
|
/** The object system a declaration belongs to. */
|
|
12
13
|
export declare const enum ClassSystem {
|
|
13
14
|
/** `setClass`, `setClassUnion`, `setIs`, `setValidity` */
|
|
@@ -113,3 +114,8 @@ export declare function superClassesOfImpl(name: string, classes: ReadonlyMap<st
|
|
|
113
114
|
* the analysis declared carries no `package`; a referenced class `ownerOf` can place becomes a `foreign` record.
|
|
114
115
|
*/
|
|
115
116
|
export declare function toSigClassesImpl(classes: ReadonlyMap<string, DeclaredClass>, ownerOf?: (name: string) => string | undefined): SigClassInfo[];
|
|
117
|
+
/** The class vectors S3 dispatch may see for the argument at `id`, one per reaching definition, `undefined` unless all are known. */
|
|
118
|
+
export declare function s3DispatchClassesOf(id: NodeId, info: ResolveInfo & {
|
|
119
|
+
readonly graph: DataflowGraph;
|
|
120
|
+
readonly idMap: AstIdMap;
|
|
121
|
+
}): readonly (readonly string[])[] | undefined;
|