@eagleoutice/flowr 2.10.5 → 2.10.7

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 (113) hide show
  1. package/README.md +21 -21
  2. package/abstract-interpretation/absint-visitor.d.ts +1 -2
  3. package/abstract-interpretation/domains/state-domain-like.d.ts +2 -2
  4. package/config.d.ts +6 -0
  5. package/config.js +2 -0
  6. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
  7. package/control-flow/semantic-cfg-guided-visitor.js +4 -0
  8. package/dataflow/environments/built-in-proc-name.d.ts +27 -19
  9. package/dataflow/environments/built-in-proc-name.js +27 -19
  10. package/dataflow/environments/built-in.d.ts +24 -18
  11. package/dataflow/environments/built-in.js +6 -0
  12. package/dataflow/environments/default-builtin-config.d.ts +53 -1
  13. package/dataflow/environments/default-builtin-config.js +13 -3
  14. package/dataflow/environments/identifier.d.ts +19 -0
  15. package/dataflow/environments/reference-to-maybe.js +32 -6
  16. package/dataflow/eval/resolve/alias-tracking.js +5 -0
  17. package/dataflow/graph/graph.js +51 -30
  18. package/dataflow/graph/vertex.d.ts +18 -11
  19. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
  20. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
  21. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +145 -11
  22. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +15 -0
  23. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +54 -0
  24. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
  25. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +22 -8
  27. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +57 -1
  28. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
  29. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
  30. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
  31. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
  32. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
  33. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +7 -7
  34. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
  35. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
  36. package/documentation/doc-util/doc-types.d.ts +11 -2
  37. package/documentation/doc-util/doc-types.js +31 -9
  38. package/documentation/wiki-absint.d.ts +16 -0
  39. package/documentation/wiki-absint.js +50 -15
  40. package/documentation/wiki-interface.js +1 -0
  41. package/documentation/wiki-mk/doc-context.d.ts +14 -1
  42. package/documentation/wiki-mk/doc-context.js +6 -0
  43. package/documentation/wiki-normalized-ast.d.ts +0 -9
  44. package/documentation/wiki-normalized-ast.js +9 -60
  45. package/linter/linter-format.d.ts +4 -0
  46. package/linter/linter-rules.d.ts +7 -6
  47. package/linter/rules/absolute-path.d.ts +0 -2
  48. package/linter/rules/dataframe-access-validation.d.ts +4 -7
  49. package/linter/rules/dataframe-access-validation.js +3 -3
  50. package/linter/rules/dead-code.d.ts +4 -7
  51. package/linter/rules/file-path-validity.d.ts +0 -2
  52. package/linter/rules/function-finder-util.d.ts +1 -3
  53. package/linter/rules/function-finder-util.js +2 -2
  54. package/linter/rules/naming-convention.d.ts +0 -2
  55. package/linter/rules/network-functions.js +4 -1
  56. package/linter/rules/problematic-inputs.d.ts +9 -6
  57. package/linter/rules/problematic-inputs.js +108 -58
  58. package/linter/rules/roxygen-arguments.d.ts +0 -2
  59. package/linter/rules/seeded-randomness.d.ts +0 -2
  60. package/linter/rules/stop-with-call-arg.d.ts +3 -6
  61. package/linter/rules/unused-definition.d.ts +0 -2
  62. package/linter/rules/useless-loop.d.ts +0 -2
  63. package/package.json +4 -4
  64. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -2
  65. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +2 -0
  66. package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
  67. package/queries/catalog/dependencies-query/function-info/source-functions.js +1 -1
  68. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  69. package/queries/catalog/input-sources-query/input-source-functions.d.ts +1 -0
  70. package/queries/catalog/input-sources-query/input-source-functions.js +7 -1
  71. package/queries/catalog/input-sources-query/input-sources-query-format.js +3 -1
  72. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +3 -1
  73. package/queries/catalog/input-sources-query/simple-input-classifier.js +3 -1
  74. package/r-bridge/data/data.d.ts +28 -2
  75. package/r-bridge/data/data.js +34 -2
  76. package/r-bridge/lang-4.x/ast/model/model.d.ts +1 -2
  77. package/r-bridge/lang-4.x/ast/model/model.js +0 -1
  78. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +3 -3
  79. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -3
  80. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -3
  81. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +3 -3
  82. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +3 -3
  83. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +3 -3
  84. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +3 -3
  85. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +3 -3
  86. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +3 -3
  87. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +3 -3
  88. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +3 -3
  89. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +3 -3
  90. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +3 -3
  91. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +3 -3
  92. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +3 -3
  93. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +3 -3
  94. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +3 -3
  95. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +3 -3
  96. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +3 -3
  97. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -3
  98. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +3 -3
  99. package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +1 -1
  100. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +16 -16
  101. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -0
  102. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +8 -0
  103. package/search/flowr-search-builder.d.ts +16 -2
  104. package/search/flowr-search-builder.js +10 -1
  105. package/search/flowr-search.d.ts +9 -0
  106. package/search/search-executor/search-generators.d.ts +1 -1
  107. package/search/search-executor/search-generators.js +28 -2
  108. package/slicing/static/static-slicer.js +2 -2
  109. package/util/range.d.ts +13 -1
  110. package/util/range.js +32 -2
  111. package/util/version.js +1 -1
  112. package/abstract-interpretation/normalized-ast-fold.d.ts +0 -119
  113. package/abstract-interpretation/normalized-ast-fold.js +0 -181
