@eagleoutice/flowr 2.15.4 → 2.15.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 (34) hide show
  1. package/config.d.ts +2 -0
  2. package/config.js +3 -1
  3. package/dataflow/environments/default-builtin-config.d.ts +57 -0
  4. package/dataflow/environments/default-builtin-config.js +6 -2
  5. package/dataflow/environments/environment.d.ts +11 -19
  6. package/dataflow/environments/environment.js +17 -39
  7. package/dataflow/environments/frame-memory.d.ts +33 -68
  8. package/dataflow/environments/frame-memory.js +77 -200
  9. package/dataflow/environments/identifier.d.ts +5 -0
  10. package/dataflow/environments/resolve-by-name.js +7 -1
  11. package/dataflow/internal/process/functions/call/argument/make-argument.d.ts +1 -1
  12. package/dataflow/internal/process/functions/call/argument/make-argument.js +17 -1
  13. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +16 -4
  14. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +12 -0
  15. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +5 -19
  16. package/dataflow/internal/process/process-named-call.d.ts +2 -2
  17. package/dataflow/internal/process/process-named-call.js +3 -3
  18. package/documentation/wiki-setup.js +28 -3
  19. package/linter/rules/unescaped-arguments.js +43 -3
  20. package/package.json +1 -1
  21. package/project/context/flowr-analyzer-files-context.d.ts +2 -2
  22. package/project/context/flowr-analyzer-files-context.js +3 -0
  23. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -0
  24. package/project/sigdb/decode.d.ts +5 -4
  25. package/project/sigdb/decode.js +13 -18
  26. package/project/sigdb/dict.d.ts +35 -0
  27. package/project/sigdb/dict.js +97 -0
  28. package/project/sigdb/hash.d.ts +7 -2
  29. package/project/sigdb/reader.d.ts +9 -6
  30. package/project/sigdb/reader.js +40 -28
  31. package/slicing/static/fingerprint.js +6 -12
  32. package/util/text/playground-link.d.ts +14 -5
  33. package/util/text/playground-link.js +32 -8
  34. package/util/version.js +2 -2
@@ -8,6 +8,7 @@ exports.readSignatureDb = readSignatureDb;
8
8
  exports.availableVersionEntries = availableVersionEntries;
9
9
  exports.classOwnerIndexFor = classOwnerIndexFor;
10
10
  exports.sourceForPackage = sourceForPackage;
11
+ exports.setBlobCacheBudget = setBlobCacheBudget;
11
12
  exports.getSharedSigSourceSync = getSharedSigSourceSync;
12
13
  exports.getSharedSigSource = getSharedSigSource;
13
14
  exports.verifyShardedDatabase = verifyShardedDatabase;
@@ -25,27 +26,29 @@ const index_format_1 = require("./index-format");
25
26
  const decode_1 = require("./decode");
26
27
  const decompress_1 = require("./decompress");
27
28
  const codec_1 = require("./codec");
29
+ const dict_1 = require("./dict");
28
30
  const hash_1 = require("./hash");
29
31
  const manifest_1 = require("./manifest");
30
32
  const arrays_1 = require("../../util/collections/arrays");
