@eagleoutice/flowr 2.13.8 → 2.13.10

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 (152) hide show
  1. package/config.d.ts +50 -2
  2. package/config.js +37 -6
  3. package/dataflow/cluster.js +48 -24
  4. package/dataflow/environments/apply-kill.js +4 -4
  5. package/dataflow/environments/built-in-props.d.ts +28 -4
  6. package/dataflow/environments/built-in-props.js +31 -8
  7. package/dataflow/environments/built-in.d.ts +7 -2
  8. package/dataflow/environments/built-in.js +10 -12
  9. package/dataflow/environments/default-builtin-config.d.ts +76 -6
  10. package/dataflow/environments/default-builtin-config.js +39 -16
  11. package/dataflow/environments/environment.d.ts +16 -0
  12. package/dataflow/environments/environment.js +70 -18
  13. package/dataflow/environments/identifier.d.ts +6 -0
  14. package/dataflow/environments/identifier.js +18 -5
  15. package/dataflow/environments/query-fn-props.js +34 -2
  16. package/dataflow/environments/reference-to-maybe.js +1 -1
  17. package/dataflow/eval/resolve/alias-tracking.js +45 -1
  18. package/dataflow/eval/resolve/resolve-argument.js +25 -17
  19. package/dataflow/eval/resolve/resolve-strings.d.ts +17 -0
  20. package/dataflow/eval/resolve/resolve-strings.js +16 -9
  21. package/dataflow/eval/resolve/resolve.js +3 -1
  22. package/dataflow/graph/call-graph.d.ts +7 -0
  23. package/dataflow/graph/call-graph.js +103 -0
  24. package/dataflow/graph/df-helper.d.ts +2 -0
  25. package/dataflow/graph/graph.d.ts +6 -8
  26. package/dataflow/graph/graph.js +21 -6
  27. package/dataflow/internal/linker.d.ts +5 -5
  28. package/dataflow/internal/linker.js +31 -92
  29. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -2
  30. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +3 -9
  31. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +4 -30
  32. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +1 -1
  34. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -1
  35. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +3 -3
  36. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.d.ts +1 -1
  37. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +5 -1
  38. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +2 -2
  39. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +5 -6
  40. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +32 -14
  41. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +16 -4
  42. package/dataflow/internal/process/functions/call/known-call-handling.js +29 -8
  43. package/documentation/doc-util/doc-sigdb.d.ts +9 -0
  44. package/documentation/doc-util/doc-sigdb.js +32 -0
  45. package/documentation/wiki-interface.js +13 -2
  46. package/documentation/wiki-query.js +3 -0
  47. package/documentation/wiki-signature-database.js +2 -5
  48. package/gas.d.ts +6 -0
  49. package/gas.js +7 -1
  50. package/package.json +2 -2
  51. package/project/attached-packages.d.ts +13 -0
  52. package/project/attached-packages.js +30 -0
  53. package/project/context/flowr-analyzer-context.d.ts +15 -0
  54. package/project/context/flowr-analyzer-context.js +14 -3
  55. package/project/context/flowr-analyzer-files-context.d.ts +11 -0
  56. package/project/context/flowr-analyzer-files-context.js +3 -0
  57. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +4 -0
  58. package/project/context/flowr-analyzer-incremental-analysis-context.js +69 -0
  59. package/project/dependency-version-space.d.ts +45 -8
  60. package/project/dependency-version-space.js +86 -26
  61. package/project/plugins/file-plugins/files/flowr-namespace-file.js +52 -24
  62. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.d.ts +22 -0
  63. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +101 -0
  64. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +30 -11
  65. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +79 -37
  66. package/project/plugins/package-version-plugins/package.d.ts +2 -0
  67. package/project/plugins/package-version-plugins/package.js +4 -0
  68. package/project/plugins/plugin-registry.d.ts +2 -1
  69. package/project/plugins/plugin-registry.js +2 -0
  70. package/project/sigdb/manifest.js +9 -5
  71. package/project/sigdb/signature-match.d.ts +5 -18
  72. package/project/sigdb/signature-match.js +5 -18
  73. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +4 -2
  74. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +25 -0
  75. package/queries/catalog/call-graph-query/call-graph-query-executor.js +3 -1
  76. package/queries/catalog/call-graph-query/call-graph-query-format.d.ts +4 -0
  77. package/queries/catalog/call-graph-query/call-graph-query-format.js +4 -0
  78. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +11 -1
  79. package/queries/catalog/dependencies-query/dependencies-query-executor.js +13 -5
  80. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +27 -1
  81. package/queries/catalog/dependencies-query/dependencies-query-format.js +69 -7
  82. package/queries/catalog/dependencies-query/function-info/library-functions.js +9 -2
  83. package/queries/catalog/dependencies-query/function-info/read-functions.js +31 -5
  84. package/queries/catalog/dependencies-query/function-info/remote-functions.d.ts +18 -0
  85. package/queries/catalog/dependencies-query/function-info/remote-functions.js +46 -0
  86. package/queries/catalog/dependencies-query/function-info/test-functions.d.ts +2 -0
  87. package/queries/catalog/dependencies-query/function-info/test-functions.js +33 -31
  88. package/queries/catalog/dependencies-query/function-info/visualize-functions.js +52 -2
  89. package/queries/catalog/dependencies-query/function-info/write-functions.js +28 -5
  90. package/queries/catalog/dependencies-query/link-devices.d.ts +12 -0
  91. package/queries/catalog/dependencies-query/link-devices.js +58 -0
  92. package/queries/catalog/dice-query/dice-query-format.d.ts +2 -0
  93. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +25 -6
  94. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +38 -7
  95. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +18 -5
  96. package/queries/catalog/happens-before-query/happens-before-query-format.js +3 -2
  97. package/queries/catalog/input-sources-query/input-sources-query-format.js +4 -0
  98. package/queries/catalog/input-sources-query/input-types.d.ts +10 -0
  99. package/queries/catalog/input-sources-query/input-types.js +10 -0
  100. package/queries/catalog/location-map-query/location-map-query-executor.js +16 -6
  101. package/queries/catalog/location-map-query/location-map-query-format.d.ts +15 -1
  102. package/queries/catalog/location-map-query/location-map-query-format.js +22 -5
  103. package/queries/catalog/signature-query/signature-query-executor.js +3 -0
  104. package/queries/catalog/signature-query/signature-query-format.d.ts +5 -0
  105. package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
  106. package/queries/query.d.ts +1 -1
  107. package/r-bridge/data/data.d.ts +1 -1
  108. package/r-bridge/data/data.js +1 -1
  109. package/r-bridge/lang-4.x/ast/model/model.d.ts +14 -2
  110. package/r-bridge/lang-4.x/ast/model/model.js +32 -0
  111. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +2 -0
  112. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -0
  113. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +2 -0
  114. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +2 -0
  115. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +2 -0
  116. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +2 -0
  117. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +2 -0
  118. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +7 -8
  119. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +9 -46
  120. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +2 -0
  121. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +2 -0
  122. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +2 -0
  123. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +2 -0
  124. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +2 -0
  125. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +2 -0
  126. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +2 -0
  127. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +2 -0
  128. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +2 -0
  129. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +2 -0
  130. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +2 -0
  131. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +2 -0
  132. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +2 -0
  133. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +0 -5
  134. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +6 -3
  135. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +1 -1
  136. package/search/flowr-search-filters.d.ts +17 -1
  137. package/search/flowr-search-filters.js +23 -0
  138. package/slicing/criterion/parse.d.ts +6 -25
  139. package/slicing/criterion/parse.js +50 -19
  140. package/slicing/static/fingerprint.d.ts +1 -1
  141. package/slicing/static/fingerprint.js +52 -8
  142. package/slicing/static/slicer-types.d.ts +10 -0
  143. package/slicing/static/static-slicer.d.ts +1 -1
  144. package/slicing/static/static-slicer.js +29 -6
  145. package/slicing/static/visiting-queue.d.ts +15 -3
  146. package/slicing/static/visiting-queue.js +37 -3
  147. package/util/arg-matching.d.ts +18 -0
  148. package/util/arg-matching.js +70 -0
  149. package/util/r-regex.js +19 -1
  150. package/util/range.d.ts +7 -8
  151. package/util/range.js +10 -11
  152. package/util/version.js +1 -1
