@eagleoutice/flowr 2.15.10 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +23 -26
  2. package/abstract-interpretation/data-frame/arguments.js +11 -7
  3. package/control-flow/happens-before.d.ts +5 -0
  4. package/control-flow/happens-before.js +48 -34
  5. package/control-flow/useless-loop.d.ts +1 -1
  6. package/control-flow/useless-loop.js +29 -42
  7. package/dataflow/environments/built-in-props.d.ts +9 -0
  8. package/dataflow/environments/built-in-props.js +25 -19
  9. package/dataflow/environments/built-in.d.ts +2 -2
  10. package/dataflow/environments/built-in.js +41 -77
  11. package/dataflow/environments/default-builtin-config.d.ts +181 -29
  12. package/dataflow/environments/default-builtin-config.js +38 -24
  13. package/dataflow/environments/environment.d.ts +6 -4
  14. package/dataflow/environments/environment.js +54 -121
  15. package/dataflow/environments/identifier.d.ts +4 -2
  16. package/dataflow/environments/identifier.js +23 -69
  17. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  18. package/dataflow/environments/reference-to-maybe.js +23 -51
  19. package/dataflow/environments/resolve-by-name.js +37 -76
  20. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  21. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  22. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  23. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  24. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  25. package/dataflow/eval/resolve/resolve.js +23 -14
  26. package/dataflow/extractor.js +176 -59
  27. package/dataflow/fn/class-declaration.d.ts +8 -2
  28. package/dataflow/fn/class-declaration.js +96 -97
  29. package/dataflow/fn/exceptions-of-function.js +68 -37
  30. package/dataflow/fn/frame-reflection.d.ts +12 -4
  31. package/dataflow/fn/frame-reflection.js +51 -41
  32. package/dataflow/fn/function-props.js +15 -33
  33. package/dataflow/fn/function-semantics.d.ts +11 -3
  34. package/dataflow/fn/function-semantics.js +6 -0
  35. package/dataflow/fn/higher-order-function.js +13 -17
  36. package/dataflow/fn/strict-function.d.ts +13 -0
  37. package/dataflow/fn/strict-function.js +285 -122
  38. package/dataflow/graph/call-graph.d.ts +7 -6
  39. package/dataflow/graph/call-graph.js +35 -46
  40. package/dataflow/graph/graph.d.ts +6 -1
  41. package/dataflow/graph/graph.js +57 -66
  42. package/dataflow/info.d.ts +8 -1
  43. package/dataflow/info.js +24 -30
  44. package/dataflow/internal/control-flow.d.ts +31 -4
  45. package/dataflow/internal/control-flow.js +61 -39
  46. package/dataflow/internal/linker.d.ts +15 -9
  47. package/dataflow/internal/linker.js +253 -241
  48. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
  49. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +446 -78
  50. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  51. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
  52. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
  53. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
  54. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  55. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  56. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
  57. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
  58. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +289 -251
  59. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  60. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  61. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  62. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
  63. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  64. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
  65. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  66. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  67. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  68. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
  69. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
  70. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
  72. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  73. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
  74. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  75. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  76. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  77. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  78. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  79. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
  80. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  81. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  82. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  83. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  84. package/dataflow/internal/process/functions/call/common.d.ts +1 -3
  85. package/dataflow/internal/process/functions/call/common.js +36 -76
  86. package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
  87. package/dataflow/internal/process/functions/call/deferred.js +54 -57
  88. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  89. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  90. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  91. package/dataflow/internal/process/functions/call/named-call-handling.js +35 -21
  92. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  93. package/dataflow/internal/process/functions/call/quoted.js +162 -172
  94. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  95. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  96. package/dataflow/internal/process/process-symbol.js +3 -6
  97. package/dataflow/internal/program-order.d.ts +26 -0
  98. package/dataflow/internal/program-order.js +49 -0
  99. package/documentation/wiki-setup.js +23 -0
  100. package/linter/linter-rules.d.ts +17 -8
  101. package/linter/rules/absolute-path.js +63 -87
  102. package/linter/rules/file-path-validity.d.ts +4 -2
  103. package/linter/rules/file-path-validity.js +114 -80
  104. package/linter/rules/namespace-access.js +21 -33
  105. package/linter/rules/naming-convention.d.ts +1 -1
  106. package/linter/rules/naming-convention.js +60 -48
  107. package/linter/rules/network-functions.js +11 -7
  108. package/linter/rules/no-leaked-credentials.js +15 -18
  109. package/linter/rules/problematic-inputs.d.ts +2 -1
  110. package/linter/rules/problematic-inputs.js +39 -59
  111. package/linter/rules/roxygen-arguments.d.ts +9 -4
  112. package/linter/rules/roxygen-arguments.js +29 -48
  113. package/linter/rules/seeded-randomness.d.ts +7 -4
  114. package/linter/rules/seeded-randomness.js +128 -89
  115. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  116. package/linter/rules/stop-with-call-arg.js +25 -22
  117. package/linter/rules/unclosed-connection.js +31 -24
  118. package/linter/rules/undefined-symbol.d.ts +4 -6
  119. package/linter/rules/undefined-symbol.js +58 -75
  120. package/linter/rules/unescaped-arguments.js +18 -44
  121. package/linter/rules/unused-definition.d.ts +6 -0
  122. package/linter/rules/unused-definition.js +105 -145
  123. package/linter/rules/unused-import.d.ts +3 -0
  124. package/linter/rules/unused-import.js +25 -43
  125. package/package.json +5 -2
  126. package/project/flowr-analyzer.js +6 -2
  127. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  128. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  129. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  130. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  131. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +16 -41
  132. package/queries/base-query-format.js +1 -2
  133. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  134. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  135. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  136. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  137. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  138. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  139. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  140. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  141. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  142. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  143. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  144. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  145. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  146. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  147. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  148. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  149. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  150. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  151. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  152. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  153. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  154. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  155. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  156. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  157. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  158. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  159. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  160. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  161. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  162. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  163. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  164. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  165. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  166. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  167. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  168. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  169. package/r-bridge/shell.js +6 -0
  170. package/search/search-executor/search-enrichers.js +25 -37
  171. package/slicing/static/slice-call.d.ts +4 -3
  172. package/slicing/static/slice-call.js +56 -88
  173. package/slicing/static/static-slicer.js +115 -79
  174. package/slicing/static/visiting-queue.d.ts +4 -6
  175. package/slicing/static/visiting-queue.js +9 -13
  176. package/util/proc.js +2 -1
  177. package/util/r-base-packages.d.ts +2 -0
  178. package/util/r-base-packages.js +23 -13
  179. package/util/text/playground-link.d.ts +12 -3
  180. package/util/text/playground-link.js +18 -27
  181. 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 { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
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 => r_argument_1.RArgument.isEmpty(arg) ? undefined : (0, unpack_argument_1.unpackArg)(arg))
30
- .map(value => value !== undefined ? (0, built_in_envir_utils_1.resolveConstantString)(value, data) : undefined);
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 firstArg = args.length >= 1 ? args[0] : undefined;
46
- const retrieve = firstArg !== undefined && firstArg !== r_function_call_1.EmptyArgument
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
- const remainingArgs = args.slice(1);
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
- ...remainingArgs
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 !== undefined ? processedArguments[targets.length] : undefined;
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
- let condArg;
21
- let thenArg;
22
- let otherwiseArg;
23
- if (config?.args) {
24
- const params = {
25
- [config.args.cond]: 'cond',
26
- [config.args.yes]: 'yes',
27
- [config.args.no]: 'no',
28
- '...': '...'
29
- };
30
- const argMaps = function_semantics_1.FunctionSemantics.call.match.toSpec((0, common_1.convertFnArguments)(args), params);
31
- condArg = (0, unpack_argument_1.unpackArg)(r_argument_1.RArgument.getWithId(args, argMaps.get('cond')?.[0]));
32
- thenArg = (0, unpack_argument_1.unpackArg)(r_argument_1.RArgument.getWithId(args, argMaps.get('yes')?.[0]));
33
- otherwiseArg = (0, unpack_argument_1.unpackArg)(r_argument_1.RArgument.getWithId(args, argMaps.get('no')?.[0]));
34
- }
35
- else {
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 { condArg, thenArg, otherwiseArg } = getArguments(config, args);
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
- let then;
64
- let makeThenMaybe = false;
65
- // we should defer this to the abstract interpretation
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 conditionIsAlwaysFalse = branchesAreLazy && (values?.elements.every(d => d.type === 'logical' && d.value === false) ?? false);
73
- const conditionIsAlwaysTrue = branchesAreLazy && (values?.elements.every(d => d.type === 'logical' && d.value === true) ?? false);
74
- if (!conditionIsAlwaysFalse) {
75
- then = (0, processor_1.processDataflowFor)(thenArg, data);
76
- if (then.entryPoint) {
77
- then.graph.addEdge(rootId, then.entryPoint, edge_1.EdgeType.Returns);
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
- let makeOtherwiseMaybe = false;
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?.environment ?? cond.environment;
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 (conditionIsAlwaysFalse) {
100
- finalEnvironment = otherwise ? otherwise.environment : cond.environment;
92
+ if (alwaysFalse) {
93
+ finalEnvironment = otherwiseEnvironment;
101
94
  }
102
- else if (conditionIsAlwaysTrue) {
95
+ else if (alwaysTrue) {
103
96
  finalEnvironment = thenEnvironment;
104
97
  }
105
98
  else {
106
- finalEnvironment = (0, append_1.appendEnvironment)(thenEnvironment, otherwise ? otherwise.environment : cond.environment);
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
- // again within an if-then-else we consider all actives to be read
113
- const ingoing = cond.in.concat(makeThenMaybe ? (0, reference_to_maybe_1.makeAllMaybe)(then?.in, nextGraph, finalEnvironment, false, cdTrue) : then?.in ?? [], makeOtherwiseMaybe ? (0, reference_to_maybe_1.makeAllMaybe)(otherwise?.in, nextGraph, finalEnvironment, false, cdFalse) : otherwise?.in ?? [], cond.unknownReferences, makeThenMaybe ? (0, reference_to_maybe_1.makeAllMaybe)(then?.unknownReferences, nextGraph, finalEnvironment, false, cdTrue) : then?.unknownReferences ?? [], makeOtherwiseMaybe ? (0, reference_to_maybe_1.makeAllMaybe)(otherwise?.unknownReferences, nextGraph, finalEnvironment, false, cdFalse) : otherwise?.unknownReferences ?? []);
114
- // we assign all with a maybe marker
115
- // we do not merge even if they appear in both branches because the maybe links will refer to different ids
116
- const outgoing = cond.out.concat((makeThenMaybe ? (0, reference_to_maybe_1.makeAllMaybe)(then?.out, nextGraph, finalEnvironment, true, cdTrue) : then?.out ?? []), (makeOtherwiseMaybe ? (0, reference_to_maybe_1.makeAllMaybe)(otherwise?.out, nextGraph, finalEnvironment, true, cdFalse) : otherwise?.out ?? []));
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 = (makeThenMaybe ? (0, apply_kill_1.makeKillsMaybe)(then?.kill, cdTrue) : then?.kill ?? [])
121
- .concat(makeOtherwiseMaybe ? (0, apply_kill_1.makeKillsMaybe)(otherwise?.kill, cdFalse) : otherwise?.kill ?? []);
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: makeThenMaybe ? [...data.cds ?? [], { id: rootId, when: true }] : e.cds }))
135
- .concat((otherwise?.exitPoints ?? []).map(e => ({ ...e, cds: makeOtherwiseMaybe ? [...data.cds ?? [], { id: rootId, when: false }] : 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 (conditionIsAlwaysTrue) {
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, then ? control_flow_1.ControlFlow.entryOf(then) : rootId);
142
+ control_flow_1.ControlFlow.continuesWith(nextGraph, cond, entryOrJoin(then));
141
143
  }
142
- else if (conditionIsAlwaysFalse) {
143
- control_flow_1.ControlFlow.continuesWith(nextGraph, cond, otherwise ? control_flow_1.ControlFlow.entryOf(otherwise) : rootId);
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, then ? control_flow_1.ControlFlow.entryOf(then) : rootId, whenTrue);
147
- control_flow_1.ControlFlow.branchesTo(nextGraph, cond, otherwise ? control_flow_1.ControlFlow.entryOf(otherwise) : rootId, whenFalse);
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
- if (otherwise !== undefined) {
153
- control_flow_1.ControlFlow.continuesWith(nextGraph, otherwise, rootId);
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: [],