@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,7 @@
|
|
|
1
1
|
import type { DataflowProcessorInformation } from '../../../../../processor';
|
|
2
2
|
import type { DataflowInformation } from '../../../../../info';
|
|
3
3
|
import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
|
-
import type
|
|
4
|
+
import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
5
5
|
import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
6
6
|
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
7
|
import type { FnSig } from '../../../../../environments/built-in-props';
|
|
@@ -4,6 +4,7 @@ exports.processGet = processGet;
|
|
|
4
4
|
const known_call_handling_1 = require("../known-call-handling");
|
|
5
5
|
const unpack_argument_1 = require("../argument/unpack-argument");
|
|
6
6
|
const make_argument_1 = require("../argument/make-argument");
|
|
7
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
7
8
|
const logger_1 = require("../../../../../logger");
|
|
8
9
|
const retriever_1 = require("../../../../../../r-bridge/retriever");
|
|
9
10
|
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
@@ -15,7 +16,6 @@ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-
|
|
|
15
16
|
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
16
17
|
const range_1 = require("../../../../../../util/range");
|
|
17
18
|
const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
18
|
-
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
19
19
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
20
20
|
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
21
21
|
const assert_1 = require("../../../../../../util/assert");
|
|
@@ -26,12 +26,33 @@ function namesDenotedBy(node, data) {
|
|
|
26
26
|
}
|
|
27
27
|
if (r_function_call_1.RFunctionCall.isNamed(node) && identifier_1.Identifier.getName(node.functionName.content) === 'c'
|
|
28
28
|
&& resolve_helper_1.Resolve.isBuiltIn(node.functionName.content, data.environment, identifier_1.ReferenceType.Function)) {
|
|
29
|
-
const parts = node.arguments.map(arg =>
|
|
30
|
-
|
|
29
|
+
const parts = node.arguments.map(arg => {
|
|
30
|
+
const value = r_argument_1.RArgument.valueOf(arg);
|
|
31
|
+
return value === undefined ? undefined : (0, built_in_envir_utils_1.resolveConstantString)(value, data);
|
|
32
|
+
});
|
|
31
33
|
return parts.every(assert_1.isNotUndefined) ? parts : [];
|
|
32
34
|
}
|
|
33
35
|
return [];
|
|
34
36
|
}
|
|
37
|
+
/** One symbol per constant name the first argument of `get` denotes, so the lookup is processed like a plain read of them. */
|
|
38
|
+
function synthesizeTargets(retrieve, name, rootId, data) {
|
|
39
|
+
const literal = r_string_1.RString.is(retrieve);
|
|
40
|
+
const names = literal ? [(0, retriever_1.removeRQuotes)(retrieve.lexeme)] : namesDenotedBy(retrieve, data);
|
|
41
|
+
const location = literal ? retrieve.location : retrieve.location ?? name.location ?? range_1.SourceRange.invalid();
|
|
42
|
+
const literalLexeme = literal ? retrieve.lexeme : undefined;
|
|
43
|
+
return names.map((resolvedName, i) => {
|
|
44
|
+
const synthId = `${rootId}-get-name${i > 0 ? '-' + String(i) : ''}`;
|
|
45
|
+
const synthSymbol = {
|
|
46
|
+
type: type_1.RType.Symbol,
|
|
47
|
+
info: { ...retrieve.info, id: synthId, parent: retrieve.info.id },
|
|
48
|
+
content: resolvedName,
|
|
49
|
+
lexeme: literalLexeme ?? resolvedName,
|
|
50
|
+
location
|
|
51
|
+
};
|
|
52
|
+
data.completeAst.idMap.set(synthId, synthSymbol);
|
|
53
|
+
return synthSymbol;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
35
56
|
/**
|
|
36
57
|
* Processes a built-in 'get' function call.
|
|
37
58
|
*
|
|
@@ -42,38 +63,15 @@ function namesDenotedBy(node, data) {
|
|
|
42
63
|
*/
|
|
43
64
|
function processGet(name, args, rootId, data, config = {}) {
|
|
44
65
|
const resolution = (0, built_in_envir_utils_1.resolveFirstEnvirArg)(args, data, config.sig, ['envir', ...built_in_envir_utils_1.EnvirPositionFormals]);
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
? (0, unpack_argument_1.unpackNonameArg)(firstArg)
|
|
48
|
-
: undefined;
|
|
49
|
-
const targets = [];
|
|
50
|
-
let nameExpression = undefined;
|
|
51
|
-
if (retrieve !== undefined) {
|
|
52
|
-
const literal = r_string_1.RString.is(retrieve);
|
|
53
|
-
const names = literal ? [(0, retriever_1.removeRQuotes)(retrieve.lexeme)] : namesDenotedBy(retrieve, data);
|
|
54
|
-
const location = literal ? retrieve.location : retrieve.location ?? name.location ?? range_1.SourceRange.invalid();
|
|
55
|
-
for (const [i, resolvedName] of names.entries()) {
|
|
56
|
-
const synthId = `${rootId}-get-name${i > 0 ? '-' + String(i) : ''}`;
|
|
57
|
-
const synthSymbol = {
|
|
58
|
-
type: type_1.RType.Symbol,
|
|
59
|
-
info: { ...retrieve.info, id: synthId },
|
|
60
|
-
content: resolvedName,
|
|
61
|
-
lexeme: literal ? retrieve.lexeme : resolvedName,
|
|
62
|
-
location
|
|
63
|
-
};
|
|
64
|
-
data.completeAst.idMap.set(synthId, synthSymbol);
|
|
65
|
-
targets.push(synthSymbol);
|
|
66
|
-
}
|
|
67
|
-
if (!literal && targets.length > 0) {
|
|
68
|
-
nameExpression = firstArg;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
66
|
+
const retrieve = (0, unpack_argument_1.unpackNonameArg)(args[0]);
|
|
67
|
+
const targets = retrieve === undefined ? [] : synthesizeTargets(retrieve, name, rootId, data);
|
|
71
68
|
if (targets.length === 0) {
|
|
72
69
|
logger_1.dataflowLogger.warn(`symbol access with ${identifier_1.Identifier.toString(name.content)} has no resolvable name argument, skipping`);
|
|
73
70
|
// dynamic, unresolvable name: reached-but-unknown rather than dropped
|
|
74
71
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default', hasUnknownSideEffect: true }).information;
|
|
75
72
|
}
|
|
76
|
-
|
|
73
|
+
/* a computed name is an expression the call evaluates and reads */
|
|
74
|
+
const nameExpression = r_string_1.RString.is(retrieve) ? undefined : args[0];
|
|
77
75
|
/* resolve in the custom environment if one was found, else the global one.
|
|
78
76
|
* Pass remaining original args (e.g. envir=e) so they appear as Use vertices in the graph. */
|
|
79
77
|
const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({
|
|
@@ -81,7 +79,7 @@ function processGet(name, args, rootId, data, config = {}) {
|
|
|
81
79
|
args: [
|
|
82
80
|
...(0, make_argument_1.wrapArgumentsUnnamed)(targets, data.completeAst.idMap),
|
|
83
81
|
...(nameExpression !== undefined ? [nameExpression] : []),
|
|
84
|
-
...
|
|
82
|
+
...args.slice(1)
|
|
85
83
|
],
|
|
86
84
|
rootId,
|
|
87
85
|
data: resolution ? resolution.envirData : data,
|
|
@@ -98,7 +96,7 @@ function processGet(name, args, rootId, data, config = {}) {
|
|
|
98
96
|
}
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
|
-
const nameExpressionProcessed = nameExpression
|
|
99
|
+
const nameExpressionProcessed = nameExpression === undefined ? undefined : processedArguments[targets.length];
|
|
102
100
|
if (nameExpressionProcessed) {
|
|
103
101
|
information.graph.addEdge(rootId, nameExpressionProcessed.entryPoint, edge_1.EdgeType.Reads);
|
|
104
102
|
}
|
|
@@ -3,39 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.processIfThenElse = processIfThenElse;
|
|
4
4
|
const processor_1 = require("../../../../../processor");
|
|
5
5
|
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
6
|
+
const resolve_1 = require("../../../../../eval/resolve/resolve");
|
|
6
7
|
const known_call_handling_1 = require("../known-call-handling");
|
|
7
8
|
const common_1 = require("../common");
|
|
8
9
|
const unpack_argument_1 = require("../argument/unpack-argument");
|
|
9
10
|
const logger_1 = require("../../../../../logger");
|
|
10
11
|
const edge_1 = require("../../../../../graph/edge");
|
|
11
12
|
const control_flow_1 = require("../../../../control-flow");
|
|
13
|
+
const built_in_ambient_state_1 = require("./built-in-ambient-state");
|
|
12
14
|
const append_1 = require("../../../../../environments/append");
|
|
13
15
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
14
16
|
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
15
17
|
const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
|
|
16
18
|
const apply_kill_1 = require("../../../../../environments/apply-kill");
|
|
19
|
+
const model_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/model");
|
|
20
|
+
const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
17
21
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
18
22
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
19
23
|
function getArguments(config, args) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
[condArg, thenArg, otherwiseArg] = args.map(e => (0, unpack_argument_1.unpackArg)(e));
|
|
37
|
-
}
|
|
38
|
-
return { condArg, thenArg, otherwiseArg };
|
|
24
|
+
if (!config?.args) {
|
|
25
|
+
return args.map(e => (0, unpack_argument_1.unpackArg)(e));
|
|
26
|
+
}
|
|
27
|
+
const params = {
|
|
28
|
+
[config.args.cond]: 'cond',
|
|
29
|
+
[config.args.yes]: 'yes',
|
|
30
|
+
[config.args.no]: 'no',
|
|
31
|
+
'...': '...'
|
|
32
|
+
};
|
|
33
|
+
const argMaps = function_semantics_1.FunctionSemantics.call.match.toSpec((0, common_1.convertFnArguments)(args), params);
|
|
34
|
+
return ['cond', 'yes', 'no'].map(k => (0, unpack_argument_1.unpackArg)(r_argument_1.RArgument.getWithId(args, argMaps.get(k)?.[0])));
|
|
35
|
+
}
|
|
36
|
+
/** Whether `id` may run again in the same frame, as part of a loop not left through a function definition. */
|
|
37
|
+
function withinLoop(id, idMap) {
|
|
38
|
+
const enclosing = model_1.RNode.findEnclosing(id, idMap, n => r_function_definition_1.RFunctionDefinition.is(n) || model_1.RLoopConstructs.is(n));
|
|
39
|
+
return enclosing !== undefined && !r_function_definition_1.RFunctionDefinition.is(idMap.get(enclosing));
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Processes an if-then-else built-in function call.
|
|
@@ -47,78 +48,78 @@ function processIfThenElse(name, args, rootId, data, config) {
|
|
|
47
48
|
logger_1.dataflowLogger.warn(`If-then-else ${identifier_1.Identifier.toString(name.content)} has something different from 2 or 3 arguments, skipping`);
|
|
48
49
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
|
|
49
50
|
}
|
|
50
|
-
const
|
|
51
|
+
const [condArg, thenArg, otherwiseArg] = getArguments(config, args);
|
|
51
52
|
if (condArg === undefined || thenArg === undefined) {
|
|
52
53
|
logger_1.dataflowLogger.warn(`If-then-else ${identifier_1.Identifier.toString(name.content)} has empty condition or then case in ${JSON.stringify(args)}, skipping`);
|
|
53
54
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
|
|
54
55
|
}
|
|
55
56
|
const cond = (0, processor_1.processDataflowFor)(condArg, data);
|
|
56
|
-
if (control_flow_1.ControlFlow.alwaysExits(cond)) {
|
|
57
|
+
if (control_flow_1.ControlFlow.alwaysExits(cond, data.cds)) {
|
|
57
58
|
logger_1.dataflowLogger.warn(`If-then-else ${rootId} forces exit in condition, skipping rest`);
|
|
58
59
|
return cond;
|
|
59
60
|
}
|
|
60
61
|
const originalDependency = data.cds?.slice();
|
|
61
|
-
// currently we update the cd afterward :sweat:
|
|
62
62
|
data = { ...data, environment: cond.environment };
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const values = node_value_1.NodeValue.setOf(condArg?.info.id, data);
|
|
63
|
+
/* within a loop, what the condition reads may change after it, for the next iteration */
|
|
64
|
+
const mayChange = !(0, resolve_1.onlyLiterals)(condArg) && withinLoop(rootId, data.completeAst.idMap);
|
|
65
|
+
const values = mayChange ? undefined : node_value_1.NodeValue.setOf(condArg.info.id, data);
|
|
67
66
|
/*
|
|
68
67
|
* `ifelse` and its relatives are ordinary functions, so R evaluates every argument whatever the condition
|
|
69
68
|
* says; only the `if` keyword leaves a branch unevaluated and may therefore be resolved away here.
|
|
70
69
|
*/
|
|
71
70
|
const branchesAreLazy = config?.args === undefined;
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!conditionIsAlwaysTrue) {
|
|
80
|
-
makeThenMaybe = true;
|
|
81
|
-
}
|
|
71
|
+
const conditionIsAlways = (value) => branchesAreLazy && (values?.elements.every(d => d.type === 'logical' && d.value === value) ?? false);
|
|
72
|
+
const alwaysFalse = conditionIsAlways(false);
|
|
73
|
+
const alwaysTrue = conditionIsAlways(true);
|
|
74
|
+
const uncertain = !alwaysFalse && !alwaysTrue;
|
|
75
|
+
const then = alwaysFalse ? undefined : (0, processor_1.processDataflowFor)(thenArg, data);
|
|
76
|
+
if (then?.entryPoint) {
|
|
77
|
+
then.graph.addEdge(rootId, then.entryPoint, edge_1.EdgeType.Returns);
|
|
82
78
|
}
|
|
83
79
|
let otherwise;
|
|
84
|
-
|
|
85
|
-
if (otherwiseArg !== undefined && !conditionIsAlwaysTrue) {
|
|
80
|
+
if (otherwiseArg !== undefined && !alwaysTrue) {
|
|
86
81
|
data = { ...data, cds: originalDependency?.slice() };
|
|
87
82
|
otherwise = (0, processor_1.processDataflowFor)(otherwiseArg, data);
|
|
88
83
|
if (otherwise.entryPoint) {
|
|
89
84
|
otherwise.graph.addEdge(rootId, otherwise.entryPoint, edge_1.EdgeType.Returns);
|
|
90
85
|
}
|
|
91
|
-
if (!conditionIsAlwaysFalse) {
|
|
92
|
-
makeOtherwiseMaybe = true;
|
|
93
|
-
}
|
|
94
86
|
}
|
|
95
|
-
const nextGraph = cond.graph.mergeWith(then?.graph).mergeWith(otherwise?.graph);
|
|
96
|
-
const thenEnvironment = then
|
|
87
|
+
const nextGraph = cond.graph.mergeWith(then?.graph, true, true).mergeWith(otherwise?.graph, true, true);
|
|
88
|
+
const thenEnvironment = (then ?? cond).environment;
|
|
89
|
+
const otherwiseEnvironment = (otherwise ?? cond).environment;
|
|
97
90
|
// if there is no "else" case, we have to recover whatever we had before as it may be not executed
|
|
98
91
|
let finalEnvironment;
|
|
99
|
-
if (
|
|
100
|
-
finalEnvironment =
|
|
92
|
+
if (alwaysFalse) {
|
|
93
|
+
finalEnvironment = otherwiseEnvironment;
|
|
101
94
|
}
|
|
102
|
-
else if (
|
|
95
|
+
else if (alwaysTrue) {
|
|
103
96
|
finalEnvironment = thenEnvironment;
|
|
104
97
|
}
|
|
105
98
|
else {
|
|
106
|
-
finalEnvironment = (0, append_1.appendEnvironment)(thenEnvironment,
|
|
99
|
+
finalEnvironment = (0, append_1.appendEnvironment)(thenEnvironment, otherwiseEnvironment);
|
|
107
100
|
}
|
|
108
101
|
const whenTrue = { id: rootId, when: true };
|
|
109
102
|
const whenFalse = { id: rootId, when: false };
|
|
110
103
|
const cdTrue = [whenTrue];
|
|
111
104
|
const cdFalse = [whenFalse];
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
if (uncertain && then !== undefined) {
|
|
106
|
+
(0, built_in_ambient_state_1.makeAmbientWritesMaybe)(then.environment, cond.environment, finalEnvironment, cdTrue);
|
|
107
|
+
}
|
|
108
|
+
if (uncertain && otherwise !== undefined) {
|
|
109
|
+
(0, built_in_ambient_state_1.makeAmbientWritesMaybe)(otherwise.environment, cond.environment, finalEnvironment, cdFalse);
|
|
110
|
+
}
|
|
111
|
+
/*
|
|
112
|
+
* we assign all branch references with a maybe marker; we do not merge even if they appear in both branches
|
|
113
|
+
* because the maybe links will refer to different ids
|
|
114
|
+
*/
|
|
115
|
+
const maybe = (refs, cds, includeDefs = false) => uncertain ? (0, reference_to_maybe_1.makeAllMaybe)(refs, nextGraph, finalEnvironment, includeDefs, cds) : refs ?? [];
|
|
116
|
+
const ingoing = cond.in.concat(maybe(then?.in, cdTrue), maybe(otherwise?.in, cdFalse), cond.unknownReferences, maybe(then?.unknownReferences, cdTrue), maybe(otherwise?.unknownReferences, cdFalse));
|
|
117
|
+
const outgoing = cond.out.concat(maybe(then?.out, cdTrue, true), maybe(otherwise?.out, cdFalse, true));
|
|
117
118
|
// a branch-local removal only happens maybe; apply it here since the branch-environment merge cannot represent it
|
|
118
119
|
let killed;
|
|
119
120
|
if (then?.kill?.length || otherwise?.kill?.length) {
|
|
120
|
-
killed = (
|
|
121
|
-
.concat(
|
|
121
|
+
killed = (uncertain ? (0, apply_kill_1.makeKillsMaybe)(then?.kill, cdTrue) : then?.kill ?? [])
|
|
122
|
+
.concat(uncertain ? (0, apply_kill_1.makeKillsMaybe)(otherwise?.kill, cdFalse) : otherwise?.kill ?? []);
|
|
122
123
|
finalEnvironment = (0, apply_kill_1.applyKills)(finalEnvironment, killed);
|
|
123
124
|
}
|
|
124
125
|
(0, common_1.patchFunctionCall)({
|
|
@@ -131,26 +132,26 @@ function processIfThenElse(name, args, rootId, data, config) {
|
|
|
131
132
|
});
|
|
132
133
|
// as an if always evaluates its condition, we add a 'reads'-edge
|
|
133
134
|
nextGraph.addEdge(rootId, cond.entryPoint, edge_1.EdgeType.Reads);
|
|
134
|
-
const exitPoints = (then?.exitPoints ?? []).map(e => ({ ...e, cds:
|
|
135
|
-
.concat((otherwise?.exitPoints ?? []).map(e => ({ ...e, cds:
|
|
135
|
+
const exitPoints = (then?.exitPoints ?? []).map(e => ({ ...e, cds: uncertain ? [...data.cds ?? [], { id: rootId, when: true }] : e.cds }))
|
|
136
|
+
.concat((otherwise?.exitPoints ?? []).map(e => ({ ...e, cds: uncertain ? [...data.cds ?? [], { id: rootId, when: false }] : e.cds })));
|
|
137
|
+
const entryOrJoin = (branch) => branch ? control_flow_1.ControlFlow.entryOf(branch) : rootId;
|
|
136
138
|
const reachesJoin = then === undefined || otherwise === undefined
|
|
137
139
|
|| control_flow_1.ControlFlow.canComplete(then) || control_flow_1.ControlFlow.canComplete(otherwise);
|
|
138
|
-
if (
|
|
140
|
+
if (alwaysTrue) {
|
|
139
141
|
/* the condition is known, so there is no decision left to make and only one way to go */
|
|
140
|
-
control_flow_1.ControlFlow.continuesWith(nextGraph, cond,
|
|
142
|
+
control_flow_1.ControlFlow.continuesWith(nextGraph, cond, entryOrJoin(then));
|
|
141
143
|
}
|
|
142
|
-
else if (
|
|
143
|
-
control_flow_1.ControlFlow.continuesWith(nextGraph, cond,
|
|
144
|
+
else if (alwaysFalse) {
|
|
145
|
+
control_flow_1.ControlFlow.continuesWith(nextGraph, cond, entryOrJoin(otherwise));
|
|
144
146
|
}
|
|
145
147
|
else {
|
|
146
|
-
control_flow_1.ControlFlow.branchesTo(nextGraph, cond,
|
|
147
|
-
control_flow_1.ControlFlow.branchesTo(nextGraph, cond,
|
|
148
|
-
}
|
|
149
|
-
if (then !== undefined) {
|
|
150
|
-
control_flow_1.ControlFlow.continuesWith(nextGraph, then, rootId);
|
|
148
|
+
control_flow_1.ControlFlow.branchesTo(nextGraph, cond, entryOrJoin(then), whenTrue);
|
|
149
|
+
control_flow_1.ControlFlow.branchesTo(nextGraph, cond, entryOrJoin(otherwise), whenFalse);
|
|
151
150
|
}
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
for (const branch of [then, otherwise]) {
|
|
152
|
+
if (branch !== undefined) {
|
|
153
|
+
control_flow_1.ControlFlow.continuesWith(nextGraph, branch, rootId);
|
|
154
|
+
}
|
|
154
155
|
}
|
|
155
156
|
return {
|
|
156
157
|
unknownReferences: [],
|