@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
@@ -2,8 +2,14 @@ import type { RStringValue } from '../../../../r-bridge/lang-4.x/convert-values'
2
2
  import { type Value, type ValueString } from '../r-value';
3
3
  /** lift a raw string or R string value into a ValueString */
4
4
  export declare function stringFrom(str: RStringValue | string): ValueString;
5
- /** the characters an R string literal stands for (`"a\tb"` is three characters, not the four its source is written with); undefined for an escape R would reject */
5
+ /**
6
+ * The characters R stores for the content of a string literal, with its escapes undone as R's parser undoes them:
7
+ * `a\tb` is three characters. It is `undefined` where R rejects the literal (an unknown escape such as `\.`, a nul)
8
+ * or stores a byte no character stands for (`\xff`).
9
+ */
6
10
  export declare function unescapeRString(this: void, str: string): string | undefined;
11
+ /** the characters a string literal stands for, see {@link unescapeRString}: a raw string stands for its characters as written */
12
+ export declare function contentOf(this: void, { str, flag }: RStringValue): string | undefined;
7
13
  /** the {@link ValueString} an R string literal stands for, escapes resolved (a raw string has none, so it stands for its characters as written); undefined for an escape R would reject */
8
14
  export declare function stringFromLiteral(this: void, value: RStringValue): ValueString | undefined;
9
15
  /** collect strings from an array of ValueString, with quotes if `withQuotes`; undefined if any value is not a string, or is Bottom/Top */
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringFrom = stringFrom;
4
4
  exports.unescapeRString = unescapeRString;
5
+ exports.contentOf = contentOf;
5
6
  exports.stringFromLiteral = stringFromLiteral;
6
7
  exports.collectStrings = collectStrings;
7
8
  const general_1 = require("../general");
@@ -10,49 +11,50 @@ const r_value_1 = require("../r-value");
10
11
  function stringFrom(str) {
11
12
  return { type: 'string', value: typeof str === 'string' ? { quotes: '"', str } : str };
12
13
  }
13
- /** the escapes standing for exactly one character, everything else R writes as a numeric code */
14
+ /** the escapes of an R string that stand for one character each */
14
15
  const SimpleEscapes = {
15
- n: '\n',
16
- r: '\r',
17
- t: '\t',
18
- b: '\b',
19
- a: '\x07',
20
- f: '\f',
21
- v: '\v',
22
- '\\': '\\',
23
- '"': '"',
24
- '\'': '\'',
25
- '`': '`'
16
+ a: '\x07', b: '\b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\v', '\\': '\\', '"': '"', '\'': '\'', '`': '`', ' ': ' ', '\n': '\n'
26
17
  };
