@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.
Files changed (120) hide show
  1. package/abstract-interpretation/branch-paths.d.ts +10 -0
  2. package/abstract-interpretation/branch-paths.js +104 -10
  3. package/config.js +3 -1
  4. package/control-flow/control-flow-graph.js +18 -2
  5. package/data/r-base-guards.generated.js +2 -2
  6. package/dataflow/environments/ambient-effect.js +4 -1
  7. package/dataflow/environments/built-in-props.d.ts +8 -2
  8. package/dataflow/environments/built-in-props.js +16 -5
  9. package/dataflow/environments/default-builtin-config/base-functions.js +1 -1
  10. package/dataflow/environments/default-builtin-config/guards.d.ts +1 -1
  11. package/dataflow/environments/default-builtin-config/guards.js +28 -0
  12. package/dataflow/environments/default-builtin-config/index.d.ts +8 -4
  13. package/dataflow/environments/default-builtin-config/index.js +9 -5
  14. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +1 -1
  15. package/dataflow/environments/default-builtin-config/parallel-execution.js +25 -0
  16. package/dataflow/environments/guard-facts.d.ts +28 -1
  17. package/dataflow/environments/pkg-name.d.ts +2 -0
  18. package/dataflow/environments/query-fn-props.d.ts +19 -15
  19. package/dataflow/environments/query-fn-props.js +46 -36
  20. package/dataflow/environments/removal-marker.d.ts +1 -1
  21. package/dataflow/environments/removal-marker.js +18 -3
  22. package/dataflow/environments/reserved-names.d.ts +6 -0
  23. package/dataflow/environments/reserved-names.js +14 -0
  24. package/dataflow/environments/resolve-by-name.js +5 -10
  25. package/dataflow/eval/resolve/alias-tracking.js +23 -6
  26. package/dataflow/extractor.js +103 -28
  27. package/dataflow/fn/argument-roles.d.ts +3 -0
  28. package/dataflow/fn/argument-roles.js +5 -5
  29. package/dataflow/fn/exceptions-of-function.d.ts +7 -0
  30. package/dataflow/fn/exceptions-of-function.js +15 -2
  31. package/dataflow/fn/function-props.d.ts +1 -1
  32. package/dataflow/fn/function-props.js +40 -18
  33. package/dataflow/fn/function-semantics.d.ts +3 -1
  34. package/dataflow/fn/function-semantics.js +2 -0
  35. package/dataflow/fn/guards/built-in-guards.js +2 -1
  36. package/dataflow/fn/guards/condition-grouping.d.ts +11 -0
  37. package/dataflow/fn/guards/condition-grouping.js +50 -3
  38. package/dataflow/fn/guards/function-guards.d.ts +10 -0
  39. package/dataflow/fn/guards/function-guards.js +130 -14
  40. package/dataflow/fn/guards/guard-claims.d.ts +2 -0
  41. package/dataflow/fn/guards/guard-claims.js +42 -2
  42. package/dataflow/fn/guards/guard-knowledge.d.ts +7 -1
  43. package/dataflow/fn/guards/guard-knowledge.js +50 -4
  44. package/dataflow/fn/guards/guard-term.js +10 -1
  45. package/dataflow/fn/higher-order-function.d.ts +15 -1
  46. package/dataflow/fn/higher-order-function.js +54 -10
  47. package/dataflow/graph/call-graph.d.ts +5 -0
  48. package/dataflow/graph/call-graph.js +51 -15
  49. package/dataflow/graph/df-helper.d.ts +2 -0
  50. package/dataflow/graph/df-helper.js +4 -2
  51. package/dataflow/graph/graph.d.ts +21 -0
  52. package/dataflow/graph/graph.js +63 -2
  53. package/dataflow/internal/linker.d.ts +20 -0
  54. package/dataflow/internal/linker.js +190 -24
  55. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +20 -12
  56. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +5 -3
  57. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +2 -1
  58. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +2 -0
  59. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +5 -0
  60. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +7 -3
  61. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +12 -5
  62. package/dataflow/internal/process/functions/call/deferred.d.ts +7 -2
  63. package/dataflow/internal/process/functions/call/deferred.js +63 -28
  64. package/dataflow/internal/process/functions/call/quoted.js +33 -7
  65. package/documentation/data/dfg/doc-ambient.js +3 -1
  66. package/documentation/wiki-normalized-ast.js +1 -1
  67. package/documentation/wiki-query.js +9 -3
  68. package/package.json +5 -3
  69. package/project/context/flowr-analyzer-context.d.ts +7 -4
  70. package/project/context/flowr-analyzer-context.js +8 -3
  71. package/project/context/flowr-analyzer-files-context.js +1 -0
  72. package/project/context/flowr-analyzer-functions-context.d.ts +2 -1
  73. package/project/context/flowr-analyzer-functions-context.js +9 -8
  74. package/project/flowr-analyzer.d.ts +7 -4
  75. package/project/flowr-analyzer.js +37 -8
  76. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +22 -0
  77. package/project/plugins/file-plugins/files/flowr-namespace-file.js +34 -0
  78. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -1
  79. package/project/sigdb/build.js +41 -2
  80. package/project/sigdb/decode.d.ts +3 -1
  81. package/project/sigdb/decode.js +45 -1
  82. package/project/sigdb/decompress.d.ts +5 -0
  83. package/project/sigdb/decompress.js +17 -1
  84. package/project/sigdb/manifest.d.ts +2 -1
  85. package/project/sigdb/manifest.js +12 -5
  86. package/project/sigdb/native-routines.d.ts +82 -0
  87. package/project/sigdb/native-routines.js +178 -0
  88. package/project/sigdb/reader.d.ts +21 -3
  89. package/project/sigdb/reader.js +35 -3
  90. package/project/sigdb/schema.d.ts +107 -3
  91. package/project/sigdb/schema.js +8 -2
  92. package/project/sigdb/sigdb-download.js +1 -1
  93. package/project/sigdb/sigdb-version.d.ts +7 -1
  94. package/project/sigdb/sigdb-version.js +12 -9
  95. package/project/sigdb/spec-query.d.ts +9 -4
  96. package/project/sigdb/spec-query.js +71 -45
  97. package/queries/catalog/call-context-query/call-context-query-executor.js +76 -29
  98. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +1 -12
  99. package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.d.ts +3 -0
  100. package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.js +3 -2
  101. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +3 -0
  102. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +3 -2
  103. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +3 -1
  104. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +4 -2
  105. package/queries/catalog/signature-query/signature-query-executor.js +6 -2
  106. package/queries/catalog/signature-query/signature-query-format.d.ts +4 -0
  107. package/util/collections/bounded-map.d.ts +9 -0
  108. package/util/collections/bounded-map.js +22 -0
  109. package/util/collections/defaultmap.d.ts +5 -0
  110. package/util/collections/defaultmap.js +10 -0
  111. package/util/fixpoint.d.ts +6 -1
  112. package/util/fixpoint.js +45 -3
  113. package/util/flowr-version.d.ts +1 -1
  114. package/util/flowr-version.js +2 -2
  115. package/util/global-caches.d.ts +26 -0
  116. package/util/global-caches.js +43 -0
  117. package/util/monoid.js +2 -2
  118. package/util/quads.js +11 -3
  119. package/util/r-package-urls.d.ts +19 -0
  120. package/util/r-package-urls.js +41 -0
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NativeRoutines = void 0;
4
+ const identifier_1 = require("../../dataflow/environments/identifier");
5
+ const signature_db_1 = require("./signature-db");
6
+ const vertex_1 = require("../../dataflow/graph/vertex");
7
+ const graph_1 = require("../../dataflow/graph/graph");
8
+ const match_args_1 = require("../../dataflow/graph/match-args");
9
+ const built_in_props_1 = require("../../dataflow/environments/built-in-props");
10
+ const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
11
+ const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
12
+ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
13
+ const flowr_file_1 = require("../context/flowr-file");
14
+ /** the formals of the foreign function interface, which have to be named in full as they follow `...`; `.C` and `.Fortran` take the last three as well */
15
+ const Formals = { '.NAME': 'name', '...': '...', 'PACKAGE': 'package', 'NAOK': 'option', 'DUP': 'option', 'ENCODING': 'option' };
16
+ /** The value of each argument of the call bound to `formal` of {@link Formals}, in order. */
17
+ function valuesOf(vertex, formal, idMap) {
18
+ const values = new Map(vertex.args.filter(graph_1.FunctionArgument.isNamed).map(a => [a.nodeId, a.valueId]));
19
+ return (match_args_1.MatchArgs.toSpec(vertex.args, Formals).get(formal) ?? []).map(arg => {
20
+ const vid = values.has(arg) ? values.get(arg) : arg;
21
+ return vid === undefined ? undefined : idMap.get(vid);
22
+ });
23
+ }
24
+ /** the interface a call goes through, as {@link SigNativeRoutineInfo.iface} names it (`.External2` reaches `.External` routines) */
25
+ function ifaceOf(call) {
26
+ switch (call === undefined ? undefined : String(call)) {
27
+ case '.External2':
28
+ case '.External.graphics': return '.External';
29
+ case '.Call.graphics': return '.Call';
30
+ default: return call === undefined ? undefined : String(call);
31
+ }
32
+ }
33
+ /** a fact's category matches `fact` itself or, asked by its family (`parallel`), every fact of it (`parallel:openmp`) */
34
+ function matches(fact, asked) {
35
+ return fact === asked || fact.startsWith(asked + ':');
36
+ }
37
+ /**
38
+ * Helpers for the native routines of a signature database.
39
+ * @example
40
+ * ```ts
41
+ * const routines = db.nativeRoutines('data.table') ?? [];
42
+ * const r = NativeRoutines.resolve(routines, { name: 'Cforder', symbolic: true, iface: '.Call' });
43
+ * NativeRoutines.has(r, 'parallel'); // true: the routine (or what it calls) has an OpenMP directive
44
+ * ```
45
+ */
46
+ exports.NativeRoutines = {
47
+ name: 'NativeRoutines',
48
+ /**
49
+ * The routine a foreign function call names, the way R finds it: an R variable is the one `useDynLib` binds
50
+ * (the database's {@link SigNativeRoutineInfo.rNames}, else the package's `useDynLib` directives, if given);
51
+ * a string is first a registered name of the call's interface, then any registered name, then a linker symbol
52
+ * (`"foo"` also finds the Fortran symbol `foo_`). `undefined` when nothing matches.
53
+ */
54
+ resolve(routines, ref, dynLibs) {
55
+ const iface = ifaceOf(ref.iface);
56
+ const byName = (name) => routines.find(r => r.name === name && (iface === undefined || r.iface === undefined || r.iface === iface))
57
+ ?? routines.find(r => r.name === name);
58
+ if (ref.symbolic) {
59
+ const bound = routines.find(r => r.rNames?.includes(ref.name));
60
+ if (bound !== undefined) {
61
+ return bound;
62
+ }
63
+ for (const dyn of dynLibs ?? []) {
64
+ const explicit = dyn.symbols.find(s => s.rName === ref.name);
65
+ if (explicit !== undefined) {
66
+ return byName(explicit.routine);
67
+ }
68
+ if (dyn.registration && ref.name.startsWith(dyn.prefix) && ref.name.endsWith(dyn.suffix) && ref.name.length >= dyn.prefix.length + dyn.suffix.length) {
69
+ const hit = byName(ref.name.slice(dyn.prefix.length, ref.name.length - dyn.suffix.length));
70
+ if (hit !== undefined) {
71
+ return hit;
72
+ }
73
+ }
74
+ }
75
+ /* `useDynLib(pkg, foo)` binds `foo` to the routine of that name */
76
+ return byName(ref.name);
77
+ }
78
+ const lower = ref.name.toLowerCase() + '_';
79
+ return byName(ref.name)
80
+ ?? routines.find(r => r.symbol === ref.name || (r.symbol === undefined && r.name === ref.name))
81
+ ?? routines.find(r => r.lang === 'fortran' && r.symbol === lower);
82
+ },
83
+ /**
84
+ * Whether the routine has the fact (or, asked by family like `parallel`, any fact of it): `true` when a tool
85
+ * found it, `false` only when the routine is {@link SigNativeRoutineInfo.closed} and the fact is not an
86
+ * `error:`/`warning:` one, `undefined` when not known (including for an unknown routine).
87
+ */
88
+ has(routine, fact) {
89
+ if (routine === undefined) {
90
+ return undefined;
91
+ }
92
+ if (routine.facts?.some(f => matches(f, fact))) {
93
+ return true;
94
+ }
95
+ if (!routine.closed || fact.startsWith('error') || fact.startsWith('warning')) {
96
+ return undefined;
97
+ }
98
+ return false;
99
+ },
100
+ /** Whether the routine runs code concurrently: it forks, starts threads, or runs OpenMP, TBB, or rayon work. */
101
+ concurrent(routine) {
102
+ return routine?.facts?.some(f => matches(f, 'parallel') || f === 'process:fork') === true;
103
+ },
104
+ /**
105
+ * How to find the routine a call of the analyzed program runs, among the `natives` of the analyzed package: only a call
106
+ * `info` states to be a foreign function call ({@link CallProp.Ffi}) runs one.
107
+ */
108
+ lookup(natives, graph, info, ctx) {
109
+ if (natives.length === 0) {
110
+ return () => undefined;
111
+ }
112
+ const dynLibs = ctx === undefined ? [] : exports.NativeRoutines.dynLibsIn(ctx);
113
+ return vertex => {
114
+ const ref = built_in_props_1.CallProps.hasAny(info(vertex.name), built_in_props_1.CallProp.Ffi) ? exports.NativeRoutines.refOf(vertex, graph.idMap) : undefined;
115
+ return ref === undefined ? undefined : exports.NativeRoutines.resolve(natives, ref, dynLibs);
116
+ };
117
+ },
118
+ /** the facts of the routine of the family `family` (`parallel` gives `parallel:openmp`, ...), empty if none is known */
119
+ factsOf(routine, family) {
120
+ return routine?.facts?.filter(f => matches(f, family)) ?? [];
121
+ },
122
+ /** How the foreign function call names its routine, `undefined` unless as a string or an R variable. */
123
+ refOf(vertex, idMap) {
124
+ const [nameNode] = valuesOf(vertex, 'name', idMap);
125
+ const [pkgNode] = valuesOf(vertex, 'package', idMap);
126
+ const iface = identifier_1.Identifier.getName(vertex.name);
127
+ const pkg = pkgNode !== undefined && r_string_1.RString.is(pkgNode) ? { package: pkgNode.content.str } : {};
128
+ if (nameNode !== undefined && r_string_1.RString.is(nameNode)) {
129
+ return { iface, name: nameNode.content.str, symbolic: false, ...pkg };
130
+ }
131
+ else if (nameNode !== undefined && r_symbol_1.RSymbol.is(nameNode)) {
132
+ return { iface, name: String(identifier_1.Identifier.getName(nameNode.content)), symbolic: true, ...pkg };
133
+ }
134
+ return undefined;
135
+ },
136
+ /** The values the foreign function call hands its routine, the routine's parameters in order, `undefined` where flowR lost track of one. */
137
+ argumentsOf(vertex, idMap) {
138
+ return valuesOf(vertex, '...', idMap);
139
+ },
140
+ /**
141
+ * The routines the signature database records for the analyzed package itself, the one its DESCRIPTION names, at its version if the
142
+ * database has it, else the newest. flowR cannot read compiled code itself, so this is how a package the database knows gets them.
143
+ */
144
+ ofProject(ctx) {
145
+ const description = ctx.files.getFilesByRole(flowr_file_1.FileRole.Description)[0];
146
+ const pkg = description?.packageName();
147
+ const db = (0, signature_db_1.signatureDbOf)(ctx.deps);
148
+ if (pkg === undefined || !db.available()) {
149
+ return [];
150
+ }
151
+ const source = db.sources();
152
+ return source.nativeRoutines?.(pkg, description?.version()?.str) ?? source.nativeRoutines?.(pkg) ?? [];
153
+ },
154
+ /** the `useDynLib` directives of the NAMESPACE of the analyzed package, empty when it has none */
155
+ dynLibsIn(ctx) {
156
+ const fmt = ctx.files.getFilesByRole(flowr_file_1.FileRole.Namespace)[0]?.content();
157
+ return fmt?.current.dynLibs ?? [];
158
+ },
159
+ /**
160
+ * The foreign function calls of the analyzed program (the calls flowR knows to be `.Call`, `.C`, ... by
161
+ * {@link CallProp.Ffi}, so a redefined `.Call` is not one), with the routine each names, when written as a
162
+ * string or a variable.
163
+ */
164
+ async callSites(analyzer) {
165
+ const df = await analyzer.dataflow();
166
+ const idMap = (await analyzer.normalize()).idMap;
167
+ const out = [];
168
+ for (const [id, vertex] of df.graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
169
+ const props = (0, query_fn_props_1.callFnProps)(id, df);
170
+ const ref = built_in_props_1.CallProps.hasAny(props, built_in_props_1.CallProp.Ffi) && props?.sig?.some(([formal]) => formal === '.NAME') ? exports.NativeRoutines.refOf(vertex, idMap) : undefined;
171
+ if (ref !== undefined) {
172
+ out.push({ id, ...ref });
173
+ }
174
+ }
175
+ return out;
176
+ }
177
+ };
178
+ //# sourceMappingURL=native-routines.js.map
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { BrandedIdentifier, BrandedNamespace } from '../../dataflow/environments/identifier';
6
6
  import { RVersion, type VersionString } from '../../util/r-version';
