@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
|
@@ -18,6 +18,34 @@ const identifier_1 = require("../../../../../environments/identifier");
|
|
|
18
18
|
const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
|
|
19
19
|
const apply_kill_1 = require("../../../../../environments/apply-kill");
|
|
20
20
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
21
|
+
const built_in_ambient_state_1 = require("./built-in-ambient-state");
|
|
22
|
+
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
23
|
+
const r_binary_op_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
24
|
+
const vertex_1 = require("../../../../../graph/vertex");
|
|
25
|
+
const ScalarTypes = new Set(['interval', 'number', 'string', 'logical']);
|
|
26
|
+
/** a value R iterates over at least once, `NULL` and empty vectors are the ones it does not */
|
|
27
|
+
function hasElement(value) {
|
|
28
|
+
return value.type === 'vector' ? Array.isArray(value.elements) && value.elements.length > 0 : ScalarTypes.has(value.type);
|
|
29
|
+
}
|
|
30
|
+
/** whether the node certainly holds a value and every value it may hold satisfies `holds` */
|
|
31
|
+
function alwaysHolds(node, data, holds) {
|
|
32
|
+
const values = node_value_1.NodeValue.setOf(node.info.id, data)?.elements;
|
|
33
|
+
return values !== undefined && values.length > 0 && values.every(holds);
|
|
34
|
+
}
|
|
35
|
+
/** `a:b` always has an element or fails, unless both sides are factors, which a plain value is not */
|
|
36
|
+
function isNonEmptyRange(vector, entry, data) {
|
|
37
|
+
if (!r_binary_op_1.RBinaryOp.is(vector) || vector.operator !== ':') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (!vertex_1.DfgVertex.hasOrigin(entry.graph.getVertex(vector.info.id), built_in_proc_name_1.BuiltInProcName.Default)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return [vector.lhs, vector.rhs].some(side => alwaysHolds(side, data, v => v.type !== 'vector' && hasElement(v)));
|
|
44
|
+
}
|
|
45
|
+
/** whether a for-loop over `vector` certainly runs its body at least once */
|
|
46
|
+
function iteratesAtLeastOnce(vector, entry, data) {
|
|
47
|
+
return isNonEmptyRange(vector, entry, data) || alwaysHolds(vector, data, hasElement);
|
|
48
|
+
}
|
|
21
49
|
/**
|
|
22
50
|
* Processes a for-loop call: `for(<variable> in <vector>) <body>`
|
|
23
51
|
* desugared as:
|
|
@@ -31,45 +59,53 @@ function processForLoop(name, args, rootId, data) {
|
|
|
31
59
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
|
|
32
60
|
}
|
|
33
61
|
const [variableArg, vectorArg, bodyArg] = args.map(e => (0, unpack_argument_1.unpackNonameArg)(e));
|
|
34
|
-
|
|
62
|
+
/* merged back in case the loop never runs */
|
|
35
63
|
const origEnv = data.environment;
|
|
36
64
|
(0, assert_1.guard)(variableArg !== undefined && vectorArg !== undefined && bodyArg !== undefined, () => `For-Loop ${JSON.stringify(args)} has missing arguments! Bad!`);
|
|
37
65
|
const vector = (0, processor_1.processDataflowFor)(vectorArg, data);
|
|
38
|
-
if (control_flow_1.ControlFlow.alwaysExits(vector)) {
|
|
66
|
+
if (control_flow_1.ControlFlow.alwaysExits(vector, data.cds)) {
|
|
39
67
|
logger_1.dataflowLogger.warn(`For-Loop ${rootId} forces exit in vector, skipping rest`);
|
|
40
68
|
return vector;
|
|
41
69
|
}
|
|
70
|
+
/* resolved before the loop variable is bound, as it may share the name of what the vector reads */
|
|
71
|
+
const nonEmpty = iteratesAtLeastOnce(vectorArg, vector, data);
|
|
42
72
|
const variable = (0, processor_1.processDataflowFor)(variableArg, data);
|
|
43
|
-
// this should not be able to exit always!
|
|
44
|
-
const originalDependency = data.cds;
|
|
45
73
|
let headEnvironments = (0, overwrite_1.overwriteEnvironment)(vector.environment, variable.environment);
|
|
46
74
|
/* only the vector's references and entry point are read past this, its graph is not */
|
|
47
75
|
const headGraph = variable.graph.mergeWith(vector.graph, true, true);
|
|
48
76
|
const writtenVariable = variable.unknownReferences.concat(variable.in);
|
|
49
|
-
const writtenIds = new Set();
|
|
50
77
|
for (const write of writtenVariable) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
78
|
+
const definition = {
|
|
79
|
+
...write,
|
|
80
|
+
definedAt: name.info.id,
|
|
81
|
+
type: identifier_1.ReferenceType.Unknown,
|
|
82
|
+
value: [vectorArg.info.id],
|
|
83
|
+
iterated: true
|
|
84
|
+
};
|
|
85
|
+
headEnvironments = (0, define_1.define)(definition, false, headEnvironments);
|
|
54
86
|
}
|
|
55
87
|
data.environment = headEnvironments;
|
|
56
88
|
const body = (0, processor_1.processDataflowFor)(bodyArg, data);
|
|
57
|
-
const outEnvironment = (0, append_1.appendEnvironment)(headEnvironments, body.environment);
|
|
58
89
|
const cd = [{ id: name.info.id, when: true }];
|
|
59
90
|
const bodyRefs = body.in.concat(body.unknownReferences);
|
|
60
91
|
(0, reference_to_maybe_1.applyCdsToAllInGraphButConstants)(body.graph, bodyRefs, cd);
|
|
61
92
|
/* likewise the body's, what is taken from it afterwards are its references, exit points and hooks */
|
|
62
93
|
const nextGraph = headGraph.mergeWith(body.graph, true, true);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const nameIdShares = (0, linker_1.produceNameSharedIdMap)((0, linker_1.findNonLocalReads)(nextGraph, writtenIds));
|
|
94
|
+
/* the reads with a non-local resolve may be affected by a circular redefinition */
|
|
95
|
+
const nameIdShares = (0, linker_1.produceNameSharedIdMap)((0, linker_1.findNonLocalReads)(nextGraph, new Set(writtenVariable.map(w => w.nodeId))));
|
|
66
96
|
for (const write of writtenVariable) {
|
|
67
97
|
nextGraph.addEdge(write.nodeId, vector.entryPoint, edge_1.EdgeType.DefinedBy);
|
|
68
98
|
nextGraph.setDefinitionOfVertex(write, [vector.entryPoint]);
|
|
69
99
|
}
|
|
70
|
-
|
|
100
|
+
/* a `break` or `next` may cut the first iteration short */
|
|
101
|
+
const once = nonEmpty && !body.exitPoints.some(e => e.type === 2 /* ExitPointType.Break */ || e.type === 3 /* ExitPointType.Next */);
|
|
102
|
+
/* a body that certainly runs defines as definitely as the code around the loop */
|
|
103
|
+
if (!once) {
|
|
104
|
+
(0, reference_to_maybe_1.applyCdToReferences)(body.out, cd);
|
|
105
|
+
}
|
|
71
106
|
const outgoing = variable.out.concat(writtenVariable, body.out);
|
|
72
107
|
(0, linker_1.linkCircularRedefinitionsWithinALoop)(nextGraph, nameIdShares, body.out, body.environment);
|
|
108
|
+
const ambientReads = (0, built_in_ambient_state_1.linkAmbientStateWithinLoop)(nextGraph, bodyRefs, body);
|
|
73
109
|
/* the loop variable is bound by the head whenever the body runs, so reads of it are not ingoing */
|
|
74
110
|
const loopVariables = new Set(writtenVariable.map(w => w.name));
|
|
75
111
|
const bodyReadsOfOthers = [...nameIdShares.entries()].filter(([n]) => !loopVariables.has(n)).flatMap(([, refs]) => refs);
|
|
@@ -78,36 +114,32 @@ function processForLoop(name, args, rootId, data) {
|
|
|
78
114
|
nextGraph,
|
|
79
115
|
rootId,
|
|
80
116
|
name,
|
|
81
|
-
data
|
|
117
|
+
data,
|
|
82
118
|
argumentProcessResult: [variable, vector, body],
|
|
83
119
|
origin: built_in_proc_name_1.BuiltInProcName.ForLoop
|
|
84
120
|
});
|
|
85
|
-
/* mark the last argument as nse */
|
|
86
121
|
nextGraph.addEdge(rootId, body.entryPoint, edge_1.EdgeType.NonStandardEvaluation);
|
|
87
|
-
// as the for-loop always evaluates its condition
|
|
88
122
|
nextGraph.addEdge(name.info.id, vector.entryPoint, edge_1.EdgeType.Reads);
|
|
89
|
-
const bodyEntry = control_flow_1.ControlFlow.entryOf(body);
|
|
90
123
|
const variableEntry = control_flow_1.ControlFlow.entryOf(variable);
|
|
91
124
|
control_flow_1.ControlFlow.continuesWith(nextGraph, vector, variableEntry);
|
|
92
|
-
control_flow_1.ControlFlow.branchesTo(nextGraph, variable,
|
|
125
|
+
control_flow_1.ControlFlow.branchesTo(nextGraph, variable, control_flow_1.ControlFlow.entryOf(body), cd[0]);
|
|
93
126
|
control_flow_1.ControlFlow.branchesTo(nextGraph, variable, rootId, { id: cd[0].id, when: false });
|
|
94
127
|
control_flow_1.ControlFlow.continuesWith(nextGraph, body, variableEntry);
|
|
95
128
|
control_flow_1.ControlFlow.jumpsTo(nextGraph, body, 3 /* ExitPointType.Next */, variableEntry);
|
|
96
129
|
control_flow_1.ControlFlow.jumpsTo(nextGraph, body, 2 /* ExitPointType.Break */, rootId);
|
|
97
|
-
// the body
|
|
98
|
-
const loopKill = body.kill?.length ? (0, apply_kill_1.makeKillsMaybe)(body.kill, cd) : undefined;
|
|
99
|
-
const loopEnvironment = (0, append_1.appendEnvironment)(origEnv,
|
|
130
|
+
// unless the body certainly runs, a removal within it only happens maybe; apply it as the merge cannot represent it
|
|
131
|
+
const loopKill = body.kill?.length ? (once ? body.kill : (0, apply_kill_1.makeKillsMaybe)(body.kill, cd)) : undefined;
|
|
132
|
+
const loopEnvironment = once ? body.environment : (0, append_1.appendEnvironment)(origEnv, (0, append_1.appendEnvironment)(headEnvironments, body.environment));
|
|
100
133
|
return {
|
|
101
134
|
unknownReferences: [],
|
|
102
|
-
|
|
103
|
-
in: [{ nodeId: rootId, name: name.content, cds:
|
|
135
|
+
/* we only want those not bound by a local variable */
|
|
136
|
+
in: [{ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function }, ...vector.unknownReferences, ...bodyReadsOfOthers, ...ambientReads],
|
|
104
137
|
out: outgoing,
|
|
105
138
|
graph: nextGraph,
|
|
106
139
|
entryPoint: name.info.id,
|
|
107
140
|
cfgEntry: control_flow_1.ControlFlow.entryOf(vector),
|
|
108
141
|
cfgExit: rootId,
|
|
109
142
|
exitPoints: (0, info_1.filterOutLoopExitPoints)(body.exitPoints),
|
|
110
|
-
// if we can not be sure that the for-loop runs once, we have to merge back the original environment, as the body may never execute
|
|
111
143
|
environment: loopKill ? (0, apply_kill_1.applyKills)(loopEnvironment, loopKill) : loopEnvironment,
|
|
112
144
|
hooks: variable.hooks.concat(vector.hooks, body.hooks),
|
|
113
145
|
kill: loopKill,
|