@eagleoutice/flowr 2.17.3 → 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 (592) 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/commands/repl-signature.d.ts +1 -1
  18. package/cli/repl/completion.d.ts +23 -0
  19. package/cli/repl/completion.js +9 -0
  20. package/cli/repl/core.d.ts +0 -23
  21. package/cli/repl/core.js +0 -5
  22. package/cli/repl/parser/slice-query-parser.d.ts +1 -1
  23. package/cli/repl/parser/slice-query-parser.js +3 -3
  24. package/cli/repl/print-version.d.ts +1 -1
  25. package/cli/repl/print-version.js +2 -1
  26. package/cli/repl/server/connection.d.ts +1 -1
  27. package/cli/repl/server/connection.js +7 -9
  28. package/cli/slicer-app.js +2 -1
  29. package/clones/algorithms/baxter-ast.d.ts +33 -0
  30. package/clones/algorithms/baxter-ast.js +70 -0
  31. package/clones/algorithms/greedy-string-tiling.d.ts +17 -0
  32. package/clones/algorithms/greedy-string-tiling.js +56 -0
  33. package/clones/algorithms/winnowing.d.ts +27 -0
  34. package/clones/algorithms/winnowing.js +66 -0
  35. package/clones/clone-ast.d.ts +75 -0
  36. package/clones/clone-ast.js +174 -0
  37. package/clones/clone-dataflow.d.ts +11 -0
  38. package/clones/clone-dataflow.js +83 -0
  39. package/clones/clone-detector.d.ts +116 -0
  40. package/clones/clone-detector.js +200 -0
  41. package/clones/clone-index.d.ts +54 -0
  42. package/clones/clone-index.js +56 -0
  43. package/config.d.ts +21 -2
  44. package/config.js +7 -1
  45. package/control-flow/basic-cfg-guided-visitor.js +1 -2
  46. package/control-flow/happens-before.d.ts +2 -0
  47. package/control-flow/happens-before.js +15 -9
  48. package/control-flow/simple-visitor.js +2 -4
  49. package/core/steps/all/core/00-parse.js +2 -1
  50. package/core/steps/all/core/01-parse-tree-sitter.js +2 -1
  51. package/core/steps/all/core/10-normalize.js +2 -1
  52. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -1
  53. package/core/steps/all/static-slicing/00-slice.js +2 -1
  54. package/core/steps/all/static-slicing/10-reconstruct.js +2 -1
  55. package/core/steps/pipeline/create-pipeline.js +1 -2
  56. package/core/steps/pipeline/default-pipelines.d.ts +1 -1
  57. package/core/steps/pipeline/default-pipelines.js +5 -4
  58. package/core/steps/pipeline-step.d.ts +3 -1
  59. package/core/steps/pipeline-step.js +5 -0
  60. package/data/r-base-primitives.generated.d.ts +2 -1
  61. package/dataflow/cluster.js +1 -2
  62. package/dataflow/environments/ambient-state-name.d.ts +14 -22
  63. package/dataflow/environments/ambient-state-name.js +4 -18
  64. package/dataflow/environments/apply-kill.d.ts +9 -20
  65. package/dataflow/environments/apply-kill.js +51 -25
  66. package/dataflow/environments/built-in-config.d.ts +7 -15
  67. package/dataflow/environments/built-in-config.js +15 -16
  68. package/dataflow/environments/built-in-eval-name.d.ts +5 -6
  69. package/dataflow/environments/built-in-eval-name.js +4 -5
  70. package/dataflow/environments/built-in-kinds.d.ts +111 -0
  71. package/dataflow/environments/built-in-kinds.js +35 -0
  72. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  73. package/dataflow/environments/built-in-proc-name.js +11 -0
  74. package/dataflow/environments/built-in-props.d.ts +66 -172
  75. package/dataflow/environments/built-in-props.js +47 -151
  76. package/dataflow/environments/built-in.d.ts +42 -76
  77. package/dataflow/environments/built-in.js +46 -66
  78. package/dataflow/environments/data-masking-functions.d.ts +2 -2
  79. package/dataflow/environments/default-builtin-config/base-functions.d.ts +7 -0
  80. package/dataflow/environments/default-builtin-config/base-functions.js +339 -0
  81. package/dataflow/environments/default-builtin-config/base-language.d.ts +3 -0
  82. package/dataflow/environments/default-builtin-config/base-language.js +66 -0
  83. package/dataflow/environments/default-builtin-config/base-operators.d.ts +58 -0
  84. package/dataflow/environments/default-builtin-config/base-operators.js +169 -0
  85. package/dataflow/environments/default-builtin-config/database-access.d.ts +3 -0
  86. package/dataflow/environments/default-builtin-config/database-access.js +16 -0
  87. package/dataflow/environments/default-builtin-config/define-helpers.d.ts +45 -0
  88. package/dataflow/environments/default-builtin-config/define-helpers.js +50 -0
  89. package/dataflow/environments/default-builtin-config/dev-tooling.d.ts +3 -0
  90. package/dataflow/environments/default-builtin-config/dev-tooling.js +63 -0
  91. package/dataflow/environments/default-builtin-config/file-io.d.ts +3 -0
  92. package/dataflow/environments/default-builtin-config/file-io.js +81 -0
  93. package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +3 -0
  94. package/dataflow/environments/default-builtin-config/graphics-devices.js +57 -0
  95. package/dataflow/environments/default-builtin-config/index.d.ts +18 -0
  96. package/dataflow/environments/default-builtin-config/index.js +114 -0
  97. package/dataflow/environments/default-builtin-config/media-formats.d.ts +3 -0
  98. package/dataflow/environments/default-builtin-config/media-formats.js +41 -0
  99. package/dataflow/environments/default-builtin-config/misc-packages.d.ts +3 -0
  100. package/dataflow/environments/default-builtin-config/misc-packages.js +18 -0
  101. package/dataflow/environments/default-builtin-config/network-access.d.ts +3 -0
  102. package/dataflow/environments/default-builtin-config/network-access.js +47 -0
  103. package/dataflow/environments/default-builtin-config/object-systems.d.ts +3 -0
  104. package/dataflow/environments/default-builtin-config/object-systems.js +39 -0
  105. package/dataflow/environments/default-builtin-config/package-data-table.d.ts +3 -0
  106. package/dataflow/environments/default-builtin-config/package-data-table.js +18 -0
  107. package/dataflow/environments/default-builtin-config/package-spatial.d.ts +3 -0
  108. package/dataflow/environments/default-builtin-config/package-spatial.js +32 -0
  109. package/dataflow/environments/default-builtin-config/package-tidyverse.d.ts +3 -0
  110. package/dataflow/environments/default-builtin-config/package-tidyverse.js +96 -0
  111. package/dataflow/environments/default-builtin-config/package-utils.d.ts +3 -0
  112. package/dataflow/environments/default-builtin-config/package-utils.js +35 -0
  113. package/dataflow/environments/default-builtin-config/package-withr.d.ts +3 -0
  114. package/dataflow/environments/default-builtin-config/package-withr.js +41 -0
  115. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +3 -0
  116. package/dataflow/environments/default-builtin-config/parallel-execution.js +31 -0
  117. package/dataflow/environments/default-builtin-config/session-interactive.d.ts +3 -0
  118. package/dataflow/environments/default-builtin-config/session-interactive.js +31 -0
  119. package/dataflow/environments/default-builtin-config/shared-configs.d.ts +267 -0
  120. package/dataflow/environments/default-builtin-config/shared-configs.js +483 -0
  121. package/dataflow/environments/default-builtin-config/shared-signatures.d.ts +21 -0
  122. package/dataflow/environments/default-builtin-config/shared-signatures.js +32 -0
  123. package/dataflow/environments/default-builtin-config/statistics.d.ts +3 -0
  124. package/dataflow/environments/default-builtin-config/statistics.js +32 -0
  125. package/dataflow/environments/default-builtin-config/unit-testing.d.ts +3 -0
  126. package/dataflow/environments/default-builtin-config/unit-testing.js +13 -0
  127. package/dataflow/environments/environment.d.ts +28 -52
  128. package/dataflow/environments/environment.js +24 -71
  129. package/dataflow/environments/group-generics.d.ts +12 -19
  130. package/dataflow/environments/group-generics.js +17 -14
  131. package/dataflow/environments/identifier.d.ts +72 -427
  132. package/dataflow/environments/identifier.js +34 -145
  133. package/dataflow/environments/pkg-name.d.ts +197 -0
  134. package/dataflow/environments/pkg-name.js +3 -0
  135. package/dataflow/environments/query-fn-props.d.ts +27 -76
  136. package/dataflow/environments/query-fn-props.js +34 -95
  137. package/dataflow/environments/resolve-by-name.d.ts +6 -16
  138. package/dataflow/environments/resolve-by-name.js +23 -35
  139. package/dataflow/environments/scoping.d.ts +5 -5
  140. package/dataflow/environments/scoping.js +13 -5
  141. package/dataflow/eval/resolve/alias-tracking.d.ts +31 -68
  142. package/dataflow/eval/resolve/alias-tracking.js +611 -126
  143. package/dataflow/eval/resolve/match-arguments.d.ts +5 -3
  144. package/dataflow/eval/resolve/resolve-argument.d.ts +11 -11
  145. package/dataflow/eval/resolve/resolve-argument.js +35 -35
  146. package/dataflow/eval/resolve/resolve-field.d.ts +10 -0
  147. package/dataflow/eval/resolve/resolve-field.js +127 -0
  148. package/dataflow/eval/resolve/resolve-numbers.d.ts +1 -178
  149. package/dataflow/eval/resolve/resolve-numbers.js +2 -13
  150. package/dataflow/eval/resolve/resolve-replacement.d.ts +10 -0
  151. package/dataflow/eval/resolve/resolve-replacement.js +80 -0
  152. package/dataflow/eval/resolve/resolve-strings.d.ts +3 -95
  153. package/dataflow/eval/resolve/resolve-strings.js +2 -17
  154. package/dataflow/eval/resolve/resolve-working-directory.js +3 -4
  155. package/dataflow/eval/resolve/resolve.d.ts +13 -10
  156. package/dataflow/eval/resolve/resolve.js +81 -32
  157. package/dataflow/eval/values/general.d.ts +6 -24
  158. package/dataflow/eval/values/general.js +12 -29
  159. package/dataflow/eval/values/lists/list-constants.d.ts +11 -0
  160. package/dataflow/eval/values/lists/list-constants.js +65 -0
  161. package/dataflow/eval/values/r-value.d.ts +20 -23
  162. package/dataflow/eval/values/r-value.js +22 -17
  163. package/dataflow/extractor.d.ts +2 -10
  164. package/dataflow/extractor.js +134 -62
  165. package/dataflow/fn/argument-roles.d.ts +2 -4
  166. package/dataflow/fn/argument-roles.js +49 -23
  167. package/dataflow/fn/class-declaration.d.ts +36 -52
  168. package/dataflow/fn/class-declaration.js +22 -56
  169. package/dataflow/fn/condition-handlers.d.ts +2 -1
  170. package/dataflow/fn/dispatch.d.ts +70 -0
  171. package/dataflow/fn/dispatch.js +434 -0
  172. package/dataflow/fn/exceptions-of-function.d.ts +1 -2
  173. package/dataflow/fn/exceptions-of-function.js +36 -106
  174. package/dataflow/fn/frame-reflection.d.ts +1 -3
  175. package/dataflow/fn/frame-reflection.js +8 -16
  176. package/dataflow/fn/function-props.d.ts +2 -5
  177. package/dataflow/fn/function-props.js +27 -36
  178. package/dataflow/fn/function-semantics.d.ts +14 -26
  179. package/dataflow/fn/function-semantics.js +4 -18
  180. package/dataflow/fn/higher-order-function.js +2 -4
  181. package/dataflow/fn/strict-function.d.ts +10 -35
  182. package/dataflow/fn/strict-function.js +126 -138
  183. package/dataflow/graph/ambient-access.d.ts +51 -0
  184. package/dataflow/graph/ambient-access.js +80 -0
  185. package/dataflow/graph/call-graph.d.ts +9 -29
  186. package/dataflow/graph/call-graph.js +17 -41
  187. package/dataflow/graph/closure-frames.d.ts +46 -0
  188. package/dataflow/graph/closure-frames.js +225 -0
  189. package/dataflow/graph/dataflowgraph-builder.d.ts +25 -96
  190. package/dataflow/graph/dataflowgraph-builder.js +29 -97
  191. package/dataflow/graph/df-helper.d.ts +48 -187
  192. package/dataflow/graph/df-helper.js +107 -207
  193. package/dataflow/graph/diff-dataflow-graph.d.ts +5 -15
  194. package/dataflow/graph/diff-dataflow-graph.js +25 -25
  195. package/dataflow/graph/edge.js +1 -1
  196. package/dataflow/graph/graph-helper.d.ts +10 -46
  197. package/dataflow/graph/graph-helper.js +16 -50
  198. package/dataflow/graph/graph.d.ts +44 -97
  199. package/dataflow/graph/graph.js +83 -79
  200. package/dataflow/graph/match-args.d.ts +21 -88
  201. package/dataflow/graph/match-args.js +284 -97
  202. package/dataflow/graph/vertex.d.ts +101 -128
  203. package/dataflow/graph/vertex.js +23 -20
  204. package/dataflow/hooks.d.ts +7 -14
  205. package/dataflow/hooks.js +15 -13
  206. package/dataflow/info.d.ts +2 -17
  207. package/dataflow/internal/dispatch-linking.d.ts +71 -0
  208. package/dataflow/internal/dispatch-linking.js +332 -0
  209. package/dataflow/internal/linker.d.ts +48 -50
  210. package/dataflow/internal/linker.js +458 -155
  211. package/dataflow/internal/process/functions/call/argument/make-argument.js +2 -1
  212. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -14
  213. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -46
  214. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +7 -6
  215. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +10 -9
  216. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +25 -69
  217. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +292 -89
  218. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +10 -7
  219. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +66 -45
  220. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +15 -19
  221. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +85 -64
  222. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -4
  223. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -2
  224. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +2 -2
  225. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +3 -2
  226. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +15 -0
  227. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +416 -0
  228. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +37 -54
  229. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +192 -111
  230. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +4 -3
  231. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +60 -13
  232. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -3
  233. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +80 -76
  234. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +1 -7
  235. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -13
  236. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +4 -8
  237. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +436 -140
  238. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +18 -10
  239. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +90 -12
  240. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -5
  241. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -14
  242. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +9 -8
  243. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -7
  244. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
  245. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +3 -5
  246. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +2 -6
  247. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -1
  248. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +9 -24
  249. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +10 -6
  250. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +5 -6
  251. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +3 -4
  252. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -4
  253. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +8 -11
  254. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -5
  255. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +20 -28
  256. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +17 -4
  257. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +117 -4
  258. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +5 -3
  259. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +3 -3
  260. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +8 -4
  261. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +18 -29
  262. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -34
  263. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +42 -56
  264. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +4 -18
  265. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +16 -22
  266. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +18 -16
  267. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +130 -65
  268. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -1
  269. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +2 -1
  270. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +39 -21
  271. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +587 -107
  272. package/dataflow/internal/process/functions/call/common.d.ts +8 -24
  273. package/dataflow/internal/process/functions/call/common.js +24 -24
  274. package/dataflow/internal/process/functions/call/deferred.d.ts +7 -27
  275. package/dataflow/internal/process/functions/call/deferred.js +6 -27
  276. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +7 -50
  277. package/dataflow/internal/process/functions/call/known-call-handling.js +14 -50
  278. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -4
  279. package/dataflow/internal/process/functions/call/named-call-handling.js +14 -35
  280. package/dataflow/internal/process/functions/call/nse-kind.d.ts +24 -0
  281. package/dataflow/internal/process/functions/call/nse-kind.js +30 -0
  282. package/dataflow/internal/process/functions/call/nse.d.ts +2 -9
  283. package/dataflow/internal/process/functions/call/nse.js +6 -13
  284. package/dataflow/internal/process/functions/call/quoted.d.ts +4 -15
  285. package/dataflow/internal/process/functions/call/quoted.js +26 -62
  286. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +3 -6
  287. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +29 -11
  288. package/dataflow/internal/process/functions/process-parameter.js +1 -1
  289. package/dataflow/internal/program-order.d.ts +3 -10
  290. package/dataflow/internal/program-order.js +19 -10
  291. package/dataflow/origin/dfg-get-origin.js +2 -1
  292. package/documentation/data/faq/faqs.js +16 -1
  293. package/documentation/data/interface/doc-writing-code.js +5 -7
  294. package/documentation/doc-capabilities.js +3 -3
  295. package/documentation/doc-readme.js +1 -1
  296. package/documentation/doc-util/doc-code.d.ts +0 -5
  297. package/documentation/doc-util/doc-code.js +2 -22
  298. package/documentation/doc-util/doc-query.d.ts +1 -2
  299. package/documentation/doc-util/doc-query.js +4 -5
  300. package/documentation/doc-util/doc-search.js +1 -1
  301. package/documentation/wiki-analyzer.js +4 -3
  302. package/documentation/wiki-core.js +5 -5
  303. package/documentation/wiki-dataflow-graph.js +6 -0
  304. package/documentation/wiki-interface.js +2 -1
  305. package/documentation/wiki-linter.js +15 -3
  306. package/documentation/wiki-linting-and-testing.js +15 -2
  307. package/documentation/wiki-query.js +114 -31
  308. package/index.d.ts +3 -1
  309. package/index.js +6 -3
  310. package/linter/linter-executor.js +1 -1
  311. package/linter/linter-rules.d.ts +37 -8
  312. package/linter/linter-rules.js +8 -1
  313. package/linter/linter-util.d.ts +3 -3
  314. package/linter/linter-util.js +1 -1
  315. package/linter/rules/absolute-path.js +5 -5
  316. package/linter/rules/cmd-check/bogus-return.d.ts +2 -1
  317. package/linter/rules/cmd-check/call-arguments.d.ts +3 -2
  318. package/linter/rules/cmd-check/call-arguments.js +5 -5
  319. package/linter/rules/cmd-check/cmd-check-util.d.ts +9 -8
  320. package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -1
  321. package/linter/rules/cmd-check/dependency-declaration.js +3 -3
  322. package/linter/rules/cmd-check/documentation-mismatch.d.ts +3 -2
  323. package/linter/rules/cmd-check/documentation-mismatch.js +2 -1
  324. package/linter/rules/cmd-check/file-checks.d.ts +2 -2
  325. package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -1
  326. package/linter/rules/cmd-check/global-environment-modification.d.ts +6 -5
  327. package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -1
  328. package/linter/rules/cmd-check/non-ascii-code.js +1 -1
  329. package/linter/rules/cmd-check/package-files.d.ts +2 -2
  330. package/linter/rules/cmd-check/package-hooks.d.ts +5 -4
  331. package/linter/rules/cmd-check/package-runtime.js +4 -4
  332. package/linter/rules/cmd-check/rd-files.js +2 -1
  333. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +3 -2
  334. package/linter/rules/cmd-check/s-three-method-consistency.js +2 -1
  335. package/linter/rules/code-clones.d.ts +57 -0
  336. package/linter/rules/code-clones.js +53 -0
  337. package/linter/rules/deprecated-functions.js +5 -8
  338. package/linter/rules/file-path-validity.js +11 -9
  339. package/linter/rules/function-finder-util.d.ts +4 -2
  340. package/linter/rules/function-finder-util.js +2 -2
  341. package/linter/rules/naming-convention.d.ts +6 -5
  342. package/linter/rules/naming-convention.js +2 -3
  343. package/linter/rules/no-leaked-credentials.d.ts +2 -1
  344. package/linter/rules/no-leaked-credentials.js +1 -1
  345. package/linter/rules/overwritten-file.d.ts +2 -1
  346. package/linter/rules/overwritten-file.js +2 -4
  347. package/linter/rules/problematic-inputs.d.ts +2 -1
  348. package/linter/rules/problematic-inputs.js +3 -3
  349. package/linter/rules/process-state-in-session.d.ts +7 -6
  350. package/linter/rules/process-state-in-session.js +1 -1
  351. package/linter/rules/roxygen-arguments.d.ts +1 -1
  352. package/linter/rules/secret-exfiltration.d.ts +3 -2
  353. package/linter/rules/secret-exfiltration.js +9 -4
  354. package/linter/rules/seeded-randomness.d.ts +3 -3
  355. package/linter/rules/unclosed-connection.js +1 -2
  356. package/linter/rules/undefined-symbol-util.d.ts +3 -2
  357. package/linter/rules/undefined-symbol.d.ts +3 -2
  358. package/linter/rules/unescaped-arguments.d.ts +1 -1
  359. package/linter/rules/unescaped-arguments.js +6 -8
  360. package/linter/rules/unused-definition.d.ts +4 -3
  361. package/linter/rules/unused-definition.js +10 -12
  362. package/linter/rules/unused-import.d.ts +6 -5
  363. package/linter/rules/unused-import.js +20 -6
  364. package/package.json +1 -1
  365. package/project/attached-packages.d.ts +5 -4
  366. package/project/cache/flowr-analyzer-cache.d.ts +14 -1
  367. package/project/cache/flowr-analyzer-cache.js +40 -3
  368. package/project/cache/flowr-analyzer-controlflow-cache.d.ts +0 -6
  369. package/project/cache/flowr-analyzer-controlflow-cache.js +7 -27
  370. package/project/context/flowr-analyzer-context.d.ts +2 -2
  371. package/project/context/flowr-analyzer-context.js +2 -2
  372. package/project/context/flowr-analyzer-dependencies-context.d.ts +12 -12
  373. package/project/context/flowr-analyzer-environment-context.d.ts +3 -3
  374. package/project/context/flowr-analyzer-environment-context.js +3 -3
  375. package/project/context/flowr-analyzer-files-context.d.ts +8 -0
  376. package/project/context/flowr-analyzer-files-context.js +51 -6
  377. package/project/context/flowr-analyzer-functions-context.d.ts +9 -7
  378. package/project/context/flowr-analyzer-gas-context.d.ts +25 -0
  379. package/project/context/flowr-analyzer-gas-context.js +34 -4
  380. package/project/dependency-version-space.d.ts +30 -29
  381. package/project/dependency-version-space.js +1 -2
  382. package/project/flowr-analyzer-builder.d.ts +2 -3
  383. package/project/flowr-analyzer.d.ts +35 -12
  384. package/project/flowr-analyzer.js +18 -33
  385. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +15 -17
  386. package/project/plugins/file-plugins/files/flowr-namespace-file.js +57 -163
  387. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +2 -3
  388. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -3
  389. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -3
  390. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
  391. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -2
  392. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +5 -4
  393. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +1 -1
  394. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -1
  395. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +4 -3
  396. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -2
  397. package/project/plugins/package-version-plugins/package.d.ts +6 -5
  398. package/project/plugins/package-version-plugins/package.js +1 -1
  399. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -3
  400. package/project/sigdb/build.js +1 -1
  401. package/project/sigdb/decode.d.ts +8 -7
  402. package/project/sigdb/decode.js +1 -2
  403. package/project/sigdb/dict.d.ts +2 -1
  404. package/project/sigdb/dict.js +2 -2
  405. package/project/sigdb/index-format.d.ts +2 -1
  406. package/project/sigdb/manifest.d.ts +1 -1
  407. package/project/sigdb/memory-source.d.ts +18 -17
  408. package/project/sigdb/on-demand/package-sources.d.ts +4 -3
  409. package/project/sigdb/on-demand/recoverer.d.ts +2 -1
  410. package/project/sigdb/on-demand/remote-sources.d.ts +2 -1
  411. package/project/sigdb/reader.d.ts +85 -80
  412. package/project/sigdb/reader.js +0 -4
  413. package/project/sigdb/schema.d.ts +9 -8
  414. package/project/sigdb/signature-db.d.ts +6 -6
  415. package/queries/catalog/absint-query/absint-query-format.d.ts +1 -1
  416. package/queries/catalog/ambient-access-query/ambient-access-query-executor.d.ts +6 -0
  417. package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +50 -0
  418. package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +54 -0
  419. package/queries/catalog/ambient-access-query/ambient-access-query-format.js +45 -0
  420. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +2 -1
  421. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
  422. package/queries/catalog/call-graph-query/expand-library-internals.d.ts +3 -2
  423. package/queries/catalog/code-clones-query/code-clones-query-executor.d.ts +6 -0
  424. package/queries/catalog/code-clones-query/code-clones-query-executor.js +38 -0
  425. package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +54 -0
  426. package/queries/catalog/code-clones-query/code-clones-query-format.js +73 -0
  427. package/queries/catalog/config-query/config-query-format.d.ts +1 -1
  428. package/queries/catalog/config-query/config-query-format.js +4 -4
  429. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +3 -3
  430. package/queries/catalog/dependencies-query/data-flow.d.ts +5 -4
  431. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +5 -2
  432. package/queries/catalog/dependencies-query/dependencies-query-executor.js +11 -10
  433. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +4 -6
  434. package/queries/catalog/dependencies-query/dependencies-query-format.js +12 -12
  435. package/queries/catalog/dependencies-query/dependency-values.d.ts +9 -0
  436. package/queries/catalog/dependencies-query/dependency-values.js +13 -0
  437. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
  438. package/queries/catalog/dependencies-query/function-info/remote-functions.js +2 -2
  439. package/queries/catalog/dependencies-query/function-info/write-functions.js +8 -7
  440. package/queries/catalog/dependencies-query/implicit-echo.js +4 -2
  441. package/queries/catalog/dependencies-query/plot-description.d.ts +1 -1
  442. package/queries/catalog/dependencies-query/plot-description.js +2 -2
  443. package/queries/catalog/dice-query/dice-query-format.d.ts +2 -1
  444. package/queries/catalog/dice-query/dice-query-format.js +1 -0
  445. package/queries/catalog/does-call-query/does-call-query-executor.js +1 -2
  446. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -0
  447. package/queries/catalog/does-call-query/does-call-query-format.js +1 -0
  448. package/queries/catalog/files-query/files-query-format.d.ts +1 -1
  449. package/queries/catalog/function-info-query/function-info-query-format.d.ts +2 -1
  450. package/queries/catalog/function-info-query/function-origin.d.ts +3 -2
  451. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -3
  452. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +5 -4
  453. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -0
  454. package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -0
  455. package/queries/catalog/input-sources-query/input-sources-query-executor.js +7 -3
  456. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +9 -9
  457. package/queries/catalog/input-sources-query/simple-input-classifier.js +1 -1
  458. package/queries/catalog/linter-query/linter-query-executor.js +4 -1
  459. package/queries/catalog/linter-query/linter-query-format.d.ts +2 -2
  460. package/queries/catalog/linter-query/linter-query-format.js +16 -11
  461. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -0
  462. package/queries/catalog/origin-query/origin-query-format.js +1 -0
  463. package/queries/catalog/project-query/project-query-format.d.ts +2 -1
  464. package/queries/catalog/provenance-query/provenance-query-format.d.ts +1 -0
  465. package/queries/catalog/provenance-query/provenance-query-format.js +1 -0
  466. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -0
  467. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -0
  468. package/queries/catalog/signature-query/signature-query-executor.d.ts +10 -7
  469. package/queries/catalog/signature-query/signature-query-executor.js +14 -15
  470. package/queries/catalog/signature-query/signature-query-format.d.ts +21 -20
  471. package/queries/catalog/signature-query/signature-query-render.js +1 -1
  472. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  473. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +9 -5
  474. package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
  475. package/queries/catalog/taint-query/taint-query-format.d.ts +1 -1
  476. package/queries/query.d.ts +61 -10
  477. package/queries/query.js +59 -37
  478. package/r-bridge/data/data.d.ts +39 -28
  479. package/r-bridge/data/data.js +37 -28
  480. package/r-bridge/init.js +1 -1
  481. package/r-bridge/lang-4.x/ast/model/model.d.ts +10 -1
  482. package/r-bridge/lang-4.x/ast/model/model.js +30 -0
  483. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +21 -0
  484. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +25 -2
  485. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -1
  486. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -2
  487. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +2 -2
  488. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  489. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  490. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  491. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  492. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +4 -3
  493. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  494. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  495. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  496. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  497. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  498. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  499. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  500. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  501. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  502. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +5 -6
  503. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +2 -7
  504. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  505. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -2
  506. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +2 -2
  507. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  508. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -5
  509. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +7 -2
  510. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +14 -6
  511. package/r-bridge/lang-4.x/ast/model/processing/visitor.d.ts +1 -1
  512. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +2 -2
  513. package/r-bridge/lang-4.x/ast/model/type.d.ts +1 -1
  514. package/r-bridge/lang-4.x/ast/model/type.js +1 -1
  515. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -2
  516. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -2
  517. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  518. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +3 -2
  519. package/r-bridge/parser.d.ts +8 -2
  520. package/r-bridge/parser.js +6 -0
  521. package/r-bridge/shell-executor.d.ts +2 -2
  522. package/r-bridge/shell-executor.js +3 -2
  523. package/r-bridge/shell.d.ts +2 -2
  524. package/r-bridge/shell.js +3 -2
  525. package/reconstruct/auto-select/magic-comments.js +1 -1
  526. package/reconstruct/reconstruct.d.ts +0 -5
  527. package/reconstruct/reconstruct.js +6 -5
  528. package/search/flowr-search-builder.d.ts +14 -0
  529. package/search/flowr-search-builder.js +7 -0
  530. package/search/flowr-search-executor.js +2 -2
  531. package/search/flowr-search-filters.js +10 -11
  532. package/search/flowr-search.js +1 -1
  533. package/search/search-executor/search-enrichers.d.ts +2 -0
  534. package/search/search-executor/search-enrichers.js +6 -1
  535. package/search/search-executor/search-generators.d.ts +2 -3
  536. package/search/search-executor/search-generators.js +18 -14
  537. package/search/search-executor/search-mappers.js +1 -1
  538. package/search/search-executor/search-transformer.d.ts +2 -2
  539. package/search/search-executor/search-transformer.js +6 -6
  540. package/search/search-logger.d.ts +1 -0
  541. package/search/search-logger.js +6 -0
  542. package/slicing/criterion/parse.d.ts +2 -1
  543. package/slicing/criterion/parse.js +2 -1
  544. package/slicing/static/removal-slice.js +2 -1
  545. package/slicing/static/slice-call.d.ts +30 -4
  546. package/slicing/static/slice-call.js +74 -9
  547. package/slicing/static/slicer-types.d.ts +2 -1
  548. package/slicing/static/static-slicer.js +66 -11
  549. package/slicing/static/visiting-queue.d.ts +2 -0
  550. package/slicing/static/visiting-queue.js +4 -0
  551. package/taint-analysis/builder/report-template.d.ts +3 -3
  552. package/util/arg-matching.d.ts +1 -1
  553. package/util/collections/relation.d.ts +23 -0
  554. package/util/collections/relation.js +63 -0
  555. package/util/fixpoint.d.ts +65 -0
  556. package/util/fixpoint.js +216 -0
  557. package/util/flowr-version.d.ts +1 -1
  558. package/util/flowr-version.js +2 -2
  559. package/util/json.d.ts +4 -0
  560. package/util/json.js +12 -3
  561. package/util/mermaid/cfg.js +1 -2
  562. package/util/mermaid/dfg.d.ts +1 -1
  563. package/util/mermaid/dfg.js +1 -1
  564. package/util/mermaid/mermaid.d.ts +2 -1
  565. package/util/monoid.d.ts +26 -0
  566. package/util/monoid.js +31 -0
  567. package/util/prefix.d.ts +1 -1
  568. package/util/r-base-packages.d.ts +10 -7
  569. package/util/r-base-packages.js +11 -6
  570. package/util/r-package-urls.d.ts +10 -9
  571. package/util/r-value.js +2 -1
  572. package/util/r-version-order.d.ts +2 -0
  573. package/util/r-version-order.js +19 -0
  574. package/util/r-version.d.ts +2 -1
  575. package/util/r-version.js +2 -14
  576. package/util/range.d.ts +38 -29
  577. package/util/range.js +10 -5
  578. package/util/simple-df/dfg-ascii.js +2 -2
  579. package/util/text/ansi.d.ts +13 -9
  580. package/util/text/ansi.js +4 -6
  581. package/util/text/strings.d.ts +10 -3
  582. package/util/text/strings.js +10 -1
  583. package/util/version.d.ts +1 -1
  584. package/util/version.js +2 -1
  585. package/dataflow/environments/default-builtin-config.d.ts +0 -8856
  586. package/dataflow/environments/default-builtin-config.js +0 -1735
  587. package/r-bridge/lang-4.x/ast/model/operators.d.ts +0 -33
  588. package/r-bridge/lang-4.x/ast/model/operators.js +0 -54
  589. package/taint-analysis/eval/eval.d.ts +0 -1
  590. package/taint-analysis/eval/eval.js +0 -124
  591. package/taint-analysis/eval/instrumentation.d.ts +0 -59
  592. 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,78 +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;
