@eagleoutice/flowr 2.15.10 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/README.md +23 -26
  2. package/abstract-interpretation/data-frame/arguments.js +11 -7
  3. package/cli/flowr-main-options.d.ts +15 -0
  4. package/cli/flowr-main-options.js +18 -0
  5. package/cli/flowr.d.ts +18 -0
  6. package/cli/flowr.js +13 -2
  7. package/cli/repl/commands/repl-clipboard.js +2 -1
  8. package/cli/repl/commands/repl-commands.js +2 -0
  9. package/cli/repl/commands/repl-main.d.ts +5 -0
  10. package/cli/repl/commands/repl-signature.js +2 -0
  11. package/cli/repl/core.d.ts +7 -1
  12. package/cli/repl/core.js +17 -8
  13. package/cli/repl/execute.js +2 -0
  14. package/cli/repl/server/connection.js +2 -1
  15. package/cli/repl/server/net.d.ts +10 -0
  16. package/cli/repl/server/net.js +34 -1
  17. package/cli/slicer-app.js +2 -1
  18. package/config.d.ts +12 -2
  19. package/config.js +91 -14
  20. package/control-flow/happens-before.d.ts +5 -0
  21. package/control-flow/happens-before.js +48 -34
  22. package/control-flow/useless-loop.d.ts +1 -1
  23. package/control-flow/useless-loop.js +29 -42
  24. package/dataflow/environments/built-in-props.d.ts +9 -0
  25. package/dataflow/environments/built-in-props.js +25 -19
  26. package/dataflow/environments/built-in.d.ts +2 -2
  27. package/dataflow/environments/built-in.js +41 -77
  28. package/dataflow/environments/default-builtin-config.d.ts +181 -29
  29. package/dataflow/environments/default-builtin-config.js +38 -24
  30. package/dataflow/environments/environment.d.ts +6 -4
  31. package/dataflow/environments/environment.js +54 -121
  32. package/dataflow/environments/identifier.d.ts +4 -2
  33. package/dataflow/environments/identifier.js +23 -69
  34. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  35. package/dataflow/environments/reference-to-maybe.js +23 -51
  36. package/dataflow/environments/resolve-by-name.js +37 -76
  37. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  38. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  39. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  40. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  41. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  42. package/dataflow/eval/resolve/resolve.js +23 -14
  43. package/dataflow/extractor.js +185 -59
  44. package/dataflow/fn/class-declaration.d.ts +8 -2
  45. package/dataflow/fn/class-declaration.js +96 -97
  46. package/dataflow/fn/exceptions-of-function.js +68 -37
  47. package/dataflow/fn/frame-reflection.d.ts +12 -4
  48. package/dataflow/fn/frame-reflection.js +64 -42
  49. package/dataflow/fn/function-props.js +15 -33
  50. package/dataflow/fn/function-semantics.d.ts +11 -3
  51. package/dataflow/fn/function-semantics.js +6 -0
  52. package/dataflow/fn/higher-order-function.js +13 -17
  53. package/dataflow/fn/strict-function.d.ts +13 -0
  54. package/dataflow/fn/strict-function.js +285 -122
  55. package/dataflow/graph/call-graph.d.ts +7 -6
  56. package/dataflow/graph/call-graph.js +35 -46
  57. package/dataflow/graph/graph.d.ts +6 -1
  58. package/dataflow/graph/graph.js +57 -66
  59. package/dataflow/info.d.ts +8 -1
  60. package/dataflow/info.js +24 -30
  61. package/dataflow/internal/control-flow.d.ts +42 -4
  62. package/dataflow/internal/control-flow.js +76 -39
  63. package/dataflow/internal/linker.d.ts +15 -9
  64. package/dataflow/internal/linker.js +253 -241
  65. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
  66. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +441 -79
  67. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  68. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
  69. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
  70. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
  71. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  72. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
  74. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
  75. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +290 -252
  76. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  78. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  79. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
  80. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
  82. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  84. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  85. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
  86. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
  91. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  92. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  93. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  94. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  95. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
  97. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  98. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  99. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +120 -93
  101. package/dataflow/internal/process/functions/call/common.d.ts +1 -3
  102. package/dataflow/internal/process/functions/call/common.js +36 -76
  103. package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
  104. package/dataflow/internal/process/functions/call/deferred.js +60 -58
  105. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  106. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  107. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  108. package/dataflow/internal/process/functions/call/named-call-handling.js +44 -21
  109. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  110. package/dataflow/internal/process/functions/call/quoted.js +162 -172
  111. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  112. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  113. package/dataflow/internal/process/process-symbol.js +3 -6
  114. package/dataflow/internal/program-order.d.ts +26 -0
  115. package/dataflow/internal/program-order.js +49 -0
  116. package/documentation/doc-capabilities.js +4 -1
  117. package/documentation/wiki-interface.js +4 -0
  118. package/documentation/wiki-setup.js +23 -0
  119. package/engines.js +11 -3
  120. package/linter/linter-executor.js +19 -1
  121. package/linter/linter-rules.d.ts +17 -8
  122. package/linter/rules/absolute-path.js +63 -87
  123. package/linter/rules/file-path-validity.d.ts +4 -2
  124. package/linter/rules/file-path-validity.js +117 -80
  125. package/linter/rules/namespace-access.js +21 -33
  126. package/linter/rules/naming-convention.d.ts +1 -1
  127. package/linter/rules/naming-convention.js +60 -48
  128. package/linter/rules/network-functions.js +11 -7
  129. package/linter/rules/no-leaked-credentials.js +15 -18
  130. package/linter/rules/problematic-inputs.d.ts +2 -1
  131. package/linter/rules/problematic-inputs.js +39 -59
  132. package/linter/rules/roxygen-arguments.d.ts +9 -4
  133. package/linter/rules/roxygen-arguments.js +29 -48
  134. package/linter/rules/seeded-randomness.d.ts +7 -4
  135. package/linter/rules/seeded-randomness.js +130 -89
  136. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  137. package/linter/rules/stop-with-call-arg.js +25 -22
  138. package/linter/rules/unclosed-connection.js +31 -24
  139. package/linter/rules/undefined-symbol.d.ts +4 -6
  140. package/linter/rules/undefined-symbol.js +58 -75
  141. package/linter/rules/unescaped-arguments.js +18 -44
  142. package/linter/rules/unused-definition.d.ts +6 -0
  143. package/linter/rules/unused-definition.js +105 -145
  144. package/linter/rules/unused-import.d.ts +3 -0
  145. package/linter/rules/unused-import.js +25 -43
  146. package/package.json +5 -2
  147. package/project/flowr-analyzer.js +6 -2
  148. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  149. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  150. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +14 -5
  151. package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
  152. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  153. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  154. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +18 -42
  155. package/project/sigdb/decompress.js +3 -1
  156. package/project/sigdb/sigdb-download.js +9 -6
  157. package/queries/base-query-format.js +1 -2
  158. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  159. package/queries/catalog/config-query/config-query-executor.js +9 -2
  160. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  161. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  162. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  163. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  164. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  165. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  166. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  167. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  168. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  169. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  170. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  171. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  172. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  173. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  174. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  175. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  176. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  177. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  178. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  179. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  180. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  181. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  182. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  183. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  184. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  185. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  186. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  187. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  188. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  189. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  190. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  191. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  192. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  193. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  194. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  195. package/r-bridge/shell-executor.js +2 -0
  196. package/r-bridge/shell.js +8 -0
  197. package/search/search-executor/search-enrichers.js +25 -37
  198. package/slicing/static/slice-call.d.ts +4 -3
  199. package/slicing/static/slice-call.js +56 -88
  200. package/slicing/static/static-slicer.js +120 -79
  201. package/slicing/static/visiting-queue.d.ts +4 -6
  202. package/slicing/static/visiting-queue.js +9 -13
  203. package/util/files.d.ts +6 -0
  204. package/util/files.js +12 -0
  205. package/util/parallel.js +2 -0
  206. package/util/proc.js +2 -1
  207. package/util/r-base-packages.d.ts +2 -0
  208. package/util/r-base-packages.js +23 -13
  209. package/util/secure-mode.d.ts +42 -0
  210. package/util/secure-mode.js +70 -0
  211. package/util/text/playground-link.d.ts +12 -3
  212. package/util/text/playground-link.js +18 -27
  213. package/util/version.js +4 -10
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CallGraph = void 0;
4
+ exports.fallbackUntargetedCall = fallbackUntargetedCall;
4
5
  const graph_1 = require("./graph");
