@eagleoutice/flowr 2.17.11 → 2.17.13

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 (48) hide show
  1. package/abstract-interpretation/branch-paths-interpreter.js +12 -1
  2. package/benchmark/slicer.js +3 -1
  3. package/config.d.ts +1 -0
  4. package/config.js +4 -2
  5. package/dataflow/environments/default-builtin-config/base-functions.d.ts +1 -1
  6. package/dataflow/environments/default-builtin-config/base-functions.js +2 -0
  7. package/dataflow/environments/default-builtin-config/database-access.d.ts +1 -1
  8. package/dataflow/environments/default-builtin-config/database-access.js +3 -0
  9. package/dataflow/environments/default-builtin-config/guards.js +3 -1
  10. package/dataflow/environments/default-builtin-config/index.d.ts +1 -1
  11. package/dataflow/extractor.js +66 -4
  12. package/dataflow/fn/guards/built-in-guards.js +4 -4
  13. package/dataflow/fn/guards/call-contracts.js +8 -8
  14. package/dataflow/fn/guards/condition-grouping.js +4 -3
  15. package/dataflow/fn/guards/function-guards.js +103 -97
  16. package/dataflow/fn/guards/group-method-guards.js +22 -12
  17. package/dataflow/fn/guards/guard-claims.js +152 -128
  18. package/dataflow/fn/guards/guard-knowledge.js +19 -18
  19. package/dataflow/fn/guards/guard-term-syntax.js +13 -12
  20. package/dataflow/fn/guards/guard-term.d.ts +71 -0
  21. package/dataflow/fn/guards/guard-term.js +183 -75
  22. package/dataflow/graph/graph.d.ts +9 -0
  23. package/dataflow/graph/graph.js +19 -0
  24. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +6 -2
  25. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +9 -2
  26. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +1 -1
  27. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +135 -10
  28. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +1 -1
  29. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +19 -9
  30. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +35 -3
  31. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +2 -1
  32. package/dataflow/internal/program-order.d.ts +9 -0
  33. package/dataflow/internal/program-order.js +38 -2
  34. package/documentation/wiki-interface.js +1 -0
  35. package/linter/linter-rules.d.ts +1 -0
  36. package/linter/rules/problematic-inputs.d.ts +3 -0
  37. package/linter/rules/problematic-inputs.js +12 -9
  38. package/linter/rules/undefined-symbol.js +3 -2
  39. package/package.json +5 -2
  40. package/project/sigdb/export-keys.d.ts +9 -0
  41. package/project/sigdb/export-keys.js +121 -0
  42. package/project/sigdb/reader.d.ts +7 -9
  43. package/project/sigdb/reader.js +24 -42
  44. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +0 -4
  45. package/queries/catalog/input-sources-query/simple-input-classifier.js +136 -38
  46. package/util/flowr-version.d.ts +1 -1
  47. package/util/flowr-version.js +2 -2
  48. package/util/mermaid/mermaid.js +1 -1
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.exportKeysFor = exportKeysFor;
7
+ /**
8
+ * The reverse index of a bundle, `dictionary id of a name -> the packages exporting it`, kept as one sorted run of numbers
9
+ * (`id * {@link OrdinalStride} + package ordinal`) so a lookup is a binary search. Deriving it decodes every package, so
10
+ * {@link ExportKeys.persist|persisting} it next to the bundle lets later processes answer from a few ranged reads.
11
+ */
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const decompress_1 = require("./decompress");
14
+ /** the ordinals of a bundle's packages stay below this, so a key keeps the name id and the ordinal apart exactly */
15
+ const OrdinalStride = 2 ** 21;
16
+ const KeyBytes = Float64Array.BYTES_PER_ELEMENT;
17
+ /** the file extension of the persisted index, appended to the plain bundle */
18
+ const ExportKeysExt = '.exports';
19
+ /** the index over `keys`, which {@link buildKeys} sorted */
20
+ function inMemory(keys) {
21
+ return { ordinalsOf: id => collect(keys.length, at => keys[at], id) };
22
+ }
23
+ /** the sorted keys of the `[name id, package ordinal]` pairs, each pair once */
24
+ function buildKeys(pairs) {
25
+ const keys = Float64Array.from(pairs, ([id, ordinal]) => id * OrdinalStride + ordinal).sort();
26
+ let unique = 0;
27
+ for (let i = 0; i < keys.length; i++) {
28
+ if (i === 0 || keys[i] !== keys[i - 1]) {
29
+ keys[unique++] = keys[i];
30
+ }
31
+ }
32
+ return keys.slice(0, unique);
33
+ }
34
+ /** the ordinals of the keys of `id`, off a sorted run read through `keyAt` */
35
+ function collect(count, keyAt, id) {
36
+ let lo = 0, hi = count;
37
+ while (lo < hi) {
38
+ const mid = (lo + hi) >> 1;
39
+ if (keyAt(mid) < id * OrdinalStride) {
40
+ lo = mid + 1;
41
+ }
42
+ else {
43
+ hi = mid;
44
+ }
45
+ }
46
+ const ordinals = [];
47
+ for (let key = lo < count ? keyAt(lo) : Infinity; key < (id + 1) * OrdinalStride; key = ++lo < count ? keyAt(lo) : Infinity) {
48
+ ordinals.push(key % OrdinalStride);
49
+ }
50
+ return ordinals;
51
+ }
52
+ const StampKeys = 2;
53
+ /** the persisted index at `file` when it exists and was derived for `stamp`, answering by ranged reads */
54
+ function readPersisted(file, stamp) {
55
+ let size;
56
+ try {
57
+ size = fs_1.default.statSync(file).size;
58
+ }
59
+ catch {
60
+ return undefined;
61
+ }
62
+ const head = Buffer.allocUnsafe(KeyBytes);
63
+ const at = (fd, i) => (fs_1.default.readSync(fd, head, 0, KeyBytes, i * KeyBytes), head.readDoubleLE(0));
64
+ const count = size / KeyBytes - StampKeys;
65
+ const fd = fs_1.default.openSync(file, 'r');
66
+ try {
67
+ if (!Number.isInteger(count) || count < 0 || stamp.some((s, i) => at(fd, i) !== s)) {
68
+ return undefined;
69
+ }
70
+ }
71
+ finally {
72
+ fs_1.default.closeSync(fd);
73
+ }
74
+ return {
75
+ ordinalsOf: id => {
76
+ const reading = fs_1.default.openSync(file, 'r');
77
+ try {
78
+ return collect(count, i => at(reading, i + StampKeys), id);
79
+ }
80
+ finally {
81
+ fs_1.default.closeSync(reading);
82
+ }
83
+ }
84
+ };
85
+ }
86
+ /** write the index next to the bundle, not failing the query when the directory does not let us */
87
+ function persist(file, stamp, keys) {
88
+ const tmp = (0, decompress_1.uniqueTempPath)(file, 'tmp');
89
+ try {
90
+ const out = new Float64Array(keys.length + StampKeys);
91
+ out.set(stamp);
92
+ out.set(keys, StampKeys);
93
+ fs_1.default.writeFileSync(tmp, new Uint8Array(out.buffer));
94
+ (0, decompress_1.moveIntoPlace)(tmp, file);
95
+ }
96
+ catch {
97
+ /* read-only location: the index then lives for this process only */
98
+ }
99
+ finally {
100
+ fs_1.default.rmSync(tmp, { force: true });
101
+ }
102
+ }
103
+ /**
104
+ * The export index of a bundle of `packages` packages: the one persisted for `bundleFile` when there is one, otherwise
105
+ * derived from `pairs` (computed on demand) and persisted for the next process. Without a file, kept in memory only.
106
+ */
107
+ function exportKeysFor(bundleFile, packages, pairs) {
108
+ const file = bundleFile === undefined ? undefined : bundleFile + ExportKeysExt;
109
+ const stamp = bundleFile === undefined ? undefined : [packages, fs_1.default.statSync(bundleFile).mtimeMs];
110
+ const persisted = file === undefined || stamp === undefined ? undefined : readPersisted(file, stamp);
111
+ if (persisted !== undefined) {
112
+ return persisted;
113
+ }
114
+ const keys = buildKeys(pairs());
115
+ if (file === undefined || stamp === undefined) {
116
+ return inMemory(keys);
117
+ }
118
+ persist(file, stamp, keys);
119
+ return readPersisted(file, stamp) ?? inMemory(keys);
120
+ }
121
+ //# sourceMappingURL=export-keys.js.map
@@ -200,6 +200,10 @@ export declare class SigDatabase extends HistorySource implements PackageSignatu
200
200
  */
