@eagleoutice/flowr 2.10.10 → 2.11.1

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 (223) hide show
  1. package/README.md +35 -27
  2. package/cli/common/options.d.ts +2 -108
  3. package/cli/common/options.js +3 -27
  4. package/cli/common/scripts-info.d.ts +2 -123
  5. package/cli/common/scripts-info.js +0 -17
  6. package/cli/flowr-main-options.d.ts +5 -0
  7. package/cli/flowr-main-options.js +10 -0
  8. package/cli/flowr.js +2 -2
  9. package/cli/repl/commands/repl-commands.js +7 -6
  10. package/cli/repl/print-version.d.ts +3 -1
  11. package/cli/repl/print-version.js +21 -2
  12. package/cli/repl/server/connection.d.ts +2 -0
  13. package/cli/repl/server/connection.js +40 -31
  14. package/cli/script-core/summarizer-core.js +13 -32
  15. package/cli/wiki.d.ts +2 -1
  16. package/cli/wiki.js +2 -0
  17. package/config.d.ts +9 -0
  18. package/config.js +10 -0
  19. package/control-flow/semantic-cfg-guided-visitor.js +1 -0
  20. package/core/steps/pipeline/default-pipelines.d.ts +146 -146
  21. package/data/pkgdb/pkgdb-latest.json.br +0 -0
  22. package/data/pkgdb/pkgdb-tiny.json.br +0 -0
  23. package/dataflow/environments/append.d.ts +1 -2
  24. package/dataflow/environments/append.js +3 -10
  25. package/dataflow/environments/apply-kill.d.ts +21 -0
  26. package/dataflow/environments/apply-kill.js +155 -0
  27. package/dataflow/environments/built-in-proc-name.d.ts +2 -0
  28. package/dataflow/environments/built-in-proc-name.js +2 -0
  29. package/dataflow/environments/built-in.d.ts +2 -0
  30. package/dataflow/environments/built-in.js +2 -0
  31. package/dataflow/environments/default-builtin-config.d.ts +63 -3
  32. package/dataflow/environments/default-builtin-config.js +40 -8
  33. package/dataflow/environments/environment.d.ts +49 -32
  34. package/dataflow/environments/environment.js +133 -18
  35. package/dataflow/environments/identifier.d.ts +10 -0
  36. package/dataflow/environments/identifier.js +23 -0
  37. package/dataflow/environments/overwrite.js +2 -10
  38. package/dataflow/environments/resolve-by-name.d.ts +1 -1
  39. package/dataflow/environments/resolve-by-name.js +10 -2
  40. package/dataflow/environments/scoping.d.ts +9 -2
  41. package/dataflow/environments/scoping.js +15 -2
  42. package/dataflow/extractor.js +23 -2
  43. package/dataflow/graph/df-helper.d.ts +8 -0
  44. package/dataflow/graph/df-helper.js +8 -0
  45. package/dataflow/graph/graph.d.ts +4 -1
  46. package/dataflow/graph/graph.js +5 -1
  47. package/dataflow/info.d.ts +26 -0
  48. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -5
  49. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +19 -0
  50. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -8
  51. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +7 -13
  52. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +9 -48
  53. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -47
  54. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +17 -0
  55. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +6 -1
  56. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -2
  57. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +8 -1
  58. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +9 -0
  59. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +37 -3
  60. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +391 -21
  61. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -1
  62. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +131 -48
  63. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +25 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +94 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +10 -3
  66. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +30 -0
  67. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +279 -0
  68. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
  69. package/dataflow/internal/process/functions/call/named-call-handling.js +17 -0
  70. package/documentation/data/faq/faqs.js +3 -0
  71. package/documentation/data/interface/doc-writing-code.js +4 -80
  72. package/documentation/doc-util/doc-structure.js +1 -2
  73. package/documentation/wiki-core.js +2 -1
  74. package/documentation/wiki-dataflow-graph.js +35 -1
  75. package/documentation/wiki-interface.js +2 -2
  76. package/documentation/wiki-linter.js +2 -0
  77. package/documentation/wiki-overview.js +1 -14
  78. package/documentation/wiki-package-database.d.ts +9 -0
  79. package/documentation/wiki-package-database.js +63 -0
  80. package/documentation/wiki-query.js +1 -0
  81. package/linter/linter-rules.d.ts +23 -0
  82. package/linter/linter-rules.js +3 -1
  83. package/linter/rules/absolute-path.js +2 -1
  84. package/linter/rules/undefined-symbol.d.ts +39 -0
  85. package/linter/rules/undefined-symbol.js +80 -0
  86. package/package.json +4 -4
  87. package/project/cache/flowr-analyzer-cache.d.ts +2 -0
  88. package/project/cache/flowr-analyzer-cache.js +9 -1
  89. package/project/context/flowr-analyzer-dependencies-context.d.ts +16 -8
  90. package/project/context/flowr-analyzer-dependencies-context.js +39 -4
  91. package/project/context/flowr-analyzer-environment-context.d.ts +2 -4
  92. package/project/context/flowr-analyzer-environment-context.js +3 -4
  93. package/project/context/flowr-analyzer-files-context.d.ts +1 -0
  94. package/project/context/flowr-file.d.ts +2 -0
  95. package/project/context/flowr-file.js +2 -0
  96. package/project/flowr-analyzer-builder.js +3 -0
  97. package/project/flowr-analyzer.d.ts +2 -1
  98. package/project/flowr-analyzer.js +3 -1
  99. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +13 -15
  100. package/project/plugins/file-plugins/files/flowr-namespace-file.js +36 -13
  101. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +27 -0
  102. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +41 -0
  103. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +18 -0
  104. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +62 -0
  105. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +63 -0
  106. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +176 -0
  107. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +10 -0
  108. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +6 -0
  109. package/project/plugins/package-version-plugins/package.d.ts +3 -0
  110. package/project/plugins/package-version-plugins/package.js +12 -0
  111. package/project/plugins/package-version-plugins/pkgdb.d.ts +133 -0
  112. package/project/plugins/package-version-plugins/pkgdb.js +370 -0
  113. package/project/plugins/plugin-registry.d.ts +4 -1
  114. package/project/plugins/plugin-registry.js +7 -0
  115. package/queries/catalog/call-context-query/call-context-query-executor.js +8 -0
  116. package/queries/catalog/call-context-query/call-context-query-format.d.ts +2 -0
  117. package/queries/catalog/call-context-query/call-context-query-format.js +1 -0
  118. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +8 -0
  119. package/queries/catalog/dependencies-query/dependencies-query-executor.js +31 -3
  120. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -1
  121. package/queries/catalog/dependencies-query/dependencies-query-format.js +3 -2
  122. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +1 -1
  123. package/queries/catalog/dependencies-query/function-info/other-path-functions.d.ts +2 -0
  124. package/queries/catalog/dependencies-query/function-info/other-path-functions.js +27 -0
  125. package/queries/catalog/dependencies-query/function-info/read-functions.js +5 -4
  126. package/queries/catalog/dependencies-query/function-info/visualize-functions.js +3 -1
  127. package/queries/catalog/linter-query/linter-query-executor.js +1 -0
  128. package/r-bridge/data/data.d.ts +2 -2
  129. package/r-bridge/data/data.js +2 -2
  130. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +13 -4
  131. package/search/search-executor/search-enrichers.d.ts +1 -1
  132. package/search/search-executor/search-enrichers.js +7 -4
  133. package/util/mermaid/mermaid.d.ts +4 -0
  134. package/util/mermaid/mermaid.js +8 -1
  135. package/util/text/ansi.d.ts +10 -1
  136. package/util/text/ansi.js +17 -4
  137. package/util/version.js +10 -2
  138. package/cli/common/features.d.ts +0 -9
  139. package/cli/common/features.js +0 -35
  140. package/cli/script-core/statistics-core.d.ts +0 -6
  141. package/cli/script-core/statistics-core.js +0 -104
  142. package/cli/script-core/statistics-helper-core.d.ts +0 -6
  143. package/cli/script-core/statistics-helper-core.js +0 -86
  144. package/cli/statistics-app.d.ts +0 -11
  145. package/cli/statistics-app.js +0 -16
  146. package/cli/statistics-helper-app.d.ts +0 -11
  147. package/cli/statistics-helper-app.js +0 -14
  148. package/statistics/features/common-syntax-probability.d.ts +0 -38
  149. package/statistics/features/common-syntax-probability.js +0 -169
  150. package/statistics/features/feature.d.ts +0 -179
  151. package/statistics/features/feature.js +0 -38
  152. package/statistics/features/post-processing.d.ts +0 -18
  153. package/statistics/features/post-processing.js +0 -26
  154. package/statistics/features/supported/assignments/assignments.d.ts +0 -12
  155. package/statistics/features/supported/assignments/assignments.js +0 -56
  156. package/statistics/features/supported/assignments/post-process.d.ts +0 -6
  157. package/statistics/features/supported/assignments/post-process.js +0 -126
  158. package/statistics/features/supported/comments/comments.d.ts +0 -18
  159. package/statistics/features/supported/comments/comments.js +0 -143
  160. package/statistics/features/supported/comments/post-process.d.ts +0 -6
  161. package/statistics/features/supported/comments/post-process.js +0 -51
  162. package/statistics/features/supported/control-flow/control-flow.d.ts +0 -17
  163. package/statistics/features/supported/control-flow/control-flow.js +0 -69
  164. package/statistics/features/supported/control-flow/post-process.d.ts +0 -6
  165. package/statistics/features/supported/control-flow/post-process.js +0 -66
  166. package/statistics/features/supported/data-access/data-access.d.ts +0 -15
  167. package/statistics/features/supported/data-access/data-access.js +0 -122
  168. package/statistics/features/supported/data-access/post-process.d.ts +0 -6
  169. package/statistics/features/supported/data-access/post-process.js +0 -108
  170. package/statistics/features/supported/defined-functions/defined-functions.d.ts +0 -34
  171. package/statistics/features/supported/defined-functions/defined-functions.js +0 -145
  172. package/statistics/features/supported/defined-functions/post-process.d.ts +0 -6
  173. package/statistics/features/supported/defined-functions/post-process.js +0 -168
  174. package/statistics/features/supported/expression-list/post-process.d.ts +0 -6
  175. package/statistics/features/supported/expression-list/post-process.js +0 -45
  176. package/statistics/features/supported/expression-list/statistics-expression-list.d.ts +0 -9
  177. package/statistics/features/supported/expression-list/statistics-expression-list.js +0 -37
  178. package/statistics/features/supported/loops/loops.d.ts +0 -20
  179. package/statistics/features/supported/loops/loops.js +0 -81
  180. package/statistics/features/supported/loops/post-process.d.ts +0 -6
  181. package/statistics/features/supported/loops/post-process.js +0 -73
  182. package/statistics/features/supported/used-functions/post-process.d.ts +0 -6
  183. package/statistics/features/supported/used-functions/post-process.js +0 -176
  184. package/statistics/features/supported/used-functions/used-functions.d.ts +0 -24
  185. package/statistics/features/supported/used-functions/used-functions.js +0 -99
  186. package/statistics/features/supported/used-packages/post-process.d.ts +0 -6
  187. package/statistics/features/supported/used-packages/post-process.js +0 -122
  188. package/statistics/features/supported/used-packages/used-packages.d.ts +0 -16
  189. package/statistics/features/supported/used-packages/used-packages.js +0 -140
  190. package/statistics/features/supported/values/post-process.d.ts +0 -6
  191. package/statistics/features/supported/values/post-process.js +0 -73
  192. package/statistics/features/supported/values/values.d.ts +0 -14
  193. package/statistics/features/supported/values/values.js +0 -111
  194. package/statistics/features/supported/variables/post-process.d.ts +0 -15
  195. package/statistics/features/supported/variables/post-process.js +0 -126
  196. package/statistics/features/supported/variables/variables.d.ts +0 -15
  197. package/statistics/features/supported/variables/variables.js +0 -62
  198. package/statistics/meta-statistics.d.ts +0 -32
  199. package/statistics/meta-statistics.js +0 -16
  200. package/statistics/output/file-provider.d.ts +0 -36
  201. package/statistics/output/file-provider.js +0 -96
  202. package/statistics/output/print-stats.d.ts +0 -29
  203. package/statistics/output/print-stats.js +0 -81
  204. package/statistics/output/statistics-file.d.ts +0 -36
  205. package/statistics/output/statistics-file.js +0 -68
  206. package/statistics/statistics.d.ts +0 -29
  207. package/statistics/statistics.js +0 -108
  208. package/statistics/summarizer/auto-detect.d.ts +0 -5
  209. package/statistics/summarizer/auto-detect.js +0 -34
  210. package/statistics/summarizer/first-phase/process.d.ts +0 -6
  211. package/statistics/summarizer/first-phase/process.js +0 -81
  212. package/statistics/summarizer/post-process/clusterer.d.ts +0 -25
  213. package/statistics/summarizer/post-process/clusterer.js +0 -40
  214. package/statistics/summarizer/post-process/file-based-count.d.ts +0 -16
  215. package/statistics/summarizer/post-process/file-based-count.js +0 -47
  216. package/statistics/summarizer/post-process/histogram.d.ts +0 -57
  217. package/statistics/summarizer/post-process/histogram.js +0 -126
  218. package/statistics/summarizer/post-process/post-process-output.d.ts +0 -14
  219. package/statistics/summarizer/post-process/post-process-output.js +0 -102
  220. package/statistics/summarizer/second-phase/process.d.ts +0 -15
  221. package/statistics/summarizer/second-phase/process.js +0 -118
  222. package/statistics/summarizer/summarizer.d.ts +0 -34
  223. package/statistics/summarizer/summarizer.js +0 -141
