@eagleoutice/flowr 2.10.6 → 2.10.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 (78) hide show
  1. package/README.md +9 -9
  2. package/abstract-interpretation/domains/multi-value-state-domain.d.ts +4 -10
  3. package/abstract-interpretation/domains/multi-value-state-domain.js +1 -6
  4. package/abstract-interpretation/domains/partial-product-domain.d.ts +6 -2
  5. package/abstract-interpretation/domains/partial-product-domain.js +7 -3
  6. package/control-flow/semantic-cfg-guided-visitor.js +1 -0
  7. package/dataflow/environments/built-in-proc-name.d.ts +22 -20
  8. package/dataflow/environments/built-in-proc-name.js +22 -20
  9. package/dataflow/environments/built-in.d.ts +19 -19
  10. package/dataflow/environments/identifier.d.ts +5 -0
  11. package/dataflow/environments/reference-to-maybe.js +32 -6
  12. package/dataflow/eval/resolve/alias-tracking.js +5 -0
  13. package/dataflow/graph/graph.js +51 -30
  14. package/dataflow/graph/vertex.d.ts +12 -11
  15. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +49 -12
  16. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -2
  17. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +12 -6
  18. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +22 -8
  19. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +57 -1
  20. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +1 -1
  21. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +7 -7
  22. package/documentation/wiki-linting-and-testing.js +1 -1
  23. package/documentation/wiki-mk/doc-context.d.ts +21 -1
  24. package/documentation/wiki-mk/doc-context.js +9 -0
  25. package/documentation/wiki-search.js +13 -2
  26. package/linter/linter-format.d.ts +4 -0
  27. package/linter/linter-rules.d.ts +9 -7
  28. package/linter/rules/absolute-path.d.ts +3 -2
  29. package/linter/rules/absolute-path.js +37 -12
  30. package/linter/rules/dataframe-access-validation.d.ts +4 -7
  31. package/linter/rules/dataframe-access-validation.js +3 -3
  32. package/linter/rules/dead-code.d.ts +4 -7
  33. package/linter/rules/file-path-validity.d.ts +9 -4
  34. package/linter/rules/file-path-validity.js +83 -36
  35. package/linter/rules/function-finder-util.d.ts +1 -3
  36. package/linter/rules/function-finder-util.js +2 -2
  37. package/linter/rules/naming-convention.d.ts +0 -2
  38. package/linter/rules/network-functions.js +4 -1
  39. package/linter/rules/problematic-inputs.d.ts +0 -2
  40. package/linter/rules/problematic-inputs.js +4 -1
  41. package/linter/rules/roxygen-arguments.d.ts +0 -2
  42. package/linter/rules/seeded-randomness.d.ts +0 -2
  43. package/linter/rules/stop-with-call-arg.d.ts +3 -6
  44. package/linter/rules/unused-definition.d.ts +0 -2
  45. package/linter/rules/useless-loop.d.ts +0 -2
  46. package/package.json +7 -6
  47. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -2
  48. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +2 -0
  49. package/queries/catalog/dependencies-query/function-info/read-functions.js +21 -1
  50. package/queries/catalog/dependencies-query/function-info/source-functions.js +1 -1
  51. package/queries/catalog/dependencies-query/function-info/write-functions.js +18 -1
  52. package/queries/catalog/input-sources-query/input-source-functions.d.ts +3 -1
  53. package/queries/catalog/input-sources-query/input-source-functions.js +322 -46
  54. package/queries/catalog/input-sources-query/input-sources-query-executor.js +14 -9
  55. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +4 -2
  56. package/queries/catalog/input-sources-query/input-sources-query-format.js +8 -4
  57. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +13 -6
  58. package/queries/catalog/input-sources-query/simple-input-classifier.js +33 -8
  59. package/queries/catalog/linter-query/linter-query-format.d.ts +2 -2
  60. package/queries/catalog/linter-query/linter-query-format.js +9 -3
  61. package/queries/query.d.ts +3 -2
  62. package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +1 -1
  63. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +16 -16
  64. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -0
  65. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +8 -0
  66. package/search/flowr-search-builder.d.ts +64 -16
  67. package/search/flowr-search-builder.js +41 -16
  68. package/search/flowr-search-filters.d.ts +10 -1
  69. package/search/flowr-search-filters.js +10 -0
  70. package/search/flowr-search.d.ts +17 -3
  71. package/search/search-executor/search-generators.d.ts +3 -1
  72. package/search/search-executor/search-generators.js +30 -4
  73. package/slicing/static/static-slicer.js +2 -2
  74. package/util/range.d.ts +13 -1
  75. package/util/range.js +32 -2
  76. package/util/text/strings.d.ts +7 -0
  77. package/util/text/strings.js +23 -0
  78. package/util/version.js +1 -1
