@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,16 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.computeCallGraphSummaries = computeCallGraphSummaries;
4
+ exports.foldCallGraph = foldCallGraph;
5
+ exports.linkPromisesToWritesOfCall = linkPromisesToWritesOfCall;
6
+ exports.linkStateWritesOfForcedPromises = linkStateWritesOfForcedPromises;
7
+ exports.linkUsesOfScopedInstances = linkUsesOfScopedInstances;
8
+ exports.linkStatementsAfterCallsOfClosures = linkStatementsAfterCallsOfClosures;
9
+ exports.settleConditionalWritesOfCalls = settleConditionalWritesOfCalls;
4
10
  exports.linkMaterializedExportsToLoaders = linkMaterializedExportsToLoaders;
5
11
  exports.reResolveOpenReferences = reResolveOpenReferences;
6
- exports.ambientWritesOfFunctions = ambientWritesOfFunctions;
12
+ exports.ambientAccessOfFunctions = ambientAccessOfFunctions;
13
+ exports.ambientAccessOf = ambientAccessOf;
7
14
  exports.propagateTransitiveSideEffects = propagateTransitiveSideEffects;
15
+ const graph_1 = require("../../../../../graph/graph");
8
16
  const edge_1 = require("../../../../../graph/edge");
9
17
  const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
10
18
  const environment_1 = require("../../../../../environments/environment");
11
19
  const built_in_library_1 = require("./built-in-library");
12
20
  const frame_memory_1 = require("../../../../../environments/frame-memory");
13
21
  const vertex_1 = require("../../../../../graph/vertex");
22
+ const model_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/model");
23
+ const r_project_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-project");
14
24
  const program_order_1 = require("../../../../program-order");
15
25
  const resolve_helper_1 = require("../../../../../environments/resolve-helper");
16
26
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
@@ -19,43 +29,564 @@ const built_in_ambient_state_1 = require("./built-in-ambient-state");
19
29
  const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
20
30
  const df_helper_1 = require("../../../../../graph/df-helper");
21
31
  const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
32
+ const ambient_access_1 = require("../../../../../graph/ambient-access");
33
+ const query_fn_props_1 = require("../../../../../environments/query-fn-props");
34
+ const built_in_props_1 = require("../../../../../environments/built-in-props");
35
+ const function_semantics_1 = require("../../../../../fn/function-semantics");
36
+ const built_in_props_2 = require("../../../../../environments/built-in-props");
37
+ const logic_1 = require("../../../../../../util/logic");
22
38
  const info_1 = require("../../../../../info");
39
+ const fixpoint_1 = require("../../../../../../util/fixpoint");
40
+ const monoid_1 = require("../../../../../../util/monoid");
41
+ const relation_1 = require("../../../../../../util/collections/relation");
42
+ const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
43
+ const r_expression_list_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
44
+ const r_binary_op_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
45
+ const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
46
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
47
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
48
+ const r_value_1 = require("../../../../../eval/values/r-value");
49
+ const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
50
+ const removal_marker_1 = require("../../../../../environments/removal-marker");
51
+ const r_base_packages_1 = require("../../../../../../util/r-base-packages");
23
52
  /**
24
53
  * Computes, for every function-definition vertex `F`, `summary(F) = own(F)` unioned with `summary(G)` over every transitive callee `G`.
25
- * @param graph - the fully linked dataflow graph
26
- * @param own - the effects a single function definition produces itself (its contribution to the summary)
27
- * @returns a map from each function-definition vertex to its transitive-effect summary
28
54
  * @useInstead {@link Dataflow.sideEffects.callGraphSummaries}
29
55
  */
30
56
  function computeCallGraphSummaries(graph, own) {
31
- const summary = new Map();
32
- const callees = new Map();
33
- for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
34
- summary.set(id, new Set(own(id, vertex)));
35
- callees.set(id, df_helper_1.Dataflow.callsIn(vertex, graph).flatMap(([node]) => df_helper_1.Dataflow.calleeIdsOf(graph, node)).toArray());
57
+ return foldCallGraph(graph, monoid_1.Monoid.set(), (id, fdef) => new Set(own(id, fdef)));
58
+ }
59
+ /**
60
+ * Computes, for every function-definition vertex `F`, what `F` and every function it transitively calls contribute together.
61
+ * @useInstead {@link Dataflow.sideEffects.foldCallGraph}
62
+ */
63
+ function foldCallGraph(graph, monoid, own) {
64
+ const summaries = new fixpoint_1.ReachSummaries(id => {
65
+ const vertex = graph.getVertex(id);
66
+ if (!vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
67
+ return [];
68
+ }
69
+ /* an exit hook (`on.exit(expr)`) runs as part of the function */
70
+ return df_helper_1.Dataflow.callsIn(vertex, graph).flatMap(([node]) => df_helper_1.Dataflow.calleeIdsOf(graph, node)).toArray().concat(vertex.subflow.hooks.map(h => h.id));
71
+ }, id => {
72
+ const vertex = graph.getVertex(id);
73
+ return vertex_1.DfgVertex.isFunctionDefinition(vertex) ? own(id, vertex) : undefined;
74
+ }, monoid);
75
+ return new Map(graph.verticesOfType(vertex_1.VertexType.FunctionDefinition).map(([id]) => [id, summaries.of(id)]));
76
+ }
77
+ /** A promise reads the state at the point it is forced, which is wherever the callee first needs it: after the call wrote what the promise reads (`g <- function(b) { x <<- 1; b }; g(x)`), after another argument did (`f(n, n <- 4)`), or, once a closure captured its parameter, after the call returned (`mk <- function(a) function() a`). */
78
+ function linkPromisesToWritesOfCall(graph, ctx) {
79
+ const idMap = graph.idMap;
80
+ if (idMap === undefined) {
81
+ return;
82
+ }
83
+ const nameOf = (id) => {
84
+ const node = idMap.get(id);
85
+ return r_symbol_1.RSymbol.is(node) ? identifier_1.Identifier.getName(node.content) : undefined;
86
+ };
87
+ let outlives;
88
+ let later;
89
+ let forcing;
90
+ let order;
91
+ let functions;
92
+ /* the global state a closure changes while it runs, which a promise it forces may see */
93
+ const changedBy = (fns) => {
94
+ functions ??= ambientAccessOfFunctions(graph);
95
+ return monoid_1.Monoid.fold(ambient_access_1.AmbientAccess.monoid, fns.map(fn => functions?.get(fn) ?? ambient_access_1.AmbientAccess.empty));
96
+ };
97
+ for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
98
+ /* a function of a package flowR has no body for forces its arguments as its signature states, see `keptPromisesOfPackageCall` */
99
+ const kept = df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls).some(t => !node_id_1.NodeId.isBuiltIn(t) && vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)))
100
+ ? undefined : keptPromisesOfPackageCall(graph, vertex, ctx);
101
+ if (kept === false) {
102
+ continue;
103
+ }
104
+ const args = vertex.args.filter(graph_1.FunctionArgument.isNotEmpty).map(a => ({ ids: new Set(model_1.RNode.collectAllIds(idMap.get(a.nodeId))), at: a.nodeId }));
105
+ /* what each write is named, and the argument it is written in, if any */
106
+ const writes = new Map();
107
+ const write = (name, def, within) => {
108
+ if (name !== undefined) {
109
+ writes.set(name, [...writes.get(name) ?? [], [def, within]]);
110
+ }
111
+ };
112
+ for (const def of df_helper_1.Dataflow.sourcesOf(graph, id, edge_1.EdgeType.SideEffectOnCall)) {
113
+ write(node_id_1.NodeId.isBuiltIn(def) ? undefined : nameOf(def), def);
114
+ }
115
+ for (const { ids } of args) {
116
+ for (const node of ids) {
117
+ write(vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(node)) ? nameOf(node) : undefined, node, ids);
118
+ }
119
+ }
120
+ const closures = kept === undefined ? df_helper_1.Dataflow.calleeIdsOf(graph, id).filter(t => !node_id_1.NodeId.isBuiltIn(t)) : [];
121
+ for (const { ids } of closures.length > 0 ? args : []) {
122
+ linkAmbientReadsToWrites(graph, ids, () => changedBy(closures));
123
+ }
124
+ for (const { ids, at } of args) {
125
+ /* whether the promise may be forced after the call, asked only once a read has a later definition to see */
126
+ let late;
127
+ const outlived = () => {
128
+ /* resolving the condition of each branch to a constant would cost a value resolution per branch */
129
+ forcing ??= function_semantics_1.FunctionSemantics.promiseForcing(graph, { ctx, constantBranches: false });
130
+ outlives ??= promiseOutlivesCall(graph, idMap, forcing);
131
+ late ??= kept === undefined ? df_helper_1.Dataflow.targetsOf(graph, at, edge_1.EdgeType.DefinesOnCall).some(outlives) && forcing(id, at) !== logic_1.Ternary.Always : kept.has(at);
132
+ return late;
133
+ };
134
+ for (const node of ids) {
135
+ const name = vertex_1.DfgVertex.isUse(graph.getVertex(node)) ? nameOf(node) : undefined;
136
+ if (name === undefined) {
137
+ continue;
138
+ }
139
+ for (const [def, within] of writes.get(name) ?? []) {
140
+ if (within !== ids) {
141
+ graph.addEdge(node, def, edge_1.EdgeType.Reads);
142
+ }
143
+ }
144
+ later ??= definitionsAfter(graph, idMap);
145
+ const after = later(id, name);
146
+ if (after.length > 0 && outlived()) {
147
+ for (const def of after) {
148
+ graph.addEdge(node, def, edge_1.EdgeType.Reads);
149
+ }
150
+ }
151
+ (order ??= new PromiseOrder(graph, idMap)).settle(id, at, node, name);
152
+ }
153
+ }
36
154
  }
