@eagleoutice/flowr 2.15.9 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.strictnessOfEach = strictnessOfEach;
4
+ exports.promiseDependencies = promiseDependencies;
5
+ exports.promiseForcing = promiseForcing;
6
+ exports.settleJumpsInPromises = settleJumpsInPromises;
4
7
  /**
5
8
  * The `FunctionSemantics` facade wires these together, so a sibling here has to call the backing function
6
9
  * directly; going through `FunctionSemantics` would make `src/dataflow/fn/function-semantics.ts` import its own importers.
@@ -9,7 +12,11 @@ exports.strictnessOfEach = strictnessOfEach;
9
12
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
10
13
  const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
11
14
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
15
+ const info_1 = require("../info");
12
16
  const edge_1 = require("../graph/edge");
17
+ const node_value_1 = require("../eval/resolve/node-value");
18
+ const resolve_helper_1 = require("../environments/resolve-helper");
19
+ const call_graph_1 = require("../graph/call-graph");
13
20
  const vertex_1 = require("../graph/vertex");
14
21
  const built_in_proc_name_1 = require("../environments/built-in-proc-name");
15
22
  const built_in_props_1 = require("../environments/built-in-props");
@@ -20,6 +27,8 @@ const logic_1 = require("../../util/logic");
20
27
  const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
21
28
  const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
22
29
  const r_parameter_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
30
+ const assert_1 = require("../../util/assert");
31
+ const defaultmap_1 = require("../../util/collections/defaultmap");
23
32
  /**
24
33
  * What an argument is used for when the call never evaluates it: quoted or read in another frame
25
34
  * ({@link ArgProp.Nse}), or looked at only for having been supplied ({@link ArgProp.Presence}).
@@ -38,9 +47,7 @@ const LazyAfterFirst = [built_in_proc_name_1.BuiltInProcName.Switch, built_in_pr
38
47
  */
39
48
  const LazyThroughout = [built_in_proc_name_1.BuiltInProcName.RegisterHook, built_in_proc_name_1.BuiltInProcName.Recall];
40
49
  /** The processors dispatching to a method chosen at run time. */
41
- const DispatchProcessors = [
42
- built_in_proc_name_1.BuiltInProcName.S3Dispatch, built_in_proc_name_1.BuiltInProcName.S3DispatchNext, built_in_proc_name_1.BuiltInProcName.S7Dispatch
43
- ];
50
+ const DispatchProcessors = [built_in_proc_name_1.BuiltInProcName.S3Dispatch, built_in_proc_name_1.BuiltInProcName.S3DispatchNext, built_in_proc_name_1.BuiltInProcName.S7Dispatch];
44
51
  /**
45
52
  * Whether the call hands the work to a method chosen at run time: flowR's own dispatch processors say so for
46
53
  * `UseMethod` and `NextMethod`, and {@link DispatchCallees} covers the ones it has no processor for.
@@ -56,50 +63,66 @@ function hasProcessor(vertex, of) {
56
63
  function enclosingDefinition(id, idMap, graph) {
57
64
  return model_1.RNode.findEnclosing(id, idMap, node => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(node.info.id)));
58
65
  }
59
- function makeState(graph, ctx) {
66
+ /** The definitions whose body dispatches, with what each dispatch does with the arguments. */
67
+ function dispatchingDefinitions(graph) {
60
68
  const idMap = graph.idMap;
69
+ const dispatch = new Map();
70
+ if (idMap === undefined) {
71
+ return dispatch;
72
+ }
73
+ for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
74
+ if (!isDispatch(vertex) || typeof node_id_1.NodeId.normalize(id) !== 'number') {
75
+ continue;
76
+ }
77
+ const within = enclosingDefinition(id, idMap, graph);
78
+ if (within === undefined) {
79
+ continue;
80
+ }
81
+ const node = idMap.get(id);
82
+ const known = dispatch.get(within);
83
+ dispatch.set(within, {
84
+ named: (r_function_call_1.RFunctionCall.is(node) && node.arguments.length > 1) || (known?.named ?? false),
85
+ certain: conditionsBeyond(vertex.cds, graph.getVertex(within)?.cds).length === 0 || (known?.certain ?? false),
86
+ next: [...known?.next ?? [], ...(0, frame_reflection_1.calledDefinitions)(graph, id).filter(t => t !== within)]
87
+ });
88
+ }
89
+ return dispatch;
90
+ }
91
+ /** The logical value the condition of an `if` holds wherever it is reached, `undefined` if it may differ. */
92
+ function branchOutcomes(graph, ctx) {
93
+ return (0, defaultmap_1.memoize)((ifCall) => {
94
+ const call = graph.getVertex(ifCall);
95
+ const isIf = vertex_1.DfgVertex.hasOrigin(call, built_in_proc_name_1.BuiltInProcName.IfThenElse) && vertex_1.DfgVertex.isFunctionCall(call);
96
+ const condition = isIf ? call.args[0] : r_function_call_1.EmptyArgument;
97
+ if (ctx === undefined || condition === r_function_call_1.EmptyArgument) {
98
+ return undefined;
99
+ }
100
+ const values = node_value_1.NodeValue.setOf(condition.nodeId, resolve_helper_1.Resolve.info(graph, ctx))?.elements ?? [];
101
+ const outcomes = new Set(values.map(v => v.type === 'logical' && typeof v.value === 'boolean' ? v.value : undefined));
102
+ return outcomes.size === 1 ? [...outcomes][0] : undefined;
103
+ });
104
+ }
105
+ function makeState(graph, ctx) {
61
106
  const owner = new Map();
62
107
  for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
63
108
  for (const param of Object.keys(vertex.params)) {
64
109
  owner.set(node_id_1.NodeId.normalize(param), id);
65
110
  }
66
111
  }
