@eagleoutice/flowr 2.13.14 → 2.13.15

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 (131) hide show
  1. package/README.md +23 -23
  2. package/abstract-interpretation/data-frame/resolve-args.js +11 -12
  3. package/benchmark/summarizer/second-phase/graph.d.ts +23 -0
  4. package/benchmark/summarizer/second-phase/graph.js +47 -14
  5. package/cli/repl/commands/repl-cfg.js +2 -42
  6. package/cli/repl/commands/repl-clipboard.d.ts +7 -0
  7. package/cli/repl/commands/repl-clipboard.js +53 -0
  8. package/cli/repl/commands/repl-dataflow.js +5 -70
  9. package/cli/repl/commands/repl-normalize.js +3 -51
  10. package/control-flow/cfg-dead-code.js +5 -29
  11. package/control-flow/diff-cfg.js +2 -56
  12. package/control-flow/semantic-cfg-guided-visitor.d.ts +7 -0
  13. package/control-flow/semantic-cfg-guided-visitor.js +14 -0
  14. package/control-flow/useless-loop.js +4 -26
  15. package/core/steps/all/core/10-normalize.d.ts +8 -0
  16. package/core/steps/all/core/10-normalize.js +10 -8
  17. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +5 -7
  18. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -9
  19. package/data/r-base-packages.generated.d.ts +1 -0
  20. package/data/r-base-packages.generated.js +5 -3
  21. package/dataflow/environments/built-in-config.d.ts +9 -1
  22. package/dataflow/environments/built-in-proc-name.d.ts +2 -0
  23. package/dataflow/environments/built-in-proc-name.js +2 -0
  24. package/dataflow/environments/built-in-props.d.ts +4 -0
  25. package/dataflow/environments/built-in-props.js +3 -3
  26. package/dataflow/environments/built-in.d.ts +4 -2
  27. package/dataflow/environments/built-in.js +53 -3
  28. package/dataflow/environments/data-masking-functions.d.ts +3 -4
  29. package/dataflow/environments/data-masking-functions.js +7 -8
  30. package/dataflow/environments/default-builtin-config.d.ts +92 -12
  31. package/dataflow/environments/default-builtin-config.js +86 -43
  32. package/dataflow/environments/environment.d.ts +5 -0
  33. package/dataflow/environments/environment.js +17 -12
  34. package/dataflow/environments/identifier.d.ts +3 -0
  35. package/dataflow/eval/resolve/alias-tracking.js +4 -7
  36. package/dataflow/eval/resolve/node-value.d.ts +51 -0
  37. package/dataflow/eval/resolve/node-value.js +71 -0
  38. package/dataflow/eval/resolve/resolve-argument.js +10 -7
  39. package/dataflow/eval/resolve/resolve-operators.js +1 -2
  40. package/dataflow/eval/values/general.d.ts +4 -0
  41. package/dataflow/eval/values/general.js +11 -0
  42. package/dataflow/eval/values/r-value.d.ts +15 -0
  43. package/dataflow/eval/values/r-value.js +27 -1
  44. package/dataflow/extractor.js +2 -0
  45. package/dataflow/fn/higher-order-function.js +2 -3
  46. package/dataflow/graph/diff-dataflow-graph.js +3 -55
  47. package/dataflow/graph/graph.d.ts +5 -0
  48. package/dataflow/graph/graph.js +27 -0
  49. package/dataflow/internal/linker.d.ts +23 -0
  50. package/dataflow/internal/linker.js +70 -1
  51. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +4 -1
  52. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +2 -0
  53. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -29
  54. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +39 -6
  55. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +10 -22
  56. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +29 -53
  57. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -5
  58. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -7
  59. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -3
  60. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +19 -12
  61. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +2 -1
  62. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +3 -0
  63. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +69 -52
  64. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
  65. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +2 -8
  66. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +2 -8
  67. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +2 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +2 -2
  69. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +5 -0
  70. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +23 -3
  71. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.d.ts +5 -4
  72. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +7 -10
  73. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +6 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +20 -3
  75. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -8
  76. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +25 -0
  77. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +105 -0
  78. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +1 -27
  79. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +4 -5
  80. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +1 -1
  81. package/dataflow/internal/process/functions/call/deferred.d.ts +41 -0
  82. package/dataflow/internal/process/functions/call/deferred.js +127 -0
  83. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +13 -12
  84. package/dataflow/internal/process/functions/call/known-call-handling.js +35 -35
  85. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
  86. package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
  87. package/dataflow/internal/process/functions/call/nse.d.ts +28 -0
  88. package/dataflow/internal/process/functions/call/nse.js +87 -0
  89. package/dataflow/internal/process/functions/call/quoted.d.ts +29 -0
  90. package/dataflow/internal/process/functions/call/quoted.js +188 -0
  91. package/documentation/doc-util/doc-types.js +15 -9
  92. package/linter/rules/deprecated-functions.js +9 -3
  93. package/linter/rules/seeded-randomness.js +2 -3
  94. package/linter/rules/undefined-symbol.js +10 -1
  95. package/package.json +1 -1
  96. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +6 -0
  97. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +17 -1
  98. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.d.ts +2 -11
  99. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.js +3 -15
  100. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +16 -0
  101. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +26 -0
  102. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +2 -11
  103. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +3 -15
  104. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin.js +4 -10
  105. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +2 -9
  106. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +2 -9
  107. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +1 -1
  108. package/project/sigdb/reader.d.ts +9 -0
  109. package/project/sigdb/reader.js +30 -0
  110. package/queries/catalog/input-sources-query/input-sources-query-format.js +1 -1
  111. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.d.ts +0 -12
  112. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -37
  113. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -23
  114. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +2 -2
  115. package/queries/query-function-filter.d.ts +21 -0
  116. package/queries/query-function-filter.js +48 -0
  117. package/r-bridge/data/data.d.ts +13 -3
  118. package/r-bridge/data/data.js +15 -3
  119. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +2 -0
  120. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +4 -0
  121. package/search/flowr-search-filters.d.ts +5 -1
  122. package/search/flowr-search-filters.js +31 -21
  123. package/search/search-executor/search-enrichers.d.ts +24 -4
  124. package/search/search-executor/search-enrichers.js +22 -9
  125. package/search/search-executor/search-transformer.js +1 -1
  126. package/util/diff-graph.d.ts +13 -0
  127. package/util/diff-graph.js +64 -1
  128. package/util/files.js +9 -8
  129. package/util/r-base-packages.d.ts +2 -0
  130. package/util/r-base-packages.js +3 -1
  131. package/util/version.js +1 -1
