@eagleoutice/flowr 2.17.4 → 2.17.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (544) hide show
  1. package/README.md +13 -52
  2. package/abstract-interpretation/absint-inference.js +1 -2
  3. package/abstract-interpretation/data-frame/arguments.d.ts +14 -3
  4. package/abstract-interpretation/data-frame/arguments.js +34 -0
  5. package/abstract-interpretation/data-frame/dataframe-semantics.js +7 -15
  6. package/abstract-interpretation/data-frame/resolve-args.d.ts +2 -2
  7. package/abstract-interpretation/data-frame/semantics.d.ts +8 -1
  8. package/abstract-interpretation/data-frame/semantics.js +14 -6
  9. package/abstract-interpretation/domains/state-abstract-domain.js +28 -18
  10. package/abstract-interpretation/domains/state-map.d.ts +43 -0
  11. package/abstract-interpretation/domains/state-map.js +147 -0
  12. package/benchmark/slicer.d.ts +1 -1
  13. package/benchmark/slicer.js +8 -7
  14. package/cli/repl/commands/repl-dataflow.js +5 -5
  15. package/cli/repl/commands/repl-execute.js +3 -2
  16. package/cli/repl/commands/repl-parse.js +2 -1
  17. package/cli/repl/print-version.d.ts +1 -1
  18. package/cli/repl/print-version.js +2 -1
  19. package/cli/repl/server/connection.d.ts +1 -1
  20. package/cli/repl/server/connection.js +7 -9
  21. package/cli/slicer-app.js +2 -1
  22. package/clones/algorithms/baxter-ast.d.ts +33 -0
  23. package/clones/algorithms/baxter-ast.js +70 -0
  24. package/clones/algorithms/greedy-string-tiling.d.ts +17 -0
  25. package/clones/algorithms/greedy-string-tiling.js +56 -0
  26. package/clones/algorithms/winnowing.d.ts +27 -0
  27. package/clones/algorithms/winnowing.js +66 -0
  28. package/clones/clone-ast.d.ts +75 -0
  29. package/clones/clone-ast.js +174 -0
  30. package/clones/clone-dataflow.d.ts +11 -0
  31. package/clones/clone-dataflow.js +83 -0
  32. package/clones/clone-detector.d.ts +116 -0
  33. package/clones/clone-detector.js +200 -0
  34. package/clones/clone-index.d.ts +54 -0
  35. package/clones/clone-index.js +56 -0
  36. package/config.d.ts +21 -2
  37. package/config.js +7 -1
  38. package/control-flow/basic-cfg-guided-visitor.js +1 -2
  39. package/control-flow/happens-before.d.ts +2 -0
  40. package/control-flow/happens-before.js +15 -9
  41. package/control-flow/simple-visitor.js +2 -4
  42. package/core/steps/all/core/00-parse.js +2 -1
  43. package/core/steps/all/core/01-parse-tree-sitter.js +2 -1
  44. package/core/steps/all/core/10-normalize.js +2 -1
  45. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -1
  46. package/core/steps/all/static-slicing/00-slice.js +2 -1
  47. package/core/steps/all/static-slicing/10-reconstruct.js +2 -1
  48. package/core/steps/pipeline/create-pipeline.js +1 -2
  49. package/core/steps/pipeline/default-pipelines.d.ts +1 -1
  50. package/core/steps/pipeline/default-pipelines.js +5 -4
  51. package/core/steps/pipeline-step.d.ts +3 -1
  52. package/core/steps/pipeline-step.js +5 -0
  53. package/data/r-base-primitives.generated.d.ts +2 -1
  54. package/dataflow/cluster.js +1 -2
  55. package/dataflow/environments/ambient-state-name.d.ts +14 -22
  56. package/dataflow/environments/ambient-state-name.js +4 -18
  57. package/dataflow/environments/apply-kill.d.ts +9 -20
  58. package/dataflow/environments/apply-kill.js +51 -25
  59. package/dataflow/environments/built-in-config.d.ts +7 -15
  60. package/dataflow/environments/built-in-config.js +15 -16
  61. package/dataflow/environments/built-in-eval-name.d.ts +5 -6
  62. package/dataflow/environments/built-in-eval-name.js +4 -5
  63. package/dataflow/environments/built-in-kinds.d.ts +111 -0
  64. package/dataflow/environments/built-in-kinds.js +35 -0
  65. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  66. package/dataflow/environments/built-in-proc-name.js +11 -0
  67. package/dataflow/environments/built-in-props.d.ts +62 -175
  68. package/dataflow/environments/built-in-props.js +42 -154
  69. package/dataflow/environments/built-in.d.ts +37 -73
  70. package/dataflow/environments/built-in.js +41 -62
  71. package/dataflow/environments/data-masking-functions.d.ts +2 -2
  72. package/dataflow/environments/default-builtin-config/base-functions.d.ts +7 -0
  73. package/dataflow/environments/default-builtin-config/base-functions.js +339 -0
  74. package/dataflow/environments/default-builtin-config/base-language.d.ts +3 -0
  75. package/dataflow/environments/default-builtin-config/base-language.js +66 -0
  76. package/dataflow/environments/default-builtin-config/base-operators.d.ts +58 -0
  77. package/dataflow/environments/default-builtin-config/base-operators.js +169 -0
  78. package/dataflow/environments/default-builtin-config/database-access.d.ts +3 -0
  79. package/dataflow/environments/default-builtin-config/database-access.js +16 -0
  80. package/dataflow/environments/default-builtin-config/define-helpers.d.ts +45 -0
  81. package/dataflow/environments/default-builtin-config/define-helpers.js +50 -0
  82. package/dataflow/environments/default-builtin-config/dev-tooling.d.ts +3 -0
  83. package/dataflow/environments/default-builtin-config/dev-tooling.js +63 -0
  84. package/dataflow/environments/default-builtin-config/file-io.d.ts +3 -0
  85. package/dataflow/environments/default-builtin-config/file-io.js +81 -0
  86. package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +3 -0
  87. package/dataflow/environments/default-builtin-config/graphics-devices.js +57 -0
  88. package/dataflow/environments/default-builtin-config/index.d.ts +18 -0
  89. package/dataflow/environments/default-builtin-config/index.js +114 -0
  90. package/dataflow/environments/default-builtin-config/media-formats.d.ts +3 -0
  91. package/dataflow/environments/default-builtin-config/media-formats.js +41 -0
  92. package/dataflow/environments/default-builtin-config/misc-packages.d.ts +3 -0
  93. package/dataflow/environments/default-builtin-config/misc-packages.js +18 -0
  94. package/dataflow/environments/default-builtin-config/network-access.d.ts +3 -0
  95. package/dataflow/environments/default-builtin-config/network-access.js +47 -0
  96. package/dataflow/environments/default-builtin-config/object-systems.d.ts +3 -0
  97. package/dataflow/environments/default-builtin-config/object-systems.js +39 -0
  98. package/dataflow/environments/default-builtin-config/package-data-table.d.ts +3 -0
  99. package/dataflow/environments/default-builtin-config/package-data-table.js +18 -0
  100. package/dataflow/environments/default-builtin-config/package-spatial.d.ts +3 -0
  101. package/dataflow/environments/default-builtin-config/package-spatial.js +32 -0
  102. package/dataflow/environments/default-builtin-config/package-tidyverse.d.ts +3 -0
  103. package/dataflow/environments/default-builtin-config/package-tidyverse.js +96 -0
  104. package/dataflow/environments/default-builtin-config/package-utils.d.ts +3 -0
  105. package/dataflow/environments/default-builtin-config/package-utils.js +35 -0
  106. package/dataflow/environments/default-builtin-config/package-withr.d.ts +3 -0
  107. package/dataflow/environments/default-builtin-config/package-withr.js +41 -0
  108. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +3 -0
  109. package/dataflow/environments/default-builtin-config/parallel-execution.js +31 -0
  110. package/dataflow/environments/default-builtin-config/session-interactive.d.ts +3 -0
  111. package/dataflow/environments/default-builtin-config/session-interactive.js +31 -0
  112. package/dataflow/environments/default-builtin-config/shared-configs.d.ts +267 -0
  113. package/dataflow/environments/default-builtin-config/shared-configs.js +483 -0
  114. package/dataflow/environments/default-builtin-config/shared-signatures.d.ts +21 -0
  115. package/dataflow/environments/default-builtin-config/shared-signatures.js +32 -0
  116. package/dataflow/environments/default-builtin-config/statistics.d.ts +3 -0
  117. package/dataflow/environments/default-builtin-config/statistics.js +32 -0
  118. package/dataflow/environments/default-builtin-config/unit-testing.d.ts +3 -0
  119. package/dataflow/environments/default-builtin-config/unit-testing.js +13 -0
  120. package/dataflow/environments/environment.d.ts +28 -52
  121. package/dataflow/environments/environment.js +24 -71
  122. package/dataflow/environments/group-generics.d.ts +12 -19
  123. package/dataflow/environments/group-generics.js +17 -14
  124. package/dataflow/environments/identifier.d.ts +72 -427
  125. package/dataflow/environments/identifier.js +34 -145
  126. package/dataflow/environments/pkg-name.d.ts +197 -0
  127. package/dataflow/environments/pkg-name.js +3 -0
  128. package/dataflow/environments/query-fn-props.d.ts +27 -76
  129. package/dataflow/environments/query-fn-props.js +34 -95
  130. package/dataflow/environments/resolve-by-name.d.ts +6 -16
  131. package/dataflow/environments/resolve-by-name.js +23 -35
  132. package/dataflow/environments/scoping.d.ts +5 -5
  133. package/dataflow/environments/scoping.js +13 -5
  134. package/dataflow/eval/resolve/alias-tracking.d.ts +31 -68
  135. package/dataflow/eval/resolve/alias-tracking.js +611 -126
  136. package/dataflow/eval/resolve/match-arguments.d.ts +5 -3
  137. package/dataflow/eval/resolve/resolve-argument.d.ts +11 -11
  138. package/dataflow/eval/resolve/resolve-argument.js +25 -30
  139. package/dataflow/eval/resolve/resolve-field.d.ts +10 -0
  140. package/dataflow/eval/resolve/resolve-field.js +127 -0
  141. package/dataflow/eval/resolve/resolve-replacement.d.ts +10 -0
  142. package/dataflow/eval/resolve/resolve-replacement.js +80 -0
  143. package/dataflow/eval/resolve/resolve-strings.d.ts +2 -2
  144. package/dataflow/eval/resolve/resolve.d.ts +13 -10
  145. package/dataflow/eval/resolve/resolve.js +81 -32
  146. package/dataflow/eval/values/general.d.ts +6 -24
  147. package/dataflow/eval/values/general.js +12 -29
  148. package/dataflow/eval/values/lists/list-constants.d.ts +11 -0
  149. package/dataflow/eval/values/lists/list-constants.js +65 -0
  150. package/dataflow/eval/values/r-value.d.ts +20 -23
  151. package/dataflow/eval/values/r-value.js +22 -17
  152. package/dataflow/extractor.d.ts +2 -10
  153. package/dataflow/extractor.js +100 -46
  154. package/dataflow/fn/argument-roles.d.ts +2 -4
  155. package/dataflow/fn/argument-roles.js +49 -23
  156. package/dataflow/fn/class-declaration.d.ts +36 -52
  157. package/dataflow/fn/class-declaration.js +22 -56
  158. package/dataflow/fn/condition-handlers.d.ts +2 -1
  159. package/dataflow/fn/dispatch.d.ts +70 -0
  160. package/dataflow/fn/dispatch.js +434 -0
  161. package/dataflow/fn/exceptions-of-function.d.ts +1 -2
  162. package/dataflow/fn/exceptions-of-function.js +36 -106
  163. package/dataflow/fn/frame-reflection.d.ts +1 -3
  164. package/dataflow/fn/frame-reflection.js +8 -16
  165. package/dataflow/fn/function-props.d.ts +2 -5
  166. package/dataflow/fn/function-props.js +27 -36
  167. package/dataflow/fn/function-semantics.d.ts +14 -26
  168. package/dataflow/fn/function-semantics.js +4 -18
  169. package/dataflow/fn/higher-order-function.js +2 -4
  170. package/dataflow/fn/strict-function.d.ts +10 -35
  171. package/dataflow/fn/strict-function.js +126 -138
  172. package/dataflow/graph/ambient-access.d.ts +51 -0
  173. package/dataflow/graph/ambient-access.js +80 -0
  174. package/dataflow/graph/call-graph.d.ts +9 -29
  175. package/dataflow/graph/call-graph.js +17 -41
  176. package/dataflow/graph/closure-frames.d.ts +46 -0
  177. package/dataflow/graph/closure-frames.js +225 -0
  178. package/dataflow/graph/dataflowgraph-builder.d.ts +25 -96
  179. package/dataflow/graph/dataflowgraph-builder.js +29 -97
  180. package/dataflow/graph/df-helper.d.ts +48 -188
  181. package/dataflow/graph/df-helper.js +107 -208
  182. package/dataflow/graph/diff-dataflow-graph.d.ts +5 -15
  183. package/dataflow/graph/diff-dataflow-graph.js +25 -25
  184. package/dataflow/graph/edge.js +1 -1
  185. package/dataflow/graph/graph-helper.d.ts +10 -46
  186. package/dataflow/graph/graph-helper.js +16 -50
  187. package/dataflow/graph/graph.d.ts +44 -97
  188. package/dataflow/graph/graph.js +83 -79
  189. package/dataflow/graph/match-args.d.ts +21 -88
  190. package/dataflow/graph/match-args.js +284 -97
  191. package/dataflow/graph/vertex.d.ts +101 -128
  192. package/dataflow/graph/vertex.js +23 -20
  193. package/dataflow/hooks.d.ts +7 -14
  194. package/dataflow/hooks.js +15 -13
  195. package/dataflow/info.d.ts +2 -17
  196. package/dataflow/internal/dispatch-linking.d.ts +71 -0
  197. package/dataflow/internal/dispatch-linking.js +332 -0
  198. package/dataflow/internal/linker.d.ts +48 -50
  199. package/dataflow/internal/linker.js +457 -155
  200. package/dataflow/internal/process/functions/call/argument/make-argument.js +2 -1
  201. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -14
  202. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -46
  203. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +7 -6
  204. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +10 -9
  205. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +23 -75
  206. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +263 -97
  207. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +10 -7
  208. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +66 -45
  209. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +15 -19
  210. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +82 -62
  211. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -4
  212. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -2
  213. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +2 -2
  214. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +3 -2
  215. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +15 -0
  216. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +416 -0
  217. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +37 -54
  218. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +192 -111
  219. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +4 -3
  220. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +60 -13
  221. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -3
  222. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +80 -76
  223. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +1 -7
  224. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -13
  225. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +4 -8
  226. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +436 -140
  227. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +18 -10
  228. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +90 -12
  229. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -5
  230. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -14
  231. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +9 -8
  232. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -7
  233. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
  234. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +3 -5
  235. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +2 -6
  236. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +9 -24
  237. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +10 -6
  238. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +5 -6
  239. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +3 -4
  240. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -4
  241. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +8 -11
  242. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -5
  243. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +20 -28
  244. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +17 -4
  245. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +117 -4
  246. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +5 -3
  247. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +3 -3
  248. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +8 -4
  249. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +18 -29
  250. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -25
  251. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +31 -35
  252. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +4 -18
  253. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +13 -19
  254. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +18 -16
  255. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +130 -65
  256. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -1
  257. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +38 -30
  258. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +584 -114
  259. package/dataflow/internal/process/functions/call/common.d.ts +8 -24
  260. package/dataflow/internal/process/functions/call/common.js +24 -24
  261. package/dataflow/internal/process/functions/call/deferred.d.ts +7 -27
  262. package/dataflow/internal/process/functions/call/deferred.js +6 -27
  263. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +6 -26
  264. package/dataflow/internal/process/functions/call/known-call-handling.js +6 -16
  265. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -4
  266. package/dataflow/internal/process/functions/call/named-call-handling.js +14 -35
  267. package/dataflow/internal/process/functions/call/nse.d.ts +2 -9
  268. package/dataflow/internal/process/functions/call/nse.js +6 -13
  269. package/dataflow/internal/process/functions/call/quoted.d.ts +4 -15
  270. package/dataflow/internal/process/functions/call/quoted.js +26 -62
  271. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +3 -6
  272. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +29 -11
  273. package/dataflow/internal/process/functions/process-parameter.js +1 -1
  274. package/dataflow/internal/program-order.d.ts +3 -10
  275. package/dataflow/internal/program-order.js +19 -10
  276. package/dataflow/origin/dfg-get-origin.js +2 -1
  277. package/documentation/data/faq/faqs.js +16 -1
  278. package/documentation/data/interface/doc-writing-code.js +5 -7
  279. package/documentation/doc-capabilities.js +3 -3
  280. package/documentation/doc-readme.js +1 -1
  281. package/documentation/doc-util/doc-code.d.ts +0 -5
  282. package/documentation/doc-util/doc-code.js +2 -22
  283. package/documentation/doc-util/doc-query.d.ts +1 -2
  284. package/documentation/doc-util/doc-query.js +4 -5
  285. package/documentation/doc-util/doc-search.js +1 -1
  286. package/documentation/wiki-analyzer.js +4 -3
  287. package/documentation/wiki-core.js +5 -5
  288. package/documentation/wiki-dataflow-graph.js +6 -0
  289. package/documentation/wiki-interface.js +2 -1
  290. package/documentation/wiki-linter.js +15 -3
  291. package/documentation/wiki-linting-and-testing.js +15 -2
  292. package/documentation/wiki-query.js +111 -29
  293. package/index.d.ts +3 -1
  294. package/index.js +6 -3
  295. package/linter/linter-executor.js +1 -1
  296. package/linter/linter-rules.d.ts +37 -8
  297. package/linter/linter-rules.js +8 -1
  298. package/linter/linter-util.d.ts +3 -3
  299. package/linter/linter-util.js +1 -1
  300. package/linter/rules/cmd-check/bogus-return.d.ts +2 -1
  301. package/linter/rules/cmd-check/call-arguments.d.ts +3 -2
  302. package/linter/rules/cmd-check/call-arguments.js +5 -5
  303. package/linter/rules/cmd-check/cmd-check-util.d.ts +9 -8
  304. package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -1
  305. package/linter/rules/cmd-check/dependency-declaration.js +1 -1
  306. package/linter/rules/cmd-check/documentation-mismatch.d.ts +3 -2
  307. package/linter/rules/cmd-check/documentation-mismatch.js +2 -1
  308. package/linter/rules/cmd-check/file-checks.d.ts +2 -2
  309. package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -1
  310. package/linter/rules/cmd-check/global-environment-modification.d.ts +6 -5
  311. package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -1
  312. package/linter/rules/cmd-check/non-ascii-code.js +1 -1
  313. package/linter/rules/cmd-check/package-files.d.ts +2 -2
  314. package/linter/rules/cmd-check/package-hooks.d.ts +5 -4
  315. package/linter/rules/cmd-check/package-runtime.js +2 -2
  316. package/linter/rules/cmd-check/rd-files.js +2 -1
  317. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +3 -2
  318. package/linter/rules/cmd-check/s-three-method-consistency.js +2 -1
  319. package/linter/rules/code-clones.d.ts +57 -0
  320. package/linter/rules/code-clones.js +53 -0
  321. package/linter/rules/deprecated-functions.js +3 -6
  322. package/linter/rules/file-path-validity.js +6 -4
  323. package/linter/rules/function-finder-util.d.ts +4 -2
  324. package/linter/rules/naming-convention.d.ts +6 -5
  325. package/linter/rules/naming-convention.js +2 -3
  326. package/linter/rules/no-leaked-credentials.d.ts +2 -1
  327. package/linter/rules/no-leaked-credentials.js +1 -1
  328. package/linter/rules/overwritten-file.d.ts +2 -1
  329. package/linter/rules/problematic-inputs.d.ts +2 -1
  330. package/linter/rules/problematic-inputs.js +3 -3
  331. package/linter/rules/process-state-in-session.d.ts +7 -6
  332. package/linter/rules/process-state-in-session.js +1 -1
  333. package/linter/rules/roxygen-arguments.d.ts +1 -1
  334. package/linter/rules/secret-exfiltration.js +1 -1
  335. package/linter/rules/seeded-randomness.d.ts +3 -3
  336. package/linter/rules/unclosed-connection.js +1 -2
  337. package/linter/rules/undefined-symbol-util.d.ts +3 -2
  338. package/linter/rules/undefined-symbol.d.ts +3 -2
  339. package/linter/rules/unescaped-arguments.d.ts +1 -1
  340. package/linter/rules/unescaped-arguments.js +6 -8
  341. package/linter/rules/unused-definition.d.ts +4 -3
  342. package/linter/rules/unused-definition.js +10 -12
  343. package/linter/rules/unused-import.d.ts +6 -5
  344. package/package.json +1 -1
  345. package/project/attached-packages.d.ts +5 -4
  346. package/project/cache/flowr-analyzer-cache.d.ts +14 -1
  347. package/project/cache/flowr-analyzer-cache.js +40 -3
  348. package/project/context/flowr-analyzer-dependencies-context.d.ts +12 -12
  349. package/project/context/flowr-analyzer-environment-context.d.ts +3 -3
  350. package/project/context/flowr-analyzer-environment-context.js +3 -3
  351. package/project/context/flowr-analyzer-functions-context.d.ts +9 -7
  352. package/project/context/flowr-analyzer-gas-context.d.ts +25 -0
  353. package/project/context/flowr-analyzer-gas-context.js +34 -4
  354. package/project/dependency-version-space.d.ts +30 -29
  355. package/project/dependency-version-space.js +1 -2
  356. package/project/flowr-analyzer-builder.d.ts +2 -3
  357. package/project/flowr-analyzer.d.ts +35 -3
  358. package/project/flowr-analyzer.js +11 -5
  359. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +15 -14
  360. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +5 -4
  361. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +1 -1
  362. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -1
  363. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +4 -3
  364. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -1
  365. package/project/plugins/package-version-plugins/package.d.ts +6 -5
  366. package/project/sigdb/build.js +1 -1
  367. package/project/sigdb/decode.d.ts +8 -7
  368. package/project/sigdb/decode.js +1 -2
  369. package/project/sigdb/dict.d.ts +2 -1
  370. package/project/sigdb/dict.js +2 -2
  371. package/project/sigdb/index-format.d.ts +2 -1
  372. package/project/sigdb/manifest.d.ts +1 -1
  373. package/project/sigdb/memory-source.d.ts +18 -17
  374. package/project/sigdb/on-demand/package-sources.d.ts +4 -3
  375. package/project/sigdb/on-demand/recoverer.d.ts +2 -1
  376. package/project/sigdb/on-demand/remote-sources.d.ts +2 -1
  377. package/project/sigdb/reader.d.ts +85 -80
  378. package/project/sigdb/reader.js +0 -4
  379. package/project/sigdb/schema.d.ts +9 -8
  380. package/project/sigdb/signature-db.d.ts +6 -6
  381. package/queries/catalog/ambient-access-query/ambient-access-query-executor.d.ts +6 -0
  382. package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +50 -0
  383. package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +54 -0
  384. package/queries/catalog/ambient-access-query/ambient-access-query-format.js +45 -0
  385. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +2 -1
  386. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
  387. package/queries/catalog/call-graph-query/expand-library-internals.d.ts +3 -2
  388. package/queries/catalog/code-clones-query/code-clones-query-executor.d.ts +6 -0
  389. package/queries/catalog/code-clones-query/code-clones-query-executor.js +38 -0
  390. package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +54 -0
  391. package/queries/catalog/code-clones-query/code-clones-query-format.js +73 -0
  392. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +3 -3
  393. package/queries/catalog/dependencies-query/data-flow.d.ts +5 -4
  394. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +5 -2
  395. package/queries/catalog/dependencies-query/dependencies-query-executor.js +5 -5
  396. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -2
  397. package/queries/catalog/dependencies-query/dependencies-query-format.js +1 -1
  398. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
  399. package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
  400. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -0
  401. package/queries/catalog/dice-query/dice-query-format.js +1 -0
  402. package/queries/catalog/does-call-query/does-call-query-executor.js +1 -2
  403. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -0
  404. package/queries/catalog/does-call-query/does-call-query-format.js +1 -0
  405. package/queries/catalog/function-info-query/function-info-query-format.d.ts +2 -1
  406. package/queries/catalog/function-info-query/function-origin.d.ts +3 -2
  407. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -3
  408. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +5 -4
  409. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -0
  410. package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -0
  411. package/queries/catalog/input-sources-query/input-sources-query-executor.js +7 -3
  412. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +9 -9
  413. package/queries/catalog/input-sources-query/simple-input-classifier.js +1 -1
  414. package/queries/catalog/linter-query/linter-query-executor.js +4 -1
  415. package/queries/catalog/linter-query/linter-query-format.js +3 -2
  416. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -0
  417. package/queries/catalog/origin-query/origin-query-format.js +1 -0
  418. package/queries/catalog/project-query/project-query-format.d.ts +2 -1
  419. package/queries/catalog/provenance-query/provenance-query-format.d.ts +1 -0
  420. package/queries/catalog/provenance-query/provenance-query-format.js +1 -0
  421. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -0
  422. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -0
  423. package/queries/catalog/signature-query/signature-query-executor.d.ts +9 -6
  424. package/queries/catalog/signature-query/signature-query-executor.js +14 -15
  425. package/queries/catalog/signature-query/signature-query-format.d.ts +21 -20
  426. package/queries/catalog/signature-query/signature-query-render.js +1 -1
  427. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  428. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +9 -5
  429. package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
  430. package/queries/query-function-filter.d.ts +1 -1
  431. package/queries/query.d.ts +59 -8
  432. package/queries/query.js +59 -37
  433. package/r-bridge/data/data.d.ts +39 -28
  434. package/r-bridge/data/data.js +37 -28
  435. package/r-bridge/lang-4.x/ast/model/model.d.ts +10 -1
  436. package/r-bridge/lang-4.x/ast/model/model.js +30 -0
  437. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +21 -0
  438. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +25 -2
  439. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -1
  440. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -2
  441. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +2 -2
  442. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  443. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  444. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  445. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  446. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +4 -3
  447. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  448. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  449. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  450. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  451. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  452. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  453. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  454. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  455. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  456. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +5 -6
  457. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +2 -7
  458. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  459. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -2
  460. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +2 -2
  461. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  462. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -5
  463. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +7 -2
  464. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +14 -6
  465. package/r-bridge/lang-4.x/ast/model/processing/visitor.d.ts +1 -1
  466. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +2 -2
  467. package/r-bridge/lang-4.x/ast/model/type.d.ts +1 -1
  468. package/r-bridge/lang-4.x/ast/model/type.js +1 -1
  469. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -2
  470. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -2
  471. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  472. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +3 -2
  473. package/r-bridge/parser.d.ts +8 -2
  474. package/r-bridge/parser.js +6 -0
  475. package/r-bridge/shell-executor.d.ts +2 -2
  476. package/r-bridge/shell-executor.js +3 -2
  477. package/r-bridge/shell.d.ts +2 -2
  478. package/r-bridge/shell.js +3 -2
  479. package/reconstruct/auto-select/magic-comments.js +1 -1
  480. package/reconstruct/reconstruct.d.ts +0 -5
  481. package/reconstruct/reconstruct.js +6 -5
  482. package/search/flowr-search-builder.d.ts +14 -0
  483. package/search/flowr-search-builder.js +7 -0
  484. package/search/flowr-search-executor.js +2 -2
  485. package/search/flowr-search-filters.js +8 -9
  486. package/search/flowr-search.js +1 -1
  487. package/search/search-executor/search-enrichers.d.ts +2 -0
  488. package/search/search-executor/search-enrichers.js +6 -1
  489. package/search/search-executor/search-generators.d.ts +2 -2
  490. package/search/search-executor/search-generators.js +13 -8
  491. package/search/search-executor/search-mappers.js +1 -1
  492. package/search/search-executor/search-transformer.d.ts +2 -2
  493. package/search/search-executor/search-transformer.js +6 -6
  494. package/slicing/criterion/parse.d.ts +2 -1
  495. package/slicing/criterion/parse.js +2 -1
  496. package/slicing/static/removal-slice.js +2 -1
  497. package/slicing/static/slice-call.d.ts +30 -4
  498. package/slicing/static/slice-call.js +74 -9
  499. package/slicing/static/slicer-types.d.ts +2 -1
  500. package/slicing/static/static-slicer.js +66 -11
  501. package/slicing/static/visiting-queue.d.ts +2 -0
  502. package/slicing/static/visiting-queue.js +4 -0
  503. package/taint-analysis/builder/report-template.d.ts +3 -3
  504. package/util/arg-matching.d.ts +1 -1
  505. package/util/collections/relation.d.ts +23 -0
  506. package/util/collections/relation.js +63 -0
  507. package/util/fixpoint.d.ts +65 -0
  508. package/util/fixpoint.js +216 -0
  509. package/util/flowr-version.d.ts +1 -1
  510. package/util/flowr-version.js +2 -2
  511. package/util/json.d.ts +4 -0
  512. package/util/json.js +12 -3
  513. package/util/mermaid/cfg.js +1 -2
  514. package/util/mermaid/dfg.d.ts +1 -1
  515. package/util/mermaid/dfg.js +1 -1
  516. package/util/mermaid/mermaid.d.ts +2 -1
  517. package/util/monoid.d.ts +26 -0
  518. package/util/monoid.js +31 -0
  519. package/util/prefix.d.ts +1 -1
  520. package/util/r-base-packages.d.ts +10 -7
  521. package/util/r-base-packages.js +11 -6
  522. package/util/r-package-urls.d.ts +10 -9
  523. package/util/r-value.js +2 -1
  524. package/util/r-version-order.d.ts +2 -0
  525. package/util/r-version-order.js +19 -0
  526. package/util/r-version.d.ts +2 -1
  527. package/util/r-version.js +2 -14
  528. package/util/range.d.ts +38 -29
  529. package/util/range.js +10 -5
  530. package/util/simple-df/dfg-ascii.js +2 -2
  531. package/util/text/ansi.d.ts +13 -9
  532. package/util/text/ansi.js +4 -6
  533. package/util/text/strings.d.ts +10 -3
  534. package/util/text/strings.js +10 -1
  535. package/util/version.d.ts +1 -1
  536. package/util/version.js +2 -1
  537. package/dataflow/environments/default-builtin-config.d.ts +0 -8874
  538. package/dataflow/environments/default-builtin-config.js +0 -1737
  539. package/r-bridge/lang-4.x/ast/model/operators.d.ts +0 -33
  540. package/r-bridge/lang-4.x/ast/model/operators.js +0 -54
  541. package/taint-analysis/eval/eval.d.ts +0 -1
  542. package/taint-analysis/eval/eval.js +0 -124
  543. package/taint-analysis/eval/instrumentation.d.ts +0 -59
  544. package/taint-analysis/eval/instrumentation.js +0 -124
