@eagleoutice/flowr 2.13.4 → 2.13.6

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 (133) hide show
  1. package/README.md +29 -29
  2. package/cli/repl/core.js +10 -2
  3. package/config.d.ts +4 -1
  4. package/config.js +10 -1
  5. package/control-flow/cfg-dead-code.js +19 -4
  6. package/control-flow/extract-cfg.js +12 -4
  7. package/dataflow/environments/built-in-config.d.ts +6 -3
  8. package/dataflow/environments/built-in-eval-name.d.ts +20 -0
  9. package/dataflow/environments/built-in-eval-name.js +25 -0
  10. package/dataflow/environments/built-in-props.d.ts +175 -0
  11. package/dataflow/environments/built-in-props.js +207 -0
  12. package/dataflow/environments/built-in.d.ts +26 -22
  13. package/dataflow/environments/built-in.js +37 -10
  14. package/dataflow/environments/default-builtin-config.d.ts +1068 -95
  15. package/dataflow/environments/default-builtin-config.js +549 -216
  16. package/dataflow/environments/identifier.d.ts +24 -1
  17. package/dataflow/environments/identifier.js +24 -2
  18. package/dataflow/environments/query-fn-props.d.ts +102 -0
  19. package/dataflow/environments/query-fn-props.js +188 -0
  20. package/dataflow/eval/resolve/alias-tracking.d.ts +6 -5
  21. package/dataflow/eval/resolve/alias-tracking.js +45 -12
  22. package/dataflow/eval/resolve/match-arguments.d.ts +15 -0
  23. package/dataflow/eval/resolve/match-arguments.js +77 -0
  24. package/dataflow/eval/resolve/resolve-numbers.d.ts +202 -0
  25. package/dataflow/eval/resolve/resolve-numbers.js +163 -0
  26. package/dataflow/eval/resolve/resolve-operators.d.ts +60 -0
  27. package/dataflow/eval/resolve/resolve-operators.js +115 -0
  28. package/dataflow/eval/resolve/resolve-strings.d.ts +98 -0
  29. package/dataflow/eval/resolve/resolve-strings.js +116 -0
  30. package/dataflow/eval/resolve/resolve.d.ts +5 -37
  31. package/dataflow/eval/resolve/resolve.js +56 -134
  32. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +5 -4
  34. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +1 -4
  35. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
  36. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +2 -1
  37. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  38. package/documentation/data/faq/faqs.js +11 -0
  39. package/documentation/doc-util/doc-types.js +1 -1
  40. package/documentation/wiki-analyzer.js +75 -0
  41. package/documentation/wiki-core.js +81 -16
  42. package/documentation/wiki-interface.js +3 -0
  43. package/linter/linter-rules.d.ts +10 -11
  44. package/linter/rules/deprecated-functions.js +5 -3
  45. package/linter/rules/function-finder-util.d.ts +2 -2
  46. package/linter/rules/function-finder-util.js +10 -3
  47. package/linter/rules/network-functions.d.ts +25 -5
  48. package/linter/rules/network-functions.js +51 -11
  49. package/linter/rules/problematic-inputs.d.ts +1 -1
  50. package/linter/rules/problematic-inputs.js +7 -1
  51. package/linter/rules/seeded-randomness.d.ts +5 -8
  52. package/linter/rules/seeded-randomness.js +18 -10
  53. package/linter/rules/unused-definition.js +29 -17
  54. package/package.json +4 -2
  55. package/project/cache/flowr-analyzer-cache.d.ts +4 -3
  56. package/project/cache/flowr-analyzer-cache.js +32 -13
  57. package/project/cache/flowr-cache.d.ts +39 -12
  58. package/project/cache/flowr-cache.js +5 -3
  59. package/project/context/flowr-analyzer-context.d.ts +8 -1
  60. package/project/context/flowr-analyzer-context.js +11 -1
  61. package/project/context/flowr-analyzer-dependencies-context.d.ts +8 -2
  62. package/project/context/flowr-analyzer-dependencies-context.js +43 -11
  63. package/project/context/flowr-analyzer-files-context.d.ts +8 -4
  64. package/project/context/flowr-analyzer-files-context.js +20 -1
  65. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +33 -0
  66. package/project/context/flowr-analyzer-incremental-analysis-context.js +63 -0
  67. package/project/context/flowr-analyzer-meta-context.d.ts +3 -1
  68. package/project/context/flowr-analyzer-meta-context.js +14 -0
  69. package/project/context/flowr-file.d.ts +25 -3
  70. package/project/context/flowr-file.js +24 -2
  71. package/project/dependency-version-space.d.ts +37 -0
  72. package/project/dependency-version-space.js +118 -26
  73. package/project/flowr-analyzer.d.ts +6 -0
  74. package/project/flowr-analyzer.js +6 -2
  75. package/project/incremental/incremental-parse/edit-computation.d.ts +7 -0
  76. package/project/incremental/incremental-parse/edit-computation.js +61 -0
  77. package/project/incremental/incremental-parse/incremental-parse.d.ts +12 -0
  78. package/project/incremental/incremental-parse/incremental-parse.js +37 -0
  79. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +1 -1
  80. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +57 -0
  81. package/project/plugins/file-plugins/files/flowr-manifest-files.js +121 -0
  82. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -2
  83. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +2 -2
  84. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +1 -1
  85. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +33 -0
  86. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +53 -0
  87. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  88. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  89. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +27 -0
  90. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +47 -0
  91. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +7 -0
  92. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -3
  93. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +10 -4
  94. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +17 -4
  95. package/project/plugins/plugin-registry.d.ts +4 -4
  96. package/project/plugins/plugin-registry.js +7 -4
  97. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  98. package/project/sigdb/reader.d.ts +7 -0
  99. package/project/sigdb/reader.js +12 -0
  100. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +10 -0
  101. package/queries/catalog/dependencies-query/function-info/derived-functions.js +41 -0
  102. package/queries/catalog/dependencies-query/function-info/read-functions.js +13 -12
  103. package/queries/catalog/dependencies-query/function-info/write-functions.js +16 -23
  104. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +33 -3
  105. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +31 -0
  106. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +9 -2
  107. package/queries/catalog/input-sources-query/input-source-functions.d.ts +8 -10
  108. package/queries/catalog/input-sources-query/input-source-functions.js +23 -388
  109. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -0
  110. package/queries/catalog/input-sources-query/input-sources-query-format.js +27 -10
  111. package/queries/catalog/signature-query/signature-query-executor.d.ts +2 -1
  112. package/queries/catalog/signature-query/signature-query-executor.js +79 -3
  113. package/queries/catalog/signature-query/signature-query-format.d.ts +27 -0
  114. package/queries/catalog/signature-query/signature-query-render.js +21 -3
  115. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +6 -2
  116. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +21 -2
  117. package/r-bridge/parser.d.ts +11 -1
  118. package/r-bridge/parser.js +7 -4
  119. package/r-bridge/shell-executor.d.ts +1 -0
  120. package/r-bridge/shell-executor.js +1 -0
  121. package/r-bridge/shell.d.ts +1 -0
  122. package/r-bridge/shell.js +1 -0
  123. package/search/flowr-search-filters.d.ts +1 -6
  124. package/search/flowr-search-filters.js +1 -8
  125. package/search/search-executor/search-enrichers.d.ts +2 -0
  126. package/search/search-executor/search-enrichers.js +29 -12
  127. package/util/version.js +1 -1
  128. package/project/plugins/file-plugins/files/flowr-rproject-file.d.ts +0 -31
  129. package/project/plugins/file-plugins/files/flowr-rproject-file.js +0 -66
  130. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.d.ts +0 -22
  131. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.js +0 -36
  132. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.d.ts +0 -13
  133. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.js +0 -32