@@ -10,7 +10,9 @@ exports.findSource = findSource;
10
10
  exports.processSourceCall = processSourceCall;
11
11
  exports.sourceRequest = sourceRequest;
12
12
  exports.standaloneSourceFile = standaloneSourceFile;
13
+ exports.mergeSourced = mergeSourced;
13
14
  const processor_1 = require("../../../../../processor");
15
+ const append_1 = require("../../../../../environments/append");
14
16
  const info_1 = require("../../../../../info");
15
17
  const config_1 = require("../../../../../../config");
16
18
  const known_call_handling_1 = require("../known-call-handling");
@@ -26,10 +28,9 @@ const shell_executor_1 = require("../../../../../../r-bridge/shell-executor");
26
28
  const assert_1 = require("../../../../../../util/assert");
27
29
  const path_1 = __importDefault(require("path"));
28
30
  const gas_1 = require("../../../../../../gas");
29
- const general_1 = require("../../../../../eval/values/general");
30
31
  const r_value_1 = require("../../../../../eval/values/r-value");
31
32
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
32
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
33
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
33
34
  const edge_1 = require("../../../../../graph/edge");
34
35
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
35
36
  /**
@@ -151,7 +152,7 @@ function processSourceCall(name, args, rootId, data, config) {
151
152
  sourceFile = [(0, retriever_1.removeRQuotes)(sourceFileArgument.lexeme)];
152
153
  }
153
154
  else if (sourceFileArgument !== r_function_call_1.EmptyArgument) {
154
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(sourceFileArgument.info.id, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx }));
155
+ const resolved = node_value_1.NodeValue.setOf(sourceFileArgument.info.id, data);
155
156
  sourceFile = resolved?.elements.map(r => r.type === 'string' && (0, r_value_1.isValue)(r.value) ? r.value.str : undefined).filter(assert_1.isNotUndefined);
156
157
  }
157
158
  if (sourceFile?.length === 1) {
@@ -305,4 +306,23 @@ function standaloneSourceFile(idx, file, data, information) {
305
306
  referenceChain: [...data.referenceChain, file.filePath]
306
307
  }, information, false);
307
308
  }
309
+ /**
310
+ * Folds the results of analyzing sourced code back into the information of the call that asked for it, which
311
+ * `eval` and the string templates both need: the code contributes everything it reads, writes, and leaves open.
312
+ */
313
+ function mergeSourced(information, sourced) {
314
+ if (sourced.length === 0) {
315
+ return information;
316
+ }
317
+ return {
318
+ ...information,
319
+ graph: sourced.reduce((acc, r) => acc.mergeWith(r.graph), information.graph),
320
+ environment: sourced.reduce((acc, r) => (0, append_1.appendEnvironment)(acc, r.environment), information.environment),
321
+ in: information.in.concat(sourced.flatMap(r => r.in)),
322
+ out: information.out.concat(sourced.flatMap(r => r.out)),
323
+ unknownReferences: information.unknownReferences.concat(sourced.flatMap(r => r.unknownReferences)),
324
+ exitPoints: information.exitPoints.concat(sourced.flatMap(r => r.exitPoints)),
325
+ hooks: information.hooks.concat(sourced.flatMap(r => r.hooks))
326
+ };
327
+ }
308
328
  //# sourceMappingURL=built-in-source.js.map
@@ -7,10 +7,11 @@ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/proce
7
7
  import type { ForceArguments } from '../common';