@@ -5,13 +5,13 @@ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/
5
5
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
6
6
  import type { DataflowInformation } from '../../../../../info';
7
7
  import type { DataflowProcessorInformation } from '../../../../../processor';
8
- import type { REnvironmentInformation } from '../../../../../environments/environment';
8
+ import { type REnvironmentInformation } from '../../../../../environments/environment';
9
9
  import type { ClassDeclarationConfig } from '../../../../../fn/class-declaration';
10
10
  /** Processes an `R6Class`/`setRefClass` generator call, tagging it so the assignment layer can record its method list. */
11
11
  export declare function processClassGenerator<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config?: {
12
12
  readonly classDecl?: ClassDeclarationConfig;
13
13
  }): DataflowInformation;
14
- /** The method env of a class generator's `public`/`methods` `list(...)` (via {@link resolveListToEnvState}); `undefined` if absent. */
14
+ /** The env an instance of a class generator's class carries: its `public`/`methods` and `fields`/`private` lists (via {@link resolveListToEnvState}), or an empty one, as every R6 or reference class object is an environment, shared by every variable holding it. */
15
15
  export declare function resolveClassMethodsToEnvState<OtherInfo>(source: RNode<OtherInfo & ParentInformation>, data: Pick<DataflowProcessorInformation<never>, 'environment'>): REnvironmentInformation | undefined;
