@eagleoutice/flowr 2.15.9 → 2.16.0

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 (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UNUSED_DEFINITION = void 0;
4
+ exports.collectCalledNames = collectCalledNames;
5
+ exports.isS3MethodName = isS3MethodName;
4
6
  const linter_format_1 = require("../linter-format");
5
7
  const function_semantics_1 = require("../../dataflow/fn/function-semantics");
6
8
  const flowr_search_builder_1 = require("../../search/flowr-search-builder");
7
9
  const range_1 = require("../../util/range");
8
10
  const linter_tags_1 = require("../linter-tags");
9
- const assert_1 = require("../../util/assert");
11
+ const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
10
12
  const vertex_1 = require("../../dataflow/graph/vertex");
11
13
  const edge_1 = require("../../dataflow/graph/edge");
12
14
  const flowr_search_filters_1 = require("../../search/flowr-search-filters");
@@ -23,6 +25,7 @@ const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-
23
25
  const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
24
26
  const r_parameter_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
25
27
  const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
28
+ const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
26
29
  /**
27
30
  * The dots parameter is a special parameter and must never be reported as an unused definition.
28
31
  */
@@ -57,57 +60,37 @@ const PackageHookFunctions = new Set([
57
60
  ]);
58
61
  /** Gathers the analyzed project's own `NAMESPACE` exports and declared S3 generics (empty when it is not a package). */
59
62
  function collectPackageInfo(data) {
60
- const exported = new Set();
61
- const s3Generics = new Set();
62
- for (const ns of data.inspectContext().files.getFilesByRole(flowr_file_1.FileRole.Namespace)) {
63
- const info = ns.content().current;
64
- for (const name of (0, flowr_namespace_file_1.getExportedNames)(info)) {
65
- exported.add(name);
66
- }
67
- for (const generic of info.exportS3Generics.keys()) {
68
- s3Generics.add(generic);
69
- }
70
- }
71
- return { exported, s3Generics };
63
+ const namespaces = data.inspectContext().files.getFilesByRole(flowr_file_1.FileRole.Namespace).map(ns => ns.content().current);
64
+ return {
65
+ exported: new Set(namespaces.flatMap(flowr_namespace_file_1.getExportedNames)),
66
+ s3Generics: new Set(namespaces.flatMap(info => [...info.exportS3Generics.keys()]))
67
+ };
72
68
  }
73
69
  /** Collects the names of every function call in the graph, so we can tell whether an S3 generic is dispatched anywhere. */
74
70
  function collectCalledNames(dfg) {
75
- const names = new Set();
76
- for (const [, vertex] of dfg.verticesOfType(vertex_1.VertexType.FunctionCall)) {
77
- names.add(identifier_1.Identifier.getName(vertex.name));
78
- }
79
- return names;
71
+ return new Set(dfg.verticesOfType(vertex_1.VertexType.FunctionCall).map(([, vertex]) => identifier_1.Identifier.getName(vertex.name)));
80
72
  }
81
73
  /** S3 (`UseMethod`) and S4/S7 (`standardGeneric`) generic dispatchers, invoked indirectly by R's dispatch. */
82
74
  const GenericDispatchers = new Set(['UseMethod', 'standardGeneric']);
83
75
  /** Whether a function body is a single call to a generic dispatcher. */
84
76
  function isGenericDispatcherOnlyBody(node) {
85
- if (r_function_call_1.RFunctionCall.isNamed(node) && GenericDispatchers.has(identifier_1.Identifier.getName(node.functionName.content))) {
86
- return true;
87
- }
88
- const nodeWithChildren = node;
89
- if (Array.isArray(nodeWithChildren.children) && nodeWithChildren.children.length === 1) {
90
- const child = nodeWithChildren.children[0];
91
- if (child && r_function_call_1.RFunctionCall.isNamed(child) && GenericDispatchers.has(identifier_1.Identifier.getName(child.functionName.content))) {
92
- return true;
93
- }
94
- }
95
- return false;
77
+ const isDispatcherCall = (n) => r_function_call_1.RFunctionCall.isNamed(n) && GenericDispatchers.has(identifier_1.Identifier.getName(n.functionName.content));
78
+ return isDispatcherCall(node) || (r_expression_list_1.RExpressionList.is(node) && node.children.length === 1 && isDispatcherCall(node.children[0]));
96
79
  }
97
- /** Collects the parameter IDs of generic dispatcher functions. */
80
+ /** Collects the parameter IDs of generic dispatcher functions, which hand them on to their methods. */
98
81
  function collectS3GenericParameterIds(ast) {
99
- const paramIds = new Set();
100
- for (const [, node] of ast.idMap) {
101
- if (!r_function_definition_1.RFunctionDefinition.is(node)) {
102
- continue;
103
- }
104
- if (isGenericDispatcherOnlyBody(node.body)) {
105
- for (const param of node.parameters) {
106
- paramIds.add(param.name.info.id);
107
- }
82
+ return new Set(ast.idMap.values().flatMap(node => r_function_definition_1.RFunctionDefinition.is(node) && isGenericDispatcherOnlyBody(node.body) ? node.parameters.map(param => param.name.info.id) : []));
83
+ }
84
+ /** Whether `name` reads as `generic.class` for a generic that is known, declared, or called, so R dispatches to it by that name. */
85
+ function isS3MethodName(name, ctx, called, declared = new Set()) {
86
+ /* every dot may be the one splitting method from class, as the generic may carry dots itself (`as.character.foo`) */
87
+ for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
88
+ const generic = name.slice(0, dot);
89
+ if (ctx.env.deriveFromIndex(knownS3Generics).has(generic) || declared.has(generic) || isDispatched(generic, called)) {
90
+ return true;
108
91
  }
109
92
  }
110
- return paramIds;
93
+ return false;
111
94
  }
112
95
  /**
113
96
  * A definition is treated as used (and hence not reported) if it is the dots parameter, a package lifecycle hook,
@@ -118,36 +101,19 @@ function isConsideredUsed(lexeme, config, pkg, called, ctx) {
118
101
  if (lexeme === undefined) {
119
102
  return false;
120
103
  }
121
- // non-syntactic definition names (e.g. S3 methods like `"[.irts"`) carry their R quotes or backticks in the lexeme
104
+ /* non-syntactic definition names (e.g. S3 methods like `"[.irts"`) carry their R quotes or backticks in the lexeme */
122
105
  const unquoted = (0, retriever_1.removeRQuotes)(lexeme);
123
106
  const name = unquoted.length > 1 && unquoted.startsWith('`') && unquoted.endsWith('`') ? unquoted.slice(1, -1) : unquoted;
124
- // the dots are a special parameter and must never be reported
125
- if (name === DotsParameter) {
126
- return true;
127
- }
128
- // package lifecycle hooks are called by R's package machinery
129
- if (PackageHookFunctions.has(name)) {
130
- return true;
131
- }
132
- // every dot may be the one splitting method from class, as the generic may carry dots itself (`as.character.foo`)
133
- for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
134
- const generic = name.slice(0, dot);
135
- if (ctx.env.deriveFromIndex(knownS3Generics).has(generic) || pkg.s3Generics.has(generic) || isDispatched(generic, called)) {
136
- return true;
137
- }
138
- }
139
- if (config.excludeExportedDefinitions && pkg.exported.has(name)) {
107
+ /* the dots are a special parameter, and package lifecycle hooks are called by R's package machinery */
108
+ if (name === DotsParameter || PackageHookFunctions.has(name)) {
140
109
  return true;
141
110
  }
142
- return false;
111
+ return isS3MethodName(name, ctx, called, pkg.s3Generics) || (config.excludeExportedDefinitions && pkg.exported.has(name));
143
112
  }
144
113
  const InterestingEdgesVariable = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls | edge_1.EdgeType.DefinesOnCall;
145
- const InterestingEdgesFunction = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls; // include read as this could print the function definition
114
+ /* include read as this could print the function definition */
115
+ const InterestingEdgesFunction = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls;
146
116
  const InterestingEdgesTargets = edge_1.EdgeType.SideEffectOnCall;
147
- function getDefinitionArguments(def, dfg) {
148
- return dfg.outgoingEdges(def)?.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy))
149
- .map(([target]) => target).toArray() ?? [];
150
- }
151
117
  /**
152
118
  * Whether the node names a parameter of a function whose signature something outside the code fixes: a package
153
119
  * lifecycle hook R calls with a set of arguments, or an S3 method a generic dispatches to. Such a parameter is
@@ -155,20 +121,19 @@ function getDefinitionArguments(def, dfg) {
155
121
  */