201
201
  private readonly outlines;
202
202
  private readonly fd;
203
+ /** the plain bundle file, `undefined` for an in-memory one */
204
+ private readonly file;
205
+ /** what {@link packagesExporting} reads, derived (or read from where an earlier process left it) on the first call */
206
+ private exportKeys;
203
207
  /** the dictionary, or how to load it: a bundle asked only for the versions it holds never needs its names */
204
208
  private dictionary;
205
209
  readonly index: SigDbIndex;
@@ -232,11 +236,6 @@ export declare class SigDatabase extends HistorySource implements PackageSignatu
232
236
  * nothing is known about the package yet, so this only ever skips work that would have found nothing.
233
237
  */
234
238
  private mayOffer;
235
- /**
236
- * Whether `pkg` may offer the name with dictionary id `id`, deciding from the raw bytes of a blob not decoded yet: every `[id,` they hold may
237
- * start a function record, so their ids are a superset of the names the package has, kept for {@link mayOffer} as {@link nameIdsOfBlob}.
238
- */
239
- private mayHoldNameId;
240
239
  /** drop one decoded blob, for the shared budget to reclaim what it costs (see {@link keepBlob}) */
241
240
  dropBlob(blobIdx: number): void;
242
241
  /** store `value` under `key`, dropping the oldest entry first once the cache sits at `cap` */
@@ -259,12 +258,11 @@ export declare class SigDatabase extends HistorySource implements PackageSignatu
259
258
  lookup(pkg: BrandedNamespace, version?: string): LibraryExports | undefined;
260
259
  packagesExporting(name: BrandedIdentifier): readonly BrandedNamespace[];
261
260
  /**
262
- * Whether the newest version of `pkg` exports the name with dictionary id `id`. The same answer
263
- * {@link lookup}'s `exported` gives, off the function records themselves: asking a package at a time is what
264
- * {@link packagesExporting} does, and deriving a whole export view per package to read one name out of it is not
261
+ * Every `[name id, package ordinal]` the newest version of a package exports, the same answer {@link lookup}'s `exported` gives
262
+ * off the function records themselves: deriving a whole export view per package to read the names out of it is not
265
263
  * worth the five arrays and the map it builds.
266
264
  */
