@eagleoutice/flowr 2.15.2 → 2.15.4

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 (42) hide show
  1. package/README.md +20 -20
  2. package/dataflow/environments/environment.d.ts +28 -13
  3. package/dataflow/environments/environment.js +62 -23
  4. package/dataflow/environments/frame-memory.d.ts +84 -0
  5. package/dataflow/environments/frame-memory.js +241 -0
  6. package/dataflow/environments/query-fn-props.d.ts +39 -2
  7. package/dataflow/environments/query-fn-props.js +98 -12
  8. package/dataflow/environments/resolve-by-name.js +28 -9
  9. package/dataflow/graph/graph.d.ts +18 -4
  10. package/dataflow/graph/graph.js +101 -64
  11. package/dataflow/graph/vertex.js +1 -1
  12. package/dataflow/internal/linker.js +9 -5
  13. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +1 -1
  14. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +2 -1
  15. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -2
  16. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +2 -2
  17. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +2 -2
  18. package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +1 -1
  19. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +19 -5
  20. package/dataflow/internal/process/functions/call/common.js +6 -2
  21. package/dataflow/internal/process/functions/call/known-call-handling.js +1 -1
  22. package/dataflow/internal/process/functions/call/quoted.js +1 -1
  23. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +1 -1
  24. package/dataflow/internal/process/functions/process-argument.js +1 -1
  25. package/dataflow/internal/process/process-symbol.js +1 -1
  26. package/index.d.ts +2 -0
  27. package/index.js +4 -1
  28. package/linter/linter-rules.d.ts +9 -9
  29. package/package.json +1 -1
  30. package/project/context/flowr-analyzer-environment-context.d.ts +6 -0
  31. package/project/context/flowr-analyzer-environment-context.js +4 -2
  32. package/project/flowr-analyzer.d.ts +13 -0
  33. package/project/flowr-analyzer.js +5 -0
  34. package/project/sigdb/reader.js +44 -13
  35. package/project/sigdb/signature-db.d.ts +3 -0
  36. package/project/sigdb/signature-db.js +5 -4
  37. package/queries/catalog/input-sources-query/simple-input-classifier.js +4 -5
  38. package/queries/catalog/signature-query/signature-query-format.d.ts +1 -2
  39. package/slicing/static/fingerprint.js +7 -2
  40. package/util/collections/bimap.d.ts +2 -1
  41. package/util/collections/bimap.js +4 -4
  42. package/util/version.js +2 -2
