@eagleoutice/flowr 2.13.3 → 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 (176) hide show
  1. package/README.md +32 -32
  2. package/abstract-interpretation/absint-visitor.js +2 -2
  3. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  4. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +1 -1
  5. package/abstract-interpretation/unsupported-functions.js +1 -1
  6. package/cli/repl/core.js +10 -2
  7. package/config.d.ts +4 -1
  8. package/config.js +10 -1
  9. package/control-flow/cfg-dead-code.js +91 -15
  10. package/control-flow/extract-cfg.js +93 -8
  11. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  12. package/dataflow/environments/built-in-config.d.ts +6 -3
  13. package/dataflow/environments/built-in-eval-name.d.ts +20 -0
  14. package/dataflow/environments/built-in-eval-name.js +25 -0
  15. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  16. package/dataflow/environments/built-in-proc-name.js +4 -0
  17. package/dataflow/environments/built-in-props.d.ts +175 -0
  18. package/dataflow/environments/built-in-props.js +207 -0
  19. package/dataflow/environments/built-in.d.ts +28 -20
  20. package/dataflow/environments/built-in.js +39 -8
  21. package/dataflow/environments/default-builtin-config.d.ts +1094 -86
  22. package/dataflow/environments/default-builtin-config.js +496 -212
  23. package/dataflow/environments/identifier.d.ts +25 -1
  24. package/dataflow/environments/identifier.js +24 -2
  25. package/dataflow/environments/query-fn-props.d.ts +102 -0
  26. package/dataflow/environments/query-fn-props.js +188 -0
  27. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
  28. package/dataflow/eval/resolve/alias-tracking.js +12 -2
  29. package/dataflow/eval/resolve/match-arguments.d.ts +15 -0
  30. package/dataflow/eval/resolve/match-arguments.js +77 -0
  31. package/dataflow/eval/resolve/resolve-numbers.d.ts +202 -0
  32. package/dataflow/eval/resolve/resolve-numbers.js +163 -0
  33. package/dataflow/eval/resolve/resolve-operators.d.ts +60 -0
  34. package/dataflow/eval/resolve/resolve-operators.js +115 -0
  35. package/dataflow/eval/resolve/resolve-strings.d.ts +98 -0
  36. package/dataflow/eval/resolve/resolve-strings.js +116 -0
  37. package/dataflow/eval/resolve/resolve.d.ts +5 -23
  38. package/dataflow/eval/resolve/resolve.js +56 -87
  39. package/dataflow/fn/higher-order-function.js +3 -3
  40. package/dataflow/fn/recursive-function.js +1 -1
  41. package/dataflow/graph/df-helper.js +1 -1
  42. package/dataflow/graph/vertex.d.ts +32 -25
  43. package/dataflow/graph/vertex.js +40 -36
  44. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  45. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  46. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  47. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  48. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  49. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  50. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
  52. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -0
  53. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
  54. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  55. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  56. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
  57. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  58. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  59. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  60. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
  61. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
  62. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
  63. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
  64. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +2 -1
  65. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  66. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  67. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  68. package/documentation/data/faq/faqs.js +11 -0
  69. package/documentation/doc-util/doc-types.js +1 -1
  70. package/documentation/wiki-analyzer.js +75 -0
  71. package/documentation/wiki-core.js +65 -16
  72. package/documentation/wiki-interface.js +3 -0
  73. package/linter/linter-rules.d.ts +10 -11
  74. package/linter/rules/absolute-path.js +1 -1
  75. package/linter/rules/deprecated-functions.js +5 -3
  76. package/linter/rules/function-finder-util.d.ts +2 -2
  77. package/linter/rules/function-finder-util.js +11 -4
  78. package/linter/rules/network-functions.d.ts +25 -5
  79. package/linter/rules/network-functions.js +51 -11
  80. package/linter/rules/no-leaked-credentials.js +1 -1
  81. package/linter/rules/problematic-inputs.d.ts +1 -1
  82. package/linter/rules/problematic-inputs.js +7 -1
  83. package/linter/rules/seeded-randomness.d.ts +5 -8
  84. package/linter/rules/seeded-randomness.js +17 -9
  85. package/linter/rules/undefined-symbol.js +1 -1
  86. package/linter/rules/unused-definition.js +15 -10
  87. package/linter/rules/useless-loop.js +1 -1
  88. package/package.json +3 -2
  89. package/project/cache/flowr-analyzer-cache.d.ts +4 -3
  90. package/project/cache/flowr-analyzer-cache.js +32 -13
  91. package/project/cache/flowr-cache.d.ts +39 -12
  92. package/project/cache/flowr-cache.js +5 -3
  93. package/project/context/flowr-analyzer-context.d.ts +8 -1
  94. package/project/context/flowr-analyzer-context.js +11 -1
  95. package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -2
  96. package/project/context/flowr-analyzer-dependencies-context.js +15 -1
  97. package/project/context/flowr-analyzer-files-context.d.ts +8 -4
  98. package/project/context/flowr-analyzer-files-context.js +20 -1
  99. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +33 -0
  100. package/project/context/flowr-analyzer-incremental-analysis-context.js +63 -0
  101. package/project/context/flowr-analyzer-meta-context.d.ts +3 -1
  102. package/project/context/flowr-analyzer-meta-context.js +14 -0
  103. package/project/context/flowr-file.d.ts +25 -3
  104. package/project/context/flowr-file.js +24 -2
  105. package/project/dependency-version-space.d.ts +37 -0
  106. package/project/dependency-version-space.js +118 -26
  107. package/project/flowr-analyzer.d.ts +6 -0
  108. package/project/flowr-analyzer.js +6 -2
  109. package/project/incremental/incremental-parse/edit-computation.d.ts +7 -0
  110. package/project/incremental/incremental-parse/edit-computation.js +61 -0
  111. package/project/incremental/incremental-parse/incremental-parse.d.ts +12 -0
  112. package/project/incremental/incremental-parse/incremental-parse.js +37 -0
  113. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +1 -1
  114. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +57 -0
  115. package/project/plugins/file-plugins/files/flowr-manifest-files.js +121 -0
  116. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -2
  117. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +2 -2
  118. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +1 -1
  119. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +33 -0
  120. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +53 -0
  121. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  122. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  123. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +27 -0
  124. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +47 -0
  125. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +7 -0
  126. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -3
  127. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +10 -4
  128. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +17 -4
  129. package/project/plugins/plugin-registry.d.ts +4 -4
  130. package/project/plugins/plugin-registry.js +7 -4
  131. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  132. package/project/sigdb/reader.d.ts +7 -0
  133. package/project/sigdb/reader.js +12 -0
  134. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  135. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  136. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +10 -0
  137. package/queries/catalog/dependencies-query/function-info/derived-functions.js +41 -0
  138. package/queries/catalog/dependencies-query/function-info/read-functions.js +14 -13
  139. package/queries/catalog/dependencies-query/function-info/write-functions.js +28 -36
  140. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +33 -3
  141. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +31 -0
  142. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +9 -2
  143. package/queries/catalog/input-sources-query/input-source-functions.d.ts +9 -10
  144. package/queries/catalog/input-sources-query/input-source-functions.js +23 -394
  145. package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
  146. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -0
  147. package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -10
  148. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
  149. package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
  150. package/queries/catalog/signature-query/signature-query-executor.d.ts +2 -1
  151. package/queries/catalog/signature-query/signature-query-executor.js +79 -3
  152. package/queries/catalog/signature-query/signature-query-format.d.ts +27 -0
  153. package/queries/catalog/signature-query/signature-query-render.js +21 -3
  154. package/r-bridge/data/data.d.ts +2 -2
  155. package/r-bridge/data/data.js +2 -2
  156. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +6 -2
  157. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +21 -2
  158. package/r-bridge/parser.d.ts +11 -1
  159. package/r-bridge/parser.js +7 -4
  160. package/r-bridge/shell-executor.d.ts +1 -0
  161. package/r-bridge/shell-executor.js +1 -0
  162. package/r-bridge/shell.d.ts +1 -0
  163. package/r-bridge/shell.js +1 -0
  164. package/reconstruct/inline/source-inline-map.js +1 -1
  165. package/search/flowr-search-filters.d.ts +1 -6
  166. package/search/flowr-search-filters.js +1 -8
  167. package/search/search-executor/search-enrichers.d.ts +2 -0
  168. package/search/search-executor/search-enrichers.js +29 -12
  169. package/util/mermaid/dfg.js +1 -1
  170. package/util/version.js +1 -1
  171. package/project/plugins/file-plugins/files/flowr-rproject-file.d.ts +0 -31
  172. package/project/plugins/file-plugins/files/flowr-rproject-file.js +0 -66
  173. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.d.ts +0 -22
  174. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.js +0 -36
  175. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.d.ts +0 -13
  176. 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",
