@eagleoutice/flowr 2.14.1 → 2.14.3

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 (419) hide show
  1. package/README.md +142 -87
  2. package/abstract-interpretation/absint-visitor.d.ts +132 -25
  3. package/abstract-interpretation/absint-visitor.js +459 -99
  4. package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +1 -1
  5. package/abstract-interpretation/data-frame/mappers/access-mapper.js +4 -4
  6. package/abstract-interpretation/data-frame/mappers/arguments.d.ts +1 -1
  7. package/abstract-interpretation/data-frame/mappers/arguments.js +1 -1
  8. package/abstract-interpretation/data-frame/mappers/function-mapper.js +107 -254
  9. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +5 -5
  10. package/abstract-interpretation/data-frame/resolve-args.d.ts +1 -1
  11. package/abstract-interpretation/data-frame/resolve-args.js +6 -4
  12. package/abstract-interpretation/data-frame/shape-inference.d.ts +4 -9
  13. package/abstract-interpretation/domains/bounded-set-domain.d.ts +1 -0
  14. package/abstract-interpretation/domains/bounded-set-domain.js +1 -0
  15. package/abstract-interpretation/domains/partial-product-domain.js +1 -1
  16. package/abstract-interpretation/domains/set-range-domain.d.ts +3 -2
  17. package/abstract-interpretation/domains/set-range-domain.js +3 -2
  18. package/abstract-interpretation/domains/set-upper-bound-domain.d.ts +3 -2
  19. package/abstract-interpretation/domains/set-upper-bound-domain.js +3 -2
  20. package/benchmark/calibration.d.ts +11 -6
  21. package/benchmark/calibration.js +19 -8
  22. package/benchmark/slicer.d.ts +7 -1
  23. package/benchmark/slicer.js +38 -34
  24. package/benchmark/stats/count-comments.d.ts +16 -0
  25. package/benchmark/stats/count-comments.js +30 -0
  26. package/benchmark/stats/print.js +2 -0
  27. package/benchmark/stats/size-of.d.ts +7 -3
  28. package/benchmark/stats/size-of.js +7 -3
  29. package/benchmark/stats/stats.d.ts +7 -0
  30. package/benchmark/summarizer/first-phase/process.js +2 -19
  31. package/benchmark/summarizer/second-phase/graph.js +13 -3
  32. package/benchmark/summarizer/second-phase/process.js +2 -0
  33. package/cli/repl/commands/repl-dataflow.js +70 -27
  34. package/cli/repl/core.d.ts +1 -1
  35. package/cli/repl/core.js +1 -1
  36. package/cli/repl/parser/slice-query-parser.js +2 -1
  37. package/cli/repl/server/connection.d.ts +4 -0
  38. package/cli/repl/server/connection.js +19 -16
  39. package/cli/repl/server/messages/message-analysis.d.ts +1 -1
  40. package/config.d.ts +21 -8
  41. package/config.js +12 -5
  42. package/control-flow/basic-cfg-guided-visitor.d.ts +7 -2
  43. package/control-flow/basic-cfg-guided-visitor.js +37 -24
  44. package/control-flow/cfg-dead-code.js +44 -33
  45. package/control-flow/cfg-properties.js +2 -2
  46. package/control-flow/cfg-simplification.js +6 -5
  47. package/control-flow/cfg-to-basic-blocks.js +11 -13
  48. package/control-flow/control-flow-graph.d.ts +179 -189
  49. package/control-flow/control-flow-graph.js +400 -263
  50. package/control-flow/dfg-cfg-guided-visitor.d.ts +21 -3
  51. package/control-flow/dfg-cfg-guided-visitor.js +17 -13
  52. package/control-flow/diff-cfg.js +6 -14
  53. package/control-flow/happens-before.js +5 -4
  54. package/control-flow/semantic-cfg-guided-visitor.d.ts +44 -101
  55. package/control-flow/semantic-cfg-guided-visitor.js +6 -3
  56. package/control-flow/simple-visitor.js +14 -15
  57. package/control-flow/syntax-cfg-guided-visitor.d.ts +2 -1
  58. package/control-flow/useless-loop.js +18 -14
  59. package/core/steps/all/core/20-dataflow.d.ts +1 -3
  60. package/core/steps/pipeline/default-pipelines.d.ts +141 -157
  61. package/dataflow/cluster.js +7 -0
  62. package/dataflow/environments/apply-kill.d.ts +6 -0
  63. package/dataflow/environments/apply-kill.js +63 -31
  64. package/dataflow/environments/built-in-props.d.ts +5 -1
  65. package/dataflow/environments/built-in-props.js +4 -0
  66. package/dataflow/environments/built-in.d.ts +6 -3
  67. package/dataflow/environments/built-in.js +8 -5
  68. package/dataflow/environments/clone.d.ts +3 -3
  69. package/dataflow/environments/clone.js +5 -5
  70. package/dataflow/environments/default-builtin-config.d.ts +114 -3
  71. package/dataflow/environments/default-builtin-config.js +137 -35
  72. package/dataflow/environments/environment.d.ts +5 -5
  73. package/dataflow/environments/environment.js +5 -5
  74. package/dataflow/environments/identifier.d.ts +11 -1
  75. package/dataflow/environments/identifier.js +4 -1
  76. package/dataflow/environments/resolve-by-name.d.ts +7 -0
  77. package/dataflow/environments/resolve-by-name.js +12 -0
  78. package/dataflow/environments/resolve-helper.d.ts +3 -1
  79. package/dataflow/environments/resolve-helper.js +2 -0
  80. package/dataflow/eval/resolve/alias-tracking.d.ts +3 -3
  81. package/dataflow/eval/resolve/alias-tracking.js +3 -3
  82. package/dataflow/eval/resolve/match-arguments.js +7 -5
  83. package/dataflow/eval/resolve/node-value.d.ts +3 -1
  84. package/dataflow/eval/resolve/node-value.js +12 -0
  85. package/dataflow/eval/resolve/resolve-argument.js +5 -4
  86. package/dataflow/eval/resolve/resolve-operators.js +9 -6
  87. package/dataflow/eval/resolve/resolve-strings.js +2 -2
  88. package/dataflow/eval/resolve/resolve-working-directory.js +4 -3
  89. package/dataflow/eval/resolve/resolve.js +3 -2
  90. package/dataflow/eval/values/general.js +8 -5
  91. package/dataflow/extractor.d.ts +1 -4
  92. package/dataflow/extractor.js +11 -10
  93. package/dataflow/fn/exceptions-of-function.d.ts +3 -1
  94. package/dataflow/fn/strict-function.js +7 -5
  95. package/dataflow/graph/call-graph.js +2 -2
  96. package/dataflow/graph/df-helper.d.ts +8 -1
  97. package/dataflow/graph/diff-dataflow-graph.d.ts +1 -1
  98. package/dataflow/graph/diff-dataflow-graph.js +19 -2
  99. package/dataflow/graph/edge.d.ts +38 -2
  100. package/dataflow/graph/edge.js +32 -2
  101. package/dataflow/graph/graph.d.ts +4 -3
  102. package/dataflow/graph/graph.js +6 -2
  103. package/dataflow/graph/match-args.d.ts +69 -0
  104. package/dataflow/graph/match-args.js +167 -0
  105. package/dataflow/info.d.ts +15 -6
  106. package/dataflow/info.js +0 -17
  107. package/dataflow/internal/control-flow.d.ts +114 -0
  108. package/dataflow/internal/control-flow.js +224 -0
  109. package/dataflow/internal/linker.d.ts +6 -31
  110. package/dataflow/internal/linker.js +24 -81
  111. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +1 -1
  112. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +3 -3
  113. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -2
  114. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +9 -6
  115. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
  116. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +6 -4
  117. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -10
  118. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +18 -37
  119. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -1
  120. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +3 -3
  121. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +1 -1
  122. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +11 -7
  123. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +6 -8
  124. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +1 -1
  125. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +18 -14
  126. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +18 -2
  127. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +12 -1
  128. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -1
  129. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +38 -30
  130. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +3 -2
  131. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -1
  132. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +36 -8
  133. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +1 -1
  134. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +20 -17
  135. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +1 -1
  136. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +6 -4
  137. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +4 -3
  138. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +9 -4
  139. package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.d.ts +2 -2
  140. package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +5 -5
  141. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +1 -1
  142. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +5 -4
  143. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +7 -5
  144. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +1 -1
  145. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +15 -13
  146. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +1 -1
  147. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +11 -2
  148. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
  149. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +4 -3
  150. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.d.ts +1 -1
  151. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +26 -4
  152. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +2 -2
  153. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +17 -4
  154. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -2
  155. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +71 -33
  156. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +6 -15
  157. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +13 -14
  158. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -1
  159. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +14 -11
  160. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +15 -1
  161. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +1 -1
  162. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +12 -8
  163. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -5
  164. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +1 -1
  165. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +5 -4
  166. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +2 -2
  167. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +50 -10
  168. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +2 -2
  169. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +20 -4
  170. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +6 -2
  171. package/dataflow/internal/process/functions/call/common.js +5 -6
  172. package/dataflow/internal/process/functions/call/deferred.js +2 -2
  173. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +12 -2
  174. package/dataflow/internal/process/functions/call/known-call-handling.js +41 -15
  175. package/dataflow/internal/process/functions/call/named-call-handling.js +2 -0
  176. package/dataflow/internal/process/functions/call/nse.d.ts +1 -1
  177. package/dataflow/internal/process/functions/call/nse.js +6 -1
  178. package/dataflow/internal/process/functions/call/quoted.js +2 -2
  179. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +19 -6
  180. package/dataflow/internal/process/functions/process-argument.d.ts +1 -1
  181. package/dataflow/internal/process/functions/process-argument.js +12 -4
  182. package/dataflow/internal/process/functions/process-parameter.js +13 -0
  183. package/dataflow/internal/process/process-named-call.d.ts +2 -2
  184. package/dataflow/internal/process/process-named-call.js +9 -7
  185. package/documentation/data/server/doc-data-server-messages.js +4 -4
  186. package/documentation/doc-readme.js +33 -0
  187. package/documentation/doc-util/doc-cfg.d.ts +8 -7
  188. package/documentation/doc-util/doc-cfg.js +10 -10
  189. package/documentation/doc-util/doc-playground.d.ts +12 -0
  190. package/documentation/doc-util/doc-playground.js +21 -0
  191. package/documentation/doc-util/doc-query.d.ts +4 -1
  192. package/documentation/doc-util/doc-query.js +4 -2
  193. package/documentation/wiki-absint.d.ts +3 -4
  194. package/documentation/wiki-absint.js +17 -5
  195. package/documentation/wiki-analyzer.js +2 -2
  196. package/documentation/wiki-cfg.js +101 -106
  197. package/documentation/wiki-dataflow-graph.js +84 -53
  198. package/documentation/wiki-interface.js +1 -0
  199. package/documentation/wiki-linter.js +15 -1
  200. package/documentation/wiki-linting-and-testing.js +1 -16
  201. package/documentation/wiki-mk/doc-maker.js +6 -4
  202. package/documentation/wiki-query.js +14 -4
  203. package/documentation/wiki-signature-database.js +28 -2
  204. package/linter/linter-fix.d.ts +16 -0
  205. package/linter/linter-fix.js +104 -0
  206. package/linter/linter-format.d.ts +18 -1
  207. package/linter/linter-format.js +31 -1
  208. package/linter/linter-output.js +46 -10
  209. package/linter/linter-rules.d.ts +40 -9
  210. package/linter/linter-rules.js +2 -0
  211. package/linter/rules/absolute-path.js +4 -2
  212. package/linter/rules/dataframe-access-validation.js +6 -7
  213. package/linter/rules/deprecated-functions.d.ts +107 -10
  214. package/linter/rules/deprecated-functions.js +311 -23
  215. package/linter/rules/file-path-validity.js +5 -4
  216. package/linter/rules/function-finder-util.d.ts +6 -0
  217. package/linter/rules/function-finder-util.js +21 -13
  218. package/linter/rules/naming-convention.js +1 -1
  219. package/linter/rules/network-functions.d.ts +2 -2
  220. package/linter/rules/stop-with-call-arg.js +2 -2
  221. package/linter/rules/unclosed-connection.js +2 -2
  222. package/linter/rules/undefined-symbol-util.js +6 -4
  223. package/linter/rules/undefined-symbol.js +2 -2
  224. package/linter/rules/unused-definition.js +8 -4
  225. package/linter/rules/unused-import.d.ts +60 -0
  226. package/linter/rules/unused-import.js +179 -0
  227. package/package.json +2 -2
  228. package/project/attached-packages.js +2 -1
  229. package/project/cache/flowr-analyzer-cache.d.ts +2 -5
  230. package/project/cache/flowr-analyzer-cache.js +4 -7
  231. package/project/cache/flowr-analyzer-controlflow-cache.d.ts +9 -8
  232. package/project/cache/flowr-analyzer-controlflow-cache.js +17 -34
  233. package/project/cache/flowr-cache.d.ts +9 -0
  234. package/project/cache/flowr-cache.js +19 -0
  235. package/project/context/flowr-analyzer-context.d.ts +7 -3
  236. package/project/context/flowr-analyzer-context.js +15 -9
  237. package/project/context/flowr-analyzer-dependencies-context.d.ts +24 -3
  238. package/project/context/flowr-analyzer-dependencies-context.js +9 -14
  239. package/project/context/flowr-analyzer-files-context.js +15 -17
  240. package/project/context/flowr-analyzer-meta-context.js +2 -12
  241. package/project/dependency-version-space.d.ts +1 -7
  242. package/project/dependency-version-space.js +9 -8
  243. package/project/flowr-analyzer-builder.d.ts +4 -4
  244. package/project/flowr-analyzer.d.ts +4 -6
  245. package/project/flowr-analyzer.js +4 -5
  246. package/project/plugins/file-plugins/files/flowr-namespace-file.js +22 -34
  247. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +13 -13
  248. package/project/plugins/file-plugins/files/flowr-rda-file.js +131 -286
  249. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +1 -0
  250. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -0
  251. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +2 -5
  252. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +2 -8
  253. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +32 -0
  254. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +43 -1
  255. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +4 -12
  256. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +3 -16
  257. package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.d.ts +5 -8
  258. package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.js +4 -10
  259. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +3 -10
  260. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +1 -13
  261. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.d.ts +3 -6
  262. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.js +2 -8
  263. package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.d.ts +2 -5
  264. package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.js +2 -8
  265. package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.d.ts +2 -5
  266. package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.js +2 -8
  267. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.d.ts +3 -4
  268. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -6
  269. package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.d.ts +4 -12
  270. package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.js +3 -16
  271. package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.d.ts +4 -12
  272. package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.js +3 -16
  273. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +4 -12
  274. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -16
  275. package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.d.ts +2 -5
  276. package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.js +2 -8
  277. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +2 -6
  278. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +1 -10
  279. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.d.ts +2 -5
  280. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.js +2 -8
  281. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +2 -1
  282. package/project/sigdb/build.d.ts +2 -2
  283. package/project/sigdb/decode.d.ts +0 -5
  284. package/project/sigdb/decode.js +0 -8
  285. package/project/sigdb/index-format.d.ts +4 -4
  286. package/project/sigdb/manifest.d.ts +2 -2
  287. package/project/sigdb/reader.d.ts +54 -13
  288. package/project/sigdb/reader.js +4 -3
  289. package/project/sigdb/schema.d.ts +3 -1
  290. package/project/sigdb/signature-db.d.ts +69 -0
  291. package/project/sigdb/signature-db.js +54 -0
  292. package/project/sigdb/signature-match.d.ts +10 -5
  293. package/project/sigdb/signature-match.js +13 -8
  294. package/queries/catalog/absint-query/absint-query-executor.js +1 -2
  295. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -4
  296. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +1 -1
  297. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +33 -6
  298. package/queries/catalog/control-flow-query/control-flow-query-executor.js +1 -2
  299. package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -2
  300. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +8 -7
  301. package/queries/catalog/dependencies-query/dependencies-query-format.js +22 -35
  302. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +13 -1
  303. package/queries/catalog/dependencies-query/function-info/library-functions.js +26 -22
  304. package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +9 -0
  305. package/queries/catalog/dependencies-query/function-info/statistics-functions.js +19 -0
  306. package/queries/catalog/dependencies-query/implicit-echo.d.ts +13 -0
  307. package/queries/catalog/dependencies-query/implicit-echo.js +133 -0
  308. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +2 -2
  309. package/queries/catalog/happens-before-query/happens-before-query-executor.js +1 -2
  310. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +2 -2
  311. package/queries/catalog/signature-query/signature-query-executor.js +4 -3
  312. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
  313. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.d.ts +1 -0
  314. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.js +1 -0
  315. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  316. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +1 -0
  317. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +4 -1
  318. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -2
  319. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  320. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +1 -0
  321. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  322. package/r-bridge/lang-4.x/ast/model/nodes/r-break.js +1 -0
  323. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  324. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.js +1 -0
  325. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  326. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.js +1 -0
  327. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  328. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.js +1 -0
  329. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -4
  330. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +6 -4
  331. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  332. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.js +1 -0
  333. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  334. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.js +1 -0
  335. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  336. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.js +1 -0
  337. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  338. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.js +1 -0
  339. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  340. package/r-bridge/lang-4.x/ast/model/nodes/r-next.js +1 -0
  341. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -0
  342. package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +13 -0
  343. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +8 -0
  344. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.js +8 -0
  345. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  346. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.js +1 -0
  347. package/r-bridge/lang-4.x/ast/model/nodes/r-project.d.ts +1 -0
  348. package/r-bridge/lang-4.x/ast/model/nodes/r-project.js +1 -0
  349. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  350. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.js +1 -0
  351. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  352. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +1 -0
  353. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  354. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +1 -0
  355. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  356. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +1 -0
  357. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  358. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.js +1 -0
  359. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +2 -1
  360. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +5 -1
  361. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +0 -5
  362. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.d.ts +1 -1
  363. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.js +3 -2
  364. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then-else.js +2 -1
  365. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then.js +2 -1
  366. package/r-bridge/lang-4.x/ast/parser/main/internal/expression/normalize-expression.js +1 -1
  367. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +2 -1
  368. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.d.ts +2 -2
  369. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +6 -3
  370. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +2 -1
  371. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-parameter.js +2 -1
  372. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-for.js +5 -3
  373. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-repeat.js +2 -1
  374. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-while.js +2 -1
  375. package/r-bridge/lang-4.x/ast/parser/main/internal/normalize-access.js +2 -1
  376. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +5 -3
  377. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -1
  378. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.d.ts +1 -1
  379. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -1
  380. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-root.js +3 -1
  381. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.d.ts +1 -1
  382. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.js +2 -1
  383. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +5 -3
  384. package/reconstruct/inline/source-inline-map.js +3 -3
  385. package/reconstruct/reconstruct.js +6 -4
  386. package/search/flowr-search-builder.d.ts +8 -8
  387. package/search/flowr-search-builder.js +4 -4
  388. package/search/flowr-search-filters.d.ts +2 -2
  389. package/search/flowr-search-filters.js +3 -2
  390. package/search/search-executor/search-enrichers.d.ts +6 -0
  391. package/search/search-executor/search-enrichers.js +44 -5
  392. package/slicing/criterion/filters/all-variables.js +2 -1
  393. package/slicing/criterion/parse.js +8 -6
  394. package/slicing/static/slice-call.js +2 -2
  395. package/util/arg-matching.d.ts +3 -0
  396. package/util/arg-matching.js +12 -1
  397. package/util/collections/arrays.d.ts +0 -4
  398. package/util/collections/arrays.js +4 -26
  399. package/util/diff-graph.d.ts +1 -1
  400. package/util/diff-graph.js +17 -3
  401. package/util/diff.d.ts +6 -0
  402. package/util/mermaid/ast.d.ts +1 -1
  403. package/util/mermaid/ast.js +5 -4
  404. package/util/mermaid/cfg.js +130 -24
  405. package/util/mermaid/dfg.js +31 -10
  406. package/util/mermaid/mermaid.js +2 -0
  407. package/util/objects.d.ts +24 -4
  408. package/util/objects.js +12 -0
  409. package/util/prefix.d.ts +1 -1
  410. package/util/text/playground-link.d.ts +131 -0
  411. package/util/text/playground-link.js +214 -0
  412. package/util/text/strings.js +7 -3
  413. package/util/version.js +1 -1
  414. package/control-flow/cfg-builder.d.ts +0 -30
  415. package/control-flow/cfg-builder.js +0 -79
  416. package/control-flow/extract-cfg.d.ts +0 -36
  417. package/control-flow/extract-cfg.js +0 -693
  418. package/project/cfg-kind.d.ts +0 -21
  419. package/project/cfg-kind.js +0 -26
