@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,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.strictnessOfEach = strictnessOfEach;
|
|
4
|
+
exports.promiseDependencies = promiseDependencies;
|
|
5
|
+
exports.promiseForcing = promiseForcing;
|
|
6
|
+
exports.settleJumpsInPromises = settleJumpsInPromises;
|
|
4
7
|
/**
|
|
5
8
|
* The `FunctionSemantics` facade wires these together, so a sibling here has to call the backing function
|
|
6
9
|
* directly; going through `FunctionSemantics` would make `src/dataflow/fn/function-semantics.ts` import its own importers.
|
|
@@ -9,7 +12,11 @@ exports.strictnessOfEach = strictnessOfEach;
|
|
|
9
12
|
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
10
13
|
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
11
14
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
15
|
+
const info_1 = require("../info");
|
|
12
16
|
const edge_1 = require("../graph/edge");
|
|
17
|
+
const node_value_1 = require("../eval/resolve/node-value");
|
|
18
|
+
const resolve_helper_1 = require("../environments/resolve-helper");
|
|
19
|
+
const call_graph_1 = require("../graph/call-graph");
|
|
13
20
|
const vertex_1 = require("../graph/vertex");
|
|
14
21
|
const built_in_proc_name_1 = require("../environments/built-in-proc-name");
|
|
15
22
|
const built_in_props_1 = require("../environments/built-in-props");
|
|
@@ -20,6 +27,8 @@ const logic_1 = require("../../util/logic");
|
|
|
20
27
|
const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
21
28
|
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
22
29
|
const r_parameter_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
|
|
30
|
+
const assert_1 = require("../../util/assert");
|
|
31
|
+
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
23
32
|
/**
|
|
24
33
|
* What an argument is used for when the call never evaluates it: quoted or read in another frame
|
|
25
34
|
* ({@link ArgProp.Nse}), or looked at only for having been supplied ({@link ArgProp.Presence}).
|
|
@@ -38,9 +47,7 @@ const LazyAfterFirst = [built_in_proc_name_1.BuiltInProcName.Switch, built_in_pr
|
|
|
38
47
|
*/
|
|
39
48
|
const LazyThroughout = [built_in_proc_name_1.BuiltInProcName.RegisterHook, built_in_proc_name_1.BuiltInProcName.Recall];
|
|
40
49
|
/** The processors dispatching to a method chosen at run time. */
|
|
41
|
-
const DispatchProcessors = [
|
|
42
|
-
built_in_proc_name_1.BuiltInProcName.S3Dispatch, built_in_proc_name_1.BuiltInProcName.S3DispatchNext, built_in_proc_name_1.BuiltInProcName.S7Dispatch
|
|
43
|
-
];
|
|
50
|
+
const DispatchProcessors = [built_in_proc_name_1.BuiltInProcName.S3Dispatch, built_in_proc_name_1.BuiltInProcName.S3DispatchNext, built_in_proc_name_1.BuiltInProcName.S7Dispatch];
|
|
44
51
|
/**
|
|
45
52
|
* Whether the call hands the work to a method chosen at run time: flowR's own dispatch processors say so for
|
|
46
53
|
* `UseMethod` and `NextMethod`, and {@link DispatchCallees} covers the ones it has no processor for.
|
|
@@ -56,50 +63,66 @@ function hasProcessor(vertex, of) {
|
|
|
56
63
|
function enclosingDefinition(id, idMap, graph) {
|
|
57
64
|
return model_1.RNode.findEnclosing(id, idMap, node => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(node.info.id)));
|
|
58
65
|
}
|
|
59
|
-
|
|
66
|
+
/** The definitions whose body dispatches, with what each dispatch does with the arguments. */
|
|
67
|
+
function dispatchingDefinitions(graph) {
|
|
60
68
|
const idMap = graph.idMap;
|
|
69
|
+
const dispatch = new Map();
|
|
70
|
+
if (idMap === undefined) {
|
|
71
|
+
return dispatch;
|
|
72
|
+
}
|
|
73
|
+
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
74
|
+
if (!isDispatch(vertex) || typeof node_id_1.NodeId.normalize(id) !== 'number') {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const within = enclosingDefinition(id, idMap, graph);
|
|
78
|
+
if (within === undefined) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const node = idMap.get(id);
|
|
82
|
+
const known = dispatch.get(within);
|
|
83
|
+
dispatch.set(within, {
|
|
84
|
+
named: (r_function_call_1.RFunctionCall.is(node) && node.arguments.length > 1) || (known?.named ?? false),
|
|
85
|
+
certain: conditionsBeyond(vertex.cds, graph.getVertex(within)?.cds).length === 0 || (known?.certain ?? false),
|
|
86
|
+
next: [...known?.next ?? [], ...(0, frame_reflection_1.calledDefinitions)(graph, id).filter(t => t !== within)]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return dispatch;
|
|
90
|
+
}
|
|
91
|
+
/** The logical value the condition of an `if` holds wherever it is reached, `undefined` if it may differ. */
|
|
92
|
+
function branchOutcomes(graph, ctx) {
|
|
93
|
+
return (0, defaultmap_1.memoize)((ifCall) => {
|
|
94
|
+
const call = graph.getVertex(ifCall);
|
|
95
|
+
const isIf = vertex_1.DfgVertex.hasOrigin(call, built_in_proc_name_1.BuiltInProcName.IfThenElse) && vertex_1.DfgVertex.isFunctionCall(call);
|
|
96
|
+
const condition = isIf ? call.args[0] : r_function_call_1.EmptyArgument;
|
|
97
|
+
if (ctx === undefined || condition === r_function_call_1.EmptyArgument) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const values = node_value_1.NodeValue.setOf(condition.nodeId, resolve_helper_1.Resolve.info(graph, ctx))?.elements ?? [];
|
|
101
|
+
const outcomes = new Set(values.map(v => v.type === 'logical' && typeof v.value === 'boolean' ? v.value : undefined));
|
|
102
|
+
return outcomes.size === 1 ? [...outcomes][0] : undefined;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function makeState(graph, ctx) {
|
|
61
106
|
const owner = new Map();
|
|
62
107
|
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
63
108
|
for (const param of Object.keys(vertex.params)) {
|
|
64
109
|
owner.set(node_id_1.NodeId.normalize(param), id);
|
|
65
110
|
}
|
|
66
111
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
112
|
+
return {
|
|
113
|
+
graph,
|
|
114
|
+
idMap: graph.idMap,
|
|
115
|
+
owner,
|
|
116
|
+
dispatch: dispatchingDefinitions(graph),
|
|
117
|
+
fnInfo: (0, query_fn_props_1.builtInLookup)(ctx),
|
|
118
|
+
branches: branchOutcomes(graph, ctx),
|
|
119
|
+
untargeted: new Map(),
|
|
120
|
+
known: new Map(),
|
|
121
|
+
provisional: new Map(),
|
|
122
|
+
assumptions: new Map(),
|
|
123
|
+
asking: new Set(),
|
|
124
|
+
assumed: false
|
|
78
125
|
};
|
|
79
|
-
const dispatch = new Map();
|
|
80
|
-
if (idMap !== undefined) {
|
|
81
|
-
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
82
|
-
if (!isDispatch(vertex) || typeof node_id_1.NodeId.normalize(id) !== 'number') {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const within = enclosingDefinition(id, idMap, graph);
|
|
86
|
-
if (within === undefined) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const node = idMap.get(id);
|
|
90
|
-
const known = dispatch.get(within);
|
|
91
|
-
const named = (r_function_call_1.RFunctionCall.is(node) && (node.arguments?.length ?? 0) > 1) || (known?.named ?? false);
|
|
92
|
-
const certain = !underCondition(vertex.cds, graph.getVertex(within)?.cds) || (known?.certain ?? false);
|
|
93
|
-
const next = [...known?.next ?? []];
|
|
94
|
-
for (const [target, edge] of graph.edgesFrom(id)) {
|
|
95
|
-
if (target !== within && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(target))) {
|
|
96
|
-
next.push(target);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
dispatch.set(within, { named, certain, next });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return { graph, idMap, owner, dispatch, fnInfo, sigs: new Map(), props: name => fnInfo(name)?.sig, known: new Map(), provisional: new Map(), asking: new Set(), assumed: false };
|
|
103
126
|
}
|
|
104
127
|
/** What is certain becomes a possibility once something may intervene. */
|
|
105
128
|
function weaken(value) {
|
|
@@ -112,9 +135,9 @@ function agree(values) {
|
|
|
112
135
|
}
|
|
113
136
|
return values.every(v => v === values[0]) ? values[0] : logic_1.Ternary.Maybe;
|
|
114
137
|
}
|
|
115
|
-
/**
|
|
116
|
-
function
|
|
117
|
-
return cds
|
|
138
|
+
/** The control dependencies beyond the definition's own; a `byPromise` one is no condition here, the walk up asks its holder. */
|
|
139
|
+
function conditionsBeyond(cds, definition) {
|
|
140
|
+
return info_1.ControlDependency.minus(cds ?? [], definition ?? []).filter(c => c.byPromise !== true);
|
|
118
141
|
}
|
|
119
142
|
/**
|
|
120
143
|
* Built-ins force what they are given, and the ones that do not (`quote` and its relatives) leave no read of
|
|
@@ -141,50 +164,68 @@ function argumentIndex(call, child, idMap) {
|
|
|
141
164
|
return call.args.findIndex(arg => arg !== r_function_call_1.EmptyArgument && (arg.nodeId === child || arg.nodeId === value));
|
|
142
165
|
}
|
|
143
166
|
/** Whether the node is the function a call is of rather than something handed to it. */
|
|
144
|
-
function isCallee(call, child
|
|
145
|
-
|
|
146
|
-
if (!r_function_call_1.RFunctionCall.is(node)) {
|
|
167
|
+
function isCallee(call, child) {
|
|
168
|
+
if (!r_function_call_1.RFunctionCall.is(call)) {
|
|
147
169
|
return false;
|
|
148
170
|
}
|
|
149
|
-
return (r_function_call_1.RFunctionCall.isNamed(
|
|
171
|
+
return (r_function_call_1.RFunctionCall.isNamed(call) ? call.functionName.info.id : call.calledFunction.info.id) === child;
|
|
150
172
|
}
|
|
151
173
|
/**
|
|
152
174
|
* What flowR states the argument at `index` of the call is used for. A `...` covers every position from
|
|
153
175
|
* where it is declared, which {@link FunctionSemantics.call.signature.propAt} takes care of.
|
|
154
176
|
*/
|
|
155
177
|
function argProps(vertex, index, state) {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
if (sig === undefined && !state.sigs.has(name)) {
|
|
159
|
-
state.sigs.set(name, sig = state.props(vertex.name));
|
|
160
|
-
}
|
|
161
|
-
return sig === undefined || index < 0 ? 0 : built_in_props_1.FnSig.propAt(built_in_props_1.FnSig.layout(sig), index);
|
|
178
|
+
const sig = index < 0 ? undefined : state.fnInfo(vertex.name)?.sig;
|
|
179
|
+
return sig === undefined ? 0 : built_in_props_1.FnSig.propAt(built_in_props_1.FnSig.layout(sig), index);
|
|
162
180
|
}
|
|
163
181
|
/** The verdict a callee's parameter carries over to what is handed to it. */
|
|
164
182
|
function handedTo(param, state) {
|
|
165
183
|
const owner = state.owner.get(param);
|
|
166
184
|
return owner === undefined ? logic_1.Ternary.Maybe : strictnessOf(owner, state).parameters[param] ?? logic_1.Ternary.Maybe;
|
|
167
185
|
}
|
|
186
|
+
/** Whether the call reads a name from the program itself (a parameter, a variable) rather than a built-in. */
|
|
187
|
+
function readsProgramName(call, graph) {
|
|
188
|
+
for (const [target, edge] of graph.edgesFrom(call.id)) {
|
|
189
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && !edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument) && !node_id_1.NodeId.isBuiltIn(target)) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
/** The parameter at `index` of the definition, `undefined` if it is no definition or a `...` comes first. */
|
|
196
|
+
function parameterAt(definition, index, idMap, graph) {
|
|
197
|
+
const node = idMap.get(definition);
|
|
198
|
+
if (!vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(definition)) || !r_function_definition_1.RFunctionDefinition.is(node)) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const dotsBefore = node.parameters.slice(0, index + 1).some(r_parameter_1.RParameter.isDotDotDotDot);
|
|
202
|
+
return dotsBefore ? undefined : node.parameters[index]?.name.info.id;
|
|
203
|
+
}
|
|
204
|
+
/** The parameters an argument of `call` binds to, by position in each definition an unlinked call may reach, `undefined` if unknown. */
|
|
205
|
+
function boundParameters(call, argument, idMap, graph, origins) {
|
|
206
|
+
const sources = new Set([argument, argumentValue(argument, idMap)]);
|
|
207
|
+
const linked = [...sources].flatMap(from => (0, frame_reflection_1.edgeTargets)(graph, from, edge_1.EdgeType.DefinesOnCall));
|
|
208
|
+
if (linked.length > 0 || (0, frame_reflection_1.calledDefinitions)(graph, call.id).length > 0) {
|
|
209
|
+
return linked;
|
|
210
|
+
}
|
|
211
|
+
const index = argumentIndex(call, argument, idMap);
|
|
212
|
+
const arg = call.args[index];
|
|
213
|
+
if (index < 0 || arg === r_function_call_1.EmptyArgument || arg.name !== undefined || !readsProgramName(call, graph)) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
const found = origins?.get(call.id) ?? [...(0, call_graph_1.fallbackUntargetedCall)(call, graph)];
|
|
217
|
+
origins?.set(call.id, found);
|
|
218
|
+
const params = found.map(definition => parameterAt(definition, index, idMap, graph));
|
|
219
|
+
return params.length > 0 && params.every(assert_1.isNotUndefined) ? params : undefined;
|
|
220
|
+
}
|
|
168
221
|
/**
|
|
169
222
|
* Whether handing `argument` to `call` forces it. An argument the call passes on is forced exactly as the
|
|
170
223
|
* function receiving it forces the parameter it binds to; a call flowR cannot resolve, and one whose argument
|
|
171
224
|
* it cannot match to a parameter, leave the question open.
|
|
172
225
|
*/
|
|
173
226
|
function forcedByCallee(call, argument, idMap, state) {
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
if (!resolved) {
|
|
177
|
-
return logic_1.Ternary.Maybe;
|
|
178
|
-
}
|
|
179
|
-
const bound = [];
|
|
180
|
-
for (const from of new Set([argument, argumentValue(argument, idMap)])) {
|
|
181
|
-
for (const [target, edge] of state.graph.edgesFrom(from)) {
|
|
182
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinesOnCall)) {
|
|
183
|
-
bound.push(handedTo(target, state));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return bound.length === 0 ? logic_1.Ternary.Maybe : agree(bound);
|
|
227
|
+
const bound = boundParameters(call, argument, idMap, state.graph, state.untargeted);
|
|
228
|
+
return bound === undefined || bound.length === 0 ? logic_1.Ternary.Maybe : agree(bound.map(param => handedTo(param, state)));
|
|
188
229
|
}
|
|
189
230
|
/**
|
|
190
231
|
* How far the given read of a parameter is unavoidable: it has to stand under no condition the definition
|
|
@@ -194,73 +235,79 @@ function forcedByCallee(call, argument, idMap, state) {
|
|
|
194
235
|
function forces(read, definition, state) {
|
|
195
236
|
const idMap = state.idMap;
|
|
196
237
|
if (idMap === undefined) {
|
|
197
|
-
return logic_1.Ternary.Maybe;
|
|
238
|
+
return { value: logic_1.Ternary.Maybe };
|
|
198
239
|
}
|
|
199
|
-
|
|
240
|
+
/* the branches the read sits in, and whether anything else keeps it from being certain */
|
|
241
|
+
const conditions = [];
|
|
242
|
+
let lazy = false;
|
|
243
|
+
const verdict = (value) => ({
|
|
244
|
+
value: lazy || conditions.length > 0 ? weaken(value) : value,
|
|
245
|
+
onlyUnder: lazy || value !== logic_1.Ternary.Always ? undefined : conditions
|
|
246
|
+
});
|
|
200
247
|
let child = read;
|
|
201
248
|
let node = idMap.get(read);
|
|
202
249
|
while (node !== undefined && node.info.id !== definition.id) {
|
|
203
250
|
const vertex = state.graph.getVertex(node.info.id);
|
|
204
|
-
|
|
205
|
-
|
|
251
|
+
for (const cd of conditionsBeyond(vertex?.cds, definition.cds)) {
|
|
252
|
+
const holds = cd.when === undefined ? undefined : state.branches(cd.id);
|
|
253
|
+
if (holds === undefined) {
|
|
254
|
+
info_1.ControlDependency.append(conditions, [cd]);
|
|
255
|
+
}
|
|
256
|
+
else if (holds !== cd.when) {
|
|
257
|
+
return { value: logic_1.Ternary.Never };
|
|
258
|
+
}
|
|
206
259
|
}
|
|
207
260
|
if (node.info.id !== read) {
|
|
208
|
-
if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
|
|
209
|
-
/* nothing says
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
else if (r_parameter_1.RParameter.is(node)) {
|
|
213
|
-
/* a default is evaluated only when the argument is left out */
|
|
214
|
-
certain = false;
|
|
261
|
+
if (vertex_1.DfgVertex.isFunctionDefinition(vertex) || r_parameter_1.RParameter.is(node)) {
|
|
262
|
+
/* nothing says a nested definition is ever called, and a default is evaluated only when the argument is left out */
|
|
263
|
+
lazy = true;
|
|
215
264
|
}
|
|
216
|
-
else if (vertex_1.DfgVertex.isFunctionCall(vertex) && !isDispatch(vertex) && !isCallee(node
|
|
265
|
+
else if (vertex_1.DfgVertex.isFunctionCall(vertex) && !isDispatch(vertex) && !isCallee(node, child)) {
|
|
217
266
|
if (!isBuiltInCall(vertex)) {
|
|
218
|
-
|
|
219
|
-
return certain ? handed : weaken(handed);
|
|
267
|
+
return verdict(forcedByCallee(vertex, child, idMap, state));
|
|
220
268
|
}
|
|
221
269
|
const index = argumentIndex(vertex, child, idMap);
|
|
222
270
|
const props = argProps(vertex, index, state);
|
|
223
271
|
if ((props & NotEvaluated) !== 0) {
|
|
224
|
-
return logic_1.Ternary.Never;
|
|
272
|
+
return { value: logic_1.Ternary.Never };
|
|
225
273
|
}
|
|
226
274
|
else if ((props & built_in_props_1.ArgProp.Forced) === 0
|
|
227
275
|
&& (hasProcessor(vertex, LazyThroughout) || (index !== 0 && hasProcessor(vertex, LazyAfterFirst)))) {
|
|
228
|
-
|
|
276
|
+
lazy = true;
|
|
229
277
|
}
|
|
230
278
|
}
|
|
231
279
|
}
|
|
232
280
|
child = node.info.id;
|
|
233
281
|
node = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
|
|
234
282
|
}
|
|
235
|
-
|
|
236
|
-
return logic_1.Ternary.Never;
|
|
237
|
-
}
|
|
238
|
-
return certain ? logic_1.Ternary.Always : logic_1.Ternary.Maybe;
|
|
283
|
+
return node === undefined ? { value: logic_1.Ternary.Never } : verdict(logic_1.Ternary.Always);
|
|
239
284
|
}
|
|
240
285
|
function strictnessOfParameter(param, definition, state) {
|
|
241
286
|
const reads = [];
|
|
242
|
-
|
|
287
|
+
const branches = [];
|
|
288
|
+
for (const read of (0, frame_reflection_1.edgeSources)(state.graph, param, edge_1.EdgeType.Reads)) {
|
|
243
289
|
/* a `NextMethod` hands the parameter on unforced, the methods it reaches decide below */
|
|
244
|
-
if (
|
|
245
|
-
|
|
290
|
+
if (!vertex_1.DfgVertex.hasOrigin(state.graph.getVertex(read), built_in_proc_name_1.BuiltInProcName.S3DispatchNext)) {
|
|
291
|
+
const { value, onlyUnder = [] } = forces(read, definition, state);
|
|
292
|
+
reads.push(value);
|
|
293
|
+
branches.push(...onlyUnder);
|
|
246
294
|
}
|
|
247
295
|
}
|
|
296
|
+
if (info_1.ControlDependency.happensInEveryBranch(branches)) {
|
|
297
|
+
reads.push(logic_1.Ternary.Always);
|
|
298
|
+
}
|
|
248
299
|
const dispatch = state.dispatch.get(definition.id);
|
|
249
300
|
if (dispatch !== undefined) {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
methods.push(handedTo(target, state));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
reads.push(dispatch.certain ? agree(methods) : weaken(agree(methods)));
|
|
301
|
+
const surely = (values) => dispatch.certain ? agree(values) : weaken(agree(values));
|
|
302
|
+
const methods = (0, frame_reflection_1.edgeTargets)(state.graph, param, edge_1.EdgeType.DefinesOnCall).map(target => handedTo(target, state));
|
|
303
|
+
reads.push(surely(methods));
|
|
257
304
|
if (dispatch.next.length > 0) {
|
|
258
305
|
const at = parameterIds(definition.id, state.idMap).indexOf(param);
|
|
259
306
|
const along = at < 0 ? [] : dispatch.next.map(method => {
|
|
260
307
|
const same = parameterIds(method, state.idMap)[at];
|
|
261
|
-
return same === undefined ? logic_1.Ternary.Maybe :
|
|
308
|
+
return same === undefined ? logic_1.Ternary.Maybe : handedTo(same, state);
|
|
262
309
|
});
|
|
263
|
-
reads.push(
|
|
310
|
+
reads.push(surely(along));
|
|
264
311
|
}
|
|
265
312
|
}
|
|
266
313
|
return logic_1.TernaryLogic.or(...reads);
|
|
@@ -270,6 +317,8 @@ function parameterIds(definition, idMap) {
|
|
|
270
317
|
const node = idMap?.get(definition);
|
|
271
318
|
return r_function_definition_1.RFunctionDefinition.is(node) ? node.parameters.map(p => p.name.info.id) : [];
|
|
272
319
|
}
|
|
320
|
+
/** How many rounds a cycle of definitions gets to settle before all of them answer {@link Ternary#Maybe}. */
|
|
321
|
+
const MaxCycleRounds = 8;
|
|
273
322
|
function strictnessOf(id, state) {
|
|
274
323
|
const known = state.known.get(id) ?? state.provisional.get(id);
|
|
275
324
|
if (known !== undefined) {
|
|
@@ -281,37 +330,37 @@ function strictnessOf(id, state) {
|
|
|
281
330
|
}
|
|
282
331
|
const params = Object.keys(vertex.params);
|
|
283
332
|
if (state.asking.has(id)) {
|
|
284
|
-
/*
|
|
333
|
+
/* a cycle starts out assuming every parameter is forced: a run that keeps recursing never returns, so that claims nothing */
|
|
285
334
|
state.assumed = true;
|
|
286
|
-
return
|
|
335
|
+
return state.assumptions.get(id) ?? uniform(params, logic_1.Ternary.Always);
|
|
287
336
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
parameters[param] = strictnessOfParameter(node_id_1.NodeId.normalize(param), vertex, state);
|
|
337
|
+
let result = computeStrictness(id, vertex, params, state);
|
|
338
|
+
if (!state.assumed) {
|
|
339
|
+
state.known.set(id, result);
|
|
292
340
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
341
|
+
else if (state.asking.size === 0) {
|
|
342
|
+
/* the outermost question of a cycle: recompute it until a round is stable */
|
|
343
|
+
state.provisional.set(id, result);
|
|
344
|
+
let settled = false;
|
|
345
|
+
for (let round = 0; round < MaxCycleRounds && !settled; round++) {
|
|
346
|
+
state.assumptions = new Map(state.provisional);
|
|
347
|
+
state.provisional.clear();
|
|
348
|
+
state.assumed = false;
|
|
349
|
+
result = computeStrictness(id, vertex, params, state);
|
|
350
|
+
state.provisional.set(id, result);
|
|
351
|
+
settled = [...state.provisional].every(([other, r]) => sameStrictness(r, state.assumptions.get(other)));
|
|
297
352
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
353
|
+
if (settled) {
|
|
354
|
+
/* the fixpoint holds for the whole cycle, so none of it has to be worked out again */
|
|
355
|
+
for (const [other, r] of state.provisional) {
|
|
356
|
+
state.known.set(other, r);
|
|
357
|
+
}
|
|
303
358
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
parameters[object] = dispatch.certain ? logic_1.Ternary.Always : logic_1.TernaryLogic.or(parameters[object], logic_1.Ternary.Maybe);
|
|
359
|
+
else {
|
|
360
|
+
result = uniform(params, logic_1.Ternary.Maybe);
|
|
307
361
|
}
|
|
308
|
-
}
|
|
309
|
-
state.asking.delete(id);
|
|
310
|
-
const result = { strict: logic_1.TernaryLogic.and(...Object.values(parameters)), parameters };
|
|
311
|
-
if (!state.assumed) {
|
|
312
362
|
state.known.set(id, result);
|
|
313
|
-
|
|
314
|
-
else if (state.asking.size === 0) {
|
|
363
|
+
state.assumptions = new Map();
|
|
315
364
|
state.assumed = false;
|
|
316
365
|
state.provisional.clear();
|
|
317
366
|
}
|
|
@@ -320,6 +369,31 @@ function strictnessOf(id, state) {
|
|
|
320
369
|
}
|
|
321
370
|
return result;
|
|
322
371
|
}
|
|
372
|
+
function uniform(params, value) {
|
|
373
|
+
return { strict: value, parameters: Object.fromEntries(params.map(param => [param, value])) };
|
|
374
|
+
}
|
|
375
|
+
function sameStrictness(a, b) {
|
|
376
|
+
return b !== undefined && a.strict === b.strict && Object.entries(a.parameters).every(([param, value]) => b.parameters[param] === value);
|
|
377
|
+
}
|
|
378
|
+
function computeStrictness(id, vertex, params, state) {
|
|
379
|
+
state.asking.add(id);
|
|
380
|
+
const dispatch = state.dispatch.get(id);
|
|
381
|
+
/* a dispatch, or reflection flowR could not follow, may read a parameter without any read of it showing in the code */
|
|
382
|
+
const reflective = ((0, frame_reflection_1.reflectiveRolesOf)(vertex, state.graph, { known: state.fnInfo }) & MayEvaluate) !== 0;
|
|
383
|
+
const open = dispatch !== undefined || reflective;
|
|
384
|
+
const parameters = {};
|
|
385
|
+
for (const param of params) {
|
|
386
|
+
const own = strictnessOfParameter(node_id_1.NodeId.normalize(param), vertex, state);
|
|
387
|
+
parameters[param] = open ? logic_1.TernaryLogic.or(own, logic_1.Ternary.Maybe) : own;
|
|
388
|
+
}
|
|
389
|
+
/* the object a certain dispatch is on is forced by the dispatch itself */
|
|
390
|
+
const object = dispatch?.certain && !dispatch.named ? parameterIds(id, state.idMap)[0] : undefined;
|
|
391
|
+
if (object !== undefined && parameters[object] !== undefined) {
|
|
392
|
+
parameters[object] = logic_1.Ternary.Always;
|
|
393
|
+
}
|
|
394
|
+
state.asking.delete(id);
|
|
395
|
+
return { strict: logic_1.TernaryLogic.and(...Object.values(parameters)), parameters };
|
|
396
|
+
}
|
|
323
397
|
/**
|
|
324
398
|
* Determines whether the function with the given id is strict, i.e., whether calling it forces its arguments.
|
|
325
399
|
* {@link Ternary#Always} says every call forces every parameter, {@link Ternary#Never} that no call forces
|
|
@@ -353,4 +427,93 @@ function strictnessOfEach(ids, graph, { ctx } = {}) {
|
|
|
353
427
|
}
|
|
354
428
|
return result;
|
|
355
429
|
}
|
|
430
|
+
/** Where the promises bound to `params` may be forced: their reads, calls of closures capturing them, and the callees they are handed to. */
|
|
431
|
+
function forcingPointsOf(params, graph, idMap, seen = new Set()) {
|
|
432
|
+
const found = [];
|
|
433
|
+
for (const param of params) {
|
|
434
|
+
if (seen.has(param)) {
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
seen.add(param);
|
|
438
|
+
const owner = idMap.get(idMap.get(param)?.info.parent ?? -1)?.info.parent;
|
|
439
|
+
for (const read of (0, frame_reflection_1.edgeSources)(graph, param, edge_1.EdgeType.Reads)) {
|
|
440
|
+
found.push(read);
|
|
441
|
+
let closure = model_1.RNode.findEnclosing(read, idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
442
|
+
while (closure !== undefined && closure !== owner) {
|
|
443
|
+
found.push(...(0, frame_reflection_1.edgeSources)(graph, closure, edge_1.EdgeType.Calls));
|
|
444
|
+
closure = model_1.RNode.strictlyEnclosingFunction(closure, idMap);
|
|
445
|
+
}
|
|
446
|
+
/* a read that is an argument hands the promise on */
|
|
447
|
+
for (const holder of (0, frame_reflection_1.edgeSources)(graph, read, edge_1.EdgeType.Argument)) {
|
|
448
|
+
const call = graph.getVertex(holder);
|
|
449
|
+
if (vertex_1.DfgVertex.isFunctionCall(call) && !isBuiltInCall(call)) {
|
|
450
|
+
const bound = boundParameters(call, read, idMap, graph) ?? [];
|
|
451
|
+
found.push(holder, ...forcingPointsOf(bound, graph, idMap, seen));
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return found;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* What a node within promises depends on to run: the holder of each `byPromise` dependency and where that promise may be forced.
|
|
460
|
+
* @example
|
|
461
|
+
* ```r
|
|
462
|
+
* 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
|
|
463
|
+
* ```
|
|
464
|
+
*/
|
|
465
|
+
function promiseDependencies(id, graph) {
|
|
466
|
+
const idMap = graph.idMap;
|
|
467
|
+
const found = [];
|
|
468
|
+
if (idMap === undefined) {
|
|
469
|
+
return found;
|
|
470
|
+
}
|
|
471
|
+
for (const cd of graph.getVertex(id)?.cds ?? []) {
|
|
472
|
+
if (cd.byPromise !== true) {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const call = graph.getVertex(cd.id);
|
|
476
|
+
if (vertex_1.DfgVertex.isFunctionCall(call)) {
|
|
477
|
+
const argument = model_1.RNode.findEnclosing(id, idMap, n => n.info.parent === cd.id);
|
|
478
|
+
const bound = argument === undefined ? [] : boundParameters(call, argument, idMap, graph) ?? [];
|
|
479
|
+
found.push(cd.id, ...forcingPointsOf(bound, graph, idMap));
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
found.push(...forcingPointsOf([cd.id], graph, idMap));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return found;
|
|
486
|
+
}
|
|
487
|
+
/** How surely the holder of a promise forces it, asked for a node `inner` within the promise. */
|
|
488
|
+
function promiseForcing(graph, { ctx } = {}) {
|
|
489
|
+
const idMap = graph.idMap;
|
|
490
|
+
let state = undefined;
|
|
491
|
+
return (holder, inner) => {
|
|
492
|
+
if (idMap === undefined) {
|
|
493
|
+
return logic_1.Ternary.Maybe;
|
|
494
|
+
}
|
|
495
|
+
state ??= makeState(graph, ctx);
|
|
496
|
+
if (state.owner.has(holder)) {
|
|
497
|
+
return handedTo(holder, state);
|
|
498
|
+
}
|
|
499
|
+
const call = graph.getVertex(holder);
|
|
500
|
+
if (!vertex_1.DfgVertex.isFunctionCall(call) || isBuiltInCall(call)) {
|
|
501
|
+
return logic_1.Ternary.Maybe;
|
|
502
|
+
}
|
|
503
|
+
const argument = model_1.RNode.findEnclosing(inner, idMap, n => n.info.parent === holder);
|
|
504
|
+
return argument === undefined ? logic_1.Ternary.Maybe : forcedByCallee(call, argument, idMap, state);
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/** Drops the resume of a jump within a promise ({@link ControlFlow.promise}) once the linked holder surely forces it. */
|
|
508
|
+
function settleJumpsInPromises(graph, topLevel, { ctx } = {}) {
|
|
509
|
+
const forcing = promiseForcing(graph, { ctx });
|
|
510
|
+
const definitions = graph.verticesOfType(vertex_1.VertexType.FunctionDefinition).map(([, definition]) => definition.exitPoints);
|
|
511
|
+
for (const exit of [topLevel, ...definitions].flat()) {
|
|
512
|
+
for (const cd of exit.cds ?? []) {
|
|
513
|
+
if (cd.byPromise === true && forcing(cd.id, exit.nodeId) === logic_1.Ternary.Always) {
|
|
514
|
+
graph.removeEdgeType(exit.nodeId, cd.id, edge_1.EdgeType.FlowEdge);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
356
519
|
//# sourceMappingURL=strict-function.js.map
|
|
@@ -14,6 +14,11 @@ export interface State {
|
|
|
14
14
|
visited: Set<NodeId>;
|
|
15
15
|
potentials: [NodeId, Set<NodeId>][];
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The origins of what a call flowR found no target for calls, following its name back through reads and
|
|
19
|
+
* parameter bindings: `f(x)` within `apply_f <- function(f, x) f(x)` ends at what callers hand in as `f`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function fallbackUntargetedCall(vtx: Pick<DataflowGraphVertexFunctionCall, 'id'>, graph: DataflowGraph): Set<NodeId>;
|
|
17
22
|
/**
|
|
18
23
|
* Helper object for call-graphs, you can compute new call graphs based on {@link CallGraph.compute}.
|
|
19
24
|
* @helper dataflow
|
|
@@ -22,9 +27,7 @@ export interface State {
|
|
|
22
27
|
*/
|
|
23
28
|
export declare const CallGraph: {
|
|
24
29
|
readonly name: "CallGraph";
|
|
25
|
-
/**
|
|
26
|
-
* Extracts the sub call graph from the given call graph, starting from the given entry points.
|
|
27
|
-
*/
|
|
30
|
+
/** Extracts the sub call graph from the given call graph, starting from the given entry points. */
|
|
28
31
|
readonly computeSubCallGraph: (this: void, graph: CallGraph, entryPoints: Set<NodeId>) => CallGraph;
|
|
29
32
|
/** The calls the program makes on its own: those outside of any function definition. */
|
|
30
33
|
readonly entryPoints: (this: void, graph: CallGraph) => Set<NodeId>;
|
|
@@ -33,9 +36,7 @@ export declare const CallGraph: {
|
|
|
33
36
|
* What {@link mayRunAnyway} may still run is left out, so a call reported here really does not run.
|
|
34
37
|
*/
|
|
35
38
|
readonly unreachableCalls: (this: void, graph: CallGraph) => NodeId[];
|
|
36
|
-
/**
|
|
37
|
-
* Reduces the call graph by dropping all transitive edges.
|
|
38
|
-
*/
|
|
39
|
+
/** Reduces the call graph by dropping all transitive edges. */
|
|
39
40
|
readonly dropTransitiveEdges: (this: void, graph: CallGraph) => CallGraph;
|
|
40
41
|
/**
|
|
41
42
|
* Computes the call graph from the given dataflow graph.
|