67
- const environment = ctx?.env.makeCleanEnv();
68
- const info = environment === undefined
69
- ? (name) => query_fn_props_1.BuiltInIndex.default().get(name)
70
- : (name) => (0, query_fn_props_1.queryFnProps)(name, { environment });
71
- const infos = new Map();
72
- const fnInfo = (name) => {
73
- const key = identifier_1.Identifier.getName(name);
74
- if (!infos.has(key)) {
75
- infos.set(key, info(name));
76
- }
77
- return infos.get(key);
112
+ return {
113
+ graph,
114
+ idMap: graph.idMap,
115
+ owner,
116
+ dispatch: dispatchingDefinitions(graph),
117
+ fnInfo: (0, query_fn_props_1.builtInLookup)(ctx),
118
+ branches: branchOutcomes(graph, ctx),
119
+ untargeted: new Map(),
120
+ known: new Map(),
121
+ provisional: new Map(),
122
+ assumptions: new Map(),
123
+ asking: new Set(),
124
+ assumed: false
78
125
  };
79
- const dispatch = new Map();
80
- if (idMap !== undefined) {
81
- for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
82
- if (!isDispatch(vertex) || typeof node_id_1.NodeId.normalize(id) !== 'number') {
83
- continue;
84
- }
85
- const within = enclosingDefinition(id, idMap, graph);
86
- if (within === undefined) {
87
- continue;
88
- }
89
- const node = idMap.get(id);
90
- const known = dispatch.get(within);
91
- const named = (r_function_call_1.RFunctionCall.is(node) && (node.arguments?.length ?? 0) > 1) || (known?.named ?? false);
92
- const certain = !underCondition(vertex.cds, graph.getVertex(within)?.cds) || (known?.certain ?? false);
93
- const next = [...known?.next ?? []];
94
- for (const [target, edge] of graph.edgesFrom(id)) {
95
- if (target !== within && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(target))) {
96
- next.push(target);
97
- }
98
- }
99
- dispatch.set(within, { named, certain, next });
100
- }
101
- }
102
- return { graph, idMap, owner, dispatch, fnInfo, sigs: new Map(), props: name => fnInfo(name)?.sig, known: new Map(), asking: new Set(), assumed: false };
103
126
  }
104
127
  /** What is certain becomes a possibility once something may intervene. */
105
128
  function weaken(value) {
@@ -112,9 +135,9 @@ function agree(values) {
112
135
  }
113
136
  return values.every(v => v === values[0]) ? values[0] : logic_1.Ternary.Maybe;
114
137
  }
