@eagleoutice/flowr 2.17.4 → 2.17.6

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