317
- if (done.has(at(cid, call))) {
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);
450
+ /* without a call nothing restricts the walk, so that visit covers those under any call */
451
+ if (calls === undefined) {
452
+ done.set(cid, new Set([call]));
453
+ }
454
+ else if (calls.has(call) || calls.has(undefined)) {
318
455
  continue;
319
456
  }
320
- done.add(at(cid, call));
321
- visited.add(at(cid, call));
322
- if (node_id_1.NodeId.isBuiltIn(cid)) {
323
- builtIns.add(cid);
324
- continue;
457
+ else {
458
+ calls.add(call);
325
459
  }
326
- const vertex = dataflowGraph.getVertex(cid);
327
- if (vertex === undefined) {
460
+ const end = walkLinkedDefinitions(dataflowGraph, cid, viaAccess, call, scopes, next);
461
+ if (end === undefined) {
328
462
  continue;
329
463
  }
330
- else if (vertex.subflow !== undefined) {
331
- result.add(vertex);
332
- continue;
464
+ else if (node_id_1.NodeId.isBuiltIn(end)) {
465
+ builtIns.add(end);
333
466
  }
334
- const nextViaAccess = viaAccess || vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access);
335
- const isSkipType = vertex_2.DfgVertex.isFunctionCall(vertex) || (vertex_2.DfgVertex.isVariableDefinition(vertex) && vertex.par && !nextViaAccess);
336
- let hasReturnEdge = false;
337
- let followTargets;
338
- /* a list handed on as a whole (a loop, an apply) yields its entries, an access the entry it names */
339
- 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;
340
- /* only a call into a body binds parameters, a built-in hands back what it is given in the same context */
341
- const returnedTo = vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex.onlyBuiltin ? cid : call;
342
- for (const [target, e] of dataflowGraph.edgesFrom(cid)) {
343
- if (edge_1.DfEdge.includesType(e, handedBack)) {
344
- hasReturnEdge = true;
345
- if (!visited.has(at(target, returnedTo))) {
346
- potential.push([target, nextViaAccess, returnedTo]);
347
- }
348
- }
349
- else if (!isSkipType && !hasReturnEdge && edge_1.DfEdge.includesType(e, ValueFlowBits)) {
350
- (followTargets ??= []).push([target, edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall)]);
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));
351
516
  }