@@ -51,6 +51,15 @@ export declare const Identifier: {
51
51
  * ```
52
52
  */
53
53
  readonly from: (this: void, arr: [BrandedIdentifier, BrandedNamespace] | [BrandedIdentifier, BrandedNamespace, boolean]) => Identifier;
54
+ /**
55
+ * The same fast path for many names of one package: the given array of names is cast in place,
56
+ * so the literal you pass is the only array involved.
57
+ * @example
58
+ * ```ts
59
+ * Identifier.fromAll('purrr', ['map', 'walk']) // [['map', 'purrr'], ['walk', 'purrr']]
60
+ * ```
61
+ */
62
+ readonly fromAll: (this: void, namespace: BrandedNamespace, names: BrandedIdentifier[]) => Identifier[];
54
63
  /**
55
64
  * Verify whether an unknown element has a valid identifier shape!
56
65
  */
@@ -92,6 +101,10 @@ export declare const Identifier: {
92
101
  * If the first identifier is internal, it will match any target (internal or not).
93
102
  */
94
103
  readonly matches: (this: void, id: Identifier, target: Identifier, s3?: boolean) => boolean;
104
+ /**
105
+ * Helper to create a regular expression that matches against an array of {@link Identifier} values. If both the passed identifier and the matched identifier are namespaced, their namespaces are expected to match. If either is not namespaced, the namespace is ignored on both.
106
+ */
107
+ readonly regex: (this: void, ...identifiers: readonly Identifier[]) => RegExp;
95
108
  /** Special identifier for the `...` argument */
96
109
  readonly dotdotdot: (this: void) => BrandedIdentifier;
97
110
  /**
@@ -140,6 +153,7 @@ export declare const enum PkgName {
140
153
  AssertThat = "assertthat",
141
154
  Box = "box",
142
155
  Cli = "cli",
156
+ CohortBuilder = "cohortBuilder",
143
157
  DataTable = "data.table",
144
158
  Devtools = "devtools",
145
159
  Dplyr = "dplyr",
@@ -160,17 +174,26 @@ export declare const enum PkgName {
160
174
  Ragg = "ragg",
161
175
  R6 = "R6",
162
176
  RasterPdf = "rasterpdf",
177
+ Rcpp = "Rcpp",
163
178
  Remotes = "remotes",
164
179
  Rlang = "rlang",
165
180
  RmethodsS3 = "R.methodsS3",
166
181
  Roo = "R.oo",
182
+ RstudioApi = "rstudioapi",
167
183
  Rutils = "R.utils",
168
184
  S7 = "S7",
185
+ Shiny = "shiny",
186
+ ShinyCohortBuilder = "shinyCohortBuilder",
187
+ ShinyFiles = "shinyFiles",
188
+ ShinyJs = "shinyjs",
169
189
  Soda = "SoDA",
190
+ SvDialogs = "svDialogs",
191
+ Tcltk = "tcltk",
170
192
  Testthat = "testthat",
171
193
  TidyR = "tidyr",
172
194
  TinyPlot = "tinyplot",
173
- TryCatchLog = "tryCatchLog"
195
+ TryCatchLog = "tryCatchLog",
196
+ Withr = "withr"
174
197
  }
175
198
  /**
176
199
  * Each reference has exactly one reference type, stored as the respective number.
@@ -47,6 +47,21 @@ exports.Identifier = {
47
47
  from(arr) {
48
48
  return arr;
49
49
  },
50
+ /**
51
+ * The same fast path for many names of one package: the given array of names is cast in place,
52
+ * so the literal you pass is the only array involved.
53
+ * @example
54
+ * ```ts
55
+ * Identifier.fromAll('purrr', ['map', 'walk']) // [['map', 'purrr'], ['walk', 'purrr']]
56
+ * ```
57
+ */
58
+ fromAll(namespace, names) {
59
+ const ids = names;
60
+ for (let i = 0; i < names.length; i++) {
61
+ ids[i] = [names[i], namespace];
62
+ }
63
+ return ids;
64
+ },
50
65
  /**
51
66
  * Verify whether an unknown element has a valid identifier shape!
52
67
  */
@@ -144,8 +159,15 @@ exports.Identifier = {
144
159
  if (idInternal === true) {
145
160
  return true;
146
161
  }
147
- const targetInternal = exports.Identifier.accessesInternal(target);
148
- return idInternal === targetInternal;
162
+ /* an omitted flag is the same as an explicit `false`, `pkg::fn` written either way is one identifier */
163
+ return (idInternal ?? false) === (exports.Identifier.accessesInternal(target) ?? false);
164
+ },
165
+ /**
166
+ * Helper to create a regular expression that matches against an array of {@link Identifier} values. If both the passed identifier and the matched identifier are namespaced, their namespaces are expected to match. If either is not namespaced, the namespace is ignored on both.
167
+ */
168
+ regex(...identifiers) {
169
+ // if the passed identifier is not namespaced, we match against *any* namespace. if it is namespaced, we match against the correct namespace or no namespace
170
+ return new RegExp(`^(${identifiers.map(i => `(${exports.Identifier.getNamespace(i) ?? '.+'}:::?)?${exports.Identifier.getName(i)}`).join('|')})$`);
149
171
  },
150
172
  /** Special identifier for the `...` argument */
151
173
  dotdotdot() {
@@ -0,0 +1,102 @@
1
+ import type { ArgProps, BuiltInFnInfo, CallProps, FnSig } from './built-in-props';
2
+ import type { BuiltIns } from './built-in';
3
+ import type { BuiltInDefinition, BuiltInDefinitions } from './built-in-config';
4
+ import type { REnvironmentInformation } from './environment';
5
+ import { Identifier } from './identifier';
6
+ import type { PackageSignatureSource } from '../../project/sigdb/reader';
7
+ /**
8
+ * Where to look up what flowR knows about a function, in that order:
9
+ * the name as it resolves here, the built-in definitions, and the signature database for the rest.
10
+ */
11
+ export interface FnPropsSource {
12
+ /** resolve the name here first, so a definition in the analyzed code shadows the built-in as it does in R */
13
+ readonly environment?: REnvironmentInformation;
14
+ /** consulted when there is no environment at hand */
15
+ readonly builtIns?: BuiltIns;
16
+ /** fills in what the built-in definitions do not state, for namespaced names */
17
+ readonly signatures?: PackageSignatureSource;
18
+ /** the package version to ask the signature database for (its latest by default) */
19
+ readonly version?: string;
20
+ }
21
+ /**
22
+ * What flowR knows about the function `name`: what the built-in definitions state, filled up with what the
23
+ * signature database knows (see {@link fnInfoFromSignature}). A declared signature wins, the properties of
24
+ * both are joined. `undefined` if neither has anything to say, and also if the name resolves to a definition
25
+ * in the analyzed code, which shadows any built-in.
26
+ */
27
+ export declare function queryFnProps(name: Identifier, { environment, builtIns, signatures, version }: FnPropsSource): BuiltInFnInfo | undefined;
28
+ /**
29
+ * What the signature database implies for a package function: what its own entry states
30
+ * (see {@link fnInfoFromSignature}) plus the {@link PropagatedProps} of everything it calls, transitively.
31
+ * A package function that ends up in `system()` runs a system command as well.
32
+ */
33
+ export declare function inferFnProps(src: PackageSignatureSource, pkg: string, name: string, version?: string): BuiltInFnInfo | undefined;
34
+ /** The identifiers a definition registers, with the suffixes of a replacement spelled out. */
35
+ export declare function builtInNames(definition: BuiltInDefinition): Identifier[];
36
+ /** One built-in as the {@link BuiltInIndex} sees it: the name it is registered under and what flowR states about it. */
37
+ export interface BuiltInEntry {
38
+ /** the identifier the built-in is registered under, with a replacement's suffix spelled out */
39
+ readonly name: Identifier;
40
+ /** the {@link CallProp} bits the definition states, `undefined` when it states none */
41
+ readonly props?: CallProps;
42
+ /** the declared parameters and what each of their arguments is used for */
43
+ readonly sig?: FnSig;
44
+ /** whether the value solver can fold a call of this built-in to a constant */
45
+ readonly folds: boolean;
46
+ }
47
+ /** One parameter of a built-in, as {@link BuiltInIndex#params} reports it. */
48
+ export interface BuiltInParam {
49
+ /** the built-in the parameter belongs to */
50
+ readonly call: Identifier;
51
+ /** the position it is declared at; a `...` parameter covers every position from here on */
52
+ readonly index: number;
53
+ readonly name: string;
54
+ readonly props: ArgProps;
55
+ }
56
+ /**
57
+ * The one place to ask what flowR's built-ins are: _every pure function_, _every call that reads a file_,
58
+ * _every parameter that names a resource_, _everything the value solver can fold_. Each answer is derived
59
+ * from the {@link BuiltInFnInfo} the definitions carry, so a built-in that states its {@link CallProp} bits and
60
+ * its {@link FnSig} is found here without anything else being registered.
61
+ *
62
+ * Build one over the {@link DefaultBuiltinConfig} with {@link BuiltInIndex.default} (computed once and shared),
63
+ * over your own definitions with {@link BuiltInIndex.of}, or over the built-ins an analysis actually registered
64
+ * with {@link BuiltInIndex.ofEnvironment}, which reflects configured overrides. For a single name (where a
65
+ * definition in the analyzed code shadows the built-in) use {@link queryFnProps} instead.
66
+ */
67
+ export declare class BuiltInIndex {
68
+ readonly entries: readonly BuiltInEntry[];
69
+ private readonly byName;
70
+ private readonly cache;
71
+ private constructor();
72
+ /** The index of flowR's own {@link DefaultBuiltinConfig}, computed on first use and shared from then on. */
73
+ static default(): BuiltInIndex;
74
+ /** The index of a set of built-in definitions, e.g. the ones a flowR config adds. */
75
+ static of(definitions: BuiltInDefinitions): BuiltInIndex;
76
+ /** The index of the built-ins an analysis registered, so a configured or overwritten built-in is what shows up. */
77
+ static ofEnvironment(builtIns: BuiltIns): BuiltInIndex;
78
+ /** answers are keyed by what was asked, as every caller asks the same handful of questions over and over */
79
+ private cached;
80
+ /** Every built-in whose props carry at least one bit of `props`, like {@link CallProp.File} for the file calls. */
81
+ with(props: CallProps): readonly Identifier[];
82
+ /**
83
+ * Every built-in whose props carry *every* bit of `props`, for the questions a single bit cannot answer,
84
+ * like {@link FileInputProps} for the calls that read a file rather than only write one.
85
+ */
86
+ withAll(props: CallProps): readonly Identifier[];
87
+ /**
88
+ * Every built-in that states its props but carries no bit of `props`. With {@link InputProps} this yields
89
+ * the calls that derive their result from their arguments alone.
90
+ */
91
+ without(props: CallProps): readonly Identifier[];
92
+ /** Every built-in flowR states computes a result and nothing else ({@link CallProp.Pure}). */
93
+ get pure(): readonly Identifier[];
94
+ /** Every built-in the value solver can fold to a constant (the ones with a `evalHandler`). */
95
+ get folding(): readonly Identifier[];
96
+ /** Every parameter whose argument carries at least one bit of `props`, like {@link ArgProp.Resource}. */
97
+ params(props: ArgProps): BuiltInParam[];
98
+ /** What the index states about `name`, ignoring any namespace (built-ins are registered by their bare name). */
99
+ get(name: Identifier): BuiltInEntry | undefined;
100
+ /** The {@link CallProp} bits of `name`, `undefined` when no built-in of that name states any. */
101
+ propsOf(name: Identifier): CallProps | undefined;
102
+ }
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuiltInIndex = void 0;
4
+ exports.queryFnProps = queryFnProps;
5
+ exports.inferFnProps = inferFnProps;
6
+ exports.builtInNames = builtInNames;
7
+ const built_in_props_1 = require("./built-in-props");
8
+ const default_builtin_config_1 = require("./default-builtin-config");
9
+ const identifier_1 = require("./identifier");
10
+ const resolve_by_name_1 = require("./resolve-by-name");
11
+ function ofDefinitions(definitions) {
12
+ let sig, props;
13
+ for (const d of definitions ?? []) {
14
+ if (d.type !== identifier_1.ReferenceType.BuiltInFunction) {
15
+ continue;
16
+ }
17
+ const info = d.config;
18
+ sig ??= info?.sig;
19
+ props = info?.props === undefined ? props : (props ?? 0) | info.props;
20
+ }
21
+ return sig === undefined && props === undefined ? undefined : { sig, props };
22
+ }
23
+ /**
24
+ * What flowR knows about the function `name`: what the built-in definitions state, filled up with what the
25
+ * signature database knows (see {@link fnInfoFromSignature}). A declared signature wins, the properties of
26
+ * both are joined. `undefined` if neither has anything to say, and also if the name resolves to a definition
27
+ * in the analyzed code, which shadows any built-in.
28
+ */
29
+ function queryFnProps(name, { environment, builtIns, signatures, version }) {
30
+ let info;
31
+ if (environment !== undefined) {
32
+ const resolved = (0, resolve_by_name_1.resolveByName)(name, environment, identifier_1.ReferenceType.Function);
33
+ if (resolved?.some(d => d.type !== identifier_1.ReferenceType.BuiltInFunction)) {
34
+ return undefined;
35
+ }
36
+ info = ofDefinitions(resolved);
37
+ }
38
+ else if (builtIns !== undefined) {
39
+ info = ofDefinitions(builtIns.builtInMemory.get(identifier_1.Identifier.getName(name)));
40
+ }
41
+ const pkg = identifier_1.Identifier.getNamespace(name);
42
+ if (signatures === undefined || pkg === undefined) {
43
+ return info;
44
+ }
45
+ const known = inferFnProps(signatures, pkg, identifier_1.Identifier.getName(name), version);
46
+ if (known === undefined) {
47
+ return info;
48
+ }
49
+ return { sig: info?.sig ?? known.sig, props: (info?.props ?? 0) | (known.props ?? 0) };
50
+ }
51
+ /**
52
+ * What the signature database implies for a package function: what its own entry states
53
+ * (see {@link fnInfoFromSignature}) plus the {@link PropagatedProps} of everything it calls, transitively.
54
+ * A package function that ends up in `system()` runs a system command as well.
55
+ */
56
+ function inferFnProps(src, pkg, name, version) {
57
+ const fn = src.functionByName(pkg, name, version);
58
+ if (fn === undefined) {
59
+ return undefined;
60
+ }
61
+ const own = (0, built_in_props_1.fnInfoFromSignature)(fn);
62
+ const known = BuiltInIndex.default();
63
+ let props = own.props ?? 0;
64
+ for (const callee of src.transitiveCallees(pkg, name, version) ?? fn.callees) {
65
+ props |= (known.propsOf(callee) ?? 0) & built_in_props_1.PropagatedProps;
66
+ }
67
+ return { sig: own.sig, props };
68
+ }
69
+ /** The identifiers a definition registers, with the suffixes of a replacement spelled out. */
70
+ function builtInNames(definition) {
71
+ if (definition.type !== 'replacement') {
72
+ return definition.names;
73
+ }
74
+ return definition.names.flatMap(n => definition.suffixes.map(s => identifier_1.Identifier.make(`${identifier_1.Identifier.getName(n)}${s}`, identifier_1.Identifier.getNamespace(n))));
75
+ }
76
+ function entryOfDefinition(definition) {
77
+ if (definition.type === 'constant') {
78
+ return [];
79
+ }
80
+ const info = definition.config;
81
+ const folds = definition.type === 'function' && definition.evalHandler !== undefined;
82
+ return builtInNames(definition).map(name => ({ name, props: info?.props, sig: info?.sig, folds }));
83
+ }
84
+ function entriesOfMemory(builtIns) {
85
+ const out = [];
86
+ for (const [registered, definitions] of builtIns.builtInMemory) {
87
+ for (const d of definitions) {
88
+ if (d.type !== identifier_1.ReferenceType.BuiltInFunction) {
89
+ continue;
90
+ }
91
+ const info = d.config;
92
+ /* the memory is keyed by the bare name, the definition keeps the namespace it was declared with */
93
+ out.push({ name: d.name ?? registered, props: info?.props, sig: info?.sig, folds: d.evalHandler !== undefined });
94
+ }
95
+ }
96
+ return out;
97
+ }
98
+ let defaultIndex;
99
+ /**
100
+ * The one place to ask what flowR's built-ins are: _every pure function_, _every call that reads a file_,
101
+ * _every parameter that names a resource_, _everything the value solver can fold_. Each answer is derived
102
+ * from the {@link BuiltInFnInfo} the definitions carry, so a built-in that states its {@link CallProp} bits and
103
+ * its {@link FnSig} is found here without anything else being registered.
104
+ *
105
+ * Build one over the {@link DefaultBuiltinConfig} with {@link BuiltInIndex.default} (computed once and shared),
106
+ * over your own definitions with {@link BuiltInIndex.of}, or over the built-ins an analysis actually registered
107
+ * with {@link BuiltInIndex.ofEnvironment}, which reflects configured overrides. For a single name (where a
108
+ * definition in the analyzed code shadows the built-in) use {@link queryFnProps} instead.
109
+ */
110
+ class BuiltInIndex {
111
+ entries;
112
+ byName = new Map();
113
+ cache = new Map();
114
+ constructor(entries) {
115
+ this.entries = entries;
116
+ for (const e of entries) {
117
+ this.byName.set(identifier_1.Identifier.getName(e.name), e);
118
+ }
119
+ }
120
+ /** The index of flowR's own {@link DefaultBuiltinConfig}, computed on first use and shared from then on. */
121
+ static default() {
122
+ return defaultIndex ??= BuiltInIndex.of(default_builtin_config_1.DefaultBuiltinConfig);
123
+ }
124
+ /** The index of a set of built-in definitions, e.g. the ones a flowR config adds. */
125
+ static of(definitions) {
126
+ return new BuiltInIndex(definitions.flatMap(entryOfDefinition));
127
+ }
128
+ /** The index of the built-ins an analysis registered, so a configured or overwritten built-in is what shows up. */
129
+ static ofEnvironment(builtIns) {
130
+ return new BuiltInIndex(entriesOfMemory(builtIns));
131
+ }
132
+ /** answers are keyed by what was asked, as every caller asks the same handful of questions over and over */
133
+ cached(key, filter) {
134
+ let found = this.cache.get(key);
135
+ if (found === undefined) {
136
+ this.cache.set(key, found = this.entries.filter(filter).map(e => e.name));
137
+ }
138
+ return found;
139
+ }
140
+ /** Every built-in whose props carry at least one bit of `props`, like {@link CallProp.File} for the file calls. */
141
+ with(props) {
142
+ return this.cached(`with:${props}`, e => ((e.props ?? 0) & props) !== 0);
143
+ }
144
+ /**
145
+ * Every built-in whose props carry *every* bit of `props`, for the questions a single bit cannot answer,
146
+ * like {@link FileInputProps} for the calls that read a file rather than only write one.
147
+ */
148
+ withAll(props) {
149
+ return this.cached(`all:${props}`, e => e.props !== undefined && (e.props & props) === props);
150
+ }
151
+ /**
152
+ * Every built-in that states its props but carries no bit of `props`. With {@link InputProps} this yields
153
+ * the calls that derive their result from their arguments alone.
154
+ */
155
+ without(props) {
156
+ return this.cached(`without:${props}`, e => e.props !== undefined && (e.props & props) === 0);
157
+ }
158
+ /** Every built-in flowR states computes a result and nothing else ({@link CallProp.Pure}). */
159
+ get pure() {
160
+ return this.with(built_in_props_1.CallProp.Pure);
161
+ }
162
+ /** Every built-in the value solver can fold to a constant (the ones with a `evalHandler`). */
163
+ get folding() {
164
+ return this.cached('folding', e => e.folds);
165
+ }
166
+ /** Every parameter whose argument carries at least one bit of `props`, like {@link ArgProp.Resource}. */
167
+ params(props) {
168
+ const found = [];
169
+ for (const e of this.entries) {
170
+ e.sig?.forEach(([name, p], index) => {
171
+ if ((p & props) !== 0) {
172
+ found.push({ call: e.name, index, name, props: p });
173
+ }
174
+ });
175
+ }
176
+ return found;
177
+ }
178
+ /** What the index states about `name`, ignoring any namespace (built-ins are registered by their bare name). */
179
+ get(name) {
180
+ return this.byName.get(identifier_1.Identifier.getName(name));
181
+ }
182
+ /** The {@link CallProp} bits of `name`, `undefined` when no built-in of that name states any. */
183
+ propsOf(name) {
184
+ return this.get(name)?.props;
185
+ }
186
+ }
187
+ exports.BuiltInIndex = BuiltInIndex;
188
+ //# sourceMappingURL=query-fn-props.js.map
@@ -76,13 +76,14 @@ export declare function trackAliasInEnvironments(identifier: Identifier | undefi
76
76
  * Please use {@link resolveIdToValue}
77
77
  *
78
78
  * Tries to resolve the value of a node by traversing the dataflow graph
79
- * @param id - node to resolve
80
- * @param ctx - analysis context
81
- * @param graph - dataflow graph
82
- * @param idMap - idmap of dataflow graph
79
+ * @param id - node to resolve
80
+ * @param ctx - analysis context
81
+ * @param graph - dataflow graph
82
+ * @param idMap - idmap of dataflow graph
83
+ * @param blocked - the ids already being resolved, so a cyclic definition stops
83
84
  * @returns Value of node or Top/Bottom
84
85
  */
85
- export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext, idMap?: AstIdMap): ResolveResult;
86
+ export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext, idMap?: AstIdMap, blocked?: Set<NodeId>): ResolveResult;
86
87
  /**
87
88
  * Please use {@link resolveIdToValue}
88
89
  *
@@ -30,7 +30,9 @@ const AliasHandler = {
30
30
  [vertex_1.VertexType.VariableDefinition]: () => undefined
31
31
  };
32
32
  function getFunctionCallAlias(sourceId, dataflow, environment) {
33
- const identifier = (0, node_id_1.recoverName)(sourceId, dataflow.idMap);
33
+ const vertex = dataflow.getVertex(sourceId);
34
+ /* the lexeme of an infix call like `a %% b` is the whole expression, so we prefer the effective name of the vertex */
35
+ const identifier = vertex?.tag === vertex_1.VertexType.FunctionCall ? vertex.name : (0, node_id_1.recoverName)(sourceId, dataflow.idMap);
34
36
  if (identifier === undefined) {
35
37
  return undefined;
36
38
  }
@@ -144,7 +146,7 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, ctx, res
144
146
  return trackAliasInEnvironments(identifier_1.Identifier.toString(node.content), environment, { idMap, resolve, ctx, graph, blocked });
145
147
  }
146
148
  else if (graph && resolve === config_1.VariableResolve.Alias) {
147
- return trackAliasesInGraph(node.info.id, graph, ctx, idMap);
149
+ return trackAliasesInGraph(node.info.id, graph, ctx, idMap, blocked);
148
150
  }
149
151
  }
150
152
  return r_value_1.Top;
@@ -153,6 +155,7 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, ctx, res
153
155
  case type_1.RType.FunctionCall:
154
156
  case type_1.RType.BinaryOp:
155
157
  case type_1.RType.UnaryOp:
158
+ case type_1.RType.ExpressionList:
156
159
  return (0, set_constants_1.setFrom)((0, resolve_1.resolveNode)({
157
160
  resolve, node, ctx, environment, graph, idMap, blocked
158
161
  }));
@@ -204,7 +207,15 @@ function trackAliasInEnvironments(identifier, environment, { blocked, idMap, res
204
207
  for (const alias of def.value) {
205
208
  const definitionOfAlias = idMap?.get(alias);
206
209
  if (definitionOfAlias !== undefined) {
207
- const value = (0, resolve_1.resolveNode)({ resolve, node: definitionOfAlias, ctx, environment, graph, idMap, blocked });
210
+ /* the environment attempt below marks what it visited as blocked, so the retry starts from a copy */
211
+ const beforeAttempt = blocked === undefined ? undefined : new Set(blocked);
212
+ let value = (0, resolve_1.resolveNode)({ resolve, node: definitionOfAlias, ctx, environment, graph, idMap, blocked });
213
+ if ((0, r_value_1.isTop)(value) && graph?.unknownSideEffects.size === 0) {
214
+ /* `x <- x + 1`: the environment holds only the definition we are resolving, so its own operand
215
+ * finds nothing there, while the graph still knows which definition that operand reads. Only
216
+ * when nothing unknown happened, as then the environment is right to give up */
217
+ value = (0, resolve_1.resolveNode)({ resolve, node: definitionOfAlias, ctx, graph, idMap, blocked: beforeAttempt });
218
+ }
208
219
  if ((0, r_value_1.isTop)(value)) {
209
220
  return r_value_1.Top;
210
221
  }
@@ -255,17 +266,23 @@ function trackAliasInEnvironments(identifier, environment, { blocked, idMap, res
255
266
  function isNestedInLoop(node, ast) {
256
267
  return model_1.RNode.iterateParents(node, ast).some(model_1.RLoopConstructs.is);
257
268
  }
269
+ /** whether the node is (or sits in) a parameter's default, which any call site may override */
270
+ function isParameterDefault(node, idMap) {
271
+ return node !== undefined && (node.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */
272
+ || model_1.RNode.iterateParents(node, idMap).some(p => p.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */));
273
+ }
258
274
  /**
259
275
  * Please use {@link resolveIdToValue}
260
276
  *
261
277
  * Tries to resolve the value of a node by traversing the dataflow graph
262
- * @param id - node to resolve
263
- * @param ctx - analysis context
264
- * @param graph - dataflow graph
265
- * @param idMap - idmap of dataflow graph
278
+ * @param id - node to resolve
279
+ * @param ctx - analysis context
280
+ * @param graph - dataflow graph
281
+ * @param idMap - idmap of dataflow graph
282
+ * @param blocked - the ids already being resolved, so a cyclic definition stops
266
283
  * @returns Value of node or Top/Bottom
267
284
  */
268
- function trackAliasesInGraph(id, graph, ctx, idMap) {
285
+ function trackAliasesInGraph(id, graph, ctx, idMap, blocked) {
269
286
  if (!graph.get(id)) {
270
287
  return r_value_1.Bottom;
271
288
  }
@@ -277,6 +294,8 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
277
294
  queue.add(id, clean, cleanFingerprint, false);
278
295
  let forceTop = false;
279
296
  const resultIds = [];
297
+ /* what a call the walk ended in folds to, see below */
298
+ const folded = [];
280
299
  while (queue.nonEmpty()) {
281
300
  const { id, baseEnvironment } = queue.next();
282
301
  const vertex = graph.getVertex(id);
@@ -301,6 +320,11 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
301
320
  break;
302
321
  }
303
322
  const t = vertex.tag;
323
+ /* a replacement (`df[1] <- v`) defines its target from just a part of it, so what it is defined by is not
324
+ * the value of the target */
325
+ if (t === vertex_1.VertexType.VariableDefinition && idMap.get(id)?.info.role === "acc" /* RoleInParent.Accessed */) {
326
+ return r_value_1.Top;
327
+ }
304
328
  if (t === vertex_1.VertexType.Value || t === vertex_1.VertexType.FunctionDefinition) {
305
329
  resultIds.push(id);
306
330
  continue;
@@ -323,13 +347,22 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
323
347
  }
324
348
  }
325
349
  if (isFn && !foundRetuns) {
326
- return r_value_1.Top;
350
+ /* a call that hands back none of its arguments has no `Returns` edge to follow, yet the value solver may
351
+ * well know what it produces (`p <- file.path("data", "x.csv")`), so we fold it instead of giving up */
352
+ const node = idMap.get(id);
353
+ const values = isParameterDefault(node, idMap) ? undefined
354
+ : (0, general_1.valueSetGuard)(resolveIdToValue(node, { graph, idMap, ctx, resolve: config_1.VariableResolve.Alias, blocked }));
355
+ if (values === undefined || values.elements.some(r_value_1.isTop)) {
356
+ return r_value_1.Top;
357
+ }
358
+ folded.push(...values.elements);
359
+ continue;
327
360
  }
328
361
  }
329
- if (forceTop || resultIds.length === 0) {
362
+ if (forceTop || (resultIds.length === 0 && folded.length === 0)) {
330
363
  return r_value_1.Top;
331
364
  }
332
- const values = new Set();
365
+ const values = new Set(folded);
333
366
  for (const id of resultIds) {
334
367
  const vertex = graph.getVertex(id);
335
368
  if (vertex_1.ValueVertex.is(vertex) && vertex.value !== undefined) {
@@ -338,7 +371,7 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
338
371
  }
339
372
  const node = idMap.get(id);
340
373
  if (node !== undefined) {
341
- if (node.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */ || model_1.RNode.iterateParents(node, idMap).some(p => p.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */)) {
374
+ if (isParameterDefault(node, idMap)) {
342
375
  return r_value_1.Top;
343
376
  }
344
377
  values.add((0, general_1.valueFromRNodeConstant)(node));
@@ -0,0 +1,15 @@
1
+ import type { RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
+ /** what one declared parameter was given: nothing, one argument, or -- for `...` -- every argument it collected */
3
+ export type MatchedArgument = RNodeWithParent | readonly RNodeWithParent[] | undefined;
4
+ /**
5
+ * The arguments of a call, one slot per declared parameter, matched the way R does: a named argument goes to
6
+ * the parameter it names, the rest fill the remaining slots left to right, and a `...` parameter collects
7
+ * everything that is left over (positional arguments from its position on, and named ones matching no other
8
+ * parameter). Parameters in `ignored` may be supplied but get no slot, for the ones that change nothing about
9
+ * what the call yields.
10
+ *
11
+ * `undefined` when the call cannot be the one `params` describes: an argument that names an unknown parameter
12
+ * with no `...` to absorb it, one parameter given twice, or more arguments than there are slots. The value
13
+ * solver relies on that, since a call it cannot match is one whose result it must not guess at.
14
+ */
15
+ export declare function matchCallArguments(node: RNodeWithParent, params: readonly string[], ignored?: readonly string[]): MatchedArgument[] | undefined;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchCallArguments = matchCallArguments;
4
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
5
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
6
+ /**
7
+ * The arguments of a call, one slot per declared parameter, matched the way R does: a named argument goes to
8
+ * the parameter it names, the rest fill the remaining slots left to right, and a `...` parameter collects
9
+ * everything that is left over (positional arguments from its position on, and named ones matching no other
10
+ * parameter). Parameters in `ignored` may be supplied but get no slot, for the ones that change nothing about
11
+ * what the call yields.
12
+ *
13
+ * `undefined` when the call cannot be the one `params` describes: an argument that names an unknown parameter
14
+ * with no `...` to absorb it, one parameter given twice, or more arguments than there are slots. The value
15
+ * solver relies on that, since a call it cannot match is one whose result it must not guess at.
16
+ */
17
+ function matchCallArguments(node, params, ignored = []) {
18
+ if (node.type === type_1.RType.UnaryOp) {
19
+ return [node.operand];
20
+ }
21
+ else if (node.type === type_1.RType.BinaryOp) {
22
+ return [node.lhs, node.rhs];
23
+ }
24
+ else if (node.type !== type_1.RType.FunctionCall || !node.named) {
25
+ return undefined;
26
+ }
27
+ const rest = params.indexOf('...');
28
+ const matched = params.map(() => undefined);
29
+ // what `...` collects, remembered with the position it was written at, since R keeps them in source order
30
+ const collected = [];
31
+ const positional = [];
32
+ // R matches every named argument before it gives a slot to a positional one, so this takes two passes
33
+ for (const [at, arg] of node.arguments.entries()) {
34
+ if (arg === r_function_call_1.EmptyArgument || arg.value === undefined) {
35
+ continue;
36
+ }
37
+ else if (arg.name === undefined) {
38
+ positional.push({ at, value: arg.value });
39
+ continue;
40
+ }
41
+ const name = arg.name.content;
42
+ if (ignored.includes(name)) {
43
+ continue;
44
+ }
45
+ const to = params.indexOf(name);
46
+ if (to >= 0 && to !== rest) {
47
+ if (matched[to] !== undefined) {
48
+ return undefined; // the same parameter twice, which R would reject too
49
+ }
50
+ matched[to] = arg.value;
51
+ }
52
+ else if (rest >= 0) {
53
+ collected.push({ at, value: arg.value }); // a name no parameter carries falls into `...`, as it does in R
54
+ }
55
+ else {
56
+ return undefined;
57
+ }
58
+ }
59
+ // the slots before `...` take positional arguments in order, everything from there on `...` collects
60
+ for (const entry of positional) {
61
+ const free = matched.findIndex((m, i) => m === undefined && i !== rest);
62
+ if (free >= 0 && (rest < 0 || free < rest)) {
63
+ matched[free] = entry.value;
64
+ }
65
+ else if (rest >= 0) {
66
+ collected.push(entry);
67
+ }
68
+ else {
69
+ return undefined; // more arguments than the parameters describe, so this is another call
70
+ }
71
+ }
72
+ if (rest >= 0) {
73
+ matched[rest] = collected.sort((a, b) => a.at - b.at).map(e => e.value);
74
+ }
75
+ return matched;
76
+ }
77
+ //# sourceMappingURL=match-arguments.js.map