16
16
  /** The method env an instance from `<Cls>$new(...)`/`<Cls>[["new"]](...)` carries, from the generator's recorded `returnsEnvState`; `undefined` otherwise. */
17
17
  export declare function resolveConstructorInstanceEnvState<OtherInfo>(source: RNode<OtherInfo & ParentInformation>, data: Pick<DataflowProcessorInformation<never>, 'environment'>): REnvironmentInformation | undefined;
@@ -7,6 +7,7 @@ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model
7
7
  const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
8
8
  const known_call_handling_1 = require("../known-call-handling");
9
9
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
10
+ const environment_1 = require("../../../../../environments/environment");
10
11
  const built_in_list_1 = require("./built-in-list");
11
12
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
12
13
  const identifier_1 = require("../../../../../environments/identifier");
@@ -27,7 +28,7 @@ function processClassGenerator(name, args, rootId, data, config) {
27
28
  (0, built_in_s_four_1.linkS4Declaration)(info, rootId, data);
28
29
  return info;
29
30
  }
30
- /** The method env of a class generator's `public`/`methods` `list(...)` (via {@link resolveListToEnvState}); `undefined` if absent. */
31
+ /** The env an instance of a class generator's class carries: its `public`/`methods` and `fields`/`private` lists (via {@link resolveListToEnvState}), or an empty one, as every R6 or reference class object is an environment, shared by every variable holding it. */
31
32
  function resolveClassMethodsToEnvState(source, data) {
32
33
  if (!r_function_call_1.RFunctionCall.isNamed(source)) {
33
34
  return undefined;
@@ -39,7 +40,7 @@ function resolveClassMethodsToEnvState(source, data) {
39
40
  const resolved = list === undefined ? undefined : (0, built_in_list_1.resolveListToEnvState)(list, envState ? { environment: envState } : data, values);
40
41
  envState = resolved ?? envState;
41
42
  }
42
- return envState;
43
+ return envState ?? environment_1.REnvironment.pushLocal(data.environment);
43
44
  }
44
45
  const ConstructorField = 'new';
45
46
  /** The method env an instance from `<Cls>$new(...)`/`<Cls>[["new"]](...)` carries, from the generator's recorded `returnsEnvState`; `undefined` otherwise. */
@@ -0,0 +1,15 @@
1
+ import type { DataflowProcessorInformation } from '../../../../../processor';
2
+ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
3
+ import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ import type { DataflowGraph } from '../../../../../graph/graph';
5
+ import { type DataflowGraphVertexFunctionDefinition, type DeferredEnvOp } from '../../../../../graph/vertex';
6
+ import { type REnvironmentInformation } from '../../../../../environments/environment';
7
+ import type { ReadOnlyFlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
8
+ /** The calls of a function body `roots` whose environment operation depends on the call of the function: a name not written down, or a read or removal in an environment the body does not bind (what a body defines in such an environment under a name written down already reaches the caller, see {@link InGraphIdentifierDefinition#envWrites}). */
9
+ export declare function deferredEnvOps<OtherInfo>(roots: Iterable<NodeId>, graph: DataflowGraph, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DeferredEnvOp[] | undefined;
10
+ /** Runs the {@link deferredEnvOps} of the function `fn` for the call `call`, which runs `fn` itself or through the `chain` of calls in the functions it runs, the last one calling `fn`: the names they compute from parameters resolve with the values the call of `fn` hands over, and an environment a free variable or a parameter names is the one it holds at `call`, if `call` runs `fn` itself, else only the global environment is known to be the same. */
11
+ export declare function instantiateEnvOps(call: NodeId, fn: DataflowGraphVertexFunctionDefinition, chain: readonly NodeId[], environment: REnvironmentInformation, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext): REnvironmentInformation;
12
+ /** Whether the call `call` of `fn` replayed the replacement or assignment `write` of its body (see {@link EnvOpKind.Replace} and {@link EnvOpKind.Define}) into the environment it hands over, so what it writes is known there. */
13
+ export declare function replayedAt(write: NodeId, fn: DataflowGraphVertexFunctionDefinition, call: NodeId, graph: DataflowGraph): boolean;
14
+ /** The definitions the function `fn` makes in the frame of its caller (`assign("x", v, envir = parent.frame())`) for the call `call` within another function: the reads of that frame may see them, which the frame does not know of when it is processed, as it learns of the callee later (the top level runs them in {@link instantiateEnvOps}). */
15
+ export declare function linkCallerFrameWrites(call: NodeId, fn: DataflowGraphVertexFunctionDefinition, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext): void;
@@ -0,0 +1,416 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deferredEnvOps = deferredEnvOps;
4
+ exports.instantiateEnvOps = instantiateEnvOps;
5
+ exports.replayedAt = replayedAt;
6
+ exports.linkCallerFrameWrites = linkCallerFrameWrites;
7
+ const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
8
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
9
+ const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
10
+ const r_number_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-number");
11
+ const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
12
+ const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
13
+ const model_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/model");
14
+ const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
15
+ const vertex_1 = require("../../../../../graph/vertex");
16
+ const edge_1 = require("../../../../../graph/edge");
17
+ const df_helper_1 = require("../../../../../graph/df-helper");
18
+ const function_semantics_1 = require("../../../../../fn/function-semantics");
19
+ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
20
+ const environment_1 = require("../../../../../environments/environment");
21
+ const identifier_1 = require("../../../../../environments/identifier");
22
+ const resolve_helper_1 = require("../../../../../environments/resolve-helper");
23
+ const apply_kill_1 = require("../../../../../environments/apply-kill");
24
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
25
+ const linker_1 = require("../../../../linker");
26
+ const shared_configs_1 = require("../../../../../environments/default-builtin-config/shared-configs");
27
+ const built_in_stack_env_1 = require("./built-in-stack-env");
28
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
29
+ const r_binary_op_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
30
+ const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
31
+ const OpOfProcessor = {
32
+ [built_in_proc_name_1.BuiltInProcName.Assignment]: vertex_1.EnvOpKind.Define,
33
+ [built_in_proc_name_1.BuiltInProcName.Get]: vertex_1.EnvOpKind.Read,
34
+ [built_in_proc_name_1.BuiltInProcName.Rm]: vertex_1.EnvOpKind.Remove
35
+ };
36
+ /** The formal of `rm` naming what it removes by value, its `...` names them unevaluated. */
37
+ const RemovedByValue = 'list';
38
+ /** The calls of a function body `roots` whose environment operation depends on the call of the function: a name not written down, or a read or removal in an environment the body does not bind (what a body defines in such an environment under a name written down already reaches the caller, see {@link InGraphIdentifierDefinition#envWrites}). */
39
+ function deferredEnvOps(roots, graph, data) {
40
+ let ops;
41
+ for (const id of roots) {
42
+ const vertex = graph.getVertex(id);
43
+ const node = data.completeAst.idMap.get(id);
44
+ if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.TableAssignment)) {
45
+ /* `t[, a := v]` changes the table the parameter `t` holds, which is the caller's */
46
+ for (const target of df_helper_1.Dataflow.sourcesOf(graph, id, edge_1.EdgeType.DefinedBy).filter(t => heldByParameter(t, graph, data.completeAst.idMap))) {
47
+ (ops ??= []).push({ id: target, kind: vertex_1.EnvOpKind.ChangeInPlace, names: [], literals: [], envir: target, returns: false });
48
+ }
49
+ continue;
50
+ }
51
+ else if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Replacement)) {
52
+ const op = replacementOf(id, node, graph, data.completeAst.idMap, data.environment);
53
+ if (op !== undefined) {
54
+ (ops ??= []).push(op);
55
+ }
56
+ continue;
57
+ }
58
+ else if (!vertex_1.DfgVertex.isFunctionCall(vertex) || !r_function_call_1.RFunctionCall.isNamed(node)) {
59
+ continue;
60
+ }
61
+ const defs = df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Calls).some(t => !node_id_1.NodeId.isBuiltIn(t)) ? undefined : resolve_helper_1.Resolve.byNameAndType(node.functionName.content, data.environment, identifier_1.ReferenceType.Function);
62
+ const builtIn = defs?.length === 1 && defs[0].type === identifier_1.ReferenceType.BuiltInFunction ? defs[0] : undefined;
63
+ if (builtIn?.processorName === built_in_proc_name_1.BuiltInProcName.Local && builtIn.config !== undefined) {
64
+ const evaluated = evaluatedDefinitions(node, builtIn.config, graph, data.completeAst.idMap, data.environment);
65
+ if (evaluated.length > 0) {
66
+ (ops ??= []).push(...evaluated);
67
+ }
68
+ continue;
69
+ }
70
+ const kind = builtIn?.processorName === undefined ? undefined : OpOfProcessor[builtIn.processorName];
71
+ const config = builtIn?.config;
72
+ if (kind === undefined || config?.sig === undefined || (kind === vertex_1.EnvOpKind.Define && config.targetVariable !== true)) {
73
+ continue;
74
+ }
75
+ const formals = config.sig.map(([name]) => name);
76
+ const bound = function_semantics_1.FunctionSemantics.call.match.toNames(node.arguments, formals);
77
+ const named = r_argument_1.RArgument.valueOf(bound.get(kind === vertex_1.EnvOpKind.Remove ? RemovedByValue : formals[0]));
78
+ const envir = r_argument_1.RArgument.valueOf(bound.get('envir'));
79
+ /* `rm` takes the names in its `...` as written */
80
+ const literals = kind === vertex_1.EnvOpKind.Remove ? node.arguments.flatMap(a => r_argument_1.RArgument.isEmpty(a) || (a.name !== undefined && formals.includes(a.name.content)) ? [] : [literalName(a.value)]) : [];
81
+ const computed = named !== undefined && !r_string_1.RString.is(named);
82
+ /* without an environment, the operation works on the frame of the call, which no caller sees */
83
+ if (envir === undefined || (named === undefined && literals.length === 0) || literals.includes(undefined)
84
+ || (kind === vertex_1.EnvOpKind.Define && !computed && !heldByParameter(envir.info.id, graph, data.completeAst.idMap) && callerGenerations(envir, data.environment, graph, data.completeAst.idMap) === undefined)) {
85
+ continue;
86
+ }
87
+ (ops ??= []).push({
88
+ id,
89
+ kind,
90
+ names: named === undefined ? [] : [named.info.id],
91
+ literals: literals,
92
+ envir: envir.info.id,
93
+ value: kind === vertex_1.EnvOpKind.Define ? r_argument_1.RArgument.valueOf(bound.get(formals[1]))?.info.id : undefined,
94
+ returns: config.returnsValue !== false
95
+ });
96
+ }
97
+ return ops;
98
+ }
99
+ /** What `local(expr, envir)` and `evalq(expr, envir)` define in an environment a parameter holds: the body evaluates `expr` in a frame of its own, as it cannot know the environment, its call defines into the one it hands over. */
100
+ function evaluatedDefinitions(node, config, graph, idMap, environment) {
101
+ const bound = function_semantics_1.FunctionSemantics.call.match.toNames(node.arguments, [config.args.expr, config.args.env]);
102
+ const envir = r_argument_1.RArgument.valueOf(bound.get(config.args.env));
103
+ const expr = r_argument_1.RArgument.valueOf(bound.get(config.args.expr));
104
+ if (expr === undefined || envir === undefined || !(heldByParameter(envir.info.id, graph, idMap) || callerGenerations(envir, environment, graph, idMap) !== undefined)) {
105
+ return [];
106
+ }
107
+ const ops = [];
108
+ for (const id of model_1.RNode.collectAllIdsWithStop(expr, r_function_definition_1.RFunctionDefinition.is)) {
109
+ const name = literalName(idMap.get(id));
110
+ /* a super assignment defines outside the evaluation */
111
+ if (name !== undefined && vertex_1.DfgVertex.isVariableDefinition(graph.getVertex(id)) && !df_helper_1.Dataflow.definedBySuperAssignment(graph, id)) {
112
+ ops.push({ id: node.info.id, kind: vertex_1.EnvOpKind.Define, names: [], literals: [name], envir: envir.info.id, value: id, returns: true });
113
+ }
114
+ }
115
+ return ops;
116
+ }
117
+ /** `env$x <- value` or `env[["x"]] <- value` in a body where `env` is a parameter: the call decides whether it writes into an environment the caller holds or into a copy of a list, see {@link EnvOpKind.Replace}. */
118
+ function replacementOf(id, node, graph, idMap, environment) {
119
+ const access = r_access_1.RAccess.is(node) ? node : undefined;
120
+ const assignment = access && model_1.RNode.directParent(access, idMap);
121
+ const value = r_binary_op_1.RBinaryOp.is(assignment) && assignment.lhs === access && ReplacedBy.has(assignment.operator) ? assignment.rhs : undefined;
122
+ const target = value !== undefined && r_symbol_1.RSymbol.is(access?.accessed) ? access : undefined;
123
+ const field = target !== undefined && target.access.length === 1 && FieldAccess.has(target.operator) ? r_argument_1.RArgument.valueOf(target.access[0]) : undefined;
124
+ if (target === undefined || field === undefined || !(heldByParameter(target.accessed.info.id, graph, idMap) || callerGenerations(target.accessed, environment, graph, idMap) !== undefined)) {
125
+ return undefined;
126
+ }
127
+ const literal = target.operator === '$' || r_string_1.RString.is(field) ? literalName(field) : undefined;
128
+ return { id, kind: vertex_1.EnvOpKind.Replace, names: literal === undefined ? [field.info.id] : [], literals: literal === undefined ? [] : [literal], envir: target.accessed.info.id, value: value?.info.id, returns: true };
129
+ }
130
+ /** the assignments a replacement rebinds its target in the frame of the body with */
131
+ const ReplacedBy = new Set(['<-', '=']);
132
+ /** the accesses naming a single variable of an environment */
133
+ const FieldAccess = new Set(['$', '[[']);
134
+ /** Whether `id` reads a parameter, which holds what the call hands over (the body cannot know the environment it may hold). */
135
+ function heldByParameter(id, graph, idMap) {
136
+ const closure = frameOf(idMap.get(id));
137
+ const held = readBindings(closure?.info.id ?? id, graph);
138
+ return held.length === 1 && idMap.get(held[0])?.info.role === "param-n" /* RoleInParent.ParameterName */;
139
+ }
140
+ /** What `id` reads, the target of a replacement (`env$x <- v`) reads the variable it rebinds besides the replacement itself. */
141
+ function readBindings(id, graph) {
142
+ return df_helper_1.Dataflow.targetsOf(graph, id, edge_1.EdgeType.Reads).filter(t => !vertex_1.DfgVertex.isFunctionCall(graph.getVertex(t)));
143
+ }
144
+ /** How many calls up the frame `node` names lies: 1 for the caller (`parent.frame()`, directly or by a variable bound to it only), `n` for `parent.frame(n)` with a constant `n`, `undefined` for any other environment. */
145
+ function callerGenerations(node, environment, graph, idMap) {
146
+ if (!r_symbol_1.RSymbol.is(node)) {
147
+ return frameGenerations(node, environment);
148
+ }
149
+ const held = readBindings(node.info.id, graph).map(d => frameGenerations(idMap.get(df_helper_1.Dataflow.assignedValueOf(d, graph) ?? ''), environment));
150
+ return held.length > 0 && held.every(g => g !== undefined && g === held[0]) ? held[0] : undefined;
151
+ }
152
+ /** {@link callerGenerations} of a `parent.frame` call itself. */
153
+ function frameGenerations(node, environment) {
154
+ if ((0, built_in_stack_env_1.stackEnvKindOf)(node, { environment }) === shared_configs_1.StackEnvKind.CallerFrame) {
155
+ return 1;
156
+ }
157
+ const call = r_function_call_1.RFunctionCall.isNamed(node, 'parent.frame') && node.arguments.length === 1 ? node : undefined;
158
+ const count = call === undefined ? undefined : r_argument_1.RArgument.valueOf(call.arguments[0]);
159
+ const n = r_number_1.RNumber.is(count) ? count.content.num : undefined;
160
+ return call !== undefined && n !== undefined && Number.isInteger(n) && n > 1 && resolve_helper_1.Resolve.isBuiltIn(call.functionName.content, environment, identifier_1.ReferenceType.Function) ? n : undefined;
161
+ }
162
+ /** The closure whose frame `environment(fn)` names, see {@link closureFrameResolution}. */
163
+ function frameOf(node) {
164
+ const fn = r_function_call_1.RFunctionCall.isNamed(node, 'environment') && node.arguments.length === 1 ? r_argument_1.RArgument.valueOf(node.arguments[0]) : undefined;
165
+ return r_symbol_1.RSymbol.is(fn) ? fn : undefined;
166
+ }
167
+ function literalName(node) {
168
+ return r_symbol_1.RSymbol.is(node) ? identifier_1.Identifier.getName(node.content) : r_string_1.RString.is(node) ? node.content.str : undefined;
169
+ }
170
+ /** The parameter of the function run that `id` reads, if it reads just that. */
171
+ function parameterReadBy(id, { fn, graph }) {
172
+ const vertex = graph.getVertex(id);
173
+ const bindings = vertex_1.DfgVertex.isUse(vertex) || (vertex_1.DfgVertex.isVariableDefinition(vertex) && vertex.par) ? readBindings(id, graph) : [];
174
+ return bindings.length === 1 && Object.hasOwn(fn.params, bindings[0]) ? bindings[0] : undefined;
175
+ }
176
+ /** What the call hands to `parameter`, matched as R matches arguments. */
177
+ function handedTo(parameter, { fn, via, graph, idMap }) {
178
+ const call = graph.getVertex(via);
179
+ if (!vertex_1.DfgVertex.isFunctionCall(call)) {
180
+ return [];
181
+ }
182
+ const formals = {};
183
+ for (const p of Object.keys(fn.params)) {
184
+ const name = idMap.get(node_id_1.NodeId.normalize(p));
185
+ if (r_symbol_1.RSymbol.is(name)) {
186
+ formals[identifier_1.Identifier.getName(name.content)] = name.info.id;
187
+ }
188
+ }
189
+ return (function_semantics_1.FunctionSemantics.call.match.toSpec(call.args, formals).get(parameter) ?? []).map(a => r_argument_1.RArgument.valueOf(idMap.get(a))?.info.id ?? a);
190
+ }
191
+ /** What the call hands over for `id`, if that just reads a parameter, else `id` itself. */
192
+ function valueAt(id, run) {
193
+ const parameter = parameterReadBy(id, run);
194
+ const handed = parameter === undefined ? [] : handedTo(parameter, run);
195
+ return handed.length === 1 ? handed[0] : id;
196
+ }
197
+ function envAtCall(envir, environment, run) {
198
+ const node = run.idMap.get(envir);
199
+ const stack = (0, built_in_stack_env_1.stackEnvKindOf)(node, { environment });
200
+ /* run by a call of another function, only the global environment is the same for both */
201
+ if (stack === shared_configs_1.StackEnvKind.Global) {
202
+ return stack;
203
+ }
204
+ else if (run.direct && callerGenerations(node, environment, run.graph, run.idMap) === 1) {
205
+ return shared_configs_1.StackEnvKind.CallerFrame;
206
+ }
207
+ const closure = frameOf(node);
208
+ const symbol = closure ?? node;
209
+ if (!r_symbol_1.RSymbol.is(symbol)) {
210
+ return undefined;
211
+ }
212
+ /* a parameter holds what the call hands over, any other binding of the body is its own */
213
+ const bound = readBindings(symbol.info.id, run.graph).some(b => run.fn.subflow.graph.has(b));
214
+ /* a free variable of a function defined at the top is a global one, which a call at the top sees as the function does */
215
+ if (!run.direct && (bound || environment.level > 0 || model_1.RNode.strictlyEnclosingFunction(run.fn.id, run.idMap) !== undefined)) {
216
+ return undefined;
217
+ }
218
+ const handed = bound ? run.idMap.get(valueAt(symbol.info.id, run)) : symbol;
219
+ /* the call may hand over the frame of a closure itself, `put(environment(g))` */
220
+ const handedFrame = handed === symbol ? undefined : frameOf(handed);
221
+ const held = handedFrame ?? handed;
222
+ if (!r_symbol_1.RSymbol.is(held) || (held === symbol && bound)) {
223
+ return undefined;
224
+ }
225
+ else if (closure !== undefined || handedFrame !== undefined) {
226
+ /* the frame of the closure the variable holds, tracked on the variable, see `closureFrameResolution` */
227
+ const defs = resolve_helper_1.Resolve.byName(held.content, environment);
228
+ const def = defs?.length === 1 && !node_id_1.NodeId.isBuiltIn(defs[0].definedAt) ? defs[0] : undefined;
229
+ return def === undefined ? undefined : { holders: [{ ...def, envState: def.envState ?? environment_1.REnvironment.pushLocal(environment), envId: def.envId ?? def.nodeId, closureFrame: true }] };
230
+ }
231
+ const holders = resolve_helper_1.Resolve.byNameAndType(held.content, environment, identifier_1.ReferenceType.Variable);
232
+ if (holders === undefined || holders.length === 0 || !holders.every(h => (0, identifier_1.hasEnvState)(h) && h.name !== undefined && h.closureFrame !== true)) {
233
+ return undefined;
234
+ }
235
+ return { holders: holders };
236
+ }
237
+ /** Each function the calls `calls` run on the way to `fn`, the last one calling `fn`, with the call running it. */
238
+ function contextOfChain(calls, fn, idMap) {
239
+ const context = new Map([[fn, calls[calls.length - 1]]]);
240
+ for (let i = 0; i < calls.length - 1; i++) {
241
+ const runs = model_1.RNode.strictlyEnclosingFunction(calls[i + 1], idMap);
242
+ if (runs !== undefined) {
243
+ context.set(runs, calls[i]);
244
+ }
245
+ }
246
+ return context;
247
+ }
248
+ /** The names `name` computes in the run: a parameter takes what the call hands over, anything else is resolved for the call it runs in. */
249
+ function namesAt(name, run, ctx) {
250
+ const node = run.idMap.get(name);
251
+ if (r_string_1.RString.is(node)) {
252
+ return [node.content.str];
253
+ }
254
+ const info = resolve_helper_1.Resolve.info(run.graph, ctx);
255
+ const parameter = parameterReadBy(name, run);
256
+ if (parameter !== undefined) {
257
+ const handed = handedTo(parameter, run);
258
+ const names = handed.map(a => node_value_1.NodeValue.stringsOf(a, { ...info, callContext: run.context }));
259
+ return handed.length === 0 || names.includes(undefined) ? undefined : names.flat();
260
+ }
261
+ return node_value_1.NodeValue.stringsOf(name, { ...info, callContext: run.context });
262
+ }
263
+ /** Runs the {@link deferredEnvOps} of the function `fn` for the call `call`, which runs `fn` itself or through the `chain` of calls in the functions it runs, the last one calling `fn`: the names they compute from parameters resolve with the values the call of `fn` hands over, and an environment a free variable or a parameter names is the one it holds at `call`, if `call` runs `fn` itself, else only the global environment is known to be the same. */
264
+ function instantiateEnvOps(call, fn, chain, environment, graph, ctx) {
265
+ const idMap = graph.idMap;
266
+ if (fn.envOps === undefined || idMap === undefined) {
267
+ return environment;
268
+ }
269
+ const calls = [call, ...chain];
270
+ const run = { fn, via: chain.at(-1) ?? call, direct: chain.length === 0, graph, idMap, context: contextOfChain(calls, fn.id, idMap) };
271
+ const callCds = graph.getVertex(call)?.cds;
272
+ for (const op of fn.envOps) {
273
+ if (op.kind === vertex_1.EnvOpKind.ChangeInPlace) {
274
+ environment = changeInPlaceAt(op, run, call, environment);
275
+ continue;
276
+ }
277
+ const names = op.names.map(n => namesAt(n, run, ctx));
278
+ const at = envAtCall(op.envir, environment, run);
279
+ if (at === undefined || names.some(n => n === undefined || n.length === 0) || (op.kind === vertex_1.EnvOpKind.Replace && at !== shared_configs_1.StackEnvKind.CallerFrame && (typeof at !== 'object' || !at.holders.every(h => h.closureFrame === true || (0, built_in_envir_utils_1.holdsValueOf)(h, graph, built_in_envir_utils_1.EnvironmentProducers))))) {
280
+ continue;
281
+ }
282
+ const all = [...op.literals, ...names.flat()];
283
+ const holders = typeof at === 'object' ? at.holders : [];
284
+ /* with several names or environments, each is only maybe the one */
285
+ const cds = callCds ?? (all.length > 1 || holders.length > 1 ? [] : undefined);
286
+ /* what a call within another function hands over is kept by that call only, which a slice reaches through the value in the body */
287
+ const value = op.value === undefined || !run.direct ? op.value : valueAt(op.value, run);
288
+ /* every call on the way makes the change */
289
+ for (const c of op.kind === vertex_1.EnvOpKind.Read ? [] : calls) {
290
+ graph.addEdge(value ?? op.id, c, edge_1.EdgeType.SideEffectOnCall);
291
+ }
292
+ environment = applyOp(op, value, all, at, environment, cds, call, graph);
293
+ }
294
+ return environment;
295
+ }
296
+ /** Binds the variable the call hands to the parameter of the {@link EnvOpKind.ChangeInPlace} `op`, and what else holds its object, to the change. */
297
+ function changeInPlaceAt(op, run, call, environment) {
298
+ const parameter = run.direct ? readBindings(op.envir, run.graph).find(b => Object.hasOwn(run.fn.params, b)) : undefined;
299
+ const args = parameter === undefined ? [] : handedTo(parameter, run);
300
+ const handed = args.length === 1 ? run.idMap.get(args[0]) : undefined;
301
+ if (!r_symbol_1.RSymbol.is(handed)) {
302
+ return environment;
303
+ }
304
+ run.graph.addEdge(op.id, call, edge_1.EdgeType.SideEffectOnCall);
305
+ const [rebound] = (0, built_in_envir_utils_1.rebindAliases)(environment, handed.content, op.id, call);
306
+ /* the caller's variable may still hold the table as it was, the change joins its binding */
307
+ return environment_1.REnvironment.define({ name: handed.content, nodeId: op.id, definedAt: call, type: identifier_1.ReferenceType.Variable, cds: [] }, false, rebound);
308
+ }
309
+ function applyOp(op, value, names, at, environment, cds, call, graph) {
310
+ const update = (state, global, closureFrame = false) => {
311
+ switch (op.kind) {
312
+ case vertex_1.EnvOpKind.Define:
313
+ case vertex_1.EnvOpKind.Replace: {
314
+ let next = state;
315
+ const type = referenceTypeOf(value === undefined ? undefined : graph.getVertex(value), graph);
316
+ for (const name of names) {
317
+ next = environment_1.REnvironment.define({ name, nodeId: value ?? op.id, definedAt: value === undefined ? op.id : call, type, cds }, global && next.level > 0, next);
318
+ }
319
+ return next;
320
+ }
321
+ case vertex_1.EnvOpKind.Remove: {
322
+ const kills = names.map(name => ({ kind: 'named', reference: { nodeId: op.id, name, cds, type: identifier_1.ReferenceType.Variable }, killedBy: op.id }));
323
+ /* the frame of a closure records the removal, see `removeFromCustomEnv` */
324
+ return global ? (0, apply_kill_1.applyGlobalKills)(state, kills) : (0, apply_kill_1.applyKills)(state, kills, closureFrame);
325
+ }
326
+ case vertex_1.EnvOpKind.Read: {
327
+ const found = [];
328
+ for (const def of names.flatMap(name => resolve_helper_1.Resolve.byName(name, state) ?? [])) {
329
+ if (!node_id_1.NodeId.isBuiltIn(def.nodeId)) {
330
+ graph.addEdge(op.id, def.nodeId, op.returns ? edge_1.EdgeType.Reads | edge_1.EdgeType.Returns : edge_1.EdgeType.Reads);
331
+ found.push(def.nodeId);
332
+ }
333
+ }
334
+ (0, linker_1.recordFound)(graph, op.id, found, call);
335
+ return state;
336
+ }
337
+ case vertex_1.EnvOpKind.ChangeInPlace:
338
+ /* replayed by `changeInPlaceAt`, it names no environment */
339
+ return state;
340
+ }
341
+ };
342
+ if (at === shared_configs_1.StackEnvKind.Global || at === shared_configs_1.StackEnvKind.CallerFrame) {
343
+ return update(environment, at === shared_configs_1.StackEnvKind.Global);
344
+ }
345
+ for (const holder of at.holders) {
346
+ environment = (0, built_in_envir_utils_1.rebindHolders)(environment, holder, update(holder.envState, false, holder.closureFrame === true), call);
347
+ }
348
+ return environment;
349
+ }
350
+ /** Whether the call `call` of `fn` replayed the replacement or assignment `write` of its body (see {@link EnvOpKind.Replace} and {@link EnvOpKind.Define}) into the environment it hands over, so what it writes is known there. */
351
+ function replayedAt(write, fn, call, graph) {
352
+ const op = fn.envOps?.find(o => o.id === write && (o.kind === vertex_1.EnvOpKind.Replace || o.kind === vertex_1.EnvOpKind.Define));
353
+ if (op?.value === undefined || graph.idMap === undefined) {
354
+ return false;
355
+ }
356
+ const value = valueAt(op.value, { fn, via: call, direct: true, graph, idMap: graph.idMap });
357
+ return df_helper_1.Dataflow.hasEdge(graph, value, call, edge_1.EdgeType.SideEffectOnCall);
358
+ }
359
+ /** What a definition of the value `vertex` binds, as an assignment does: a function, a value, or what a read, call, or other definition hands on. */
360
+ function referenceTypeOf(vertex, graph) {
361
+ if (vertex_1.DfgVertex.isFunctionDefinition(vertex)) {
362
+ return identifier_1.ReferenceType.Function;
363
+ }
364
+ else if (vertex_1.DfgVertex.isVariableDefinition(vertex)) {
365
+ return df_helper_1.Dataflow.targetsOf(graph, vertex.id, edge_1.EdgeType.DefinedBy).some(t => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t))) ? identifier_1.ReferenceType.Function : identifier_1.ReferenceType.Unknown;
366
+ }
367
+ return vertex_1.DfgVertex.isUse(vertex) || vertex_1.DfgVertex.isFunctionCall(vertex) ? identifier_1.ReferenceType.Unknown : identifier_1.ReferenceType.Variable;
368
+ }
369
+ /** The definitions the function `fn` makes in the frame of its caller (`assign("x", v, envir = parent.frame())`) for the call `call` within another function: the reads of that frame may see them, which the frame does not know of when it is processed, as it learns of the callee later (the top level runs them in {@link instantiateEnvOps}). */
370
+ function linkCallerFrameWrites(call, fn, graph, ctx) {
371
+ const idMap = graph.idMap;
372
+ const enclosing = idMap === undefined ? undefined : model_1.RNode.strictlyEnclosingFunction(call, idMap);
373
+ const frame = enclosing === undefined ? undefined : idMap?.get(enclosing);
374
+ if (fn.envOps === undefined || idMap === undefined || !r_function_definition_1.RFunctionDefinition.is(frame)) {
375
+ return;
376
+ }
377
+ const run = { fn, via: call, direct: true, graph, idMap, context: contextOfChain([call], fn.id, idMap) };
378
+ for (const op of fn.envOps) {
379
+ const generations = op.kind === vertex_1.EnvOpKind.Read || op.kind === vertex_1.EnvOpKind.Remove ? undefined : op.generations ?? callerGenerations(idMap.get(op.envir), fn.subflow.environment, graph, idMap);
380
+ if (generations === undefined) {
381
+ continue;
382
+ }
383
+ else if (generations > 1) {
384
+ /* `parent.frame(n)` of the callee is `parent.frame(n - 1)` of the function the call is in, which runs it by this call */
385
+ graph.addEdge(op.value ?? op.id, call, edge_1.EdgeType.SideEffectOnCall);
386
+ handOnToCallers({ ...op, generations: generations - 1 }, frame.info.id, graph, ctx);
387
+ continue;
388
+ }
389
+ const names = op.names.map(n => namesAt(n, run, ctx));
390
+ if (names.includes(undefined)) {
391
+ continue;
392
+ }
393
+ const all = new Set([...op.literals, ...names.flat()]);
394
+ const value = op.value === undefined ? op.id : valueAt(op.value, run);
395
+ graph.addEdge(value, call, edge_1.EdgeType.SideEffectOnCall);
396
+ for (const id of model_1.RNode.collectAllIdsWithStop(frame.body, r_function_definition_1.RFunctionDefinition.is)) {
397
+ const name = vertex_1.DfgVertex.isUse(graph.getVertex(id)) ? node_id_1.NodeId.recoverBareName(id, idMap) : undefined;
398
+ if (name !== undefined && all.has(name)) {
399
+ graph.addEdge(id, value, edge_1.EdgeType.Reads);
400
+ graph.addEdge(id, op.id, edge_1.EdgeType.Reads);
401
+ }
402
+ }
403
+ }
404
+ }
405
+ /** Registers `op` with the function `fn`, so the calls of it, linked already or later, replay it in their frame in turn. */
406
+ function handOnToCallers(op, fn, graph, ctx) {
407
+ const definition = graph.getVertex(fn);
408
+ if (!vertex_1.DfgVertex.isFunctionDefinition(definition) || definition.envOps?.some(o => o.id === op.id && o.generations === op.generations)) {
409
+ return;
410
+ }
411
+ definition.envOps = [...definition.envOps ?? [], op];
412
+ for (const caller of df_helper_1.Dataflow.sourcesOf(graph, fn, edge_1.EdgeType.Calls)) {
413
+ linkCallerFrameWrites(caller, definition, graph, ctx);
414
+ }
415
+ }
416
+ //# sourceMappingURL=built-in-deferred-env-ops.js.map
@@ -4,10 +4,13 @@ import type { DataflowInformation } from '../../../../../info';
4
4
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
5
  import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
