@eagleoutice/flowr 2.15.1 → 2.15.3
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.
- package/README.md +20 -20
- package/dataflow/environments/identifier.d.ts +2 -0
- package/dataflow/environments/identifier.js +8 -1
- package/dataflow/environments/query-fn-props.d.ts +48 -3
- package/dataflow/environments/query-fn-props.js +182 -18
- package/dataflow/graph/graph.d.ts +18 -4
- package/dataflow/graph/graph.js +100 -63
- package/dataflow/graph/vertex.js +1 -1
- package/dataflow/internal/linker.js +9 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +1 -1
- package/dataflow/internal/process/functions/call/common.js +6 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +1 -1
- package/dataflow/internal/process/functions/call/quoted.js +1 -1
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +1 -1
- package/dataflow/internal/process/functions/process-argument.js +1 -1
- package/dataflow/internal/process/process-symbol.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +4 -1
- package/linter/linter-rules.d.ts +9 -9
- package/linter/rules/problematic-inputs.js +1 -1
- package/linter/rules/undefined-symbol.js +3 -2
- package/package.json +1 -1
- package/project/context/flowr-analyzer-environment-context.d.ts +6 -0
- package/project/context/flowr-analyzer-environment-context.js +2 -0
- package/project/flowr-analyzer.d.ts +13 -0
- package/project/flowr-analyzer.js +5 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +3 -1
- package/project/sigdb/manifest.js +1 -1
- package/project/sigdb/reader.d.ts +11 -5
- package/project/sigdb/reader.js +63 -31
- package/project/sigdb/signature-db.d.ts +3 -0
- package/project/sigdb/signature-db.js +5 -4
- package/queries/catalog/dice-query/dice-query-executor.js +3 -2
- package/queries/catalog/input-sources-query/simple-input-classifier.js +67 -0
- package/queries/catalog/signature-query/signature-query-format.d.ts +1 -2
- package/queries/catalog/slice-query-options.d.ts +10 -4
- package/queries/catalog/slice-query-options.js +27 -5
- package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +7 -4
- package/queries/query.d.ts +56 -2
- package/queries/query.js +66 -1
- package/util/collections/bimap.d.ts +2 -1
- package/util/collections/bimap.js +4 -4
- package/util/version.js +2 -2
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ It offers a wide variety of features, for example:
|
|
|
47
47
|
|
|
48
48
|
```shell
|
|
49
49
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
50
|
-
flowR repl v2.15.
|
|
50
|
+
flowR repl v2.15.2, R grammar v14 (tree-sitter engine)
|
|
51
51
|
R> :query @linter "read.csv(\"/root/x.txt\")"
|
|
52
52
|
```
|
|
53
53
|
|
|
@@ -56,7 +56,7 @@ It offers a wide variety of features, for example:
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
```text
|
|
59
|
-
Query: linter (
|
|
59
|
+
Query: linter (9 ms)
|
|
60
60
|
╰ Deprecated Functions (deprecated-functions): no findings
|
|
61
61
|
╰ File Path Validity (file-path-validity): no findings
|
|
62
62
|
╰ Seeded Randomness (seeded-randomness): no findings
|
|
@@ -74,7 +74,7 @@ It offers a wide variety of features, for example:
|
|
|
74
74
|
╰ Unused Import (unused-import): no findings
|
|
75
75
|
╰ Unclosed Connection (unclosed-connection): no findings
|
|
76
76
|
╰ Unescaped Arguments (unescaped-arguments): no findings
|
|
77
|
-
All queries together required ≈
|
|
77
|
+
All queries together required ≈9 ms (1ms accuracy, total 9 ms)
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
|
|
@@ -96,7 +96,7 @@ It offers a wide variety of features, for example:
|
|
|
96
96
|
|
|
97
97
|
_Results (prettified and summarized):_
|
|
98
98
|
|
|
99
|
-
Query: **linter** (
|
|
99
|
+
Query: **linter** (16 ms)\
|
|
100
100
|
╰ **Deprecated Functions** (deprecated-functions): _no findings_\
|
|
101
101
|
╰ **File Path Validity** (file-path-validity):\
|
|
102
102
|
╰ certain:\
|
|
@@ -106,7 +106,7 @@ It offers a wide variety of features, for example:
|
|
|
106
106
|
╰ **Absolute Paths** (absolute-file-paths):\
|
|
107
107
|
╰ certain:\
|
|
108
108
|
╰ Path `/root/x.txt` at 1.1-23\
|
|
109
|
-
╰ _Metadata_: totalConsidered: 1, totalUnknown: 0, searchTimeMs:
|
|
109
|
+
╰ _Metadata_: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 1, processTimeMs: 0\
|
|
110
110
|
╰ **Unused Definitions** (unused-definitions): _no findings_\
|
|
111
111
|
╰ **Network Functions** (network-functions): _no findings_\
|
|
112
112
|
╰ **Dataframe Access Validation** (dataframe-access-validation): _no findings_\
|
|
@@ -120,11 +120,11 @@ It offers a wide variety of features, for example:
|
|
|
120
120
|
╰ **Unused Import** (unused-import): _no findings_\
|
|
121
121
|
╰ **Unclosed Connection** (unclosed-connection): _no findings_\
|
|
122
122
|
╰ **Unescaped Arguments** (unescaped-arguments): _no findings_\
|
|
123
|
-
_All queries together required ≈
|
|
123
|
+
_All queries together required ≈16 ms (1ms accuracy, total 17 ms)_
|
|
124
124
|
|
|
125
125
|
<details> <summary style="color:gray">Show Detailed Results as Json</summary>
|
|
126
126
|
|
|
127
|
-
The analysis required
|
|
127
|
+
The analysis required _17.1 ms_ (including parsing and normalization and the query) within the generation environment.
|
|
128
128
|
|
|
129
129
|
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR.
|
|
130
130
|
Please consult the [Interface](https://github.com/flowr-analysis/flowr/wiki/Interface) wiki page for more information on how to get those.
|
|
@@ -141,7 +141,7 @@ It offers a wide variety of features, for example:
|
|
|
141
141
|
".meta": {
|
|
142
142
|
"builtin": 0,
|
|
143
143
|
"sigdb": 0,
|
|
144
|
-
"searchTimeMs":
|
|
144
|
+
"searchTimeMs": 1,
|
|
145
145
|
"processTimeMs": 1
|
|
146
146
|
}
|
|
147
147
|
},
|
|
@@ -176,7 +176,7 @@ It offers a wide variety of features, for example:
|
|
|
176
176
|
"callsWithAssignmentProducers": 0,
|
|
177
177
|
"callsWithNonConstantProducers": 0,
|
|
178
178
|
"callsWithOtherBranchProducers": 0,
|
|
179
|
-
"searchTimeMs":
|
|
179
|
+
"searchTimeMs": 0,
|
|
180
180
|
"processTimeMs": 0
|
|
181
181
|
}
|
|
182
182
|
},
|
|
@@ -196,7 +196,7 @@ It offers a wide variety of features, for example:
|
|
|
196
196
|
".meta": {
|
|
197
197
|
"totalConsidered": 1,
|
|
198
198
|
"totalUnknown": 0,
|
|
199
|
-
"searchTimeMs":
|
|
199
|
+
"searchTimeMs": 1,
|
|
200
200
|
"processTimeMs": 0
|
|
201
201
|
}
|
|
202
202
|
},
|
|
@@ -224,13 +224,13 @@ It offers a wide variety of features, for example:
|
|
|
224
224
|
"numAccesses": 0,
|
|
225
225
|
"totalAccessed": 0,
|
|
226
226
|
"searchTimeMs": 0,
|
|
227
|
-
"processTimeMs":
|
|
227
|
+
"processTimeMs": 0
|
|
228
228
|
}
|
|
229
229
|
},
|
|
230
230
|
"dead-code": {
|
|
231
231
|
"results": [],
|
|
232
232
|
".meta": {
|
|
233
|
-
"searchTimeMs":
|
|
233
|
+
"searchTimeMs": 1,
|
|
234
234
|
"processTimeMs": 0
|
|
235
235
|
}
|
|
236
236
|
},
|
|
@@ -285,7 +285,7 @@ It offers a wide variety of features, for example:
|
|
|
285
285
|
"subscript": 0
|
|
286
286
|
},
|
|
287
287
|
"searchTimeMs": 0,
|
|
288
|
-
"processTimeMs":
|
|
288
|
+
"processTimeMs": 8
|
|
289
289
|
}
|
|
290
290
|
},
|
|
291
291
|
"unused-import": {
|
|
@@ -319,11 +319,11 @@ It offers a wide variety of features, for example:
|
|
|
319
319
|
}
|
|
320
320
|
},
|
|
321
321
|
".meta": {
|
|
322
|
-
"timing":
|
|
322
|
+
"timing": 16
|
|
323
323
|
}
|
|
324
324
|
},
|
|
325
325
|
".meta": {
|
|
326
|
-
"timing":
|
|
326
|
+
"timing": 16
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
```
|
|
@@ -389,7 +389,7 @@ It offers a wide variety of features, for example:
|
|
|
389
389
|
|
|
390
390
|
```shell
|
|
391
391
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
392
|
-
flowR repl v2.15.
|
|
392
|
+
flowR repl v2.15.2, R grammar v14 (tree-sitter engine)
|
|
393
393
|
R> :query @static-slice (11@sum) file://test/testfiles/example.R
|
|
394
394
|
```
|
|
395
395
|
|
|
@@ -403,7 +403,7 @@ It offers a wide variety of features, for example:
|
|
|
403
403
|
N <- 10
|
|
404
404
|
for(i in 1:(N-1)) sum <- sum + i + w
|
|
405
405
|
sum
|
|
406
|
-
All queries together required ≈
|
|
406
|
+
All queries together required ≈4 ms (1ms accuracy, total 4 ms)
|
|
407
407
|
```
|
|
408
408
|
|
|
409
409
|
|
|
@@ -418,7 +418,7 @@ It offers a wide variety of features, for example:
|
|
|
418
418
|
</details>
|
|
419
419
|
|
|
420
420
|
* 🚀 **fast call-graph, data-, and control-flow graphs**\
|
|
421
|
-
Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">
|
|
421
|
+
Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">101.9 ms</span></i> (as of Aug 26, 2026)](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark),
|
|
422
422
|
_flowR_ can analyze the data- and control-flow of the average real-world R script. See the [benchmarks](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark) for more information,
|
|
423
423
|
and consult the [wiki pages](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph) for more details on the [dataflow graphs](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph) as well as [call graphs](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph#perspectives-cg).
|
|
424
424
|
( [▶ Explore in Browser](https://flowr-analysis.github.io/flowr/wiki/playground/#c=zDYSwRgTghhCeAUATADsWECUAoLBnAxlMAKYD6ALgPakC2UAHgAQA8AtIwGYCuAdvuSEo949DIyYB6RnXojsWaAHdGKlW0aIo5KADoO0GsXghEjALyMAjAC4AbABpGANyJdi5xvngBmRwA5HAHZHACZHAE5HABYMbHwSKB5VdQ4QYHJiCHglRxdgN0YAPkYQuISeABICImJTdWqSCmoZeHjiRIq8t3lcLho6OFJcbXJcFnZe-pgQXCM2xMdDRI8l4Qba2KxeLlnEJu1gNQm%2B7KhFTtdieUUIEAydfFwneEmB2CGR3EcAIleYWAeT2%2B2FQlHIrXKVUIJEQIMoIB4owh7UqJgwQA&p=13:1 "run this script in flowR's playground, no setup") )
|
|
@@ -456,7 +456,7 @@ It offers a wide variety of features, for example:
|
|
|
456
456
|
|
|
457
457
|
```shell
|
|
458
458
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
459
|
-
flowR repl v2.15.
|
|
459
|
+
flowR repl v2.15.2, R grammar v14 (tree-sitter engine)
|
|
460
460
|
R> :dataflow* test/testfiles/example.R
|
|
461
461
|
```
|
|
462
462
|
|
|
@@ -765,7 +765,7 @@ It offers a wide variety of features, for example:
|
|
|
765
765
|
```
|
|
766
766
|
|
|
767
767
|
|
|
768
|
-
(The analysis required
|
|
768
|
+
(The analysis required _2.8 ms_ (including parse and normalize, using the [tree-sitter](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment. No [signature database](https://github.com/flowr-analysis/flowr/wiki/Signature-Database) is mounted for these generated graphs, so `library()` calls attach no package exports; base-R names are still qualified via the generated base-package store (e.g. `acf` as `stats::acf`).)
|
|
769
769
|
|
|
770
770
|
|
|
771
771
|
|
|
@@ -114,6 +114,8 @@ export declare const Identifier: {
|
|
|
114
114
|
* If the first identifier is internal, it will match any target (internal or not).
|
|
115
115
|
*/
|
|
116
116
|
readonly matches: (this: void, id: Identifier, target: Identifier, s3?: boolean) => boolean;
|
|
117
|
+
/** The text as a regex matches it literally: `[`, `$` and `.` name functions in R, they are not pattern syntax. */
|
|
118
|
+
readonly quote: (this: void, text: string) => string;
|
|
117
119
|
/**
|
|
118
120
|
* 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.
|
|
119
121
|
*/
|
|
@@ -180,12 +180,19 @@ exports.Identifier = {
|
|
|
180
180
|
/* an omitted flag is the same as an explicit `false`, `pkg::fn` written either way is one identifier */
|
|
181
181
|
return (idInternal ?? false) === (exports.Identifier.accessesInternal(target) ?? false);
|
|
182
182
|
},
|
|
183
|
+
/** The text as a regex matches it literally: `[`, `$` and `.` name functions in R, they are not pattern syntax. */
|
|
184
|
+
quote(text) {
|
|
185
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
186
|
+
},
|
|
183
187
|
/**
|
|
184
188
|
* 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.
|
|
185
189
|
*/
|
|
186
190
|
regex(...identifiers) {
|
|
187
191
|
// 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
|
|
188
|
-
return new RegExp(`^(${identifiers.map(i =>
|
|
192
|
+
return new RegExp(`^(${identifiers.map(i => {
|
|
193
|
+
const namespace = exports.Identifier.getNamespace(i);
|
|
194
|
+
return `(${namespace === undefined ? '.+' : exports.Identifier.quote(namespace)}:::?)?${exports.Identifier.quote(exports.Identifier.getName(i))}`;
|
|
195
|
+
}).join('|')})$`);
|
|
189
196
|
},
|
|
190
197
|
/** Special identifier for the `...` argument */
|
|
191
198
|
dotdotdot() {
|
|
@@ -5,6 +5,7 @@ import type { REnvironmentInformation } from './environment';
|
|
|
5
5
|
import { Identifier } from './identifier';
|
|
6
6
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
7
|
import type { PackageSignatureSource } from '../../project/sigdb/reader';
|
|
8
|
+
import type { DecodedFunction } from '../../project/sigdb/decode';
|
|
8
9
|
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
|
|
9
10
|
import type { DataflowInformation } from '../info';
|
|
10
11
|
/**
|
|
@@ -43,6 +44,42 @@ export declare function callFnProps(id: NodeId, { graph, environment }: Pick<Dat
|
|
|
43
44
|
* A package function that ends up in `system()` runs a system command as well.
|
|
44
45
|
*/
|
|
45
46
|
export declare function inferFnProps(src: PackageSignatureSource, pkg: string, name: string, version?: string): BuiltInFnInfo | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Everything flowR knows about one function, no matter which of its sources knows it; see {@link fnInfo}.
|
|
49
|
+
* It extends {@link BuiltInFnInfo}, so anything taking what a built-in states takes this as well.
|
|
50
|
+
*/
|
|
51
|
+
export interface FnInfo extends BuiltInFnInfo {
|
|
52
|
+
/** the identifier the answer is for, with the namespace filled in when an unqualified ask resolved to a package */
|
|
53
|
+
readonly name: Identifier;
|
|
54
|
+
/** the package the answer is for, `undefined` when the name resolves to no package at all */
|
|
55
|
+
readonly package?: string;
|
|
56
|
+
/** the package version the answer is for, i.e. the one the analysis assumes; see {@link SignatureDb.versionOf} */
|
|
57
|
+
readonly version?: string;
|
|
58
|
+
/** the formal names in order, empty when neither source declares any */
|
|
59
|
+
readonly parameters: readonly string[];
|
|
60
|
+
/** whether flowR's own built-in definitions state anything about the name */
|
|
61
|
+
readonly builtIn: boolean;
|
|
62
|
+
/** whether flowR's value solver can fold a call of it to a constant */
|
|
63
|
+
readonly foldable: boolean;
|
|
64
|
+
/** the signature database entry: where the function is defined, its callees, its help topic */
|
|
65
|
+
readonly entry?: DecodedFunction;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The one place to ask what flowR knows about a function by name: one of its own built-ins, a package function
|
|
69
|
+
* the signature database carries, or both. What the built-in states wins wherever the two overlap, exactly as
|
|
70
|
+
* {@link queryFnProps} joins them. `undefined` when neither has anything to say about the name.
|
|
71
|
+
* @param name - The function to ask about, qualified (`Identifier.make('lead', 'dplyr')`) to pin the package down.
|
|
72
|
+
* @param ctx - The analyzer context the built-ins, the database and the assumed versions come from.
|
|
73
|
+
* @param version - The package version to answer for, the one the analysis assumes if omitted.
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const ctx = analyzer.inspectContext();
|
|
77
|
+
* fnInfo(Identifier.make('lead', 'dplyr'), ctx)?.parameters; // ['x', 'n', 'default', 'order_by', '...']
|
|
78
|
+
* fnInfo(Identifier.make('nchar'), ctx)?.foldable; // true, flowR folds it itself
|
|
79
|
+
* ```
|
|
80
|
+
* @see {@link fnInfoLookup} - to ask the same question for many names
|
|
81
|
+
*/
|
|
82
|
+
export declare function fnInfo(name: Identifier, ctx: ReadOnlyFlowrAnalyzerContext, version?: string): FnInfo | undefined;
|
|
46
83
|
/** The identifiers a definition registers, with the suffixes of a replacement spelled out. */
|
|
47
84
|
export declare function builtInNames(definition: BuiltInDefinition): Identifier[];
|
|
48
85
|
/** One built-in as the {@link BuiltInIndex} sees it: the name it is registered under and what flowR states about it. */
|
|
@@ -56,7 +93,7 @@ export interface BuiltInEntry extends StatedProps {
|
|
|
56
93
|
/** the declared parameters and what each of their arguments is used for */
|
|
57
94
|
readonly sig?: FnSig;
|
|
58
95
|
/** whether the value solver can fold a call of this built-in to a constant */
|
|
59
|
-
readonly
|
|
96
|
+
readonly foldable: boolean;
|
|
60
97
|
}
|
|
61
98
|
/** One parameter of a built-in, as {@link BuiltInIndex#params} reports it. */
|
|
62
99
|
export interface BuiltInParam {
|
|
@@ -79,8 +116,12 @@ export interface BuiltInParam {
|
|
|
79
116
|
* definition in the analyzed code shadows the built-in) use {@link queryFnProps} instead.
|
|
80
117
|
*/
|
|
81
118
|
export declare class BuiltInIndex {
|
|
119
|
+
/** every built-in the index knows, one entry per namespace and name */
|
|
82
120
|
readonly entries: readonly BuiltInEntry[];
|
|
121
|
+
/** the entry an unqualified name resolves to, the one R's default search path would find */
|
|
83
122
|
private readonly byName;
|
|
123
|
+
/** namespace to name to entry, so a qualified name is two lookups and no string built to ask */
|
|
124
|
+
private readonly byNamespace;
|
|
84
125
|
private readonly cache;
|
|
85
126
|
private constructor();
|
|
86
127
|
/** The index of flowR's own {@link DefaultBuiltinConfig}, computed on first use and shared from then on. */
|
|
@@ -106,10 +147,14 @@ export declare class BuiltInIndex {
|
|
|
106
147
|
/** Every built-in flowR states computes a result and nothing else ({@link CallProp.Pure}). */
|
|
107
148
|
get pure(): readonly Identifier[];
|
|
108
149
|
/** Every built-in the value solver can fold to a constant (the ones with a `evalHandler`). */
|
|
109
|
-
get
|
|
150
|
+
get foldable(): readonly Identifier[];
|
|
110
151
|
/** Every parameter whose argument carries at least one bit of `props`, like {@link ArgProp.Resource}. */
|
|
111
152
|
params(props: ArgProps): BuiltInParam[];
|
|
112
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* What the index states about `name`. A qualified name answers for that package alone, so `stats::filter`
|
|
155
|
+
* does not report what `dplyr::filter` states; an unqualified one answers with what R's default search
|
|
156
|
+
* path would find, `base` first and the other {@link AttachedBasePackageSet|attached base packages} next.
|
|
157
|
+
*/
|
|
113
158
|
get(name: Identifier): BuiltInEntry | undefined;
|
|
114
159
|
/** The {@link CallProp} bits of `name`, `undefined` when no built-in of that name states any. */
|
|
115
160
|
propsOf(name: Identifier): CallProps | undefined;
|
|
@@ -5,15 +5,18 @@ exports.queryFnProps = queryFnProps;
|
|
|
5
5
|
exports.builtInLookup = builtInLookup;
|
|
6
6
|
exports.callFnProps = callFnProps;
|
|
7
7
|
exports.inferFnProps = inferFnProps;
|
|
8
|
+
exports.fnInfo = fnInfo;
|
|
8
9
|
exports.builtInNames = builtInNames;
|
|
9
10
|
const built_in_props_1 = require("./built-in-props");
|
|
10
11
|
const default_builtin_config_1 = require("./default-builtin-config");
|
|
11
12
|
const environment_1 = require("./environment");
|
|
12
13
|
const identifier_1 = require("./identifier");
|
|
13
14
|
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
15
|
+
const signature_db_1 = require("../../project/sigdb/signature-db");
|
|
14
16
|
const resolve_helper_1 = require("./resolve-helper");
|
|
15
17
|
const vertex_1 = require("../graph/vertex");
|
|
16
18
|
const df_helper_1 = require("../graph/df-helper");
|
|
19
|
+
const r_base_packages_1 = require("../../util/r-base-packages");
|
|
17
20
|
/**
|
|
18
21
|
* What flowR states about the package export `definition` binds, `undefined` if it binds none or if flowR
|
|
19
22
|
* states nothing about it. `library(pkg)` binds every export itself, and that binding hides the built-in layer.
|
|
@@ -93,13 +96,20 @@ function queryFnProps(name, { environment, builtIns, signatures, version }) {
|
|
|
93
96
|
*/
|
|
94
97
|
function builtInLookup(ctx) {
|
|
95
98
|
const environment = ctx?.env.makeCleanEnv();
|
|
99
|
+
/* keyed by namespace and name, as `stats::filter` and `dplyr::filter` are not the same function */
|
|
96
100
|
const known = new Map();
|
|
97
101
|
return name => {
|
|
102
|
+
const namespace = identifier_1.Identifier.getNamespace(name);
|
|
98
103
|
const key = identifier_1.Identifier.getName(name);
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
let bucket = known.get(namespace);
|
|
105
|
+
if (bucket === undefined) {
|
|
106
|
+
bucket = new Map();
|
|
107
|
+
known.set(namespace, bucket);
|
|
101
108
|
}
|
|
102
|
-
|
|
109
|
+
if (!bucket.has(key)) {
|
|
110
|
+
bucket.set(key, environment === undefined ? BuiltInIndex.default().get(name) : queryFnProps(name, { environment }));
|
|
111
|
+
}
|
|
112
|
+
return bucket.get(key);
|
|
103
113
|
};
|
|
104
114
|
}
|
|
105
115
|
/** What flowR states about the call `id` makes, together with the name the call resolved to. */
|
|
@@ -126,17 +136,101 @@ function callFnProps(id, { graph, environment }) {
|
|
|
126
136
|
*/
|
|
127
137
|
function inferFnProps(src, pkg, name, version) {
|
|
128
138
|
const fn = src.functionByName(pkg, name, version);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
return fn === undefined ? undefined : propsOfSignature(src, fn, pkg, version);
|
|
140
|
+
}
|
|
141
|
+
/** {@link inferFnProps} for an already decoded entry, so a lookup that found one does not repeat it. */
|
|
142
|
+
function propsOfSignature(src, fn, pkg, version) {
|
|
132
143
|
const own = (0, built_in_props_1.fnInfoFromSignature)(fn);
|
|
133
144
|
const known = BuiltInIndex.default();
|
|
134
145
|
let props = own;
|
|
135
|
-
for (const callee of src.transitiveCallees(pkg, name, version) ?? fn.callees) {
|
|
146
|
+
for (const callee of src.transitiveCallees(pkg, fn.name, version) ?? fn.callees) {
|
|
136
147
|
props = built_in_props_1.CallProps.join(props, built_in_props_1.CallProps.filter(known.get(callee), built_in_props_1.PropagatedProps));
|
|
137
148
|
}
|
|
138
149
|
return { sig: own.sig, ...props };
|
|
139
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* The one place to ask what flowR knows about a function by name: one of its own built-ins, a package function
|
|
153
|
+
* the signature database carries, or both. What the built-in states wins wherever the two overlap, exactly as
|
|
154
|
+
* {@link queryFnProps} joins them. `undefined` when neither has anything to say about the name.
|
|
155
|
+
* @param name - The function to ask about, qualified (`Identifier.make('lead', 'dplyr')`) to pin the package down.
|
|
156
|
+
* @param ctx - The analyzer context the built-ins, the database and the assumed versions come from.
|
|
157
|
+
* @param version - The package version to answer for, the one the analysis assumes if omitted.
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const ctx = analyzer.inspectContext();
|
|
161
|
+
* fnInfo(Identifier.make('lead', 'dplyr'), ctx)?.parameters; // ['x', 'n', 'default', 'order_by', '...']
|
|
162
|
+
* fnInfo(Identifier.make('nchar'), ctx)?.foldable; // true, flowR folds it itself
|
|
163
|
+
* ```
|
|
164
|
+
* @see {@link fnInfoLookup} - to ask the same question for many names
|
|
165
|
+
*/
|
|
166
|
+
function fnInfo(name, ctx, version) {
|
|
167
|
+
const db = (0, signature_db_1.signatureDbOf)(ctx.deps);
|
|
168
|
+
const available = db.available();
|
|
169
|
+
const [bare, namespace, internal] = identifier_1.Identifier.toArray(name);
|
|
170
|
+
const pkg = namespace ?? packageExporting(bare, ctx);
|
|
171
|
+
/* an unqualified ask keeps its form, the built-in layer has a search path of its own */
|
|
172
|
+
const stated = queryFnProps(name, { environment: ctx.env.makeCleanEnv() });
|
|
173
|
+
const qualified = pkg === undefined ? name : identifier_1.Identifier.make(bare, pkg, internal === true);
|
|
174
|
+
const assumed = pkg === undefined ? undefined : version ?? db.versionOf(pkg);
|
|
175
|
+
/* the identifier says how far to reach, `::` to the exports and `:::` past them */
|
|
176
|
+
const entry = pkg === undefined || !available ? undefined : db.functionOf(qualified, version);
|
|
177
|
+
const known = entry === undefined || pkg === undefined ? undefined : propsOfSignature(db.sources(), entry, pkg, assumed);
|
|
178
|
+
if (stated === undefined && known === undefined) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
/* the same identifier the built-in layer was asked with, so both halves of the answer describe one function */
|
|
182
|
+
const definition = ctx.env.builtInFunctionOf(name);
|
|
183
|
+
const sig = nonEmpty(stated?.sig) ?? nonEmpty(known?.sig);
|
|
184
|
+
/* the database keeps every formal, a `sig` only the ones flowR models, so it answers first, but an entry
|
|
185
|
+
* that records none must not hide the formals the built-in does state */
|
|
186
|
+
const parameters = nonEmpty(entry?.signature)?.map(p => p.name) ?? sig?.map(([param]) => param) ?? [];
|
|
187
|
+
return {
|
|
188
|
+
name: qualified,
|
|
189
|
+
package: pkg,
|
|
190
|
+
version: assumed,
|
|
191
|
+
sig,
|
|
192
|
+
parameters,
|
|
193
|
+
...built_in_props_1.CallProps.join(stated, known),
|
|
194
|
+
frame: stated?.frame,
|
|
195
|
+
keepEnvironment: stated?.keepEnvironment,
|
|
196
|
+
builtIn: definition !== undefined || stated !== undefined,
|
|
197
|
+
foldable: definition?.evalHandler !== undefined,
|
|
198
|
+
entry
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** The array itself, `undefined` when it holds nothing, so an empty one does not count as an answer. */
|
|
202
|
+
function nonEmpty(of) {
|
|
203
|
+
return of !== undefined && of.length > 0 ? of : undefined;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The package an unqualified `name` is answered for. Only one the project pulls in counts, as a name some
|
|
207
|
+
* unrelated package exports says nothing about the code at hand, and a `library()` of one sits above the base
|
|
208
|
+
* packages. Where several pulled-in packages export it the most-used answers, as attach order is not known here.
|
|
209
|
+
*
|
|
210
|
+
* Base R is settled by {@link baseRExportOwner} when the database's export index does not carry the name, so
|
|
211
|
+
* `sum` still answers as `base::sum` on a bundle holding no record of it and with no database at all.
|
|
212
|
+
*/
|
|
213
|
+
function packageExporting(name, ctx) {
|
|
214
|
+
let best;
|
|
215
|
+
let bestRank = Number.MAX_SAFE_INTEGER;
|
|
216
|
+
let pulled;
|
|
217
|
+
for (const pkg of ctx.deps.packagesExporting(name)) {
|
|
218
|
+
const attached = pkg === "base" /* PkgName.Base */ || r_base_packages_1.AttachedBasePackageSet.has(pkg);
|
|
219
|
+
if (!attached) {
|
|
220
|
+
pulled ??= new Set(ctx.deps.getDependencies().map(d => d.name));
|
|
221
|
+
if (!pulled.has(pkg)) {
|
|
222
|
+
continue; // nothing attaches it here, so no call in this project reaches it unqualified
|
|
223
|
+
}
|
|
224
|
+
return pkg; // and nothing outranks a package the code attaches itself
|
|
225
|
+
}
|
|
226
|
+
const rank = pkg === "base" /* PkgName.Base */ ? 2 : 1;
|
|
227
|
+
if (rank < bestRank) {
|
|
228
|
+
bestRank = rank;
|
|
229
|
+
best = pkg;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return best ?? (0, r_base_packages_1.baseRExportOwner)(name);
|
|
233
|
+
}
|
|
140
234
|
/** The identifiers a definition registers, with the suffixes of a replacement spelled out. */
|
|
141
235
|
function builtInNames(definition) {
|
|
142
236
|
if (definition.type !== 'replacement') {
|
|
@@ -149,8 +243,8 @@ function entryOfDefinition(definition) {
|
|
|
149
243
|
return [];
|
|
150
244
|
}
|
|
151
245
|
const info = definition.config;
|
|
152
|
-
const
|
|
153
|
-
return builtInNames(definition).map(name => ({ name, props: info?.props, tags: info?.tags, sig: info?.sig,
|
|
246
|
+
const foldable = definition.type === 'function' && definition.evalHandler !== undefined;
|
|
247
|
+
return builtInNames(definition).map(name => ({ name, props: info?.props, tags: info?.tags, sig: info?.sig, foldable, overrides: definition.overrides }));
|
|
154
248
|
}
|
|
155
249
|
function entriesOfMemory(builtIns) {
|
|
156
250
|
const out = [];
|
|
@@ -165,13 +259,39 @@ function entriesOfMemory(builtIns) {
|
|
|
165
259
|
}
|
|
166
260
|
const info = d.config;
|
|
167
261
|
/* the memory is keyed by the bare name, the definition keeps the namespace it was declared with */
|
|
168
|
-
out.push({ name: d.name ?? registered, props: info?.props, tags: info?.tags, sig: info?.sig,
|
|
262
|
+
out.push({ name: d.name ?? registered, props: info?.props, tags: info?.tags, sig: info?.sig, foldable: d.evalHandler !== undefined });
|
|
169
263
|
}
|
|
170
264
|
}
|
|
171
265
|
}
|
|
172
266
|
return out;
|
|
173
267
|
}
|
|
174
268
|
let defaultIndex;
|
|
269
|
+
/**
|
|
270
|
+
* The one entry for a name several definitions state something about, the later definition winning wherever
|
|
271
|
+
* it states anything -- a definition that only adds a {@link FnSig} must not drop the props of the one before.
|
|
272
|
+
* A definition marked `overrides` replaces the earlier one outright, as that is what it says it does.
|
|
273
|
+
*/
|
|
274
|
+
function mergedEntry(known, next) {
|
|
275
|
+
return {
|
|
276
|
+
name: next.name,
|
|
277
|
+
props: next.props ?? known.props,
|
|
278
|
+
tags: next.tags ?? known.tags,
|
|
279
|
+
sig: next.sig ?? known.sig,
|
|
280
|
+
foldable: next.foldable || known.foldable
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/** The entry alone, without what only the index build needs to know about it. */
|
|
284
|
+
function plainEntry({ name, props, tags, sig, foldable }) {
|
|
285
|
+
return { name, props, tags, sig, foldable };
|
|
286
|
+
}
|
|
287
|
+
/** How early R's default search path reaches a name, deciding which package an unqualified ask answers with. */
|
|
288
|
+
function searchPathRank(name) {
|
|
289
|
+
const namespace = identifier_1.Identifier.getNamespace(name);
|
|
290
|
+
if (namespace === undefined) {
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
return namespace === "base" /* PkgName.Base */ ? 1 : r_base_packages_1.AttachedBasePackageSet.has(namespace) ? 2 : 3;
|
|
294
|
+
}
|
|
175
295
|
/**
|
|
176
296
|
* The one place to ask what flowR's built-ins are: _every pure function_, _every call that reads a file_,
|
|
177
297
|
* _every parameter that names a resource_, _everything the value solver can fold_. Each answer is derived
|
|
@@ -184,13 +304,44 @@ let defaultIndex;
|
|
|
184
304
|
* definition in the analyzed code shadows the built-in) use {@link queryFnProps} instead.
|
|
185
305
|
*/
|
|
186
306
|
class BuiltInIndex {
|
|
307
|
+
/** every built-in the index knows, one entry per namespace and name */
|
|
187
308
|
entries;
|
|
309
|
+
/** the entry an unqualified name resolves to, the one R's default search path would find */
|
|
188
310
|
byName = new Map();
|
|
311
|
+
/** namespace to name to entry, so a qualified name is two lookups and no string built to ask */
|
|
312
|
+
byNamespace = new Map();
|
|
189
313
|
cache = new Map();
|
|
190
|
-
constructor(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
314
|
+
constructor(definitions) {
|
|
315
|
+
const unqualified = new Map();
|
|
316
|
+
/* where each name was first seen, so the entries keep the order the definitions come in */
|
|
317
|
+
const order = [];
|
|
318
|
+
for (const e of definitions) {
|
|
319
|
+
const name = identifier_1.Identifier.getName(e.name);
|
|
320
|
+
const namespace = identifier_1.Identifier.getNamespace(e.name);
|
|
321
|
+
let bucket = unqualified;
|
|
322
|
+
if (namespace !== undefined) {
|
|
323
|
+
const inNamespace = this.byNamespace.get(namespace);
|
|
324
|
+
if (inNamespace === undefined) {
|
|
325
|
+
bucket = new Map();
|
|
326
|
+
this.byNamespace.set(namespace, bucket);
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
bucket = inNamespace;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const known = bucket.get(name);
|
|
333
|
+
bucket.set(name, known === undefined || e.overrides ? plainEntry(e) : mergedEntry(known, e));
|
|
334
|
+
if (known === undefined) {
|
|
335
|
+
order.push([bucket, name]);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
this.entries = order.map(([bucket, name]) => bucket.get(name));
|
|
339
|
+
for (const e of this.entries) {
|
|
340
|
+
const name = identifier_1.Identifier.getName(e.name);
|
|
341
|
+
const known = this.byName.get(name);
|
|
342
|
+
if (known === undefined || searchPathRank(e.name) < searchPathRank(known.name)) {
|
|
343
|
+
this.byName.set(name, e);
|
|
344
|
+
}
|
|
194
345
|
}
|
|
195
346
|
}
|
|
196
347
|
/** The index of flowR's own {@link DefaultBuiltinConfig}, computed on first use and shared from then on. */
|
|
@@ -236,8 +387,8 @@ class BuiltInIndex {
|
|
|
236
387
|
return this.with(built_in_props_1.CallProp.Pure);
|
|
237
388
|
}
|
|
238
389
|
/** Every built-in the value solver can fold to a constant (the ones with a `evalHandler`). */
|
|
239
|
-
get
|
|
240
|
-
return this.cached('
|
|
390
|
+
get foldable() {
|
|
391
|
+
return this.cached('foldable', e => e.foldable);
|
|
241
392
|
}
|
|
242
393
|
/** Every parameter whose argument carries at least one bit of `props`, like {@link ArgProp.Resource}. */
|
|
243
394
|
params(props) {
|
|
@@ -251,9 +402,22 @@ class BuiltInIndex {
|
|
|
251
402
|
}
|
|
252
403
|
return found;
|
|
253
404
|
}
|
|
254
|
-
/**
|
|
405
|
+
/**
|
|
406
|
+
* What the index states about `name`. A qualified name answers for that package alone, so `stats::filter`
|
|
407
|
+
* does not report what `dplyr::filter` states; an unqualified one answers with what R's default search
|
|
408
|
+
* path would find, `base` first and the other {@link AttachedBasePackageSet|attached base packages} next.
|
|
409
|
+
*/
|
|
255
410
|
get(name) {
|
|
256
|
-
|
|
411
|
+
const namespace = identifier_1.Identifier.getNamespace(name);
|
|
412
|
+
if (namespace === undefined) {
|
|
413
|
+
return this.byName.get(identifier_1.Identifier.getName(name));
|
|
414
|
+
}
|
|
415
|
+
const found = this.byNamespace.get(namespace)?.get(identifier_1.Identifier.getName(name));
|
|
416
|
+
if (found === undefined) {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
/* the maps settled name and namespace, what is left is `::` asking for a name only `:::` states */
|
|
420
|
+
return identifier_1.Identifier.accessesInternal(found.name) !== true || identifier_1.Identifier.accessesInternal(name) === true ? found : undefined;
|
|
257
421
|
}
|
|
258
422
|
/** The {@link CallProp} bits of `name`, `undefined` when no built-in of that name states any. */
|
|
259
423
|
propsOf(name) {
|
|
@@ -135,6 +135,11 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
135
135
|
private edgeInformation;
|
|
136
136
|
private incomingIndex?;
|
|
137
137
|
private readonly types;
|
|
138
|
+
/** The id list of `tag`, created on first use, so a caller adding many ids looks it up once. */
|
|
139
|
+
private typeList;
|
|
140
|
+
private indexType;
|
|
141
|
+
/** Every write above keeps an id listed under one tag at most once, so a lookup never hands the same one out twice. */
|
|
142
|
+
private unindexType;
|
|
138
143
|
private qualifiedNames?;
|
|
139
144
|
toJSON(): DataflowGraphJson;
|
|
140
145
|
/** Gets the {@link DataflowGraphVertexInfo} attached to `id` (searching function definitions too if `includeDefinedFunctions`) and its outgoing edges. */
|
|
@@ -163,7 +168,9 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
163
168
|
private qualifications;
|
|
164
169
|
/** one resolution fills both variants: what costs is resolving the call, not qualifying it */
|
|
165
170
|
private resolveInto;
|
|
166
|
-
/**
|
|
171
|
+
/** set by a `consume` merge, see {@link DataflowGraph#mergeWith|mergeWith()}; the graph must not change after that */
|
|
172
|
+
private consumed;
|
|
173
|
+
/** Drops the cached qualifications, as the graph may no longer imply them. Every mutator runs through here, so the guard covers them all. */
|
|
167
174
|
private dropQualifications;
|
|
168
175
|
/** For a node of the normalized AST: `nodeId` if it is a DFG vertex itself, else the DFG vertices linked to it, else `undefined`. */
|
|
169
176
|
getLinked(nodeId: NodeId): NodeId[] | undefined;
|
|
@@ -175,9 +182,11 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
175
182
|
setIdMap(idMap: AstIdMap): void;
|
|
176
183
|
/** Ids of all toplevel vertices (or all, including those nested in function definitions, if `includeDefinedFunctions`) with their info, see {@link DataflowGraph#edges}. */
|
|
177
184
|
vertices(includeDefinedFunctions: boolean): MapIterator<[NodeId, Vertex]>;
|
|
185
|
+
/** Every vertex carrying `type`, in the order the graph learned of them. */
|
|
178
186
|
verticesOfType<T extends Vertex['tag']>(type: T): MapIterator<[NodeId, Vertex & {
|
|
179
187
|
tag: T;
|
|
180
188
|
}]>;
|
|
189
|
+
/** The ids of {@link DataflowGraph#verticesOfType|verticesOfType}, as a fresh array the caller may keep. */
|
|
181
190
|
vertexIdsOfType<T extends Vertex['tag']>(type: T): NodeId[];
|
|
182
191
|
/** Ids of all edges in the graph together with their edge information, see {@link DataflowGraph#vertices}. */
|
|
183
192
|
edges(): MapIterator<[NodeId, OutgoingEdges]>;
|
|
@@ -195,11 +204,16 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
|
|
|
195
204
|
* Adds `vertex` to the graph, filling in `fallbackEnv` if it carries no environment. `asRoot = false` skips
|
|
196
205
|
* adding it to {@link rootIds|root vertices} (mostly useful when constructing graphs for tests); `overwrite` replaces an existing vertex of the same id.
|
|
197
206
|
*/
|
|
198
|
-
addVertex(vertex: DataflowGraphVertexArgument & Omit<Vertex, keyof DataflowGraphVertexArgument>, fallbackEnv: REnvironmentInformation, asRoot?: boolean, overwrite?: boolean): this;
|
|
207
|
+
addVertex(vertex: DataflowGraphVertexArgument & Omit<Vertex, keyof DataflowGraphVertexArgument>, fallbackEnv: REnvironmentInformation | (() => REnvironmentInformation), asRoot?: boolean, overwrite?: boolean): this;
|
|
199
208
|
addEdge(fromId: NodeId, toId: NodeId, type: EdgeType.ControlEdge, data: Omit<DFControlFlowEdge, 'types'>): this;
|
|
200
209
|
addEdge(fromId: NodeId, toId: NodeId, type: Exclude<EdgeType, EdgeType.ControlEdge> | number): this;
|
|
201
|
-
/**
|
|
202
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Merges `otherGraph` into *this* one in-place (the return value is only for convenience);
|
|
212
|
+
* `mergeRootVertices = false` excludes its root vertices (useful when merging in a function definition).
|
|
213
|
+
*
|
|
214
|
+
* `consume` takes `otherGraph`'s edge tables instead of copying them (perf). Pass it only for a graph that dies with the call.
|
|
215
|
+
*/
|
|
216
|
+
mergeWith(otherGraph: DataflowGraph<Vertex, Edge> | undefined, mergeRootVertices?: boolean, consume?: boolean): this;
|
|
203
217
|
mergeVertices(otherGraph: DataflowGraph<Vertex, Edge>, mergeRootVertices?: boolean): void;
|
|
204
218
|
private mergeEdges;
|
|
205
219
|
/** Marks the vertex referenced by `reference` as a definition, with `sourceIds` as the source vertex ids of the def if known. */
|