7
- import { type LibraryExports, type PkgBlob, type SigClassInfo, type SigDb, type SigDbContent } from './schema';
7
+ import { type LibraryExports, type PkgBlob, type SigClassInfo, type SigNativeRoutineInfo, type SigDb, type SigDbContent } from './schema';
8
8
  import { type VersionRelease } from './sigdb-version';
9
9
  import { type SigDbIndex } from './index-format';
10
10
  import { type DecodedFunction, type ResolvedDependency } from './decode';
@@ -50,6 +50,11 @@ export interface PackageSignatureSource {
50
50
  * union) -- {@link LibraryExports.s4Classes}, a flat name list, has nowhere to hang this; `version` defaults to the newest.
51
51
  */
52
52
  classes(pkg: BrandedNamespace, version?: string): SigClassInfo[] | undefined;
53
+ /**
54
+ * The native (C, C++, Fortran) routines of a package version with their tool-derived facts (see
55
+ * {@link SigNativeRoutineInfo}); `version` defaults to the newest. Optional: a source without them leaves it out.
56
+ */
57
+ nativeRoutines?(pkg: BrandedNamespace, version?: string): SigNativeRoutineInfo[] | undefined;
53
58
  /** every package name this source can resolve */
54
59
  packageNames(): BrandedNamespace[];