6
6
  import { RFunctionCall } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
7
- import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
8
- import { Identifier, type IdentifierDefinition, type NamedInGraphIdentifierDefinition } from '../../../../../environments/identifier';
7
+ import { type EnvHolderDefinition, type BrandedIdentifier, Identifier, type IdentifierDefinition } from '../../../../../environments/identifier';
9
8
  import type { REnvironmentInformation } from '../../../../../environments/environment';
10
9
  import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
10
+ import type { DataflowGraph } from '../../../../../graph/graph';
11
+ import { type DataflowGraphVertexFunctionDefinition } from '../../../../../graph/vertex';
12
+ import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
13
+ import { BuiltInProcName } from '../../../../../environments/built-in-proc-name';
11
14
  import { FnSig } from '../../../../../environments/built-in-props';
12
15
  /** The real stack environments a resolution can name, as opposed to a tracked custom env. */
13
16
  export type StackEnv = 'global' | 'base';
@@ -16,83 +19,63 @@ export interface EnvirResolution<OtherInfo> {
16
19
  /** `data` with its `environment` replaced by the resolved `envState` for in-env lookups. */
17
20
  readonly envirData: DataflowProcessorInformation<OtherInfo & ParentInformation>;
18
21
  /** The definition of the variable that holds the environment */
19
- readonly envDef: NamedInGraphIdentifierDefinition & {
20
- envState: REnvironmentInformation;
21
- };
22
+ readonly envDef: EnvHolderDefinition;
22
23
  /** Node ID of the USE of the envir variable (e.g. the `e` in `envir=e`). */
23
24
  readonly envirNodeId: NodeId;
24
25
  /** which real stack env this resolves to, absent for a tracked custom env; only `'global'` reaches the real frame chain */
25
26
  readonly stack?: StackEnv;
26
27
  }
