@eagleoutice/flowr 2.17.4 → 2.17.5

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 (544) hide show
  1. package/README.md +13 -52
  2. package/abstract-interpretation/absint-inference.js +1 -2
  3. package/abstract-interpretation/data-frame/arguments.d.ts +14 -3
  4. package/abstract-interpretation/data-frame/arguments.js +34 -0
  5. package/abstract-interpretation/data-frame/dataframe-semantics.js +7 -15
  6. package/abstract-interpretation/data-frame/resolve-args.d.ts +2 -2
  7. package/abstract-interpretation/data-frame/semantics.d.ts +8 -1
  8. package/abstract-interpretation/data-frame/semantics.js +14 -6
  9. package/abstract-interpretation/domains/state-abstract-domain.js +28 -18
  10. package/abstract-interpretation/domains/state-map.d.ts +43 -0
  11. package/abstract-interpretation/domains/state-map.js +147 -0
  12. package/benchmark/slicer.d.ts +1 -1
  13. package/benchmark/slicer.js +8 -7
  14. package/cli/repl/commands/repl-dataflow.js +5 -5
  15. package/cli/repl/commands/repl-execute.js +3 -2
  16. package/cli/repl/commands/repl-parse.js +2 -1
  17. package/cli/repl/print-version.d.ts +1 -1
  18. package/cli/repl/print-version.js +2 -1
  19. package/cli/repl/server/connection.d.ts +1 -1
  20. package/cli/repl/server/connection.js +7 -9
  21. package/cli/slicer-app.js +2 -1
  22. package/clones/algorithms/baxter-ast.d.ts +33 -0
  23. package/clones/algorithms/baxter-ast.js +70 -0
  24. package/clones/algorithms/greedy-string-tiling.d.ts +17 -0
  25. package/clones/algorithms/greedy-string-tiling.js +56 -0
  26. package/clones/algorithms/winnowing.d.ts +27 -0
  27. package/clones/algorithms/winnowing.js +66 -0
  28. package/clones/clone-ast.d.ts +75 -0
  29. package/clones/clone-ast.js +174 -0
  30. package/clones/clone-dataflow.d.ts +11 -0
  31. package/clones/clone-dataflow.js +83 -0
  32. package/clones/clone-detector.d.ts +116 -0
  33. package/clones/clone-detector.js +200 -0
  34. package/clones/clone-index.d.ts +54 -0
  35. package/clones/clone-index.js +56 -0
  36. package/config.d.ts +21 -2
  37. package/config.js +7 -1
  38. package/control-flow/basic-cfg-guided-visitor.js +1 -2
  39. package/control-flow/happens-before.d.ts +2 -0
  40. package/control-flow/happens-before.js +15 -9
  41. package/control-flow/simple-visitor.js +2 -4
  42. package/core/steps/all/core/00-parse.js +2 -1
  43. package/core/steps/all/core/01-parse-tree-sitter.js +2 -1
  44. package/core/steps/all/core/10-normalize.js +2 -1
  45. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -1
  46. package/core/steps/all/static-slicing/00-slice.js +2 -1
  47. package/core/steps/all/static-slicing/10-reconstruct.js +2 -1
  48. package/core/steps/pipeline/create-pipeline.js +1 -2
  49. package/core/steps/pipeline/default-pipelines.d.ts +1 -1
  50. package/core/steps/pipeline/default-pipelines.js +5 -4
  51. package/core/steps/pipeline-step.d.ts +3 -1
  52. package/core/steps/pipeline-step.js +5 -0
  53. package/data/r-base-primitives.generated.d.ts +2 -1
  54. package/dataflow/cluster.js +1 -2
  55. package/dataflow/environments/ambient-state-name.d.ts +14 -22
  56. package/dataflow/environments/ambient-state-name.js +4 -18
  57. package/dataflow/environments/apply-kill.d.ts +9 -20
  58. package/dataflow/environments/apply-kill.js +51 -25
  59. package/dataflow/environments/built-in-config.d.ts +7 -15
  60. package/dataflow/environments/built-in-config.js +15 -16
  61. package/dataflow/environments/built-in-eval-name.d.ts +5 -6
  62. package/dataflow/environments/built-in-eval-name.js +4 -5
  63. package/dataflow/environments/built-in-kinds.d.ts +111 -0
  64. package/dataflow/environments/built-in-kinds.js +35 -0
  65. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  66. package/dataflow/environments/built-in-proc-name.js +11 -0
  67. package/dataflow/environments/built-in-props.d.ts +62 -175
  68. package/dataflow/environments/built-in-props.js +42 -154
  69. package/dataflow/environments/built-in.d.ts +37 -73
  70. package/dataflow/environments/built-in.js +41 -62
  71. package/dataflow/environments/data-masking-functions.d.ts +2 -2
  72. package/dataflow/environments/default-builtin-config/base-functions.d.ts +7 -0
  73. package/dataflow/environments/default-builtin-config/base-functions.js +339 -0
  74. package/dataflow/environments/default-builtin-config/base-language.d.ts +3 -0
  75. package/dataflow/environments/default-builtin-config/base-language.js +66 -0
  76. package/dataflow/environments/default-builtin-config/base-operators.d.ts +58 -0
  77. package/dataflow/environments/default-builtin-config/base-operators.js +169 -0
  78. package/dataflow/environments/default-builtin-config/database-access.d.ts +3 -0
  79. package/dataflow/environments/default-builtin-config/database-access.js +16 -0
  80. package/dataflow/environments/default-builtin-config/define-helpers.d.ts +45 -0
  81. package/dataflow/environments/default-builtin-config/define-helpers.js +50 -0
  82. package/dataflow/environments/default-builtin-config/dev-tooling.d.ts +3 -0
  83. package/dataflow/environments/default-builtin-config/dev-tooling.js +63 -0
  84. package/dataflow/environments/default-builtin-config/file-io.d.ts +3 -0
  85. package/dataflow/environments/default-builtin-config/file-io.js +81 -0
  86. package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +3 -0
  87. package/dataflow/environments/default-builtin-config/graphics-devices.js +57 -0
  88. package/dataflow/environments/default-builtin-config/index.d.ts +18 -0
  89. package/dataflow/environments/default-builtin-config/index.js +114 -0
  90. package/dataflow/environments/default-builtin-config/media-formats.d.ts +3 -0
  91. package/dataflow/environments/default-builtin-config/media-formats.js +41 -0
  92. package/dataflow/environments/default-builtin-config/misc-packages.d.ts +3 -0
  93. package/dataflow/environments/default-builtin-config/misc-packages.js +18 -0
  94. package/dataflow/environments/default-builtin-config/network-access.d.ts +3 -0
  95. package/dataflow/environments/default-builtin-config/network-access.js +47 -0
  96. package/dataflow/environments/default-builtin-config/object-systems.d.ts +3 -0
  97. package/dataflow/environments/default-builtin-config/object-systems.js +39 -0
  98. package/dataflow/environments/default-builtin-config/package-data-table.d.ts +3 -0
  99. package/dataflow/environments/default-builtin-config/package-data-table.js +18 -0
  100. package/dataflow/environments/default-builtin-config/package-spatial.d.ts +3 -0
  101. package/dataflow/environments/default-builtin-config/package-spatial.js +32 -0
  102. package/dataflow/environments/default-builtin-config/package-tidyverse.d.ts +3 -0
  103. package/dataflow/environments/default-builtin-config/package-tidyverse.js +96 -0
  104. package/dataflow/environments/default-builtin-config/package-utils.d.ts +3 -0
  105. package/dataflow/environments/default-builtin-config/package-utils.js +35 -0
  106. package/dataflow/environments/default-builtin-config/package-withr.d.ts +3 -0
  107. package/dataflow/environments/default-builtin-config/package-withr.js +41 -0
  108. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +3 -0
  109. package/dataflow/environments/default-builtin-config/parallel-execution.js +31 -0
  110. package/dataflow/environments/default-builtin-config/session-interactive.d.ts +3 -0
  111. package/dataflow/environments/default-builtin-config/session-interactive.js +31 -0
  112. package/dataflow/environments/default-builtin-config/shared-configs.d.ts +267 -0
  113. package/dataflow/environments/default-builtin-config/shared-configs.js +483 -0
  114. package/dataflow/environments/default-builtin-config/shared-signatures.d.ts +21 -0
  115. package/dataflow/environments/default-builtin-config/shared-signatures.js +32 -0
  116. package/dataflow/environments/default-builtin-config/statistics.d.ts +3 -0
  117. package/dataflow/environments/default-builtin-config/statistics.js +32 -0
  118. package/dataflow/environments/default-builtin-config/unit-testing.d.ts +3 -0
  119. package/dataflow/environments/default-builtin-config/unit-testing.js +13 -0
  120. package/dataflow/environments/environment.d.ts +28 -52
  121. package/dataflow/environments/environment.js +24 -71
  122. package/dataflow/environments/group-generics.d.ts +12 -19
  123. package/dataflow/environments/group-generics.js +17 -14
  124. package/dataflow/environments/identifier.d.ts +72 -427
  125. package/dataflow/environments/identifier.js +34 -145
  126. package/dataflow/environments/pkg-name.d.ts +197 -0
  127. package/dataflow/environments/pkg-name.js +3 -0
  128. package/dataflow/environments/query-fn-props.d.ts +27 -76
  129. package/dataflow/environments/query-fn-props.js +34 -95
  130. package/dataflow/environments/resolve-by-name.d.ts +6 -16
  131. package/dataflow/environments/resolve-by-name.js +23 -35
  132. package/dataflow/environments/scoping.d.ts +5 -5
  133. package/dataflow/environments/scoping.js +13 -5
  134. package/dataflow/eval/resolve/alias-tracking.d.ts +31 -68
  135. package/dataflow/eval/resolve/alias-tracking.js +611 -126
  136. package/dataflow/eval/resolve/match-arguments.d.ts +5 -3
  137. package/dataflow/eval/resolve/resolve-argument.d.ts +11 -11
  138. package/dataflow/eval/resolve/resolve-argument.js +25 -30
  139. package/dataflow/eval/resolve/resolve-field.d.ts +10 -0
  140. package/dataflow/eval/resolve/resolve-field.js +127 -0
  141. package/dataflow/eval/resolve/resolve-replacement.d.ts +10 -0
  142. package/dataflow/eval/resolve/resolve-replacement.js +80 -0
  143. package/dataflow/eval/resolve/resolve-strings.d.ts +2 -2
  144. package/dataflow/eval/resolve/resolve.d.ts +13 -10
  145. package/dataflow/eval/resolve/resolve.js +81 -32
  146. package/dataflow/eval/values/general.d.ts +6 -24
  147. package/dataflow/eval/values/general.js +12 -29
  148. package/dataflow/eval/values/lists/list-constants.d.ts +11 -0
  149. package/dataflow/eval/values/lists/list-constants.js +65 -0
  150. package/dataflow/eval/values/r-value.d.ts +20 -23
  151. package/dataflow/eval/values/r-value.js +22 -17
  152. package/dataflow/extractor.d.ts +2 -10
  153. package/dataflow/extractor.js +100 -46
  154. package/dataflow/fn/argument-roles.d.ts +2 -4
  155. package/dataflow/fn/argument-roles.js +49 -23
  156. package/dataflow/fn/class-declaration.d.ts +36 -52
  157. package/dataflow/fn/class-declaration.js +22 -56
  158. package/dataflow/fn/condition-handlers.d.ts +2 -1
  159. package/dataflow/fn/dispatch.d.ts +70 -0
  160. package/dataflow/fn/dispatch.js +434 -0
  161. package/dataflow/fn/exceptions-of-function.d.ts +1 -2
  162. package/dataflow/fn/exceptions-of-function.js +36 -106
  163. package/dataflow/fn/frame-reflection.d.ts +1 -3
  164. package/dataflow/fn/frame-reflection.js +8 -16
  165. package/dataflow/fn/function-props.d.ts +2 -5
  166. package/dataflow/fn/function-props.js +27 -36
  167. package/dataflow/fn/function-semantics.d.ts +14 -26
  168. package/dataflow/fn/function-semantics.js +4 -18
  169. package/dataflow/fn/higher-order-function.js +2 -4
  170. package/dataflow/fn/strict-function.d.ts +10 -35
  171. package/dataflow/fn/strict-function.js +126 -138
  172. package/dataflow/graph/ambient-access.d.ts +51 -0
  173. package/dataflow/graph/ambient-access.js +80 -0
  174. package/dataflow/graph/call-graph.d.ts +9 -29
  175. package/dataflow/graph/call-graph.js +17 -41
  176. package/dataflow/graph/closure-frames.d.ts +46 -0
  177. package/dataflow/graph/closure-frames.js +225 -0
  178. package/dataflow/graph/dataflowgraph-builder.d.ts +25 -96
  179. package/dataflow/graph/dataflowgraph-builder.js +29 -97
  180. package/dataflow/graph/df-helper.d.ts +48 -188
  181. package/dataflow/graph/df-helper.js +107 -208
  182. package/dataflow/graph/diff-dataflow-graph.d.ts +5 -15
  183. package/dataflow/graph/diff-dataflow-graph.js +25 -25
  184. package/dataflow/graph/edge.js +1 -1
  185. package/dataflow/graph/graph-helper.d.ts +10 -46
  186. package/dataflow/graph/graph-helper.js +16 -50
  187. package/dataflow/graph/graph.d.ts +44 -97
  188. package/dataflow/graph/graph.js +83 -79
  189. package/dataflow/graph/match-args.d.ts +21 -88
  190. package/dataflow/graph/match-args.js +284 -97
  191. package/dataflow/graph/vertex.d.ts +101 -128
  192. package/dataflow/graph/vertex.js +23 -20
  193. package/dataflow/hooks.d.ts +7 -14
  194. package/dataflow/hooks.js +15 -13
  195. package/dataflow/info.d.ts +2 -17
  196. package/dataflow/internal/dispatch-linking.d.ts +71 -0
  197. package/dataflow/internal/dispatch-linking.js +332 -0
  198. package/dataflow/internal/linker.d.ts +48 -50
  199. package/dataflow/internal/linker.js +457 -155
  200. package/dataflow/internal/process/functions/call/argument/make-argument.js +2 -1
  201. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -14
  202. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -46
  203. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +7 -6
  204. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +10 -9
  205. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +23 -75
  206. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +263 -97
  207. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +10 -7
  208. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +66 -45
  209. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +15 -19
  210. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +82 -62
  211. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -4
  212. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -2
  213. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +2 -2
  214. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +3 -2
  215. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +15 -0
  216. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +416 -0
  217. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +37 -54
  218. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +192 -111
  219. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +4 -3
  220. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +60 -13
  221. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -3
  222. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +80 -76
  223. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +1 -7
  224. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -13
  225. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +4 -8
  226. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +436 -140
  227. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +18 -10
  228. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +90 -12
  229. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -5
  230. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -14
  231. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +9 -8
  232. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -7
  233. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
  234. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +3 -5
  235. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +2 -6
  236. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +9 -24
  237. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +10 -6
  238. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +5 -6
  239. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +3 -4
  240. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -4
  241. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +8 -11
  242. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -5
  243. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +20 -28
  244. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +17 -4
  245. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +117 -4
  246. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +5 -3
  247. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +3 -3
  248. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +8 -4
  249. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +18 -29
  250. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -25
  251. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +31 -35
  252. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +4 -18
  253. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +13 -19
  254. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +18 -16
  255. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +130 -65
  256. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -1
  257. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +38 -30
  258. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +584 -114
  259. package/dataflow/internal/process/functions/call/common.d.ts +8 -24
  260. package/dataflow/internal/process/functions/call/common.js +24 -24
  261. package/dataflow/internal/process/functions/call/deferred.d.ts +7 -27
  262. package/dataflow/internal/process/functions/call/deferred.js +6 -27
  263. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +6 -26
  264. package/dataflow/internal/process/functions/call/known-call-handling.js +6 -16
  265. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -4
  266. package/dataflow/internal/process/functions/call/named-call-handling.js +14 -35
  267. package/dataflow/internal/process/functions/call/nse.d.ts +2 -9
  268. package/dataflow/internal/process/functions/call/nse.js +6 -13
  269. package/dataflow/internal/process/functions/call/quoted.d.ts +4 -15
  270. package/dataflow/internal/process/functions/call/quoted.js +26 -62
  271. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +3 -6
  272. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +29 -11
  273. package/dataflow/internal/process/functions/process-parameter.js +1 -1
  274. package/dataflow/internal/program-order.d.ts +3 -10
  275. package/dataflow/internal/program-order.js +19 -10
  276. package/dataflow/origin/dfg-get-origin.js +2 -1
  277. package/documentation/data/faq/faqs.js +16 -1
  278. package/documentation/data/interface/doc-writing-code.js +5 -7
  279. package/documentation/doc-capabilities.js +3 -3
  280. package/documentation/doc-readme.js +1 -1
  281. package/documentation/doc-util/doc-code.d.ts +0 -5
  282. package/documentation/doc-util/doc-code.js +2 -22
  283. package/documentation/doc-util/doc-query.d.ts +1 -2
  284. package/documentation/doc-util/doc-query.js +4 -5
  285. package/documentation/doc-util/doc-search.js +1 -1
  286. package/documentation/wiki-analyzer.js +4 -3
  287. package/documentation/wiki-core.js +5 -5
  288. package/documentation/wiki-dataflow-graph.js +6 -0
  289. package/documentation/wiki-interface.js +2 -1
  290. package/documentation/wiki-linter.js +15 -3
  291. package/documentation/wiki-linting-and-testing.js +15 -2
  292. package/documentation/wiki-query.js +111 -29
  293. package/index.d.ts +3 -1
  294. package/index.js +6 -3
  295. package/linter/linter-executor.js +1 -1
  296. package/linter/linter-rules.d.ts +37 -8
  297. package/linter/linter-rules.js +8 -1
  298. package/linter/linter-util.d.ts +3 -3
  299. package/linter/linter-util.js +1 -1
  300. package/linter/rules/cmd-check/bogus-return.d.ts +2 -1
  301. package/linter/rules/cmd-check/call-arguments.d.ts +3 -2
  302. package/linter/rules/cmd-check/call-arguments.js +5 -5
  303. package/linter/rules/cmd-check/cmd-check-util.d.ts +9 -8
  304. package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -1
  305. package/linter/rules/cmd-check/dependency-declaration.js +1 -1
  306. package/linter/rules/cmd-check/documentation-mismatch.d.ts +3 -2
  307. package/linter/rules/cmd-check/documentation-mismatch.js +2 -1
  308. package/linter/rules/cmd-check/file-checks.d.ts +2 -2
  309. package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -1
  310. package/linter/rules/cmd-check/global-environment-modification.d.ts +6 -5
  311. package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -1
  312. package/linter/rules/cmd-check/non-ascii-code.js +1 -1
  313. package/linter/rules/cmd-check/package-files.d.ts +2 -2
  314. package/linter/rules/cmd-check/package-hooks.d.ts +5 -4
  315. package/linter/rules/cmd-check/package-runtime.js +2 -2
  316. package/linter/rules/cmd-check/rd-files.js +2 -1
  317. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +3 -2
  318. package/linter/rules/cmd-check/s-three-method-consistency.js +2 -1
  319. package/linter/rules/code-clones.d.ts +57 -0
  320. package/linter/rules/code-clones.js +53 -0
  321. package/linter/rules/deprecated-functions.js +3 -6
  322. package/linter/rules/file-path-validity.js +6 -4
  323. package/linter/rules/function-finder-util.d.ts +4 -2
  324. package/linter/rules/naming-convention.d.ts +6 -5
  325. package/linter/rules/naming-convention.js +2 -3
  326. package/linter/rules/no-leaked-credentials.d.ts +2 -1
  327. package/linter/rules/no-leaked-credentials.js +1 -1
  328. package/linter/rules/overwritten-file.d.ts +2 -1
  329. package/linter/rules/problematic-inputs.d.ts +2 -1
  330. package/linter/rules/problematic-inputs.js +3 -3
  331. package/linter/rules/process-state-in-session.d.ts +7 -6
  332. package/linter/rules/process-state-in-session.js +1 -1
  333. package/linter/rules/roxygen-arguments.d.ts +1 -1
  334. package/linter/rules/secret-exfiltration.js +1 -1
  335. package/linter/rules/seeded-randomness.d.ts +3 -3
  336. package/linter/rules/unclosed-connection.js +1 -2
  337. package/linter/rules/undefined-symbol-util.d.ts +3 -2
  338. package/linter/rules/undefined-symbol.d.ts +3 -2
  339. package/linter/rules/unescaped-arguments.d.ts +1 -1
  340. package/linter/rules/unescaped-arguments.js +6 -8
  341. package/linter/rules/unused-definition.d.ts +4 -3
  342. package/linter/rules/unused-definition.js +10 -12
  343. package/linter/rules/unused-import.d.ts +6 -5
  344. package/package.json +1 -1
  345. package/project/attached-packages.d.ts +5 -4
  346. package/project/cache/flowr-analyzer-cache.d.ts +14 -1
  347. package/project/cache/flowr-analyzer-cache.js +40 -3
  348. package/project/context/flowr-analyzer-dependencies-context.d.ts +12 -12
  349. package/project/context/flowr-analyzer-environment-context.d.ts +3 -3
  350. package/project/context/flowr-analyzer-environment-context.js +3 -3
  351. package/project/context/flowr-analyzer-functions-context.d.ts +9 -7
  352. package/project/context/flowr-analyzer-gas-context.d.ts +25 -0
  353. package/project/context/flowr-analyzer-gas-context.js +34 -4
  354. package/project/dependency-version-space.d.ts +30 -29
  355. package/project/dependency-version-space.js +1 -2
  356. package/project/flowr-analyzer-builder.d.ts +2 -3
  357. package/project/flowr-analyzer.d.ts +35 -3
  358. package/project/flowr-analyzer.js +11 -5
  359. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +15 -14
  360. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +5 -4
  361. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +1 -1
  362. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -1
  363. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +4 -3
  364. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -1
  365. package/project/plugins/package-version-plugins/package.d.ts +6 -5
  366. package/project/sigdb/build.js +1 -1
  367. package/project/sigdb/decode.d.ts +8 -7
  368. package/project/sigdb/decode.js +1 -2
  369. package/project/sigdb/dict.d.ts +2 -1
  370. package/project/sigdb/dict.js +2 -2
  371. package/project/sigdb/index-format.d.ts +2 -1
  372. package/project/sigdb/manifest.d.ts +1 -1
  373. package/project/sigdb/memory-source.d.ts +18 -17
  374. package/project/sigdb/on-demand/package-sources.d.ts +4 -3
  375. package/project/sigdb/on-demand/recoverer.d.ts +2 -1
  376. package/project/sigdb/on-demand/remote-sources.d.ts +2 -1
  377. package/project/sigdb/reader.d.ts +85 -80
  378. package/project/sigdb/reader.js +0 -4
  379. package/project/sigdb/schema.d.ts +9 -8
  380. package/project/sigdb/signature-db.d.ts +6 -6
  381. package/queries/catalog/ambient-access-query/ambient-access-query-executor.d.ts +6 -0
  382. package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +50 -0
  383. package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +54 -0
  384. package/queries/catalog/ambient-access-query/ambient-access-query-format.js +45 -0
  385. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +2 -1
  386. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
  387. package/queries/catalog/call-graph-query/expand-library-internals.d.ts +3 -2
  388. package/queries/catalog/code-clones-query/code-clones-query-executor.d.ts +6 -0
  389. package/queries/catalog/code-clones-query/code-clones-query-executor.js +38 -0
  390. package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +54 -0
  391. package/queries/catalog/code-clones-query/code-clones-query-format.js +73 -0
  392. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +3 -3
  393. package/queries/catalog/dependencies-query/data-flow.d.ts +5 -4
  394. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +5 -2
  395. package/queries/catalog/dependencies-query/dependencies-query-executor.js +5 -5
  396. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -2
  397. package/queries/catalog/dependencies-query/dependencies-query-format.js +1 -1
  398. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
  399. package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
  400. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -0
  401. package/queries/catalog/dice-query/dice-query-format.js +1 -0
  402. package/queries/catalog/does-call-query/does-call-query-executor.js +1 -2
  403. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -0
  404. package/queries/catalog/does-call-query/does-call-query-format.js +1 -0
  405. package/queries/catalog/function-info-query/function-info-query-format.d.ts +2 -1
  406. package/queries/catalog/function-info-query/function-origin.d.ts +3 -2
  407. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -3
  408. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +5 -4
  409. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -0
  410. package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -0
  411. package/queries/catalog/input-sources-query/input-sources-query-executor.js +7 -3
  412. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +9 -9
  413. package/queries/catalog/input-sources-query/simple-input-classifier.js +1 -1
  414. package/queries/catalog/linter-query/linter-query-executor.js +4 -1
  415. package/queries/catalog/linter-query/linter-query-format.js +3 -2
  416. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -0
  417. package/queries/catalog/origin-query/origin-query-format.js +1 -0
  418. package/queries/catalog/project-query/project-query-format.d.ts +2 -1
  419. package/queries/catalog/provenance-query/provenance-query-format.d.ts +1 -0
  420. package/queries/catalog/provenance-query/provenance-query-format.js +1 -0
  421. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -0
  422. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -0
  423. package/queries/catalog/signature-query/signature-query-executor.d.ts +9 -6
  424. package/queries/catalog/signature-query/signature-query-executor.js +14 -15
  425. package/queries/catalog/signature-query/signature-query-format.d.ts +21 -20
  426. package/queries/catalog/signature-query/signature-query-render.js +1 -1
  427. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  428. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +9 -5
  429. package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
  430. package/queries/query-function-filter.d.ts +1 -1
  431. package/queries/query.d.ts +59 -8
  432. package/queries/query.js +59 -37
  433. package/r-bridge/data/data.d.ts +39 -28
  434. package/r-bridge/data/data.js +37 -28
  435. package/r-bridge/lang-4.x/ast/model/model.d.ts +10 -1
  436. package/r-bridge/lang-4.x/ast/model/model.js +30 -0
  437. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +21 -0
  438. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +25 -2
  439. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -1
  440. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -2
  441. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +2 -2
  442. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  443. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  444. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  445. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  446. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +4 -3
  447. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  448. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  449. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  450. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  451. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  452. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  453. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  454. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  455. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  456. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +5 -6
  457. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +2 -7
  458. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  459. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -2
  460. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +2 -2
  461. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  462. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -5
  463. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +7 -2
  464. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +14 -6
  465. package/r-bridge/lang-4.x/ast/model/processing/visitor.d.ts +1 -1
  466. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +2 -2
  467. package/r-bridge/lang-4.x/ast/model/type.d.ts +1 -1
  468. package/r-bridge/lang-4.x/ast/model/type.js +1 -1
  469. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -2
  470. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -2
  471. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  472. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +3 -2
  473. package/r-bridge/parser.d.ts +8 -2
  474. package/r-bridge/parser.js +6 -0
  475. package/r-bridge/shell-executor.d.ts +2 -2
  476. package/r-bridge/shell-executor.js +3 -2
  477. package/r-bridge/shell.d.ts +2 -2
  478. package/r-bridge/shell.js +3 -2
  479. package/reconstruct/auto-select/magic-comments.js +1 -1
  480. package/reconstruct/reconstruct.d.ts +0 -5
  481. package/reconstruct/reconstruct.js +6 -5
  482. package/search/flowr-search-builder.d.ts +14 -0
  483. package/search/flowr-search-builder.js +7 -0
  484. package/search/flowr-search-executor.js +2 -2
  485. package/search/flowr-search-filters.js +8 -9
  486. package/search/flowr-search.js +1 -1
  487. package/search/search-executor/search-enrichers.d.ts +2 -0
  488. package/search/search-executor/search-enrichers.js +6 -1
  489. package/search/search-executor/search-generators.d.ts +2 -2
  490. package/search/search-executor/search-generators.js +13 -8
  491. package/search/search-executor/search-mappers.js +1 -1
  492. package/search/search-executor/search-transformer.d.ts +2 -2
  493. package/search/search-executor/search-transformer.js +6 -6
  494. package/slicing/criterion/parse.d.ts +2 -1
  495. package/slicing/criterion/parse.js +2 -1
  496. package/slicing/static/removal-slice.js +2 -1
  497. package/slicing/static/slice-call.d.ts +30 -4
  498. package/slicing/static/slice-call.js +74 -9
  499. package/slicing/static/slicer-types.d.ts +2 -1
  500. package/slicing/static/static-slicer.js +66 -11
  501. package/slicing/static/visiting-queue.d.ts +2 -0
  502. package/slicing/static/visiting-queue.js +4 -0
  503. package/taint-analysis/builder/report-template.d.ts +3 -3
  504. package/util/arg-matching.d.ts +1 -1
  505. package/util/collections/relation.d.ts +23 -0
  506. package/util/collections/relation.js +63 -0
  507. package/util/fixpoint.d.ts +65 -0
  508. package/util/fixpoint.js +216 -0
  509. package/util/flowr-version.d.ts +1 -1
  510. package/util/flowr-version.js +2 -2
  511. package/util/json.d.ts +4 -0
  512. package/util/json.js +12 -3
  513. package/util/mermaid/cfg.js +1 -2
  514. package/util/mermaid/dfg.d.ts +1 -1
  515. package/util/mermaid/dfg.js +1 -1
  516. package/util/mermaid/mermaid.d.ts +2 -1
  517. package/util/monoid.d.ts +26 -0
  518. package/util/monoid.js +31 -0
  519. package/util/prefix.d.ts +1 -1
  520. package/util/r-base-packages.d.ts +10 -7
  521. package/util/r-base-packages.js +11 -6
  522. package/util/r-package-urls.d.ts +10 -9
  523. package/util/r-value.js +2 -1
  524. package/util/r-version-order.d.ts +2 -0
  525. package/util/r-version-order.js +19 -0
  526. package/util/r-version.d.ts +2 -1
  527. package/util/r-version.js +2 -14
  528. package/util/range.d.ts +38 -29
  529. package/util/range.js +10 -5
  530. package/util/simple-df/dfg-ascii.js +2 -2
  531. package/util/text/ansi.d.ts +13 -9
  532. package/util/text/ansi.js +4 -6
  533. package/util/text/strings.d.ts +10 -3
  534. package/util/text/strings.js +10 -1
  535. package/util/version.d.ts +1 -1
  536. package/util/version.js +2 -1
  537. package/dataflow/environments/default-builtin-config.d.ts +0 -8874
  538. package/dataflow/environments/default-builtin-config.js +0 -1737
  539. package/r-bridge/lang-4.x/ast/model/operators.d.ts +0 -33
  540. package/r-bridge/lang-4.x/ast/model/operators.js +0 -54
  541. package/taint-analysis/eval/eval.d.ts +0 -1
  542. package/taint-analysis/eval/eval.js +0 -124
  543. package/taint-analysis/eval/instrumentation.d.ts +0 -59
  544. package/taint-analysis/eval/instrumentation.js +0 -124
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClosureRefs = void 0;
3
+ exports.ClosureRefs = exports.LinkedFunctionResolver = void 0;
4
4
  exports.findNonLocalReads = findNonLocalReads;