156
122
  function hasContractedSignature(node, ast, config, pkg, called, ctx) {
157
123
  let inParameter = false;
158
- for (let up = node.info.parent; up !== undefined;) {
159
- const parent = ast.idMap.get(up);
160
- if (parent === undefined) {
161
- return false;
162
- }
124
+ for (const parent of model_1.RNode.iterateParents(node, ast.idMap)) {
163
125
  inParameter ||= r_parameter_1.RParameter.is(parent);
164
126
  if (r_function_definition_1.RFunctionDefinition.is(parent)) {
165
127
  /* the name the definition is bound under is what reaches it, so that is what the contract goes by */
166
- const bound = parent.info.parent !== undefined ? ast.idMap.get(parent.info.parent) : undefined;
128
+ const bound = model_1.RNode.directParent(parent, ast.idMap);
129
+ /* a function handed to a call is called by it, like a `tryCatch` handler or an `lapply` callback */
130
+ if (r_argument_1.RArgument.is(bound)) {
131
+ return inParameter;
132
+ }
167
133
  const name = r_binary_op_1.RBinaryOp.is(bound) ? bound.lhs.lexeme
168
134
  : r_function_call_1.RFunctionCall.is(bound) && bound.arguments[0] !== r_function_call_1.EmptyArgument ? bound.arguments[0]?.lexeme : undefined;
169
135
  return inParameter && name !== undefined && isConsideredUsed(name, config, pkg, called, ctx);
170
136
  }
171
- up = parent.info.parent;
172
137
  }
173
138
  return false;
174
139
  }
@@ -199,6 +164,17 @@ function getAssignmentPeer(node, ast) {
199
164
  }
200
165
  return undefined;
201
166
  }