37
- /* pull each callee's summary, its callers are revisited whenever a function grew */
38
- df_helper_1.Dataflow.propagateToFixpoint(summary.keys(), callees, id => {
39
- const effects = summary.get(id);
40
- const before = effects.size;
41
- for (const callee of callees.get(id) ?? []) {
42
- for (const effect of summary.get(callee) ?? []) {
43
- effects.add(effect);
155
+ for (const [fn] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
156
+ const definition = idMap.get(fn);
157
+ for (const parameter of r_function_definition_1.RFunctionDefinition.is(definition) ? definition.parameters : []) {
158
+ if (parameter.defaultValue !== undefined) {
159
+ linkAmbientReadsToWrites(graph, model_1.RNode.collectAllIds(parameter.defaultValue), () => changedBy([fn]));
160
+ }
161
+ for (const read of parameter.defaultValue === undefined ? [] : model_1.RNode.collectAllIds(parameter.defaultValue)) {
162
+ const name = vertex_1.DfgVertex.isUse(graph.getVertex(read)) ? nameOf(read) : undefined;
163
+ if (name !== undefined) {
164
+ (order ??= new PromiseOrder(graph, idMap)).settleDefault(fn, parameter.name.info.id, read, name);
165
+ }
44
166
  }
45
167
  }
46
- return effects.size > before;
47
- });
48
- return summary;
168
+ }
49
169
  }
50
- /**
51
- * Links every materialized package-export vertex back to the `library()`/`use()` call that loaded it,
52
- * reading the loading call from the export binding's `definedAt` in the (final, authoritative) environment.
53
- * Only vertices created on demand (exports actually referenced) get an edge, keeping the graph small.
54
- */
170
+ /** A promise (`delayedAssign`) forced where its name is not read at the top level, by a call running a closure that reads it or by an access of an environment holding it, changes the state at that point, which later code reading the state sees. */
171
+ function linkStateWritesOfForcedPromises(graph) {
172
+ let readers;
173
+ for (const [id] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
174
+ const binding = function_semantics_1.FunctionSemantics.call.quoted.promisedBinding(graph, id);
175
+ const promise = binding === undefined ? [] : df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.NonStandardEvaluation);
176
+ const calls = promise.flatMap(p => [...model_1.RNode.collectAllIds(graph.idMap?.get(p))]).filter(c => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(c)));
177
+ /* the calls of the promise changing the state, which run where it is forced even if its value goes unused */
178
+ const writers = calls.filter(c => ambientAccessOf(graph, [c])[ambient_access_1.AmbientAccessKind.Write].size > 0);
179
+ const written = writers.length === 0 ? [] : [...ambientAccessOf(graph, writers)[ambient_access_1.AmbientAccessKind.Write].keys()];
180
+ if (binding === undefined || written.length === 0) {
181
+ continue;
182
+ }
183
+ readers ??= new Map([...graph.ambientAccessIds()].map(r => [r, new Set(graph.ambientAccessOf(r)?.[ambient_access_1.AmbientAccessKind.Read].keys())]));
184
+ for (const site of function_semantics_1.FunctionSemantics.promiseForcingPoints(binding, graph)) {
185
+ for (const writer of writers) {
186
+ graph.addEdge(site, writer, edge_1.EdgeType.Reads);
187
+ }
188
+ const statement = program_order_1.ProgramOrder.runsOnceAt(site, graph);
189
+ if (statement === undefined || written.every(name => graph.ambientAccessOf(site)?.[ambient_access_1.AmbientAccessKind.Write].has(name))) {
190
+ continue;
191
+ }
192
+ for (const expr of promise) {
193
+ graph.addEdge(site, expr, edge_1.EdgeType.Reads);
194
+ }
195
+ for (const [reader, reads] of readers) {
196
+ if (written.some(name => reads.has(name)) && program_order_1.ProgramOrder.offset(reader, statement, graph) > 0) {
197
+ graph.addEdge(reader, site, edge_1.EdgeType.Reads);
198
+ }
199
+ }
200
+ }
201
+ }
202
+ }
203
+ /** The families of instances a scope may open one of for its code, see {@link linkUsesOfScopedInstances}. */
204
+ const ScopedInstances = [ambient_state_name_1.OutputSinks, ambient_state_name_1.GraphicsDevices];
205
+ /** A scope opening an instance for its code (`capture.output`, `with_png`) ends it afterward, so it reads every use of it within its arguments, in the functions they call as well (`capture.output(f())` reads what `f` prints). */
206
+ function linkUsesOfScopedInstances(graph) {
207
+ const idMap = graph.idMap;
208
+ if (idMap === undefined) {
209
+ return;
210
+ }
211
+ let functions;
212
+ for (const id of graph.ambientAccessIds()) {
213
+ /* a scope changes the states of the instance it opens in its own frame only */
214
+ const local = graph.ambientAccessOf(id)?.[ambient_access_1.AmbientAccessKind.Local];
215
+ const scoped = ScopedInstances.filter(family => local?.has(family.used) && local.has(family.opened));
216
+ const vertex = graph.getVertex(id);
217
+ if (scoped.length === 0 || !vertex_1.DfgVertex.isFunctionCall(vertex)) {
218
+ continue;
219
+ }
220
+ const code = vertex.args.filter(graph_1.FunctionArgument.isNotEmpty).flatMap(a => [...model_1.RNode.collectAllIds(idMap.get(a.nodeId))]);
221
+ functions ??= ambientAccessOfFunctions(graph);
222
+ const writes = ambientAccessOf(graph, code, { functions })[ambient_access_1.AmbientAccessKind.Write];
223
+ for (const writer of scoped.flatMap(family => [...writes.get(family.used) ?? []])) {
224
+ if (writer !== id) {
225
+ graph.addEdge(id, writer, edge_1.EdgeType.Reads);
226
+ }
227
+ }
228
+ }
229
+ }
230
+ /** What a body runs after a call of a closure within it sees the global state that closure changes, which the body, processed before it learned of the callee, does not know of: `f <- function() { g(); print(pi) }` with `g` setting the `digits` option. */
231
+ function linkStatementsAfterCallsOfClosures(graph) {
232
+ const idMap = graph.idMap;
233
+ if (idMap === undefined) {
234
+ return;
235
+ }
236
+ let functions;
237
+ for (const [id] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
238
+ const closures = graph.isRoot(id) ? [] : df_helper_1.Dataflow.calleeIdsOf(graph, id).filter(t => !node_id_1.NodeId.isBuiltIn(t) && vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)));
239
+ const after = closures.length === 0 ? undefined : runsAfterWithinFunction(id, idMap);
240
+ if (after === undefined || after.size === 0) {
241
+ continue;
242
+ }
243
+ const changed = () => {
244
+ functions ??= ambientAccessOfFunctions(graph);
245
+ return monoid_1.Monoid.fold(ambient_access_1.AmbientAccess.monoid, closures.map(fn => functions?.get(fn) ?? ambient_access_1.AmbientAccess.empty));
246
+ };
247
+ for (const reader of linkAmbientReadsToWrites(graph, after, changed)) {
248
+ /* the reader sees the write only as the call runs it */
249
+ graph.addEdge(reader, id, edge_1.EdgeType.Reads);
250
+ }
251
+ }
252
+ }
253
+ /** The nodes the function holding `id` may run after it: the later statements of each block around it, and all of a loop around it. */
254
+ function runsAfterWithinFunction(id, idMap) {
255
+ const after = new Set();
256
+ const add = (nodes) => nodes.forEach(n => model_1.RNode.collectAllIdsWithStop(n, r_function_definition_1.RFunctionDefinition.is).forEach(i => after.add(i)));
257
+ let node = idMap.get(id);
258
+ for (let parent = node && model_1.RNode.directParent(node, idMap); parent !== undefined && node !== undefined && !r_function_definition_1.RFunctionDefinition.is(parent); parent = model_1.RNode.directParent(parent, idMap)) {
259
+ if (r_expression_list_1.RExpressionList.is(parent)) {
260
+ add(parent.children.slice(parent.children.indexOf(node) + 1));
261
+ }
262
+ else if (model_1.RLoopConstructs.is(parent)) {
263
+ add([parent]);
264
+ }
265
+ node = parent;
266
+ }
267
+ return after;
268
+ }
269
+ /** The calls among `ids` of a promise read the global state where it is forced, after what the function forcing it may have `changed` (`function(code) { set.seed(1); code }`); returns the readers so linked. */
270
+ function linkAmbientReadsToWrites(graph, ids, changed) {
271
+ let access;
272
+ const readers = [];
273
+ for (const node of ids) {
274
+ for (const name of graph.ambientAccessOf(node)?.[ambient_access_1.AmbientAccessKind.Read].keys() ?? []) {
275
+ access ??= changed();
276
+ for (const kind of [ambient_access_1.AmbientAccessKind.Write, ambient_access_1.AmbientAccessKind.Local, ambient_access_1.AmbientAccessKind.Assumed]) {
277
+ for (const writer of access[kind].get(name) ?? []) {
278
+ if (!ids.has(writer)) {
279
+ graph.addEdge(node, writer, edge_1.EdgeType.Reads);
280
+ readers.push(node);
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }
286
+ return readers;
287
+ }
288
+ /** Whether the branches of `fn` a node stands under are taken in the frame `call` makes: a parameter holds what that call hands it, so a condition on it may be constant there. */
289
+ function branchesTakenIn(conditions, fn, call, graph, ctx) {
290
+ let result = logic_1.Ternary.Always;
291
+ for (const cd of conditions) {
292
+ const branch = graph.getVertex(cd.id);
293
+ const condition = vertex_1.DfgVertex.isFunctionCall(branch) && vertex_1.DfgVertex.hasOrigin(branch, built_in_proc_name_1.BuiltInProcName.IfThenElse) ? branch.args[0] : undefined;
294
+ const values = condition === undefined || condition === r_function_call_1.EmptyArgument || cd.when === undefined ? undefined
295
+ : node_value_1.NodeValue.setOf(condition.nodeId, resolve_helper_1.Resolve.info(graph, ctx), { callContext: new Map([[fn, call]]) })?.elements.map(r_value_1.RValue.truthOf);
296
+ const outcome = values !== undefined && values.length > 0 && values.every(v => v !== undefined && v === values[0]) ? values[0] : undefined;
297
+ if (outcome === undefined) {
298
+ result = logic_1.Ternary.Maybe;
299
+ }
300
+ else if (outcome !== cd.when) {
301
+ return logic_1.Ternary.Never;
302
+ }
303
+ }
304
+ return result;
305
+ }
306
+ /** Whether every reference to the definition is a call of it among `calls`: it is bound to names (`f <- function...`) only these calls read, so no other way leads into it. */
307
+ function onlyCalledBy(fn, calls, graph) {
308
+ const binds = (source) => vertex_1.DfgVertex.hasOrigin(graph.getVertex(source), built_in_proc_name_1.BuiltInProcName.Assignment);
309
+ const holders = [];
310
+ for (const [source, edge] of graph.edgesTo(fn)) {
311
+ if (edge_1.DfEdge.isOnlyControlFlow(edge) || binds(source) || (edge_1.DfEdge.isOnlyType(edge, edge_1.EdgeType.Calls) && calls.has(source))) {
312
+ continue;
313
+ }
314
+ else if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedBy) && vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(source))) {
315
+ holders.push(source);
316
+ }
317
+ else {
318
+ return false;
319
+ }
320
+ }
321
+ return holders.every(holder => graph.edgesTo(holder).entries().every(([source, edge]) => edge_1.DfEdge.isOnlyControlFlow(edge) || binds(source) || calls.has(source)));
322
+ }
323
+ /** Settles what a function writes beyond its frame (`<<-`) under branches of its own, once the calls passing the write on are linked: bound to what a call hands it, a parameter may make a branch constant (`f <- function(go) if(go) n <<- 5; f(FALSE)`). */
324
+ function settleConditionalWritesOfCalls(graph, ctx) {
325
+ const idMap = graph.idMap;
326
+ if (idMap === undefined) {
327
+ return;
328
+ }
329
+ for (const [write, vertex] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
330
+ const calls = df_helper_1.Dataflow.targetsOf(graph, write, edge_1.EdgeType.SideEffectOnCall);
331
+ const fn = calls.length === 0 ? undefined : model_1.RNode.strictlyEnclosingFunction(write, idMap);
332
+ const conditions = fn === undefined ? [] : info_1.ControlDependency.minus(vertex.cds ?? [], graph.getVertex(fn)?.cds ?? []);
333
+ if (fn === undefined || conditions.length === 0 || calls.some(c => !df_helper_1.Dataflow.hasEdge(graph, c, fn, edge_1.EdgeType.Calls))) {
334
+ continue;
335
+ }
336
+ const taken = calls.map(call => branchesTakenIn(conditions, fn, call, graph, ctx));
337
+ if (taken.every(t => t === logic_1.Ternary.Never)) {
338
+ if (onlyCalledBy(fn, new Set(calls), graph)) {
339
+ for (const reader of df_helper_1.Dataflow.sourcesOf(graph, write, edge_1.EdgeType.Reads)) {
340
+ graph.removeEdgeType(reader, write, edge_1.EdgeType.Reads);
341
+ }
342
+ }
343
+ continue;
344
+ }
345
+ const definition = graph.getVertex(fn);
346
+ const at = idMap.get(write)?.location;
347
+ /* a return or an error before the write may end the call without it */
348
+ const reached = vertex_1.DfgVertex.isFunctionDefinition(definition) && at !== undefined && model_1.RNode.strictlyEnclosingFunction(fn, idMap) === undefined
349
+ && !definition.exitPoints.some(e => {
350
+ const exit = idMap.get(e.nodeId)?.location;
351
+ return e.type !== 0 /* ExitPointType.Default */ && (exit === undefined || exit[0] < at[0] || (exit[0] === at[0] && exit[1] <= at[1]));
352
+ });
353
+ for (let i = 0; reached && i < calls.length; i++) {
354
+ const statement = taken[i] === logic_1.Ternary.Always && !graph.getVertex(calls[i])?.cds?.length ? program_order_1.ProgramOrder.runsOnceAt(calls[i], graph) : undefined;
355
+ if (statement !== undefined) {
356
+ program_order_1.ProgramOrder.replaceEarlier(write, statement, graph, true);
357
+ }
358
+ }
359
+ }
360
+ }
361
+ /** How many calls deep {@link PromiseOrder} follows a promise handed on, or a callee that writes. */
362
+ const MaxPromiseHandOn = 4;
363
+ /** When a promise is forced relative to the writes of the call it is handed to: `f <- function(a) { x <<- 2; a }` forces `a` only once `x` is replaced, so `f(x)` never sees what `x` held before the call. */
364
+ class PromiseOrder {
365
+ graph;
366
+ idMap;
367
+ constructor(graph, idMap) {
368
+ this.graph = graph;
369
+ this.idMap = idMap;
370
+ }
371
+ /** The one definition the call is linked to, if it is a closure defined at the top level. */
372
+ topLevelTarget(call) {
373
+ const targets = df_helper_1.Dataflow.calleeIdsOf(this.graph, call);
374
+ const [target] = targets;
375
+ return targets.length === 1 && !node_id_1.NodeId.isBuiltIn(target) && vertex_1.DfgVertex.isFunctionDefinition(this.graph.getVertex(target))
376
+ && model_1.RNode.strictlyEnclosingFunction(target, this.idMap) === undefined ? target : undefined;
377
+ }
378
+ /** The statements of the body of the definition, in the order they run. */
379
+ statementsOf(fn) {
380
+ const definition = this.idMap.get(fn);
381
+ if (!r_function_definition_1.RFunctionDefinition.is(definition)) {
382
+ return [];
383
+ }
384
+ return r_expression_list_1.RExpressionList.is(definition.body) ? definition.body.children : [definition.body];
385
+ }
386
+ /** Where among the statements the node is, `-1` if in none. */
387
+ statementIndex(id, statements) {
388
+ const node = this.idMap.get(id);
389
+ for (const at of node === undefined ? [] : [node, ...model_1.RNode.iterateParents(node, this.idMap)]) {
390
+ const index = statements.indexOf(at);
391
+ if (index >= 0) {
392
+ return index;
393
+ }
394
+ }
395
+ return -1;
396
+ }
397
+ /** The call a statement makes on its own (`g()`) or assigns the result of (`v <- g()`). */
398
+ callOf(statement) {
399
+ const vertex = this.graph.getVertex(statement.info.id);
400
+ const value = r_binary_op_1.RBinaryOp.is(statement) && vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Assignment) ? statement.rhs : statement;
401
+ return vertex_1.DfgVertex.isFunctionCall(this.graph.getVertex(value.info.id)) ? value.info.id : undefined;
402
+ }
403
+ /** Whether the call defines `name` in the frame it is evaluated in, with an assignment of its own. */
404
+ assigns(id, name, origin) {
405
+ return vertex_1.DfgVertex.hasOrigin(this.graph.getVertex(id), origin)
406
+ && df_helper_1.Dataflow.targetsOf(this.graph, id, edge_1.EdgeType.Returns).some(t => {
407
+ const node = this.idMap.get(t);
408
+ return vertex_1.DfgVertex.isVariableDefinition(this.graph.getVertex(t)) && r_symbol_1.RSymbol.is(node) && identifier_1.Identifier.getName(node.content) === name;
409
+ });
410
+ }
411
+ /** Whether running the statement of the top-level closure `fn` surely replaces the global `name`: `name <<- v`, a call of a top-level closure surely doing so, or, for the call the promise came from, forcing another of its arguments that assigns `name` (`f(n, n <- 4)`). */
412
+ surelyWrites(statement, name, fn, call, depth) {
413
+ const id = statement.info.id;
414
+ if (this.assigns(id, name, built_in_proc_name_1.BuiltInProcName.SuperAssignment)) {
415
+ return true;
416
+ }
417
+ if (depth === 0 && vertex_1.DfgVertex.isUse(this.graph.getVertex(id))) {
418
+ const forced = df_helper_1.Dataflow.targetsOf(this.graph, id, edge_1.EdgeType.Reads).filter(p => this.idMap.get(this.idMap.get(p)?.info.parent ?? -1)?.info.parent === fn);
419
+ return forced.some(p => df_helper_1.Dataflow.argumentsBoundTo(this.graph, p).some(a => model_1.RNode.findEnclosing(a, this.idMap, n => n.info.id === call) !== undefined
420
+ && (this.assigns(a, name, built_in_proc_name_1.BuiltInProcName.Assignment) || this.assigns(a, name, built_in_proc_name_1.BuiltInProcName.SuperAssignment))));
421
+ }
422
+ const inner = this.callOf(statement);
423
+ const callee = inner === undefined || depth >= MaxPromiseHandOn ? undefined : this.topLevelTarget(inner);
424
+ if (inner === undefined || callee === undefined) {
425
+ return false;
426
+ }
427
+ const statements = this.statementsOf(callee);
428
+ const at = statements.findIndex(s => this.surelyWrites(s, name, callee, inner, depth + 1));
429
+ const definition = this.graph.getVertex(callee);
430
+ /* a return before the write may leave the callee without it */
431
+ return at >= 0 && !definition.exitPoints.some(e => e.type === 1 /* ExitPointType.Return */ && this.statementIndex(e.nodeId, statements) < at);
432
+ }
433
+ /** Whether the top-level closure `fn` surely replaces the global `name` before anything forces the promise `call` binds to its parameter `param`: every read of the parameter follows a statement surely writing `name`, or hands the promise on to a callee for which the same holds. */
434
+ writtenBeforeForced(fn, param, name, call, depth = 0) {
435
+ const reads = df_helper_1.Dataflow.sourcesOf(this.graph, param, edge_1.EdgeType.Reads);
436
+ const statements = this.statementsOf(fn);
437
+ let firstWrite;
438
+ return reads.length > 0 && reads.every(read => {
439
+ const at = model_1.RNode.findEnclosing(read, this.idMap, r_function_definition_1.RFunctionDefinition.is) === fn ? this.statementIndex(read, statements) : -1;
440
+ if (at < 0) {
441
+ return false;
442
+ }
443
+ firstWrite ??= statements.findIndex(s => this.surelyWrites(s, name, fn, call, depth));
444
+ if (firstWrite >= 0 && firstWrite < at) {
445
+ return true;
446
+ }
447
+ /* `g(a)`: the promise is handed on, and `g` decides when it is forced */
448
+ const inner = this.callOf(statements[at]);
449
+ const callee = inner === undefined || depth >= MaxPromiseHandOn ? undefined : this.topLevelTarget(inner);
450
+ const argument = this.idMap.get(read)?.info.parent;
451
+ const handed = argument === undefined ? undefined : this.idMap.get(argument);
452
+ if (inner === undefined || callee === undefined || !r_argument_1.RArgument.is(handed) || handed.info.parent !== inner) {
453
+ return false;
454
+ }
455
+ const bound = [read, handed.info.id].flatMap(r => df_helper_1.Dataflow.targetsOf(this.graph, r, edge_1.EdgeType.DefinesOnCall));
456
+ return bound.length === 1 && this.writtenBeforeForced(callee, bound[0], name, inner, depth + 1);
457
+ });
458
+ }
459
+ /** Drops what a read in an argument of the top-level call `call` sees of the definitions the program made before the call, when the call replaces the name before it forces the promise. */
460
+ settle(call, argument, read, name) {
461
+ const fn = this.topLevelTarget(call);
462
+ const statement = fn === undefined || !this.graph.isRoot(read) ? undefined : program_order_1.ProgramOrder.runsOnceAt(call, this.graph);
463
+ if (fn === undefined || statement === undefined) {
464
+ return;
465
+ }
466
+ const before = df_helper_1.Dataflow.targetsOf(this.graph, read, edge_1.EdgeType.Reads).filter(t => program_order_1.ProgramOrder.runsOnceAt(t, this.graph) !== undefined && program_order_1.ProgramOrder.offset(t, statement, this.graph) < 0);
467
+ const params = before.length === 0 ? [] : df_helper_1.Dataflow.targetsOf(this.graph, argument, edge_1.EdgeType.DefinesOnCall);
468
+ if (params.length !== 1 || !this.writtenBeforeForced(fn, params[0], name, call)) {
469
+ return;
470
+ }
471
+ /* where a `<<-` writes depends on whether the name was bound before, so its writes read what the promise no longer does */
472
+ const writes = df_helper_1.Dataflow.sourcesOf(this.graph, call, edge_1.EdgeType.SideEffectOnCall).filter(w => {
473
+ const node = this.idMap.get(w);
474
+ return r_symbol_1.RSymbol.is(node) && identifier_1.Identifier.getName(node.content) === name;
475
+ });
476
+ for (const def of before) {
477
+ this.graph.removeEdgeType(read, def, edge_1.EdgeType.Reads);
478
+ for (const write of writes) {
479
+ this.graph.addEdge(write, def, edge_1.EdgeType.Reads);
480
+ }
481
+ }
482
+ }
483
+ /** Drops what a read in the default of `param` cannot see: the default is evaluated once, in the frame of `fn`, by the statement first forcing it, so it sees neither what later statements define, nor, once a statement before surely redefines the name, the parameter it names or what came before (`function(a, b = a) { a <- 10; b }`). */
484
+ settleDefault(fn, param, read, name) {
485
+ const seen = df_helper_1.Dataflow.targetsOf(this.graph, read, edge_1.EdgeType.Reads);
486
+ if (seen.length < 2) {
487
+ return;
488
+ }
489
+ const statements = this.statementsOf(fn);
490
+ const reads = df_helper_1.Dataflow.sourcesOf(this.graph, param, edge_1.EdgeType.Reads);
491
+ const at = (r) => model_1.RNode.findEnclosing(r, this.idMap, r_function_definition_1.RFunctionDefinition.is) === fn ? this.statementIndex(r, statements) : -1;
492
+ /* the first statement that may force it, and the first that surely does */
493
+ const mayForce = Math.min(...reads.map(at));
494
+ const own = this.graph.getVertex(fn)?.cds ?? [];
495
+ const surelyForces = Math.min(...reads.filter(r => info_1.ControlDependency.minus(this.graph.getVertex(r)?.cds ?? [], own).length === 0).map(at));
496
+ if (mayForce < 0 || !Number.isFinite(mayForce)) {
497
+ return;
498
+ }
499
+ const lastWrite = statements.findLastIndex((s, i) => i < mayForce && this.assigns(s.info.id, name, built_in_proc_name_1.BuiltInProcName.Assignment));
500
+ for (const before of seen) {
501
+ const node = this.idMap.get(before);
502
+ const parameter = node?.info.role === "param-n" /* RoleInParent.ParameterName */ && this.idMap.get(node.info.parent ?? -1)?.info.parent === fn;
503
+ const index = this.statementIndex(before, statements);
504
+ if ((parameter && lastWrite >= 0) || (index >= 0 && (index < lastWrite || index > surelyForces))) {
505
+ this.graph.removeEdgeType(read, before, edge_1.EdgeType.Reads);
506
+ }
507
+ }
508
+ }
509
+ }
510
+ /** For a call of a package function flowR has no body for (not one of R's own packages, whose functions the built-in configuration states): `false` if it is none, else the arguments whose promises may be forced after the call returned. */
511
+ function keptPromisesOfPackageCall(graph, call, ctx) {
512
+ const info = call.name === undefined ? undefined : ctx.functionInfo(call.name);
513
+ const pkg = info?.package ?? (call.name === undefined ? undefined : identifier_1.Identifier.getNamespace(call.name));
514
+ if (pkg === undefined || (0, r_base_packages_1.isBaseRPackage)(pkg)) {
515
+ return false;
516
+ }
517
+ if (!handsBackCalledValue(graph, call.id)) {
518
+ return new Set();
519
+ }
520
+ const layout = info?.sig === undefined ? undefined : built_in_props_1.FnSig.layout(info.sig);
521
+ const args = call.args.filter(graph_1.FunctionArgument.isNotEmpty);
522
+ const slots = layout === undefined ? undefined : built_in_props_1.FnSig.slots(layout, args.map(graph_1.FunctionArgument.getName));
523
+ return new Set(args.filter((_, i) => {
524
+ const props = layout === undefined || slots === undefined || slots[i] < 0 ? 0 : layout.props[slots[i]];
525
+ return (props & (built_in_props_1.ArgProp.Forced | built_in_props_1.ArgProp.Lazy)) === 0;
526
+ }).map(a => a.nodeId));
527
+ }
528
+ /** Whether the value of `call` may be called after it returned: it is a function, or it flows (through variables, returns, and reads) to where a call takes its function from, as `g` in `g <- f(); g()`. */
529
+ function handsBackCalledValue(graph, call) {
530
+ if (df_helper_1.Dataflow.targetsOf(graph, call, edge_1.EdgeType.Returns).some(t => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)))) {
531
+ return true;
532
+ }
533
+ const seen = new Set([call]);
534
+ const todo = [call];
535
+ for (let id = todo.pop(); id !== undefined; id = todo.pop()) {
536
+ for (const [source, edge] of graph.edgesTo(id)) {
537
+ if (seen.has(source) || edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Argument) || edge_1.DfEdge.doesNotIncludeType(edge, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.Returns)) {
538
+ continue;
539
+ }
540
+ else if (vertex_1.DfgVertex.isFunctionCall(graph.getVertex(source)) && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
541
+ return true;
542
+ }
543
+ seen.add(source);
544
+ todo.push(source);
545
+ }
546
+ }
547
+ return false;
548
+ }
549
+ /** Whether the promise bound to a parameter may be forced after its call returned: its function does not surely force it, and a closure within the function reads it or it is handed on to a parameter whose promise may. */
550
+ function promiseOutlivesCall(graph, idMap, forcing) {
551
+ const ownerOf = new Map();
552
+ for (const [id, definition] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
553
+ for (const parameter of df_helper_1.Dataflow.parametersOf(definition)) {
554
+ ownerOf.set(parameter, id);
555
+ }
556
+ }
557
+ const handedTo = new defaultmap_1.DefaultMap(() => []);
558
+ for (const parameter of ownerOf.keys()) {
559
+ for (const argument of df_helper_1.Dataflow.argumentsBoundTo(graph, parameter)) {
560
+ for (const read of df_helper_1.Dataflow.targetsOf(graph, argument, edge_1.EdgeType.Reads)) {
561
+ if (ownerOf.has(read)) {
562
+ handedTo.get(read).push(parameter);
563
+ }
564
+ }
565
+ }
566
+ }
567
+ const captured = (parameter) => df_helper_1.Dataflow.sourcesOf(graph, parameter, edge_1.EdgeType.Reads)
568
+ .some(read => model_1.RNode.findEnclosing(read, idMap, r_function_definition_1.RFunctionDefinition.is) !== ownerOf.get(parameter));
569
+ const open = (p) => forcing(p, p) !== logic_1.Ternary.Always;
570
+ const outlives = new fixpoint_1.ReachSummaries(p => open(p) ? handedTo.get(p) : [], p => open(p) && captured(p), monoid_1.Monoid.any);
571
+ return parameter => ownerOf.has(parameter) && outlives.of(parameter);
572
+ }
573
+ /** The definitions of a name that may be made after a call: those in its scope it does not surely run after, and every `<<-`. */
574
+ function definitionsAfter(graph, idMap) {
575
+ const byName = df_helper_1.Dataflow.definitionsByName(graph);
576
+ const superAssigned = new Set(graph.verticesOfType(vertex_1.VertexType.FunctionCall)
577
+ .filter(([id]) => df_helper_1.Dataflow.superAssigns(graph, id))
578
+ .flatMap(([id]) => df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Returns)));
579
+ const scopeOf = (0, defaultmap_1.memoize)((id) => graph.isRoot(id) ? undefined : model_1.RNode.strictlyEnclosingFunction(id, idMap));
580
+ return (call, name) => {
581
+ const scope = scopeOf(call);
582
+ const statement = program_order_1.ProgramOrder.runsOnceAt(call, graph);
583
+ return byName.get(name).filter(def => superAssigned.has(def)
584
+ || (scopeOf(def) === scope && (statement === undefined || program_order_1.ProgramOrder.offset(def, statement, graph) > 0)));
585
+ };
586
+ }
587
+ /** Links every materialized package-export vertex back to the `library()`/`use()` call that loaded it, reading the loading call from the export binding's `definedAt` in the (final, authoritative) environment. */
55
588
  function linkMaterializedExportsToLoaders(graph, environment, ctx) {
56
- /* the attached namespaces hold every export of every package, far more than the graph ever materializes, so the
57
- * cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or something points
58
- * to it, called or read as a value (`g <- select`). Both are read off the graph once here instead of per export binding. */
589
+ /* the attached namespaces hold every export of every package, far more than the graph ever materializes, so the cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or something points to it, called or read as a value (`g <- select`). */
59
590
  const called = new Set(graph.vertices(true).map(([id]) => id).filter(node_id_1.NodeId.isBuiltIn));
60
591
  for (const [, outgoing] of graph.edges()) {
61
592
  for (const target of outgoing.keys()) {
@@ -81,8 +612,7 @@ function linkMaterializedExportsToLoaders(graph, environment, ctx) {
81
612
  }
82
613
  }
83
614
  }
84
- /* the loader targets are `library()` call ids, never export ids, so the edges added here never make a further
85
- * export qualify -- the lazy checks this replaces could not have observed one either */
615
+ /* the loader targets are `library()` call ids, never export ids, so the edges added here never make a further export qualify -- the lazy checks this replaces could not have observed one either */
86
616
  for (const [id, loadedAt] of loaders) {
87
617
  /* an export only read as a value (`g <- select`) has no vertex yet, which a slice could not pass */
88
618
  (0, built_in_library_1.attachExportVertex)(graph, id, environment, ctx);
@@ -108,39 +638,29 @@ function ownLibraryCalls(_id, fdef) {
108
638
  }
109
639
  return packages;
110
640
  }
111
- /** The scopes outside a function's own frame, i.e. those a definition of its body can have escaped into. */
112
- function escapeTargetFrames(fdef) {
113
- return environment_1.REnvironment.frames(fdef.subflow.environment.current.parent);
114
- }
115
- /**
116
- * The non-built-in definitions a function body lets escape to an outer scope (e.g. a `<<-` super-assignment),
117
- * as a callback for {@link computeCallGraphSummaries}. Nested definitions share their outer frames, and a frame is
118
- * dominated by the built-ins it holds, so filtering each frame once per pass saves the bulk of the work.
119
- */
120
- function escapedDefinitions(hidden) {
641
+ /** The non-built-in definitions a function body lets escape to an outer scope (e.g. a `<<-` super-assignment), as a callback for {@link computeCallGraphSummaries}. */
642
+ function escapedDefinitions(graph, hidden) {
121
643
  const perFrame = new Map();
122
- return (_id, fdef) => {
644
+ /* the function an exit hook runs in folds the hook's writes into its final environment in the order R runs the hooks */
645
+ const hooks = new Set(graph.verticesOfType(vertex_1.VertexType.FunctionDefinition).flatMap(([, v]) => v.subflow.hooks.map(h => h.id)));
646
+ return (id, fdef) => {
123
647
  const defs = hidden.keys().filter(call => fdef.subflow.graph.has(call)).toArray();
124
- for (const e of escapeTargetFrames(fdef)) {
648
+ if (hooks.has(id)) {
649
+ return defs;
650
+ }
651
+ for (const e of environment_1.REnvironment.frames(fdef.subflow.environment.current.parent)) {
125
652
  let escaped = perFrame.get(e.memory);
126
- if (escaped === undefined && e.memory instanceof frame_memory_1.Frame && e.memory.lazy() !== undefined) {
127
- /* an attached package binds nothing but its exports, which are built-ins */
653
+ if (escaped === undefined) {
128
654
  escaped = [];
129
655
  perFrame.set(e.memory, escaped);
130
- }
131
- else if (escaped === undefined) {
132
- /* a package frame holds thousands of entries and keeps none of them, so this walks them in place
133
- * rather than through a spread/flatMap/filter/map chain that allocates an array per step */
134
- const collected = [];
135
- for (const ds of e.memory.values()) {
656
+ /* an attached package binds nothing but its exports, which are built-ins, and a package frame holds thousands of entries, so this walks the others in place */
657
+ for (const ds of e.memory instanceof frame_memory_1.Frame && e.memory.lazy() !== undefined ? [] : e.memory.values()) {
136
658
  for (const d of ds) {
137
659
  if (!node_id_1.NodeId.isBuiltIn(d.nodeId)) {
138
- collected.push(d.nodeId);
660
+ escaped.push(d.nodeId);
139
661
  }
140
662
  }
141
663
  }
142
- escaped = collected;
143
- perFrame.set(e.memory, escaped);
144
664
  }
145
665
  for (const d of escaped) {
146
666
  /* a package the caller attached is visible in the body, but only one the body attaches escapes it */
@@ -166,11 +686,7 @@ function propagateTransitiveDefinitions(graph, environment, ctx, summary) {
166
686
  }
167
687
  }
168
688
  }
169
- /**
170
- * Attaches packages transitively loaded by top-level calls to `environment`.
171
- * `g <- function() library(A); f <- function() g(); f()` makes `A` available after `f()`.
172
- * @returns the enriched environment and whether it grew (so the caller can re-link and re-run to a fixpoint).
173
- */
689
+ /** Attaches packages transitively loaded by top-level calls to `environment`. */
174
690
  function propagateTransitivePackages(graph, environment, ctx) {
175
691
  const summary = computeCallGraphSummaries(graph, ownLibraryCalls);
176
692
  /* package to its loading `library()` call and, unless a call reaching it surely runs, the cds of one that may */
@@ -199,19 +715,12 @@ function propagateTransitivePackages(graph, environment, ctx) {
199
715
  }
200
716
  return { environment, grew };
201
717
  }
202
- /** The ambient writes of body calls only linking resolved to a built-in (see {@link writesOfHiddenBuiltIn}), linking their reads as well. */
203
- function hiddenBuiltInWrites(graph, environment) {
204
- const { writes, reads } = hiddenBuiltInAccess(graph, environment);
205
- linkHiddenReads(graph, reads);
206
- return writes;
207
- }
208
- /** The ambient writes and reads of body calls only linking resolved to a built-in, per call. */
209
- function hiddenBuiltInAccess(graph, environment) {
718
+ /** The ambient writes of body calls only linking resolved to a built-in (see {@link writesOfHiddenBuiltIn}), recording and linking their reads as well. */
719
+ function hiddenBuiltInWrites(graph, environment, drawing) {
210
720
  const builtIns = environment_1.REnvironment.findBuiltIn(environment.current);
211
721
  const writes = new Map();
212
722
  const reads = new Map();
213
- const writesOf = new defaultmap_1.DefaultMap(() => [], writes);
214
- const readsOf = new defaultmap_1.DefaultMap(() => [], reads);
723
+ const resolved = [];
215
724
  for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
216
725
  if (graph.isRoot(id) || !(0, built_in_ambient_state_1.reachesBuiltInLate)(vertex)) {
217
726
  continue;
@@ -220,19 +729,26 @@ function hiddenBuiltInAccess(graph, environment) {
220
729
  for (const target of df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls)) {
221
730
  if (node_id_1.NodeId.isBuiltIn(target) && (own === undefined || node_id_1.NodeId.toBuiltIn(identifier_1.Identifier.getName(own)) !== target)) {
222
731
  const targets = resolve_helper_1.Resolve.byNameAndType(node_id_1.NodeId.fromBuiltIn(target), { current: builtIns, level: 0 }, identifier_1.ReferenceType.Function) ?? [];
223
- (0, built_in_ambient_state_1.hiddenSideEffects)(graph, environment, id, targets);
224
- const defs = targets.flatMap(d => (0, built_in_ambient_state_1.writesOfHiddenBuiltIn)(d, id));
732
+ resolved.push([id, targets]);
733
+ const defs = targets.flatMap(d => (0, built_in_ambient_state_1.writesOfHiddenBuiltIn)(d, id, drawing));
225
734
  if (defs.length > 0) {
226
- writesOf.get(id).push(...defs);
735
+ writes.set(id, [...writes.get(id) ?? [], ...defs]);
227
736
  }
228
737
  const names = targets.flatMap(built_in_ambient_state_1.readsOfHiddenBuiltIn);
229
738
  if (names.length > 0) {
230
- readsOf.get(id).push(...names);
739
+ reads.set(id, [...reads.get(id) ?? [], ...names]);
231
740
  }
232
741
  }
233
742
  }
234
743
  }
235
- return { writes, reads };
744
+ for (const [id, targets] of resolved) {
745
+ (0, built_in_ambient_state_1.hiddenSideEffects)(graph, environment, id, targets);
746
+ }
747
+ for (const id of new Set([...writes.keys(), ...reads.keys()])) {
748
+ graph.recordAmbientAccess(id, { reads: reads.get(id), writes: writes.get(id)?.map(d => d.name) });
749
+ }
750
+ linkHiddenReads(graph, reads);
751
+ return writes;
236
752
  }
237
753
  /** A hidden call reads the state where the functions running it are called. */
238
754
  function linkHiddenReads(graph, reads) {
@@ -257,16 +773,13 @@ function linkHiddenReads(graph, reads) {
257
773
  }
258
774
  }
259
775
  }
260
- /**
261
- * Maps each definition escaping into the global frame to its full (name-carrying) definitions, one node may define several names
262
- * (`options(digits = 3)`); a write from a function defined within another one may be caught by that function's frame instead.
263
- */
776
+ /** Maps each definition escaping into the global frame to its full (name-carrying) definitions, one node may define several names (`options(digits = 3)`); a write from a function defined within another one may be caught by that function's frame instead. */
264
777
  function escapedDefinitionMap(graph, hidden) {
265
778
  const map = new Map(hidden.entries().map(([id, defs]) => [id, [...defs]]));
266
779
  const definitionsOf = new defaultmap_1.DefaultMap(() => [], map);
267
780
  const seen = new Set();
268
781
  for (const [, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
269
- const global = escapeTargetFrames(vertex).filter(e => e.t === undefined).reduce((_, e) => e, undefined);
782
+ const global = environment_1.REnvironment.frames(vertex.subflow.environment.current.parent).filter(e => e.t === undefined).reduce((_, e) => e, undefined);
270
783
  /* a frame shared with an already-visited definition contributes the same entries */
271
784
  if (global !== undefined && !seen.has(global.memory)) {
272
785
  seen.add(global.memory);
@@ -281,11 +794,7 @@ function escapedDefinitionMap(graph, hidden) {
281
794
  }
282
795
  return map;
283
796
  }
284
- /**
285
- * Folds the `<<-` definitions that escape transitively from top-level calls into `environment`.
286
- * `f <- function() x <<- 1; g <- function() f(); g(); print(x)` makes `x` resolvable.
287
- * @returns the enriched environment and whether it grew (so the extractor can re-resolve open reads and re-run).
288
- */
797
+ /** Folds the `<<-` definitions that escape transitively from top-level calls into `environment`. */
289
798
  function propagateTransitiveEscapedDefinitions(graph, environment, defined, hidden, summary, open) {
290
799
  const defs = escapedDefinitionMap(graph, hidden);
291
800
  const names = new Set();
@@ -300,9 +809,7 @@ function propagateTransitiveEscapedDefinitions(graph, environment, defined, hidd
300
809
  for (const def of (summary.get(target) ?? []).values().flatMap(nodeId => defs.get(nodeId) ?? [])) {
301
810
  const nodeId = def.nodeId;
302
811
  names.add(def.name);
303
- /* a name may hold several definitions while a lookup answers with one, so asking the environment
304
- * would call every shadowed one missing and define it again on every round; what this fixpoint
305
- * has already folded in is what says whether there is anything left to add */
812
+ /* a name may hold several definitions while a lookup answers with one, so asking the environment would call every shadowed one missing and define it again on every round; what this fixpoint has already folded in is what says whether there is anything left to add */
306
813
  const key = `${def.name}\u0000${String(nodeId)}`;
307
814
  if (defined.has(key)) {
308
815
  continue;
@@ -312,21 +819,20 @@ function propagateTransitiveEscapedDefinitions(graph, environment, defined, hidd
312
819
  continue;
313
820
  }
314
821
  environment = environment_1.REnvironment.define(def, false, environment);
315
- linkReadsAfter(graph, id, def, open, definitionsNamed);
822
+ linkReadsAfter(graph, id, def, open, definitionsNamed, defs);
316
823
  grew = true;
317
824
  }
318
825
  }
319
826
  }
320
827
  return { environment, grew, names };
321
828
  }
322
- /**
323
- * A read that may run after `call` and sees a definition the call may replace (or nothing, as with the `open` reads) may see `def`
324
- * instead, as with a callee only the call binds: `g <- function(f) f(); x <- 1; g(function() x <<- 2); print(x)`, or `g(runif)`.
325
- */
326
- function linkReadsAfter(graph, call, def, open, definitionsNamed) {
829
+ /** A read that may run after `call` and sees a definition the call may replace (or nothing, as with the `open` reads) may see `def` instead, as with a callee only the call binds: `g <- function(f) f(); x <- 1; g(function() x <<- 2); print(x)`, or `g(runif)`. */
830
+ function linkReadsAfter(graph, call, def, open, definitionsNamed, escaped) {
327
831
  const before = graph.getVertex(call)?.environment;
328
832
  const visible = before === undefined ? definitionsNamed(def.name) : resolve_helper_1.Resolve.byName(def.name, before)?.map(d => d.nodeId) ?? [];
329
- const replaced = new Set([...visible, ...df_helper_1.Dataflow.sourcesOf(graph, call, edge_1.EdgeType.SideEffectOnCall)]);
833
+ /* a write of the call that escapes under another name (`par` beside `plot` in the body) replaces nothing of this one */
834
+ const sameName = (id) => escaped.get(id)?.some(d => d.name === def.name) ?? true;
835
+ const replaced = new Set([...visible, ...df_helper_1.Dataflow.sourcesOf(graph, call, edge_1.EdgeType.SideEffectOnCall).filter(sameName)]);
330
836
  const readers = new Set(open.filter(r => r.name === def.name).map(r => r.nodeId));
331
837
  for (const [id] of graph.vertices(true)) {
332
838
  /* an argument reads the value of a call, not a name the call may define (an ambient state is defined at its call) */
@@ -349,40 +855,142 @@ function reResolveOpenReferences(graph, environment, references, escapedNames) {
349
855
  }
350
856
  }
351
857
  }
858
+ function graphOf(from) {
859
+ return 'graph' in from ? [from.graph, from.environment] : [from, undefined];
860
+ }
861
+ /** Whether the call `id` is tagged as a graphics call, or reaches one through a parameter (`g <- function(f) f(1); g(plot)`). */
862
+ function drawsOn(graph, id, environment) {
863
+ const draws = (info) => function_semantics_1.FunctionSemantics.call.props.hasAny(info, built_in_props_2.SemanticCallTag.Graphics);
864
+ if (draws((0, query_fn_props_1.callFnProps)(id, graph, environment))) {
865
+ return true;
866
+ }
867
+ const builtIns = environment === undefined ? undefined : { level: 0, current: environment_1.REnvironment.findBuiltIn(environment.current) };
868
+ return df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls).some(t => node_id_1.NodeId.isBuiltIn(t)
869
+ && draws(builtIns === undefined ? query_fn_props_1.BuiltInIndex.default().get(node_id_1.NodeId.fromBuiltIn(t)) : (0, query_fn_props_1.queryFnProps)(node_id_1.NodeId.fromBuiltIn(t), { environment: builtIns })));
870
+ }
871
+ /** What the call `id` itself accesses, without the functions it calls. */
872
+ function accessOfCall(graph, id, environment) {
873
+ const recorded = graph.ambientAccessOf(id) ?? ambient_access_1.AmbientAccess.empty;
874
+ return drawsOn(graph, id, environment) ? { ...recorded, draws: new Set([id]) } : recorded;
875
+ }
352
876
  /**
353
- * The global state each function may leave changed when it is called, as the names of the pseudo variables it changes
354
- * (see {@link AmbientStateName}): `#option:digits` for `options(digits = 3)`, `#env:PATH` for `Sys.setenv(PATH = "")`, or `#sink`,
355
- * and the global variables it binds.
356
- * A function reports what its callees report as well, so with `a01 <- function() options(digits = 3)` and `a22 <- function() a01()`,
357
- * both set `#option:digits`. What a function only changes within its own frame (`withr::local_options`) is left out.
358
- * @param info - the dataflow information of the whole program
359
- * @returns per function-definition vertex what it may change, which is empty for a function changing nothing
360
- * @useInstead {@link Dataflow.sideEffects.ambientWrites}
877
+ * What each function accesses when it is called: the pseudo variables it reads and changes (see {@link AmbientStateName}), the global variables it binds and the drawing calls it makes, together with what the functions it calls access.
878
+ * @useInstead {@link Dataflow.sideEffects.ambientAccessOfFunctions}
361
879
  */
362
- function ambientWritesOfFunctions(info) {
363
- const hidden = hiddenBuiltInAccess(info.graph, info.environment).writes;
364
- const names = escapedDefinitionMap(info.graph, hidden);
365
- const summary = computeCallGraphSummaries(info.graph, escapedDefinitions(hidden));
366
- return new Map(summary.entries().map(([id, definitions]) => [id, writesOf(definitions.values().flatMap(d => names.get(d) ?? []))]));
880
+ function ambientAccessOfFunctions(from) {
881
+ const [graph, environment] = graphOf(from);
882
+ const names = escapedDefinitionMap(graph, new Map());
883
+ const escaped = escapedDefinitions(graph, new Map());
884
+ return foldCallGraph(graph, ambient_access_1.AmbientAccess.monoid, (id, fdef) => monoid_1.Monoid.fold(ambient_access_1.AmbientAccess.monoid, [
885
+ ...df_helper_1.Dataflow.callsIn(fdef, graph).map(([call]) => accessOfCall(graph, call, environment)),
886
+ {
887
+ ...ambient_access_1.AmbientAccess.empty,
888
+ /* removing a global is a write of it, as far as what a function binds goes */
889
+ variables: relation_1.Relation.fromPairs(escaped(id, fdef).flatMap(def => names.get(def) ?? []).filter(({ name }) => !ambient_state_name_1.AmbientStateName.is(name)).map(({ name, nodeId }) => [(0, removal_marker_1.removedNameOf)(name), nodeId]))
890
+ }
891
+ ]));
367
892
  }
368
- function writesOf(definitions) {
369
- const state = new Set();
370
- const assumed = new Set();
371
- const variables = new Set();
372
- for (const d of definitions) {
373
- (!ambient_state_name_1.AmbientStateName.is(d.name) ? variables : (0, built_in_ambient_state_1.isAssumedWrite)(d) ? assumed : state).add(d.name);
893
+ /** Adds the ids of every file a `source` call among `ids` runs, transitively, found by where the call continues with another file. */
894
+ function addSourcedFiles(graph, ids) {
895
+ const idMap = graph.idMap;
896
+ if (idMap === undefined) {
897
+ return;
898
+ }
899
+ const todo = [...ids];
900
+ for (let id = todo.pop(); id !== undefined; id = todo.pop()) {
901
+ if (!vertex_1.DfgVertex.hasOrigin(graph.getVertex(id), built_in_proc_name_1.BuiltInProcName.Source)) {
902
+ continue;
903
+ }
904
+ const file = idMap.get(id)?.info.file;
905
+ for (const next of df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.FlowEdge)) {
906
+ const node = idMap.get(next);
907
+ if (node === undefined || node.info.file === file || ids.has(next)) {
908
+ continue;
909
+ }
910
+ const root = model_1.RNode.iterateParents(node, idMap).reduce((_, parent) => parent, node);
911
+ for (const inner of model_1.RNode.collectAllIds(root)) {
912
+ if (!ids.has(inner)) {
913
+ ids.add(inner);
914
+ todo.push(inner);
915
+ }
916
+ }
917
+ }
918
+ }
919
+ }
920
+ function idsOfScope(graph, scope) {
921
+ if (typeof scope === 'string' || typeof scope === 'number') {
922
+ const node = graph.idMap?.get(scope);
923
+ return node === undefined ? new Set([scope]) : model_1.RNode.collectAllIds(node);
924
+ }
925
+ else if (r_project_1.RProject.is(scope)) {
926
+ return r_project_1.RProject.collectAllIds(scope);
927
+ }
928
+ else if ('type' in scope) {
929
+ return model_1.RNode.collectAllIds(scope);
930
+ }
931
+ return new Set(scope);
932
+ }
933
+ /**
934
+ * What running the given code reads and writes of the global state, see {@link AmbientAccess}: the calls in `scope` and, unless turned off, what the functions they call access.
935
+ * @useInstead {@link Dataflow.sideEffects.ambientAccess}
936
+ */
937
+ function ambientAccessOf(from, scope, opts) {
938
+ const [graph, environment] = graphOf(from);
939
+ const ids = idsOfScope(graph, scope);
940
+ addSourcedFiles(graph, ids);
941
+ /* the bodies of nested definitions, exit hooks among them, are no part of the scope (`collectAllIds` misses the hooks) */
942
+ const bodies = new Set();
943
+ const definitions = [...ids];
944
+ for (let id = definitions.pop(); id !== undefined; id = definitions.pop()) {
945
+ const vertex = graph.getVertex(id);
946
+ if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
947
+ for (const inner of vertex.subflow.graph) {
948
+ if (!bodies.has(inner)) {
949
+ bodies.add(inner);
950
+ definitions.push(inner);
951
+ }
952
+ }
953
+ }
954
+ }
955
+ const accesses = [];
956
+ const callees = new Set();
957
+ for (const id of ids) {
958
+ if (bodies.has(id) || !vertex_1.DfgVertex.isFunctionCall(graph.getVertex(id))) {
959
+ continue;
960
+ }
961
+ accesses.push(accessOfCall(graph, id, environment));
962
+ if (opts?.includeCallees !== false) {
963
+ for (const callee of df_helper_1.Dataflow.calleeIdsOf(graph, id)) {
964
+ callees.add(callee);
965
+ }
966
+ }
967
+ /* what the call evaluates that the code does not write (`eval(parse(text = s))`, `eval(call("f"))`, `do.call(name)`) is part of it */
968
+ for (const made of df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument)) {
969
+ if (!node_id_1.NodeId.isWritten(made) && !node_id_1.NodeId.isBuiltIn(made)) {
970
+ const node = graph.idMap?.get(made);
971
+ (node === undefined ? [made] : model_1.RNode.collectAllIds(node)).forEach(inner => ids.add(inner));
972
+ }
973
+ }
974
+ }
975
+ if (callees.size > 0) {
976
+ const functions = opts?.functions ?? ambientAccessOfFunctions(from);
977
+ for (const callee of callees) {
978
+ const access = functions.get(callee);
979
+ if (access !== undefined) {
980
+ accesses.push(access);
981
+ }
982
+ }
374
983
  }
375
- return { state, assumed: assumed.difference(state), variables };
984
+ return monoid_1.Monoid.fold(ambient_access_1.AmbientAccess.monoid, accesses);
376
985
  }
377
986
  /**
378
987
  * Propagates every function's escaped side effects (attached packages and `<<-` definitions) to its transitive callers.
379
- * @returns the enriched top-level environment and whether it grew (so the extractor can re-link and re-run to a fixpoint).
380
988
  * @useInstead {@link Dataflow.sideEffects.propagateTransitive}
381
989
  */
382
990
  function propagateTransitiveSideEffects(graph, environment, ctx, defined = new Set(), open = []) {
383
- const hidden = hiddenBuiltInWrites(graph, environment);
991
+ const hidden = hiddenBuiltInWrites(graph, environment, (0, built_in_ambient_state_1.drawingWritesDevice)(ctx.config));
384
992
  /* both passes ask what escapes each function, and neither changes a body or a call target in between */
385
- const escapes = computeCallGraphSummaries(graph, escapedDefinitions(hidden));
993
+ const escapes = computeCallGraphSummaries(graph, escapedDefinitions(graph, hidden));
386
994
  propagateTransitiveDefinitions(graph, environment, ctx, escapes);
387
995
  const packages = propagateTransitivePackages(graph, environment, ctx);
388
996
  const escaped = propagateTransitiveEscapedDefinitions(graph, packages.environment, defined, hidden, escapes, open);