@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
@@ -121,14 +121,37 @@ class DataflowGraph {
121
121
  * bulk write (`mergeEdges`, `fromJson`): rebuilding it per lookup made every caller asking for the ingoing
122
122
  * edges of many nodes scan the whole graph once per node */
123
123
  incomingIndex;
124
+ /* tag to the ids carrying it; a lookup re-checks the vertex, as another graph may retag an object they share */
124
125
  types = new Map();
126
+ /** The id list of `tag`, created on first use, so a caller adding many ids looks it up once. */
127
+ typeList(tag) {
128
+ let ids = this.types.get(tag);
129
+ if (ids === undefined) {
130
+ this.types.set(tag, ids = []);
131
+ }
132
+ return ids;
133
+ }
134
+ indexType(tag, id) {
135
+ this.typeList(tag).push(id);
136
+ }
137
+ /** Every write above keeps an id listed under one tag at most once, so a lookup never hands the same one out twice. */
138
+ unindexType(tag, id) {
139
+ const ids = this.types.get(tag);
140
+ if (ids === undefined) {
141
+ return;
142
+ }
143
+ for (let idx = ids.lastIndexOf(id); idx >= 0; idx = ids.lastIndexOf(id)) {
144
+ ids.splice(idx, 1);
145
+ }
146
+ }
125
147
  /* the qualified call names, built on demand and dropped on every change, as vertices and edges both decide them */
126
148
  qualifiedNames;
127
149
  toJSON() {
128
150
  return {
129
151
  rootVertices: Array.from(this.rootVertices),
130
- vertexInformation: Array.from(this.vertexInformation.entries()),
131
- edgeInformation: Array.from(this.edgeInformation.entries()).map(([id, edges]) => [id, Array.from(edges.entries())]),
152
+ vertexInformation: Array.from(this.vertexInformation),
153
+ /* mapping inside `Array.from`, a trailing `.map()` would build the outer array twice */
154
+ edgeInformation: Array.from(this.edgeInformation, ([id, edges]) => [id, Array.from(edges)]),
132
155
  _unknownSideEffects: Array.from(this._unknownSideEffects)
133
156
  };
134
157
  }
@@ -225,8 +248,11 @@ class DataflowGraph {
225
248
  cache.bare.set(id, bare);
226
249
  cache.baseR.set(id, baseR);
227
250
  }
228
- /** Drops the cached qualifications, as the graph may no longer imply them */
251
+ /** set by a `consume` merge, see {@link DataflowGraph#mergeWith|mergeWith()}; the graph must not change after that */
252
+ consumed = false;
253
+ /** Drops the cached qualifications, as the graph may no longer imply them. Every mutator runs through here, so the guard covers them all. */
229
254
  dropQualifications() {
255
+ (0, assert_1.guard)(!this.consumed, 'this graph was consumed by a merge and must not be changed any more');
230
256
  if (this.qualifiedNames !== undefined) {
231
257
  this.qualifiedNames = undefined;
232
258
  }
@@ -267,14 +293,27 @@ class DataflowGraph {
267
293
  }
268
294
  }
269
295
  }
296
+ /** Every vertex carrying `type`, in the order the graph learned of them. */
270
297
  *verticesOfType(type) {
271
- const ids = this.types.get(type) ?? [];
298
+ const ids = this.types.get(type);
299
+ if (ids === undefined) {
300
+ return;
301
+ }
272
302
  for (const id of ids) {
273
- yield [id, this.vertexInformation.get(id)];
303
+ const vertex = this.vertexInformation.get(id);
304
+ /* a stale entry would hand out a vertex without the fields its tag promises */
305
+ if (vertex?.tag === type) {
306
+ yield [id, vertex];
307
+ }
274
308
  }
275
309
  }
310
+ /** The ids of {@link DataflowGraph#verticesOfType|verticesOfType}, as a fresh array the caller may keep. */
276
311
  vertexIdsOfType(type) {
277
- return this.types.get(type) ?? [];
312
+ const ids = this.types.get(type);
313
+ if (ids === undefined) {
314
+ return [];
315
+ }
316
+ return ids.filter(id => this.vertexInformation.get(id)?.tag === type);
278
317
  }
279
318
  /** Ids of all edges in the graph together with their edge information, see {@link DataflowGraph#vertices}. */
