@eagleoutice/flowr 2.17.7 → 2.17.8
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/abstract-interpretation/branch-paths.d.ts +10 -0
- package/abstract-interpretation/branch-paths.js +104 -10
- package/config.js +3 -1
- package/control-flow/control-flow-graph.js +18 -2
- package/data/r-base-guards.generated.js +2 -2
- package/dataflow/environments/ambient-effect.js +4 -1
- package/dataflow/environments/built-in-props.d.ts +8 -2
- package/dataflow/environments/built-in-props.js +16 -5
- package/dataflow/environments/default-builtin-config/base-functions.js +1 -1
- package/dataflow/environments/default-builtin-config/guards.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/guards.js +28 -0
- package/dataflow/environments/default-builtin-config/index.d.ts +8 -4
- package/dataflow/environments/default-builtin-config/index.js +9 -5
- package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/parallel-execution.js +25 -0
- package/dataflow/environments/guard-facts.d.ts +28 -1
- package/dataflow/environments/pkg-name.d.ts +2 -0
- package/dataflow/environments/query-fn-props.d.ts +19 -15
- package/dataflow/environments/query-fn-props.js +46 -36
- package/dataflow/environments/removal-marker.d.ts +1 -1
- package/dataflow/environments/removal-marker.js +18 -3
- package/dataflow/environments/reserved-names.d.ts +6 -0
- package/dataflow/environments/reserved-names.js +14 -0
- package/dataflow/environments/resolve-by-name.js +5 -10
- package/dataflow/eval/resolve/alias-tracking.js +23 -6
- package/dataflow/extractor.js +103 -28
- package/dataflow/fn/argument-roles.d.ts +3 -0
- package/dataflow/fn/argument-roles.js +5 -5
- package/dataflow/fn/exceptions-of-function.d.ts +7 -0
- package/dataflow/fn/exceptions-of-function.js +15 -2
- package/dataflow/fn/function-props.d.ts +1 -1
- package/dataflow/fn/function-props.js +40 -18
- package/dataflow/fn/function-semantics.d.ts +3 -1
- package/dataflow/fn/function-semantics.js +2 -0
- package/dataflow/fn/guards/built-in-guards.js +2 -1
- package/dataflow/fn/guards/condition-grouping.d.ts +11 -0
- package/dataflow/fn/guards/condition-grouping.js +50 -3
- package/dataflow/fn/guards/function-guards.d.ts +10 -0
- package/dataflow/fn/guards/function-guards.js +130 -14
- package/dataflow/fn/guards/guard-claims.d.ts +2 -0
- package/dataflow/fn/guards/guard-claims.js +42 -2
- package/dataflow/fn/guards/guard-knowledge.d.ts +7 -1
- package/dataflow/fn/guards/guard-knowledge.js +50 -4
- package/dataflow/fn/guards/guard-term.js +10 -1
- package/dataflow/fn/higher-order-function.d.ts +15 -1
- package/dataflow/fn/higher-order-function.js +54 -10
- package/dataflow/graph/call-graph.d.ts +5 -0
- package/dataflow/graph/call-graph.js +51 -15
- package/dataflow/graph/df-helper.d.ts +2 -0
- package/dataflow/graph/df-helper.js +4 -2
- package/dataflow/graph/graph.d.ts +21 -0
- package/dataflow/graph/graph.js +63 -2
- package/dataflow/internal/linker.d.ts +20 -0
- package/dataflow/internal/linker.js +190 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +20 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +5 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +7 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +12 -5
- package/dataflow/internal/process/functions/call/deferred.d.ts +7 -2
- package/dataflow/internal/process/functions/call/deferred.js +63 -28
- package/dataflow/internal/process/functions/call/quoted.js +33 -7
- package/documentation/data/dfg/doc-ambient.js +3 -1
- package/documentation/wiki-normalized-ast.js +1 -1
- package/documentation/wiki-query.js +9 -3
- package/package.json +5 -3
- package/project/context/flowr-analyzer-context.d.ts +7 -4
- package/project/context/flowr-analyzer-context.js +8 -3
- package/project/context/flowr-analyzer-files-context.js +1 -0
- package/project/context/flowr-analyzer-functions-context.d.ts +2 -1
- package/project/context/flowr-analyzer-functions-context.js +9 -8
- package/project/flowr-analyzer.d.ts +7 -4
- package/project/flowr-analyzer.js +37 -8
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +22 -0
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +34 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -1
- package/project/sigdb/build.js +41 -2
- package/project/sigdb/decode.d.ts +3 -1
- package/project/sigdb/decode.js +45 -1
- package/project/sigdb/decompress.d.ts +5 -0
- package/project/sigdb/decompress.js +17 -1
- package/project/sigdb/manifest.d.ts +2 -1
- package/project/sigdb/manifest.js +12 -5
- package/project/sigdb/native-routines.d.ts +82 -0
- package/project/sigdb/native-routines.js +178 -0
- package/project/sigdb/reader.d.ts +21 -3
- package/project/sigdb/reader.js +35 -3
- package/project/sigdb/schema.d.ts +107 -3
- package/project/sigdb/schema.js +8 -2
- package/project/sigdb/sigdb-download.js +1 -1
- package/project/sigdb/sigdb-version.d.ts +7 -1
- package/project/sigdb/sigdb-version.js +12 -9
- package/project/sigdb/spec-query.d.ts +9 -4
- package/project/sigdb/spec-query.js +71 -45
- package/queries/catalog/call-context-query/call-context-query-executor.js +76 -29
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +1 -12
- package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.d.ts +3 -0
- package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.js +3 -2
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +3 -0
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +3 -2
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +3 -1
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +4 -2
- package/queries/catalog/signature-query/signature-query-executor.js +6 -2
- package/queries/catalog/signature-query/signature-query-format.d.ts +4 -0
- package/util/collections/bounded-map.d.ts +9 -0
- package/util/collections/bounded-map.js +22 -0
- package/util/collections/defaultmap.d.ts +5 -0
- package/util/collections/defaultmap.js +10 -0
- package/util/fixpoint.d.ts +6 -1
- package/util/fixpoint.js +45 -3
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/global-caches.d.ts +26 -0
- package/util/global-caches.js +43 -0
- package/util/monoid.js +2 -2
- package/util/quads.js +11 -3
- package/util/r-package-urls.d.ts +19 -0
- package/util/r-package-urls.js +41 -0
|
@@ -32,6 +32,8 @@ class FlowrAnalyzer {
|
|
|
32
32
|
parserInfo;
|
|
33
33
|
/** the graph whose calls are already being qualified in the background, see {@link qualifyInBackground} */
|
|
34
34
|
qualifying;
|
|
35
|
+
/** stops the background qualification of {@link qualifying}, so a dropped graph is neither worked on nor kept */
|
|
36
|
+
stopQualifying;
|
|
35
37
|
/**
|
|
36
38
|
* Create a new analyzer instance.
|
|
37
39
|
* **Prefer the use of the {@link FlowrAnalyzerBuilder} instead of calling this constructor directly.**
|
|
@@ -57,23 +59,32 @@ class FlowrAnalyzer {
|
|
|
57
59
|
inspectContext() {
|
|
58
60
|
return this.ctx.inspect();
|
|
59
61
|
}
|
|
60
|
-
functionInfo(name,
|
|
61
|
-
return this.ctx.functionInfo(name,
|
|
62
|
+
functionInfo(name, options) {
|
|
63
|
+
return this.ctx.functionInfo(name, options);
|
|
62
64
|
}
|
|
63
65
|
reset() {
|
|
66
|
+
this.stopBackgroundWork();
|
|
64
67
|
this.ctx.reset();
|
|
65
68
|
this.cache.reset();
|
|
66
69
|
}
|
|
70
|
+
stopBackgroundWork() {
|
|
71
|
+
this.stopQualifying?.();
|
|
72
|
+
this.stopQualifying = undefined;
|
|
73
|
+
this.qualifying = undefined;
|
|
74
|
+
}
|
|
67
75
|
receive(event) {
|
|
76
|
+
this.stopBackgroundWork();
|
|
68
77
|
this.ctx.receive(event);
|
|
69
78
|
this.cache.receive(event);
|
|
70
79
|
}
|
|
71
80
|
updateConfig(update) {
|
|
81
|
+
this.stopBackgroundWork();
|
|
72
82
|
this.ctx.updateConfig(update);
|
|
73
83
|
// the parse/dataflow results were computed under the previous config, so they must be recomputed
|
|
74
84
|
this.cache.reset();
|
|
75
85
|
}
|
|
76
86
|
resetConfig() {
|
|
87
|
+
this.stopBackgroundWork();
|
|
77
88
|
this.ctx.resetConfig();
|
|
78
89
|
this.cache.reset();
|
|
79
90
|
}
|
|
@@ -114,8 +125,9 @@ class FlowrAnalyzer {
|
|
|
114
125
|
async dataflow(force) {
|
|
115
126
|
const dataflow = await this.cache.dataflow(force);
|
|
116
127
|
if (this.qualifying !== dataflow.graph) {
|
|
128
|
+
this.stopBackgroundWork();
|
|
117
129
|
this.qualifying = dataflow.graph;
|
|
118
|
-
qualifyInBackground(dataflow.graph);
|
|
130
|
+
this.stopQualifying = qualifyInBackground(dataflow.graph, () => this.cache.peekDataflow()?.graph === dataflow.graph);
|
|
119
131
|
}
|
|
120
132
|
return dataflow;
|
|
121
133
|
}
|
|
@@ -154,27 +166,44 @@ class FlowrAnalyzer {
|
|
|
154
166
|
* Closing is only required for an RShell/remote engine, but this also frees the cached parse trees.
|
|
155
167
|
*/
|
|
156
168
|
close() {
|
|
169
|
+
this.stopBackgroundWork();
|
|
157
170
|
this.cache.reset();
|
|
158
171
|
return this.parser?.close();
|
|
159
172
|
}
|
|
160
173
|
}
|
|
161
174
|
exports.FlowrAnalyzer = FlowrAnalyzer;
|
|
162
|
-
/**
|
|
163
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Qualifies calls (see {@link Dataflow.qualify}) in idle time on unreferenced timers, so later queries find it done.
|
|
177
|
+
* Stops once the graph is no longer `current`, and returns how to stop it right away: a pending timer keeps the graph alive.
|
|
178
|
+
*/
|
|
179
|
+
function qualifyInBackground(graph, current) {
|
|
164
180
|
const calls = Array.from(graph.verticesOfType(vertex_1.VertexType.FunctionCall), ([id]) => id);
|
|
165
181
|
let next = 0;
|
|
182
|
+
let timer;
|
|
166
183
|
function step() {
|
|
184
|
+
timer = undefined;
|
|
185
|
+
if (!current()) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
167
188
|
for (const end = Math.min(next + 256, calls.length); next < end; next++) {
|
|
168
189
|
df_helper_1.Dataflow.qualify(calls[next], graph, false);
|
|
169
190
|
}
|
|
170
191
|
if (next < calls.length) {
|
|
171
|
-
later(step);
|
|
192
|
+
timer = later(step);
|
|
172
193
|
}
|
|
173
194
|
}
|
|
174
|
-
later(step);
|
|
195
|
+
timer = later(step);
|
|
196
|
+
return () => {
|
|
197
|
+
if (timer !== undefined) {
|
|
198
|
+
clearTimeout(timer);
|
|
199
|
+
timer = undefined;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
175
202
|
}
|
|
176
203
|
/** an unreferenced timer where there are such (node), a plain one elsewhere (the browser returns a number) */
|
|
177
204
|
function later(step) {
|
|
178
|
-
setTimeout(step, 0)
|
|
205
|
+
const timer = setTimeout(step, 0);
|
|
206
|
+
timer.unref?.();
|
|
207
|
+
return timer;
|
|
179
208
|
}
|
|
180
209
|
//# sourceMappingURL=flowr-analyzer.js.map
|
|
@@ -20,10 +20,32 @@ export interface NamespaceInfo {
|
|
|
20
20
|
exportedPatterns: string[];
|
|
21
21
|
importedPackages: Map<BrandedNamespace, BrandedIdentifier[] | 'all'>;
|
|
22
22
|
loadsWithSideEffects: boolean;
|
|
23
|
+
/** the `useDynLib()` directives, with the R names they bind to native routines (absent when there are none) */
|
|
24
|
+
dynLibs?: DynLibDirective[];
|
|
23
25
|
callable: BrandedIdentifier[];
|
|
24
26
|
/** Present only in complex parsed NAMESPACE files. Maps conditions to the parts they gate. */
|
|
25
27
|
conditional?: Map<RNode<ParentInformation>, NamespaceInfo>;
|
|
26
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* One `useDynLib(lib, ...)` directive, as R's `parseNamespaceFile` reads it: `useDynLib(pkg, foo, bar = baz)` binds
|
|
31
|
+
* the R names `foo` and `bar` to the native routines `foo` and `baz`; with `.registration = TRUE`, every registered
|
|
32
|
+
* routine is bound, prefixed by `.fixes` (`useDynLib(pkg, .registration = TRUE, .fixes = "C_")` binds `C_foo`).
|
|
33
|
+
*/
|
|
34
|
+
export interface DynLibDirective {
|
|
35
|
+
/** the shared library, usually the package's own name */
|
|
36
|
+
readonly library: string;
|
|
37
|
+
/** whether `.registration` is `TRUE` */
|
|
38
|
+
readonly registration: boolean;
|
|
39
|
+
/** the prefix of `.fixes` (its first element), `''` when not given */
|
|
40
|
+
readonly prefix: string;
|
|
41
|
+
/** the suffix of `.fixes` (its second element), `''` when not given */
|
|
42
|
+
readonly suffix: string;
|
|
43
|
+
/** the routines named explicitly: `{ rName: 'bar', routine: 'baz' }` for `bar = baz`, prefix and suffix applied to `rName` */
|
|
44
|
+
readonly symbols: readonly {
|
|
45
|
+
readonly rName: string;
|
|
46
|
+
readonly routine: string;
|
|
47
|
+
}[];
|
|
48
|
+
}
|
|
27
49
|
export interface NamespaceFormat {
|
|
28
50
|
current: NamespaceInfo;
|
|
29
51
|
[packageName: BrandedNamespace]: NamespaceInfo;
|
|
@@ -21,6 +21,32 @@ const r_regex_1 = require("../../../../util/r-regex");
|
|
|
21
21
|
const r_argument_1 = require("../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
22
22
|
const arrays_1 = require("../../../../util/collections/arrays");
|
|
23
23
|
const args_1 = require("../../../../util/text/args");
|
|
24
|
+
/** the strings of a `.fixes` value as written: `"C_"` or `c("C_", "_x")` */
|
|
25
|
+
function fixesOf(value) {
|
|
26
|
+
const parts = [...value.matchAll(/(["'])((?:\\.|(?!\1).)*)\1/g)].map(m => m[2]);
|
|
27
|
+
return [parts[0] ?? '', parts[1] ?? ''];
|
|
28
|
+
}
|
|
29
|
+
/** read a `useDynLib` directive's arguments the way R's `parseNamespaceFile` does */
|
|
30
|
+
function dynLibDirective(args) {
|
|
31
|
+
const [lib, ...rest] = args.filter(a => a.name === undefined || !a.name.startsWith('.'));
|
|
32
|
+
if (lib === undefined || lib.name !== undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const option = (name) => args.find(a => a.name === name)?.value;
|
|
36
|
+
const registration = /^(TRUE|T)$/.test(option('.registration')?.trim() ?? '');
|
|
37
|
+
const fixes = option('.fixes');
|
|
38
|
+
const [prefix, suffix] = fixes === undefined ? ['', ''] : fixesOf(fixes);
|
|
39
|
+
return {
|
|
40
|
+
library: r_string_1.RString.unquote(lib.value),
|
|
41
|
+
registration,
|
|
42
|
+
prefix,
|
|
43
|
+
suffix,
|
|
44
|
+
symbols: rest.map(a => {
|
|
45
|
+
const routine = r_string_1.RString.unquote(a.value);
|
|
46
|
+
return { rName: prefix + (a.name === undefined ? routine : r_string_1.RString.unquote(a.name)) + suffix, routine };
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
}
|
|
24
50
|
/**
|
|
25
51
|
* Decorates a text file to expose its content as a {@link NamespaceFormat}.
|
|
26
52
|
* Simple parsing is quicker but does not support `if`/other R constructs.
|
|
@@ -298,6 +324,12 @@ const DirectiveOptions = new Map([
|
|
|
298
324
|
]);
|
|
299
325
|
/** Applies the directive `name` (if it is one) with its `args` to `g`. */
|
|
300
326
|
function applyDirective(g, name, args) {
|
|
327
|
+
if (name === 'useDynLib') {
|
|
328
|
+
const dyn = dynLibDirective(args);
|
|
329
|
+
if (dyn !== undefined) {
|
|
330
|
+
(g.current.dynLibs ??= []).push(dyn);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
301
333
|
const options = DirectiveOptions.get(name);
|
|
302
334
|
NamespaceDirectives.get(name)?.(g, args.filter(a => a.name === undefined || !options?.has(a.name)).map(a => a.value));
|
|
303
335
|
return g;
|
|
@@ -379,7 +411,9 @@ function mergeNamespaceInfo(target, source) {
|
|
|
379
411
|
}
|
|
380
412
|
const s3MethodFunctions = target.s3MethodFunctions || source.s3MethodFunctions
|
|
381
413
|
? new Map([...target.s3MethodFunctions ?? [], ...source.s3MethodFunctions ?? []]) : undefined;
|
|
414
|
+
const dynLibs = target.dynLibs || source.dynLibs ? [...target.dynLibs ?? [], ...source.dynLibs ?? []] : undefined;
|
|
382
415
|
return {
|
|
416
|
+
...(dynLibs ? { dynLibs } : {}),
|
|
383
417
|
...(s3MethodFunctions ? { s3MethodFunctions } : {}),
|
|
384
418
|
...(mergedConditional.size > 0 ? { conditional: mergedConditional } : {}),
|
|
385
419
|
callable: [...target.callable, ...source.callable],
|
package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js
CHANGED
|
@@ -55,6 +55,7 @@ const config_1 = require("../../../config");
|
|
|
55
55
|
const r_version_1 = require("../../../util/r-version");
|
|
56
56
|
const r_base_packages_1 = require("../../../util/r-base-packages");
|
|
57
57
|
const defaultmap_1 = require("../../../util/collections/defaultmap");
|
|
58
|
+
const bounded_map_1 = require("../../../util/collections/bounded-map");
|
|
58
59
|
const arrays_1 = require("../../../util/collections/arrays");
|
|
59
60
|
const r_reexports_generated_1 = require("../../../data/r-reexports.generated");
|
|
60
61
|
const secure_mode_1 = require("../../../util/secure-mode");
|
|
@@ -104,11 +105,13 @@ function reconstructS3Generics(exported) {
|
|
|
104
105
|
* source; this stays proportional to what a run actually asks about rather than scanning all ~1.1M export names up front.
|
|
105
106
|
*/
|
|
106
107
|
const exportOwnersBySource = new WeakMap();
|
|
108
|
+
/** bounds the names {@link exportOwnersBySource} keeps per source, which lives as long as the process */
|
|
109
|
+
const MaxExportOwnersPerSource = 65_536;
|
|
107
110
|
/** The packages of `src` exporting `name`, most downloaded first, scanning only the first time a name is asked. */
|
|
108
111
|
function exportOwners(src, name) {
|
|
109
112
|
let byName = exportOwnersBySource.get(src);
|
|
110
113
|
if (byName === undefined) {
|
|
111
|
-
byName = new defaultmap_1.DefaultMap(n => src.packagesExporting(n));
|
|
114
|
+
byName = new defaultmap_1.DefaultMap(n => src.packagesExporting(n), new bounded_map_1.BoundedMap(MaxExportOwnersPerSource));
|
|
112
115
|
exportOwnersBySource.set(src, byName);
|
|
113
116
|
}
|
|
114
117
|
return byName.get(name);
|
package/project/sigdb/build.js
CHANGED
|
@@ -40,7 +40,8 @@ function resolveFeatures(f) {
|
|
|
40
40
|
locations: f?.locations ?? true,
|
|
41
41
|
dependencies: f?.dependencies ?? true,
|
|
42
42
|
classes: f?.classes ?? true,
|
|
43
|
-
contracts: f?.contracts ?? true
|
|
43
|
+
contracts: f?.contracts ?? true,
|
|
44
|
+
natives: f?.natives ?? true
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
/** an ascending list with its duplicates dropped, so a class named twice in one version is stored once */
|
|
@@ -100,6 +101,7 @@ function buildBlob(p, strings, tier, feats) {
|
|
|
100
101
|
const classes = new Pool();
|
|
101
102
|
const contracts = new Pool();
|
|
102
103
|
const contractOf = {};
|
|
104
|
+
const natives = new Pool();
|
|
103
105
|
function sig(params) {
|
|
104
106
|
if (!feats.signatures || params.length === 0) {
|
|
105
107
|
return -1;
|
|
@@ -162,7 +164,25 @@ function buildBlob(p, strings, tier, feats) {
|
|
|
162
164
|
const rec = c.package !== undefined ? [...head, strings.str(String(c.package))] : head;
|
|
163
165
|
return classes.intern(JSON.stringify(rec), rec);
|
|
164
166
|
}
|
|
167
|
+
/** one native routine record, pooled like a class so versions that change nothing about a routine share it */
|
|
168
|
+
function native(n) {
|
|
169
|
+
const lang = Math.max(0, schema_1.NativeLangNames.indexOf(n.lang));
|
|
170
|
+
const iface = Math.max(0, schema_1.NativeIfaceNames.indexOf(n.iface));
|
|
171
|
+
const flags = lang | (iface << 3) | (n.closed ? 64 /* NativeFlag.Closed */ : 0) | (n.pure ? 128 /* NativeFlag.Pure */ : 0) | (n.undefined ? 256 /* NativeFlag.Undefined */ : 0);
|
|
172
|
+
const params = (n.params ?? []).map(({ name, props = 0, type }) => type === undefined ? [strings.str(name), props] : [strings.str(name), props, strings.str(type)]);
|
|
173
|
+
const sorted = (xs) => uniqueSortedNumbers(Array.from(xs ?? [], x => strings.str(x)).sort((a, b) => a - b));
|
|
174
|
+
const head = [strings.str(n.name), flags, n.symbol !== undefined && n.symbol !== n.name ? strings.str(n.symbol) : -1,
|
|
175
|
+
feats.locations && n.file ? strings.str(n.file) : -1, feats.locations ? n.line ?? -1 : -1, n.arity ?? -1,
|
|
176
|
+
sorted(n.rNames), params, sorted(n.facts)];
|
|
177
|
+
const contract = feats.contracts && n.guards !== undefined ? contracts.intern(JSON.stringify(n.guards), n.guards) : -1;
|
|
178
|
+
const [endLine, column] = feats.locations ? [n.endLine ?? -1, n.column ?? -1] : [-1, -1];
|
|
179
|
+
/* the trailing fields only as far as one is known, so a record without them stays as short as before */
|
|
180
|
+
const tail = column >= 0 ? [contract, endLine, column] : endLine >= 0 ? [contract, endLine] : contract >= 0 ? [contract] : [];
|
|
181
|
+
const rec = [...head, ...tail];
|
|
182
|
+
return natives.intern(JSON.stringify(rec), rec);
|
|
183
|
+
}
|
|
165
184
|
const versions = {};
|
|
185
|
+
const nativesByVersion = {};
|
|
166
186
|
const classesByVersion = {};
|
|
167
187
|
const depsByVersion = {};
|
|
168
188
|
const dates = {};
|
|
@@ -185,6 +205,11 @@ function buildBlob(p, strings, tier, feats) {
|
|
|
185
205
|
.map(cls).sort((a, b) => a - b);
|
|
186
206
|
classesByVersion[version] = deltaEncode(uniqueSortedNumbers(classIdxs));
|
|
187
207
|
}
|
|
208
|
+
if (feats.natives && info.natives && info.natives.length > 0) {
|
|
209
|
+
nativesByVersion[version] = deltaEncode(uniqueSortedNumbers(info.natives
|
|
210
|
+
.toSorted((a, b) => a.name.localeCompare(b.name) || (a.iface ?? '').localeCompare(b.iface ?? ''))
|
|
211
|
+
.map(native).sort((a, b) => a - b)));
|
|
212
|
+
}
|
|
188
213
|
if (info.date !== undefined && Number.isFinite(info.date)) {
|
|
189
214
|
dates[version] = Math.round(info.date / 86_400_000); // days since the Unix epoch (compact; day precision)
|
|
190
215
|
}
|
|
@@ -197,7 +222,7 @@ function buildBlob(p, strings, tier, feats) {
|
|
|
197
222
|
sources[version] = strings.str(info.source);
|
|
198
223
|
}
|
|
199
224
|
}
|
|
200
|
-
const blob = { sigs: sigs.items, cgs: cgs.items, fns: fns.items, versions, deps: deps.items, depsByVersion, dates, noncran: noncran.length ? noncran : undefined, sources: Object.keys(sources).length ? sources : undefined, classes: classes.items.length ? classes.items : undefined, classesByVersion: Object.keys(classesByVersion).length ? classesByVersion : undefined, contracts: contracts.items.length ? contracts.items : undefined, contractOf: contracts.items.length ? contractOf : undefined };
|
|
225
|
+
const blob = { sigs: sigs.items, cgs: cgs.items, fns: fns.items, versions, deps: deps.items, depsByVersion, dates, noncran: noncran.length ? noncran : undefined, sources: Object.keys(sources).length ? sources : undefined, classes: classes.items.length ? classes.items : undefined, classesByVersion: Object.keys(classesByVersion).length ? classesByVersion : undefined, contracts: contracts.items.length ? contracts.items : undefined, contractOf: contracts.items.length ? contractOf : undefined, natives: natives.items.length ? natives.items : undefined, nativesByVersion: natives.items.length ? nativesByVersion : undefined };
|
|
201
226
|
return { blob, versionCount, functionCount };
|
|
202
227
|
}
|
|
203
228
|
/**
|
|
@@ -419,6 +444,20 @@ function mapStringRefs(blob, map) {
|
|
|
419
444
|
c[5] = at(c[5]);
|
|
420
445
|
}
|
|
421
446
|
}
|
|
447
|
+
/* a native routine names itself, its symbol, file, R names, parameters, their types, and its facts */
|
|
448
|
+
for (const r of blob.natives ?? []) {
|
|
449
|
+
r[0] = at(r[0]);
|
|
450
|
+
r[2] = at(r[2]);
|
|
451
|
+
r[3] = at(r[3]);
|
|
452
|
+
r[6] = r[6].map(at).sort((x, y) => x - y);
|
|
453
|
+
for (const par of r[7]) {
|
|
454
|
+
par[0] = at(par[0]);
|
|
455
|
+
if (par.length === 3) {
|
|
456
|
+
par[2] = at(par[2]);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
r[8] = r[8].map(at).sort((x, y) => x - y);
|
|
460
|
+
}
|
|
422
461
|
}
|
|
423
462
|
/** renumber the dictionary so the most-referenced strings get the smallest indices (a pure bijection) */
|
|
424
463
|
function optimizeStringOrder(strings, blobs) {
|
|
@@ -5,7 +5,7 @@ import type { BrandedIdentifier, BrandedNamespace } from '../../dataflow/environ
|
|
|
5
5
|
* Split out of `../sigdb` so the reader/writer there does not carry the per-record decoding.
|
|
6
6
|
*/
|
|
7
7
|
import type { SigDict } from './dict';
|
|
8
|
-
import { type DepType, type LibraryExports, type PkgBlob, type PkgBlobTuple, type SigClassInfo, type SigDbPkgMeta } from './schema';
|
|
8
|
+
import { type SigNativeRoutineInfo, type DepType, type LibraryExports, type PkgBlob, type PkgBlobTuple, type SigClassInfo, type SigDbPkgMeta } from './schema';
|
|
9
9
|
import type { ArgProps } from '../../dataflow/environments/built-in-props';
|
|
10
10
|
import type { StatedGuards } from '../../dataflow/fn/guards/built-in-guards';
|
|
11
11
|
/** the CRAN status of a version, used to build (or skip) its source-tarball link */
|
|
@@ -56,6 +56,8 @@ export interface DecodedFunction {
|
|
|
56
56
|
export declare function transitiveCallees(functions: readonly DecodedFunction[], name: BrandedIdentifier): BrandedIdentifier[];
|
|
57
57
|
/** decode one of a blob's function records against the global string dictionary */
|
|
58
58
|
export declare function decodeFunction(strings: SigDict, blob: Readonly<PkgBlob>, fnIdx: number): DecodedFunction;
|
|
59
|
+
/** decode the native routines of one blob version (empty when it has none / the bundle omits them) */
|
|
60
|
+
export declare function decodeNatives(strings: SigDict, blob: Readonly<PkgBlob>, ver: string): SigNativeRoutineInfo[];
|
|
59
61
|
/** a decoded package dependency of one version (`type` is the compact {@link DepType} enum; map to a label via {@link DepTypeNames}) */
|
|
60
62
|
export interface ResolvedDependency {
|
|
61
63
|
readonly name: BrandedNamespace;
|
package/project/sigdb/decode.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.blobTuple = blobTuple;
|
|
|
5
5
|
exports.tupleToBlob = tupleToBlob;
|
|
6
6
|
exports.transitiveCallees = transitiveCallees;
|
|
7
7
|
exports.decodeFunction = decodeFunction;
|
|
8
|
+
exports.decodeNatives = decodeNatives;
|
|
8
9
|
exports.decodeDependencies = decodeDependencies;
|
|
9
10
|
exports.decodeClasses = decodeClasses;
|
|
10
11
|
exports.versionFnIndices = versionFnIndices;
|
|
@@ -39,6 +40,9 @@ function hasEntries(record) {
|
|
|
39
40
|
*/
|
|
40
41
|
function blobTuple(b) {
|
|
41
42
|
const head = [b.sigs, b.cgs, b.fns, b.versions, b.noncran ?? [], b.deps, b.depsByVersion];
|
|
43
|
+
if (b.natives?.length) {
|
|
44
|
+
return [...head, b.dates, b.sources ?? {}, b.classes ?? [], b.classesByVersion ?? {}, b.contracts ?? [], b.contractOf ?? {}, b.natives, b.nativesByVersion ?? {}];
|
|
45
|
+
}
|
|
42
46
|
if (b.contracts?.length) {
|
|
43
47
|
return [...head, b.dates, b.sources ?? {}, b.classes ?? [], b.classesByVersion ?? {}, b.contracts, b.contractOf ?? {}];
|
|
44
48
|
}
|
|
@@ -52,7 +56,7 @@ function blobTuple(b) {
|
|
|
52
56
|
}
|
|
53
57
|
/** the inverse of {@link blobTuple}: rebuild a {@link PkgBlob} from its on-disk tuple */
|
|
54
58
|
function tupleToBlob(t) {
|
|
55
|
-
return { sigs: t[0], cgs: t[1], fns: t[2], versions: t[3], noncran: t[4]?.length ? t[4] : undefined, deps: t[5] ?? [], depsByVersion: t[6] ?? {}, dates: t[7] ?? {}, sources: t[8], classes: t[9]?.length ? t[9] : undefined, classesByVersion: t[10], contracts: t[11]?.length ? t[11] : undefined, contractOf: t[12] };
|
|
59
|
+
return { sigs: t[0], cgs: t[1], fns: t[2], versions: t[3], noncran: t[4]?.length ? t[4] : undefined, deps: t[5] ?? [], depsByVersion: t[6] ?? {}, dates: t[7] ?? {}, sources: t[8], classes: t[9]?.length ? t[9] : undefined, classesByVersion: t[10], contracts: t[11]?.length ? t[11] : undefined, contractOf: t[11]?.length ? t[12] : undefined, natives: t[13]?.length ? t[13] : undefined, nativesByVersion: t[13]?.length ? t[14] : undefined };
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
58
62
|
* The transitive callees of `name`. Each local callee that is itself a function of `functions` (one package
|
|
@@ -105,6 +109,46 @@ function decodeFunction(strings, blob, fnIdx) {
|
|
|
105
109
|
callees
|
|
106
110
|
});
|
|
107
111
|
}
|
|
112
|
+
/** decode the native routines of one blob version (empty when it has none / the bundle omits them) */
|
|
113
|
+
function decodeNatives(strings, blob, ver) {
|
|
114
|
+
const list = blob.nativesByVersion?.[ver];
|
|
115
|
+
const pool = blob.natives;
|
|
116
|
+
if (list === undefined || pool === undefined) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
const out = [];
|
|
120
|
+
let prev = 0;
|
|
121
|
+
for (const delta of list) {
|
|
122
|
+
const rec = pool[prev += delta];
|
|
123
|
+
if (rec === undefined) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const [nameIdx, flags, symbolIdx, fileIdx, line, arity, rNames, params, facts, contractIdx = -1, endLine = -1, column = -1] = rec;
|
|
127
|
+
out.push((0, objects_1.compactRecord)({
|
|
128
|
+
name: strings.at(nameIdx),
|
|
129
|
+
iface: schema_1.NativeIfaceNames[(flags >> 3) & 0b111],
|
|
130
|
+
symbol: symbolIdx >= 0 ? strings.at(symbolIdx) : undefined,
|
|
131
|
+
lang: schema_1.NativeLangNames[flags & 0b111],
|
|
132
|
+
file: fileIdx >= 0 ? strings.at(fileIdx) : undefined,
|
|
133
|
+
line: line >= 0 ? line : undefined,
|
|
134
|
+
column: column >= 0 ? column : undefined,
|
|
135
|
+
endLine: endLine >= 0 ? endLine : undefined,
|
|
136
|
+
arity: arity >= 0 ? arity : undefined,
|
|
137
|
+
rNames: rNames.length ? rNames.map(i => strings.at(i)) : undefined,
|
|
138
|
+
params: params.map(([n, props, t]) => (0, objects_1.compactRecord)({
|
|
139
|
+
name: strings.at(n),
|
|
140
|
+
type: t === undefined ? undefined : strings.at(t),
|
|
141
|
+
props: props === 0 ? undefined : props
|
|
142
|
+
})),
|
|
143
|
+
facts: facts.map(i => strings.at(i)),
|
|
144
|
+
closed: (flags & 64 /* NativeFlag.Closed */) !== 0,
|
|
145
|
+
pure: flags & 128 /* NativeFlag.Pure */ ? true : undefined,
|
|
146
|
+
undefined: flags & 256 /* NativeFlag.Undefined */ ? true : undefined,
|
|
147
|
+
guards: contractIdx < 0 ? undefined : blob.contracts?.[contractIdx]
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
108
152
|
/** decode the declared dependencies of one blob version (empty when it declares none / the bundle omits them) */
|
|
109
153
|
function decodeDependencies(strings, blob, ver) {
|
|
110
154
|
const idx = blob.depsByVersion[ver];
|
|
@@ -22,6 +22,11 @@ export declare function resolveSource(baseDir: string, relPath: string): string;
|
|
|
22
22
|
export declare function sigDbCacheDir(override?: string, create?: boolean): string;
|
|
23
23
|
/** a temp path next to `target`, unique even across containers sharing a volume */
|
|
24
24
|
export declare const uniqueTempPath: (target: string, ext: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Moves the finished `tmp` to `target`. Another process writing the same content (the names are keyed by it) may have put it
|
|
27
|
+
* there first, and Windows does not let a rename replace a file that is open, so a target of the same size is taken as it is.
|
|
28
|
+
*/
|
|
29
|
+
export declare function moveIntoPlace(tmp: string, target: string): void;
|
|
25
30
|
/** read the (small) header line of a possibly-compressed bundle without decompressing the whole thing */
|
|
26
31
|
export declare function readHeaderOf(source: string): Promise<Record<string, unknown> | undefined>;
|
|
27
32
|
/** where an index for a decompressed source comes from -- a caller-supplied one (e.g. a manifest) or the sibling `.idx` */
|
|
@@ -8,6 +8,7 @@ exports.parseHeader = parseHeader;
|
|
|
8
8
|
exports.sigDbStream = sigDbStream;
|
|
9
9
|
exports.resolveSource = resolveSource;
|
|
10
10
|
exports.sigDbCacheDir = sigDbCacheDir;
|
|
11
|
+
exports.moveIntoPlace = moveIntoPlace;
|
|
11
12
|
exports.readHeaderOf = readHeaderOf;
|
|
12
13
|
exports.isUnpacked = isUnpacked;
|
|
13
14
|
exports.ensurePlain = ensurePlain;
|
|
@@ -105,6 +106,21 @@ function isWritableDir(dir, create) {
|
|
|
105
106
|
/** a temp path next to `target`, unique even across containers sharing a volume */
|
|
106
107
|
const uniqueTempPath = (target, ext) => `${target}.${process.pid}-${(0, crypto_1.randomBytes)(6).toString('hex')}.${ext}`;
|
|
107
108
|
exports.uniqueTempPath = uniqueTempPath;
|
|
109
|
+
/**
|
|
110
|
+
* Moves the finished `tmp` to `target`. Another process writing the same content (the names are keyed by it) may have put it
|
|
111
|
+
* there first, and Windows does not let a rename replace a file that is open, so a target of the same size is taken as it is.
|
|
112
|
+
*/
|
|
113
|
+
function moveIntoPlace(tmp, target) {
|
|
114
|
+
try {
|
|
115
|
+
fs_1.default.renameSync(tmp, target);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
if (!fs_1.default.existsSync(target) || fs_1.default.statSync(target).size !== fs_1.default.statSync(tmp).size) {
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
fs_1.default.rmSync(tmp, { force: true });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
108
124
|
/** read the (small) header line of a possibly-compressed bundle without decompressing the whole thing */
|
|
109
125
|
async function readHeaderOf(source) {
|
|
110
126
|
if (!(0, exports.isCompressed)(source)) {
|
|
@@ -164,7 +180,7 @@ function commitPlain(source, tmp, plain, idx, opts) {
|
|
|
164
180
|
if (opts.bytes !== undefined && size !== opts.bytes) {
|
|
165
181
|
throw new Error(`decompressing ${source} gave ${size} bytes, expected ${opts.bytes}; the file is corrupt or does not match its manifest`);
|
|
166
182
|
}
|
|
167
|
-
|
|
183
|
+
moveIntoPlace(tmp, plain);
|
|
168
184
|
if (!opts.indexless) {
|
|
169
185
|
writeCacheIndex(source, idx, opts.index);
|
|
170
186
|
}
|
|
@@ -69,7 +69,8 @@ export declare function defaultSigDbPath(scope?: SigDbScope, searchRoots?: reado
|
|
|
69
69
|
* Every distinct sigdb bundle discoverable in the search dirs (see {@link defaultSigDbPath}) -- not just the
|
|
70
70
|
* richest scope. So dropping an extra bundle next to the shipped default (a downloaded full-history
|
|
71
71
|
* `full.manifest.json.br`, a custom `*.manifest.json`, or a standalone `*.sigs.ndjson`) makes flowR mount it
|
|
72
|
-
* automatically. Manifests come first
|
|
72
|
+
* automatically. Manifests come first, those of an earlier search root first (so `$FLOWR_SIGDB_DIR` overrides
|
|
73
|
+
* what ships with flowR), then scope-named leading, richest scope first, then standalone bundles; the
|
|
73
74
|
* shard and dictionary files a manifest already owns are skipped. Deduped by filename, first search location wins.
|
|
74
75
|
*/
|
|
75
76
|
export declare function defaultSigDbPaths(searchRoots?: readonly string[]): string[];
|
|
@@ -21,6 +21,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
21
21
|
const schema_1 = require("./schema");
|
|
22
22
|
const codec_1 = require("./codec");
|
|
23
23
|
const decompress_1 = require("./decompress");
|
|
24
|
+
const global_caches_1 = require("../../util/global-caches");
|
|
24
25
|
exports.SigDbManifestMagic = 'flowr-sigdb-manifest';
|
|
25
26
|
exports.SigDbManifestSchema = 2;
|
|
26
27
|
/** write a {@link SigDbManifest} (compact JSON) plus a compressed copy per available codec (`.br` always, `.zst` when supported) beside it */
|
|
@@ -155,7 +156,7 @@ function defaultSigDbPath(scope, searchRoots) {
|
|
|
155
156
|
* repeats it for nothing. Kept honest by remembering the modification time of every directory the scan read: a
|
|
156
157
|
* bundle dropped next to the shipped ones bumps that directory and the next call rescans.
|
|
157
158
|
*/
|
|
158
|
-
const defaultSigDbPathsMemo =
|
|
159
|
+
const defaultSigDbPathsMemo = global_caches_1.GlobalCaches.map('default-sigdb-paths', global_caches_1.CacheScope.Process, 64);
|
|
159
160
|
/** Whether every directory the memoized scan read still carries the modification time it had back then */
|
|
160
161
|
function memoizedScanStillCurrent(watched) {
|
|
161
162
|
for (const [dir, mtimeMs] of watched) {
|
|
@@ -174,7 +175,8 @@ function memoizedScanStillCurrent(watched) {
|
|
|
174
175
|
* Every distinct sigdb bundle discoverable in the search dirs (see {@link defaultSigDbPath}) -- not just the
|
|
175
176
|
* richest scope. So dropping an extra bundle next to the shipped default (a downloaded full-history
|
|
176
177
|
* `full.manifest.json.br`, a custom `*.manifest.json`, or a standalone `*.sigs.ndjson`) makes flowR mount it
|
|
177
|
-
* automatically. Manifests come first
|
|
178
|
+
* automatically. Manifests come first, those of an earlier search root first (so `$FLOWR_SIGDB_DIR` overrides
|
|
179
|
+
* what ships with flowR), then scope-named leading, richest scope first, then standalone bundles; the
|
|
178
180
|
* shard and dictionary files a manifest already owns are skipped. Deduped by filename, first search location wins.
|
|
179
181
|
*/
|
|
180
182
|
function defaultSigDbPaths(searchRoots) {
|
|
@@ -192,12 +194,16 @@ function defaultSigDbPaths(searchRoots) {
|
|
|
192
194
|
const manifests = new Map(); // `<name>.manifest.json` (ignoring compression ext) -> first-found path
|
|
193
195
|
const standalones = new Map(); // `<name>.sigs.ndjson` (ignoring compression ext) -> first-found path
|
|
194
196
|
const foundIn = new Map(); // where a key was first found, to only compare codecs within one directory
|
|
197
|
+
/* the search root a key was first found under: a root asked for (`$FLOWR_SIGDB_DIR`) comes before the shipped bundles */
|
|
198
|
+
const rootOf = new Map();
|
|
199
|
+
let root = 0;
|
|
195
200
|
/** keeps the first location, but picks the cheapest readable codec among the copies that location offers */
|
|
196
201
|
function keep(into, key, file, dir) {
|
|
197
202
|
const previous = into.get(key);
|
|
198
203
|
if (previous === undefined) {
|
|
199
204
|
into.set(key, file);
|
|
200
205
|
foundIn.set(key, dir);
|
|
206
|
+
rootOf.set(key, root);
|
|
201
207
|
}
|
|
202
208
|
else if (foundIn.get(key) === dir && codecRank(file) < codecRank(previous)) {
|
|
203
209
|
into.set(key, file);
|
|
@@ -225,8 +231,8 @@ function defaultSigDbPaths(searchRoots) {
|
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
|
-
for (const
|
|
229
|
-
for (let dir =
|
|
234
|
+
for (const start of roots) {
|
|
235
|
+
for (let dir = start, i = 0; i < 10; i++) {
|
|
230
236
|
scanDir(dir);
|
|
231
237
|
const parent = path_1.default.dirname(dir);
|
|
232
238
|
if (parent === dir) {
|
|
@@ -234,6 +240,7 @@ function defaultSigDbPaths(searchRoots) {
|
|
|
234
240
|
}
|
|
235
241
|
dir = parent;
|
|
236
242
|
}
|
|
243
|
+
root++;
|
|
237
244
|
}
|
|
238
245
|
for (const bundle of sigDbBundleDirs(watched)) {
|
|
239
246
|
scanDir(bundle);
|
|
@@ -249,7 +256,7 @@ function defaultSigDbPaths(searchRoots) {
|
|
|
249
256
|
return scope === -1 ? SigDbScopeOrder.length : scope; // custom bundles sort after the known scopes
|
|
250
257
|
}
|
|
251
258
|
const orderedManifests = [...manifests.entries()]
|
|
252
|
-
.sort((a, b) => scopeRank(a[0]) - scopeRank(b[0]) || (0, strings_1.compareByCodeUnit)(a[0], b[0])).map(([, p]) => p);
|
|
259
|
+
.sort((a, b) => (rootOf.get(a[0]) ?? 0) - (rootOf.get(b[0]) ?? 0) || scopeRank(a[0]) - scopeRank(b[0]) || (0, strings_1.compareByCodeUnit)(a[0], b[0])).map(([, p]) => p);
|
|
253
260
|
const bundles = standalones.entries().filter(([name]) => !isShard(name)).map(([, p]) => p);
|
|
254
261
|
const paths = [...orderedManifests, ...bundles];
|
|
255
262
|
defaultSigDbPathsMemo.set(memoKey, { paths, watched });
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linking R's foreign function calls (`.Call(C_foo, x)`, `.C("foo", ..., PACKAGE = "pkg")`) to the native routines
|
|
3
|
+
* a signature database records for the package (see {@link SigNativeRoutineInfo}), and asking those routines'
|
|
4
|
+
* tool-derived facts with "unknown" kept apart from "no".
|
|
5
|
+
*/
|
|
6
|
+
import type { SigNativeRoutineInfo } from './schema';
|
|
7
|
+
import type { DynLibDirective } from '../plugins/file-plugins/files/flowr-namespace-file';
|
|
8
|
+
import type { FlowrAnalyzer } from '../flowr-analyzer';
|
|
9
|
+
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
10
|
+
import { type BrandedIdentifier, Identifier } from '../../dataflow/environments/identifier';
|
|
11
|
+
import { type DataflowGraphVertexFunctionCall } from '../../dataflow/graph/vertex';
|
|
12
|
+
import { type DataflowGraph } from '../../dataflow/graph/graph';
|
|
13
|
+
import { type StatedProps } from '../../dataflow/environments/built-in-props';
|
|
14
|
+
import type { AstIdMap, RNodeWithParent } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
15
|
+
import type { ReadOnlyFlowrAnalyzerContext } from '../context/flowr-analyzer-context';
|
|
16
|
+
/** How a foreign function call names its routine. */
|
|
17
|
+
export interface NativeRoutineRef {
|
|
18
|
+
/** the routine's name as written: the string's content, or the R variable's name */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** the call names an R variable (`.Call(C_foo)`), which `useDynLib` binds, rather than a string (`.Call("foo")`) */
|
|
21
|
+
readonly symbolic: boolean;
|
|
22
|
+
/** the R function called, `.Call`, `.C`, `.Fortran`, `.External`, ... */
|
|
23
|
+
readonly iface?: BrandedIdentifier;
|
|
24
|
+
/** the string given as `PACKAGE`, if any */
|
|
25
|
+
readonly package?: string;
|
|
26
|
+
}
|
|
27
|
+
/** One foreign function call of an analyzed program. */
|
|
28
|
+
export interface NativeCallSite extends NativeRoutineRef {
|
|
29
|
+
/** the call node */
|
|
30
|
+
readonly id: NodeId;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Helpers for the native routines of a signature database.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const routines = db.nativeRoutines('data.table') ?? [];
|
|
37
|
+
* const r = NativeRoutines.resolve(routines, { name: 'Cforder', symbolic: true, iface: '.Call' });
|
|
38
|
+
* NativeRoutines.has(r, 'parallel'); // true: the routine (or what it calls) has an OpenMP directive
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const NativeRoutines: {
|
|
42
|
+
readonly name: "NativeRoutines";
|
|
43
|
+
/**
|
|
44
|
+
* The routine a foreign function call names, the way R finds it: an R variable is the one `useDynLib` binds
|
|
45
|
+
* (the database's {@link SigNativeRoutineInfo.rNames}, else the package's `useDynLib` directives, if given);
|
|
46
|
+
* a string is first a registered name of the call's interface, then any registered name, then a linker symbol
|
|
47
|
+
* (`"foo"` also finds the Fortran symbol `foo_`). `undefined` when nothing matches.
|
|
48
|
+
*/
|
|
49
|
+
readonly resolve: (this: void, routines: readonly SigNativeRoutineInfo[], ref: NativeRoutineRef, dynLibs?: readonly DynLibDirective[]) => SigNativeRoutineInfo | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the routine has the fact (or, asked by family like `parallel`, any fact of it): `true` when a tool
|
|
52
|
+
* found it, `false` only when the routine is {@link SigNativeRoutineInfo.closed} and the fact is not an
|
|
53
|
+
* `error:`/`warning:` one, `undefined` when not known (including for an unknown routine).
|
|
54
|
+
*/
|
|
55
|
+
readonly has: (this: void, routine: SigNativeRoutineInfo | undefined, fact: string) => boolean | undefined;
|
|
56
|
+
/** Whether the routine runs code concurrently: it forks, starts threads, or runs OpenMP, TBB, or rayon work. */
|
|
57
|
+
readonly concurrent: (this: void, routine: SigNativeRoutineInfo | undefined) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* How to find the routine a call of the analyzed program runs, among the `natives` of the analyzed package: only a call
|
|
60
|
+
* `info` states to be a foreign function call ({@link CallProp.Ffi}) runs one.
|
|
61
|
+
*/
|
|
62
|
+
readonly lookup: (this: void, natives: readonly SigNativeRoutineInfo[], graph: DataflowGraph, info: (name: Identifier) => StatedProps | undefined, ctx?: ReadOnlyFlowrAnalyzerContext) => (vertex: DataflowGraphVertexFunctionCall) => SigNativeRoutineInfo | undefined;
|
|
63
|
+
/** the facts of the routine of the family `family` (`parallel` gives `parallel:openmp`, ...), empty if none is known */
|
|
64
|
+
readonly factsOf: (this: void, routine: SigNativeRoutineInfo | undefined, family: string) => string[];
|
|
65
|
+
/** How the foreign function call names its routine, `undefined` unless as a string or an R variable. */
|
|
66
|
+
readonly refOf: (this: void, vertex: DataflowGraphVertexFunctionCall, idMap: AstIdMap) => NativeRoutineRef | undefined;
|
|
67
|
+
/** The values the foreign function call hands its routine, the routine's parameters in order, `undefined` where flowR lost track of one. */
|
|
68
|
+
readonly argumentsOf: (this: void, vertex: DataflowGraphVertexFunctionCall, idMap: AstIdMap) => (RNodeWithParent | undefined)[];
|
|
69
|
+
/**
|
|
70
|
+
* The routines the signature database records for the analyzed package itself, the one its DESCRIPTION names, at its version if the
|
|
71
|
+
* database has it, else the newest. flowR cannot read compiled code itself, so this is how a package the database knows gets them.
|
|
72
|
+
*/
|
|
73
|
+
readonly ofProject: (this: void, ctx: ReadOnlyFlowrAnalyzerContext) => readonly SigNativeRoutineInfo[];
|
|
74
|
+
/** the `useDynLib` directives of the NAMESPACE of the analyzed package, empty when it has none */
|
|
75
|
+
readonly dynLibsIn: (this: void, ctx: ReadOnlyFlowrAnalyzerContext) => readonly DynLibDirective[];
|
|
76
|
+
/**
|
|
77
|
+
* The foreign function calls of the analyzed program (the calls flowR knows to be `.Call`, `.C`, ... by
|
|
78
|
+
* {@link CallProp.Ffi}, so a redefined `.Call` is not one), with the routine each names, when written as a
|
|
79
|
+
* string or a variable.
|
|
80
|
+
*/
|
|
81
|
+
readonly callSites: (this: void, analyzer: FlowrAnalyzer) => Promise<NativeCallSite[]>;
|
|
82
|
+
};
|