@@ -2,20 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractInterpretationVisitor = void 0;
4
4
  const control_flow_graph_1 = require("../control-flow/control-flow-graph");
5
+ const simple_visitor_1 = require("../control-flow/simple-visitor");
5
6
  const semantic_cfg_guided_visitor_1 = require("../control-flow/semantic-cfg-guided-visitor");
6
7
  const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
7
8
  const df_helper_1 = require("../dataflow/graph/df-helper");
9
+ const graph_1 = require("../dataflow/graph/graph");
10
+ const edge_1 = require("../dataflow/graph/edge");
8
11
  const vertex_1 = require("../dataflow/graph/vertex");
9
- const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
10
12
  const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
11
- const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
13
+ const node_id_1 = require("../r-bridge/lang-4.x/ast/model/processing/node-id");
12
14
  const assert_1 = require("../util/assert");
13
15
  const abstract_domain_1 = require("./domains/abstract-domain");
14
16
  const unsupported_functions_1 = require("./unsupported-functions");
17
+ const r_argument_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-argument");
18
+ const r_binary_op_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
19
+ const r_expression_list_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
20
+ const r_if_then_else_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else");
21
+ const r_pipe_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-pipe");
22
+ const r_parameter_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
23
+ const r_symbol_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
24
+ function stepFrom(graph, node) {
25
+ return { node, successors: [...graph.successors(node)], at: 0 };
26
+ }
27
+ /** Whether two rounds of a fixpoint bound the same values, `undefined` standing for nothing known yet. */
28
+ function sameValues(a, b) {
29
+ return b !== undefined && a.length === b.length
30
+ && a.every((value, at) => value === undefined ? b[at] === undefined : b[at] !== undefined && value.equals(b[at]));
31
+ }
15
32
  /**
16
33
  * A control flow graph visitor to perform abstract interpretation.
17
34
  *
18
- * However, the visitor does not yet support inter-procedural abstract interpretation and abstract condition semantics.
35
+ * The worklist below stays within the function it starts in: a function definition produces a closure and its
36
+ * body is a region of its own, which nothing flows into.
37
+ *
38
+ * Calls are not followed by default: flip {@link AbstractInterpretationVisitor#shouldEnterCall|shouldEnterCall()} to
39
+ * step into what a call dispatches to and continue with the state at the function's exit points.
40
+ * Condition semantics are not applied by default either, but everything needed for them is there:
41
+ * {@link AbstractInterpretationVisitor#getPredecessorState|getPredecessorState()} is handed the branch that was
42
+ * taken, and {@link BasicCfgGuidedVisitor#getDecidedConstructs|getDecidedConstructs()} names the construct a
43
+ * condition belongs to.
19
44
  */