352
517
  }
353
- if (!hasReturnEdge && followTargets) {
354
- /* a parameter the call binds holds only what that call passes, the walk then goes on in the caller */
355
- const passed = call === undefined ? undefined : new Set(df_helper_1.Dataflow.targetsOf(dataflowGraph, call, edge_1.EdgeType.Argument));
356
- const bound = followTargets.some(([target, onCall]) => onCall && passed?.has(target));
357
- for (const [target, onCall] of followTargets) {
358
- const next = onCall ? undefined : call;
359
- if ((!bound || !onCall || passed?.has(target)) && !visited.has(at(target, next))) {
360
- 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));
361
580
  }
362
581
  }
363
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;
364
608
  }
365
- return [result, builtIns];
366
609
  }
610
+ exports.LinkedFunctionResolver = LinkedFunctionResolver;
367
611
  /**
368
- * Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and
369
- * 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.
370
613
  * @useInstead {@link FunctionSemantics.call.quoted.evaluateIn}
371
614
  */
372
615
  function linkExpressionIn(graph, expr, environment, idMap) {
@@ -405,14 +648,10 @@ function linkCallToDefinitions(graph, callId, definitions, idMap) {
405
648
  }
406
649
  }
407
650
  }
408
- /**
409
- * Links a set of read variables to definitions in `environmentInformation`; each reference that cannot be linked (or
410
- * links to built-ins only) is added to `givenInputs` (marked maybe if `maybeForRemaining`), and the extended list is returned.
411
- * @param alsoFrom - a node that reads every definition found as well
412
- */
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. */
413
652
  function linkInputs(referencesToLinkAgainstEnvironment, environmentInformation, givenInputs, graph, maybeForRemaining, alsoFrom) {
414
653
  for (const bodyInput of referencesToLinkAgainstEnvironment) {
415
- 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;
416
655
  if (probableTarget === undefined) {
417
656
  if (maybeForRemaining) {
418
657
  bodyInput.cds ??= [];
@@ -433,22 +672,21 @@ function linkInputs(referencesToLinkAgainstEnvironment, environmentInformation,
433
672
  }
434
673
  return givenInputs;
435
674
  }
436
- /**
437
- * A loop variable read before its within-loop redefinition gets a maybe marker to that def (e.g. `x_2` may read the
438
- * prior iteration's `x_1` in `for(...) { x_1 <- x_2 + 1 }`); with `environment`, this uses all defs live at loop exit.
439
- */
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}). */
440
676
  function linkCircularRedefinitionsWithinALoop(graph, openIns, outgoing, environment) {
441
677
  if (environment !== undefined) {
442
678
  const outgoingIds = new Set(outgoing.map(o => o.nodeId));
443
679
  for (const [name, targets] of openIns.entries()) {
444
680
  for (const def of environment.current.memory.get(identifier_1.Identifier.getName(name)) ?? []) {
445
- 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))) {
446
683
  for (const target of targets) {
447
684
  graph.addEdge(target.nodeId, def.nodeId, edge_1.EdgeType.Reads);
448
685
  }
449
686
  }
450
687
  }
451
688
  }
