@eagleoutice/flowr 2.13.13 → 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 (186) hide show
  1. package/README.md +31 -28
  2. package/abstract-interpretation/data-frame/resolve-args.js +11 -12
  3. package/benchmark/calibration.d.ts +18 -0
  4. package/benchmark/calibration.js +63 -0
  5. package/benchmark/slicer.d.ts +19 -0
  6. package/benchmark/slicer.js +84 -1
  7. package/benchmark/stats/feature-counts.d.ts +6 -0
  8. package/benchmark/stats/feature-counts.js +61 -0
  9. package/benchmark/stats/print.js +20 -0
  10. package/benchmark/stats/sigdb-counts.d.ts +7 -0
  11. package/benchmark/stats/sigdb-counts.js +219 -0
  12. package/benchmark/stats/size-of.d.ts +6 -0
  13. package/benchmark/stats/size-of.js +8 -0
  14. package/benchmark/stats/stats.d.ts +79 -0
  15. package/benchmark/stats/stats.js +7 -1
  16. package/benchmark/stopwatch.d.ts +4 -0
  17. package/benchmark/stopwatch.js +12 -1
  18. package/benchmark/summarizer/data.d.ts +17 -1
  19. package/benchmark/summarizer/first-phase/input.js +5 -0
  20. package/benchmark/summarizer/first-phase/process.js +12 -2
  21. package/benchmark/summarizer/second-phase/graph.d.ts +24 -1
  22. package/benchmark/summarizer/second-phase/graph.js +249 -18
  23. package/benchmark/summarizer/second-phase/process.js +56 -0
  24. package/benchmark/summarizer/summarizer.js +1 -2
  25. package/cli/benchmark-app.d.ts +1 -0
  26. package/cli/benchmark-app.js +2 -1
  27. package/cli/benchmark-helper-app.d.ts +1 -0
  28. package/cli/benchmark-helper-app.js +12 -2
  29. package/cli/common/options.d.ts +10 -0
  30. package/cli/common/options.js +3 -1
  31. package/cli/common/scripts-info.d.ts +10 -0
  32. package/cli/repl/commands/repl-cfg.js +2 -42
  33. package/cli/repl/commands/repl-clipboard.d.ts +7 -0
  34. package/cli/repl/commands/repl-clipboard.js +53 -0
  35. package/cli/repl/commands/repl-dataflow.js +5 -70
  36. package/cli/repl/commands/repl-normalize.js +3 -51
  37. package/control-flow/cfg-builder.d.ts +30 -0
  38. package/control-flow/cfg-builder.js +79 -0
  39. package/control-flow/cfg-dead-code.js +5 -29
  40. package/control-flow/diff-cfg.js +2 -56
  41. package/control-flow/extract-cfg.js +17 -10
  42. package/control-flow/semantic-cfg-guided-visitor.d.ts +7 -0
  43. package/control-flow/semantic-cfg-guided-visitor.js +14 -0
  44. package/control-flow/useless-loop.js +4 -26
  45. package/core/steps/all/core/10-normalize.d.ts +8 -0
  46. package/core/steps/all/core/10-normalize.js +10 -8
  47. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +5 -7
  48. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -9
  49. package/data/r-base-packages.generated.d.ts +1 -0
  50. package/data/r-base-packages.generated.js +5 -3
  51. package/dataflow/environments/apply-kill.d.ts +3 -3
  52. package/dataflow/environments/apply-kill.js +60 -31
  53. package/dataflow/environments/built-in-config.d.ts +9 -1
  54. package/dataflow/environments/built-in-proc-name.d.ts +2 -0
  55. package/dataflow/environments/built-in-proc-name.js +2 -0
  56. package/dataflow/environments/built-in-props.d.ts +4 -0
  57. package/dataflow/environments/built-in-props.js +3 -3
  58. package/dataflow/environments/built-in.d.ts +4 -2
  59. package/dataflow/environments/built-in.js +53 -3
  60. package/dataflow/environments/data-masking-functions.d.ts +3 -4
  61. package/dataflow/environments/data-masking-functions.js +7 -8
  62. package/dataflow/environments/default-builtin-config.d.ts +92 -12
  63. package/dataflow/environments/default-builtin-config.js +86 -43
  64. package/dataflow/environments/environment.d.ts +5 -0
  65. package/dataflow/environments/environment.js +17 -12
  66. package/dataflow/environments/identifier.d.ts +3 -0
  67. package/dataflow/environments/reference-to-maybe.d.ts +5 -3
  68. package/dataflow/environments/reference-to-maybe.js +17 -52
  69. package/dataflow/environments/resolve-helper.d.ts +2 -1
  70. package/dataflow/environments/resolve-helper.js +2 -1
  71. package/dataflow/eval/resolve/alias-tracking.js +4 -7
  72. package/dataflow/eval/resolve/node-value.d.ts +51 -0
  73. package/dataflow/eval/resolve/node-value.js +71 -0
  74. package/dataflow/eval/resolve/resolve-argument.js +10 -7
  75. package/dataflow/eval/resolve/resolve-operators.js +1 -2
  76. package/dataflow/eval/values/general.d.ts +4 -0
  77. package/dataflow/eval/values/general.js +11 -0
  78. package/dataflow/eval/values/r-value.d.ts +15 -0
  79. package/dataflow/eval/values/r-value.js +27 -1
  80. package/dataflow/extractor.js +2 -0
  81. package/dataflow/fn/higher-order-function.js +2 -3
  82. package/dataflow/graph/df-helper.d.ts +2 -1
  83. package/dataflow/graph/diff-dataflow-graph.js +3 -55
  84. package/dataflow/graph/graph.d.ts +5 -0
  85. package/dataflow/graph/graph.js +27 -0
  86. package/dataflow/info.d.ts +7 -1
  87. package/dataflow/info.js +36 -7
  88. package/dataflow/internal/linker.d.ts +23 -0
  89. package/dataflow/internal/linker.js +70 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +4 -1
  91. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +2 -0
  92. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -29
  93. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +39 -6
  94. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +10 -22
  95. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +29 -53
  96. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +33 -10
  97. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -1
  98. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -5
  99. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -7
  100. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -3
  101. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +6 -2
  102. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +19 -12
  103. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +2 -1
  104. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +3 -0
  105. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +69 -52
  106. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
  107. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +2 -8
  108. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
  109. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +7 -2
  110. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +2 -8
  111. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +2 -2
  112. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +2 -2
  113. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +5 -0
  114. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +23 -3
  115. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.d.ts +5 -4
  116. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +7 -10
  117. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +6 -1
  118. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +20 -3
  119. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -8
  120. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +25 -0
  121. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +105 -0
  122. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +9 -28
  123. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +4 -5
  124. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +1 -1
  125. package/dataflow/internal/process/functions/call/deferred.d.ts +41 -0
  126. package/dataflow/internal/process/functions/call/deferred.js +127 -0
  127. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +13 -12
  128. package/dataflow/internal/process/functions/call/known-call-handling.js +35 -35
  129. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
  130. package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
  131. package/dataflow/internal/process/functions/call/nse.d.ts +28 -0
  132. package/dataflow/internal/process/functions/call/nse.js +87 -0
  133. package/dataflow/internal/process/functions/call/quoted.d.ts +29 -0
  134. package/dataflow/internal/process/functions/call/quoted.js +188 -0
  135. package/documentation/doc-readme.js +5 -2
  136. package/documentation/doc-util/doc-issue.d.ts +2 -0
  137. package/documentation/doc-util/doc-issue.js +3 -1
  138. package/documentation/doc-util/doc-types.js +15 -9
  139. package/documentation/wiki-dataflow-graph.js +4 -0
  140. package/documentation/wiki-faq.js +6 -2
  141. package/documentation/wiki-onboarding.js +11 -1
  142. package/documentation/wiki-setup.js +2 -1
  143. package/linter/rules/deprecated-functions.js +9 -3
  144. package/linter/rules/seeded-randomness.js +2 -3
  145. package/linter/rules/undefined-symbol.js +10 -1
  146. package/package.json +9 -4
  147. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +6 -0
  148. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +17 -1
  149. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.d.ts +2 -11
  150. package/project/plugins/file-plugins/notebooks/flowr-analyzer-qmd-file-plugin.js +3 -15
  151. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +16 -0
  152. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +26 -0
  153. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +2 -11
  154. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +3 -15
  155. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin.js +4 -10
  156. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +2 -9
  157. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +2 -9
  158. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +1 -1
  159. package/project/sigdb/reader.d.ts +9 -0
  160. package/project/sigdb/reader.js +30 -0
  161. package/queries/catalog/input-sources-query/input-sources-query-format.js +1 -1
  162. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.d.ts +0 -12
  163. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -37
  164. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -23
  165. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +2 -2
  166. package/queries/query-function-filter.d.ts +21 -0
  167. package/queries/query-function-filter.js +48 -0
  168. package/r-bridge/data/data.d.ts +13 -3
  169. package/r-bridge/data/data.js +15 -3
  170. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +2 -0
  171. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +4 -0
  172. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -9
  173. package/search/flowr-search-filters.d.ts +5 -1
  174. package/search/flowr-search-filters.js +31 -21
  175. package/search/search-executor/search-enrichers.d.ts +24 -4
  176. package/search/search-executor/search-enrichers.js +22 -9
  177. package/search/search-executor/search-transformer.js +1 -1
  178. package/slicing/static/slice-call.js +4 -4
  179. package/util/diff-graph.d.ts +13 -0
  180. package/util/diff-graph.js +64 -1
  181. package/util/files.js +9 -8
  182. package/util/node-version.d.ts +4 -0
  183. package/util/node-version.js +29 -0
  184. package/util/r-base-packages.d.ts +2 -0
  185. package/util/r-base-packages.js +3 -1
  186. package/util/version.js +1 -1
