@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
|
@@ -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();
|
package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js
CHANGED
|
@@ -323,7 +323,9 @@ class FlowrAnalyzerPackageVersionsSigDbPlugin extends flowr_analyzer_package_ver
|
|
|
323
323
|
if (cached !== undefined) {
|
|
324
324
|
return cached;
|
|
325
325
|
}
|
|
326
|
-
|
|
326
|
+
/* the historical bundle is not asked: a name is hinted so a `library()` can be added for it, and a package
|
|
327
|
+
only that bundle carries is one nothing can attach today */
|
|
328
|
+
const sources = this.loadSources().filter(s => describeLoadedDatabase(s).scope !== 'history');
|
|
327
329
|
const seen = new Set();
|
|
328
330
|
const owners = [];
|
|
329
331
|
for (const src of sources) {
|
|
@@ -239,7 +239,7 @@ function defaultSigDbPaths(searchRoots) {
|
|
|
239
239
|
// a standalone bundle is a `.sigs.ndjson` that is not a shard of a discovered manifest (`<manifest>.<shard>...`)
|
|
240
240
|
const prefixes = [...manifests.keys()].map(k => k.replace(/\.manifest\.json$/, ''));
|
|
241
241
|
const isShard = (name) => {
|
|
242
|
-
const base = name.replace(new RegExp(`${schema_1.SigDbExt.replace(
|
|
242
|
+
const base = name.replace(new RegExp(`${schema_1.SigDbExt.replace(/\./g, '\\.')}$`), '');
|
|
243
243
|
return prefixes.some(p => base === p || base.startsWith(p + '.'));
|
|
244
244
|
};
|
|
245
245
|
const scopeRank = (name) => {
|
|
@@ -143,11 +143,11 @@ export interface OpenSyncFromOptions extends SigDbOpenOptions, OpenSyncOptions {
|
|
|
143
143
|
*/
|
|
144
144
|
export declare class SigDatabase implements PackageSignatureSource {
|
|
145
145
|
private closed;
|
|
146
|
-
/** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse;
|
|
146
|
+
/** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; bounded by {@link BlobCacheBudget} */
|
|
147
147
|
private readonly blobCache;
|
|
148
|
-
|
|
149
|
-
/** a version's function indices plus its `name -> index` view; FIFO-bounded like {@link blobCache} */
|
|
148
|
+
/** a version's function indices plus its `name -> index` view, keyed by package and version; FIFO-bounded */
|
|
150
149
|
private readonly versionFnCache;
|
|
150
|
+
private static readonly VersionFnCacheCap;
|
|
151
151
|
/** which names a package can offer at all, as sorted dictionary ids; filled the first time its blob is read */
|
|
152
152
|
private readonly nameIdsOfBlob;
|
|
153
153
|
/** dictionary id per name asked for, so only the names someone actually queried are ever resolved */
|
|
@@ -185,7 +185,9 @@ export declare class SigDatabase implements PackageSignatureSource {
|
|
|
185
185
|
* nothing is known about the package yet, so this only ever skips work that would have found nothing.
|
|
186
186
|
*/
|
|
187
187
|
private mayOffer;
|
|
188
|
-
/**
|
|
188
|
+
/** drop one decoded blob, for the shared budget to reclaim what it costs (see {@link keepBlob}) */
|
|
189
|
+
dropBlob(blobIdx: number): void;
|
|
190
|
+
/** store `value` under `key`, dropping the oldest entry first once the cache sits at `cap` */
|
|
189
191
|
private static cache;
|
|
190
192
|
/** seek to a byte range, read + decode the package blob there (no caching) */
|
|
191
193
|
private readBlobAt;
|
|
@@ -209,7 +211,11 @@ export declare class SigDatabase implements PackageSignatureSource {
|
|
|
209
211
|
*/
|
|
210
212
|
private exportsNameId;
|
|
211
213
|
classOwner(className: string, version?: string): string | undefined;
|
|
212
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* Resolve a package version to its blob and the function records of that version (the shared prologue of
|
|
216
|
+
* {@link functions}/{@link functionByName}). The blob comes from {@link blob} every time rather than out of
|
|
217
|
+
* {@link versionFnCache}: holding one here would keep it decoded past what {@link BlobCacheBudget} allows.
|
|
218
|
+
*/
|
|
213
219
|
private versionFns;
|
|
214
220
|
functions(pkg: string, version?: string): DecodedFunction[] | undefined;
|
|
215
221
|
functionByName(pkg: string, name: string, version?: string): DecodedFunction | undefined;
|
package/project/sigdb/reader.js
CHANGED
|
@@ -50,22 +50,22 @@ function bucketKeyOf(name) {
|
|
|
50
50
|
function dictionaryIdOf(strings, name) {
|
|
51
51
|
let buckets = dictionaryBuckets.get(strings);
|
|
52
52
|
if (buckets === undefined) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
sizes.set(key, (sizes.get(key) ?? 0) + 1);
|
|
57
|
-
}
|
|
58
|
-
buckets = new Map();
|
|
59
|
-
const filled = new Map();
|
|
60
|
-
for (const [key, size] of sizes) {
|
|
61
|
-
buckets.set(key, new Int32Array(size));
|
|
62
|
-
filled.set(key, 0);
|
|
63
|
-
}
|
|
53
|
+
/* one pass over the 1.4 million entries: sizing them first meant walking all of them twice and a map
|
|
54
|
+
lookup per entry to know where in its group the next one goes */
|
|
55
|
+
const grouped = new Map();
|
|
64
56
|
for (let i = 0; i < strings.length; i++) {
|
|
65
57
|
const key = bucketKeyOf(strings[i]);
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
const group = grouped.get(key);
|
|
59
|
+
if (group === undefined) {
|
|
60
|
+
grouped.set(key, [i]);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
group.push(i);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
buckets = new Map();
|
|
67
|
+
for (const [key, group] of grouped) {
|
|
68
|
+
buckets.set(key, Int32Array.from(group));
|
|
69
69
|
}
|
|
70
70
|
dictionaryBuckets.set(strings, buckets);
|
|
71
71
|
}
|
|
@@ -308,17 +308,37 @@ function sourceForPackage(sources, pkg) {
|
|
|
308
308
|
}
|
|
309
309
|
/** the {@link SigDatabase.fd} of a database that has no file behind it (see {@link SigDatabase.fromMemory}) */
|
|
310
310
|
const NoFile = -1;
|
|
311
|
+
/**
|
|
312
|
+
* One budget for every open bundle, spent in the bytes the blobs take on disk. Per bundle it would not bound
|
|
313
|
+
* anything: how many shards a query set opens is not something the caller picks, and each would claim the
|
|
314
|
+
* budget again. A count would not bound anything either -- one package's blob outweighs a hundred small ones.
|
|
315
|
+
*/
|
|
316
|
+
const BlobCacheBudget = 8 * 1024 * 1024;
|
|
317
|
+
/** what every open bundle holds decoded, oldest read first, so the budget is spent across all of them */
|
|
318
|
+
const cachedBlobs = [];
|
|
319
|
+
let cachedBlobBytes = 0;
|
|
320
|
+
/** keep `blob` decoded for `db`, dropping what any bundle read longest ago until all of them fit the budget */
|
|
321
|
+
function keepBlob(db, blobIdx, bytes) {
|
|
322
|
+
while (cachedBlobBytes + bytes > BlobCacheBudget && cachedBlobs.length > 0) {
|
|
323
|
+
const dropped = cachedBlobs.shift();
|
|
324
|
+
/* the bytes are off the list either way: a closed bundle already let its blobs go */
|
|
325
|
+
cachedBlobBytes -= dropped.bytes;
|
|
326
|
+
dropped.db.dropBlob(dropped.blobIdx);
|
|
327
|
+
}
|
|
328
|
+
cachedBlobs.push({ db, blobIdx, bytes });
|
|
329
|
+
cachedBlobBytes += bytes;
|
|
330
|
+
}
|
|
311
331
|
/**
|
|
312
332
|
* Fast, partial reader for a single bundle. `open()`/`openSync()` load the string dictionary + `.idx` once, then every
|
|
313
333
|
* query seeks straight to one package blob; `open()` additionally decompresses a `.br`/`.gz` source into a hash-keyed cache.
|
|
314
334
|
*/
|
|
315
335
|
class SigDatabase {
|
|
316
336
|
closed = false;
|
|
317
|
-
/** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse;
|
|
337
|
+
/** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; bounded by {@link BlobCacheBudget} */
|
|
318
338
|
blobCache = new Map();
|
|
319
|
-
|
|
320
|
-
/** a version's function indices plus its `name -> index` view; FIFO-bounded like {@link blobCache} */
|
|
339
|
+
/** a version's function indices plus its `name -> index` view, keyed by package and version; FIFO-bounded */
|
|
321
340
|
versionFnCache = new Map();
|
|
341
|
+
static VersionFnCacheCap = 2048;
|
|
322
342
|
/** which names a package can offer at all, as sorted dictionary ids; filled the first time its blob is read */
|
|
323
343
|
nameIdsOfBlob = new Map();
|
|
324
344
|
/** dictionary id per name asked for, so only the names someone actually queried are ever resolved */
|
|
@@ -406,11 +426,14 @@ class SigDatabase {
|
|
|
406
426
|
if (this.fd === NoFile) {
|
|
407
427
|
return undefined; // an in-memory database starts out with every blob cached
|
|
408
428
|
}
|
|
409
|
-
const
|
|
429
|
+
const range = this.index.blobs[blobIdx];
|
|
430
|
+
const blob = this.readBlobAt(range);
|
|
410
431
|
if (!this.nameIdsOfBlob.has(blobIdx)) {
|
|
411
432
|
this.nameIdsOfBlob.set(blobIdx, Int32Array.from(new Set(blob.fns.map(fn => fn[0]))).sort());
|
|
412
433
|
}
|
|
413
|
-
|
|
434
|
+
keepBlob(this, blobIdx, range[1]);
|
|
435
|
+
this.blobCache.set(blobIdx, blob);
|
|
436
|
+
return blob;
|
|
414
437
|
}
|
|
415
438
|
/** the dictionary id of `name`, or `-1` if the dictionary does not hold it, so no package can offer it */
|
|
416
439
|
nameId(name) {
|
|
@@ -449,9 +472,13 @@ class SigDatabase {
|
|
|
449
472
|
}
|
|
450
473
|
return false;
|
|
451
474
|
}
|
|
452
|
-
/**
|
|
453
|
-
|
|
454
|
-
|
|
475
|
+
/** drop one decoded blob, for the shared budget to reclaim what it costs (see {@link keepBlob}) */
|
|
476
|
+
dropBlob(blobIdx) {
|
|
477
|
+
this.blobCache.delete(blobIdx);
|
|
478
|
+
}
|
|
479
|
+
/** store `value` under `key`, dropping the oldest entry first once the cache sits at `cap` */
|
|
480
|
+
static cache(cache, key, value, cap) {
|
|
481
|
+
if (cache.size >= cap) {
|
|
455
482
|
const oldest = cache.keys().next().value;
|
|
456
483
|
if (oldest !== undefined) {
|
|
457
484
|
cache.delete(oldest);
|
|
@@ -528,7 +555,7 @@ class SigDatabase {
|
|
|
528
555
|
if (r === undefined) {
|
|
529
556
|
return false;
|
|
530
557
|
}
|
|
531
|
-
for (const i of r.idxs) {
|
|
558
|
+
for (const i of r.fns.idxs) {
|
|
532
559
|
const fn = r.blob.fns[i];
|
|
533
560
|
if (fn[0] === id && (fn[3] & 1 /* FnProp.Exported */) !== 0) {
|
|
534
561
|
return true;
|
|
@@ -543,7 +570,11 @@ class SigDatabase {
|
|
|
543
570
|
this.classIndex ??= classOwnerIndexFor(this, this.packageNames());
|
|
544
571
|
return this.classIndex.get(className);
|
|
545
572
|
}
|
|
546
|
-
/**
|
|
573
|
+
/**
|
|
574
|
+
* Resolve a package version to its blob and the function records of that version (the shared prologue of
|
|
575
|
+
* {@link functions}/{@link functionByName}). The blob comes from {@link blob} every time rather than out of
|
|
576
|
+
* {@link versionFnCache}: holding one here would keep it decoded past what {@link BlobCacheBudget} allows.
|
|
577
|
+
*/
|
|
547
578
|
versionFns(pkg, version) {
|
|
548
579
|
const bm = this.blobMeta(pkg);
|
|
549
580
|
if (!bm) {
|
|
@@ -557,17 +588,17 @@ class SigDatabase {
|
|
|
557
588
|
const key = `${pkg}\0${ver}`;
|
|
558
589
|
const cached = this.versionFnCache.get(key);
|
|
559
590
|
if (cached !== undefined) {
|
|
560
|
-
return cached;
|
|
591
|
+
return { blob: bm.blob, fns: cached };
|
|
561
592
|
}
|
|
562
593
|
const idxs = (0, decode_1.versionFnIndices)(bm.blob, ver);
|
|
563
594
|
if (idxs === undefined) {
|
|
564
595
|
return undefined;
|
|
565
596
|
}
|
|
566
|
-
return SigDatabase.cache(this.versionFnCache, key, {
|
|
597
|
+
return { blob: bm.blob, fns: SigDatabase.cache(this.versionFnCache, key, { idxs }, SigDatabase.VersionFnCacheCap) };
|
|
567
598
|
}
|
|
568
599
|
functions(pkg, version) {
|
|
569
600
|
const r = this.versionFns(pkg, version);
|
|
570
|
-
return r?.idxs.map(i => (0, decode_1.decodeFunction)(this.strings, r.blob, i));
|
|
601
|
+
return r?.fns.idxs.map(i => (0, decode_1.decodeFunction)(this.strings, r.blob, i));
|
|
571
602
|
}
|
|
572
603
|
functionByName(pkg, name, version) {
|
|
573
604
|
if (!this.mayOffer(pkg, name)) {
|
|
@@ -577,18 +608,18 @@ class SigDatabase {
|
|
|
577
608
|
if (r === undefined) {
|
|
578
609
|
return undefined;
|
|
579
610
|
}
|
|
580
|
-
if (r.byName === undefined) {
|
|
611
|
+
if (r.fns.byName === undefined) {
|
|
581
612
|
const byName = new Map();
|
|
582
|
-
for (const i of r.idxs) {
|
|
613
|
+
for (const i of r.fns.idxs) {
|
|
583
614
|
const fn = this.strings[r.blob.fns[i][0]];
|
|
584
615
|
// first record wins, as the linear scan did
|
|
585
616
|
if (!byName.has(fn)) {
|
|
586
617
|
byName.set(fn, i);
|
|
587
618
|
}
|
|
588
619
|
}
|
|
589
|
-
r.byName = byName;
|
|
620
|
+
r.fns.byName = byName;
|
|
590
621
|
}
|
|
591
|
-
const hit = r.byName.get(name);
|
|
622
|
+
const hit = r.fns.byName.get(name);
|
|
592
623
|
return hit !== undefined ? (0, decode_1.decodeFunction)(this.strings, r.blob, hit) : undefined;
|
|
593
624
|
}
|
|
594
625
|
transitiveCallees(pkg, name, version) {
|
|
@@ -647,6 +678,7 @@ class SigDatabase {
|
|
|
647
678
|
if (!this.closed) {
|
|
648
679
|
this.closed = true;
|
|
649
680
|
this.blobCache.clear();
|
|
681
|
+
this.versionFnCache.clear();
|
|
650
682
|
this.classIndex = undefined;
|
|
651
683
|
if (this.fd !== NoFile) {
|
|
652
684
|
fs_1.default.closeSync(this.fd);
|
|
@@ -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,
|
|
@@ -14,8 +14,9 @@ async function executeDiceQuery({ analyzer }, queries) {
|
|
|
14
14
|
const results = {};
|
|
15
15
|
const ast = await analyzer.normalize();
|
|
16
16
|
const df = await analyzer.dataflow();
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const keys = (0, slice_query_options_1.sliceResultKeys)(queries, query => `${query.from.join(',')}->${query.to.join(',')}`);
|
|
18
|
+
for (const [at, query] of queries.entries()) {
|
|
19
|
+
const key = keys[at];
|
|
19
20
|
if (results[key]) {
|
|
20
21
|
log_1.log.warn(`Duplicate key for dice-query: ${key}, skipping...`);
|
|
21
22
|
continue;
|
|
@@ -428,6 +428,11 @@ class InputClassifier {
|
|
|
428
428
|
if (callee !== undefined) {
|
|
429
429
|
return this.classifyCdsAndReturn(call, { ...callee, id: call.id });
|
|
430
430
|
}
|
|
431
|
+
// a call of a function the code defines yields whatever that function returns
|
|
432
|
+
const returned = this.classifyDefinitionResult(call);
|
|
433
|
+
if (returned !== undefined) {
|
|
434
|
+
return this.classifyCdsAndReturn(call, returned);
|
|
435
|
+
}
|
|
431
436
|
// if it is not pure, we cannot classify based on the inputs, in that case we do not know!
|
|
432
437
|
types.push(input_types_1.InputType.Unknown);
|
|
433
438
|
}
|
|
@@ -466,6 +471,68 @@ class InputClassifier {
|
|
|
466
471
|
argTypes.push(input_types_1.InputType.DerivedConstant);
|
|
467
472
|
return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: (0, arrays_1.uniqueArray)(argTypes), trace: input_types_1.InputTraceType.Known, cds }));
|
|
468
473
|
}
|
|
474
|
+
/**
|
|
475
|
+
* What a call of a function the analyzed code defines yields: what its exit points do, as a function whose
|
|
476
|
+
* body is `system(x)` runs a system command whether the call reads `f(cmd)` or `system(cmd)`. `undefined`
|
|
477
|
+
* when the call names no definition here or when none of them says anything about what it returns.
|
|
478
|
+
*/
|
|
479
|
+
classifyDefinitionResult(call) {
|
|
480
|
+
const graph = this.fullDfg ?? this.dfg;
|
|
481
|
+
const acc = new ClassificationAccumulator();
|
|
482
|
+
let known = false;
|
|
483
|
+
for (const fn of this.functionDefinitionsAt(call.id)) {
|
|
484
|
+
const definition = graph.getVertex(fn);
|
|
485
|
+
if (!vertex_1.FunctionDefinitionVertex.is(definition)) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
for (const { nodeId } of definition.exitPoints) {
|
|
489
|
+
for (const value of this.exitValues(nodeId)) {
|
|
490
|
+
const vtx = value === undefined ? undefined : this.dfg.getVertex(value) ?? graph.getVertex(value);
|
|
491
|
+
const classified = vtx ? this.classifyEntry(vtx) : undefined;
|
|
492
|
+
if (classified === undefined) {
|
|
493
|
+
/* an exit flowR cannot place says nothing about the call, so neither can the others */
|
|
494
|
+
return undefined;
|
|
495
|
+
}
|
|
496
|
+
known = true;
|
|
497
|
+
acc.merge(classified);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (!known) {
|
|
502
|
+
return undefined;
|
|
503
|
+
}
|
|
504
|
+
const built = acc.build(call.id);
|
|
505
|
+
return built.types.includes(input_types_1.InputType.Unknown) ? undefined : built;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* What an exit point hands back, descending through the branches of an `if` (which yields one of them, while
|
|
509
|
+
* {@link classifyFunctionCall} reports the condition it depends on). Yields `undefined` for a construct whose
|
|
510
|
+
* value flowR cannot name, a loop above all, so the caller stops rather than answers with the branches alone.
|
|
511
|
+
*/
|
|
512
|
+
*exitValues(id, depth = 0) {
|
|
513
|
+
const vtx = (this.dfg.getVertex(id) ?? (this.fullDfg ?? this.dfg).getVertex(id));
|
|
514
|
+
if (vtx === undefined || !vertex_1.FunctionCallVertex.is(vtx)) {
|
|
515
|
+
yield id;
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop) || vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop) || vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.RepeatLoop)) {
|
|
519
|
+
yield undefined;
|
|
520
|
+
}
|
|
521
|
+
else if (vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) && depth <= MaxFunctionResolveDepth) {
|
|
522
|
+
for (const branch of vtx.args.slice(1)) {
|
|
523
|
+
const ref = graph_1.FunctionArgument.isEmpty(branch) ? undefined : graph_1.FunctionArgument.getReference(branch);
|
|
524
|
+
if (ref === undefined) {
|
|
525
|
+
yield undefined;
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
yield* this.exitValues(ref, depth + 1);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
yield id;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
469
536
|
/** classifies what a call of a variable (e.g. a shiny reactive `n()`) yields, by what that variable holds */
|
|
470
537
|
classifyCallee(call) {
|
|
471
538
|
for (const o of df_helper_1.Dataflow.origin(this.dfg, call.id) ?? []) {
|
|
@@ -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
|
}
|
|
@@ -57,11 +57,17 @@ export declare const SliceQueryOptionsSchema: {
|
|
|
57
57
|
readonly reportPackages: Joi.BooleanSchema<boolean>;
|
|
58
58
|
};
|
|
59
59
|
/**
|
|
60
|
-
* How a slicing query's result is keyed: under the name it was given, else under
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* How a slicing query's result is keyed: under the name it was given, else under what it slices (`2@x`), which
|
|
61
|
+
* is what a caller looks the result up by. Use {@link sliceResultKeys} for a whole request, as only there can
|
|
62
|
+
* two queries be seen to want the same key.
|
|
63
63
|
*/
|
|
64
|
-
export declare function sliceResultKey(query:
|
|
64
|
+
export declare function sliceResultKey<T extends SliceQueryOptions>(query: T, describe: (query: T) => string): string;
|
|
65
|
+
/**
|
|
66
|
+
* The keys a whole request's results are reported under (see {@link sliceResultKey}). Two queries that differ
|
|
67
|
+
* only in their options would want the same key, and only one of them could be reported; those fall back to the
|
|
68
|
+
* serialized query, so nothing is silently merged. Two *identical* queries still share one entry, as they must.
|
|
69
|
+
*/
|
|
70
|
+
export declare function sliceResultKeys<T extends SliceQueryOptions>(queries: readonly T[], describe: (query: T) => string): string[];
|
|
65
71
|
/** Whether a result key is a serialized query rather than the name someone gave the slice. */
|
|
66
72
|
export declare function isSerializedQuery(key: string): boolean;
|
|
67
73
|
/**
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SliceQueryOptionsSchema = void 0;
|
|
7
7
|
exports.sliceResultKey = sliceResultKey;
|
|
8
|
+
exports.sliceResultKeys = sliceResultKeys;
|
|
8
9
|
exports.isSerializedQuery = isSerializedQuery;
|
|
9
10
|
exports.resolveSliceCriteria = resolveSliceCriteria;
|
|
10
11
|
exports.reconstructSlice = reconstructSlice;
|
|
@@ -31,12 +32,33 @@ exports.SliceQueryOptionsSchema = {
|
|
|
31
32
|
reportPackages: joi_1.default.boolean().optional().description('Also report the packages the slice calls into, i.e. what this selection needs installed rather than what the whole program loads.')
|
|
32
33
|
};
|
|
33
34
|
/**
|
|
34
|
-
* How a slicing query's result is keyed: under the name it was given, else under
|
|
35
|
-
*
|
|
36
|
-
*
|
|
35
|
+
* How a slicing query's result is keyed: under the name it was given, else under what it slices (`2@x`), which
|
|
36
|
+
* is what a caller looks the result up by. Use {@link sliceResultKeys} for a whole request, as only there can
|
|
37
|
+
* two queries be seen to want the same key.
|
|
37
38
|
*/
|
|
38
|
-
function sliceResultKey(query) {
|
|
39
|
-
return query.name ??
|
|
39
|
+
function sliceResultKey(query, describe) {
|
|
40
|
+
return query.name ?? describe(query);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The keys a whole request's results are reported under (see {@link sliceResultKey}). Two queries that differ
|
|
44
|
+
* only in their options would want the same key, and only one of them could be reported; those fall back to the
|
|
45
|
+
* serialized query, so nothing is silently merged. Two *identical* queries still share one entry, as they must.
|
|
46
|
+
*/
|
|
47
|
+
function sliceResultKeys(queries, describe) {
|
|
48
|
+
const short = queries.map(q => sliceResultKey(q, describe));
|
|
49
|
+
const claimed = new Map();
|
|
50
|
+
const collided = new Set();
|
|
51
|
+
queries.forEach((query, i) => {
|
|
52
|
+
const serialized = JSON.stringify(query);
|
|
53
|
+
const first = claimed.get(short[i]);
|
|
54
|
+
if (first === undefined) {
|
|
55
|
+
claimed.set(short[i], serialized);
|
|
56
|
+
}
|
|
57
|
+
else if (first !== serialized) {
|
|
58
|
+
collided.add(short[i]);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return queries.map((query, i) => query.name === undefined && collided.has(short[i]) ? JSON.stringify(query) : short[i]);
|
|
40
62
|
}
|
|
41
63
|
/** Whether a result key is a serialized query rather than the name someone gave the slice. */
|
|
42
64
|
function isSerializedQuery(key) {
|
|
@@ -2,7 +2,7 @@ import type { StaticSliceQuery, StaticSliceQueryResult } from './static-slice-qu
|
|
|
2
2
|
import type { BasicQueryData } from '../../base-query-format';
|
|
3
3
|
/**
|
|
4
4
|
* The key a static slice query's result is reported under: the {@link SliceQueryOptions#name|name} it was given,
|
|
5
|
-
* else
|
|
5
|
+
* else what it slices. Within a request use {@link sliceResultKeys}, which settles two queries wanting one key.
|
|
6
6
|
*/
|
|
7
7
|
export declare function fingerPrintOfQuery(query: StaticSliceQuery): string;
|
|
8
8
|
/**
|
|
@@ -7,12 +7,14 @@ const slice_query_options_1 = require("../slice-query-options");
|
|
|
7
7
|
const log_1 = require("../../../util/log");
|
|
8
8
|
const slice_direction_1 = require("../../../util/slice-direction");
|
|
9
9
|
const df_helper_1 = require("../../../dataflow/graph/df-helper");
|
|
10
|
+
/** what a static slice is of, which is what its result is keyed by when it was given no name */
|
|
11
|
+
const slicedBy = (query) => query.criteria.join(',');
|
|
10
12
|
/**
|
|
11
13
|
* The key a static slice query's result is reported under: the {@link SliceQueryOptions#name|name} it was given,
|
|
12
|
-
* else
|
|
14
|
+
* else what it slices. Within a request use {@link sliceResultKeys}, which settles two queries wanting one key.
|
|
13
15
|
*/
|
|
14
16
|
function fingerPrintOfQuery(query) {
|
|
15
|
-
return (0, slice_query_options_1.sliceResultKey)(query);
|
|
17
|
+
return (0, slice_query_options_1.sliceResultKey)(query, slicedBy);
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Execute static slice queries, catching duplicates with the same fingerprint
|
|
@@ -23,8 +25,9 @@ function fingerPrintOfQuery(query) {
|
|
|
23
25
|
async function executeStaticSliceQuery({ analyzer }, queries) {
|
|
24
26
|
const start = Date.now();
|
|
25
27
|
const results = {};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
const keys = (0, slice_query_options_1.sliceResultKeys)(queries, slicedBy);
|
|
29
|
+
for (const [at, query] of queries.entries()) {
|
|
30
|
+
const key = keys[at];
|
|
28
31
|
if (results[key]) {
|
|
29
32
|
log_1.log.warn(`Duplicate Key for slicing-query: ${key}, skipping...`);
|
|
30
33
|
}
|
package/queries/query.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CallContextQuery } from './catalog/call-context-query/call-context-query-format';
|
|
1
|
+
import { type CallContextQuery, type CallContextQuerySubKindResult } from './catalog/call-context-query/call-context-query-format';
|
|
2
2
|
import type { BaseQueryFormat, BaseQueryResult, BasicQueryData } from './base-query-format';
|
|
3
3
|
import { type VirtualQueryArgumentsWithType } from './virtual-query/virtual-queries';
|
|
4
4
|
import type { VirtualCompoundConstraint } from './virtual-query/compound-query';
|
|
@@ -36,7 +36,7 @@ import type { DoesCallQuery } from './catalog/does-call-query/does-call-query-fo
|
|
|
36
36
|
import type { InspectExceptionQuery } from './catalog/inspect-exceptions-query/inspect-exception-query-format';
|
|
37
37
|
import type { InputSourcesQuery } from './catalog/input-sources-query/input-sources-query-format';
|
|
38
38
|
import type { ProvenanceQuery } from './catalog/provenance-query/provenance-query-format';
|
|
39
|
-
import type { LintingResultCertainty } from '../linter/linter-format';
|
|
39
|
+
import type { LintingResult, LintingResultCertainty } from '../linter/linter-format';
|
|
40
40
|
import { type DiceQuery } from './catalog/dice-query/dice-query-format';
|
|
41
41
|
import { type GuessDepVersionsQuery } from './catalog/guess-dep-versions-query/guess-dep-versions-query-format';
|
|
42
42
|
import { type AbsintQuery } from './catalog/absint-query/absint-query-format';
|
|
@@ -391,4 +391,58 @@ export declare function QueriesSchema(): Joi.ArraySchema<any[]>;
|
|
|
391
391
|
* Wraps a function that executes a REPL query and, if it fails, checks whether there were any requests to analyze.
|
|
392
392
|
*/
|
|
393
393
|
export declare function genericWrapReplFailIfNoRequest<T>(fn: () => Promise<T>, output: ReplOutput, analyzer: ReadonlyFlowrAnalysisProvider): Promise<T | undefined>;
|
|
394
|
+
/** What a query reports per key, for the queries that report anything per key. */
|
|
395
|
+
type ResultsOf<Type extends SupportedQueryTypes> = Awaited<QueryResult<Type>> extends {
|
|
396
|
+
readonly results: infer R;
|
|
397
|
+
} ? R : never;
|
|
398
|
+
/** The keys {@link ResultsOf} is indexed by, e.g. the slicing criterion a slice was taken at. */
|
|
399
|
+
type KeyOf<Type extends SupportedQueryTypes> = Extract<keyof ResultsOf<Type>, string>;
|
|
400
|
+
/** What one key of {@link ResultsOf} holds, e.g. one slice with its reconstruction. */
|
|
401
|
+
type ValueOf<Type extends SupportedQueryTypes> = ResultsOf<Type>[KeyOf<Type>];
|
|
402
|
+
/** One call a `call-context` query found, with the kind and subkind it was found under. */
|
|
403
|
+
export interface FoundCall extends CallContextQuerySubKindResult {
|
|
404
|
+
readonly kind: string;
|
|
405
|
+
readonly subkind: string;
|
|
406
|
+
}
|
|
407
|
+
/** One finding a `linter` query reported, with the rule that reported it. */
|
|
408
|
+
export interface FoundLint {
|
|
409
|
+
readonly rule: string;
|
|
410
|
+
readonly result: LintingResult;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Running queries and reading what they reported, without `Object.entries` and the casts it forces. Reading
|
|
414
|
+
* changes nothing: the results keep the shape they are serialized in.
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* const out = await executeQueries({ analyzer }, [{ type: 'static-slice', criteria: ['2@x'] }]);
|
|
418
|
+
* Query.get(out, 'static-slice', '2@x'); // the slice taken at `2@x`
|
|
419
|
+
* Query.first(out, 'static-slice'); // the only slice, when one was asked for
|
|
420
|
+
* for(const [criterion, slice] of Query.entries(out, 'static-slice')) { ... }
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
export declare const Query: {
|
|
424
|
+
name: string;
|
|
425
|
+
/**
|
|
426
|
+
* Run a single query and answer with what it reported, so a caller asking one thing is handed that one
|
|
427
|
+
* thing instead of a {@link QueryResults} to index into.
|
|
428
|
+
*/
|
|
429
|
+
one<Type extends SupportedQueryTypes>(this: void, data: BasicQueryData, query: Extract<Query, {
|
|
430
|
+
type: Type;
|
|
431
|
+
}>): Promise<Awaited<QueryResult<Type>>>;
|
|
432
|
+
/** Every key and result of one query, typed as that query reports them. */
|
|
433
|
+
entries<Base extends SupportedQueryTypes, Type extends Base>(this: void, results: QueryResults<Base>, type: Type): [KeyOf<Type>, ValueOf<Type>][];
|
|
434
|
+
/** Every result of one query, for when the keys are not what you are after. */
|
|
435
|
+
values<Base extends SupportedQueryTypes, Type extends Base>(this: void, results: QueryResults<Base>, type: Type): ValueOf<Type>[];
|
|
436
|
+
/** The result of one query under one key, `undefined` when it reported none. */
|
|
437
|
+
get<Base extends SupportedQueryTypes, Type extends Base>(this: void, results: QueryResults<Base>, type: Type, key: KeyOf<Type>): ValueOf<Type> | undefined;
|
|
438
|
+
/** The one result of a query that was asked for one thing, `undefined` when it reported none. */
|
|
439
|
+
first<Base extends SupportedQueryTypes, Type extends Base>(this: void, results: QueryResults<Base>, type: Type): ValueOf<Type> | undefined;
|
|
440
|
+
/**
|
|
441
|
+
* Every call a `call-context` query found, flat, each carrying the kind and subkind it was found under
|
|
442
|
+
* rather than leaving them as the two levels of record the result nests them in.
|
|
443
|
+
*/
|
|
444
|
+
calls(this: void, results: Partial<QueryResults<"call-context">>): FoundCall[];
|
|
445
|
+
/** Every finding a `linter` query reported, flat, each carrying the rule that reported it. */
|
|
446
|
+
lints(this: void, results: Partial<QueryResults<"linter">>): FoundLint[];
|
|
447
|
+
};
|
|
394
448
|
export {};
|