689
+ linkLoopCarriedCalls(graph, environment, outgoingIds, new Set(outgoing.map(o => identifier_1.Identifier.getName(o.name))));
452
690
  return;
453
691
  }
454
692
  /* fallback: keep only the last definition per identifier (used when no environment is available) */
@@ -468,6 +706,76 @@ function linkCircularRedefinitionsWithinALoop(graph, openIns, outgoing, environm
468
706
  }
469
707
  }
470
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
+ }
471
779
  function addControlDependency(holder, cd) {
472
780
  if (holder.cds?.some(c => c.id === cd.id)) {
473
781
  return false;
@@ -475,9 +783,7 @@ function addControlDependency(holder, cd) {
475
783
  holder.cds = [...holder.cds ?? [], cd];
476
784
  return true;
477
785
  }
478
- /**
479
- * Reapplies the loop exit points' control dependencies to the given identifier references.
480
- */
786
+ /** Reapplies the loop exit points' control dependencies to the given identifier references. */
481
787
  function reapplyLoopExitPoints(exits, references, graph) {
482
788
  const exitCds = exits.flatMap(e => e.cds?.map(info_1.negateControlDependency))
483
789
  .filter(assert_1.isNotUndefined)
@@ -505,10 +811,7 @@ function reapplyLoopExitPoints(exits, references, graph) {
505
811
  */
506
812
  exports.ClosureRefs = {
507
813
  name: 'ClosureRefs',
508
- /**
509
- * Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`,
510
- * links what resolves, and leaves only the references that stay open.
511
- */
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. */
512
815
  resolveOpenIngoing(graph, callId, definition, environment) {
513
816
  definition.subflow.in = linkInputs(definition.subflow.in, environment, [], graph, false, callId);
514
817
  }
@@ -524,11 +827,23 @@ function accessedFieldName(fieldNode, treatIndicesAsString) {
524
827
  return r_number_1.RNumber.is(fieldNode) && !fieldNode.content.complexNumber && Number.isInteger(fieldNode.content.num) && fieldNode.content.num > 0
525
828
  ? String(fieldNode.content.num) : undefined;
526
829
  }
527
- /**
528
- * Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns,
529
- * and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`.
530
- */
531
- 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);
532
847
  for (const fd of fieldDefs ?? []) {
533
848
  graph.addEdge(accessId, fd.nodeId, edge_1.EdgeType.Reads);
534
849
  if (fd.definedAt !== undefined && fd.definedAt !== fd.nodeId) {
@@ -539,14 +854,18 @@ function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions) {
539
854
  }
540
855
  }
541
856
  }
857
+ const AssignFormals = ['x', 'value', 'pos', 'envir', 'inherits', 'immediate'];
542
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)`. */
543
859
  function fieldAssignmentOf(readId, idMap) {
544
860
  const read = idMap.get(readId);
545
861
  const access = read === undefined ? undefined : model_1.RNode.directParent(read, idMap);
546
862
  /* `assign("f", v, envir = x)` writes into `x` as well */
547
863
  const call = access === undefined ? undefined : model_1.RNode.directParent(access, idMap);
548
- if (r_function_call_1.RFunctionCall.isNamed(call, 'assign') && call.arguments.indexOf(access) >= 2) {
549
- 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
+ }
550
869
  }
551
870
  if (!r_access_1.RAccess.is(access) || access.accessed.info.id !== readId) {
552
871
  return undefined;
@@ -561,18 +880,15 @@ function fieldAssignmentOf(readId, idMap) {
561
880
  /* the replacement call `$<-` carries the id of the access it writes through */
562
881
  return r_binary_op_1.RBinaryOp.is(assign) && assign.lhs.info.id === target.info.id && /^(<<?-|=)$/.test(assign.operator) ? access.info.id : undefined;
563
882
  }
564
- /**
565
- * An access `x$f` written where `x` was still open reads the field of whatever `x` is bound to once that binding is
566
- * known, so binding the read at `readId` to a definition holding `envState` links the access to that field.
567
- */
568
- 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) {
569
885
  const read = idMap.get(readId);
570
886
  const access = read === undefined ? undefined : model_1.RNode.directParent(read, idMap);
571
887
  if (!r_access_1.RAccess.is(access) || access.accessed.info.id !== readId) {
572
888
  return;
573
889
  }
574
890
  const fieldName = accessedFieldName(r_argument_1.RArgument.valueOf(access.access[0]), r_access_1.RAccess.isNamed(access));
575
- 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);
576
892
  }
577
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. */
578
894
  function factoryOf(closure, graph, known, idMap) {
@@ -589,7 +905,7 @@ function factoryOf(closure, graph, known, idMap) {
589
905
  continue;
590
906
  }
591
907
  else if (vertex_2.DfgVertex.isFunctionDefinition(vertex) || (vertex_2.DfgVertex.isFunctionCall(vertex) && (!vertex.onlyBuiltin || graph.unknownSideEffects.has(node_id_1.NodeId.normalize(node))))
592
- || vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.SuperAssignment)) {
908
+ || df_helper_1.Dataflow.superAssigns(graph, node)) {
593
909
  return undefined;
594
910
  }
595
911
  else if (vertex_2.DfgVertex.isVariableDefinition(vertex)) {
@@ -606,24 +922,11 @@ function instancesOf(call, closure, factory, graph) {
606
922
  if (!df_helper_1.Dataflow.hasEdge(graph, call, closure, edge_1.EdgeType.Calls)) {
607
923
  return undefined;
608
924
  }
609
- const instances = [];
610
- for (const [binding, edge] of graph.edgesFrom(call)) {
611
- 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)) {
612
- continue;
613
- }
614
- /* the binding the call reads holds what one call of the factory created, and nothing else */
615
- const isCallOfAFunction = (target) => {
616
- const vertex = graph.getVertex(target);
617
- return vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Assignment);
618
- };
619
- const created = vertex_2.DfgVertex.isVariableDefinition(graph.getVertex(binding)) ? df_helper_1.Dataflow.targetsOf(graph, binding, edge_1.EdgeType.DefinedBy).filter(isCallOfAFunction) : [];
620
- const callees = created.length === 1 ? df_helper_1.Dataflow.targetsOf(graph, created[0], edge_1.EdgeType.Calls) : [];
621
- if (callees.length !== 1 || callees[0] !== factory) {
622
- return undefined;
623
- }
624
- instances.push(created[0]);
625
- }
626
- 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;
627
930
  }
628
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. */
629
932
  function separateClosureInstances(graph, known) {
@@ -633,7 +936,7 @@ function separateClosureInstances(graph, known) {
633
936
  }
634
937
  for (const [closure, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
635
938
  /* only a closure writing with `<<-` can share state */
636
- 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();
637
940
  const found = superAssignments.length === 0 ? undefined : factoryOf(vertex, graph, known, idMap);
638
941
  if (found === undefined) {
639
942
  continue;