@eagleoutice/flowr 2.15.2 → 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/query-fn-props.d.ts +39 -2
- package/dataflow/environments/query-fn-props.js +98 -12
- 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/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/sigdb/signature-db.d.ts +3 -0
- package/project/sigdb/signature-db.js +5 -4
- package/queries/catalog/signature-query/signature-query-format.d.ts +1 -2
- 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
|
|
|
@@ -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 {
|
|
@@ -110,7 +147,7 @@ export declare class BuiltInIndex {
|
|
|
110
147
|
/** Every built-in flowR states computes a result and nothing else ({@link CallProp.Pure}). */
|
|
111
148
|
get pure(): readonly Identifier[];
|
|
112
149
|
/** Every built-in the value solver can fold to a constant (the ones with a `evalHandler`). */
|
|
113
|
-
get
|
|
150
|
+
get foldable(): readonly Identifier[];
|
|
114
151
|
/** Every parameter whose argument carries at least one bit of `props`, like {@link ArgProp.Resource}. */
|
|
115
152
|
params(props: ArgProps): BuiltInParam[];
|
|
116
153
|
/**
|
|
@@ -5,12 +5,14 @@ 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");
|
|
@@ -134,17 +136,101 @@ function callFnProps(id, { graph, environment }) {
|
|
|
134
136
|
*/
|
|
135
137
|
function inferFnProps(src, pkg, name, version) {
|
|
136
138
|
const fn = src.functionByName(pkg, name, version);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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) {
|
|
140
143
|
const own = (0, built_in_props_1.fnInfoFromSignature)(fn);
|
|
141
144
|
const known = BuiltInIndex.default();
|
|
142
145
|
let props = own;
|
|
143
|
-
for (const callee of src.transitiveCallees(pkg, name, version) ?? fn.callees) {
|
|
146
|
+
for (const callee of src.transitiveCallees(pkg, fn.name, version) ?? fn.callees) {
|
|
144
147
|
props = built_in_props_1.CallProps.join(props, built_in_props_1.CallProps.filter(known.get(callee), built_in_props_1.PropagatedProps));
|
|
145
148
|
}
|
|
146
149
|
return { sig: own.sig, ...props };
|
|
147
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
|
+
}
|
|
148
234
|
/** The identifiers a definition registers, with the suffixes of a replacement spelled out. */
|
|
149
235
|
function builtInNames(definition) {
|
|
150
236
|
if (definition.type !== 'replacement') {
|
|
@@ -157,8 +243,8 @@ function entryOfDefinition(definition) {
|
|
|
157
243
|
return [];
|
|
158
244
|
}
|
|
159
245
|
const info = definition.config;
|
|
160
|
-
const
|
|
161
|
-
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 }));
|
|
162
248
|
}
|
|
163
249
|
function entriesOfMemory(builtIns) {
|
|
164
250
|
const out = [];
|
|
@@ -173,7 +259,7 @@ function entriesOfMemory(builtIns) {
|
|
|
173
259
|
}
|
|
174
260
|
const info = d.config;
|
|
175
261
|
/* the memory is keyed by the bare name, the definition keeps the namespace it was declared with */
|
|
176
|
-
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 });
|
|
177
263
|
}
|
|
178
264
|
}
|
|
179
265
|
}
|
|
@@ -191,12 +277,12 @@ function mergedEntry(known, next) {
|
|
|
191
277
|
props: next.props ?? known.props,
|
|
192
278
|
tags: next.tags ?? known.tags,
|
|
193
279
|
sig: next.sig ?? known.sig,
|
|
194
|
-
|
|
280
|
+
foldable: next.foldable || known.foldable
|
|
195
281
|
};
|
|
196
282
|
}
|
|
197
283
|
/** The entry alone, without what only the index build needs to know about it. */
|
|
198
|
-
function plainEntry({ name, props, tags, sig,
|
|
199
|
-
return { name, props, tags, sig,
|
|
284
|
+
function plainEntry({ name, props, tags, sig, foldable }) {
|
|
285
|
+
return { name, props, tags, sig, foldable };
|
|
200
286
|
}
|
|
201
287
|
/** How early R's default search path reaches a name, deciding which package an unqualified ask answers with. */
|
|
202
288
|
function searchPathRank(name) {
|
|
@@ -301,8 +387,8 @@ class BuiltInIndex {
|
|
|
301
387
|
return this.with(built_in_props_1.CallProp.Pure);
|
|
302
388
|
}
|
|
303
389
|
/** Every built-in the value solver can fold to a constant (the ones with a `evalHandler`). */
|
|
304
|
-
get
|
|
305
|
-
return this.cached('
|
|
390
|
+
get foldable() {
|
|
391
|
+
return this.cached('foldable', e => e.foldable);
|
|
306
392
|
}
|
|
307
393
|
/** Every parameter whose argument carries at least one bit of `props`, like {@link ArgProp.Resource}. */
|
|
308
394
|
params(props) {
|
|
@@ -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. */
|
package/dataflow/graph/graph.js
CHANGED
|
@@ -121,14 +121,37 @@ class DataflowGraph {
|
|
|
121
121
|
* bulk write (`mergeEdges`, `fromJson`): rebuilding it per lookup made every caller asking for the ingoing
|
|
122
122
|
* edges of many nodes scan the whole graph once per node */
|
|
123
123
|
incomingIndex;
|
|
124
|
+
/* tag to the ids carrying it; a lookup re-checks the vertex, as another graph may retag an object they share */
|
|
124
125
|
types = new Map();
|
|
126
|
+
/** The id list of `tag`, created on first use, so a caller adding many ids looks it up once. */
|
|
127
|
+
typeList(tag) {
|
|
128
|
+
let ids = this.types.get(tag);
|
|
129
|
+
if (ids === undefined) {
|
|
130
|
+
this.types.set(tag, ids = []);
|
|
131
|
+
}
|
|
132
|
+
return ids;
|
|
133
|
+
}
|
|
134
|
+
indexType(tag, id) {
|
|
135
|
+
this.typeList(tag).push(id);
|
|
136
|
+
}
|
|
137
|
+
/** Every write above keeps an id listed under one tag at most once, so a lookup never hands the same one out twice. */
|
|
138
|
+
unindexType(tag, id) {
|
|
139
|
+
const ids = this.types.get(tag);
|
|
140
|
+
if (ids === undefined) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
for (let idx = ids.lastIndexOf(id); idx >= 0; idx = ids.lastIndexOf(id)) {
|
|
144
|
+
ids.splice(idx, 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
125
147
|
/* the qualified call names, built on demand and dropped on every change, as vertices and edges both decide them */
|
|
126
148
|
qualifiedNames;
|
|
127
149
|
toJSON() {
|
|
128
150
|
return {
|
|
129
151
|
rootVertices: Array.from(this.rootVertices),
|
|
130
|
-
vertexInformation: Array.from(this.vertexInformation
|
|
131
|
-
|
|
152
|
+
vertexInformation: Array.from(this.vertexInformation),
|
|
153
|
+
/* mapping inside `Array.from`, a trailing `.map()` would build the outer array twice */
|
|
154
|
+
edgeInformation: Array.from(this.edgeInformation, ([id, edges]) => [id, Array.from(edges)]),
|
|
132
155
|
_unknownSideEffects: Array.from(this._unknownSideEffects)
|
|
133
156
|
};
|
|
134
157
|
}
|
|
@@ -225,8 +248,11 @@ class DataflowGraph {
|
|
|
225
248
|
cache.bare.set(id, bare);
|
|
226
249
|
cache.baseR.set(id, baseR);
|
|
227
250
|
}
|
|
228
|
-
/**
|
|
251
|
+
/** set by a `consume` merge, see {@link DataflowGraph#mergeWith|mergeWith()}; the graph must not change after that */
|
|
252
|
+
consumed = false;
|
|
253
|
+
/** Drops the cached qualifications, as the graph may no longer imply them. Every mutator runs through here, so the guard covers them all. */
|
|
229
254
|
dropQualifications() {
|
|
255
|
+
(0, assert_1.guard)(!this.consumed, 'this graph was consumed by a merge and must not be changed any more');
|
|
230
256
|
if (this.qualifiedNames !== undefined) {
|
|
231
257
|
this.qualifiedNames = undefined;
|
|
232
258
|
}
|
|
@@ -267,14 +293,27 @@ class DataflowGraph {
|
|
|
267
293
|
}
|
|
268
294
|
}
|
|
269
295
|
}
|
|
296
|
+
/** Every vertex carrying `type`, in the order the graph learned of them. */
|
|
270
297
|
*verticesOfType(type) {
|
|
271
|
-
const ids = this.types.get(type)
|
|
298
|
+
const ids = this.types.get(type);
|
|
299
|
+
if (ids === undefined) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
272
302
|
for (const id of ids) {
|
|
273
|
-
|
|
303
|
+
const vertex = this.vertexInformation.get(id);
|
|
304
|
+
/* a stale entry would hand out a vertex without the fields its tag promises */
|
|
305
|
+
if (vertex?.tag === type) {
|
|
306
|
+
yield [id, vertex];
|
|
307
|
+
}
|
|
274
308
|
}
|
|
275
309
|
}
|
|
310
|
+
/** The ids of {@link DataflowGraph#verticesOfType|verticesOfType}, as a fresh array the caller may keep. */
|
|
276
311
|
vertexIdsOfType(type) {
|
|
277
|
-
|
|
312
|
+
const ids = this.types.get(type);
|
|
313
|
+
if (ids === undefined) {
|
|
314
|
+
return [];
|
|
315
|
+
}
|
|
316
|
+
return ids.filter(id => this.vertexInformation.get(id)?.tag === type);
|
|
278
317
|
}
|
|
279
318
|
/** Ids of all edges in the graph together with their edge information, see {@link DataflowGraph#vertices}. */
|
|
280
319
|
*edges() {
|
|
@@ -325,23 +364,32 @@ class DataflowGraph {
|
|
|
325
364
|
*/
|
|
326
365
|
addVertex(vertex, fallbackEnv, asRoot = true, overwrite = false) {
|
|
327
366
|
const vid = vertex.id;
|
|
328
|
-
|
|
367
|
+
const previous = this.vertexInformation.get(vid);
|
|
368
|
+
if (previous !== undefined && !overwrite) {
|
|
329
369
|
return this;
|
|
330
370
|
}
|
|
331
371
|
this.dropQualifications();
|
|
332
372
|
const vtag = vertex.tag;
|
|
333
373
|
// keep a clone of the original environment, isolating the snapshot from later updates
|
|
334
|
-
|
|
374
|
+
let environment;
|
|
375
|
+
if (vertex.environment) {
|
|
376
|
+
environment = (0, clone_1.cloneEnvironmentInformation)(vertex.environment);
|
|
377
|
+
}
|
|
378
|
+
else if (vtag === vertex_1.VertexType.FunctionDefinition || (vtag === vertex_1.VertexType.FunctionCall && !vertex.onlyBuiltin)) {
|
|
379
|
+
/* only here is a fallback wanted, so a thunk spares every other vertex one it would discard */
|
|
380
|
+
environment = typeof fallbackEnv === 'function' ? fallbackEnv() : fallbackEnv;
|
|
381
|
+
}
|
|
382
|
+
vertex.environment = environment;
|
|
335
383
|
this.vertexInformation.set(vid, vertex);
|
|
336
384
|
if (gas_1.activeDataflowBudget !== undefined) {
|
|
337
385
|
gas_1.activeDataflowBudget.vertex();
|
|
338
386
|
}
|
|
339
|
-
|
|
340
|
-
if (
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
this.
|
|
387
|
+
/* an overwrite keeping the tag is indexed already */
|
|
388
|
+
if (previous?.tag !== vtag) {
|
|
389
|
+
if (previous !== undefined) {
|
|
390
|
+
this.unindexType(previous.tag, vid);
|
|
391
|
+
}
|
|
392
|
+
this.indexType(vtag, vid);
|
|
345
393
|
}
|
|
346
394
|
if (asRoot) {
|
|
347
395
|
this.rootVertices.add(vid);
|
|
@@ -384,26 +432,20 @@ class DataflowGraph {
|
|
|
384
432
|
}
|
|
385
433
|
return this;
|
|
386
434
|
}
|
|
387
|
-
/**
|
|
388
|
-
|
|
435
|
+
/**
|
|
436
|
+
* Merges `otherGraph` into *this* one in-place (the return value is only for convenience);
|
|
437
|
+
* `mergeRootVertices = false` excludes its root vertices (useful when merging in a function definition).
|
|
438
|
+
*
|
|
439
|
+
* `consume` takes `otherGraph`'s edge tables instead of copying them (perf). Pass it only for a graph that dies with the call.
|
|
440
|
+
*/
|
|
441
|
+
mergeWith(otherGraph, mergeRootVertices = true, consume = false) {
|
|
389
442
|
if (otherGraph === undefined || otherGraph === this) {
|
|
390
443
|
return this;
|
|
391
444
|
}
|
|
445
|
+
(0, assert_1.guard)(!otherGraph.consumed, 'a graph consumed by an earlier merge cannot be merged again');
|
|
392
446
|
this.mergeVertices(otherGraph, mergeRootVertices);
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (existing) {
|
|
396
|
-
if (existing !== ids) {
|
|
397
|
-
for (const id of ids) {
|
|
398
|
-
existing.push(id);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
this.types.set(type, ids.slice());
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
this.mergeEdges(otherGraph);
|
|
447
|
+
this.mergeEdges(otherGraph, consume);
|
|
448
|
+
otherGraph.consumed ||= consume;
|
|
407
449
|
return this;
|
|
408
450
|
}
|
|
409
451
|
mergeVertices(otherGraph, mergeRootVertices = true) {
|
|
@@ -417,19 +459,34 @@ class DataflowGraph {
|
|
|
417
459
|
for (const unknown of otherGraph.unknownSideEffects) {
|
|
418
460
|
this._unknownSideEffects.add(unknown);
|
|
419
461
|
}
|
|
462
|
+
/* the tags of the vertices coming in repeat, so the list each goes on is looked up only when it changes */
|
|
463
|
+
let lastTag;
|
|
464
|
+
let lastIds = [];
|
|
420
465
|
for (const [id, info] of otherGraph.vertexInformation) {
|
|
421
466
|
const currentInfo = this.vertexInformation.get(id);
|
|
422
|
-
|
|
467
|
+
if (currentInfo === undefined) {
|
|
468
|
+
this.vertexInformation.set(id, info);
|
|
469
|
+
if (info.tag !== lastTag) {
|
|
470
|
+
lastIds = this.typeList(lastTag = info.tag);
|
|
471
|
+
}
|
|
472
|
+
lastIds.push(id);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
/* a known vertex keeps its tag, and with it its place in the index */
|
|
476
|
+
const merged = mergeNodeInfos(currentInfo, info);
|
|
477
|
+
if (merged !== currentInfo) {
|
|
478
|
+
this.vertexInformation.set(id, merged);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
423
481
|
}
|
|
424
482
|
}
|
|
425
|
-
mergeEdges(otherGraph) {
|
|
483
|
+
mergeEdges(otherGraph, consume = false) {
|
|
426
484
|
this.dropQualifications();
|
|
427
485
|
this.incomingIndex = undefined;
|
|
428
|
-
for (const [id, edges] of otherGraph.edgeInformation
|
|
429
|
-
|
|
486
|
+
for (const [id, edges] of otherGraph.edgeInformation) {
|
|
487
|
+
const existing = this.edgeInformation.get(id);
|
|
430
488
|
if (existing === undefined) {
|
|
431
|
-
|
|
432
|
-
this.edgeInformation.set(id, existing);
|
|
489
|
+
this.edgeInformation.set(id, consume ? edges : new Map(edges));
|
|
433
490
|
}
|
|
434
491
|
else {
|
|
435
492
|
for (const [target, edge] of edges) {
|
|
@@ -459,19 +516,8 @@ class DataflowGraph {
|
|
|
459
516
|
if (sourceIds) {
|
|
460
517
|
vertex.source = sourceIds;
|
|
461
518
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
for (let idx = oldIds.lastIndexOf(vid); idx >= 0; idx = oldIds.lastIndexOf(vid)) {
|
|
465
|
-
oldIds.splice(idx, 1);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
const newIds = this.types.get(vertex_1.VertexType.VariableDefinition);
|
|
469
|
-
if (newIds) {
|
|
470
|
-
newIds.push(vid);
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
this.types.set(vertex_1.VertexType.VariableDefinition, [vid]);
|
|
474
|
-
}
|
|
519
|
+
this.unindexType(oldTag, vid);
|
|
520
|
+
this.indexType(vertex_1.VertexType.VariableDefinition, vid);
|
|
475
521
|
}
|
|
476
522
|
}
|
|
477
523
|
/** Marks the vertex `info.id` in the graph to be a function call with the new `info`. */
|
|
@@ -482,19 +528,8 @@ class DataflowGraph {
|
|
|
482
528
|
(0, assert_1.guard)(vertex !== undefined && (vertex_2.UseVertex.is(vertex) || vertex_2.ValueVertex.is(vertex)), () => `node must be a use or value node for ${JSON.stringify(info.id)} to update it to a function call but is ${vertex?.tag}`);
|
|
483
529
|
const previousTag = vertex.tag;
|
|
484
530
|
this.vertexInformation.set(infoId, { ...vertex, ...info, tag: vertex_1.VertexType.FunctionCall });
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
for (let idx = prevIds.lastIndexOf(infoId); idx >= 0; idx = prevIds.lastIndexOf(infoId)) {
|
|
488
|
-
prevIds.splice(idx, 1);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
const callIds = this.types.get(vertex_1.VertexType.FunctionCall);
|
|
492
|
-
if (callIds) {
|
|
493
|
-
callIds.push(infoId);
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
this.types.set(vertex_1.VertexType.FunctionCall, [infoId]);
|
|
497
|
-
}
|
|
531
|
+
this.unindexType(previousTag, infoId);
|
|
532
|
+
this.indexType(vertex_1.VertexType.FunctionCall, infoId);
|
|
498
533
|
}
|
|
499
534
|
/** If you do not pass the `to` node, this will just mark the node as maybe */
|
|
500
535
|
addControlDependency(from, to, when) {
|
|
@@ -531,10 +566,12 @@ class DataflowGraph {
|
|
|
531
566
|
const graph = new DataflowGraph(undefined);
|
|
532
567
|
graph.rootVertices = new Set(data.rootVertices);
|
|
533
568
|
graph.vertexInformation = new Map(data.vertexInformation);
|
|
534
|
-
for (const [, vertex] of graph.vertexInformation) {
|
|
569
|
+
for (const [id, vertex] of graph.vertexInformation) {
|
|
535
570
|
if (vertex.environment) {
|
|
536
571
|
vertex.environment = renvFromJson(vertex.environment);
|
|
537
572
|
}
|
|
573
|
+
/* the index is not serialized, without rebuilding it every lookup by tag comes up empty */
|
|
574
|
+
graph.indexType(vertex.tag, id);
|
|
538
575
|
}
|
|
539
576
|
graph.edgeInformation = new Map(data.edgeInformation.map(([id, edges]) => [id, new Map(edges)]));
|
|
540
577
|
graph.incomingIndex = undefined;
|
package/dataflow/graph/vertex.js
CHANGED
|
@@ -59,7 +59,7 @@ exports.FunctionCallVertex = {
|
|
|
59
59
|
* Deliberately not a type predicate: a `false` says nothing about the tag, the call may simply carry another origin.
|
|
60
60
|
*/
|
|
61
61
|
hasOrigin(vertex, origin) {
|
|
62
|
-
return exports.FunctionCallVertex.is(vertex) && vertex.origin
|
|
62
|
+
return exports.FunctionCallVertex.is(vertex) && vertex.origin?.includes(origin) === true;
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
@@ -36,18 +36,22 @@ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
|
36
36
|
* Find all reads within the graph that do not reference a local definition in the graph.
|
|
37
37
|
*/
|
|
38
38
|
function findNonLocalReads(graph, ignores = new Set()) {
|
|
39
|
-
const defs = new Set(
|
|
39
|
+
const defs = new Set();
|
|
40
|
+
for (const tag of [vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition]) {
|
|
41
|
+
for (const [id] of graph.verticesOfType(tag)) {
|
|
42
|
+
defs.add(id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
40
45
|
/* find all variable use ids which do not link to a given id */
|
|
41
46
|
const nonLocalReads = [];
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
/* the tag already says what the reference is, so no vertex has to be fetched to decide */
|
|
48
|
+
for (const [tag, type] of [[vertex_1.VertexType.Use, identifier_1.ReferenceType.Variable], [vertex_1.VertexType.FunctionCall, identifier_1.ReferenceType.Function]]) {
|
|
49
|
+
for (const [nodeId] of graph.verticesOfType(tag)) {
|
|
44
50
|
if (ignores.has(nodeId)) {
|
|
45
51
|
continue;
|
|
46
52
|
}
|
|
47
53
|
const outgoing = graph.outgoingEdges(nodeId);
|
|
48
|
-
const origin = graph.getVertex(nodeId);
|
|
49
54
|
const name = node_id_1.NodeId.recoverName(nodeId, graph.idMap);
|
|
50
|
-
const type = vertex_2.FunctionCallVertex.is(origin) ? identifier_1.ReferenceType.Function : identifier_1.ReferenceType.Variable;
|
|
51
55
|
const identifierRef = { nodeId, name, type };
|
|
52
56
|
/* control flow edges say nothing about what a name resolves to, so they do not count as a link */
|
|
53
57
|
let linked = false;
|
|
@@ -123,7 +123,7 @@ function processApply(name, args, rootId, data, config) {
|
|
|
123
123
|
cds: data.cds,
|
|
124
124
|
args: allOtherArguments, // same reference
|
|
125
125
|
origin: [built_in_proc_name_1.BuiltInProcName.Function]
|
|
126
|
-
}, data.ctx.env.
|
|
126
|
+
}, data.ctx.env.cleanEnv);
|
|
127
127
|
information.graph.addEdge(rootId, rootFnId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
|
|
128
128
|
information.graph.addEdge(rootId, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Argument);
|
|
129
129
|
information = {
|
|
@@ -264,7 +264,8 @@ function processExpressionList(name, args, rootId, data) {
|
|
|
264
264
|
data.environment = environment;
|
|
265
265
|
const processed = (0, processor_1.processDataflowFor)(expression, data);
|
|
266
266
|
processedExpressions.push(processed);
|
|
267
|
-
|
|
267
|
+
/* the expression's graph dies here, what is kept of it afterward is its entry point and its references */
|
|
268
|
+
nextGraph.mergeWith(processed.graph, true, true);
|
|
268
269
|
defaultReturnExpr = processed;
|
|
269
270
|
// a prior next/break means we do not know if the rest executes, so later environments append rather than overwrite
|
|
270
271
|
if (exitPoints.length > 0) {
|
|
@@ -43,7 +43,8 @@ function processForLoop(name, args, rootId, data) {
|
|
|
43
43
|
// this should not be able to exit always!
|
|
44
44
|
const originalDependency = data.cds;
|
|
45
45
|
let headEnvironments = (0, overwrite_1.overwriteEnvironment)(vector.environment, variable.environment);
|
|
46
|
-
|
|
46
|
+
/* only the vector's references and entry point are read past this, its graph is not */
|
|
47
|
+
const headGraph = variable.graph.mergeWith(vector.graph, true, true);
|
|
47
48
|
const writtenVariable = variable.unknownReferences.concat(variable.in);
|
|
48
49
|
const writtenIds = new Set();
|
|
49
50
|
for (const write of writtenVariable) {
|
|
@@ -57,7 +58,8 @@ function processForLoop(name, args, rootId, data) {
|
|
|
57
58
|
const cd = [{ id: name.info.id, when: true }];
|
|
58
59
|
const bodyRefs = body.in.concat(body.unknownReferences);
|
|
59
60
|
(0, reference_to_maybe_1.applyCdsToAllInGraphButConstants)(body.graph, bodyRefs, cd);
|
|
60
|
-
|
|
61
|
+
/* likewise the body's, what is taken from it afterwards are its references, exit points and hooks */
|
|
62
|
+
const nextGraph = headGraph.mergeWith(body.graph, true, true);
|
|
61
63
|
// now we have to identify all reads that may be effected by a circular redefinition
|
|
62
64
|
// for this, we search for all reads with a non-local read resolve!
|
|
63
65
|
const nameIdShares = (0, linker_1.produceNameSharedIdMap)((0, linker_1.findNonLocalReads)(nextGraph, writtenIds));
|
|
@@ -138,7 +138,7 @@ function processFunctionDefinition(name, args, rootId, data) {
|
|
|
138
138
|
id: read.nodeId,
|
|
139
139
|
environment: undefined,
|
|
140
140
|
cds: undefined
|
|
141
|
-
}, data.ctx.env.
|
|
141
|
+
}, data.ctx.env.cleanEnv);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
const compactedHooks = (0, hooks_1.compactHookStates)(body.hooks);
|
|
@@ -229,7 +229,7 @@ function processFunctionDefinition(name, args, rootId, data) {
|
|
|
229
229
|
subflow: flow,
|
|
230
230
|
exitPoints: afterHookExitPoints,
|
|
231
231
|
returnEnvState
|
|
232
|
-
}, data.ctx.env.
|
|
232
|
+
}, data.ctx.env.cleanEnv);
|
|
233
233
|
return {
|
|
234
234
|
/* nothing escapes a function definition, but the function itself, will be forced in assignment: { nodeId: functionDefinition.info.id, scope: data.activeScope, used: 'always', name: functionDefinition.info.id as string } */
|
|
235
235
|
unknownReferences: [],
|
|
@@ -283,7 +283,7 @@ function attachExportVertex(graph, builtInId, environment, ctx, cds) {
|
|
|
283
283
|
environment, cds, params: {},
|
|
284
284
|
subflow: { graph: new Set(), unknownReferences: [], in: [], out: [], environment, entryPoint: builtInId, hooks: [] },
|
|
285
285
|
exitPoints: [],
|
|
286
|
-
}, ctx.env.
|
|
286
|
+
}, ctx.env.cleanEnv);
|
|
287
287
|
}
|
|
288
288
|
/** Reserved marker binding recording an unresolved `library()`/`require()` load; the leading space cannot collide with a real export name. */
|
|
289
289
|
const libraryLoadMarker = ' library-load';
|
|
@@ -49,7 +49,7 @@ function processNamespaceAccess(name, args, rootId, data, config) {
|
|
|
49
49
|
tag: vertex_1.VertexType.Use,
|
|
50
50
|
id: rootId,
|
|
51
51
|
cds: data.cds
|
|
52
|
-
}, data.ctx.env.
|
|
52
|
+
}, data.ctx.env.cleanEnv),
|
|
53
53
|
entryPoint: rootId,
|
|
54
54
|
exitPoints: [{ nodeId: rootId, type: 0 /* ExitPointType.Default */, cds: data.cds }],
|
|
55
55
|
hooks: []
|
|
@@ -104,8 +104,11 @@ function processAllArguments({ functionName, args, data, finalGraph, functionRoo
|
|
|
104
104
|
continue;
|
|
105
105
|
}
|
|
106
106
|
let processed;
|
|
107
|
+
/* a precomputed argument is handed in from elsewhere and stays alive there, only a freshly built one dies here */
|
|
108
|
+
let ownsGraph = true;
|
|
107
109
|
if (i === 0 && data.precomputedFirstArg?.rootId === functionRootId) {
|
|
108
110
|
processed = data.precomputedFirstArg.info;
|
|
111
|
+
ownsGraph = false;
|
|
109
112
|
}
|
|
110
113
|
else {
|
|
111
114
|
processed = r_argument_1.RArgument.is(arg) ? (0, process_argument_1.processFunctionArgument)(arg, data) : (0, processor_1.processDataflowFor)(arg, data);
|
|
@@ -115,7 +118,8 @@ function processAllArguments({ functionName, args, data, finalGraph, functionRoo
|
|
|
115
118
|
}
|
|
116
119
|
processedArguments.push(processed);
|
|
117
120
|
finalEnv = (0, overwrite_1.overwriteEnvironment)(finalEnv, processed.environment);
|
|
118
|
-
|
|
121
|
+
/* nothing reads the argument's own graph past this point, only its entry point and references */
|
|
122
|
+
finalGraph.mergeWith(processed.graph, true, ownsGraph);
|
|
119
123
|
// resolve reads within argument, we resolve before adding the `processed.environment` to avoid cyclic dependencies
|
|
120
124
|
for (const l of [processed.in, processed.unknownReferences]) {
|
|
121
125
|
for (const original of l) {
|
|
@@ -176,7 +180,7 @@ function patchFunctionCall({ nextGraph, rootId, name, data, argumentProcessResul
|
|
|
176
180
|
args: argumentProcessResult.map(arg => arg === undefined ? r_function_call_1.EmptyArgument : { nodeId: arg.entryPoint, cds: undefined, call: undefined, type: identifier_1.ReferenceType.Argument }),
|
|
177
181
|
origin: [origin],
|
|
178
182
|
link
|
|
179
|
-
}, data.ctx.env.
|
|
183
|
+
}, data.ctx.env.cleanEnv, !nextGraph.hasVertex(rootId) || nextGraph.isRoot(rootId), true);
|
|
180
184
|
for (const arg of argumentProcessResult) {
|
|
181
185
|
if (arg) {
|
|
182
186
|
nextGraph.addEdge(rootId, arg.entryPoint, edge_1.EdgeType.Argument);
|
|
@@ -113,7 +113,7 @@ function processKnownFunctionCall({ name, args, rootId, data, reverseOrder = fal
|
|
|
113
113
|
cds: data.cds,
|
|
114
114
|
args: reverseOrder ? callArgs.toReversed() : callArgs,
|
|
115
115
|
origin: origin === 'default' ? [built_in_proc_name_1.BuiltInProcName.Function] : [origin]
|
|
116
|
-
}, data.ctx.env.
|
|
116
|
+
}, data.ctx.env.cleanEnv);
|
|
117
117
|
if (hasUnknownSideEffect) {
|
|
118
118
|
(0, unknown_side_effect_1.handleUnknownSideEffect)(finalGraph, data.environment, rootId);
|
|
119
119
|
}
|
|
@@ -32,7 +32,7 @@ const EvaluatingElsewhereCalls = new Set(['evalq']);
|
|
|
32
32
|
*/
|
|
33
33
|
const ValueFlow = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument;
|
|
34
34
|
function hasOrigin(vertex, of) {
|
|
35
|
-
return vertex.origin
|
|
35
|
+
return Array.isArray(vertex.origin) && vertex.origin.some(o => of.includes(o));
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* A language object reads nothing where it is written and everything where it reaches `eval`, with the bindings
|
|
@@ -68,7 +68,7 @@ function processUnnamedFunctionCall(functionCall, data) {
|
|
|
68
68
|
cds: data.cds,
|
|
69
69
|
args: callArgs, // same reference
|
|
70
70
|
origin: [built_in_proc_name_1.BuiltInProcName.Unnamed]
|
|
71
|
-
}, data.ctx.env.
|
|
71
|
+
}, data.ctx.env.cleanEnv);
|
|
72
72
|
const cfgEntry = control_flow_1.ControlFlow.inSequence(finalGraph, [calledFunction, ...processedArguments], functionRootId);
|
|
73
73
|
/* a jump within an argument is caught here, just like for a named call */
|
|
74
74
|
for (const argument of processedArguments) {
|
|
@@ -48,7 +48,7 @@ function processFunctionArgument(argument, data) {
|
|
|
48
48
|
tag: vertex_1.VertexType.Use,
|
|
49
49
|
id: argument.info.id,
|
|
50
50
|
cds: data.cds
|
|
51
|
-
}, data.ctx.env.
|
|
51
|
+
}, data.ctx.env.cleanEnv);
|
|
52
52
|
entryPoint = argument.info.id;
|
|
53
53
|
}
|
|
54
54
|
const ingoingRefs = value ? value.unknownReferences.concat(value.in, name?.in ?? []) : name?.in;
|
|
@@ -25,7 +25,7 @@ function processSymbol(symbol, data) {
|
|
|
25
25
|
tag: vertex_1.VertexType.Use,
|
|
26
26
|
id: sid,
|
|
27
27
|
cds: data.cds
|
|
28
|
-
}, data.ctx.env.
|
|
28
|
+
}, data.ctx.env.cleanEnv),
|
|
29
29
|
entryPoint: sid,
|
|
30
30
|
exitPoints: [{ nodeId: sid, type: 0 /* ExitPointType.Default */, cds: data.cds }],
|
|
31
31
|
hooks: []
|
package/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
export { FlowrAnalyzer } from './project/flowr-analyzer';
|
|
18
18
|
export type { FlowrAnalysisOptions, FlowrAnalysisProvider, ReadonlyFlowrAnalysisProvider } from './project/flowr-analyzer';
|
|
19
19
|
export { FlowrAnalyzerBuilder } from './project/flowr-analyzer-builder';
|
|
20
|
+
export { Identifier } from './dataflow/environments/identifier';
|
|
21
|
+
export type { FnInfo } from './dataflow/environments/query-fn-props';
|
|
20
22
|
export type { Query, QueryResults, SupportedQueryTypes } from './queries/query';
|
|
21
23
|
export { SlicingCriteria, SlicingCriterion } from './slicing/criterion/parse';
|
|
22
24
|
export { requestFromInput } from './r-bridge/retriever';
|
package/index.js
CHANGED
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.retrieveVersionInformation = exports.flowrVersion = exports.TREE_SITTER_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.TREE_SITTER_SLICING_PIPELINE = exports.TREE_SITTER_DATAFLOW_PIPELINE = exports.DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.DEFAULT_SLICING_PIPELINE = exports.DEFAULT_DATAFLOW_PIPELINE = exports.PipelineExecutor = exports.FlowrConfig = exports.TreeSitterExecutor = exports.RShell = exports.requestFromInput = exports.SlicingCriterion = exports.SlicingCriteria = exports.FlowrAnalyzerBuilder = exports.FlowrAnalyzer = void 0;
|
|
19
|
+
exports.retrieveVersionInformation = exports.flowrVersion = exports.TREE_SITTER_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.TREE_SITTER_SLICING_PIPELINE = exports.TREE_SITTER_DATAFLOW_PIPELINE = exports.DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.DEFAULT_SLICING_PIPELINE = exports.DEFAULT_DATAFLOW_PIPELINE = exports.PipelineExecutor = exports.FlowrConfig = exports.TreeSitterExecutor = exports.RShell = exports.requestFromInput = exports.SlicingCriterion = exports.SlicingCriteria = exports.Identifier = exports.FlowrAnalyzerBuilder = exports.FlowrAnalyzer = void 0;
|
|
20
20
|
/* the analyzer, which is the front door: everything else here is what its methods hand you or take */
|
|
21
21
|
var flowr_analyzer_1 = require("./project/flowr-analyzer");
|
|
22
22
|
Object.defineProperty(exports, "FlowrAnalyzer", { enumerable: true, get: function () { return flowr_analyzer_1.FlowrAnalyzer; } });
|
|
23
23
|
var flowr_analyzer_builder_1 = require("./project/flowr-analyzer-builder");
|
|
24
24
|
Object.defineProperty(exports, "FlowrAnalyzerBuilder", { enumerable: true, get: function () { return flowr_analyzer_builder_1.FlowrAnalyzerBuilder; } });
|
|
25
|
+
/* what `functionInfo` takes and hands back */
|
|
26
|
+
var identifier_1 = require("./dataflow/environments/identifier");
|
|
27
|
+
Object.defineProperty(exports, "Identifier", { enumerable: true, get: function () { return identifier_1.Identifier; } });
|
|
25
28
|
var parse_1 = require("./slicing/criterion/parse");
|
|
26
29
|
Object.defineProperty(exports, "SlicingCriteria", { enumerable: true, get: function () { return parse_1.SlicingCriteria; } });
|
|
27
30
|
Object.defineProperty(exports, "SlicingCriterion", { enumerable: true, get: function () { return parse_1.SlicingCriterion; } });
|
package/linter/linter-rules.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare const LintingRules: {
|
|
|
23
23
|
readonly certainty: import("./linter-format").LintingRuleCertainty.BestEffort;
|
|
24
24
|
readonly description: "Marks deprecated functions and deprecated arguments of still-current functions, offering the replacement as a quick fix where one is known. A call to a bare name whose package the code never attaches is reported as uncertain, as any function of that name would answer to it.";
|
|
25
25
|
readonly defaultConfig: {
|
|
26
|
-
readonly always: import("
|
|
26
|
+
readonly always: import("..").Identifier[];
|
|
27
27
|
readonly conditionally: Record<import("../dataflow/environments/identifier").BrandedIdentifier, import("./rules/deprecated-functions").DeprecatedFunctionInformation>;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
@@ -475,7 +475,7 @@ export declare const LintingRules: {
|
|
|
475
475
|
readonly system: {
|
|
476
476
|
readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Process;
|
|
477
477
|
readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
|
|
478
|
-
readonly sanitizers: readonly [import("
|
|
478
|
+
readonly sanitizers: readonly [import("..").Identifier];
|
|
479
479
|
readonly quickFix: {
|
|
480
480
|
readonly call: "shQuote";
|
|
481
481
|
};
|
|
@@ -483,14 +483,14 @@ export declare const LintingRules: {
|
|
|
483
483
|
readonly eval: {
|
|
484
484
|
readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Eval;
|
|
485
485
|
readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
|
|
486
|
-
readonly sanitizers: readonly [import("
|
|
486
|
+
readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier];
|
|
487
487
|
};
|
|
488
488
|
readonly database: {
|
|
489
489
|
readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Database;
|
|
490
490
|
readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
|
|
491
|
-
readonly sanitizers: readonly [import("
|
|
491
|
+
readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier];
|
|
492
492
|
readonly quickFix: {
|
|
493
|
-
readonly call: import("
|
|
493
|
+
readonly call: import("..").Identifier;
|
|
494
494
|
readonly firstArg: import("../dataflow/environments/built-in-props").ArgProp.Handle;
|
|
495
495
|
readonly partsOnly: true;
|
|
496
496
|
};
|
|
@@ -498,17 +498,17 @@ export declare const LintingRules: {
|
|
|
498
498
|
readonly html: {
|
|
499
499
|
readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Html;
|
|
500
500
|
readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
|
|
501
|
-
readonly sanitizers: readonly [import("
|
|
501
|
+
readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier];
|
|
502
502
|
readonly quickFix: {
|
|
503
|
-
readonly call: import("
|
|
503
|
+
readonly call: import("..").Identifier;
|
|
504
504
|
};
|
|
505
505
|
};
|
|
506
506
|
readonly javascript: {
|
|
507
507
|
readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.JavaScript;
|
|
508
508
|
readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
|
|
509
|
-
readonly sanitizers: readonly [import("
|
|
509
|
+
readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier];
|
|
510
510
|
readonly quickFix: {
|
|
511
|
-
readonly call: import("
|
|
511
|
+
readonly call: import("..").Identifier;
|
|
512
512
|
readonly partsOnly: true;
|
|
513
513
|
};
|
|
514
514
|
};
|
package/package.json
CHANGED
|
@@ -38,6 +38,11 @@ export interface ReadOnlyFlowrAnalyzerEnvironmentContext {
|
|
|
38
38
|
* Knows only the built-ins, no attached package, so prefer {@link cleanEnvOf} wherever an environment is at hand.
|
|
39
39
|
*/
|
|
40
40
|
makeCleanEnv(): REnvironmentInformation;
|
|
41
|
+
/**
|
|
42
|
+
* {@link makeCleanEnv} as a stable thunk. Hand this to something that may or may not need a clean
|
|
43
|
+
* environment (see {@link DataflowGraph#addVertex}), so offering one costs nothing when it goes unused.
|
|
44
|
+
*/
|
|
45
|
+
readonly cleanEnv: () => REnvironmentInformation;
|
|
41
46
|
/**
|
|
42
47
|
* Get the fingerprint of the clean environment with the configured built-in environment as base.
|
|
43
48
|
*/
|
|
@@ -77,6 +82,7 @@ export declare class FlowrAnalyzerEnvironmentContext implements ReadOnlyFlowrAna
|
|
|
77
82
|
builtInDefinitionsOf(name: Identifier): readonly IdentifierDefinition[];
|
|
78
83
|
knowsPackage(pkg: string): boolean;
|
|
79
84
|
builtInFunctionOf(name: Identifier): BuiltInIdentifierDefinition | undefined;
|
|
85
|
+
readonly cleanEnv: () => REnvironmentInformation;
|
|
80
86
|
makeCleanEnv(): REnvironmentInformation;
|
|
81
87
|
getCleanEnvFingerprint(): Fingerprint;
|
|
82
88
|
makeCleanEnvWithEmptyBuiltIns(): REnvironmentInformation;
|
|
@@ -83,6 +83,8 @@ class FlowrAnalyzerEnvironmentContext {
|
|
|
83
83
|
return this.builtInDefinitionsOf(name).find((d) => d.type === identifier_1.ReferenceType.BuiltInFunction && typeof d.processor === 'function'
|
|
84
84
|
&& (namespace === undefined || (d.name !== undefined && identifier_1.Identifier.getNamespace(d.name) === namespace)));
|
|
85
85
|
}
|
|
86
|
+
/* one thunk per context rather than one per call, as the callers offering it mostly do not need it */
|
|
87
|
+
cleanEnv = () => this.makeCleanEnv();
|
|
86
88
|
makeCleanEnv() {
|
|
87
89
|
return {
|
|
88
90
|
current: new environment_1.Environment(this.builtInEnv).asGlobal(),
|
|
@@ -19,6 +19,8 @@ import type { Tree } from 'web-tree-sitter';
|
|
|
19
19
|
import type { CallGraph } from '../dataflow/graph/call-graph';
|
|
20
20
|
import type { InvalidationEvent } from './cache/flowr-cache';
|
|
21
21
|
import type { GasOverrides } from '../gas';
|
|
22
|
+
import type { FnInfo } from '../dataflow/environments/query-fn-props';
|
|
23
|
+
import { Identifier } from '../dataflow/environments/identifier';
|
|
22
24
|
/** Options for a single analyzer operation, bounding what it may cost. */
|
|
23
25
|
export interface FlowrAnalysisOptions {
|
|
24
26
|
/**
|
|
@@ -79,6 +81,16 @@ export interface ReadonlyFlowrAnalysisProvider<Parser extends KnownParser = Know
|
|
|
79
81
|
* This is the preferred method for users that want to inspect the context.
|
|
80
82
|
*/
|
|
81
83
|
inspectContext(): ReadOnlyFlowrAnalyzerContext;
|
|
84
|
+
/**
|
|
85
|
+
* What flowR knows about the function `name`, whether that is one of its own built-ins, a package function
|
|
86
|
+
* the signature database carries, or both; see {@link fnInfo}.
|
|
87
|
+
*
|
|
88
|
+
* A string is read the way R source spells a name, so `'dplyr::lead'` and `'dplyr:::internal'` name the
|
|
89
|
+
* package function rather than a symbol with a `::` in it (pass an {@link Identifier} for that one).
|
|
90
|
+
* @param name - The function to ask about, `'dplyr::lead'` or `Identifier.make('lead', 'dplyr')` to pin the package down.
|
|
91
|
+
* @param version - The package version to answer for, the one the analysis assumes if omitted.
|
|
92
|
+
*/
|
|
93
|
+
functionInfo(name: Identifier | string, version?: string): FnInfo | undefined;
|
|
82
94
|
/**
|
|
83
95
|
* Get the parse output for the request.
|
|
84
96
|
*
|
|
@@ -195,6 +207,7 @@ export declare class FlowrAnalyzer<Parser extends KnownParser = KnownParser> imp
|
|
|
195
207
|
context(): FlowrAnalyzerContext;
|
|
196
208
|
parserInformation(): KnownParserInformation;
|
|
197
209
|
inspectContext(): ReadOnlyFlowrAnalyzerContext;
|
|
210
|
+
functionInfo(name: Identifier | string, version?: string): FnInfo | undefined;
|
|
198
211
|
reset(): void;
|
|
199
212
|
receive(event: InvalidationEvent): void;
|
|
200
213
|
updateConfig(update: DeepPartial<FlowrConfig>): void;
|
|
@@ -8,6 +8,8 @@ const retriever_1 = require("../r-bridge/retriever");
|
|
|
8
8
|
const files_1 = require("../util/files");
|
|
9
9
|
const tree_sitter_normalize_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize");
|
|
10
10
|
const tree_sitter_executor_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-executor");
|
|
11
|
+
const query_fn_props_1 = require("../dataflow/environments/query-fn-props");
|
|
12
|
+
const identifier_1 = require("../dataflow/environments/identifier");
|
|
11
13
|
/**
|
|
12
14
|
* Central class for conducting analyses with FlowR.
|
|
13
15
|
* Use the {@link FlowrAnalyzerBuilder} to create a new instance.
|
|
@@ -50,6 +52,9 @@ class FlowrAnalyzer {
|
|
|
50
52
|
inspectContext() {
|
|
51
53
|
return this.ctx.inspect();
|
|
52
54
|
}
|
|
55
|
+
functionInfo(name, version) {
|
|
56
|
+
return (0, query_fn_props_1.fnInfo)(typeof name === 'string' ? identifier_1.Identifier.parse(name) : name, this.ctx.inspect(), version);
|
|
57
|
+
}
|
|
53
58
|
reset() {
|
|
54
59
|
this.ctx.reset();
|
|
55
60
|
this.cache.reset();
|
|
@@ -44,6 +44,9 @@ export interface SignatureDb {
|
|
|
44
44
|
* A name the package answers only as part of an S4 group falls back to the group: `Matrix::sin` is served by
|
|
45
45
|
* `Matrix`'s `Math` entry when there is no `sin` of its own, because that is what an `sin(x)` call dispatches
|
|
46
46
|
* to. The result then carries the group's name, not the one that was asked for.
|
|
47
|
+
*
|
|
48
|
+
* The {@link Identifier} decides how far the lookup reaches: `pkg::fn` answers only with what the package
|
|
49
|
+
* exports, `pkg:::fn` reaches its internals as well, exactly as R has it.
|
|
47
50
|
* @param id - The qualified identifier of the function.
|
|
48
51
|
* @param version - The version to answer for, {@link versionOf} of its package if omitted.
|
|
49
52
|
*/
|
|
@@ -34,18 +34,19 @@ function signatureDbOf(deps) {
|
|
|
34
34
|
return any;
|
|
35
35
|
};
|
|
36
36
|
const functionOf = (id, version) => {
|
|
37
|
-
const pkg = identifier_1.Identifier.
|
|
37
|
+
const [name, pkg, internal] = identifier_1.Identifier.toArray(id);
|
|
38
38
|
if (pkg === undefined) {
|
|
39
39
|
return undefined; // without a package there is nothing to look the function up in
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
const
|
|
41
|
+
/* `::` reaches what the package exports, only `:::` reaches the rest */
|
|
42
|
+
const reaches = (fn) => fn !== undefined && (fn.exported || internal === true) ? fn : undefined;
|
|
43
|
+
const found = reaches(answerFor(pkg, version, (src, v) => src.functionByName(pkg, name, v)));
|
|
43
44
|
if (found !== undefined) {
|
|
44
45
|
return found;
|
|
45
46
|
}
|
|
46
47
|
/* `setMethod('Math', 'cls', ...)` answers every member of the group at once, so the group is the entry */
|
|
47
48
|
const group = (0, group_generics_1.groupGenericOf)(name);
|
|
48
|
-
return group === undefined ? undefined : answerFor(pkg, version, (src, v) => src.functionByName(pkg, group, v));
|
|
49
|
+
return group === undefined ? undefined : reaches(answerFor(pkg, version, (src, v) => src.functionByName(pkg, group, v)));
|
|
49
50
|
};
|
|
50
51
|
return {
|
|
51
52
|
available: () => deps.signatureSources().length > 0,
|
|
@@ -98,8 +98,7 @@ export interface SignatureFunctionView {
|
|
|
98
98
|
/**
|
|
99
99
|
* whether the whole view comes from flowR's built-in definition because the database has no entry: the
|
|
100
100
|
* primitives and operators (`+`, `[`, `if`) that appear in no package's sources, and anything a flowR
|
|
101
|
-
* configuration adds.
|
|
102
|
-
* and since flowR records no defaults, every {@link SignatureParameterView.required} reads `false`.
|
|
101
|
+
* configuration adds.
|
|
103
102
|
*/
|
|
104
103
|
readonly flowrOnly?: boolean;
|
|
105
104
|
}
|
|
@@ -16,7 +16,6 @@ export type BiMapReverse = 'lazy' | 'eager';
|
|
|
16
16
|
*/
|
|
17
17
|
export declare class BiMap<K, V extends object> implements Map<K, V> {
|
|
18
18
|
readonly [Symbol.toStringTag]: string;
|
|
19
|
-
size: number;
|
|
20
19
|
private readonly k2v;
|
|
21
20
|
private v2k;
|
|
22
21
|
private readonly eager;
|
|
@@ -26,6 +25,8 @@ export declare class BiMap<K, V extends object> implements Map<K, V> {
|
|
|
26
25
|
*/
|
|
27
26
|
constructor(base?: Iterable<[K, V]>, reverse?: BiMapReverse);
|
|
28
27
|
[Symbol.iterator](): MapIterator<[K, V]>;
|
|
28
|
+
/** Read off the forward direction, so filling the map costs no bookkeeping per entry. */
|
|
29
|
+
get size(): number;
|
|
29
30
|
clear(): void;
|
|
30
31
|
delete(key: K): boolean;
|
|
31
32
|
entries(): MapIterator<[K, V]>;
|
|
@@ -8,7 +8,6 @@ exports.BiMap = void 0;
|
|
|
8
8
|
*/
|
|
9
9
|
class BiMap {
|
|
10
10
|
[Symbol.toStringTag] = 'BiMap';
|
|
11
|
-
size = 0;
|
|
12
11
|
k2v = new Map();
|
|
13
12
|
/* see {@link BiMapReverse}: `undefined` until the first reverse lookup unless this map was asked to be eager */
|
|
14
13
|
v2k;
|
|
@@ -31,8 +30,11 @@ class BiMap {
|
|
|
31
30
|
[Symbol.iterator]() {
|
|
32
31
|
return this.k2v[Symbol.iterator]();
|
|
33
32
|
}
|
|
33
|
+
/** Read off the forward direction, so filling the map costs no bookkeeping per entry. */
|
|
34
|
+
get size() {
|
|
35
|
+
return this.k2v.size;
|
|
36
|
+
}
|
|
34
37
|
clear() {
|
|
35
|
-
this.size = 0;
|
|
36
38
|
this.k2v.clear();
|
|
37
39
|
this.v2k = this.eager ? new WeakMap() : undefined;
|
|
38
40
|
}
|
|
@@ -44,7 +46,6 @@ class BiMap {
|
|
|
44
46
|
this.k2v.delete(key);
|
|
45
47
|
/* another key may still hold this value, so dropping just its entry would lose a live mapping */
|
|
46
48
|
this.staleReverse();
|
|
47
|
-
this.size = this.k2v.size;
|
|
48
49
|
return true;
|
|
49
50
|
}
|
|
50
51
|
entries() {
|
|
@@ -86,7 +87,6 @@ class BiMap {
|
|
|
86
87
|
this.v2k.set(value, key);
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
|
-
this.size = this.k2v.size;
|
|
90
90
|
return this;
|
|
91
91
|
}
|
|
92
92
|
/** the reverse direction can no longer be maintained in place, so re-derive it (at once if eager) */
|
package/util/version.js
CHANGED
|
@@ -42,9 +42,9 @@ const assert_1 = require("./assert");
|
|
|
42
42
|
const sigdb_download_1 = require("../project/sigdb/sigdb-download");
|
|
43
43
|
const doc_files_1 = require("../documentation/doc-util/doc-files");
|
|
44
44
|
// this is automatically replaced with the current version by release-it
|
|
45
|
-
const version = '2.15.
|
|
45
|
+
const version = '2.15.3';
|
|
46
46
|
// this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
|
|
47
|
-
const versionDate = '2026-08-
|
|
47
|
+
const versionDate = '2026-08-26T12:04:46Z';
|
|
48
48
|
/**
|
|
49
49
|
* Retrieves the current flowR version as a new {@link SemVer} object.
|
|
50
50
|
*/
|