167
+ function yieldsFunctionValue(node, ast, dfg) {
168
+ const path = new Set([node.info.id]);
169
+ for (const up of model_1.RNode.iterateParents(node, ast.idMap)) {
170
+ if (r_function_definition_1.RFunctionDefinition.is(up)) {
171
+ const fn = dfg.getVertex(up.info.id);
172
+ return vertex_1.DfgVertex.isFunctionDefinition(fn) && fn.exitPoints.some(e => path.has(e.nodeId));
173
+ }
174
+ path.add(up.info.id);
175
+ }
176
+ return false;
177
+ }
202
178
  function isStandaloneStatement(node, ast) {
203
179
  if (node.info.role !== "el-c" /* RoleInParent.ExpressionListChild */) {
204
180
  return false;
@@ -210,6 +186,13 @@ function isStandaloneStatement(node, ast) {
210
186
  const opening = r_expression_list_1.RExpressionList.groupStart(parent);
211
187
  return opening === undefined || opening.lexeme === '{';
212
188
  }
189
+ /** Whether the definition's value has obligations, like side effects, so the definition cannot be removed. */
190
+ function hasImportantArgs(definedBys, df, binds) {
191
+ const dfg = df.graph;
192
+ return definedBys.some(d => dfg.unknownSideEffects.has(d) || doesMoreThanCompute(d, df, binds)
193
+ || dfg.edgesTo(d).values().some(edge => edge_1.DfEdge.includesType(edge, InterestingEdgesTargets))
194
+ || dfg.edgesFrom(d).entries().some(([target, edge]) => edge_1.DfEdge.includesType(edge, InterestingEdgesTargets) || dfg.unknownSideEffects.has(target)));
195
+ }
213
196
  function buildQuickFix(variable, df, ast) {
214
197
  const dfg = df.graph;
215
198
  // first we check whether any of the 'Defined by' targets have any obligations - if so, we can not remove the definition
@@ -218,41 +201,27 @@ function buildQuickFix(variable, df, ast) {
218
201
  // this is an access or a for variable, we can not remove it currently
219
202
  return undefined;
220
203
  }
221
- const definedBys = getDefinitionArguments(variable.info.id, dfg);
222
- const hasImportantArgs = definedBys.some(d => dfg.unknownSideEffects.has(d) || doesMoreThanCompute(d, df, variable.info.parent))
223
- || definedBys.some(e => Array.from(dfg.edgesTo(e)).some(([, edge]) => edge_1.DfEdge.includesType(edge, InterestingEdgesTargets)))
224
- || definedBys.flatMap(e => Array.from(dfg.edgesFrom(e)))
225
- .some(([target, e]) => {
226
- return edge_1.DfEdge.includesType(e, InterestingEdgesTargets) || dfg.unknownSideEffects.has(target);
227
- });
228
- if (hasImportantArgs) {
229
- return undefined; // we can not remove this definition, it has important arguments
204
+ const definedBys = (0, frame_reflection_1.edgeTargets)(dfg, variable.info.id, edge_1.EdgeType.DefinedBy);
205
+ if (hasImportantArgs(definedBys, df, variable.info.parent)) {
206
+ return undefined;
230
207
  }
231
208
  const assignment = getAssignmentPeer(variable, ast);
232
- const totalRangeToRemove = range_1.SourceLocation.merge([...definedBys.map(d => {
233
- const vertex = ast.idMap.get(d);
234
- return vertex ? range_1.SourceLocation.fromNode(vertex) : undefined;
235
- }),
236
- assignment ? range_1.SourceLocation.fromNode(assignment.value) : undefined,
237
- variable.info.fullRange ?? variable.location]);
209
+ const totalRangeToRemove = range_1.SourceLocation.merge([
210
+ ...definedBys.map(d => range_1.SourceLocation.fromNode(ast.idMap.get(d))),
211
+ range_1.SourceLocation.fromNode(assignment?.value),
212
+ variable.info.fullRange ?? variable.location
213
+ ]);
238
214
  if (totalRangeToRemove === undefined) {
239
215
  /* a fix that names no place cannot be carried out, so none is offered */
240
216
  return undefined;
241
217
  }
242
218
  const description = `Remove unused definition of \`${variable.lexeme}\``;
243
- if (isStandaloneStatement(assignment?.statement ?? variable, ast)) {
244
- return [{ type: 'remove', loc: totalRangeToRemove, description }];
245
- }
246
- const replacement = assignment !== undefined ? assignment.value.info.fullLexeme ?? assignment.value.lexeme : undefined;
247
- if (replacement === undefined) {
248
- return undefined;
219
+ const statement = assignment?.statement ?? variable;
220
+ if (isStandaloneStatement(statement, ast)) {
221
+ return yieldsFunctionValue(statement, ast, dfg) ? undefined : [{ type: 'remove', loc: totalRangeToRemove, description }];
249
222
  }
250
- return [{
251
- type: 'replace',
252
- loc: totalRangeToRemove,
253
- replacement,
254
- description
255
- }];
223
+ const replacement = assignment?.value.info.fullLexeme ?? assignment?.value.lexeme;
224
+ return replacement === undefined ? undefined : [{ type: 'replace', loc: totalRangeToRemove, replacement, description }];
256
225
  }
257
226
  /**
258
227
  * consider `x <- function() ...` if we say `x` is unused and propose to remove everything, there should be no separate quick fix for the function definition
@@ -270,77 +239,68 @@ function onlyKeepSupersetOfUnused(elements) {
270
239
  /** Whether the node sits inside a promise, i.e. an argument default value or a `delayedAssign` body, which may never run. */
271
240
  function isWithinPromise(node, idMap) {
272
241
  let child = node;
273
- let parentId = node.info.parent;
274
- while (parentId !== undefined) {
275
- const parent = idMap.get(parentId);
276
- if (parent === undefined) {
277
- return false;
278
- }
279
- if (r_parameter_1.RParameter.is(parent) && parent.defaultValue?.info.id === child.info.id) {
280
- return true;
281
- }
282
- if (r_function_call_1.RFunctionCall.isNamed(parent) && identifier_1.Identifier.getName(parent.functionName.content) === 'delayedAssign') {
242
+ for (const parent of model_1.RNode.iterateParents(node, idMap)) {
243
+ if ((r_parameter_1.RParameter.is(parent) && parent.defaultValue?.info.id === child.info.id)
244
+ || (r_function_call_1.RFunctionCall.isNamed(parent) && identifier_1.Identifier.getName(parent.functionName.content) === 'delayedAssign')) {
283
245
  return true;
284
246
  }
285
247
  child = parent;
286
- parentId = parent.info.parent;
287
248
  }
288
249
  return false;
289
250
  }
290
251
  exports.UNUSED_DEFINITION = {
291
- /* this can be done better once we have types */
292
252
  createSearch: config => flowr_search_builder_1.Q.all().filter(config.includeFunctionDefinitions ? flowr_search_filters_1.F.or(vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition) : vertex_1.VertexType.VariableDefinition),
293
253
  processSearchResult: async (elements, config, data) => {
294
254
  const normalize = await data.normalize();
295
255
  const dataflow = await data.dataflow();
256
+ const graph = dataflow.graph;
257
+ const ctx = data.inspectContext();
296
258
  const packageInfo = collectPackageInfo(data);
297
- const calledNames = collectCalledNames(dataflow.graph);
259
+ const calledNames = collectCalledNames(graph);
298
260
  const s3GenericParams = collectS3GenericParameterIds(normalize);
299
261
  const metadata = {
300
262
  totalConsidered: 0
301
263
  };
264
+ const isUnused = (node) => {
265
+ if (isWithinPromise(node, normalize.idMap)) {
266
+ return false;
267
+ }
268
+ const vertex = graph.getVertex(node.info.id);
269
+ if (!vertex || (!vertex_1.DfgVertex.isVariableDefinition(vertex) && vertex_1.DfgVertex.isFunctionDefinition(vertex) && !config.includeFunctionDefinitions)) {
270
+ return false;
271
+ }
272
+ if (s3GenericParams.has(node.info.id)) {
273
+ return false;
274
+ }
275
+ // an anonymous dispatcher passed to setGeneric()/new_generic() runs on every dispatch, so it is used
276
+ if (vertex_1.DfgVertex.isFunctionDefinition(vertex) && r_function_definition_1.RFunctionDefinition.is(node) && isGenericDispatcherOnlyBody(node.body)) {
277
+ return false;
278
+ }
279
+ if (isConsideredUsed(node.lexeme, config, packageInfo, calledNames, ctx)) {
280
+ return false;
281
+ }
282
+ /* what calls a hook or dispatches to a method decides its parameters, so they are no more the
283
+ author's to drop than the name is: `print.foo` keeps the `x` the generic hands it */
284
+ if (hasContractedSignature(node, normalize, config, packageInfo, calledNames, ctx)) {
285
+ return false;
286
+ }
287
+ const interestedIn = vertex_1.DfgVertex.isVariableDefinition(vertex) ? InterestingEdgesVariable : InterestingEdgesFunction;
288
+ return !graph.edgesTo(vertex.id).values().some(e => edge_1.DfEdge.includesType(e, interestedIn));
289
+ };
302
290
  return {
303
- results: onlyKeepSupersetOfUnused(elements.getElements().flatMap(element => {
291
+ results: onlyKeepSupersetOfUnused(elements.getElements().flatMap(({ node }) => {
304
292
  metadata.totalConsidered++;
305
- if (isWithinPromise(element.node, normalize.idMap)) {
293
+ if (!isUnused(node)) {
306
294
  return [];
307
295
  }
308
- const dfgVertex = dataflow.graph.getVertex(element.node.info.id);
309
- if (!dfgVertex || (!vertex_1.DfgVertex.isVariableDefinition(dfgVertex)
310
- && vertex_1.DfgVertex.isFunctionDefinition(dfgVertex) && !config.includeFunctionDefinitions)) {
311
- return undefined;
312
- }
313
- if (s3GenericParams.has(element.node.info.id)) {
314
- return undefined;
315
- }
316
- // an anonymous dispatcher passed to setGeneric()/new_generic() runs on every dispatch, so it is used
317
- if (vertex_1.DfgVertex.isFunctionDefinition(dfgVertex) && r_function_definition_1.RFunctionDefinition.is(element.node) && isGenericDispatcherOnlyBody(element.node.body)) {
318
- return undefined;
319
- }
320
- if (isConsideredUsed(element.node.lexeme, config, packageInfo, calledNames, data.inspectContext())) {
321
- return undefined;
322
- }
323
- /* what calls a hook or dispatches to a method decides its parameters, so they are no more the
324
- author's to drop than the name is: `print.foo` keeps the `x` the generic hands it */
325
- if (hasContractedSignature(element.node, normalize, config, packageInfo, calledNames, data.inspectContext())) {
326
- return undefined;
327
- }
328
- const ingoingEdges = dataflow.graph.ingoingEdges(dfgVertex.id);
329
- const interestedIn = vertex_1.DfgVertex.isVariableDefinition(dfgVertex) ? InterestingEdgesVariable : InterestingEdgesFunction;
330
- const ingoingInteresting = ingoingEdges?.values().some(e => edge_1.DfEdge.includesType(e, interestedIn));
331
- if (ingoingInteresting) {
332
- return undefined;
333
- }
334
- // found an unused definition
335
- const variableName = element.node.lexeme;
336
296
  return [{
337
297
  certainty: linter_format_1.LintingResultCertainty.Uncertain,
338
- variableName,
339
- involvedId: element.node.info.id,
340
- loc: range_1.SourceLocation.fromNode(element.node) ?? range_1.SourceLocation.invalid(),
341
- quickFix: buildQuickFix(element.node, dataflow, normalize)
298
+ variableName: node.lexeme,
299
+ involvedId: node.info.id,
300
+ loc: range_1.SourceLocation.fromNode(node) ?? range_1.SourceLocation.invalid(),
301
+ quickFix: buildQuickFix(node, dataflow, normalize)
342
302
  }];
343
- }).filter(assert_1.isNotUndefined)),
303
+ })),
344
304
  '.meta': metadata
345
305
  };
346
306
  },
@@ -3,6 +3,7 @@ import type { MergeableRecord } from '../../util/objects';
3
3
  import { LintingRuleTag } from '../linter-tags';
4
4
  import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
5
5
  import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
6
+ import type { PackageSignatureSource } from '../../project/sigdb/reader';
6
7
  export interface UnusedImportResult extends LintingResult {
7
8
  /** the package the flagged call attaches */
8
9
  readonly package: string;
@@ -23,6 +24,8 @@ export interface UnusedImportMetadata extends MergeableRecord {
23
24
  /** the attaches reported as unused */
24
25
  totalUnused: number;
25
26
  }
27
+ /** The packages `name` imports from apart from base R, whose exports it may re-export. */
28
+ export declare function nonBaseImports(src: PackageSignatureSource, name: string, version?: string): string[];
26
29
  /**
27
30
  * Flags packages that are attached but never used, so dropping the `library`/`require` call would leave the code running
28
31
  * just the same. A package counts as used as soon as any call resolves into it or anything reads one of its exports.
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UNUSED_IMPORT = void 0;
4
+ exports.nonBaseImports = nonBaseImports;
4
5
  const linter_format_1 = require("../linter-format");
5
6
  const range_1 = require("../../util/range");
6
7
  const flowr_search_builder_1 = require("../../search/flowr-search-builder");
7
8
  const linter_tags_1 = require("../linter-tags");
8
9
  const df_helper_1 = require("../../dataflow/graph/df-helper");
10
+ const graph_1 = require("../../dataflow/graph/graph");
9
11
  const edge_1 = require("../../dataflow/graph/edge");
10
12
  const vertex_1 = require("../../dataflow/graph/vertex");
11
13
  const identifier_1 = require("../../dataflow/environments/identifier");
@@ -14,14 +16,11 @@ const search_enrichers_1 = require("../../search/search-executor/search-enricher
14
16
  const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
15
17
  const library_functions_1 = require("../../queries/catalog/dependencies-query/function-info/library-functions");
16
18
  const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
17
- /**
18
- * Whether the loader a `library`-category finding came from attaches the package, taken from the one place that
19
- * says so. A call this does not know attaches nothing either: `pkg::fn` is reported as a loader of `pkg` and is no
20
- * import of its own, and neither is whatever else may come to be reported here. Matching ignores the loader's own
21
- * namespace, so `base::require` is caught just as well as a bare `require`.
22
- */
23
- function attachesPackage(info) {
24
- return library_functions_1.LibraryFunctions.some(loader => loader.attaches && identifier_1.Identifier.matches(loader.name, info.functionName));
19
+ const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
20
+ const built_in_proc_name_1 = require("../../dataflow/environments/built-in-proc-name");
21
+ /** The packages `name` imports from apart from base R, whose exports it may re-export. */
22
+ function nonBaseImports(src, name, version) {
23
+ return src.dependencies(name, version)?.filter(d => d.type === 1 /* DepType.Imports */ && !src.isBaseR(d.name)).map(d => d.name) ?? [];
25
24
  }
26
25
  /** whether the call reaches no definition of the analyzed code itself */
27
26
  function isUnbound(graph, id) {
@@ -30,23 +29,18 @@ function isUnbound(graph, id) {
30
29
  }
31
30
  /** whether removing the call would empty a slot the syntax requires, as in an unbraced `if(c) library(x)` */
32
31
  function removalWouldBreakSyntax(node, idMap) {
33
- const parent = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
32
+ const parent = model_1.RNode.directParent(node, idMap);
34
33
  return r_expression_list_1.RExpressionList.isImplicit(parent) && parent.children.length === 1 && parent.info.role !== "root" /* RoleInParent.Root */;
35
34
  }
36
35
  /** whether anything reads out of the attach itself */
37
36
  function isReadFrom(graph, id) {
38
- for (const edge of (graph.edgesTo(id)).values()) {
39
- if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
40
- return true;
41
- }
42
- }
43
- return false;
37
+ return graph.edgesTo(id).values().some(edge => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads));
44
38
  }
45
39
  /**
46
40
  * Which of the `attachments` the program never makes use of. A call that resolves names its package outright;
47
41
  * one that does not bind yet (a call in a function body) keeps every attached package exporting its name.
48
42
  */
49
- function unusedPackages(attachments, graph) {
43
+ function unusedPackages(attachments, graph, src) {
50
44
  const pending = new Set(attachments.map(a => a.name));
51
45
  const unbound = new Set();
52
46
  for (const [id, qualified] of df_helper_1.Dataflow.qualifyAll(graph)) {
@@ -69,15 +63,10 @@ function unusedPackages(attachments, graph) {
69
63
  }
70
64
  }
71
65
  }
72
- for (const { name, callable } of attachments) {
73
- if (!pending.has(name)) {
74
- continue;
75
- }
76
- for (const call of unbound) {
77
- if (callable.has(call)) {
78
- pending.delete(name);
79
- break;
80
- }
66
+ for (const { name, callable, imports } of attachments) {
67
+ const usesPackage = (call) => callable.has(call) || src.packagesExporting(call).some(p => imports.has(p));
68
+ if (pending.has(name) && unbound.values().some(usesPackage)) {
69
+ pending.delete(name);
81
70
  }
82
71
  }
83
72
  return pending;
@@ -99,31 +88,21 @@ exports.UNUSED_IMPORT = {
99
88
  return { results: [], '.meta': metadata };
100
89
  }
101
90
  const whitelist = new Set(config.whitelist);
102
- // one call may name more than one package, so the query can report it several times under the same id
103
- const attachedBy = new Map();
104
- for (const info of elements.enrichmentContent(search_enrichers_1.Enrichment.QueryData).queries['dependencies'].library) {
105
- if (info.nodeId === undefined) {
106
- continue;
107
- }
108
- const known = attachedBy.get(info.nodeId);
109
- if (known === undefined) {
110
- attachedBy.set(info.nodeId, [info]);
111
- }
112
- else {
113
- known.push(info);
114
- }
115
- }
91
+ const src = deps.signatures().sources();
92
+ /* one call may name more than one package, so the query can report it several times under the same id */
93
+ const libraryInfos = elements.enrichmentContent(search_enrichers_1.Enrichment.QueryData).queries['dependencies'].library;
94
+ const attachedBy = Map.groupBy(libraryInfos.filter(info => info.nodeId !== undefined), info => info.nodeId);
116
95
  const attachments = [];
117
96
  const seen = new Set();
118
97
  for (const { node } of elements.getElements()) {
119
98
  const infos = attachedBy.get(node.info.id);
120
- if (infos === undefined || seen.has(node.info.id) || !attachesPackage(infos[0])) {
99
+ if (infos === undefined || seen.has(node.info.id) || !(0, library_functions_1.attachesPackage)(infos[0])) {
121
100
  continue;
122
101
  }
123
102
  seen.add(node.info.id);
124
103
  metadata.totalConsidered++;
125
104
  if (infos.length > 1) {
126
- // a dynamic attach, e.g. `for(p in pkgs) library(p, character.only = TRUE)`; naming one of them would be a guess
105
+ /* a dynamic attach, e.g. `for(p in pkgs) library(p, character.only = TRUE)`; naming one of them would be a guess */
127
106
  metadata.totalMultiPackage++;
128
107
  continue;
129
108
  }
@@ -150,7 +129,8 @@ exports.UNUSED_IMPORT = {
150
129
  loc,
151
130
  name,
152
131
  version: pkg.resolvedVersion,
153
- callable: new Set(pkg.namespaceInfo?.callable)
132
+ callable: new Set(pkg.namespaceInfo?.callable),
133
+ imports: new Set(nonBaseImports(src, name, pkg.resolvedVersion))
154
134
  });
155
135
  }
156
136
  if (attachments.length === 0) {
@@ -158,7 +138,9 @@ exports.UNUSED_IMPORT = {
158
138
  }
159
139
  const { graph } = await data.dataflow();
160
140
  const idMap = (await data.normalize()).idMap;
161
- const unused = unusedPackages(attachments, graph);
141
+ /* code a `source()` flowR could not resolve runs as well and may use any attached package */
142
+ const unseen = graph.unknownSideEffects.values().some(e => vertex_1.DfgVertex.hasOrigin(graph.getVertex(graph_1.UnknownSideEffect.id(e)), built_in_proc_name_1.BuiltInProcName.Source));
143
+ const unused = unseen ? new Set() : unusedPackages(attachments, graph, src);
162
144
  const results = attachments.filter(({ id, name }) => unused.has(name) && !isReadFrom(graph, id)).map(({ id, node, loc, name, version }) => ({
163
145
  certainty: linter_format_1.LintingResultCertainty.Uncertain,
164
146
  involvedId: id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.15.9",
3
+ "version": "2.16.0",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -26,7 +26,10 @@
26
26
  "author": "Florian Sihler",
27
27
  "license": "ISC",
28
28
  "overrides": {
29
- "lodash.isequal": "npm:fast-deep-equal@^3.1.3"
29
+ "lodash.isequal": "npm:fast-deep-equal@^3.1.3",
30
+ "get-uri": {
31
+ "basic-ftp": "6.2.3"
32
+ }
30
33
  },
31
34
  "dependencies": {
32
35
  "@davisvaughan/tree-sitter-r": "^1.2.0",
@@ -195,6 +195,8 @@ export declare class FlowrAnalyzer<Parser extends KnownParser = KnownParser> imp
195
195
  private readonly cache;
196
196
  private readonly ctx;
197
197
  private parserInfo;
198
+ /** the graph whose calls are already being qualified in the background, see {@link qualifyInBackground} */
199
+ private qualifying;
198
200
  /**
199
201
  * Create a new analyzer instance.
200
202
  * **Prefer the use of the {@link FlowrAnalyzerBuilder} instead of calling this constructor directly.**
@@ -8,6 +8,8 @@ const retriever_1 = require("../r-bridge/retriever");
8
8
  const files_1 = require("../util/files");
9
9
  const tree_sitter_normalize_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize");
10
10
  const tree_sitter_executor_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-executor");
11
+ const vertex_1 = require("../dataflow/graph/vertex");
12
+ const df_helper_1 = require("../dataflow/graph/df-helper");
11
13
  /**
12
14
  * Central class for conducting analyses with FlowR.
13
15
  * Use the {@link FlowrAnalyzerBuilder} to create a new instance.
@@ -24,6 +26,8 @@ class FlowrAnalyzer {
24
26
  cache;
25
27
  ctx;
26
28
  parserInfo;
29
+ /** the graph whose calls are already being qualified in the background, see {@link qualifyInBackground} */
30
+ qualifying;
27
31
  /**
28
32
  * Create a new analyzer instance.
29
33
  * **Prefer the use of the {@link FlowrAnalyzerBuilder} instead of calling this constructor directly.**
@@ -133,7 +137,12 @@ class FlowrAnalyzer {
133
137
  return this.cache.peekNormalize();
134
138
  }
135
139
  async dataflow(force) {
136
- return this.cache.dataflow(force);
140
+ const dataflow = await this.cache.dataflow(force);
141
+ if (this.qualifying !== dataflow.graph) {
142
+ this.qualifying = dataflow.graph;
143
+ qualifyInBackground(dataflow.graph);
144
+ }
145
+ return dataflow;
137
146
  }
138
147
  peekDataflow() {
139
148
  return this.cache.peekDataflow();
@@ -170,4 +179,22 @@ class FlowrAnalyzer {
170
179
  }
171
180
  }
172
181
  exports.FlowrAnalyzer = FlowrAnalyzer;
182
+ /** Qualifies calls (see {@link Dataflow.qualify}) in idle time on unreferenced timers, so later queries find it done. */
183
+ function qualifyInBackground(graph) {
184
+ const calls = Array.from(graph.verticesOfType(vertex_1.VertexType.FunctionCall), ([id]) => id);
185
+ let next = 0;
186
+ const step = () => {
187
+ for (const end = Math.min(next + 256, calls.length); next < end; next++) {
188
+ df_helper_1.Dataflow.qualify(calls[next], graph, false);
189
+ }
190
+ if (next < calls.length) {
191
+ later(step);
192
+ }
193
+ };
194
+ later(step);
195
+ }
196
+ /** an unreferenced timer where there are such (node), a plain one elsewhere (the browser returns a number) */
197
+ function later(step) {
198
+ setTimeout(step, 0).unref?.();
199
+ }
173
200
  //# sourceMappingURL=flowr-analyzer.js.map
@@ -8,9 +8,9 @@ export declare class FlowrJupyterFile extends FlowrFile {
8
8
  private readonly wrapped;
9
9
  /**
10
10
  * Prefer the static {@link FlowrJupyterFile.from} method
11
- * @param file - the file to load as Jupyter
11
+ * @param wrapped - the file to load as Jupyter
12
12
  */
13
- constructor(file: FlowrFileProvider<string>);
13
+ constructor(wrapped: FlowrFileProvider<string>);
14
14
  /**
15
15
  * Loads and parses the content of the wrapped file.
16
16
  * @returns RmdInfo