@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.
Files changed (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processTryCatch = processTryCatch;
4
+ exports.orderRaisingBodies = orderRaisingBodies;
4
5
  const condition_handlers_1 = require("../../../../../fn/condition-handlers");
5
6
  const function_semantics_1 = require("../../../../../fn/function-semantics");
6
7
  const info_1 = require("../../../../../info");
7
8
  const known_call_handling_1 = require("../known-call-handling");
8
9
  const control_flow_1 = require("../../../../control-flow");
10
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
9
11
  const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
12
+ const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
10
13
  const logger_1 = require("../../../../../logger");
11
14
  const linker_1 = require("../../../../linker");
12
15
  const vertex_1 = require("../../../../../graph/vertex");
@@ -20,6 +23,17 @@ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-
20
23
  const apply_kill_1 = require("../../../../../environments/apply-kill");
21
24
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
22
25
  const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
26
+ const built_in_ambient_state_1 = require("./built-in-ambient-state");
27
+ const query_fn_props_1 = require("../../../../../environments/query-fn-props");
28
+ const built_in_props_1 = require("../../../../../environments/built-in-props");
29
+ const model_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/model");
30
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
31
+ const r_expression_list_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
32
+ const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
33
+ const resolve_helper_1 = require("../../../../../environments/resolve-helper");
34
+ const append_1 = require("../../../../../environments/append");
35
+ const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
36
+ const frame_reflection_1 = require("../../../../../fn/frame-reflection");
23
37
  /**
24
38
  * Process a built-in try-catch or similar handler.
25
39
  */
@@ -29,51 +43,58 @@ function processTryCatch(name, args, rootId, data, config) {
29
43
  logger_1.dataflowLogger.warn(`TryCatch Handler ${identifier_1.Identifier.toString(name.content)} does not have 1 argument, skipping`);
30
44
  return res.information;
31
45
  }
32
- // artificial ids :)
33
- const params = {
46
+ const { error, finally: cleanupName } = config.handlers;
47
+ const argMaps = function_semantics_1.FunctionSemantics.call.match.toSpec(res.callArgs, {
34
48
  [config.block]: 'block',
35
- '...': '...'
36
- };
37
- if (config.handlers.error) {
38
- params[config.handlers.error] = 'error';
39
- }
40
- if (config.handlers.finally) {
41
- params[config.handlers.finally] = 'finally';
42
- }
43
- // only remove exit points from the block
44
- const argMaps = function_semantics_1.FunctionSemantics.call.match.toSpec(res.callArgs, params);
49
+ '...': '...',
50
+ ...error ? { [error]: 'error' } : {},
51
+ ...cleanupName ? { [cleanupName]: 'finally' } : {}
52
+ });
45
53
  const info = res.information;
46
54
  const blockArg = new Set(argMaps.get('block'));
47
55
  const errorArg = new Set(argMaps.get('error'));
48
56
  const finallyArg = new Set(argMaps.get('finally'));
49
57
  const dots = new Set(argMaps.get('...'));
50
- const otherHandlerArg = new Set(res.callArgs
58
+ const otherHandlerArg = res.callArgs
51
59
  .filter((a) => graph_1.FunctionArgument.isNamed(a) && dots.has(a.nodeId))
52
- .map(a => a.nodeId));
60
+ .map(a => a.nodeId);
53
61
  /* handlers are matched by the class of the condition, so a call naming none for an error lets it out:
54
62
  `tryCatch(stop("x"), warning = ...)` throws, and so does one with nothing but a `finally`.
55
63
  A construct declaring no handler parameter at all, as `try` does, catches whatever arrives. */
56
- const catchesError = (config.aborts ?? true) && (config.handlers.error === undefined || (0, condition_handlers_1.namesAnErrorHandler)(args));
57
- // only take those exit points from the block
58
- // check whether blockArg has *always* happening exceptions, if so we do not constrain the error handler
64
+ const catchesError = (config.aborts ?? true) && (error === undefined || (0, condition_handlers_1.namesAnErrorHandler)(args));
65
+ const raising = [];
66
+ if (catchesError) {
67
+ const targetsOf = (n) => [data.environment, info.environment]
68
+ .flatMap(env => resolve_helper_1.Resolve.byNameAndType(n, env, identifier_1.ReferenceType.Function) ?? []);
69
+ const order = raisingOrder(info.graph, (0, query_fn_props_1.builtInLookup)(data.ctx), { rootId, targetsOf });
70
+ for (const arg of res.processedArguments) {
71
+ const block = arg && blockArg.has(arg.entryPoint) ? data.completeAst.idMap.get(arg.entryPoint) : undefined;
72
+ if (arg && block) {
73
+ const raised = (0, built_in_ambient_state_1.errorsOfWarnings)(block, info.environment, info.graph, data);
74
+ for (const site of raised) {
75
+ info.graph.addEdge(site.nodeId, rootId, edge_1.EdgeType.Reads);
76
+ }
77
+ arg.exitPoints = arg.exitPoints.concat(raised);
78
+ raising.push(...order(block, []));
79
+ }
80
+ }
81
+ }
82
+ /* if the block raises an error in every case, the error handler is not constrained by it */
59
83
  const blockErrorExitPoints = [];
60
84
  const errorExitPoints = [];
61
85
  info.exitPoints = res.processedArguments.flatMap(arg => {
62
86
  if (!arg) {
63
87
  return [];
64
88
  }
65
- // this calls error and finally args
66
- if (finallyArg.has(arg.entryPoint)) {
67
- return handleFdefAsCalled(arg.entryPoint, info.graph, arg.exitPoints, undefined);
89
+ else if (finallyArg.has(arg.entryPoint)) {
90
+ return exitPointsOfHandler(arg.entryPoint, info.graph) ?? arg.exitPoints;
68
91
  }
69
92
  else if (errorArg.has(arg.entryPoint)) {
70
- errorExitPoints.push(...getExitPoints(info.graph.getVertex(arg.entryPoint), info.graph) ?? []);
93
+ /* a `return` within the handler only leaves the handler, its value is the one of the construct */
94
+ const handlerExits = exitPointsOfHandler(arg.entryPoint, info.graph) ?? [];
95
+ errorExitPoints.push(...handlerExits.map(e => e.type === 1 /* ExitPointType.Return */ ? { ...e, type: 0 /* ExitPointType.Default */ } : e));
71
96
  }
72
- if (!blockArg.has(arg.entryPoint)) {
73
- // not killing other args
74
- return arg.exitPoints;
75
- }
76
- if (!catchesError) {
97
+ if (!blockArg.has(arg.entryPoint) || !catchesError) {
77
98
  return arg.exitPoints;
78
99
  }
79
100
  blockErrorExitPoints.push(...arg.exitPoints.filter(ep => ep.type === 4 /* ExitPointType.Error */).flatMap(a => a.cds));
@@ -89,10 +110,7 @@ function processTryCatch(name, args, rootId, data, config) {
89
110
  }
90
111
  for (const e of [...errorArg, ...otherHandlerArg]) {
91
112
  info.graph.addEdge(rootId, e, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
92
- const linkTo = promoteCallToFunction(rootId, e, info, data);
93
- if (linkTo) {
94
- info.graph.addEdge(e, linkTo, edge_1.EdgeType.Calls);
95
- }
113
+ promoteCallToFunction(rootId, e, info, data);
96
114
  }
97
115
  for (const f of finallyArg) {
98
116
  info.graph.addEdge(rootId, f, edge_1.EdgeType.Calls);
@@ -119,20 +137,21 @@ function processTryCatch(name, args, rootId, data, config) {
119
137
  * raises is caught here as well, so it reaches the call rather than leaving it.
120
138
  */
121
139
  info.cfgExit = rootId;
140
+ const entryOfArg = (of) => {
141
+ const arg = res.processedArguments.find(a => a !== undefined && of.has(a.entryPoint));
142
+ return arg && control_flow_1.ControlFlow.entryOf(arg);
143
+ };
122
144
  /*
123
145
  * An error the block raises lands on the handler when there is one, and the `finally` follows it, which the
124
146
  * arguments being in sequence already says. Without either, the error simply arrives at the call.
147
+ * R runs `finally` whatever leaves the block, so a jump reaches it on its way out just as an error does.
125
148
  */
126
- const handler = res.processedArguments.find(arg => arg !== undefined && errorArg.has(arg.entryPoint));
127
- const cleanup = res.processedArguments.find(arg => arg !== undefined && finallyArg.has(arg.entryPoint));
128
- const caughtAt = handler !== undefined ? control_flow_1.ControlFlow.entryOf(handler)
129
- : cleanup === undefined ? rootId : control_flow_1.ControlFlow.entryOf(cleanup);
130
- /* R runs `finally` whatever leaves the block, so a jump reaches it on its way out just as an error does */
131
- const cleanupEntry = cleanup !== undefined ? control_flow_1.ControlFlow.entryOf(cleanup) : undefined;
149
+ const cleanupEntry = entryOfArg(finallyArg);
150
+ const caughtAt = entryOfArg(errorArg) ?? cleanupEntry ?? rootId;
132
151
  if (cleanupEntry !== undefined) {
133
152
  /* and it leaves through the call, so whatever claims the jump links to where the cleanup ends, not to the
134
153
  jump itself, which would let control out without running it */
135
- info.exitPoints = info.exitPoints.map(e => JumpExitPoints.includes(e.type) ? { ...e, nodeId: rootId } : e);
154
+ info.exitPoints = info.exitPoints.map(e => JumpExitPoints.includes(e.type) ? (0, info_1.leaveThrough)(e, rootId) : e);
136
155
  }
137
156
  for (const arg of res.processedArguments) {
138
157
  if (arg === undefined || errorArg.has(arg.entryPoint) || finallyArg.has(arg.entryPoint)) {
@@ -147,118 +166,158 @@ function processTryCatch(name, args, rootId, data, config) {
147
166
  }
148
167
  }
149
168
  }
150
- if (escaping.length === 0 && escapingKills === undefined) {
169
+ const mayAbort = raising.length > 0;
170
+ if (!mayAbort && escaping.length === 0 && escapingKills === undefined) {
151
171
  return info;
152
172
  }
173
+ for (const id of raising) {
174
+ const call = info.graph.getVertex(id);
175
+ if (call !== undefined) {
176
+ call.cds = [...call.cds ?? [], { id: rootId, when: true }];
177
+ }
178
+ }
179
+ const environment = mayAbort ? (0, append_1.appendEnvironment)(data.environment, info.environment) : info.environment;
153
180
  return {
154
181
  ...info,
155
- out: info.out.concat(escaping),
156
- environment: (0, apply_kill_1.applyKills)(info.environment, escapingKills),
182
+ out: info.out.concat(mayAbort ? (0, reference_to_maybe_1.makeAllMaybe)(escaping, info.graph, environment, true) : escaping),
183
+ environment: (0, apply_kill_1.applyKills)(environment, escapingKills),
157
184
  kill: escapingKills
158
185
  };
159
186
  }
187
+ /** Orders the raising calls in every body a block catching errors may run, once per definition and after linking bound all calls. */
188
+ function orderRaisingBodies(graph, idMap, ctx) {
189
+ const ordered = new Set();
190
+ const reach = (node) => {
191
+ for (const id of r_function_definition_1.RFunctionDefinition.is(node) ? [node.info.id] : (0, frame_reflection_1.calledDefinitions)(graph, node.info.id)) {
192
+ const definition = idMap.get(id);
193
+ if (!ordered.has(id) && r_function_definition_1.RFunctionDefinition.is(definition)) {
194
+ ordered.add(id);
195
+ order(definition.body, []);
196
+ }
197
+ }
198
+ };
199
+ const order = raisingOrder(graph, (0, query_fn_props_1.builtInLookup)(ctx), { reach });
200
+ for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
201
+ const call = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Try) ? idMap.get(id) : undefined;
202
+ for (const arg of r_function_call_1.RFunctionCall.is(call) ? call.arguments : []) {
203
+ if (arg !== r_function_call_1.EmptyArgument && !(0, frame_reflection_1.hasEdgeOfType)(graph, id, arg.info.id, edge_1.EdgeType.Calls)) {
204
+ model_1.RNode.visitAst(arg, n => {
205
+ reach(n);
206
+ return r_function_definition_1.RFunctionDefinition.is(n);
207
+ });
208
+ }
209
+ }
210
+ }
211
+ }
212
+ /** Makes every later call read the earlier ones that may raise, and those read the construct `rootId`; returns the raising ones. */
213
+ function raisingOrder(graph, lookup, { rootId, targetsOf, reach }) {
214
+ const raises = (node) => {
215
+ const vertex = graph.getVertex(node.info.id);
216
+ const name = vertex_1.DfgVertex.isFunctionCall(vertex) ? vertex.name : r_function_call_1.RFunctionCall.is(node) ? node.named ? node.functionName.content : undefined : r_access_1.RAccess.is(node) ? node.operator : node.lexeme;
217
+ if (name === undefined || built_in_props_1.CallProps.hasAny(lookup(name), built_in_props_1.CallProp.Throws) || (rootId !== undefined && (0, frame_reflection_1.hasEdgeOfType)(graph, node.info.id, rootId, edge_1.EdgeType.Reads))) {
218
+ return true;
219
+ }
220
+ else if (vertex_1.DfgVertex.isFunctionCall(vertex)) {
221
+ return !vertex.onlyBuiltin;
222
+ }
223
+ const targets = targetsOf?.(name) ?? [];
224
+ return targets.length === 0 || targets.some(t => !node_id_1.NodeId.isBuiltIn(t.nodeId));
225
+ };
226
+ const order = (node, before) => {
227
+ reach?.(node);
228
+ if (r_function_definition_1.RFunctionDefinition.is(node)) {
229
+ return [];
230
+ }
231
+ else if (r_expression_list_1.RExpressionList.is(node)) {
232
+ const sites = [];
233
+ let current = before;
234
+ for (const child of node.children) {
235
+ const raised = order(child, current);
236
+ current = raised.length > 0 ? raised : current;
237
+ sites.push(...raised);
238
+ }
239
+ return sites;
240
+ }
241
+ /* what a later iteration runs follows what an earlier one may raise, which the loop carries */
242
+ const loop = model_1.RLoopConstructs.is(node);
243
+ const sites = model_1.RNode.directChildren(node).flatMap(child => child === r_function_call_1.EmptyArgument ? [] : order(child, loop ? [...before, node.info.id] : before));
244
+ if (!CallTypes.has(node.type)) {
245
+ return sites;
246
+ }
247
+ const raising = raises(node);
248
+ for (const site of [...before, ...rootId !== undefined && raising ? [rootId] : [], ...loop ? sites : []]) {
249
+ graph.addEdge(node.info.id, site, edge_1.EdgeType.Reads);
250
+ }
251
+ return raising ? [...sites, node.info.id] : sites;
252
+ };
253
+ return order;
254
+ }
255
+ const CallTypes = new Set([type_1.RType.FunctionCall, type_1.RType.BinaryOp, type_1.RType.UnaryOp, type_1.RType.Access, type_1.RType.Pipe, type_1.RType.IfThenElse, type_1.RType.ForLoop, type_1.RType.WhileLoop, type_1.RType.RepeatLoop, type_1.RType.Break, type_1.RType.Next]);
160
256
  /** the exits that leave the construct for a destination of their own, which `finally` still runs before */
161
257
  const JumpExitPoints = [2 /* ExitPointType.Break */, 3 /* ExitPointType.Next */, 1 /* ExitPointType.Return */];
258
+ /** Links the handler `arg` of the construct `call` as called: a symbol becomes a call, an anonymous function gets a synthetic one. */
162
259
  function promoteCallToFunction(call, arg, info, data) {
163
- let functionId = undefined;
164
- let functionName = undefined;
165
- let anonymous = false;
166
- const argNode = data.completeAst.idMap.get(arg);
167
- if (!argNode) {
168
- return undefined;
169
- }
170
- const val = r_argument_1.RArgument.is(argNode) ? (0, unpack_argument_1.unpackArg)(argNode) : argNode;
171
- if (!val) {
172
- return undefined;
173
- }
260
+ const val = r_argument_1.RArgument.valueOf(data.completeAst.idMap.get(arg));
174
261
  if (r_symbol_1.RSymbol.is(val)) {
175
- functionId = val.info.id;
176
- functionName = val.content;
177
- }
178
- else if (r_function_definition_1.RFunctionDefinition.is(val)) {
179
- anonymous = true;
180
- functionId = val.info.id;
181
- functionName = `${unnamed_call_handling_1.UnnamedFunctionCallPrefix}${functionId}`;
182
- }
183
- if (functionName === undefined || functionId === undefined) {
184
- return undefined;
185
- }
186
- if (anonymous) {
187
- info.graph.addEdge(arg, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
188
- const syntheticCall = 'anon-' + functionId;
189
- info.graph.addVertex({
190
- tag: vertex_1.VertexType.FunctionCall,
191
- id: syntheticCall,
192
- environment: data.environment,
193
- name: functionName,
194
- onlyBuiltin: false,
195
- cds: data.cds,
196
- args: [],
197
- origin: [built_in_proc_name_1.BuiltInProcName.Function]
198
- }, data.ctx.env.cleanEnv);
199
- info.graph.addEdge(arg, syntheticCall, edge_1.EdgeType.Calls);
200
- info.graph.addEdge(syntheticCall, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
201
- info.graph.addEdge(call, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
202
- const handler = info.graph.getVertex(functionId);
203
- if (vertex_1.DfgVertex.isFunctionDefinition(handler)) {
204
- linker_1.ClosureRefs.resolveOpenIngoing(info.graph, syntheticCall, handler, data.environment);
205
- }
206
- // we did the linking
207
- return undefined;
208
- }
209
- else {
210
262
  info.graph.updateToFunctionCall({
211
263
  tag: vertex_1.VertexType.FunctionCall,
212
- id: functionId,
213
- name: functionName,
264
+ id: val.info.id,
265
+ name: val.content,
214
266
  args: [],
215
267
  environment: data.environment,
216
268
  onlyBuiltin: false,
217
269
  cds: data.cds,
218
270
  origin: [built_in_proc_name_1.BuiltInProcName.Function]
219
271
  });
220
- return functionId;
272
+ info.graph.addEdge(arg, val.info.id, edge_1.EdgeType.Calls);
273
+ return;
221
274
  }
222
- }
223
- function getExitPoints(vertex, graph) {
224
- if (!vertex) {
225
- return undefined;
275
+ if (!r_function_definition_1.RFunctionDefinition.is(val)) {
276
+ return;
277
+ }
278
+ const functionId = val.info.id;
279
+ info.graph.addEdge(arg, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
280
+ const syntheticCall = 'anon-' + functionId;
281
+ info.graph.addVertex({
282
+ tag: vertex_1.VertexType.FunctionCall,
283
+ id: syntheticCall,
284
+ environment: data.environment,
285
+ name: `${unnamed_call_handling_1.UnnamedFunctionCallPrefix}${functionId}`,
286
+ onlyBuiltin: false,
287
+ cds: data.cds,
288
+ args: [],
289
+ origin: [built_in_proc_name_1.BuiltInProcName.Function]
290
+ }, data.ctx.env.cleanEnv);
291
+ info.graph.addEdge(arg, syntheticCall, edge_1.EdgeType.Calls);
292
+ info.graph.addEdge(syntheticCall, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
293
+ info.graph.addEdge(call, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
294
+ const handler = info.graph.getVertex(functionId);
295
+ if (vertex_1.DfgVertex.isFunctionDefinition(handler)) {
296
+ linker_1.ClosureRefs.resolveOpenIngoing(info.graph, syntheticCall, handler, data.environment);
226
297
  }
298
+ }
299
+ function exitPointsOfHandler(id, graph) {
300
+ const vertex = graph.getVertex(id);
227
301
  if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
228
302
  return vertex.exitPoints;
229
303
  }
230
304
  // we assumed named argument
231
- const n = graph.idMap?.get(vertex.id);
232
- if (!n) {
233
- return undefined;
234
- }
235
- if (r_argument_1.RArgument.is(n) && r_function_definition_1.RFunctionDefinition.is(n.value)) {
236
- const fdefV = graph.getVertex(n.value.info.id);
237
- if (vertex_1.DfgVertex.isFunctionDefinition(fdefV)) {
238
- return fdefV.exitPoints;
239
- }
240
- }
241
- return undefined;
242
- }
243
- function handleFdefAsCalled(nodeId, graph, def, constrain) {
244
- const v = graph.getVertex(nodeId);
245
- const e = getExitPoints(v, graph);
246
- return e ? constrainExitPoints(e, constrain) : def;
305
+ const node = vertex === undefined ? undefined : graph.idMap?.get(id);
306
+ const definition = r_argument_1.RArgument.is(node) && r_function_definition_1.RFunctionDefinition.is(node.value) ? graph.getVertex(node.value.info.id) : undefined;
307
+ return vertex_1.DfgVertex.isFunctionDefinition(definition) ? definition.exitPoints : undefined;
247
308
  }
309
+ /** Constrains the given exit points to happen only when every node in `constrain` is reached (`when: true`). */
248
310
  function constrainExitPoints(exitPoints, constrain) {
249
- if (!constrain || constrain.size === 0) {
311
+ if (constrain.size === 0) {
250
312
  return exitPoints;
251
313
  }
252
- // append constrains with true
253
314
  const cds = Array.from(constrain, id => ({ id, when: true }));
254
315
  return exitPoints.map(e => {
255
316
  if (e.cds) {
256
317
  e.cds.push(...cds);
257
318
  return e;
258
319
  }
259
- else {
260
- return { ...e, cds: cds };
261
- }
320
+ return { ...e, cds };
262
321
  });
263
322
  }
264
323
  //# sourceMappingURL=built-in-try-catch.js.map
@@ -4,7 +4,5 @@ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/
4
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
- /**
8
- * Process a while loop like `while(cond) { ... }`.
9
- */
7
+ /** Process a while loop like `while(cond) { ... }`. */
10
8
  export declare function processWhileLoop<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
@@ -16,9 +16,8 @@ const apply_kill_1 = require("../../../../../environments/apply-kill");
16
16
  const append_1 = require("../../../../../environments/append");
17
17
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
18
18
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
19
- /**
20
- * Process a while loop like `while(cond) { ... }`.
21
- */
19
+ const built_in_ambient_state_1 = require("./built-in-ambient-state");
20
+ /** Process a while loop like `while(cond) { ... }`. */
22
21
  function processWhileLoop(name, args, rootId, data) {
23
22
  if (args.length !== 2 || r_argument_1.RArgument.isEmpty(args[1])) {
24
23
  logger_1.dataflowLogger.warn(`While-Loop ${identifier_1.Identifier.toString(name.content)} does not have 2 arguments, skipping`);
@@ -31,14 +30,13 @@ function processWhileLoop(name, args, rootId, data) {
31
30
  }
32
31
  const nameId = name.info.id;
33
32
  const origEnv = data.environment;
34
- // we should defer this to the abstract interpretation
35
33
  const values = node_value_1.NodeValue.setOf(unpackedArgs[0]?.info.id, data);
36
- const conditionIsAlwaysFalse = values?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
37
- //We don't care about the body if it never executes
34
+ const conditionIsAlways = (value) => values?.elements.every(d => d.type === 'logical' && d.value === value) ?? false;
35
+ const conditionIsAlwaysFalse = conditionIsAlways(false);
36
+ /* the body is left out if it never runs */
38
37
  if (conditionIsAlwaysFalse) {
39
38
  unpackedArgs.pop();
40
39
  }
41
- /* we inject the cf-dependency of the while-loop after the condition */
42
40
  const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({
43
41
  name,
44
42
  args: unpackedArgs,
@@ -49,11 +47,11 @@ function processWhileLoop(name, args, rootId, data) {
49
47
  origin: built_in_proc_name_1.BuiltInProcName.WhileLoop
50
48
  });
51
49
  const [condition, body] = processedArguments;
52
- // If the condition is always false, we don't include the body
50
+ const graph = information.graph;
53
51
  if (condition !== undefined && conditionIsAlwaysFalse) {
54
- information.graph.addEdge(nameId, condition.entryPoint, edge_1.EdgeType.Reads);
52
+ graph.addEdge(nameId, condition.entryPoint, edge_1.EdgeType.Reads);
55
53
  /* the body never runs, but the condition is still evaluated before the loop is left */
56
- control_flow_1.ControlFlow.branchesTo(information.graph, condition, rootId, { id: nameId, when: false });
54
+ control_flow_1.ControlFlow.branchesTo(graph, condition, rootId, { id: nameId, when: false });
57
55
  return {
58
56
  unknownReferences: [],
59
57
  in: [{ nodeId: nameId, name: name.lexeme, cds: data.cds, type: identifier_1.ReferenceType.Function }],
@@ -62,51 +60,50 @@ function processWhileLoop(name, args, rootId, data) {
62
60
  cfgEntry: control_flow_1.ControlFlow.entryOf(condition),
63
61
  cfgExit: rootId,
64
62
  exitPoints: [],
65
- graph: information.graph,
63
+ graph,
66
64
  environment: information.environment,
67
65
  hooks: condition.hooks
68
66
  };
69
67
  }
70
- const conditionIsAlwaysTrue = values?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
71
68
  (0, assert_1.guard)(condition !== undefined && body !== undefined, () => `While-Loop ${identifier_1.Identifier.toString(name.content)} has no condition or body, impossible!`);
72
- const originalDependency = data.cds;
73
- if (control_flow_1.ControlFlow.alwaysExits(condition)) {
69
+ if (control_flow_1.ControlFlow.alwaysExits(condition, data.cds)) {
74
70
  logger_1.dataflowLogger.warn(`While-Loop ${rootId} forces exit in condition, skipping rest`);
75
- information.graph.addEdge(nameId, condition.entryPoint, edge_1.EdgeType.Reads);
71
+ graph.addEdge(nameId, condition.entryPoint, edge_1.EdgeType.Reads);
76
72
  return condition;
77
73
  }
78
74
  const whenTrue = { id: nameId, when: true };
79
75
  const cdTrue = [whenTrue];
80
76
  const bodyRead = body.in.concat(body.unknownReferences);
81
77
  (0, reference_to_maybe_1.applyCdsToAllInGraphButConstants)(body.graph, bodyRead, cdTrue);
82
- const remainingInputs = (0, linker_1.linkInputs)(bodyRead, information.environment, condition.in.concat(condition.unknownReferences), information.graph, true);
78
+ const remainingInputs = (0, linker_1.linkInputs)(bodyRead, information.environment, condition.in.concat(condition.unknownReferences), graph, true);
83
79
  (0, reference_to_maybe_1.applyCdToReferences)(body.out, cdTrue);
84
- (0, linker_1.linkCircularRedefinitionsWithinALoop)(information.graph, (0, linker_1.produceNameSharedIdMap)((0, linker_1.findNonLocalReads)(information.graph, new Set(condition.in.map(i => i.nodeId)))), body.out, body.environment);
85
- (0, linker_1.reapplyLoopExitPoints)(body.exitPoints, body.in.concat(body.out, body.unknownReferences), information.graph);
86
- // as the while-loop always evaluates its condition
87
- information.graph.addEdge(nameId, condition.entryPoint, edge_1.EdgeType.Reads);
88
- const graph = information.graph;
80
+ const nonLocalReads = (0, linker_1.findNonLocalReads)(graph, new Set(condition.in.map(i => i.nodeId)));
81
+ (0, linker_1.linkCircularRedefinitionsWithinALoop)(graph, (0, linker_1.produceNameSharedIdMap)(nonLocalReads), body.out, body.environment);
82
+ (0, built_in_ambient_state_1.linkAmbientStateWithinLoop)(graph, bodyRead.concat(condition.in, condition.unknownReferences), body);
83
+ (0, linker_1.reapplyLoopExitPoints)(body.exitPoints, body.in.concat(body.out, body.unknownReferences), graph);
84
+ /* as the while-loop always evaluates its condition */
85
+ graph.addEdge(nameId, condition.entryPoint, edge_1.EdgeType.Reads);
89
86
  const conditionEntry = control_flow_1.ControlFlow.entryOf(condition);
90
87
  control_flow_1.ControlFlow.branchesTo(graph, condition, control_flow_1.ControlFlow.entryOf(body), whenTrue);
91
88
  control_flow_1.ControlFlow.branchesTo(graph, condition, rootId, { id: nameId, when: false });
92
89
  control_flow_1.ControlFlow.continuesWith(graph, body, conditionEntry);
93
90
  control_flow_1.ControlFlow.jumpsTo(graph, body, 3 /* ExitPointType.Next */, conditionEntry);
94
91
  control_flow_1.ControlFlow.jumpsTo(graph, body, 2 /* ExitPointType.Break */, rootId);
95
- // the body's environment carries its side effects (e.g. a `library()` call), which must survive the loop
92
+ /* the body's environment carries its side effects (e.g. a `library()` call), the original one stays unless the body surely runs */
93
+ const conditionIsAlwaysTrue = conditionIsAlways(true);
96
94
  const bodyEnvironment = (0, append_1.appendEnvironment)(information.environment, body.environment);
97
- // as we do not know whether the loop executes at all, we merge the original environment back in (the body may never run)
98
95
  const loopEnvironment = conditionIsAlwaysTrue ? bodyEnvironment : (0, append_1.appendEnvironment)(origEnv, bodyEnvironment);
99
- // unless the loop always runs, a body removal only happens maybe; apply it as the merge cannot represent it
96
+ /* unless the loop always runs, a body removal only happens maybe; apply it as the merge cannot represent it */
100
97
  const loopKill = body.kill?.length ? (conditionIsAlwaysTrue ? body.kill : (0, apply_kill_1.makeKillsMaybe)(body.kill, cdTrue)) : undefined;
101
98
  return {
102
99
  unknownReferences: [],
103
- in: [{ nodeId: nameId, name: name.lexeme, cds: originalDependency, type: identifier_1.ReferenceType.Function }, ...remainingInputs],
100
+ in: [{ nodeId: nameId, name: name.lexeme, cds: data.cds, type: identifier_1.ReferenceType.Function }, ...remainingInputs],
104
101
  out: condition.out.concat(body.out),
105
102
  entryPoint: nameId,
106
103
  cfgEntry: conditionEntry,
107
104
  cfgExit: rootId,
108
105
  exitPoints: (0, info_1.filterOutLoopExitPoints)(body.exitPoints),
109
- graph: information.graph,
106
+ graph,
110
107
  environment: loopKill ? (0, apply_kill_1.applyKills)(loopEnvironment, loopKill) : loopEnvironment,
111
108
  hooks: condition.hooks.concat(body.hooks),
112
109
  kill: loopKill,
@@ -2,7 +2,7 @@ import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import { DataflowInformation } from '../../../../../info';
3
3
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
4
  import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
- import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
5
+ import { 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
  /**
8
8
  * Processes `with(data, expr)` and `within(data, expr)`.
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processWithEnv = processWithEnv;
4
+ const vertex_1 = require("../../../../../graph/vertex");
4
5
  const function_semantics_1 = require("../../../../../fn/function-semantics");
5
6
  const processor_1 = require("../../../../../processor");
6
7
  const info_1 = require("../../../../../info");
7
8
  const known_call_handling_1 = require("../known-call-handling");
9
+ const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
10
+ const resolve_helper_1 = require("../../../../../environments/resolve-helper");
11
+ const define_1 = require("../../../../../environments/define");
8
12
  const identifier_1 = require("../../../../../environments/identifier");
9
13
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
10
14
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
@@ -42,7 +46,8 @@ function processWithEnv(name, args, rootId, data) {
42
46
  }
43
47
  // prefer R's real `base::with` signature from the database, falling back to the known formals when it is absent
44
48
  // use the call's own name (`with` or `within`) qualified to base, so each gets its real signature
45
- const bound = function_semantics_1.FunctionSemantics.call.match.toNames(args, (0, built_in_envir_utils_1.signatureParamNames)(data, identifier_1.Identifier.make(identifier_1.Identifier.getName(name.content), "base" /* PkgName.Base */), withParamsFallback));
49
+ const qualifiedName = identifier_1.Identifier.make(identifier_1.Identifier.getName(name.content), "base" /* PkgName.Base */);
50
+ const bound = function_semantics_1.FunctionSemantics.call.match.toNames(args, (0, built_in_envir_utils_1.signatureParamNames)(data, qualifiedName, withParamsFallback));
46
51
  const dataArg = bound.get('data');
47
52
  const exprArg = bound.get('expr');
48
53
  // when we cannot resolve the data to a tracked environment, `expr` is still data-masked: its symbols name
@@ -54,16 +59,16 @@ function processWithEnv(name, args, rootId, data) {
54
59
  const envirResolution = (0, built_in_envir_utils_1.envirOf)(envirRouting);
55
60
  if (!envirResolution) {
56
61
  const fallback = markAsMaskedFallback(name, args, rootId, data);
57
- (0, built_in_envir_utils_1.unknownIfAmbiguous)(envirRouting, fallback, rootId);
62
+ /* only a definition or a call we cannot see into (a closure of `data`) can write to a `data` we cannot pin down */
63
+ if ((!fallback.graph.verticesOfType(vertex_1.VertexType.VariableDefinition).next().done || callsOpaque(fallback.graph, rootId)) && !(0, built_in_envir_utils_1.unknownIfAmbiguous)(envirRouting, fallback, rootId)) {
64
+ return mayWriteInto(dataArg.value, fallback, rootId, data);
65
+ }
58
66
  return fallback;
59
67
  }
60
68
  const pipedData = (0, common_1.isPipedArgument)(dataArg, rootId, data);
61
69
  const dfDataArg = pipedData ? info_1.DataflowInformation.initialize(rootId, data) : (0, processor_1.processDataflowFor)(dataArg.value, data);
62
70
  /* evaluate expr in the resolved env's scope so variable lookup uses envState */
63
- const dfExpr = (0, processor_1.processDataflowFor)(exprArg.value, {
64
- ...data,
65
- environment: envirResolution.envirData.environment
66
- });
71
+ const dfExpr = (0, processor_1.processDataflowFor)(exprArg.value, { ...data, environment: envirResolution.envirData.environment });
67
72
  /*
68
73
  * processSymbol puts symbol uses in unknownReferences without creating reads edges.
69
74
  * Explicitly link expr's unknown references against the envState so reads edges are
@@ -83,14 +88,15 @@ function processWithEnv(name, args, rootId, data) {
83
88
  const merged = dfDataArg.graph.mergeWith(dfExpr.graph);
84
89
  const cfgEntry = control_flow_1.ControlFlow.inSequence(merged, pipedData ? [dfExpr] : [dfDataArg, dfExpr], rootId);
85
90
  const ingoing = dfDataArg.in.concat(dfExpr.in, dfDataArg.unknownReferences, remainingFromExpr, /* unresolved expr refs propagate to outer scope */ [{ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function }]);
86
- const isWithin = identifier_1.Identifier.getName(name.content) === 'within';
87
91
  merged.addEdge(rootId, envirResolution.envirNodeId, edge_1.EdgeType.Reads);
88
92
  let resultEnv = data.environment;
89
- if (isWithin && dfExpr.out.length > 0) {
93
+ /* an environment is not copied, so the writes of `with` stay in it just like those of `within` */
94
+ if (dfExpr.out.length > 0) {
95
+ keepCallFor(dfExpr.out, merged, rootId);
90
96
  const tempResult = { ...dfExpr, environment: data.environment, graph: merged };
91
97
  resultEnv = (0, built_in_envir_utils_1.routeWrittenToEnvir)(tempResult, envirResolution, rootId, data.environment).environment;
92
98
  }
93
- return {
99
+ const result = {
94
100
  hooks: dfDataArg.hooks.concat(dfExpr.hooks),
95
101
  environment: resultEnv,
96
102
  exitPoints: dfDataArg.exitPoints.concat(dfExpr.exitPoints),
@@ -102,5 +108,24 @@ function processWithEnv(name, args, rootId, data) {
102
108
  out: [], /* writes are inside envState, not directly in outer scope */
103
109
  unknownReferences: []
104
110
  };
111
+ return callsOpaque(dfExpr.graph, rootId) ? mayWriteInto(dataArg.value, result, rootId, data) : result;
112
+ }
113
+ /** whether `graph` holds a call other than `rootId` that may run a closure of the data, like `with(e, inc())` */
114
+ function callsOpaque(graph, rootId) {
115
+ return graph.verticesOfType(vertex_1.VertexType.FunctionCall).some(([id, vertex]) => id !== rootId && !vertex.onlyBuiltin);
116
+ }
117
+ /** `data` may be an untracked environment `expr` writes into, so later reads of its variable see the call as a maybe redefinition. */
118
+ function mayWriteInto(dataNode, result, rootId, data) {
119
+ keepCallFor(result.out, result.graph, rootId);
120
+ if (!r_symbol_1.RSymbol.is(dataNode) || resolve_helper_1.Resolve.byNameAndType(dataNode.content, result.environment, identifier_1.ReferenceType.Variable) === undefined) {
121
+ return result;
122
+ }
123
+ return { ...result, environment: (0, define_1.define)({ name: dataNode.content, nodeId: rootId, definedAt: rootId, type: identifier_1.ReferenceType.Variable, cds: data.cds }, false, result.environment) };
124
+ }
125
+ /** a write in `expr` only happens because the call evaluates it */
126
+ function keepCallFor(written, graph, rootId) {
127
+ for (const w of written) {
128
+ graph.addEdge(w.nodeId, rootId, edge_1.EdgeType.Reads);
129
+ }
105
130
  }
106
131
  //# sourceMappingURL=built-in-with.js.map
@@ -25,7 +25,7 @@ export declare function reResolveOpenReferences(this: void, graph: DataflowGraph
25
25
  * @returns the enriched top-level environment and whether it grew (so the extractor can re-link and re-run to a fixpoint).
26
26
  * @useInstead {@link Dataflow.sideEffects.propagateTransitive}
27
27
  */
28
- export declare function propagateTransitiveSideEffects(this: void, graph: DataflowGraph, environment: REnvironmentInformation, ctx: FlowrAnalyzerContext, defined?: Set<string>): {
28
+ export declare function propagateTransitiveSideEffects(this: void, graph: DataflowGraph, environment: REnvironmentInformation, ctx: FlowrAnalyzerContext, defined?: Set<string>, open?: readonly IdentifierReference[]): {
29
29
  environment: REnvironmentInformation;
30
30
  grew: boolean;
31
31
  escapedNames: Set<string>;