27
- /**
28
- * The formal parameter names of the qualified call `id` (a `pkg::fn` {@link Identifier}) from the signature
29
- * database (excluding `...`), or `fallback` when the database is disabled or does not carry the function. Lets a
30
- * built-in argument matcher use R's real signature (via {@link ReadOnlyFlowrAnalyzerDependenciesContext#signatureOf})
31
- * instead of a hardcoded formal list, while staying correct -- and graph-invariant -- when no signature is available.
32
- */
28
+ /** The formal parameter names of the qualified call `id` (a `pkg::fn` {@link Identifier}) from the signature database (excluding `...`), or `fallback` when the database is disabled or does not carry the function. */
33
29
  export declare function signatureParamNames<OtherInfo>(data: DataflowProcessorInformation<OtherInfo & ParentInformation>, id: Identifier, fallback: readonly string[]): readonly string[];
34
30
  /** desugars `lhs |> rhs(...)` one level to `rhs(lhs, ...)`, for literal-shape inspection */
35
31
  export declare function pipedCall<OtherInfo>(node: RNode<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): RFunctionCall<OtherInfo & ParentInformation> & {
36
32
  named: true;
37
33
  } | undefined;
38
- /**
39
- * The constant string a name-position node denotes at construction time (string literal, aliased variable, or
40
- * a paste-like join of such); `undefined` if any part is dynamic or the fold is user-shadowed. Unwraps one
41
- * leading pipe (the value domain does not desugar those) and otherwise defers entirely to it -- the shadow
42
- * check, the paste-like fold and its numeric/logical coercion all live there, in {@link resolveAsStringFn}.
43
- */
34
+ /** The constant string a name-position node denotes at construction time (string literal, aliased variable, or a paste-like join of such); `undefined` if any part is dynamic or the fold is user-shadowed. */
44
35
  export declare function resolveConstantString<OtherInfo>(node: RNode<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): string | undefined;
