@eagleoutice/flowr 2.15.10 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -26
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/control-flow/happens-before.d.ts +5 -0
- package/control-flow/happens-before.js +48 -34
- package/control-flow/useless-loop.d.ts +1 -1
- package/control-flow/useless-loop.js +29 -42
- package/dataflow/environments/built-in-props.d.ts +9 -0
- package/dataflow/environments/built-in-props.js +25 -19
- package/dataflow/environments/built-in.d.ts +2 -2
- package/dataflow/environments/built-in.js +41 -77
- package/dataflow/environments/default-builtin-config.d.ts +181 -29
- package/dataflow/environments/default-builtin-config.js +38 -24
- package/dataflow/environments/environment.d.ts +6 -4
- package/dataflow/environments/environment.js +54 -121
- package/dataflow/environments/identifier.d.ts +4 -2
- package/dataflow/environments/identifier.js +23 -69
- package/dataflow/environments/reference-to-maybe.d.ts +9 -0
- package/dataflow/environments/reference-to-maybe.js +23 -51
- package/dataflow/environments/resolve-by-name.js +37 -76
- package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
- package/dataflow/eval/resolve/resolve-argument.js +61 -64
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
- package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
- package/dataflow/eval/resolve/resolve.d.ts +4 -0
- package/dataflow/eval/resolve/resolve.js +23 -14
- package/dataflow/extractor.js +176 -59
- package/dataflow/fn/class-declaration.d.ts +8 -2
- package/dataflow/fn/class-declaration.js +96 -97
- package/dataflow/fn/exceptions-of-function.js +68 -37
- package/dataflow/fn/frame-reflection.d.ts +12 -4
- package/dataflow/fn/frame-reflection.js +51 -41
- package/dataflow/fn/function-props.js +15 -33
- package/dataflow/fn/function-semantics.d.ts +11 -3
- package/dataflow/fn/function-semantics.js +6 -0
- package/dataflow/fn/higher-order-function.js +13 -17
- package/dataflow/fn/strict-function.d.ts +13 -0
- package/dataflow/fn/strict-function.js +285 -122
- package/dataflow/graph/call-graph.d.ts +7 -6
- package/dataflow/graph/call-graph.js +35 -46
- package/dataflow/graph/graph.d.ts +6 -1
- package/dataflow/graph/graph.js +57 -66
- package/dataflow/info.d.ts +8 -1
- package/dataflow/info.js +24 -30
- package/dataflow/internal/control-flow.d.ts +31 -4
- package/dataflow/internal/control-flow.js +61 -39
- package/dataflow/internal/linker.d.ts +15 -9
- package/dataflow/internal/linker.js +253 -241
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +446 -78
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +289 -251
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
- package/dataflow/internal/process/functions/call/common.d.ts +1 -3
- package/dataflow/internal/process/functions/call/common.js +36 -76
- package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
- package/dataflow/internal/process/functions/call/deferred.js +54 -57
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
- package/dataflow/internal/process/functions/call/named-call-handling.js +35 -21
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +162 -172
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
- package/dataflow/internal/process/functions/process-parameter.js +25 -32
- package/dataflow/internal/process/process-symbol.js +3 -6
- package/dataflow/internal/program-order.d.ts +26 -0
- package/dataflow/internal/program-order.js +49 -0
- package/documentation/wiki-setup.js +23 -0
- package/linter/linter-rules.d.ts +17 -8
- package/linter/rules/absolute-path.js +63 -87
- package/linter/rules/file-path-validity.d.ts +4 -2
- package/linter/rules/file-path-validity.js +114 -80
- package/linter/rules/namespace-access.js +21 -33
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +60 -48
- package/linter/rules/network-functions.js +11 -7
- package/linter/rules/no-leaked-credentials.js +15 -18
- package/linter/rules/problematic-inputs.d.ts +2 -1
- package/linter/rules/problematic-inputs.js +39 -59
- package/linter/rules/roxygen-arguments.d.ts +9 -4
- package/linter/rules/roxygen-arguments.js +29 -48
- package/linter/rules/seeded-randomness.d.ts +7 -4
- package/linter/rules/seeded-randomness.js +128 -89
- package/linter/rules/stop-with-call-arg.d.ts +4 -2
- package/linter/rules/stop-with-call-arg.js +25 -22
- package/linter/rules/unclosed-connection.js +31 -24
- package/linter/rules/undefined-symbol.d.ts +4 -6
- package/linter/rules/undefined-symbol.js +58 -75
- package/linter/rules/unescaped-arguments.js +18 -44
- package/linter/rules/unused-definition.d.ts +6 -0
- package/linter/rules/unused-definition.js +105 -145
- package/linter/rules/unused-import.d.ts +3 -0
- package/linter/rules/unused-import.js +25 -43
- package/package.json +5 -2
- package/project/flowr-analyzer.js +6 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +16 -41
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
- package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
- package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
- package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
- package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
- package/r-bridge/lang-4.x/ast/model/model.js +19 -43
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/roxygen2/roxygen-parse.js +28 -42
- package/r-bridge/shell.js +6 -0
- package/search/search-executor/search-enrichers.js +25 -37
- package/slicing/static/slice-call.d.ts +4 -3
- package/slicing/static/slice-call.js +56 -88
- package/slicing/static/static-slicer.js +115 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/proc.js +2 -1
- package/util/r-base-packages.d.ts +2 -0
- package/util/r-base-packages.js +23 -13
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
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,151 @@ 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
|
+
const bindings = new Map();
|
|
164
|
+
for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
|
|
165
|
+
const fns = (0, frame_reflection_1.calledDefinitions)(graph, id);
|
|
166
|
+
if (fns.length > 0) {
|
|
167
|
+
bindings.set(id, fns);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const [, ids] of bindings.size === 0 ? [] : (0, frame_reflection_1.definitionsByName)(graph).entries()) {
|
|
171
|
+
const fns = ids.flatMap(id => bindings.get(id) ?? []);
|
|
172
|
+
for (const id of fns.length === 0 ? [] : ids.filter(id => !bindings.has(id))) {
|
|
173
|
+
for (const assignment of (0, frame_reflection_1.edgeSources)(graph, id, edge_1.EdgeType.Returns).filter(a => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(a)))) {
|
|
174
|
+
for (const fn of fns) {
|
|
175
|
+
graph.addEdge(assignment, fn, edge_1.EdgeType.Calls);
|
|
176
|
+
graph.addEdge(id, fn, edge_1.EdgeType.Calls);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const isActiveBinding = (def) => vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(def)) && (0, frame_reflection_1.edgeTargets)(graph, def, edge_1.EdgeType.Calls).length > 0;
|
|
182
|
+
for (const id of graph.vertexIdsOfType(vertex_1.VertexType.Use)) {
|
|
183
|
+
const node = graph.idMap?.get(id);
|
|
184
|
+
if (r_symbol_1.RSymbol.is(node) && (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads).some(isActiveBinding)) {
|
|
185
|
+
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] });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/** A call of what a closure returned that we could not link (`h2 <- h()` with `h` returning `sys.function()`) may run anything. */
|
|
190
|
+
function markCallsOfUnknownValues(graph, environment) {
|
|
191
|
+
const fromClosure = (def) => vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(def))
|
|
192
|
+
&& (0, frame_reflection_1.edgeTargets)(graph, def, edge_1.EdgeType.DefinedBy).some(c => (0, frame_reflection_1.calledDefinitions)(graph, c).length > 0);
|
|
193
|
+
for (const [id, call] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
194
|
+
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)) {
|
|
195
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(graph, environment, id);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** `environment()` hands out the function's frame by reference, so the call reads every definition of the frame, a closure's `<<-` included. */
|
|
200
|
+
function readFramesThroughEnvironment(graph) {
|
|
201
|
+
const idMap = graph.idMap;
|
|
202
|
+
if (idMap === undefined) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const environmentCall = node_id_1.NodeId.toBuiltIn('environment');
|
|
206
|
+
const callsEnvironment = (id) => (0, frame_reflection_1.hasEdgeOfType)(graph, id, environmentCall, edge_1.EdgeType.Calls);
|
|
207
|
+
/* `environment(fn)` hands out the frame `fn` was created in */
|
|
208
|
+
const ofClosures = new defaultmap_1.DefaultMap(() => []);
|
|
209
|
+
for (const [id, call] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
210
|
+
const fn = call.args.length === 1 && callsEnvironment(id) ? graph_1.FunctionArgument.getReference(call.args[0]) : undefined;
|
|
211
|
+
for (const closure of fn === undefined ? [] : (0, linker_1.getAllLinkedFunctionDefinitions)(new Set([fn]), graph)[0]) {
|
|
212
|
+
const creator = model_1.RNode.strictlyEnclosingFunction(closure.id, idMap);
|
|
213
|
+
if (creator !== undefined) {
|
|
214
|
+
ofClosures.get(creator).push(id);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
for (const [, definition] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
219
|
+
const frameCalls = ofClosures.get(definition.id);
|
|
220
|
+
if (frameCalls.length === 0 && !definition.subflow.graph.values().some(callsEnvironment)) {
|
|
136
221
|
continue;
|
|
137
222
|
}
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
for (const
|
|
141
|
-
|
|
142
|
-
|
|
223
|
+
/* the nested functions' bodies, too, where a closure may write the frame */
|
|
224
|
+
const within = [...definition.subflow.graph];
|
|
225
|
+
for (const id of within) {
|
|
226
|
+
const vertex = graph.getVertex(id);
|
|
227
|
+
if (vertex_1.DfgVertex.isFunctionDefinition(vertex) && vertex.id !== definition.id) {
|
|
228
|
+
within.push(...vertex.subflow.graph);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const definitions = [];
|
|
232
|
+
for (const id of new Set(within)) {
|
|
233
|
+
const vertex = graph.getVertex(id);
|
|
234
|
+
const own = model_1.RNode.findEnclosing(id, idMap, r_function_definition_1.RFunctionDefinition.is) === definition.id;
|
|
235
|
+
if (own && vertex_1.DfgVertex.isFunctionCall(vertex) && vertex.args.length === 0 && callsEnvironment(id)) {
|
|
236
|
+
frameCalls.push(id);
|
|
143
237
|
}
|
|
144
|
-
else if (
|
|
145
|
-
|
|
238
|
+
else if (vertex_1.DfgVertex.isVariableDefinition(vertex) && !(id in definition.params)) {
|
|
239
|
+
/* a parameter is what the call binds, which reflecting on the frame already accounts for */
|
|
240
|
+
definitions.push({ id, own, name: node_id_1.NodeId.recoverName(id, idMap) });
|
|
146
241
|
}
|
|
147
242
|
}
|
|
148
|
-
|
|
149
|
-
|
|
243
|
+
const local = new Set(definitions.filter(d => d.own && d.name !== undefined).map(d => d.name));
|
|
244
|
+
/* a nested definition writes this frame only by `<<-` to a name it binds */
|
|
245
|
+
const bySuperAssignment = (id) => vertex_1.DfgVertex.hasOrigin(graph.getVertex(idMap.get(id)?.info.parent ?? ''), built_in_proc_name_1.BuiltInProcName.SuperAssignment);
|
|
246
|
+
for (const d of definitions.filter(d => local.has(d.name ?? '') && (d.own || bySuperAssignment(d.id)))) {
|
|
247
|
+
for (const call of frameCalls) {
|
|
248
|
+
graph.addEdge(call, d.id, edge_1.EdgeType.Reads);
|
|
249
|
+
}
|
|
150
250
|
}
|
|
151
251
|
}
|
|
152
252
|
}
|
|
153
253
|
function argsWithProp(vertex, info, prop) {
|
|
154
254
|
return info?.sig === undefined ? [] : match_args_1.MatchArgs.findWithProps(vertex.args, info.sig, prop);
|
|
155
255
|
}
|
|
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
256
|
function definitionsReachedBy(node, graph) {
|
|
165
257
|
return df_helper_1.Dataflow.reachable(graph, node, {
|
|
166
258
|
follow: edge_1.EdgeType.Reads,
|
|
167
259
|
stopAt: id => vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(id))
|
|
168
260
|
});
|
|
169
261
|
}
|
|
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
262
|
function fileCallNames(index) {
|
|
184
263
|
return new Set(index.with(built_in_props_1.SemanticCallTag.File).map(identifier_1.Identifier.getName));
|
|
185
264
|
}
|
|
@@ -211,10 +290,10 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
211
290
|
continue;
|
|
212
291
|
}
|
|
213
292
|
const resource = argsWithProp(vertex, info, built_in_props_1.ArgProp.Resource)[0];
|
|
214
|
-
|
|
215
|
-
|
|
293
|
+
/* writing to the console names no file, and neither does a reader we cannot pin down */
|
|
294
|
+
if (resource !== undefined) {
|
|
295
|
+
(reads ? readers : writers).push({ id, resource });
|
|
216
296
|
}
|
|
217
|
-
(reads ? readers : writers).push({ id, resource });
|
|
218
297
|
}
|
|
219
298
|
if (readers.length === 0 || writers.length === 0) {
|
|
220
299
|
return;
|
|
@@ -222,35 +301,63 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
|
|
|
222
301
|
const reachedBy = (0, defaultmap_1.memoize)((id) => definitionsReachedBy(id, graph));
|
|
223
302
|
const where = { graph, idMap: graph.idMap, resolve: ctx.config.solver.variables, ctx, environment };
|
|
224
303
|
const pathOf = (0, defaultmap_1.memoize)((id) => resolve_helper_1.Resolve.toSingleString(id, where));
|
|
304
|
+
const sameResource = (a, b) => {
|
|
305
|
+
if (a === b || reachedBy(b).values().some(t => reachedBy(a).has(t))) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
const path = pathOf(a);
|
|
309
|
+
return path !== undefined && path === pathOf(b);
|
|
310
|
+
};
|
|
225
311
|
let cfg;
|
|
226
312
|
for (const reader of readers) {
|
|
227
313
|
let before;
|
|
228
314
|
for (const writer of writers) {
|
|
229
|
-
if (reader.id === writer.id || !sameResource(reader.resource, writer.resource
|
|
315
|
+
if (reader.id === writer.id || !sameResource(reader.resource, writer.resource)) {
|
|
230
316
|
continue;
|
|
231
317
|
}
|
|
232
318
|
before ??= (0, happens_before_1.reachableTo)(cfg ??= new control_flow_graph_1.ControlFlowGraph(graph), [reader.id]);
|
|
233
319
|
if (before.has(writer.id)) {
|
|
234
320
|
graph.addEdge(reader.id, writer.id, edge_1.EdgeType.Reads);
|
|
235
321
|
/* 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) {
|
|
322
|
+
for (const id of (0, frame_reflection_1.edgeSources)(graph, writer.id, edge_1.EdgeType.Reads)) {
|
|
238
323
|
graph.addEdge(reader.id, id, edge_1.EdgeType.Reads);
|
|
239
324
|
}
|
|
240
325
|
}
|
|
241
326
|
}
|
|
242
327
|
}
|
|
243
328
|
}
|
|
329
|
+
/** A variable read linked to a call diverting the output (`sink(con)`, see `AmbientStateName.textConnection`) also reads what that call diverts. */
|
|
330
|
+
function linkReadsOfDivertedOutput(graph, environment) {
|
|
331
|
+
if (!(0, built_in_ambient_state_1.mayForce)(environment)) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
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]));
|
|
335
|
+
const printingCall = (writer) => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(writer)) && printsOf(writer);
|
|
336
|
+
const writersOf = (0, defaultmap_1.memoize)((target) => (0, frame_reflection_1.edgeSources)(graph, target, edge_1.EdgeType.Reads).filter(printingCall));
|
|
337
|
+
for (const [id] of graph.verticesOfType(vertex_1.VertexType.Use)) {
|
|
338
|
+
for (const target of (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads)) {
|
|
339
|
+
const diverting = graph.getVertex(target);
|
|
340
|
+
if (!vertex_1.DfgVertex.isFunctionCall(diverting) || diverting.args.length === 0) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
for (const writer of writersOf(target)) {
|
|
344
|
+
if (writer !== id) {
|
|
345
|
+
graph.addEdge(id, writer, edge_1.EdgeType.Reads);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
244
351
|
function resolveLinkToSideEffects(graph, ctx) {
|
|
245
352
|
const gasLevel = ctx.gas.checkGas(gas_1.GasFeatureKey.SideEffectLinking);
|
|
246
353
|
if (gasLevel >= 2 /* GasLevel.Critical */) {
|
|
247
354
|
logger_1.dataflowLogger.warn('Skipping side-effect link resolution due to resource pressure (gas: critical). See ' + gas_1.GasWikiRef);
|
|
248
|
-
return
|
|
355
|
+
return;
|
|
249
356
|
}
|
|
250
357
|
else if (gasLevel >= 1 /* GasLevel.Problematic */) {
|
|
251
358
|
logger_1.dataflowLogger.warn('Approaching resource limits during side-effect link resolution (gas: problematic). See ' + gas_1.GasWikiRef);
|
|
252
359
|
}
|
|
253
|
-
let cf
|
|
360
|
+
let cf;
|
|
254
361
|
let knownCalls;
|
|
255
362
|
let allCallNames = [];
|
|
256
363
|
const killedRegexes = new Set();
|
|
@@ -273,11 +380,10 @@ function resolveLinkToSideEffects(graph, ctx) {
|
|
|
273
380
|
handled.add(s.id);
|
|
274
381
|
const regexKey = s.linkTo.callName.source + '//' + s.linkTo.callName.flags;
|
|
275
382
|
if (killedRegexes.has(regexKey)) {
|
|
276
|
-
// we already know we will not find it!
|
|
277
383
|
continue;
|
|
278
384
|
}
|
|
279
385
|
else if (allCallNames.length > 0 && !allCallNames.some(name => s.linkTo.callName.test(name))) {
|
|
280
|
-
|
|
386
|
+
/* we know no call matches the regex */
|
|
281
387
|
killedRegexes.add(regexKey);
|
|
282
388
|
continue;
|
|
283
389
|
}
|
|
@@ -331,13 +437,17 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
|
331
437
|
df = (0, built_in_source_1.standaloneSourceFile)(i, files[i], dfData, df);
|
|
332
438
|
}
|
|
333
439
|
// resolve linkages and propagate transitive side effects across calls to a fixpoint
|
|
440
|
+
callActiveBindings(df.graph);
|
|
441
|
+
readFramesThroughEnvironment(df.graph);
|
|
334
442
|
(0, built_in_function_definition_1.updateNestedFunctionCalls)(df.graph, df.environment, ctx);
|
|
335
443
|
const escapedNames = new Set();
|
|
336
444
|
/* carried across the rounds, so a definition already folded in does not read as growth again */
|
|
337
445
|
const foldedIn = new Set();
|
|
338
446
|
const rounds = ctx.config.solver.transitiveSideEffectRounds ?? config_1.DefaultTransitiveSideEffectRounds;
|
|
447
|
+
/* a read of the options or graphics state nothing set reads the state R starts with, unless a write escaping a call replaces it */
|
|
448
|
+
const [initialState, open] = (0, arrays_1.partitionArray)(df.in, r => built_in_ambient_state_1.AmbientStateName.is(r.name));
|
|
339
449
|
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);
|
|
450
|
+
const { environment, grew, escapedNames: roundNames } = df_helper_1.Dataflow.sideEffects.propagateTransitive(df.graph, df.environment, ctx, foldedIn, initialState);
|
|
341
451
|
df.environment = environment;
|
|
342
452
|
for (const n of roundNames) {
|
|
343
453
|
escapedNames.add(n);
|
|
@@ -347,16 +457,23 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
|
|
|
347
457
|
}
|
|
348
458
|
(0, built_in_function_definition_1.updateNestedFunctionCalls)(df.graph, df.environment, ctx);
|
|
349
459
|
}
|
|
460
|
+
markCallsOfUnknownValues(df.graph, df.environment);
|
|
461
|
+
df.in = open.concat(openReadsOfCalledFunctions(df.graph));
|
|
350
462
|
// resolve top-level reads that now see the escaped `<<-` definitions folded in above
|
|
351
463
|
if (escapedNames.size > 0) {
|
|
352
464
|
(0, transitive_side_effects_1.reResolveOpenReferences)(df.graph, df.environment, [...df.in, ...df.unknownReferences], escapedNames);
|
|
353
465
|
}
|
|
354
466
|
// link on-demand-materialized package exports back to their `library()` loaders
|
|
355
467
|
(0, transitive_side_effects_1.linkMaterializedExportsToLoaders)(df.graph, df.environment);
|
|
468
|
+
const cleanEnvironment = ctx.env.makeCleanEnv();
|
|
469
|
+
(0, linker_1.separateClosureInstances)(df.graph, name => (0, query_fn_props_1.queryFnProps)(name, { environment: cleanEnvironment }));
|
|
356
470
|
function_semantics_1.FunctionSemantics.call.quoted.finalize(df.graph, df.environment, completeAst.idMap, () => new control_flow_graph_1.ControlFlowGraph(df.graph));
|
|
471
|
+
(0, built_in_try_catch_1.orderRaisingBodies)(df.graph, completeAst.idMap, ctx);
|
|
472
|
+
function_semantics_1.FunctionSemantics.settleJumpsInPromises(df.graph, df.exitPoints, { ctx });
|
|
357
473
|
linkEnvironmentArgumentsWrittenByCallee(df.graph, df.environment);
|
|
358
474
|
resolveLinkToSideEffects(df.graph, ctx);
|
|
359
475
|
linkResourceReadersToWriters(df.graph, df.environment, ctx);
|
|
476
|
+
linkReadsOfDivertedOutput(df.graph, df.environment);
|
|
360
477
|
return df;
|
|
361
478
|
}
|
|
362
479
|
//# 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;
|