115
- /** Whether the control dependencies exceed the ones the definition itself stands under. */
116
- function underCondition(cds, definition) {
117
- return cds?.some(c => !definition?.some(d => d.id === c.id && d.when === c.when)) ?? false;
138
+ /** The control dependencies beyond the definition's own; a `byPromise` one is no condition here, the walk up asks its holder. */
139
+ function conditionsBeyond(cds, definition) {
140
+ return info_1.ControlDependency.minus(cds ?? [], definition ?? []).filter(c => c.byPromise !== true);
118
141
  }
119
142
  /**
120
143
  * Built-ins force what they are given, and the ones that do not (`quote` and its relatives) leave no read of
@@ -141,50 +164,68 @@ function argumentIndex(call, child, idMap) {
141
164
  return call.args.findIndex(arg => arg !== r_function_call_1.EmptyArgument && (arg.nodeId === child || arg.nodeId === value));
142
165
  }
143
166
  /** Whether the node is the function a call is of rather than something handed to it. */
144
- function isCallee(call, child, idMap) {
145
- const node = idMap.get(call);
146
- if (!r_function_call_1.RFunctionCall.is(node)) {
167
+ function isCallee(call, child) {
168
+ if (!r_function_call_1.RFunctionCall.is(call)) {
147
169
  return false;
148
170
  }
149
- return (r_function_call_1.RFunctionCall.isNamed(node) ? node.functionName.info.id : node.calledFunction.info.id) === child;
171
+ return (r_function_call_1.RFunctionCall.isNamed(call) ? call.functionName.info.id : call.calledFunction.info.id) === child;
150
172
  }
151
173
  /**
152
174
  * What flowR states the argument at `index` of the call is used for. A `...` covers every position from
153
175
  * where it is declared, which {@link FunctionSemantics.call.signature.propAt} takes care of.
154
176
  */
155
177
  function argProps(vertex, index, state) {
156
- const name = identifier_1.Identifier.getName(vertex.name);
157
- let sig = state.sigs.get(name);
158
- if (sig === undefined && !state.sigs.has(name)) {
159
- state.sigs.set(name, sig = state.props(vertex.name));
160
- }
161
- return sig === undefined || index < 0 ? 0 : built_in_props_1.FnSig.propAt(built_in_props_1.FnSig.layout(sig), index);
178
+ const sig = index < 0 ? undefined : state.fnInfo(vertex.name)?.sig;
179
+ return sig === undefined ? 0 : built_in_props_1.FnSig.propAt(built_in_props_1.FnSig.layout(sig), index);
162
180
  }
163
181
  /** The verdict a callee's parameter carries over to what is handed to it. */
164
182
  function handedTo(param, state) {
165
183
  const owner = state.owner.get(param);
166
184
  return owner === undefined ? logic_1.Ternary.Maybe : strictnessOf(owner, state).parameters[param] ?? logic_1.Ternary.Maybe;
167
185
  }
186
+ /** Whether the call reads a name from the program itself (a parameter, a variable) rather than a built-in. */
187
+ function readsProgramName(call, graph) {
188
+ for (const [target, edge] of graph.edgesFrom(call.id)) {
189
+ if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && !edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument) && !node_id_1.NodeId.isBuiltIn(target)) {
190
+ return true;
191
+ }
192
+ }
193
+ return false;
194
+ }
195
+ /** The parameter at `index` of the definition, `undefined` if it is no definition or a `...` comes first. */
196
+ function parameterAt(definition, index, idMap, graph) {
197
+ const node = idMap.get(definition);
198
+ if (!vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(definition)) || !r_function_definition_1.RFunctionDefinition.is(node)) {
199
+ return undefined;
200
+ }
201
+ const dotsBefore = node.parameters.slice(0, index + 1).some(r_parameter_1.RParameter.isDotDotDotDot);
202
+ return dotsBefore ? undefined : node.parameters[index]?.name.info.id;
203
+ }
204
+ /** The parameters an argument of `call` binds to, by position in each definition an unlinked call may reach, `undefined` if unknown. */
205
+ function boundParameters(call, argument, idMap, graph, origins) {
206
+ const sources = new Set([argument, argumentValue(argument, idMap)]);
207
+ const linked = [...sources].flatMap(from => (0, frame_reflection_1.edgeTargets)(graph, from, edge_1.EdgeType.DefinesOnCall));
208
+ if (linked.length > 0 || (0, frame_reflection_1.calledDefinitions)(graph, call.id).length > 0) {
209
+ return linked;
210
+ }
211
+ const index = argumentIndex(call, argument, idMap);
212
+ const arg = call.args[index];
213
+ if (index < 0 || arg === r_function_call_1.EmptyArgument || arg.name !== undefined || !readsProgramName(call, graph)) {
214
+ return undefined;
215
+ }
216
+ const found = origins?.get(call.id) ?? [...(0, call_graph_1.fallbackUntargetedCall)(call, graph)];
217
+ origins?.set(call.id, found);
218
+ const params = found.map(definition => parameterAt(definition, index, idMap, graph));
219
+ return params.length > 0 && params.every(assert_1.isNotUndefined) ? params : undefined;
220
+ }
168
221
  /**
169
222
  * Whether handing `argument` to `call` forces it. An argument the call passes on is forced exactly as the
170
223
  * function receiving it forces the parameter it binds to; a call flowR cannot resolve, and one whose argument
171
224
  * it cannot match to a parameter, leave the question open.
172
225
  */