45
36
  /** The `returnsEnvState` of the first reaching definition that carries one, else `undefined`. */
46
37
  export declare function findReturnsEnvState(defs: readonly IdentifierDefinition[] | undefined): REnvironmentInformation | undefined;
47
- /**
48
- * The environment to route into, if flowR can pin one down; `'ambiguous'` when the argument names a value whose
49
- * identity is out of reach at this point (e.g. a function parameter), so routing anywhere would be unsound.
50
- */
38
+ /** The environment to route into, if flowR can pin one down; `'ambiguous'` when the argument names a value whose identity is out of reach at this point (e.g. a function parameter), so routing anywhere would be unsound. */
51
39
  export type EnvirArgRouting<OtherInfo> = EnvirResolution<OtherInfo> | 'ambiguous' | undefined;
52
40
  /** the environment `routing` pinned down, dropping the ambiguous marker. */
53
41
  export declare function envirOf<OtherInfo>(routing: EnvirArgRouting<OtherInfo>): EnvirResolution<OtherInfo> | undefined;
54
42
  /** Resolves a single already-found argument (e.g. from {@link RFunctionCall.matchArgsToParams}) to an {@link EnvirArgRouting}. */
55
43
  export declare function resolveArgToEnvirOrAmbiguous<OtherInfo>(arg: PotentiallyEmptyRArgument<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirArgRouting<OtherInfo>;
56
- /**
57
- * The slots `envir` falls back to (`envir = as.environment(pos)`), so an environment handed to one of them is the
58
- * target as well. They are tried after the envir formal itself.
59
- */
60
- export declare const EnvirPositionFormals: readonly string[];
44
+ /** `environment(fn)` names the frame the closure `fn` holds, tracked as the environment state of the variable holding the closure: what is written into the frame is read by the closure once it is called (see {@link linkClosureFrameReads}). */
45
+ export declare function closureFrameResolution<OtherInfo>(node: RNode<OtherInfo & ParentInformation> | undefined, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
46
+ /** A call of a closure whose frame was written (see {@link closureFrameResolution}) reads those writes wherever its body reads a name it does not bind itself. */
47
+ export declare function linkClosureFrameReads(call: NodeId, called: DataflowGraphVertexFunctionDefinition, environment: REnvironmentInformation, graph: DataflowGraph): void;
48
+ /** The slots `envir` falls back to (`envir = as.environment(pos)`), so an environment handed to one of them is the target as well. */
49
+ export declare const EnvirPositionFormals: readonly BrandedIdentifier[];
61
50
  /** Resolves the argument bound to `formal` (default `'envir'`) to an {@link EnvirArgRouting}. */
62
51
  export declare function resolveEnvirArgOrAmbiguous<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], data: DataflowProcessorInformation<OtherInfo & ParentInformation>, sig: FnSig | undefined, formal?: string): EnvirArgRouting<OtherInfo>;
