@eagleoutice/flowr 2.16.6 → 2.16.7

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 (315) hide show
  1. package/README.md +21 -15
  2. package/abstract-interpretation/data-frame/dataframe-semantics.d.ts +2 -0
  3. package/abstract-interpretation/data-frame/dataframe-semantics.js +3 -1
  4. package/abstract-interpretation/data-frame/resolve-args.d.ts +1 -7
  5. package/abstract-interpretation/data-frame/resolve-args.js +2 -11
  6. package/cli/repl/commands/repl-cfg.js +5 -19
  7. package/cli/repl/commands/repl-code-command.d.ts +10 -0
  8. package/cli/repl/commands/repl-code-command.js +18 -0
  9. package/cli/repl/commands/repl-dataflow.js +34 -59
  10. package/cli/repl/commands/repl-normalize.js +24 -41
  11. package/cli/repl/commands/repl-query.js +10 -17
  12. package/config.js +3 -3
  13. package/control-flow/cfg-dead-code.js +15 -2
  14. package/control-flow/useless-loop.js +1 -2
  15. package/data/r-base-packages.generated.d.ts +1 -1
  16. package/data/r-base-packages.generated.js +3 -3
  17. package/dataflow/environments/ambient-state-name.d.ts +80 -0
  18. package/dataflow/environments/ambient-state-name.js +113 -0
  19. package/dataflow/environments/built-in-eval-name.d.ts +3 -1
  20. package/dataflow/environments/built-in-eval-name.js +2 -0
  21. package/dataflow/environments/built-in-props.d.ts +27 -7
  22. package/dataflow/environments/built-in-props.js +59 -44
  23. package/dataflow/environments/built-in.d.ts +5 -2
  24. package/dataflow/environments/built-in.js +22 -5
  25. package/dataflow/environments/default-builtin-config.d.ts +538 -14
  26. package/dataflow/environments/default-builtin-config.js +189 -123
  27. package/dataflow/environments/environment.d.ts +7 -1
  28. package/dataflow/environments/environment.js +19 -1
  29. package/dataflow/environments/identifier.d.ts +11 -0
  30. package/dataflow/eval/resolve/alias-tracking.d.ts +13 -3
  31. package/dataflow/eval/resolve/alias-tracking.js +66 -37
  32. package/dataflow/eval/resolve/resolve-argument.d.ts +4 -2
  33. package/dataflow/eval/resolve/resolve-argument.js +23 -11
  34. package/dataflow/eval/resolve/resolve.d.ts +5 -0
  35. package/dataflow/eval/resolve/resolve.js +25 -3
  36. package/dataflow/eval/values/r-value.d.ts +4 -2
  37. package/dataflow/eval/values/r-value.js +3 -1
  38. package/dataflow/eval/values/string/string-constants.d.ts +7 -1
  39. package/dataflow/eval/values/string/string-constants.js +38 -36
  40. package/dataflow/extractor.js +105 -2
  41. package/dataflow/fn/argument-roles.js +22 -8
  42. package/dataflow/fn/function-semantics.d.ts +3 -2
  43. package/dataflow/fn/strict-function.js +13 -2
  44. package/dataflow/graph/df-helper.d.ts +14 -1
  45. package/dataflow/graph/df-helper.js +37 -4
  46. package/dataflow/graph/graph.d.ts +6 -0
  47. package/dataflow/graph/graph.js +6 -0
  48. package/dataflow/internal/linker.d.ts +4 -1
  49. package/dataflow/internal/linker.js +11 -7
  50. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +41 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +88 -0
  52. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +19 -44
  53. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +125 -158
  54. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +6 -1
  55. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +35 -9
  56. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +10 -1
  57. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -1
  58. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +6 -1
  59. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +1 -1
  60. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +3 -2
  61. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +7 -0
  62. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +21 -12
  63. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  64. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +8 -1
  65. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +3 -0
  66. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +5 -0
  67. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +5 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +11 -12
  69. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -1
  70. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +6 -0
  71. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +1 -1
  72. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -0
  73. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +42 -0
  74. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +11 -0
  75. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +29 -4
  76. package/dataflow/internal/process/functions/call/common.js +3 -4
  77. package/dataflow/internal/process/functions/call/deferred.d.ts +3 -2
  78. package/dataflow/internal/process/functions/call/deferred.js +17 -9
  79. package/dataflow/internal/process/functions/call/quoted.js +1 -1
  80. package/documentation/doc-capabilities.js +3 -2
  81. package/documentation/doc-readme.js +1 -2
  82. package/documentation/doc-util/doc-dfg.js +2 -2
  83. package/documentation/doc-util/doc-query.d.ts +3 -1
  84. package/documentation/doc-util/doc-query.js +4 -4
  85. package/documentation/wiki-create-linting-rules.js +1 -1
  86. package/documentation/wiki-linter.js +16 -206
  87. package/documentation/wiki-linting-and-testing.js +31 -64
  88. package/documentation/wiki-query.js +41 -0
  89. package/index.d.ts +1 -0
  90. package/index.js +5 -1
  91. package/linter/linter-format.d.ts +6 -0
  92. package/linter/linter-format.js +10 -0
  93. package/linter/linter-rules.d.ts +155 -103
  94. package/linter/linter-rules.js +2 -0
  95. package/linter/linter-util.d.ts +23 -0
  96. package/linter/linter-util.js +58 -0
  97. package/linter/rules/absolute-path.d.ts +2 -2
  98. package/linter/rules/absolute-path.js +1 -4
  99. package/linter/rules/cmd-check/bogus-return.d.ts +2 -2
  100. package/linter/rules/cmd-check/bogus-return.js +3 -7
  101. package/linter/rules/cmd-check/call-arguments.d.ts +2 -2
  102. package/linter/rules/cmd-check/class-string-comparison.d.ts +2 -2
  103. package/linter/rules/cmd-check/class-string-comparison.js +3 -7
  104. package/linter/rules/cmd-check/cmd-check-util.d.ts +8 -9
  105. package/linter/rules/cmd-check/cmd-check-util.js +14 -26
  106. package/linter/rules/cmd-check/compiled-code.d.ts +8 -3
  107. package/linter/rules/cmd-check/compiled-code.js +3 -13
  108. package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -2
  109. package/linter/rules/cmd-check/dependency-declaration.js +6 -7
  110. package/linter/rules/cmd-check/description-metadata.d.ts +4 -4
  111. package/linter/rules/cmd-check/documentation-mismatch.d.ts +2 -2
  112. package/linter/rules/cmd-check/documentation-mismatch.js +4 -11
  113. package/linter/rules/cmd-check/file-checks.d.ts +19 -6
  114. package/linter/rules/cmd-check/file-checks.js +13 -5
  115. package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -2
  116. package/linter/rules/cmd-check/global-environment-modification.d.ts +2 -2
  117. package/linter/rules/cmd-check/global-environment-modification.js +3 -2
  118. package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -2
  119. package/linter/rules/cmd-check/namespace-tampering.js +9 -9
  120. package/linter/rules/cmd-check/non-ascii-code.d.ts +2 -2
  121. package/linter/rules/cmd-check/package-data.d.ts +11 -5
  122. package/linter/rules/cmd-check/package-data.js +5 -12
  123. package/linter/rules/cmd-check/package-files.js +4 -10
  124. package/linter/rules/cmd-check/package-hooks.d.ts +2 -2
  125. package/linter/rules/cmd-check/package-hooks.js +10 -8
  126. package/linter/rules/cmd-check/package-metafiles.d.ts +8 -3
  127. package/linter/rules/cmd-check/package-metafiles.js +3 -12
  128. package/linter/rules/cmd-check/package-runtime.d.ts +18 -5
  129. package/linter/rules/cmd-check/package-runtime.js +64 -20
  130. package/linter/rules/cmd-check/package-structure.d.ts +11 -5
  131. package/linter/rules/cmd-check/package-structure.js +4 -12
  132. package/linter/rules/cmd-check/rd-files.d.ts +8 -3
  133. package/linter/rules/cmd-check/rd-files.js +4 -14
  134. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +2 -2
  135. package/linter/rules/cmd-check/s-three-method-consistency.js +3 -4
  136. package/linter/rules/cmd-check/true-false-abbreviation.d.ts +2 -2
  137. package/linter/rules/dataframe-access-validation.d.ts +2 -2
  138. package/linter/rules/dataframe-access-validation.js +5 -8
  139. package/linter/rules/dead-code.d.ts +5 -4
  140. package/linter/rules/dead-code.js +25 -14
  141. package/linter/rules/deprecated-functions.d.ts +3 -3
  142. package/linter/rules/deprecated-functions.js +16 -23
  143. package/linter/rules/file-path-validity.d.ts +2 -2
  144. package/linter/rules/file-path-validity.js +3 -6
  145. package/linter/rules/function-finder-util.d.ts +3 -3
  146. package/linter/rules/function-finder-util.js +7 -14
  147. package/linter/rules/namespace-access.d.ts +2 -2
  148. package/linter/rules/namespace-access.js +6 -9
  149. package/linter/rules/naming-convention.d.ts +2 -2
  150. package/linter/rules/naming-convention.js +1 -4
  151. package/linter/rules/network-functions.d.ts +3 -3
  152. package/linter/rules/no-leaked-credentials.d.ts +2 -2
  153. package/linter/rules/no-leaked-credentials.js +1 -4
  154. package/linter/rules/overwritten-file.d.ts +38 -0
  155. package/linter/rules/overwritten-file.js +102 -0
  156. package/linter/rules/problematic-inputs.d.ts +16 -6
  157. package/linter/rules/problematic-inputs.js +78 -34
  158. package/linter/rules/roxygen-arguments.d.ts +2 -2
  159. package/linter/rules/roxygen-arguments.js +1 -4
  160. package/linter/rules/seeded-randomness.d.ts +3 -3
  161. package/linter/rules/seeded-randomness.js +6 -23
  162. package/linter/rules/software-has-license.d.ts +2 -2
  163. package/linter/rules/software-has-license.js +1 -4
  164. package/linter/rules/software-has-tests.d.ts +2 -2
  165. package/linter/rules/software-has-tests.js +1 -4
  166. package/linter/rules/stop-with-call-arg.d.ts +2 -2
  167. package/linter/rules/stop-with-call-arg.js +4 -11
  168. package/linter/rules/syntactically-valid.d.ts +4 -2
  169. package/linter/rules/syntactically-valid.js +29 -10
  170. package/linter/rules/unclosed-connection.d.ts +2 -2
  171. package/linter/rules/unclosed-connection.js +1 -4
  172. package/linter/rules/undefined-symbol.d.ts +2 -2
  173. package/linter/rules/undefined-symbol.js +25 -22
  174. package/linter/rules/unescaped-arguments.d.ts +2 -2
  175. package/linter/rules/unescaped-arguments.js +1 -4
  176. package/linter/rules/unused-definition.d.ts +2 -2
  177. package/linter/rules/unused-definition.js +37 -25
  178. package/linter/rules/unused-import.d.ts +2 -2
  179. package/linter/rules/unused-import.js +9 -14
  180. package/linter/rules/useless-loop.d.ts +7 -6
  181. package/linter/rules/useless-loop.js +4 -8
  182. package/package.json +5 -3
  183. package/project/cache/flowr-analyzer-cache.d.ts +2 -0
  184. package/project/cache/flowr-analyzer-cache.js +15 -11
  185. package/project/context/flowr-analyzer-files-context.d.ts +3 -0
  186. package/project/context/flowr-analyzer-files-context.js +6 -0
  187. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +6 -1
  188. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +35 -0
  189. package/project/plugins/file-plugins/files/flowr-namespace-file.js +2 -1
  190. package/project/plugins/file-plugins/files/flowr-rsession-file.d.ts +26 -0
  191. package/project/plugins/file-plugins/files/flowr-rsession-file.js +44 -0
  192. package/project/plugins/file-plugins/files/r-session.d.ts +20 -0
  193. package/project/plugins/file-plugins/files/r-session.js +58 -0
  194. package/project/plugins/file-plugins/files/recorded-runs.d.ts +18 -0
  195. package/project/plugins/file-plugins/files/recorded-runs.js +8 -0
  196. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rsession-file-plugin.d.ts +20 -0
  197. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rsession-file-plugin.js +28 -0
  198. package/project/plugins/plugin-registry.d.ts +2 -1
  199. package/project/plugins/plugin-registry.js +2 -0
  200. package/project/sigdb/spec-query.d.ts +73 -0
  201. package/project/sigdb/spec-query.js +339 -0
  202. package/queries/base-query-format.d.ts +1 -1
  203. package/queries/base-query-format.js +2 -2
  204. package/queries/catalog/absint-query/absint-query-executor.js +3 -6
  205. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +1 -0
  206. package/queries/catalog/call-context-query/call-context-query-executor.js +113 -73
  207. package/queries/catalog/call-graph-query/call-graph-query-executor.js +2 -3
  208. package/queries/catalog/cluster-query/cluster-query-executor.js +2 -3
  209. package/queries/catalog/config-query/config-query-format.d.ts +0 -1
  210. package/queries/catalog/config-query/config-query-format.js +1 -2
  211. package/queries/catalog/control-flow-query/control-flow-query-executor.js +2 -3
  212. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +2 -4
  213. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +0 -1
  214. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +1 -2
  215. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -3
  216. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +7 -0
  217. package/queries/catalog/dependencies-query/dependencies-query-executor.js +72 -42
  218. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +24 -6
  219. package/queries/catalog/dependencies-query/dependencies-query-format.js +108 -3
  220. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -1
  221. package/queries/catalog/dependencies-query/function-info/read-functions.js +6 -6
  222. package/queries/catalog/dependencies-query/function-info/write-functions.js +13 -7
  223. package/queries/catalog/dependencies-query/implicit-echo.js +21 -7
  224. package/queries/catalog/dice-query/dice-query-executor.js +2 -3
  225. package/queries/catalog/does-call-query/does-call-query-executor.js +2 -3
  226. package/queries/catalog/files-query/files-query-executor.js +2 -3
  227. package/queries/catalog/function-info-query/function-info-query-executor.js +2 -1
  228. package/queries/catalog/function-info-query/function-info-query-format.d.ts +0 -2
  229. package/queries/catalog/function-info-query/function-info-query-format.js +1 -2
  230. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -2
  231. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +0 -2
  232. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +1 -2
  233. package/queries/catalog/happens-before-query/happens-before-query-executor.js +2 -3
  234. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +0 -1
  235. package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -2
  236. package/queries/catalog/id-map-query/id-map-query-executor.js +2 -3
  237. package/queries/catalog/id-map-query/id-map-query-format.d.ts +0 -1
  238. package/queries/catalog/id-map-query/id-map-query-format.js +1 -2
  239. package/queries/catalog/input-sources-query/input-sources-query-executor.js +3 -4
  240. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +2 -1
  241. package/queries/catalog/input-sources-query/simple-input-classifier.js +60 -13
  242. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -3
  243. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +2 -3
  244. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +2 -1
  245. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.d.ts +3 -2
  246. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +1 -7
  247. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +6 -9
  248. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +8 -33
  249. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.d.ts +3 -2
  250. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +1 -7
  251. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.d.ts +6 -7
  252. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +8 -31
  253. package/queries/catalog/linter-query/linter-query-executor.js +2 -3
  254. package/queries/catalog/location-map-query/location-map-query-executor.js +2 -3
  255. package/queries/catalog/location-map-query/location-map-query-format.d.ts +0 -1
  256. package/queries/catalog/location-map-query/location-map-query-format.js +1 -2
  257. package/queries/catalog/normalized-ast-query/normalized-ast-query-executor.js +2 -3
  258. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +0 -1
  259. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +1 -2
  260. package/queries/catalog/origin-query/origin-query-executor.d.ts +0 -5
  261. package/queries/catalog/origin-query/origin-query-executor.js +3 -11
  262. package/queries/catalog/project-query/project-query-executor.js +23 -7
  263. package/queries/catalog/project-query/project-query-format.d.ts +5 -0
  264. package/queries/catalog/project-query/project-query-format.js +20 -2
  265. package/queries/catalog/provenance-query/provenance-query-executor.js +2 -3
  266. package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +2 -3
  267. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +0 -1
  268. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -2
  269. package/queries/catalog/search-query/search-query-executor.js +2 -3
  270. package/queries/catalog/signature-query/signature-query-executor.js +39 -0
  271. package/queries/catalog/signature-query/signature-query-format.d.ts +7 -1
  272. package/queries/catalog/signature-query/signature-query-format.js +15 -1
  273. package/queries/catalog/signature-query/signature-query-render.js +2 -1
  274. package/queries/catalog/static-slice-query/static-slice-query-executor.js +2 -3
  275. package/queries/query-function-property.d.ts +28 -0
  276. package/queries/query-function-property.js +48 -0
  277. package/queries/query-meta.d.ts +3 -0
  278. package/queries/query-meta.js +8 -0
  279. package/queries/query.d.ts +13 -18
  280. package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +2 -2
  281. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -3
  282. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -0
  283. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +9 -0
  284. package/r-bridge/lang-4.x/ast/model/syntax-version.d.ts +8 -0
  285. package/r-bridge/lang-4.x/ast/model/syntax-version.js +49 -0
  286. package/r-bridge/lang-4.x/ast/model/type.d.ts +2 -0
  287. package/r-bridge/lang-4.x/ast/model/type.js +3 -0
  288. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-parameter.js +4 -1
  289. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-single-node.js +1 -0
  290. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +1 -1
  291. package/reconstruct/reconstruct.js +35 -1
  292. package/search/search-executor/search-generators.js +1 -1
  293. package/slicing/static/fingerprint.js +7 -3
  294. package/slicing/static/static-slicer.js +6 -0
  295. package/util/assert.js +2 -2
  296. package/util/collections/arrays.d.ts +4 -0
  297. package/util/collections/arrays.js +11 -0
  298. package/util/collections/defaultmap.d.ts +5 -1
  299. package/util/collections/defaultmap.js +6 -1
  300. package/util/files.js +26 -5
  301. package/util/flowr-version.d.ts +10 -0
  302. package/util/flowr-version.js +20 -0
  303. package/util/glob.js +6 -4
  304. package/util/r-regex.d.ts +6 -0
  305. package/util/r-regex.js +17 -0
  306. package/util/text/args.d.ts +5 -0
  307. package/util/text/args.js +28 -22
  308. package/util/text/name-rank.d.ts +2 -0
  309. package/util/text/name-rank.js +3 -1
  310. package/util/text/regex.d.ts +10 -0
  311. package/util/text/regex.js +29 -0
  312. package/util/version.d.ts +1 -6
  313. package/util/version.js +6 -14
  314. package/documentation/doc-util/doc-functions.d.ts +0 -24
  315. package/documentation/doc-util/doc-functions.js +0 -65
