@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
@@ -10,19 +10,13 @@ const environment_1 = require("../../../../../environments/environment");
10
10
  const built_in_library_1 = require("./built-in-library");
11
11
  const define_1 = require("../../../../../environments/define");
12
12
  const vertex_1 = require("../../../../../graph/vertex");
13
+ const program_order_1 = require("../../../../program-order");
13
14
  const resolve_helper_1 = require("../../../../../environments/resolve-helper");
14
- /**
15
- * The function-definition vertices a `call` resolves to (via {@link EdgeType.Calls}).
16
- */
17
- function calledDefinitions(graph, call) {
18
- const targets = [];
19
- for (const [target, edge] of graph.edgesFrom(call)) {
20
- if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(target))) {
21
- targets.push(target);
22
- }
23
- }
24
- return targets;
25
- }
15
+ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
16
+ const identifier_1 = require("../../../../../environments/identifier");
17
+ const built_in_ambient_state_1 = require("./built-in-ambient-state");
18
+ const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
19
+ const frame_reflection_1 = require("../../../../../fn/frame-reflection");
26
20
  /**
27
21
  * Computes, for every function-definition vertex `F`, `summary(F) = own(F)` unioned with `summary(G)` over every transitive callee `G`.
28
22
  * @param graph - the fully linked dataflow graph
@@ -34,59 +28,22 @@ function computeCallGraphSummaries(graph, own) {
34
28
  const summary = new Map();
35
29
  const callees = new Map();
36
30
  for (const [id, vertex] of graph.vertices(true)) {
37
- if (!vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
38
- continue;
31
+ if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
32
+ summary.set(id, new Set(own(id, vertex)));
33
+ callees.set(id, (0, frame_reflection_1.callsIn)(vertex, graph).flatMap(([node]) => (0, frame_reflection_1.calledDefinitions)(graph, node)).toArray());
39
34
  }
40
- summary.set(id, new Set(own(id, vertex)));
41
- const targets = [];
42
- for (const node of vertex.subflow.graph) {
43
- if (vertex_1.DfgVertex.isFunctionCall(graph.getVertex(node))) {
44
- targets.push(...calledDefinitions(graph, node));
45
- }
46
- }
47
- callees.set(id, targets);
48
- }
49
- if (summary.size === 0) {
50
- return summary;
51
35
  }
52
- // reverse edges: callers of each function
53
- const callers = new Map();
54
- for (const [id, targets] of callees) {
55
- for (const callee of targets) {
56
- const existing = callers.get(callee);
57
- if (existing === undefined) {
58
- callers.set(callee, [id]);
59
- }
60
- else {
61
- existing.push(id);
62
- }
63
- }
64
- }
65
- // worklist fixpoint: pull each callee's summary, re-enqueue callers when a function grew
66
- const queue = [...summary.keys()];
67
- const queued = new Set(queue);
68
- while (queue.length > 0) {
69
- const id = queue.pop();
70
- queued.delete(id);
36
+ /* pull each callee's summary, its callers are revisited whenever a function grew */
37
+ (0, frame_reflection_1.propagateToFixpoint)(summary.keys(), callees, id => {
71
38
  const effects = summary.get(id);
72
- let grew = false;
39
+ const before = effects.size;
73
40
  for (const callee of callees.get(id) ?? []) {
74
41
  for (const effect of summary.get(callee) ?? []) {
75
- if (!effects.has(effect)) {
76
- effects.add(effect);
77
- grew = true;
78
- }
79
- }
80
- }
81
- if (grew) {
82
- for (const caller of callers.get(id) ?? []) {
83
- if (!queued.has(caller)) {
84
- queued.add(caller);
85
- queue.push(caller);
86
- }
42
+ effects.add(effect);
87
43
  }
88
44
  }
89
- }
45
+ return effects.size > before;
46
+ });
90
47
  return summary;
91
48
  }
92
49
  /**
@@ -98,10 +55,7 @@ function linkMaterializedExportsToLoaders(graph, environment) {
98
55
  /* the attached namespaces hold every export of every package, far more than the graph ever materializes, so the
99
56
  * cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or the target of a
100
57
  * `calls` edge. Both are read off the graph once here instead of per export binding. */
101
- const called = new Set();
102
- for (const [id] of graph.vertices(true)) {
103
- called.add(id);
104
- }
58
+ const called = new Set(graph.vertices(true).map(([id]) => id));
105
59
  for (const [, outgoing] of graph.edges()) {
106
60
  for (const [target, edge] of outgoing) {
107
61
  if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls)) {
@@ -109,7 +63,7 @@ function linkMaterializedExportsToLoaders(graph, environment) {
109
63
  }
110
64
  }