27
- /** the largest code point there is, so an `\U` escape naming none of them is rejected instead of throwing */
28
- const MaxCodePoint = 0x10FFFF;
29
- /** `\xnn`, `\u{nnnn}`, `\unnnn`, `\U{nnnnnnnn}`, `\Unnnnnnnn`, an octal `\nnn`, or a single-character escape */
30
- const EscapePattern = /\\(?:x([0-9a-fA-F]{1,2})|u\{([0-9a-fA-F]{1,6})\}|u([0-9a-fA-F]{1,4})|U\{([0-9a-fA-F]{1,8})\}|U([0-9a-fA-F]{1,8})|([0-7]{1,3})|([\s\S]))/g;
31
- /** the characters an R string literal stands for (`"a\tb"` is three characters, not the four its source is written with); undefined for an escape R would reject */
18
+ /** the escapes of an R string that state a code: octal, hex, and the unicode forms with and without braces */
19
+ const CodedEscape = /^(?:([0-7]{1,3})|x([0-9a-fA-F]{1,2})|u\{([0-9a-fA-F]{1,4})\}|u([0-9a-fA-F]{1,4})|U\{([0-9a-fA-F]{1,8})\}|U([0-9a-fA-F]{1,8}))/;
20
+ /**
21
+ * The characters R stores for the content of a string literal, with its escapes undone as R's parser undoes them:
22
+ * `a\tb` is three characters. It is `undefined` where R rejects the literal (an unknown escape such as `\.`, a nul)
23
+ * or stores a byte no character stands for (`\xff`).
24
+ */
32
25
  function unescapeRString(str) {
33
- if (!str.includes('\\')) {
34
- return str;
35
- }
36
- let rejected = false;
37
- const out = str.replace(EscapePattern, (_all, hex, uBraced, u, bigBraced, big, octal, single) => {
38
- const code = hex ?? uBraced ?? u ?? bigBraced ?? big;
39
- if (code !== undefined || octal !== undefined) {
40
- const point = code !== undefined ? parseInt(code, 16) : parseInt(octal, 8);
41
- rejected ||= point > MaxCodePoint;
42
- return point > MaxCodePoint ? '' : String.fromCodePoint(point);
26
+ let out = '';
27
+ for (let i = 0; i < str.length; i++) {
28
+ if (str[i] !== '\\') {
29
+ out += str[i];
30
+ continue;
31
+ }
32
+ const simple = SimpleEscapes[str[++i]];
33
+ if (simple !== undefined) {
34
+ out += simple;
35
+ continue;
43
36
  }
44
- const simple = single === undefined ? undefined : SimpleEscapes[single];
45
- rejected ||= simple === undefined;
46
- return simple ?? '';
47
- });
48
- return rejected ? undefined : out;
37
+ const coded = CodedEscape.exec(str.slice(i));
38
+ if (coded === null) {
39
+ return undefined;
40
+ }
41
+ const [whole, octal, hex, ...unicode] = coded;
42
+ const code = parseInt(octal ?? hex ?? unicode.find(u => u !== undefined) ?? '', octal === undefined ? 16 : 8);
43
+ if (code === 0 || code > 0x10FFFF || (code >= 0xD800 && code <= 0xDFFF) || ((octal ?? hex) !== undefined && code > 0x7F)) {
44
+ return undefined;
45
+ }
46
+ out += String.fromCodePoint(code);
47
+ i += whole.length - 1;
48
+ }
49
+ return out;
50
+ }
51
+ /** the characters a string literal stands for, see {@link unescapeRString}: a raw string stands for its characters as written */
52
+ function contentOf({ str, flag }) {
53
+ return flag === 'raw' ? str : unescapeRString(str);
49
54
  }
50
55
  /** the {@link ValueString} an R string literal stands for, escapes resolved (a raw string has none, so it stands for its characters as written); undefined for an escape R would reject */
51
56
  function stringFromLiteral(value) {
52
- if (value.flag === 'raw') {
53
- return stringFrom(value);
54
- }
55
- const str = unescapeRString(value.str);
57
+ const str = contentOf(value);
56
58
  return str === undefined ? undefined : stringFrom({ ...value, str });
57
59
  }
58
60
  /** collect strings from an array of ValueString, with quotes if `withQuotes`; undefined if any value is not a string, or is Bottom/Top */
@@ -40,6 +40,7 @@ const gas_1 = require("../gas");
40
40
  const config_1 = require("../config");
41
41
  const df_helper_1 = require("./graph/df-helper");
42
42
  const built_in_ambient_state_1 = require("./internal/process/functions/call/built-in/built-in-ambient-state");
43
+ const ambient_state_name_1 = require("./environments/ambient-state-name");
43
44
  const unnamed_call_handling_1 = require("./internal/process/functions/call/unnamed-call-handling");
44
45
  const built_in_proc_name_1 = require("./environments/built-in-proc-name");
45
46
  const arrays_1 = require("../util/collections/arrays");
@@ -50,6 +51,8 @@ const query_fn_props_1 = require("./environments/query-fn-props");
50
51
  const resolve_helper_1 = require("./environments/resolve-helper");
51
52
  const happens_before_1 = require("../control-flow/happens-before");
52
53
  const assert_1 = require("../util/assert");
54
+ const node_value_1 = require("./eval/resolve/node-value");
55
+ const r_argument_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-argument");
53
56
  /**
54
57
  * The best friend of {@link produceDataFlowGraph} and {@link processDataflowFor}.
55
58
  * Maps every {@link RType} in the normalized AST to a processor.
@@ -151,7 +154,7 @@ function openReadsOfCalledFunctions(graph) {
151
154
  for (const [id, definition] of graph.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
152
155
  if (df_helper_1.Dataflow.sourcesOf(graph, id, edge_1.EdgeType.Calls).length > 0) {
153
156
  for (const read of definition.subflow.in) {
154
- if (read.name !== undefined && !built_in_ambient_state_1.AmbientStateName.is(read.name) && !identifier_1.Identifier.getName(read.name).startsWith(unnamed_call_handling_1.UnnamedFunctionCallPrefix)) {
157
+ if (read.name !== undefined && !ambient_state_name_1.AmbientStateName.is(read.name) && !identifier_1.Identifier.getName(read.name).startsWith(unnamed_call_handling_1.UnnamedFunctionCallPrefix)) {
155
158
  reads.set(read.nodeId, read);
156
159
  }
157
160
  }
@@ -340,6 +343,104 @@ function linkResourceReadersToWriters(graph, environment, ctx) {
340
343
  }
341
344
  }
342
345
  }
346
+ /** The paths the {@link ArgProp.Resource} arguments of the file accessing call `id` name, `undefined` unless every one resolves to strings. */
347
+ function pathsOf(id, graph, environment, ctx, callContext) {
348
+ const vertex = graph.getVertex(id);
349
+ if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
350
+ return undefined;
351
+ }
352
+ const resources = argsWithProp((0, applied_arguments_1.appliedArguments)(graph, vertex), (0, query_fn_props_1.callFnProps)(id, { graph, environment }), built_in_props_1.ArgProp.Resource);
353
+ const paths = new Set();
354
+ for (const resource of resources) {
355
+ const strings = node_value_1.NodeValue.stringsOf(r_argument_1.RArgument.valueOf(graph.idMap?.get(resource)) ?? resource, resolve_helper_1.Resolve.info(graph, ctx), { callContext });
356
+ if (strings === undefined || strings.length === 0) {
357
+ return undefined;
358
+ }
359
+ strings.forEach(p => paths.add(p));
360
+ }
361
+ return resources.length === 0 ? undefined : paths;
362
+ }
363
+ /**
364
+ * The levels of calls that run the file write `writer`: the calls of the function holding it, then the calls of the
365
+ * function holding such a call, and so on. Each call resolves the file for the calls leading to it ({@link CallContext}).
366
+ * `undefined` unless the levels account for every call the write has an effect on (a recursive function, a call we
367
+ * do not see through), as only then can the write leave it to the calls to tell which of them run it.
368
+ */
369
+ function fileWriteLevels(writer, graph, idMap, paths) {
370
+ const affected = new Set(df_helper_1.Dataflow.targetsOf(graph, writer, edge_1.EdgeType.SideEffectOnCall));
371
+ const first = model_1.RNode.findEnclosing(writer, idMap, r_function_definition_1.RFunctionDefinition.is);
372
+ if (first === undefined || affected.size === 0) {
373
+ return undefined;
374
+ }
375
+ const levels = [];
376
+ const covered = new Set();
377
+ const queue = [{ at: writer, definition: first, context: new Map() }];
378
+ for (let item = queue.shift(); item !== undefined; item = queue.shift()) {
379
+ const { at, definition, context } = item;
380
+ const calls = [...affected].filter(c => df_helper_1.Dataflow.targetsOf(graph, c, edge_1.EdgeType.Calls).includes(definition));
381
+ if (calls.length === 0 || context.has(definition)) {
382
+ return undefined;
383
+ }
384
+ levels.push({ at, definition, calls: calls.map(call => {
385
+ covered.add(call);
386
+ const within = new Map(context).set(definition, call);
387
+ const outer = model_1.RNode.strictlyEnclosingFunction(call, idMap);
388
+ if (outer !== undefined) {
389
+ queue.push({ at: call, definition: outer, context: within });
390
+ }
391
+ return { call, paths: paths(within) };
392
+ }) });
393
+ }
394
+ return covered.size === affected.size ? levels : undefined;
395
+ }
396
+ /**
397
+ * A file written within a function is written at each of its calls, so whatever reads it reads the write in the body,
398
+ * which in turn depends on every call ({@link EdgeType.SideEffectOnCall}). Where the calls name their files, as
399
+ * `save <- function(n) writeLines("x", n)` does for `save("a.txt")` and `save("b.txt")`, a read reads the calls writing
400
+ * the file it reads as well, so the write no longer needs to depend on all of them: a read of `a.txt` needs `save("a.txt")`
401
+ * only. Through a function calling `save` in turn, the read reads the call within it and the calls of that function.
402
+ */
403
+ function separateFileWritesPerCall(graph, environment, ctx) {
404
+ const idMap = graph.idMap;
405
+ if (idMap === undefined) {
406
+ return;
407
+ }
408
+ const fileAccess = (0, defaultmap_1.memoize)((id) => {
409
+ const info = (0, query_fn_props_1.callFnProps)(id, { graph, environment });
410
+ return function_semantics_1.FunctionSemantics.call.props.hasAll(info, [built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Writes]) ? 'write'
411
+ : function_semantics_1.FunctionSemantics.call.props.hasAll(info, [built_in_props_1.SemanticCallTag.File, built_in_props_1.SemanticCallTag.Reads]) ? 'read' : undefined;
412
+ });
413
+ const readPaths = (0, defaultmap_1.memoize)((id) => fileAccess(id) === 'read' ? pathsOf(id, graph, environment, ctx) : undefined);
414
+ /* writing to the console (`cat(x)`) names no file, and has no call to tell apart */
415
+ const namesFile = (id) => {
416
+ const vertex = graph.getVertex(id);
417
+ return argsWithProp((0, applied_arguments_1.appliedArguments)(graph, vertex), (0, query_fn_props_1.callFnProps)(id, { graph, environment }), built_in_props_1.ArgProp.Resource).length > 0;
418
+ };
419
+ const writers = [...graph.verticesOfType(vertex_1.VertexType.FunctionCall)].map(([id]) => id)
420
+ .filter(id => graph.edgesFrom(id).values().some(e => edge_1.DfEdge.includesType(e, edge_1.EdgeType.SideEffectOnCall)) && !graph.unknownSideEffects.has(id) && fileAccess(id) === 'write' && namesFile(id));
421
+ const separated = new Set();
422
+ for (const writer of writers) {
423
+ const levels = fileWriteLevels(writer, graph, idMap, callContext => pathsOf(writer, graph, environment, ctx, callContext));
424
+ if (levels !== undefined) {
425
+ separated.add(writer);
426
+ }
427
+ for (const { at, definition, calls } of levels ?? []) {
428
+ const body = graph.getVertex(definition).subflow.graph;
429
+ /* what holds the definition (`(function(p) ...)`) is no reader of what its body writes */
430
+ const holders = new Set([...model_1.RNode.iterateParents(idMap.get(at), idMap)].map(n => n.info.id));
431
+ const readers = df_helper_1.Dataflow.sourcesOf(graph, at, edge_1.EdgeType.Reads).filter(r => !body.has(r) && !holders.has(r) && !calls.some(c => c.call === r));
432
+ for (const { call, paths } of calls) {
433
+ for (const reader of readers) {
434
+ const read = readPaths(reader);
435
+ if (read === undefined || paths === undefined || !read.isDisjointFrom(paths)) {
436
+ graph.addEdge(reader, call, edge_1.EdgeType.Reads);
437
+ }
438
+ }
439
+ }
440
+ }
441
+ }
442
+ graph.fileWritesPerCall = separated;
443
+ }
343
444
  /** A variable read linked to a call diverting the output (`sink(con)`, see `AmbientStateName.textConnection`) also reads what that call diverts. */