55
60
  /** whether the package is an R-core / base package (its versions are the R releases it shipped with) */
@@ -65,7 +70,7 @@ export interface PackageSignatureSource {
65
70
  releaseDate(pkg: BrandedNamespace, version?: string): Date | undefined;
66
71
  /** every known release of a package (version + date), ascending by R-version order */
67
72
  releaseDates(pkg: BrandedNamespace): VersionRelease[];
68
- /** the newest version of a package by release date (falling back to the recorded latest, then SemVer order) */
73
+ /** the version a package's latest stands for, see {@link newestVersion} */
69
74
  latestVersion(pkg: BrandedNamespace): RVersion | undefined;
70
75
  /** release any held file handles */
71
76
  close(): void;
@@ -114,6 +119,7 @@ export declare class MergedSignatureSource implements PackageSignatureSource {
114
119
  transitiveCallees(pkg: BrandedNamespace, name: BrandedIdentifier, version?: string): BrandedIdentifier[] | undefined;
115
120
  dependencies(pkg: BrandedNamespace, version?: string): ResolvedDependency[] | undefined;
116
121
  classes(pkg: BrandedNamespace, version?: string): SigClassInfo[] | undefined;
122
+ nativeRoutines(pkg: BrandedNamespace, version?: string): SigNativeRoutineInfo[] | undefined;
117
123
  packageNames(): BrandedNamespace[];
118
124
  isBaseR(pkg: BrandedNamespace): boolean;
119
125
  downloads(pkg: BrandedNamespace): number;
@@ -167,7 +173,7 @@ declare abstract class HistorySource {
167
173
  private dated;
168
174
  /** the release date of a package version (defaulting to the newest release), or `undefined` if unknown */
169
175
  releaseDate(pkg: BrandedNamespace, version?: string): Date | undefined;
170
- /** the newest version of a package by release date (falling back to the recorded latest, then SemVer order) */
176
+ /** the version a package's latest stands for, see {@link newestVersion} */
171
177
  latestVersion(pkg: BrandedNamespace): RVersion | undefined;
172
178
  }
173
179
  /**
@@ -181,10 +187,17 @@ export declare class SigDatabase extends HistorySource implements PackageSignatu
181
187
  /** a version's function indices plus its `name -> index` view, keyed by package and version; FIFO-bounded */
182
188
  private readonly versionFnCache;
183
189
  private static readonly VersionFnCacheCap;
190
+ /** bounds {@link nameIds}: a shared database lives as long as the process, and the names asked for come from the analyzed code */
191
+ private static readonly NameIdCacheCap;
184
192
  /** which names a package can offer at all, as sorted dictionary ids; filled the first time its blob is read */
185
193
  private readonly nameIdsOfBlob;
186
194
  /** dictionary id per name asked for, so only the names someone actually queried are ever resolved */
187
195
  private readonly nameIds;
196
+ /**
197
+ * per package, what the version lookups need of its blob: every name resolved asks for a package's latest version, and a blob
198
+ * the shared budget dropped would be read and decoded again just for that; at most one per package of the bundle
199
+ */
200
+ private readonly outlines;
188
201
  private readonly fd;
189
202
  readonly strings: SigDict;
190
203
  readonly index: SigDbIndex;
@@ -233,6 +246,9 @@ export declare class SigDatabase extends HistorySource implements PackageSignatu
233
246
  contentHash(blobs?: PkgBlob[]): string;
234
247
  /** whether this bundle actually carries the given version of a package (not just the package) */
235
248
  hasVersion(pkg: BrandedNamespace, version: string): boolean;
249
+ latestVersion(pkg: BrandedNamespace): RVersion | undefined;
250
+ /** the {@link outlines} entry of the package, read off its blob the first time */
251
+ private outline;
236
252
  isCranVersion(pkg: BrandedNamespace, version: string): boolean;
237
253
  sourceOf(pkg: BrandedNamespace, version: string): string | undefined;
238
254
  /** `{ blob, meta }` for `pkg` when this bundle carries both, `undefined` otherwise; the shared prologue of most per-package queries below. */
@@ -258,6 +274,7 @@ export declare class SigDatabase extends HistorySource implements PackageSignatu
258
274
  private decodedFor;
259
275
  dependencies(pkg: BrandedNamespace, version?: string): ResolvedDependency[] | undefined;
260
276
  classes(pkg: BrandedNamespace, version?: string): SigClassInfo[] | undefined;
277
+ nativeRoutines(pkg: BrandedNamespace, version?: string): SigNativeRoutineInfo[] | undefined;
261
278
  /** whether this is an R-core / base package (its versions are the R releases it shipped with; see {@link SigDbPkgMeta}) */
262
279
  isBaseR(pkg: BrandedNamespace): boolean;
263
280
  /** the download count recorded for the package, `0` when this source does not carry it */
@@ -347,6 +364,7 @@ export declare class SigDatabaseSet extends HistorySource implements PackageSign
347
364
  functionByName(pkg: BrandedNamespace, name: BrandedIdentifier, version?: string): DecodedFunction | undefined;
348
365
  dependencies(pkg: BrandedNamespace, version?: string): ResolvedDependency[] | undefined;
349
366
  classes(pkg: BrandedNamespace, version?: string): SigClassInfo[] | undefined;
367
+ nativeRoutines(pkg: BrandedNamespace, version?: string): SigNativeRoutineInfo[] | undefined;
350
368
  /** whether this is an R-core / base package (see {@link SigDatabase.isBaseR}); O(1) via the hoisted metadata */
351
369
  isBaseR(pkg: BrandedNamespace): boolean;
352
370
  /** the download count of the package; O(1) via the hoisted metadata, so no shard has to be unpacked for it */
@@ -246,6 +246,9 @@ class MergedSignatureSource {
246
246
  classes(pkg, version) {
247
247
  return this.pick(pkg, version)?.classes(pkg, version);
248
248
  }
249
+ nativeRoutines(pkg, version) {
250
+ return this.pick(pkg, version)?.nativeRoutines?.(pkg, version);
251
+ }
249
252
  packageNames() {
250
253
  return (0, arrays_1.uniqueArray)(this.sources.flatMap(s => s.packageNames()));
251
254
  }
@@ -377,7 +380,7 @@ class HistorySource {
377
380
  const day = d?.ver === undefined ? undefined : d.blob.dates[d.ver];
378
381
  return day === undefined ? undefined : new Date((0, sigdb_version_1.dayToMillis)(day));
379
382
  }
380
- /** the newest version of a package by release date (falling back to the recorded latest, then SemVer order) */
383
+ /** the version a package's latest stands for, see {@link newestVersion} */
381
384
  latestVersion(pkg) {
382
385
  const ver = this.dated(pkg)?.ver;
383
386
  return ver === undefined ? undefined : r_version_1.RVersion.parseOrZero(ver);
@@ -394,10 +397,17 @@ class SigDatabase extends HistorySource {
394
397
  /** a version's function indices plus its `name -> index` view, keyed by package and version; FIFO-bounded */
395
398
  versionFnCache = new Map();
396
399
  static VersionFnCacheCap = 2048;
400
+ /** bounds {@link nameIds}: a shared database lives as long as the process, and the names asked for come from the analyzed code */
401
+ static NameIdCacheCap = 65_536;
397
402
  /** which names a package can offer at all, as sorted dictionary ids; filled the first time its blob is read */
398
403
  nameIdsOfBlob = new Map();
399
404
  /** dictionary id per name asked for, so only the names someone actually queried are ever resolved */
400
405
  nameIds = new Map();
406
+ /**
407
+ * per package, what the version lookups need of its blob: every name resolved asks for a package's latest version, and a blob
408
+ * the shared budget dropped would be read and decoded again just for that; at most one per package of the bundle
409
+ */
410
+ outlines = new Map();
401
411
  fd;
402
412
  strings;
403
413
  index;
@@ -498,7 +508,7 @@ class SigDatabase extends HistorySource {
498
508
  nameId(name) {
499
509
  let id = this.nameIds.get(name);
500
510
  if (id === undefined) {
501
- this.nameIds.set(name, id = dictionaryIdOf(this.strings, name));
511
+ id = SigDatabase.cache(this.nameIds, name, dictionaryIdOf(this.strings, name), SigDatabase.NameIdCacheCap);
502
512
  }
503
513
  return id;
504
514
  }
@@ -597,7 +607,23 @@ class SigDatabase extends HistorySource {
597
607
  }
598
608
  /** whether this bundle actually carries the given version of a package (not just the package) */
599
609
  hasVersion(pkg, version) {
600
- return this.blob(pkg)?.versions[version] !== undefined;
610
+ return this.outline(pkg)?.versions.has(version) ?? false;
611
+ }
612
+ latestVersion(pkg) {
613
+ return this.outline(pkg)?.latest;
614
+ }
615
+ /** the {@link outlines} entry of the package, read off its blob the first time */
616
+ outline(pkg) {
617
+ let outline = this.outlines.get(pkg);
618
+ if (outline === undefined) {
619
+ const blob = this.blob(pkg);
620
+ if (blob === undefined) {
621
+ return undefined;
622
+ }
623
+ outline = { latest: super.latestVersion(pkg), versions: new Set(Object.keys(blob.versions)) };
624
+ this.outlines.set(pkg, outline);
625
+ }
626
+ return outline;
601
627
  }
602
628
  isCranVersion(pkg, version) {
603
629
  return !this.blob(pkg)?.noncran?.includes(version);
@@ -703,6 +729,9 @@ class SigDatabase extends HistorySource {
703
729
  classes(pkg, version) {
704
730
  return this.decodedFor(pkg, version, decode_1.decodeClasses);
705
731
  }
732
+ nativeRoutines(pkg, version) {
733
+ return this.decodedFor(pkg, version, decode_1.decodeNatives);
734
+ }
706
735
  /** whether this is an R-core / base package (its versions are the R releases it shipped with; see {@link SigDbPkgMeta}) */
707
736
  isBaseR(pkg) {
708
737
  return this.index.meta[pkg]?.[3] === 1;
@@ -977,6 +1006,9 @@ class SigDatabaseSet extends HistorySource {
977
1006
  classes(pkg, version) {
978
1007
  return this.firstOf(pkg, version, db => db.classes(pkg, version));
979
1008
  }
1009
+ nativeRoutines(pkg, version) {
1010
+ return this.firstOf(pkg, version, db => db.nativeRoutines(pkg, version));
1011
+ }
980
1012
  /** whether this is an R-core / base package (see {@link SigDatabase.isBaseR}); O(1) via the hoisted metadata */
981
1013
  isBaseR(pkg) {
982
1014
  const meta = this.manifest.meta?.[pkg];
@@ -92,7 +92,11 @@ export declare const enum FnProp {
92
92
  * The definition is a generic others dispatch on (S3 `UseMethod`, S4 `setGeneric`/`standardGeneric`, S7
93
93
  * `new_generic`). The call graph only shows this for an S3 generic with a bundled body, never for S4/S7.
94
94
  */
95
- Generic = 16384
95
+ Generic = 16384,
96
+ /** runs code concurrently: it reaches a call flowR knows does (`future::future`), or a native routine that forks or starts threads */
97
+ Concurrent = 32768,
98
+ /** computes a result and nothing else (flowR's `CallProp.Pure`): every call it makes does so, a native routine one only if {@link NativeFlag.Pure} */
99
+ Pure = 65536
96
100
  }
97
101
  /** the {@link FnProp} bit to its name (for decoding); integer keys iterate in ascending bit order */
98
102
  export declare const FnPropNames: Readonly<Record<FnProp, string>>;
@@ -140,6 +144,53 @@ export type SigSlot = number | [nameIdx: number, typeIdx: number];
140
144
  * class when that is not the one carrying the record (see {@link ClassProp.Foreign}); additive, so older readers stay working.
141
145
  */
142
146
  export type SigClass = [nameIdx: number, system: SigClassSystem, props: number, supers: number[], slots: SigSlot[]] | [nameIdx: number, system: SigClassSystem, props: number, supers: number[], slots: SigSlot[], pkgIdx: number];
147
+ /** the language a native routine is written in, one on-disk number (`0` = not known) */
148
+ export declare const enum NativeLang {
149
+ Unknown = 0,
150
+ C = 1,
151
+ Cxx = 2,
152
+ Fortran = 3,
153
+ Rust = 4
154
+ }
155
+ /** the {@link NativeLang} values in order, with their names (for decoding) */
156
+ export declare const NativeLangNames: readonly [undefined, "c", "c++", "fortran", "rust"];
157
+ /** the interface a routine is registered for (`R_registerRoutines`), one on-disk number (`0` = not registered) */
158
+ export declare const enum NativeIface {
159
+ None = 0,
160
+ Call = 1,
161
+ C = 2,
162
+ Fortran = 3,
163
+ External = 4
164
+ }
165
+ /** the {@link NativeIface} values in order, with the R function calling through them (for decoding) */
166
+ export declare const NativeIfaceNames: readonly [undefined, ".Call", ".C", ".Fortran", ".External"];
167
+ /** routine-level flags of a {@link SigNative}, above the 3 bits of {@link NativeLang} and the 3 bits of {@link NativeIface} */
168
+ export declare const enum NativeFlag {
169
+ /**
170
+ * Everything the routine calls was resolved: no call through a pointer, no callee outside the package
171
+ * that the analyzer's API table does not know, no translation unit that failed to parse. Only then does
172
+ * a fact missing from {@link SigNativeRoutineInfo.facts} mean the routine does not have it.
173
+ */
174
+ Closed = 64,
175
+ /** closed, no fact but `error:*`/`warning:*`, no parameter written or escaping, no global written */
176
+ Pure = 128,
177
+ /** registered, but the analyzer found no definition of the routine in the package's sources */
178
+ Undefined = 256
179
+ }
180
+ /**
181
+ * One argument of a native routine: `[nameIdx, props]` or `[nameIdx, props, typeIdx]` (the declared C type). `props` are the
182
+ * {@link ArgProps} R functions use: `Value` (read), `Written` (may be written, also when it reaches code the analyzer cannot see
183
+ * into), `Atomic` (has to be an atomic vector) and `Guarded` (the routine fails on some values, see {@link SigNativeRoutineInfo.guards}).
184
+ */
185
+ export type SigNativeParam = [nameIdx: number, props: ArgProps] | [nameIdx: number, props: ArgProps, typeIdx: number];
186
+ /**
187
+ * One native routine record `[nameIdx, flags, symbolIdx, fileIdx, line, arity, rNames, params, facts, contractIdx?, endLine?, column?]`. `flags`
188
+ * packs {@link NativeLang} (bits 0-2), {@link NativeIface} (bits 3-5) and {@link NativeFlag}; `symbolIdx`/`fileIdx`
189
+ * are -1 when absent, `arity` is the registered argument count (-1 = any or not registered); `rNames`, `facts`
190
+ * are dictionary indices (ascending), `params` in declaration order; `contractIdx` indexes {@link PkgBlob.contracts} (-1 for none);
191
+ * `endLine` and `column` complete the location of the definition (-1 when not known).
192
+ */
193
+ export type SigNative = [nameIdx: number, flags: number, symbolIdx: number, fileIdx: number, line: number, arity: number, rNames: number[], params: SigNativeParam[], facts: number[], contractIdx?: number, endLine?: number, column?: number];
143
194
  /** the kind of a package dependency (mirrors the DESCRIPTION fields) */
144
195
  export declare const enum DepType {
145
196
  Depends = 0,
@@ -187,9 +238,13 @@ export interface PkgBlob {
187
238
  * A function's contract is part of its pooled record, so two versions only share a slot if their contracts agree.
188
239
  */
189
240
  contractOf?: Record<number, number>;
241
+ /** pool of unique native routine records (shared across a package's versions), absent when the bundle stores none */
242
+ natives?: SigNative[];
243
+ /** version name to a delta-encoded ascending list of indices into {@link PkgBlob.natives} */
244
+ nativesByVersion?: Record<string, number[]>;
190
245
  }
191
- /** On-disk tuple form of a {@link PkgBlob}, field order, ending `contractOf`; trailing elements are additive. */
192
- export type PkgBlobTuple = [Sig[], number[][], SigFn[], Record<string, number[]>, string[], SigDep[][], Record<string, number>, Record<string, number>?, Record<string, number>?, SigClass[]?, Record<string, number[]>?, StatedGuards[]?, Record<number, number>?];
246
+ /** On-disk tuple form of a {@link PkgBlob}, field order, ending `nativesByVersion`; trailing elements are additive. */
247
+ export type PkgBlobTuple = [Sig[], number[][], SigFn[], Record<string, number[]>, string[], SigDep[][], Record<string, number>, Record<string, number>?, Record<string, number>?, SigClass[]?, Record<string, number[]>?, StatedGuards[]?, Record<number, number>?, SigNative[]?, Record<string, number[]>?];
193
248
  /**
194
249
  * Per-package metadata. The optional 4th element marks an **R-core / base package**: for these the version keys
195
250
  * are the R releases the package shipped with core R, so the set of versions is exactly its core-R history.
@@ -281,6 +336,53 @@ export interface SigVersionInfo {
281
336
  readonly date?: number;
282
337
  /** the classes this version declares and the relations it states between them */
283
338
  readonly classes?: readonly SigClassInfo[];
339
+ /** the native (C, C++, Fortran) routines the package's compiled code offers R, as tools read them off `src/` */
340
+ readonly natives?: readonly SigNativeRoutineInfo[];
341
+ }
342
+ /** One argument of a native routine, as the analyzer read it off the routine's source. */
343
+ export interface SigNativeParamInfo {
344
+ readonly name: string;
345
+ /** the declared C type (`SEXP`, `double *`); absent for Fortran or when not known */
346
+ readonly type?: string;
347
+ /** what the routine does with the argument, see {@link SigNativeParam} */
348
+ readonly props?: ArgProps;
349
+ }
350
+ /**
351
+ * One native routine of a package version: where it is, how R reaches it, and the facts the C/Fortran tools
352
+ * found for it. Facts are tool findings with a fixed vocabulary (`parallel:openmp`, `rng:r`, `io:file`,
353
+ * `process:exit`, `error:r`, `hw:simd`, `platform:_WIN32`, `global:write`, ...; see sigdb-build's `docs/native-routines.md`), each
354
+ * one positive evidence. An absent fact means "not found"; it means "does not happen" only when {@link closed}
355
+ * holds, and never for `error:*`/`warning:*` (R's allocators may always raise).
356
+ */
357
+ export interface SigNativeRoutineInfo {
358
+ /** the name R calls it by: the registered name, or, unregistered, the symbol the R code names */
359
+ readonly name: string;
360
+ /** the interface the routine is registered for, absent when it is not registered */
361
+ readonly iface?: typeof NativeIfaceNames[number];
362
+ /** the linker symbol of the definition (`qpgen2_` for Fortran), when it differs from {@link name} */
363
+ readonly symbol?: string;
364
+ readonly lang?: typeof NativeLangNames[number];
365
+ readonly file?: string;
366
+ readonly line?: number;
367
+ /** where the routine's name starts on {@link line}, 1-based */
368
+ readonly column?: number;
369
+ /** the last line of the definition */
370
+ readonly endLine?: number;
371
+ /** the registered argument count; absent when not registered or registered as "any" (-1) */
372
+ readonly arity?: number;
373
+ /** the R names binding the routine in the namespace (`useDynLib(pkg, .registration = TRUE, .fixes = "C_")` binds `C_foo`) */
374
+ readonly rNames?: readonly string[];
375
+ readonly params?: readonly SigNativeParamInfo[];
376
+ /** the facts the analyzers found, see the interface comment */
377
+ readonly facts?: readonly string[];
378
+ /** the analyzer resolved every callee, so an absent fact is absent (see {@link NativeFlag.Closed}) */
379
+ readonly closed?: boolean;
380
+ /** see {@link NativeFlag.Pure} */
381
+ readonly pure?: boolean;
382
+ /** what a call has to hand the routine for it not to fail, over the names of its {@link params} */
383
+ readonly guards?: StatedGuards;
384
+ /** registered but not defined in the package's sources (see {@link NativeFlag.Undefined}) */
385
+ readonly undefined?: boolean;
284
386
  }
285
387
  /**
286
388
  * One class of a package version: what its declaration states, plus which package defines it -- structure
@@ -323,4 +425,6 @@ export interface SigDbFeatures {
323
425
  classes?: boolean;
324
426
  /** per-function contracts (what a call has to fulfill to return normally, see {@link SigFunctionInfo.guards}) -- default true */
325
427
  contracts?: boolean;
428
+ /** per-version native routines and their tool-derived facts (see {@link SigVersionInfo.natives}) -- default true */
429
+ natives?: boolean;
326
430
  }
@@ -5,7 +5,7 @@
5
5
  * operates on these lives in `./sigdb` (which re-exports this module, so `./sigdb` stays the single entry point).
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.DepTypeNames = exports.SigClassSystemNames = exports.FnPropNames = exports.SigDbExt = exports.MaxDefaultLength = exports.DefaultCranBase = exports.SigDbSchema = exports.SigDbMagic = void 0;
8
+ exports.DepTypeNames = exports.NativeIfaceNames = exports.NativeLangNames = exports.SigClassSystemNames = exports.FnPropNames = exports.SigDbExt = exports.MaxDefaultLength = exports.DefaultCranBase = exports.SigDbSchema = exports.SigDbMagic = void 0;
9
9
  exports.SigDbMagic = 'flowr-sigdb';
10
10
  exports.SigDbSchema = 5;
11
11
  /** default CRAN source-package base URL, used to build a version's tarball link */
@@ -30,10 +30,16 @@ exports.FnPropNames = {
30
30
  [2048 /* FnProp.S4Owner */]: 's4-owner',
31
31
  [4096 /* FnProp.S4Method */]: 's4-method',
32
32
  [8192 /* FnProp.Value */]: 'value',
33
- [16384 /* FnProp.Generic */]: 'generic'
33
+ [16384 /* FnProp.Generic */]: 'generic',
34
+ [32768 /* FnProp.Concurrent */]: 'concurrent',
35
+ [65536 /* FnProp.Pure */]: 'pure'
34
36
  };
35
37
  /** the {@link SigClassSystem} values in order, with their names (for decoding) */
36
38
  exports.SigClassSystemNames = ['s4', 'rc', 's7', 'r6'];
39
+ /** the {@link NativeLang} values in order, with their names (for decoding) */
40
+ exports.NativeLangNames = [undefined, 'c', 'c++', 'fortran', 'rust'];
41
+ /** the {@link NativeIface} values in order, with the R function calling through them (for decoding) */
42
+ exports.NativeIfaceNames = [undefined, '.Call', '.C', '.Fortran', '.External'];
37
43
  /** the {@link DepType} values in order, with their names (for decoding) */
38
44
  exports.DepTypeNames = ['depends', 'imports', 'linkingTo', 'suggests', 'enhances'];
39
45
  //# sourceMappingURL=schema.js.map
@@ -127,7 +127,7 @@ async function downloadTo(url, dest, name, progress, expected) {
127
127
  throw new Error(`sha256 mismatch (expected ${expected.sha256.slice(0, 12)}..., got ${actual.slice(0, 12)}...); the download is corrupt or sigdb.remote.json is outdated`);
128
128
  }
129
129
  }
130
- fs_1.default.renameSync(part, dest);
130
+ (0, decompress_1.moveIntoPlace)(part, dest);
131
131
  return received;
132
132
  }
133
133
  finally {
@@ -34,7 +34,13 @@ export interface VersionRelease {
34
34
  * differ in writing but not in order (`1.2` and `1.2.0`) compare equal, so their dates settle them.
35
35
  */
36
36
  export declare function releasesOf(blob: Readonly<PkgBlob> | undefined): VersionRelease[];
37
- /** the version with the newest release date (falling back to `latest`, then the highest by R-version order) */
37
+ /**
38
+ * The version a package's latest stands for: the `latest` its metadata records, which the builder chose
39
+ * knowing which repository still offers what; else the version with the newest release date; else the
40
+ * highest by R-version order. The dates come only second because they do not say which release is the
41
+ * current one: a GitHub build of the next version is dated after the CRAN release it builds on, and a
42
+ * version listed without a date would lose to every older one.
43
+ */
38
44
  export declare function newestVersion(blob: Readonly<PkgBlob>, latest: string): string | undefined;
39
45
  /** pick the version tuple: requested, else the package's latest, else the highest present by R-version order */
40
46
  export declare function resolveVersion(blob: Readonly<PkgBlob>, latest: string, version?: string): string | undefined;
@@ -87,8 +87,17 @@ function releasesOf(blob) {
87
87
  .map(([ver, day]) => ({ version: r_version_1.RVersion.parseOrZero(ver), date: new Date(dayToMillis(day)) }))
88
88
  .sort((a, b) => r_version_1.RVersion.compare(a.version.str, b.version.str) || (a.date.getTime() - b.date.getTime()));
89
89
  }
90
- /** the version with the newest release date (falling back to `latest`, then the highest by R-version order) */
90
+ /**
91
+ * The version a package's latest stands for: the `latest` its metadata records, which the builder chose
92
+ * knowing which repository still offers what; else the version with the newest release date; else the
93
+ * highest by R-version order. The dates come only second because they do not say which release is the
94
+ * current one: a GitHub build of the next version is dated after the CRAN release it builds on, and a
95
+ * version listed without a date would lose to every older one.
96
+ */
91
97
  function newestVersion(blob, latest) {
98
+ if (blob.versions[latest]) {
99
+ return latest;
100
+ }
92
101
  let best;
93
102
  let bestDay = -Infinity;
94
103
  for (const [ver, day] of Object.entries(blob.dates)) {
@@ -97,14 +106,8 @@ function newestVersion(blob, latest) {
97
106
  best = ver;
98
107
  }
99
108
  }
100
- if (best !== undefined) {
101
- return best;
102
- }
103
- if (blob.versions[latest]) {
104
- return latest;
105
- }
106
- // no dates and no recorded latest: pick the highest by R's numeric-version order (not string order)
107
- return r_version_1.RVersion.highest(Object.keys(blob.versions));
109
+ // no recorded latest and no dates: the highest by R's numeric-version order (not string order)
110
+ return best ?? r_version_1.RVersion.highest(Object.keys(blob.versions));
108
111
  }
109
112
  /** pick the version tuple: requested, else the package's latest, else the highest present by R-version order */
110
113
  function resolveVersion(blob, latest, version) {
@@ -1,12 +1,15 @@
1
1
  import { type PropWord } from '../../dataflow/environments/built-in-props';
2
- /** The query language of the sigdb page: `name(arg, [role], name[role], *)[prop]`. */
3
- /** the kinds of words a query states: roles of an argument in parentheses, properties of a call outside */
2
+ /** The query language of the sigdb page: `name(arg, [role], name[role], *)[prop]{trait}`. */
3
+ /** the kinds of words a query states: roles of an argument in parentheses, properties of a call outside, traits of a name in braces */
4
4
  export declare enum WordKind {
5
5
  Role = "role",
6
- Prop = "prop"
6
+ Prop = "prop",
7
+ Trait = "trait"
7
8
  }
8
- /** the words of each kind, as the built-in configuration words them */
9
+ /** the words of each kind, as the built-in configuration words them, the traits as the page defines them */
9
10
  export declare const Vocabulary: Readonly<Record<WordKind, readonly PropWord[]>>;
11
+ /** Sets the words `{trait}` takes, which only the page knows how to tell of a name. */
12
+ export declare function defineTraits(words: readonly PropWord[]): void;
10
13
  /** the short form of a word, the word itself where it has none */
11
14
  export declare function shortOf(word: string): string;
12
15
  /** what a role or property word means, `undefined` for any other word */
@@ -30,6 +33,8 @@ export interface Spec {
30
33
  readonly nameRegex?: RegExp;
31
34
  readonly args?: readonly ArgPattern[];
32
35
  readonly props: readonly string[];
36
+ /** the `{traits}` asked for, as the words {@link defineTraits} set */
37
+ readonly traits: readonly string[];
33
38
  }
34
39
  /** The short form of a word, so `forced` and `F` are the same. */
35
40
  export declare const norm: (word: string) => string;