@eagleoutice/flowr 2.13.13 → 2.13.15

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 (186) hide show
  1. package/README.md +31 -28
  2. package/abstract-interpretation/data-frame/resolve-args.js +11 -12
  3. package/benchmark/calibration.d.ts +18 -0
  4. package/benchmark/calibration.js +63 -0
  5. package/benchmark/slicer.d.ts +19 -0
  6. package/benchmark/slicer.js +84 -1
  7. package/benchmark/stats/feature-counts.d.ts +6 -0
  8. package/benchmark/stats/feature-counts.js +61 -0
  9. package/benchmark/stats/print.js +20 -0
  10. package/benchmark/stats/sigdb-counts.d.ts +7 -0
  11. package/benchmark/stats/sigdb-counts.js +219 -0
  12. package/benchmark/stats/size-of.d.ts +6 -0
  13. package/benchmark/stats/size-of.js +8 -0
  14. package/benchmark/stats/stats.d.ts +79 -0
  15. package/benchmark/stats/stats.js +7 -1
  16. package/benchmark/stopwatch.d.ts +4 -0
  17. package/benchmark/stopwatch.js +12 -1
  18. package/benchmark/summarizer/data.d.ts +17 -1
  19. package/benchmark/summarizer/first-phase/input.js +5 -0
  20. package/benchmark/summarizer/first-phase/process.js +12 -2
  21. package/benchmark/summarizer/second-phase/graph.d.ts +24 -1
  22. package/benchmark/summarizer/second-phase/graph.js +249 -18
  23. package/benchmark/summarizer/second-phase/process.js +56 -0
  24. package/benchmark/summarizer/summarizer.js +1 -2
  25. package/cli/benchmark-app.d.ts +1 -0
  26. package/cli/benchmark-app.js +2 -1
  27. package/cli/benchmark-helper-app.d.ts +1 -0
  28. package/cli/benchmark-helper-app.js +12 -2
  29. package/cli/common/options.d.ts +10 -0
  30. package/cli/common/options.js +3 -1
  31. package/cli/common/scripts-info.d.ts +10 -0
  32. package/cli/repl/commands/repl-cfg.js +2 -42
  33. package/cli/repl/commands/repl-clipboard.d.ts +7 -0
  34. package/cli/repl/commands/repl-clipboard.js +53 -0
  35. package/cli/repl/commands/repl-dataflow.js +5 -70
  36. package/cli/repl/commands/repl-normalize.js +3 -51
  37. package/control-flow/cfg-builder.d.ts +30 -0
  38. package/control-flow/cfg-builder.js +79 -0
  39. package/control-flow/cfg-dead-code.js +5 -29
  40. package/control-flow/diff-cfg.js +2 -56
  41. package/control-flow/extract-cfg.js +17 -10
  42. package/control-flow/semantic-cfg-guided-visitor.d.ts +7 -0
  43. package/control-flow/semantic-cfg-guided-visitor.js +14 -0
  44. package/control-flow/useless-loop.js +4 -26
  45. package/core/steps/all/core/10-normalize.d.ts +8 -0
  46. package/core/steps/all/core/10-normalize.js +10 -8
  47. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +5 -7
  48. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -9
  49. package/data/r-base-packages.generated.d.ts +1 -0
  50. package/data/r-base-packages.generated.js +5 -3
  51. package/dataflow/environments/apply-kill.d.ts +3 -3
  52. package/dataflow/environments/apply-kill.js +60 -31
  53. package/dataflow/environments/built-in-config.d.ts +9 -1
  54. package/dataflow/environments/built-in-proc-name.d.ts +2 -0
  55. package/dataflow/environments/built-in-proc-name.js +2 -0
  56. package/dataflow/environments/built-in-props.d.ts +4 -0
  57. package/dataflow/environments/built-in-props.js +3 -3
  58. package/dataflow/environments/built-in.d.ts +4 -2
  59. package/dataflow/environments/built-in.js +53 -3
  60. package/dataflow/environments/data-masking-functions.d.ts +3 -4
  61. package/dataflow/environments/data-masking-functions.js +7 -8
  62. package/dataflow/environments/default-builtin-config.d.ts +92 -12
  63. package/dataflow/environments/default-builtin-config.js +86 -43
  64. package/dataflow/environments/environment.d.ts +5 -0
  65. package/dataflow/environments/environment.js +17 -12
  66. package/dataflow/environments/identifier.d.ts +3 -0
  67. package/dataflow/environments/reference-to-maybe.d.ts +5 -3
  68. package/dataflow/environments/reference-to-maybe.js +17 -52
  69. package/dataflow/environments/resolve-helper.d.ts +2 -1
  70. package/dataflow/environments/resolve-helper.js +2 -1
  71. package/dataflow/eval/resolve/alias-tracking.js +4 -7
  72. package/dataflow/eval/resolve/node-value.d.ts +51 -0
  73. package/dataflow/eval/resolve/node-value.js +71 -0
  74. package/dataflow/eval/resolve/resolve-argument.js +10 -7
  75. package/dataflow/eval/resolve/resolve-operators.js +1 -2
  76. package/dataflow/eval/values/general.d.ts +4 -0
  77. package/dataflow/eval/values/general.js +11 -0
  78. package/dataflow/eval/values/r-value.d.ts +15 -0
  79. package/dataflow/eval/values/r-value.js +27 -1
  80. package/dataflow/extractor.js +2 -0
  81. package/dataflow/fn/higher-order-function.js +2 -3
  82. package/dataflow/graph/df-helper.d.ts +2 -1
  83. package/dataflow/graph/diff-dataflow-graph.js +3 -55
  84. package/dataflow/graph/graph.d.ts +5 -0
  85. package/dataflow/graph/graph.js +27 -0
  86. package/dataflow/info.d.ts +7 -1
  87. package/dataflow/info.js +36 -7
  88. package/dataflow/internal/linker.d.ts +23 -0
  89. package/dataflow/internal/linker.js +70 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +4 -1
  91. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +2 -0
  92. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -29
  93. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +39 -6
  94. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +10 -22
  95. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +29 -53
  96. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +33 -10
  97. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -1
  98. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -5
  99. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -7
  100. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -3
  101. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +6 -2
  102. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +19 -12
  103. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +2 -1
  104. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +3 -0
  105. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +69 -52
  106. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
  107. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +2 -8
  108. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
  109. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +7 -2
  110. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +2 -8
  111. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +2 -2
  112. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +2 -2
  113. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +5 -0
  114. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +23 -3
  115. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.d.ts +5 -4
  116. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +7 -10
  117. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +6 -1
  118. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +20 -3
  119. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -8
  120. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +25 -0
  121. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +105 -0
  122. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +9 -28
  123. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +4 -5
  124. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +1 -1
  125. package/dataflow/internal/process/functions/call/deferred.d.ts +41 -0
  126. package/dataflow/internal/process/functions/call/deferred.js +127 -0
  127. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +13 -12
  128. package/dataflow/internal/process/functions/call/known-call-handling.js +35 -35
  129. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
  130. package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
  131. package/dataflow/internal/process/functions/call/nse.d.ts +28 -0
  132. package/dataflow/internal/process/functions/call/nse.js +87 -0
  133. package/dataflow/internal/process/functions/call/quoted.d.ts +29 -0
  134. package/dataflow/internal/process/functions/call/quoted.js +188 -0
  135. package/documentation/doc-readme.js +5 -2
  136. package/documentation/doc-util/doc-issue.d.ts +2 -0
  137. package/documentation/doc-util/doc-issue.js +3 -1
  138. package/documentation/doc-util/doc-types.js +15 -9
  139. package/documentation/wiki-dataflow-graph.js +4 -0
  140. package/documentation/wiki-faq.js +6 -2
  141. package/documentation/wiki-onboarding.js +11 -1
  142. package/documentation/wiki-setup.js +2 -1
  143. package/linter/rules/deprecated-functions.js +9 -3
  144. package/linter/rules/seeded-randomness.js +2 -3
  145. package/linter/rules/undefined-symbol.js +10 -1
  146. package/package.json +9 -4
  147. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +6 -0
  148. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +17 -1
  149. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.d.ts +2 -11
  150. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.js +3 -15
  151. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +16 -0
  152. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +26 -0
  153. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +2 -11
  154. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +3 -15
  155. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin.js +4 -10
  156. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +2 -9
  157. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +2 -9
  158. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +1 -1
  159. package/project/sigdb/reader.d.ts +9 -0
  160. package/project/sigdb/reader.js +30 -0
  161. package/queries/catalog/input-sources-query/input-sources-query-format.js +1 -1
  162. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.d.ts +0 -12
  163. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -37
  164. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -23
  165. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +2 -2
  166. package/queries/query-function-filter.d.ts +21 -0
  167. package/queries/query-function-filter.js +48 -0
  168. package/r-bridge/data/data.d.ts +13 -3
  169. package/r-bridge/data/data.js +15 -3
  170. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +2 -0
  171. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +4 -0
  172. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -9
  173. package/search/flowr-search-filters.d.ts +5 -1
  174. package/search/flowr-search-filters.js +31 -21
  175. package/search/search-executor/search-enrichers.d.ts +24 -4
  176. package/search/search-executor/search-enrichers.js +22 -9
  177. package/search/search-executor/search-transformer.js +1 -1
  178. package/slicing/static/slice-call.js +4 -4
  179. package/util/diff-graph.d.ts +13 -0
  180. package/util/diff-graph.js +64 -1
  181. package/util/files.js +9 -8
  182. package/util/node-version.d.ts +4 -0
  183. package/util/node-version.js +29 -0
  184. package/util/r-base-packages.d.ts +2 -0
  185. package/util/r-base-packages.js +3 -1
  186. package/util/version.js +1 -1
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryFunctionFilter = void 0;
4
+ const parse_1 = require("../slicing/criterion/parse");
5
+ const vertex_1 = require("../dataflow/graph/vertex");
6
+ /**
7
+ * Resolves the function filter shared by the inspection queries (`inspect-*`).
8
+ */
9
+ exports.QueryFunctionFilter = {
10
+ name: 'QueryFunctionFilter',
11
+ /** The ids the given queries restrict themselves to; empty if at least one query wants all functions. */
12
+ async criteria(queries, analyzer) {
13
+ let filters = undefined;
14
+ // filter will remain undefined if at least one of the queries wants all functions
15
+ for (const q of queries) {
16
+ if (q.filter === undefined) {
17
+ filters = undefined;
18
+ break;
19
+ }
20
+ else {
21
+ filters ??= [];
22
+ filters = filters.concat(q.filter);
23
+ }
24
+ }
25
+ const ast = await analyzer.normalize();
26
+ const filterFor = new Set();
27
+ if (filters) {
28
+ for (const f of filters) {
29
+ const i = parse_1.SlicingCriterion.tryParse(f, ast.idMap);
30
+ if (i !== undefined) {
31
+ filterFor.add(i);
32
+ }
33
+ }
34
+ }
35
+ return filterFor;
36
+ },
37
+ /** The call graph together with the functions the given queries want to inspect. */
38
+ async inCallGraph(queries, analyzer, onlyDefinitions = true) {
39
+ const filterFor = await exports.QueryFunctionFilter.criteria(queries, analyzer);
40
+ const cg = await analyzer.callGraph();
41
+ let fns = (onlyDefinitions || filterFor.size === 0 ? cg.verticesOfType(vertex_1.VertexType.FunctionDefinition) : cg.vertices(true));
42
+ if (filterFor.size > 0) {
43
+ fns = fns.filter(([id]) => filterFor.has(id));
44
+ }
45
+ return { cg, fns };
46
+ }
47
+ };
48
+ //# sourceMappingURL=query-function-filter.js.map
@@ -435,7 +435,7 @@ export declare const flowrCapabilities: {
435
435
  readonly name: "Promises";
436
436
  readonly id: "formals-promises";
437
437
  readonly supported: "partially";
438
- readonly description: "_Handle `function(x = y) { y <- 3; x }`, `function(x = { x <- 3; x}) { x * x }`, ..._ We _try_ to identify promises correctly but this is really rudimentary.";
438
+ readonly description: "_Handle `function(x = y) { y <- 3; x }`, `function(x = { x <- 3; x}) { x * x }`, ..._ A default argument resolves in the function's own environment and an argument passed in resolves in the caller's, both as R does it. We do not model _when_ a promise is forced: a `delayedAssign`ed expression is linked to every binding it may be forced against, which never misses the one that feeds it but may name others as well. What forcing _does_ is not modelled either, so the writes a promise performs when it is forced (`delayedAssign(\"x\", { x <- 99; 2 })`, where reading `x` yields `2` and leaves `x` at `99`) do not reach the reads that follow.";
439
439
  }];