@@ -9,6 +9,7 @@ const common_1 = require("../common");
9
9
  const unpack_argument_1 = require("../argument/unpack-argument");
10
10
  const scoping_1 = require("../../../../../environments/scoping");
11
11
  const identifier_1 = require("../../../../../environments/identifier");
12
+ const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
12
13
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
13
14
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
14
15
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
@@ -56,16 +57,19 @@ function processLocal(name, args, rootId, data, config) {
56
57
  argumentProcessResult: [dfExpr, dfEnv],
57
58
  origin: built_in_proc_name_1.BuiltInProcName.Local
58
59
  });
60
+ const resultEnvironment = envirResolution ? data.environment : (0, scoping_1.popLocalEnvironment)(dfExpr.environment);
61
+ /* definitions of the local scope vanish with it, only what escaped it (e.g. via `<<-`) may bubble up */
62
+ const escaping = envirResolution ? dfExpr.out : dfExpr.out.filter(o => o.name !== undefined && (0, resolve_by_name_1.resolveByName)(o.name, resultEnvironment, o.type)?.some(d => d.nodeId === o.nodeId));
59
63
  const ingoing = dfEnv.in.concat(dfExpr.in, dfEnv.unknownReferences, dfExpr.unknownReferences);
60
64
  ingoing.push({ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function });