@@ -8,6 +8,7 @@ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model
8
8
  const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
9
9
  const logger_1 = require("../../../../../logger");
10
10
  const vertex_1 = require("../../../../../graph/vertex");
11
+ const graph_1 = require("../../../../../graph/graph");
11
12
  const edge_1 = require("../../../../../graph/edge");
12
13
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
13
14
  const identifier_1 = require("../../../../../environments/identifier");
@@ -46,7 +47,7 @@ function resolveFunctionArgument(val, data, opts) {
46
47
  * Process an apply call like `vapply` or `mapply`.
47
48
  */
48
49
  function processApply(name, args, rootId, data, config) {
49
- const { indexOfFunction = 1, nameOfFunctionArgument, unquoteFunction, resolveInEnvironment, resolveValue, hasUnknownSideEffects } = config;
50
+ const { indexOfFunction = 1, nameOfFunctionArgument, unquoteFunction, resolveInEnvironment, resolveValue, hasUnknownSideEffects, isTheCall } = config;
50
51
  /* the length is one-based and the argument mapping zero-based, so the function sits at `indexOfFunction` */
51
52
  const resFn = (0, known_call_handling_1.processKnownFunctionCall)({
52
53
  name, args, rootId, data, sig: function_semantics_1.FunctionSemantics.call.signature.only(indexOfFunction, nameOfFunctionArgument ?? 'FUN'), origin: built_in_proc_name_1.BuiltInProcName.Apply
@@ -80,6 +81,12 @@ function processApply(name, args, rootId, data, config) {
80
81
  }
81
82
  const { functionName, anonymous, asString, computed } = resolvedFn;
82
83
  let functionId = resolvedFn.functionId;
84
+ if (!anonymous && !computed && !information.graph.hasVertex(functionId)) {
85
+ /* in `f |> Map(1:3)` the function comes from the pipe, which is processed after this call, so the call it makes is unknown */
86
+ logger_1.dataflowLogger.warn(`Function argument ${identifier_1.Identifier.toString(functionName)} is not processed yet, treating the call as unknown`);
87
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
88
+ return information;
89
+ }
83
90
  if (computed) {
84
91
  /* the call the computed name stands for gets a vertex of its own, which reads the name */
85
92
  const nameId = functionId;
@@ -92,7 +99,7 @@ function processApply(name, args, rootId, data, config) {
92
99
  if (asString) {
93
100
  information.in = [...information.in, { type: identifier_1.ReferenceType.Function, name: functionName, cds: data.cds, nodeId: functionId }];
94
101
  }
95
- const allOtherArguments = processedArguments.map((arg, i) => {
102
+ const handedOn = processedArguments.map((arg, i) => {
96
103
  const counterpart = args[i];
97
104
  if (!arg || counterpart === r_function_call_1.EmptyArgument) {
98
105
  return r_function_call_1.EmptyArgument;
@@ -105,6 +112,9 @@ function processApply(name, args, rootId, data, config) {
105
112
  nodeId: arg.entryPoint
106
113
  };
107
114
  }).filter((_, i) => i !== index);
115
+ /* `do.call(f, list(a, b))` passes `a` and `b` to `f` as separate arguments */
116
+ const spread = isTheCall && handedOn.length === 1 ? information.graph.getVertex(graph_1.FunctionArgument.getReference(handedOn[0])) : undefined;
117
+ const allOtherArguments = vertex_1.DfgVertex.isFunctionCall(spread) && vertex_1.DfgVertex.hasOrigin(spread, built_in_proc_name_1.BuiltInProcName.List) ? spread.args : handedOn;
108
118
  if (anonymous) {
109
119
  const rootFnId = functionId;
110
120
  functionId = 'anon-' + rootFnId;
@@ -152,18 +162,34 @@ function processApply(name, args, rootId, data, config) {
152
162
  });
153
163
  /* once the call has its arguments, which may name the files it accesses */
154
164
  information = (0, built_in_ambient_state_1.applyAmbientStateOfCallee)(information, functionId, functionName, data);
155
- /* `do.call(new.env, list())` creates an environment just like `new.env()` does */
156
- const call = information.graph.getVertex(rootId);
157
- if (vertex_1.DfgVertex.isFunctionCall(call) && resolve_helper_1.Resolve.byNameAndType(functionName, data.environment, identifier_1.ReferenceType.Function)
165
+ /* `do.call(new.env, list())` returns a new environment, so both calls get the origin `new.env()` has */
166
+ if (resolve_helper_1.Resolve.byNameAndType(functionName, data.environment, identifier_1.ReferenceType.Function)
158
167
  ?.some(t => t.type === identifier_1.ReferenceType.BuiltInFunction && t.processorName === built_in_proc_name_1.BuiltInProcName.NewEnv)) {
159
- call.origin = [...Array.isArray(call.origin) ? call.origin : [], built_in_proc_name_1.BuiltInProcName.NewEnv];
168
+ for (const call of [information.graph.getVertex(rootId), information.graph.getVertex(functionId)]) {
169
+ if (vertex_1.DfgVertex.isFunctionCall(call)) {
170
+ call.origin = [...Array.isArray(call.origin) ? call.origin : [], built_in_proc_name_1.BuiltInProcName.NewEnv];
171
+ }
172
+ }
160
173
  }
161
174
  }
162
- for (const [i, arg] of processedArguments.entries()) {
163
- if (arg && !(anonymous && i === index)) {
164
- information.graph.addEdge(functionId, arg.entryPoint, edge_1.EdgeType.Argument);
175
+ if (allOtherArguments === handedOn) {
176
+ for (const [i, arg] of processedArguments.entries()) {
177
+ if (arg && !(anonymous && i === index)) {
178
+ information.graph.addEdge(functionId, arg.entryPoint, edge_1.EdgeType.Argument);
179
+ }
165
180
  }
166
181
  }
182
+ else {
183
+ for (const arg of allOtherArguments) {
184
+ const ref = graph_1.FunctionArgument.getReference(arg);
185
+ if (ref !== undefined) {
186
+ information.graph.addEdge(functionId, ref, edge_1.EdgeType.Argument);
187
+ }
188
+ }
189
+ }
190
+ if (isTheCall) {
191
+ information.graph.addEdge(rootId, functionId, edge_1.EdgeType.Returns);
192
+ }
167
193
  if (resolveInEnvironment !== 'global') {
168
194
  return information;
169
195
  }
@@ -19,6 +19,7 @@ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model
19
19
  const logger_1 = require("../../../../../logger");
20
20
  const identifier_1 = require("../../../../../environments/identifier");
21
21
  const built_in_ambient_state_1 = require("./built-in-ambient-state");
22
+ const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
22
23
  const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
23
24
  const vertex_1 = require("../../../../../graph/vertex");
24
25
  const edge_1 = require("../../../../../graph/edge");
@@ -261,7 +262,7 @@ function processAssignmentTarget(name, args, rootId, data, config) {
261
262
  }
262
263
  /** Promotes the ingoing/unknown references of target (an assignment) to definitions. */
263
264
  function produceWrittenNodes(rootId, target, referenceType, data, makeMaybe, value) {
264
- return [...target.in, ...target.unknownReferences].filter(ref => !built_in_ambient_state_1.AmbientStateName.is(ref.name)).map(ref => ({
265
+ return [...target.in, ...target.unknownReferences].filter(ref => !ambient_state_name_1.AmbientStateName.is(ref.name)).map(ref => ({
265
266
  nodeId: ref.nodeId,
266
267
  name: ref.name,
267
268
  type: referenceType,
@@ -344,6 +345,14 @@ function tryRouteDollarEnvAssign(rootId, data, config, target, source, replaceme
344
345
  definedAt: normalResult.entryPoint,
345
346
  cds: data.cds ?? (config.makeMaybe ? [] : undefined)
346
347
  };
348
+ if (envirResolution.stack === 'global' && normalResult.graph.hasVertex(fieldNode.info.id)) {
349
+ /* `e$f <- v` with `e` the global frame (`e <- globalenv()`, or `environment()` at the top level) is `f <<- v` */
350
+ const definition = { ...fieldDef, nodeId: fieldNode.info.id };
351
+ normalResult.graph.setDefinitionOfVertex(definition, [source.info.id]);
352
+ normalResult.graph.addEdge(fieldNode.info.id, source.info.id, edge_1.EdgeType.DefinedBy);
353
+ normalResult.graph.addEdge(normalResult.entryPoint, envirResolution.envirNodeId, edge_1.EdgeType.Reads);
354
+ return { ...normalResult, environment: environment_1.REnvironment.define(definition, true, normalResult.environment) };
355
+ }
347
356
  const newEnvState = environment_1.REnvironment.define(fieldDef, false, envirResolution.envDef.envState);
348
357
  const updatedEnvDef = {
349
358
  ...envirResolution.envDef,
@@ -4,5 +4,8 @@ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/
4
4
  import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
5
  import { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
+ import { type AmbientStateAccess } from './built-in-ambient-state';
7
8
  /** Processes `attach(what, ...)`, injecting the tracked env's known definitions into a new scope layer below `.GlobalEnv`. */
8
- export declare function processAttach<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
9
+ export declare function processAttach<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config?: {
10
+ readonly ambient?: AmbientStateAccess | readonly AmbientStateAccess[];
11
+ }): DataflowInformation;
@@ -11,8 +11,13 @@ const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect"
11
11
  const edge_1 = require("../../../../../graph/edge");
12
12
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
13
13
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
14
+ const built_in_ambient_state_1 = require("./built-in-ambient-state");
14
15
  /** Processes `attach(what, ...)`, injecting the tracked env's known definitions into a new scope layer below `.GlobalEnv`. */
15
- function processAttach(name, args, rootId, data) {
16
+ function processAttach(name, args, rootId, data, config = {}) {
17
+ const result = attachLayer(name, args, rootId, data);
18
+ return config.ambient === undefined ? result : (0, built_in_ambient_state_1.applyAmbientStateAccess)(result, args, rootId, data, config.ambient);
19
+ }
20
+ function attachLayer(name, args, rootId, data) {
16
21
  const result = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Attach }).information;
17
22
  const whatArg = args.length >= 1 ? args[0] : undefined;
18
23
  const whatNode = whatArg && whatArg !== r_function_call_1.EmptyArgument ? r_argument_1.RArgument.valueOf(whatArg) : undefined;
@@ -68,7 +68,7 @@ function processEvalCall(name, args, rootId, data, config) {
68
68
  * pretending they do would produce wrong edges */
69
69
  (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
70
70
  }
71
- const idGenerator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(name.lexeme + '::' + rootId, name.location);
71
+ const idGenerator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(name.lexeme + '::' + rootId);
72
72
  data = {
73
73
  ...data,
74
74
  cds: code.length > 1 ? [...(data.cds ?? []), { id: rootId, when: true }] : data.cds
@@ -28,6 +28,7 @@ const model_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/model");
28
28
  const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
29
29
  const objects_1 = require("../../../../../../util/objects");
30
30
  const built_in_ambient_state_1 = require("./built-in-ambient-state");
31
+ const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
31
32
  const df_helper_1 = require("../../../../../graph/df-helper");
32
33
  const environment_1 = require("../../../../../environments/environment");
33
34
  /**
@@ -332,7 +333,7 @@ function processExpressionList(name, args, rootId, data) {
332
333
  // all inputs that have not been written until now are read!
333
334
  const activeReads = [];
334
335
  for (const read of processed.in.concat(processed.unknownReferences)) {
335
- if (!linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph, activeReads) && autoPrint && built_in_ambient_state_1.AmbientStateName.is(read.name)) {
336
+ if (!linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph, activeReads) && autoPrint && ambient_state_name_1.AmbientStateName.is(read.name)) {
336
337
  (initialState ??= new Set()).add(read);
337
338
  }
338
339
  }
@@ -423,7 +424,7 @@ function processExpressionList(name, args, rootId, data) {
423
424
  unknownReferences: [],
424
425
  /* at the top of the script, only a read of the options or graphics state nothing set reads the state R starts with,
425
426
  which a write escaping a higher-order call may still replace, see the extractor */
426
- in: autoPrint ? ingoing.filter(r => !built_in_ambient_state_1.AmbientStateName.is(r.name) || initialState?.has(r) === true) : ingoing,
427
+ in: autoPrint ? ingoing.filter(r => !ambient_state_name_1.AmbientStateName.is(r.name) || initialState?.has(r) === true) : ingoing,
427
428
  /* a definition that a still-effective removal undid is no longer visible to the outside */
428
429
  out: (0, apply_kill_1.dropKilledWrites)(out, killed),
429
430
  environment,
@@ -5,6 +5,7 @@ import { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-s
5
5
  import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
6
6
  import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  import { DataflowGraph } from '../../../../../graph/graph';
8
+ import { type IdentifierReference } from '../../../../../environments/identifier';
8
9
  import type { REnvironmentInformation } from '../../../../../environments/environment';
9
10
  import type { ReadOnlyFlowrAnalyzerContext, FlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
10
11
  /**
@@ -13,6 +14,12 @@ import type { ReadOnlyFlowrAnalyzerContext, FlowrAnalyzerContext } from '../../.
13
14
  export declare function processFunctionDefinition<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
14
15
  /** Retrieve the active environment when entering a function definition or call. */
15
16
  export declare function retrieveActiveEnvironment(callerEnvironment: REnvironmentInformation | undefined, baseEnvironment: REnvironmentInformation, ctx: ReadOnlyFlowrAnalyzerContext): REnvironmentInformation;
17
+ /**
18
+ * Links the free variables of the functions defined in `graph` to their definitions in `outEnvironment`, the scope
19
+ * the functions were defined in. Call it before that scope is popped, at the end of a function body or of `local`.
20
+ * Reads that `outEnvironment` does not define are added to `openReads`.
21
+ */
22
+ export declare function updateNestedFunctionClosures(graph: DataflowGraph, outEnvironment: REnvironmentInformation, openReads: IdentifierReference[]): void;
16
23
  /**
17
24
  * Update the closure links of all nested function calls, done once at the end of the script.
18
25
  * @lintIgnore vertex-has-origin
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processFunctionDefinition = processFunctionDefinition;
4
4
  exports.retrieveActiveEnvironment = retrieveActiveEnvironment;
5
+ exports.updateNestedFunctionClosures = updateNestedFunctionClosures;
5
6
  exports.updateNestedFunctionCalls = updateNestedFunctionCalls;
6
7
  const processor_1 = require("../../../../../processor");
7
8
  const function_semantics_1 = require("../../../../../fn/function-semantics");
@@ -30,7 +31,7 @@ const r_number_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/
30
31
  const hooks_1 = require("../../../../../hooks");
31
32
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
32
33
  const resolve_helper_1 = require("../../../../../environments/resolve-helper");
33
- const built_in_ambient_state_1 = require("./built-in-ambient-state");
34
+ const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
34
35
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
35
36
  const r_function_definition_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
36
37
  const r_parameter_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
@@ -161,7 +162,7 @@ function processFunctionDefinition(name, args, rootId, data) {
161
162
  subgraph.addEdge(read.nodeId, nodeId, edge_1.EdgeType.Reads);
162
163
  }
163
164
  }
164
- if (built_in_ambient_state_1.AmbientStateName.is(read.name)) {
165
+ if (ambient_state_name_1.AmbientStateName.is(read.name)) {
165
166
  remainingRead.push(read);
166
167
  }
167
168
  }
@@ -303,6 +304,11 @@ function resolveIngoingRefs(refs, environment, onResolved) {
303
304
  return resolved === undefined || onResolved(ingoing, resolved);
304
305
  });
305
306
  }
307
+ /**
308
+ * Links the free variables of the functions defined in `graph` to their definitions in `outEnvironment`, the scope
309
+ * the functions were defined in. Call it before that scope is popped, at the end of a function body or of `local`.
310
+ * Reads that `outEnvironment` does not define are added to `openReads`.
311
+ */
306
312
  function updateNestedFunctionClosures(graph, outEnvironment, openReads) {
307
313
  const open = new Set(openReads.map(r => r.nodeId));
308
314
  const settled = new Set();
@@ -381,26 +387,26 @@ function namesShadowingBuiltIns(environment) {
381
387
  }
382
388
  return { shadowing, generics };
383
389
  }
384
- function fnPropsOf(name, environment, ctx) {
385
- return (0, query_fn_props_1.queryFnProps)(name, { environment }) ?? ctx.functionInfo(name);
390
+ function fnPropsOf(name, environment, infoOf) {
391
+ return (0, query_fn_props_1.queryFnProps)(name, { environment }) ?? infoOf(name);
386
392
  }
387
393
  /** Whether `name` resolves to a built-in that dispatches, so the methods the code writes for it are reachable. */
388
- function dispatchesOnClass(name, environment, ctx) {
394
+ function dispatchesOnClass(name, environment, infoOf) {
389
395
  /* a generic only the signature database knows (`toString`) dispatches as well */
390
- const props = fnPropsOf(name, environment, ctx);
396
+ const props = fnPropsOf(name, environment, infoOf);
391
397
  return props === undefined ? resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.Function) === undefined : built_in_props_1.CallProps.hasAny(props, built_in_props_1.CallProp.Generic);
392
398
  }
393
399
  /**
394
400
  * Links `call` to the S3 methods the analyzed code binds as `<name>.<class>`, returning their definition vertices.
395
401
  * Unless {@link dispatchedS3Methods} knows the class, every such method counts, same as the {@link BuiltInProcName.S3Dispatch} path.
396
402
  */
397
- function linkOwnS3Methods(call, name, graph, environment, statement, ctx) {
403
+ function linkOwnS3Methods(call, name, graph, environment, statement, ctx, infoOf) {
398
404
  const defs = resolve_helper_1.Resolve.byNameAndType(name, environment, identifier_1.ReferenceType.S3MethodPrefix)
399
405
  ?.filter(d => !node_id_1.NodeId.isBuiltIn(d.nodeId) && !program_order_1.ProgramOrder.definedLater(d.nodeId, statement, graph));
400
406
  if (defs === undefined || defs.length === 0) {
401
407
  return [];
402
408
  }
403
- const dispatched = dispatchedS3Methods(call, name, defs, graph, environment, statement, ctx) ?? defs;
409
+ const dispatched = dispatchedS3Methods(call, name, defs, graph, environment, statement, ctx, infoOf) ?? defs;
404
410
  for (const def of dispatched) {
405
411
  /* the dispatch looks the method up by name, just like a call written out would */
406
412
  graph.addEdge(call.id, def.nodeId, edge_1.EdgeType.Reads);
@@ -414,7 +420,7 @@ function linkedFunctionIds(defs, graph) {
414
420
  * The `methods` a call dispatches to per known class of its dispatch object (then `default`), stopping for a top-level call at one surely bound before it;
415
421
  * `undefined` if the class is unknown or a method may `NextMethod()`.
416
422
  */
417
- function dispatchedS3Methods(call, name, methods, graph, environment, statement, ctx) {
423
+ function dispatchedS3Methods(call, name, methods, graph, environment, statement, ctx, infoOf) {
418
424
  const generic = identifier_1.Identifier.getName(name);
419
425
  const node = graph.idMap?.get(call.id);
420
426
  const first = call.args[0];
@@ -427,7 +433,7 @@ function dispatchedS3Methods(call, name, methods, graph, environment, statement,
427
433
  return undefined;
428
434
  }
429
435
  /* a closure dispatches on what binds its first formal, a primitive (or anything else) may on the first argument given */
430
- const props = fnPropsOf(name, environment, ctx);
436
+ const props = fnPropsOf(name, environment, infoOf);
431
437
  const closure = bound !== undefined && props !== undefined && !built_in_props_1.CallProps.hasAny(props, built_in_props_1.CallProp.Primitive);
432
438
  const classes = new Set(closure ? bound : [first.nodeId, ...bound ?? []]).values().map(a => (0, class_declaration_1.s3DispatchClassesOf)(a, { graph, idMap: graph.idMap, ctx })).toArray();
433
439
  if (!classes.every(assert_1.isNotUndefined)) {
@@ -461,6 +467,7 @@ function updateNestedFunctionCalls(graph, outEnvironment, ctx) {
461
467
  const lifted = [];
462
468
  const enclosingOf = (0, defaultmap_1.memoize)((id) => graph.idMap === undefined ? undefined : model_1.RNode.strictlyEnclosingFunction(id, graph.idMap));
463
469
  const runsOnceAt = (0, defaultmap_1.memoize)((id) => program_order_1.ProgramOrder.runsOnceAt(id, graph));
470
+ const databaseInfoOf = (0, defaultmap_1.memoize)((name) => ctx.functionInfo(name));
464
471
  const environmentAt = (0, defaultmap_1.memoize)((id) => {
465
472
  const environment = graph.getVertex(id).environment;
466
473
  return environment ? environment_1.REnvironment.overwrite(outEnvironment, environment) : outEnvironment;
@@ -498,8 +505,8 @@ function updateNestedFunctionCalls(graph, outEnvironment, ctx) {
498
505
  }
499
506
  }
500
507
  }
501
- if (mayDispatch && !treatAsS3 && dispatchesOnClass(name, effectiveEnvironment, ctx)) {
502
- for (const method of linkOwnS3Methods(vertex, name, graph, effectiveEnvironment, runsOnceAt(id), ctx)) {
508
+ if (mayDispatch && !treatAsS3 && dispatchesOnClass(name, effectiveEnvironment, databaseInfoOf)) {
509
+ for (const method of linkOwnS3Methods(vertex, name, graph, effectiveEnvironment, runsOnceAt(id), ctx, databaseInfoOf)) {
503
510
  targets.add(method);
504
511
  }
505
512
  treatAsS3 = true;
@@ -661,6 +668,8 @@ function prepareFunctionEnvironment(data, rootId) {
661
668
  enclosing.push(frame);
662
669
  }
663
670
  let env = environment_1.REnvironment.cleanOf(data.environment);
671
+ /* the global frame is emptied as well, but keeps its old bindings for {@link Environment#lookupLexically} */
672
+ env.current.standsInFor(environment_1.REnvironment.findGlobal(data.environment.current).memory);
664
673
  for (let i = 0; i < level + 1; i++) {
665
674
  env = environment_1.REnvironment.pushLocal(env);
666
675
  if (i === level) {
@@ -4,7 +4,7 @@ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/
4
4
  import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
5
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
- import type { FnSig } from '../../../../../environments/built-in-props';
7
+ import { type FnSig } from '../../../../../environments/built-in-props';
8
8
  /**
9
9
  * Processes a built-in 'get' function call.
10
10
  *
@@ -17,6 +17,7 @@ const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/
17
17
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
18
18
  const resolve_helper_1 = require("../../../../../environments/resolve-helper");
19
19
  const assert_1 = require("../../../../../../util/assert");
20
+ const built_in_props_1 = require("../../../../../environments/built-in-props");
20
21
  function namesDenotedBy(node, data) {
21
22
  const folded = (0, built_in_envir_utils_1.resolveConstantString)(node, data);
22
23
  if (folded !== undefined) {
@@ -66,7 +67,13 @@ function processGet(name, args, rootId, data, config = {}) {
66
67
  if (targets.length === 0) {
67
68
  logger_1.dataflowLogger.warn(`symbol access with ${identifier_1.Identifier.toString(name.content)} has no resolvable name argument, skipping`);
68
69
  // dynamic, unresolvable name: reached-but-unknown rather than dropped
69
- return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default', hasUnknownSideEffect: true }).information;
70
+ const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default', hasUnknownSideEffect: true });
71
+ /* `match.fun(f)` hands back the function `f` holds, as it only looks up what names one */
72
+ const handedBack = config.sig?.[0] !== undefined && (config.sig[0][1] & built_in_props_1.ArgProp.Alias) !== 0 ? processedArguments[0] : undefined;
73
+ if (handedBack !== undefined && retrieve !== undefined && !r_string_1.RString.is(retrieve)) {
74
+ information.graph.addEdge(rootId, handedBack.entryPoint, edge_1.EdgeType.Returns);
75
+ }
76
+ return information;
70
77
  }
71
78
  /* a computed name is an expression the call evaluates and reads */
72
79
  const nameExpression = r_string_1.RString.is(retrieve) ? undefined : args[0];
@@ -8,6 +8,7 @@ import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing
8
8
  import type { REnvironmentInformation } from '../../../../../environments/environment';
9
9
  import type { FlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
10
10
  import { Package } from '../../../../../../project/plugins/package-version-plugins/package';
11
+ import { type AmbientStateAccess } from './built-in-ambient-state';
11
12
  /** Controls how {@link processLibrary} brings a package into scope. */
12
13
  export interface LibraryProcessorConfig {
13
14
  /** `requireNamespace("pkg")` / `loadNamespace("pkg")`: load without attaching bare names */
@@ -18,6 +19,8 @@ export interface LibraryProcessorConfig {
18
19
  readonly fromImports?: boolean;
19
20
  /** `box::use(pkg[a, b])`: attach only the symbols listed in the `[...]` bracket */
20
21
  readonly boxUse?: boolean;
22
+ /** the state the call changes besides the environment, like the search path */
23
+ readonly ambient?: AmbientStateAccess | readonly AmbientStateAccess[];
21
24
  }
22
25
  /** Restricts/aliases which exports of a package are attached; `undefined` fields attach every export. */
23
26
  interface AttachSpec {
@@ -40,10 +40,15 @@ const r_base_packages_1 = require("../../../../../../util/r-base-packages");
40
40
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
41
41
  const arrays_1 = require("../../../../../../util/collections/arrays");
42
42
  const built_in_load_1 = require("./built-in-load");
43
+ const built_in_ambient_state_1 = require("./built-in-ambient-state");
43
44
  /**
44
45
  * Process a library call like `library` or `require`
45
46
  */
46
47
  function processLibrary(name, args, rootId, data, config = {}) {
48
+ const info = loadPackages(name, args, rootId, data, config);
49
+ return config.ambient === undefined ? info : (0, built_in_ambient_state_1.applyAmbientStateAccess)(info, args, rootId, data, config.ambient);
50
+ }
51
+ function loadPackages(name, args, rootId, data, config) {
47
52
  /* we do not really know what loading the library does and what side effects it causes, hence we mark it as an unknown side effect */
48
53
  if (args.length === 0) {
49
54
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: true, origin: 'default' }).information;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processLocal = processLocal;
4
4
  const function_semantics_1 = require("../../../../../fn/function-semantics");
5
+ const built_in_function_definition_1 = require("./built-in-function-definition");
5
6
  const processor_1 = require("../../../../../processor");
6
7
  const info_1 = require("../../../../../info");
7
8
  const vertex_1 = require("../../../../../graph/vertex");
@@ -58,14 +59,16 @@ function processLocal(name, args, rootId, data, config) {
58
59
  argumentProcessResult: env ? [dfExpr, dfEnv] : [dfExpr],
59
60
  origin: built_in_proc_name_1.BuiltInProcName.Local
60
61
  });
62
+ /* in `local({ y <- 1; function() y })` the read of `y` is linked now, as the frame of `local` is dropped below */
63
+ (0, built_in_function_definition_1.updateNestedFunctionClosures)(dfExpr.graph, dfExpr.environment, []);
61
64
  const resultEnvironment = envirResolution ? data.environment : environment_1.REnvironment.popLocal(dfExpr.environment);
62
65
  /* definitions of the local scope vanish with it, only what escaped it (e.g. via `<<-`) may bubble up */
63
66
  const escaping = envirResolution ? dfExpr.out : dfExpr.out.filter(o => o.name !== undefined && resolve_helper_1.Resolve.byNameAndType(o.name, resultEnvironment, o.type)?.some(d => d.nodeId === o.nodeId));
64
67
  const graph = dfEnv.graph.mergeWith(dfExpr.graph);
65
68
  graph.addEdge(rootId, expr.info.id, edge_1.EdgeType.Returns);
66
- /* the body only runs because `local` runs it */
69
+ /* `y` in `local(y <- 1)` gets its value from `1`, so a definition in the body gets no `Reads` edge to `local` */
67
70
  for (const [id, vertex] of dfExpr.graph.vertices(false)) {
68
- if (!vertex_1.DfgVertex.isUse(vertex) && !vertex_1.DfgVertex.isValue(vertex)) {
71
+ if (!vertex_1.DfgVertex.isUse(vertex) && !vertex_1.DfgVertex.isValue(vertex) && !vertex_1.DfgVertex.isVariableDefinition(vertex)) {
69
72
  graph.addEdge(id, rootId, edge_1.EdgeType.Reads);
70
73
  }
71
74
  }
@@ -102,20 +102,19 @@ function processPipe(name, args, rootId, data, { pipePlaceholderName, assignLhs,
102
102
  treatedAsFunctionCall = true;
103
103
  }
104
104
  }
105
+ const argId = lhs.info.id;
106
+ /* a placeholder stands for the lhs wherever it is, in an argument (`x |> f(y = _)`) or at the head of an extraction (`x |> _$a`) */
107
+ if (occurrenceIds.length > 1) {
108
+ log_1.log.warn(`Expected exactly one occurrence of the pipe placeholder '${identifier_1.Identifier.toString(pipePlaceholderName)}' in the rhs of the pipe, but found ${occurrenceIds.length}. Linking all occurrences to the lhs.`);
109
+ }
110
+ for (const occId of occurrenceIds) {
111
+ information.graph.addEdge(occId, argId, edge_1.EdgeType.Reads);
112
+ }
105
113
  if (treatedAsFunctionCall || r_function_call_1.RFunctionCall.is(rhs)) {
106
114
  const functionCallNode = information.graph.getVertex(rhs.info.id);
107
115
  (0, assert_1.guard)(vertex_1.DfgVertex.isFunctionCall(functionCallNode), () => `Expected function call node with id ${rhs.info.id} to be a function call node, but got ${functionCallNode?.tag} instead.`);
108
- // make the lhs an argument node (or link it to placeholders within the rhs call):
109
- const argId = lhs.info.id;
110
- if (occurrenceIds.length > 0) {
111
- if (occurrenceIds.length !== 1) {
112
- log_1.log.warn(`Expected exactly one occurrence of the pipe placeholder '${identifier_1.Identifier.toString(pipePlaceholderName)}' in the rhs of the pipe, but found ${occurrenceIds.length}. Linking all occurrences to the lhs.`);
113
- }
114
- for (const occId of occurrenceIds) {
115
- information.graph.addEdge(occId, argId, edge_1.EdgeType.Reads);
116
- }
117
- }
118
- else {
116
+ // without a placeholder the lhs becomes the first argument of the rhs call
117
+ if (occurrenceIds.length === 0) {
119
118
  logger_1.dataflowLogger.trace(`Linking pipe arg ${argId} as first argument of ${rhs.info.id}`);
120
119
  functionCallNode.args.unshift({
121
120
  name: undefined,
@@ -129,7 +128,7 @@ function processPipe(name, args, rootId, data, { pipePlaceholderName, assignLhs,
129
128
  markPipedDataMask(rhs, information.graph);
130
129
  }
131
130
  }
132
- else {
131
+ else if (occurrenceIds.length === 0) {
133
132
  logger_1.dataflowLogger.warn(`Expected rhs of pipe to be a function call, but got ${rhs.type} instead.`);
134
133
  }
135
134
  const firstArgument = processedArguments[0];
@@ -2,7 +2,7 @@ import type { DataflowProcessorInformation } from '../../../../../processor';
2
2
  import { DataflowInformation } from '../../../../../info';
3
3
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
4
  import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
- import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
5
+ import { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  /** e.g. UseMethod(generic, object) */
8
8
  interface S3DispatchConfig {
@@ -5,6 +5,7 @@ const function_semantics_1 = require("../../../../../fn/function-semantics");
5
5
  const processor_1 = require("../../../../../processor");
6
6
  const info_1 = require("../../../../../info");
7
7
  const known_call_handling_1 = require("../known-call-handling");
8
+ const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
8
9
  const logger_1 = require("../../../../../logger");
9
10
  const common_1 = require("../common");
10
11
  const node_value_1 = require("../../../../../eval/resolve/node-value");
@@ -73,7 +74,12 @@ function processS3Dispatch(name, args, rootId, data, config) {
73
74
  unknownReferences: []
74
75
  };
75
76
  }
77
+ /* in `g <- "p"; f <- function(x) UseMethod(g)` the generic is the value of `g` where `f` is defined */
76
78
  const accessedIdentifiers = node_value_1.NodeValue.knownStringsOf(generic.info.id, data);
79
+ if (accessedIdentifiers.length === 0 && r_symbol_1.RSymbol.is(generic)) {
80
+ const bound = data.environment.current.lookupLexically(identifier_1.Identifier.getName(generic.content)) ?? [];
81
+ accessedIdentifiers.push(...bound.flatMap(d => d.type === identifier_1.ReferenceType.BuiltInConstant || d.type === identifier_1.ReferenceType.BuiltInFunction ? [] : d.value ?? []).flatMap(value => node_value_1.NodeValue.knownStringsOf(value, data)));
82
+ }
77
83
  if (accessedIdentifiers.length === 0) {
78
84
  logger_1.dataflowLogger.warn('s3 dispatch with non-resolvable generic, skipping');
79
85
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
@@ -106,7 +106,7 @@ function processStringTemplate(name, args, rootId, data, config) {
106
106
  }
107
107
  const template = arg.value;
108
108
  /* one generator for the whole template so its interpolations do not collide on the same ids */
109
- const generator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(`${name.lexeme}::${template.info.id}`, template.location);
109
+ const generator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(`${name.lexeme}::${template.info.id}`);
110
110
  for (const code of interpolationsOf(template.content.str, open, close, config.markup)) {
111
111
  const result = (0, built_in_source_1.sourceRequest)(rootId, (0, retriever_1.requestFromInput)(code), data, information, false, generator, true);
112
112
  /* the template stands where the call does, so what it leaves open resolves against the bindings here */
@@ -6,6 +6,7 @@ import { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-s
6
6
  import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  import { type DataflowGraph } from '../../../../../graph/graph';
8
8
  import type { FlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
9
+ import { type REnvironmentInformation } from '../../../../../environments/environment';
9
10
  /**
10
11
  * Process a built-in try-catch or similar handler.
11
12
  */
@@ -17,5 +18,11 @@ export declare function processTryCatch<OtherInfo>(name: RSymbol<OtherInfo & Par
17
18
  };
18
19
  aborts?: boolean;
19
20
  }): DataflowInformation;
21
+ /**
22
+ * Links what a block catching errors may raise because a warning turns into one, where the `warn` option that does
23
+ * so is only known after linking: `g(options, warn = 2)` sets it through the function `g` is handed. Every call of
24
+ * the block written after such a write may then raise, so the construct's value reads it, and it reads the write.
25
+ */
26
+ export declare function linkLateWarningsAsErrors(graph: DataflowGraph, environment: REnvironmentInformation, idMap: AstIdMap): void;
20
27
  /** Orders the raising calls in every body a block catching errors may run, once per definition and after linking bound all calls. */
21
28
  export declare function orderRaisingBodies(graph: DataflowGraph, idMap: AstIdMap, ctx: FlowrAnalyzerContext): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processTryCatch = processTryCatch;
4
+ exports.linkLateWarningsAsErrors = linkLateWarningsAsErrors;
4
5
  exports.orderRaisingBodies = orderRaisingBodies;
5
6
  const condition_handlers_1 = require("../../../../../fn/condition-handlers");
6
7
  const function_semantics_1 = require("../../../../../fn/function-semantics");
@@ -33,6 +34,8 @@ const resolve_helper_1 = require("../../../../../environments/resolve-helper");
33
34
  const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
34
35
  const df_helper_1 = require("../../../../../graph/df-helper");
35
36
  const environment_1 = require("../../../../../environments/environment");
37
+ const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
38
+ const range_1 = require("../../../../../../util/range");
36
39
  /**
37
40
  * Process a built-in try-catch or similar handler.
38
41
  */
@@ -72,6 +75,7 @@ function processTryCatch(name, args, rootId, data, config) {
72
75
  const raised = (0, built_in_ambient_state_1.errorsOfWarnings)(block, info.environment, info.graph, data);
73
76
  for (const site of raised) {
74
77
  info.graph.addEdge(site.nodeId, rootId, edge_1.EdgeType.Reads);
78
+ info.graph.addEdge(rootId, site.nodeId, edge_1.EdgeType.Reads);
75
79
  }
76
80
  arg.exitPoints = arg.exitPoints.concat(raised);
77
81
  raising.push(...order(block, []));
@@ -174,6 +178,8 @@ function processTryCatch(name, args, rootId, data, config) {
174
178
  if (call !== undefined) {
175
179
  call.cds = [...call.cds ?? [], { id: rootId, when: true }];
176
180
  }
181
+ /* whether the block raises decides what the construct yields, its value or that of a handler */
182
+ info.graph.addEdge(rootId, id, edge_1.EdgeType.Reads);
177
183
  }
178
184
  const environment = mayAbort ? environment_1.REnvironment.append(data.environment, info.environment) : info.environment;
179
185
  return {
@@ -183,6 +189,42 @@ function processTryCatch(name, args, rootId, data, config) {
183
189
  kill: escapingKills
184
190
  };
185
191
  }
192
+ /**
193
+ * Links what a block catching errors may raise because a warning turns into one, where the `warn` option that does
194
+ * so is only known after linking: `g(options, warn = 2)` sets it through the function `g` is handed. Every call of
195
+ * the block written after such a write may then raise, so the construct's value reads it, and it reads the write.
196
+ */
197
+ function linkLateWarningsAsErrors(graph, environment, idMap) {
198
+ const writes = (resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.warnsAsErrors, environment) ?? []).filter(d => vertex_1.DfgVertex.isFunctionCall(graph.getVertex(d.nodeId)));
199
+ if (writes.length === 0) {
200
+ return;
201
+ }
202
+ const startOf = (id) => idMap.get(id)?.location;
203
+ for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
204
+ const call = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Try) ? idMap.get(id) : undefined;
205
+ const [block] = r_function_call_1.RFunctionCall.is(call) ? call.arguments : [];
206
+ const at = startOf(id);
207
+ const before = at === undefined ? [] : writes.filter(w => {
208
+ const written = startOf(w.nodeId);
209
+ return written !== undefined && range_1.SourceRange.compare(written, at) < 0 && !df_helper_1.Dataflow.hasEdge(graph, id, w.nodeId, edge_1.EdgeType.Reads);
210
+ });
211
+ if (block === undefined || block === r_function_call_1.EmptyArgument || before.length === 0) {
212
+ continue;
213
+ }
214
+ model_1.RNode.visitAst(block, n => {
215
+ if (r_function_definition_1.RFunctionDefinition.is(n)) {
216
+ return true;
217
+ }
218
+ else if (vertex_1.DfgVertex.isFunctionCall(graph.getVertex(n.info.id))) {
219
+ graph.addEdge(id, n.info.id, edge_1.EdgeType.Reads);
220
+ for (const write of before) {
221
+ graph.addEdge(n.info.id, write.nodeId, edge_1.EdgeType.Reads);
222
+ }
223
+ }
224
+ return false;
225
+ });
226
+ }
227
+ }
186
228
  /** Orders the raising calls in every body a block catching errors may run, once per definition and after linking bound all calls. */
187
229
  function orderRaisingBodies(graph, idMap, ctx) {
188
230
  const ordered = new Set();