5
5
  exports.produceNameSharedIdMap = produceNameSharedIdMap;
6
+ exports.linkInstanceReads = linkInstanceReads;
7
+ exports.readsOfUncalledClosures = readsOfUncalledClosures;
6
8
  exports.linkFunctionCallWithSingleTarget = linkFunctionCallWithSingleTarget;
9
+ exports.isWithinArgumentOf = isWithinArgumentOf;
7
10
  exports.linkFunctionCalls = linkFunctionCalls;
8
11
  exports.getAllFunctionCallTargets = getAllFunctionCallTargets;
9
12
  exports.getAllLinkedFunctionDefinitions = getAllLinkedFunctionDefinitions;
@@ -11,12 +14,15 @@ exports.linkExpressionIn = linkExpressionIn;
11
14
  exports.linkCallToDefinitions = linkCallToDefinitions;
12
15
  exports.linkInputs = linkInputs;
13
16
  exports.linkCircularRedefinitionsWithinALoop = linkCircularRedefinitionsWithinALoop;
17
+ exports.linkWritesCarriedByLoop = linkWritesCarriedByLoop;
14
18
  exports.reapplyLoopExitPoints = reapplyLoopExitPoints;
15
19
  exports.accessedFieldName = accessedFieldName;
20
+ exports.recordFound = recordFound;
16
21
  exports.linkFieldReads = linkFieldReads;