@@ -27,6 +27,7 @@ const resolve_by_name_1 = require("../dataflow/environments/resolve-by-name");
27
27
  const default_pipelines_1 = require("../core/steps/pipeline/default-pipelines");
28
28
  const text_1 = require("../util/text/text");
29
29
  const linker_1 = require("../dataflow/internal/linker");
30
+ const apply_kill_1 = require("../dataflow/environments/apply-kill");
30
31
  const doc_normalized_ast_1 = require("./doc-util/doc-normalized-ast");
31
32
  const dfg_get_origin_1 = require("../dataflow/origin/dfg-get-origin");
32
33
  const identify_link_to_last_call_relation_1 = require("../queries/catalog/call-context-query/identify-link-to-last-call-relation");
@@ -965,7 +966,7 @@ Let's start by looking at the properties of the dataflow information object: ${O
965
966
 
966
967
  ${(() => {
967
968
  /* this includes the meta field for timing and the quick CFG in order to enable re-use and improve performance */
968
- (0, assert_1.guard)(Object.keys(result).length === 10, () => 'Update Dataflow Documentation! (Keys: ' + Object.keys(result).join(', ') + ')');
969
+ (0, assert_1.guard)(Object.keys(result).length === 11, () => 'Update Dataflow Documentation! (Keys: ' + Object.keys(result).join(', ') + ')');
969
970
  return '';
970
971
  })()}