267
- private exportsNameId;
265
+ private exportedPairs;
268
266
  /**
269
267
  * Resolve a package version to its blob and the function records of that version (the shared prologue of
270
268
  * {@link functions}/{@link functionByName}). The blob comes from {@link blob} every time rather than out of
@@ -24,6 +24,7 @@ const decode_1 = require("./decode");
24
24
  const decompress_1 = require("./decompress");
25
25
  const codec_1 = require("./codec");
26
26
  const dict_1 = require("./dict");
27
+ const export_keys_1 = require("./export-keys");
27
28
  const hash_1 = require("./hash");
28
29
  const manifest_1 = require("./manifest");
29
30
  const arrays_1 = require("../../util/collections/arrays");
@@ -407,14 +408,19 @@ class SigDatabase extends HistorySource {
407
408
  */
408
409
  outlines = new Map();
409
410
  fd;
411
+ /** the plain bundle file, `undefined` for an in-memory one */
412
+ file;
413
+ /** what {@link packagesExporting} reads, derived (or read from where an earlier process left it) on the first call */
414
+ exportKeys;
410
415
  /** the dictionary, or how to load it: a bundle asked only for the versions it holds never needs its names */
411
416
  dictionary;
412
417
  index;
413
418
  content;
414
419
  cranBase;