31
- /** apply one `d` line (`["d", start, payload]`, new newline-blob or legacy `string[]` form) to the dictionary in place */
32
- function applyDictLine(json, strings) {
33
+ /** the run of names one `d` line (`["d", start, payload]`, newline-blob or legacy `string[]` form) adds */
34
+ function dictLineRun(json) {
33
35
  const [, start, payload] = JSON.parse(json);
34
- const batch = typeof payload === 'string' ? payload.split('\n') : payload;
36
+ return { start, names: typeof payload === 'string' ? payload : payload.join('\n') };
37
+ }
38
+ /** apply one `d` line to a plain array, for the whole-file form {@link readSigDbFile} reads */
39
+ function applyDictLine(json, strings) {
40
+ const { start, names } = dictLineRun(json);
41
+ const batch = names.split('\n');
35
42
  for (let k = 0; k < batch.length; k++) {
36
43
  strings[start + k] = batch[k];
37
44
  }
38
45
  }
39
46
  /**
40
- * Dictionary ids grouped by first character and length, shared per dictionary rather than per reader (the shards of one
41
- * database read the same array). One `Int32Array` per group, ascending, so a lookup answers what `indexOf` would while
42
- * comparing a few hundred strings rather than the 1.4 million a scan of the whole dictionary walks.
47
+ * Dictionary ids grouped by first byte and byte length, kept per dictionary rather than per reader (the shards of one
48
+ * database read the same one). One `Int32Array` per group, ascending, so a lookup answers what `indexOf` would while
49
+ * comparing a few hundred names rather than the 1.4 million a scan of the whole dictionary walks.
43
50
  */
44
51
  const dictionaryBuckets = new WeakMap();
45
- /** the group `name` belongs to; the empty string has none of its own, which is what `0` stands for */
46
- function bucketKeyOf(name) {
47
- return name.length === 0 ? 0 : (name.charCodeAt(0) << 8) | Math.min(name.length, 255);
48
- }
49
52
  /** the id `strings.indexOf(name)` would give, through {@link dictionaryBuckets}; `-1` when the dictionary lacks it */
50
53
  function dictionaryIdOf(strings, name) {
51
54
  let buckets = dictionaryBuckets.get(strings);
@@ -54,7 +57,7 @@ function dictionaryIdOf(strings, name) {
54
57
  lookup per entry to know where in its group the next one goes */
55
58
  const grouped = new Map();
56
59
  for (let i = 0; i < strings.length; i++) {
57
- const key = bucketKeyOf(strings[i]);
60
+ const key = strings.groupOf(i);
58
61
  const group = grouped.get(key);
59
62
  if (group === undefined) {
60
63
  grouped.set(key, [i]);
@@ -69,16 +72,18 @@ function dictionaryIdOf(strings, name) {
69
72
  }
70
73
  dictionaryBuckets.set(strings, buckets);
71
74
  }
72
- const bucket = buckets.get(bucketKeyOf(name));
75
+ const bucket = buckets.get(dict_1.SigDict.keyOf(name));
73
76
  /* ascending, so the first match is the one a scan from the front would have found */
74
77
  for (const id of bucket ?? []) {
75
- if (strings[id] === name) {
78
+ if (strings.at(id) === name) {
76
79
  return id;
77
80
  }
78
81
  }
79
82
  return -1;
80
83
  }
81
- function readDictSection(buf, strings) {
84
+ /** the dictionary a bundle's `d` lines spell out */
85
+ function readDictSection(buf) {
86
+ const runs = [];
82
87
  let off = 0;
83
88
  while (off < buf.length) {
84
89
  let nl = buf.indexOf(0x0a, off);
@@ -86,10 +91,11 @@ function readDictSection(buf, strings) {
86
91
  nl = buf.length;
87
92
  }
88
93
  if (nl > off) {
89
- applyDictLine(buf.toString('utf8', off, nl), strings);
94
+ runs.push(dictLineRun(buf.toString('utf8', off, nl)));
90
95
  }
91
96
  off = nl + 1;
92
97
  }
98
+ return dict_1.SigDict.ofRuns(runs);
93
99
  }
94
100
  /** stream-read a whole bundle into a {@link SigDb} (any size; never one string). Prefer {@link SigDatabase} for partial access. */
95
101
  async function readSignatureDb(file) {
@@ -313,7 +319,11 @@ const NoFile = -1;
313
319
  * anything: how many shards a query set opens is not something the caller picks, and each would claim the
314
320
  * budget again. A count would not bound anything either -- one package's blob outweighs a hundred small ones.
315
321
  */
316
- const BlobCacheBudget = 64 * 1024 * 1024;
322
+ let blobCacheBudget = 16 * 1024 * 1024;
323
+ /** Sets how many bytes of decoded blobs all open bundles may hold together (`solver.sigdb.blobCacheBudgetMb`). */
324
+ function setBlobCacheBudget(bytes) {
325
+ blobCacheBudget = Math.max(0, bytes);
326
+ }
317
327
  /** what every open bundle holds decoded, so the budget is spent across all of them */
318
328
  const cachedBlobs = [];
319
329
  /** where {@link keepBlob} resumes looking for something to drop */
@@ -323,7 +333,7 @@ let cachedBlobBytes = 0;
323
333
  * Keep `blob` decoded for `db`, dropping blobs until all of them fit the budget (age gated).
324
334
  */
325
335
  function keepBlob(db, blobIdx, bytes) {
326
- while (cachedBlobBytes + bytes > BlobCacheBudget && cachedBlobs.length > 0) {
336
+ while (cachedBlobBytes + bytes > blobCacheBudget && cachedBlobs.length > 0) {
327
337
  if (hand >= cachedBlobs.length) {
328
338
  hand = 0;
329
339
  }
@@ -362,7 +372,7 @@ function releaseBlobs(db) {
362
372
  */
363
373
  class SigDatabase {
364
374
  closed = false;
365
- /** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; bounded by {@link BlobCacheBudget} */
375
+ /** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; bounded by {@link setBlobCacheBudget|the shared budget} */
366
376
  blobCache = new Map();
367
377
  /** a version's function indices plus its `name -> index` view, keyed by package and version; FIFO-bounded */
368
378
  versionFnCache = new Map();
@@ -388,7 +398,7 @@ class SigDatabase {
388
398
  /** 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. */
389
399
  static fromMemory(db) {
390
400
  const index = { byteCount: 0, dict: [0, 0], blobs: [], pkgs: db.pkgs, meta: db.meta };
391
- const source = new SigDatabase(NoFile, db.strings, index, db.content, db.cranBase ?? schema_1.DefaultCranBase);
401
+ const source = new SigDatabase(NoFile, dict_1.SigDict.of(db.strings), index, db.content, db.cranBase ?? schema_1.DefaultCranBase);
392
402
  db.blobs.forEach((blob, i) => source.blobCache.set(i, { blob }));
393
403
  return source;
394
404
  }
@@ -406,13 +416,15 @@ class SigDatabase {
406
416
  fs_1.default.readSync(fd, head, 0, head.length, 0);
407
417
  const header = (0, decompress_1.parseHeader)(head.toString('utf8'));
408
418
  let strings = opts.strings;
409
- if (!strings) {
410
- strings = [];
419
+ if (strings === undefined) {
411
420
  const [dictStart, dictBytes] = index.dict;
412
421
  if (dictBytes > 0) {
413
422
  const buf = Buffer.allocUnsafe(dictBytes);
414
423
  fs_1.default.readSync(fd, buf, 0, dictBytes, dictStart);
415
- readDictSection(buf, strings);
424
+ strings = readDictSection(buf);
425
+ }
426
+ else {
427
+ strings = dict_1.SigDict.of([]);
416
428
  }
417
429
  }
418
430
  const cranBase = header?.cranBase ?? schema_1.DefaultCranBase;
@@ -549,7 +561,7 @@ class SigDatabase {
549
561
  }
550
562
  sourceOf(pkg, version) {
551
563
  const idx = this.blob(pkg)?.sources?.[version];
552
- return idx === undefined ? undefined : this.strings[idx];
564
+ return idx === undefined ? undefined : this.strings.at(idx);
553
565
  }
554
566
  /** `{ blob, meta }` for `pkg` when this bundle carries both, `undefined` otherwise; the shared prologue of most per-package queries below. */
555
567
  blobMeta(pkg) {
@@ -603,7 +615,7 @@ class SigDatabase {
603
615
  /**
604
616
  * Resolve a package version to its blob and the function records of that version (the shared prologue of
605
617
  * {@link functions}/{@link functionByName}). The blob comes from {@link blob} every time rather than out of
606
- * {@link versionFnCache}: holding one here would keep it decoded past what {@link BlobCacheBudget} allows.
618
+ * {@link versionFnCache}: holding one here would keep it decoded past what {@link setBlobCacheBudget|the shared budget} allows.
607
619
  */
608
620
  versionFns(pkg, version) {
609
621
  const bm = this.blobMeta(pkg);
@@ -641,7 +653,7 @@ class SigDatabase {
641
653
  if (r.fns.byName === undefined) {
642
654
  const byName = new Map();
643
655
  for (const i of r.fns.idxs) {
644
- const fn = this.strings[r.blob.fns[i][0]];
656
+ const fn = this.strings.at(r.blob.fns[i][0]);
645
657
  // first record wins, as the linear scan did
646
658
  if (!byName.has(fn)) {
647
659
  byName.set(fn, i);
@@ -816,13 +828,13 @@ class SigDatabaseSet {
816
828
  throw new Error(`manifest references unknown dictionary '${dictId}'`);
817
829
  }
818
830
  const plain = (0, decompress_1.ensurePlainSync)((0, decompress_1.resolveSource)(this.baseDir, ref.path), { cacheDir: this.cacheDir, hash: ref.hash, indexless: true });
819
- const strings = [];
831
+ let strings;
820
832
  const fd = fs_1.default.openSync(plain, 'r');
821
833
  try {
822
834
  const [start, bytes] = ref.range;
823
835
  const buf = Buffer.allocUnsafe(bytes);
824
836
  fs_1.default.readSync(fd, buf, 0, bytes, start);
825
- readDictSection(buf, strings);
837
+ strings = readDictSection(buf);
826
838
  }
827
839
  finally {
828
840
  fs_1.default.closeSync(fd);
@@ -938,7 +950,7 @@ class SigDatabaseSet {
938
950
  allShards() {
939
951
  return this.manifest.shards.map((ref, i) => ({ ref, db: this.shard(i) }));
940
952
  }
941
- /** load (and cache) a shared dictionary's strings by id, for verification/inspection */
953
+ /** load (and cache) a shared dictionary by id, for verification/inspection */
942
954
  sharedDictionary(id) {
943
955
  return this.dictionaryStrings(id);
944
956
  }
@@ -15,11 +15,10 @@ const HashOptions = {
15
15
  ignoreUnknown: true,
16
16
  replacer: (v) => (0, environment_1.isDefaultBuiltInEnvironment)(v) ? undefined : v
17
17
  };
18
- /* definitions, definition maps, and frames are shared across the environments a slice builds, and a definition may
19
- * hold a whole environment of its own (`envState`), so each is hashed once instead of on every fingerprint. The
20
- * map is keyed separately from the frame because cloning a frame shares its definitions until one side writes
21
- * (see {@link Environment#clone}): the graph holds many frames per distinct set of definitions, and hashing that
22
- * set is what costs. */
18
+ /* definitions, bindings, and frames are shared across the environments a slice builds, and a definition may hold
19
+ * a whole environment of its own (`envState`), so each is hashed once instead of on every fingerprint. Bindings
20
+ * are keyed apart from the frame because cloning shares them until one side writes (see {@link Environment#clone}):
21
+ * the graph holds many frames per distinct set of bindings, and hashing that set is what costs. */
23
22
  const definitionHashes = new WeakMap();
24
23
  const memoryHashes = new WeakMap();
25
24
  const frameHashes = new WeakMap();
@@ -32,12 +31,7 @@ function definitionHash(definition) {
32
31
  return hash;
33
32
  }
34
33
  function memoryHash(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);
34
+ let hash = memoryHashes.get(memory);
41
35
  if (hash === undefined) {
42
36
  const entries = [];
43
37
  for (const [name, definitions] of memory) {
@@ -45,7 +39,7 @@ function memoryHash(memory) {
45
39
  }
46
40
  entries.sort();
47
41
  hash = (0, object_hash_1.default)(entries, HashOptions);
48
- byVersion.set(memory.version, hash);
42
+ memoryHashes.set(memory, hash);
49
43
  }
50
44
  return hash;
51
45
  }
@@ -103,11 +103,20 @@ export declare const Playground: {
103
103
  */
104
104
  link(this: void, parts: PlaygroundLinkParts): string;
105
105
  /**
106
- * A fragment is not a query, so `,`, `:`, and the braces a configuration carries stand in it as they
107
- * are and only what would end it, split it, or read back as something else has to be escaped. `<` and
108
- * `>` go together: both are excluded from a URI, and a bare one of either ends the autolink a chat
109
- * client or a markdown reader made of the address. A link is also made not to end on punctuation,
110
- * because that is where a chat client stops reading it.
106
+ * The configuration keys as one field. A key is `a.b.c=<json>`, and the json is brackets, braces and quotes
107
+ * that a fragment does not carry, so it travels packed like the script rather than as a run of `%5B`.
108
+ */
109
+ packConfig(this: void, config: readonly string[]): string;
110
+ /** The keys back out of that field, which older links wrote out plainly and which is read either way. */
111
+ unpackConfig(this: void, field: string | null | undefined): string[];
112
+ /**
113
+ * Everything a fragment does not carry as itself is escaped, so a configuration's brackets, braces and
114
+ * quotes travel as `%5B`, `%7B` and `%22` rather than as characters a chat client, a markdown reader or
115
+ * a terminal cuts the address at. What is left is what {@link FragmentSafe} lists: a fragment is not a
116
+ * query, so `,`, `:` and `;` stand in it as they are and keep a link readable. `&` and `+` are escaped
117
+ * beyond that, the first because it separates the fields here and the second because a reader takes it
118
+ * for a space. A link is also made not to end on punctuation, because that is where a chat client stops
119
+ * reading it.
111
120
  */
112
121
  hash(this: void, fields: readonly (readonly [string, string])[]): string;
113
122
  /**
@@ -23,6 +23,12 @@ const FoundMarkPattern = /^(lint|dep):[^@,]+(@\d+)?$/;
23
23
  const MaxExpandedRange = 500;
24
24
  /** the longest link the page still opens, and the longest a chat client hands on in one piece */
25
25
  const MaxSharedLink = 4000;
26
+ /**
27
+ * What a fragment carries unescaped: the unreserved characters plus the sub-delimiters a link is still read
28
+ * with, minus `&` and `+`, which mean something of their own here. The `u` flag keeps a character outside the
29
+ * basic plane one match, so escaping never splits a surrogate pair.
30
+ */
31
+ const FragmentSafe = /[^A-Za-z0-9\-._~!$'()*,;:@/?=]/gu;
26
32
  /**
27
33
  * The helper object associated with {@link PlaygroundMark}, which makes it easy to check a mark and to
28
34
  * keep a list of them as short as a link should be.
@@ -104,7 +110,7 @@ exports.Playground = {
104
110
  fields.push(['c', (0, url_encoding_1.packForUrl)(code)]);
105
111
  }
106
112
  if (config.length > 0) {
107
- fields.push(['k', config.join(';')]);
113
+ fields.push(['k', exports.Playground.packConfig(config)]);
108
114
  }
109
115
  const kept = exports.PlaygroundMark.compress(marks);
110
116
  if (kept.length > 0) {
@@ -135,18 +141,36 @@ exports.Playground = {
135
141
  return hash.length > 0 ? `${base}#${hash}` : base;
136
142
  },
137
143
  /**
138
- * A fragment is not a query, so `,`, `:`, and the braces a configuration carries stand in it as they
139
- * are and only what would end it, split it, or read back as something else has to be escaped. `<` and
140
- * `>` go together: both are excluded from a URI, and a bare one of either ends the autolink a chat
141
- * client or a markdown reader made of the address. A link is also made not to end on punctuation,
142
- * because that is where a chat client stops reading it.
144
+ * The configuration keys as one field. A key is `a.b.c=<json>`, and the json is brackets, braces and quotes
145
+ * that a fragment does not carry, so it travels packed like the script rather than as a run of `%5B`.
146
+ */
147
+ packConfig(config) {
148
+ return (0, url_encoding_1.packForUrl)(config.join(';'));
149
+ },
150
+ /** The keys back out of that field, which older links wrote out plainly and which is read either way. */
151
+ unpackConfig(field) {
152
+ if (!field) {
153
+ return [];
154
+ }
155
+ /* a key carries its `=`, and neither packing produces one, so what has one was written before they did */
156
+ const text = field.includes('=') ? field : (0, url_encoding_1.unpackFromUrl)(field) ?? '';
157
+ return text.split(';').filter(key => key.length > 0);
158
+ },
159
+ /**
160
+ * Everything a fragment does not carry as itself is escaped, so a configuration's brackets, braces and
161
+ * quotes travel as `%5B`, `%7B` and `%22` rather than as characters a chat client, a markdown reader or
162
+ * a terminal cuts the address at. What is left is what {@link FragmentSafe} lists: a fragment is not a
163
+ * query, so `,`, `:` and `;` stand in it as they are and keep a link readable. `&` and `+` are escaped
164
+ * beyond that, the first because it separates the fields here and the second because a reader takes it
165
+ * for a space. A link is also made not to end on punctuation, because that is where a chat client stops
166
+ * reading it.
143
167
  */
144
168
  hash(fields) {
145
169
  const hash = fields
146
170
  .filter(([, value]) => value.length > 0)
147
- .map(([key, value]) => `${key}=${value.replace(/[%&#+<>\s]/g, character => encodeURIComponent(character))}`)
171
+ .map(([key, value]) => `${key}=${value.replace(FragmentSafe, character => encodeURIComponent(character))}`)
148
172
  .join('&');
149
- return hash.replace(/[.,:;"')\]]$/, character => encodeURIComponent(character));
173
+ return hash.replace(/[.,:;')]$/, character => encodeURIComponent(character));
150
174
  },
151
175
  /**
152
176
  * Where a criterion points in the given code, as the `<line>:<column>` the page opens the cursor on.
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.4';
45
+ const version = '2.15.8';
46
46
  // this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
47
- const versionDate = '2026-08-26T17:54:03Z';
47
+ const versionDate = '2026-08-27T16:01:04Z';
48
48
  /**
49
49
  * Retrieves the current flowR version as a new {@link SemVer} object.
50
50
  */