5
6
  const vertex_1 = require("./vertex");
6
7
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
@@ -25,10 +26,11 @@ function processCds(vtx, graph, result, state) {
25
26
  const UntargetedCallFollow = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Returns;
26
27
  const UntargetedCallAvoid = edge_1.EdgeType.NonStandardEvaluation | edge_1.EdgeType.Argument;
27
28
  /**
28
- * This tracks the known symbol origins for a function call for which we know that flowr found no targets!
29
+ * The origins of what a call flowR found no target for calls, following its name back through reads and
30
+ * parameter bindings: `f(x)` within `apply_f <- function(f, x) f(x)` ends at what callers hand in as `f`.
29
31
  */
30
32
  function fallbackUntargetedCall(vtx, graph) {
31
- // we track all aliases to their roots here, we know there is no known call target
33
+ /* we track all aliases to their roots here, we know there is no known call target */
32
34
  const collected = new Set();
33
35
  const visited = new Set();
34
36
  const toVisit = [vtx.id];
@@ -43,13 +45,16 @@ function fallbackUntargetedCall(vtx, graph) {
43
45
  continue;
44
46
  }
45
47
  let addedNew = false;
48
+ /* past the call asked about, a call hands back what it returns; a plain read of another call is state it depends on, not its name */
49
+ const follow = currentId !== vtx.id && vertex_1.DfgVertex.isFunctionCall(currentVtx) ? edge_1.EdgeType.Returns : UntargetedCallFollow;
46
50
  for (const [tar, e] of graph.edgesFrom(currentId)) {
47
- if (edge_1.DfEdge.includesType(e, UntargetedCallFollow) && edge_1.DfEdge.doesNotIncludeType(e, UntargetedCallAvoid)) {
51
+ if (edge_1.DfEdge.includesType(e, follow) && edge_1.DfEdge.doesNotIncludeType(e, UntargetedCallAvoid)
52
+ && (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns) || !vertex_1.DfgVertex.isFunctionCall(graph.getVertex(tar)))) {
48
53
  addedNew = true;
49
54
  toVisit.push(tar);
50
55
  }
51
56
  }
52
- // we have reached our end(s)
57
+ /* we have reached our end(s) */
53
58
  if (!addedNew && currentId !== vtx.id) {
54
59
  collected.add(currentId);
55
60
  }
@@ -67,23 +72,19 @@ function processCall(vtx, from, graph, result, state) {
67
72
  state.visited.add(vid);
68
73
  result.addVertex(vtx, undefined, true);
69
74
  processCds(vtx, graph, result, state);
70
- // for each call, resolve the targets
71
- const tars = (0, linker_1.getAllFunctionCallTargets)(vid, graph, vtx.environment);
72
75
  let addedTarget = false;
73
76
  let addedBiTarget = false;
74
- for (const tar of tars) {
77
+ for (const tar of (0, linker_1.getAllFunctionCallTargets)(vid, graph, vtx.environment)) {
78
+ const targetVtx = graph.getVertex(tar);
75
79
  if (node_id_1.NodeId.isBuiltIn(tar)) {
76
80
  result.addEdge(vid, tar, edge_1.EdgeType.Calls);
77
81
  addedTarget = true;
78
82
  addedBiTarget = true;
79
- continue;
80
83
  }
81
- const targetVtx = graph.getVertex(tar);
82
- if (!vertex_1.DfgVertex.isFunctionDefinition(targetVtx)) {
83
- continue;
84
+ else if (vertex_1.DfgVertex.isFunctionDefinition(targetVtx)) {
85
+ addedTarget = true;
86
+ processFunctionDefinition(targetVtx, vid, graph, result, state);
84
87
  }
85
- addedTarget = true;
86
- processFunctionDefinition(targetVtx, vid, graph, result, state);
87
88
  }
88
89
  if (!addedBiTarget && vtx.origin !== 'unnamed') {
89
90
  for (const origs of vtx.origin) {
@@ -94,8 +95,7 @@ function processCall(vtx, from, graph, result, state) {
94
95
  }
95
96
  }
96
97
  if (!addedTarget) {
97
- const origs = fallbackUntargetedCall(vtx, graph);
98
- for (const ori of origs) {
98
+ for (const ori of fallbackUntargetedCall(vtx, graph)) {
99
99
  const oriVtx = graph.getVertex(ori);
100
100
  if (!oriVtx) {
101
101
  continue;
@@ -114,30 +114,23 @@ function processCall(vtx, from, graph, result, state) {
114
114
  }
115
115
  }
116
116
  }
117
- // handle arguments, traversing the 'reads' and the 'returns' edges
118
- for (const [tar, e] of graph.edgesFrom(vtx.id)) {
117
+ /* handle arguments, traversing the 'reads' and the 'returns' edges */
118
+ for (const [tar, e] of graph.edgesFrom(vid)) {
119
119
  if (edge_1.DfEdge.doesNotIncludeType(e, edge_1.EdgeType.Reads | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument)) {
120
120
  continue;
121
121
  }
122
122
  const tVtx = graph.getVertex(tar);
123
- if (!tVtx) {
124
- continue;
123
+ if (tVtx) {
124
+ processUnknown(tVtx, vid, graph, result, state);
125
125
  }
126
- processUnknown(tVtx, vtx.id, graph, result, state);
127
126
  }
128
127
  }
129
128
  function processUnknown(vtx, from, graph, result, state) {
130
- switch (vtx.tag) {
131
- case vertex_1.VertexType.FunctionCall:
132
- processCall(vtx, from, graph, result, state);
133
- return;
134
- case vertex_1.VertexType.FunctionDefinition:
135
- if (from) {
136
- result.addEdge(from, node_id_1.NodeId.toBuiltIn('function'), edge_1.EdgeType.Calls);
137
- }
138
- return;
139
- default:
140
- return;
129
+ if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
130
+ processCall(vtx, from, graph, result, state);
131
+ }
132
+ else if (vertex_1.DfgVertex.isFunctionDefinition(vtx) && from) {
133
+ result.addEdge(from, node_id_1.NodeId.toBuiltIn('function'), edge_1.EdgeType.Calls);
141
134
  }
142
135
  }
143
136
  function processFunctionDefinition(vtx, from, graph, result, state) {
@@ -183,6 +176,15 @@ function followCalls(graph, seeds, reached) {
183
176
  }
184
177
  }
185
178
  }
179
+ /** Whether `name` is a `<generic>.<class>` of a generic that is called, as `print.foo` is when `print` is. */
180
+ function mayBeDispatchedTo(name, generics) {
181
+ for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
182
+ if (generics.has(name.slice(0, dot))) {
183
+ return true;
184
+ }
185
+ }
186
+ return false;
187
+ }
186
188
  /** The names the reached calls go by, which are the generics a method of the program may be dispatched to for. */
187
189
  function reachedCallNames(graph, reached) {
188
190
  const names = new Set();
@@ -194,15 +196,6 @@ function reachedCallNames(graph, reached) {
194
196
  }
195
197
  return names;
196
198
  }
197
- /** Whether `name` is a `<generic>.<class>` of a generic that is called, as `print.foo` is when `print` is. */
198
- function mayBeDispatchedTo(name, generics) {
199
- for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
200
- if (generics.has(name.slice(0, dot))) {
201
- return true;
202
- }
203
- }
204
- return false;
205
- }
206
199
  /**
207
200
  * The unreached function definitions that may still run: one the code hands to another call (a callback, an
208
201
  * S4 method, a shiny handler), and one bound to a `<generic>.<class>` name of a generic the program calls.
@@ -244,9 +237,7 @@ function mayRunAnyway(graph, reached) {
244
237
  exports.CallGraph = {
245
238
  ...graph_helper_1.GraphHelper,
246
239
  name: 'CallGraph',
247
- /**
248
- * Extracts the sub call graph from the given call graph, starting from the given entry points.
249
- */
240
+ /** Extracts the sub call graph from the given call graph, starting from the given entry points. */
250
241
  computeSubCallGraph(graph, entryPoints) {
251
242
  const result = new graph_1.DataflowGraph(graph.idMap);
252
243
  const toVisit = Array.from(entryPoints);
@@ -301,9 +292,7 @@ exports.CallGraph = {
301
292
  .map(([id]) => id)
302
293
  .toArray();
303
294
  },
304
- /**
305
- * Reduces the call graph by dropping all transitive edges.
306
- */
295
+ /** Reduces the call graph by dropping all transitive edges. */
307
296
  dropTransitiveEdges(graph) {
308
297
  const newCg = new graph_1.DataflowGraph(graph.idMap);
309
298
  newCg.mergeVertices(graph);
@@ -142,7 +142,7 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
142
142
  /** All edges in the complete graph (including those nested in function definition) */
143
143
  private edgeInformation;
144
144
  private incomingIndex?;
145
- private readonly types;
145
+ private types;
146
146
  /** The id list of `tag`, created on first use, so a caller adding many ids looks it up once. */
147
147
  private typeList;
148
148
  private indexType;
@@ -150,6 +150,8 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
150
150
  private unindexType;
151
151
  private qualifiedNames?;
152
152
  toJSON(): DataflowGraphJson;
153
+ /** A view of this graph without the environments of its vertices and subflows, sharing everything else. */
154
+ withoutEnvironments(): DataflowGraph<Vertex, Edge>;
153
155
  /** Gets the {@link DataflowGraphVertexInfo} attached to `id` (searching function definitions too if `includeDefinedFunctions`) and its outgoing edges. */
154
156
  get(id: NodeId, includeDefinedFunctions?: boolean): [Vertex, OutgoingEdges] | undefined;
155
157
  /** Gets the {@link DataflowGraphVertexInfo} attached to `id`, see {@link DataflowGraph#getRootVertex}. */
@@ -256,6 +258,9 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
256
258
  * `consume` takes `otherGraph`'s edge tables instead of copying them (perf). Pass it only for a graph that dies with the call.
257
259
  */
258
260
  mergeWith(otherGraph: DataflowGraph<Vertex, Edge> | undefined, mergeRootVertices?: boolean, consume?: boolean): this;
261
+ /** An empty graph takes over the contents of a graph it consumes rather than copying them entry by entry. */
262
+ private adopt;
263
+ private mergeRootsAndUnknowns;
259
264
  mergeVertices(otherGraph: DataflowGraph<Vertex, Edge>, mergeRootVertices?: boolean): void;
260
265
  private mergeEdges;
261
266
  /** Marks the vertex referenced by `reference` as a definition, with `sourceIds` as the source vertex ids of the def if known. */
@@ -40,10 +40,7 @@ exports.FunctionArgument = {
40
40
  },
41
41
  /** The node id of a non-empty `arg`, e.g. of either `a` or `2` in `foo(a=3, 2)`. */
42
42
  getId(arg) {
43
- if (arg !== r_function_call_1.EmptyArgument) {
44
- return arg?.nodeId;
45
- }
46
- return undefined;
43
+ return arg === r_function_call_1.EmptyArgument ? undefined : arg.nodeId;
47
44
  },
48
45
  /** The name of `arg` if named, `undefined` otherwise. */
49
46
  getName(arg) {
@@ -54,10 +51,7 @@ exports.FunctionArgument = {
54
51
  if (arg === r_function_call_1.EmptyArgument) {
55
52
  return undefined;
56
53
  }
57
- else if (arg.name === undefined) {
58
- return arg.nodeId;
59
- }
60
- return arg.valueId;
54
+ return arg.name === undefined ? arg.nodeId : arg.valueId;
61
55
  },
62
56
  /** Whether `arg` is named exactly `name` (textual match only, not R's argument-matching; see {@link FunctionSemantics.call.match.toSpec} for that). */
63
57
  hasName(arg, name) {
@@ -139,10 +133,7 @@ class DataflowGraph {
139
133
  }
140
134
  /** Every write above keeps an id listed under one tag at most once, so a lookup never hands the same one out twice. */
141
135
  unindexType(tag, id) {
142
- const ids = this.types.get(tag);
143
- if (ids === undefined) {
144
- return;
145
- }
136
+ const ids = this.types.get(tag) ?? [];
146
137
  for (let idx = ids.lastIndexOf(id); idx >= 0; idx = ids.lastIndexOf(id)) {
147
138
  ids.splice(idx, 1);
148
139
  }
@@ -158,9 +149,20 @@ class DataflowGraph {
158
149
  _unknownSideEffects: Array.from(this._unknownSideEffects)
159
150
  };
160
151
  }
152
+ /** A view of this graph without the environments of its vertices and subflows, sharing everything else. */
153
+ withoutEnvironments() {
154
+ const graph = new DataflowGraph(this._idMap);
155
+ graph.rootVertices = this.rootVertices;
156
+ graph.edgeInformation = this.edgeInformation;
157
+ graph.types = this.types;
158
+ graph.vertexInformation = new Map(Array.from(this.vertexInformation, ([id, vertex]) => [id, (vertex_2.DfgVertex.isFunctionDefinition(vertex)
159
+ ? { ...vertex, environment: undefined, subflow: { ...vertex.subflow, environment: undefined } }
160
+ : { ...vertex, environment: undefined })]));
161
+ graph.mergeRootsAndUnknowns(this, false);
162
+ return graph;
163
+ }
161
164
  /** Gets the {@link DataflowGraphVertexInfo} attached to `id` (searching function definitions too if `includeDefinedFunctions`) and its outgoing edges. */
162
165
  get(id, includeDefinedFunctions = true) {
163
- // if we do not want to include function definitions, only retrieve the value if the id is part of the root vertices
164
166
  const vertex = includeDefinedFunctions ? this.getVertex(id) : this.getRootVertex(id);
165
167
  return vertex === undefined ? undefined : [vertex, this.outgoingEdges(id) ?? new Map()];
166
168
  }
@@ -170,10 +172,7 @@ class DataflowGraph {
170
172
  }
171
173
  /** Gets the {@link DataflowGraphVertexInfo} attached to `id`, but only if it is a root-level vertex, see {@link DataflowGraph#getVertex}. */
172
174
  getRootVertex(id) {
173
- if (!this.rootVertices.has(id)) {
174
- return undefined;
175
- }
176
- return this.vertexInformation.get(id);
175
+ return this.rootVertices.has(id) ? this.vertexInformation.get(id) : undefined;
177
176
  }
178
177
  /**
179
178
  * The edges leaving `id`, the mutable map the graph stores, `undefined` for a vertex that has none.
@@ -212,7 +211,7 @@ class DataflowGraph {
212
211
  ingoingEdges(id) {
213
212
  if (this.incomingIndex === undefined) {
214
213
  const index = new Map();
215
- for (const [source, outgoing] of this.edgeInformation.entries()) {
214
+ for (const [source, outgoing] of this.edgeInformation) {
216
215
  for (const [target, edge] of outgoing) {
217
216
  const into = index.get(target);
218
217
  if (into === undefined) {
@@ -236,10 +235,10 @@ class DataflowGraph {
236
235
  isQuoted(id, withOutgoing = false) {
237
236
  /* an nse edge quotes iff it does not originate from a loop marking its body */
238
237
  const quotes = (source, e) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.NonStandardEvaluation) && !model_1.RLoopConstructs.is(this.idMap?.get(source));
239
- if (this.ingoingEdges(id)?.entries().some(([source, e]) => quotes(source, e))) {
238
+ if (this.edgesTo(id).entries().some(([source, e]) => quotes(source, e))) {
240
239
  return true;
241
240
  }
242
- return withOutgoing && (this.outgoingEdges(id)?.values().some(e => quotes(id, e)) ?? false);
241
+ return withOutgoing && this.edgesFrom(id).values().some(e => quotes(id, e));
243
242
  }
244
243
  /**
245
244
  * The cached `pkg::fn` name of the call `id`, asking `resolve` only for a call the cache does not know yet.
@@ -287,9 +286,7 @@ class DataflowGraph {
287
286
  /** Drops the cached qualifications, as the graph may no longer imply them. Every mutator runs through here, so the guard covers them all. */
288
287
  dropQualifications() {
289
288
  (0, assert_1.guard)(!this.consumed, 'this graph was consumed by a merge and must not be changed any more');
290
- if (this.qualifiedNames !== undefined) {
291
- this.qualifiedNames = undefined;
292
- }
289
+ this.qualifiedNames = undefined;
293
290
  }
294
291
  /** For a node of the normalized AST: `nodeId` if it is a DFG vertex itself, else the DFG vertices linked to it, else `undefined`. */
295
292
  getLinked(nodeId) {
@@ -329,11 +326,7 @@ class DataflowGraph {
329
326
  }
330
327
  /** Every vertex carrying `type`, in the order the graph learned of them. */
331
328
  *verticesOfType(type) {
332
- const ids = this.types.get(type);
333
- if (ids === undefined) {
334
- return;
335
- }
336
- for (const id of ids) {
329
+ for (const id of this.types.get(type) ?? []) {
337
330
  const vertex = this.vertexInformation.get(id);
338
331
  /* a stale entry would hand out a vertex without the fields its tag promises */
339
332
  if (vertex?.tag === type) {
@@ -343,11 +336,7 @@ class DataflowGraph {
343
336
  }
344
337
  /** The ids of {@link DataflowGraph#verticesOfType|verticesOfType}, as a fresh array the caller may keep. */
345
338
  vertexIdsOfType(type) {
346
- const ids = this.types.get(type);
347
- if (ids === undefined) {
348
- return [];
349
- }
350
- return ids.filter(id => this.vertexInformation.get(id)?.tag === type);
339
+ return this.types.get(type)?.filter(id => this.vertexInformation.get(id)?.tag === type) ?? [];
351
340
  }
352
341
  /** Ids of all edges in the graph together with their edge information, see {@link DataflowGraph#vertices}. */
353
342
  *edges() {
@@ -420,7 +409,7 @@ class DataflowGraph {
420
409
  }
421
410
  this.dropQualifications();
422
411
  const vtag = vertex.tag;
423
- // keep a clone of the original environment, isolating the snapshot from later updates
412
+ /* keep a clone of the original environment, isolating the snapshot from later updates */
424
413
  let environment;
425
414
  if (vertex.environment) {
426
415
  environment = (0, clone_1.cloneEnvironmentInformation)(vertex.environment);
@@ -431,9 +420,7 @@ class DataflowGraph {
431
420
  }
432
421
  vertex.environment = environment;
433
422
  this.vertexInformation.set(vid, vertex);
434
- if (gas_1.activeDataflowBudget !== undefined) {
435
- gas_1.activeDataflowBudget.vertex();
436
- }
423
+ gas_1.activeDataflowBudget?.vertex();
437
424
  /* an overwrite keeping the tag is indexed already */
438
425
  if (previous?.tag !== vtag) {
439
426
  if (previous !== undefined) {
@@ -494,14 +481,30 @@ class DataflowGraph {
494
481
  return this;
495
482
  }
496
483
  (0, assert_1.guard)(!otherGraph.consumed, 'a graph consumed by an earlier merge cannot be merged again');
497
- this.mergeVertices(otherGraph, mergeRootVertices);
498
- this.mergeEdges(otherGraph, consume);
484
+ if (consume && this.vertexInformation.size === 0 && this.edgeInformation.size === 0) {
485
+ this.adopt(otherGraph, mergeRootVertices);
486
+ }
487
+ else {
488
+ this.mergeVertices(otherGraph, mergeRootVertices);
489
+ this.mergeEdges(otherGraph, consume);
490
+ }
499
491
  otherGraph.consumed ||= consume;
500
492
  return this;
501
493
  }
502
- mergeVertices(otherGraph, mergeRootVertices = true) {
494
+ /** An empty graph takes over the contents of a graph it consumes rather than copying them entry by entry. */
495
+ adopt(otherGraph, mergeRootVertices) {
503
496
  this.dropQualifications();
504
- // merge root ids
497
+ this.vertexInformation = otherGraph.vertexInformation;
498
+ this.edgeInformation = otherGraph.edgeInformation;
499
+ this.types = otherGraph.types;
500
+ this.incomingIndex = undefined;
501
+ const takeRoots = mergeRootVertices && this.rootVertices.size === 0;
502
+ if (takeRoots) {
503
+ this.rootVertices = otherGraph.rootVertices;
504
+ }
505
+ this.mergeRootsAndUnknowns(otherGraph, mergeRootVertices && !takeRoots);
506
+ }
507
+ mergeRootsAndUnknowns(otherGraph, mergeRootVertices) {
505
508
  if (mergeRootVertices) {
506
509
  for (const root of otherGraph.rootVertices) {
507
510
  this.rootVertices.add(root);
@@ -510,6 +513,10 @@ class DataflowGraph {
510
513
  for (const unknown of otherGraph.unknownSideEffects) {
511
514
  this._unknownSideEffects.add(unknown);
512
515
  }
516
+ }
517
+ mergeVertices(otherGraph, mergeRootVertices = true) {
518
+ this.dropQualifications();
519
+ this.mergeRootsAndUnknowns(otherGraph, mergeRootVertices);
513
520
  /* the tags of the vertices coming in repeat, so the list each goes on is looked up only when it changes */
514
521
  let lastTag;
515
522
  let lastIds = [];
@@ -602,14 +609,10 @@ class DataflowGraph {
602
609
  }
603
610
  /** Marks the given node as having unknown side effects */
604
611
  markIdForUnknownSideEffects(id, target) {
605
- if (target) {
606
- this._unknownSideEffects.add({
607
- id: node_id_1.NodeId.normalize(id),
608
- linkTo: typeof target.callName === 'string' ? { ...target, callName: new RegExp(target.callName) } : target
609
- });
610
- return this;
611
- }
612
- this._unknownSideEffects.add(node_id_1.NodeId.normalize(id));
612
+ this._unknownSideEffects.add(target ? {
613
+ id: node_id_1.NodeId.normalize(id),
614
+ linkTo: typeof target.callName === 'string' ? { ...target, callName: new RegExp(target.callName) } : target
615
+ } : node_id_1.NodeId.normalize(id));
613
616
  return this;
614
617
  }
615
618
  /** Constructs a dataflow graph instance from the given JSON data, e.g. as sent by the flowR server for further analysis. */
@@ -634,10 +637,7 @@ class DataflowGraph {
634
637
  }
635
638
  exports.DataflowGraph = DataflowGraph;
636
639
  function mergeNodeInfos(current, next) {
637
- if (current.tag !== next.tag) {
638
- return current;
639
- }
640
- else if (vertex_2.DfgVertex.isFunctionDefinition(current)) {
640
+ if (current.tag === next.tag && vertex_2.DfgVertex.isFunctionDefinition(current)) {
641
641
  const n = next;
642
642
  current.exitPoints = (0, arrays_1.uniqueArrayMerge)(current.exitPoints, n.exitPoints);
643
643
  if (n.mode && n.mode.length > 0) {
@@ -653,24 +653,15 @@ function mergeNodeInfos(current, next) {
653
653
  }
654
654
  function envFromJson(json) {
655
655
  const parent = json.parent ? envFromJson(json.parent) : undefined;
656
- const memory = new Map();
657
- for (const [key, value] of Object.entries(json.memory)) {
658
- memory.set(key, value);
659
- }
660
- const obj = new environment_1.Environment(parent, json.builtInEnv);
661
- obj.id = json.id;
662
- obj.adoptMap(memory);
663
- const env = obj;
656
+ const env = new environment_1.Environment(parent, json.builtInEnv);
657
+ env.id = json.id;
658
+ env.adoptMap(new Map(Object.entries(json.memory)));
664
659
  env.n = json.n;
665
660
  env.t = json.t;
666
661
  env.globalEnv = json.globalEnv;
667
662
  return env;
668
663
  }
669
664
  function renvFromJson(json) {
670
- const current = envFromJson(json.current);
671
- return {
672
- current,
673
- level: json.level
674
- };
665
+ return { current: envFromJson(json.current), level: json.level };
675
666
  }
676
667
  //# sourceMappingURL=graph.js.map
@@ -21,6 +21,8 @@ export interface ControlDependency {
21
21
  readonly when?: boolean;
22
22
  /** whether this control dependency was created due to iteration (e.g., a loop) */
23
23
  readonly byIteration?: boolean;
24
+ /** whether this control dependency is a promise's: what stands under it runs only once the call `id` forces it, see {@link ControlFlow.withinPromise} */
25
+ readonly byPromise?: boolean;
24
26
  /**
25
27
  * any file-exist assumptions made
26
28
  */
@@ -93,6 +95,8 @@ export interface ExitPoint {
93
95
  readonly type: ExitPointType;
94
96
  /** The id of the node which causes the exit point! */
95
97
  readonly nodeId: NodeId;
98
+ /** The jump this exit stands for, when {@link ExitPoint#nodeId|nodeId} is a construct it leaves through */
99
+ readonly jump?: NodeId;
96
100
  /**
97
101
  * Control dependencies which influence if the exit point triggers
98
102
  * (e.g., if the `return` is contained within an `if` statement).
@@ -100,12 +104,15 @@ export interface ExitPoint {
100
104
  */
101
105
  readonly cds?: ControlDependency[];
102
106
  }
107
+ /** `exit` leaving through the construct `rootId`, which keeps the jump it stands for. */
108
+ export declare function leaveThrough(exit: ExitPoint, rootId: NodeId): ExitPoint;
103
109
  /**
104
110
  * Adds all non-default exit points to the existing list and updates the `invertExitCds` accordingly.
105
111
  */
106
112
  export declare function addNonDefaultExitPoints(existing: ExitPoint[], invertExitCds: ControlDependency[], activeCds: ControlDependency[] | undefined, add: readonly ExitPoint[]): void;
107
113
  /**
108
- * Overwrites the existing exit points with the given ones, taking care of cds.
114
+ * Overwrites the existing exit points with the given ones, taking care of cds:
115
+ * the existing ones stay if the replacements only happen in some branches.
109
116
  */
110
117
  export declare function overwriteExitPoints(existing: readonly ExitPoint[], replace: ExitPoint[]): ExitPoint[];
111
118
  /**
package/dataflow/info.js CHANGED
@@ -5,6 +5,7 @@ exports.appendCds = appendCds;
5
5
  exports.withCds = withCds;
6
6
  exports.negateControlDependency = negateControlDependency;
7
7
  exports.doesExitPointPropagateCalls = doesExitPointPropagateCalls;
8
+ exports.leaveThrough = leaveThrough;
8
9
  exports.addNonDefaultExitPoints = addNonDefaultExitPoints;
9
10
  exports.overwriteExitPoints = overwriteExitPoints;
10
11
  exports.happensInEveryBranch = happensInEveryBranch;
@@ -13,7 +14,6 @@ exports.filterOutLoopExitPoints = filterOutLoopExitPoints;
13
14
  exports.diffControlDependency = diffControlDependency;
14
15
  exports.diffControlDependencies = diffControlDependencies;
15
16
  const graph_1 = require("./graph/graph");
16
- const assert_1 = require("../util/assert");
17
17
  const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
18
18
  /** Whether the two control dependencies trigger on the same condition and branch. */
19
19
  function sameControlDependency(a, b) {
@@ -48,10 +48,7 @@ exports.ControlDependency = {
48
48
  };
49
49
  /** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
50
50
  function appendCds(target, toAdd) {
51
- if (!toAdd) {
52
- return;
53
- }
54
- for (const add of toAdd) {
51
+ for (const add of toAdd ?? []) {
55
52
  if (!target.some(have => sameControlDependency(have, add))) {
56
53
  target.push(add);
57
54
  }
@@ -59,7 +56,7 @@ function appendCds(target, toAdd) {
59
56
  }
60
57
  /** A copy of `base` with `toAdd` appended, skipping the control dependencies that are already in there. */
61
58
  function withCds(base, toAdd) {
62
- const result = base ? Array.from(base) : [];
59
+ const result = [...base ?? []];
63
60
  appendCds(result, toAdd);
64
61
  return result;
65
62
  }
@@ -79,30 +76,29 @@ function negateControlDependency(cd) {
79
76
  function doesExitPointPropagateCalls(type) {
80
77
  return type === 4 /* ExitPointType.Error */;
81
78
  }
79
+ /** `exit` leaving through the construct `rootId`, which keeps the jump it stands for. */
80
+ function leaveThrough(exit, rootId) {
81
+ return { ...exit, nodeId: rootId, jump: exit.jump ?? exit.nodeId };
82
+ }
82
83
  /**
83
84
  * Adds all non-default exit points to the existing list and updates the `invertExitCds` accordingly.
84
85
  */
85
86
  function addNonDefaultExitPoints(existing, invertExitCds, activeCds, add) {
86
- const toAdd = add.filter(({ type }) => type !== 0 /* ExitPointType.Default */);
87
- if (toAdd.length === 0) {
88
- return;
89
- }
90
- const invertedCds = toAdd.flatMap(e => e.cds?.filter(icd => !activeCds?.some(e => e.id === icd.id && e.when === icd.when)).map(negateControlDependency)).filter(assert_1.isNotUndefined);
91
- for (const ep of toAdd) {
92
- existing.push(ep);
93
- }
94
- for (const icd of invertedCds) {
95
- if (!invertExitCds.some(e => e.id === icd.id && e.when === icd.when)) {
96
- invertExitCds.push(icd);
87
+ for (const ep of add) {
88
+ if (ep.type !== 0 /* ExitPointType.Default */) {
89
+ existing.push(ep);
90
+ const ownCds = exports.ControlDependency.minus(ep.cds ?? [], activeCds ?? []);
91
+ appendCds(invertExitCds, ownCds.map(negateControlDependency));
97
92
  }
98
93
  }
99
94
  }
100
95
  /**
101
- * Overwrites the existing exit points with the given ones, taking care of cds.
96
+ * Overwrites the existing exit points with the given ones, taking care of cds:
97
+ * the existing ones stay if the replacements only happen in some branches.
102
98
  */
103
99
  function overwriteExitPoints(existing, replace) {
104
100
  const replaceCds = replace.flatMap(e => e.cds);
105
- if (replaceCds.length === 0 || replaceCds.includes(undefined) || happensInEveryBranch(replaceCds.filter(e => e !== undefined))) {
101
+ if (replaceCds.length === 0 || replaceCds.includes(undefined) || happensInEveryBranch(replaceCds)) {
106
102
  return replace;
107
103
  }
108
104
  return existing.concat(replace);
@@ -149,22 +145,20 @@ function happensInEveryBranch(cds) {
149
145
  function coversSet(cds) {
150
146
  /* as deep as the surrounding branches, so the pairwise scan beats any set */
151
147
  for (const { id, when } of cds) {
152
- if (when !== true && when !== false) {
153
- continue;
154
- }
155
- let counterpart = false;
156
- for (const other of cds) {
157
- if (other.id === id && other.when === !when) {
158
- counterpart = true;
159
- break;
160
- }
161
- }
162
- if (!counterpart) {
148
+ if (when !== undefined && !hasCounterpart(cds, id, !when)) {
163
149
  return false;
164
150
  }
165
151
  }
166
152
  return true;
167
153
  }
154
+ function hasCounterpart(cds, id, when) {
155
+ for (const other of cds) {
156
+ if (other.id === id && other.when === when) {
157
+ return true;
158
+ }
159
+ }
160
+ return false;
161
+ }
168
162
  /** As {@link happensInEveryBranch}, but for a set of control dependencies. */
169
163
  function happensInEveryBranchSet(cds) {
170
164
  return cds === undefined || (cds.size !== 0 && coversSet(cds));