@@ -92,27 +92,35 @@ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environm
92
92
  if (resolved) {
93
93
  const values = [];
94
94
  for (const value of resolved.elements) {
95
- if (!(0, r_value_1.isValue)(value)) {
96
- return undefined;
97
- }
98
- else if (value.type === 'string' && (0, r_value_1.isValue)(value.value)) {
99
- values.push(value.value.str);
100
- }
101
- else if (value.type === 'logical' && (0, r_value_1.isValue)(value.value)) {
102
- values.push(value.value.valueOf() ? convert_values_1.RTrue : convert_values_1.RFalse);
103
- }
104
- else if (value.type === 'vector' && (0, r_value_1.isValue)(value.elements)) {
105
- const elements = (0, string_constants_1.collectStrings)(value.elements, !full);
106
- if (elements === undefined) {
107
- return undefined;
108
- }
109
- values.push(...elements);
110
- }
111
- else {
95
+ const strings = (0, r_value_1.isValue)(value) ? stringsOfValue(value, full) : undefined;
96
+ if (strings === undefined) {
112
97
  return undefined;
113
98
  }
99
+ values.push(...strings);
114
100
  }
115
101
  return values;
116
102
  }
117
103
  }
104
+ /**
105
+ * The strings a resolved value stands for. A value that is no string is data given inline and hence reported as
106
+ * {@link Constant}, so that a consumer can tell it apart from a value we failed to resolve ({@link Unknown}).
107
+ */
108
+ function stringsOfValue(value, full) {
109
+ switch (value.type) {
110
+ case 'string':
111
+ return (0, r_value_1.isValue)(value.value) ? [value.value.str] : undefined;
112
+ case 'logical':
113
+ return (0, r_value_1.isValue)(value.value) ? [value.value.valueOf() ? convert_values_1.RTrue : convert_values_1.RFalse] : undefined;
114
+ case 'vector':
115
+ return (0, r_value_1.isValue)(value.elements)
116
+ ? (0, string_constants_1.collectStrings)(value.elements, !full) ?? (value.elements.every(r_value_1.isValue) ? [dependencies_query_format_1.Constant] : undefined)
117
+ : undefined;
118
+ case 'number':
119
+ case 'interval':
120
+ case 'null':
121
+ return [dependencies_query_format_1.Constant];
122
+ default:
123
+ return undefined;
124
+ }
125
+ }
118
126
  //# sourceMappingURL=resolve-argument.js.map