173
226
  function forcedByCallee(call, argument, idMap, state) {
174
- const resolved = [...state.graph.edgesFrom(call.id)]
175
- .some(([target, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && vertex_1.DfgVertex.isFunctionDefinition(state.graph.getVertex(target)));
176
- if (!resolved) {
177
- return logic_1.Ternary.Maybe;
178
- }
179
- const bound = [];
180
- for (const from of new Set([argument, argumentValue(argument, idMap)])) {
181
- for (const [target, edge] of state.graph.edgesFrom(from)) {
182
- if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinesOnCall)) {
183
- bound.push(handedTo(target, state));
184
- }
185
- }
186
- }
187
- return bound.length === 0 ? logic_1.Ternary.Maybe : agree(bound);
227
+ const bound = boundParameters(call, argument, idMap, state.graph, state.untargeted);
228
+ return bound === undefined || bound.length === 0 ? logic_1.Ternary.Maybe : agree(bound.map(param => handedTo(param, state)));
188
229
  }
189
230
  /**
190
231
  * How far the given read of a parameter is unavoidable: it has to stand under no condition the definition
@@ -194,72 +235,79 @@ function forcedByCallee(call, argument, idMap, state) {
194
235
  function forces(read, definition, state) {
195
236
  const idMap = state.idMap;
196
237
  if (idMap === undefined) {
197
- return logic_1.Ternary.Maybe;
238
+ return { value: logic_1.Ternary.Maybe };
198
239
  }
199
- let certain = true;
240
+ /* the branches the read sits in, and whether anything else keeps it from being certain */
241
+ const conditions = [];
242
+ let lazy = false;
243
+ const verdict = (value) => ({
244
+ value: lazy || conditions.length > 0 ? weaken(value) : value,
245
+ onlyUnder: lazy || value !== logic_1.Ternary.Always ? undefined : conditions
246
+ });
200
247
  let child = read;
201
248
  let node = idMap.get(read);
