@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
@@ -11,37 +11,46 @@ const log_1 = require("../../../../../../util/log");
11
11
  const built_in_source_1 = require("./built-in-source");
12
12
  const edge_1 = require("../../../../../graph/edge");
13
13
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
14
- const append_1 = require("../../../../../environments/append");
15
14
  const assert_1 = require("../../../../../../util/assert");
16
- const general_1 = require("../../../../../eval/values/general");
17
- const string_constants_1 = require("../../../../../eval/values/string/string-constants");
18
15
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
19
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
16
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
20
17
  const arrays_1 = require("../../../../../../util/collections/arrays");
21
18
  const identifier_1 = require("../../../../../environments/identifier");
22
19
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
20
+ /** the formals of `eval(expr, envir, enclos)` */
21
+ const EvalParameterNames = ['expr', 'envir', 'enclos'];
23
22
  /**
24
23
  * Process a call to `eval()`, trying to resolve the code being evaluated if possible.
25
24
  */
26
25
  function processEvalCall(name, args, rootId, data, config) {
27
- if (args.length !== 1 || args[0] === r_function_call_1.EmptyArgument || !args[0].value) {
28
- logger_1.dataflowLogger.warn(`Expected exactly one argument for eval currently, but got ${args.length} instead, skipping`);
29
- return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
26
+ const bound = r_function_call_1.RFunctionCall.matchArgsToParams(args, EvalParameterNames);
27
+ /* `evalText` names its formal differently, so a lone argument is the expression whatever it is called */
28
+ const evalArgument = (bound.get('expr') ?? r_function_call_1.RFunctionCall.soleArgument(args))?.value;
29
+ const envirArg = bound.get('envir');
30
+ if (evalArgument === undefined) {
31
+ logger_1.dataflowLogger.warn(`Expected an expression argument for eval, but got ${args.length} argument(s), skipping`);
32
+ const bail = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
33
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(bail.graph, bail.environment, rootId);
34
+ return bail;
30
35
  }
31
36
  const information = config.includeFunctionCall ?
32
37
  (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: [true], origin: built_in_proc_name_1.BuiltInProcName.Eval }).information
33
38
  : info_1.DataflowInformation.initialize(rootId, data);
34
- const evalArgument = args[0];
35
39
  if (config.includeFunctionCall) {
36
- information.graph.addEdge(rootId, args[0].value.info.id, edge_1.EdgeType.Returns);
40
+ information.graph.addEdge(rootId, evalArgument.info.id, edge_1.EdgeType.Returns);
37
41
  }
38
42
  if (!data.ctx.config.solver.evalStrings) {
39
43
  (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Skipping eval call ${JSON.stringify(evalArgument)} (disabled in config file)`);
40
44
  (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
41
45
  return information;
42
46
  }
43
- const code = resolveEvalToCode(evalArgument.value, config, data);
47
+ const code = resolveEvalToCode(evalArgument, config, data);
44
48
  if (code) {
49
+ if (envirArg !== undefined) {
50
+ /* the code runs in another environment, so its definitions do not land in the current one and
51
+ * pretending they do would produce wrong edges */
52
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
53
+ }
45
54
  const idGenerator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(name.lexeme + '::' + rootId, name.location);
46
55
  data = {
47
56
  ...data,
@@ -58,37 +67,16 @@ function processEvalCall(name, args, rootId, data, config) {
58
67
  information.graph.addEdge(rootId, e.nodeId, edge_1.EdgeType.Returns);
59
68
  }
60
69
  }
61
- return {
62
- graph: result.reduce((acc, r) => acc.mergeWith(r.graph), information.graph),
63
- environment: result.reduce((acc, r) => (0, append_1.appendEnvironment)(acc, r.environment), information.environment),
64
- entryPoint: rootId,
65
- out: information.out.concat(result.flatMap(r => r.out)),
66
- in: information.in.concat(result.flatMap(r => r.in)),
67
- unknownReferences: information.unknownReferences.concat(result.flatMap(r => r.unknownReferences)),
68
- exitPoints: information.exitPoints.concat(result.flatMap(r => r.exitPoints)),
69
- hooks: information.hooks.concat(result.flatMap(r => r.hooks)),
70
- };
70
+ return (0, built_in_source_1.mergeSourced)({ ...information, entryPoint: rootId }, result);
71
71
  }
72
72
  (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Non-constant argument ${JSON.stringify(args)} for eval is currently not supported, skipping`);
73
73
  (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
74
74
  return information;
75
75
  }
76
76
  function resolveEvalToCode(evalArgument, config, data) {
77
- const ctx = data.ctx;
78
- const env = data.environment;
79
- const idMap = data.completeAst.idMap;
80
77
  const val = evalArgument;
81
78
  if (config.supportFunctionCall) {
82
- if (val.type === type_1.RType.String) {
83
- return [val.content.str];
84
- }
85
- else if (val.type === type_1.RType.Symbol) {
86
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(val.info.id, { environment: env, idMap: idMap, resolve: ctx.config.solver.variables, ctx }));
87
- if (resolved) {
88
- return (0, string_constants_1.collectStrings)(resolved.elements);
89
- }
90
- }
91
- return undefined;
79
+ return getAsString(val, data);
92
80
  }
93
81
  else {
94
82
  if (val.type === type_1.RType.FunctionCall && val.named && val.functionName.content === 'parse') {
@@ -97,19 +85,10 @@ function resolveEvalToCode(evalArgument, config, data) {
97
85
  if (nArg !== undefined || arg === undefined || arg === r_function_call_1.EmptyArgument) {
98
86
  return undefined;
99
87
  }
100
- if (arg.value?.type === type_1.RType.String) {
101
- return [arg.value.content.str];
102
- }
103
- else if (arg.value?.type === type_1.RType.Symbol) {
104
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(arg.value.info.id, { environment: env, idMap: idMap, resolve: ctx.config.solver.variables, ctx }));
105
- if (resolved) {
106
- return (0, string_constants_1.collectStrings)(resolved.elements);
107
- }
108
- }
109
- else if (arg.value?.type === type_1.RType.FunctionCall && arg.value.named && ['paste', 'paste0'].includes(identifier_1.Identifier.getName(arg.value.functionName.content))) {
110
- return handlePaste(ctx.config, arg.value.arguments, env, idMap, arg.value.functionName.content === 'paste' ? [' '] : [''], ctx);
88
+ if (arg.value?.type === type_1.RType.FunctionCall && arg.value.named && ['paste', 'paste0'].includes(identifier_1.Identifier.getName(arg.value.functionName.content))) {
89
+ return handlePaste(arg.value.arguments, data, arg.value.functionName.content === 'paste' ? [' '] : ['']);
111
90
  }
112
- return undefined;
91
+ return getAsString(arg.value, data);
113
92
  }
114
93
  else if (val.type === type_1.RType.Symbol) {
115
94
  // const resolved = resolveValueOfVariable(val.content, env);
@@ -121,7 +100,7 @@ function resolveEvalToCode(evalArgument, config, data) {
121
100
  }
122
101
  }
123
102
  }
124
- function getAsString(config, val, env, idMap, ctx) {
103
+ function getAsString(val, data) {
125
104
  if (!val) {
126
105
  return undefined;
127
106
  }
@@ -129,17 +108,14 @@ function getAsString(config, val, env, idMap, ctx) {
129
108
  return [val.content.str];
130
109
  }
131
110
  else if (val.type === type_1.RType.Symbol) {
132
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(val.info.id, { environment: env, idMap: idMap, resolve: config.solver.variables, ctx }));
133
- if (resolved) {
134
- return (0, string_constants_1.collectStrings)(resolved.elements);
135
- }
111
+ return node_value_1.NodeValue.stringsOf(val.info.id, data);
136
112
  }
137
113
  return undefined;
138
114
  }
139
- function handlePaste(config, args, env, idMap, sepDefault, ctx) {
115
+ function handlePaste(args, data, sepDefault) {
140
116
  const sepArg = args.find(v => v !== r_function_call_1.EmptyArgument && v.name?.content === 'sep');
141
117
  if (sepArg) {
142
- const res = sepArg !== r_function_call_1.EmptyArgument && sepArg.value ? getAsString(config, sepArg.value, env, idMap, ctx) : undefined;
118
+ const res = sepArg !== r_function_call_1.EmptyArgument && sepArg.value ? getAsString(sepArg.value, data) : undefined;
143
119
  if (!res) {
144
120
  // sep not resolvable clearly / unknown
145
121
  return undefined;
@@ -148,7 +124,7 @@ function handlePaste(config, args, env, idMap, sepDefault, ctx) {
148
124
  }
149
125
  const allArgs = args
150
126
  .filter(v => v !== r_function_call_1.EmptyArgument && v.name?.content !== 'sep' && v.value)
151
- .map(v => getAsString(config, v.value, env, idMap, ctx));
127
+ .map(v => getAsString(v.value, data));
152
128
  if (allArgs.some(assert_1.isUndefined)) {
153
129
  return undefined;
154
130
  }
@@ -10,8 +10,7 @@ const logger_1 = require("../../../../../logger");
10
10
  const edge_1 = require("../../../../../graph/edge");
11
11
  const append_1 = require("../../../../../environments/append");
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 linker_1 = require("../../../../linker");
@@ -64,9 +63,9 @@ function processIfThenElse(name, args, rootId, data, config) {
64
63
  let then;
65
64
  let makeThenMaybe = false;
66
65
  // we should defer this to the abstract interpretation
67
- const values = (0, alias_tracking_1.resolveIdToValue)(condArg?.info.id, { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx });
68
- const conditionIsAlwaysFalse = (0, general_1.valueSetGuard)(values)?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
69
- const conditionIsAlwaysTrue = (0, general_1.valueSetGuard)(values)?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
66
+ const values = node_value_1.NodeValue.setOf(condArg?.info.id, data);
67
+ const conditionIsAlwaysFalse = values?.elements.every(d => d.type === 'logical' && d.value === false) ?? false;
68
+ const conditionIsAlwaysTrue = values?.elements.every(d => d.type === 'logical' && d.value === true) ?? false;
70
69
  if (!conditionIsAlwaysFalse) {
71
70
  then = (0, processor_1.processDataflowFor)(thenArg, data);
72
71
  if (then.entryPoint) {
@@ -8,6 +8,7 @@ exports.attachBaseRNamespaces = attachBaseRNamespaces;
8
8
  exports.attachDeclaredDependencies = attachDeclaredDependencies;
9
9
  exports.attachProjectImports = attachProjectImports;
10
10
  exports.attachProject = attachProject;
11
+ const r_value_1 = require("../../../../../eval/values/r-value");
11
12
  const known_call_handling_1 = require("../known-call-handling");
12
13
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
13
14
  const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
@@ -22,8 +23,7 @@ const environment_1 = require("../../../../../environments/environment");
22
23
  const edge_1 = require("../../../../../graph/edge");
23
24
  const assert_1 = require("../../../../../../util/assert");
24
25
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
25
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
26
- const general_1 = require("../../../../../eval/values/general");
26
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
27
27
  const package_1 = require("../../../../../../project/plugins/package-version-plugins/package");
28
28
  const attached_packages_1 = require("../../../../../../project/attached-packages");
29
29
  const flowr_namespace_file_1 = require("../../../../../../project/plugins/file-plugins/files/flowr-namespace-file");
@@ -51,7 +51,6 @@ function processLibrary(name, args, rootId, data, config = {}) {
51
51
  /* last, so the positional fallback keeps its previous order */
52
52
  'pos': 'pos'
53
53
  };
54
- const resolveArgs = { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx };
55
54
  const argMaps = (0, linker_1.pMatch)((0, common_1.convertFnArguments)(args), params);
56
55
  const packageId = Array.from(new Set(argMaps.get('pkg')));
57
56
  const charId = Array.from(new Set(argMaps.get('char')));
@@ -71,7 +70,7 @@ function processLibrary(name, args, rootId, data, config = {}) {
71
70
  }
72
71
  let isCharacterOnly = config.characterOnly === true;
73
72
  if (!config.characterOnly && charId.length >= 1) {
74
- const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(charId[0], resolveArgs));
73
+ const values = node_value_1.NodeValue.setOf(charId[0], data);
75
74
  if (values?.type === 'set' && values?.elements.length > 0) {
76
75
  let hasTrue = 0;
77
76
  let hasFalse = 0;
@@ -109,11 +108,12 @@ function processLibrary(name, args, rootId, data, config = {}) {
109
108
  //case: true or maybe
110
109
  if (isCharacterOnly) {
111
110
  for (const nameToLoad of namesToLoad) {
112
- const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(nameToLoad.info.id, resolveArgs));
111
+ const values = node_value_1.NodeValue.setOf(nameToLoad.info.id, data);
113
112
  if (values?.type === 'set' && values.elements.length !== 0) {
114
113
  for (const elem of values.elements) {
115
- if (elem.type === 'string' && 'str' in elem.value) {
116
- packetName.push(elem.value.str);
114
+ const name = r_value_1.RValue.stringOf(elem);
115
+ if (name !== undefined) {
116
+ packetName.push(name);
117
117
  }
118
118
  }
119
119
  }
@@ -12,8 +12,7 @@ const logger_1 = require("../../../../../logger");
12
12
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
13
13
  const edge_1 = require("../../../../../graph/edge");
14
14
  const unpack_argument_1 = require("../argument/unpack-argument");
15
- const general_1 = require("../../../../../eval/values/general");
16
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
15
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
17
16
  const r_value_1 = require("../../../../../eval/values/r-value");
18
17
  const assert_1 = require("../../../../../../util/assert");
19
18
  const range_1 = require("../../../../../../util/range");
@@ -47,7 +46,7 @@ function processLoadCall(name, args, rootId, data) {
47
46
  sourceFile = [(0, retriever_1.removeRQuotes)(fileArg.lexeme)];
48
47
  }
49
48
  else {
50
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(fileArg.info.id, { environment: envirResolution ? envirResolution.envirData.environment : data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx }));
49
+ const resolved = node_value_1.NodeValue.setOf(fileArg.info.id, data, { environment: envirResolution?.envirData.environment ?? data.environment });
51
50
  sourceFile = resolved?.elements.map(r => r.type === 'string' && (0, r_value_1.isValue)(r.value) ? r.value.str : undefined).filter(assert_1.isNotUndefined);
52
51
  }
53
52
  if (sourceFile) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processPipe = processPipe;
4
4
  const known_call_handling_1 = require("../known-call-handling");
5
+ const nse_1 = require("../nse");
5
6
  const assert_1 = require("../../../../../../util/assert");
6
7
  const unpack_argument_1 = require("../argument/unpack-argument");
7
8
  const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
@@ -17,6 +18,23 @@ const make_argument_1 = require("../argument/make-argument");
17
18
  const built_in_assignment_1 = require("./built-in-assignment");
18
19
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
19
20
  const log_1 = require("../../../../../../util/log");
21
+ /** Piping the data in shifts the arguments, so the call's own `all-but-first` marking misses them. */
22
+ function markPipedDataMask(rhs, graph) {
23
+ for (const arg of rhs.arguments) {
24
+ if (arg === r_function_call_1.EmptyArgument) {
25
+ continue;
26
+ }
27
+ model_1.RNode.visitAst(arg, node => {
28
+ if (nse_1.Nse.isUnquote(node, nse_1.Unquote.Rlang)) {
29
+ return true;
30
+ }
31
+ if (r_symbol_1.RSymbol.is(node) && nse_1.Nse.suppliedByMask(graph, node.info.id)) {
32
+ graph.addEdge(rhs.info.id, node.info.id, edge_1.EdgeType.NonStandardEvaluation);
33
+ }
34
+ return false;
35
+ });
36
+ }
37
+ }
20
38
  /**
21
39
  * Support for R's pipe functions like `|>` or magrittr's `%>%`
22
40
  */
@@ -96,18 +114,7 @@ function processPipe(name, args, rootId, data, { pipePlaceholderName, assignLhs,
96
114
  information.graph.addEdge(functionCallNode.id, argId, edge_1.EdgeType.Argument | edge_1.EdgeType.Reads);
97
115
  }
98
116
  if (r_function_call_1.RFunctionCall.isNamed(rhs) && data_masking_functions_1.DataMaskingFunctionNames.has(identifier_1.Identifier.getName(rhs.functionName.content))) {
99
- for (const arg of rhs.arguments) {
100
- if (arg === r_function_call_1.EmptyArgument) {
101
- continue;
102
- }
103
- /* only the symbols may name columns, the rest is evaluated in the caller's frame */
104
- model_1.RNode.visitAst(arg, node => {
105
- if (r_symbol_1.RSymbol.is(node)) {
106
- information.graph.addEdge(rhs.info.id, node.info.id, edge_1.EdgeType.NonStandardEvaluation);
107
- }
108
- return false;
109
- });
110
- }
117
+ markPipedDataMask(rhs, information.graph);
111
118
  }
112
119
  }
113
120
  else {
@@ -27,7 +27,8 @@ function linkOnSymbol(rootId, filteredArgs, node, graph, data) {
27
27
  // If the target directly maps to a function definition AST, try to link arguments to parameters
28
28
  let linked = data.completeAst.idMap.get(def.nodeId);
29
29
  if (linked?.type !== type_1.RType.FunctionDefinition) {
30
- for (const vid of def.value) {
30
+ const values = def.value;
31
+ for (const vid of Array.isArray(values) ? values : []) {
31
32
  const candidate = data.completeAst.idMap.get(vid);
32
33
  if (candidate && candidate.type === type_1.RType.FunctionDefinition) {
33
34
  linked = candidate;
@@ -5,9 +5,12 @@ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-
5
5
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  import type { ForceArguments } from '../common';
8
+ import { Unquote } from '../nse';
8
9
  interface QuoteConfig extends ForceArguments {
9
10
  quoteArgumentsWithIndex: number;
10
11
  envArgIndex?: number;
12
+ /** which unquote escape the function supports, {@link Unquote.None} if unset */
13
+ unquote?: Unquote;
11
14
  }
12
15
  /**
13
16
  * Process a call to `quote` or similar nse/substitution functions.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processQuote = processQuote;
4
4
  const known_call_handling_1 = require("../known-call-handling");
5
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
5
6
  const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
6
7
  const vertex_1 = require("../../../../../graph/vertex");
7
8
  const logger_1 = require("../../../../../logger");
@@ -9,6 +10,8 @@ const df_helper_1 = require("../../../../../graph/df-helper");
9
10
  const edge_1 = require("../../../../../graph/edge");
10
11
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
11
12
  const graph_1 = require("../../../../../graph/graph");
13
+ const nse_1 = require("../nse");
14
+ const linker_1 = require("../../../../linker");
12
15
  /**
13
16
  * Process a call to `quote` or similar nse/substitution functions.
14
17
  */
@@ -27,66 +30,33 @@ function processQuote(name, args, rootId, data, config) {
27
30
  }
28
31
  }
29
32
  });
30
- let inRefs = [fnRef];
31
- let outRefs = [];
32
- let unknownRefs = [];
33
+ const inRefs = [fnRef];
34
+ const outRefs = [];
35
+ const unknownRefs = [];
36
+ const quotedArg = args[config.quoteArgumentsWithIndex];
37
+ const evaluated = nse_1.Nse.unquoted(quotedArg === r_function_call_1.EmptyArgument ? undefined : quotedArg?.value, config.unquote ?? nse_1.Unquote.None);
33
38
  for (let i = 0; i < args.length; i++) {
34
39
  const processedArg = processedArguments[i];
35
- if (processedArg && i !== config?.quoteArgumentsWithIndex) {
36
- inRefs = inRefs.concat(processedArg.in);
37
- outRefs = outRefs.concat(processedArg.out);
38
- unknownRefs = unknownRefs.concat(processedArg.unknownReferences);
40
+ if (processedArg && i !== config.quoteArgumentsWithIndex) {
41
+ inRefs.push(...processedArg.in);
42
+ outRefs.push(...processedArg.out);
43
+ unknownRefs.push(...processedArg.unknownReferences);
39
44
  }
40
- else if (processedArg) {
41
- information.graph.addEdge(rootId, processedArg.entryPoint, edge_1.EdgeType.NonStandardEvaluation);
42
- /* nse actually affects _everything_ within that argument! */
43
- for (const [vtx] of processedArg.graph.vertices(true)) {
44
- information.graph.addEdge(rootId, vtx, edge_1.EdgeType.NonStandardEvaluation);
45
- }
45
+ }
46
+ const quotedProcessed = processedArguments[config.quoteArgumentsWithIndex];
47
+ if (quotedProcessed) {
48
+ (0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, [config.quoteArgumentsWithIndex], { evaluated });
49
+ if (evaluated) {
50
+ /* the argument was processed in a clean env, so the escaped reads need linking by hand */
51
+ const escaped = [...quotedProcessed.in, ...quotedProcessed.unknownReferences].filter(r => evaluated.has(r.nodeId));
52
+ (0, linker_1.linkInputs)(escaped, lastEnv, inRefs, information.graph, false);
46
53
  }
47
54
  }
48
- if (config?.envArgIndex !== undefined) {
55
+ if (config.envArgIndex !== undefined) {
49
56
  const envProcessed = processedArguments[config.envArgIndex];
50
57
  const exprProcessed = processedArguments[config.quoteArgumentsWithIndex];
51
58
  if (envProcessed && exprProcessed) {
52
- try {
53
- // traverse the env processed DFG to find list calls (prefix-aware handling)
54
- df_helper_1.Dataflow.visitDfg(envProcessed.graph, envProcessed.entryPoint, (vtx) => {
55
- if (vtx.tag !== vertex_1.VertexType.FunctionCall) {
56
- return;
57
- }
58
- if (!vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.List)) {
59
- return true;
60
- }
61
- const useMap = new Map();
62
- for (const vType of [vertex_1.VertexType.Use, vertex_1.VertexType.FunctionCall]) {
63
- for (const [useId] of exprProcessed.graph.verticesOfType(vType)) {
64
- const rn = (0, node_id_1.recoverName)(useId, exprProcessed.graph.idMap);
65
- if (rn) {
66
- const arr = useMap.get(rn) ?? [];
67
- arr.push(useId);
68
- useMap.set(rn, arr);
69
- }
70
- }
71
- }
72
- if (useMap.size === 0) {
73
- return true;
74
- }
75
- const listFields = vtx.args.filter(graph_1.FunctionArgument.isNamed);
76
- for (const field of listFields) {
77
- const uses = useMap.get(field.name);
78
- if (uses) {
79
- for (const useId of uses) {
80
- information.graph.addEdge(useId, field.nodeId, edge_1.EdgeType.Reads);
81
- }
82
- }
83
- }
84
- return true;
85
- });
86
- }
87
- catch (e) {
88
- logger_1.dataflowLogger.warn('Failed to apply substitute-style env list replacement in quote-like call', { error: e });
89
- }
59
+ applyEnvListReplacement(information, envProcessed, exprProcessed);
90
60
  }
91
61
  }
92
62
  return {
@@ -97,4 +67,51 @@ function processQuote(name, args, rootId, data, config) {
97
67
  unknownReferences: unknownRefs
98
68
  };
99
69
  }
70
+ /** The uses within `expr`, by name, to match a `substitute` env list against. */
71
+ function usesByName(expr) {
72
+ const useMap = new Map();
73
+ for (const vType of [vertex_1.VertexType.Use, vertex_1.VertexType.FunctionCall]) {
74
+ for (const [useId] of expr.graph.verticesOfType(vType)) {
75
+ const rn = (0, node_id_1.recoverName)(useId, expr.graph.idMap);
76
+ if (rn) {
77
+ const arr = useMap.get(rn);
78
+ if (arr) {
79
+ arr.push(useId);
80
+ }
81
+ else {
82
+ useMap.set(rn, [useId]);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ return useMap;
88
+ }
89
+ /** `substitute(expr, list(a = 1))` replaces the listed names within `expr`. */
90
+ function applyEnvListReplacement(information, env, expr) {
91
+ let useMap = undefined;
92
+ try {
93
+ /* traverse the env processed DFG to find list calls (prefix-aware handling) */
94
+ df_helper_1.Dataflow.visitDfg(env.graph, env.entryPoint, (vtx) => {
95
+ if (vtx.tag !== vertex_1.VertexType.FunctionCall) {
96
+ return;
97
+ }
98
+ if (!vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.List)) {
99
+ return true;
100
+ }
101
+ useMap ??= usesByName(expr);
102
+ if (useMap.size === 0) {
103
+ return true;
104
+ }
105
+ for (const field of vtx.args.filter(graph_1.FunctionArgument.isNamed)) {
106
+ for (const useId of useMap.get(field.name) ?? []) {
107
+ information.graph.addEdge(useId, field.nodeId, edge_1.EdgeType.Reads);
108
+ }
109
+ }
110
+ return true;
111
+ });
112
+ }
113
+ catch (e) {
114
+ logger_1.dataflowLogger.warn('Failed to apply substitute-style env list replacement in quote-like call', { error: e });
115
+ }
116
+ }
100
117
  //# sourceMappingURL=built-in-quote.js.map
@@ -25,8 +25,8 @@ function processRecall(name, args, rootId, data, config) {
25
25
  });
26
26
  // If requested, treat Recall as an unknown side effect when a single argument is provided and it is not the numeric literal 0.
27
27
  if (config?.unknownOnNonZeroArg) {
28
- if (args.length === 1 && args[0] !== r_function_call_1.EmptyArgument && args[0].value) {
29
- const v = args[0].value;
28
+ const v = r_function_call_1.RFunctionCall.soleArgument(args)?.value;
29
+ if (v) {
30
30
  // only allow the normal recall handling if the single arg is the literal 0
31
31
  if (!(v.type === type_1.RType.Number && v.content.num === 0)) {
32
32
  (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
@@ -7,6 +7,7 @@ const linker_1 = require("../../../../linker");
7
7
  const common_1 = require("../common");
8
8
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
9
9
  const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
10
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
10
11
  const general_1 = require("../../../../../eval/values/general");
11
12
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
12
13
  const range_1 = require("../../../../../../util/range");
@@ -61,14 +62,7 @@ function processRegisterHook(name, args, rootId, data, config) {
61
62
  }
62
63
  });
63
64
  const res = (0, known_call_handling_1.processKnownFunctionCall)({ name, args: transformed, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.RegisterHook });
64
- const resolveArgs = {
65
- graph: res.information.graph,
66
- environment: res.information.environment,
67
- resolve: data.ctx.config.solver.variables,
68
- ctx: data.ctx,
69
- idMap: data.completeAst.idMap,
70
- full: true
71
- };
65
+ const resolveArgs = node_value_1.NodeValue.infoOf(data, { graph: res.information.graph, environment: res.information.environment });
72
66
  const shouldAdd = addIds.size === 0 ? config.args.add?.default :
73
67
  Array.from(addIds).flatMap(id => (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(id, resolveArgs))?.elements ?? [])
74
68
  .some(v => v.type === 'logical' && v.value !== false);
@@ -8,8 +8,7 @@ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
8
8
  const identifier_1 = require("../../../../../environments/identifier");
9
9
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
10
10
  const prefix_1 = require("../../../../../../util/prefix");
11
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
12
- const general_1 = require("../../../../../eval/values/general");
11
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
13
12
  const r_value_1 = require("../../../../../eval/values/r-value");
14
13
  const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
15
14
  const apply_kill_1 = require("../../../../../environments/apply-kill");
@@ -63,12 +62,7 @@ function collectListArg(targets, value, data) {
63
62
  targets.all = true;
64
63
  }
65
64
  else {
66
- const elements = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(value.info.id, {
67
- environment: data.environment,
68
- idMap: data.completeAst.idMap,
69
- resolve: data.ctx.config.solver.variables,
70
- ctx: data.ctx
71
- }))?.elements;
65
+ const elements = node_value_1.NodeValue.setOf(value.info.id, data)?.elements;
72
66
  if (!elements || elements.length === 0) {
73
67
  targets.unknown = true;
74
68
  }
@@ -15,7 +15,7 @@ const edge_1 = require("../../../../../graph/edge");
15
15
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
16
16
  const assert_1 = require("../../../../../../util/assert");
17
17
  const identifier_1 = require("../../../../../environments/identifier");
18
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
18
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
19
19
  const r_value_1 = require("../../../../../eval/values/r-value");
20
20
  const vertex_1 = require("../../../../../graph/vertex");
21
21
  const range_1 = require("../../../../../../util/range");
@@ -41,7 +41,7 @@ function processS7NewGeneric(name, args, rootId, data, config) {
41
41
  if (!genName) {
42
42
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
43
43
  }
44
- const n = (0, alias_tracking_1.resolveIdToValue)(genName.info.id, { environment: data.environment, resolve: data.ctx.config.solver.variables, idMap: data.completeAst.idMap, full: true, ctx: data.ctx });
44
+ const n = node_value_1.NodeValue.of(genName.info.id, data);
45
45
  const accessedIdentifiers = [];
46
46
  if (n.type === 'set') {
47
47
  for (const elem of n.elements) {
@@ -8,7 +8,7 @@ const logger_1 = require("../../../../../logger");
8
8
  const linker_1 = require("../../../../linker");
9
9
  const common_1 = require("../common");
10
10
  const unpack_argument_1 = require("../argument/unpack-argument");
11
- const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
11
+ const node_value_1 = require("../../../../../eval/resolve/node-value");
12
12
  const r_value_1 = require("../../../../../eval/values/r-value");
13
13
  const identifier_1 = require("../../../../../environments/identifier");
14
14
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
@@ -68,7 +68,7 @@ function processS3Dispatch(name, args, rootId, data, config) {
68
68
  unknownReferences: []
69
69
  };
70
70
  }
71
- const n = (0, alias_tracking_1.resolveIdToValue)(generic.info.id, { environment: data.environment, resolve: data.ctx.config.solver.variables, idMap: data.completeAst.idMap, full: true, ctx: data.ctx });
71
+ const n = node_value_1.NodeValue.of(generic.info.id, data);
72
72
  const accessedIdentifiers = [];
73
73
  if (n.type === 'set') {
74
74
  for (const elem of n.elements) {
@@ -50,3 +50,8 @@ export declare function sourceRequest<OtherInfo>(rootId: NodeId, request: RParse
50
50
  * Processes a standalone source file (i.e., not from a source function call)
51
51
  */
52
52
  export declare function standaloneSourceFile<OtherInfo>(idx: number, file: RProjectFile<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, information: DataflowInformation): DataflowInformation;
53
+ /**
54
+ * Folds the results of analyzing sourced code back into the information of the call that asked for it, which
55
+ * `eval` and the string templates both need: the code contributes everything it reads, writes, and leaves open.
56
+ */
57
+ export declare function mergeSourced(information: DataflowInformation, sourced: readonly DataflowInformation[]): DataflowInformation;