@eagleoutice/flowr 2.15.10 → 2.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -26
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/cli/flowr-main-options.d.ts +15 -0
- package/cli/flowr-main-options.js +18 -0
- package/cli/flowr.d.ts +18 -0
- package/cli/flowr.js +13 -2
- package/cli/repl/commands/repl-clipboard.js +2 -1
- package/cli/repl/commands/repl-commands.js +2 -0
- package/cli/repl/commands/repl-main.d.ts +5 -0
- package/cli/repl/commands/repl-signature.js +2 -0
- package/cli/repl/core.d.ts +7 -1
- package/cli/repl/core.js +17 -8
- package/cli/repl/execute.js +2 -0
- package/cli/repl/server/connection.js +2 -1
- package/cli/repl/server/net.d.ts +10 -0
- package/cli/repl/server/net.js +34 -1
- package/cli/slicer-app.js +2 -1
- package/config.d.ts +12 -2
- package/config.js +91 -14
- package/control-flow/happens-before.d.ts +5 -0
- package/control-flow/happens-before.js +48 -34
- package/control-flow/useless-loop.d.ts +1 -1
- package/control-flow/useless-loop.js +29 -42
- package/dataflow/environments/built-in-props.d.ts +9 -0
- package/dataflow/environments/built-in-props.js +25 -19
- package/dataflow/environments/built-in.d.ts +2 -2
- package/dataflow/environments/built-in.js +41 -77
- package/dataflow/environments/default-builtin-config.d.ts +181 -29
- package/dataflow/environments/default-builtin-config.js +38 -24
- package/dataflow/environments/environment.d.ts +6 -4
- package/dataflow/environments/environment.js +54 -121
- package/dataflow/environments/identifier.d.ts +4 -2
- package/dataflow/environments/identifier.js +23 -69
- package/dataflow/environments/reference-to-maybe.d.ts +9 -0
- package/dataflow/environments/reference-to-maybe.js +23 -51
- package/dataflow/environments/resolve-by-name.js +37 -76
- package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
- package/dataflow/eval/resolve/resolve-argument.js +61 -64
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
- package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
- package/dataflow/eval/resolve/resolve.d.ts +4 -0
- package/dataflow/eval/resolve/resolve.js +23 -14
- package/dataflow/extractor.js +185 -59
- package/dataflow/fn/class-declaration.d.ts +8 -2
- package/dataflow/fn/class-declaration.js +96 -97
- package/dataflow/fn/exceptions-of-function.js +68 -37
- package/dataflow/fn/frame-reflection.d.ts +12 -4
- package/dataflow/fn/frame-reflection.js +64 -42
- package/dataflow/fn/function-props.js +15 -33
- package/dataflow/fn/function-semantics.d.ts +11 -3
- package/dataflow/fn/function-semantics.js +6 -0
- package/dataflow/fn/higher-order-function.js +13 -17
- package/dataflow/fn/strict-function.d.ts +13 -0
- package/dataflow/fn/strict-function.js +285 -122
- package/dataflow/graph/call-graph.d.ts +7 -6
- package/dataflow/graph/call-graph.js +35 -46
- package/dataflow/graph/graph.d.ts +6 -1
- package/dataflow/graph/graph.js +57 -66
- package/dataflow/info.d.ts +8 -1
- package/dataflow/info.js +24 -30
- package/dataflow/internal/control-flow.d.ts +42 -4
- package/dataflow/internal/control-flow.js +76 -39
- package/dataflow/internal/linker.d.ts +15 -9
- package/dataflow/internal/linker.js +253 -241
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +441 -79
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +290 -252
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +120 -93
- package/dataflow/internal/process/functions/call/common.d.ts +1 -3
- package/dataflow/internal/process/functions/call/common.js +36 -76
- package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
- package/dataflow/internal/process/functions/call/deferred.js +60 -58
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
- package/dataflow/internal/process/functions/call/named-call-handling.js +44 -21
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +162 -172
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
- package/dataflow/internal/process/functions/process-parameter.js +25 -32
- package/dataflow/internal/process/process-symbol.js +3 -6
- package/dataflow/internal/program-order.d.ts +26 -0
- package/dataflow/internal/program-order.js +49 -0
- package/documentation/doc-capabilities.js +4 -1
- package/documentation/wiki-interface.js +4 -0
- package/documentation/wiki-setup.js +23 -0
- package/engines.js +11 -3
- package/linter/linter-executor.js +19 -1
- package/linter/linter-rules.d.ts +17 -8
- package/linter/rules/absolute-path.js +63 -87
- package/linter/rules/file-path-validity.d.ts +4 -2
- package/linter/rules/file-path-validity.js +117 -80
- package/linter/rules/namespace-access.js +21 -33
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +60 -48
- package/linter/rules/network-functions.js +11 -7
- package/linter/rules/no-leaked-credentials.js +15 -18
- package/linter/rules/problematic-inputs.d.ts +2 -1
- package/linter/rules/problematic-inputs.js +39 -59
- package/linter/rules/roxygen-arguments.d.ts +9 -4
- package/linter/rules/roxygen-arguments.js +29 -48
- package/linter/rules/seeded-randomness.d.ts +7 -4
- package/linter/rules/seeded-randomness.js +130 -89
- package/linter/rules/stop-with-call-arg.d.ts +4 -2
- package/linter/rules/stop-with-call-arg.js +25 -22
- package/linter/rules/unclosed-connection.js +31 -24
- package/linter/rules/undefined-symbol.d.ts +4 -6
- package/linter/rules/undefined-symbol.js +58 -75
- package/linter/rules/unescaped-arguments.js +18 -44
- package/linter/rules/unused-definition.d.ts +6 -0
- package/linter/rules/unused-definition.js +105 -145
- package/linter/rules/unused-import.d.ts +3 -0
- package/linter/rules/unused-import.js +25 -43
- package/package.json +5 -2
- package/project/flowr-analyzer.js +6 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +14 -5
- package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +18 -42
- package/project/sigdb/decompress.js +3 -1
- package/project/sigdb/sigdb-download.js +9 -6
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/config-query/config-query-executor.js +9 -2
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
- package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
- package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
- package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
- package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
- package/r-bridge/lang-4.x/ast/model/model.js +19 -43
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/roxygen2/roxygen-parse.js +28 -42
- package/r-bridge/shell-executor.js +2 -0
- package/r-bridge/shell.js +8 -0
- package/search/search-executor/search-enrichers.js +25 -37
- package/slicing/static/slice-call.d.ts +4 -3
- package/slicing/static/slice-call.js +56 -88
- package/slicing/static/static-slicer.js +120 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/files.d.ts +6 -0
- package/util/files.js +12 -0
- package/util/parallel.js +2 -0
- package/util/proc.js +2 -1
- package/util/r-base-packages.d.ts +2 -0
- package/util/r-base-packages.js +23 -13
- package/util/secure-mode.d.ts +42 -0
- package/util/secure-mode.js +70 -0
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
2
2
|
import type { DataflowGraph } from '../graph/graph';
|
|
3
|
-
import type { DataflowCfgInformation } from '../info';
|
|
3
|
+
import type { DataflowCfgInformation, ExitPoint } from '../info';
|
|
4
4
|
import { ControlDependency, ExitPointType } from '../info';
|
|
5
|
+
import { Ternary } from '../../util/logic';
|
|
5
6
|
/**
|
|
6
7
|
* Records the control flow of a program in the {@link DataflowGraph} while the dataflow analysis walks it.
|
|
7
8
|
* The {@link ControlFlowGraph} is a view on what is recorded here.
|
|
@@ -41,7 +42,7 @@ export declare const ControlFlow: {
|
|
|
41
42
|
readonly isExpression: (this: void, graph: DataflowGraph, id: NodeId) => boolean;
|
|
42
43
|
/**
|
|
43
44
|
* Whether the subtree always jumps away instead of being left normally, i.e. whether a non-default exit
|
|
44
|
-
* point happens in every branch.
|
|
45
|
+
* point happens in every branch. The control dependencies in `context` (like a promise's) hold for the whole subtree.
|
|
45
46
|
* @see {@link ControlFlow#canComplete|canComplete()} - for whether it can be left normally at all
|
|
46
47
|
* @example
|
|
47
48
|
* ```r
|
|
@@ -49,7 +50,7 @@ export declare const ControlFlow: {
|
|
|
49
50
|
* { if(u) break } # only maybe
|
|
50
51
|
* ```
|
|
51
52
|
*/
|
|
52
|
-
readonly alwaysExits: (this: void, info: DataflowCfgInformation) => boolean;
|
|
53
|
+
readonly alwaysExits: (this: void, info: DataflowCfgInformation, context?: readonly ControlDependency[]) => boolean;
|
|
53
54
|
/**
|
|
54
55
|
* Whether the subtree can be left normally instead of always jumping away.
|
|
55
56
|
* @see {@link ControlFlow#alwaysExits|alwaysExits()} - for whether it always jumps away
|
|
@@ -80,13 +81,50 @@ export declare const ControlFlow: {
|
|
|
80
81
|
*/
|
|
81
82
|
readonly branchesTo: (this: void, graph: DataflowGraph, from: DataflowCfgInformation, target: NodeId, cd: ControlDependency) => void;
|
|
82
83
|
/**
|
|
83
|
-
* Every jump of the given kind within `from` lands on `target
|
|
84
|
+
* Every jump of the given kind within `from` lands on `target`, which reads a `break` as it decides how often a loop runs.
|
|
84
85
|
* @example
|
|
85
86
|
* ```r
|
|
86
87
|
* while(u) { break } # the `break` lands on the loop it leaves
|
|
87
88
|
* ```
|
|
88
89
|
*/
|
|
89
90
|
readonly jumpsTo: (this: void, graph: DataflowGraph, from: DataflowCfgInformation, kind: ExitPointType, target: NodeId) => void;
|
|
91
|
+
/**
|
|
92
|
+
* What is handed to `holder` runs only once `holder` forces it, so it is analyzed under that control
|
|
93
|
+
* dependency: a definition within a promise may not happen, and what it would overwrite stays visible.
|
|
94
|
+
* @see {@link ControlFlow#promise|promise()} - for the jumps within a promise
|
|
95
|
+
* @example
|
|
96
|
+
* ```r
|
|
97
|
+
* g(x <- 2) # `x` is 2 afterwards only if `g` forces its argument
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
readonly withinPromise: <Data extends {
|
|
101
|
+
readonly cds?: readonly ControlDependency[];
|
|
102
|
+
}>(this: void, data: Data, holder: NodeId) => Data;
|
|
103
|
+
/**
|
|
104
|
+
* A function defined within a promise: forcing the promise only creates it, its body runs once it is called,
|
|
105
|
+
* so neither the definition nor its body depend on the call holding the promise.
|
|
106
|
+
* @example
|
|
107
|
+
* ```r
|
|
108
|
+
* f(function() print(1)) # the print runs when `f` calls its argument, which `f(...)` itself does not decide
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
readonly outsidePromises: <Data extends {
|
|
112
|
+
readonly cds?: readonly ControlDependency[];
|
|
113
|
+
}>(this: void, data: Data) => Data;
|
|
114
|
+
/**
|
|
115
|
+
* The jumps within a promise, an argument or default R evaluates only if `holder` forces it. A jump
|
|
116
|
+
* - never runs if the promise is {@link Ternary#Never|never} forced, so control resumes at `holder`,
|
|
117
|
+
* - leaves whenever reached if it is {@link Ternary#Always|always} forced,
|
|
118
|
+
* - otherwise stays an exit under a `byPromise` dependency on `holder`, and control may resume at `holder` as well,
|
|
119
|
+
* until {@link FunctionSemantics.settleJumpsInPromises} settles it.
|
|
120
|
+
* @returns the exit points the holder takes over from the promise
|
|
121
|
+
* @example
|
|
122
|
+
* ```r
|
|
123
|
+
* g(return(1)) # whether this returns is up to `g`
|
|
124
|
+
* function(x = break) x # the `break` runs where `x` is first used
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
readonly promise: (this: void, graph: DataflowGraph, promise: DataflowCfgInformation | undefined, forcing: Ternary, holder: NodeId) => ExitPoint[];
|
|
90
128
|
/**
|
|
91
129
|
* The parts run one after the other and the last one continues with `last`, if it is given.
|
|
92
130
|
* Parts that are `undefined` are skipped, which keeps optional arguments cheap to handle.
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ControlFlow = void 0;
|
|
4
4
|
const edge_1 = require("../graph/edge");
|
|
5
5
|
const info_1 = require("../info");
|
|
6
|
+
const logic_1 = require("../../util/logic");
|
|
6
7
|
const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
8
|
+
const assert_1 = require("../../util/assert");
|
|
7
9
|
/** Where `from` completes: its single CFG exit when it has one, else each of its default exit points. */
|
|
8
10
|
function completionsOf(from) {
|
|
9
11
|
return from.cfgExit !== undefined ? [from.cfgExit]
|
|
@@ -59,7 +61,7 @@ exports.ControlFlow = {
|
|
|
59
61
|
},
|
|
60
62
|
/**
|
|
61
63
|
* Whether the subtree always jumps away instead of being left normally, i.e. whether a non-default exit
|
|
62
|
-
* point happens in every branch.
|
|
64
|
+
* point happens in every branch. The control dependencies in `context` (like a promise's) hold for the whole subtree.
|
|
63
65
|
* @see {@link ControlFlow#canComplete|canComplete()} - for whether it can be left normally at all
|
|
64
66
|
* @example
|
|
65
67
|
* ```r
|
|
@@ -67,14 +69,18 @@ exports.ControlFlow = {
|
|
|
67
69
|
* { if(u) break } # only maybe
|
|
68
70
|
* ```
|
|
69
71
|
*/
|
|
70
|
-
alwaysExits(info) {
|
|
71
|
-
|
|
72
|
+
alwaysExits(info, context = []) {
|
|
73
|
+
const cds = [];
|
|
72
74
|
for (const exit of info.exitPoints) {
|
|
73
75
|
if (exit.type !== 0 /* ExitPointType.Default */) {
|
|
74
76
|
if (exit.cds === undefined) {
|
|
75
77
|
return true;
|
|
76
78
|
}
|
|
77
|
-
|
|
79
|
+
const own = info_1.ControlDependency.minus(exit.cds, context);
|
|
80
|
+
if (own.length === 0 && exit.cds.length > 0) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
cds.push(...own);
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
return info_1.ControlDependency.happensInEveryBranch(cds);
|
|
@@ -89,15 +95,7 @@ exports.ControlFlow = {
|
|
|
89
95
|
* ```
|
|
90
96
|
*/
|
|
91
97
|
canComplete(info) {
|
|
92
|
-
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
for (const exit of info.exitPoints) {
|
|
96
|
-
if (exit.type === 0 /* ExitPointType.Default */) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
98
|
+
return info.cfgExit !== undefined || info.exitPoints.some(e => e.type === 0 /* ExitPointType.Default */);
|
|
101
99
|
},
|
|
102
100
|
/**
|
|
103
101
|
* Whatever `from` completes at continues with `next`.
|
|
@@ -127,7 +125,7 @@ exports.ControlFlow = {
|
|
|
127
125
|
}
|
|
128
126
|
},
|
|
129
127
|
/**
|
|
130
|
-
* Every jump of the given kind within `from` lands on `target
|
|
128
|
+
* Every jump of the given kind within `from` lands on `target`, which reads a `break` as it decides how often a loop runs.
|
|
131
129
|
* @example
|
|
132
130
|
* ```r
|
|
133
131
|
* while(u) { break } # the `break` lands on the loop it leaves
|
|
@@ -137,9 +135,62 @@ exports.ControlFlow = {
|
|
|
137
135
|
for (const exit of from.exitPoints) {
|
|
138
136
|
if (exit.type === kind) {
|
|
139
137
|
graph.addEdge(exit.nodeId, target, edge_1.EdgeType.FlowEdge);
|
|
138
|
+
if (kind === 2 /* ExitPointType.Break */) {
|
|
139
|
+
graph.addEdge(target, exit.jump ?? exit.nodeId, edge_1.EdgeType.Reads);
|
|
140
|
+
}
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
},
|
|
144
|
+
/**
|
|
145
|
+
* What is handed to `holder` runs only once `holder` forces it, so it is analyzed under that control
|
|
146
|
+
* dependency: a definition within a promise may not happen, and what it would overwrite stays visible.
|
|
147
|
+
* @see {@link ControlFlow#promise|promise()} - for the jumps within a promise
|
|
148
|
+
* @example
|
|
149
|
+
* ```r
|
|
150
|
+
* g(x <- 2) # `x` is 2 afterwards only if `g` forces its argument
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
withinPromise(data, holder) {
|
|
154
|
+
return { ...data, cds: (0, info_1.withCds)(data.cds, [{ id: holder, when: true, byPromise: true }]) };
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* A function defined within a promise: forcing the promise only creates it, its body runs once it is called,
|
|
158
|
+
* so neither the definition nor its body depend on the call holding the promise.
|
|
159
|
+
* @example
|
|
160
|
+
* ```r
|
|
161
|
+
* f(function() print(1)) # the print runs when `f` calls its argument, which `f(...)` itself does not decide
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
outsidePromises(data) {
|
|
165
|
+
if (!data.cds?.some(cd => cd.byPromise)) {
|
|
166
|
+
return data;
|
|
167
|
+
}
|
|
168
|
+
const kept = data.cds.filter(cd => !cd.byPromise);
|
|
169
|
+
return { ...data, cds: kept.length > 0 ? kept : undefined };
|
|
170
|
+
},
|
|
171
|
+
/**
|
|
172
|
+
* The jumps within a promise, an argument or default R evaluates only if `holder` forces it. A jump
|
|
173
|
+
* - never runs if the promise is {@link Ternary#Never|never} forced, so control resumes at `holder`,
|
|
174
|
+
* - leaves whenever reached if it is {@link Ternary#Always|always} forced,
|
|
175
|
+
* - otherwise stays an exit under a `byPromise` dependency on `holder`, and control may resume at `holder` as well,
|
|
176
|
+
* until {@link FunctionSemantics.settleJumpsInPromises} settles it.
|
|
177
|
+
* @returns the exit points the holder takes over from the promise
|
|
178
|
+
* @example
|
|
179
|
+
* ```r
|
|
180
|
+
* g(return(1)) # whether this returns is up to `g`
|
|
181
|
+
* function(x = break) x # the `break` runs where `x` is first used
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
promise(graph, promise, forcing, holder) {
|
|
185
|
+
const exits = promise?.exitPoints.filter(e => e.type !== 0 /* ExitPointType.Default */) ?? [];
|
|
186
|
+
if (forcing === logic_1.Ternary.Always) {
|
|
187
|
+
return exits;
|
|
188
|
+
}
|
|
189
|
+
for (const exit of exits) {
|
|
190
|
+
graph.addEdge(exit.nodeId, holder, edge_1.EdgeType.FlowEdge);
|
|
191
|
+
}
|
|
192
|
+
return forcing === logic_1.Ternary.Never ? [] : exits.map(e => exports.ControlFlow.withinPromise(e, holder));
|
|
193
|
+
},
|
|
143
194
|
/**
|
|
144
195
|
* The parts run one after the other and the last one continues with `last`, if it is given.
|
|
145
196
|
* Parts that are `undefined` are skipped, which keeps optional arguments cheap to handle.
|
|
@@ -156,11 +207,11 @@ exports.ControlFlow = {
|
|
|
156
207
|
if (part === undefined) {
|
|
157
208
|
continue;
|
|
158
209
|
}
|
|
210
|
+
const next = exports.ControlFlow.entryOf(part);
|
|
159
211
|
if (previous === undefined) {
|
|
160
|
-
entry =
|
|
212
|
+
entry = next;
|
|
161
213
|
}
|
|
162
214
|
else {
|
|
163
|
-
const next = exports.ControlFlow.entryOf(part);
|
|
164
215
|
exports.ControlFlow.continuesWith(graph, previous, next);
|
|
165
216
|
/*
|
|
166
217
|
* R promises the parts are evaluated in this order, not that one jumping away keeps the next
|
|
@@ -194,30 +245,16 @@ exports.ControlFlow = {
|
|
|
194
245
|
* ```
|
|
195
246
|
*/
|
|
196
247
|
picksOneOf(graph, parts, from, joinsAt, hasDefault) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
exports.ControlFlow.continuesWith(graph, selector, exports.ControlFlow.entryOf(part));
|
|
209
|
-
}
|
|
210
|
-
selector = part;
|
|
211
|
-
}
|
|
212
|
-
for (let i = from; i < parts.length; i++) {
|
|
213
|
-
const alternative = parts[i];
|
|
214
|
-
if (alternative === undefined) {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (selector !== undefined) {
|
|
218
|
-
exports.ControlFlow.branchesTo(graph, selector, exports.ControlFlow.entryOf(alternative), { id: joinsAt, when: true });
|
|
248
|
+
const selectors = parts.slice(0, from).filter(assert_1.isNotUndefined);
|
|
249
|
+
const selector = selectors.at(-1);
|
|
250
|
+
const entry = exports.ControlFlow.inSequence(graph, selectors);
|
|
251
|
+
for (const alternative of parts.slice(from)) {
|
|
252
|
+
if (alternative !== undefined) {
|
|
253
|
+
if (selector !== undefined) {
|
|
254
|
+
exports.ControlFlow.branchesTo(graph, selector, exports.ControlFlow.entryOf(alternative), { id: joinsAt, when: true });
|
|
255
|
+
}
|
|
256
|
+
exports.ControlFlow.continuesWith(graph, alternative, joinsAt);
|
|
219
257
|
}
|
|
220
|
-
exports.ControlFlow.continuesWith(graph, alternative, joinsAt);
|
|
221
258
|
}
|
|
222
259
|
if (selector !== undefined && !hasDefault) {
|
|
223
260
|
exports.ControlFlow.branchesTo(graph, selector, joinsAt, { id: joinsAt, when: false });
|
|
@@ -9,6 +9,7 @@ import type { AstIdMap, ParentInformation } from '../../r-bridge/lang-4.x/ast/mo
|
|
|
9
9
|
import { type DataflowGraphVertexFunctionCall, type DataflowGraphVertexFunctionDefinition, type DataflowGraphVertexInfo } from '../graph/vertex';
|
|
10
10
|
import type { REnvironmentInformation } from '../environments/environment';
|
|
11
11
|
import type { ExitPoint } from '../info';
|
|
12
|
+
import { type BuiltInLookup } from '../fn/frame-reflection';
|
|
12
13
|
export type NameIdMap = DefaultMap<Identifier, IdentifierReference[]>;
|
|
13
14
|
/**
|
|
14
15
|
* Find all reads within the graph that do not reference a local definition in the graph.
|
|
@@ -28,18 +29,20 @@ export declare function linkArgumentsOnCall(args: readonly FunctionArgument[], p
|
|
|
28
29
|
* Links a function call with a single target function definition.
|
|
29
30
|
*/
|
|
30
31
|
export declare function linkFunctionCallWithSingleTarget(graph: DataflowGraph, { subflow: fnSubflow, exitPoints, id: fnId, params }: DataflowGraphVertexFunctionDefinition, info: DataflowGraphVertexFunctionCall, idMap: AstIdMap): ExitPoint[];
|
|
32
|
+
/** What {@link linkFunctionCalls} reports for a call it linked. */
|
|
33
|
+
export type CalledFunctions = {
|
|
34
|
+
functionCall: NodeId;
|
|
35
|
+
called: readonly DataflowGraphVertexInfo[];
|
|
36
|
+
propagateExitPoints: readonly ExitPoint[];
|
|
37
|
+
calledBuiltIns?: readonly NodeId[];
|
|
38
|
+
};
|
|
31
39
|
/**
|
|
32
40
|
* Returns the called functions within `graph` (ideally a superset of `thisGraph`, the graph searched for calls), which
|
|
33
41
|
* can be used to merge the environments with the call; also links the corresponding arguments.
|
|
34
42
|
*/
|
|
35
43
|
export declare function linkFunctionCalls(graph: DataflowGraph, idMap: AstIdMap, thisGraph: DataflowGraph,
|
|
36
44
|
/** calls `graph` knows of that `thisGraph` does not, as a read that became a call */
|
|
37
|
-
alsoCalls?: readonly NodeId[]):
|
|
38
|
-
functionCall: NodeId;
|
|
39
|
-
called: readonly DataflowGraphVertexInfo[];
|
|
40
|
-
propagateExitPoints: readonly ExitPoint[];
|
|
41
|
-
calledBuiltIns?: readonly NodeId[];
|
|
42
|
-
}[];
|
|
45
|
+
alsoCalls?: readonly NodeId[]): CalledFunctions[];
|
|
43
46
|
/**
|
|
44
47
|
* convenience function returning all known call targets, as well as the name source which defines them
|
|
45
48
|
*/
|
|
@@ -58,10 +61,11 @@ export declare function linkExpressionIn<Info>(this: void, graph: DataflowGraph,
|
|
|
58
61
|
/** Links the call `callId` to the functions the given definitions bind, which it did not know of when it was processed. */
|
|
59
62
|
export declare function linkCallToDefinitions(graph: DataflowGraph, callId: NodeId, definitions: readonly NodeId[], idMap: AstIdMap): void;
|
|
60
63
|
/**
|
|
61
|
-
* Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked
|
|
62
|
-
* added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned.
|
|
64
|
+
* Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked (or
|
|
65
|
+
* links to built-ins only) is added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned.
|
|
66
|
+
* @param alsoFrom - a node that reads every definition found as well
|
|
63
67
|
*/
|
|
64
|
-
export declare function linkInputs(referencesToLinkAgainstEnvironment: readonly IdentifierReference[], environmentInformation: REnvironmentInformation, givenInputs: IdentifierReference[], graph: DataflowGraph, maybeForRemaining: boolean): IdentifierReference[];
|
|
68
|
+
export declare function linkInputs(referencesToLinkAgainstEnvironment: readonly IdentifierReference[], environmentInformation: REnvironmentInformation, givenInputs: IdentifierReference[], graph: DataflowGraph, maybeForRemaining: boolean, alsoFrom?: NodeId): IdentifierReference[];
|
|
65
69
|
/**
|
|
66
70
|
* A loop variable read before its within-loop redefinition gets a maybe marker to that def (e.g. `x_2` may read the
|
|
67
71
|
* prior iteration's `x_1` in `for(...) { x_1 <- x_2 + 1 }`); with `environment`, this uses all defs live at loop exit.
|
|
@@ -92,3 +96,5 @@ export declare function linkFieldReads(graph: DataflowGraph, accessId: NodeId, f
|
|
|
92
96
|
* known, so binding the read at `readId` to a definition holding `envState` links the access to that field.
|
|
93
97
|
*/
|
|
94
98
|
export declare function bindAccessedField(graph: DataflowGraph, readId: NodeId, envState: REnvironmentInformation, idMap: AstIdMap): void;
|
|
99
|
+
/** A closure's `<<-` into its factory frame is seen only by calls of closures from the same factory call, so such calls depend on each other instead. */
|
|
100
|
+
export declare function separateClosureInstances(graph: DataflowGraph, known: BuiltInLookup): void;
|