@eagleoutice/flowr 2.15.9 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -41
- package/abstract-interpretation/absint-inference.d.ts +2 -2
- package/abstract-interpretation/absint-inference.js +32 -79
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/benchmark/slicer.d.ts +0 -1
- package/benchmark/slicer.js +1 -2
- package/cli/repl/commands/repl-signature.js +12 -3
- package/config.d.ts +5 -1
- package/control-flow/cfg-properties.js +0 -22
- package/control-flow/happens-before.d.ts +7 -2
- package/control-flow/happens-before.js +55 -31
- package/control-flow/useless-loop.d.ts +1 -1
- package/control-flow/useless-loop.js +29 -42
- package/dataflow/environments/apply-kill.js +6 -2
- package/dataflow/environments/built-in-config.d.ts +2 -0
- package/dataflow/environments/built-in-props.d.ts +16 -1
- package/dataflow/environments/built-in-props.js +33 -20
- package/dataflow/environments/built-in.d.ts +8 -3
- package/dataflow/environments/built-in.js +52 -82
- package/dataflow/environments/default-builtin-config.d.ts +551 -21
- package/dataflow/environments/default-builtin-config.js +121 -45
- package/dataflow/environments/define.d.ts +3 -2
- package/dataflow/environments/define.js +4 -3
- package/dataflow/environments/deprecation-info.d.ts +45 -0
- package/dataflow/environments/deprecation-info.js +13 -0
- package/dataflow/environments/environment.d.ts +7 -5
- package/dataflow/environments/environment.js +55 -121
- package/dataflow/environments/identifier.d.ts +6 -2
- package/dataflow/environments/identifier.js +23 -69
- package/dataflow/environments/reference-to-maybe.d.ts +9 -0
- package/dataflow/environments/reference-to-maybe.js +23 -51
- package/dataflow/environments/resolve-by-name.js +37 -76
- package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
- package/dataflow/eval/resolve/resolve-argument.js +61 -64
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
- package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
- package/dataflow/eval/resolve/resolve.d.ts +4 -0
- package/dataflow/eval/resolve/resolve.js +23 -14
- package/dataflow/extractor.js +180 -58
- package/dataflow/fn/class-declaration.d.ts +8 -13
- package/dataflow/fn/class-declaration.js +95 -116
- package/dataflow/fn/exceptions-of-function.js +68 -37
- package/dataflow/fn/frame-reflection.d.ts +12 -4
- package/dataflow/fn/frame-reflection.js +51 -41
- package/dataflow/fn/function-props.js +15 -33
- package/dataflow/fn/function-semantics.d.ts +11 -3
- package/dataflow/fn/function-semantics.js +6 -0
- package/dataflow/fn/higher-order-function.d.ts +9 -1
- package/dataflow/fn/higher-order-function.js +27 -24
- package/dataflow/fn/strict-function.d.ts +13 -0
- package/dataflow/fn/strict-function.js +291 -123
- package/dataflow/graph/call-graph.d.ts +7 -6
- package/dataflow/graph/call-graph.js +35 -46
- package/dataflow/graph/graph.d.ts +13 -1
- package/dataflow/graph/graph.js +74 -66
- package/dataflow/graph/vertex.d.ts +1 -1
- package/dataflow/info.d.ts +8 -1
- package/dataflow/info.js +24 -30
- package/dataflow/internal/control-flow.d.ts +31 -4
- package/dataflow/internal/control-flow.js +61 -39
- package/dataflow/internal/linker.d.ts +17 -8
- package/dataflow/internal/linker.js +286 -213
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
- package/dataflow/internal/process/functions/call/common.d.ts +4 -4
- package/dataflow/internal/process/functions/call/common.js +49 -71
- package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
- package/dataflow/internal/process/functions/call/deferred.js +81 -63
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
- package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +257 -154
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
- package/dataflow/internal/process/functions/process-parameter.js +25 -32
- package/dataflow/internal/process/process-symbol.js +4 -3
- package/dataflow/internal/program-order.d.ts +26 -0
- package/dataflow/internal/program-order.js +49 -0
- package/documentation/data/faq/faqs.js +3 -3
- package/documentation/data/interface/doc-writing-code.js +1 -2
- package/documentation/data/server/doc-data-server-messages.js +7 -7
- package/documentation/doc-capabilities.js +80 -34
- package/documentation/doc-util/doc-query.d.ts +0 -3
- package/documentation/doc-util/doc-query.js +4 -3
- package/documentation/wiki-analyzer.js +1 -1
- package/documentation/wiki-cfg.js +5 -6
- package/documentation/wiki-core.js +8 -8
- package/documentation/wiki-dataflow-graph.js +10 -11
- package/documentation/wiki-interface.js +2 -2
- package/documentation/wiki-linting-and-testing.js +3 -3
- package/documentation/wiki-overview.js +6 -6
- package/documentation/wiki-query.js +9 -101
- package/documentation/wiki-setup.js +23 -0
- package/documentation/wiki-signature-database.js +1 -1
- package/linter/linter-rules.d.ts +18 -9
- package/linter/rules/absolute-path.js +63 -87
- package/linter/rules/deprecated-functions.d.ts +1 -45
- package/linter/rules/deprecated-functions.js +24 -33
- package/linter/rules/file-path-validity.d.ts +4 -2
- package/linter/rules/file-path-validity.js +114 -80
- package/linter/rules/namespace-access.js +21 -33
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +60 -48
- package/linter/rules/network-functions.js +11 -7
- package/linter/rules/no-leaked-credentials.js +15 -18
- package/linter/rules/problematic-inputs.d.ts +2 -1
- package/linter/rules/problematic-inputs.js +39 -59
- package/linter/rules/roxygen-arguments.d.ts +9 -4
- package/linter/rules/roxygen-arguments.js +29 -48
- package/linter/rules/seeded-randomness.d.ts +7 -4
- package/linter/rules/seeded-randomness.js +128 -89
- package/linter/rules/stop-with-call-arg.d.ts +4 -2
- package/linter/rules/stop-with-call-arg.js +25 -22
- package/linter/rules/unclosed-connection.js +31 -24
- package/linter/rules/undefined-symbol.d.ts +4 -6
- package/linter/rules/undefined-symbol.js +58 -75
- package/linter/rules/unescaped-arguments.js +18 -44
- package/linter/rules/unused-definition.d.ts +6 -0
- package/linter/rules/unused-definition.js +105 -145
- package/linter/rules/unused-import.d.ts +3 -0
- package/linter/rules/unused-import.js +25 -43
- package/package.json +5 -2
- package/project/flowr-analyzer.d.ts +2 -0
- package/project/flowr-analyzer.js +28 -1
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
- package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
- package/project/sigdb/build.js +4 -0
- package/project/sigdb/manifest.d.ts +2 -0
- package/project/sigdb/manifest.js +10 -1
- package/project/sigdb/reader.js +23 -61
- package/project/sigdb/sigdb-download.d.ts +29 -6
- package/project/sigdb/sigdb-download.js +212 -64
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
- package/queries/catalog/call-context-query/cascade-action.js +2 -0
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
- package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
- package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
- package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
- package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
- package/queries/catalog/origin-query/origin-query-executor.js +2 -2
- package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
- package/queries/catalog/origin-query/origin-query-format.js +1 -1
- package/queries/query.d.ts +1 -1
- package/r-bridge/data/data.d.ts +21 -14
- package/r-bridge/data/data.js +28 -20
- package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
- package/r-bridge/lang-4.x/ast/model/model.js +19 -43
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
- package/r-bridge/roxygen2/roxygen-parse.js +28 -42
- package/r-bridge/shell.js +6 -0
- package/search/search-executor/search-enrichers.js +25 -37
- package/slicing/static/slice-call.d.ts +4 -3
- package/slicing/static/slice-call.js +56 -88
- package/slicing/static/static-slicer.js +115 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/files.d.ts +2 -0
- package/util/files.js +3 -1
- package/util/mermaid/mermaid.js +6 -2
- package/util/proc.js +2 -1
- package/util/r-base-packages.d.ts +2 -0
- package/util/r-base-packages.js +23 -13
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Quoted = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `FunctionSemantics.call` is the entry point these members are reached through, and it is built on this file, so the backing
|
|
6
|
+
* functions are called directly here; going through `FunctionSemantics` would make `src/dataflow/fn/function-semantics.ts` import its own
|
|
7
|
+
* importers.
|
|
8
|
+
* @lintIgnore use-instead
|
|
9
|
+
*/
|
|
10
|
+
const model_1 = require("../../../../../r-bridge/lang-4.x/ast/model/model");
|
|
4
11
|
const r_function_call_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
12
|
+
const match_args_1 = require("../../../../graph/match-args");
|
|
5
13
|
const node_id_1 = require("../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
6
14
|
const identifier_1 = require("../../../../environments/identifier");
|
|
15
|
+
const resolve_helper_1 = require("../../../../environments/resolve-helper");
|
|
16
|
+
const program_order_1 = require("../../../program-order");
|
|
17
|
+
const r_symbol_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
7
18
|
const built_in_proc_name_1 = require("../../../../environments/built-in-proc-name");
|
|
8
19
|
const edge_1 = require("../../../../graph/edge");
|
|
9
20
|
const df_helper_1 = require("../../../../graph/df-helper");
|
|
@@ -13,19 +24,16 @@ const linker_1 = require("../../../linker");
|
|
|
13
24
|
const nse_1 = require("./nse");
|
|
14
25
|
const deferred_1 = require("./deferred");
|
|
15
26
|
const r_argument_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
16
|
-
const retriever_1 = require("../../../../../r-bridge/retriever");
|
|
17
27
|
const happens_before_1 = require("../../../../../control-flow/happens-before");
|
|
18
|
-
const logic_1 = require("../../../../../util/logic");
|
|
19
28
|
const query_fn_props_1 = require("../../../../environments/query-fn-props");
|
|
20
29
|
const built_in_props_1 = require("../../../../environments/built-in-props");
|
|
21
|
-
|
|
22
|
-
const
|
|
30
|
+
const frame_reflection_1 = require("../../../../fn/frame-reflection");
|
|
31
|
+
const defaultmap_1 = require("../../../../../util/collections/defaultmap");
|
|
23
32
|
/** Calls whose result is a language object although they read their arguments like any other call. */
|
|
24
33
|
const CapturingCalls = new Set(['expression']);
|
|
25
34
|
/** Calls capturing an expression as a promise, forced at some later read of the variable they bind. */
|
|
26
35
|
const DelayingCalls = new Set(['delayedAssign']);
|
|
27
|
-
|
|
28
|
-
const EvaluatingProcessors = [built_in_proc_name_1.BuiltInProcName.Eval];
|
|
36
|
+
const DelayedAssignFormals = ['x', 'value', 'eval.env', 'assign.env'];
|
|
29
37
|
/** Calls evaluating their own unevaluated argument, in a frame of their own. */
|
|
30
38
|
const EvaluatingElsewhereCalls = new Set(['evalq']);
|
|
31
39
|
/**
|
|
@@ -33,9 +41,6 @@ const EvaluatingElsewhereCalls = new Set(['evalq']);
|
|
|
33
41
|
* counts because a call handing back one of them, a container included, must not hide the capture inside.
|
|
34
42
|
*/
|
|
35
43
|
const ValueFlow = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument;
|
|
36
|
-
function hasOrigin(vertex, of) {
|
|
37
|
-
return Array.isArray(vertex.origin) && vertex.origin.some(o => of.includes(o));
|
|
38
|
-
}
|
|
39
44
|
/**
|
|
40
45
|
* A language object reads nothing where it is written and everything where it reaches `eval`, with the bindings
|
|
41
46
|
* in effect there. Working on the finished graph makes assignments, branches, loops, and calls one traversal.
|
|
@@ -52,13 +57,8 @@ exports.Quoted = {
|
|
|
52
57
|
if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
53
58
|
return [];
|
|
54
59
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
else if (CapturingCalls.has(identifier_1.Identifier.getName(vertex.name))) {
|
|
59
|
-
return capturedArgumentsOf(graph, id, false);
|
|
60
|
-
}
|
|
61
|
-
return [];
|
|
60
|
+
const marked = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Quote);
|
|
61
|
+
return marked || CapturingCalls.has(identifier_1.Identifier.getName(vertex.name)) ? capturedArgumentsOf(graph, id, marked) : [];
|
|
62
62
|
},
|
|
63
63
|
/** Every expression the value at `id` may hold, with the call that captured it. Several is normal. */
|
|
64
64
|
sourcesOf(graph, id) {
|
|
@@ -72,6 +72,18 @@ exports.Quoted = {
|
|
|
72
72
|
} });
|
|
73
73
|
return found;
|
|
74
74
|
},
|
|
75
|
+
/** What `id` within captured code needs to run at all: the capturing call and every call evaluating it (`eval`, `body(f) <- quote(...)`). */
|
|
76
|
+
evaluationDependencies(graph, id) {
|
|
77
|
+
const idMap = graph.idMap;
|
|
78
|
+
for (let parent = idMap?.get(id)?.info.parent; parent !== undefined; parent = idMap?.get(parent)?.info.parent) {
|
|
79
|
+
const captured = exports.Quoted.capturedBy(graph, parent);
|
|
80
|
+
if (captured.length > 0) {
|
|
81
|
+
const evaluating = captured.flatMap(expr => (0, frame_reflection_1.edgeSources)(graph, expr, edge_1.EdgeType.Returns | edge_1.EdgeType.Reads | edge_1.EdgeType.Calls));
|
|
82
|
+
return [parent, ...evaluating.filter(from => from !== parent)];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [];
|
|
86
|
+
},
|
|
75
87
|
/** Links every name in `expr` against `environment` and hands back what stays unresolved. */
|
|
76
88
|
evaluateIn: linker_1.linkExpressionIn,
|
|
77
89
|
/**
|
|
@@ -80,94 +92,135 @@ exports.Quoted = {
|
|
|
80
92
|
* forced against, and a masked name the caller binds after all loses its mark.
|
|
81
93
|
*/
|
|
82
94
|
finalize(graph, environment, idMap, controlFlow) {
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
/* lets the forces of a parameter be reused without counting its reads again while nothing touched them (see `forcesOf`) */
|
|
96
|
+
graph.trackIncomingReads(true);
|
|
97
|
+
let names;
|
|
98
|
+
const namesOnce = () => names ??= deferred_1.Deferred.indexOf(graph, idMap);
|
|
99
|
+
let bindings;
|
|
85
100
|
let cfg = null;
|
|
86
101
|
const cfgOnce = () => (cfg === null ? (cfg = controlFlow()) : cfg);
|
|
87
102
|
const masking = [];
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let installers
|
|
103
|
+
const evaluated = [];
|
|
104
|
+
let sideEffects;
|
|
105
|
+
let installers;
|
|
91
106
|
const installersOnce = () => installers ??= languageInstallersOf(graph, environment);
|
|
107
|
+
/* every call of a function forces its parameters at the same sites, so this pass works them out once */
|
|
108
|
+
const forcing = new Map();
|
|
109
|
+
/* evaluations within one function and forces of one parameter share their sites, and with them what reaches them */
|
|
110
|
+
const reaches = new defaultmap_1.DefaultMap(() => ({}));
|
|
111
|
+
const reachOf = (sites) => reaches.get(sites.join('\0'));
|
|
112
|
+
let enclosing;
|
|
92
113
|
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
93
114
|
const masks = nse_1.Nse.dropResolvedMask(graph, id, vertex.name);
|
|
94
115
|
if (masks !== undefined) {
|
|
95
116
|
masking.push(masks);
|
|
96
117
|
}
|
|
97
118
|
for (const installed of installedLanguageOf(graph, id, installersOnce)) {
|
|
98
|
-
|
|
99
|
-
deferred_1.Deferred.link(graph, installed, names, idMap);
|
|
119
|
+
deferred_1.Deferred.link(graph, installed, namesOnce(), idMap);
|
|
100
120
|
graph.addEdge(id, installed, edge_1.EdgeType.Returns);
|
|
101
121
|
}
|
|
102
122
|
if (DelayingCalls.has(identifier_1.Identifier.getName(vertex.name))) {
|
|
103
123
|
const promise = capturedArgumentsOf(graph, id, true)[0];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
124
|
+
if (promise === undefined) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const promised = namesOnce();
|
|
128
|
+
const binding = boundBy(graph, id);
|
|
129
|
+
const flow = binding === undefined ? undefined : cfgOnce();
|
|
130
|
+
const sites = flow === undefined || binding === undefined ? undefined : deferred_1.Deferred.forcedAt(graph, binding, flow, true);
|
|
131
|
+
/* the promise runs in `eval.env`, so whatever that environment holds may be what it reads */
|
|
132
|
+
const call = idMap.get(id);
|
|
133
|
+
const evalEnv = r_function_call_1.RFunctionCall.is(call) ? match_args_1.MatchArgs.toNames(call.arguments, DelayedAssignFormals).get('eval.env')?.value : undefined;
|
|
134
|
+
const tracked = trackedEnvOf(vertex, evalEnv);
|
|
135
|
+
/* a tracked `eval.env` that binds every name the promise reads leaves no other binding in play, its writes still reach later reads */
|
|
136
|
+
const bound = tracked !== undefined && exports.Quoted.evaluateIn(graph, promise, tracked, idMap).length === 0;
|
|
137
|
+
const candidates = bound ? { definitions: new Map(), uses: promised.uses } : promised;
|
|
138
|
+
const forces = flow !== undefined && sites?.length && binding !== undefined ? { cfg: flow, sites, binding } : undefined;
|
|
139
|
+
deferred_1.Deferred.link(graph, promise, candidates, idMap, forces);
|
|
140
|
+
if (binding !== undefined) {
|
|
141
|
+
linkForcesToPromise(graph, binding, promise);
|
|
142
|
+
}
|
|
143
|
+
if (evalEnv !== undefined) {
|
|
144
|
+
graph.addEdge(promise, evalEnv.info.id, edge_1.EdgeType.Reads);
|
|
113
145
|
}
|
|
114
146
|
}
|
|
115
|
-
else if (hasOrigin(vertex,
|
|
116
|
-
|
|
117
|
-
bindings ??=
|
|
118
|
-
resolveEvaluation(graph, vertex, idMap, names, bindings, cfgOnce());
|
|
147
|
+
else if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Eval) || EvaluatingElsewhereCalls.has(identifier_1.Identifier.getName(vertex.name))) {
|
|
148
|
+
bindings ??= (0, deferred_1.verticesByName)(graph, vertex_1.VertexType.VariableDefinition, idMap);
|
|
149
|
+
resolveEvaluation(graph, vertex, idMap, namesOnce(), bindings, cfgOnce(), reachOf, enclosing ??= enclosingDefinitions(graph), evaluated);
|
|
119
150
|
}
|
|
120
151
|
else {
|
|
121
|
-
for (const escaped of escapingArguments(graph, id)) {
|
|
122
|
-
|
|
123
|
-
|
|
152
|
+
for (const [escaped, closure] of escapingArguments(graph, id)) {
|
|
153
|
+
deferred_1.Deferred.link(graph, escaped, namesOnce(), idMap);
|
|
154
|
+
readAtForcingCalls(graph, id, escaped, closure, idMap);
|
|
155
|
+
}
|
|
156
|
+
sideEffects ??= callsWithSideEffects(graph);
|
|
157
|
+
const flow = sideEffects.has(id) ? cfgOnce() : undefined;
|
|
158
|
+
if (flow === undefined) {
|
|
159
|
+
continue;
|
|
124
160
|
}
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (sites.length > 0) {
|
|
132
|
-
deferred_1.Deferred.link(graph, argument, names, idMap, { cfg: flow, sites, binding: parameter });
|
|
133
|
-
}
|
|
161
|
+
for (const parameter of df_helper_1.Dataflow.calleesOf(graph, id).flatMap(df_helper_1.Dataflow.parametersOf)) {
|
|
162
|
+
for (const argument of df_helper_1.Dataflow.argumentsBoundTo(graph, parameter)) {
|
|
163
|
+
const index = namesOnce();
|
|
164
|
+
const forces = forcesOf(graph, parameter, flow, forcing, reachOf);
|
|
165
|
+
if (forces !== undefined) {
|
|
166
|
+
deferred_1.Deferred.link(graph, argument, index, idMap, forces);
|
|
134
167
|
}
|
|
135
168
|
}
|
|
136
169
|
}
|
|
137
170
|
}
|
|
138
171
|
}
|
|
172
|
+
for (const at of evaluated) {
|
|
173
|
+
nse_1.Nse.unmark(graph, at);
|
|
174
|
+
}
|
|
175
|
+
graph.trackIncomingReads(false);
|
|
139
176
|
/* only once every mark has settled: the read a column gets makes it look bound from here on */
|
|
140
177
|
nse_1.Nse.linkMasksToData(graph, masking);
|
|
141
178
|
}
|
|
142
179
|
};
|
|
180
|
+
/** Where `parameter` is forced, shared by all calls handing it an argument; only reused while its reads are unchanged. */
|
|
181
|
+
function forcesOf(graph, parameter, cfg, forcing, reachOf) {
|
|
182
|
+
const version = graph.incomingReadsVersion(parameter);
|
|
183
|
+
const known = forcing.get(parameter);
|
|
184
|
+
if (known?.version === version) {
|
|
185
|
+
return known.forces;
|
|
186
|
+
}
|
|
187
|
+
/* counting is only needed once something touched the reads, and the same count still means the same forces */
|
|
188
|
+
const reads = (0, frame_reflection_1.edgeSources)(graph, parameter, edge_1.EdgeType.Reads).length;
|
|
189
|
+
if (known?.reads === reads) {
|
|
190
|
+
forcing.set(parameter, { ...known, version });
|
|
191
|
+
return known.forces;
|
|
192
|
+
}
|
|
193
|
+
const sites = deferred_1.Deferred.forcedAt(graph, parameter, cfg);
|
|
194
|
+
const forces = sites.length > 0 ? { cfg, sites, binding: parameter, reach: reachOf(sites) } : undefined;
|
|
195
|
+
forcing.set(parameter, { version, reads, forces });
|
|
196
|
+
return forces;
|
|
197
|
+
}
|
|
143
198
|
/** The name a delaying call binds, which is the definition its reads have to go through. */
|
|
144
199
|
function boundBy(graph, id) {
|
|
145
|
-
|
|
146
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedBy) && vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(target))) {
|
|
147
|
-
return target;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return undefined;
|
|
200
|
+
return (0, frame_reflection_1.edgeSources)(graph, id, edge_1.EdgeType.DefinedBy).find(target => vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(target)));
|
|
151
201
|
}
|
|
152
202
|
/** Every read of the delayed name takes the promised expression's value, so all of them get the link, not just whichever forces it first. */
|
|
153
203
|
function linkForcesToPromise(graph, binding, promise) {
|
|
154
|
-
for (const
|
|
155
|
-
if (
|
|
204
|
+
for (const reader of (0, frame_reflection_1.edgeSources)(graph, binding, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall)) {
|
|
205
|
+
if (reader !== promise) {
|
|
156
206
|
graph.addEdge(reader, promise, edge_1.EdgeType.Reads);
|
|
157
207
|
}
|
|
158
208
|
}
|
|
159
209
|
}
|
|
210
|
+
/** The tracked custom environment `evalEnv` names, if it is a single one. */
|
|
211
|
+
function trackedEnvOf(call, evalEnv) {
|
|
212
|
+
const defs = r_symbol_1.RSymbol.is(evalEnv) && call.environment !== undefined ? resolve_helper_1.Resolve.byNameAndType(evalEnv.content, call.environment, identifier_1.ReferenceType.Variable) : undefined;
|
|
213
|
+
const env = defs?.length === 1 && (0, identifier_1.hasEnvState)(defs[0]) ? defs[0].envState : undefined;
|
|
214
|
+
return env?.current.globalEnv || env?.current.builtInEnv ? undefined : env;
|
|
215
|
+
}
|
|
160
216
|
function* installedLanguageOf(graph, id, installers) {
|
|
161
|
-
for (const
|
|
162
|
-
if (!
|
|
217
|
+
for (const definition of (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Reads)) {
|
|
218
|
+
if (!vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(definition))) {
|
|
163
219
|
continue;
|
|
164
220
|
}
|
|
165
221
|
let installs = false;
|
|
166
222
|
const captured = [];
|
|
167
|
-
for (const
|
|
168
|
-
if (!edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy)) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
223
|
+
for (const by of (0, frame_reflection_1.edgeTargets)(graph, definition, edge_1.EdgeType.DefinedBy)) {
|
|
171
224
|
const captures = capturedArgumentsOf(graph, by, true);
|
|
172
225
|
if (captures.length > 0) {
|
|
173
226
|
captured.push(...captures);
|
|
@@ -185,7 +238,7 @@ function languageInstallersOf(graph, environment) {
|
|
|
185
238
|
const installers = new Set();
|
|
186
239
|
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
187
240
|
if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Replacement)
|
|
188
|
-
&& ((
|
|
241
|
+
&& built_in_props_1.CallProps.hasAny((0, query_fn_props_1.callFnProps)(id, { graph, environment }), built_in_props_1.CallProp.Lang)) {
|
|
189
242
|
installers.add(id);
|
|
190
243
|
}
|
|
191
244
|
}
|
|
@@ -196,134 +249,159 @@ function languageInstallersOf(graph, environment) {
|
|
|
196
249
|
* and still hands back the language object they form, all of them.
|
|
197
250
|
*/
|
|
198
251
|
function capturedArgumentsOf(graph, id, marked) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
captured.push(target);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return captured;
|
|
206
|
-
}
|
|
207
|
-
/** Every name a definition binds, the string-named ones an `assign` creates included. */
|
|
208
|
-
function bindingsOf(graph, idMap) {
|
|
209
|
-
const bindings = new Map();
|
|
210
|
-
for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
|
|
211
|
-
const name = node_id_1.NodeId.recoverName(id, idMap);
|
|
212
|
-
if (name === undefined) {
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
const key = identifier_1.Identifier.getName((0, retriever_1.removeRQuotes)(name));
|
|
216
|
-
const known = bindings.get(key);
|
|
217
|
-
if (known !== undefined) {
|
|
218
|
-
known.push(id);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
bindings.set(key, [id]);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return bindings;
|
|
252
|
+
return [...graph.edgesFrom(id)]
|
|
253
|
+
.filter(([, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument) && (!marked || edge_1.DfEdge.includesType(edge, edge_1.EdgeType.NonStandardEvaluation)))
|
|
254
|
+
.map(([target]) => target);
|
|
225
255
|
}
|
|
226
256
|
/**
|
|
227
257
|
* Where the evaluation happens: the call itself, or, for one inside a closure, every call of that closure (those
|
|
228
258
|
* are the points whose bindings the evaluation sees). `undefined` if a nesting closure is never seen called.
|
|
229
259
|
*/
|
|
230
|
-
function evaluationSites(graph, id) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
260
|
+
function evaluationSites(graph, id, enclosing) {
|
|
261
|
+
if ((enclosing.get(id) ?? []).length === 0) {
|
|
262
|
+
return [id];
|
|
263
|
+
}
|
|
264
|
+
const sites = new Set();
|
|
265
|
+
const todo = [id];
|
|
266
|
+
for (let at = todo.pop(); at !== undefined; at = todo.pop()) {
|
|
267
|
+
for (const definition of enclosing.get(at) ?? []) {
|
|
268
|
+
for (const caller of (0, frame_reflection_1.edgeSources)(graph, definition, edge_1.EdgeType.Calls)) {
|
|
269
|
+
if (!sites.has(caller)) {
|
|
270
|
+
sites.add(caller);
|
|
271
|
+
todo.push(caller);
|
|
272
|
+
}
|
|
241
273
|
}
|
|
242
274
|
}
|
|
243
275
|
}
|
|
244
|
-
|
|
245
|
-
|
|
276
|
+
return sites.size > 0 ? [...sites] : undefined;
|
|
277
|
+
}
|
|
278
|
+
/** the function definitions each vertex sits in, built once per pass instead of searching them for every evaluation */
|
|
279
|
+
function enclosingDefinitions(graph) {
|
|
280
|
+
const enclosing = new Map();
|
|
281
|
+
for (const [definition, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
|
|
282
|
+
for (const id of vertex.subflow.graph) {
|
|
283
|
+
const known = enclosing.get(id);
|
|
284
|
+
if (known === undefined) {
|
|
285
|
+
enclosing.set(id, [definition]);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
known.push(definition);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
246
291
|
}
|
|
247
|
-
return
|
|
292
|
+
return enclosing;
|
|
248
293
|
}
|
|
249
|
-
/** Whether some point the evaluation may run at
|
|
250
|
-
function
|
|
251
|
-
|
|
294
|
+
/** Whether some point the evaluation may run at is reached with a definition in effect; the same for every definition, so walked once. */
|
|
295
|
+
function mayReachFrom(sites, cfg, reach) {
|
|
296
|
+
if (cfg === undefined || sites === undefined) {
|
|
297
|
+
return () => true;
|
|
298
|
+
}
|
|
299
|
+
return definition => (reach.before ??= (0, happens_before_1.reachableTo)(cfg, sites)).has(definition);
|
|
252
300
|
}
|
|
253
301
|
/**
|
|
254
302
|
* The names the frames we know do not bind: a capture forced inside a closure may see bindings the caller made
|
|
255
303
|
* after the closure was written, so every reachable definition of the name stays a candidate.
|
|
256
304
|
*/
|
|
257
|
-
function linkAgainstAnyBinding(graph, open, bindings, sites, cfg) {
|
|
305
|
+
function linkAgainstAnyBinding(graph, open, bindings, sites, cfg, reach) {
|
|
306
|
+
const mayReach = mayReachFrom(sites, cfg, reach);
|
|
258
307
|
for (const reference of open) {
|
|
259
308
|
if (reference.name === undefined) {
|
|
260
309
|
continue;
|
|
261
310
|
}
|
|
262
311
|
for (const definition of bindings.get(identifier_1.Identifier.getName(reference.name)) ?? []) {
|
|
263
|
-
if (definition !== reference.nodeId && mayReach(
|
|
312
|
+
if (definition !== reference.nodeId && mayReach(definition)) {
|
|
264
313
|
graph.addEdge(reference.nodeId, definition, edge_1.EdgeType.Reads);
|
|
265
314
|
}
|
|
266
315
|
}
|
|
267
316
|
}
|
|
268
317
|
}
|
|
269
318
|
function callsWithSideEffects(graph) {
|
|
270
|
-
|
|
271
|
-
for (const [id] of graph.vertices(true)) {
|
|
272
|
-
for (const [target, edge] of graph.edgesFrom(id)) {
|
|
273
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.SideEffectOnCall)) {
|
|
274
|
-
calls.add(target);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return calls;
|
|
279
|
-
}
|
|
280
|
-
function* forcedParameters(graph, id) {
|
|
281
|
-
for (const callee of df_helper_1.Dataflow.calleesOf(graph, id)) {
|
|
282
|
-
for (const parameter of df_helper_1.Dataflow.parametersOf(callee)) {
|
|
283
|
-
for (const argument of df_helper_1.Dataflow.argumentsBoundTo(graph, parameter)) {
|
|
284
|
-
yield [argument, parameter];
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
319
|
+
return new Set(graph.vertices(true).flatMap(([from]) => (0, frame_reflection_1.edgeTargets)(graph, from, edge_1.EdgeType.SideEffectOnCall)));
|
|
288
320
|
}
|
|
289
321
|
/** Links a capture handed to an evaluating call, in that call's scope. */
|
|
290
|
-
function resolveEvaluation(graph, call, idMap, names, bindings, cfg) {
|
|
322
|
+
function resolveEvaluation(graph, call, idMap, names, bindings, cfg, reachOf, enclosing, evaluated) {
|
|
291
323
|
const id = call.id;
|
|
292
324
|
const own = EvaluatingElsewhereCalls.has(identifier_1.Identifier.getName(call.name));
|
|
293
325
|
const sources = own ? capturedArgumentsOf(graph, id, true).map(expr => ({ expr, at: id })) : sourcesHandedTo(graph, call, idMap);
|
|
294
326
|
const environment = call.environment;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
327
|
+
const node = idMap.get(id);
|
|
328
|
+
/* a frame of its own (`eval(expr, envir)` runs in the one it is given) says nothing about the bindings here,
|
|
329
|
+
so every one of them stays possible */
|
|
330
|
+
const elsewhere = own || environment === undefined || (r_function_call_1.RFunctionCall.isNamed(node) && node.arguments.length > 1);
|
|
331
|
+
const sites = sources.length > 0 ? evaluationSites(graph, id, enclosing) : undefined;
|
|
332
|
+
const reach = sites === undefined ? {} : reachOf(sites);
|
|
298
333
|
for (const { expr, at } of sources) {
|
|
299
334
|
if (elsewhere) {
|
|
300
|
-
const forces = cfg === undefined || sites === undefined ? undefined : { cfg, sites, binding: id };
|
|
335
|
+
const forces = cfg === undefined || sites === undefined ? undefined : { cfg, sites, binding: id, reach };
|
|
301
336
|
deferred_1.Deferred.link(graph, expr, { definitions: bindings, uses: names.uses }, idMap, forces);
|
|
302
|
-
deferred_1.Deferred.publish(graph, expr, names, idMap, id,
|
|
337
|
+
deferred_1.Deferred.publish(graph, expr, names, idMap, id, sites ?? []);
|
|
303
338
|
}
|
|
304
339
|
else {
|
|
305
340
|
const open = (0, linker_1.linkExpressionIn)(graph, expr, environment, idMap);
|
|
306
341
|
/* R falls through to the enclosing scope for names the evaluating frame does not bind */
|
|
307
342
|
const enclosing = open.length > 0 ? graph.getVertex(at)?.environment : undefined;
|
|
308
343
|
const unbound = enclosing === undefined ? open : (0, linker_1.linkInputs)(open, enclosing, [], graph, false);
|
|
309
|
-
linkAgainstAnyBinding(graph, unbound, bindings, sites, cfg);
|
|
310
|
-
deferred_1.Deferred.publish(graph, expr, names, idMap, id, cfg);
|
|
344
|
+
linkAgainstAnyBinding(graph, unbound, bindings, sites, cfg, reach);
|
|
345
|
+
deferred_1.Deferred.publish(graph, expr, names, idMap, id, sites ?? [], cfg);
|
|
311
346
|
}
|
|
312
347
|
graph.addEdge(id, expr, edge_1.EdgeType.Returns);
|
|
348
|
+
/* the captured code only runs because this call evaluates it */
|
|
349
|
+
graph.addEdge(expr, id, edge_1.EdgeType.Reads);
|
|
313
350
|
if (!elsewhere) {
|
|
314
351
|
/* the capture said "not evaluated here", and being handed to `eval` settles that it is */
|
|
315
|
-
|
|
352
|
+
evaluated.push(at);
|
|
316
353
|
}
|
|
317
354
|
}
|
|
318
355
|
if (sources.length > 0 && !elsewhere) {
|
|
319
356
|
forgetUnknownSideEffect(graph, id);
|
|
320
357
|
}
|
|
358
|
+
if (sources.length > 0 && environment !== undefined && !sources.some(({ expr }) => mayConfigure(graph, expr, environment))) {
|
|
359
|
+
forgetStateWrites(graph, id, new Set(sources.filter(({ at }) => model_1.RNode.findEnclosing(at, idMap, n => n.info.id === id) === undefined).map(({ expr }) => expr)));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** Whether evaluating `expr` may change the options, graphics, or RNG state: a call states {@link CallProp.Configures} or {@link SemanticCallTag.Random}, or is opaque. */
|
|
363
|
+
function mayConfigure(graph, expr, environment) {
|
|
364
|
+
const seen = new Set();
|
|
365
|
+
const todo = [expr];
|
|
366
|
+
while (todo.length > 0) {
|
|
367
|
+
const id = todo.pop();
|
|
368
|
+
if (seen.has(id) || node_id_1.NodeId.isBuiltIn(id)) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
seen.add(id);
|
|
372
|
+
const vertex = graph.getVertex(id);
|
|
373
|
+
if (vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
374
|
+
const builtIn = Array.isArray(vertex.origin) && vertex.origin.every(o => String(o).startsWith('builtin:') && o !== built_in_proc_name_1.BuiltInProcName.Function && o !== built_in_proc_name_1.BuiltInProcName.Eval);
|
|
375
|
+
if (!builtIn || built_in_props_1.CallProps.hasAny((0, query_fn_props_1.callFnProps)(id, { graph, environment }), [built_in_props_1.CallProp.Configures, built_in_props_1.SemanticCallTag.Random])) {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
for (const [target, edge] of graph.edgesFrom(id)) {
|
|
380
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument | edge_1.EdgeType.Returns) || (vertex_1.DfgVertex.isUse(vertex) && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads))) {
|
|
381
|
+
todo.push(target);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* An evaluation is assumed to write the options and graphics state until we know what it evaluates (see `evaluatesCapturedCode`);
|
|
389
|
+
* a captured call then no longer needs the evaluation either, `eval(quote(x <- 1))` slices to `x <- 1`.
|
|
390
|
+
*/
|
|
391
|
+
function forgetStateWrites(graph, id, evaluatedElsewhere) {
|
|
392
|
+
for (const [from, edge] of graph.edgesTo(id)) {
|
|
393
|
+
if (edge_1.DfEdge.isOnlyType(edge, edge_1.EdgeType.Reads) && vertex_1.DfgVertex.isFunctionCall(graph.getVertex(from)) && !evaluatedElsewhere.has(from)) {
|
|
394
|
+
graph.removeEdgeType(from, id, edge_1.EdgeType.Reads);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
321
397
|
}
|
|
322
398
|
/** The captures the first argument of an evaluating call may carry. */
|
|
323
399
|
function sourcesHandedTo(graph, call, idMap) {
|
|
324
400
|
const argument = call.args.find(a => !graph_1.FunctionArgument.isEmpty(a));
|
|
325
|
-
const reference = argument === undefined ? undefined :
|
|
326
|
-
|
|
401
|
+
const reference = argument === undefined ? undefined : graph_1.FunctionArgument.getReference(argument);
|
|
402
|
+
const node = reference === undefined ? undefined : idMap.get(reference);
|
|
403
|
+
const value = r_argument_1.RArgument.is(node) ? node.value?.info.id : reference;
|
|
404
|
+
return value === undefined ? [] : exports.Quoted.sourcesOf(graph, value);
|
|
327
405
|
}
|
|
328
406
|
/**
|
|
329
407
|
* The arguments of `id` whose promise outlives the call: the callee hands back a closure and never reads the
|
|
@@ -338,29 +416,54 @@ function* escapingArguments(graph, id) {
|
|
|
338
416
|
continue;
|
|
339
417
|
}
|
|
340
418
|
for (const parameter of df_helper_1.Dataflow.parametersOf(callee)) {
|
|
341
|
-
|
|
342
|
-
for (const [reader, edge] of graph.edgesTo(parameter)) {
|
|
343
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && !closure.subflow.graph.has(reader)) {
|
|
344
|
-
escapes = false;
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if (!escapes) {
|
|
419
|
+
if ((0, frame_reflection_1.edgeSources)(graph, parameter, edge_1.EdgeType.Reads).some(reader => !closure.subflow.graph.has(reader))) {
|
|
349
420
|
continue;
|
|
350
421
|
}
|
|
351
|
-
|
|
422
|
+
for (const argument of df_helper_1.Dataflow.argumentsBoundTo(graph, parameter)) {
|
|
423
|
+
yield [argument, closure.id];
|
|
424
|
+
}
|
|
352
425
|
}
|
|
353
426
|
}
|
|
354
427
|
}
|
|
355
428
|
}
|
|
356
|
-
/**
|
|
357
|
-
function
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
429
|
+
/** A promise only `closure` forces sees what is bound where it is called, so if each of its calls runs once, a definition none of them sees does not reach it. */
|
|
430
|
+
function readAtForcingCalls(graph, factoryCall, argument, closure, idMap) {
|
|
431
|
+
const environments = [];
|
|
432
|
+
for (const [binding, edge] of graph.edgesTo(factoryCall)) {
|
|
433
|
+
const via = graph.getVertex(binding);
|
|
434
|
+
if (!edge_1.DfEdge.includesType(edge, ~edge_1.ControlFlowEdgeTypes) || vertex_1.DfgVertex.hasOrigin(via, built_in_proc_name_1.BuiltInProcName.Assignment)) {
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
else if (!vertex_1.DfgVertex.isVariableDefinition(via) || !edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedBy)) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
for (const reader of (0, frame_reflection_1.edgeSources)(graph, binding, edge_1.EdgeType.Reads)) {
|
|
441
|
+
const call = graph.getVertex(reader);
|
|
442
|
+
if (!vertex_1.DfgVertex.isFunctionCall(call) || !(0, frame_reflection_1.hasEdgeOfType)(graph, reader, closure, edge_1.EdgeType.Calls)
|
|
443
|
+
|| call.environment === undefined || program_order_1.ProgramOrder.runsOnceAt(reader, graph) === undefined) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
environments.push(call.environment);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (environments.length === 0 || program_order_1.ProgramOrder.runsOnceAt(factoryCall, graph) === undefined) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
model_1.RNode.visitAst(idMap.get(argument), node => {
|
|
453
|
+
/* what a function within the argument reads is read when that function runs, not when the promise is forced */
|
|
454
|
+
if (graph.hasVertex(node.info.id) && !graph.isRoot(node.info.id)) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
if (r_symbol_1.RSymbol.is(node)) {
|
|
458
|
+
const visible = new Set(environments.flatMap(env => resolve_helper_1.Resolve.byName(node.content, env) ?? []).map(d => d.nodeId));
|
|
459
|
+
for (const target of (0, frame_reflection_1.edgeTargets)(graph, node.info.id, edge_1.EdgeType.Reads)) {
|
|
460
|
+
if (vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(target)) && !visible.has(target)) {
|
|
461
|
+
graph.removeEdgeType(node.info.id, target, edge_1.EdgeType.Reads);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return false;
|
|
466
|
+
});
|
|
364
467
|
}
|
|
365
468
|
/** Drops the marker the call carries while we cannot say what it evaluates. */
|
|
366
469
|
function forgetUnknownSideEffect(graph, id) {
|