280
319
  *edges() {
@@ -325,23 +364,32 @@ class DataflowGraph {
325
364
  */
326
365
  addVertex(vertex, fallbackEnv, asRoot = true, overwrite = false) {
327
366
  const vid = vertex.id;
328
- if (this.vertexInformation.has(vid) && !overwrite) {
367
+ const previous = this.vertexInformation.get(vid);
368
+ if (previous !== undefined && !overwrite) {
329
369
  return this;
330
370
  }
331
371
  this.dropQualifications();
332
372
  const vtag = vertex.tag;
333
373
  // keep a clone of the original environment, isolating the snapshot from later updates
334
- vertex.environment = vertex.environment ? (0, clone_1.cloneEnvironmentInformation)(vertex.environment) : (vtag === vertex_1.VertexType.FunctionDefinition || (vtag === vertex_1.VertexType.FunctionCall && !vertex.onlyBuiltin) ? fallbackEnv : undefined);
374
+ let environment;
375
+ if (vertex.environment) {
376
+ environment = (0, clone_1.cloneEnvironmentInformation)(vertex.environment);
377
+ }
378
+ else if (vtag === vertex_1.VertexType.FunctionDefinition || (vtag === vertex_1.VertexType.FunctionCall && !vertex.onlyBuiltin)) {
379
+ /* only here is a fallback wanted, so a thunk spares every other vertex one it would discard */
380
+ environment = typeof fallbackEnv === 'function' ? fallbackEnv() : fallbackEnv;
381
+ }
382
+ vertex.environment = environment;
335
383
  this.vertexInformation.set(vid, vertex);
336
384
  if (gas_1.activeDataflowBudget !== undefined) {
337
385
  gas_1.activeDataflowBudget.vertex();
338
386
  }
339
- const typeIds = this.types.get(vtag);
340
- if (typeIds) {
341
- typeIds.push(vid);
342
- }
343
- else {
344
- this.types.set(vtag, [vid]);
387
+ /* an overwrite keeping the tag is indexed already */
388
+ if (previous?.tag !== vtag) {
389
+ if (previous !== undefined) {
390
+ this.unindexType(previous.tag, vid);
391
+ }
392
+ this.indexType(vtag, vid);
345
393
  }
346
394
  if (asRoot) {
347
395
  this.rootVertices.add(vid);
@@ -384,26 +432,20 @@ class DataflowGraph {
384
432
  }
385
433
  return this;
386
434
  }
387
- /** Merges `otherGraph` into *this* one in-place (the return value is only for convenience); `mergeRootVertices = false` excludes its root vertices (useful when merging in a function definition). */
388
- mergeWith(otherGraph, mergeRootVertices = true) {
435
+ /**
436
+ * Merges `otherGraph` into *this* one in-place (the return value is only for convenience);
437
+ * `mergeRootVertices = false` excludes its root vertices (useful when merging in a function definition).
438
+ *
439
+ * `consume` takes `otherGraph`'s edge tables instead of copying them (perf). Pass it only for a graph that dies with the call.
440
+ */
441
+ mergeWith(otherGraph, mergeRootVertices = true, consume = false) {
389
442
  if (otherGraph === undefined || otherGraph === this) {
390
443
  return this;
391
444
  }
445
+ (0, assert_1.guard)(!otherGraph.consumed, 'a graph consumed by an earlier merge cannot be merged again');
392
446
  this.mergeVertices(otherGraph, mergeRootVertices);
393
- for (const [type, ids] of otherGraph.types) {
394
- const existing = this.types.get(type);
395
- if (existing) {
396
- if (existing !== ids) {
397
- for (const id of ids) {
398
- existing.push(id);
399
- }
400
- }
401
- }
402
- else {
403
- this.types.set(type, ids.slice());
404
- }
405
- }
406
- this.mergeEdges(otherGraph);
447
+ this.mergeEdges(otherGraph, consume);
448
+ otherGraph.consumed ||= consume;
407
449
  return this;
408
450
  }
409
451
  mergeVertices(otherGraph, mergeRootVertices = true) {
@@ -417,19 +459,34 @@ class DataflowGraph {
417
459
  for (const unknown of otherGraph.unknownSideEffects) {
418
460
  this._unknownSideEffects.add(unknown);
419
461
  }
462
+ /* the tags of the vertices coming in repeat, so the list each goes on is looked up only when it changes */
463
+ let lastTag;
464
+ let lastIds = [];
420
465
  for (const [id, info] of otherGraph.vertexInformation) {
421
466
  const currentInfo = this.vertexInformation.get(id);
422
- this.vertexInformation.set(id, currentInfo === undefined ? info : mergeNodeInfos(currentInfo, info));
467
+ if (currentInfo === undefined) {
468
+ this.vertexInformation.set(id, info);
469
+ if (info.tag !== lastTag) {
470
+ lastIds = this.typeList(lastTag = info.tag);
471
+ }
472
+ lastIds.push(id);
473
+ }
474
+ else {
475
+ /* a known vertex keeps its tag, and with it its place in the index */
476
+ const merged = mergeNodeInfos(currentInfo, info);
477
+ if (merged !== currentInfo) {
478
+ this.vertexInformation.set(id, merged);
479
+ }
480
+ }
423
481
  }
424
482
  }
425
- mergeEdges(otherGraph) {
483
+ mergeEdges(otherGraph, consume = false) {
426
484
  this.dropQualifications();
427
485
  this.incomingIndex = undefined;
428
- for (const [id, edges] of otherGraph.edgeInformation.entries()) {
429
- let existing = this.edgeInformation.get(id);
486
+ for (const [id, edges] of otherGraph.edgeInformation) {
487
+ const existing = this.edgeInformation.get(id);
430
488
  if (existing === undefined) {
431
- existing = new Map(edges);
432
- this.edgeInformation.set(id, existing);
489
+ this.edgeInformation.set(id, consume ? edges : new Map(edges));
433
490
  }
434
491
  else {
435
492
  for (const [target, edge] of edges) {
@@ -459,19 +516,8 @@ class DataflowGraph {
459
516
  if (sourceIds) {
460
517
  vertex.source = sourceIds;
461
518
  }
462
- const oldIds = this.types.get(oldTag);
463
- if (oldIds) {
464
- for (let idx = oldIds.lastIndexOf(vid); idx >= 0; idx = oldIds.lastIndexOf(vid)) {
465
- oldIds.splice(idx, 1);
466
- }
467
- }
468
- const newIds = this.types.get(vertex_1.VertexType.VariableDefinition);
469
- if (newIds) {
470
- newIds.push(vid);
471
- }
472
- else {
473
- this.types.set(vertex_1.VertexType.VariableDefinition, [vid]);
474
- }
519
+ this.unindexType(oldTag, vid);
520
+ this.indexType(vertex_1.VertexType.VariableDefinition, vid);
475
521
  }
476
522
  }
477
523
  /** Marks the vertex `info.id` in the graph to be a function call with the new `info`. */
@@ -482,19 +528,8 @@ class DataflowGraph {
482
528
  (0, assert_1.guard)(vertex !== undefined && (vertex_2.UseVertex.is(vertex) || vertex_2.ValueVertex.is(vertex)), () => `node must be a use or value node for ${JSON.stringify(info.id)} to update it to a function call but is ${vertex?.tag}`);
483
529
  const previousTag = vertex.tag;
484
530
  this.vertexInformation.set(infoId, { ...vertex, ...info, tag: vertex_1.VertexType.FunctionCall });
485
- const prevIds = this.types.get(previousTag);
486
- if (prevIds) {
487
- for (let idx = prevIds.lastIndexOf(infoId); idx >= 0; idx = prevIds.lastIndexOf(infoId)) {
488
- prevIds.splice(idx, 1);
489
- }
490
- }
491
- const callIds = this.types.get(vertex_1.VertexType.FunctionCall);
492
- if (callIds) {
493
- callIds.push(infoId);
494
- }
495
- else {
496
- this.types.set(vertex_1.VertexType.FunctionCall, [infoId]);
497
- }
531
+ this.unindexType(previousTag, infoId);
532
+ this.indexType(vertex_1.VertexType.FunctionCall, infoId);
498
533
  }
499
534
  /** If you do not pass the `to` node, this will just mark the node as maybe */
500
535
  addControlDependency(from, to, when) {
@@ -531,10 +566,12 @@ class DataflowGraph {
531
566
  const graph = new DataflowGraph(undefined);
532
567
  graph.rootVertices = new Set(data.rootVertices);
533
568
  graph.vertexInformation = new Map(data.vertexInformation);
534
- for (const [, vertex] of graph.vertexInformation) {
569
+ for (const [id, vertex] of graph.vertexInformation) {
535
570
  if (vertex.environment) {
536
571
  vertex.environment = renvFromJson(vertex.environment);
537
572
  }
573
+ /* the index is not serialized, without rebuilding it every lookup by tag comes up empty */
574
+ graph.indexType(vertex.tag, id);
538
575
  }
539
576
  graph.edgeInformation = new Map(data.edgeInformation.map(([id, edges]) => [id, new Map(edges)]));
540
577
  graph.incomingIndex = undefined;
@@ -571,7 +608,7 @@ function envFromJson(json) {
571
608
  }
572
609
  const obj = new environment_1.Environment(parent, json.builtInEnv);
573
610
  obj.id = json.id;
574
- obj.memory = memory;
611
+ obj.adoptMap(memory);
575
612
  const env = obj;
576
613
  env.n = json.n;
577
614
  env.t = json.t;
@@ -59,7 +59,7 @@ exports.FunctionCallVertex = {
59
59
  * Deliberately not a type predicate: a `false` says nothing about the tag, the call may simply carry another origin.
60
60
  */
61
61
  hasOrigin(vertex, origin) {
62
- return exports.FunctionCallVertex.is(vertex) && vertex.origin.includes(origin);
62
+ return exports.FunctionCallVertex.is(vertex) && vertex.origin?.includes(origin) === true;
63
63
  }
64
64
  };
65
65
  /**
@@ -36,18 +36,22 @@ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
36
36
  * Find all reads within the graph that do not reference a local definition in the graph.
37
37
  */
38
38
  function findNonLocalReads(graph, ignores = new Set()) {
39
- const defs = new Set(graph.vertexIdsOfType(vertex_1.VertexType.VariableDefinition).concat(graph.vertexIdsOfType(vertex_1.VertexType.FunctionDefinition)));
39
+ const defs = new Set();
40
+ for (const tag of [vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition]) {
41
+ for (const [id] of graph.verticesOfType(tag)) {
42
+ defs.add(id);
43
+ }
44
+ }
40
45
  /* find all variable use ids which do not link to a given id */
41
46
  const nonLocalReads = [];
42
- for (const ids of [graph.vertexIdsOfType(vertex_1.VertexType.Use), graph.vertexIdsOfType(vertex_1.VertexType.FunctionCall)]) {
43
- for (const nodeId of ids) {
47
+ /* the tag already says what the reference is, so no vertex has to be fetched to decide */
48
+ for (const [tag, type] of [[vertex_1.VertexType.Use, identifier_1.ReferenceType.Variable], [vertex_1.VertexType.FunctionCall, identifier_1.ReferenceType.Function]]) {
49
+ for (const [nodeId] of graph.verticesOfType(tag)) {
44
50
  if (ignores.has(nodeId)) {
45
51
  continue;
46
52
  }
47
53
  const outgoing = graph.outgoingEdges(nodeId);
48
- const origin = graph.getVertex(nodeId);
49
54
  const name = node_id_1.NodeId.recoverName(nodeId, graph.idMap);
50
- const type = vertex_2.FunctionCallVertex.is(origin) ? identifier_1.ReferenceType.Function : identifier_1.ReferenceType.Variable;
51
55
  const identifierRef = { nodeId, name, type };
52
56
  /* control flow edges say nothing about what a name resolves to, so they do not count as a link */
53
57
  let linked = false;
@@ -123,7 +123,7 @@ function processApply(name, args, rootId, data, config) {
123
123
  cds: data.cds,
124
124
  args: allOtherArguments, // same reference
125
125
  origin: [built_in_proc_name_1.BuiltInProcName.Function]
126
- }, data.ctx.env.makeCleanEnv());
126
+ }, data.ctx.env.cleanEnv);
127
127
  information.graph.addEdge(rootId, rootFnId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
128
128
  information.graph.addEdge(rootId, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Argument);
129
129
  information = {
@@ -264,7 +264,8 @@ function processExpressionList(name, args, rootId, data) {
264
264
  data.environment = environment;
265
265
  const processed = (0, processor_1.processDataflowFor)(expression, data);
266
266
  processedExpressions.push(processed);
267
- nextGraph.mergeWith(processed.graph);
267
+ /* the expression's graph dies here, what is kept of it afterward is its entry point and its references */
268
+ nextGraph.mergeWith(processed.graph, true, true);
268
269
  defaultReturnExpr = processed;
269
270
  // a prior next/break means we do not know if the rest executes, so later environments append rather than overwrite
270
271
  if (exitPoints.length > 0) {
@@ -43,7 +43,8 @@ function processForLoop(name, args, rootId, data) {
43
43
  // this should not be able to exit always!
44
44
  const originalDependency = data.cds;
45
45
  let headEnvironments = (0, overwrite_1.overwriteEnvironment)(vector.environment, variable.environment);
46
- const headGraph = variable.graph.mergeWith(vector.graph);
46
+ /* only the vector's references and entry point are read past this, its graph is not */
47
+ const headGraph = variable.graph.mergeWith(vector.graph, true, true);
47
48
  const writtenVariable = variable.unknownReferences.concat(variable.in);
48
49
  const writtenIds = new Set();
49
50
  for (const write of writtenVariable) {
@@ -57,7 +58,8 @@ function processForLoop(name, args, rootId, data) {
57
58
  const cd = [{ id: name.info.id, when: true }];
58
59
  const bodyRefs = body.in.concat(body.unknownReferences);
59
60
  (0, reference_to_maybe_1.applyCdsToAllInGraphButConstants)(body.graph, bodyRefs, cd);
60
- const nextGraph = headGraph.mergeWith(body.graph);
61
+ /* likewise the body's, what is taken from it afterwards are its references, exit points and hooks */
62
+ const nextGraph = headGraph.mergeWith(body.graph, true, true);
61
63
  // now we have to identify all reads that may be effected by a circular redefinition
62
64
  // for this, we search for all reads with a non-local read resolve!
63
65
  const nameIdShares = (0, linker_1.produceNameSharedIdMap)((0, linker_1.findNonLocalReads)(nextGraph, writtenIds));
@@ -138,7 +138,7 @@ function processFunctionDefinition(name, args, rootId, data) {
138
138
  id: read.nodeId,
139
139
  environment: undefined,
140
140
  cds: undefined
141
- }, data.ctx.env.makeCleanEnv());
141
+ }, data.ctx.env.cleanEnv);
142
142
  }
143
143
  }
144
144
  const compactedHooks = (0, hooks_1.compactHookStates)(body.hooks);
@@ -229,7 +229,7 @@ function processFunctionDefinition(name, args, rootId, data) {
229
229
  subflow: flow,
230
230
  exitPoints: afterHookExitPoints,
231
231
  returnEnvState
232
- }, data.ctx.env.makeCleanEnv());
232
+ }, data.ctx.env.cleanEnv);
233
233
  return {
234
234
  /* nothing escapes a function definition, but the function itself, will be forced in assignment: { nodeId: functionDefinition.info.id, scope: data.activeScope, used: 'always', name: functionDefinition.info.id as string } */
235
235
  unknownReferences: [],
@@ -283,7 +283,7 @@ function attachExportVertex(graph, builtInId, environment, ctx, cds) {
283
283
  environment, cds, params: {},
284
284
  subflow: { graph: new Set(), unknownReferences: [], in: [], out: [], environment, entryPoint: builtInId, hooks: [] },
285
285
  exitPoints: [],
286
- }, ctx.env.makeCleanEnv());
286
+ }, ctx.env.cleanEnv);
287
287
  }
288
288
  /** Reserved marker binding recording an unresolved `library()`/`require()` load; the leading space cannot collide with a real export name. */
289
289
  const libraryLoadMarker = ' library-load';
@@ -567,7 +567,7 @@ function attachStatedDefinitions(pack, envInfo, ctx, spec, as, loadedAt, cds) {
567
567
  }
568
568
  const layer = new environment_1.Environment(envInfo.current)
569
569
  .asLibrary(pack, as ?? (spec.namespaceOnly ? environment_1.EnvType.LoadedNamespace : environment_1.EnvType.Namespace));
570
- layer.memory = memory;
570
+ layer.adoptMap(memory);
571
571
  return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, layer, layer, spec.pos) };
572
572
  }
573
573
  /**
@@ -49,7 +49,7 @@ function processNamespaceAccess(name, args, rootId, data, config) {
49
49
  tag: vertex_1.VertexType.Use,
50
50
  id: rootId,
51
51
  cds: data.cds
52
- }, data.ctx.env.makeCleanEnv()),
52
+ }, data.ctx.env.cleanEnv),
53
53
  entryPoint: rootId,
54
54
  exitPoints: [{ nodeId: rootId, type: 0 /* ExitPointType.Default */, cds: data.cds }],
55
55
  hooks: []
@@ -161,11 +161,18 @@ function* escapeTargetFrames(fdef) {
161
161
  * dominated by the built-ins it holds, so filtering each frame once per pass saves the bulk of the work.
162
162
  */
163
163
  function escapedDefinitions() {
164
+ /* keyed by frame and then by version: one frame answers differently at each, so the version has to be part of it */
164
165
  const perFrame = new Map();
165
166
  return (_id, fdef) => {
166
167
  const defs = [];
167
168
  for (const e of escapeTargetFrames(fdef)) {
168
- let escaped = perFrame.get(e.memory);
169
+ const { frame, version } = e.memory;
170
+ let byVersion = perFrame.get(frame);
171
+ if (byVersion === undefined) {
172
+ byVersion = new Map();
173
+ perFrame.set(frame, byVersion);
174
+ }
175
+ let escaped = byVersion.get(version);
169
176
  if (escaped === undefined) {
170
177
  /* a package frame holds thousands of entries and keeps none of them, so this walks them in place
171
178
  * rather than through a spread/flatMap/filter/map chain that allocates an array per step */
@@ -178,7 +185,7 @@ function escapedDefinitions() {
178
185
  }
179
186
  }
180
187
  escaped = collected;
181
- perFrame.set(e.memory, escaped);
188
+ byVersion.set(version, escaped);
182
189
  }
183
190
  for (const d of escaped) {
184
191
  defs.push(d);
@@ -242,16 +249,23 @@ function propagateTransitivePackages(graph, environment, ctx) {
242
249
  /** Maps each escaped definition's node id to its full (name-carrying) definition. */
243
250
  function escapedDefinitionMap(graph) {
244
251
  const map = new Map();
245
- const seen = new Set();
252
+ /* a frame answers differently at each version, so a visit is only a repeat when both match */
253
+ const seen = new Map();
246
254
  for (const [, vertex] of graph.vertices(true)) {
247
255
  if (!vertex_1.FunctionDefinitionVertex.is(vertex)) {
248
256
  continue;
249
257
  }
250
258
  for (const e of escapeTargetFrames(vertex)) {
251
- if (seen.has(e.memory)) {
259
+ const { frame, version } = e.memory;
260
+ let versions = seen.get(frame);
261
+ if (versions === undefined) {
262
+ versions = new Set();
263
+ seen.set(frame, versions);
264
+ }
265
+ else if (versions.has(version)) {
252
266
  continue; // a frame shared with an already-visited definition contributes the same entries
253
267
  }
254
- seen.add(e.memory);
268
+ versions.add(version);
255
269
  for (const definitions of e.memory.values()) {
256
270
  for (const def of definitions) {
257
271
  if (!node_id_1.NodeId.isBuiltIn(def.nodeId) && def.name !== undefined) {
@@ -104,8 +104,11 @@ function processAllArguments({ functionName, args, data, finalGraph, functionRoo
104
104
  continue;
105
105
  }
106
106
  let processed;
107
+ /* a precomputed argument is handed in from elsewhere and stays alive there, only a freshly built one dies here */
108
+ let ownsGraph = true;
107
109
  if (i === 0 && data.precomputedFirstArg?.rootId === functionRootId) {
108
110
  processed = data.precomputedFirstArg.info;
111
+ ownsGraph = false;
109
112
  }
110
113
  else {
111
114
  processed = r_argument_1.RArgument.is(arg) ? (0, process_argument_1.processFunctionArgument)(arg, data) : (0, processor_1.processDataflowFor)(arg, data);
@@ -115,7 +118,8 @@ function processAllArguments({ functionName, args, data, finalGraph, functionRoo
115
118
  }
116
119
  processedArguments.push(processed);
117
120
  finalEnv = (0, overwrite_1.overwriteEnvironment)(finalEnv, processed.environment);
118
- finalGraph.mergeWith(processed.graph);
121
+ /* nothing reads the argument's own graph past this point, only its entry point and references */
122
+ finalGraph.mergeWith(processed.graph, true, ownsGraph);
119
123
  // resolve reads within argument, we resolve before adding the `processed.environment` to avoid cyclic dependencies
120
124
  for (const l of [processed.in, processed.unknownReferences]) {
121
125
  for (const original of l) {
@@ -176,7 +180,7 @@ function patchFunctionCall({ nextGraph, rootId, name, data, argumentProcessResul
176
180
  args: argumentProcessResult.map(arg => arg === undefined ? r_function_call_1.EmptyArgument : { nodeId: arg.entryPoint, cds: undefined, call: undefined, type: identifier_1.ReferenceType.Argument }),
177
181
  origin: [origin],
178
182
  link
179
- }, data.ctx.env.makeCleanEnv(), !nextGraph.hasVertex(rootId) || nextGraph.isRoot(rootId), true);
183
+ }, data.ctx.env.cleanEnv, !nextGraph.hasVertex(rootId) || nextGraph.isRoot(rootId), true);
180
184
  for (const arg of argumentProcessResult) {
181
185
  if (arg) {
182
186
  nextGraph.addEdge(rootId, arg.entryPoint, edge_1.EdgeType.Argument);
@@ -113,7 +113,7 @@ function processKnownFunctionCall({ name, args, rootId, data, reverseOrder = fal
113
113
  cds: data.cds,
114
114
  args: reverseOrder ? callArgs.toReversed() : callArgs,
115
115
  origin: origin === 'default' ? [built_in_proc_name_1.BuiltInProcName.Function] : [origin]
116
- }, data.ctx.env.makeCleanEnv());
116
+ }, data.ctx.env.cleanEnv);
117
117
  if (hasUnknownSideEffect) {
118
118
  (0, unknown_side_effect_1.handleUnknownSideEffect)(finalGraph, data.environment, rootId);
119
119
  }
@@ -32,7 +32,7 @@ const EvaluatingElsewhereCalls = new Set(['evalq']);
32
32
  */
33
33
  const ValueFlow = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument;
34
34
  function hasOrigin(vertex, of) {
35
- return vertex.origin !== 'unnamed' && vertex.origin.some(o => of.includes(o));
35
+ return Array.isArray(vertex.origin) && vertex.origin.some(o => of.includes(o));
36
36
  }
37
37
  /**
38
38
  * A language object reads nothing where it is written and everything where it reaches `eval`, with the bindings
@@ -68,7 +68,7 @@ function processUnnamedFunctionCall(functionCall, data) {
68
68
  cds: data.cds,
69
69
  args: callArgs, // same reference
70
70
  origin: [built_in_proc_name_1.BuiltInProcName.Unnamed]
71
- }, data.ctx.env.makeCleanEnv());
71
+ }, data.ctx.env.cleanEnv);
72
72
  const cfgEntry = control_flow_1.ControlFlow.inSequence(finalGraph, [calledFunction, ...processedArguments], functionRootId);
73
73
  /* a jump within an argument is caught here, just like for a named call */
74
74
  for (const argument of processedArguments) {
@@ -48,7 +48,7 @@ function processFunctionArgument(argument, data) {
48
48
  tag: vertex_1.VertexType.Use,
49
49
  id: argument.info.id,
50
50
  cds: data.cds
51
- }, data.ctx.env.makeCleanEnv());
51
+ }, data.ctx.env.cleanEnv);
52
52
  entryPoint = argument.info.id;
53
53
  }
54
54
  const ingoingRefs = value ? value.unknownReferences.concat(value.in, name?.in ?? []) : name?.in;
@@ -25,7 +25,7 @@ function processSymbol(symbol, data) {
25
25
  tag: vertex_1.VertexType.Use,
26
26
  id: sid,
27
27
  cds: data.cds
28
- }, data.ctx.env.makeCleanEnv()),
28
+ }, data.ctx.env.cleanEnv),
29
29
  entryPoint: sid,
30
30
  exitPoints: [{ nodeId: sid, type: 0 /* ExitPointType.Default */, cds: data.cds }],
31
31
  hooks: []
package/index.d.ts CHANGED
@@ -17,6 +17,8 @@
17
17
  export { FlowrAnalyzer } from './project/flowr-analyzer';
18
18
  export type { FlowrAnalysisOptions, FlowrAnalysisProvider, ReadonlyFlowrAnalysisProvider } from './project/flowr-analyzer';
19
19
  export { FlowrAnalyzerBuilder } from './project/flowr-analyzer-builder';
20
+ export { Identifier } from './dataflow/environments/identifier';
21
+ export type { FnInfo } from './dataflow/environments/query-fn-props';
20
22
  export type { Query, QueryResults, SupportedQueryTypes } from './queries/query';
21
23
  export { SlicingCriteria, SlicingCriterion } from './slicing/criterion/parse';
22
24
  export { requestFromInput } from './r-bridge/retriever';
package/index.js CHANGED
@@ -16,12 +16,15 @@
16
16
  * @module
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.retrieveVersionInformation = exports.flowrVersion = exports.TREE_SITTER_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.TREE_SITTER_SLICING_PIPELINE = exports.TREE_SITTER_DATAFLOW_PIPELINE = exports.DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.DEFAULT_SLICING_PIPELINE = exports.DEFAULT_DATAFLOW_PIPELINE = exports.PipelineExecutor = exports.FlowrConfig = exports.TreeSitterExecutor = exports.RShell = exports.requestFromInput = exports.SlicingCriterion = exports.SlicingCriteria = exports.FlowrAnalyzerBuilder = exports.FlowrAnalyzer = void 0;
19
+ exports.retrieveVersionInformation = exports.flowrVersion = exports.TREE_SITTER_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.TREE_SITTER_SLICING_PIPELINE = exports.TREE_SITTER_DATAFLOW_PIPELINE = exports.DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE = exports.DEFAULT_SLICING_PIPELINE = exports.DEFAULT_DATAFLOW_PIPELINE = exports.PipelineExecutor = exports.FlowrConfig = exports.TreeSitterExecutor = exports.RShell = exports.requestFromInput = exports.SlicingCriterion = exports.SlicingCriteria = exports.Identifier = exports.FlowrAnalyzerBuilder = exports.FlowrAnalyzer = void 0;
20
20
  /* the analyzer, which is the front door: everything else here is what its methods hand you or take */
21
21
  var flowr_analyzer_1 = require("./project/flowr-analyzer");
22
22
  Object.defineProperty(exports, "FlowrAnalyzer", { enumerable: true, get: function () { return flowr_analyzer_1.FlowrAnalyzer; } });
23
23
  var flowr_analyzer_builder_1 = require("./project/flowr-analyzer-builder");
24
24
  Object.defineProperty(exports, "FlowrAnalyzerBuilder", { enumerable: true, get: function () { return flowr_analyzer_builder_1.FlowrAnalyzerBuilder; } });
25
+ /* what `functionInfo` takes and hands back */
26
+ var identifier_1 = require("./dataflow/environments/identifier");
27
+ Object.defineProperty(exports, "Identifier", { enumerable: true, get: function () { return identifier_1.Identifier; } });
25
28
  var parse_1 = require("./slicing/criterion/parse");
26
29
  Object.defineProperty(exports, "SlicingCriteria", { enumerable: true, get: function () { return parse_1.SlicingCriteria; } });
27
30
  Object.defineProperty(exports, "SlicingCriterion", { enumerable: true, get: function () { return parse_1.SlicingCriterion; } });
@@ -23,7 +23,7 @@ export declare const LintingRules: {
23
23
  readonly certainty: import("./linter-format").LintingRuleCertainty.BestEffort;
24
24
  readonly description: "Marks deprecated functions and deprecated arguments of still-current functions, offering the replacement as a quick fix where one is known. A call to a bare name whose package the code never attaches is reported as uncertain, as any function of that name would answer to it.";
25
25
  readonly defaultConfig: {
26
- readonly always: import("../dataflow/environments/identifier").Identifier[];
26
+ readonly always: import("..").Identifier[];
27
27
  readonly conditionally: Record<import("../dataflow/environments/identifier").BrandedIdentifier, import("./rules/deprecated-functions").DeprecatedFunctionInformation>;
28
28
  };
29
29
  };
@@ -475,7 +475,7 @@ export declare const LintingRules: {
475
475
  readonly system: {
476
476
  readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Process;
477
477
  readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
478
- readonly sanitizers: readonly [import("../dataflow/environments/identifier").Identifier];
478
+ readonly sanitizers: readonly [import("..").Identifier];
479
479
  readonly quickFix: {
480
480
  readonly call: "shQuote";
481
481
  };
@@ -483,14 +483,14 @@ export declare const LintingRules: {
483
483
  readonly eval: {
484
484
  readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Eval;
485
485
  readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
486
- readonly sanitizers: readonly [import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier];
486
+ readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier];
487
487
  };
488
488
  readonly database: {
489
489
  readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Database;
490
490
  readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
491
- readonly sanitizers: readonly [import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier];
491
+ readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier];
492
492
  readonly quickFix: {
493
- readonly call: import("../dataflow/environments/identifier").Identifier;
493
+ readonly call: import("..").Identifier;
494
494
  readonly firstArg: import("../dataflow/environments/built-in-props").ArgProp.Handle;
495
495
  readonly partsOnly: true;
496
496
  };
@@ -498,17 +498,17 @@ export declare const LintingRules: {
498
498
  readonly html: {
499
499
  readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.Html;
500
500
  readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
501
- readonly sanitizers: readonly [import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier];
501
+ readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier];
502
502
  readonly quickFix: {
503
- readonly call: import("../dataflow/environments/identifier").Identifier;
503
+ readonly call: import("..").Identifier;
504
504
  };
505
505
  };
506
506
  readonly javascript: {
507
507
  readonly criticalCalls: import("../dataflow/environments/built-in-props").SemanticCallTag.JavaScript;
508
508
  readonly criticalArgs: import("../dataflow/environments/built-in-props").ArgProp.Injectable;
509
- readonly sanitizers: readonly [import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier, import("../dataflow/environments/identifier").Identifier];
509
+ readonly sanitizers: readonly [import("..").Identifier, import("..").Identifier, import("..").Identifier, import("..").Identifier];
510
510
  readonly quickFix: {
511
- readonly call: import("../dataflow/environments/identifier").Identifier;
511
+ readonly call: import("..").Identifier;
512
512
  readonly partsOnly: true;
513
513
  };
514
514
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.15.2",
3
+ "version": "2.15.4",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "engines": {
6
6
  "node": ">=22"