@@ -23,6 +23,11 @@ export declare const DefaultBuiltinConfig: [{
23
23
  readonly names: ["NULL", "NA", "NaN", "NA_integer_", "NA_real_", "NA_complex_", "NA_character_"];
24
24
  readonly value: null;
25
25
  readonly assumePrimitive: true;
26
+ }, {
27
+ readonly type: "constant";
28
+ readonly names: [".GlobalEnv", ".BaseNamespaceEnv", ".BaseEnv"];
29
+ readonly value: null;
30
+ readonly assumePrimitive: true;
26
31
  }, {
27
32
  readonly type: "constant";
28
33
  readonly names: ["TRUE", "T"];
@@ -424,6 +429,7 @@ export declare const DefaultBuiltinConfig: [{
424
429
  readonly config: {
425
430
  readonly targetVariable: true;
426
431
  readonly mayHaveMoreArgs: true;
432
+ readonly environmentArg: "envir";
427
433
  };
428
434
  readonly assumePrimitive: true;
429
435
  }, {
@@ -948,6 +954,38 @@ export declare const DefaultBuiltinConfig: [{
948
954
  };
949
955
  };
950
956
  readonly assumePrimitive: false;
957
+ }, {
958
+ readonly type: "function";
959
+ readonly names: ["with", "within"];
960
+ readonly processor: BuiltInProcName.With;
961
+ readonly config: {};
962
+ readonly assumePrimitive: false;
963
+ }, {
964
+ readonly type: "function";
965
+ readonly names: ["new.env", Identifier];
966
+ readonly processor: BuiltInProcName.NewEnv;
967
+ readonly config: {};
968
+ readonly assumePrimitive: true;
969
+ }, {
970
+ readonly type: "function";
971
+ readonly names: ["globalenv", "baseenv", "emptyenv", "parent.env", "parent.frame", "environmentName", "as.environment", "pos.to.env", "sys.frame", "sys.frames", "topenv"];
972
+ readonly processor: BuiltInProcName.Default;
973
+ readonly config: {};
974
+ readonly assumePrimitive: true;
975
+ }, {
976
+ readonly type: "function";
977
+ readonly names: ["load", "load_image"];
978
+ readonly processor: BuiltInProcName.Default;
979
+ readonly config: {
980
+ readonly hasUnknownSideEffects: true;
981
+ };
982
+ readonly assumePrimitive: false;
983
+ }, {
984
+ readonly type: "function";
985
+ readonly names: ["attach"];
986
+ readonly processor: BuiltInProcName.Attach;
987
+ readonly config: {};
988
+ readonly assumePrimitive: false;
951
989
  }, {
952
990
  readonly type: "function";
953
991
  readonly names: ["for"];
@@ -1091,6 +1129,20 @@ export declare const DefaultBuiltinConfig: [{
1091
1129
  readonly config: {};
1092
1130
  readonly assumePrimitive: true;
1093
1131
  readonly evalHandler: "built-in:c";
1132
+ }, {
1133
+ readonly type: "function";
1134
+ readonly names: [Identifier, Identifier];
1135
+ readonly processor: BuiltInProcName.Default;
1136
+ readonly config: {
1137
+ readonly returnsNthArgument: 0;
1138
+ };
1139
+ }, {
1140
+ readonly type: "function";
1141
+ readonly names: [Identifier];
1142
+ readonly processor: BuiltInProcName.Default;
1143
+ readonly config: {
1144
+ readonly hasUnknownSideEffects: true;
1145
+ };
1094
1146
  }, {
1095
1147
  readonly type: "function";
1096
1148
  readonly names: ["setnames", "setNames", "setkey", "setkeyv", "setindex", "setindexv", "setattr"];
@@ -1103,7 +1155,7 @@ export declare const DefaultBuiltinConfig: [{
1103
1155
  };
1104
1156
  }, {
1105
1157
  readonly type: "function";
1106
- readonly names: ["sys.on.exit", "par", "tpar", "sink", "requireNamespace", "loadNamespace", "attachNamespace", "asNamespace", Identifier, "attach", "unname", "data", "dir.create", "dir_create", "Sys.chmod", "unlink", "file.remove", "file.rename", "file.copy", "file.link", "file.append", "Sys.junction"];
1158
+ readonly names: ["sys.on.exit", "par", "tpar", "sink", "requireNamespace", "loadNamespace", "attachNamespace", "asNamespace", Identifier, "unname", "data", "dir.create", "dir_create", "Sys.chmod", "unlink", "file.remove", "file.rename", "file.copy", "file.link", "file.append", "Sys.junction"];
1107
1159
  readonly processor: BuiltInProcName.Default;
1108
1160
  readonly config: {
1109
1161
  readonly hasUnknownSideEffects: true;
@@ -98,6 +98,7 @@ function toRegex(n) {
98
98
  */
99
99
  exports.DefaultBuiltinConfig = [
100
100
  { type: 'constant', names: ['NULL', 'NA', 'NaN', 'NA_integer_', 'NA_real_', 'NA_complex_', 'NA_character_'], value: null, assumePrimitive: true },
101
+ { type: 'constant', names: ['.GlobalEnv', '.BaseNamespaceEnv', '.BaseEnv'], value: null, assumePrimitive: true },
101
102
  { type: 'constant', names: ['TRUE', 'T'], value: true, assumePrimitive: true },
102
103
  { type: 'constant', names: ['FALSE', 'F'], value: false, assumePrimitive: true },
103
104
  {
@@ -259,7 +260,7 @@ exports.DefaultBuiltinConfig = [
259
260
  { type: 'function', names: [identifier_1.Identifier.make('from', 'import'), identifier_1.Identifier.make('library', 'base'), identifier_1.Identifier.make('require', 'base')], processor: built_in_proc_name_1.BuiltInProcName.Library, config: {}, assumePrimitive: false },
260
261
  { type: 'function', names: ['<-', '='], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { canBeReplacement: true }, assumePrimitive: true },
261
262
  { type: 'function', names: [':='], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: {}, assumePrimitive: true },
262
- { type: 'function', names: ['assign', 'setValidity'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { targetVariable: true, mayHaveMoreArgs: true }, assumePrimitive: true },
263
+ { type: 'function', names: ['assign', 'setValidity'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { targetVariable: true, mayHaveMoreArgs: true, environmentArg: 'envir' }, assumePrimitive: true },
263
264
  { type: 'function', names: ['setMethod'], processor: built_in_proc_name_1.BuiltInProcName.AssignmentLike, config: { targetVariable: true, canBeReplacement: false, target: { idx: 0, name: 'f' }, source: { idx: 2, name: 'definition' }, modesForFn: ['s4'] }, assumePrimitive: true },
264
265
  { type: 'function', names: ['delayedAssign'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { quoteSource: true, targetVariable: true }, assumePrimitive: true },
265
266
  { type: 'function', names: ['<<-'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { superAssignment: true, canBeReplacement: true }, assumePrimitive: true },
@@ -422,6 +423,13 @@ exports.DefaultBuiltinConfig = [
422
423
  { type: 'function', names: [identifier_1.Identifier.make('enquo', 'rlang'), identifier_1.Identifier.make('enquos', 'rlang'), identifier_1.Identifier.make('quo', 'rlang'), identifier_1.Identifier.make('quos', 'rlang'), identifier_1.Identifier.make('sym', 'rlang'), identifier_1.Identifier.make('syms', 'rlang'), identifier_1.Identifier.make('ensym', 'rlang'), identifier_1.Identifier.make('ensyms', 'rlang'), identifier_1.Identifier.make('expr', 'rlang'), identifier_1.Identifier.make('exprs', 'rlang'), identifier_1.Identifier.make('quo_name', 'rlang'), identifier_1.Identifier.make('as_name', 'rlang'), identifier_1.Identifier.make('as_label', 'rlang'), identifier_1.Identifier.make('as_string', 'rlang')], processor: built_in_proc_name_1.BuiltInProcName.Quote, config: { quoteArgumentsWithIndex: 0, libFn: true }, assumePrimitive: true },
423
424
  { type: 'function', names: [identifier_1.Identifier.make('call2', 'rlang'), identifier_1.Identifier.make('exec', 'rlang'), identifier_1.Identifier.make('invoke', 'purrr'), identifier_1.Identifier.make('invoke_map', 'purrr')], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { libFn: true, hasUnknownSideEffects: true, unquoteFunction: true }, assumePrimitive: false },
424
425
  { type: 'function', names: ['local'], processor: built_in_proc_name_1.BuiltInProcName.Local, config: { args: { env: 'envir', expr: 'expr' } }, assumePrimitive: false },
426
+ { type: 'function', names: ['with', 'within'], processor: built_in_proc_name_1.BuiltInProcName.With, config: {}, assumePrimitive: false },
427
+ { type: 'function', names: ['new.env', identifier_1.Identifier.make('new_environment', 'rlang')], processor: built_in_proc_name_1.BuiltInProcName.NewEnv, config: {}, assumePrimitive: true },
428
+ { type: 'function', names: ['globalenv', 'baseenv', 'emptyenv', 'parent.env', 'parent.frame', 'environmentName', 'as.environment', 'pos.to.env', 'sys.frame', 'sys.frames', 'topenv'],
429
+ processor: built_in_proc_name_1.BuiltInProcName.Default, config: {}, assumePrimitive: true },
430
+ { type: 'function', names: ['load', 'load_image'], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { hasUnknownSideEffects: true }, assumePrimitive: false },
431
+ /* attach injects an environment's contents into the search path; detach reverses it (treated as unknown side effect) */
432
+ { type: 'function', names: ['attach'], processor: built_in_proc_name_1.BuiltInProcName.Attach, config: {}, assumePrimitive: false },
425
433
  { type: 'function', names: ['for'], processor: built_in_proc_name_1.BuiltInProcName.ForLoop, config: {}, assumePrimitive: true },
426
434
  { type: 'function', names: ['repeat'], processor: built_in_proc_name_1.BuiltInProcName.RepeatLoop, config: {}, assumePrimitive: true },
427
435
  { type: 'function', names: ['while'], processor: built_in_proc_name_1.BuiltInProcName.WhileLoop, config: {}, assumePrimitive: true },
@@ -438,6 +446,8 @@ exports.DefaultBuiltinConfig = [
438
446
  { type: 'function', names: ['Recall'], processor: built_in_proc_name_1.BuiltInProcName.Recall, config: { libFn: true }, assumePrimitive: false },
439
447
  { type: 'function', names: ['sys.function'], processor: built_in_proc_name_1.BuiltInProcName.Recall, config: { libFn: true, unknownOnNonZeroArg: true }, assumePrimitive: false },
440
448
  { type: 'function', names: ['c'], processor: built_in_proc_name_1.BuiltInProcName.Vector, config: {}, assumePrimitive: true, evalHandler: 'built-in:c' },
449
+ { type: 'function', names: [identifier_1.Identifier.make('cmpfun', 'compiler'), identifier_1.Identifier.make('compile', 'compiler')], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { returnsNthArgument: 0 } },
450
+ { type: 'function', names: [identifier_1.Identifier.make('loadcmp', 'compiler')], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { hasUnknownSideEffects: true } },
441
451
  {
442
452
  type: 'function',
443
453
  names: ['setnames', 'setNames', 'setkey', 'setkeyv', 'setindex', 'setindexv', 'setattr'],
@@ -457,7 +467,7 @@ exports.DefaultBuiltinConfig = [
457
467
  'requireNamespace', 'loadNamespace', 'attachNamespace', 'asNamespace',
458
468
  identifier_1.Identifier.make('use', 'base'),
459
469
  /* weird env attachments */
460
- 'attach', 'unname', 'data',
470
+ 'unname', 'data',
461
471
  /* file creation/removal */
462
472
  'dir.create', 'dir_create', 'Sys.chmod', 'unlink', 'file.remove', 'file.rename', 'file.copy', 'file.link', 'file.append', 'Sys.junction'
463
473
  ],
@@ -516,7 +526,7 @@ exports.DefaultBuiltinConfig = [
516
526
  config: {
517
527
  readIndices: false
518
528
  }
519
- }
529
+ },
520
530
  ];
521
531
  /**
522
532
  * Expensive and naive lookup of the default processor for a built-in function name
@@ -1,6 +1,7 @@
1
1
  import type { BuiltInIdentifierConstant, BuiltInIdentifierDefinition } from './built-in';
2
2
  import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
3
3
  import type { ControlDependency } from '../info';
4
+ import type { REnvironmentInformation } from './environment';
4
5
  /** this is just a safe-guard type to prevent mixing up branded identifiers with normal strings */
5
6
  export type BrandedIdentifier = string & {
6
7
  __brand?: 'identifier';
@@ -198,7 +199,25 @@ export interface InGraphIdentifierDefinition extends IdentifierReference {
198
199
  * For example, in `x <- 3; y <- x`, the definition of `y` will have the value `3` in its value set
199
200
  */
200
201
  readonly value?: NodeId[];
202
+ /**
203
+ * If this variable holds an R environment (created by `new.env()` etc.),
204
+ * this tracks the current known state of that environment.
205
+ * Use this to resolve variables assigned via `assign(name, val, envir=<this var>)`.
206
+ */
207
+ readonly envState?: REnvironmentInformation;
208
+ /**
209
+ * If this is a function that returns a tracked environment, stores the envState
210
+ * that the function returns (best-effort: only set when statically detectable).
211
+ */
212
+ readonly returnsEnvState?: REnvironmentInformation;
201
213
  }
214
+ /**
215
+ * A narrowed variant of {@link InGraphIdentifierDefinition} that is guaranteed to have a non-undefined `name`.
216
+ * Prefer this over the inline intersection `InGraphIdentifierDefinition & { name: Identifier }`.
217
+ */
218
+ export type NamedInGraphIdentifierDefinition = InGraphIdentifierDefinition & {
219
+ readonly name: Identifier;
220
+ };
202
221
  /**
203
222
  * Stores the definition of an identifier within an {@link IEnvironment}.
204
223
  *
@@ -8,17 +8,40 @@ const identifier_1 = require("./identifier");
8
8
  const resolve_by_name_1 = require("./resolve-by-name");
9
9
  const vertex_1 = require("../graph/vertex");
10
10
  function appToCdsUnique(target, toAdd) {
11
- if (toAdd) {
12
- target.push(...toAdd.filter(c => !target.some(tc => tc.id === c.id && tc.when === c.when)));
11
+ if (!toAdd) {
12
+ return;
13
+ }
14
+ for (const c of toAdd) {
15
+ let found = false;
16
+ for (const tc of target) {
17
+ if (tc.id === c.id && tc.when === c.when) {
18
+ found = true;
19
+ break;
20
+ }
21
+ }
22
+ if (!found) {
23
+ target.push(c);
24
+ }
13
25
  }
14
26
  }
15
27
  function concatCdsUnique(target, toAdd) {
16
- if (toAdd) {
17
- return target.concat(toAdd.filter(c => !target.some(tc => tc.id === c.id && tc.when === c.when)));
18
- }
19
- else {
28
+ if (!toAdd) {
20
29
  return target;
21
30
  }
31
+ const result = Array.from(target);
32
+ for (const c of toAdd) {
33
+ let found = false;
34
+ for (const tc of target) {
35
+ if (tc.id === c.id && tc.when === c.when) {
36
+ found = true;
37
+ break;
38
+ }
39
+ }
40
+ if (!found) {
41
+ result.push(c);
42
+ }
43
+ }
44
+ return result;
22
45
  }
23
46
  /**
24
47
  * Marks the reference as maybe (i.e., as controlled by a set of {@link IdentifierReference#cds|control dependencies}).
@@ -94,6 +117,9 @@ function applyCdsToAllInGraphButConstants(graph, references, cds) {
94
117
  * apply the given cds to all given references, but not to the graph. This is useful if we want to mark the references as maybe without marking all other nodes in the graph as maybe.
95
118
  */
96
119
  function applyCdToReferences(references, cds) {
120
+ if (cds.length === 0) {
121
+ return;
122
+ }
97
123
  for (const ref of references) {
98
124
  if (ref.cds) {
99
125
  appToCdsUnique(ref.cds, cds);
@@ -324,6 +324,11 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
324
324
  }
325
325
  const values = new Set();
326
326
  for (const id of resultIds) {
327
+ const vertex = graph.getVertex(id);
328
+ if ((0, vertex_1.isValueVertex)(vertex) && vertex.value !== undefined) {
329
+ values.add(vertex.value);
330
+ continue;
331
+ }
327
332
  const node = idMap.get(id);
328
333
  if (node !== undefined) {
329
334
  if (node.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */ || model_1.RNode.iterateParents(node, idMap).some(p => p.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */)) {
@@ -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}.
@@ -110,6 +106,12 @@ export interface DataflowGraphVertexFunctionCall extends DataflowGraphVertexBase
110
106
  environment: REnvironmentInformation | undefined;
111
107
  /** More detailed Information on this function call */
112
108
  origin: FunctionOriginInformation[] | 'unnamed';
109
+ /**
110
+ * For `new.env()`-family calls: the resolved parent {@link REnvironmentInformation} that the
111
+ * freshly-created environment should inherit from. Set by `processNewEnv` when the `parent`
112
+ * argument can be statically resolved (tracked env variable or `emptyenv()`-family call).
113
+ */
114
+ newEnvParent?: REnvironmentInformation;
113
115
  }
114
116
  /** Describes the processor responsible for a function call */
115
117
  export type FunctionOriginInformation = BuiltInProcName;
@@ -153,6 +155,11 @@ export interface DataflowGraphVertexFunctionDefinition extends DataflowGraphVert
153
155
  * This is more of a convenience flag for later processing.
154
156
  */
155
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;
156
163
  }
157
164
  /**
158
165
  * What is to be passed to construct a vertex in the {@link DataflowGraph|dataflow graph}
@@ -12,6 +12,8 @@ const built_in_assignment_1 = require("./built-in-assignment");
12
12
  const identifier_1 = require("../../../../../environments/identifier");
13
13
  const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
14
14
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
15
+ const unpack_argument_1 = require("../argument/unpack-argument");
16
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
15
17
  function tableAssignmentProcessor(name, args, rootId, data, outInfo) {
16
18
  outInfo.definitionRootNodes.push(rootId);
17
19
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.TableAssignment }).information;
@@ -57,6 +59,20 @@ function processAccess(name, args, rootId, data, config) {
57
59
  }
58
60
  /* we include the read edges to the constant arguments as well so that they are included if necessary */
59
61
  }
62
+ /* for $ access on a tracked env variable, add Reads edges to the field definition in envState */
63
+ if (config.treatIndicesAsString && identifier_1.Identifier.getName(name.content) === '$'
64
+ && head !== r_function_call_1.EmptyArgument && head.value?.type === type_1.RType.Symbol
65
+ && args.length >= 2 && args[1] !== r_function_call_1.EmptyArgument) {
66
+ const envirResolution = (0, built_in_envir_utils_1.resolveSymbolToEnvir)(head.value.content, head.value.info.id, data);
67
+ if (envirResolution) {
68
+ const fieldNode = (0, unpack_argument_1.unpackArg)(args[1]);
69
+ const fieldName = fieldNode?.type === type_1.RType.String ? fieldNode.content.str : fieldNode?.lexeme;
70
+ const fieldDefs = fieldName ? envirResolution.envDef.envState.current.memory.get(fieldName) : undefined;
71
+ for (const fd of fieldDefs ?? []) {
72
+ info.graph.addEdge(name.info.id, fd.nodeId, edge_1.EdgeType.Reads);
73
+ }
74
+ }
75
+ }
60
76
  return {
61
77
  ...info,
62
78
  /*
@@ -21,6 +21,12 @@ export interface AssignmentConfiguration extends ForceArguments {
21
21
  readonly targetVariable?: boolean;
22
22
  readonly mayHaveMoreArgs?: boolean;
23
23
  readonly modesForFn?: DataflowGraphVertexFunctionDefinition['mode'];
24
+ /**
25
+ * The name of the argument that selects the target environment (e.g. `'envir'` for `assign`).
26
+ * When present and the argument resolves to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
27
+ * the assignment is routed into that environment instead of the current scope.
28
+ */
29
+ readonly environmentArg?: string;
24
30
  }
25
31
  export interface ExtendedAssignmentConfiguration extends AssignmentConfiguration {
26
32
  readonly source: {