111
65
  }
112
- // export node id -> its loading `library()`/`use()` call, from the final environment
66
+ /* export node id -> its loading `library()`/`use()` call, from the final environment */
113
67
  const loaders = new Map();
114
68
  for (let e = environment.current; e !== undefined && !e.builtInEnv; e = e.parent) {
115
69
  if (e.t !== environment_1.EnvType.Namespace) {
@@ -134,7 +88,7 @@ function attachedPackages(_id, fdef) {
134
88
  const packages = [];
135
89
  for (let e = fdef.subflow.environment.current; e !== undefined && !e.builtInEnv; e = e.parent) {
136
90
  if (e.t === environment_1.EnvType.Namespace && e.n !== undefined) {
137
- // an export binding carries the loading `library()` call in `definedAt`
91
+ /* an export binding carries the loading `library()` call in `definedAt` */
138
92
  let definedAt = node_id_1.NodeId.toBuiltIn(e.n);
139
93
  for (const defs of e.memory.values()) {
140
94
  const real = defs.find(d => !node_id_1.NodeId.isBuiltIn(d.definedAt));
@@ -159,10 +113,10 @@ function* escapeTargetFrames(fdef) {
159
113
  * as a callback for {@link computeCallGraphSummaries}. Nested definitions share their outer frames, and a frame is
160
114
  * dominated by the built-ins it holds, so filtering each frame once per pass saves the bulk of the work.
161
115
  */
162
- function escapedDefinitions() {
116
+ function escapedDefinitions(hidden) {
163
117
  const perFrame = new Map();
164
118
  return (_id, fdef) => {
165
- const defs = [];
119
+ const defs = hidden.keys().filter(call => fdef.subflow.graph.has(call)).toArray();
166
120
  for (const e of escapeTargetFrames(fdef)) {
167
121
  let escaped = perFrame.get(e.memory);
168
122
  if (escaped === undefined) {
@@ -187,15 +141,15 @@ function escapedDefinitions() {
187
141
  };
188
142
  }
189
143
  /** Emits {@link EdgeType.SideEffectOnCall} edges for definitions that escape a function transitively. */
190
- function propagateTransitiveDefinitions(graph, environment, ctx) {
191
- const summary = computeCallGraphSummaries(graph, escapedDefinitions());
144
+ function propagateTransitiveDefinitions(graph, environment, ctx, hidden) {
145
+ const summary = computeCallGraphSummaries(graph, escapedDefinitions(hidden));
192
146
  for (const [id, vertex] of graph.vertices(true)) {
193
147
  if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
194
148
  continue;
195
149
  }
196
- for (const target of calledDefinitions(graph, id)) {
150
+ for (const target of (0, frame_reflection_1.calledDefinitions)(graph, id)) {
197
151
  for (const def of summary.get(target) ?? []) {
198
- // an escaping package export is only in the environment; materialize its vertex on demand
152
+ /* an escaping package export is only in the environment; materialize its vertex on demand */
199
153
  if (node_id_1.NodeId.isBuiltIn(def)) {
200
154
  (0, built_in_library_1.attachExportVertex)(graph, def, environment, ctx);
201
155
  }
@@ -216,7 +170,7 @@ function propagateTransitivePackages(graph, environment, ctx) {
216
170
  if (!vertex_1.DfgVertex.isFunctionCall(vertex) || !graph.isRoot(id)) {
217
171
  continue;
218
172
  }
219
- for (const target of calledDefinitions(graph, id)) {
173
+ for (const target of (0, frame_reflection_1.calledDefinitions)(graph, id)) {
220
174
  for (const { pack, definedAt } of summary.get(target) ?? []) {
221
175
  if (!reachable.has(pack)) {
222
176
  reachable.set(pack, definedAt);
@@ -238,23 +192,78 @@ function propagateTransitivePackages(graph, environment, ctx) {
238
192
  }
239
193
  return { environment, grew };
240
194
  }
241
- /** Maps each escaped definition's node id to its full (name-carrying) definition. */
242
- function escapedDefinitionMap(graph) {
243
- const map = new Map();
195
+ /** The ambient writes of body calls only linking resolved to a built-in (see {@link writesOfHiddenBuiltIn}), linking their reads as well. */
196
+ function hiddenBuiltInWrites(graph, environment) {
197
+ const builtIns = environment_1.REnvironment.findBuiltIn(environment.current);
198
+ const writes = new Map();
199
+ const reads = new Map();
200
+ const writesOf = new defaultmap_1.DefaultMap(() => [], writes);
201
+ const readsOf = new defaultmap_1.DefaultMap(() => [], reads);
202
+ for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
203
+ if (graph.isRoot(id)) {
204
+ continue;
205
+ }
206
+ const own = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Function) ? undefined : vertex.name;
207
+ for (const target of (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.Calls)) {
208
+ if (node_id_1.NodeId.isBuiltIn(target) && (own === undefined || node_id_1.NodeId.toBuiltIn(identifier_1.Identifier.getName(own)) !== target)) {
209
+ const targets = resolve_helper_1.Resolve.byNameAndType(node_id_1.NodeId.fromBuiltIn(target), { current: builtIns, level: 0 }, identifier_1.ReferenceType.Function) ?? [];
210
+ const defs = targets.flatMap(d => (0, built_in_ambient_state_1.writesOfHiddenBuiltIn)(d, id));
211
+ if (defs.length > 0) {
212
+ writesOf.get(id).push(...defs);
213
+ }
214
+ const names = targets.flatMap(built_in_ambient_state_1.readsOfHiddenBuiltIn);
215
+ if (names.length > 0) {
216
+ readsOf.get(id).push(...names);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ linkHiddenReads(graph, reads);
222
+ return writes;
223
+ }
224
+ /** A hidden call reads the state where the functions running it are called. */
225
+ function linkHiddenReads(graph, reads) {
226
+ if (reads.size === 0) {
227
+ return;
228
+ }
229
+ const summary = computeCallGraphSummaries(graph, (_id, fdef) => reads.keys().filter(call => fdef.subflow.graph.has(call)));
230
+ for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
231
+ if (vertex.environment === undefined) {
232
+ continue;
233
+ }
234
+ for (const target of (0, frame_reflection_1.calledDefinitions)(graph, id)) {
235
+ for (const call of summary.get(target) ?? []) {
236
+ for (const name of reads.get(call) ?? []) {
237
+ for (const def of resolve_helper_1.Resolve.byName(name, vertex.environment) ?? []) {
238
+ if (def.nodeId !== call && graph.hasVertex(def.nodeId)) {
239
+ graph.addEdge(call, def.nodeId, edge_1.EdgeType.Reads);
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ /**
248
+ * Maps each definition escaping into the global frame to its full (name-carrying) definitions, one node may define several names
249
+ * (`options(digits = 3)`); a write from a function defined within another one may be caught by that function's frame instead.
250
+ */
251
+ function escapedDefinitionMap(graph, hidden) {
252
+ const map = new Map(hidden.entries().map(([id, defs]) => [id, [...defs]]));
253
+ const definitionsOf = new defaultmap_1.DefaultMap(() => [], map);
244
254
  const seen = new Set();
245
255
  for (const [, vertex] of graph.vertices(true)) {
246
256
  if (!vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
247
257
  continue;
248
258
  }
249
- for (const e of escapeTargetFrames(vertex)) {
250
- if (seen.has(e.memory)) {
251
- continue; // a frame shared with an already-visited definition contributes the same entries
252
- }
253
- seen.add(e.memory);
254
- for (const definitions of e.memory.values()) {
259
+ const global = escapeTargetFrames(vertex).filter(e => e.t === undefined).reduce((_, e) => e, undefined);
260
+ /* a frame shared with an already-visited definition contributes the same entries */
261
+ if (global !== undefined && !seen.has(global.memory)) {
262
+ seen.add(global.memory);
263
+ for (const definitions of global.memory.values()) {
255
264
  for (const def of definitions) {
256
265
  if (!node_id_1.NodeId.isBuiltIn(def.nodeId) && def.name !== undefined) {
257
- map.set(def.nodeId, def);
266
+ definitionsOf.get(def.nodeId).push(def);
258
267
  }
259
268
  }
260
269
  }
@@ -267,21 +276,20 @@ function escapedDefinitionMap(graph) {
267
276
  * `f <- function() x <<- 1; g <- function() f(); g(); print(x)` makes `x` resolvable.
268
277
  * @returns the enriched environment and whether it grew (so the extractor can re-resolve open reads and re-run).
269
278
  */
270
- function propagateTransitiveEscapedDefinitions(graph, environment, defined) {
271
- const summary = computeCallGraphSummaries(graph, escapedDefinitions());
272
- const defs = escapedDefinitionMap(graph);
279
+ function propagateTransitiveEscapedDefinitions(graph, environment, defined, hidden, open) {
280
+ const summary = computeCallGraphSummaries(graph, escapedDefinitions(hidden));
281
+ const defs = escapedDefinitionMap(graph, hidden);
273
282
  const names = new Set();
283
+ let byName;
284
+ const definitionsNamed = (name) => (byName ??= (0, frame_reflection_1.definitionsByName)(graph)).get(name);
274
285
  let grew = false;
275
286
  for (const [id, vertex] of graph.vertices(true)) {
276
287
  if (!vertex_1.DfgVertex.isFunctionCall(vertex) || !graph.isRoot(id)) {
277
288
  continue;
278
289
  }
279
- for (const target of calledDefinitions(graph, id)) {
280
- for (const nodeId of summary.get(target) ?? []) {
281
- const def = defs.get(nodeId);
282
- if (def === undefined) {
283
- continue;
284
- }
290
+ for (const target of (0, frame_reflection_1.calledDefinitions)(graph, id)) {
291
+ for (const def of (summary.get(target) ?? []).values().flatMap(nodeId => defs.get(nodeId) ?? [])) {
292
+ const nodeId = def.nodeId;
285
293
  names.add(def.name);
286
294
  /* a name may hold several definitions while a lookup answers with one, so asking the environment
287
295
  * would call every shadowed one missing and define it again on every round; what this fixpoint
@@ -295,12 +303,29 @@ function propagateTransitiveEscapedDefinitions(graph, environment, defined) {
295
303
  continue;
296
304
  }
297
305
  environment = (0, define_1.define)(def, false, environment);
306
+ linkReadsAfter(graph, id, def, open, definitionsNamed);
298
307
  grew = true;
299
308
  }
300
309
  }
301
310
  }
302
311
  return { environment, grew, names };
303
312
  }
313
+ /**
314
+ * A read that may run after `call` and sees a definition the call may replace (or nothing, as with the `open` reads) may see `def`
315
+ * instead, as with a callee only the call binds: `g <- function(f) f(); x <- 1; g(function() x <<- 2); print(x)`, or `g(runif)`.
316
+ */
317
+ function linkReadsAfter(graph, call, def, open, definitionsNamed) {
318
+ const before = graph.getVertex(call)?.environment;
319
+ const visible = before === undefined ? definitionsNamed(def.name) : resolve_helper_1.Resolve.byName(def.name, before)?.map(d => d.nodeId) ?? [];
320
+ const replaced = new Set([...visible, ...(0, frame_reflection_1.edgeSources)(graph, call, edge_1.EdgeType.SideEffectOnCall)]);
321
+ const readers = new Set(open.filter(r => r.name === def.name).map(r => r.nodeId));
322
+ for (const [id] of graph.vertices(true)) {
323
+ if ((readers.has(id) || graph.edgesFrom(id).entries().some(([target, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && replaced.has(target)))
324
+ && !program_order_1.ProgramOrder.definedLater(call, program_order_1.ProgramOrder.runsOnceAt(id, graph), graph)) {
325
+ graph.addEdge(id, def.nodeId, edge_1.EdgeType.Reads);
326
+ }
327
+ }
328
+ }
304
329
  /** Re-resolves still-open reads whose name is one of the transitively escaped `<<-` definitions in `escapedNames`, adding {@link EdgeType.Reads} edges. */
305
330
  function reResolveOpenReferences(graph, environment, references, escapedNames) {
306
331
  for (const ref of references) {
@@ -319,10 +344,11 @@ function reResolveOpenReferences(graph, environment, references, escapedNames) {
319
344
  * @returns the enriched top-level environment and whether it grew (so the extractor can re-link and re-run to a fixpoint).
320
345
  * @useInstead {@link Dataflow.sideEffects.propagateTransitive}
321
346
  */
322
- function propagateTransitiveSideEffects(graph, environment, ctx, defined = new Set()) {
323
- propagateTransitiveDefinitions(graph, environment, ctx);
347
+ function propagateTransitiveSideEffects(graph, environment, ctx, defined = new Set(), open = []) {
348
+ const hidden = hiddenBuiltInWrites(graph, environment);
349
+ propagateTransitiveDefinitions(graph, environment, ctx, hidden);
324
350
  const packages = propagateTransitivePackages(graph, environment, ctx);
325
- const escaped = propagateTransitiveEscapedDefinitions(graph, packages.environment, defined);
351
+ const escaped = propagateTransitiveEscapedDefinitions(graph, packages.environment, defined, hidden, open);
326
352
  return { environment: escaped.environment, grew: packages.grew || escaped.grew, escapedNames: escaped.names };
327
353
  }
328
354
  //# sourceMappingURL=transitive-side-effects.js.map
@@ -28,6 +28,8 @@ export interface ProcessAllArgumentInput<OtherInfo> {
28
28
  readonly markAsNSE?: readonly number[];
29
29
  /** symbols that name data rather than code, so they must not resolve to a function of the same name */
30
30
  readonly nonFunction?: ReadonlySet<NodeId>;
31
+ /** the arguments from this index on are alternatives of which at most one runs (the arms of `switch`) */
32
+ readonly alternativesFrom?: number;
31
33
  }
32
34
  export interface ProcessAllArgumentResult {
33
35
  readonly finalEnv: REnvironmentInformation;
@@ -53,10 +55,8 @@ export declare function convertFnArgument<OtherInfo>(this: void, arg: typeof Emp
53
55
  * would duplicate it.
54
56
  */
55
57
  export declare function isPipedArgument<OtherInfo>(arg: unknown, functionRootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): boolean;
56
- /**
57
- * Processes all arguments for a function call, updating the given final graph and environment.
58
- */
59
- export declare function processAllArguments<OtherInfo>({ functionName, args, data, finalGraph, functionRootId, forced, patchData, nonFunction }: ProcessAllArgumentInput<OtherInfo>): ProcessAllArgumentResult;
58
+ /** Processes all arguments for a function call, updating the given final graph and environment. */
59
+ export declare function processAllArguments<OtherInfo>({ functionName, args, data, finalGraph, functionRootId, forced, patchData, nonFunction, alternativesFrom }: ProcessAllArgumentInput<OtherInfo>): ProcessAllArgumentResult;
60
60
  export interface PatchFunctionCallInput<OtherInfo> {
61
61
  readonly nextGraph: DataflowGraph;
62
62
  readonly rootId: NodeId;
@@ -16,6 +16,7 @@ const processor_1 = require("../../../../processor");
16
16
  const model_1 = require("../../../../../r-bridge/lang-4.x/ast/model/model");
17
17
  const r_function_call_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
18
18
  const identifier_1 = require("../../../../environments/identifier");
19
+ const built_in_ambient_state_1 = require("./built-in/built-in-ambient-state");
19
20
  const overwrite_1 = require("../../../../environments/overwrite");
20
21
  const resolve_by_name_1 = require("../../../../environments/resolve-by-name");
21
22
  const process_argument_1 = require("../process-argument");
@@ -23,12 +24,13 @@ const vertex_1 = require("../../../../graph/vertex");
23
24
  const edge_1 = require("../../../../graph/edge");
24
25
  const r_argument_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
25
26
  const vertex_2 = require("../../../../graph/vertex");
27
+ const append_1 = require("../../../../environments/append");
26
28
  function forceVertexArgumentValueReferences(rootId, value, graph, env) {
27
29
  const valueVertex = graph.getVertex(value.entryPoint);
28
30
  if (!valueVertex) {
29
31
  return;
30
32
  }
31
- // link read if it is function definition directly and reference the exit point
33
+ /* link read if it is function definition directly and reference the exit point */
32
34
  if (vertex_2.DfgVertex.isFunctionDefinition(valueVertex)) {
33
35
  for (const exit of valueVertex.exitPoints) {
34
36
  graph.addEdge(rootId, exit.nodeId, edge_1.EdgeType.Reads);
@@ -39,18 +41,11 @@ function forceVertexArgumentValueReferences(rootId, value, graph, env) {
39
41
  graph.addEdge(rootId, exit.nodeId, edge_1.EdgeType.Reads);
40
42
  }
41
43
  }
42
- const containedSubflowIn = graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)
43
- .flatMap(([, info]) => info.subflow.in);
44
- // try to resolve them against the current environment
45
- for (const l of [value.in, containedSubflowIn]) {
46
- for (const ref of l) {
47
- if (ref.name) {
48
- const refId = ref.nodeId;
49
- const resolved = (0, resolve_by_name_1.resolveByName)(ref.name, env, ref.type) ?? [];
50
- for (const resolve of resolved) {
51
- graph.addEdge(refId, resolve.nodeId, edge_1.EdgeType.Reads);
52
- }
53
- }
44
+ const containedSubflowIn = graph.verticesOfType(vertex_1.VertexType.FunctionDefinition).flatMap(([, info]) => info.subflow.in);
45
+ /* try to resolve them against the current environment */
46
+ for (const ref of [...value.in, ...containedSubflowIn]) {
47
+ for (const resolved of ref.name ? (0, resolve_by_name_1.resolveByName)(ref.name, env, ref.type) ?? [] : []) {
48
+ graph.addEdge(ref.nodeId, resolved.nodeId, edge_1.EdgeType.Reads);
54
49
  }
55
50
  }
56
51
  }
@@ -74,15 +69,7 @@ function convertFnArgument(arg) {
74
69
  else if (!arg.name || !r_argument_1.RArgument.is(arg)) {
75
70
  return { nodeId: arg.info.id, cds: undefined, type: identifier_1.ReferenceType.Argument };
76
71
  }
77
- else {
78
- return {
79
- nodeId: arg.info.id,
80
- valueId: arg.value?.info.id,
81
- name: arg.name.content,
82
- cds: undefined,
83
- type: identifier_1.ReferenceType.Argument
84
- };
85
- }
72
+ return { nodeId: arg.info.id, valueId: arg.value?.info.id, name: arg.name.content, cds: undefined, type: identifier_1.ReferenceType.Argument };
86
73
  }
87
74
  /**
88
75
  * Whether `arg` is the value the pipe handed to the call `functionRootId`, which {@link processNamedCall}
@@ -92,76 +79,67 @@ function convertFnArgument(arg) {
92
79
  function isPipedArgument(arg, functionRootId, data) {
93
80
  return data.pipedArgument?.rootId === functionRootId && data.pipedArgument.argument === arg;
94
81
  }
95
- /**
96
- * Processes all arguments for a function call, updating the given final graph and environment.
97
- */
98
- function processAllArguments({ functionName, args, data, finalGraph, functionRootId, forced = [], patchData, nonFunction }) {
82
+ /** Processes all arguments for a function call, updating the given final graph and environment. */
83
+ function processAllArguments({ functionName, args, data, finalGraph, functionRootId, forced = [], patchData, nonFunction, alternativesFrom }) {
99
84
  let finalEnv = functionName.environment;
100
85
  const callArgs = [];
101
86
  const processedArguments = [];
102
87
  const remainingReadInArgs = [];
103
- let i = -1;
104
- for (const arg of args) {
105
- i++;
106
- data = { ...data, environment: finalEnv };
88
+ /* each alternative starts from what holds before all of them, and what one of them defines only may hold afterward */
89
+ let beforeAlternatives;
90
+ let afterAlternatives;
91
+ for (const [i, arg] of args.entries()) {
92
+ if (alternativesFrom !== undefined && i >= alternativesFrom) {
93
+ beforeAlternatives ??= finalEnv;
94
+ finalEnv = beforeAlternatives;
95
+ }
96
+ /* whether an alternative runs depends on what the call picks */
97
+ data = beforeAlternatives === undefined ? { ...data, environment: finalEnv }
98
+ : { ...data, environment: finalEnv, cds: [...data.cds ?? [], { id: functionRootId, when: true }] };
107
99
  data = patchData?.(data, i) ?? data;
108
100
  if (r_argument_1.RArgument.isEmpty(arg)) {
109
101
  callArgs.push(r_function_call_1.EmptyArgument);
110
102
  processedArguments.push(undefined);
111
103
  continue;
112
104
  }
113
- if (isPipedArgument(arg, functionRootId, data)) {
105
+ else if (isPipedArgument(arg, functionRootId, data)) {
114
106
  processedArguments.push(undefined);
115
107
  continue;
116
108
  }
117
- let processed;
118
- /* a precomputed argument is handed in from elsewhere and stays alive there, only a freshly built one dies here */
119
- let ownsGraph = true;
120
- if (i === 0 && data.precomputedFirstArg?.rootId === functionRootId) {
121
- processed = data.precomputedFirstArg.info;
122
- ownsGraph = false;
123
- }
124
- else {
125
- processed = r_argument_1.RArgument.is(arg) ? (0, process_argument_1.processFunctionArgument)(arg, data) : (0, processor_1.processDataflowFor)(arg, data);
126
- }
109
+ /* a precomputed argument stays alive where it was handed in from, only a freshly built one dies here */
110
+ const precomputed = i === 0 && data.precomputedFirstArg?.rootId === functionRootId ? data.precomputedFirstArg.info : undefined;
111
+ const processed = precomputed ?? (r_argument_1.RArgument.is(arg) ? (0, process_argument_1.processFunctionArgument)(arg, data) : (0, processor_1.processDataflowFor)(arg, data));
127
112
  if (r_argument_1.RArgument.isWithValue(arg) && forced[i] && !model_1.RConstant.is(arg.value)) {
128
113
  forceVertexArgumentValueReferences(functionRootId, processed, processed.graph, data.environment);
129
114
  }
130
115
  processedArguments.push(processed);
131
116
  finalEnv = (0, overwrite_1.overwriteEnvironment)(finalEnv, processed.environment);
117
+ if (beforeAlternatives !== undefined) {
118
+ afterAlternatives = (0, append_1.appendEnvironment)(afterAlternatives ?? beforeAlternatives, finalEnv);
119
+ }
132
120
  /* nothing reads the argument's own graph past this point, only its entry point and references */
133
- finalGraph.mergeWith(processed.graph, true, ownsGraph);
134
- // resolve reads within argument, we resolve before adding the `processed.environment` to avoid cyclic dependencies
135
- for (const l of [processed.in, processed.unknownReferences]) {
136
- for (const original of l) {
137
- // check if it is called directly
138
- const inId = original.nodeId;
139
- /* a data argument holds a value, so a function of that name is not what it reads; the narrowed
140
- type stays on the reference as it bubbles through the enclosing calls */
141
- const ingoing = nonFunction?.has(inId) ? { ...original, type: identifier_1.ReferenceType.NonFunction } : original;
142
- const refType = vertex_2.DfgVertex.isFunctionCall(finalGraph.getVertex(inId)) ? identifier_1.ReferenceType.Function
121
+ finalGraph.mergeWith(processed.graph, true, precomputed === undefined);
122
+ /* resolve reads within argument, we resolve before adding the `processed.environment` to avoid cyclic dependencies */
123
+ for (const original of [...processed.in, ...processed.unknownReferences]) {
124
+ const inId = original.nodeId;
125
+ /* a data argument holds a value, so a function of that name is not what it reads; the narrowed type stays on the reference */
126
+ const ingoing = nonFunction?.has(inId) ? { ...original, type: identifier_1.ReferenceType.NonFunction } : original;
127
+ /* a call reading the options or graphics state (`#...`, see AmbientStateName) reads a variable, not itself */
128
+ const refType = built_in_ambient_state_1.AmbientStateName.is(ingoing.name) ? identifier_1.ReferenceType.Variable
129
+ : vertex_2.DfgVertex.isFunctionCall(finalGraph.getVertex(inId)) ? identifier_1.ReferenceType.Function
143
130
  : ingoing.type === identifier_1.ReferenceType.NonFunction ? identifier_1.ReferenceType.NonFunction : identifier_1.ReferenceType.Unknown;
144
- const tryToResolve = ingoing.name ? (0, resolve_by_name_1.resolveByName)(ingoing.name, data.environment, refType) : undefined;
145
- if (tryToResolve === undefined) {
146
- remainingReadInArgs.push(ingoing);
147
- }
148
- else {
149
- /* maybe all targets are not definitely of the current scope and should be still kept */
150
- let assumeItMayHaveAHigherTarget = true;
151
- for (const resolved of tryToResolve) {
152
- if ((0, identifier_1.isReferenceType)(resolved.type, identifier_1.ReferenceType.BuiltInFunction | identifier_1.ReferenceType.BuiltInConstant)) {
153
- continue;
154
- }
155
- else if ((0, info_1.happensInEveryBranch)(resolved.cds)) {
156
- assumeItMayHaveAHigherTarget = false;
157
- }
158
- finalGraph.addEdge(inId, resolved.nodeId, edge_1.EdgeType.Reads);
159
- }
160
- if (assumeItMayHaveAHigherTarget) {
161
- remainingReadInArgs.push(ingoing);
162
- }
131
+ const tryToResolve = ingoing.name ? (0, resolve_by_name_1.resolveByName)(ingoing.name, data.environment, refType) : undefined;
132
+ /* unless one target is certainly of the current scope, a higher one may still be meant */
133
+ let mayHaveHigherTarget = true;
134
+ for (const resolved of tryToResolve ?? []) {
135
+ if (!(0, identifier_1.isReferenceType)(resolved.type, identifier_1.ReferenceType.BuiltInFunction | identifier_1.ReferenceType.BuiltInConstant)) {
136
+ mayHaveHigherTarget &&= !(0, info_1.happensInEveryBranch)(resolved.cds);
137
+ finalGraph.addEdge(inId, resolved.nodeId, edge_1.EdgeType.Reads);
163
138
  }
164
139
  }
140
+ if (mayHaveHigherTarget) {
141
+ remainingReadInArgs.push(ingoing);
142
+ }
165
143
  }
166
144
  if (!r_argument_1.RArgument.is(arg) || !arg.name) {
167
145
  callArgs.push({ nodeId: processed.entryPoint, cds: undefined, type: identifier_1.ReferenceType.Argument });
@@ -171,7 +149,7 @@ function processAllArguments({ functionName, args, data, finalGraph, functionRoo
171
149
  }
172
150
  finalGraph.addEdge(functionRootId, processed.entryPoint, edge_1.EdgeType.Argument);
173
151
  }
174
- return { finalEnv, callArgs, remainingReadInArgs, processedArguments };
152
+ return { finalEnv: afterAlternatives ?? finalEnv, callArgs, remainingReadInArgs, processedArguments };
175
153
  }
176
154
  /**
177
155
  * Patches a function call vertex into the given dataflow graph.
@@ -1,6 +1,7 @@
1
1
  import type { AstIdMap, ParentInformation } from '../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
2
  import { NodeId } from '../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
3
3
  import type { DataflowGraph } from '../../../../graph/graph';
4
+ import { VertexType } from '../../../../graph/vertex';
4
5
  import type { ControlFlowGraph } from '../../../../../control-flow/control-flow-graph';
5
6
  /** The reads that may force the expression, and the control flow deciding what they can see. */
6
7
  export interface ForceSites {
@@ -8,12 +9,20 @@ export interface ForceSites {
8
9
  readonly sites: readonly NodeId[];
9
10
  /** the name the deferred expression is bound to, whose binding its own writes replace */
10
11
  readonly binding: NodeId;
12
+ /** what reaches the sites and what they reach, filled on first use and shared by everyone handed these sites */
13
+ readonly reach?: {
14
+ before?: ReadonlySet<NodeId>;
15
+ after?: ReadonlySet<NodeId>;
16
+ always?: Map<NodeId, boolean>;
17
+ };
11
18
  }
12
19
  /** Where a name is bound and where it is read, so that a deferred expression can reach either. */
13
20
  export interface NameIndex {
14
21
  readonly definitions: ReadonlyMap<string, NodeId[]>;
15
22
  readonly uses: ReadonlyMap<string, NodeId[]>;
16
23
  }
24
+ /** The vertices of `type` by their unquoted name. */
25
+ export declare function verticesByName<Info>(graph: DataflowGraph, type: VertexType, idMap: AstIdMap<Info & ParentInformation>): Map<string, NodeId[]>;
17
26
  /**
18
27
  * An expression R evaluates at a time we cannot pin down: the body a `delayedAssign` binds, forced at some
19
28
  * later read of the name, or a promise a closure carries past the call that created it.
@@ -29,14 +38,15 @@ export declare const Deferred: {
29
38
  /**
30
39
  * The reads that may be the one forcing `binding`: every read of it that no other read always precedes,
31
40
  * since an earlier read would already have forced it and cached the value.
41
+ * With `viaClosures`, a closure reading a `delayedAssign` binding forces it when called.
32
42
  */
33
- readonly forcedAt: (this: void, graph: DataflowGraph, binding: NodeId, cfg: ControlFlowGraph) => readonly NodeId[];
43
+ readonly forcedAt: (this: void, graph: DataflowGraph, binding: NodeId, cfg: ControlFlowGraph, viaClosures?: boolean) => readonly NodeId[];
34
44
  /**
35
45
  * Links the writes an expression performs to the uses that may observe them, for a call evaluating the
36
46
  * expression at a point control flow can pin down (`eval`). The reads are settled by the evaluating call
37
47
  * itself, against the environment in effect there, so only this direction is left open.
38
48
  */
39
- readonly publish: <Info>(this: void, graph: DataflowGraph, expr: NodeId, index: NameIndex, idMap: AstIdMap<Info & ParentInformation>, at: NodeId, cfg?: ControlFlowGraph) => void;
49
+ readonly publish: <Info>(this: void, graph: DataflowGraph, expr: NodeId, index: NameIndex, idMap: AstIdMap<Info & ParentInformation>, at: NodeId, sites: readonly NodeId[], cfg?: ControlFlowGraph) => void;
40
50
  /**
41
51
  * Links the expression rooted at `expr` to the bindings it may meet when it is evaluated. Given the reads
42
52
  * that may force it, control flow rules out what no force can reach; without them every binding stays a