@@ -303,20 +303,19 @@ class DataflowGraph {
303
303
  */
304
304
  addVertex(vertex, fallbackEnv, asRoot = true, overwrite = false) {
305
305
  const vid = vertex.id;
306
- const oldVertex = this.vertexInformation.get(vid);
307
- if (oldVertex !== undefined && !overwrite) {
306
+ if (this.vertexInformation.has(vid) && !overwrite) {
308
307
  return this;
309
308
  }
310
309
  const vtag = vertex.tag;
311
310
  // keep a clone of the original environment
312
311
  vertex.environment = vertex.environment ? (0, clone_1.cloneEnvironmentInformation)(vertex.environment) : (vtag === vertex_1.VertexType.FunctionDefinition || (vtag === vertex_1.VertexType.FunctionCall && !vertex.onlyBuiltin) ? fallbackEnv : undefined);
313
312
  this.vertexInformation.set(vid, vertex);
314
- const has = this.types.get(vertex.tag);
315
- if (has) {
316
- has.push(vid);
313
+ const typeIds = this.types.get(vtag);
314
+ if (typeIds) {
315
+ typeIds.push(vid);
317
316
  }
318
317
  else {
319
- this.types.set(vertex.tag, [vid]);
318
+ this.types.set(vtag, [vid]);
320
319
  }
321
320
  if (asRoot) {
322
321
  this.rootVertices.add(vid);
@@ -327,21 +326,20 @@ class DataflowGraph {
327
326
  if (fromId === toId) {
328
327
  return this;
329
328
  }
330
- const existingFrom = this.edgeInformation.get(fromId);
331
- const edgeInFrom = existingFrom?.get(toId);
332
- if (edgeInFrom === undefined) {
333
- const edge = { types: type };
334
- if (existingFrom === undefined) {
335
- this.edgeInformation.set(fromId, new Map([[toId, edge]]));
329
+ let fromEdges = this.edgeInformation.get(fromId);
330
+ if (fromEdges === undefined) {
331
+ fromEdges = new Map([[toId, { types: type }]]);
332
+ this.edgeInformation.set(fromId, fromEdges);
333
+ }
334
+ else {
335
+ const existing = fromEdges.get(toId);
336
+ if (existing === undefined) {
337
+ fromEdges.set(toId, { types: type });
336
338
  }
337
339
  else {
338
- existingFrom.set(toId, edge);
340
+ existing.types |= type;
339
341
  }
340
342
  }
341
- else {
342
- // adding the type
343
- edgeInFrom.types |= type;
344
- }
345
343
  return this;
346
344
  }
347
345
  /**
@@ -357,7 +355,12 @@ class DataflowGraph {
357
355
  this.mergeVertices(otherGraph, mergeRootVertices);
358
356
  for (const [type, ids] of otherGraph.types) {
359
357
  const existing = this.types.get(type);
360
- this.types.set(type, existing ? existing.concat(ids) : ids.slice());
358
+ if (existing) {
359
+ existing.push(...ids);
360
+ }
361
+ else {
362
+ this.types.set(type, ids.slice());
363
+ }
361
364
  }
362
365
  this.mergeEdges(otherGraph);
363
366
  return this;
@@ -379,12 +382,13 @@ class DataflowGraph {
379
382
  }
380
383
  mergeEdges(otherGraph) {
381
384
  for (const [id, edges] of otherGraph.edgeInformation.entries()) {
382
- for (const [target, edge] of edges) {
383
- const existing = this.edgeInformation.get(id);
384
- if (existing === undefined) {
385
- this.edgeInformation.set(id, new Map([[target, edge]]));
386
- }
387
- else {
385
+ let existing = this.edgeInformation.get(id);
386
+ if (existing === undefined) {
387
+ existing = new Map(edges);
388
+ this.edgeInformation.set(id, existing);
389
+ }
390
+ else {
391
+ for (const [target, edge] of edges) {
388
392
  const get = existing.get(target);
389
393
  if (get === undefined) {
390
394
  existing.set(target, edge);
@@ -409,12 +413,24 @@ class DataflowGraph {
409
413
  }
410
414
  else {
411
415
  const oldTag = vertex.tag;
416
+ const vid = reference.nodeId;
412
417
  vertex.tag = vertex_1.VertexType.VariableDefinition;
413
418
  if (sourceIds) {
414
419
  vertex.source = sourceIds;
415
420
  }
416
- this.types.set(oldTag, (this.types.get(oldTag) ?? []).filter(id => id !== reference.nodeId));
417
- this.types.set(vertex_1.VertexType.VariableDefinition, (this.types.get(vertex_1.VertexType.VariableDefinition) ?? []).concat([reference.nodeId]));
421
+ const oldIds = this.types.get(oldTag);
422
+ if (oldIds) {
423
+ for (let idx = oldIds.lastIndexOf(vid); idx >= 0; idx = oldIds.lastIndexOf(vid)) {
424
+ oldIds.splice(idx, 1);
425
+ }
426
+ }
427
+ const newIds = this.types.get(vertex_1.VertexType.VariableDefinition);
428
+ if (newIds) {
429
+ newIds.push(vid);
430
+ }
431
+ else {
432
+ this.types.set(vertex_1.VertexType.VariableDefinition, [vid]);
433
+ }
418
434
  }
419
435
  }
420
436
  /**
@@ -427,10 +443,15 @@ class DataflowGraph {
427
443
  (0, assert_1.guard)(vertex !== undefined && (vertex.tag === vertex_1.VertexType.Use || vertex.tag === vertex_1.VertexType.Value), () => `node must be a use or value node for ${JSON.stringify(info.id)} to update it to a function call but is ${vertex?.tag}`);
428
444
  const previousTag = vertex.tag;
429
445
  this.vertexInformation.set(infoId, { ...vertex, ...info, tag: vertex_1.VertexType.FunctionCall });
430
- this.types.set(previousTag, (this.types.get(previousTag) ?? []).filter(id => id !== infoId));
431
- const g = this.types.get(vertex_1.VertexType.FunctionCall);
432
- if (g) {
433
- g.push(infoId);
446
+ const prevIds = this.types.get(previousTag);
447
+ if (prevIds) {
448
+ for (let idx = prevIds.lastIndexOf(infoId); idx >= 0; idx = prevIds.lastIndexOf(infoId)) {
449
+ prevIds.splice(idx, 1);
450
+ }
451
+ }
452
+ const callIds = this.types.get(vertex_1.VertexType.FunctionCall);
453
+ if (callIds) {
454
+ callIds.push(infoId);
434
455
  }
435
456
  else {
436
457
  this.types.set(vertex_1.VertexType.FunctionCall, [infoId]);
@@ -5,6 +5,7 @@ import type { REnvironmentInformation } from '../environments/environment';
5
5
  import type { ControlDependency, ExitPoint } from '../info';
6
6
  import type { Identifier } from '../environments/identifier';
7
7
  import type { BuiltInProcName } from '../environments/built-in-proc-name';
8
+ import type { Value } from '../eval/values/r-value';
8
9
  export declare enum VertexType {
9
10
  Value = "value",
10
11
  Use = "use",
@@ -52,27 +53,22 @@ export interface DataflowGraphVertexAstLink {
52
53
  }
53
54
  /**
54
55
  * Marker vertex for a value in the dataflow of the program.
55
- * This does not contain the _value_ of the referenced constant
56
- * as this is available with the {@link DataflowGraphVertexBase#id|id} in the {@link NormalizedAst|normalized AST}
57
- * (or more specifically the {@link AstIdMap}).
58
- *
59
- * If you have a {@link DataflowGraph|dataflow graph} named `graph`
60
- * with an {@link AstIdMap} and a value vertex object with name `value` the following Code should work:
56
+ * For user-code constants (numbers, strings, logicals) the value is recovered by looking up the
57
+ * {@link DataflowGraphVertexBase#id|id} in the {@link NormalizedAst|normalized AST}:
61
58
  * @example
62
59
  * ```ts
63
60
  * const node = graph.idMap.get(value.id)
64
61
  * ```
65
62
  *
66
- * This then returns the corresponding node in the {@link NormalizedAst|normalized AST}, for example,
67
- * an {@link RNumber} or {@link RString}.
68
- *
69
- * This works similarly for {@link IdentifierReference|identifier references}
70
- * for which you can use the {@link IdentifierReference#nodeId|`nodeId`}.
63
+ * For built-in constants whose id is not in the {@link AstIdMap} (e.g. `T` resolving to `built-in:T`),
64
+ * the abstract {@link Value} is stored directly in the {@link DataflowGraphVertexValue#value|value} field.
71
65
  * @see {@link isValueVertex} - to check if a vertex is a value vertex
72
66
  */
73
67
  export interface DataflowGraphVertexValue extends DataflowGraphVertexBase {
74
68
  readonly tag: VertexType.Value;
75
69
  readonly environment?: undefined;
70
+ /** Pre-computed abstract value; set for built-in constants (e.g. `T`, `F`) whose id is not in the AST id map */
71
+ readonly value?: Value;
76
72
  }
77
73
  /**
78
74
  * Arguments required to construct a vertex which represents the usage of a variable in the {@link DataflowGraph|dataflow graph}.
@@ -159,6 +155,11 @@ export interface DataflowGraphVertexFunctionDefinition extends DataflowGraphVert
159
155
  * This is more of a convenience flag for later processing.
160
156
  */
161
157
  mode?: ('s3' | 's4' | 's7')[];
158
+ /**
159
+ * If this function statically returns a tracked environment, stores the envState it returns.
160
+ * Set by `processFunctionDefinition` when exit points include NewEnv calls or symbols resolving to tracked envs.
161
+ */
162
+ returnEnvState?: REnvironmentInformation;
162
163
  }
163
164
  /**
164
165
  * What is to be passed to construct a vertex in the {@link DataflowGraph|dataflow graph}
@@ -47,9 +47,7 @@ function findRootAccess(node) {
47
47
  if (current.type === type_1.RType.Symbol) {
48
48
  return current;
49
49
  }
50
- else {
51
- return undefined;
52
- }
50
+ return undefined;
53
51
  }
54
52
  function tryReplacement(rootId, functionName, data, name, args) {
55
53
  const resolved = (0, resolve_by_name_1.resolveByName)(functionName.content, data.environment, identifier_1.ReferenceType.Function) ?? [];
@@ -129,7 +127,7 @@ args, rootId, data, config) {
129
127
  data,
130
128
  reverseOrder: !config.swapSourceAndTarget,
131
129
  forceArgs: config.forceArgs,
132
- origin: built_in_proc_name_1.BuiltInProcName.Assignment
130
+ origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
133
131
  });
134
132
  return processAssignmentToSymbol({
135
133
  ...config,
@@ -155,7 +153,7 @@ args, rootId, data, config) {
155
153
  data,
156
154
  reverseOrder: !config.swapSourceAndTarget,
157
155
  forceArgs: config.forceArgs,
158
- origin: built_in_proc_name_1.BuiltInProcName.Assignment
156
+ origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
159
157
  });
160
158
  return processAssignmentToSymbol({
161
159
  ...config,
@@ -197,7 +195,7 @@ args, rootId, data, config) {
197
195
  data,
198
196
  reverseOrder: !config.swapSourceAndTarget,
199
197
  forceArgs: config.forceArgs,
200
- origin: built_in_proc_name_1.BuiltInProcName.Assignment
198
+ origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
201
199
  });
202
200
  return processAssignmentToSymbol({
203
201
  ...config,
@@ -217,7 +215,7 @@ args, rootId, data, config) {
217
215
  logger_1.dataflowLogger.warn(`Assignment ${identifier_1.Identifier.toString(name.content)} has an unknown target type ${target.type} => unknown impact`);
218
216
  const info = (0, known_call_handling_1.processKnownFunctionCall)({
219
217
  name, args: effectiveArgs, rootId, data, forceArgs: config.forceArgs,
220
- origin: built_in_proc_name_1.BuiltInProcName.Assignment
218
+ origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
221
219
  }).information;
222
220
  (0, unknown_side_effect_1.handleUnknownSideEffect)(info.graph, info.environment, rootId);
223
221
  return info;
@@ -267,7 +265,7 @@ function processAssignmentToString(target, args, name, rootId, data, config, sou
267
265
  data,
268
266
  reverseOrder: !config.swapSourceAndTarget,
269
267
  forceArgs: config.forceArgs,
270
- origin: built_in_proc_name_1.BuiltInProcName.Assignment
268
+ origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
271
269
  });
272
270
  return processAssignmentToSymbol({
273
271
  ...config,
@@ -326,14 +324,13 @@ function tryRouteDollarEnvAssign(rootId, data, config, target, source, replaceme
326
324
  return undefined;
327
325
  }
328
326
  const fieldName = (fieldNode.type === type_1.RType.String ? fieldNode.content.str : fieldNode.lexeme);
329
- /* run normal $<- replacement to get correct graph structure (reads of e, x, source) */
330
327
  const normalResult = tryReplacement(rootId, replacement, data, replacement.content, [(0, make_argument_1.toUnnamedArgument)(target.accessed, data.completeAst.idMap), ...target.access, source]);
331
328
  const fieldDef = {
332
329
  type: identifier_1.ReferenceType.Variable,
333
330
  name: fieldName,
334
331
  nodeId: fieldNode.info.id,
335
332
  definedAt: rootId,
336
- cds: data.cds
333
+ cds: data.cds ?? (config.makeMaybe ? [] : undefined)
337
334
  };
338
335
  const newEnvState = (0, define_1.define)(fieldDef, false, envirResolution.envDef.envState);
339
336
  const updatedEnvDef = {
@@ -345,6 +342,7 @@ function tryRouteDollarEnvAssign(rootId, data, config, target, source, replaceme
345
342
  current: normalResult.environment.current.removeAll([{ name: envirResolution.envDef.name }]),
346
343
  level: normalResult.environment.level
347
344
  };
345
+ normalResult.graph.addEdge(normalResult.entryPoint, target.accessed.info.id, edge_1.EdgeType.Reads);
348
346
  return { ...normalResult, environment: (0, define_1.define)(updatedEnvDef, false, strippedEnv) };
349
347
  }
350
348
  /**
@@ -415,18 +413,44 @@ function processAssignmentToSymbol(config) {
415
413
  : produceWrittenNodes(rootId, targetArg, referenceType, data, makeMaybe ?? false, aliases);
416
414
  if (data.ctx.config.solver.trackEnvironments) {
417
415
  let envState;
416
+ let returnsEnvState;
418
417
  if (isEnvCreatorSource(sourceArg)) {
419
418
  envState = (0, built_in_new_env_1.createFreshEnvState)(data, sourceArg);
420
419
  }
421
420
  else if (source.type === type_1.RType.Symbol) {
422
421
  const defs = (0, resolve_by_name_1.resolveByName)(source.content, data.environment, identifier_1.ReferenceType.Variable);
423
- envState = defs?.find(d => d.envState !== undefined)?.envState;
422
+ const def = defs?.find((d) => d.envState !== undefined);
423
+ envState = def?.envState;
424
+ if (!envState) {
425
+ const fnDef = defs?.find((d) => d.returnsEnvState !== undefined);
426
+ if (fnDef?.returnsEnvState) {
427
+ envState = fnDef.returnsEnvState;
428
+ }
429
+ }
430
+ }
431
+ else {
432
+ const entryVertex = sourceArg.graph.getVertex(sourceArg.entryPoint);
433
+ if ((0, vertex_1.isFunctionDefinitionVertex)(entryVertex) && entryVertex.returnEnvState !== undefined) {
434
+ returnsEnvState = entryVertex.returnEnvState;
435
+ }
436
+ else if ((0, vertex_1.isFunctionCallVertex)(entryVertex) && entryVertex.name) {
437
+ const fnDefs = (0, resolve_by_name_1.resolveByName)(entryVertex.name, data.environment, identifier_1.ReferenceType.Function);
438
+ const fnDef = fnDefs?.find((d) => d.returnsEnvState !== undefined);
439
+ if (fnDef?.returnsEnvState) {
440
+ envState = fnDef.returnsEnvState;
441
+ }
442
+ }
424
443
  }
425
444
  if (envState) {
426
445
  for (let i = 0; i < writeNodes.length; i++) {
427
446
  writeNodes[i] = { ...writeNodes[i], envState };
428
447
  }
429
448
  }
449
+ else if (returnsEnvState) {
450
+ for (let i = 0; i < writeNodes.length; i++) {
451
+ writeNodes[i] = { ...writeNodes[i], returnsEnvState };
452
+ }
453
+ }
430
454
  }
431
455
  if (writeNodes.length !== 1 && log_1.log.settings.minLevel >= 4 /* LogLevel.Warn */) {
432
456
  log_1.log.warn(`Unexpected write number in assignment: ${JSON.stringify(writeNodes)}`);
@@ -435,7 +459,20 @@ function processAssignmentToSymbol(config) {
435
459
  const readFromSourceWritten = sourceArg.out.slice(1);
436
460
  const readTargets = [
437
461
  { nodeId: rootId, name: nameOfAssignmentFunction, cds: data.cds, type: identifier_1.ReferenceType.Function }
438
- ].concat(sourceArg.unknownReferences, sourceArg.in, targetName ? targetArg.in : targetArg.in.filter(i => i.nodeId !== targetId), readFromSourceWritten);
462
+ ];
463
+ readTargets.push(...sourceArg.unknownReferences);
464
+ readTargets.push(...sourceArg.in);
465
+ if (targetName) {
466
+ readTargets.push(...targetArg.in);
467
+ }
468
+ else {
469
+ for (const i of targetArg.in) {
470
+ if (i.nodeId !== targetId) {
471
+ readTargets.push(i);
472
+ }
473
+ }
474
+ }
475
+ readTargets.push(...readFromSourceWritten);
439
476
  information.environment = (0, overwrite_1.overwriteEnvironment)(sourceArg.environment, targetArg.environment);
440
477
  // install assigned variables in environment
441
478
  for (const write of writeNodes) {
@@ -7,7 +7,9 @@ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/proce
7
7
  /**
8
8
  * Processes `attach(what, ...)` - when `what` is a variable that holds a tracked
9
9
  * {@link InGraphIdentifierDefinition#envState}, all statically-known definitions from
10
- * that environment are injected into the current scope so that subsequent reads of
11
- * those names resolve correctly.
10
+ * that environment are injected into a new scope layer inserted *between* the current
11
+ * scope and its parent. This mirrors R's behaviour: `attach` adds to the search path
12
+ * below `.GlobalEnv`, so existing global bindings take precedence, but after a
13
+ * `rm(name)` removes a global shadow the attached binding becomes visible again.
12
14
  */
13
15
  export declare function processAttach<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
@@ -6,7 +6,7 @@ const unpack_argument_1 = require("../argument/unpack-argument");
6
6
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
7
7
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
8
8
  const identifier_1 = require("../../../../../environments/identifier");
9
- const define_1 = require("../../../../../environments/define");
9
+ const environment_1 = require("../../../../../environments/environment");
10
10
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
11
11
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
12
12
  const edge_1 = require("../../../../../graph/edge");
@@ -14,8 +14,10 @@ const built_in_envir_utils_1 = require("./built-in-envir-utils");
14
14
  /**
15
15
  * Processes `attach(what, ...)` - when `what` is a variable that holds a tracked
16
16
  * {@link InGraphIdentifierDefinition#envState}, all statically-known definitions from
17
- * that environment are injected into the current scope so that subsequent reads of
18
- * those names resolve correctly.
17
+ * that environment are injected into a new scope layer inserted *between* the current
18
+ * scope and its parent. This mirrors R's behaviour: `attach` adds to the search path
19
+ * below `.GlobalEnv`, so existing global bindings take precedence, but after a
20
+ * `rm(name)` removes a global shadow the attached binding becomes visible again.
19
21
  */
20
22
  function processAttach(name, args, rootId, data) {
21
23
  const result = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Attach }).information;
@@ -30,7 +32,8 @@ function processAttach(name, args, rootId, data) {
30
32
  (0, unknown_side_effect_1.handleUnknownSideEffect)(result.graph, result.environment, rootId);
31
33
  return result;
32
34
  }
33
- let newEnvironment = result.environment;
35
+ /* build the attached layer with the env's known bindings */
36
+ let attachedLayer = new environment_1.Environment(result.environment.current.parent);
34
37
  for (const [varName, varDefs] of envirResolution.envDef.envState.current.memory) {
35
38
  for (const varDef of varDefs) {
36
39
  const inDef = varDef;
@@ -39,10 +42,13 @@ function processAttach(name, args, rootId, data) {
39
42
  name: varName,
40
43
  type: identifier_1.ReferenceType.Variable,
41
44
  };
42
- newEnvironment = (0, define_1.define)(injected, false, newEnvironment);
45
+ attachedLayer = attachedLayer.define(injected);
43
46
  result.graph.addEdge(inDef.nodeId, rootId, edge_1.EdgeType.Reads);
44
47
  }
45
48
  }
46
- return { ...result, environment: newEnvironment };
49
+ /* splice the attached layer between the current scope and its original parent */
50
+ const newCurrent = result.environment.current.clone(false);
51
+ newCurrent.parent = attachedLayer;
52
+ return { ...result, environment: { current: newCurrent, level: result.environment.level } };
47
53
  }
48
54
  //# sourceMappingURL=built-in-attach.js.map
@@ -19,6 +19,7 @@ const logger_1 = require("../../../../../logger");
19
19
  const log_1 = require("../../../../../../util/log");
20
20
  const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
21
21
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
22
+ const general_1 = require("../../../../../eval/values/general");
22
23
  function linkReadNameToWriteIfPossible(read, environments, listEnvironments, remainingRead, nextGraph) {
23
24
  const readName = read.name && identifier_1.Identifier.isDotDotDotAccess(read.name) ? identifier_1.Identifier.dotdotdot() : read.name;
24
25
  const probableTarget = readName ? (0, resolve_by_name_1.resolveByName)(readName, environments, read.type) : undefined;
@@ -41,14 +42,23 @@ function linkReadNameToWriteIfPossible(read, environments, listEnvironments, rem
41
42
  return;
42
43
  }
43
44
  const rid = read.nodeId;
45
+ const isFunc = read.type === identifier_1.ReferenceType.Function || read.type === identifier_1.ReferenceType.BuiltInFunction;
44
46
  for (const target of probableTarget) {
45
47
  const tid = target.nodeId;
46
- if (node_id_1.NodeId.isBuiltIn(target.definedAt) && (read.type === identifier_1.ReferenceType.Function || read.type === identifier_1.ReferenceType.BuiltInFunction)) {
48
+ if (node_id_1.NodeId.isBuiltIn(target.definedAt) && isFunc) {
47
49
  nextGraph.addEdge(rid, tid, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
48
50
  }
49
51
  else {
50
52
  nextGraph.addEdge(rid, tid, edge_1.EdgeType.Reads);
51
53
  }
54
+ if (target.type === identifier_1.ReferenceType.BuiltInConstant) {
55
+ nextGraph.addVertex({
56
+ tag: vertex_1.VertexType.Value,
57
+ id: tid,
58
+ cds: undefined,
59
+ value: (0, general_1.valueFromTsValue)(target.value)
60
+ }, environments, false);
61
+ }
52
62
  }
53
63
  }
54
64
  function updateSideEffectsForCalledFunctions(calledEnvs, inputEnvironment, nextGraph, localDefs) {
@@ -104,7 +114,7 @@ function processExpressionList(name, args, rootId, data) {
104
114
  const listEnvironments = new Set();
105
115
  const remainingRead = new Map();
106
116
  const nextGraph = new graph_1.DataflowGraph(data.completeAst.idMap);
107
- let out = [];
117
+ const out = [];
108
118
  const exitPoints = [];
109
119
  const activeCdsAtStart = data.cds;
110
120
  const invertExitCds = [];
@@ -128,12 +138,13 @@ function processExpressionList(name, args, rootId, data) {
128
138
  processed.in = (0, reference_to_maybe_1.makeAllMaybe)(processed.in, nextGraph, processed.environment, false, invertExitCds);
129
139
  processed.unknownReferences = (0, reference_to_maybe_1.makeAllMaybe)(processed.unknownReferences, nextGraph, processed.environment, false);
130
140
  }
131
- out = out.concat(processed.out);
141
+ out.push(...processed.out);
132
142
  // all inputs that have not been written until now are read!
133
- for (const ls of [processed.in, processed.unknownReferences]) {
134
- for (const read of ls) {
135
- linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph);
136
- }
143
+ for (const read of processed.in) {
144
+ linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph);
145
+ }
146
+ for (const read of processed.unknownReferences) {
147
+ linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph);
137
148
  }
138
149
  const calledEnvs = (0, linker_1.linkFunctionCalls)(nextGraph, data.completeAst.idMap, processed.graph);
139
150
  for (const c of calledEnvs) {
@@ -167,7 +178,10 @@ function processExpressionList(name, args, rootId, data) {
167
178
  nodeId: defaultReturnExpr.entryPoint
168
179
  });
169
180
  }
170
- const ingoing = remainingRead.values().toArray().flat();
181
+ const ingoing = [];
182
+ for (const refs of remainingRead.values()) {
183
+ ingoing.push(...refs);
184
+ }
171
185
  const rootNode = data.completeAst.idMap.get(rootId);
172
186
  const withGroup = rootNode?.grouping;
173
187
  if (withGroup) {
@@ -16,6 +16,7 @@ const graph_1 = require("../../../../../graph/graph");
16
16
  const identifier_1 = require("../../../../../environments/identifier");
17
17
  const overwrite_1 = require("../../../../../environments/overwrite");
18
18
  const vertex_1 = require("../../../../../graph/vertex");
19
+ const built_in_new_env_1 = require("./built-in-new-env");
19
20
  const scoping_1 = require("../../../../../environments/scoping");
20
21
  const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
21
22
  const edge_1 = require("../../../../../graph/edge");
@@ -128,6 +129,25 @@ function processFunctionDefinition(name, args, rootId, data) {
128
129
  afterHookExitPoints = (0, info_1.overwriteExitPoints)(afterHookExitPoints, hookExitPoints);
129
130
  }
130
131
  }
132
+ let returnEnvState;
133
+ if (data.ctx.config.solver.trackEnvironments) {
134
+ for (const ep of afterHookExitPoints) {
135
+ const epVertex = subgraph.getVertex(ep.nodeId);
136
+ if ((0, vertex_1.isFunctionCallVertex)(epVertex) && epVertex.origin.includes(built_in_proc_name_1.BuiltInProcName.NewEnv)) {
137
+ returnEnvState = (0, built_in_new_env_1.createFreshEnvState)(data, { graph: subgraph, entryPoint: ep.nodeId });
138
+ break;
139
+ }
140
+ const epNode = subgraph.idMap?.get(ep.nodeId);
141
+ if (epNode?.type === type_1.RType.Symbol) {
142
+ const defs = (0, resolve_by_name_1.resolveByName)(epNode.content, outEnvironment, identifier_1.ReferenceType.Variable);
143
+ const def = defs?.find((d) => d.envState !== undefined);
144
+ if (def?.envState) {
145
+ returnEnvState = def.envState;
146
+ break;
147
+ }
148
+ }
149
+ }
150
+ }
131
151
  const graph = new graph_1.DataflowGraph(data.completeAst.idMap).mergeWith(subgraph, false);
132
152
  graph.addVertex({
133
153
  tag: vertex_1.VertexType.FunctionDefinition,
@@ -136,7 +156,8 @@ function processFunctionDefinition(name, args, rootId, data) {
136
156
  cds: data.cds,
137
157
  params: readParams,
138
158
  subflow: flow,
139
- exitPoints: afterHookExitPoints
159
+ exitPoints: afterHookExitPoints,
160
+ returnEnvState
140
161
  }, data.ctx.env.makeCleanEnv());
141
162
  return {
142
163
  /* 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 } */
@@ -220,6 +241,41 @@ function updateNestedFunctionClosures(graph, outEnvironment, fnId) {
220
241
  }
221
242
  (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Keeping ${remainingIn.length} references to open ref ${id} in closure of function definition ${fnId}`);
222
243
  subflow.in = remainingIn;
244
+ linkSuperAssignmentsToOuterDefinitions(graph, subflow.graph, outEnvironment);
245
+ }
246
+ }
247
+ function linkSuperAssignmentsToOuterDefinitions(parentGraph, nestedGraphNodeIds, parentEnvironment) {
248
+ for (const nodeId of nestedGraphNodeIds) {
249
+ const vertex = parentGraph.getVertex(nodeId);
250
+ if (vertex?.tag !== vertex_1.VertexType.FunctionCall || !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.SuperAssignment)) {
251
+ continue;
252
+ }
253
+ const outgoingReturns = parentGraph.outgoingEdges(nodeId);
254
+ if (!outgoingReturns) {
255
+ continue;
256
+ }
257
+ for (const [targetId, edge] of outgoingReturns) {
258
+ if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
259
+ continue;
260
+ }
261
+ const targetVertex = parentGraph.getVertex(targetId);
262
+ if (targetVertex?.tag !== vertex_1.VertexType.VariableDefinition) {
263
+ continue;
264
+ }
265
+ const targetNode = parentGraph.idMap?.get(targetId);
266
+ if (targetNode?.type !== type_1.RType.Symbol) {
267
+ continue;
268
+ }
269
+ const varName = targetNode.content;
270
+ const resolved = (0, resolve_by_name_1.resolveByName)(varName, parentEnvironment, identifier_1.ReferenceType.Variable);
271
+ if (resolved) {
272
+ for (const ref of resolved) {
273
+ if (ref.nodeId !== targetId && !node_id_1.NodeId.isBuiltIn(ref.nodeId)) {
274
+ parentGraph.addEdge(targetId, ref.nodeId, edge_1.EdgeType.Reads);
275
+ }
276
+ }
277
+ }
278
+ }
223
279
  }
224
280
  }
225
281
  /**
@@ -24,4 +24,4 @@ export declare function processNewEnv<OtherInfo>(name: RSymbol<OtherInfo & Paren
24
24
  * is honoured. Without `sourceInfo` (or when no `newEnvParent` is present), falls back
25
25
  * to the current execution environment as parent.
26
26
  */
27
- export declare function createFreshEnvState(data: Pick<DataflowProcessorInformation<never>, 'environment'>, sourceInfo?: DataflowInformation): REnvironmentInformation;
27
+ export declare function createFreshEnvState(data: Pick<DataflowProcessorInformation<never>, 'environment'>, sourceInfo?: Pick<DataflowInformation, 'graph' | 'entryPoint'>): REnvironmentInformation;
@@ -79,7 +79,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
79
79
  content: 'fun',
80
80
  info: {
81
81
  id: argNameId,
82
- nesting: name.info.nesting,
82
+ nest: name.info.nest,
83
83
  role: "arg-n" /* RoleInParent.ArgumentName */,
84
84
  fullRange: r,
85
85
  adToks: undefined,
@@ -96,7 +96,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
96
96
  lexeme: 'S7_dispatch',
97
97
  info: {
98
98
  id: funcNameId,
99
- nesting: name.info.nesting,
99
+ nest: name.info.nest,
100
100
  role: "call-name" /* RoleInParent.FunctionCallName */,
101
101
  fullRange: r,
102
102
  adToks: undefined,
@@ -116,7 +116,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
116
116
  arguments: [],
117
117
  info: {
118
118
  id: rootId + '-s7-new-generic-fun-body',
119
- nesting: name.info.nesting,
119
+ nest: name.info.nest,
120
120
  role: "fun-b" /* RoleInParent.FunctionDefinitionBody */,
121
121
  fullRange: r,
122
122
  adToks: undefined,
@@ -131,7 +131,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
131
131
  info: {
132
132
  file: name.info.file,
133
133
  id: fdefId,
134
- nesting: name.info.nesting,
134
+ nest: name.info.nest,
135
135
  role: "arg-v" /* RoleInParent.ArgumentValue */,
136
136
  parent: rootId,
137
137
  index: args + 1,
@@ -149,7 +149,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
149
149
  content: n,
150
150
  info: {
151
151
  id: paramNameId,
152
- nesting: name.info.nesting,
152
+ nest: name.info.nest,
153
153
  role: "param-n" /* RoleInParent.ParameterName */,
154
154
  fullRange: r,
155
155
  adToks: undefined,
@@ -168,7 +168,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
168
168
  special: n === '...',
169
169
  info: {
170
170
  id: paramId,
171
- nesting: name.info.nesting,
171
+ nest: name.info.nest,
172
172
  role: "param" /* RoleInParent.FunctionDefinitionParameter */,
173
173
  parent: fdefId,
174
174
  index: i,
@@ -193,7 +193,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
193
193
  location: r,
194
194
  info: {
195
195
  id: argId,
196
- nesting: name.info.nesting,
196
+ nest: name.info.nest,
197
197
  role: "call-arg" /* RoleInParent.FunctionCallArgument */,
198
198
  fullRange: r,
199
199
  adToks: undefined,
@@ -51,7 +51,7 @@ This command includes the construction of the docker image, the generation of th
51
51
 
52
52
  The functionality tests represent conventional unit (and depending on your terminology component/api) tests.
53
53
  We use [vitest](https://vitest.dev/) as our testing framework.
54
- You can run the tests by issuing (some quick benchmarks may be available with \`vitest bench\`):
54
+ You can run the tests by issuing (some quick benchmarks may be available with \`npm run test:bench\`):
55
55
 
56
56
  ${(0, doc_code_1.codeBlock)('shell', 'npm run test')}
57
57