8
8
  /**
9
9
  * Process a special built-in binary operator, possibly lazily.
10
- * For example, the logical AND `&&` and OR `||` operators only evaluate their right-hand side if necessary.
11
- * Please note that this is not (directly) related to R's special binary operators like `%in%`.
10
+ * Only `&&`/`||` short-circuit: their right-hand side gets a control dependency and only the left is read.
11
+ * The vectorized `&`/`|` evaluate both and hence use `lazy: false`.
12
+ * Not related to R's special binary operators like `%in%`.
12
13
  */
13
14
  export declare function processSpecialBinOp<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: {
14
- lazy: boolean;
15
- evalRhsWhen: boolean;
15
+ readonly lazy: boolean;
16
+ readonly evalRhsWhen?: boolean;
16
17
  } & ForceArguments): DataflowInformation;
@@ -8,21 +8,19 @@ const identifier_1 = require("../../../../../environments/identifier");
8
8
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
9
9
  /**
10
10
  * Process a special built-in binary operator, possibly lazily.
11
- * For example, the logical AND `&&` and OR `||` operators only evaluate their right-hand side if necessary.
12
- * Please note that this is not (directly) related to R's special binary operators like `%in%`.
11
+ * Only `&&`/`||` short-circuit: their right-hand side gets a control dependency and only the left is read.
12
+ * The vectorized `&`/`|` evaluate both and hence use `lazy: false`.
13
+ * Not related to R's special binary operators like `%in%`.
13
14
  */
14
15
  function processSpecialBinOp(name, args, rootId, data, config) {
15
- if (!config.lazy) {
16
- return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.SpecialBinOp }).information;
17
- }
18
- else if (args.length != 2) {
16
+ if (args.length != 2) {
19
17
  logger_1.dataflowLogger.warn(`Logical bin-op ${identifier_1.Identifier.toString(name.content)} has something else than 2 arguments, skipping`);
20
18
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: config.forceArgs, origin: 'default' }).information;
21
19
  }
22
20
  const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: config.forceArgs,
23
21
  patchData: (d, i) => {
24
- if (i === 1) {
25
- return { ...d, cds: [...d.cds ?? [], { id: name.info.id, when: config.evalRhsWhen }] };
22
+ if (config.lazy && i === 1) {
23
+ return { ...d, cds: [...d.cds ?? [], { id: rootId, when: config.evalRhsWhen ?? true }] };
26
24
  }
27
25
  return d;
28
26
  },
@@ -30,9 +28,8 @@ function processSpecialBinOp(name, args, rootId, data, config) {
30
28
  });
31
29
  for (const arg of processedArguments) {
32
30
  if (arg) {
33
- information.graph.addEdge(name.info.id, arg.entryPoint, edge_1.EdgeType.Reads);
31
+ information.graph.addEdge(rootId, arg.entryPoint, edge_1.EdgeType.Reads);
34
32
  }
35
- // only do first if lazy
36
33
  if (config.lazy) {
37
34
  break;
38
35
  }
@@ -20,6 +20,11 @@ export declare function processStackEnv<OtherInfo>(name: RSymbol<OtherInfo & Par
20
20
  * or a named search-path entry via `as.environment("package:x")`. Returns `undefined` otherwise.
21
21
  */
22
22
  export declare function resolveNodeToStackEnv<Info>(node: RNode<Info> | undefined, data: StackEnvContext): REnvironmentInformation | undefined;
23
- /** If `sourceInfo`'s entry is a {@link BuiltInProcName.StackEnv} call, the stack environment it refers to; else `undefined`. */
23
+ /** The stack environment `sourceInfo`'s entry call refers to (`e <- globalenv()`, `e <- environment()`), or `undefined`. */
24
24
  export declare function stackEnvStateFromSource(sourceInfo: DataflowInformation, data: StackEnvContext): REnvironmentInformation | undefined;
25
+ /**
26
+ * Whether a `$`/`[[` on the stack env `node` denotes reads through the enclosing scopes.
27
+ * Only the rlang pronoun `.env` does: it names the surrounding scope, while `$` on a real environment stays in its frame.
28
+ */
29
+ export declare function stackEnvInheritsFields<Info>(node: RNode<Info> | undefined): boolean;
25
30
  export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processStackEnv = processStackEnv;
4
4
  exports.resolveNodeToStackEnv = resolveNodeToStackEnv;
5
5
  exports.stackEnvStateFromSource = stackEnvStateFromSource;
6
+ exports.stackEnvInheritsFields = stackEnvInheritsFields;
6
7
  const known_call_handling_1 = require("../known-call-handling");
7
8
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
8
9
  const environment_1 = require("../../../../../environments/environment");
@@ -10,6 +11,8 @@ const vertex_1 = require("../../../../../graph/vertex");
10
11
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
11
12
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
12
13
  const default_builtin_config_1 = require("../../../../../environments/default-builtin-config");
14
+ /** The rlang pronoun for the scope surrounding a data mask. */
15
+ const EnvPronoun = '.env';
13
16
  /** The stack env kind a builtin/constant `name` denotes, or `undefined`. */
14
17
  function stackEnvKind(name) {
15
18
  return default_builtin_config_1.StackEnvBuiltins[name];
@@ -85,12 +88,26 @@ function asSearchPathEnv(name, data) {
85
88
  }
86
89
  return undefined;
87
90
  }
88
- /** If `sourceInfo`'s entry is a {@link BuiltInProcName.StackEnv} call, the stack environment it refers to; else `undefined`. */
91
+ /** The stack environment `sourceInfo`'s entry call refers to (`e <- globalenv()`, `e <- environment()`), or `undefined`. */
89
92
  function stackEnvStateFromSource(sourceInfo, data) {
90
93
  const vertex = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
91
- if (!vertex_1.FunctionCallVertex.is(vertex) || vertex.name === undefined || !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.StackEnv)) {
94
+ if (!vertex_1.FunctionCallVertex.is(vertex) || vertex.name === undefined) {
92
95
  return undefined;
93
96
  }
94
- return fixedStackEnv(stackEnvKind(String(vertex.name)), data);
97
+ const kind = stackEnvKind(String(vertex.name));
98
+ if (vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.StackEnv)) {
99
+ return fixedStackEnv(kind, data);
100
+ }
101
+ /* `environment()` goes through the default processor; with an argument it denotes a closure's env instead */
102
+ return kind === default_builtin_config_1.StackEnvKind.Current && vertex.args.length === 0 && vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Default)
103
+ ? { current: data.environment.current, level: data.environment.level }
104
+ : undefined;
105
+ }
106
+ /**
107
+ * Whether a `$`/`[[` on the stack env `node` denotes reads through the enclosing scopes.
108
+ * Only the rlang pronoun `.env` does: it names the surrounding scope, while `$` on a real environment stays in its frame.
109
+ */
110
+ function stackEnvInheritsFields(node) {
111
+ return node?.type === type_1.RType.Symbol && String(node.content) === EnvPronoun;
95
112
  }