61
65
  const baseResult = {
62
66
  hooks: dfExpr.hooks.concat(dfEnv.hooks),
63
- environment: envirResolution ? data.environment : (0, scoping_1.popLocalEnvironment)(dfExpr.environment),
67
+ environment: resultEnvironment,
64
68
  exitPoints: dfEnv.exitPoints.concat(dfExpr.exitPoints),
65
69
  graph: dfEnv.graph.mergeWith(dfExpr.graph),
66
70
  entryPoint: rootId,
67
71
  in: ingoing,
68
- out: dfExpr.out.concat(dfEnv.out),
72
+ out: escaping.concat(dfEnv.out),
69
73
  unknownReferences: []
70
74
  };
71
75
  /* move all definitions made inside the body into the custom env's tracked state */
@@ -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);
@@ -44,6 +44,7 @@ function processRepeatLoop(name, args, rootId, data) {
44
44
  (0, linker_1.linkCircularRedefinitionsWithinALoop)(information.graph, (0, linker_1.produceNameSharedIdMap)((0, linker_1.findNonLocalReads)(information.graph)), body.out, body.environment);
45
45
  (0, linker_1.reapplyLoopExitPoints)(body.exitPoints, body.in.concat(body.out, body.unknownReferences), information.graph);
46
46
  information.exitPoints = (0, info_1.filterOutLoopExitPoints)(information.exitPoints);
47
- return information;
47
+ /* the body is evaluated in the enclosing environment, so its definitions have to bubble up */
48
+ return { ...information, out: information.out.concat(body.out) };
48
49
  }
49
50
  //# sourceMappingURL=built-in-repeat-loop.js.map
@@ -18,6 +18,7 @@ const unknown_replacement_1 = require("../../../../../graph/unknown-replacement"
18
18
  const built_in_s_seven_dispatch_1 = require("./built-in-s-seven-dispatch");
19
19
  const make_argument_1 = require("../argument/make-argument");
20
20
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
21
+ const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
21
22
  const graph_1 = require("../../../../../graph/graph");
22
23
  const range_1 = require("../../../../../../util/range");
23
24
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
@@ -99,12 +100,16 @@ args, rootId, data, config) {
99
100
  res.graph.addEdge(rootId, ref, edge_1.EdgeType.Reads);
100
101
  }
101
102
  }
102
- if (firstArg) {
103
+ if (firstArg?.type === type_1.RType.Symbol) {
103
104
  res = {
104
105
  ...res,
105
- in: [...res.in, { name: firstArg.lexeme, type: identifier_1.ReferenceType.Variable, nodeId: firstArg.info.id, cds: data.cds }]
106
+ in: [...res.in, { name: firstArg.content, type: identifier_1.ReferenceType.Variable, nodeId: firstArg.info.id, cds: data.cds }]
106
107
  };
107
108
  }
109
+ else if (firstArg !== undefined && r_access_1.RAccess.is(firstArg)) {
110
+ /* a nested target (e.g. `a$b$c <- 5`) is no variable read, it is read through its own accessor */
111
+ res.graph.addEdge(firstArg.info.id, node_id_1.NodeId.toBuiltIn(firstArg.operator), edge_1.EdgeType.Reads);
112
+ }
108
113
  // dispatches actually as S3:
109
114
  const fns = res.in.filter(i => i.nodeId === rootId);
110
115
  for (const fn of fns) {
@@ -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;
@@ -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