20
45
  class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor {
21
46
  /**
@@ -31,15 +56,39 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
31
56
  */
32
57
  stack = [];
33
58
  /**
34
- * A set of nodes representing variable definitions that have already been visited but whose assignment has not yet been processed.
59
+ * The nodes a back edge of the control flow graph leads to, computed on demand.
60
+ * @see {@link AbstractInterpretationVisitor#isWideningPoint|isWideningPoint()}
35
61
  */
36
- unassigned = new Set();
62
+ wideningPoints;
63
+ /**
64
+ * What leads to a vertex, without the call a body was entered from.
65
+ * {@link AbstractInterpretationVisitor#shouldSkipVertex|shouldSkipVertex()} is asked once per vertex, so
66
+ * an override of it has to say the same thing every time.
67
+ */
68
+ predecessorsOf = new Map();
69
+ /** What the control flow may reach from a vertex, asked only by a read with several definitions. */
70
+ reachableFrom = new Map();
37
71
  /**
38
- * A map mapping assignments of replacement calls to their replacement calls for replacement calls that have already been visited but whose assignment has not yet been processed.
72
+ * The state each vertex was left in when it was last visited, so a re-visit can tell whether anything moved.
73
+ * The trace cannot say that: entering a call seeds it before the parameters and the call are visited.
39
74
  */
40
- replacements = new Map();
75
+ lastState = new Map();
76
+ /**
77
+ * A set of nodes representing variable definitions that have already been visited but whose assignment has not yet been processed.
78
+ */
79
+ unassigned = new Set();
80
+ /** The call a function body is currently being interpreted for, mapping the body's entry to it. */
81
+ enteredFrom = new Map();
82
+ /** The function definitions currently being interpreted, which is what makes a call back into one recursive. */
83
+ running = new Set();
84
+ /** The definitions that turned out to call themselves, which are the ones run more than once. */
85
+ recursive = new Set();
86
+ /** What a definition being interpreted was last seen to leave behind, which is what its own calls are worth. */
87
+ returns = new Map();
88
+ /** The calls that lead back into a definition still being interpreted, and the definition they reach. */
89
+ recursiveCalls = new Map();
41
90
  constructor(config, stateDomain) {
42
- super({ ...config, defaultVisitingOrder: 'forward', defaultVisitingType: 'exit' });
91
+ super({ ...config, defaultVisitingOrder: 'forward' });
43
92
  this.currentState = stateDomain.top();
44
93
  }
45
94
  /**
@@ -58,27 +107,38 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
58
107
  else if (node === undefined) {
59
108
  return;
60
109
  }
61
- else if (state?.has(node.info.id)) {
110
+ const reached = this.recursiveCalls.get(node.info.id);
111
+ if (reached !== undefined) {
112
+ /* it is worth what the definition it reaches was last seen to leave behind, nothing in round one */
113
+ return this.returns.get(reached) ?? this.currentState.domain.bottom();
114
+ }
115
+ if (state?.has(node.info.id)) {
62
116
  return state.get(node.info.id);
63
117
  }