17
22
  exports.bindAccessedField = bindAccessedField;
18
23
  exports.separateClosureInstances = separateClosureInstances;
19
24
  const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
25
+ const arrays_1 = require("../../util/collections/arrays");
20
26
  const defaultmap_1 = require("../../util/collections/defaultmap");
21
27
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
22
28
  const function_semantics_1 = require("../fn/function-semantics");
@@ -28,24 +34,28 @@ const identifier_1 = require("../environments/identifier");
28
34
  const logger_1 = require("../logger");
29
35
  const edge_1 = require("../graph/edge");
30
36
  const vertex_1 = require("../graph/vertex");
37
+ const environment_1 = require("../environments/environment");
31
38
  const info_1 = require("../info");
32
39
  const r_access_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-access");
33
40
  const r_number_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-number");
34
41
  const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
35
42
  const unnamed_call_handling_1 = require("./process/functions/call/unnamed-call-handling");
43
+ const built_in_envir_utils_1 = require("./process/functions/call/built-in/built-in-envir-utils");
36
44
  const built_in_proc_name_1 = require("../environments/built-in-proc-name");
37
45
  const vertex_2 = require("../graph/vertex");
38
46
  const resolve_helper_1 = require("../environments/resolve-helper");
47
+ const resolve_by_name_1 = require("../environments/resolve-by-name");
39
48
  const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
