@eagleoutice/flowr 2.15.1 → 2.15.2
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/dataflow/environments/identifier.d.ts +2 -0
- package/dataflow/environments/identifier.js +8 -1
- package/dataflow/environments/query-fn-props.d.ts +9 -1
- package/dataflow/environments/query-fn-props.js +88 -10
- package/linter/rules/problematic-inputs.js +1 -1
- package/linter/rules/undefined-symbol.js +3 -2
- package/package.json +1 -1
- 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/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/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/version.js +2 -2
|
@@ -114,6 +114,8 @@ export declare const Identifier: {
|
|
|
114
114
|
* If the first identifier is internal, it will match any target (internal or not).
|
|
115
115
|
*/
|
|
116
116
|
readonly matches: (this: void, id: Identifier, target: Identifier, s3?: boolean) => boolean;
|
|
117
|
+
/** The text as a regex matches it literally: `[`, `$` and `.` name functions in R, they are not pattern syntax. */
|
|
118
|
+
readonly quote: (this: void, text: string) => string;
|
|
117
119
|
/**
|
|
118
120
|
* Helper to create a regular expression that matches against an array of {@link Identifier} values. If both the passed identifier and the matched identifier are namespaced, their namespaces are expected to match. If either is not namespaced, the namespace is ignored on both.
|
|
119
121
|
*/
|
|
@@ -180,12 +180,19 @@ exports.Identifier = {
|
|
|
180
180
|
/* an omitted flag is the same as an explicit `false`, `pkg::fn` written either way is one identifier */
|
|
181
181
|
return (idInternal ?? false) === (exports.Identifier.accessesInternal(target) ?? false);
|
|
182
182
|
},
|
|
183
|
+
/** The text as a regex matches it literally: `[`, `$` and `.` name functions in R, they are not pattern syntax. */
|
|
184
|
+
quote(text) {
|
|
185
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
186
|
+
},
|
|
183
187
|
/**
|
|
184
188
|
* Helper to create a regular expression that matches against an array of {@link Identifier} values. If both the passed identifier and the matched identifier are namespaced, their namespaces are expected to match. If either is not namespaced, the namespace is ignored on both.
|
|
185
189
|
*/
|
|
186
190
|
regex(...identifiers) {
|
|
187
191
|
// if the passed identifier is not namespaced, we match against *any* namespace. if it is namespaced, we match against the correct namespace or no namespace
|
|
188
|
-
return new RegExp(`^(${identifiers.map(i =>
|
|
192
|
+
return new RegExp(`^(${identifiers.map(i => {
|
|
193
|
+
const namespace = exports.Identifier.getNamespace(i);
|
|
194
|
+
return `(${namespace === undefined ? '.+' : exports.Identifier.quote(namespace)}:::?)?${exports.Identifier.quote(exports.Identifier.getName(i))}`;
|
|
195
|
+
}).join('|')})$`);
|
|
189
196
|
},
|
|
190
197
|
/** Special identifier for the `...` argument */
|
|
191
198
|
dotdotdot() {
|
|
@@ -79,8 +79,12 @@ export interface BuiltInParam {
|
|
|
79
79
|
* definition in the analyzed code shadows the built-in) use {@link queryFnProps} instead.
|
|
80
80
|
*/
|
|
81
81
|
export declare class BuiltInIndex {
|
|
82
|
+
/** every built-in the index knows, one entry per namespace and name */
|
|
82
83
|
readonly entries: readonly BuiltInEntry[];
|
|
84
|
+
/** the entry an unqualified name resolves to, the one R's default search path would find */
|
|
83
85
|
private readonly byName;
|
|
86
|
+
/** namespace to name to entry, so a qualified name is two lookups and no string built to ask */
|
|
87
|
+
private readonly byNamespace;
|
|
84
88
|
private readonly cache;
|
|
85
89
|
private constructor();
|
|
86
90
|
/** The index of flowR's own {@link DefaultBuiltinConfig}, computed on first use and shared from then on. */
|
|
@@ -109,7 +113,11 @@ export declare class BuiltInIndex {
|
|
|
109
113
|
get folding(): readonly Identifier[];
|
|
110
114
|
/** Every parameter whose argument carries at least one bit of `props`, like {@link ArgProp.Resource}. */
|
|
111
115
|
params(props: ArgProps): BuiltInParam[];
|
|
112
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* What the index states about `name`. A qualified name answers for that package alone, so `stats::filter`
|
|
118
|
+
* does not report what `dplyr::filter` states; an unqualified one answers with what R's default search
|
|
119
|
+
* path would find, `base` first and the other {@link AttachedBasePackageSet|attached base packages} next.
|
|
120
|
+
*/
|
|
113
121
|
get(name: Identifier): BuiltInEntry | undefined;
|
|
114
122
|
/** The {@link CallProp} bits of `name`, `undefined` when no built-in of that name states any. */
|
|
115
123
|
propsOf(name: Identifier): CallProps | undefined;
|
|
@@ -14,6 +14,7 @@ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id"
|
|
|
14
14
|
const resolve_helper_1 = require("./resolve-helper");
|
|
15
15
|
const vertex_1 = require("../graph/vertex");
|
|
16
16
|
const df_helper_1 = require("../graph/df-helper");
|
|
17
|
+
const r_base_packages_1 = require("../../util/r-base-packages");
|
|
17
18
|
/**
|
|
18
19
|
* What flowR states about the package export `definition` binds, `undefined` if it binds none or if flowR
|
|
19
20
|
* states nothing about it. `library(pkg)` binds every export itself, and that binding hides the built-in layer.
|
|
@@ -93,13 +94,20 @@ function queryFnProps(name, { environment, builtIns, signatures, version }) {
|
|
|
93
94
|
*/
|
|
94
95
|
function builtInLookup(ctx) {
|
|
95
96
|
const environment = ctx?.env.makeCleanEnv();
|
|
97
|
+
/* keyed by namespace and name, as `stats::filter` and `dplyr::filter` are not the same function */
|
|
96
98
|
const known = new Map();
|
|
97
99
|
return name => {
|
|
100
|
+
const namespace = identifier_1.Identifier.getNamespace(name);
|
|
98
101
|
const key = identifier_1.Identifier.getName(name);
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
let bucket = known.get(namespace);
|
|
103
|
+
if (bucket === undefined) {
|
|
104
|
+
bucket = new Map();
|
|
105
|
+
known.set(namespace, bucket);
|
|
101
106
|
}
|
|
102
|
-
|
|
107
|
+
if (!bucket.has(key)) {
|
|
108
|
+
bucket.set(key, environment === undefined ? BuiltInIndex.default().get(name) : queryFnProps(name, { environment }));
|
|
109
|
+
}
|
|
110
|
+
return bucket.get(key);
|
|
103
111
|
};
|
|
104
112
|
}
|
|
105
113
|
/** What flowR states about the call `id` makes, together with the name the call resolved to. */
|
|
@@ -150,7 +158,7 @@ function entryOfDefinition(definition) {
|
|
|
150
158
|
}
|
|
151
159
|
const info = definition.config;
|
|
152
160
|
const folds = definition.type === 'function' && definition.evalHandler !== undefined;
|
|
153
|
-
return builtInNames(definition).map(name => ({ name, props: info?.props, tags: info?.tags, sig: info?.sig, folds }));
|
|
161
|
+
return builtInNames(definition).map(name => ({ name, props: info?.props, tags: info?.tags, sig: info?.sig, folds, overrides: definition.overrides }));
|
|
154
162
|
}
|
|
155
163
|
function entriesOfMemory(builtIns) {
|
|
156
164
|
const out = [];
|
|
@@ -172,6 +180,32 @@ function entriesOfMemory(builtIns) {
|
|
|
172
180
|
return out;
|
|
173
181
|
}
|
|
174
182
|
let defaultIndex;
|
|
183
|
+
/**
|
|
184
|
+
* The one entry for a name several definitions state something about, the later definition winning wherever
|
|
185
|
+
* it states anything -- a definition that only adds a {@link FnSig} must not drop the props of the one before.
|
|
186
|
+
* A definition marked `overrides` replaces the earlier one outright, as that is what it says it does.
|
|
187
|
+
*/
|
|
188
|
+
function mergedEntry(known, next) {
|
|
189
|
+
return {
|
|
190
|
+
name: next.name,
|
|
191
|
+
props: next.props ?? known.props,
|
|
192
|
+
tags: next.tags ?? known.tags,
|
|
193
|
+
sig: next.sig ?? known.sig,
|
|
194
|
+
folds: next.folds || known.folds
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** The entry alone, without what only the index build needs to know about it. */
|
|
198
|
+
function plainEntry({ name, props, tags, sig, folds }) {
|
|
199
|
+
return { name, props, tags, sig, folds };
|
|
200
|
+
}
|
|
201
|
+
/** How early R's default search path reaches a name, deciding which package an unqualified ask answers with. */
|
|
202
|
+
function searchPathRank(name) {
|
|
203
|
+
const namespace = identifier_1.Identifier.getNamespace(name);
|
|
204
|
+
if (namespace === undefined) {
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
return namespace === "base" /* PkgName.Base */ ? 1 : r_base_packages_1.AttachedBasePackageSet.has(namespace) ? 2 : 3;
|
|
208
|
+
}
|
|
175
209
|
/**
|
|
176
210
|
* The one place to ask what flowR's built-ins are: _every pure function_, _every call that reads a file_,
|
|
177
211
|
* _every parameter that names a resource_, _everything the value solver can fold_. Each answer is derived
|
|
@@ -184,13 +218,44 @@ let defaultIndex;
|
|
|
184
218
|
* definition in the analyzed code shadows the built-in) use {@link queryFnProps} instead.
|
|
185
219
|
*/
|
|
186
220
|
class BuiltInIndex {
|
|
221
|
+
/** every built-in the index knows, one entry per namespace and name */
|
|
187
222
|
entries;
|
|
223
|
+
/** the entry an unqualified name resolves to, the one R's default search path would find */
|
|
188
224
|
byName = new Map();
|
|
225
|
+
/** namespace to name to entry, so a qualified name is two lookups and no string built to ask */
|
|
226
|
+
byNamespace = new Map();
|
|
189
227
|
cache = new Map();
|
|
190
|
-
constructor(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
228
|
+
constructor(definitions) {
|
|
229
|
+
const unqualified = new Map();
|
|
230
|
+
/* where each name was first seen, so the entries keep the order the definitions come in */
|
|
231
|
+
const order = [];
|
|
232
|
+
for (const e of definitions) {
|
|
233
|
+
const name = identifier_1.Identifier.getName(e.name);
|
|
234
|
+
const namespace = identifier_1.Identifier.getNamespace(e.name);
|
|
235
|
+
let bucket = unqualified;
|
|
236
|
+
if (namespace !== undefined) {
|
|
237
|
+
const inNamespace = this.byNamespace.get(namespace);
|
|
238
|
+
if (inNamespace === undefined) {
|
|
239
|
+
bucket = new Map();
|
|
240
|
+
this.byNamespace.set(namespace, bucket);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
bucket = inNamespace;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const known = bucket.get(name);
|
|
247
|
+
bucket.set(name, known === undefined || e.overrides ? plainEntry(e) : mergedEntry(known, e));
|
|
248
|
+
if (known === undefined) {
|
|
249
|
+
order.push([bucket, name]);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
this.entries = order.map(([bucket, name]) => bucket.get(name));
|
|
253
|
+
for (const e of this.entries) {
|
|
254
|
+
const name = identifier_1.Identifier.getName(e.name);
|
|
255
|
+
const known = this.byName.get(name);
|
|
256
|
+
if (known === undefined || searchPathRank(e.name) < searchPathRank(known.name)) {
|
|
257
|
+
this.byName.set(name, e);
|
|
258
|
+
}
|
|
194
259
|
}
|
|
195
260
|
}
|
|
196
261
|
/** The index of flowR's own {@link DefaultBuiltinConfig}, computed on first use and shared from then on. */
|
|
@@ -251,9 +316,22 @@ class BuiltInIndex {
|
|
|
251
316
|
}
|
|
252
317
|
return found;
|
|
253
318
|
}
|
|
254
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* What the index states about `name`. A qualified name answers for that package alone, so `stats::filter`
|
|
321
|
+
* does not report what `dplyr::filter` states; an unqualified one answers with what R's default search
|
|
322
|
+
* path would find, `base` first and the other {@link AttachedBasePackageSet|attached base packages} next.
|
|
323
|
+
*/
|
|
255
324
|
get(name) {
|
|
256
|
-
|
|
325
|
+
const namespace = identifier_1.Identifier.getNamespace(name);
|
|
326
|
+
if (namespace === undefined) {
|
|
327
|
+
return this.byName.get(identifier_1.Identifier.getName(name));
|
|
328
|
+
}
|
|
329
|
+
const found = this.byNamespace.get(namespace)?.get(identifier_1.Identifier.getName(name));
|
|
330
|
+
if (found === undefined) {
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
/* the maps settled name and namespace, what is left is `::` asking for a name only `:::` states */
|
|
334
|
+
return identifier_1.Identifier.accessesInternal(found.name) !== true || identifier_1.Identifier.accessesInternal(name) === true ? found : undefined;
|
|
257
335
|
}
|
|
258
336
|
/** The {@link CallProp} bits of `name`, `undefined` when no built-in of that name states any. */
|
|
259
337
|
propsOf(name) {
|
|
@@ -13,7 +13,7 @@ const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
|
|
|
13
13
|
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
14
14
|
const defaultConsider = [
|
|
15
15
|
'^eval$',
|
|
16
|
-
...query_fn_props_1.BuiltInIndex.default().with(built_in_props_1.SemanticCallTag.Process).map(n => `^${identifier_1.Identifier.getName(n)}$`)
|
|
16
|
+
...query_fn_props_1.BuiltInIndex.default().with(built_in_props_1.SemanticCallTag.Process).map(n => `^${identifier_1.Identifier.quote(identifier_1.Identifier.getName(n))}$`)
|
|
17
17
|
];
|
|
18
18
|
const defaultPipeCommandFunctions = [
|
|
19
19
|
{ pattern: '^pdf$', argIdx: 0, argName: 'file' },
|
|
@@ -19,7 +19,7 @@ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
|
19
19
|
const LibraryLoadFunctions = new Set(['library', 'require', 'requireNamespace', 'loadNamespace', 'attachNamespace', 'load_all', 'use', 'p_load']);
|
|
20
20
|
// standard packages attached by default; exports are in scope without library()
|
|
21
21
|
/** test frameworks whose namespace a test file runs under implicitly (e.g. `tests/testthat/test-*.R` sees testthat's exports without a `library()`) */
|
|
22
|
-
const ImplicitTestFrameworks =
|
|
22
|
+
const ImplicitTestFrameworks = ['testthat', 'tinytest', 'RUnit'];
|
|
23
23
|
/** whether name is an export of a default-attached base package (needs no library()) */
|
|
24
24
|
function isAttachedBaseName(name) {
|
|
25
25
|
const owner = (0, r_base_packages_1.baseRExportOwner)(name);
|
|
@@ -51,7 +51,8 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
51
51
|
const isInstalledFile = (file) => file !== undefined && (installedFiles.has(file) || (0, undefined_symbol_util_1.isInstalledResourceFile)(file));
|
|
52
52
|
// test files run under their framework's attached namespace, so a bare name a test framework exports is defined there
|
|
53
53
|
const testFiles = new Set(ctx.files.getFilesByRole(flowr_file_1.FileRole.Test).map(f => f.path()));
|
|
54
|
-
const
|
|
54
|
+
const testExports = new Set(testFiles.size === 0 ? [] : deps.signatureSources().flatMap(src => ImplicitTestFrameworks.flatMap(pkg => src.lookup(pkg)?.exported ?? [])));
|
|
55
|
+
const isImplicitTestExport = (name, file) => file !== undefined && testFiles.has(file) && testExports.has(name);
|
|
55
56
|
// a library() we could not resolve could export any of these symbols; we still report but flag the
|
|
56
57
|
// findings as low-confidence (`mayBeProvidedByUnresolvedLibrary`) so the severity can be lowered
|
|
57
58
|
const unknownIds = new Set();
|
package/package.json
CHANGED
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);
|
|
@@ -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) ?? []) {
|
|
@@ -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 {};
|
package/queries/query.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CompoundQuerySchema = exports.SupportedQueries = void 0;
|
|
6
|
+
exports.Query = exports.CompoundQuerySchema = exports.SupportedQueries = void 0;
|
|
7
7
|
exports.queryWikiPage = queryWikiPage;
|
|
8
8
|
exports.executeQueriesOfSameType = executeQueriesOfSameType;
|
|
9
9
|
exports.executeQueries = executeQueries;
|
|
@@ -228,4 +228,69 @@ async function genericWrapReplFailIfNoRequest(fn, output, analyzer) {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Running queries and reading what they reported, without `Object.entries` and the casts it forces. Reading
|
|
233
|
+
* changes nothing: the results keep the shape they are serialized in.
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const out = await executeQueries({ analyzer }, [{ type: 'static-slice', criteria: ['2@x'] }]);
|
|
237
|
+
* Query.get(out, 'static-slice', '2@x'); // the slice taken at `2@x`
|
|
238
|
+
* Query.first(out, 'static-slice'); // the only slice, when one was asked for
|
|
239
|
+
* for(const [criterion, slice] of Query.entries(out, 'static-slice')) { ... }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
exports.Query = {
|
|
243
|
+
name: 'Query',
|
|
244
|
+
/**
|
|
245
|
+
* Run a single query and answer with what it reported, so a caller asking one thing is handed that one
|
|
246
|
+
* thing instead of a {@link QueryResults} to index into.
|
|
247
|
+
*/
|
|
248
|
+
async one(data, query) {
|
|
249
|
+
const results = await executeQueries(data, [query]);
|
|
250
|
+
return results[query.type];
|
|
251
|
+
},
|
|
252
|
+
/** Every key and result of one query, typed as that query reports them. */
|
|
253
|
+
entries(results, type) {
|
|
254
|
+
const found = results[type];
|
|
255
|
+
return Object.entries(found?.results ?? {});
|
|
256
|
+
},
|
|
257
|
+
/** Every result of one query, for when the keys are not what you are after. */
|
|
258
|
+
values(results, type) {
|
|
259
|
+
return exports.Query.entries(results, type).map(([, value]) => value);
|
|
260
|
+
},
|
|
261
|
+
/** The result of one query under one key, `undefined` when it reported none. */
|
|
262
|
+
get(results, type, key) {
|
|
263
|
+
const found = results[type];
|
|
264
|
+
return found?.results?.[key];
|
|
265
|
+
},
|
|
266
|
+
/** The one result of a query that was asked for one thing, `undefined` when it reported none. */
|
|
267
|
+
first(results, type) {
|
|
268
|
+
return exports.Query.values(results, type)[0];
|
|
269
|
+
},
|
|
270
|
+
/**
|
|
271
|
+
* Every call a `call-context` query found, flat, each carrying the kind and subkind it was found under
|
|
272
|
+
* rather than leaving them as the two levels of record the result nests them in.
|
|
273
|
+
*/
|
|
274
|
+
calls(results) {
|
|
275
|
+
const found = [];
|
|
276
|
+
for (const [kind, { subkinds }] of Object.entries(results['call-context']?.kinds ?? {})) {
|
|
277
|
+
for (const [subkind, hits] of Object.entries(subkinds)) {
|
|
278
|
+
for (const hit of hits) {
|
|
279
|
+
found.push({ ...hit, kind, subkind });
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return found;
|
|
284
|
+
},
|
|
285
|
+
/** Every finding a `linter` query reported, flat, each carrying the rule that reported it. */
|
|
286
|
+
lints(results) {
|
|
287
|
+
const found = [];
|
|
288
|
+
for (const [rule, reported] of Object.entries(results['linter']?.results ?? {})) {
|
|
289
|
+
for (const result of reported.results ?? []) {
|
|
290
|
+
found.push({ rule, result });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return found;
|
|
294
|
+
}
|
|
295
|
+
};
|
|
231
296
|
//# sourceMappingURL=query.js.map
|
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.2';
|
|
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-25T22:44:52Z';
|
|
48
48
|
/**
|
|
49
49
|
* Retrieves the current flowR version as a new {@link SemVer} object.
|
|
50
50
|
*/
|