63
- /**
64
- * Whether the call supplies an argument for any of `formals` at all, however it resolves. A `pos`/`where` that is
65
- * not an environment names a position on R's search path (`envir = as.environment(pos)`), which flowR does not
66
- * model: `assign("x", 2, 1)` writes the global environment, not the calling scope.
67
- */
68
- export declare function suppliesArg<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], sig: FnSig | undefined, formals: readonly string[]): boolean;
52
+ /** Whether the call supplies an argument for any of `formals` at all, however it resolves. */
53
+ export declare function suppliesArg<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], sig: FnSig | undefined, formals: readonly BrandedIdentifier[]): boolean;
54
+ /** The environment the argument `arg` given for `formal` names, where a position formal may name the global environment by its number. */
55
+ export declare function resolveEnvirOrPosition<OtherInfo>(arg: PotentiallyEmptyRArgument<OtherInfo & ParentInformation>, formal: BrandedIdentifier, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
69
56
  /** The first of `formals` whose argument resolves to a tracked environment; ambiguity is left to the caller. */
70
- export declare function resolveFirstEnvirArg<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], data: DataflowProcessorInformation<OtherInfo & ParentInformation>, sig: FnSig | undefined, formals: readonly string[]): EnvirResolution<OtherInfo> | undefined;
71
- /**
72
- * Marks `result` as an unknown side effect when the envir argument names a value that cannot be pinned down
73
- * (e.g. a parameter), so routing the writes anywhere would be a guess; reports whether it did.
74
- */
57
+ export declare function resolveFirstEnvirArg<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], data: DataflowProcessorInformation<OtherInfo & ParentInformation>, sig: FnSig | undefined, formals: readonly BrandedIdentifier[]): EnvirResolution<OtherInfo> | undefined;
58
+ /** Marks `result` as an unknown side effect when the envir argument names a value that cannot be pinned down (e.g. a parameter), so routing the writes anywhere would be a guess; reports whether it did. */
75
59
  export declare function unknownIfAmbiguous<OtherInfo>(routing: EnvirArgRouting<OtherInfo>, result: DataflowInformation, rootId: NodeId): boolean;