@@ -1,6 +1,7 @@
1
1
  import type { RNamedFunctionCall } from '../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
2
2
  import type { RNode } from '../../../r-bridge/lang-4.x/ast/model/model';
3
3
  import type { BuiltInEvalHandlerArgs } from '../../environments/built-in';
4
+ import { PkgName } from '../../environments/identifier';
4
5
  import { type Value } from '../values/r-value';
5
6
  /** everything after the last separator, with trailing separators dropped first (`a/b/` is `b`, `/` is the empty string) */
6
7
  declare function basename(path: string): string;
@@ -14,6 +15,8 @@ declare function dirname(path: string): string;
14
15
  * returns `undefined` for, which keeps the call `Top`.
15
16
  */
16
17
  export interface StringFn {
18
+ /** the package declaring it, so another package's function of that name does not fold */
19
+ readonly pkg: PkgName;
17
20
  /** the parameter names, in the order R declares them; `...` collects the arguments naming no other parameter */
18
21
  readonly params: readonly string[];
19
22
  /** what a parameter R gives a default stands for, so `paste(a, b)` folds like `paste(a, b, sep = ' ')` */
@@ -33,6 +36,7 @@ export interface StringFn {
33
36
  */
34
37
  export declare const StringFns: {
35
38
  readonly paste: {
39
+ readonly pkg: PkgName.Base;
36
40
  readonly params: readonly ["...", "sep"];
37
41
  readonly defaults: {
38
42
  readonly sep: " ";
@@ -41,6 +45,7 @@ export declare const StringFns: {
41
45
  readonly fold: (parts: string[], sep: string) => string;
42
46
  };
43
47
  readonly paste0: {
48
+ readonly pkg: PkgName.Base;
44
49
  readonly params: readonly ["...", "sep"];
45
50
  readonly defaults: {
46
51
  readonly sep: "";
@@ -49,34 +54,46 @@ export declare const StringFns: {
49
54
  readonly fold: (parts: string[], sep: string) => string;
50
55
  };
51
56
  readonly 'file.path': {
57
+ readonly pkg: PkgName.Base;
52
58
  readonly params: readonly ["...", "fsep"];
53
59
  readonly defaults: {
54
60
  readonly fsep: "/";
55
61
  };
56
62
  readonly fold: (parts: string[], fsep: string) => string;
57
63
  };
64
+ readonly here: {
65
+ readonly pkg: PkgName.Here;
66
+ readonly params: readonly ["..."];
67
+ readonly fold: (parts: string[]) => string;
68
+ };
58
69
  readonly basename: {
70
+ readonly pkg: PkgName.Base;
59
71
  readonly params: readonly ["path"];
60
72
  readonly fold: typeof basename;
61
73
  };
62
74
  readonly dirname: {
75
+ readonly pkg: PkgName.Base;
63
76
  readonly params: readonly ["path"];
64
77
  readonly fold: typeof dirname;
65
78
  };
66
79
  readonly toupper: {
80
+ readonly pkg: PkgName.Base;
67
81
  readonly params: readonly ["x"];
68
82
  readonly fold: (s: string) => string;
69
83
  };
70
84
  readonly tolower: {
85
+ readonly pkg: PkgName.Base;
71
86
  readonly params: readonly ["x"];
72
87
  readonly fold: (s: string) => string;
73
88
  };
74
89
  readonly trimws: {
90
+ readonly pkg: PkgName.Base;
75
91
  readonly params: readonly ["x"];
76
92
  readonly fold: (s: string) => string;
77
93
  };
78
94
  /** R counts characters, so we count code points rather than UTF-16 units */
79
95
  readonly nchar: {
96
+ readonly pkg: PkgName.Base;
80
97
  readonly params: readonly ["x"];
81
98
  readonly fold: (s: string) => number;
82
99
  };
@@ -38,18 +38,20 @@ function dirname(path) {
38
38
  */
39
39
  exports.StringFns = {
40
40
  /* the joining calls, which differ only in their separator and what the argument overriding it is called */
41
- paste: { params: ['...', 'sep'], defaults: { sep: ' ' }, ignored: ['collapse'], fold: (parts, sep) => parts.join(sep) },
42
- paste0: { params: ['...', 'sep'], defaults: { sep: '' }, ignored: ['collapse'], fold: (parts, sep) => parts.join(sep) },
43
- 'file.path': { params: ['...', 'fsep'], defaults: { fsep: '/' }, fold: (parts, fsep) => parts.join(fsep) },
41
+ paste: { pkg: "base" /* PkgName.Base */, params: ['...', 'sep'], defaults: { sep: ' ' }, ignored: ['collapse'], fold: (parts, sep) => parts.join(sep) },
42
+ paste0: { pkg: "base" /* PkgName.Base */, params: ['...', 'sep'], defaults: { sep: '' }, ignored: ['collapse'], fold: (parts, sep) => parts.join(sep) },
43
+ 'file.path': { pkg: "base" /* PkgName.Base */, params: ['...', 'fsep'], defaults: { fsep: '/' }, fold: (parts, fsep) => parts.join(fsep) },
44
+ /* the project root stays implicit, so the fold yields the path below it */
45
+ here: { pkg: "here" /* PkgName.Here */, params: ['...'], fold: (parts) => parts.length > 0 ? parts.join('/') : '.' },
44
46
  /* the path splits, which only ever treat `/` as a separator, so a Windows path keeps its non-`\` parts */
45
- basename: { params: ['path'], fold: basename },
46
- dirname: { params: ['path'], fold: dirname },
47
+ basename: { pkg: "base" /* PkgName.Base */, params: ['path'], fold: basename },
48
+ dirname: { pkg: "base" /* PkgName.Base */, params: ['path'], fold: dirname },
47
49
  /* whole-string transformations */
48
- toupper: { params: ['x'], fold: (s) => s.toUpperCase() },
49
- tolower: { params: ['x'], fold: (s) => s.toLowerCase() },
50
- trimws: { params: ['x'], fold: (s) => s.trim() },
50
+ toupper: { pkg: "base" /* PkgName.Base */, params: ['x'], fold: (s) => s.toUpperCase() },
51
+ tolower: { pkg: "base" /* PkgName.Base */, params: ['x'], fold: (s) => s.toLowerCase() },
52
+ trimws: { pkg: "base" /* PkgName.Base */, params: ['x'], fold: (s) => s.trim() },
51
53
  /** R counts characters, so we count code points rather than UTF-16 units */
52
- nchar: { params: ['x'], fold: (s) => [...s].length }
54
+ nchar: { pkg: "base" /* PkgName.Base */, params: ['x'], fold: (s) => [...s].length }
53
55
  };
54
56
  /** the entries that join what they are handed, the ones a name at construction time may be built from */
55
57
  exports.PasteLikeCalls = new Set(Object.entries(exports.StringFns).filter(([, fn]) => fn.params.includes('...')).map(([name]) => name));
@@ -63,6 +65,11 @@ function foldStringCall(node, resolveArg) {
63
65
  if (known === undefined) {
64
66
  return undefined;
65
67
  }
68
+ /* `dplyr::paste` is not `base::paste`; a bare call has already been resolved */
69
+ const ns = identifier_1.Identifier.getNamespace(node.functionName.content);
70
+ if (ns !== undefined && ns !== known.pkg) {
71
+ return undefined;
72
+ }
66
73
  const matched = (0, match_arguments_1.matchCallArguments)(node, known.params, known.ignored);
67
74
  if (matched === undefined) {
68
75
  return undefined;
@@ -49,7 +49,9 @@ function evalNameOf({ node, graph }) {
49
49
  continue;
50
50
  }
51
51
  /* an alias like `f <- c` keeps the built-in it stands for in `proc`, a direct call names itself */
52
- const named = node_id_1.NodeId.isBuiltIn(origin.proc) ? node_id_1.NodeId.fromBuiltIn(origin.proc) : origin.fn.name;
52
+ const pkgFn = node_id_1.NodeId.toPkgFn(origin.proc);
53
+ const named = pkgFn !== undefined ? identifier_1.Identifier.make(pkgFn[1], pkgFn[0])
54
+ : node_id_1.NodeId.isBuiltIn(origin.proc) ? node_id_1.NodeId.fromBuiltIn(origin.proc) : origin.fn.name;
53
55
  if (name !== undefined && identifier_1.Identifier.getName(name) !== identifier_1.Identifier.getName(named)) {
54
56
  return undefined;
55
57
  }
@@ -24,6 +24,13 @@ export declare const CallGraph: {
24
24
  * Extracts the sub call graph from the given call graph, starting from the given entry points.
25
25
  */
26
26
  readonly computeSubCallGraph: (this: void, graph: CallGraph, entryPoints: Set<NodeId>) => CallGraph;
27
+ /** The calls the program makes on its own: those outside of any function definition. */
28
+ readonly entryPoints: (this: void, graph: CallGraph) => Set<NodeId>;
29
+ /**
30
+ * The calls no execution starting at the top level reaches: those in a function nothing (transitively) calls.
31
+ * What {@link mayRunAnyway} may still run is left out, so a call reported here really does not run.
32
+ */
33
+ readonly unreachableCalls: (this: void, graph: CallGraph) => NodeId[];
27
34
  /**
28
35
  * Reduces the call graph by dropping all transitive edges.
29
36
  */
@@ -9,6 +9,11 @@ const edge_1 = require("./edge");
9
9
  const built_in_proc_name_1 = require("../environments/built-in-proc-name");
10
10
  const defaultmap_1 = require("../../util/collections/defaultmap");
11
11
  const graph_helper_1 = require("./graph-helper");
12
+ const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
13
+ const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
14
+ const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
15
+ const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
16
+ const identifier_1 = require("../environments/identifier");
12
17
  function processCds(vtx, graph, result, state) {
13
18
  for (const tar of vtx.cds ?? []) {
14
19
  const targetVtx = graph.getVertex(tar.id);
@@ -154,6 +159,74 @@ function processFunctionDefinition(vtx, from, graph, result, state) {
154
159
  }
155
160
  }
156
161
  }
162
+ /** Follows the `Calls` edges from `seeds`, collecting everything they reach in `reached`. */
163
+ function followCalls(graph, seeds, reached) {
164
+ const toVisit = Array.from(seeds);
165
+ while (toVisit.length > 0) {
166
+ const current = toVisit.pop();
167
+ if (reached.has(current)) {
168
+ continue;
169
+ }
170
+ reached.add(current);
171
+ for (const [target, edge] of graph.outgoingEdges(current) ?? []) {
172
+ if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls)) {
173
+ toVisit.push(target);
174
+ }
175
+ }
176
+ }
177
+ }
178
+ /** The names the reached calls go by, which are the generics a method of the program may be dispatched to for. */
179
+ function reachedCallNames(graph, reached) {
180
+ const names = new Set();
181
+ for (const id of reached) {
182
+ const vertex = graph.getVertex(id);
183
+ if (vertex?.tag === vertex_1.VertexType.FunctionCall) {
184
+ names.add(identifier_1.Identifier.getName(vertex.name));
185
+ }
186
+ }
187
+ return names;
188
+ }
189
+ /** Whether `name` is a `<generic>.<class>` of a generic that is called, as `print.foo` is when `print` is. */
190
+ function mayBeDispatchedTo(name, generics) {
191
+ for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
192
+ if (generics.has(name.slice(0, dot))) {
193
+ return true;
194
+ }
195
+ }
196
+ return false;
197
+ }
198
+ /**
199
+ * The unreached function definitions that may still run: one the code hands to another call (a callback, an
200
+ * S4 method, a shiny handler), and one bound to a `<generic>.<class>` name of a generic the program calls.
201
+ */
202
+ function mayRunAnyway(graph, reached) {
203
+ const idMap = graph.idMap;
204
+ if (idMap === undefined) {
205
+ return [];
206
+ }
207
+ const seeds = [];
208
+ let generics;
209
+ for (const [id, vertex] of graph.vertices(true)) {
210
+ if (vertex.tag !== vertex_1.VertexType.FunctionDefinition || reached.has(id)) {
211
+ continue;
212
+ }
213
+ const node = idMap.get(id);
214
+ if (node === undefined) {
215
+ continue;
216
+ }
217
+ const parent = model_1.RNode.directParent(node, idMap);
218
+ if (parent?.type === type_1.RType.Argument) {
219
+ seeds.push(id);
220
+ continue;
221
+ }
222
+ const bound = r_binary_op_1.RBinaryOp.is(parent) ? model_1.RNode.lexeme(parent.lhs) : undefined;
223
+ generics ??= reachedCallNames(graph, reached);
224
+ if (bound !== undefined && mayBeDispatchedTo(bound, generics)) {
225
+ seeds.push(id);
226
+ }
227
+ }
228
+ return seeds;
229
+ }
157
230
  /**
158
231
  * Helper object for call-graphs, you can compute new call graphs based on {@link CallGraph.compute}.
159
232
  * @see {@link Dataflow}
@@ -189,6 +262,36 @@ exports.CallGraph = {
189
262
  }
190
263
  return result;
191
264
  },
265
+ /** The calls the program makes on its own: those outside of any function definition. */
266
+ entryPoints(graph) {
267
+ const entries = new Set();
268
+ const idMap = graph.idMap;
269
+ if (idMap === undefined) {
270
+ return entries;
271
+ }
272
+ for (const [id, vertex] of graph.vertices(true)) {
273
+ const node = vertex.tag === vertex_1.VertexType.FunctionCall ? idMap.get(id) : undefined;
274
+ if (node !== undefined && r_function_definition_1.RFunctionDefinition.wrappingFunctionDefinition(node, idMap) === undefined) {
275
+ entries.add(id);
276
+ }
277
+ }
278
+ return entries;
279
+ },
280
+ /**
281
+ * The calls no execution starting at the top level reaches: those in a function nothing (transitively) calls.
282
+ * What {@link mayRunAnyway} may still run is left out, so a call reported here really does not run.
283
+ */
284
+ unreachableCalls(graph) {
285
+ const reached = new Set();
286
+ followCalls(graph, exports.CallGraph.entryPoints(graph), reached);
287
+ for (let seeds = mayRunAnyway(graph, reached); seeds.length > 0; seeds = mayRunAnyway(graph, reached)) {
288
+ followCalls(graph, seeds, reached);
289
+ }
290
+ return graph.vertices(true)
291
+ .filter(([id, vertex]) => vertex.tag === vertex_1.VertexType.FunctionCall && !reached.has(id))
292
+ .map(([id]) => id)
293
+ .toArray();
294
+ },
192
295
  /**
193
296
  * Reduces the call graph by dropping all transitive edges.
194
297
  */
@@ -45,6 +45,8 @@ export declare const Dataflow: {
45
45
  */
46
46
  readonly callGraph: {
47
47
  readonly computeSubCallGraph: (this: void, graph: CallGraph, entryPoints: Set<NodeId>) => CallGraph;
48
+ readonly entryPoints: (this: void, graph: CallGraph) => Set<NodeId>;
49
+ readonly unreachableCalls: (this: void, graph: CallGraph) => NodeId[];
48
50
  readonly dropTransitiveEdges: (this: void, graph: CallGraph) => CallGraph;
49
51
  readonly compute: (this: void, graph: DataflowGraph) => CallGraph;
50
52
  readonly visualize: {
@@ -156,15 +156,12 @@ export interface DataflowGraphJson {
156
156
  * Linked side effects are used whenever we know that a call may be affected by another one in a way that we cannot
157
157
  * grasp from the dataflow perspective (e.g., an indirect dependency based on the currently active graphic device).
158
158
  */
159
- export type UnknownSideEffect = NodeId | {
160
- id: NodeId;
161
- linkTo: LinkTo<RegExp>;
162
- };
159
+ export type UnknownSideEffect = NodeId | LinkedUnknownSideEffect;
163
160
  /** A {@link UnknownSideEffect} that carries a {@link LinkTo} target. */
164
- export type LinkedUnknownSideEffect = {
165
- id: NodeId;
166
- linkTo: LinkTo<RegExp>;
167
- };
161
+ export interface LinkedUnknownSideEffect {
162
+ readonly id: NodeId;
163
+ readonly linkTo: LinkTo<RegExp>;
164
+ }
168
165
  /**
169
166
  * Helpers for the {@link UnknownSideEffect} union, which is either a plain {@link NodeId} or a
170
167
  * `{ id, linkTo }` object. Use these instead of hand-rolling `typeof x === 'object' ? x.id : x`
@@ -210,6 +207,7 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
210
207
  private vertexInformation;
211
208
  /** All edges in the complete graph (including those nested in function definition) */
212
209
  private edgeInformation;
210
+ private incomingIndex?;
213
211
  private readonly types;
214
212
  toJSON(): DataflowGraphJson;
215
213
  /**
@@ -178,6 +178,9 @@ class DataflowGraph {
178
178
  vertexInformation = new Map();
179
179
  /** All edges in the complete graph (including those nested in function definition) */
180
180
  edgeInformation = new Map();
181
+ /* the reverse of `edgeInformation`, built on demand and dropped whenever an edge is added: rebuilding it per
182
+ * lookup made every caller asking for the ingoing edges of many nodes scan the whole graph once per node */
183
+ incomingIndex;
181
184
  types = new Map();
182
185
  toJSON() {
183
186
  return {
@@ -226,14 +229,23 @@ class DataflowGraph {
226
229
  return this.edgeInformation.get(id);
227
230
  }
228
231
  ingoingEdges(id) {
229
- const edges = new Map();
230
- for (const [source, outgoing] of this.edgeInformation.entries()) {
231
- const o = outgoing.get(id);
232
- if (o) {
233
- edges.set(source, o);
232
+ if (this.incomingIndex === undefined) {
233
+ const index = new Map();
234
+ for (const [source, outgoing] of this.edgeInformation.entries()) {
235
+ for (const [target, edge] of outgoing) {
236
+ const into = index.get(target);
237
+ if (into === undefined) {
238
+ index.set(target, new Map([[source, edge]]));
239
+ }
240
+ else {
241
+ into.set(source, edge);
242
+ }
243
+ }
234
244
  }
245
+ this.incomingIndex = index;
235
246
  }
236
- return edges;
247
+ /* the historic contract is an (possibly empty) map for every id, never `undefined` */
248
+ return this.incomingIndex.get(id) ?? new Map();
237
249
  }
238
250
  /**
239
251
  * Given a node in the normalized AST this either:
@@ -350,6 +362,7 @@ class DataflowGraph {
350
362
  if (fromId === toId) {
351
363
  return this;
352
364
  }
365
+ this.incomingIndex = undefined;
353
366
  let fromEdges = this.edgeInformation.get(fromId);
354
367
  if (fromEdges === undefined) {
355
368
  fromEdges = new Map([[toId, { types: type }]]);
@@ -409,6 +422,7 @@ class DataflowGraph {
409
422
  }
410
423
  }
411
424
  mergeEdges(otherGraph) {
425
+ this.incomingIndex = undefined;
412
426
  for (const [id, edges] of otherGraph.edgeInformation.entries()) {
413
427
  let existing = this.edgeInformation.get(id);
414
428
  if (existing === undefined) {
@@ -530,6 +544,7 @@ class DataflowGraph {
530
544
  }
531
545
  }
532
546
  graph.edgeInformation = new Map(data.edgeInformation.map(([id, edges]) => [id, new Map(edges)]));
547
+ graph.incomingIndex = undefined;
533
548
  for (const unknown of data._unknownSideEffects) {
534
549
  graph._unknownSideEffects.add(unknown);
535
550
  }
@@ -18,15 +18,15 @@ export declare function findNonLocalReads(graph: DataflowGraph, ignores?: Readon
18
18
  */
19
19
  export declare function produceNameSharedIdMap(references: IdentifierReference[]): NameIdMap;
20
20
  /**
21
- * Links the given arguments to the given parameters within the given graph.
22
- * This follows the `pmatch` semantics of R
23
- * @see https://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching
24
- * This returns the resolved map from argument ids to parameter ids.
21
+ * {@link matchArgumentsToParameters|Matches} the arguments to the parameters and links them in the graph,
22
+ * returning the resolved map from argument ids to parameter ids.
25
23
  * If you just want to match by name, use {@link pMatch}.
26
24
  */
27
25
  export declare function linkArgumentsOnCall(args: readonly FunctionArgument[], params: readonly RParameter<ParentInformation>[], graph: DataflowGraph): Map<NodeId, NodeId>;
28
26
  /**
29
- * Links the given arguments to the given parameters within the given graph by name only.
27
+ * {@link matchArgumentsToParameters|Matches} the arguments against a parameter specification, returning the
28
+ * arguments bound to each target. Unlike {@link linkArgumentsOnCall} this touches no graph, so it also works
29
+ * for a specification without parameters in the AST.
30
30
  * @example
31
31
  * ```ts
32
32
  * const parameterSpec = {
@@ -23,7 +23,7 @@ const edge_1 = require("../graph/edge");
23
23
  const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
24
24
  const vertex_1 = require("../graph/vertex");
25
25
  const resolve_by_name_1 = require("../environments/resolve-by-name");
26
- const prefix_1 = require("../../util/prefix");
26
+ const arg_matching_1 = require("../../util/arg-matching");
27
27
  const info_1 = require("../info");
28
28
  const unnamed_call_handling_1 = require("./process/functions/call/unnamed-call-handling");
29
29
  const built_in_proc_name_1 = require("../environments/built-in-proc-name");
@@ -71,72 +71,40 @@ function produceNameSharedIdMap(references) {
71
71
  }
72
72
  return nameIdShares;
73
73
  }
74
+ /** the argument names as {@link matchArgumentsToParameters} wants them */
75
+ function argumentNames(args) {
76
+ return args.map(a => graph_1.FunctionArgument.isNamed(a) ? a.name : undefined);
77
+ }
74
78
  /**
75
- * Links the given arguments to the given parameters within the given graph.
76
- * This follows the `pmatch` semantics of R
77
- * @see https://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching
78
- * This returns the resolved map from argument ids to parameter ids.
79
+ * {@link matchArgumentsToParameters|Matches} the arguments to the parameters and links them in the graph,
80
+ * returning the resolved map from argument ids to parameter ids.
79
81
  * If you just want to match by name, use {@link pMatch}.
80
82
  */
81
83
  function linkArgumentsOnCall(args, params, graph) {
82
- const nameArgMap = new Map(args.filter(graph_1.FunctionArgument.isNamed).map(a => [a.name, a]));
83
- const nameParamMap = new Map(params.filter(p => p?.name?.content !== undefined)
84
- .map(p => [p.name.content, p]));
84
+ const matched = (0, arg_matching_1.matchArgumentsToParameters)(argumentNames(args), params.map(p => p?.special ? arg_matching_1.DotsParameterName : p?.name?.content));
85
85
  const maps = new Map();
86
- const specialDotParameter = params.find(p => p.special);
87
- const sid = specialDotParameter?.name.info.id;
88
- // all parameters matched by name
89
- const matchedParameters = new Set();
90
- const paramNames = nameParamMap.keys().toArray();
91
- // first map names
92
- for (const [name, { nodeId: argId }] of nameArgMap) {
93
- const pmatchName = (0, prefix_1.findByPrefixIfUnique)(name, paramNames) ?? name;
94
- const param = nameParamMap.get(pmatchName);
95
- if (param?.name) {
96
- const pid = param.name.info.id;
97
- graph.addEdge(argId, pid, edge_1.EdgeType.DefinesOnCall);
98
- graph.addEdge(pid, argId, edge_1.EdgeType.DefinedByOnCall);
99
- maps.set(argId, pid);
100
- matchedParameters.add(name);
101
- }
102
- else if (sid) {
103
- graph.addEdge(argId, sid, edge_1.EdgeType.DefinesOnCall);
104
- graph.addEdge(sid, argId, edge_1.EdgeType.DefinedByOnCall);
105
- maps.set(argId, sid);
106
- }
107
- }
108
- const remainingParameter = params.filter(p => !p?.name || !matchedParameters.has(p.name.content));
109
- const remainingArguments = args.filter(graph_1.FunctionArgument.isUnnamed);
110
- for (let i = 0; i < remainingArguments.length; i++) {
111
- const arg = remainingArguments[i];
86
+ for (let i = 0; i < args.length; i++) {
87
+ const arg = args[i];
112
88
  if (arg === r_function_call_1.EmptyArgument) {
113
89
  continue;
114
90
  }
91
+ const param = matched[i];
92
+ const pid = param === undefined ? undefined : params[param].name?.info.id;
115
93
  const aid = arg.nodeId;
116
- if (remainingParameter.length <= i) {
117
- if (sid) {
118
- graph.addEdge(aid, sid, edge_1.EdgeType.DefinesOnCall);
119
- graph.addEdge(sid, aid, edge_1.EdgeType.DefinedByOnCall);
120
- maps.set(aid, sid);
121
- }
122
- else {
123
- logger_1.dataflowLogger.warn(`skipping argument ${i} as there is no corresponding parameter - R should block that`);
124
- }
94
+ if (pid === undefined) {
95
+ logger_1.dataflowLogger.warn(`skipping argument ${i} (id: ${aid}) as there is no corresponding parameter - R should block that`);
125
96
  continue;
126
97
  }
127
- const param = remainingParameter[i];
128
- logger_1.dataflowLogger.trace(`mapping unnamed argument ${i} (id: ${aid}) to parameter "${param.name?.content ?? '??'}"`);
129
- if (param.name) {
130
- const pid = param.name.info.id;
131
- graph.addEdge(aid, pid, edge_1.EdgeType.DefinesOnCall);
132
- graph.addEdge(pid, aid, edge_1.EdgeType.DefinedByOnCall);
133
- maps.set(aid, pid);
134
- }
98
+ graph.addEdge(aid, pid, edge_1.EdgeType.DefinesOnCall);
99
+ graph.addEdge(pid, aid, edge_1.EdgeType.DefinedByOnCall);
100
+ maps.set(aid, pid);
135
101
  }
136
102
  return maps;
137
103
  }
138
104
  /**
139
- * Links the given arguments to the given parameters within the given graph by name only.
105
+ * {@link matchArgumentsToParameters|Matches} the arguments against a parameter specification, returning the
106
+ * arguments bound to each target. Unlike {@link linkArgumentsOnCall} this touches no graph, so it also works
107
+ * for a specification without parameters in the AST.
140
108
  * @example
141
109
  * ```ts
142
110
  * const parameterSpec = {
@@ -155,50 +123,21 @@ function linkArgumentsOnCall(args, params, graph) {
155
123
  * or convert them with {@link convertFnArguments}.
156
124
  */
157
125
  function pMatch(args, params) {
158
- const nameArgMap = new Map(args.filter(graph_1.FunctionArgument.isNamed).map(a => [a.name, a]));
159
- const maps = new Map();
160
- function addToMaps(key, value) {
161
- const e = maps.get(key);
162
- if (e) {
163
- e.push(value);
164
- }
165
- else {
166
- maps.set(key, [value]);
167
- }
168
- }
169
- const sid = params['...'];
170
126
  const paramNames = Object.keys(params);
171
- // all parameters matched by name
172
- const matchedParameters = new Set();
173
- // first map names
174
- for (const [name, { nodeId: argId }] of nameArgMap) {
175
- const pmatchName = (0, prefix_1.findByPrefixIfUnique)(name, paramNames) ?? name;
176
- const param = params[pmatchName];
177
- if (param) {
178
- addToMaps(param, argId);
179
- matchedParameters.add(name);
180
- }
181
- else if (sid) {
182
- addToMaps(sid, argId);
183
- }
184
- }
185
- const remainingParameter = paramNames.filter(p => !matchedParameters.has(p));
186
- const remainingArguments = args.filter(graph_1.FunctionArgument.isUnnamed);
187
- for (let i = 0; i < remainingArguments.length; i++) {
188
- const arg = remainingArguments[i];
189
- if (arg === r_function_call_1.EmptyArgument) {
127
+ const matched = (0, arg_matching_1.matchArgumentsToParameters)(argumentNames(args), paramNames);
128
+ const maps = new Map();
129
+ for (let i = 0; i < args.length; i++) {
130
+ const arg = args[i], param = matched[i];
131
+ if (arg === r_function_call_1.EmptyArgument || param === undefined) {
190
132
  continue;
191
133
  }
192
- const aid = arg.nodeId;
193
- if (remainingParameter.length <= i) {
194
- if (sid) {
195
- addToMaps(sid, aid);
196
- }
197
- continue;
134
+ const target = params[paramNames[param]];
135
+ const known = maps.get(target);
136
+ if (known) {
137
+ known.push(arg.nodeId);
198
138
  }
199
- const param = params[remainingParameter[i]];
200
- if (param) {
201
- addToMaps(param, aid);
139
+ else {
140
+ maps.set(target, [arg.nodeId]);
202
141
  }
203
142
  }
204
143
  return maps;
@@ -117,7 +117,7 @@ function processNumberBasedAccess(data, name, args, rootId, config, head) {
117
117
  const existing = data.environment.current.memory.get(':=');
118
118
  const outInfo = { definitionRootNodes: [] };
119
119
  const tableAssignId = node_id_1.NodeId.toBuiltIn(':=-table');
120
- data.environment.current.memory.set(':=', [{
120
+ data.environment.current.writableMemory.set(':=', [{
121
121
  type: identifier_1.ReferenceType.BuiltInFunction,
122
122
  definedAt: tableAssignId,
123
123
  cds: undefined,
@@ -128,7 +128,7 @@ function processNumberBasedAccess(data, name, args, rootId, config, head) {
128
128
  const fnCall = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: config.forceArgs, origin: built_in_proc_name_1.BuiltInProcName.Access });
129
129
  /* recover the environment */
130
130
  if (existing !== undefined) {
131
- data.environment.current.memory.set(':=', existing);
131
+ data.environment.current.writableMemory.set(':=', existing);
132
132
  }
133
133
  if (head.value && outInfo.definitionRootNodes.length > 0) {
134
134
  (0, built_in_assignment_1.markAsAssignment)(fnCall.information, { type: identifier_1.ReferenceType.Variable, name: head.value.lexeme ?? '', nodeId: head.value.info.id, definedAt: rootId, cds: [] }, outInfo.definitionRootNodes, rootId, data);