971
972
 
@@ -985,9 +986,42 @@ ${(0, doc_env_1.printEnvironmentToMarkdown)(result.environment.current)}
985
986
  This shows us that the local environment contains a single definition for \`x\` (with id 0) and that the parent environment is the built-in environment.
986
987
  Additionally, we get the information that the node with the id 2 was responsible for the definition of \`x\`.
987
988
 
989
+ #### Attached Packages and the Search Path
990
+
991
+ Calling \`library(pkg)\` (or \`require\`) attaches a package to the search path.
992
+ Mirroring R's \`search()\`, _flowR_ inserts the package's namespace and imports environments *below* the global environment (\`.GlobalEnv\`), so resolution walks **current scope -> enclosing scopes -> global -> attached packages -> built-ins**.
993
+
994
+ **A global binding shadows a package export** of the same name, exactly as in R:
995
+
996
+ \`\`\`r
997
+ filter <- function(x) x # your global definition
998
+ library(stats) # stats also exports filter()
999
+ filter(1) # -> resolves to YOUR filter, not stats::filter
1000
+ \`\`\`
1001
+
1002
+ **Most recently attached is nearest, and re-attaching is a no-op:**
1003
+
1004
+ \`\`\`r
1005
+ library(A) # search path (top-down): A
1006
+ library(B) # B, A
1007
+ library(A) # no-op B, A (A is not moved or duplicated)
1008
+ \`\`\`
1009
+
1010
+ **Attaching inside a function propagates to the caller** (R attaches globally), and across branches every possibly-attached package is kept (a sound over-approximation of R's single runtime path):
1011
+
1012
+ \`\`\`r
1013
+ f <- function() library(A) # attaches A when called
1014
+ f()
1015
+ someExportOfA() # -> resolves against A
1016
+ if (cond) library(B) # B is kept (may be attached)
1017
+ \`\`\`
1018
+
988
1019
  Last but not least, the information contains the single **entry point** (${JSON.stringify(result.entryPoint)}) and a set of **exit points** (${JSON.stringify(result.exitPoints.map(e => e.nodeId))}).
989
1020
  Besides marking potential exits, the exit points also provide information about why the exit occurs and which control dependencies affect the exit.
990
1021
 
1022
+ Finally, the **kill** property (${ctx.link('KillReference', undefined, { type: 'type' })}) tracks references that are removed from scope within the current subtree (e.g., via \`rm(x)\`).
1023
+ It is \`undefined\` unless such a removal occurred and, like the outgoing references, bubbles up so that the enclosing scope can apply the removal (see ${ctx.link(apply_kill_1.applyKills)}) at the right location.
1024
+
991
1025
  ### Unknown Side Effects
992
1026
 
993
1027
  In case _flowR_ encounters a function call that it cannot handle, it marks the call as an unknown side effect.
@@ -35,8 +35,7 @@ ${(0, doc_structure_1.block)({
35
35
  type: 'NOTE',
36
36
  content: `
37
37
  The default ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'server', false)} uses a simple [TCP](https://de.wikipedia.org/wiki/Transmission_Control_Protocol)
38
- connection. If you want _flowR_ to expose a [WebSocket](https://de.wikipedia.org/wiki/WebSocket) server instead, add the ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'ws', false)} flag (i.e., ${(0, doc_cli_option_1.multipleCliOptions)('flowr', 'server', 'ws')}) when starting _flowR_ from the command line.
39
- `
38
+ connection. If you want _flowR_ to expose a [WebSocket](https://de.wikipedia.org/wiki/WebSocket) server instead, add the ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'ws', false)} flag (i.e., ${(0, doc_cli_option_1.multipleCliOptions)('flowr', 'server', 'ws')}) when starting _flowR_ from the command line.`
40
39
  })}
41
40
 
42
41
  ${await (0, doc_server_message_1.printServerMessages)(parser)}