76
60
  /** Resolves a symbol by name to an {@link EnvirResolution} when it holds a tracked environment. */
77
61
  export declare function resolveSymbolToEnvir<OtherInfo>(symbolName: Identifier, nodeId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
62
+ /** The calls that look up bindings in an environment they are given, or write into it, see {@link readEnvironmentContents}. */
63
+ export declare const EnvironmentLookups: ReadonlySet<BrandedIdentifier>;
64
+ /** An environment is changed in place, so a call given a variable holding a tracked environment reads everything written into the environment so far, through the writes, unless the call only looks up bindings in it (see {@link EnvironmentLookups}). */
65
+ export declare function readEnvironmentContents(graph: DataflowGraph, call: NodeId, holder: IdentifierDefinition): void;
66
+ /** What creates an environment rather than another value: `new.env()`, `globalenv()` and its kin, and `list2env()`. */
67
+ export declare const EnvironmentProducers: readonly BuiltInProcName[];
68
+ /** Whether the variable definition `holder` surely holds a value one of `origins` created, following plain copies (`e2 <- e`) and replacements (`e$f <- v` keeps what `e` held). */
69
+ export declare function holdsValueOf(holder: Pick<IdentifierDefinition, 'nodeId'>, graph: DataflowGraph, origins: readonly BuiltInProcName[]): boolean;
70
+ /** Binds every other variable holding the same object as the variable `name` (copied from it by `y <- x`, see {@link InGraphIdentifierDefinition#envId}) to the change in place `change` as well (`x[, a := 9L]`), which reaches all of them. */
71
+ export declare function rebindAliases(environment: REnvironmentInformation, name: Identifier, change: NodeId, definedAt: NodeId): [REnvironmentInformation, NodeId | undefined];
78
72
  /** Binds every variable holding the environment of `envDef` to its new state, where that variable is bound. */
79
- export declare function rebindHolders(environment: REnvironmentInformation, envDef: NamedInGraphIdentifierDefinition & {
80
- envState: REnvironmentInformation;
81
- }, envState: REnvironmentInformation, definedAt?: NodeId): REnvironmentInformation;
82
- /**
83
- * Routes writes into a real stack env's frame chain, the same way `<<-` reaches an outer scope.
84
- * Each write also gets a `Reads` edge back to `rootId`, so slicing does not drop the call that made it.
85
- */
73
+ export declare function rebindHolders(environment: REnvironmentInformation, envDef: EnvHolderDefinition, envState: REnvironmentInformation, definedAt?: NodeId): REnvironmentInformation;
74
+ /** Adds the `writes` a called function made into environments its free variables name (see {@link InGraphIdentifierDefinition#envWrites}) to the environments the caller binds these names to; a name still free in a calling function body stays with the writes, so its own calls add them. */
75
+ export declare function addEnvironmentWrites(writes: readonly IdentifierDefinition[], callee: REnvironmentInformation, caller: REnvironmentInformation, call: NodeId, graph: DataflowGraph): [REnvironmentInformation, REnvironmentInformation];
76
+ /** Routes writes into a real stack env's frame chain, the same way `<<-` reaches an outer scope. */
86
77
  export declare function routeWrittenToStackEnv(result: DataflowInformation, into: REnvironmentInformation, rootId: NodeId, definedAt?: NodeId): DataflowInformation;
87
- /**
88
- * Routes writes under a resolved `envir=` to the real stack frame or a tracked custom env, and adds the
89
- * `Reads` edge from `rootId` to the envir argument.
90
- */
78
+ /** Routes writes under a resolved `envir=` to the real stack frame or a tracked custom env, and adds the `Reads` edge from `rootId` to the envir argument. */
91
79
  export declare function routeWrittenToEnvir<OtherInfo>(result: DataflowInformation, resolution: EnvirResolution<OtherInfo>, rootId: NodeId, callerEnvironment: REnvironmentInformation, definedAt?: NodeId): DataflowInformation;
92
- /**
93
- * The `search()` position the `pos` argument of a `library()` call requests, either given as a number or as the name of
94
- * an existing entry (`pos = "package:base"`). Returns `undefined` when there is no such argument, its value is unknown
95
- * or ambiguous, or it names an entry that is not on the search path; callers then attach at {@link DefaultAttachPosition}
96
- * (as R does, which warns in the last case).
97
- */
80
+ /** The `search()` position the `pos` argument of a `library()` call requests, either given as a number or as the name of an existing entry (`pos = "package:base"`). */
98
81
  export declare function resolveAttachPosition<OtherInfo>(posId: NodeId | undefined, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): number | undefined;