440
440
  }, {
441
441
  readonly name: "Implicit Return";
@@ -498,12 +498,17 @@ export declare const flowrCapabilities: {
498
498
  readonly name: "Quoting";
499
499
  readonly id: "built-in-quoting";
500
500
  readonly supported: "partially";
501
- readonly description: "_Handle `quote`, `substitute`, `bquote`, ..._ We partially ignore some of them but most likely not all.";
501
+ readonly description: "_Handle `quote`, `substitute`, `bquote`, ..._ A quoted argument is marked as [non-standard evaluation](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph#non-standard-evaluation) as a whole, so nothing within it counts as read. We model the escapes back to standard evaluation that a quoting function offers: rlang's `!!`/`!!!` (in `expr`, `quo`, `enquo`, ... and in data-masking arguments) and `bquote`'s `.()`. Base `quote`/`substitute` have no such escape, and `substitute` does not reach the caller's expression when used on a function argument.";
502
502
  }, {
503
503
  readonly name: "Evaluation";
504
504
  readonly id: "built-in-evaluation";
505
505
  readonly supported: "partially";
506
- readonly description: "_Handle `eval`, `evalq`, `eval.parent`, ..._ We do not handle them at all.";
506
+ readonly description: "_Handle `eval`, `evalq`, `eval.parent`, ..._ `eval` of a string we can resolve is analyzed as if it were written in its place. A language object reaches the `eval` that forces it even across assignments, branches, loop iterations, and function calls, and its names resolve in the scope evaluating it, as R does. `eval(expr, envir)` runs elsewhere, so we mark the call as an unknown side effect instead of guessing. `evalq` quotes its first argument and we do not follow it into the given environment.";
507
+ }, {
508
+ readonly name: "String Templates";
509
+ readonly id: "string-templates";
510
+ readonly supported: "partially";
511
+ readonly description: "_Handle `glue::glue(\"{x}\")`, `cli::cli_alert_info(\"{.val {x}}\")`, `stringr::str_glue`/`str_interp`, ..._ The `{...}` of a template carries R code that runs where the call is, so we analyze it as if it were written there: it reads, it writes, and its side effects land in the calling scope. Doubled delimiters escape, `.open`/`.close` are honored when they are literal, and cli markup (`{.cls ...}`) contributes only the interpolations nested in it. A template aimed at another scope (`.envir`, `.con`, `glue_data`) is marked as an unknown side effect instead.";
507
512
  }, {
508
513
  readonly name: "Parsing";
509
514
  readonly id: "built-in-parsing";
@@ -552,6 +557,11 @@ export declare const flowrCapabilities: {
552
557
  readonly name: "Non-Standard Evaluations/Semantics";
553
558
  readonly id: "non-standard-evaluations-semantics";
554
559
  readonly capabilities: readonly [{
560
+ readonly name: "Data Masking";
561
+ readonly id: "data-masking";
562
+ readonly supported: "partially";
563
+ readonly description: "_Handle `subset(d, col > 1)`, dplyr verbs, `ggplot2::aes`, data.table `:=`, ..._ In a masked argument, a name the caller binds is read as that variable and any other name is taken to come from the data. Which names a data frame actually offers is unknown to us, so a column shadowing a variable of the same name still resolves to the variable. rlang's `!!`/`!!!` and its `:=` name-value pair are recognised; `[` on a `data.table` does not mask its `j`/`by` yet.";
564
+ }, {
555
565
  readonly name: "Recycling";
556
566
  readonly id: "recycling";
557
567
  readonly supported: "not";
@@ -551,7 +551,7 @@ ${await (0, doc_dfg_1.printDfGraphForCode)(parser, code, { simplified: true })}
551
551
  name: 'Promises',
552
552
  id: 'formals-promises',
553
553
  supported: 'partially',
554
- description: '_Handle `function(x = y) { y <- 3; x }`, `function(x = { x <- 3; x}) { x * x }`, ..._ We _try_ to identify promises correctly but this is really rudimentary.'
554
+ description: '_Handle `function(x = y) { y <- 3; x }`, `function(x = { x <- 3; x}) { x * x }`, ..._ A default argument resolves in the function\'s own environment and an argument passed in resolves in the caller\'s, both as R does it. We do not model _when_ a promise is forced: a `delayedAssign`ed expression is linked to every binding it may be forced against, which never misses the one that feeds it but may name others as well. What forcing _does_ is not modelled either, so the writes a promise performs when it is forced (`delayedAssign("x", { x <- 99; 2 })`, where reading `x` yields `2` and leaves `x` at `99`) do not reach the reads that follow.'
555
555
  }
556
556
  ]
557
557
  },
@@ -629,13 +629,19 @@ ${await (0, doc_dfg_1.printDfGraphForCode)(parser, code, { simplified: true })}
629
629
  name: 'Quoting',
630
630
  id: 'built-in-quoting',
631
631
  supported: 'partially',
632
- description: '_Handle `quote`, `substitute`, `bquote`, ..._ We partially ignore some of them but most likely not all.'
632
+ description: '_Handle `quote`, `substitute`, `bquote`, ..._ A quoted argument is marked as [non-standard evaluation](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph#non-standard-evaluation) as a whole, so nothing within it counts as read. We model the escapes back to standard evaluation that a quoting function offers: rlang\'s `!!`/`!!!` (in `expr`, `quo`, `enquo`, ... and in data-masking arguments) and `bquote`\'s `.()`. Base `quote`/`substitute` have no such escape, and `substitute` does not reach the caller\'s expression when used on a function argument.'
633
633
  },
634
634
  {
635
635
  name: 'Evaluation',
636
636
  id: 'built-in-evaluation',
637
637
  supported: 'partially',
638
- description: '_Handle `eval`, `evalq`, `eval.parent`, ..._ We do not handle them at all.'
638
+ description: '_Handle `eval`, `evalq`, `eval.parent`, ..._ `eval` of a string we can resolve is analyzed as if it were written in its place. A language object reaches the `eval` that forces it even across assignments, branches, loop iterations, and function calls, and its names resolve in the scope evaluating it, as R does. `eval(expr, envir)` runs elsewhere, so we mark the call as an unknown side effect instead of guessing. `evalq` quotes its first argument and we do not follow it into the given environment.'
639
+ },
640
+ {
641
+ name: 'String Templates',
642
+ id: 'string-templates',
643
+ supported: 'partially',
644
+ description: '_Handle `glue::glue("{x}")`, `cli::cli_alert_info("{.val {x}}")`, `stringr::str_glue`/`str_interp`, ..._ The `{...}` of a template carries R code that runs where the call is, so we analyze it as if it were written there: it reads, it writes, and its side effects land in the calling scope. Doubled delimiters escape, `.open`/`.close` are honored when they are literal, and cli markup (`{.cls ...}`) contributes only the interpolations nested in it. A template aimed at another scope (`.envir`, `.con`, `glue_data`) is marked as an unknown side effect instead.'
639
645
  },
640
646
  {
641
647
  name: 'Parsing',
@@ -699,6 +705,12 @@ ${await (0, doc_dfg_1.printDfGraphForCode)(parser, code, { simplified: true })}
699
705
  name: 'Non-Standard Evaluations/Semantics',
700
706
  id: 'non-standard-evaluations-semantics',
701
707
  capabilities: [
708
+ {
709
+ name: 'Data Masking',
710
+ id: 'data-masking',
711
+ supported: 'partially',
712
+ description: '_Handle `subset(d, col > 1)`, dplyr verbs, `ggplot2::aes`, data.table `:=`, ..._ In a masked argument, a name the caller binds is read as that variable and any other name is taken to come from the data. Which names a data frame actually offers is unknown to us, so a column shadowing a variable of the same name still resolves to the variable. rlang\'s `!!`/`!!!` and its `:=` name-value pair are recognised; `[` on a `data.table` does not mask its `j`/`by` yet.'
713
+ },
702
714
  {
703
715
  name: 'Recycling',
704
716
  id: 'recycling',
@@ -54,6 +54,8 @@ export declare const RFunctionCall: {
54
54
  * An empty argument (`f(1, ,3)`) takes its formal but never appears in the map, as there is nothing to bind.
55
55
  */
56
56
  readonly matchArgsToParams: <Info = object>(this: void, args: readonly PotentiallyEmptyRArgument<Info>[], paramNames: readonly string[]) => ReadonlyMap<string, RArgument<Info>>;
57
+ /** The one argument a call was given, `undefined` unless there is exactly one and it is not empty. */
58
+ readonly soleArgument: <Info = object>(this: void, args: readonly PotentiallyEmptyRArgument<Info>[]) => RArgument<Info> | undefined;
57
59
  readonly getLocation: (this: void, node: RNode) => import("../../../../../util/range").SourceLocation | undefined;
58
60
  readonly getId: (this: void, node: RNode<import("../processing/decorate").ParentInformation>) => import("../processing/node-id").NodeId;
59
61
  readonly stableId: (this: void, node: RNode<import("../processing/decorate").ParentInformation>) => string | undefined;
@@ -45,6 +45,10 @@ exports.RFunctionCall = {
45
45
  }
46
46
  }
47
47
  return bound;
48
+ },
49
+ /** The one argument a call was given, `undefined` unless there is exactly one and it is not empty. */
50
+ soleArgument(args) {
51
+ return args.length === 1 && args[0] !== exports.EmptyArgument ? args[0] : undefined;
48
52
  }
49
53
  };
50
54
  //# sourceMappingURL=r-function-call.js.map
@@ -66,6 +66,16 @@ function makeTreeSitterStrict() {
66
66
  log_1.log.info('[Tree-Sitter] Strict parsing active');
67
67
  nonErrorChildren = nonErrorChildrenStrict;
68
68
  }
69
+ function makeDefaultInfo(node, fullRange, fullLexeme) {
70
+ return {
71
+ info: {
72
+ fullRange,
73
+ adToks: [],
74
+ fullLexeme,
75
+ tsId: node.id
76
+ }
77
+ };
78
+ }
69
79
  function convertTreeNode(node) {
70
80
  if (!node) {
71
81
  return {
@@ -91,17 +101,9 @@ function convertTreeNode(node) {
91
101
  textCache ??= node.text;
92
102
  return textCache;
93
103
  };
94
- const makeDefaultInfo = () => ({
95
- info: {
96
- fullRange: range,
97
- adToks: [],
98
- fullLexeme: text(),
99
- tsId: node.id
100
- }
101
- });
102
104
  let defaultInfoCache = undefined;
103
105
  const defaultInfo = () => {
104
- defaultInfoCache ??= makeDefaultInfo();
106
+ defaultInfoCache ??= makeDefaultInfo(node, range, text());
105
107
  return defaultInfoCache;
106
108
  };
107
109
  switch (node.type) {
@@ -162,13 +162,17 @@ interface FilterData {
162
162
  dataflow: DataflowInformation;
163
163
  };
164
164
  }
165
+ /** A filter expression resolved to the function testing one element. */
166
+ export type PreparedFilter = (element: FlowrSearchElement<ParentInformation>, data: {
167
+ dataflow: DataflowInformation;
168
+ }) => boolean;
165
169
  /**
166
170
  * Resolve a filter expression to the function that tests one element.
167
171
  * Nothing here depends on the element, so a search over `n` elements should do this once instead of `n` times:
168
172
  * a bare {@link VertexType}/{@link RType} filter otherwise builds a {@link FlowrFilterCombinator} per element.
169
173
  * @see {@link evalFilter} - the one-shot form, if you only test a single element
170
174
  */
171
- export declare function prepareFilter<Filter extends FlowrFilter>(filter: FlowrFilterExpression<Filter>): (data: FilterData) => boolean;
175
+ export declare function prepareFilter<Filter extends FlowrFilter>(filter: FlowrFilterExpression<Filter>): PreparedFilter;
172
176
  /**
173
177
  * Evaluates the given filter expression against the provided data.
174
178
  * @see {@link prepareFilter} - resolve once when testing more than one element
@@ -210,26 +210,38 @@ function treeToStringImpl(tree, depth) {
210
210
  function isBinaryTree(tree) {
211
211
  return typeof tree === 'object' && tree !== null && 'tree' in tree;
212
212
  }
213
- const evalVisit = {
214
- and: ({ left, right }, data) => evalTree(left, data) && evalTree(right, data),
215
- or: ({ left, right }, data) => evalTree(left, data) || evalTree(right, data),
216
- xor: ({ left, right }, data) => evalTree(left, data) !== evalTree(right, data),
217
- not: ({ operand }, data) => !evalTree(operand, data),
218
- 'r-type': ({ value }, { element }) => element.node.type === value,
219
- 'vertex-type': ({ value }, { data, element }) => data.dataflow.graph.getVertex(element.node.info.id)?.tag === value,
220
- 'special': ({ value }, { data, element }) => {
213
+ const compileVisit = {
214
+ and: ({ left, right }) => {
215
+ const l = compileTree(left), r = compileTree(right);
216
+ return (e, d) => l(e, d) && r(e, d);
217
+ },
218
+ or: ({ left, right }) => {
219
+ const l = compileTree(left), r = compileTree(right);
220
+ return (e, d) => l(e, d) || r(e, d);
221
+ },
222
+ xor: ({ left, right }) => {
223
+ const l = compileTree(left), r = compileTree(right);
224
+ return (e, d) => l(e, d) !== r(e, d);
225
+ },
226
+ not: ({ operand }) => {
227
+ const o = compileTree(operand);
228
+ return (e, d) => !o(e, d);
229
+ },
230
+ 'r-type': ({ value }) => e => e.node.type === value,
231
+ 'vertex-type': ({ value }) => (e, d) => d.dataflow.graph.getVertex(e.node.info.id)?.tag === value,
232
+ 'special': ({ value }) => {
221
233
  const name = typeof value === 'string' ? value : value.name;
222
234
  const args = typeof value === 'string' ? undefined : value.args;
223
- const getHandler = exports.FlowrFilters[name];
224
- if (getHandler) {
225
- return getHandler(element, args, data);
235
+ const handler = exports.FlowrFilters[name];
236
+ if (!handler) {
237
+ throw new Error(`Couldn't find special filter with name ${name}`);
226
238
  }
227
- throw new Error(`Couldn't find special filter with name ${name}`);
239
+ return (e, d) => handler(e, args, d);
228
240
  }
229
241
  };
230
- function evalTree(tree, data) {
242
+ function compileTree(tree) {
231
243
  /* we ensure that the types fit */
232
- return evalVisit[tree.type](tree, data);
244
+ return compileVisit[tree.type](tree);
233
245
  }
234
246
  /**
235
247
  * Resolve a filter expression to the function that tests one element.
@@ -239,21 +251,19 @@ function evalTree(tree, data) {
239
251
  */
240
252
  function prepareFilter(filter) {
241
253
  if (filter instanceof FlowrFilterCombinator) {
242
- const tree = filter.get();
243
- return data => evalTree(tree, data);
254
+ return compileTree(filter.get());
244
255
  }
245
256
  else if (typeof filter === 'string' && exports.ValidFlowrFilters.has(filter)) {
246
257
  const handler = exports.FlowrFilters[filter];
247
- return data => handler(data.element, undefined, data.data);
258
+ return (e, d) => handler(e, undefined, d);
248
259
  }
249
260
  else if (typeof filter === 'object' && 'name' in filter) {
250
261
  const handler = exports.FlowrFilters[filter.name];
251
262
  const args = ('args' in filter ? filter.args : undefined);
252
- return data => handler(data.element, args, data.data);
263
+ return (e, d) => handler(e, args, d);
253
264
  }
254
265
  else {
255
- const tree = FlowrFilterCombinator.is(filter).get();
256
- return data => evalTree(tree, data);
266
+ return compileTree(FlowrFilterCombinator.is(filter).get());
257
267
  }
258
268
  }
259
269
  /**
@@ -261,6 +271,6 @@ function prepareFilter(filter) {
261
271
  * @see {@link prepareFilter} - resolve once when testing more than one element
262
272
  */
263
273
  function evalFilter(filter, data) {
264
- return prepareFilter(filter)(data);
274
+ return prepareFilter(filter)(data.element, data.data);
265
275
  }
266
276
  //# sourceMappingURL=flowr-search-filters.js.map
@@ -1,5 +1,6 @@
1
1
  import type { FlowrSearchElement, FlowrSearchElements } from '../flowr-search';
2
- import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
+ import type { NormalizedAst, ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
3
+ import type { DataflowInformation } from '../../dataflow/info';
3
4
  import { type MergeableRecord } from '../../util/objects';
4
5
  import type { LinkToLastCall } from '../../queries/catalog/call-context-query/call-context-query-format';
5
6
  import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
@@ -43,9 +44,18 @@ export interface CallTargetsContent extends MergeableRecord {
43
44
  */
44
45
  targets: (FlowrSearchElement<ParentInformation> | string)[];
45
46
  }
47
+ /** Analysis artifacts resolved once for the whole search rather than once per element. */
48
+ export interface CallTargetsSearchContent extends MergeableRecord {
49
+ dfg: DataflowInformation;
50
+ ast: NormalizedAst;
51
+ }
46
52
  export interface LastCallContent extends MergeableRecord {
47
53
  linkedIds: FlowrSearchElement<ParentInformation>[];
48
54
  }
55
+ /** @see {@link CallTargetsSearchContent} */
56
+ export interface LastCallSearchContent extends CallTargetsSearchContent {
57
+ cfg: ControlFlowInformation;
58
+ }
49
59
  export interface CfgInformationElementContent extends MergeableRecord {
50
60
  /**
51
61
  * Whether the current node is a root node in the CFG, which is a node that is not contained inside of a function definition.
@@ -84,6 +94,10 @@ export interface RoxygenElementContent extends MergeableRecord {
84
94
  })[];
85
95
  };
86
96
  }
97
+ /** @see {@link CallTargetsSearchContent} */
98
+ export interface RoxygenSearchContent extends MergeableRecord {
99
+ ast: NormalizedAst;
100
+ }
87
101
  export interface QueryDataElementContent extends MergeableRecord {
88
102
  /** The name of the query that this element originated from. To get each query's data, see {@link QueryDataSearchContent}. */
89
103
  query: Query['type'];
@@ -99,14 +113,19 @@ export interface QueryDataSearchContent extends MergeableRecord {
99
113
  */
100
114
  export declare const Enrichments: {
101
115
  readonly "call-targets": {
102
- enrichElement: (e: FlowrSearchElement<ParentInformation>, _s: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: {
116
+ enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: {
117
+ onlyBuiltin?: boolean;
118
+ qualifyNames?: boolean;
119
+ } | undefined, prev: CallTargetsSearchContent | undefined) => Promise<CallTargetsSearchContent>;
120
+ enrichElement: (e: FlowrSearchElement<ParentInformation>, s: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: {
103
121
  onlyBuiltin?: boolean;
104
122
  qualifyNames?: boolean;
105
123
  } | undefined, prev: CallTargetsContent | undefined) => Promise<CallTargetsContent>;
106
124
  mapper: ({ targets }: CallTargetsContent) => FlowrSearchElement<ParentInformation>[];
107
125
  };
108
126
  readonly "last-call": {
109
- enrichElement: (e: FlowrSearchElement<ParentInformation>, _s: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: Omit<LinkToLastCall<import("../../queries/catalog/call-context-query/call-context-query-format").CallNameTypes>, "type">[] | undefined, prev: LastCallContent | undefined) => Promise<LastCallContent>;
127
+ enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: Omit<LinkToLastCall<import("../../queries/catalog/call-context-query/call-context-query-format").CallNameTypes>, "type">[] | undefined, prev: LastCallSearchContent | undefined) => Promise<LastCallSearchContent>;
128
+ enrichElement: (e: FlowrSearchElement<ParentInformation>, s: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: Omit<LinkToLastCall<import("../../queries/catalog/call-context-query/call-context-query-format").CallNameTypes>, "type">[] | undefined, prev: LastCallContent | undefined) => Promise<LastCallContent>;
110
129
  mapper: ({ linkedIds }: LastCallContent) => FlowrSearchElement<ParentInformation>[];
111
130
  };
112
131
  readonly "cfg-information": {
@@ -117,7 +136,8 @@ export declare const Enrichments: {
117
136
  enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: CfgInformationArguments | undefined, prev: CfgInformationSearchContent | undefined) => Promise<CfgInformationSearchContent>;
118
137
  };
119
138
  readonly roxygen: {
120
- enrichElement: (e: FlowrSearchElement<ParentInformation>, _search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: undefined, prev: RoxygenElementContent | undefined) => Promise<{
139
+ enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: undefined, prev: RoxygenSearchContent | undefined) => Promise<RoxygenSearchContent>;
140
+ enrichElement: (e: FlowrSearchElement<ParentInformation>, search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: undefined, prev: RoxygenElementContent | undefined) => Promise<{
121
141
  [x: string]: unknown;
122
142
  documentation: ({
123
143
  value: string[];
@@ -32,11 +32,16 @@ var Enrichment;
32
32
  */
33
33
  exports.Enrichments = {
34
34
  [Enrichment.CallTargets]: {
35
- enrichElement: async (e, _s, analyzer, args, prev) => {
35
+ enrichSearch: async (_search, data, _args, prev) => prev ?? {
36
+ dfg: await data.dataflow(),
37
+ ast: await data.normalize()
38
+ },
39
+ enrichElement: async (e, s, analyzer, args, prev) => {
36
40
  // we don't resolve aliases here yet!
37
41
  const content = { targets: [] };
38
- const df = await analyzer.dataflow();
39
- const n = await analyzer.normalize();
42
+ const shared = s.enrichmentContent(Enrichment.CallTargets);
43
+ const df = shared?.dfg ?? await analyzer.dataflow();
44
+ const n = shared?.ast ?? await analyzer.normalize();
40
45
  const callVertex = df.graph.getVertex(e.node.info.id);
41
46
  if (callVertex?.tag === vertex_1.VertexType.FunctionCall) {
42
47
  const origins = df_helper_1.Dataflow.origin(df.graph, callVertex.id);
@@ -95,14 +100,20 @@ exports.Enrichments = {
95
100
  mapper: ({ targets }) => targets.map(t => t).filter(t => t.node !== undefined)
96
101
  },
97
102
  [Enrichment.LastCall]: {
98
- enrichElement: async (e, _s, analyzer, args, prev) => {
103
+ enrichSearch: async (_search, data, _args, prev) => prev ?? {
104
+ dfg: await data.dataflow(),
105
+ ast: await data.normalize(),
106
+ cfg: await data.controlflow(undefined, cfg_kind_1.CfgKind.Quick)
107
+ },
108
+ enrichElement: async (e, s, analyzer, args, prev) => {
99
109
  (0, assert_1.guard)(args && args.length, `${Enrichment.LastCall} enrichment requires at least one argument`);
100
110
  const content = prev ?? { linkedIds: [] };
101
- const df = (await analyzer.dataflow()).graph;
111
+ const shared = s.enrichmentContent(Enrichment.LastCall);
112
+ const df = (shared?.dfg ?? await analyzer.dataflow()).graph;
102
113
  const vertex = df.getVertex(e.node.info.id);
103
114
  if (vertex?.tag === vertex_1.VertexType.FunctionCall) {
104
- const n = await analyzer.normalize();
105
- const cfg = (await analyzer.controlflow(undefined, cfg_kind_1.CfgKind.Quick)).graph;
115
+ const n = shared?.ast ?? await analyzer.normalize();
116
+ const cfg = (shared?.cfg ?? await analyzer.controlflow(undefined, cfg_kind_1.CfgKind.Quick)).graph;
106
117
  for (const arg of args) {
107
118
  const lastCalls = (0, identify_link_to_last_call_relation_1.identifyLinkToLastCallRelationSync)(vertex.id, cfg, df, {
108
119
  ...arg,
@@ -149,12 +160,14 @@ exports.Enrichments = {
149
160
  }
150
161
  },
151
162
  [Enrichment.Roxygen]: {
152
- enrichElement: async (e, _search, analyzer, _args, prev) => {
163
+ enrichSearch: async (_search, data, _args, prev) => prev ?? { ast: await data.normalize() },
164
+ enrichElement: async (e, search, analyzer, _args, prev) => {
153
165
  const content = (prev ?? {
154
166
  documentation: [],
155
167
  tags: {}
156
168
  });
157
- const normalize = await analyzer.normalize();
169
+ const shared = search.enrichmentContent(Enrichment.Roxygen);
170
+ const normalize = shared?.ast ?? await analyzer.normalize();
158
171
  const roxygen = (0, documentation_provider_1.getDocumentationOf)(e.node.info.id, normalize.idMap);
159
172
  if (roxygen !== undefined) {
160
173
  const comments = (Array.isArray(roxygen) ? roxygen : [roxygen]);
@@ -100,7 +100,7 @@ async function getFilter(data, elements, { filter }) {
100
100
  // neither depends on the element, so build them once rather than n times
101
101
  const test = (0, flowr_search_filters_1.prepareFilter)(filter);
102
102
  const shared = { dataflow };
103
- return elements.mutate(e => e.filter(e => test({ element: e, data: shared })));
103
+ return elements.mutate(e => e.filter(e => test(e, shared)));
104
104
  }
105
105
  async function getWith(input, elements, { info, args }) {
106
106
  return (await elements.enrich(input, info, args)).mutate(async (s) => await Promise.all(s.map(e => (0, search_enrichers_1.enrichElement)(e, elements, input, info, args))));
@@ -11,7 +11,7 @@ const fingerprint_1 = require("./fingerprint");
11
11
  const linker_1 = require("../../dataflow/internal/linker");
12
12
  const vertex_1 = require("../../dataflow/graph/vertex");
13
13
  const graph_1 = require("../../dataflow/graph/graph");
14
- const resolve_by_name_1 = require("../../dataflow/environments/resolve-by-name");
14
+ const resolve_helper_1 = require("../../dataflow/environments/resolve-helper");
15
15
  const edge_1 = require("../../dataflow/graph/edge");
16
16
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
17
17
  const identifier_1 = require("../../dataflow/environments/identifier");
@@ -30,7 +30,7 @@ function getAllFunctionCallTargetsForSlice(dataflowGraph, callerInfo, baseEnviro
30
30
  const activeEnvironment = (0, built_in_function_definition_1.retrieveActiveEnvironment)(callerInfo.environment, baseEnvironment, ctx);
31
31
  const name = callerInfo.name;
32
32
  (0, assert_1.guard)(name !== undefined, () => `name of id: ${callerInfo.id} can not be found in id map`);
33
- const functionCallDefs = (0, resolve_by_name_1.resolveByNameAnyType)(name, activeEnvironment)?.filter(d => !node_id_1.NodeId.isBuiltIn(d.definedAt))?.map(d => d.nodeId) ?? [];
33
+ const functionCallDefs = resolve_helper_1.Resolve.byName(name, activeEnvironment)?.filter(d => !node_id_1.NodeId.isBuiltIn(d.definedAt))?.map(d => d.nodeId) ?? [];
34
34
  for (const [target, outgoingEdge] of outgoingEdges[1].entries()) {
35
35
  if (edge_1.DfEdge.includesType(outgoingEdge, edge_1.EdgeType.Calls)) {
36
36
  functionCallDefs.push(target);
@@ -56,7 +56,7 @@ function linkCallTargets(onlyForSideEffects, functionCallTargets, activeEnvironm
56
56
  for (const openIn of functionCallTarget.subflow.in) {
57
57
  // resolve them in the active env
58
58
  if (openIn.name) {
59
- const resolved = (0, resolve_by_name_1.resolveByNameAnyType)(openIn.name, activeEnvironment);
59
+ const resolved = resolve_helper_1.Resolve.byName(openIn.name, activeEnvironment);
60
60
  for (const res of resolved ?? []) {
61
61
  (0, static_slicer_1.updatePotentialAddition)(queue, functionCallTarget.id, res.nodeId, activeEnvironment, activeEnvironmentFingerprint);
62
62
  }
@@ -139,7 +139,7 @@ function sliceReachesFunctionInterface(fnDefId, graph, queue, idMap, ctx) {
139
139
  if (open.name === undefined || !queue.hasId(open.nodeId)) {
140
140
  continue;
141
141
  }
142
- const resolved = (0, resolve_by_name_1.resolveByName)(open.name, definitionEnvironment, open.type ?? identifier_1.ReferenceType.Unknown);
142
+ const resolved = resolve_helper_1.Resolve.byNameAndType(open.name, definitionEnvironment, open.type ?? identifier_1.ReferenceType.Unknown);
143
143
  if (resolved?.some(d => !node_id_1.NodeId.isBuiltIn(d.nodeId))) {
144
144
  return true;
145
145
  }
@@ -43,4 +43,17 @@ export interface GraphDiffContext<Graph = DataflowGraph> extends GenericDifferen
43
43
  * Create the context for differencing two graphs
44
44
  */
45
45
  export declare function initDiffContext<Graph>(left: NamedGraph<Graph>, right: NamedGraph<Graph>, config?: Partial<GenericDiffConfiguration>): GraphDiffContext<Graph>;
46
+ /** The minimum a graph has to offer for {@link GraphDiff} to compare its edges. */
47
+ interface EdgeIndexedGraph<EdgeMap> {
48
+ edges(): Iterable<readonly [NodeId, EdgeMap]>;
49
+ hasVertex(id: NodeId): boolean;
50
+ }
51
+ /** The edge-differencing steps shared by the dataflow and the control flow graph diff. */
52
+ export declare const GraphDiff: {
53
+ readonly name: "GraphDiff";
54
+ /** Compares all edges of both graphs vertex by vertex, handing each pair to `diffEdges`. */
55
+ readonly outgoingEdges: <EdgeMap, Graph extends EdgeIndexedGraph<EdgeMap>>(this: void, ctx: GraphDiffContext<Graph>, diffEdges: (ctx: GraphDiffContext<Graph>, id: NodeId, lEdges: EdgeMap | undefined, rEdges: EdgeMap | undefined) => void) => void;
56
+ /** Compares the outgoing edges of a single vertex, handing each pair of edges to `diffEdge`. */
57
+ readonly edges: <Edge, Graph>(this: void, ctx: GraphDiffContext<Graph>, id: NodeId, lEdges: ReadonlyMap<NodeId, Edge> | undefined, rEdges: ReadonlyMap<NodeId, Edge> | undefined, diffEdge: (edge: Edge, otherEdge: Edge, ctx: GraphDiffContext<Graph>, id: NodeId, target: NodeId) => void) => void;
58
+ };
46
59
  export {};
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GraphDifferenceReport = void 0;
3
+ exports.GraphDiff = exports.GraphDifferenceReport = void 0;
4
4
  exports.initDiffContext = initDiffContext;
5
+ const json_1 = require("./json");
5
6
  /**
6
7
  * To be produced by a function differencing two graphs (e.g., {@link DataflowGraph|DFGs} or {@link ControlFlowGraph|CFGs}).
7
8
  * @see {@link GraphDifferenceReport#isEqual|isEqual} - to check whether the graphs are equal
@@ -57,4 +58,66 @@ function initDiffContext(left, right, config) {
57
58
  }
58
59
  };
59
60
  }
61
+ /** The edge-differencing steps shared by the dataflow and the control flow graph diff. */
62
+ exports.GraphDiff = {
63
+ name: 'GraphDiff',
64
+ /** Compares all edges of both graphs vertex by vertex, handing each pair to `diffEdges`. */
65
+ outgoingEdges(ctx, diffEdges) {
66
+ const lEdges = new Map(ctx.left.edges());
67
+ const rEdges = new Map(ctx.right.edges());
68
+ if (lEdges.size < rEdges.size && !ctx.config.leftIsSubgraph || lEdges.size > rEdges.size && !ctx.config.rightIsSubgraph) {
69
+ ctx.report.addComment(`Detected different number of edges! ${ctx.leftname} has ${lEdges.size} (${JSON.stringify(lEdges, json_1.jsonReplacer)}). ${ctx.rightname} has ${rEdges.size} ${JSON.stringify(rEdges, json_1.jsonReplacer)}`);
70
+ }
71
+ for (const [id, edge] of lEdges) {
72
+ /* This has nothing to do with the subset relation as we verify this in the same graph.
73
+ * Yet we still do the check as a subgraph may not have to have all source vertices for edges.
74
+ */
75
+ if (!ctx.left.hasVertex(id)) {
76
+ if (!ctx.config.leftIsSubgraph) {
77
+ ctx.report.addComment(`The source ${id} of edges ${JSON.stringify(edge, json_1.jsonReplacer)} is not present in ${ctx.leftname}. This means that the graph contains an edge but not the corresponding vertex.`);
78
+ continue;
79
+ }
80
+ }
81
+ diffEdges(ctx, id, edge, rEdges.get(id));
82
+ }
83
+ // just to make it both ways in case the length differs
84
+ for (const [id, edge] of rEdges) {
85
+ if (!ctx.right.hasVertex(id)) {
86
+ if (!ctx.config.rightIsSubgraph) {
87
+ ctx.report.addComment(`The source ${id} of edges ${JSON.stringify(edge, json_1.jsonReplacer)} is not present in ${ctx.rightname}. This means that the graph contains an edge but not the corresponding vertex.`);
88
+ continue;
89
+ }
90
+ }
91
+ if (!ctx.config.leftIsSubgraph && !lEdges.has(id)) {
92
+ diffEdges(ctx, id, undefined, edge);
93
+ }
94
+ /* otherwise, we already cover the edge above */
95
+ }
96
+ },
97
+ /** Compares the outgoing edges of a single vertex, handing each pair of edges to `diffEdge`. */
98
+ edges(ctx, id, lEdges, rEdges, diffEdge) {
99
+ if (lEdges === undefined || rEdges === undefined) {
100
+ if ((lEdges === undefined && !ctx.config.leftIsSubgraph)
101
+ || (rEdges === undefined && !ctx.config.rightIsSubgraph)) {
102
+ ctx.report.addComment(`Vertex ${id} has undefined outgoing edges. ${ctx.leftname}: ${JSON.stringify(lEdges, json_1.jsonReplacer)} vs ${ctx.rightname}: ${JSON.stringify(rEdges, json_1.jsonReplacer)}`, { tag: 'vertex', id });
103
+ }
104
+ return;
105
+ }
106
+ if (lEdges.size < rEdges.size && !ctx.config.leftIsSubgraph
107
+ || lEdges.size > rEdges.size && !ctx.config.rightIsSubgraph) {
108
+ ctx.report.addComment(`Vertex ${id} differs in number of outgoing edges. ${ctx.leftname}: [${[...lEdges.keys()].join(',')}] vs ${ctx.rightname}: [${[...rEdges.keys()].join(',')}] `, { tag: 'vertex', id });
109
+ }
110
+ // order independent compare
111
+ for (const [target, edge] of lEdges) {
112
+ const otherEdge = rEdges.get(target);
113
+ if (otherEdge === undefined) {
114
+ if (!ctx.config.rightIsSubgraph) {
115
+ ctx.report.addComment(`Target of ${id}->${target} in ${ctx.leftname} is not present in ${ctx.rightname}`, { tag: 'edge', from: id, to: target });
116
+ }
117
+ continue;
118
+ }
119
+ diffEdge(edge, otherEdge, ctx, id, target);
120
+ }
121
+ }
122
+ };
60
123
  //# sourceMappingURL=diff-graph.js.map
package/util/files.js CHANGED
@@ -52,6 +52,13 @@ const fs_1 = __importStar(require("fs"));
52
52
  const path_1 = __importDefault(require("path"));
53
53
  const log_1 = require("./log");
54
54
  const n_readlines_1 = __importDefault(require("n-readlines"));
55
+ /** Rethrows if the caller asked for it, otherwise reports the directory as skipped. */
56
+ function skipUnreadableDir(dir, e, throwOnError) {
57
+ if (throwOnError) {
58
+ throw e;
59
+ }
60
+ log_1.log.warn(`Skipping '${dir}' during file discovery: ${e instanceof Error ? e.message : String(e)}`);
61
+ }
55
62
  /**
56
63
  * Retrieves all files in the given directory recursively
57
64
  * @param dir - Directory path to start the search from
@@ -66,10 +73,7 @@ async function* getAllFiles(dir, suffix = /.*/, throwOnError = false) {
66
73
  entries = await fs_1.promises.readdir(dir, { withFileTypes: true, recursive: false });
67
74
  }
68
75
  catch (e) {
69
- if (throwOnError) {
70
- throw e;
71
- }
72
- log_1.log.warn(`Skipping '${dir}' during file discovery: ${e instanceof Error ? e.message : String(e)}`);
76
+ skipUnreadableDir(dir, e, throwOnError);
73
77
  return;
74
78
  }
75
79
  for (const subEntries of entries) {
@@ -98,10 +102,7 @@ function* getAllFilesSync(dir, suffix = /.*/, ignoreDirs = undefined, relativeTo
98
102
  entries = fs_1.default.readdirSync(dir, { withFileTypes: true, recursive: false });
99
103
  }
100
104
  catch (e) {
101
- if (throwOnError) {
102
- throw e;
103
- }
104
- log_1.log.warn(`Skipping '${dir}' during file discovery: ${e instanceof Error ? e.message : String(e)}`);
105
+ skipUnreadableDir(dir, e, throwOnError);
105
106
  return;
106
107
  }
107
108
  for (const subEntries of entries) {
@@ -0,0 +1,4 @@
1
+ /** The `engines.node` range of the package.json, e.g. `>=22`. */
2
+ export declare function supportedNodeVersions(): string;
3
+ /** The oldest major node version flowR runs on, derived from {@link supportedNodeVersions}. */
4
+ export declare function minimumNodeMajor(): number;