@@ -158,18 +172,28 @@ export declare const enum PkgName {
158
172
  Plyr = "plyr",
159
173
  Purrr = "purrr",
160
174
  Ragg = "ragg",
175
+ R6 = "R6",
161
176
  RasterPdf = "rasterpdf",
177
+ Rcpp = "Rcpp",
162
178
  Remotes = "remotes",
163
179
  Rlang = "rlang",
164
180
  RmethodsS3 = "R.methodsS3",
165
181
  Roo = "R.oo",
182
+ RstudioApi = "rstudioapi",
166
183
  Rutils = "R.utils",
167
184
  S7 = "S7",
185
+ Shiny = "shiny",
186
+ ShinyCohortBuilder = "shinyCohortBuilder",
187
+ ShinyFiles = "shinyFiles",
188
+ ShinyJs = "shinyjs",
168
189
  Soda = "SoDA",
190
+ SvDialogs = "svDialogs",
191
+ Tcltk = "tcltk",
169
192
  Testthat = "testthat",
170
193
  TidyR = "tidyr",
171
194
  TinyPlot = "tinyplot",
172
- TryCatchLog = "tryCatchLog"
195
+ TryCatchLog = "tryCatchLog",
196
+ Withr = "withr"
173
197
  }
174
198
  /**
175
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
@@ -59,6 +59,8 @@ export declare function getAliases(sourceIds: readonly NodeId[], dataflow: Dataf
59
59
  * @param blocked - If set, the ids that should not be considered during resolution (=&gt;top)
60
60
  */