344
445
  function linkReadsOfDivertedOutput(graph, environment) {
345
446
  if (!(0, built_in_ambient_state_1.mayForce)(environment)) {
@@ -461,7 +562,7 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
461
562
  const foldedIn = new Set();
462
563
  const rounds = ctx.config.solver.transitiveSideEffectRounds ?? config_1.DefaultTransitiveSideEffectRounds;
463
564
  /* a read of the options or graphics state nothing set reads the state R starts with, unless a write escaping a call replaces it */
464
- const [initialState, open] = (0, arrays_1.partitionArray)(df.in, r => built_in_ambient_state_1.AmbientStateName.is(r.name));
565
+ const [initialState, open] = (0, arrays_1.partitionArray)(df.in, r => ambient_state_name_1.AmbientStateName.is(r.name));
465
566
  for (let round = 0; round < rounds; round++) {
466
567
  const { environment, grew, escapedNames: roundNames } = df_helper_1.Dataflow.sideEffects.propagateTransitive(df.graph, df.environment, ctx, foldedIn, initialState);
467
568
  df.environment = environment;
@@ -484,12 +585,14 @@ function extractDataFlowGraph(parser, completeAst, ctx) {
484
585
  const cleanEnvironment = ctx.env.makeCleanEnv();
485
586
  (0, linker_1.separateClosureInstances)(df.graph, name => (0, query_fn_props_1.queryFnProps)(name, { environment: cleanEnvironment }));
486
587
  function_semantics_1.FunctionSemantics.call.quoted.finalize(df.graph, df.environment, completeAst.idMap, () => new control_flow_graph_1.ControlFlowGraph(df.graph));
588
+ (0, built_in_try_catch_1.linkLateWarningsAsErrors)(df.graph, df.environment, completeAst.idMap);
487
589
  (0, built_in_try_catch_1.orderRaisingBodies)(df.graph, completeAst.idMap, ctx);
488
590
  function_semantics_1.FunctionSemantics.settleJumpsInPromises(df.graph, df.exitPoints, { ctx });
489
591
  linkEnvironmentArgumentsWrittenByCallee(df.graph, df.environment);
490
592
  resolveLinkToSideEffects(df.graph, ctx);
491
593
  linkResourceReadersToWriters(df.graph, df.environment, ctx);
492
594
  linkReadsOfDivertedOutput(df.graph, df.environment);
595
+ separateFileWritesPerCall(df.graph, df.environment, ctx);
493
596
  return df;
494
597
  }
495
598
  //# sourceMappingURL=extractor.js.map
@@ -135,8 +135,12 @@ function statedRoles(definition, state) {
135
135
  const byName = formalsByName(definition, state);
136
136
  const roles = new Map();
137
137
  const add = (node, props) => {
138
+ /* forcing `if(c) a else b` evaluates only one of `a` and `b`, so neither is forced for certain */
139
+ const always = (props & built_in_props_1.ArgProp.Forced) === 0 ? undefined : identityFrom(node, state, 0, new Set());
140
+ const written = writtenFormal(node, byName, state);
138
141
  for (const formal of aliasTargets(node, byName, state)) {
139
- roles.set(formal, (roles.get(formal) ?? 0) | props);
142
+ const own = always === undefined || always.has(formal) || formal === written ? props : props & ~built_in_props_1.ArgProp.Forced;
143
+ roles.set(formal, (roles.get(formal) ?? 0) | own);
140
144
  }
141
145
  };
142
146
  for (const [node, vertex] of df_helper_1.Dataflow.callsIn(definition, state.graph)) {
@@ -168,7 +172,7 @@ function calledNames(id, vertex, state) {
168
172
  const called = identifier_1.Identifier.getName(vertex.name);
169
173
  return [...state.graph.edgesFrom(id)]
170
174
  .filter(([target, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && !handed.has(target) && !node_id_1.NodeId.isBuiltIn(target)
171
- && node_id_1.NodeId.recoverName(target, state.graph.idMap) === called)
175
+ && node_id_1.NodeId.recoverBareName(target, state.graph.idMap) === called)
172
176
  .map(([target]) => target);
173
177
  }
174
178
  /**
@@ -191,18 +195,25 @@ function aliasTargets(node, byName, state) {
191
195
  }
192
196
  }
193
197
  }
194
- const written = state.graph.idMap?.get(node);
195
- const formal = r_symbol_1.RSymbol.is(written) ? byName.get(written.lexeme) : undefined;
198
+ const formal = writtenFormal(node, byName, state);
196
199
  if (formal !== undefined) {
197
200
  found.add(formal);
198
201
  }
199
202
  return found;
200
203
  }
201
- /** The formals of the definition by the name they are written as, to answer for an argument nothing links. */
204
+ /**
205
+ * The formal parameter a symbol argument names. In `f <- function(x) quote(x)` the `x` of `quote` is never evaluated,
206
+ * so no edge links it to the formal `x`, and its name is all there is to go by.
207
+ */
208
+ function writtenFormal(node, byName, state) {
209
+ const name = r_symbol_1.RSymbol.is(state.graph.idMap?.get(node)) ? node_id_1.NodeId.recoverBareName(node, state.graph.idMap) : undefined;
210
+ return name === undefined ? undefined : byName.get(name);
211
+ }
212
+ /** The formals of `definition` by name, for {@link writtenFormal}. */
202
213
  function formalsByName(definition, state) {
203
214
  const byName = new Map();
204
215
  for (const formal of Object.keys(definition.params)) {
205
- const name = node_id_1.NodeId.recoverName(node_id_1.NodeId.normalize(formal), state.graph.idMap);
216
+ const name = node_id_1.NodeId.recoverBareName(node_id_1.NodeId.normalize(formal), state.graph.idMap);
206
217
  if (name !== undefined) {
207
218
  byName.set(name, node_id_1.NodeId.normalize(formal));
208
219
  }
@@ -237,8 +248,11 @@ function matchArgumentProps(vertex, state) {
237
248
  if (props === 0) {
238
249
  continue;
239
250
  }
240
- for (const argument of bound.get(formal) ?? []) {
241
- found.push([props, values.get(argument) ?? argument]);
251
+ const given = bound.get(formal) ?? [];
252
+ for (const [i, argument] of given.entries()) {
253
+ /* an alias on `...` is only the last argument */
254
+ const had = formal === '...' && i < given.length - 1 ? props & ~built_in_props_1.ArgProp.Alias : props;
255
+ found.push([had, values.get(argument) ?? argument]);
242
256
  }
243
257
  }
244
258
  return found;
@@ -59,6 +59,7 @@ export declare const FunctionSemantics: {
59
59
  readonly filter: (this: void, stated: import("../environments/built-in-props").StatedProps | undefined, selector: import("../environments/built-in-props").PropSelector) => import("../environments/built-in-props").StatedProps;
60
60
  readonly key: (this: void, selector: import("../environments/built-in-props").PropSelector) => string;
61
61
  readonly names: (this: void, selector: import("../environments/built-in-props").PropSelector) => string[];
62
+ readonly vocabulary: Readonly<Record<import("../environments/built-in-props").CallProp, import("../environments/built-in-props").PropWord>>;
62
63
  readonly labels: (this: void, stated: import("../environments/built-in-props").StatedProps | undefined) => string[];
63
64
  readonly words: (this: void, props: CallProps | undefined) => string[];
64
65
  readonly mask: (this: void, names: readonly string[]) => import("../environments/built-in-props").PropMask;
@@ -77,7 +78,7 @@ export declare const FunctionSemantics: {
77
78
  };
78
79
  /** The same as {@link FunctionSemantics.call.props}, for one argument. */
79
80
  readonly argument: {
80
- readonly names: Readonly<Record<import("../environments/built-in-props").ArgProp, string>>;
81
+ readonly vocabulary: Readonly<Record<import("../environments/built-in-props").ArgProp, import("../environments/built-in-props").PropWord>>;
81
82
  readonly words: (props: ArgProps | undefined) => string[];
82
83
  readonly mask: (names: readonly string[]) => ArgProps;
83
84
  };
@@ -114,7 +115,7 @@ export declare const FunctionSemantics: {
114
115
  readonly indexOf: <Info>(this: void, graph: import("../..").DataflowGraph, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>) => import("../internal/process/functions/call/deferred").NameIndex;
115
116
  readonly forcedAt: (this: void, graph: import("../..").DataflowGraph, binding: import("../..").NodeId, cfg: import("../../control-flow/control-flow-graph").ControlFlowGraph, viaClosures?: boolean) => readonly import("../..").NodeId[];
116
117
  readonly publish: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, at: import("../..").NodeId, sites: readonly import("../..").NodeId[], cfg?: import("../../control-flow/control-flow-graph").ControlFlowGraph) => void;
117
- readonly link: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, forces?: import("../internal/process/functions/call/deferred").ForceSites) => void;
118
+ readonly link: <Info>(this: void, graph: import("../..").DataflowGraph, expr: import("../..").NodeId, index: import("../internal/process/functions/call/deferred").NameIndex, idMap: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").AstIdMap<Info & import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>, forces?: import("../internal/process/functions/call/deferred").ForceSites, inCallerFrame?: boolean) => void;
118
119
  };
119
120
  /** The calls that change the environment in ways flowR cannot follow. */
120
121
  readonly unsupported: {
@@ -64,6 +64,12 @@ function hasProcessor(vertex, of) {
64
64
  function enclosingDefinition(id, idMap, graph) {
65
65
  return model_1.RNode.findEnclosing(id, idMap, node => vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(node.info.id)));
66
66
  }
67
+ /** The `UseMethod` call of a dispatch vertex: the vertex sits on the generic argument, `"f"` in `UseMethod("f", x)`. */
68
+ function dispatchCallOf(id, idMap) {
69
+ const node = idMap.get(id);
70
+ const argument = node !== undefined && node.info.role === "arg-v" /* RoleInParent.ArgumentValue */ ? model_1.RNode.directParent(node, idMap) : undefined;
71
+ return argument === undefined ? node : model_1.RNode.directParent(argument, idMap);
72
+ }
67
73
  /** The definitions whose body dispatches, with what each dispatch does with the arguments. */
68
74
  function dispatchingDefinitions(graph) {
69
75
  const idMap = graph.idMap;
@@ -79,7 +85,7 @@ function dispatchingDefinitions(graph) {
79
85
  if (within === undefined) {
80
86
  continue;
81
87
  }
82
- const node = idMap.get(id);
88
+ const node = dispatchCallOf(id, idMap);
83
89
  const known = dispatch.get(within);
84
90
  dispatch.set(within, {
85
91
  named: (r_function_call_1.RFunctionCall.is(node) && node.arguments.length > 1) || (known?.named ?? false),
@@ -439,11 +445,16 @@ function forcingPointsOf(params, graph, idMap, seen = new Set()) {
439
445
  const owner = idMap.get(idMap.get(param)?.info.parent ?? -1)?.info.parent;
440
446
  for (const read of df_helper_1.Dataflow.sourcesOf(graph, param, edge_1.EdgeType.Reads)) {
441
447
  found.push(read);
448
+ /* only a closure within the function owning the parameter captures it, a read elsewhere is no call of one */
449
+ const closures = [];
442
450
  let closure = model_1.RNode.findEnclosing(read, idMap, r_function_definition_1.RFunctionDefinition.is);
443
451
  while (closure !== undefined && closure !== owner) {
444
- found.push(...df_helper_1.Dataflow.sourcesOf(graph, closure, edge_1.EdgeType.Calls));
452
+ closures.push(closure);
445
453
  closure = model_1.RNode.strictlyEnclosingFunction(closure, idMap);
446
454
  }
455
+ if (closure === owner) {
456
+ found.push(...closures.flatMap(c => df_helper_1.Dataflow.sourcesOf(graph, c, edge_1.EdgeType.Calls)));
457
+ }
447
458
  /* a read that is an argument hands the promise on */
448
459
  for (const holder of df_helper_1.Dataflow.sourcesOf(graph, read, edge_1.EdgeType.Argument)) {
449
460
  const call = graph.getVertex(holder);
@@ -2,7 +2,7 @@ import { DataflowGraph } from './graph';
2
2
  import { EdgeType } from './edge';
3
3
  import { emptyGraph } from './dataflowgraph-builder';
4
4
  import { getOriginInDfg } from '../origin/dfg-get-origin';
5
- import { computeCallGraphSummaries, propagateTransitiveSideEffects } from '../internal/process/functions/call/built-in/transitive-side-effects';
5
+ import { ambientWritesOfFunctions, computeCallGraphSummaries, propagateTransitiveSideEffects } from '../internal/process/functions/call/built-in/transitive-side-effects';
6
6
  import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  import type { REnvironmentInformation } from '../environments/environment';
8
8
  import { type DataflowGraphVertexFunctionCall, type DataflowGraphVertexFunctionDefinition, type DataflowGraphVertexInfo } from './vertex';
@@ -120,6 +120,14 @@ export declare const Dataflow: {
120
120
  * @param environment - The environment to resolve the call name in, if the call does not carry one itself
121
121
  */
122
122
  readonly callTargetsOf: (this: void, call: NodeId, graph: DataflowGraph, environment?: REnvironmentInformation) => NodeId[];
123
+ /**
124
+ * Whether every function the call may run is a built-in or one the program defines, so that what flowR knows
125
+ * about those functions is all there is to know about the call. In `f <- function(x) x; do.call(f, list(1))` the
126
+ * symbol `f` is called this way, while in `g <- get(name); g(1)` it is not known what `g` runs.
127
+ * A call of a name the program binds nowhere runs what a package exports under that name, which counts as known.
128
+ * @see {@link Dataflow.callTargetsOf} - for the targets themselves
129
+ */
130
+ readonly callsOnlyKnownFunctions: (this: void, call: NodeId, graph: DataflowGraph, environment?: REnvironmentInformation) => boolean;
123
131
  /**
124
132
  * The calls within the body of a function definition, id and vertex paired.
125
133
  * @see {@link Dataflow.calleeIdsOf} - for what a single call calls
@@ -144,6 +152,11 @@ export declare const Dataflow: {
144
152
  readonly sideEffects: {
145
153
  readonly propagateTransitive: typeof propagateTransitiveSideEffects;
146
154
  readonly callGraphSummaries: typeof computeCallGraphSummaries;
155
+ /**
156
+ * The global state each function may leave changed when called, as pseudo variable names ({@link AmbientStateName}),
157
+ * including what the functions it calls change. Writes only to the function's own frame are left out.
158
+ */
159
+ readonly ambientWrites: typeof ambientWritesOfFunctions;
147
160
  };
148
161
  /**
149
162
  * Only returns the sub-part of the graph that is determined by the given selection.
@@ -12,7 +12,6 @@ const vertex_1 = require("./vertex");
12
12
  const identifier_1 = require("../environments/identifier");
13
13
  const r_base_packages_1 = require("../../util/r-base-packages");
14
14
  const defaultmap_1 = require("../../util/collections/defaultmap");
15
- const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
16
15
  const linker_1 = require("../internal/linker");
17
16
  const dfg_get_symbol_refs_1 = require("../origin/dfg-get-symbol-refs");
18
17
  /**
@@ -183,6 +182,16 @@ exports.Dataflow = {
183
182
  callTargetsOf(call, graph, environment) {
184
183
  return (0, linker_1.getAllFunctionCallTargets)(call, graph, environment);
185
184
  },
185
+ /**
186
+ * Whether every function the call may run is a built-in or one the program defines, so that what flowR knows
187
+ * about those functions is all there is to know about the call. In `f <- function(x) x; do.call(f, list(1))` the
188
+ * symbol `f` is called this way, while in `g <- get(name); g(1)` it is not known what `g` runs.
189
+ * A call of a name the program binds nowhere runs what a package exports under that name, which counts as known.
190
+ * @see {@link Dataflow.callTargetsOf} - for the targets themselves
191
+ */
192
+ callsOnlyKnownFunctions(call, graph, environment) {
193
+ return exports.Dataflow.callTargetsOf(call, graph, environment).every(t => node_id_1.NodeId.isBuiltIn(t) || vertex_1.DfgVertex.isFunctionDefinition(graph.getVertex(t)));
194
+ },
186
195
  /**
187
196
  * The calls within the body of a function definition, id and vertex paired.
188
197
  * @see {@link Dataflow.calleeIdsOf} - for what a single call calls
@@ -199,9 +208,9 @@ exports.Dataflow = {
199
208
  definitionsByName(graph) {
200
209
  const byName = new defaultmap_1.DefaultMap(() => []);
201
210
  for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
202
- const name = node_id_1.NodeId.recoverName(id, graph.idMap);
211
+ const name = node_id_1.NodeId.recoverBareName(id, graph.idMap);
203
212
  if (name !== undefined) {
204
- byName.get(r_string_1.RString.unquote(name)).push(id);
213
+ byName.get(name).push(id);
205
214
  }
206
215
  }
207
216
  return byName;
@@ -247,6 +256,11 @@ exports.Dataflow = {
247
256
  sideEffects: {
248
257
  propagateTransitive: transitive_side_effects_1.propagateTransitiveSideEffects,
249
258
  callGraphSummaries: transitive_side_effects_1.computeCallGraphSummaries,
259
+ /**
260
+ * The global state each function may leave changed when called, as pseudo variable names ({@link AmbientStateName}),
261
+ * including what the functions it calls change. Writes only to the function's own frame are left out.
262
+ */
263
+ ambientWrites: transitive_side_effects_1.ambientWritesOfFunctions,
250
264
  },
251
265
  /**
252
266
  * Only returns the sub-part of the graph that is determined by the given selection.
@@ -380,6 +394,25 @@ const resolveQualification = (graph, id, vertex) => {
380
394
  const origins = exports.Dataflow.origin(graph, id);
381
395
  const name = vertex_1.DfgVertex.isFunctionCall(vertex) ? vertex.name : undefined;
382
396
  const bare = identifier_1.Identifier.toQualified(origins, name, false);
383
- return [bare, bare ?? identifier_1.Identifier.toQualified(origins, name, true)];
397
+ return [bare, bare ?? identifier_1.Identifier.toQualified(origins, name, true) ?? aliasedBaseR(graph, id, origins)];
384
398
  };
399
+ /**
400
+ * The base-R function an aliased call resolves to when it reaches nothing of the analyzed code, `utils::read.csv` for the
401
+ * `f()` of `f <- read.csv`, which the origins alone cannot tell from a call of the code, as both read the definition of `f`.
402
+ * Only a call reading such a binding is one, as an unknown `stat_summary(fun = mean)` is said to call `mean` as well.
403
+ */
404
+ function aliasedBaseR(graph, id, origins) {
405
+ if (!origins?.some(o => !('proc' in o) && !node_id_1.NodeId.isBuiltIn(o.id))) {
406
+ return undefined;
407
+ }
408
+ for (const [target, edge] of graph.edgesFrom(id)) {
409
+ if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && !node_id_1.NodeId.isBuiltIn(target)) {
410
+ return undefined;
411
+ }
412
+ }
413
+ const names = new Set(origins.flatMap(o => 'proc' in o && node_id_1.NodeId.isBuiltIn(o.proc) ? [node_id_1.NodeId.fromBuiltIn(o.proc)] : []));
414
+ const [name] = names;
415
+ const owner = names.size === 1 ? (0, r_base_packages_1.baseRExportOwner)(name) : undefined;
416
+ return owner === undefined ? undefined : identifier_1.Identifier.make(name, owner);
417
+ }
385
418
  //# sourceMappingURL=df-helper.js.map
@@ -138,6 +138,12 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
138
138
  * statement sourcing a file runs that file's statements in between. Set once the whole program is analyzed.
139
139
  */
140
140
  statementOrder: ReadonlyMap<NodeId, readonly [start: number, end: number]> | undefined;
141
+ /**
142
+ * The file writes within function bodies whose readers read the calls writing their file as well, so only a slice
143
+ * starting in their body needs every call they have an {@link EdgeType.SideEffectOnCall} on. Set once the whole
144
+ * program is analyzed.
145
+ */
146
+ fileWritesPerCall: ReadonlySet<NodeId> | undefined;
141
147
  private readonly _unknownSideEffects;
142
148
  constructor(idMap: AstIdMap | undefined);
143
149
  /** Contains the vertices of the root level graph (i.e., included those vertices from the complete graph, that are nested within function definitions) */
@@ -104,6 +104,12 @@ class DataflowGraph {
104
104
  * statement sourcing a file runs that file's statements in between. Set once the whole program is analyzed.
105
105
  */
106
106
  statementOrder;
107
+ /**
108
+ * The file writes within function bodies whose readers read the calls writing their file as well, so only a slice
109
+ * starting in their body needs every call they have an {@link EdgeType.SideEffectOnCall} on. Set once the whole
110
+ * program is analyzed.
111
+ */
112
+ fileWritesPerCall;
107
113
  /*
108
114
  * Set of vertices which have sideEffects that we do not know anything about.
109
115
  * As a (temporary) solution until we have FD edges, a side effect may also store known target links
@@ -83,7 +83,10 @@ export declare const ClosureRefs: {
83
83
  };
84
84
  /** The field an access names, if it is written out: `x$f`, `x[["f"]]`, or `x[[2]]`, which is how a list records its positional entries. */
85
85
  export declare function accessedFieldName(fieldNode: RNode<ParentInformation> | undefined, treatIndicesAsString: boolean | undefined): string | undefined;
86
- /** Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns. */
86
+ /**
87
+ * Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns,
88
+ * and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`.
89
+ */
87
90
  export declare function linkFieldReads(graph: DataflowGraph, accessId: NodeId, fieldDefs: readonly IdentifierDefinition[] | undefined, returnsFunctions: boolean): void;
88
91
  /**
89
92
  * An access `x$f` written where `x` was still open reads the field of whatever `x` is bound to once that binding is
@@ -73,7 +73,7 @@ function findNonLocalReads(graph, ignores = new Set()) {
73
73
  }
74
74
  }
75
75
  if (!linked || nonLocal) {
76
- nonLocalReads.push({ nodeId, name: node_id_1.NodeId.recoverName(nodeId, graph.idMap), type });
76
+ nonLocalReads.push({ nodeId, name: node_id_1.NodeId.recoverBareName(nodeId, graph.idMap), type });
77
77
  }
78
78
  }
79
79
  }
@@ -147,7 +147,7 @@ function linkFunctionCallWithSingleTarget(graph, { subflow: fnSubflow, exitPoint
147
147
  for (const captured of df_helper_1.Dataflow.targetsOf(graph, node, edge_1.EdgeType.Reads)) {
148
148
  const frame = fnSubflow.graph.has(captured) ? undefined : model_1.RNode.findEnclosing(captured, idMap, r_function_definition_1.RFunctionDefinition.is);
149
149
  const owner = frame === undefined ? undefined : graph.getVertex(frame);
150
- const name = node_id_1.NodeId.recoverName(captured, idMap);
150
+ const name = node_id_1.NodeId.recoverBareName(captured, idMap);
151
151
  const envState = vertex_2.DfgVertex.isFunctionDefinition(owner) && name !== undefined ? resolve_helper_1.Resolve.byName(name, owner.subflow.environment)?.filter(identifier_1.hasEnvState).find(d => d.nodeId === captured)?.envState : undefined;
152
152
  if (envState !== undefined) {
153
153
  linkFieldWritesOnCall(graph, id, fnId, node, captured, envState, idMap);
@@ -322,7 +322,8 @@ function getAllLinkedFunctionDefinitions(functionDefinitionReadIds, dataflowGrap
322
322
  let followTargets;
323
323
  /* a list handed on as a whole (a loop, an apply) yields its entries, an access the entry it names */
324
324
  const handedBack = !viaAccess && vertex_2.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.List) ? edge_1.EdgeType.Returns | edge_1.EdgeType.Argument : edge_1.EdgeType.Returns;
325
- const returnedTo = vertex_2.DfgVertex.isFunctionCall(vertex) ? cid : call;
325
+ /* only a call into a body binds parameters, a built-in hands back what it is given in the same context */
326
+ const returnedTo = vertex_2.DfgVertex.isFunctionCall(vertex) && !vertex.onlyBuiltin ? cid : call;
326
327
  for (const [target, e] of dataflowGraph.edgesFrom(cid)) {
327
328
  if (edge_1.DfEdge.includesType(e, handedBack)) {
328
329
  hasReturnEdge = true;
@@ -507,14 +508,17 @@ function accessedFieldName(fieldNode, treatIndicesAsString) {
507
508
  return r_number_1.RNumber.is(fieldNode) && !fieldNode.content.complexNumber && Number.isInteger(fieldNode.content.num) && fieldNode.content.num > 0
508
509
  ? String(fieldNode.content.num) : undefined;
509
510
  }
510
- /** Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns. */
511
+ /**
512
+ * Links the access at `accessId` to the `fieldDefs` it reaches; a function held in a field is what the access returns,
513
+ * and so may be a field of unknown kind, like the `read.csv` of `assign("f", read.csv, envir = e)`.
514
+ */
511
515
  function linkFieldReads(graph, accessId, fieldDefs, returnsFunctions) {
512
516
  for (const fd of fieldDefs ?? []) {
513
517
  graph.addEdge(accessId, fd.nodeId, edge_1.EdgeType.Reads);
514
518
  if (fd.definedAt !== undefined && fd.definedAt !== fd.nodeId) {
515
519
  graph.addEdge(accessId, fd.definedAt, edge_1.EdgeType.Reads);
516
520
  }
517
- if (returnsFunctions && fd.type === identifier_1.ReferenceType.Function) {
521
+ if (returnsFunctions && (fd.type & (identifier_1.ReferenceType.Function | identifier_1.ReferenceType.Unknown)) !== 0) {
518
522
  graph.addEdge(accessId, fd.nodeId, edge_1.EdgeType.Returns);
519
523
  }
520
524
  }
@@ -573,11 +577,11 @@ function factoryOf(closure, graph, known, idMap) {
573
577
  return undefined;
574
578
  }
575
579
  else if (vertex_2.DfgVertex.isVariableDefinition(vertex)) {
576
- locals.add(node_id_1.NodeId.recoverName(node, idMap) ?? '');
580
+ locals.add(node_id_1.NodeId.recoverBareName(node, idMap) ?? '');
577
581
  }
578
582
  }
579
583
  for (const param of Object.keys(factory.params)) {
580
- locals.add(node_id_1.NodeId.recoverName(node_id_1.NodeId.normalize(param), idMap) ?? '');
584
+ locals.add(node_id_1.NodeId.recoverBareName(node_id_1.NodeId.normalize(param), idMap) ?? '');
581
585
  }
582
586
  return { factory: factory.id, locals };
583
587
  }