40
49
  const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
41
50
  const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
42
51
  const df_helper_1 = require("../graph/df-helper");
52
+ const closure_frames_1 = require("../graph/closure-frames");
43
53
  const ambient_state_name_1 = require("../environments/ambient-state-name");
54
+ const class_declaration_1 = require("../fn/class-declaration");
55
+ const fixpoint_1 = require("../../util/fixpoint");
44
56
  const ValueFlowBits = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall;
45
57
  const FCallLinkReadBits = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall;
46
- /**
47
- * Find all reads within the graph that do not reference a local definition in the graph.
48
- */
58
+ /** Find all reads within the graph that do not reference a local definition in the graph. */
49
59
  function findNonLocalReads(graph, ignores = new Set()) {
50
60
  const defs = new Set();
51
61
  for (const tag of [vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition]) {
@@ -54,17 +64,18 @@ function findNonLocalReads(graph, ignores = new Set()) {
54
64
  }
55
65
  }
56
66
  const nonLocalReads = [];
57
- /* the tag already says what the reference is, so no vertex has to be fetched to decide */
58
- for (const [tag, type] of [[vertex_1.VertexType.Use, identifier_1.ReferenceType.Variable], [vertex_1.VertexType.FunctionCall, identifier_1.ReferenceType.Function]]) {
59
- for (const [nodeId] of graph.verticesOfType(tag)) {
60
- if (ignores.has(nodeId)) {
67
+ /* the tag already says what the reference is, so no vertex has to be fetched to decide; the target of a replacement (`x$a <- v`) reads the binding it replaces as well */
68
+ for (const [tag, type] of [[vertex_1.VertexType.Use, identifier_1.ReferenceType.Variable], [vertex_1.VertexType.FunctionCall, identifier_1.ReferenceType.Function], [vertex_1.VertexType.VariableDefinition, identifier_1.ReferenceType.Unknown]]) {
69
+ for (const [nodeId, vertex] of graph.verticesOfType(tag)) {
70
+ if (ignores.has(nodeId) || (vertex_2.DfgVertex.isVariableDefinition(vertex) && !vertex.par)) {
61
71
  continue;
62
72
  }
63
73
  /* control flow edges say nothing about what a name resolves to, so they do not count as a link */
64
74
  let linked = false;
65
75
  let nonLocal = false;
66
76
  for (const [target, e] of graph.edgesFrom(nodeId)) {
67
- if (edge_1.DfEdge.isOnlyControlFlow(e)) {
77
+ /* a replacement target is defined by its call, it reads only the binding it replaces */
78
+ if (edge_1.DfEdge.isOnlyControlFlow(e) || (tag === vertex_1.VertexType.VariableDefinition && edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy))) {
68
79
  continue;
69
80
  }
70
81
  linked = true;
@@ -80,9 +91,7 @@ function findNonLocalReads(graph, ignores = new Set()) {
80
91
  }
81
92
  return nonLocalReads;
82
93
  }
83
- /**
84
- * Produces a map from names to all identifier references sharing that name.
85
- */
94
+ /** Produces a map from names to all identifier references sharing that name. */
86
95
  function produceNameSharedIdMap(references) {
87
96
  const nameIdShares = new defaultmap_1.DefaultMap(() => []);
88
97
  for (const reference of references) {
@@ -92,43 +101,121 @@ function produceNameSharedIdMap(references) {
92
101
  }
93
102
  return nameIdShares;
94
103
  }
95
- function environmentsOfCallee(info, environment) {
96
- if (info.name === undefined) {
97
- return [];
104
+ /** how many vertices the walk for the holders of an instance visits before it settles for what it found */
105
+ const MaxInstanceFlow = 64;
106
+ /** The definitions holding the instance a method call `receiver$m(...)` runs a method on: every variable the value of the receiver flows through (aliases, the parameters it is bound to, what called functions return) and the containers it is a field of, as the environment of the call knows them, with the tracked state they carry. */
107
+ function instanceHolders(receiver, graph, environment, idMap) {
108
+ const holders = [];
109
+ const seen = new Set();
110
+ const todo = [receiver];
111
+ for (let id = todo.pop(); id !== undefined && seen.size < MaxInstanceFlow; id = todo.pop()) {
112
+ if (seen.has(id)) {
113
+ continue;
114
+ }
115
+ seen.add(id);
116
+ const node = idMap.get(id);
117
+ if (r_argument_1.RArgument.is(node)) {
118
+ todo.push(...node.value ? [node.value.info.id] : []);
119
+ continue;
120
+ }
121
+ const vertex = graph.getVertex(id);
122
+ if (vertex_2.DfgVertex.isUse(vertex)) {
123
+ /* a `self` a method hands back is bound on the call to the instance */
124
+ todo.push(...df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall).filter(t => !node_id_1.NodeId.isBuiltIn(t)));
125
+ }
126
+ else if (vertex_2.DfgVertex.isFunctionCall(vertex)) {
127
+ /* an access hands back a field of what it accesses, a function what it returns */
128
+ todo.push(...df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Returns));
129
+ }
130
+ else if (vertex_2.DfgVertex.isVariableDefinition(vertex)) {
131
+ const name = node_id_1.NodeId.recoverName(id, idMap);
132
+ const known = name === undefined ? undefined : resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.Variable)?.find(d => d.nodeId === id);
133
+ holders.push(known ?? { nodeId: id, name, type: identifier_1.ReferenceType.Variable, definedAt: id, cds: undefined });
134
+ const value = df_helper_1.Dataflow.assignedValueOf(id, graph);
135
+ todo.push(...value === undefined ? df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.DefinedByOnCall) : [value]);
136
+ }
98
137
  }
99
- return (resolve_helper_1.Resolve.byName(info.name, environment) ?? []).filter(identifier_1.hasEnvState).map(d => d.envState);
138
+ return holders;
100
139
  }
101
- /**
102
- * The frames of `environment` a function whose body runs at `bodyLevel` can see: the frame it was defined in and
103
- * those around it, never the frames of the functions calling it.
104
- */
105
- function definitionFramesOf(bodyLevel, environment) {
106
- const level = Math.max(0, Math.min(bodyLevel - 1, environment.level));
107
- let current = environment.current;
108
- for (let skip = environment.level - level; skip > 0 && current.parent !== undefined; skip--) {
109
- current = current.parent;
140
+ /** Links the reads of the names a method sees its instance by (`self`, `private`, `.self`) to the definitions holding the instance the call runs the method on. */
141
+ function linkInstanceReads(graph, info, fn, environment, idMap) {
142
+ const bindings = fn.subflow.in.length === 0 ? undefined : (0, class_declaration_1.instanceBindingsOfMethod)(fn.id, graph, idMap);
143
+ const reads = bindings === undefined ? [] : fn.subflow.in.filter(r => r.name !== undefined && bindings.includes(identifier_1.Identifier.getName(r.name)));
144
+ if (reads.length === 0) {
145
+ return;
146
+ }
147
+ const call = idMap.get(info.id);
148
+ /* a method taken out of its instance first, `f <- o$m; f()`, still runs on that instance */
149
+ const accesses = r_function_call_1.RFunctionCall.isUnnamed(call) ? [call.calledFunction] : df_helper_1.Dataflow.targetsOf(graph, info.id, edge_1.EdgeType.Reads).map(d => idMap.get(df_helper_1.Dataflow.assignedValueOf(d, graph) ?? d));
150
+ const holders = accesses.flatMap(a => r_access_1.RAccess.is(a) ? instanceHolders(a.accessed.info.id, graph, environment, idMap) : []);
151
+ for (const read of reads) {
152
+ for (const holder of holders) {
153
+ if (fn.subflow.graph.has(holder.nodeId) || node_id_1.NodeId.isBuiltIn(holder.nodeId)) {
154
+ continue;
155
+ }
156
+ graph.addEdge(read.nodeId, holder.nodeId, edge_1.EdgeType.DefinedByOnCall);
157
+ graph.addEdge(info.id, holder.nodeId, edge_1.EdgeType.DefinesOnCall);
158
+ linkFieldWritesOnCall(graph, info.id, fn.id, read.nodeId, holder.nodeId, holder.envState, idMap);
159
+ (0, built_in_envir_utils_1.readEnvironmentContents)(graph, info.id, holder);
160
+ }
110
161
  }
111
- return { current, level };
112
162
  }
113
- /**
114
- * Links a function call with a single target function definition.
115
- */
116
- function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoints, id: fnId, params }, info, idMap) {
163
+ /** The function definition directly within `fn` that holds `id`, `undefined` if `id` is in the body of `fn` itself. */
164
+ function outermostClosureOf(id, fn, idMap) {
165
+ let closure;
166
+ for (const parent of model_1.RNode.iterateParents(idMap.get(id), idMap)) {
167
+ if (parent.info.id === fn) {
168
+ return closure;
169
+ }
170
+ else if (r_function_definition_1.RFunctionDefinition.is(parent)) {
171
+ closure = parent.info.id;
172
+ }
173
+ }
174
+ return undefined;
175
+ }
176
+ /** Which free reads of the function `fn` are in a closure it makes without calling it: such a closure reads its free variables where it is called, which links them there (or, if nothing calls it, at the end of its scope), so a call of `fn` does not read them. */
177
+ function readsOfUncalledClosures(fn, subflow, graph, idMap) {
178
+ let called;
179
+ return read => {
180
+ const closure = subflow.graph.has(read) ? undefined : outermostClosureOf(read, fn, idMap);
181
+ if (closure === undefined) {
182
+ return false;
183
+ }
184
+ if (called === undefined) {
185
+ called = new Set();
186
+ for (const node of subflow.graph) {
187
+ if (vertex_2.DfgVertex.isFunctionCall(graph.getVertex(node))) {
188
+ df_helper_1.Dataflow.targetsOf(graph, node, edge_1.EdgeType.Calls).forEach(t => called?.add(t));
189
+ }
190
+ }
191
+ }
192
+ return !called.has(closure);
193
+ };
194
+ }
195
+ /** Links the free variables of the function `fnId` the call `info` runs to their definitions where the function was defined, as the environment of the call sees them. */
196
+ function linkFreeReads(graph, fnSubflow, fnId, info, idMap) {
117
197
  const id = info.id;
118
198
  const environment = info.environment;
119
199
  if (environment !== undefined) {
120
200
  let callee;
121
201
  let lexical;
202
+ const instance = fnSubflow.in.length === 0 ? undefined : (0, class_declaration_1.instanceBindingsOfMethod)(fnId, graph, idMap);
203
+ const readWhereCalled = readsOfUncalledClosures(fnId, fnSubflow, graph, idMap);
122
204
  /* for each open ingoing reference, try to resolve it here, and if so, add a read edge from the call to signal that it reads it */
123
205
  for (const ingoing of fnSubflow.in) {
124
206
  const name = ingoing.name;
125
- if (name === undefined) {
207
+ if (name === undefined || instance?.includes(identifier_1.Identifier.getName(name)) || readWhereCalled(ingoing.nodeId)) {
126
208
  continue;
127
209
  }
128
210
  /* a variable is looked up where the function was defined, global state (options, files, the working directory) is what it is where it is called */
129
- const inCallee = ambient_state_name_1.AmbientStateName.is(name) ? undefined : (callee ??= environmentsOfCallee(info, environment)).values().map(env => resolve_helper_1.Resolve.byNameAndType(name, env, ingoing.type)).find(assert_1.isNotUndefined);
130
- const defs = inCallee ?? resolve_helper_1.Resolve.byNameAndType(name, ambient_state_name_1.AmbientStateName.is(name) ? environment : lexical ??= definitionFramesOf(fnSubflow.environment.level, environment), ingoing.type) ?? [];
131
- for (const { nodeId, type, value, definedAt, envState } of defs) {
211
+ const inCallee = ambient_state_name_1.AmbientStateName.is(name) ? undefined : (callee ??= (info.name === undefined ? [] : resolve_helper_1.Resolve.byName(info.name, environment) ?? []).filter(identifier_1.hasEnvState).map(d => d.envState)).values().map(env => resolve_helper_1.Resolve.byNameAndType(name, env, ingoing.type)).find(assert_1.isNotUndefined);
212
+ let defs = inCallee ?? resolve_helper_1.Resolve.byNameAndType(name, ambient_state_name_1.AmbientStateName.is(name) ? environment : lexical ??= environment_1.REnvironment.visibleTo(fnSubflow.environment.level, environment), ingoing.type) ?? [];
213
+ /* R looks the methods of a dispatch up where the generic is called first */
214
+ if (ingoing.type === identifier_1.ReferenceType.S3MethodPrefix && inCallee === undefined) {
215
+ defs = (0, arrays_1.uniqueArrayMerge)(defs, resolve_helper_1.Resolve.byNameAndType(name, environment, ingoing.type) ?? []);
216
+ }
217
+ for (const def of defs) {
218
+ const { nodeId, type, value, definedAt, envState } = def;
132
219
  /* the state an earlier run of the function left behind is what its next run reads */
133
220
  if (fnSubflow.graph.has(nodeId) && !ambient_state_name_1.AmbientStateName.is(name) || node_id_1.NodeId.isBuiltIn(nodeId)) {
134
221
  continue;
@@ -137,6 +224,7 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
137
224
  graph.addEdge(id, nodeId, edge_1.EdgeType.DefinesOnCall);
138
225
  if (envState !== undefined) {
139
226
  linkFieldWritesOnCall(graph, id, fnId, ingoing.nodeId, nodeId, envState, idMap);
227
+ (0, built_in_envir_utils_1.readEnvironmentContents)(graph, id, def);
140
228
  }
141
229
  if (definedAt !== undefined && definedAt !== nodeId && !node_id_1.NodeId.isBuiltIn(definedAt)
142
230
  && graph.hasVertex(definedAt) && !vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(nodeId))) {
@@ -147,14 +235,23 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
147
235
  graph.addEdge(id, v, edge_1.EdgeType.Calls);
148
236
  graph.addEdge(ingoing.nodeId, v, edge_1.EdgeType.Calls);
149
237
  const vInfo = graph.getVertex(v);
150
- if (vertex_2.DfgVertex.isFunctionDefinition(vInfo) && !vInfo.mode?.includes('s7')) {
151
- (vInfo.mode ??= []).push('s7');
238
+ if (vertex_2.DfgVertex.isFunctionDefinition(vInfo) && !vInfo.mode?.includes(vertex_1.FunctionDispatch.S7)) {
239
+ (vInfo.mode ??= []).push(vertex_1.FunctionDispatch.S7);
152
240
  }
153
241
  }
154
242
  }
155
243
  }
156
244
  }
157
245
  }
246
+ }
247
+ /** Links a function call with a single target function definition. */
248
+ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoints, id: fnId, params, envOps }, info, idMap) {
249
+ const id = info.id;
250
+ const environment = info.environment;
251
+ linkFreeReads(graph, fnSubflow, fnId, info, idMap);
252
+ if (environment !== undefined) {
253
+ linkInstanceReads(graph, info, { subflow: fnSubflow, id: fnId }, environment, idMap);
254
+ }
158
255
  for (const node of fnSubflow.graph) {
159
256
  if (!vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(node)) || fieldAssignmentOf(node, idMap) === undefined) {
160
257
  continue;
@@ -176,10 +273,27 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
176
273
  graph.addEdge(id, fnId, edge_1.EdgeType.Calls);
177
274
  const fn = idMap.get(fnId);
178
275
  if (r_function_definition_1.RFunctionDefinition.is(fn)) {
179
- applyForForcedArgs(graph, id, params, function_semantics_1.FunctionSemantics.call.match.onCallAndLink(info.args, fn.parameters, graph));
276
+ const argToParam = function_semantics_1.FunctionSemantics.call.match.onCallAndLink(info.args, fn.parameters, graph);
277
+ applyForForcedArgs(graph, id, params, argToParam);
278
+ if (environment !== undefined) {
279
+ readArgumentContents(graph, info.id, environment, argToParam, envOps, idMap);
280
+ }
180
281
  }
181
282
  return exitPoints.filter(e => (0, info_1.doesExitPointPropagateCalls)(e.type));
182
283
  }
284
+ /** A call reads everything written into an environment it hands to a parameter (see {@link readEnvironmentContents}), unless the body only writes into what the parameter holds, by writes each call replays (see {@link DeferredEnvOp}): `register <- function(env, f) env$h <- f` reads nothing of `env`, so one call does not read what another stored. */
285
+ function readArgumentContents(graph, call, environment, argToParam, envOps, idMap) {
286
+ const written = new Set(envOps?.filter(o => o.kind === vertex_1.EnvOpKind.Define || o.kind === vertex_1.EnvOpKind.Replace).map(o => o.envir));
287
+ for (const [arg, param] of argToParam) {
288
+ const value = r_argument_1.RArgument.valueOf(idMap.get(arg)) ?? idMap.get(arg);
289
+ if (!r_symbol_1.RSymbol.is(value) || df_helper_1.Dataflow.sourcesOf(graph, param, edge_1.EdgeType.Reads).every(r => written.has(r))) {
290
+ continue;
291
+ }
292
+ for (const holder of resolve_helper_1.Resolve.byName(value.content, environment) ?? []) {
293
+ (0, built_in_envir_utils_1.readEnvironmentContents)(graph, call, holder);
294
+ }
295
+ }
296
+ }
183
297
  /** for each parameter that we link that gets forced, add a reads edge from the call to argument to show that it reads it */
184
298
  function applyForForcedArgs(graph, callId, readParams, argToParam) {
185
299
  for (const [arg, param] of argToParam) {
@@ -201,7 +315,9 @@ function linkFieldWritesOnCall(graph, id, fnId, start, binding, envState, idMap)
201
315
  }
202
316
  }
203
317
  for (const read of aliases) {
204
- bindAccessedField(graph, read, envState, idMap);
318
+ if (envState !== undefined) {
319
+ bindAccessedField(graph, read, envState, idMap, id);
320
+ }
205
321
  const write = fieldAssignmentOf(read, idMap);
206
322
  if (write !== undefined) {
207
323
  graph.addEdge(id, write, edge_1.EdgeType.Reads);
@@ -214,17 +330,31 @@ function linkFieldWritesOnCall(graph, id, fnId, start, binding, envState, idMap)
214
330
  }
215
331
  }
216
332
  }
217
- /**
218
- * Whether the call `info` may get its function from `target`, which it has the edge `e` to. An unnamed call reads
219
- * the expression that gives its function. A named call that only reads another call reads state that call wrote,
220
- * like the options, unless that call binds the name. No call binds a name that resolves to nothing (`unbound`),
221
- * and a call processed by default (`options()`, `par()`) binds no name at all.
222
- */
333
+ /** Whether the call `info` may get its function from `target`, which it has the edge `e` to. */
223
334
  function mayBeFunctionSource(graph, info, target, e, unbound = false) {
335
+ if (edge_1.DfEdge.includesType(e, edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall)) {
336
+ return true;
337
+ }
338
+ else if (isWithinArgumentOf(graph, info.id, target)) {
339
+ return false;
340
+ }
224
341
  const vertex = graph.getVertex(target);
225
- return vertex_2.DfgVertex.hasOrigin(info, built_in_proc_name_1.BuiltInProcName.Unnamed) || edge_1.DfEdge.includesType(e, edge_1.EdgeType.Calls | edge_1.EdgeType.DefinedByOnCall) || !vertex_2.DfgVertex.isFunctionCall(vertex)
342
+ return vertex_2.DfgVertex.hasOrigin(info, built_in_proc_name_1.BuiltInProcName.Unnamed) || !vertex_2.DfgVertex.isFunctionCall(vertex)
226
343
  || (!unbound && (vertex.origin === 'unnamed' || vertex.origin.some(o => o !== built_in_proc_name_1.BuiltInProcName.Default)));
227
344
  }
345
+ /** Whether `target` lies within an argument of `call`, which the call reads when it forces that argument, not to find its function. */
346
+ function isWithinArgumentOf(graph, call, target) {
347
+ const idMap = graph.idMap;
348
+ if (idMap === undefined) {
349
+ return false;
350
+ }
351
+ for (let node = idMap.get(target); node !== undefined && node.info.id !== call; node = model_1.RNode.directParent(node, idMap)) {
352
+ if (df_helper_1.Dataflow.hasEdge(graph, call, node.info.id, edge_1.EdgeType.Argument)) {
353
+ return true;
354
+ }
355
+ }
356
+ return false;
357
+ }
228
358
  function linkFunctionCall(graph, id, info, idMap, isRoot) {
229
359
  const readIds = new Set();
230
360
  for (const [t, e] of graph.edgesFrom(id)) {
@@ -247,10 +377,7 @@ function linkFunctionCall(graph, id, info, idMap, isRoot) {
247
377
  const calledBuiltIns = builtIns.size > 0 ? [...builtIns] : undefined;
248
378
  return { functionCall: id, called: [...functionDefs], propagateExitPoints, calledBuiltIns };
249
379
  }
250
- /**
251
- * Returns the called functions within `graph` (ideally a superset of `thisGraph`, the graph searched for calls), which
252
- * can be used to merge the environments with the call; also links the corresponding arguments.
253
- */
380
+ /** Returns the called functions within `graph` (ideally a superset of `thisGraph`, the graph searched for calls), which can be used to merge the environments with the call; also links the corresponding arguments. */
254
381
  function linkFunctionCalls(graph, idMap, thisGraph,
255
382
  /** calls `graph` knows of that `thisGraph` does not, as a read that became a call */
256
383
  alsoCalls = []) {
@@ -269,10 +396,10 @@ alsoCalls = []) {
269
396
  return called.filter(assert_1.isNotUndefined);
270
397
  }
271
398
  /**
272
- * convenience function returning all known call targets, as well as the name source which defines them
399
+ * convenience function returning all known call targets, as well as the name source which defines them Over-approximates for calls through reads and aliases (all functions the read may evaluate to are returned).
273
400
  * @useInstead {@link Dataflow.callTargetsOf}
274
401
  */
275
- function getAllFunctionCallTargets(call, graph, environment) {
402
+ function getAllFunctionCallTargets(call, graph, environment, resolver) {
276
403
  const info = graph.getVertex(call);
277
404
  if (!vertex_2.DfgVertex.isFunctionCall(info)) {
278
405
  return [];
@@ -295,79 +422,194 @@ function getAllFunctionCallTargets(call, graph, environment) {
295
422
  if (functionCallDefs.length === 0) {
296
423
  return [];
297
424
  }
298
- const [targets, builtIns] = getAllLinkedFunctionDefinitions(new Set(functionCallDefs), graph);
299
- return [...new Set([...targets.values().map(t => t.id), ...builtIns, ...functionCallDefs])];
425
+ const reads = new Set(functionCallDefs);
426
+ const shared = resolver ?? graph.sharedTargetWalks(g => new LinkedFunctionResolver(g));
427
+ const [targets, builtIns] = shared?.resolve(reads) ?? getAllLinkedFunctionDefinitions(reads, graph);
428
+ const all = new Set([...targets.values().map(t => t.id), ...builtIns, ...functionCallDefs]);
429
+ /* the methods its dispatch rules out are still found by the name */
430
+ info.ruledOut?.forEach(e => all.delete(e));
431
+ return [...all];
300
432
  }
301
- /**
302
- * Finds all linked function definitions starting from the given read ids; expects the caller to already have resolved
303
- * the accessed objects (first layer of reads/returns/calls/...). For call targets, use {@link Dataflow.callTargetsOf} instead.
304
- */
433
+ /** Finds all linked function definitions starting from the given read ids; expects the caller to already have resolved the accessed objects (first layer of reads/returns/calls/...). */
305
434
  function getAllLinkedFunctionDefinitions(functionDefinitionReadIds, dataflowGraph) {
306
435
  const result = new Set();
307
436
  const builtIns = new Set();
308
- /* `call` is the call whose return led into the current body, so a parameter it binds holds only what it passes */
309
437
  const potential = Array.from(functionDefinitionReadIds, id => [id, false, undefined]);
310
- const visited = new Set();
311
- const expanded = new Set();
312
- const expandedViaAccess = new Set();
313
- const at = (id, call) => `${id}@${call ?? ''}`;
314
- while (potential.length !== 0) {
315
- const [cid, viaAccess, call] = potential.pop();
316
- const done = viaAccess ? expandedViaAccess : expanded;
438
+ /* the calls each vertex was expanded under, by whether an access led to it */
439
+ const expanded = [new Map(), new Map()];
440
+ const scopes = new Map();
441
+ const next = (id, viaAccess, call) => {
442
+ if (expanded[viaAccess ? 1 : 0].get(id)?.has(call) !== true) {
443
+ potential.push([id, viaAccess, call]);
444
+ }
445
+ };
446
+ for (let item = potential.pop(); item !== undefined; item = potential.pop()) {
447
+ const [cid, viaAccess, call] = item;
448
+ const done = expanded[viaAccess ? 1 : 0];
449
+ const calls = done.get(cid);
317
450
  /* without a call nothing restricts the walk, so that visit covers those under any call */
318
- if (done.has(at(cid, call)) || done.has(at(cid, undefined))) {
319
- continue;
451
+ if (calls === undefined) {
452
+ done.set(cid, new Set([call]));
320
453
  }
321
- done.add(at(cid, call));
322
- visited.add(at(cid, call));
323
- if (node_id_1.NodeId.isBuiltIn(cid)) {
324
- builtIns.add(cid);
454
+ else if (calls.has(call) || calls.has(undefined)) {
325
455
  continue;
326
456
  }
327
- const vertex = dataflowGraph.getVertex(cid);
328
- if (vertex === undefined) {
329
- continue;
457
+ else {
458
+ calls.add(call);
330
459
  }
331
- else if (vertex.subflow !== undefined) {
332
- result.add(vertex);
460
+ const end = walkLinkedDefinitions(dataflowGraph, cid, viaAccess, call, scopes, next);
461
+ if (end === undefined) {
333
462
  continue;
334
463
  }
335
- const nextViaAccess = viaAccess || vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access);
336
- const isSkipType = vertex_2.DfgVertex.isFunctionCall(vertex) || (vertex_2.DfgVertex.isVariableDefinition(vertex) && vertex.par && !nextViaAccess);
337
- let hasReturnEdge = false;
338
- let followTargets;
339
- /* a list handed on as a whole (a loop, an apply) yields its entries, an access the entry it names */
340
- const handedBack = !viaAccess && vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.List) ? edge_1.EdgeType.Returns | edge_1.EdgeType.Argument : edge_1.EdgeType.Returns;
341
- /* only a call into a body binds parameters, a built-in hands back what it is given in the same context */
342
- const returnedTo = vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex.onlyBuiltin ? cid : call;
343
- for (const [target, e] of dataflowGraph.edgesFrom(cid)) {
344
- if (edge_1.DfEdge.includesType(e, handedBack)) {
345
- hasReturnEdge = true;
346
- if (!visited.has(at(target, returnedTo))) {
347
- potential.push([target, nextViaAccess, returnedTo]);
348
- }
349
- }
350
- else if (!isSkipType && !hasReturnEdge && edge_1.DfEdge.includesType(e, ValueFlowBits)) {
351
- (followTargets ??= []).push([target, edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall)]);
464
+ else if (node_id_1.NodeId.isBuiltIn(end)) {
465
+ builtIns.add(end);
466
+ }
467
+ else {
468
+ result.add(dataflowGraph.getVertex(end));
469
+ }
470
+ }
471
+ return [result, builtIns];
472
+ }
473
+ /** One step of the walk for the function definitions that reads may evaluate to: hands each state the walk goes on to from `id` to `next`, or returns `id` if the walk ends at it, being a built-in or a function definition. */
474
+ function walkLinkedDefinitions(graph, id, viaAccess, call, scopes, next) {
475
+ if (node_id_1.NodeId.isBuiltIn(id)) {
476
+ return id;
477
+ }
478
+ const vertex = graph.getVertex(id);
479
+ if (vertex === undefined) {
480
+ return undefined;
481
+ }
482
+ else if (vertex.subflow !== undefined) {
483
+ return id;
484
+ }
485
+ else if (!viaAccess && vertex_2.DfgVertex.isValue(vertex)) {
486
+ for (const named of functionsNamedBy(graph, id)) {
487
+ next(named, false, undefined);
488
+ }
489
+ }
490
+ const nextViaAccess = viaAccess || vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access);
491
+ const isSkipType = vertex_2.DfgVertex.isFunctionCall(vertex);
492
+ /* a replacement keeps its target what it was (`environment(f) <- e` leaves `f` the same function), unless the call is to what it put into a part of it, so the walk goes on to the binding it replaces only */
493
+ const replaces = vertex_2.DfgVertex.isVariableDefinition(vertex) && vertex.par && !nextViaAccess;
494
+ let hasReturnEdge = false;
495
+ let followTargets;
496
+ /* a list handed on as a whole (a loop, an apply) yields its entries, an access the entry it names */
497
+ const handedBack = !viaAccess && vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.List) ? edge_1.EdgeType.Returns | edge_1.EdgeType.Argument : edge_1.EdgeType.Returns;
498
+ /* only a call into a body binds parameters, a built-in hands back what it is given in the same context */
499
+ const returnedTo = vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex.onlyBuiltin ? id : call;
500
+ for (const [target, e] of graph.edgesFrom(id)) {
501
+ if (edge_1.DfEdge.includesType(e, handedBack)) {
502
+ hasReturnEdge = true;
503
+ next(target, nextViaAccess, returnedTo === call ? scopedTo(graph, scopes, call, target) : returnedTo);
504
+ }
505
+ else if (!isSkipType && !hasReturnEdge && edge_1.DfEdge.includesType(e, ValueFlowBits) && edge_1.DfEdge.doesNotIncludeType(e, replaces ? edge_1.EdgeType.SideEffectOnCall | edge_1.EdgeType.DefinedBy : edge_1.EdgeType.SideEffectOnCall)) {
506
+ (followTargets ??= []).push([target, edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall)]);
507
+ }
508
+ }
509
+ if (!hasReturnEdge && followTargets) {
510
+ /* a parameter the call binds holds only what that call passes, the walk then goes on in the caller */
511
+ const passed = call === undefined ? undefined : new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Argument));
512
+ const bound = followTargets.some(([target, onCall]) => onCall && passed?.has(target));
513
+ for (const [target, onCall] of followTargets) {
514
+ if (!bound || !onCall || passed?.has(target)) {
515
+ next(target, nextViaAccess, onCall ? undefined : scopedTo(graph, scopes, call, target));
352
516
  }
353
517
  }
354
- if (!hasReturnEdge && followTargets) {
355
- /* a parameter the call binds holds only what that call passes, the walk then goes on in the caller */
356
- const passed = call === undefined ? undefined : new Set(df_helper_1.Dataflow.targetsOf(dataflowGraph, call, edge_1.EdgeType.Argument));
357
- const bound = followTargets.some(([target, onCall]) => onCall && passed?.has(target));
358
- for (const [target, onCall] of followTargets) {
359
- const next = onCall ? undefined : call;
360
- if ((!bound || !onCall || passed?.has(target)) && !visited.has(at(target, next))) {
361
- potential.push([target, nextViaAccess, next]);
518
+ }
519
+ return undefined;
520
+ }
521
+ /** A string where a function is wanted names the function (`match.fun`, `do.call` and the apply family look it up), which is resolved where the string is written, by the environment of the call it is passed to. */
522
+ function functionsNamedBy(graph, id) {
523
+ const idMap = graph.idMap;
524
+ const node = idMap?.get(id);
525
+ if (idMap === undefined || !r_string_1.RString.is(node)) {
526
+ return [];
527
+ }
528
+ for (let at = model_1.RNode.directParent(node, idMap); at !== undefined; at = model_1.RNode.directParent(at, idMap)) {
529
+ const call = graph.getVertex(at.info.id);
530
+ if (vertex_2.DfgVertex.isFunctionCall(call) && call.environment !== undefined) {
531
+ return resolve_helper_1.Resolve.byNameAndType(node.content.str, call.environment, identifier_1.ReferenceType.Function)?.map(d => d.nodeId) ?? [];
532
+ }
533
+ }
534
+ return [];
535
+ }
536
+ /** The call that restricts what `target` may hold: a call binds only the parameters of the functions it runs, so once the walk leaves their bodies (to a global, say), the call restricts nothing any more. */
537
+ function scopedTo(graph, scopes, call, target) {
538
+ const idMap = graph.idMap;
539
+ if (call === undefined || idMap === undefined) {
540
+ return call;
541
+ }
542
+ let bodies = scopes.get(call);
543
+ if (bodies === undefined) {
544
+ bodies = new Set(df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Calls | edge_1.EdgeType.Returns).map(t => model_1.RNode.findEnclosing(t, idMap, r_function_definition_1.RFunctionDefinition.is)).filter(assert_1.isNotUndefined));
545
+ scopes.set(call, bodies);
546
+ }
547
+ for (let node = idMap.get(target); node !== undefined; node = model_1.RNode.directParent(node, idMap)) {
548
+ if (bodies.has(node.info.id)) {
549
+ return call;
550
+ }
551
+ }
552
+ return undefined;
553
+ }
554
+ const ReachesNothing = new Set();
555
+ /** Finds the function definitions and built-ins that reads may evaluate to (see {@link getAllLinkedFunctionDefinitions}). */
556
+ class LinkedFunctionResolver {
557
+ graph;
558
+ /** the number of each state, by whether an access led to it, its vertex, and its call */
559
+ numbers = [new Map(), new Map()];
560
+ states = [];
561
+ /** the built-ins and function definitions the walk ends at, by their state */
562
+ ends = new Map();
563
+ scopes = new Map();
564
+ summaries;
565
+ constructor(graph) {
566
+ this.graph = graph;
567
+ this.summaries = new fixpoint_1.ReachSummaries(state => this.expand(state), state => this.ends.get(state), { empty: ReachesNothing, concat: fixpoint_1.unionOfSets });
568
+ }
569
+ /** The function definitions and built-ins the reads with the given ids may evaluate to. */
570
+ resolve(reads) {
571
+ const definitions = new Set();
572
+ const builtIns = new Set();
573
+ for (const read of reads) {
574
+ for (const id of this.summaries.of(this.state(read, false, undefined))) {
575
+ if (node_id_1.NodeId.isBuiltIn(id)) {
576
+ builtIns.add(id);
577
+ }
578
+ else {
579
+ definitions.add(this.graph.getVertex(id));
362
580
  }
363
581
  }
364
582
  }
583
+ return [definitions, builtIns];
584
+ }
585
+ state(id, viaAccess, call) {
586
+ const byCall = this.numbers[viaAccess ? 1 : 0].get(id) ?? new Map();
587
+ let state = byCall.get(call);
588
+ if (state === undefined) {
589
+ state = this.states.push([id, viaAccess, call]) - 1;
590
+ if (byCall.size === 0) {
591
+ this.numbers[viaAccess ? 1 : 0].set(id, byCall);
592
+ }
593
+ byCall.set(call, state);
594
+ }
595
+ return state;
596
+ }
597
+ /** The states the walk goes on to from `state`, none for a built-in or function definition it ends at. */
598
+ expand(state) {
599
+ const [id, viaAccess, call] = this.states[state];
600
+ const successors = [];
601
+ const end = walkLinkedDefinitions(this.graph, id, viaAccess, call, this.scopes, (target, nextViaAccess, nextCall) => {
602
+ successors.push(this.state(target, nextViaAccess, nextCall));
603
+ });
604
+ if (end !== undefined) {
605
+ this.ends.set(state, new Set([end]));
606
+ }
607
+ return successors;
365
608
  }
366
- return [result, builtIns];
367
609
  }
610
+ exports.LinkedFunctionResolver = LinkedFunctionResolver;
368
611
  /**
369
- * Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and
370
- * hands back what stays unresolved. This is how an expression that was captured elsewhere is read here.
612
+ * Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and hands back what stays unresolved.
371
613
  * @useInstead {@link FunctionSemantics.call.quoted.evaluateIn}
372
614
  */
373
615
  function linkExpressionIn(graph, expr, environment, idMap) {
@@ -406,14 +648,10 @@ function linkCallToDefinitions(graph, callId, definitions, idMap) {
406
648
  }
407
649
  }
408
650
  }
409
- /**
410
- * Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked (or
411
- * links to built-ins only) is added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned.
412
- * @param alsoFrom - a node that reads every definition found as well
413
- */
651
+ /** Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked (or links to built-ins only) is added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned. */
414
652
  function linkInputs(referencesToLinkAgainstEnvironment, environmentInformation, givenInputs, graph, maybeForRemaining, alsoFrom) {
415
653
  for (const bodyInput of referencesToLinkAgainstEnvironment) {
416
- const probableTarget = bodyInput.name ? resolve_helper_1.Resolve.byNameAndType(bodyInput.name, environmentInformation, bodyInput.type) : undefined;
654
+ const probableTarget = bodyInput.name ? resolve_helper_1.Resolve.byNameAndType(identifier_1.Identifier.boundAs(bodyInput.name), (0, resolve_by_name_1.scopeOf)(bodyInput, environmentInformation), bodyInput.type) : undefined;
417
655
  if (probableTarget === undefined) {
418
656
  if (maybeForRemaining) {
419
657
  bodyInput.cds ??= [];
@@ -434,22 +672,21 @@ function linkInputs(referencesToLinkAgainstEnvironment, environmentInformation,
434
672
  }
435
673
  return givenInputs;
436
674
  }
437
- /**
438
- * A loop variable read before its within-loop redefinition gets a maybe marker to that def (e.g. `x_2` may read the
439
- * prior iteration's `x_1` in `for(...) { x_1 <- x_2 + 1 }`); with `environment`, this uses all defs live at loop exit.
440
- */
675
+ /** A loop variable read before its within-loop redefinition gets a maybe marker to that def (e.g. `x_2` may read the prior iteration's `x_1` in `for(...) { x_1 <- x_2 + 1 }`); with `environment`, this uses all defs live at loop exit, which the calls in the loop see as well (see {@link linkLoopCarriedCalls}). */
441
676
  function linkCircularRedefinitionsWithinALoop(graph, openIns, outgoing, environment) {
442
677
  if (environment !== undefined) {
443
678
  const outgoingIds = new Set(outgoing.map(o => o.nodeId));
444
679
  for (const [name, targets] of openIns.entries()) {
445
680
  for (const def of environment.current.memory.get(identifier_1.Identifier.getName(name)) ?? []) {
446
- if (outgoingIds.has(def.nodeId)) {
681
+ /* a definition within an argument of a call (`f(x <- x + 1)`) is made in the loop as well, if it is made at all */
682
+ if (outgoingIds.has(def.nodeId) || vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(def.nodeId))) {
447
683
  for (const target of targets) {
448
684
  graph.addEdge(target.nodeId, def.nodeId, edge_1.EdgeType.Reads);
449
685
  }
450
686
  }
451
687
  }
452
688
  }
689
+ linkLoopCarriedCalls(graph, environment, outgoingIds, new Set(outgoing.map(o => identifier_1.Identifier.getName(o.name))));
453
690
  return;
454
691
  }
455
692
  /* fallback: keep only the last definition per identifier (used when no environment is available) */
@@ -469,6 +706,76 @@ function linkCircularRedefinitionsWithinALoop(graph, openIns, outgoing, environm
469
706
  }
470
707
  }
471
708
  }
709
+ /** A call in a loop runs again after the rest of the body ran, so it sees what the body leaves behind as well (`environment`), and so do the free variables of the closures it calls: in `f <- function() x; for(i in 1:2) { y <- f(); x <- 2 }` the second call of `f` reads `x <- 2`. */
710
+ function linkLoopCarriedCalls(graph, environment, made, names) {
711
+ const idMap = graph.idMap;
712
+ for (const [id, info] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
713
+ if (info.onlyBuiltin || info.environment?.level !== environment.level) {
714
+ continue;
715
+ }
716
+ info.environment = environment_1.REnvironment.append(info.environment, idMap === undefined ? environment : carriedTo(graph, info, info.environment, environment, made, names, idMap));
717
+ for (const target of idMap === undefined ? [] : df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls)) {
718
+ const fn = graph.getVertex(target);
719
+ if (vertex_2.DfgVertex.isFunctionDefinition(fn)) {
720
+ linkFreeReads(graph, fn.subflow, target, info, idMap);
721
+ }
722
+ }
723
+ }
724
+ }
725
+ /** What `exit` carries into the next run for the call `info`, without the `names` the body (`made`) surely binds anew before the call: a binding the call sees that the body makes in an earlier statement, under no condition the call is not under as well. */
726
+ function carriedTo(graph, info, atCall, exit, made, names, idMap) {
727
+ let carried;
728
+ const call = idMap.get(info.id);
729
+ for (const name of names) {
730
+ const defs = name === undefined || exit.current.memory.get(name) === undefined ? undefined : atCall.current.memory.get(name);
731
+ if (defs?.some(d => made.has(d.nodeId) && info_1.ControlDependency.minus(graph.getVertex(d.nodeId)?.cds ?? [], info.cds ?? []).length === 0 && model_1.RNode.precedesInBlock(idMap.get(d.nodeId), call, idMap))) {
732
+ carried ??= exit.current.clone(false);
733
+ carried.writableMemory.delete(name);
734
+ }
735
+ }
736
+ return carried === undefined ? exit : { current: carried, level: exit.level };
737
+ }
738
+ /** A call in a loop runs again, so what its callee writes reaches the reads of the loop before the call as well: in `ch <- function() g <<- 2; for(i in 1:2) { s <- g; ch() }` the second `s <- g` reads `g <<- 2`. */
739
+ function linkWritesCarriedByLoop(graph, call, written, idMap) {
740
+ let loop;
741
+ for (let node = idMap.get(call); node !== undefined && !r_function_definition_1.RFunctionDefinition.is(node); node = model_1.RNode.directParent(node, idMap)) {
742
+ if (model_1.RLoopConstructs.is(node)) {
743
+ loop = node;
744
+ }
745
+ }
746
+ if (loop === undefined || written.length === 0) {
747
+ return;
748
+ }
749
+ const byName = new Map();
750
+ for (const def of written) {
751
+ if (def.name !== undefined) {
752
+ const name = identifier_1.Identifier.getName(def.name);
753
+ byName.set(name, [...byName.get(name) ?? [], def]);
754
+ }
755
+ }
756
+ const writtenAs = (name) => name === undefined ? undefined : byName.get(identifier_1.Identifier.getName(name));
757
+ for (const id of model_1.RNode.collectAllIdsWithStop(loop, r_function_definition_1.RFunctionDefinition.is)) {
758
+ const vertex = graph.getVertex(id);
759
+ if (!vertex_2.DfgVertex.isUse(vertex) && !vertex_2.DfgVertex.isFunctionCall(vertex)) {
760
+ continue;
761
+ }
762
+ for (const def of writtenAs(vertex_2.DfgVertex.isFunctionCall(vertex) ? vertex.name : node_id_1.NodeId.recoverBareName(id, idMap)) ?? []) {
763
+ graph.addEdge(id, def.nodeId, edge_1.EdgeType.Reads);
764
+ if (vertex_2.DfgVertex.isFunctionCall(vertex)) {
765
+ getAllLinkedFunctionDefinitions(new Set([def.nodeId]), graph)[0].forEach(fn => graph.addEdge(id, fn.id, edge_1.EdgeType.Calls));
766
+ }
767
+ }
768
+ for (const target of vertex_2.DfgVertex.isFunctionCall(vertex) ? df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls) : []) {
769
+ const fn = graph.getVertex(target);
770
+ for (const ingoing of vertex_2.DfgVertex.isFunctionDefinition(fn) ? fn.subflow.in : []) {
771
+ for (const def of writtenAs(ingoing.name) ?? []) {
772
+ graph.addEdge(ingoing.nodeId, def.nodeId, edge_1.EdgeType.DefinedByOnCall);
773
+ graph.addEdge(id, def.nodeId, edge_1.EdgeType.DefinesOnCall);
774
+ }
775
+ }
776
+ }
777
+ }
778
+ }
472
779
  function addControlDependency(holder, cd) {
473
780
  if (holder.cds?.some(c => c.id === cd.id)) {
474
781
  return false;
@@ -476,9 +783,7 @@ function addControlDependency(holder, cd) {
476
783
  holder.cds = [...holder.cds ?? [], cd];
477
784
  return true;
478
785
  }
479
- /**
480
- * Reapplies the loop exit points' control dependencies to the given identifier references.
481
- */
786
+ /** Reapplies the loop exit points' control dependencies to the given identifier references. */
482
787
  function reapplyLoopExitPoints(exits, references, graph) {
483
788
  const exitCds = exits.flatMap(e => e.cds?.map(info_1.negateControlDependency))
484
789
  .filter(assert_1.isNotUndefined)
@@ -506,10 +811,7 @@ function reapplyLoopExitPoints(exits, references, graph) {
506
811
  */
507
812
  exports.ClosureRefs = {
508
813
  name: 'ClosureRefs',
509
- /**
510
- * Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`,
511
- * links what resolves, and leaves only the references that stay open.
512
- */
814
+ /** Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`, links what resolves, and leaves only the references that stay open. */
513
815
  resolveOpenIngoing(graph, callId, definition, environment) {
514
816
  definition.subflow.in = linkInputs(definition.subflow.in, environment, [], graph, false, callId);
515
817
  }
@@ -525,11 +827,23 @@ function accessedFieldName(fieldNode, treatIndicesAsString) {
525
827
  return r_number_1.RNumber.is(fieldNode) && !fieldNode.content.complexNumber && Number.isInteger(fieldNode.content.num) && fieldNode.content.num > 0
526
828
  ? String(fieldNode.content.num) : undefined;
527
829
  }
528
- /**
529
- * Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns,
530
- * and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`.
531
- */
532
- function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions) {
830
+ /** Adds the definitions `found` to what the lookup `lookup` finds where it is written, or when `call` runs it, see {@link DataflowGraphVertexFunctionCall#found} and {@link DataflowGraphVertexFunctionCall#foundOnCall}. */
831
+ function recordFound(graph, lookup, found, call) {
832
+ const vertex = graph.getVertex(lookup);
833
+ if (found.length === 0 || !vertex_2.DfgVertex.isFunctionCall(vertex)) {
834
+ return;
835
+ }
836
+ else if (call === undefined) {
837
+ vertex.found = vertex.found === undefined ? found : (0, arrays_1.uniqueArrayMerge)(vertex.found, found);
838
+ return;
839
+ }
840
+ const known = vertex.foundOnCall?.find(f => f.call === call);
841
+ const entry = { call, found: known === undefined ? found : (0, arrays_1.uniqueArrayMerge)(known.found, found) };
842
+ vertex.foundOnCall = [...vertex.foundOnCall?.filter(f => f !== known) ?? [], entry];
843
+ }
844
+ /** Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns, and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`. */
845
+ function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions, call) {
846
+ recordFound(graph, accessId, fieldDefs?.map(d => d.nodeId).filter(d => !node_id_1.NodeId.isBuiltIn(d)) ?? [], call);
533
847
  for (const fd of fieldDefs ?? []) {
534
848
  graph.addEdge(accessId, fd.nodeId, edge_1.EdgeType.Reads);
535
849
  if (fd.definedAt !== undefined && fd.definedAt !== fd.nodeId) {
@@ -540,14 +854,18 @@ function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions) {
540
854
  }
541
855
  }
542
856
  }
857
+ const AssignFormals = ['x', 'value', 'pos', 'envir', 'inherits', 'immediate'];
543
858
  /** The call writing a field into the environment the symbol `readId` holds: `x$f <- v` (its replacement call) or `assign("f", v, envir = x)`. */
544
859
  function fieldAssignmentOf(readId, idMap) {
545
860
  const read = idMap.get(readId);
546
861
  const access = read === undefined ? undefined : model_1.RNode.directParent(read, idMap);
547
862
  /* `assign("f", v, envir = x)` writes into `x` as well */
548
863
  const call = access === undefined ? undefined : model_1.RNode.directParent(access, idMap);
549
- if (r_function_call_1.RFunctionCall.isNamed(call, 'assign') && call.arguments.indexOf(access) >= 2) {
550
- return call.info.id;
864
+ if (r_function_call_1.RFunctionCall.isNamed(call, 'assign')) {
865
+ const bound = function_semantics_1.FunctionSemantics.call.match.toNames(call.arguments, AssignFormals);
866
+ if (access === bound.get('envir') || access === bound.get('pos')) {
867
+ return call.info.id;
868
+ }
551
869
  }
552
870
  if (!r_access_1.RAccess.is(access) || access.accessed.info.id !== readId) {
553
871
  return undefined;
@@ -562,18 +880,15 @@ function fieldAssignmentOf(readId, idMap) {
562
880
  /* the replacement call `$<-` carries the id of the access it writes through */
563
881
  return r_binary_op_1.RBinaryOp.is(assign) && assign.lhs.info.id === target.info.id && /^(<<?-|=)$/.test(assign.operator) ? access.info.id : undefined;
564
882
  }
565
- /**
566
- * An access `x$f` written where `x` was still open reads the field of whatever `x` is bound to once that binding is
567
- * known, so binding the read at `readId` to a definition holding `envState` links the access to that field.
568
- */
569
- function bindAccessedField(graph, readId, envState, idMap) {
883
+ /** An access `x$f` written where `x` was still open reads the field of whatever `x` is bound to once that binding is known, so binding the read at `readId` to a definition holding `envState` links the access to that field. */
884
+ function bindAccessedField(graph, readId, envState, idMap, call) {
570
885
  const read = idMap.get(readId);
571
886
  const access = read === undefined ? undefined : model_1.RNode.directParent(read, idMap);
572
887
  if (!r_access_1.RAccess.is(access) || access.accessed.info.id !== readId) {
573
888
  return;
574
889
  }
575
890
  const fieldName = accessedFieldName(r_argument_1.RArgument.valueOf(access.access[0]), r_access_1.RAccess.isNamed(access));
576
- linkFieldReads(graph, access.info.id, fieldName ? envState.current.memory.get(fieldName) : undefined, true);
891
+ linkFieldReads(graph, access.info.id, fieldName ? envState.current.memory.get(fieldName) : undefined, true, call);
577
892
  }
578
893
  /** The factory that creates and returns only `closure`, calling only known built-ins and not reflecting on its frame, with the names its frame binds. */
579
894
  function factoryOf(closure, graph, known, idMap) {
@@ -590,7 +905,7 @@ function factoryOf(closure, graph, known, idMap) {
590
905
  continue;
591
906
  }
592
907
  else if (vertex_2.DfgVertex.isFunctionDefinition(vertex) || (vertex_2.DfgVertex.isFunctionCall(vertex) && (!vertex.onlyBuiltin || graph.unknownSideEffects.has(node_id_1.NodeId.normalize(node))))
593
- || vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.SuperAssignment)) {
908
+ || df_helper_1.Dataflow.superAssigns(graph, node)) {
594
909
  return undefined;
595
910
  }
596
911
  else if (vertex_2.DfgVertex.isVariableDefinition(vertex)) {
@@ -607,24 +922,11 @@ function instancesOf(call, closure, factory, graph) {
607
922
  if (!df_helper_1.Dataflow.hasEdge(graph, call, closure, edge_1.EdgeType.Calls)) {
608
923
  return undefined;
609
924
  }
610
- const instances = [];
611
- for (const [binding, edge] of graph.edgesFrom(call)) {
612
- if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) || edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument) || node_id_1.NodeId.isBuiltIn(binding)) {
613
- continue;
614
- }
615
- /* the binding the call reads holds what one call of the factory created, and nothing else */
616
- const isCallOfAFunction = (target) => {
617
- const vertex = graph.getVertex(target);
618
- return vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Assignment);
619
- };
620
- const created = vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(binding)) ? df_helper_1.Dataflow.targetsOf(graph, binding, edge_1.EdgeType.DefinedBy).filter(isCallOfAFunction) : [];
621
- const callees = created.length === 1 ? df_helper_1.Dataflow.targetsOf(graph, created[0], edge_1.EdgeType.Calls) : [];
622
- if (callees.length !== 1 || callees[0] !== factory) {
623
- return undefined;
624
- }
625
- instances.push(created[0]);
626
- }
627
- return instances.length > 0 ? instances : undefined;
925
+ const instances = closure_frames_1.ClosureFrames.instancesOf(graph, call);
926
+ return instances?.every(created => {
927
+ const callees = df_helper_1.Dataflow.targetsOf(graph, created, edge_1.EdgeType.Calls);
928
+ return callees.length === 1 && callees[0] === factory;
929
+ }) ? instances : undefined;
628
930
  }
629
931
  /** A closure's `<<-` into its factory frame is seen only by calls of closures from the same factory call, so such calls depend on each other instead. */
630
932
  function separateClosureInstances(graph, known) {
@@ -634,7 +936,7 @@ function separateClosureInstances(graph, known) {
634
936
  }
635
937
  for (const [closure, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
636
938
  /* only a closure writing with `<<-` can share state */
637
- const superAssignments = vertex.subflow.graph.values().filter(id => vertex_2.DfgVertex.hasOrigin(graph.getVertex(id), built_in_proc_name_1.BuiltInProcName.SuperAssignment)).toArray();
939
+ const superAssignments = vertex.subflow.graph.values().filter(id => df_helper_1.Dataflow.superAssigns(graph, id)).toArray();
638
940
  const found = superAssignments.length === 0 ? undefined : factoryOf(vertex, graph, known, idMap);
639
941
  if (found === undefined) {
640
942
  continue;