@eagleoutice/flowr 2.13.4 → 2.13.5

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 (130) hide show
  1. package/README.md +31 -31
  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 +1046 -93
  15. package/dataflow/environments/default-builtin-config.js +485 -213
  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.js +4 -1
  21. package/dataflow/eval/resolve/match-arguments.d.ts +15 -0
  22. package/dataflow/eval/resolve/match-arguments.js +77 -0
  23. package/dataflow/eval/resolve/resolve-numbers.d.ts +202 -0
  24. package/dataflow/eval/resolve/resolve-numbers.js +163 -0
  25. package/dataflow/eval/resolve/resolve-operators.d.ts +60 -0
  26. package/dataflow/eval/resolve/resolve-operators.js +115 -0
  27. package/dataflow/eval/resolve/resolve-strings.d.ts +98 -0
  28. package/dataflow/eval/resolve/resolve-strings.js +116 -0
  29. package/dataflow/eval/resolve/resolve.d.ts +5 -37
  30. package/dataflow/eval/resolve/resolve.js +56 -134
  31. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -1
  32. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +5 -4
  33. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
  34. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +2 -1
  35. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  36. package/documentation/data/faq/faqs.js +11 -0
  37. package/documentation/doc-util/doc-types.js +1 -1
  38. package/documentation/wiki-analyzer.js +75 -0
  39. package/documentation/wiki-core.js +65 -16
  40. package/documentation/wiki-interface.js +3 -0
  41. package/linter/linter-rules.d.ts +10 -11
  42. package/linter/rules/deprecated-functions.js +5 -3
  43. package/linter/rules/function-finder-util.d.ts +2 -2
  44. package/linter/rules/function-finder-util.js +10 -3
  45. package/linter/rules/network-functions.d.ts +25 -5
  46. package/linter/rules/network-functions.js +51 -11
  47. package/linter/rules/problematic-inputs.d.ts +1 -1
  48. package/linter/rules/problematic-inputs.js +7 -1
  49. package/linter/rules/seeded-randomness.d.ts +5 -8
  50. package/linter/rules/seeded-randomness.js +17 -9
  51. package/package.json +3 -2
  52. package/project/cache/flowr-analyzer-cache.d.ts +4 -3
  53. package/project/cache/flowr-analyzer-cache.js +32 -13
  54. package/project/cache/flowr-cache.d.ts +39 -12
  55. package/project/cache/flowr-cache.js +5 -3
  56. package/project/context/flowr-analyzer-context.d.ts +8 -1
  57. package/project/context/flowr-analyzer-context.js +11 -1
  58. package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -2
  59. package/project/context/flowr-analyzer-dependencies-context.js +15 -1
  60. package/project/context/flowr-analyzer-files-context.d.ts +8 -4
  61. package/project/context/flowr-analyzer-files-context.js +20 -1
  62. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +33 -0
  63. package/project/context/flowr-analyzer-incremental-analysis-context.js +63 -0
  64. package/project/context/flowr-analyzer-meta-context.d.ts +3 -1
  65. package/project/context/flowr-analyzer-meta-context.js +14 -0
  66. package/project/context/flowr-file.d.ts +25 -3
  67. package/project/context/flowr-file.js +24 -2
  68. package/project/dependency-version-space.d.ts +37 -0
  69. package/project/dependency-version-space.js +118 -26
  70. package/project/flowr-analyzer.d.ts +6 -0
  71. package/project/flowr-analyzer.js +6 -2
  72. package/project/incremental/incremental-parse/edit-computation.d.ts +7 -0
  73. package/project/incremental/incremental-parse/edit-computation.js +61 -0
  74. package/project/incremental/incremental-parse/incremental-parse.d.ts +12 -0
  75. package/project/incremental/incremental-parse/incremental-parse.js +37 -0
  76. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +1 -1
  77. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +57 -0
  78. package/project/plugins/file-plugins/files/flowr-manifest-files.js +121 -0
  79. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -2
  80. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +2 -2
  81. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +1 -1
  82. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +33 -0
  83. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +53 -0
  84. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  85. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  86. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +27 -0
  87. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +47 -0
  88. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +7 -0
  89. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -3
  90. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +10 -4
  91. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +17 -4
  92. package/project/plugins/plugin-registry.d.ts +4 -4
  93. package/project/plugins/plugin-registry.js +7 -4
  94. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  95. package/project/sigdb/reader.d.ts +7 -0
  96. package/project/sigdb/reader.js +12 -0
  97. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +10 -0
  98. package/queries/catalog/dependencies-query/function-info/derived-functions.js +41 -0
  99. package/queries/catalog/dependencies-query/function-info/read-functions.js +13 -12
  100. package/queries/catalog/dependencies-query/function-info/write-functions.js +16 -23
  101. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +33 -3
  102. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +31 -0
  103. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +9 -2
  104. package/queries/catalog/input-sources-query/input-source-functions.d.ts +8 -10
  105. package/queries/catalog/input-sources-query/input-source-functions.js +23 -388
  106. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -0
  107. package/queries/catalog/input-sources-query/input-sources-query-format.js +27 -10
  108. package/queries/catalog/signature-query/signature-query-executor.d.ts +2 -1
  109. package/queries/catalog/signature-query/signature-query-executor.js +79 -3
  110. package/queries/catalog/signature-query/signature-query-format.d.ts +27 -0
  111. package/queries/catalog/signature-query/signature-query-render.js +21 -3
  112. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +6 -2
  113. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +21 -2
  114. package/r-bridge/parser.d.ts +11 -1
  115. package/r-bridge/parser.js +7 -4
  116. package/r-bridge/shell-executor.d.ts +1 -0
  117. package/r-bridge/shell-executor.js +1 -0
  118. package/r-bridge/shell.d.ts +1 -0
  119. package/r-bridge/shell.js +1 -0
  120. package/search/flowr-search-filters.d.ts +1 -6
  121. package/search/flowr-search-filters.js +1 -8
  122. package/search/search-executor/search-enrichers.d.ts +2 -0
  123. package/search/search-executor/search-enrichers.js +29 -12
  124. package/util/version.js +1 -1
  125. package/project/plugins/file-plugins/files/flowr-rproject-file.d.ts +0 -31
  126. package/project/plugins/file-plugins/files/flowr-rproject-file.js +0 -66
  127. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.d.ts +0 -22
  128. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.js +0 -36
  129. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.d.ts +0 -13
  130. 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
@@ -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
  }
@@ -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
  }));
@@ -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