64
118
  const vertex = this.getDataflowGraph(node.info.id);
65
119
  const call = vertex_1.FunctionCallVertex.is(vertex) ? vertex : undefined;
66
120
  const origins = Array.isArray(call?.origin) ? call.origin : [];
67
- if (node.type === type_1.RType.Symbol) {
121
+ if (r_symbol_1.RSymbol.is(node)) {
68
122
  const values = this.getVariableOrigins(node.info.id)
69
123
  .map(origin => (this.getAbstractState(origin)?.isBottom() ? this.currentState.domain.bottom() : state?.get(origin)));
70
124
  if (values.length > 0 && values.every(assert_1.isNotUndefined)) {
71
125
  return abstract_domain_1.AbstractDomain.joinAll(values);
72
126
  }
73
127
  }
74
- else if (node.type === type_1.RType.Argument && node.value !== undefined) {
128
+ else if (r_argument_1.RArgument.isWithValue(node)) {
75
129
  return this.getAbstractValue(node.value, state);
76
130
  }
77
- else if (node.type === type_1.RType.ExpressionList && node.children.length > 0) {
131
+ else if (r_expression_list_1.RExpressionList.is(node) && node.children.length > 0) {
78
132
  return this.getAbstractValue(node.children.at(-1), state);
79
133
  }
134
+ else if (origins.includes(built_in_proc_name_1.BuiltInProcName.Return)) {
135
+ /* leaving with `return(x)` is worth what `x` is worth, which is what a function that does it exits with */
136
+ if (call?.args.length === 1 && call.args[0] !== r_function_call_1.EmptyArgument) {
137
+ return this.getAbstractValue(call.args[0].nodeId, state);
138
+ }
139
+ }
80
140
  else if (origins.includes(built_in_proc_name_1.BuiltInProcName.Pipe)) {
81
- if (node.type === type_1.RType.Pipe || node.type === type_1.RType.BinaryOp) {
141
+ if (r_pipe_1.RPipe.is(node) || r_binary_op_1.RBinaryOp.is(node)) {
82
142
  return this.getAbstractValue(node.rhs, state);
83
143
  }
84
144
  else if (call?.args.length === 2 && call?.args[1] !== r_function_call_1.EmptyArgument) {
@@ -87,7 +147,7 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
87
147
  }
88
148
  else if (origins.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse)) {
89
149
  let values = [];
90
- if (node.type === type_1.RType.IfThenElse && node.otherwise !== undefined) {
150
+ if (r_if_then_else_1.RIfThenElse.is(node) && node.otherwise !== undefined) {
91
151
  values = [node.then, node.otherwise].map(entry => this.getAbstractValue(entry, state));
92
152
  }
93
153
  else if (call?.args.every(arg => arg !== r_function_call_1.EmptyArgument) && call.args.length === 3) {
@@ -113,9 +173,7 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
113
173
  * @returns The inferred abstract state at the end of the program
114
174
  */
115
175
  getEndState() {
116
- const exitPoints = this.config.controlFlow.exitPoints.map(id => this.getCfgVertex(id)).filter(assert_1.isNotUndefined);
117
- const exitNodes = exitPoints.map(control_flow_graph_1.CfgVertex.getRootId).filter(assert_1.isNotUndefined);
118
- const states = exitNodes.map(node => this.trace.get(node)).filter(assert_1.isNotUndefined);
176
+ const states = this.config.controlFlow.exitPoints.map(node => this.trace.get(node)).filter(assert_1.isNotUndefined);
119
177
  return abstract_domain_1.AbstractDomain.joinAll(states, this.currentState.bottom());
120
178
  }
121
179
  /**
@@ -129,17 +187,21 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
129
187
  (0, assert_1.guard)(this.trace.size === 0, 'Abstract interpretation visitor has already been started');
130
188
  super.start();
131
189
  this.unassigned.clear();
190
+ this.lastState.clear();
132
191
  }
133
192
  startVisitor(start) {
134
193
  this.stack = Array.from(start);
194
+ const queued = new Set(this.stack);
135
195
  while (this.stack.length > 0) {
136
196
  const current = this.stack.pop();
197
+ queued.delete(current);
137
198
  if (!this.visitNode(current)) {
138
199
  continue;
139
200
  }
140
- const successors = this.config.controlFlow.graph.ingoingEdges(current)?.keys().toArray().reverse() ?? [];
201
+ const successors = [...this.config.controlFlow.graph.successors(current)].reverse();
141
202
  for (const next of successors) {
142
- if (!this.stack.includes(next)) { // prevent double entries in working list
203
+ if (!queued.has(next)) { // prevent double entries in working list
204
+ queued.add(next);
143
205
  this.stack.push(next);
144
206
  }
145
207
  }
@@ -147,65 +209,45 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
147
209
  }
148
210
  visitNode(vertexId) {
149
211
  const vertex = this.getCfgVertex(vertexId);
150
- // skip exit vertices of widening points and entry vertices of complex nodes
151
212
  if (vertex === undefined || this.shouldSkipVertex(vertex)) {
152
213
  return true;
153
214
  }
154
215
  // retrieve new abstract state by joining states of predecessor nodes
155
- const predecessors = this.getPredecessorNodes(control_flow_graph_1.CfgVertex.getId(vertex));
156
- const predecessorStates = predecessors.map(pred => this.trace.get(pred)).filter(assert_1.isNotUndefined);
216
+ const nodeId = control_flow_graph_1.CfgVertex.getId(vertex);
217
+ const predecessors = this.getPredecessors(nodeId);
218
+ const predecessorStates = predecessors.map(pred => this.getPredecessorState(pred)).filter(assert_1.isNotUndefined);
157
219
  this.currentState = abstract_domain_1.AbstractDomain.joinAll(predecessorStates, this.currentState.top());
158
- const nodeId = control_flow_graph_1.CfgVertex.getRootId(vertex);
159
- // differentiate between widening points and other vertices
160
- if (this.isWideningPoint(nodeId)) {
161
- const oldState = this.trace.get(nodeId);
162
- if (oldState !== undefined && this.shouldWiden(vertex)) {
163
- this.currentState = oldState.widen(this.currentState);
164
- }
165
- this.trace.set(nodeId, this.currentState);
166
- const visitedCount = this.visited.get(nodeId) ?? 0;
167
- this.visited.set(nodeId, visitedCount + 1);
168
- // continue visiting after widening point if visited for the first time or the state changed
169
- return visitedCount === 0 || !oldState?.equals(this.currentState);
220
+ const oldState = this.lastState.get(nodeId);
221
+ /*
222
+ * A widening point is a node of the program like any other: the head of a `while` is its condition, of a
223
+ * `repeat` its first statement. The iteration is bounded here, the node still says what it says.
224
+ */
225
+ if (oldState !== undefined && this.isWideningPoint(nodeId) && this.shouldWiden(vertex)) {
226
+ this.currentState = oldState.widen(this.currentState);
170
227
  }
171
- else {
172
- this.onVisitNode(vertexId);
173
- // discard the inferred abstract state when encountering unsupported function calls
174
- if (this.isUnsupportedFunctionCall(nodeId)) {
175
- this.currentState = this.currentState.top();
176
- }
177
- this.trace.set(nodeId, this.currentState);
178
- const predecessorVisits = predecessors.map(pred => this.visited.get(pred) ?? 0);
179
- const visitedCount = this.visited.get(nodeId) ?? 0;
180
- this.visited.set(nodeId, visitedCount + 1);
181
- // continue visiting if vertex is not a join vertex or number of visits of predecessors is the same
182
- return predecessors.length <= 1 || this.stack.length === 0 || predecessorVisits.every(visits => visits === predecessorVisits[0]);
183
- }
184
- }
185
- visitUnknown(vertex) {
186
- const nodeId = control_flow_graph_1.CfgVertex.getRootId(vertex);
187
- const replacements = this.replacements.get(nodeId);
188
- if (replacements !== undefined) {
189
- this.replacements.delete(nodeId);
190
- for (const replacement of replacements) {
191
- const call = this.getDataflowGraph(replacement);
192
- if (vertex_1.FunctionCallVertex.is(call)) {
193
- this.onReplacementCall({ call, ...this.getSourceAndTarget(call) });
194
- }
195
- }
228
+ this.onVisitNode(vertexId);
229
+ // discard the inferred abstract state when encountering unsupported function calls
230
+ if (this.isUnsupportedFunctionCall(nodeId)) {
231
+ this.currentState = this.currentState.top();
196
232
  }
233
+ this.trace.set(nodeId, this.currentState);
234
+ this.lastState.set(nodeId, this.currentState);
235
+ const visitedCount = this.visited.get(nodeId) ?? 0;
236
+ this.visited.set(nodeId, visitedCount + 1);
237
+ /*
238
+ * Carry on wherever the vertex is new or its state moved. Waiting for the branches of a join to arrive
239
+ * in step instead drops the rest of the program whenever they do not, three arms in a loop say.
240
+ */
241
+ return visitedCount === 0 || !oldState?.equals(this.currentState);
197
242
  }
198
243
  onDispatchFunctionCallOrigin(call, origin) {
199
244
  if (origin === built_in_proc_name_1.BuiltInProcName.Replacement) {
200
- const node = this.getNormalizedAst(call.id);
201
- const assignment = model_1.RNode.iterateParents(node, this.config.normalizedAst.idMap)
202
- .find(parent => this.getDataflowGraph(parent.info.id) === undefined);
203
- if (node !== undefined && assignment !== undefined) {
204
- const replacements = this.replacements.get(assignment.info.id) ?? [];
205
- replacements.push(node.info.id);
206
- this.replacements.set(assignment.info.id, replacements);
207
- return;
208
- }
245
+ /*
246
+ * A replacement is the last thing its statement does (the target and the value are evaluated first),
247
+ * so it is handled where it is visited; the `<-` it was rewritten from has no vertex to defer to.
248
+ */
249
+ this.onReplacementCall({ call, ...this.getSourceAndTarget(call) });
250
+ return;
209
251
  }
210
252
  super.onDispatchFunctionCallOrigin(call, origin);
211
253
  switch (origin) {
@@ -218,7 +260,6 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
218
260
  case built_in_proc_name_1.BuiltInProcName.Assignment:
219
261
  case built_in_proc_name_1.BuiltInProcName.AssignmentLike:
220
262
  case built_in_proc_name_1.BuiltInProcName.TableAssignment:
221
- case built_in_proc_name_1.BuiltInProcName.Replacement:
222
263
  case built_in_proc_name_1.BuiltInProcName.Access:
223
264
  case built_in_proc_name_1.BuiltInProcName.Pipe:
224
265
  case built_in_proc_name_1.BuiltInProcName.Break:
@@ -232,6 +273,23 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
232
273
  if (!this.trace.has(vertex.id)) {
233
274
  this.unassigned.add(vertex.id);
234
275
  }
276
+ /*
277
+ * `bindParameters` hands the arguments over before the function is entered, so a parameter still without
278
+ * a value is one the call passed nothing for and is worth the default it names. That default runs before
279
+ * the body, so standing on the parameter is the moment to read it.
280
+ */
281
+ if (this.currentState.has(vertex.id)) {
282
+ return;
283
+ }
284
+ const declaration = this.getNormalizedAst(this.getNormalizedAst(vertex.id)?.info.parent);
285
+ if (!r_parameter_1.RParameter.isWithDefault(declaration)) {
286
+ return;
287
+ }
288
+ const value = this.getAbstractValue(declaration.defaultValue, this.currentState);
289
+ if (value !== undefined) {
290
+ this.currentState.set(vertex.id, value);
291
+ this.unassigned.delete(vertex.id);
292
+ }
235
293
  }
236
294
  onAssignmentCall({ target, source }) {
237
295
  if (target === undefined || source === undefined) {
@@ -262,60 +320,362 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
262
320
  * @protected
263
321
  */
264
322
  onFunctionCall(_data) { }
265
- /** Gets all AST nodes for the predecessor vertices that are leaf nodes and exit vertices */
266
- getPredecessorNodes(vertexId) {
267
- return this.config.controlFlow.graph.outgoingEdges(vertexId)?.keys() // outgoing dependency edges are ingoing CFG edges
268
- .map(id => this.getCfgVertex(id))
269
- .flatMap(vertex => {
323
+ /**
324
+ * Everything the control flow may come from to reach this vertex, together with the branch it took to get here.
325
+ * Skipped vertices hold no state of their own, so what led into them is reported instead.
326
+ */
327
+ getPredecessors(vertexId) {
328
+ let result = this.predecessorsOf.get(vertexId);
329
+ if (result === undefined) {
330
+ result = this.collectPredecessors(vertexId);
331
+ this.predecessorsOf.set(vertexId, result);
332
+ }
333
+ /* a body has no predecessor of its own, so what runs before it is the call we stepped in from */
334
+ const enteredFrom = this.enteredFrom.get(vertexId);
335
+ return enteredFrom === undefined ? result : [...result, { id: enteredFrom }];
336
+ }
337
+ /** What the control flow graph itself says leads here, which is the same however often it is asked. */
338
+ collectPredecessors(vertexId) {
339
+ const result = [];
340
+ for (const [id, edge] of this.config.controlFlow.graph.ingoingEdges(vertexId) ?? graph_1.NoEdges) {
341
+ const branch = control_flow_graph_1.CfgEdge.isControlDependency(edge) ? edge : undefined;
342
+ const vertex = this.getCfgVertex(id);
270
343
  if (vertex === undefined) {
271
- return [];
344
+ continue;
272
345
  }
273
346
  else if (this.shouldSkipVertex(vertex)) {
274
- return this.getPredecessorNodes(control_flow_graph_1.CfgVertex.getId(vertex));
347
+ /* the branch closest to us is the one that decided we get here at all, so it wins */
348
+ result.push(...this.collectPredecessors(id).map(pred => branch ? { ...pred, branch } : pred));
349
+ }
350
+ else {
351
+ result.push({ id, branch });
352
+ }
353
+ }
354
+ return result;
355
+ }
356
+ /**
357
+ * The abstract state one predecessor contributes, joined into the state at the current vertex.
358
+ *
359
+ * By default, this is the state as the predecessor left it. Override it to apply condition semantics:
360
+ * on the then-branch of `if(u) a else b` the predecessor is `u` and `branch.when` is `true`, so `u` held.
361
+ */
362
+ getPredecessorState({ id }) {
363
+ return this.trace.get(id);
364
+ }
365
+ visitFunctionCall(call) {
366
+ super.visitFunctionCall(call);
367
+ if (this.shouldEnterCall(call)) {
368
+ this.currentState = this.enterCall(call.id) ?? this.currentState;
369
+ }
370
+ }
371
+ /**
372
+ * Whether to step into what the given call dispatches to, which is what makes the analysis interprocedural.
373
+ * Defaults to `abstractInterpretation.followCalls`; override it to decide per call. A call that reaches no
374
+ * definition is left alone either way.
375
+ */
376
+ shouldEnterCall(_call) {
377
+ return this.config.ctx.config.abstractInterpretation.followCalls;
378
+ }
379
+ /**
380
+ * The function definitions the given call may dispatch to.
381
+ * Built-in functions have no definition in the source, so they are not part of this.
382
+ */
383
+ getCallTargets(callId) {
384
+ const targets = control_flow_graph_1.CfgVertex.getCallTargets(this.getCfgVertex(callId));
385
+ return targets === undefined ? control_flow_graph_1.NoNeighbors : [...targets];
386
+ }
387
+ /** Where a function definition starts, i.e. the first thing that runs when it is called. */
388
+ getFunctionEntry(defId) {
389
+ const def = this.getDataflowGraph(defId);
390
+ return vertex_1.FunctionDefinitionVertex.is(def) ? def.subflow.cfgEntry ?? def.subflow.entryPoint : undefined;
391
+ }
392
+ /** Where a function definition is left, i.e. its last expressions and `return` calls. */
393
+ getFunctionExits(defId) {
394
+ const def = this.getDataflowGraph(defId);
395
+ return vertex_1.FunctionDefinitionVertex.is(def) ? def.exitPoints.map(exit => exit.nodeId) : control_flow_graph_1.NoNeighbors;
396
+ }
397
+ /**
398
+ * Runs the bodies the given call dispatches to, starting from the state at the call, and returns the state
399
+ * control comes back with: the states at their exit points joined.
400
+ * A call already being interpreted is not entered again, so recursion stops at the second entry.
401
+ * @returns the state at the exit points, or `undefined` if the call reaches nothing to step into
402
+ */
403
+ enterCall(callId) {
404
+ const states = [];
405
+ const values = [];
406
+ const outerState = this.currentState;
407
+ /* the entry picks its state up from the call, which is what makes the arguments visible in the body */
408
+ this.trace.set(callId, outerState);
409
+ /*
410
+ * The call is worth something only if every way out of every function it reaches is: one that leaves a
411
+ * frame on one path and something else on another says as little as `if(u) df else 42` does.
412
+ */
413
+ let known = true;
414
+ for (const def of this.getCallTargets(callId)) {
415
+ const entry = this.getFunctionEntry(def);
416
+ if (entry === undefined) {
417
+ continue;
418
+ }
419
+ else if (this.running.has(def)) {
420
+ /* it is worth what it leaves behind, which is only known once it is done; see `getAbstractValue` */
421
+ this.recursive.add(def);
422
+ this.recursiveCalls.set(callId, def);
423
+ continue;
424
+ }
425
+ this.running.add(def);
426
+ const left = this.runFunction(callId, def, entry, outerState);
427
+ this.running.delete(def);
428
+ this.recursive.delete(def);
429
+ this.returns.delete(def);
430
+ states.push(...left.states);
431
+ if (left.value === undefined) {
432
+ known = false;
433
+ }
434
+ else {
435
+ values.push(left.value);
436
+ }
437
+ }
438
+ this.currentState = outerState;
439
+ if (states.length === 0) {
440
+ return undefined;
441
+ }
442
+ const returned = abstract_domain_1.AbstractDomain.joinAll(states);
443
+ if (known && values.length > 0) {
444
+ /* what the call is worth is what its function leaves behind at its exits */
445
+ returned.set(callId, abstract_domain_1.AbstractDomain.joinAll(values));
446
+ }
447
+ return returned;
448
+ }
449
+ /**
450
+ * Runs one definition for one call until what it leaves behind stops moving.
451
+ *
452
+ * One that does not call itself is run once. One that does is a fixpoint in two halves: what it leaves
453
+ * behind, which its own calls read, and what its parameters are worth, which those calls decide, since
454
+ * `shrink(head(x, nrow(x) - 1))` hands over fewer rows than it was given. Both are widened so they stop.
455
+ * @returns the states at the exit points, and what the definition leaves behind if every way out says
456
+ */
457
+ runFunction(callId, def, entry, outerState) {
458
+ const threshold = this.config.ctx.config.abstractInterpretation.wideningThreshold;
459
+ /* the counts drive the widening within the body, and belong to this call rather than to the program */
460
+ const counts = this.regionVisits(entry);
461
+ let settled = undefined;
462
+ let bound = undefined;
463
+ for (let round = 0;; round++) {
464
+ /* the parameters are the definition's own, so they are bound in a state of its own */
465
+ const inner = outerState.create(outerState.value);
466
+ this.currentState = inner;
467
+ this.bindParameters(callId, def);
468
+ /*
469
+ * The calls a definition makes to itself enter it too, so its parameters are worth what either they
470
+ * or the outer call say. Widening them is what stops the rounds: a recursion that keeps adding to
471
+ * what it is handed would otherwise be described by the first step it takes.
472
+ */
473
+ for (const [call, reached] of this.recursiveCalls) {
474
+ if (reached === def) {
475
+ this.bindParameters(call, def, round > 0 ? 'widen' : 'join');
476
+ }
477
+ }
478
+ const handed = this.parameterValues(def);
479
+ this.trace.set(callId, inner);
480
+ this.enteredFrom.set(entry, callId);
481
+ /* what a recursive call is worth is no part of the state, so the traversal has to be made to re-read */
482
+ if (round > 0) {
483
+ for (const id of this.reachableSet(entry)) {
484
+ this.lastState.delete(id);
485
+ }
486
+ }
487
+ const outerStack = this.stack;
488
+ this.startVisitor([entry]);
489
+ this.stack = outerStack;
490
+ this.enteredFrom.delete(entry);
491
+ const states = [];
492
+ const exits = [];
493
+ let complete = true;
494
+ for (const exit of this.getFunctionExits(def)) {
495
+ const state = this.trace.get(exit);
496
+ if (state === undefined) {
497
+ continue;
498
+ }
499
+ states.push(state);
500
+ const value = this.getAbstractValue(exit, state);
501
+ if (value === undefined) {
502
+ complete = false;
503
+ }
504
+ else {
505
+ exits.push(value);
506
+ }
507
+ }
508
+ const left = complete && exits.length > 0 ? abstract_domain_1.AbstractDomain.joinAll(exits) : undefined;
509
+ if (!this.recursive.has(def)) {
510
+ this.restoreVisits(counts);
511
+ return { states, value: left };
512
+ }
513
+ else if (left === undefined) {
514
+ /* one way out of the recursion says nothing, so neither does the recursion */
515
+ this.restoreVisits(counts);
516
+ return { states, value: undefined };
517
+ }
518
+ /* widening bounds the rounds, the same way it bounds the rounds of a loop */
519
+ const next = settled !== undefined && round >= threshold ? settled.widen(left) : left;
520
+ const moved = settled === undefined || !next.equals(settled) || !sameValues(handed, bound);
521
+ settled = next;
522
+ bound = handed;
523
+ this.returns.set(def, next);
524
+ if (!moved) {
525
+ this.restoreVisits(counts);
526
+ return { states, value: settled };
527
+ }
528
+ }
529
+ }
530
+ /** What the parameters of a definition are worth in the state they were just bound in. */
531
+ parameterValues(defId) {
532
+ const definition = this.getDataflowGraph(defId);
533
+ if (!vertex_1.FunctionDefinitionVertex.is(definition)) {
534
+ return [];
535
+ }
536
+ return Object.keys(definition.params).map(key => this.currentState.get(node_id_1.NodeId.normalize(key)));
537
+ }
538
+ /** How often each vertex of a function has been visited, so one call does not widen the next one early. */
539
+ regionVisits(entry) {
540
+ const counts = new Map();
541
+ for (const id of this.reachableSet(entry)) {
542
+ counts.set(id, this.visited.get(id));
543
+ }
544
+ return counts;
545
+ }
546
+ /** Puts the visit counts back as they were before a function was run for one call. */
547
+ restoreVisits(counts) {
548
+ for (const [id, count] of counts) {
549
+ if (count === undefined) {
550
+ this.visited.delete(id);
275
551
  }
276
552
  else {
277
- return [control_flow_graph_1.CfgVertex.getRootId(vertex)];
553
+ this.visited.set(id, count);
554
+ }
555
+ }
556
+ }
557
+ /**
558
+ * Hand the arguments of the call to the parameters of the function it enters, so the body can read them.
559
+ * Only the arguments of this very call are used, whichever other calls the function has.
560
+ */
561
+ bindParameters(callId, defId, add) {
562
+ const call = this.getDataflowGraph(callId);
563
+ const definition = this.getDataflowGraph(defId);
564
+ if (!vertex_1.FunctionCallVertex.is(call) || !vertex_1.FunctionDefinitionVertex.is(definition)) {
565
+ return;
566
+ }
567
+ const args = new Set(call.args.filter(graph_1.FunctionArgument.isNotEmpty).map(arg => arg.nodeId));
568
+ for (const key of Object.keys(definition.params)) {
569
+ /* object keys are strings, the graph keys its vertices by the id itself */
570
+ const parameter = node_id_1.NodeId.normalize(key);
571
+ for (const [target, edge] of this.config.dfg.outgoingEdges(parameter) ?? graph_1.NoEdges) {
572
+ if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedByOnCall) || !args.has(target)) {
573
+ continue;
574
+ }
575
+ /* a call that is not the one being entered is read where it stands, not from the state here */
576
+ let value = add === undefined ? this.getAbstractValue(target, this.currentState) : this.getAbstractValue(target);
577
+ const previous = add === undefined ? undefined : this.currentState.get(parameter);
578
+ if (value !== undefined && previous !== undefined) {
579
+ value = (add === 'widen' ? previous.widen(value) : previous.join(value));
580
+ }
581
+ if (value !== undefined) {
582
+ this.currentState.set(parameter, value);
583
+ /* the parameter is a definition like any other, so the body only reads it once it counts as assigned */
584
+ this.trace.set(parameter, this.currentState);
585
+ this.unassigned.delete(parameter);
586
+ }
278
587
  }
279
- })
280
- .toArray() ?? [];
588
+ }
281
589
  }
282
590
  /** Gets each variable origin that has already been visited and whose assignment has already been processed */
283
591
  getVariableOrigins(nodeId) {
284
- return df_helper_1.Dataflow.origin(this.config.dfg, nodeId)
592
+ const origins = df_helper_1.Dataflow.origin(this.config.dfg, nodeId)
285
593
  ?.filter(origin => origin.type === 0 /* OriginType.ReadVariableOrigin */)
286
594
  .map(origin => origin.id)
287
595
  .filter(origin => this.trace.has(origin) && !this.unassigned.has(origin)) ?? [];
596
+ /*
597
+ * A read with a single definition takes it whatever the control flow does. One with several only sees
598
+ * those that can reach it: `x` within `for(i in 1:nrow(x)) x$a[i] <- 1` is a definition of the `x` in
599
+ * the head of the loop, but the head runs before the body ever does.
600
+ */
601
+ return origins.length > 1 ? origins.filter(origin => this.reaches(origin, nodeId)) : origins;
602
+ }
603
+ /** Whether the control flow may get from one vertex to another, answered from one traversal per source. */
604
+ reaches(from, to) {
605
+ return this.reachableSet(from).has(to);
606
+ }
607
+ /** Everything the control flow may reach from a vertex, walked once per source and kept. */
608
+ reachableSet(from) {
609
+ let reachable = this.reachableFrom.get(from);
610
+ if (reachable === undefined) {
611
+ reachable = (0, simple_visitor_1.visitCfgInOrder)(this.config.controlFlow.graph, [from], () => { });
612
+ this.reachableFrom.set(from, reachable);
613
+ }
614
+ return reachable;
288
615
  }
289
616
  /** Checks whether a node represents a unsupported (environment-changing) function call (e.g. `eval`, `load`, `attach`, `rm`, ...) */
290
617
  isUnsupportedFunctionCall(nodeId) {
291
618
  return unsupported_functions_1.UnsupportedFunctions.isUnsupportedCall(this.getDataflowGraph(nodeId), this.config.dfg);
292
619
  }
293
- /** We only perform widening at `for`, `while`, or `repeat` loops with more than one ingoing CFG edge */
620
+ /**
621
+ * We widen wherever the control flow comes back around, i.e. at the node a back edge leads to.
622
+ * That is what makes the iteration terminate, and it is the loop head whichever loop the code used:
623
+ * the condition of a `while`, the binding of a `for`, or the first statement of a `repeat`.
624
+ */
294
625
  isWideningPoint(nodeId) {
295
- const ingoingEdges = this.config.controlFlow.graph.outgoingEdges(nodeId)?.size; // outgoing dependency edges are ingoing CFG edges
296
- if (ingoingEdges === undefined || ingoingEdges <= 1) {
297
- return false;
298
- }
299
- else if (model_1.RLoopConstructs.is(this.getNormalizedAst(nodeId))) {
300
- return true;
626
+ this.wideningPoints ??= this.findWideningPoints();
627
+ return this.wideningPoints.has(nodeId);
628
+ }
629
+ /** The targets of the back edges of the control flow graph, found with one depth-first search. */
630
+ findWideningPoints() {
631
+ const graph = this.config.controlFlow.graph;
632
+ const heads = new Set();
633
+ const onPath = new Set();
634
+ const done = new Set();
635
+ for (const start of this.startingPoints()) {
636
+ if (done.has(start)) {
637
+ continue;
638
+ }
639
+ const stack = [stepFrom(graph, start)];
640
+ onPath.add(start);
641
+ while (stack.length > 0) {
642
+ const step = stack[stack.length - 1];
643
+ if (step.at >= step.successors.length) {
644
+ onPath.delete(step.node);
645
+ done.add(step.node);
646
+ stack.pop();
647
+ continue;
648
+ }
649
+ const next = step.successors[step.at++];
650
+ if (onPath.has(next)) {
651
+ /* the path leads back to a node it already runs through, so this is where the loop closes */
652
+ heads.add(next);
653
+ }
654
+ else if (!done.has(next)) {
655
+ onPath.add(next);
656
+ stack.push(stepFrom(graph, next));
657
+ }
658
+ }
301
659
  }
302
- const dataflowVertex = this.getDataflowGraph(nodeId);
303
- if (!vertex_1.FunctionCallVertex.is(dataflowVertex) || !Array.isArray(dataflowVertex.origin)) {
304
- return false;
660
+ return heads;
661
+ }
662
+ /** Everywhere the control flow may start: the program itself, and every function body, as nothing flows into one. */
663
+ startingPoints() {
664
+ const graph = this.config.controlFlow.graph;
665
+ const starts = [...this.config.controlFlow.entryPoints];
666
+ /* asking the control flow for all of its vertices copies it out of the dataflow graph, which already has them */
667
+ for (const [id] of this.config.dfg.verticesOfType(vertex_1.VertexType.FunctionDefinition)) {
668
+ starts.push(...graph.childrenOf(id) ?? control_flow_graph_1.NoNeighbors);
305
669
  }
306
- const origin = dataflowVertex.origin;
307
- return origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop) || origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop) || origin.includes(built_in_proc_name_1.BuiltInProcName.RepeatLoop);
670
+ return starts;
308
671
  }
309
672
  /**
310
673
  * Checks whether a control flow graph vertex should be skipped during visitation.
311
- * By default, we only process entry vertices of widening points, vertices of leaf nodes, and exit vertices (no entry nodes of complex nodes).
674
+ * Every node has exactly one vertex, reached once its operands are evaluated, so nothing is skipped
675
+ * by default; overriding this lets an analysis ignore parts of the program.
312
676
  */
313
- shouldSkipVertex(vertex) {
314
- if (this.isWideningPoint(control_flow_graph_1.CfgVertex.getRootId(vertex))) {
315
- // skip exit vertices of widening points
316
- return control_flow_graph_1.CfgVertex.isMarker(vertex);
317
- }
318
- return !control_flow_graph_1.CfgVertex.isMarker(vertex) && !control_flow_graph_1.CfgVertex.isBlock(vertex) && control_flow_graph_1.CfgVertex.getEnd(vertex) !== undefined;
677
+ shouldSkipVertex(_vertex) {
678
+ return false;
319
679
  }
320
680
  /**
321
681
  * Whether widening should be performed at a widening point.