415
- constructor(fd, strings, index, content, cranBase) {
420
+ constructor(fd, file, strings, index, content, cranBase) {
416
421
  super();
417
422
  this.fd = fd;
423
+ this.file = file;
418
424
  this.dictionary = strings;
419
425
  this.index = index;
420
426
  this.content = content;
@@ -423,7 +429,7 @@ class SigDatabase extends HistorySource {
423
429
  /** Use an already-built {@link SigDb} directly, no file involved: its blobs start out in the cache, so a test needs only {@link SigDbBuilder} plus this. */
424
430
  static fromMemory(db) {
425
431
  const index = { byteCount: 0, dict: [0, 0], blobs: [], pkgs: db.pkgs, meta: db.meta };
426
- const source = new SigDatabase(NoFile, dict_1.SigDict.of(db.strings), index, db.content, db.cranBase ?? schema_1.DefaultCranBase);
432
+ const source = new SigDatabase(NoFile, undefined, dict_1.SigDict.of(db.strings), index, db.content, db.cranBase ?? schema_1.DefaultCranBase);
427
433
  db.blobs.forEach((blob, i) => source.blobCache.set(i, { blob }));
428
434
  return source;
429
435
  }
@@ -453,7 +459,7 @@ class SigDatabase extends HistorySource {
453
459
  }
454
460
  }
455
461
  const cranBase = header?.cranBase ?? schema_1.DefaultCranBase;
456
- return new SigDatabase(fd, strings, index, header?.content, cranBase);
462
+ return new SigDatabase(fd, plainFile, strings, index, header?.content, cranBase);
457
463
  }
458
464
  /** open a `.sigs.ndjson`, `.br` or `.gz`; compressed sources are decompressed into a hash-keyed cache once */
459
465
  static async open(source, opts = {}) {
@@ -546,32 +552,6 @@ class SigDatabase extends HistorySource {
546
552
  }
547
553
  return false;
548
554
  }
549
- /**
550
- * Whether `pkg` may offer the name with dictionary id `id`, deciding from the raw bytes of a blob not decoded yet: every `[id,` they hold may
551
- * start a function record, so their ids are a superset of the names the package has, kept for {@link mayOffer} as {@link nameIdsOfBlob}.
552
- */
553
- mayHoldNameId(pkg, name) {
554
- const blobIdx = this.index.pkgs[pkg];
555
- if (blobIdx === undefined || this.fd === NoFile || this.blobCache.has(blobIdx) || this.nameIdsOfBlob.has(blobIdx)) {
556
- return true;
557
- }
558
- const [start, bytes] = this.index.blobs[blobIdx];
559
- const buf = Buffer.allocUnsafe(bytes);
560
- fs_1.default.readSync(this.fd, buf, 0, bytes, start);
561
- const ids = new Set();
562
- for (let at = buf.indexOf(91); at >= 0; at = buf.indexOf(91, at + 1)) {
563
- let num = 0;
564
- let end = at + 1;
565
- for (; end < bytes && buf[end] >= 48 && buf[end] <= 57; end++) {
566
- num = num * 10 + buf[end] - 48;
567
- }
568
- if (end > at + 1 && buf[end] === 44) {
569
- ids.add(num);
570
- }
571
- }
572
- this.nameIdsOfBlob.set(blobIdx, Int32Array.from(ids).sort());
573
- return this.mayOffer(pkg, name);
574
- }
575
555
  /** drop one decoded blob, for the shared budget to reclaim what it costs (see {@link keepBlob}) */
576
556
  dropBlob(blobIdx) {
577
557
  this.blobCache.delete(blobIdx);
@@ -652,23 +632,25 @@ class SigDatabase extends HistorySource {
652
632
  if (id < 0) {
653
633
  return [];
654
634
  }
655
- const found = [];
656
- for (const pkg in this.index.pkgs) {
657
- if (this.mayHoldNameId(pkg, name) && this.mayOffer(pkg, name) && this.exportsNameId(pkg, id)) {
658
- found.push(pkg);
659
- }
660
- }
661
- return found.sort((a, b) => this.downloads(b) - this.downloads(a) || (0, strings_1.compareByCodeUnit)(a, b));
635
+ const names = Object.keys(this.index.pkgs);
636
+ this.exportKeys ??= (0, export_keys_1.exportKeysFor)(this.file, names.length, () => this.exportedPairs(names));
637
+ return this.exportKeys.ordinalsOf(id).map(ordinal => names[ordinal]).sort((a, b) => this.downloads(b) - this.downloads(a) || (0, strings_1.compareByCodeUnit)(a, b));
662
638
  }
663
639
  /**
664
- * Whether the newest version of `pkg` exports the name with dictionary id `id`. The same answer
665
- * {@link lookup}'s `exported` gives, off the function records themselves: asking a package at a time is what
666
- * {@link packagesExporting} does, and deriving a whole export view per package to read one name out of it is not
640
+ * Every `[name id, package ordinal]` the newest version of a package exports, the same answer {@link lookup}'s `exported` gives
641
+ * off the function records themselves: deriving a whole export view per package to read the names out of it is not
667
642
  * worth the five arrays and the map it builds.
668
643
  */
669
- exportsNameId(pkg, id) {
670
- const r = this.versionFns(pkg);
671
- return r?.fns.idxs.some(i => r.blob.fns[i][0] === id && (r.blob.fns[i][3] & 1 /* FnProp.Exported */) !== 0) ?? false;
644
+ *exportedPairs(names) {
645
+ for (const [ordinal, pkg] of names.entries()) {
646
+ const r = this.versionFns(pkg);
647
+ for (const i of r?.fns.idxs ?? []) {
648
+ const fn = r?.blob.fns[i];
649
+ if (fn !== undefined && (fn[3] & 1 /* FnProp.Exported */) !== 0) {
650
+ yield [fn[0], ordinal];
651
+ }
652
+ }
653
+ }
672
654
  }
673
655
  /**
674
656
  * Resolve a package version to its blob and the function records of that version (the shared prologue of
@@ -87,10 +87,6 @@ export interface InputSource extends MergeableRecord {
87
87
  }
88
88
  /** The input sources of a criterion, each classified with an {@link InputSource} object. */
89
89
  export type InputSources = InputSource[];
90
- /**
91
- * This is either an {@link NodeId|id} of a known functions all of that category (e.g., you can issue a dependencies query before and then pass all
92
- * identified ids to this query here).
93
- */
94
90
  export type InputClassifierFunctionIdentifiers = readonly (Identifier | NodeId)[];
95
91
  /** For the specifications of `pure` etc. please have a look at {@link InputClassifierFunctionIdentifiers}. */
96
92
  export interface InputClassifierConfig<Functions extends InputClassifierFunctionIdentifiers | FlowrSearchLike = readonly Identifier[] | FlowrSearchLike> extends Partial<Record<InputType, Functions>> {
@@ -30,6 +30,8 @@ const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
30
30
  const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
31
31
  const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
32
32
  const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
33
+ const r_for_loop_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
34
+ const r_access_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
33
35
  const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
34
36
  const range_1 = require("../../../util/range");
35
37
  const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
@@ -57,6 +59,9 @@ class ClassificationAccumulator {
57
59
  this.push(input_types_1.InputType.Unknown);
58
60
  return;
59
61
  }
62
+ else if (c.types.length === 0) {
63
+ return;
64
+ }
60
65
  this.types.push(...c.types);
61
66
  this.values.push(c.value);
62
67
  this.cds.push(...c.cds ?? []);
@@ -87,6 +92,10 @@ class InputClassifier {
87
92
  packages;
88
93
  environment;
89
94
  cache = new Map();
95
+ /** the vertices being classified with their depth, the lowest depth a cycle returned to, and what was classified within an open cycle */
96
+ open = new Map();
97
+ provisional = new Map();
98
+ lowestOpen = Infinity;
90
99
  fullClassifier;
91
100
  unsanitized;
92
101
  declarationIndex;
@@ -306,23 +315,36 @@ class InputClassifier {
306
315
  if (cached) {
307
316
  return cached;
308
317
  }
309
- /* a temporary unknown breaks cycles */
310
- this.cache.set(vertex.id, sourceOf(vertex.id, input_types_1.InputType.Unknown));
311
- switch (vertex.tag) {
312
- case vertex_1.VertexType.Value: {
313
- const value = this.extractConstantValue(vertex.id);
314
- return this.classifyCdsAndReturn(vertex, (0, objects_1.compactRecord)({ ...sourceOf(vertex.id, input_types_1.InputType.Constant), value }));
318
+ /* a cycle (`i <- i + 1` in a loop) brings in nothing the other definitions do not already */
319
+ const open = this.open.get(vertex.id);
320
+ const provisional = this.provisional.get(vertex.id);
321
+ if (open !== undefined || provisional !== undefined) {
322
+ this.lowestOpen = Math.min(this.lowestOpen, open ?? provisional?.[1]);
323
+ return provisional?.[0] ?? { id: vertex.id, types: [], trace: input_types_1.InputTraceType.Pure };
324
+ }
325
+ const [depth, outer] = [this.open.size, this.lowestOpen];
326
+ this.open.set(vertex.id, depth);
327
+ this.lowestOpen = Infinity;
328
+ /* inline, as long chains of definitions come close to the stack limit; a function definition is a constant, whatever it computes when called */
329
+ const result = vertex_1.DfgVertex.isFunctionCall(vertex) ? this.classifyFunctionCall(vertex)
330
+ : vertex_1.DfgVertex.isVariableDefinition(vertex) ? this.classifyVariableDefinition(vertex)
331
+ : vertex_1.DfgVertex.isUse(vertex) ? this.classifyVariable(vertex)
332
+ : this.classifyCdsAndReturn(vertex, (0, objects_1.compactRecord)({ ...sourceOf(vertex.id, input_types_1.InputType.Constant), value: vertex_1.DfgVertex.isValue(vertex) ? this.extractConstantValue(vertex.id) : undefined }));
333
+ this.open.delete(vertex.id);
334
+ if (this.lowestOpen < depth) {
335
+ /* it lacks what the open vertex of its cycle brings in, which is all it lacks until that one is done */
336
+ this.provisional.set(vertex.id, [result, this.lowestOpen]);
337
+ }
338
+ else {
339
+ if (result.types.length === 0) {
340
+ result.types.push(input_types_1.InputType.Unknown);
315
341
  }
316
- case vertex_1.VertexType.FunctionCall:
317
- return this.classifyFunctionCall(vertex);
318
- case vertex_1.VertexType.VariableDefinition:
319
- return this.classifyVariableDefinition(vertex);
320
- case vertex_1.VertexType.Use:
321
- return this.classifyVariable(vertex);
322
- /* a function definition is a constant: its code is fixed, whatever it computes when called */
323
- case vertex_1.VertexType.FunctionDefinition:
324
- return this.classifyCdsAndReturn(vertex, sourceOf(vertex.id, input_types_1.InputType.Constant));
342
+ this.cache.set(vertex.id, result);
343
+ this.provisional.forEach(([, low], id) => low >= depth && this.provisional.delete(id));
344
+ this.lowestOpen = Infinity;
325
345
  }
346
+ this.lowestOpen = Math.min(outer, this.lowestOpen);
347
+ return result;
326
348
  }
327
349
  /**
328
350
  * Whether `call` quotes only the code written in its arguments: no name in them resolves outside of them
@@ -380,16 +402,15 @@ class InputClassifier {
380
402
  declaredAt: field !== undefined && linked.declaredBy ? this.declarations().get(declarationKey(linked.name, field)) : undefined
381
403
  });
382
404
  }
405
+ /** the field `input$n` names, or the one `input[[n]]` reads by the value of `n` */
383
406
  accessedField(call) {
384
407
  const ref = call.args[1] === undefined ? undefined : graph_1.FunctionArgument.getReference(call.args[1]);
385
408
  const node = ref === undefined ? undefined : this.dfg.idMap?.get(ref);
386
- if (r_string_1.RString.is(node)) {
387
- return node.content.str;
388
- }
389
- else if (r_symbol_1.RSymbol.is(node)) {
409
+ if (r_symbol_1.RSymbol.is(node) && r_access_1.RAccess.isNamed(this.dfg.idMap?.get(call.id))) {
390
410
  return identifier_1.Identifier.getName(node.content);
391
411
  }
392
- return undefined;
412
+ const value = r_string_1.RString.is(node) ? node.content.str : this.classifyAt(ref)?.value;
413
+ return typeof value === 'string' ? value : undefined;
393
414
  }
394
415
  /** the argument a built-in hands on: the value of a block or `get` (then `renamed`), the condition of a loop */
395
416
  passedOn(call) {
@@ -450,7 +471,7 @@ class InputClassifier {
450
471
  templateArguments(call) {
451
472
  return (this.config.templates ?? []).filter(t => this.matches(call, [t.call])).flatMap(t => t.argName === '...'
452
473
  ? call.args.filter(a => !graph_1.FunctionArgument.isNamed(a)).map(graph_1.FunctionArgument.getReference)
453
- : [this.argumentReference(call, t.argIdx, t.argName)]);
474
+ : [this.argumentReference(call, t.argIdx, t.argName)]).filter(assert_1.isNotUndefined);
454
475
  }
455
476
  /** the types and control dependencies of what `ref` yields, `unknown` when it cannot be classified */
456
477
  dependencies(ref, unknown = [input_types_1.InputType.Unknown]) {
@@ -494,7 +515,7 @@ class InputClassifier {
494
515
  if (!this.matches(call, [narrow.call])) {
495
516
  continue;
496
517
  }
497
- const bound = this.argumentReference(call, narrow.argIdx, narrow.argName);
518
+ const bound = this.argumentReference(call, narrow.argIdx, narrow.argName) ?? this.formalDefault(call);
498
519
  const narrowed = this.classifyAt(bound);
499
520
  if (narrowed) {
500
521
  /* which of the values it is depends on the other arguments */
@@ -511,6 +532,10 @@ class InputClassifier {
511
532
  types.splice(types.indexOf(input_types_1.InputType.File), 1);
512
533
  types.push(input_types_1.InputType.TempFile);
513
534
  }
535
+ else if (readsFile && call.args.some(arg => this.isStdin(graph_1.FunctionArgument.getReference(arg)))) {
536
+ /* what is read from the standard input is what the user types */
537
+ types.splice(types.indexOf(input_types_1.InputType.File), 1, ...types.includes(input_types_1.InputType.User) ? [] : [input_types_1.InputType.User]);
538
+ }
514
539
  /* `quote` yields written code, only capturing (`substitute(x)`) or splicing (`bquote(.(y))`) brings in other code */
515
540
  if (types.includes(input_types_1.InputType.Lang) && this.quotesOnlyWrittenCode(call)) {
516
541
  types.splice(types.indexOf(input_types_1.InputType.Lang), 1, input_types_1.InputType.DerivedConstant);
@@ -526,8 +551,9 @@ class InputClassifier {
526
551
  acc.merge(this.classifyAt(block));
527
552
  /* and whether they answer depends on everything the block does */
528
553
  const statements = block === undefined ? undefined : this.whole.getVertex(block);
529
- for (const arg of vertex_1.DfgVertex.isFunctionCall(statements) && vertex_1.DfgVertex.hasOrigin(statements, built_in_proc_name_1.BuiltInProcName.ExpressionList) ? statements.args : []) {
530
- acc.cds.push(...this.dependencies(graph_1.FunctionArgument.getReference(arg)));
554
+ const isBlock = vertex_1.DfgVertex.isFunctionCall(statements) && vertex_1.DfgVertex.hasOrigin(statements, built_in_proc_name_1.BuiltInProcName.ExpressionList);
555
+ for (const ref of isBlock ? statements.args.map(graph_1.FunctionArgument.getReference) : [block]) {
556
+ acc.cds.push(...this.dependencies(ref));
531
557
  }
532
558
  return this.classifyCdsAndReturn(call, acc.build(call.id));
533
559
  }
@@ -563,6 +589,19 @@ class InputClassifier {
563
589
  cds: cdTypes.length > 0 ? (0, arrays_1.uniqueArray)(cdTypes) : undefined
564
590
  }));
565
591
  }
592
+ /** Whether the value at `ref` is the standard input: `stdin()`, or `file("stdin")` and the path `"stdin"`, which R opens as it. */
593
+ isStdin(ref) {
594
+ const sources = ref === undefined ? undefined : df_helper_1.Dataflow.valueSources(ref, this.whole);
595
+ return sources !== undefined && sources.length > 0 && sources.every(at => {
596
+ const node = this.whole.idMap?.get(at);
597
+ const vertex = this.whole.getVertex(at);
598
+ if (r_string_1.RString.is(node)) {
599
+ return node.content.str === 'stdin';
600
+ }
601
+ return vertex_1.DfgVertex.isFunctionCall(vertex) && (this.matches(vertex, StdinConnection)
602
+ || (this.matches(vertex, FileConnection) && this.isStdin(this.argumentReference(vertex, 0, 'description'))));
603
+ });
604
+ }
566
605
  /**
567
606
  * What a call of a function the analyzed code defines yields: what its exit points do, as a function whose
568
607
  * body is `system(x)` runs a system command whether the call reads `f(cmd)` or `system(cmd)`. `undefined`
@@ -648,8 +687,9 @@ class InputClassifier {
648
687
  }
649
688
  const classified = this.classifyAt(o.id) ?? this.classifyInFullGraph(o.id);
650
689
  if (classified?.types.every(isConstantLike)) {
651
- /* a constant held as a function (`get("readLines")`, a body set to quoted code) says nothing about what calling it yields */
652
- return sourceOf(call.id, input_types_1.InputType.Unknown);
690
+ /* a built-in held as a function (`rl <- readline; rl()`) is that built-in, other constants (a body set to quoted code) say nothing about what calling it yields */
691
+ const held = this.heldBuiltIn(call);
692
+ return held === undefined ? sourceOf(call.id, input_types_1.InputType.Unknown) : this.classifyFunctionCall({ ...call, name: held });
653
693
  }
654
694
  else if (classified !== undefined && !classified.types.includes(input_types_1.InputType.Unknown)) {
655
695
  return classified;
@@ -657,6 +697,23 @@ class InputClassifier {
657
697
  }
658
698
  return undefined;
659
699
  }
700
+ /** without its choices, `match.arg(type)` takes the default of the parameter `type` of the function calling it */
701
+ formalDefault(call) {
702
+ const idMap = this.whole.idMap;
703
+ const arg = idMap.get(this.argumentReference(call, 0, 'arg'));
704
+ const fn = r_symbol_1.RSymbol.is(arg) ? model_1.RNode.iterateParents(arg, idMap).find(r_function_definition_1.RFunctionDefinition.is) : undefined;
705
+ return fn?.parameters.find(p => p.name.content === arg?.content)?.defaultValue?.info.id;
706
+ }
707
+ /** the one built-in the call runs, if it is called by another name */
708
+ heldBuiltIn(call) {
709
+ const callees = df_helper_1.Dataflow.targetsOf(this.whole, call.id, edge_1.EdgeType.Calls);
710
+ if (callees.length !== 1 || !node_id_1.NodeId.isBuiltIn(callees[0])) {
711
+ return undefined;
712
+ }
713
+ const [pkg, fn] = node_id_1.NodeId.toPkgFn(callees[0]) ?? [undefined, node_id_1.NodeId.fromBuiltIn(callees[0])];
714
+ const held = identifier_1.Identifier.make(fn, pkg);
715
+ return identifier_1.Identifier.getName(held) === identifier_1.Identifier.getName(call.name) ? undefined : held;
716
+ }
660
717
  /**
661
718
  * A shiny `v <- reactiveVal(init)` holds what it starts with and whatever a call `v(x)` sets later on, so a call
662
719
  * `v()` yields any of these; handed on as a value (`helper(v)`), anything may be set elsewhere.
@@ -807,13 +864,23 @@ class InputClassifier {
807
864
  const node = this.whole.idMap?.get(id);
808
865
  return r_symbol_1.RSymbol.is(node) && identifier_1.Identifier.isDotDotDotAccess(node.content) && node.content !== identifier_1.Identifier.dotdotdot();
809
866
  }
810
- /** whether the function binding the parameter is used as a value, so it may be called with anything the visible callers do not pass */
867
+ /**
868
+ * whether the function binding the parameter is used as a value, so it may be called with anything the visible callers do not pass;
869
+ * handed to an apply (`lapply(x, f)`), it is called there
870
+ */
811
871
  escapes(parameter) {
812
872
  const idMap = this.whole.idMap;
813
873
  const fn = idMap === undefined ? undefined : model_1.RNode.iterateParents(idMap.get(parameter), idMap).find(r_function_definition_1.RFunctionDefinition.is);
814
- const holders = fn === undefined ? [] : df_helper_1.Dataflow.sourcesOf(this.whole, fn.info.id, edge_1.EdgeType.DefinedBy);
815
- return holders.length === 0 || holders.some(h => df_helper_1.Dataflow.sourcesOf(this.whole, h, edge_1.EdgeType.Reads)
816
- .some(r => !r_function_call_1.RFunctionCall.is(idMap?.get(r)) || !df_helper_1.Dataflow.hasEdge(this.whole, r, fn?.info.id, edge_1.EdgeType.Calls)));
874
+ if (fn === undefined) {
875
+ return true;
876
+ }
877
+ const holders = df_helper_1.Dataflow.sourcesOf(this.whole, fn.info.id, edge_1.EdgeType.DefinedBy);
878
+ const uses = (holders.length === 0 ? [fn.info.id] : holders).flatMap(h => df_helper_1.Dataflow.sourcesOf(this.whole, h, edge_1.EdgeType.Reads));
879
+ return (holders.length === 0 && uses.length === 0) || uses.some(r => !df_helper_1.Dataflow.hasEdge(this.whole, r, fn.info.id, edge_1.EdgeType.Calls) || !(r_function_call_1.RFunctionCall.is(idMap?.get(r)) || this.calledByApply(r)));
880
+ }
881
+ /** whether an apply calls what `id` holds: `lapply` itself, or the call it makes of an argument it is handed */
882
+ calledByApply(id) {
883
+ return [id, ...df_helper_1.Dataflow.sourcesOf(this.whole, id, edge_1.EdgeType.Argument)].some(c => vertex_1.DfgVertex.hasOrigin(this.whole.getVertex(c), built_in_proc_name_1.BuiltInProcName.Apply));
817
884
  }
818
885
  /** whether code flowR cannot follow (`load`, `eval`, `e$x <-`) may rebind the variable before the use */
819
886
  mayBeRebound(use, definitions) {
@@ -822,11 +889,19 @@ class InputClassifier {
822
889
  const fn = model_1.RNode.iterateParents(node, idMap).find(r_function_definition_1.RFunctionDefinition.is);
823
890
  const within = (id) => fn !== undefined && model_1.RNode.iterateParents(idMap.get(id), idMap).some(p => p === fn);
824
891
  const local = definitions.length > 0 && definitions.every(within);
825
- /* an unconditional definition after the effect binds anew */
826
- const overwritten = (e) => definitions.length > 0 && definitions.every(d => !this.whole.getVertex(d)?.cds?.length
827
- && runsAfter(idMap.get(idMap.get(d)?.info.parent), idMap.get(e), idMap));
892
+ /* where a definition binds: once its value is computed, for the variable of a for loop before its body runs */
893
+ const binds = (d) => {
894
+ const parent = idMap.get(idMap.get(d)?.info.parent);
895
+ return r_for_loop_1.RForLoop.is(parent) ? parent.variable : parent;
896
+ };
897
+ /* an unconditional definition after the effect binds anew, whatever a loop redefines later on */
898
+ const overwritten = (e) => definitions.some(d => !this.whole.getVertex(d)?.cds?.length && runsAfter(binds(d), idMap.get(e), idMap));
899
+ /* a for loop binds its variable anew before each run of its body, so what the body does after the use cannot change it */
900
+ const loop = idMap.get(idMap.get(definitions[0])?.info.parent);
901
+ const body = r_for_loop_1.RForLoop.is(loop) && definitions.every(d => d === loop.variable.info.id) ? loop.body : undefined;
828
902
  return this.rebinders().some(([e, fields]) => (fields === undefined || fields.some(f => f === undefined || f === model_1.RNode.lexeme(node)))
829
- && (!local || within(e)) && !overwritten(e) && !((fn === undefined || local) && runsAfter(idMap.get(e), node, idMap)));
903
+ && (!local || within(e)) && !overwritten(e) && !((fn === undefined || local) && runsAfter(idMap.get(e), node, idMap))
904
+ && !(body !== undefined && runsAfter(idMap.get(e), node, idMap, body)));
830
905
  }
831
906
  /** the unknown side effects, and the replacements `e$x <- v` with the names they may bind (`undefined` for any) */
832
907
  rebinders() {
@@ -865,7 +940,6 @@ class InputClassifier {
865
940
  if (src.cds?.length === 0) {
866
941
  delete src.cds;
867
942
  }
868
- this.cache.set(vtx.id, src);
869
943
  return src;
870
944
  }
871
945
  }
@@ -901,14 +975,32 @@ const PlumberEndpoint = /^#\*\s*@(?:get|post|put|delete|patch|head|options|any|u
901
975
  /** the replacements that may write a binding of an environment, as `e$x <- v` does */
902
976
  const FieldReplacements = new Set(['$<-', '[[<-']);
903
977
  const LoopTypes = new Set([type_1.RType.ForLoop, type_1.RType.WhileLoop, type_1.RType.RepeatLoop]);
904
- /** whether `later` surely runs after `node`: later in the same file, in no shared loop, not deferred into a function apart from it */
905
- function runsAfter(later, node, idMap) {
978
+ /**
979
+ * whether `later` surely runs after `node`: later in the same file, in no shared loop, not deferred into a function apart from it;
980
+ * with a `scope`, both have to be within it and only one run of it counts (one run of a loop body)
981
+ */
982
+ function runsAfter(later, node, idMap, scope) {
906
983
  const [first, second] = [model_1.RNode.span(node), model_1.RNode.span(later)];
907
984
  if (first === undefined || second === undefined || node?.info.file !== later?.info.file || !(range_1.SourceRange.startsCompletelyBefore(first, second) || range_1.SourceRange.isSubsetOf(first, second))) {
908
985
  return false;
909
986
  }
910
987
  const around = new Set(model_1.RNode.iterateParents(later, idMap));
911
- return model_1.RNode.iterateParents(node, idMap).every(p => r_function_definition_1.RFunctionDefinition.is(p) ? around.has(p) : !LoopTypes.has(p.type) || !around.has(p));
988
+ if (scope !== undefined && !around.has(scope)) {
989
+ return false;
990
+ }
991
+ let child = node;
992
+ for (const p of model_1.RNode.iterateParents(node, idMap)) {
993
+ /* the vector of a for loop is evaluated once, before its body runs */
994
+ const once = r_for_loop_1.RForLoop.is(p) && child === p.vector;
995
+ if (p === scope) {
996
+ return true;
997
+ }
998
+ else if (r_function_definition_1.RFunctionDefinition.is(p) ? !around.has(p) : LoopTypes.has(p.type) && around.has(p) && !once) {
999
+ return false;
1000
+ }
1001
+ child = p;
1002
+ }
1003
+ return scope === undefined;
912
1004
  }
913
1005
  function declarationKey(object, field) {
914
1006
  return `${object}\u0000${field}`;
@@ -917,6 +1009,12 @@ function declarationKey(object, field) {
917
1009
  function fieldIsInput(obj, field) {
918
1010
  return obj.fields === undefined || (field !== undefined && obj.fields.includes(field));
919
1011
  }
1012
+ /**
1013
+ * This is either an {@link NodeId|id} of a known functions all of that category (e.g., you can issue a dependencies query before and then pass all
1014
+ * identified ids to this query here).
1015
+ */
1016
+ const StdinConnection = [identifier_1.Identifier.make('stdin')];
1017
+ const FileConnection = [identifier_1.Identifier.make('file')];
920
1018
  /**
921
1019
  * Whether a call by the name `called` means `id`. A `pkg::fn` call has to match exactly, while a bare call only
922
1020
  * means a namespaced entry if that package is attached - just like in R, where the search path decides.
@@ -3,6 +3,6 @@
3
3
  * @module
4
4
  */
5
5
  import { SemVer } from 'semver';
6
- export declare const versionDate = "2026-11-22T17:14:43Z";
6
+ export declare const versionDate = "2026-11-25T20:19:23Z";
7
7
  /** Retrieves the current flowR version as a new {@link SemVer} object. */
8
8
  export declare function flowrVersion(): SemVer;
@@ -8,9 +8,9 @@ exports.flowrVersion = flowrVersion;
8
8
  */
9
9
  const semver_1 = require("semver");
10
10
  // this is automatically replaced with the current version by release-it
11
- const version = '2.17.11';
11
+ const version = '2.17.13';
12
12
  // this is automatically replaced with the release date by release-it (scripts/bump-version.ts)
13
- exports.versionDate = '2026-11-22T17:14:43Z';
13
+ exports.versionDate = '2026-11-25T20:19:23Z';
14
14
  /** Retrieves the current flowR version as a new {@link SemVer} object. */
15
15
  function flowrVersion() {
16
16
  return new semver_1.SemVer(version);
@@ -74,7 +74,7 @@ exports.Mermaid = {
74
74
  * @param edit - if true, the url will point to the editor, otherwise it will point to the viewer
75
75
  */
76
76
  codeToUrl(code, edit = false) {
77
- const obj = { code, mermaid: { autoSync: true } };
77
+ const obj = { code, mermaid: JSON.stringify({ autoSync: true }) };
78
78
  /* `btoa` rather than a `Buffer`, so the pages flowR ships can build this url as well */
79
79
  return `https://mermaid.live/${edit ? 'edit' : 'view'}#base64:${(0, url_encoding_1.toBase64)(new TextEncoder().encode(JSON.stringify(obj)))}`;
80
80
  }