61
61
  export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full, ctx, resolve, blocked }: ResolveInfo): ResolveResult;
62
+ /** Resolves an id to a single constant string value, or `undefined` if it is not a unique string constant. */
63
+ export declare function resolveIdToSingleString(id: NodeId | RNodeWithParent | undefined, info: ResolveInfo): string | undefined;
62
64
  /**
63
65
  * Please use {@link resolveIdToValue}
64
66
  *
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAliases = getAliases;
4
4
  exports.resolveIdToValue = resolveIdToValue;
5
+ exports.resolveIdToSingleString = resolveIdToSingleString;
5
6
  exports.trackAliasInEnvironments = trackAliasInEnvironments;
6
7
  exports.trackAliasesInGraph = trackAliasesInGraph;
7
8
  exports.resolveToConstants = resolveToConstants;
@@ -29,7 +30,9 @@ const AliasHandler = {
29
30
  [vertex_1.VertexType.VariableDefinition]: () => undefined
30
31
  };
31
32
  function getFunctionCallAlias(sourceId, dataflow, environment) {
32
- 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);
33
36
  if (identifier === undefined) {
34
37
  return undefined;
35
38
  }
@@ -152,6 +155,7 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, ctx, res
152
155
  case type_1.RType.FunctionCall:
153
156
  case type_1.RType.BinaryOp:
154
157
  case type_1.RType.UnaryOp:
158
+ case type_1.RType.ExpressionList:
155
159
  return (0, set_constants_1.setFrom)((0, resolve_1.resolveNode)({
156
160
  resolve, node, ctx, environment, graph, idMap, blocked
157
161
  }));
@@ -163,6 +167,12 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, ctx, res
163
167
  return r_value_1.Top;
164
168
  }
165
169
  }
170
+ /** Resolves an id to a single constant string value, or `undefined` if it is not a unique string constant. */
171
+ function resolveIdToSingleString(id, info) {
172
+ const resolved = (0, general_1.valueSetGuard)(resolveIdToValue(id, info));
173
+ const element = resolved?.elements.length === 1 ? resolved.elements[0] : undefined;
174
+ return element?.type === 'string' && (0, r_value_1.isValue)(element.value) ? element.value.str : undefined;
175
+ }
166
176
  /**
167
177
  * Please use {@link resolveIdToValue}
168
178
  *
@@ -325,7 +335,7 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
325
335
  const values = new Set();
326
336
  for (const id of resultIds) {
327
337
  const vertex = graph.getVertex(id);
328
- if ((0, vertex_1.isValueVertex)(vertex) && vertex.value !== undefined) {
338
+ if (vertex_1.ValueVertex.is(vertex) && vertex.value !== undefined) {
329
339
  values.add(vertex.value);
330
340
  continue;
331
341
  }
@@ -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