@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
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.edgeTargets = edgeTargets;
|
|
4
|
+
exports.calledDefinitions = calledDefinitions;
|
|
5
|
+
exports.edgeSources = edgeSources;
|
|
6
|
+
exports.definitionsByName = definitionsByName;
|
|
7
|
+
exports.hasEdgeOfType = hasEdgeOfType;
|
|
4
8
|
exports.callsIn = callsIn;
|
|
5
9
|
exports.propagateToFixpoint = propagateToFixpoint;
|
|
6
10
|
exports.reflectiveRolesOf = reflectiveRolesOf;
|
|
@@ -10,11 +14,36 @@ const edge_1 = require("../graph/edge");
|
|
|
10
14
|
const df_helper_1 = require("../graph/df-helper");
|
|
11
15
|
const vertex_1 = require("../graph/vertex");
|
|
12
16
|
const built_in_props_1 = require("../environments/built-in-props");
|
|
17
|
+
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
18
|
+
const retriever_1 = require("../../r-bridge/retriever");
|
|
13
19
|
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
14
20
|
/** The nodes at the far end of `node`'s outgoing edges of any of `types`, shared by every walk here and in the sibling analyses that follow specific edge kinds. */
|
|
15
21
|
function edgeTargets(graph, node, types) {
|
|
16
22
|
return [...graph.edgesFrom(node)].filter(([, edge]) => edge_1.DfEdge.includesType(edge, types)).map(([target]) => target);
|
|
17
23
|
}
|
|
24
|
+
/** The function-definition vertices a `call` resolves to (via {@link EdgeType.Calls}). */
|
|
25
|
+
function calledDefinitions(graph, call) {
|
|
26
|
+
return edgeTargets(graph, call, edge_1.EdgeType.Calls).filter(t => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)));
|
|
27
|
+
}
|
|
28
|
+
/** The nodes at the near end of `node`'s incoming edges of any of `types`, see {@link edgeTargets}. */
|
|
29
|
+
function edgeSources(graph, node, types) {
|
|
30
|
+
return [...graph.edgesTo(node)].filter(([, edge]) => edge_1.DfEdge.includesType(edge, types)).map(([source]) => source);
|
|
31
|
+
}
|
|
32
|
+
/** Every variable definition by its unquoted name, in a single pass. */
|
|
33
|
+
function definitionsByName(graph) {
|
|
34
|
+
const byName = new defaultmap_1.DefaultMap(() => []);
|
|
35
|
+
for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
|
|
36
|
+
const name = node_id_1.NodeId.recoverName(id, graph.idMap);
|
|
37
|
+
if (name !== undefined) {
|
|
38
|
+
byName.get((0, retriever_1.removeRQuotes)(name)).push(id);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return byName;
|
|
42
|
+
}
|
|
43
|
+
/** Whether an edge from `from` to `to` carries any of `types`. */
|
|
44
|
+
function hasEdgeOfType(graph, from, to, types) {
|
|
45
|
+
return edge_1.DfEdge.includesType(graph.outgoingEdges(from)?.get(to) ?? { types: 0 }, types);
|
|
46
|
+
}
|
|
18
47
|
/** The calls a definition's body reaches, id and vertex paired; shared by every walk here and in the sibling analyses that visit them all. */
|
|
19
48
|
function* callsIn(definition, graph) {
|
|
20
49
|
for (const node of definition.subflow.graph) {
|
|
@@ -27,9 +56,8 @@ function* callsIn(definition, graph) {
|
|
|
27
56
|
/**
|
|
28
57
|
* Recomputes `recompute(id)` for every node reachable from `seed` along the reverse of `successors`, so a
|
|
29
58
|
* change at a node is carried on to whatever points at it, until nothing grows anymore. `recompute` updates
|
|
30
|
-
* its node's value itself and reports whether it grew; shared by {@link propagateOverCalls} and
|
|
31
|
-
* {@link
|
|
32
|
-
* by {@link carriersOf} below, which grows a set rather than a bitfield.
|
|
59
|
+
* its node's value itself and reports whether it grew; shared by {@link propagateOverCalls} and by
|
|
60
|
+
* {@link carriersOf} below, which grows a set rather than a bitfield.
|
|
33
61
|
*/
|
|
34
62
|
function propagateToFixpoint(seed, successors, recompute) {
|
|
35
63
|
const callers = new defaultmap_1.DefaultMap(() => []);
|
|
@@ -63,8 +91,9 @@ function propagateToFixpoint(seed, successors, recompute) {
|
|
|
63
91
|
function reflectiveRolesOf(definition, graph, { known }) {
|
|
64
92
|
let roles = 0;
|
|
65
93
|
for (const [node, vertex] of callsIn(definition, graph)) {
|
|
66
|
-
const
|
|
67
|
-
|
|
94
|
+
const info = known(vertex.name);
|
|
95
|
+
const frame = info?.frame ?? 0;
|
|
96
|
+
if (frame === 0 || (roles & frame) === frame || handedAnotherFrame(vertex, info)) {
|
|
68
97
|
continue;
|
|
69
98
|
}
|
|
70
99
|
if (!resolvedThroughout(node, definition, graph)) {
|
|
@@ -74,27 +103,35 @@ function reflectiveRolesOf(definition, graph, { known }) {
|
|
|
74
103
|
return roles;
|
|
75
104
|
}
|
|
76
105
|
/** Whether the call was handed the frame to look at ({@link ArgProp.Handle}, as in `environment(g)`). */
|
|
77
|
-
function handedAnotherFrame(vertex,
|
|
78
|
-
|
|
79
|
-
return sig !== undefined && built_in_props_1.FnSig.posWith(built_in_props_1.FnSig.layout(sig), vertex.args.length, built_in_props_1.ArgProp.Handle).length > 0;
|
|
106
|
+
function handedAnotherFrame(vertex, info) {
|
|
107
|
+
return info?.sig !== undefined && built_in_props_1.FnSig.posWith(built_in_props_1.FnSig.layout(info.sig), vertex.args.length, built_in_props_1.ArgProp.Handle).length > 0;
|
|
80
108
|
}
|
|
81
109
|
/** Whether every consumer of what the reflective call at `frame` handed out resolves to a formal, and there is at least one. */
|
|
82
110
|
function resolvedThroughout(frame, definition, graph) {
|
|
83
111
|
const formals = new Set(df_helper_1.Dataflow.parametersOf(definition));
|
|
84
112
|
const carrying = carriersOf(frame, definition, graph);
|
|
85
113
|
let consumers = 0;
|
|
86
|
-
for (const node of definition
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
114
|
+
for (const [node, vertex] of callsIn(definition, graph)) {
|
|
115
|
+
const args = argumentsOf(vertex);
|
|
116
|
+
if (carrying.has(node) || !args.some(id => carrying.has(id))) {
|
|
89
117
|
continue;
|
|
90
118
|
}
|
|
91
119
|
consumers++;
|
|
92
|
-
if (!resolvedToAFormal(
|
|
120
|
+
if (!resolvedToAFormal(node, args, formals, graph)) {
|
|
93
121
|
return false;
|
|
94
122
|
}
|
|
95
123
|
}
|
|
96
124
|
return consumers > 0;
|
|
97
125
|
}
|
|
126
|
+
/** Whether the consuming `call` itself, or one of its arguments naming what it looks up by a fixed name, reads a formal. */
|
|
127
|
+
function resolvedToAFormal(call, args, formals, graph) {
|
|
128
|
+
const fixed = args.filter(id => isFixedName(id, graph));
|
|
129
|
+
return [call, ...fixed].some(id => edgeTargets(graph, id, edge_1.EdgeType.Reads).some(to => formals.has(to)));
|
|
130
|
+
}
|
|
131
|
+
function isFixedName(node, graph) {
|
|
132
|
+
const vertex = graph.getVertex(node);
|
|
133
|
+
return vertex_1.DfgVertex.isValue(vertex) || (vertex_1.DfgVertex.isUse(vertex) && vertex.constantFallback === true);
|
|
134
|
+
}
|
|
98
135
|
/** Every edge kind that carries a value on to whoever reads it next, for {@link carriersOf}. */
|
|
99
136
|
const CarryingEdges = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument;
|
|
100
137
|
/** The nodes carrying what the reflective call handed out: the call itself, the names stored under it, and reads of them. */
|
|
@@ -119,36 +156,9 @@ function carriersOf(frame, definition, graph) {
|
|
|
119
156
|
function passesOn(vertex) {
|
|
120
157
|
return vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Assignment) || vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.ExpressionList);
|
|
121
158
|
}
|
|
122
|
-
/** Whether one of the call's arguments is the value the reflective call handed out. */
|
|
123
|
-
function consumes(vertex, carrying) {
|
|
124
|
-
return argumentsOf(vertex).some(id => carrying.has(id));
|
|
125
|
-
}
|
|
126
159
|
/** The nodes a call was handed, whatever way the arguments were written. */
|
|
127
160
|
function argumentsOf(vertex) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (typeof argument === 'object' && 'nodeId' in argument) {
|
|
131
|
-
ids.push(argument.nodeId);
|
|
132
|
-
if (graph_1.FunctionArgument.isNamed(argument) && argument.valueId !== undefined) {
|
|
133
|
-
ids.push(argument.valueId);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return ids;
|
|
138
|
-
}
|
|
139
|
-
function isFixedName(node, graph) {
|
|
140
|
-
const vtx = graph.getVertex(node);
|
|
141
|
-
return vertex_1.DfgVertex.isValue(vtx) || (vertex_1.DfgVertex.isUse(vtx) && vtx.constantFallback === true);
|
|
142
|
-
}
|
|
143
|
-
function resolvedToAFormal(vertex, formals, graph) {
|
|
144
|
-
for (const node of [vertex.id, ...argumentsOf(vertex)]) {
|
|
145
|
-
if (node !== vertex.id && !isFixedName(node, graph)) {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (edgeTargets(graph, node, edge_1.EdgeType.Reads).some(to => formals.has(to))) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
161
|
+
return vertex.args.filter(graph_1.FunctionArgument.isNotEmpty)
|
|
162
|
+
.flatMap(a => graph_1.FunctionArgument.isNamed(a) && a.valueId !== undefined ? [a.nodeId, a.valueId] : [a.nodeId]);
|
|
153
163
|
}
|
|
154
164
|
//# sourceMappingURL=frame-reflection.js.map
|
|
@@ -24,13 +24,13 @@ function inferFunctions(definitions, graph, options = {}) {
|
|
|
24
24
|
const { ctx, only } = options;
|
|
25
25
|
const strict = (0, strict_function_1.strictnessOfEach)(definitions, graph, { ctx });
|
|
26
26
|
return {
|
|
27
|
-
props: only === 'arguments' ? {} : callProps(definitions, graph,
|
|
27
|
+
props: only === 'arguments' ? {} : callProps(definitions, { graph, info: (0, query_fn_props_1.builtInLookup)(ctx) }, strict),
|
|
28
28
|
roles: only === 'function' ? {} : argumentProps(definitions, graph, strict, options)
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
/** The {@link CallProp} mask of each definition, `Strict` included and what its callees carry mixed in. */
|
|
32
|
-
function callProps(definitions,
|
|
33
|
-
const
|
|
32
|
+
function callProps(definitions, state, strict) {
|
|
33
|
+
const { join, filter, hasAny } = function_semantics_1.FunctionSemantics.call.props;
|
|
34
34
|
const props = new Map();
|
|
35
35
|
const callees = new Map();
|
|
36
36
|
/* a callee is asked about as well, whether or not it is one of the definitions to answer for */
|
|
@@ -41,27 +41,15 @@ function callProps(definitions, graph, strict, ctx) {
|
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
43
|
const own = propsOf(id, state);
|
|
44
|
-
props.set(id, strict[id]?.strict === logic_1.Ternary.Always ?
|
|
44
|
+
props.set(id, strict[id]?.strict === logic_1.Ternary.Always ? join(own.stated, { props: built_in_props_1.CallProp.Strict }) : own.stated);
|
|
45
45
|
callees.set(id, own.callees);
|
|
46
46
|
toVisit.push(...own.callees);
|
|
47
47
|
}
|
|
48
|
-
propagateOverCalls(props, callees);
|
|
49
|
-
const all = {};
|
|
50
|
-
for (const id of definitions) {
|
|
51
|
-
const found = props.get(id);
|
|
52
|
-
if (function_semantics_1.FunctionSemantics.call.props.hasAny(found)) {
|
|
53
|
-
all[id] = found;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return all;
|
|
57
|
-
}
|
|
58
|
-
/** Hands {@link PropagatedProps} on to callers until nothing changes, so a chain of calls carries them however long it is. */
|
|
59
|
-
function propagateOverCalls(props, callees) {
|
|
60
48
|
(0, frame_reflection_1.propagateToFixpoint)(callees.keys(), callees, id => {
|
|
61
49
|
const before = props.get(id);
|
|
62
50
|
let grown = before ?? {};
|
|
63
51
|
for (const callee of callees.get(id) ?? []) {
|
|
64
|
-
grown =
|
|
52
|
+
grown = join(grown, filter(props.get(callee), built_in_props_1.PropagatedProps));
|
|
65
53
|
}
|
|
66
54
|
/* joining only ever adds, so nothing new means the same bits and the same number of tags */
|
|
67
55
|
if ((grown.props ?? 0) === (before?.props ?? 0) && (grown.tags?.length ?? 0) === (before?.tags?.length ?? 0)) {
|
|
@@ -70,6 +58,7 @@ function propagateOverCalls(props, callees) {
|
|
|
70
58
|
props.set(id, grown);
|
|
71
59
|
return true;
|
|
72
60
|
});
|
|
61
|
+
return Object.fromEntries(definitions.filter(id => hasAny(props.get(id))).map(id => [id, props.get(id)]));
|
|
73
62
|
}
|
|
74
63
|
/** The {@link ArgProp} mask of each formal, `Forced`/`Lazy` included. */
|
|
75
64
|
function argumentProps(definitions, graph, strict, options) {
|
|
@@ -88,10 +77,8 @@ function argumentProps(definitions, graph, strict, options) {
|
|
|
88
77
|
}
|
|
89
78
|
return all;
|
|
90
79
|
}
|
|
91
|
-
function makeState(graph, ctx) {
|
|
92
|
-
return { graph, info: (0, query_fn_props_1.builtInLookup)(ctx) };
|
|
93
|
-
}
|
|
94
80
|
function propsOf(id, state) {
|
|
81
|
+
const { join, filter } = function_semantics_1.FunctionSemantics.call.props;
|
|
95
82
|
const definition = state.graph.getVertex(id);
|
|
96
83
|
if (!vertex_1.DfgVertex.isFunctionDefinition(definition)) {
|
|
97
84
|
return { stated: {}, callees: [] };
|
|
@@ -100,25 +87,21 @@ function propsOf(id, state) {
|
|
|
100
87
|
const callees = [];
|
|
101
88
|
for (const [node, vertex] of (0, frame_reflection_1.callsIn)(definition, state.graph)) {
|
|
102
89
|
const info = state.info(vertex.name);
|
|
103
|
-
const carried =
|
|
104
|
-
stated =
|
|
90
|
+
const carried = filter(info, built_in_props_1.PropagatedProps);
|
|
91
|
+
stated = join(stated, {
|
|
105
92
|
props: (carried.props ?? 0) & (bindsOutside(vertex, info) ? ~0 : ~built_in_props_1.CallProp.Scope),
|
|
106
93
|
tags: carried.tags
|
|
107
94
|
});
|
|
108
95
|
if (built_in_props_1.DispatchCallees.has(identifier_1.Identifier.getName(vertex.name))) {
|
|
109
|
-
stated =
|
|
96
|
+
stated = join(stated, { props: built_in_props_1.CallProp.Generic });
|
|
110
97
|
}
|
|
111
|
-
callees.push(...calledDefinitions(
|
|
98
|
+
callees.push(...(0, frame_reflection_1.calledDefinitions)(state.graph, node));
|
|
112
99
|
}
|
|
113
100
|
if (returnsInvisibly(definition, state)) {
|
|
114
|
-
stated =
|
|
101
|
+
stated = join(stated, { props: built_in_props_1.CallProp.Invisible });
|
|
115
102
|
}
|
|
116
103
|
return { stated, callees };
|
|
117
104
|
}
|
|
118
|
-
/** The definitions of the program the call resolved to, which are the ones stating what the call does. */
|
|
119
|
-
function calledDefinitions(node, state) {
|
|
120
|
-
return (0, frame_reflection_1.edgeTargets)(state.graph, node, edge_1.EdgeType.Calls).filter(target => vertex_1.DfgVertex.isFunctionDefinition(state.graph.getVertex(target)));
|
|
121
|
-
}
|
|
122
105
|
/** the assignments binding in the frame they run in, which is a scope of the function's own */
|
|
123
106
|
const FrameLocalBinders = new Set(['<-', '=', '->', ':=', 'assign']);
|
|
124
107
|
/** Whether the name is a replacement function binding in its own frame (`names(x) <- v`); the `<<-` twin does not. */
|
|
@@ -131,17 +114,16 @@ function bindsOutside(vertex, info) {
|
|
|
131
114
|
if (!FrameLocalBinders.has(name) && !isFrameLocalReplacement(name)) {
|
|
132
115
|
return true;
|
|
133
116
|
}
|
|
134
|
-
|
|
135
|
-
return layout !== undefined && built_in_props_1.FnSig.posWith(layout, vertex.args.length, built_in_props_1.ArgProp.Written).length > 0;
|
|
117
|
+
return info?.sig !== undefined && built_in_props_1.FnSig.posWith(built_in_props_1.FnSig.layout(info.sig), vertex.args.length, built_in_props_1.ArgProp.Written).length > 0;
|
|
136
118
|
}
|
|
137
119
|
/** Whether every unconditional exit ends in a call returning invisibly; a bare value result (`function() 1`) never does. */
|
|
138
120
|
function returnsInvisibly(definition, state) {
|
|
139
121
|
const unconditional = definition.exitPoints.filter(e => (0, info_1.happensInEveryBranch)(e.cds)).map(e => e.nodeId);
|
|
140
|
-
return unconditional.length > 0 && unconditional.every(node => yieldsInvisibly(node, state
|
|
122
|
+
return unconditional.length > 0 && unconditional.every(node => yieldsInvisibly(node, state));
|
|
141
123
|
}
|
|
142
124
|
/** How far the result is followed through the blocks and `return`s wrapping it. */
|
|
143
125
|
const MaxDepth = 6;
|
|
144
|
-
function yieldsInvisibly(node, state, depth) {
|
|
126
|
+
function yieldsInvisibly(node, state, depth = 0) {
|
|
145
127
|
const vertex = state.graph.getVertex(node);
|
|
146
128
|
if (vertex_1.DfgVertex.isFunctionCall(vertex) && ((state.info(vertex.name)?.props ?? 0) & built_in_props_1.CallProp.Invisible) !== 0) {
|
|
147
129
|
return true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inferFunctions } from './function-props';
|
|
2
2
|
import { exceptionsOfFunction } from './exceptions-of-function';
|
|
3
|
-
import { strictnessOfEach } from './strict-function';
|
|
3
|
+
import { promiseDependencies, promiseForcing, settleJumpsInPromises, strictnessOfEach } from './strict-function';
|
|
4
4
|
import { isHigherOrder } from './higher-order-function';
|
|
5
5
|
import { argumentRolesOfFunctions } from './argument-roles';
|
|
6
6
|
import { reflectiveRolesOf } from './frame-reflection';
|
|
@@ -32,6 +32,12 @@ export declare const FunctionSemantics: {
|
|
|
32
32
|
readonly exceptions: typeof exceptionsOfFunction;
|
|
33
33
|
/** The strictness of several definitions, sharing the work between them. */
|
|
34
34
|
readonly strictness: typeof strictnessOfEach;
|
|
35
|
+
/** Settles what a jump within a promise does, once the calls are linked. */
|
|
36
|
+
readonly settleJumpsInPromises: typeof settleJumpsInPromises;
|
|
37
|
+
/** What a node within promises depends on for running at all. */
|
|
38
|
+
readonly promiseDependencies: typeof promiseDependencies;
|
|
39
|
+
/** How surely the holder of a promise forces it. */
|
|
40
|
+
readonly promiseForcing: typeof promiseForcing;
|
|
35
41
|
/** Whether one definition is higher-order, i.e. whether it calls what it is handed. */
|
|
36
42
|
readonly isHigherOrder: typeof isHigherOrder;
|
|
37
43
|
/** The roles of several definitions' formals, sharing the built-in lookups. */
|
|
@@ -64,6 +70,7 @@ export declare const FunctionSemantics: {
|
|
|
64
70
|
readonly propAt: (this: void, { props, rest }: import("../environments/built-in-props").SigLayout, index: number) => ArgProps;
|
|
65
71
|
readonly posWith: (this: void, layout: import("../environments/built-in-props").SigLayout, count: number, prop: ArgProps) => number[];
|
|
66
72
|
readonly forced: (this: void, sig: FnSig | undefined, count: number) => readonly boolean[] | undefined;
|
|
73
|
+
readonly forcing: (this: void, sig: FnSig | undefined, count: number) => readonly import("../../util/logic").Ternary[] | undefined;
|
|
67
74
|
readonly every: FnSig;
|
|
68
75
|
readonly only: (this: void, index: number, name: string) => FnSig;
|
|
69
76
|
};
|
|
@@ -97,14 +104,15 @@ export declare const FunctionSemantics: {
|
|
|
97
104
|
readonly quoted: {
|
|
98
105
|
readonly capturedBy: (this: void, graph: import("../..").DataflowGraph, id: import("../..").NodeId) => readonly import("../..").NodeId[];
|
|
99
106
|
readonly sourcesOf: (this: void, graph: import("../..").DataflowGraph, id: import("../..").NodeId) => readonly import("../internal/process/functions/call/quoted").CapturedExpression[];
|
|
107
|
+
readonly evaluationDependencies: (this: void, graph: import("../..").DataflowGraph, id: import("../..").NodeId) => import("../..").NodeId[];
|
|
100
108
|
readonly evaluateIn: typeof import("../internal/linker").linkExpressionIn;
|
|
101
109
|
readonly finalize: <Info>(this: void, graph: import("../..").DataflowGraph, environment: import("../environments/environment").REnvironmentInformation, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, controlFlow: () => import("../../control-flow/control-flow-graph").ControlFlowGraph | undefined) => void;
|
|
102
110
|
};
|
|
103
111
|
/** The ones it evaluates at a time flowR cannot pin down. */
|
|
104
112
|
readonly deferred: {
|
|
105
113
|
readonly indexOf: <Info>(this: void, graph: import("../..").DataflowGraph, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>) => import("../internal/process/functions/call/deferred").NameIndex;
|
|
106
|
-
readonly forcedAt: (this: void, graph: import("../..").DataflowGraph, binding: import("../..").NodeId, cfg: import("../../control-flow/control-flow-graph").ControlFlowGraph) => readonly import("../..").NodeId[];
|
|
107
|
-
readonly publish: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, at: import("../..").NodeId, cfg?: import("../../control-flow/control-flow-graph").ControlFlowGraph) => void;
|
|
114
|
+
readonly forcedAt: (this: void, graph: import("../..").DataflowGraph, binding: import("../..").NodeId, cfg: import("../../control-flow/control-flow-graph").ControlFlowGraph, viaClosures?: boolean) => readonly import("../..").NodeId[];
|
|
115
|
+
readonly publish: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, at: import("../..").NodeId, sites: readonly import("../..").NodeId[], cfg?: import("../../control-flow/control-flow-graph").ControlFlowGraph) => void;
|
|
108
116
|
readonly link: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, forces?: import("../internal/process/functions/call/deferred").ForceSites) => void;
|
|
109
117
|
};
|
|
110
118
|
/** The calls that change the environment in ways flowR cannot follow. */
|
|
@@ -40,6 +40,12 @@ exports.FunctionSemantics = {
|
|
|
40
40
|
exceptions: exceptions_of_function_1.exceptionsOfFunction,
|
|
41
41
|
/** The strictness of several definitions, sharing the work between them. */
|
|
42
42
|
strictness: strict_function_1.strictnessOfEach,
|
|
43
|
+
/** Settles what a jump within a promise does, once the calls are linked. */
|
|
44
|
+
settleJumpsInPromises: strict_function_1.settleJumpsInPromises,
|
|
45
|
+
/** What a node within promises depends on for running at all. */
|
|
46
|
+
promiseDependencies: strict_function_1.promiseDependencies,
|
|
47
|
+
/** How surely the holder of a promise forces it. */
|
|
48
|
+
promiseForcing: strict_function_1.promiseForcing,
|
|
43
49
|
/** Whether one definition is higher-order, i.e. whether it calls what it is handed. */
|
|
44
50
|
isHigherOrder: higher_order_function_1.isHigherOrder,
|
|
45
51
|
/** The roles of several definitions' formals, sharing the built-in lookups. */
|
|
@@ -29,19 +29,12 @@ function isAnyReturnAFunction(def, graph) {
|
|
|
29
29
|
if (vertex_1.DfgVertex.isFunctionDefinition(current)) {
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
for (const [t, e] of
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
/* a returned name is followed to what it holds, as `g <- function() 1; g` hands back that function */
|
|
40
|
-
if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns | edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy) && !node_id_1.NodeId.isBuiltIn(t)) {
|
|
41
|
-
const v = graph.getVertex(t);
|
|
42
|
-
if (v) {
|
|
43
|
-
workingQueue.push(v);
|
|
44
|
-
}
|
|
32
|
+
/* a call hands back what its callee returns, never the callee; a returned name is followed to what it holds */
|
|
33
|
+
const follow = vertex_1.DfgVertex.isFunctionCall(current) ? edge_1.EdgeType.Returns : edge_1.EdgeType.Returns | edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy;
|
|
34
|
+
for (const [t, e] of graph.edgesFrom(current.id)) {
|
|
35
|
+
const v = edge_1.DfEdge.includesType(e, follow) && !node_id_1.NodeId.isBuiltIn(t) ? graph.getVertex(t) : undefined;
|
|
36
|
+
if (v) {
|
|
37
|
+
workingQueue.push(v);
|
|
45
38
|
}
|
|
46
39
|
}
|
|
47
40
|
}
|
|
@@ -71,12 +64,15 @@ function definitionsBehind(id, graph) {
|
|
|
71
64
|
continue;
|
|
72
65
|
}
|
|
73
66
|
seen.add(current);
|
|
74
|
-
|
|
67
|
+
const vertex = graph.getVertex(current);
|
|
68
|
+
if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
|
|
75
69
|
found.add(current);
|
|
76
70
|
continue;
|
|
77
71
|
}
|
|
72
|
+
/* what a call reads beyond its arguments (state it depends on, writes it follows) is no value it hands back */
|
|
73
|
+
const isCall = vertex_1.DfgVertex.isFunctionCall(vertex);
|
|
78
74
|
for (const [t, e] of graph.edgesFrom(current)) {
|
|
79
|
-
if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns | edge_1.EdgeType.Reads
|
|
75
|
+
if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns | edge_1.EdgeType.DefinedBy) || (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Reads) && (!isCall || edge_1.DfEdge.includesType(e, edge_1.EdgeType.Argument)))) {
|
|
80
76
|
workingQueue.push(t);
|
|
81
77
|
}
|
|
82
78
|
}
|
|
@@ -90,7 +86,7 @@ function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph, facts) {
|
|
|
90
86
|
continue;
|
|
91
87
|
}
|
|
92
88
|
const caller = graph.getVertex(callerId);
|
|
93
|
-
if (!
|
|
89
|
+
if (!vertex_1.DfgVertex.isFunctionCall(caller)) {
|
|
94
90
|
continue;
|
|
95
91
|
}
|
|
96
92
|
for (const arg of caller.args) {
|
|
@@ -129,7 +125,7 @@ function callsAFormal(id, graph, ctx) {
|
|
|
129
125
|
*/
|
|
130
126
|
function isHigherOrder(id, graph, { ctx, invertedGraph, argumentFacts }) {
|
|
131
127
|
const vert = graph.getVertex(id);
|
|
132
|
-
if (!
|
|
128
|
+
if (!vertex_1.DfgVertex.isFunctionDefinition(vert)) {
|
|
133
129
|
return false;
|
|
134
130
|
}
|
|
135
131
|
return isAnyReturnAFunction(vert, graph) || callsAFormal(id, graph, ctx) || inspectCallSitesArgumentsFns(vert, graph, ctx, invertedGraph, argumentFacts);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @lintIgnore use-instead
|
|
5
5
|
*/
|
|
6
6
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
|
+
import type { ExitPoint } from '../info';
|
|
7
8
|
import type { DataflowGraph } from '../graph/graph';
|
|
8
9
|
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
|
|
9
10
|
import { Ternary } from '../../util/logic';
|
|
@@ -48,3 +49,15 @@ export interface FunctionStrictnessesOptions {
|
|
|
48
49
|
/** how to ask what a built-in states, so a configured or overwritten one answers */
|
|
49
50
|
readonly ctx?: ReadOnlyFlowrAnalyzerContext;
|
|
50
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* What a node within promises depends on to run: the holder of each `byPromise` dependency and where that promise may be forced.
|
|
54
|
+
* @example
|
|
55
|
+
* ```r
|
|
56
|
+
* g(print(1)) # the print runs only when `g` forces its argument, so it depends on `g(...)` and on the reads of `g`'s parameter
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function promiseDependencies(this: void, id: NodeId, graph: DataflowGraph): NodeId[];
|
|
60
|
+
/** How surely the holder of a promise forces it, asked for a node `inner` within the promise. */
|
|
61
|
+
export declare function promiseForcing(this: void, graph: DataflowGraph, { ctx }?: FunctionStrictnessesOptions): (holder: NodeId, inner: NodeId) => Ternary;
|
|
62
|
+
/** Drops the resume of a jump within a promise ({@link ControlFlow.promise}) once the linked holder surely forces it. */
|
|
63
|
+
export declare function settleJumpsInPromises(this: void, graph: DataflowGraph, topLevel: readonly ExitPoint[], { ctx }?: FunctionStrictnessesOptions): void;
|