@@ -38,6 +38,11 @@ export interface ReadOnlyFlowrAnalyzerEnvironmentContext {
38
38
  * Knows only the built-ins, no attached package, so prefer {@link cleanEnvOf} wherever an environment is at hand.
39
39
  */
40
40
  makeCleanEnv(): REnvironmentInformation;
41
+ /**
42
+ * {@link makeCleanEnv} as a stable thunk. Hand this to something that may or may not need a clean
43
+ * environment (see {@link DataflowGraph#addVertex}), so offering one costs nothing when it goes unused.
44
+ */
45
+ readonly cleanEnv: () => REnvironmentInformation;
41
46
  /**
42
47
  * Get the fingerprint of the clean environment with the configured built-in environment as base.
43
48
  */
@@ -77,6 +82,7 @@ export declare class FlowrAnalyzerEnvironmentContext implements ReadOnlyFlowrAna
77
82
  builtInDefinitionsOf(name: Identifier): readonly IdentifierDefinition[];
78
83
  knowsPackage(pkg: string): boolean;
79
84
  builtInFunctionOf(name: Identifier): BuiltInIdentifierDefinition | undefined;
85
+ readonly cleanEnv: () => REnvironmentInformation;
80
86
  makeCleanEnv(): REnvironmentInformation;
81
87
  getCleanEnvFingerprint(): Fingerprint;
82
88
  makeCleanEnvWithEmptyBuiltIns(): REnvironmentInformation;
@@ -23,9 +23,9 @@ class FlowrAnalyzerEnvironmentContext {
23
23
  const builtInsConfig = ctx.config.semantics.environment.overwriteBuiltIns;
24
24
  const builtIns = (0, built_in_config_1.getBuiltInDefinitions)(builtInsConfig.definitions, builtInsConfig.loadDefaults);
25
25
  this.builtInEnv = new environment_1.Environment(undefined, true);
26
- this.builtInEnv.memory = builtIns.builtInMemory;
26
+ this.builtInEnv.adoptMap(builtIns.builtInMemory);
27
27
  this.emptyBuiltInEnv = new environment_1.Environment(undefined, true);
28
- this.emptyBuiltInEnv.memory = builtIns.emptyBuiltInMemory;
28
+ this.emptyBuiltInEnv.adoptMap(builtIns.emptyBuiltInMemory);
29
29
  this.stated = builtIns.packageMemory;
30
30
  /* `pkg::fn` resolves whether or not the package is attached, so the built-in env answers for it */
31
31
  this.builtInEnv.namespaces = builtIns.packageMemory;
@@ -83,6 +83,8 @@ class FlowrAnalyzerEnvironmentContext {
83
83
  return this.builtInDefinitionsOf(name).find((d) => d.type === identifier_1.ReferenceType.BuiltInFunction && typeof d.processor === 'function'
84
84
  && (namespace === undefined || (d.name !== undefined && identifier_1.Identifier.getNamespace(d.name) === namespace)));
85
85
  }
86
+ /* one thunk per context rather than one per call, as the callers offering it mostly do not need it */
87
+ cleanEnv = () => this.makeCleanEnv();
86
88
  makeCleanEnv() {
87
89
  return {
88
90
  current: new environment_1.Environment(this.builtInEnv).asGlobal(),
@@ -19,6 +19,8 @@ import type { Tree } from 'web-tree-sitter';
19
19
  import type { CallGraph } from '../dataflow/graph/call-graph';
20
20
  import type { InvalidationEvent } from './cache/flowr-cache';
21
21
  import type { GasOverrides } from '../gas';
22
+ import type { FnInfo } from '../dataflow/environments/query-fn-props';
23
+ import { Identifier } from '../dataflow/environments/identifier';
22
24
  /** Options for a single analyzer operation, bounding what it may cost. */
23
25
  export interface FlowrAnalysisOptions {
24
26
  /**
@@ -79,6 +81,16 @@ export interface ReadonlyFlowrAnalysisProvider<Parser extends KnownParser = Know
79
81
  * This is the preferred method for users that want to inspect the context.
80
82
  */
81
83
  inspectContext(): ReadOnlyFlowrAnalyzerContext;
84
+ /**
85
+ * What flowR knows about the function `name`, whether that is one of its own built-ins, a package function
86
+ * the signature database carries, or both; see {@link fnInfo}.
87
+ *
88
+ * A string is read the way R source spells a name, so `'dplyr::lead'` and `'dplyr:::internal'` name the
89
+ * package function rather than a symbol with a `::` in it (pass an {@link Identifier} for that one).
90
+ * @param name - The function to ask about, `'dplyr::lead'` or `Identifier.make('lead', 'dplyr')` to pin the package down.
91
+ * @param version - The package version to answer for, the one the analysis assumes if omitted.
92
+ */
93
+ functionInfo(name: Identifier | string, version?: string): FnInfo | undefined;
82
94
  /**
83
95
  * Get the parse output for the request.
84
96
  *
@@ -195,6 +207,7 @@ export declare class FlowrAnalyzer<Parser extends KnownParser = KnownParser> imp
195
207
  context(): FlowrAnalyzerContext;
196
208
  parserInformation(): KnownParserInformation;
197
209
  inspectContext(): ReadOnlyFlowrAnalyzerContext;
210
+ functionInfo(name: Identifier | string, version?: string): FnInfo | undefined;
198
211
  reset(): void;
199
212
  receive(event: InvalidationEvent): void;
200
213
  updateConfig(update: DeepPartial<FlowrConfig>): void;
@@ -8,6 +8,8 @@ const retriever_1 = require("../r-bridge/retriever");
8
8
  const files_1 = require("../util/files");
9
9
  const tree_sitter_normalize_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize");
10
10
  const tree_sitter_executor_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-executor");
11
+ const query_fn_props_1 = require("../dataflow/environments/query-fn-props");
12
+ const identifier_1 = require("../dataflow/environments/identifier");
11
13
  /**
12
14
  * Central class for conducting analyses with FlowR.
13
15
  * Use the {@link FlowrAnalyzerBuilder} to create a new instance.
@@ -50,6 +52,9 @@ class FlowrAnalyzer {
50
52
  inspectContext() {
51
53
  return this.ctx.inspect();
52
54
  }
55
+ functionInfo(name, version) {
56
+ return (0, query_fn_props_1.fnInfo)(typeof name === 'string' ? identifier_1.Identifier.parse(name) : name, this.ctx.inspect(), version);
57
+ }
53
58
  reset() {
54
59
  this.ctx.reset();
55
60
  this.cache.reset();
@@ -313,20 +313,48 @@ const NoFile = -1;
313
313
  * anything: how many shards a query set opens is not something the caller picks, and each would claim the
314
314
  * budget again. A count would not bound anything either -- one package's blob outweighs a hundred small ones.
315
315
  */
316
- const BlobCacheBudget = 8 * 1024 * 1024;
317
- /** what every open bundle holds decoded, oldest read first, so the budget is spent across all of them */
316
+ const BlobCacheBudget = 64 * 1024 * 1024;
317
+ /** what every open bundle holds decoded, so the budget is spent across all of them */
318
318
  const cachedBlobs = [];
319
+ /** where {@link keepBlob} resumes looking for something to drop */
320
+ let hand = 0;
319
321
  let cachedBlobBytes = 0;
320
- /** keep `blob` decoded for `db`, dropping what any bundle read longest ago until all of them fit the budget */
322
+ /**
323
+ * Keep `blob` decoded for `db`, dropping blobs until all of them fit the budget (age gated).
324
+ */
321
325
  function keepBlob(db, blobIdx, bytes) {
322
326
  while (cachedBlobBytes + bytes > BlobCacheBudget && cachedBlobs.length > 0) {
323
- const dropped = cachedBlobs.shift();
324
- /* the bytes are off the list either way: a closed bundle already let its blobs go */
325
- cachedBlobBytes -= dropped.bytes;
326
- dropped.db.dropBlob(dropped.blobIdx);
327
+ if (hand >= cachedBlobs.length) {
328
+ hand = 0;
329
+ }
330
+ const candidate = cachedBlobs[hand];
331
+ if (candidate.used) {
332
+ candidate.used = false;
333
+ hand++;
334
+ continue;
335
+ }
336
+ cachedBlobs.splice(hand, 1);
337
+ cachedBlobBytes -= candidate.bytes;
338
+ candidate.db.dropBlob(candidate.blobIdx);
327
339
  }
328
- cachedBlobs.push({ db, blobIdx, bytes });
340
+ const entry = { db, blobIdx, bytes, used: true };
341
+ cachedBlobs.push(entry);
329
342
  cachedBlobBytes += bytes;
343
+ return entry;
344
+ }
345
+ /** Mark `entry` read, so the hand passes over it once before dropping it. */
346
+ function touchBlob(entry) {
347
+ entry.used = true;
348
+ }
349
+ /** give back what `db` held, so a closed bundle stops spending the budget of the open ones */
350
+ function releaseBlobs(db) {
351
+ for (let i = cachedBlobs.length - 1; i >= 0; i--) {
352
+ if (cachedBlobs[i].db === db) {
353
+ cachedBlobBytes -= cachedBlobs[i].bytes;
354
+ cachedBlobs.splice(i, 1);
355
+ }
356
+ }
357
+ hand = 0;
330
358
  }
331
359
  /**
332
360
  * Fast, partial reader for a single bundle. `open()`/`openSync()` load the string dictionary + `.idx` once, then every
@@ -361,7 +389,7 @@ class SigDatabase {
361
389
  static fromMemory(db) {
362
390
  const index = { byteCount: 0, dict: [0, 0], blobs: [], pkgs: db.pkgs, meta: db.meta };
363
391
  const source = new SigDatabase(NoFile, db.strings, index, db.content, db.cranBase ?? schema_1.DefaultCranBase);
364
- db.blobs.forEach((blob, i) => source.blobCache.set(i, blob));
392
+ db.blobs.forEach((blob, i) => source.blobCache.set(i, { blob }));
365
393
  return source;
366
394
  }
367
395
  /**
@@ -421,7 +449,10 @@ class SigDatabase {
421
449
  }
422
450
  const cached = this.blobCache.get(blobIdx);
423
451
  if (cached !== undefined) {
424
- return cached;
452
+ if (cached.entry !== undefined) {
453
+ touchBlob(cached.entry);
454
+ }
455
+ return cached.blob;
425
456
  }
426
457
  if (this.fd === NoFile) {
427
458
  return undefined; // an in-memory database starts out with every blob cached
@@ -431,8 +462,7 @@ class SigDatabase {
431
462
  if (!this.nameIdsOfBlob.has(blobIdx)) {
432
463
  this.nameIdsOfBlob.set(blobIdx, Int32Array.from(new Set(blob.fns.map(fn => fn[0]))).sort());
433
464
  }
434
- keepBlob(this, blobIdx, range[1]);
435
- this.blobCache.set(blobIdx, blob);
465
+ this.blobCache.set(blobIdx, { blob, entry: keepBlob(this, blobIdx, range[1]) });
436
466
  return blob;
437
467
  }
438
468
  /** the dictionary id of `name`, or `-1` if the dictionary does not hold it, so no package can offer it */
@@ -498,7 +528,7 @@ class SigDatabase {
498
528
  allBlobs() {
499
529
  // an in-memory database has no byte ranges to re-read: its blobs are the cached ones, in blob-index order
500
530
  return this.fd === NoFile
501
- ? [...this.blobCache.entries()].sort(([a], [b]) => a - b).map(([, blob]) => blob)
531
+ ? [...this.blobCache.entries()].sort(([a], [b]) => a - b).map(([, { blob }]) => blob)
502
532
  : this.index.blobs.map(range => this.readBlobAt(range));
503
533
  }
504
534
  /** recompute this bundle's self-contained content hash from its re-read data (matches {@link writeSignatureDb}) */
@@ -677,6 +707,7 @@ class SigDatabase {
677
707
  close() {
678
708
  if (!this.closed) {
679
709
  this.closed = true;
710
+ releaseBlobs(this);
680
711
  this.blobCache.clear();
681
712
  this.versionFnCache.clear();
682
713
  this.classIndex = undefined;
@@ -44,6 +44,9 @@ export interface SignatureDb {
44
44
  * A name the package answers only as part of an S4 group falls back to the group: `Matrix::sin` is served by
45
45
  * `Matrix`'s `Math` entry when there is no `sin` of its own, because that is what an `sin(x)` call dispatches
46
46
  * to. The result then carries the group's name, not the one that was asked for.
47
+ *
48
+ * The {@link Identifier} decides how far the lookup reaches: `pkg::fn` answers only with what the package
49
+ * exports, `pkg:::fn` reaches its internals as well, exactly as R has it.
47
50
  * @param id - The qualified identifier of the function.
48
51
  * @param version - The version to answer for, {@link versionOf} of its package if omitted.
49
52
  */
@@ -34,18 +34,19 @@ function signatureDbOf(deps) {
34
34
  return any;
35
35
  };
36
36
  const functionOf = (id, version) => {
37
- const pkg = identifier_1.Identifier.getNamespace(id);
37
+ const [name, pkg, internal] = identifier_1.Identifier.toArray(id);
38
38
  if (pkg === undefined) {
39
39
  return undefined; // without a package there is nothing to look the function up in
40
40
  }
41
- const name = identifier_1.Identifier.getName(id);
42
- const found = answerFor(pkg, version, (src, v) => src.functionByName(pkg, name, v));
41
+ /* `::` reaches what the package exports, only `:::` reaches the rest */
42
+ const reaches = (fn) => fn !== undefined && (fn.exported || internal === true) ? fn : undefined;
43
+ const found = reaches(answerFor(pkg, version, (src, v) => src.functionByName(pkg, name, v)));
43
44
  if (found !== undefined) {
44
45
  return found;
45
46
  }
46
47
  /* `setMethod('Math', 'cls', ...)` answers every member of the group at once, so the group is the entry */
47
48
  const group = (0, group_generics_1.groupGenericOf)(name);
48
- return group === undefined ? undefined : answerFor(pkg, version, (src, v) => src.functionByName(pkg, group, v));
49
+ return group === undefined ? undefined : reaches(answerFor(pkg, version, (src, v) => src.functionByName(pkg, group, v)));
49
50
  };
50
51
  return {
51
52
  available: () => deps.signatureSources().length > 0,
@@ -593,11 +593,10 @@ class InputClassifier {
593
593
  // caller argument), follow it into the caller; only if that leads nowhere is it an opaque Scope origin
594
594
  const onCall = this.definedByOnCallTargets(v.id);
595
595
  if (onCall.length > 0) {
596
- const callers = onCall.map(t => this.classifyInFullGraph(t))
597
- .filter(assert_1.isNotUndefined)
598
- .filter(c => !c.types.includes(input_types_1.InputType.Unknown));
599
- if (callers.length > 0) {
600
- callers.forEach(c => acc.merge(c));
596
+ const callers = onCall.map(t => this.classifyInFullGraph(t)).filter(assert_1.isNotUndefined);
597
+ const known = callers.filter(c => !c.types.includes(input_types_1.InputType.Unknown));
598
+ known.forEach(c => acc.merge(c));
599
+ if (known.length > 0 && known.length === callers.length) {
601
600
  return;
602
601
  }
603
602
  acc.types.push(input_types_1.InputType.Scope);
@@ -98,8 +98,7 @@ export interface SignatureFunctionView {
98
98
  /**
99
99
  * whether the whole view comes from flowR's built-in definition because the database has no entry: the
100
100
  * primitives and operators (`+`, `[`, `if`) that appear in no package's sources, and anything a flowR
101
- * configuration adds. Everything the database would contribute (defaults, callees, location) is then empty,
102
- * and since flowR records no defaults, every {@link SignatureParameterView.required} reads `false`.
101
+ * configuration adds.
103
102
  */
104
103
  readonly flowrOnly?: boolean;
105
104
  }
@@ -32,7 +32,12 @@ function definitionHash(definition) {
32
32
  return hash;
33
33
  }
34
34
  function memoryHash(memory) {
35
- let hash = memoryHashes.get(memory);
35
+ let byVersion = memoryHashes.get(memory.frame);
36
+ if (byVersion === undefined) {
37
+ byVersion = new Map();
38
+ memoryHashes.set(memory.frame, byVersion);
39
+ }
40
+ let hash = byVersion.get(memory.version);
36
41
  if (hash === undefined) {
37
42
  const entries = [];
38
43
  for (const [name, definitions] of memory) {
@@ -40,7 +45,7 @@ function memoryHash(memory) {
40
45
  }
41
46
  entries.sort();
42
47
  hash = (0, object_hash_1.default)(entries, HashOptions);
43
- memoryHashes.set(memory, hash);
48
+ byVersion.set(memory.version, hash);
44
49
  }
45
50
  return hash;
46
51
  }
@@ -16,7 +16,6 @@ export type BiMapReverse = 'lazy' | 'eager';
16
16
  */
17
17
  export declare class BiMap<K, V extends object> implements Map<K, V> {
18
18
  readonly [Symbol.toStringTag]: string;
19
- size: number;
20
19
  private readonly k2v;
21
20
  private v2k;
22
21
  private readonly eager;
@@ -26,6 +25,8 @@ export declare class BiMap<K, V extends object> implements Map<K, V> {
26
25
  */
27
26
  constructor(base?: Iterable<[K, V]>, reverse?: BiMapReverse);
28
27
  [Symbol.iterator](): MapIterator<[K, V]>;
28
+ /** Read off the forward direction, so filling the map costs no bookkeeping per entry. */
29
+ get size(): number;
29
30
  clear(): void;
30
31
  delete(key: K): boolean;
31
32
  entries(): MapIterator<[K, V]>;
@@ -8,7 +8,6 @@ exports.BiMap = void 0;
8
8
  */
9
9
  class BiMap {
10
10
  [Symbol.toStringTag] = 'BiMap';
11
- size = 0;
12
11
  k2v = new Map();
13
12
  /* see {@link BiMapReverse}: `undefined` until the first reverse lookup unless this map was asked to be eager */
14
13
  v2k;
@@ -31,8 +30,11 @@ class BiMap {
31
30
  [Symbol.iterator]() {
32
31
  return this.k2v[Symbol.iterator]();
33
32
  }
33
+ /** Read off the forward direction, so filling the map costs no bookkeeping per entry. */
34
+ get size() {
35
+ return this.k2v.size;
36
+ }
34
37
  clear() {
35
- this.size = 0;
36
38
  this.k2v.clear();
37
39
  this.v2k = this.eager ? new WeakMap() : undefined;
38
40
  }
@@ -44,7 +46,6 @@ class BiMap {
44
46
  this.k2v.delete(key);
45
47
  /* another key may still hold this value, so dropping just its entry would lose a live mapping */
46
48
  this.staleReverse();
47
- this.size = this.k2v.size;
48
49
  return true;
49
50
  }
50
51
  entries() {
@@ -86,7 +87,6 @@ class BiMap {
86
87
  this.v2k.set(value, key);
87
88
  }
88
89
  }
89
- this.size = this.k2v.size;
90
90
  return this;
91
91
  }
92
92
  /** the reverse direction can no longer be maintained in place, so re-derive it (at once if eager) */
package/util/version.js CHANGED
@@ -42,9 +42,9 @@ const assert_1 = require("./assert");
42
42
  const sigdb_download_1 = require("../project/sigdb/sigdb-download");
43
43
  const doc_files_1 = require("../documentation/doc-util/doc-files");
44
44
  // this is automatically replaced with the current version by release-it
45
- const version = '2.15.2';
45
+ const version = '2.15.4';
46
46
  // this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
47
- const versionDate = '2026-08-25T22:44:52Z';
47
+ const versionDate = '2026-08-26T17:54:03Z';
48
48
  /**
49
49
  * Retrieves the current flowR version as a new {@link SemVer} object.
50
50
  */