96
113
  //# sourceMappingURL=built-in-stack-env.js.map
@@ -5,8 +5,7 @@ const known_call_handling_1 = require("../known-call-handling");
5
5
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
6
  const logger_1 = require("../../../../../logger");
7
7
  const defaultmap_1 = require("../../../../../../util/collections/defaultmap");
8
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
9
- const general_1 = require("../../../../../eval/values/general");
8
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
10
9
  const assert_1 = require("../../../../../../util/assert");
11
10
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
12
11
  const identifier_1 = require("../../../../../environments/identifier");
@@ -45,12 +44,11 @@ function processStopIfNot(name, args, rootId, data) {
45
44
  }
46
45
  const localArgs = argMap.get('local');
47
46
  const localArg = localArgs.length > 0 ? localArgs.at(-1) : undefined;
48
- const resolveArgs = { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx };
49
47
  // we collect all control dependencies from: all '...', all expressions in 'exprs', and 'exprObject'
50
48
  const ids = collectIdsForControl(argMap, data);
51
49
  if (localArg !== undefined && localArg !== r_function_call_1.EmptyArgument) {
52
- const localVal = (0, alias_tracking_1.resolveIdToValue)(localArg?.value?.info.id, resolveArgs);
53
- const alwaysTrue = (0, general_1.valueSetGuard)(localVal)?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
50
+ const localVal = node_value_1.NodeValue.setOf(localArg?.value?.info.id, data);
51
+ const alwaysTrue = localVal?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
54
52
  if (!alwaysTrue) {
55
53
  logger_1.dataflowLogger.warn(`stopifnot (${identifier_1.Identifier.toString(name.content)}) with non-true 'local' argument is not yet supported, over-approximate`);
56
54
  const cds = (data.cds ?? []).concat(Array.from(ids).map(r => ({
@@ -67,8 +65,8 @@ function processStopIfNot(name, args, rootId, data) {
67
65
  }
68
66
  const cds = [];
69
67
  for (const id of ids) {
70
- const val = (0, alias_tracking_1.resolveIdToValue)(id, resolveArgs);
71
- const alwaysFalse = (0, general_1.valueSetGuard)(val)?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
68
+ const val = node_value_1.NodeValue.setOf(id, data);
69
+ const alwaysFalse = val?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
72
70
  if (alwaysFalse) {
73
71
  // we know that this fails *always*
74
72
  res.exitPoints.push(data.cds ? {
@@ -81,7 +79,7 @@ function processStopIfNot(name, args, rootId, data) {
81
79
  });
82
80
  return res;
83
81
  }
84
- const alwaysTrue = (0, general_1.valueSetGuard)(val)?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
82
+ const alwaysTrue = val?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
85
83
  if (!alwaysTrue) {
86
84
  cds.push({
87
85
  id: id,
@@ -0,0 +1,25 @@
1
+ import type { DataflowProcessorInformation } from '../../../../../processor';
2
+ import type { DataflowInformation } from '../../../../../info';
3
+ import { type ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
+ import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
+ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
+ export interface StringTemplateConfiguration {
8
+ /** what opens an interpolation, `{` unless given */
9
+ readonly open?: string;
10
+ /** what closes it, `}` unless given */
11
+ readonly close?: string;
12
+ /** whether `{.cls ...}` styles its content instead of evaluating it, as cli does */
13
+ readonly markup?: boolean;
14
+ }
15
+ /**
16
+ * The R expressions a template interpolates. A doubled delimiter escapes it, delimiters nest, and one inside a
17
+ * string is literal, so this walks the template. With `markup`, `{.cls ...}` contributes its content instead.
18
+ */
19
+ export declare function interpolationsOf(template: string, open: string, close: string, markup?: boolean): readonly string[];
20
+ /**
21
+ * Processes a call whose string arguments are templates carrying R code, as `glue` and `cli` use them.
22
+ * The code runs where the call is, reading and writing like anything written there, so that is how it is
23
+ * analyzed. A template pointed at another scope is marked unknown instead.
24
+ */
25
+ export declare function processStringTemplate<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: StringTemplateConfiguration): DataflowInformation;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interpolationsOf = interpolationsOf;
4
+ exports.processStringTemplate = processStringTemplate;
5
+ const known_call_handling_1 = require("../known-call-handling");
6
+ const retriever_1 = require("../../../../../../r-bridge/retriever");
7
+ const decorate_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate");
8
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
9
+ const identifier_1 = require("../../../../../environments/identifier");
10
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
11
+ const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
12
+ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
13
+ const built_in_source_1 = require("./built-in-source");
14
+ const linker_1 = require("../../../../linker");
15
+ /** Arguments naming the scope the template runs against, which we cannot follow. */
16
+ const RedirectingParameters = ['.envir', '.con', '.x', '.data'];
17
+ /** cli markup: `{.cls text}` styles its content, so the class is no expression but the content may hold some. */
18
+ const Markup = /^\.[A-Za-z][\w.-]*[\s]/;
19
+ /**
20
+ * The R expressions a template interpolates. A doubled delimiter escapes it, delimiters nest, and one inside a
21
+ * string is literal, so this walks the template. With `markup`, `{.cls ...}` contributes its content instead.
22
+ */
23
+ function interpolationsOf(template, open, close, markup = false) {
24
+ const found = [];
25
+ let at = 0;
26
+ while (at < template.length) {
27
+ if (template.startsWith(open + open, at)) {
28
+ at += 2 * open.length;
29
+ continue;
30
+ }
31
+ else if (!template.startsWith(open, at)) {
32
+ at += 1;
33
+ continue;
34
+ }
35
+ const from = at + open.length;
36
+ let depth = 1, quote = undefined, i = from;
37
+ for (; i < template.length && depth > 0; i++) {
38
+ const c = template[i];
39
+ if (quote !== undefined) {
40
+ quote = c === '\\' ? (i++, quote) : c === quote ? undefined : quote;
41
+ }
42
+ else if (c === '"' || c === '\'' || c === '`') {
43
+ quote = c;
44
+ }
45
+ else if (template.startsWith(open, i)) {
46
+ depth++;
47
+ }
48
+ else if (template.startsWith(close, i)) {
49
+ depth--;
50
+ }
51
+ }
52
+ if (depth === 0) {
53
+ const content = template.slice(from, i - close.length);
54
+ if (markup && Markup.test(content)) {
55
+ found.push(...interpolationsOf(content, open, close, markup));
56
+ }
57
+ else {
58
+ found.push(content);
59
+ }
60
+ }
61
+ at = i;
62
+ }
63
+ return found;
64
+ }
65
+ /** The argument given under `name`, `undefined` if the call does not name it. */
66
+ function namedArgument(args, name) {
67
+ return args.find((a) => a !== r_function_call_1.EmptyArgument && a.name !== undefined
68
+ && identifier_1.Identifier.getName(a.name.content) === name);
69
+ }
70
+ /** The string a named argument spells out, `undefined` unless it is a literal. */
71
+ function literalOf(args, name) {
72
+ const value = namedArgument(args, name)?.value;
73
+ return value?.type === type_1.RType.String ? value.content.str : undefined;
74
+ }
75
+ /**
76
+ * Processes a call whose string arguments are templates carrying R code, as `glue` and `cli` use them.
77
+ * The code runs where the call is, reading and writing like anything written there, so that is how it is
78
+ * analyzed. A template pointed at another scope is marked unknown instead.
79
+ */
80
+ function processStringTemplate(name, args, rootId, data, config) {
81
+ const { information } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.StringTemplate });
82
+ /* these are only ever given by name, and matching them positionally would swallow the template itself */
83
+ if (RedirectingParameters.some(p => namedArgument(args, p) !== undefined)) {
84
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
85
+ return information;
86
+ }
87
+ const open = literalOf(args, '.open') ?? config.open ?? '{';
88
+ const close = literalOf(args, '.close') ?? config.close ?? '}';
89
+ const results = [];
90
+ for (const arg of args) {
91
+ if (arg === r_function_call_1.EmptyArgument || arg.name !== undefined || arg.value?.type !== type_1.RType.String) {
92
+ continue;
93
+ }
94
+ const template = arg.value;
95
+ for (const code of interpolationsOf(template.content.str, open, close, config.markup)) {
96
+ const generator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(`${name.lexeme}::${template.info.id}`, template.location);
97
+ const result = (0, built_in_source_1.sourceRequest)(rootId, (0, retriever_1.requestFromInput)(code), data, information, false, generator);
98
+ /* the template stands where the call does, so what it leaves open resolves against the bindings here */
99
+ (0, linker_1.linkInputs)([...result.in, ...result.unknownReferences], data.environment, [], result.graph, false);
100
+ results.push(result);
101
+ }
102
+ }
103
+ return (0, built_in_source_1.mergeSourced)(information, results);
104
+ }
105
+ //# sourceMappingURL=built-in-string-template.js.map
@@ -13,9 +13,6 @@ const assert_1 = require("../../../../../../util/assert");
13
13
  const edge_1 = require("../../../../../graph/edge");
14
14
  const unnamed_call_handling_1 = require("../unnamed-call-handling");
15
15
  const identifier_1 = require("../../../../../environments/identifier");
16
- const identifier_2 = require("../../../../../environments/identifier");
17
- const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
18
- const log_1 = require("../../../../../../util/log");
19
16
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
20
17
  /**
21
18
  * Process a built-in try-catch or similar handler.
@@ -125,30 +122,7 @@ function promoteCallToFunction(call, arg, info, data) {
125
122
  info.graph.addEdge(arg, functionId, edge_1.EdgeType.Calls | edge_1.EdgeType.Reads);
126
123
  const dfVert = info.graph.getVertex(call);
127
124
  if (dfVert && dfVert.tag === vertex_1.VertexType.FunctionDefinition) {
128
- // resolve all ingoings against the environment
129
- const ingoingRefs = dfVert.subflow.in;
130
- const remainingIn = [];
131
- for (const ingoing of ingoingRefs) {
132
- const resolved = ingoing.name ? (0, resolve_by_name_1.resolveByName)(ingoing.name, data.environment, ingoing.type) : undefined;
133
- if (resolved === undefined) {
134
- remainingIn.push(ingoing);
135
- continue;
136
- }
137
- (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Found ${resolved.length} references to open ref ${ingoing.nodeId} in closure of function definition ${call}`);
138
- let allBuiltIn = true;
139
- for (const ref of resolved) {
140
- const rid = ref.nodeId;
141
- info.graph.addEdge(ingoing.nodeId, rid, edge_1.EdgeType.Reads);
142
- info.graph.addEdge(call, rid, edge_1.EdgeType.Reads); // because the def. is the anonymous call
143
- if (!(0, identifier_2.isReferenceType)(ref.type, identifier_2.ReferenceType.BuiltInConstant | identifier_2.ReferenceType.BuiltInFunction)) {
144
- allBuiltIn = false;
145
- }
146
- }
147
- if (allBuiltIn) {
148
- remainingIn.push(ingoing);
149
- }
150
- }
151
- dfVert.subflow.in = remainingIn;
125
+ linker_1.ClosureRefs.resolveOpenIngoing(info.graph, call, dfVert, data.environment);
152
126
  }
153
127
  // we did the linking
154
128
  return undefined;
@@ -10,8 +10,7 @@ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model
10
10
  const logger_1 = require("../../../../../logger");
11
11
  const edge_1 = require("../../../../../graph/edge");
12
12
  const identifier_1 = require("../../../../../environments/identifier");
13
- const general_1 = require("../../../../../eval/values/general");
14
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
13
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
15
14
  const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
16
15
  const apply_kill_1 = require("../../../../../environments/apply-kill");
17
16
  const append_1 = require("../../../../../environments/append");
@@ -32,8 +31,8 @@ function processWhileLoop(name, args, rootId, data) {
32
31
  const nameId = name.info.id;
33
32
  const origEnv = data.environment;
34
33
  // we should defer this to the abstract interpretation
35
- const values = (0, alias_tracking_1.resolveIdToValue)(unpackedArgs[0]?.info.id, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx });
36
- const conditionIsAlwaysFalse = (0, general_1.valueSetGuard)(values)?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
34
+ const values = node_value_1.NodeValue.setOf(unpackedArgs[0]?.info.id, data);
35
+ const conditionIsAlwaysFalse = values?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
37
36
  //We don't care about the body if it never executes
38
37
  if (conditionIsAlwaysFalse) {
39
38
  unpackedArgs.pop();
@@ -62,7 +61,7 @@ function processWhileLoop(name, args, rootId, data) {
62
61
  hooks: condition.hooks
63
62
  };
64
63
  }
65
- const conditionIsAlwaysTrue = (0, general_1.valueSetGuard)(values)?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
64
+ const conditionIsAlwaysTrue = values?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
66
65
  (0, assert_1.guard)(condition !== undefined && body !== undefined, () => `While-Loop ${identifier_1.Identifier.toString(name.content)} has no condition or body, impossible!`);
67
66
  const originalDependency = data.cds;
68
67
  if ((0, info_1.alwaysExits)(condition)) {
@@ -15,7 +15,7 @@ const withParamsFallback = ['data', 'expr'];
15
15
  /** Normal call analysis, marking the data-masked arguments (columns of the data) as NSE. */
16
16
  function markAsMaskedFallback(name, args, rootId, data) {
17
17
  const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.With });
18
- (0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, known_call_handling_1.NseArguments.AllButFirst, known_call_handling_1.NseKind.DataMasked);
18
+ (0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, known_call_handling_1.NseArguments.AllButFirst, { kind: known_call_handling_1.NseKind.DataMasked });
19
19
  return information;
20
20
  }
21
21
  /**
@@ -0,0 +1,41 @@
1
+ import type { AstIdMap, ParentInformation } from '../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
+ import type { NodeId } from '../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
3
+ import type { DataflowGraph } from '../../../../graph/graph';
4
+ import type { ControlFlowGraph } from '../../../../../control-flow/control-flow-graph';
5
+ /** The reads that may force the expression, and the control flow deciding what they can see. */
6
+ export interface ForceSites {
7
+ readonly cfg: ControlFlowGraph;
8
+ readonly sites: readonly NodeId[];
9
+ /** the name the deferred expression is bound to, whose binding its own writes replace */
10
+ readonly binding: NodeId;
11
+ }
12
+ /** Where a name is bound and where it is read, so that a deferred expression can reach either. */
13
+ interface NameIndex {
14
+ readonly definitions: ReadonlyMap<string, NodeId[]>;
15
+ readonly uses: ReadonlyMap<string, NodeId[]>;
16
+ }
17
+ /**
18
+ * An expression R evaluates at a time we cannot pin down: the body a `delayedAssign` binds, forced at some
19
+ * later read of the name, or a promise a closure carries past the call that created it.
20
+ *
21
+ * Since the moment is open, every binding the expression may meet is a candidate, and symmetrically so:
22
+ * a name it reads may read any definition of that name, and a name it writes may be read by any use of it.
23
+ * That is the may-analysis both directions ask for, so nothing the expression really depends on, and nothing
24
+ * really depending on it, can be missed.
25
+ */
26
+ export declare const Deferred: {
27
+ /** Where each name is bound and read, built once and shared by every deferred expression in the graph. */
28
+ readonly indexOf: <Info>(this: void, graph: DataflowGraph, idMap: AstIdMap<Info & ParentInformation>) => NameIndex;
29
+ /**
30
+ * The reads that may be the one forcing `binding`: every read of it that no other read always precedes,
31
+ * since an earlier read would already have forced it and cached the value.
32
+ */
33
+ readonly forcedAt: (this: void, graph: DataflowGraph, binding: NodeId, cfg: ControlFlowGraph) => readonly NodeId[];
34
+ /**
35
+ * Links the expression rooted at `expr` to the bindings it may meet when it is evaluated. Given the reads
36
+ * that may force it, control flow rules out what no force can reach; without them every binding stays a
37
+ * candidate.
38
+ */
39
+ readonly link: <Info>(this: void, graph: DataflowGraph, expr: NodeId, index: NameIndex, idMap: AstIdMap<Info & ParentInformation>, forces?: ForceSites) => void;
40
+ };
41
+ export {};
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Deferred = void 0;
4
+ const model_1 = require("../../../../../r-bridge/lang-4.x/ast/model/model");
5
+ const r_function_call_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
+ const type_1 = require("../../../../../r-bridge/lang-4.x/ast/model/type");
7
+ const node_id_1 = require("../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
8
+ const identifier_1 = require("../../../../environments/identifier");
9
+ const retriever_1 = require("../../../../../r-bridge/retriever");
10
+ const edge_1 = require("../../../../graph/edge");
11
+ const vertex_1 = require("../../../../graph/vertex");
12
+ const happens_before_1 = require("../../../../../control-flow/happens-before");
13
+ const logic_1 = require("../../../../../util/logic");
14
+ /** Drops the read of `target` from `use`, for a binding another write has replaced. */
15
+ function dropRead(graph, use, target) {
16
+ graph.removeEdgeType(use, target, edge_1.EdgeType.Reads);
17
+ }
18
+ function add(index, name, id) {
19
+ const known = index.get(name);
20
+ if (known) {
21
+ known.push(id);
22
+ }
23
+ else {
24
+ index.set(name, [id]);
25
+ }
26
+ }
27
+ /** The names a deferred expression touches, each with the node touching it and whether it is written. */
28
+ function namesWithin(expr, graph, idMap) {
29
+ const node = idMap.get(expr);
30
+ const names = [];
31
+ if (node === undefined) {
32
+ return names;
33
+ }
34
+ const callees = new Set();
35
+ model_1.RNode.visitAst(node, inner => {
36
+ if (r_function_call_1.RFunctionCall.isNamed(inner)) {
37
+ callees.add(inner.functionName.info.id);
38
+ return false;
39
+ }
40
+ else if (inner.type !== type_1.RType.Symbol || callees.has(inner.info.id)) {
41
+ return false;
42
+ }
43
+ const vertex = graph.getVertex(inner.info.id);
44
+ if (vertex_1.UseVertex.is(vertex) || vertex_1.VariableDefinitionVertex.is(vertex)) {
45
+ names.push([inner.info.id, identifier_1.Identifier.getName(inner.content), vertex_1.VariableDefinitionVertex.is(vertex)]);
46
+ }
47
+ return false;
48
+ });
49
+ return names;
50
+ }
51
+ /**
52
+ * An expression R evaluates at a time we cannot pin down: the body a `delayedAssign` binds, forced at some
53
+ * later read of the name, or a promise a closure carries past the call that created it.
54
+ *
55
+ * Since the moment is open, every binding the expression may meet is a candidate, and symmetrically so:
56
+ * a name it reads may read any definition of that name, and a name it writes may be read by any use of it.
57
+ * That is the may-analysis both directions ask for, so nothing the expression really depends on, and nothing
58
+ * really depending on it, can be missed.
59
+ */
60
+ exports.Deferred = {
61
+ /** Where each name is bound and read, built once and shared by every deferred expression in the graph. */
62
+ indexOf(graph, idMap) {
63
+ const definitions = new Map();
64
+ const uses = new Map();
65
+ for (const [type, index] of [[vertex_1.VertexType.VariableDefinition, definitions], [vertex_1.VertexType.Use, uses]]) {
66
+ for (const [id] of graph.verticesOfType(type)) {
67
+ const name = (0, node_id_1.recoverName)(id, idMap);
68
+ if (name !== undefined) {
69
+ add(index, name, id);
70
+ }
71
+ }
72
+ }
73
+ return { definitions, uses };
74
+ },
75
+ /**
76
+ * The reads that may be the one forcing `binding`: every read of it that no other read always precedes,
77
+ * since an earlier read would already have forced it and cached the value.
78
+ */
79
+ forcedAt(graph, binding, cfg) {
80
+ const reads = [];
81
+ for (const [reader, edge] of graph.ingoingEdges(binding) ?? []) {
82
+ if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
83
+ reads.push(reader);
84
+ }
85
+ }
86
+ return reads.filter(r => !reads.some(other => other !== r && (0, happens_before_1.happensBefore)(cfg, other, r) === logic_1.Ternary.Always));
87
+ },
88
+ /**
89
+ * Links the expression rooted at `expr` to the bindings it may meet when it is evaluated. Given the reads
90
+ * that may force it, control flow rules out what no force can reach; without them every binding stays a
91
+ * candidate.
92
+ */
93
+ link(graph, expr, index, idMap, forces) {
94
+ const within = namesWithin(expr, graph, idMap);
95
+ const own = new Set(within.map(([id]) => id));
96
+ /* a binding matters only if some force can see it, and a use only if some force can reach it */
97
+ const seenByAForce = (definition) => forces === undefined
98
+ || forces.sites.some(site => (0, happens_before_1.happensBefore)(forces.cfg, definition, site) !== logic_1.Ternary.Never);
99
+ /* the forcing read yields the promise's value, so only reads after it observe what the promise wrote */
100
+ const reachedByAForce = (use) => forces === undefined
101
+ || (!forces.sites.includes(use) && forces.sites.some(site => (0, happens_before_1.happensBefore)(forces.cfg, site, use) !== logic_1.Ternary.Never));
102
+ /* `delayedAssign` names its variable with a string literal, so the recovered name still carries quotes */
103
+ const bindingName = forces === undefined ? undefined : (0, retriever_1.removeRQuotes)((0, node_id_1.recoverName)(forces.binding, idMap) ?? '');
104
+ for (const [node, name, writes] of within) {
105
+ if (writes) {
106
+ /* a write of the bound name replaces the binding, so a read it definitely reaches sees only it */
107
+ const shadows = forces !== undefined && name === bindingName && graph.getVertex(node)?.cds === undefined;
108
+ for (const use of index.uses.get(name) ?? []) {
109
+ if (!own.has(use) && reachedByAForce(use)) {
110
+ graph.addEdge(use, node, edge_1.EdgeType.Reads);
111
+ if (shadows && forces.sites.some(site => (0, happens_before_1.happensBefore)(forces.cfg, site, use) === logic_1.Ternary.Always)) {
112
+ dropRead(graph, use, forces.binding);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ else {
118
+ for (const definition of index.definitions.get(name) ?? []) {
119
+ if (seenByAForce(definition)) {
120
+ graph.addEdge(node, definition, edge_1.EdgeType.Reads);
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ };
127
+ //# sourceMappingURL=deferred.js.map