202
249
  while (node !== undefined && node.info.id !== definition.id) {
203
250
  const vertex = state.graph.getVertex(node.info.id);
204
- if (underCondition(vertex?.cds, definition.cds)) {
205
- certain = false;
251
+ for (const cd of conditionsBeyond(vertex?.cds, definition.cds)) {
252
+ const holds = cd.when === undefined ? undefined : state.branches(cd.id);
253
+ if (holds === undefined) {
254
+ info_1.ControlDependency.append(conditions, [cd]);
255
+ }
256
+ else if (holds !== cd.when) {
257
+ return { value: logic_1.Ternary.Never };
258
+ }
206
259
  }
207
260
  if (node.info.id !== read) {
208
- if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
209
- /* nothing says the nested definition is ever called */
210
- certain = false;
211
- }
212
- else if (r_parameter_1.RParameter.is(node)) {
213
- /* a default is evaluated only when the argument is left out */
214
- certain = false;
261
+ if (vertex_1.DfgVertex.isFunctionDefinition(vertex) || r_parameter_1.RParameter.is(node)) {
262
+ /* nothing says a nested definition is ever called, and a default is evaluated only when the argument is left out */
263
+ lazy = true;
215
264
  }
216
- else if (vertex_1.DfgVertex.isFunctionCall(vertex) && !isDispatch(vertex) && !isCallee(node.info.id, child, idMap)) {
265
+ else if (vertex_1.DfgVertex.isFunctionCall(vertex) && !isDispatch(vertex) && !isCallee(node, child)) {
217
266
  if (!isBuiltInCall(vertex)) {
218
- const handed = forcedByCallee(vertex, child, idMap, state);
219
- return certain ? handed : weaken(handed);
267
+ return verdict(forcedByCallee(vertex, child, idMap, state));
220
268
  }
221
269
  const index = argumentIndex(vertex, child, idMap);
222
270
  const props = argProps(vertex, index, state);
223
271
  if ((props & NotEvaluated) !== 0) {
224
- return logic_1.Ternary.Never;
272
+ return { value: logic_1.Ternary.Never };
225
273
  }
226
274
  else if ((props & built_in_props_1.ArgProp.Forced) === 0
227
275
  && (hasProcessor(vertex, LazyThroughout) || (index !== 0 && hasProcessor(vertex, LazyAfterFirst)))) {
228
- certain = false;
276
+ lazy = true;
229
277
  }
230
278
  }
231
279
  }
232
280
  child = node.info.id;
233
281
  node = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
234
282
  }
235
- if (node === undefined) {
236
- return logic_1.Ternary.Never;
237
- }
238
- return certain ? logic_1.Ternary.Always : logic_1.Ternary.Maybe;
283
+ return node === undefined ? { value: logic_1.Ternary.Never } : verdict(logic_1.Ternary.Always);
239
284
  }
240
285
  function strictnessOfParameter(param, definition, state) {
241
286
  const reads = [];
242
- for (const [read, edge] of state.graph.edgesTo(param)) {
243
- if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
244
- reads.push(forces(read, definition, state));
287
+ const branches = [];
288
+ for (const read of (0, frame_reflection_1.edgeSources)(state.graph, param, edge_1.EdgeType.Reads)) {
289
+ /* a `NextMethod` hands the parameter on unforced, the methods it reaches decide below */
290
+ if (!vertex_1.DfgVertex.hasOrigin(state.graph.getVertex(read), built_in_proc_name_1.BuiltInProcName.S3DispatchNext)) {
291
+ const { value, onlyUnder = [] } = forces(read, definition, state);
292
+ reads.push(value);
293
+ branches.push(...onlyUnder);
245
294
  }
246
295
  }
296
+ if (info_1.ControlDependency.happensInEveryBranch(branches)) {
297
+ reads.push(logic_1.Ternary.Always);
298
+ }
247
299
  const dispatch = state.dispatch.get(definition.id);
248
300
  if (dispatch !== undefined) {
249
- const methods = [];
250
- for (const [target, edge] of state.graph.edgesFrom(param)) {
251
- if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinesOnCall)) {
252
- methods.push(handedTo(target, state));
253
- }
254
- }
255
- reads.push(dispatch.certain ? agree(methods) : weaken(agree(methods)));
301
+ const surely = (values) => dispatch.certain ? agree(values) : weaken(agree(values));
302
+ const methods = (0, frame_reflection_1.edgeTargets)(state.graph, param, edge_1.EdgeType.DefinesOnCall).map(target => handedTo(target, state));
303
+ reads.push(surely(methods));
256
304
  if (dispatch.next.length > 0) {
257
305
  const at = parameterIds(definition.id, state.idMap).indexOf(param);
258
306
  const along = at < 0 ? [] : dispatch.next.map(method => {
259
307
  const same = parameterIds(method, state.idMap)[at];
260
- return same === undefined ? logic_1.Ternary.Maybe : strictnessOf(method, state).parameters[same] ?? logic_1.Ternary.Maybe;
308
+ return same === undefined ? logic_1.Ternary.Maybe : handedTo(same, state);
261
309
  });
262
- reads.push(dispatch.certain ? agree(along) : weaken(agree(along)));
310
+ reads.push(surely(along));
263
311
  }
264
312
  }
265
313
  return logic_1.TernaryLogic.or(...reads);
@@ -269,8 +317,10 @@ function parameterIds(definition, idMap) {
269
317
  const node = idMap?.get(definition);
270
318
  return r_function_definition_1.RFunctionDefinition.is(node) ? node.parameters.map(p => p.name.info.id) : [];
271
319
  }
320
+ /** How many rounds a cycle of definitions gets to settle before all of them answer {@link Ternary#Maybe}. */
321
+ const MaxCycleRounds = 8;
272
322
  function strictnessOf(id, state) {
273
- const known = state.known.get(id);
323
+ const known = state.known.get(id) ?? state.provisional.get(id);
274
324
  if (known !== undefined) {
275
325
  return known;
276
326
  }
@@ -280,41 +330,70 @@ function strictnessOf(id, state) {
280
330
  }
281
331
  const params = Object.keys(vertex.params);
282
332
  if (state.asking.has(id)) {
283
- /* the answer is the one still being worked out */
333
+ /* a cycle starts out assuming every parameter is forced: a run that keeps recursing never returns, so that claims nothing */
284
334
  state.assumed = true;
285
- return { strict: logic_1.Ternary.Maybe, parameters: Object.fromEntries(params.map(param => [param, logic_1.Ternary.Maybe])) };
335
+ return state.assumptions.get(id) ?? uniform(params, logic_1.Ternary.Always);
286
336
  }
287
- state.asking.add(id);
288
- const parameters = {};
289
- for (const param of params) {
290
- parameters[param] = strictnessOfParameter(node_id_1.NodeId.normalize(param), vertex, state);
337
+ let result = computeStrictness(id, vertex, params, state);
338
+ if (!state.assumed) {
339
+ state.known.set(id, result);
291
340
  }
292
- /* reflection flowR could not follow may read a parameter without any read of it showing in the code */
293
- if (((0, frame_reflection_1.reflectiveRolesOf)(vertex, state.graph, { known: state.fnInfo }) & MayEvaluate) !== 0) {
294
- for (const param of params) {
295
- parameters[param] = logic_1.TernaryLogic.or(parameters[param], logic_1.Ternary.Maybe);
341
+ else if (state.asking.size === 0) {
342
+ /* the outermost question of a cycle: recompute it until a round is stable */
343
+ state.provisional.set(id, result);
344
+ let settled = false;
345
+ for (let round = 0; round < MaxCycleRounds && !settled; round++) {
346
+ state.assumptions = new Map(state.provisional);
347
+ state.provisional.clear();
348
+ state.assumed = false;
349
+ result = computeStrictness(id, vertex, params, state);
350
+ state.provisional.set(id, result);
351
+ settled = [...state.provisional].every(([other, r]) => sameStrictness(r, state.assumptions.get(other)));
296
352
  }
297
- }
298
- const dispatch = state.dispatch.get(id);
299
- if (dispatch !== undefined) {
300
- for (const param of params) {
301
- parameters[param] = logic_1.TernaryLogic.or(parameters[param], logic_1.Ternary.Maybe);
353
+ if (settled) {
354
+ /* the fixpoint holds for the whole cycle, so none of it has to be worked out again */
355
+ for (const [other, r] of state.provisional) {
356
+ state.known.set(other, r);
357
+ }
302
358
  }
303
- const object = dispatch.named ? undefined : parameterIds(id, state.idMap)[0];
304
- if (object !== undefined && parameters[object] !== undefined) {
305
- parameters[object] = dispatch.certain ? logic_1.Ternary.Always : logic_1.TernaryLogic.or(parameters[object], logic_1.Ternary.Maybe);
359
+ else {
360
+ result = uniform(params, logic_1.Ternary.Maybe);
306
361
  }
307
- }
308
- state.asking.delete(id);
309
- const result = { strict: logic_1.TernaryLogic.and(...Object.values(parameters)), parameters };
310
- if (!state.assumed) {
311
362
  state.known.set(id, result);
312
- }
313
- else if (state.asking.size === 0) {
363
+ state.assumptions = new Map();
314
364
  state.assumed = false;
365
+ state.provisional.clear();
366
+ }
367
+ else {
368
+ state.provisional.set(id, result);
315
369
  }
316
370
  return result;
317
371
  }
372
+ function uniform(params, value) {
373
+ return { strict: value, parameters: Object.fromEntries(params.map(param => [param, value])) };
374
+ }
375
+ function sameStrictness(a, b) {
376
+ return b !== undefined && a.strict === b.strict && Object.entries(a.parameters).every(([param, value]) => b.parameters[param] === value);
377
+ }
378
+ function computeStrictness(id, vertex, params, state) {
379
+ state.asking.add(id);
380
+ const dispatch = state.dispatch.get(id);
381
+ /* a dispatch, or reflection flowR could not follow, may read a parameter without any read of it showing in the code */
382
+ const reflective = ((0, frame_reflection_1.reflectiveRolesOf)(vertex, state.graph, { known: state.fnInfo }) & MayEvaluate) !== 0;
383
+ const open = dispatch !== undefined || reflective;
384
+ const parameters = {};
385
+ for (const param of params) {
386
+ const own = strictnessOfParameter(node_id_1.NodeId.normalize(param), vertex, state);
387
+ parameters[param] = open ? logic_1.TernaryLogic.or(own, logic_1.Ternary.Maybe) : own;
388
+ }
389
+ /* the object a certain dispatch is on is forced by the dispatch itself */
390
+ const object = dispatch?.certain && !dispatch.named ? parameterIds(id, state.idMap)[0] : undefined;
391
+ if (object !== undefined && parameters[object] !== undefined) {
392
+ parameters[object] = logic_1.Ternary.Always;
393
+ }
394
+ state.asking.delete(id);
395
+ return { strict: logic_1.TernaryLogic.and(...Object.values(parameters)), parameters };
396
+ }
318
397
  /**
319
398
  * Determines whether the function with the given id is strict, i.e., whether calling it forces its arguments.
320
399
  * {@link Ternary#Always} says every call forces every parameter, {@link Ternary#Never} that no call forces
@@ -348,4 +427,93 @@ function strictnessOfEach(ids, graph, { ctx } = {}) {
348
427
  }
349
428
  return result;
350
429
  }
430
+ /** Where the promises bound to `params` may be forced: their reads, calls of closures capturing them, and the callees they are handed to. */
431
+ function forcingPointsOf(params, graph, idMap, seen = new Set()) {
432
+ const found = [];
433
+ for (const param of params) {
434
+ if (seen.has(param)) {
435
+ continue;
436
+ }
437
+ seen.add(param);
438
+ const owner = idMap.get(idMap.get(param)?.info.parent ?? -1)?.info.parent;
439
+ for (const read of (0, frame_reflection_1.edgeSources)(graph, param, edge_1.EdgeType.Reads)) {
440
+ found.push(read);
441
+ let closure = model_1.RNode.findEnclosing(read, idMap, r_function_definition_1.RFunctionDefinition.is);
442
+ while (closure !== undefined && closure !== owner) {
443
+ found.push(...(0, frame_reflection_1.edgeSources)(graph, closure, edge_1.EdgeType.Calls));
444
+ closure = model_1.RNode.strictlyEnclosingFunction(closure, idMap);
445
+ }
446
+ /* a read that is an argument hands the promise on */
447
+ for (const holder of (0, frame_reflection_1.edgeSources)(graph, read, edge_1.EdgeType.Argument)) {
448
+ const call = graph.getVertex(holder);
449
+ if (vertex_1.DfgVertex.isFunctionCall(call) && !isBuiltInCall(call)) {
450
+ const bound = boundParameters(call, read, idMap, graph) ?? [];
451
+ found.push(holder, ...forcingPointsOf(bound, graph, idMap, seen));
452
+ }
453
+ }
454
+ }
455
+ }
456
+ return found;
457
+ }
458
+ /**
459
+ * What a node within promises depends on to run: the holder of each `byPromise` dependency and where that promise may be forced.
460
+ * @example
461
+ * ```r
462
+ * g(print(1)) # the print runs only when `g` forces its argument, so it depends on `g(...)` and on the reads of `g`'s parameter
463
+ * ```
464
+ */
465
+ function promiseDependencies(id, graph) {
466
+ const idMap = graph.idMap;
467
+ const found = [];
468
+ if (idMap === undefined) {
469
+ return found;
470
+ }
471
+ for (const cd of graph.getVertex(id)?.cds ?? []) {
472
+ if (cd.byPromise !== true) {
473
+ continue;
474
+ }
475
+ const call = graph.getVertex(cd.id);
476
+ if (vertex_1.DfgVertex.isFunctionCall(call)) {
477
+ const argument = model_1.RNode.findEnclosing(id, idMap, n => n.info.parent === cd.id);
478
+ const bound = argument === undefined ? [] : boundParameters(call, argument, idMap, graph) ?? [];
479
+ found.push(cd.id, ...forcingPointsOf(bound, graph, idMap));
480
+ }
481
+ else {
482
+ found.push(...forcingPointsOf([cd.id], graph, idMap));
483
+ }
484
+ }
485
+ return found;
486
+ }
487
+ /** How surely the holder of a promise forces it, asked for a node `inner` within the promise. */
488
+ function promiseForcing(graph, { ctx } = {}) {
489
+ const idMap = graph.idMap;
490
+ let state = undefined;
491
+ return (holder, inner) => {
492
+ if (idMap === undefined) {
493
+ return logic_1.Ternary.Maybe;
494
+ }
495
+ state ??= makeState(graph, ctx);
496
+ if (state.owner.has(holder)) {
497
+ return handedTo(holder, state);
498
+ }
499
+ const call = graph.getVertex(holder);
500
+ if (!vertex_1.DfgVertex.isFunctionCall(call) || isBuiltInCall(call)) {
501
+ return logic_1.Ternary.Maybe;
502
+ }
503
+ const argument = model_1.RNode.findEnclosing(inner, idMap, n => n.info.parent === holder);
504
+ return argument === undefined ? logic_1.Ternary.Maybe : forcedByCallee(call, argument, idMap, state);
505
+ };
506
+ }
507
+ /** Drops the resume of a jump within a promise ({@link ControlFlow.promise}) once the linked holder surely forces it. */
508
+ function settleJumpsInPromises(graph, topLevel, { ctx } = {}) {
509
+ const forcing = promiseForcing(graph, { ctx });
510
+ const definitions = graph.verticesOfType(vertex_1.VertexType.FunctionDefinition).map(([, definition]) => definition.exitPoints);
511
+ for (const exit of [topLevel, ...definitions].flat()) {
512
+ for (const cd of exit.cds ?? []) {
513
+ if (cd.byPromise === true && forcing(cd.id, exit.nodeId) === logic_1.Ternary.Always) {
514
+ graph.removeEdgeType(exit.nodeId, cd.id, edge_1.EdgeType.FlowEdge);
515
+ }
516
+ }
517
+ }
518
+ }
351
519
  //# sourceMappingURL=strict-function.js.map
@@ -14,6 +14,11 @@ export interface State {
14
14
  visited: Set<NodeId>;
15
15
  potentials: [NodeId, Set<NodeId>][];
16
16
  }
17
+ /**
18
+ * The origins of what a call flowR found no target for calls, following its name back through reads and
19
+ * parameter bindings: `f(x)` within `apply_f <- function(f, x) f(x)` ends at what callers hand in as `f`.
20
+ */
21
+ export declare function fallbackUntargetedCall(vtx: Pick<DataflowGraphVertexFunctionCall, 'id'>, graph: DataflowGraph): Set<NodeId>;
17
22
  /**
18
23
  * Helper object for call-graphs, you can compute new call graphs based on {@link CallGraph.compute}.
19
24
  * @helper dataflow
@@ -22,9 +27,7 @@ export interface State {
22
27
  */
23
28
  export declare const CallGraph: {
24
29
  readonly name: "CallGraph";
25
- /**
26
- * Extracts the sub call graph from the given call graph, starting from the given entry points.
27
- */
30
+ /** Extracts the sub call graph from the given call graph, starting from the given entry points. */
28
31
  readonly computeSubCallGraph: (this: void, graph: CallGraph, entryPoints: Set<NodeId>) => CallGraph;
29
32
  /** The calls the program makes on its own: those outside of any function definition. */
30
33
  readonly entryPoints: (this: void, graph: CallGraph) => Set<NodeId>;
@@ -33,9 +36,7 @@ export declare const CallGraph: {
33
36
  * What {@link mayRunAnyway} may still run is left out, so a call reported here really does not run.
34
37
  */
35
38
  readonly unreachableCalls: (this: void, graph: CallGraph) => NodeId[];
36
- /**
37
- * Reduces the call graph by dropping all transitive edges.
38
- */
39
+ /** Reduces the call graph by dropping all transitive edges. */
39
40
  readonly dropTransitiveEdges: (this: void, graph: CallGraph) => CallGraph;
40
41
  /**
41
42
  * Computes the call graph from the given dataflow graph.