@@ -264,6 +263,7 @@ ${(0, doc_code_1.codeBlock)('json', JSON.stringify({
264
263
  variables: config_1.VariableResolve.Alias,
265
264
  evalStrings: true,
266
265
  trackEnvironments: true,
266
+ pkgdb: { enabled: true, eagerlyLoad: false, eagerlyLoadExports: false },
267
267
  resolveSource: {
268
268
  dropPaths: config_1.DropPathsOption.No,
269
269
  ignoreCapitalization: true,
@@ -132,6 +132,7 @@ function(x) {
132
132
  rule(knownParser, 'software-has-license', 'SoftwareHasLicenseConfig', 'SOFTWARE_HAS_LICENSE', 'lint-software-has-license', 'cat("a project without a license")', tagTypes);
133
133
  rule(knownParser, 'software-has-tests', 'SoftwareHasTestsConfig', 'SOFTWARE_HAS_TESTS', 'lint-software-has-tests', 'cat("hello")', tagTypes);
134
134
  rule(knownParser, 'no-leaked-credentials', 'NoLeakedCredentialsConfig', 'NO_LEAKED_CREDENTIALS', 'lint-no-leaked-credentials', 'password <- "s3cr3t"', tagTypes);
135
+ rule(knownParser, 'undefined-symbol', 'UndefinedSymbolConfig', 'UNDEFINED_SYMBOL', 'lint-undefined-symbol', 'undefined_helper(42)', tagTypes);
135
136
  function rule(parser, name, configType, ruleType, testfile, example, types) {
136
137
  const rule = linter_rules_1.LintingRules[name];
137
138
  const tags = rule.info.tags.toSorted((a, b) => {
@@ -209,6 +210,7 @@ async function getTextMainPage(knownParser, tagTypes, ctx) {
209
210
  const rules = registerRules(knownParser, tagTypes.info);
210
211
  return `
211
212
  This page describes the flowR linter, which is a tool that utilizes flowR's dataflow analysis to find common issues in R scripts. The linter can currently be used through the linter ${ctx.linkPage('wiki/Query API', 'query')}.
213
+ Some rules also draw on the ${ctx.linkPage('wiki/Package Database', 'package database')}.
212
214
  For example:
213
215
 
214
216
  ${await (async () => {
@@ -28,7 +28,6 @@ for instructions on how to install _flowR_.
28
28
  - [Generate Static Slices](#generate-static-slices)
29
29
  - [Benchmark the Slicer](#benchmark-the-slicer)
30
30
  - [Summarizing the Benchmark Results](#summarizing-the-benchmark-results)
31
- - [Generate Usage Statistics of R Code](#generate-usage-statistics-of-r-code)
32
31
  <!-- TOC -->
33
32
 
34
33
  ## _flowR_'s Modules
@@ -42,11 +41,9 @@ If you wish to use _flowR_, check out one of its extensions (e.g., the ${ctx.lin
42
41
  the [REPL and server interfaces](#using-_flowr_-from-the-outside) or its coding API with the
43
42
  ${ctx.link(flowr_analyzer_1.FlowrAnalyzer)}.
44
43
 
45
- The benchmark module is only of interest if you want to benchmark/measure the runtime performance and reduction of the slicer.
44
+ The benchmark module is only of interest if you want to benchmark/measure the runtime performance and reduction of the slicer.
46
45
  It is available with the [\`benchmark\`](#benchmark-the-slicer) script.
47
46
 
48
- The statistics module is mostly independent of the slicer and can be used to analyze R files regarding their use of function definitions, assignments, and more. It is used to identify common patterns in R code and is available with the [\`statistics\`](#generate-usage-statistics-of-r-code) script.
49
-
50
47
  The [core](https://github.com/flowr-analysis/flowr/tree/main/src/core) module contains _flowR_'s read-eval-print loop (REPL) and
51
48
  _flowR_'s server. Furthermore, it contains the root definitions of how _flowR_ slices (see the ${ctx.linkPage('wiki/Interface')} wiki page for more information).
52
49
 
@@ -230,16 +227,6 @@ For more options, run the following from the \`cli\` directory:
230
227
 
231
228
  \`\`\`shell
232
229
  npm run summarizer -- --help
233
- \`\`\`
234
-
235
- ### Generate Usage Statistics of R Code
236
-
237
- If you want to reproduce the statistics as presented in the original [master's thesis](http://dx.doi.org/10.18725/OPARU-50107), see the corresponding [wiki page](https://github.com/flowr-analysis/flowr/wiki/Thesis#how-to-reproduce-the-statistics-from-the-masters-thesis).
238
-
239
- For more information, run the following from the \`cli\` directory:
240
-
241
- \`\`\`shell
242
- npm run stats -- --help
243
230
  \`\`\`
244
231
  `.trim();
245
232
  }
@@ -0,0 +1,9 @@
1
+ import type { DocMakerArgs } from './wiki-mk/doc-maker';
2
+ import { DocMaker } from './wiki-mk/doc-maker';
3
+ /**
4
+ * https://github.com/flowr-analysis/flowr/wiki/Package-Database
5
+ */
6
+ export declare class WikiPackageDatabase extends DocMaker<'wiki/Package Database.md'> {
7
+ constructor();
8
+ text({ ctx }: DocMakerArgs): string;
9
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WikiPackageDatabase = void 0;
4
+ const doc_maker_1 = require("./wiki-mk/doc-maker");
5
+ const doc_files_1 = require("./doc-util/doc-files");
6
+ const pkgdb_1 = require("../project/plugins/package-version-plugins/pkgdb");
7
+ const flowr_analyzer_package_versions_pkgdb_plugin_1 = require("../project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin");
8
+ const flowr_analyzer_builder_1 = require("../project/flowr-analyzer-builder");
9
+ /** point the resolver at your own database (a file path or http(s) URL) */
10
+ function usePackageDatabase(parser) {
11
+ const pkgdb = new flowr_analyzer_package_versions_pkgdb_plugin_1.FlowrAnalyzerPackageVersionsPkgDbPlugin('/path/to/pkgdb-all.json.br');
12
+ return new flowr_analyzer_builder_1.FlowrAnalyzerBuilder().setParser(parser).registerPlugins(pkgdb).build();
13
+ }
14
+ /** link a built-in plugin key (e.g. `versions:pkgdb`) to its registration */
15
+ function pluginLink(key) {
16
+ return `[\`${key}\`](${doc_files_1.RemoteFlowrFilePathBaseRef}src/project/plugins/plugin-registry.ts)`;
17
+ }
18
+ /**
19
+ * https://github.com/flowr-analysis/flowr/wiki/Package-Database
20
+ */
21
+ class WikiPackageDatabase extends doc_maker_1.DocMaker {
22
+ constructor() {
23
+ super('wiki/Package Database.md', module.filename, 'bundled CRAN package database that resolves `library()` calls');
24
+ }
25
+ text({ ctx }) {
26
+ return `
27
+ # Package Database
28
+
29
+ flowR ships a database of CRAN package exports so it can resolve calls into the packages you load.
30
+ After \`library(ggplot2)\`, a call to \`ggplot()\` resolves to \`ggplot2::ggplot\`. This also backs
31
+ qualified names (a bare \`map()\` after \`library(purrr)\` is \`purrr::map\`, not the \`maps\` plot), the
32
+ ${ctx.linkPage('wiki/Query API', 'dependencies and call-context queries')}, and the ${ctx.linkPage('wiki/Linter', '`undefined-symbol` rule')}.
33
+
34
+ ## Configuration
35
+
36
+ The exports come from ${pluginLink('versions:pkgdb')}, which reads the bundled database (on by default;
37
+ see ${ctx.linkPage('wiki/Interface', 'configuring flowR', 'configuring-flowr')}).
38
+
39
+ *Which* version's exports are resolved is decided by the version-reading plugins that pin the packages
40
+ used in a project. These are only examples - more may be registered:
41
+
42
+ - ${pluginLink('versions:description')} reads a package's \`DESCRIPTION\` (\`Depends\` / \`Imports\`, ${(0, doc_files_1.linkFlowRSourceFile)('src/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.ts')}).
43
+ - ${pluginLink('versions:renv')} and ${pluginLink('versions:rv')} read a project's \`renv.lock\` / \`rv.lock\`
44
+ to pin exact versions (${(0, doc_files_1.linkFlowRSourceFile)('src/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.ts')}).
45
+
46
+ So \`library(pkg)\` resolves the pinned version's exports. To override or extend the bundle, hand
47
+ ${pluginLink('versions:pkgdb')} extra sources (file paths, parsed objects, or \`http(s)\` URLs).
48
+
49
+ ${ctx.code(usePackageDatabase, { dropLinesStart: 1 })}
50
+
51
+ File sources load lazily on the first package load, so scripts without \`library()\`/\`use()\` calls never
52
+ pay for parsing them (set \`solver.pkgdb.eagerlyLoad\` to mount the database up front, or \`solver.pkgdb.enabled: false\` to switch it off entirely).
53
+ For a URL source call ${ctx.linkM(flowr_analyzer_package_versions_pkgdb_plugin_1.FlowrAnalyzerPackageVersionsPkgDbPlugin, 'preload', { hideClass: true, codeFont: true })} (\`await pkgdb.preload()\`) before analysis to download it.
54
+
55
+ ## Format
56
+
57
+ One JSON object (\`flowr-pkgdb\`, schema ${pkgdb_1.PkgDbSchema}) with a pooled string table.
58
+ Reader and writer both live in ${(0, doc_files_1.linkFlowRSourceFile)('src/project/plugins/package-version-plugins/pkgdb.ts')}.
59
+ `.trim();
60
+ }
61
+ }
62
+ exports.WikiPackageDatabase = WikiPackageDatabase;
63
+ //# sourceMappingURL=wiki-package-database.js.map
@@ -660,6 +660,7 @@ print("hello world!")
660
660
  return `
661
661
  This query extracts all dependencies from an R script, using a combination of a ${(0, doc_query_1.linkToQueryOfName)('call-context')}
662
662
  and more advanced tracking in the ${ctx.linkPage('wiki/Dataflow Graph', 'Dataflow Graph')}.
663
+ Loaded libraries are resolved against the ${ctx.linkPage('wiki/Package Database', 'package database')}.
663
664
 
664
665
  In other words, if you have a script simply reading: \`${exampleCode}\`, the following query returns the loaded library:
665
666
  ${await (0, doc_query_1.showQuery)(shell, exampleCode, [{
@@ -357,6 +357,29 @@ export declare const LintingRules: {
357
357
  };
358
358
  };
359
359
  };
360
+ readonly 'undefined-symbol': {
361
+ readonly createSearch: (_config: import("./rules/undefined-symbol").UndefinedSymbolConfig) => import("../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, Promise<import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, [] | import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>>;
362
+ readonly processSearchResult: (elements: import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: import("../util/objects").MergeableRecord, data: import("../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>) => Promise<{
363
+ results: {
364
+ certainty: import("./linter-format").LintingResultCertainty.Uncertain;
365
+ name: import("../dataflow/environments/identifier").BrandedIdentifier;
366
+ involvedId: import("../r-bridge/lang-4.x/ast/model/processing/node-id").NodeId;
367
+ loc: [startLine: number, startColumn: number, endLine: number, endColumn: number, f?: string | undefined];
368
+ }[];
369
+ '.meta': import("./rules/undefined-symbol").UndefinedSymbolMetadata;
370
+ }>;
371
+ readonly prettyPrint: {
372
+ readonly query: (result: import("./rules/undefined-symbol").UndefinedSymbolResult) => string;
373
+ readonly full: (result: import("./rules/undefined-symbol").UndefinedSymbolResult) => string;
374
+ };
375
+ readonly info: {
376
+ readonly name: "Undefined Symbol";
377
+ readonly certainty: import("./linter-format").LintingRuleCertainty.OverApproximative;
378
+ readonly description: "Flags calls to functions that are neither defined locally, a known builtin, nor exported by a loaded package.";
379
+ readonly tags: readonly [import("./linter-tags").LintingRuleTag.Bug, import("./linter-tags").LintingRuleTag.Experimental];
380
+ readonly defaultConfig: {};
381
+ };
382
+ };
360
383
  };
361
384
  export type LintingRuleNames = keyof typeof LintingRules;
362
385
  export type LintingRuleMetadata<Name extends LintingRuleNames> = typeof LintingRules[Name] extends LintingRule<infer _Result, infer Metadata, infer _Config, infer _Info, infer _Elements> ? Metadata : never;
@@ -17,6 +17,7 @@ const problematic_inputs_1 = require("./rules/problematic-inputs");
17
17
  const software_has_license_1 = require("./rules/software-has-license");
18
18
  const software_has_tests_1 = require("./rules/software-has-tests");
19
19
  const no_leaked_credentials_1 = require("./rules/no-leaked-credentials");
20
+ const undefined_symbol_1 = require("./rules/undefined-symbol");
20
21
  /**
21
22
  * The registry of currently supported linting rules.
22
23
  * A linting rule can be executed on a dataflow pipeline result using {@link executeLintingRule}.
@@ -37,6 +38,7 @@ exports.LintingRules = {
37
38
  'roxygen-arguments': roxygen_arguments_1.ROXYGEN_ARGS,
38
39
  'software-has-license': software_has_license_1.SOFTWARE_HAS_LICENSE,
39
40
  'software-has-tests': software_has_tests_1.SOFTWARE_HAS_TESTS,
40
- 'no-leaked-credentials': no_leaked_credentials_1.NO_LEAKED_CREDENTIALS
41
+ 'no-leaked-credentials': no_leaked_credentials_1.NO_LEAKED_CREDENTIALS,
42
+ 'undefined-symbol': undefined_symbol_1.UNDEFINED_SYMBOL
41
43
  };
42
44
  //# sourceMappingURL=linter-rules.js.map
@@ -21,6 +21,7 @@ const dependencies_query_format_1 = require("../../queries/catalog/dependencies-
21
21
  const resolve_argument_1 = require("../../dataflow/eval/resolve/resolve-argument");
22
22
  const path_1 = __importDefault(require("path"));
23
23
  const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
24
+ const other_path_functions_1 = require("../../queries/catalog/dependencies-query/function-info/other-path-functions");
24
25
  function inferWd(file, wd) {
25
26
  if (wd === '@script') {
26
27
  // we can use the script path as the working directory
@@ -94,7 +95,7 @@ exports.ABSOLUTE_PATH = {
94
95
  type: 'dependencies',
95
96
  // we use the dependencies query to give us all functions that take a file path as input
96
97
  ignoreDefaultFunctions: true,
97
- readFunctions: read_functions_1.ReadFunctions.concat(write_functions_1.WriteFunctions, source_functions_1.SourceFunctions, config.additionalPathFunctions),
98
+ readFunctions: read_functions_1.ReadFunctions.concat(write_functions_1.WriteFunctions, source_functions_1.SourceFunctions, other_path_functions_1.OtherPathFunctions, config.additionalPathFunctions),
98
99
  });
99
100
  }
100
101
  if (config.include.constructed) {
@@ -0,0 +1,39 @@
1
+ import type { MergeableRecord } from '../../util/objects';
2
+ import { type LintingResult, LintingResultCertainty, LintingRuleCertainty } from '../linter-format';
3
+ import { LintingRuleTag } from '../linter-tags';
4
+ export interface UndefinedSymbolResult extends LintingResult {
5
+ /** the called name that could not be resolved */
6
+ name: string;
7
+ }
8
+ export type UndefinedSymbolConfig = MergeableRecord;
9
+ export interface UndefinedSymbolMetadata extends MergeableRecord {
10
+ totalCalls: number;
11
+ }
12
+ /**
13
+ * Flags calls to functions that are neither defined locally, a known builtin, nor exported by a
14
+ * package loaded via `library()`/`require()`/`use()` (resolved from the `flowr-pkgdb` database).
15
+ * Over-approximative: reflection/NSE and packages without export info can cause false positives.
16
+ */
17
+ export declare const UNDEFINED_SYMBOL: {
18
+ readonly createSearch: (_config: UndefinedSymbolConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, [] | import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>>;
19
+ readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: MergeableRecord, data: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>) => Promise<{
20
+ results: {
21
+ certainty: LintingResultCertainty.Uncertain;
22
+ name: import("../../dataflow/environments/identifier").BrandedIdentifier;
23
+ involvedId: import("../../r-bridge/lang-4.x/ast/model/processing/node-id").NodeId;
24
+ loc: [startLine: number, startColumn: number, endLine: number, endColumn: number, f?: string | undefined];
25
+ }[];
26
+ '.meta': UndefinedSymbolMetadata;
27
+ }>;
28
+ readonly prettyPrint: {
29
+ readonly query: (result: UndefinedSymbolResult) => string;
30
+ readonly full: (result: UndefinedSymbolResult) => string;
31
+ };
32
+ readonly info: {
33
+ readonly name: "Undefined Symbol";
34
+ readonly certainty: LintingRuleCertainty.OverApproximative;
35
+ readonly description: "Flags calls to functions that are neither defined locally, a known builtin, nor exported by a loaded package.";
36
+ readonly tags: readonly [LintingRuleTag.Bug, LintingRuleTag.Experimental];
37
+ readonly defaultConfig: {};
38
+ };
39
+ };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNDEFINED_SYMBOL = void 0;
4
+ const vertex_1 = require("../../dataflow/graph/vertex");
5
+ const dfg_get_origin_1 = require("../../dataflow/origin/dfg-get-origin");
6
+ const identifier_1 = require("../../dataflow/environments/identifier");
7
+ const flowr_search_builder_1 = require("../../search/flowr-search-builder");
8
+ const assert_1 = require("../../util/assert");
9
+ const range_1 = require("../../util/range");
10
+ const linter_format_1 = require("../linter-format");
11
+ const linter_tags_1 = require("../linter-tags");
12
+ /** calls that load a package; an unresolved one means we cannot enumerate all exports in scope */
13
+ const LibraryLoadFunctions = new Set(['library', 'require', 'requireNamespace', 'loadNamespace', 'attachNamespace', 'load_all', 'use', 'p_load']);
14
+ /**
15
+ * Flags calls to functions that are neither defined locally, a known builtin, nor exported by a
16
+ * package loaded via `library()`/`require()`/`use()` (resolved from the `flowr-pkgdb` database).
17
+ * Over-approximative: reflection/NSE and packages without export info can cause false positives.
18
+ */
19
+ exports.UNDEFINED_SYMBOL = {
20
+ createSearch: (_config) => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.FunctionCall),
21
+ processSearchResult: async (elements, config, data) => {
22
+ const dataflow = await data.dataflow();
23
+ const deps = data.inspectContext().deps;
24
+ const meta = { totalCalls: 0 };
25
+ // only report when every loaded library's exports are known: a library() whose package we could
26
+ // not resolve is flagged with an unknown side effect and could export the symbol, so we bail out
27
+ const unknownIds = new Set();
28
+ for (const e of dataflow.graph.unknownSideEffects) {
29
+ unknownIds.add(String(typeof e === 'object' ? e.id : e));
30
+ }
31
+ if (unknownIds.size > 0) {
32
+ for (const [id, v] of dataflow.graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
33
+ if (LibraryLoadFunctions.has(identifier_1.Identifier.getName(v.name)) && unknownIds.has(String(id))) {
34
+ return { results: [], '.meta': meta };
35
+ }
36
+ }
37
+ }
38
+ const results = elements.getElements().map(element => {
39
+ const vtx = dataflow.graph.getVertex(element.node.info.id);
40
+ if (!vtx || !(0, vertex_1.isFunctionCallVertex)(vtx) || vtx.origin === 'unnamed') {
41
+ return undefined;
42
+ }
43
+ meta.totalCalls++;
44
+ const name = identifier_1.Identifier.getName(vtx.name);
45
+ // resolved locally, as a builtin, or as an attached package export?
46
+ const origins = (0, dfg_get_origin_1.getOriginInDfg)(dataflow.graph, vtx.id);
47
+ if (origins && origins.length > 0) {
48
+ return undefined;
49
+ }
50
+ // cross-check loaded packages' exports (covers namespace-only / `pkg::fn` loads)
51
+ const namespace = identifier_1.Identifier.getNamespace(vtx.name);
52
+ const known = namespace !== undefined
53
+ ? deps.getDependency(namespace)?.has(name) === true
54
+ : deps.getDependencies().some(p => p.has(name));
55
+ if (known) {
56
+ return undefined;
57
+ }
58
+ const loc = range_1.SourceLocation.fromNode(element.node);
59
+ return loc === undefined ? undefined : {
60
+ certainty: linter_format_1.LintingResultCertainty.Uncertain,
61
+ name,
62
+ involvedId: vtx.id,
63
+ loc
64
+ };
65
+ }).filter(assert_1.isNotUndefined);
66
+ return { results, '.meta': meta };
67
+ },
68
+ prettyPrint: {
69
+ [linter_format_1.LintingPrettyPrintContext.Query]: result => `Call to \`${result.name}\` at ${range_1.SourceLocation.format(result.loc)}`,
70
+ [linter_format_1.LintingPrettyPrintContext.Full]: result => `\`${result.name}\` at ${range_1.SourceLocation.format(result.loc)} is neither defined locally nor exported by a loaded package`
71
+ },
72
+ info: {
73
+ name: 'Undefined Symbol',
74
+ certainty: linter_format_1.LintingRuleCertainty.OverApproximative,
75
+ description: 'Flags calls to functions that are neither defined locally, a known builtin, nor exported by a loaded package.',
76
+ tags: [linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Experimental],
77
+ defaultConfig: {}
78
+ }
79
+ };
80
+ //# sourceMappingURL=undefined-symbol.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.10.10",
3
+ "version": "2.11.1",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -19,8 +19,6 @@
19
19
  "main-dev": "node -r ts-node/register --watch src/cli/flowr.ts",
20
20
  "publish-library": "cp .npmignore package.json README.md LICENSE dist/src/ && cd dist/src && npm publish --access public",
21
21
  "release": "npx release-it --ci",
22
- "stats": "ts-node src/cli/statistics-app.ts",
23
- "stats-helper": "ts-node src/cli/statistics-helper-app.ts",
24
22
  "slicer": "ts-node src/cli/slicer-app.ts",
25
23
  "benchmark-helper": "ts-node src/cli/benchmark-helper-app.ts",
26
24
  "benchmark": "npm run build-dev && node dist/src/cli/benchmark-app.js",
@@ -29,7 +27,8 @@
29
27
  "capabilities-markdown": "ts-node src/documentation/doc-capabilities.ts",
30
28
  "wiki": "ts-node src/cli/wiki.ts",
31
29
  "wiki:watch": "node -r ts-node/register --watch src/cli/wiki.ts --keep-alive",
32
- "build": "tsc --project .",
30
+ "build": "tsc --project . && npm run build:copy-data",
31
+ "build:copy-data": "node scripts/pkgdb-compress.mjs",
33
32
  "build-dev": "npm run build && npm run build:copy-wasm",
34
33
  "build:bundle-flowr": "npm run build && esbuild --bundle dist/src/cli/flowr.js --platform=node --tree-shaking=true --minify --external:clipboardy --target=node22 --outfile=dist/src/cli/flowr.min.js && npm run build:copy-wasm",
35
34
  "build:copy-wasm": "mkdir -p dist/node_modules/@davisvaughan/tree-sitter-r/ && mkdir -p dist/node_modules/web-tree-sitter && cp node_modules/@davisvaughan/tree-sitter-r/tree-sitter-r.wasm dist/node_modules/@davisvaughan/tree-sitter-r/ && cp node_modules/web-tree-sitter/tree-sitter.wasm dist/node_modules/web-tree-sitter/",
@@ -46,6 +45,7 @@
46
45
  "test-full": "npm run test:coverage -- --no-watch -- --make-summary --test-installation",
47
46
  "performance-test": "func() { cd test/performance/ && bash run-all-suites.sh $1 $2 $3 $4; cd ../../; }; func",
48
47
  "test:performance": "npm run performance-test --",
48
+ "test:docker": "func() { for df in scripts/Dockerfile scripts/Dockerfile-NoR; do echo \"=== building $df ===\"; docker build -t flowr-docker-test -f \"$df\" . || return 1; echo \"=== smoke-testing $df ===\"; docker run --rm flowr-docker-test --version || return 1; done; }; func",
49
49
  "detect-circular-deps": "npx madge --extensions ts,tsx --circular src/",
50
50
  "checkup": "npm run flowr -- --execute \":version\" && npm run lint && npm run test-full -- --allowOnly=false && npm run test:system -- --no-watch && docker build -t test-flowr -f scripts/Dockerfile . && npm run doc && npm run wiki"
51
51
  },
@@ -27,6 +27,8 @@ export declare class FlowrAnalyzerCache<Parser extends KnownParser> extends Flow
27
27
  private callGraphCache;
28
28
  protected constructor(args: FlowrAnalyzerCacheOptions<Parser>);
29
29
  private initCacheProviders;
30
+ /** Free the current parse trees: tree-sitter trees live on the WASM heap, which the GC does not reclaim. */
31
+ private disposeParse;
30
32
  static create<Parser extends KnownParser>(data: FlowrAnalyzerCacheOptions<Parser>): FlowrAnalyzerCache<Parser>;
31
33
  receive(event: CacheInvalidationEvent): void;
32
34
  private get;
@@ -28,13 +28,21 @@ class FlowrAnalyzerCache extends flowr_cache_1.FlowrCache {
28
28
  this.controlFlowCache = new flowr_analyzer_controlflow_cache_1.FlowrAnalyzerControlFlowCache();
29
29
  this.callGraphCache = undefined;
30
30
  }
31
+ /** Free the current parse trees: tree-sitter trees live on the WASM heap, which the GC does not reclaim. */
32
+ disposeParse() {
33
+ const files = this.peekParse()?.files;
34
+ for (const file of files ?? []) {
35
+ file.parsed?.delete?.();
36
+ }
37
+ }
31
38
  static create(data) {
32
39
  return new FlowrAnalyzerCache(data);
33
40
  }
34
41
  receive(event) {
35
- super.receive(event);
36
42
  switch (event.type) {
37
43
  case "full" /* CacheInvalidationEventType.Full */:
44
+ this.disposeParse();
45
+ super.receive(event);
38
46
  this.initCacheProviders();
39
47
  break;
40
48
  default:
@@ -1,11 +1,9 @@
1
1
  import { AbstractFlowrAnalyzerContext } from './abstract-flowr-analyzer-context';
2
- import { FlowrAnalyzerPackageVersionsPlugin } from '../plugins/package-version-plugins/flowr-analyzer-package-versions-plugin';
2
+ import { FlowrAnalyzerPackageVersionsPlugin, type PkgDbLoadedInfo } from '../plugins/package-version-plugins/flowr-analyzer-package-versions-plugin';
3
3
  import type { Package } from '../plugins/package-version-plugins/package';
4
4
  import type { FlowrAnalyzerFunctionsContext, ReadOnlyFlowrAnalyzerFunctionsContext } from './flowr-analyzer-functions-context';
5
5
  /**
6
- * This is a read-only interface to the {@link FlowrAnalyzerDependenciesContext}.
7
- * It prevents you from modifying the dependencies, but allows you to inspect them (which is probably what you want when using the {@link FlowrAnalyzer}).
8
- * If you are a {@link FlowrAnalyzerPackageVersionsPlugin} and want to modify the dependencies, you can use the {@link FlowrAnalyzerDependenciesContext} directly.
6
+ * Read-only interface to the {@link FlowrAnalyzerDependenciesContext} for inspecting dependencies without modifying them.
9
7
  */
10
8
  export interface ReadOnlyFlowrAnalyzerDependenciesContext {
11
9
  /**
@@ -28,21 +26,31 @@ export interface ReadOnlyFlowrAnalyzerDependenciesContext {
28
26
  * Get all dependencies known to this context.
29
27
  */
30
28
  getDependencies(): readonly Readonly<Package>[];
29
+ /**
30
+ * Metadata of the package databases the version plugins currently have loaded.
31
+ */
32
+ loadedPackageDatabases(): PkgDbLoadedInfo[];
31
33
  }
32
34
  /**
33
- * This context is responsible for managing the dependencies of the project, including their versions and interplays with {@link FlowrAnalyzerPackageVersionsPlugin}s.
34
- *
35
- * If you are interested in inspecting these dependencies, refer to {@link ReadOnlyFlowrAnalyzerDependenciesContext}.
35
+ * Manages the project's dependencies, their versions, and their interplay with {@link FlowrAnalyzerPackageVersionsPlugin}s.
36
36
  */
37
37
  export declare class FlowrAnalyzerDependenciesContext extends AbstractFlowrAnalyzerContext<undefined, void, FlowrAnalyzerPackageVersionsPlugin> implements ReadOnlyFlowrAnalyzerDependenciesContext {
38
38
  readonly name = "flowr-analyzer-dependencies-context";
39
39
  readonly functionsContext: FlowrAnalyzerFunctionsContext;
40
40
  private dependencies;
41
41
  private staticsLoaded;
42
+ /** resolvers consulted lazily to fill in exports; `existing` carries version info from other plugins */
43
+ private lazyResolvers;
44
+ private resolvedMisses;
42
45
  reset(): void;
46
+ /** Register a resolver consulted by {@link getDependency} to fill in a package's exports lazily. */
47
+ addLazyResolver(resolver: (name: string, existing?: Package) => Package | undefined): void;
48
+ loadedPackageDatabases(): PkgDbLoadedInfo[];
49
+ /** Eagerly mount every version plugin's package database up front (see `solver.pkgdb.eagerlyLoad`). */
50
+ eagerlyLoadPackageDatabases(): void;
43
51
  constructor(functionsContext: FlowrAnalyzerFunctionsContext, plugins?: readonly FlowrAnalyzerPackageVersionsPlugin[]);
44
52
  resolveStaticDependencies(): void;
45
- addDependency(pkg: Package): void;
53
+ addDependency(pkg: Package): this;
46
54
  getDependency(name: string): Package | undefined;
47
55
  getDependencies(): Package[];
48
56
  }
@@ -4,18 +4,37 @@ exports.FlowrAnalyzerDependenciesContext = void 0;
4
4
  const abstract_flowr_analyzer_context_1 = require("./abstract-flowr-analyzer-context");
5
5
  const flowr_analyzer_package_versions_plugin_1 = require("../plugins/package-version-plugins/flowr-analyzer-package-versions-plugin");
6
6
  /**
7
- * This context is responsible for managing the dependencies of the project, including their versions and interplays with {@link FlowrAnalyzerPackageVersionsPlugin}s.
8
- *
9
- * If you are interested in inspecting these dependencies, refer to {@link ReadOnlyFlowrAnalyzerDependenciesContext}.
7
+ * Manages the project's dependencies, their versions, and their interplay with {@link FlowrAnalyzerPackageVersionsPlugin}s.
10
8
  */
11
9
  class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1.AbstractFlowrAnalyzerContext {
12
10
  name = 'flowr-analyzer-dependencies-context';
13
11
  functionsContext;
14
12
  dependencies = new Map();
15
13
  staticsLoaded = false;
14
+ /** resolvers consulted lazily to fill in exports; `existing` carries version info from other plugins */
15
+ lazyResolvers = [];
16
+ resolvedMisses = new Set();
16
17
  reset() {
17
18
  this.dependencies = new Map();
18
19
  this.staticsLoaded = false;
20
+ this.lazyResolvers = [];
21
+ this.resolvedMisses = new Set();
22
+ }
23
+ /** Register a resolver consulted by {@link getDependency} to fill in a package's exports lazily. */
24
+ addLazyResolver(resolver) {
25
+ this.lazyResolvers.push(resolver);
26
+ }
27
+ loadedPackageDatabases() {
28
+ if (!this.ctx.config.solver.pkgdb.enabled) {
29
+ return [];
30
+ }
31
+ return this.plugins.flatMap(p => p.loadedDatabases());
32
+ }
33
+ /** Eagerly mount every version plugin's package database up front (see `solver.pkgdb.eagerlyLoad`). */
34
+ eagerlyLoadPackageDatabases() {
35
+ for (const p of this.plugins) {
36
+ p.preloadDatabasesSync();
37
+ }
19
38
  }
20
39
  constructor(functionsContext, plugins) {
21
40
  super(functionsContext.getAttachedContext(), flowr_analyzer_package_versions_plugin_1.FlowrAnalyzerPackageVersionsPlugin.defaultPlugin(), plugins);
@@ -33,12 +52,28 @@ class FlowrAnalyzerDependenciesContext extends abstract_flowr_analyzer_context_1
33
52
  else {
34
53
  this.dependencies.set(pkg.name, pkg);
35
54
  }
55
+ return this;
36
56
  }
37
57
  getDependency(name) {
38
58
  if (!this.staticsLoaded) {
39
59
  this.resolveStaticDependencies();
40
60
  }
41
- return this.dependencies.get(name);
61
+ const existing = this.dependencies.get(name);
62
+ // a package already carrying exports is complete; a version-only one is still enriched below
63
+ if (existing?.namespaceInfo || (!existing && this.resolvedMisses.has(name))) {
64
+ return existing;
65
+ }
66
+ if (!this.resolvedMisses.has(name)) {
67
+ for (const resolve of this.lazyResolvers) {
68
+ const resolved = resolve(name, existing);
69
+ if (resolved) {
70
+ this.addDependency(resolved); // merges exports into any existing version info
71
+ return this.dependencies.get(name);
72
+ }
73
+ }
74
+ this.resolvedMisses.add(name);
75
+ }
76
+ return existing;
42
77
  }
43
78
  getDependencies() {
44
79
  if (!this.staticsLoaded) {
@@ -3,8 +3,7 @@ import type { IEnvironment, REnvironmentInformation } from '../../dataflow/envir
3
3
  import type { DeepReadonly } from 'ts-essentials';
4
4
  import type { Fingerprint } from '../../slicing/static/fingerprint';
5
5
  /**
6
- * This is the read-only interface to the {@link FlowrAnalyzerEnvironmentContext},
7
- * which provides access to the built-in environment used during analysis.
6
+ * Read-only interface to the {@link FlowrAnalyzerEnvironmentContext}.
8
7
  */
9
8
  export interface ReadOnlyFlowrAnalyzerEnvironmentContext {
10
9
  /**
@@ -34,8 +33,7 @@ export interface ReadOnlyFlowrAnalyzerEnvironmentContext {
34
33
  makeEmptyEnv(): REnvironmentInformation;
35
34
  }
36
35
  /**
37
- * This context is responsible for providing the built-in environment.
38
- * It creates the built-in environment based on the configuration provided in the {@link FlowrAnalyzerContext}.
36
+ * Provides the built-in environment, created from the {@link FlowrAnalyzerContext} configuration.
39
37
  */
40
38
  export declare class FlowrAnalyzerEnvironmentContext implements ReadOnlyFlowrAnalyzerEnvironmentContext {
41
39
  readonly name = "flowr-analyzer-environment-context";