@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
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeValue = void 0;
4
+ const alias_tracking_1 = require("./alias-tracking");
5
+ const general_1 = require("../values/general");
6
+ const string_constants_1 = require("../values/string/string-constants");
7
+ function infoOf(data, overrides) {
8
+ return {
9
+ environment: data.environment,
10
+ idMap: data.completeAst.idMap,
11
+ resolve: data.ctx.config.solver.variables,
12
+ ctx: data.ctx,
13
+ ...overrides
14
+ };
15
+ }
16
+ function graphInfoOf(graph, ctx, overrides) {
17
+ return { graph, resolve: ctx.config.solver.variables, ctx, ...overrides };
18
+ }
19
+ /**
20
+ * The value(s) a node may hold, resolved against the state the current processor sees.
21
+ * Use {@link NodeValue.inGraph} to resolve against a finished {@link DataflowGraph} instead.
22
+ * Every entry point accepts overrides for the cases that deviate (e.g. another environment).
23
+ *
24
+ * This is constant propagation over the dataflow graph, not abstract interpretation: it follows definitions to
25
+ * constants and gives up wherever a value is not statically pinned down, with no fixpoint and no widening.
26
+ * Anything needing an abstract state lives in `src/abstract-interpretation/`.
27
+ */
28
+ exports.NodeValue = {
29
+ name: 'NodeValue',
30
+ /** The resolve info the processor's state stands for, for repeated resolutions. */
31
+ infoOf,
32
+ /** The value(s) the node may hold. */
33
+ of(id, data, overrides) {
34
+ return (0, alias_tracking_1.resolveIdToValue)(id, infoOf(data, overrides));
35
+ },
36
+ /** The value set the node may hold, `undefined` if it resolves to top or bottom. */
37
+ setOf(id, data, overrides) {
38
+ return (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(id, infoOf(data, overrides)));
39
+ },
40
+ /** The strings the node may hold, `undefined` if it does not resolve to strings. */
41
+ stringsOf(id, data, overrides) {
42
+ const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(id, infoOf(data, overrides)));
43
+ return resolved ? (0, string_constants_1.collectStrings)(resolved.elements) : undefined;
44
+ },
45
+ /** The single string the node resolves to, `undefined` if it is not exactly one. */
46
+ singleStringOf(id, data, overrides) {
47
+ return (0, alias_tracking_1.resolveIdToSingleString)(id, infoOf(data, overrides));
48
+ },
49
+ /** The one value a set holds, `undefined` unless it holds exactly one, optionally of the given kind. */
50
+ sole: general_1.soleValue,
51
+ /** The one value the node resolves to, `undefined` unless it is exactly one, optionally of the given kind. */
52
+ soleOf(id, data, type, overrides) {
53
+ return (0, general_1.soleValue)((0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(id, infoOf(data, overrides))), type);
54
+ },
55
+ /** The same questions, asked of a finished dataflow graph instead of a running processor. */
56
+ inGraph: {
57
+ /** The value set the node may hold, `undefined` if it resolves to top or bottom. */
58
+ setOf(id, graph, ctx, overrides) {
59
+ return (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(id, graphInfoOf(graph, ctx, overrides)));
60
+ },
61
+ /** The single string the node resolves to, `undefined` if it is not exactly one. */
62
+ singleStringOf(id, graph, ctx, overrides) {
63
+ return (0, alias_tracking_1.resolveIdToSingleString)(id, graphInfoOf(graph, ctx, overrides));
64
+ },
65
+ /** The one value the node resolves to, `undefined` unless it is exactly one, optionally of the given kind. */
66
+ soleOf(id, graph, ctx, type, overrides) {
67
+ return (0, general_1.soleValue)((0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(id, graphInfoOf(graph, ctx, overrides))), type);
68
+ }
69
+ }
70
+ };
71
+ //# sourceMappingURL=node-value.js.map
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getArgumentStringValue = getArgumentStringValue;
4
4
  const graph_1 = require("../../graph/graph");
5
+ const r_value_1 = require("../values/r-value");
5
6
  const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
7
  const assert_1 = require("../../../util/assert");
7
8
  const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
8
9
  const dependencies_query_format_1 = require("../../../queries/catalog/dependencies-query/dependencies-query-format");
9
10
  const general_1 = require("../values/general");
10
11
  const alias_tracking_1 = require("./alias-tracking");
11
- const r_value_1 = require("../values/r-value");
12
+ const r_value_2 = require("../values/r-value");
12
13
  const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
13
14
  const string_constants_1 = require("../values/string/string-constants");
14
15
  /**
@@ -92,7 +93,7 @@ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environm
92
93
  if (resolved) {
93
94
  const values = [];
94
95
  for (const value of resolved.elements) {
95
- const strings = (0, r_value_1.isValue)(value) ? stringsOfValue(value, full) : undefined;
96
+ const strings = (0, r_value_2.isValue)(value) ? stringsOfValue(value, full) : undefined;
96
97
  if (strings === undefined) {
97
98
  return undefined;
98
99
  }
@@ -107,13 +108,15 @@ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environm
107
108
  */
108
109
  function stringsOfValue(value, full) {
109
110
  switch (value.type) {
110
- case 'string':
111
- return (0, r_value_1.isValue)(value.value) ? [value.value.str] : undefined;
111
+ case 'string': {
112
+ const str = r_value_1.RValue.stringOf(value);
113
+ return str !== undefined ? [str] : undefined;
114
+ }
112
115
  case 'logical':
113
- return (0, r_value_1.isValue)(value.value) ? [value.value.valueOf() ? convert_values_1.RTrue : convert_values_1.RFalse] : undefined;
116
+ return (0, r_value_2.isValue)(value.value) ? [value.value.valueOf() ? convert_values_1.RTrue : convert_values_1.RFalse] : undefined;
114
117
  case 'vector':
115
- return (0, r_value_1.isValue)(value.elements)
116
- ? (0, string_constants_1.collectStrings)(value.elements, !full) ?? (value.elements.every(r_value_1.isValue) ? [dependencies_query_format_1.Constant] : undefined)
118
+ return (0, r_value_2.isValue)(value.elements)
119
+ ? (0, string_constants_1.collectStrings)(value.elements, !full) ?? (value.elements.every(r_value_2.isValue) ? [dependencies_query_format_1.Constant] : undefined)
117
120
  : undefined;
118
121
  case 'number':
119
122
  case 'interval':
@@ -109,7 +109,6 @@ function resolveAsGroup(args) {
109
109
  return r_value_2.Top;
110
110
  }
111
111
  /* unwrap the set again, as the caller of a handler wraps the returned value in one */
112
- const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(node.children[0], args));
113
- return values?.elements.length === 1 ? values.elements[0] : r_value_2.Top;
112
+ return (0, general_1.soleValue)((0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(node.children[0], args))) ?? r_value_2.Top;
114
113
  }
115
114
  //# sourceMappingURL=resolve-operators.js.map
@@ -11,6 +11,10 @@ export declare function bottomTopGuard(...a: Lift<unknown>[]): typeof Top | type
11
11
  * @returns value set if a is not top or bottom
12
12
  */
13
13
  export declare function valueSetGuard(a: Lift<ValueSet<Value[]>>): ValueSet<Value[]> | undefined;
14
+ export declare function soleValue(this: void, set: ValueSet<Value[]> | undefined): Value | undefined;
15
+ export declare function soleValue<T extends Value['type']>(this: void, set: ValueSet<Value[]> | undefined, type: T): Extract<Value, {
16
+ type: T;
17
+ }> | undefined;
14
18
  /**
15
19
  * Constructs an Abstract Value from a normal TS value
16
20
  * @param a - ts value
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bottomTopGuard = bottomTopGuard;
4
4
  exports.valueSetGuard = valueSetGuard;
5
+ exports.soleValue = soleValue;
5
6
  exports.valueFromTsValue = valueFromTsValue;
6
7
  exports.valueFromRNodeConstant = valueFromRNodeConstant;
7
8
  const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
@@ -30,6 +31,16 @@ function bottomTopGuard(...a) {
30
31
  function valueSetGuard(a) {
31
32
  return ((0, r_value_1.isBottom)(a) || (0, r_value_1.isTop)(a)) ? undefined : a;
32
33
  }
34
+ /**
35
+ * The one value a set holds, `undefined` unless it holds exactly one, optionally of the given kind.
36
+ * @param set - the set to take the value from
37
+ * @param type - the kind the value has to have, any kind if unset
38
+ * @returns the sole value, `undefined` if the set holds another number of them or another kind
39
+ */
40
+ function soleValue(set, type) {
41
+ const only = set?.elements.length === 1 ? set.elements[0] : undefined;
42
+ return only !== undefined && (type === undefined || only.type === type) ? only : undefined;
43
+ }
33
44
  /**
34
45
  * Constructs an Abstract Value from a normal TS value
35
46
  * @param a - ts value
@@ -74,3 +74,18 @@ export declare function asValue<V extends Lift<unknown>>(value: V): Unlift<V>;
74
74
  *
75
75
  */
76
76
  export declare function stringifyValue(value: Lift<Value>): string;
77
+ /**
78
+ * Reads the plain TS value a {@link Value} stands for, `undefined` whenever it stands for more than one, for
79
+ * none, or for another kind. Prefer these over reaching into a value's shape by hand.
80
+ *
81
+ * This is the constant-folding view: it answers "is this one known constant" and nothing else. It runs no
82
+ * fixpoint, knows no control flow, and widens nothing. For an abstract state that does, use the dedicated
83
+ * abstract interpretation in `src/abstract-interpretation/`.
84
+ */
85
+ export declare const RValue: {
86
+ readonly name: "RValue";
87
+ /** The number the value stands for, collapsing an interval that admits a single one. */
88
+ readonly numberOf: (this: void, value: Value) => number | undefined;
89
+ /** The string the value stands for. */
90
+ readonly stringOf: (this: void, value: Value) => string | undefined;
91
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Bottom = exports.Top = void 0;
3
+ exports.RValue = exports.Bottom = exports.Top = void 0;
4
4
  exports.typeOfValue = typeOfValue;
5
5
  exports.isTop = isTop;
6
6
  exports.isBottom = isBottom;
@@ -103,4 +103,30 @@ function stringifyValue(value) {
103
103
  }
104
104
  });
105
105
  }
106
+ /**
107
+ * Reads the plain TS value a {@link Value} stands for, `undefined` whenever it stands for more than one, for
108
+ * none, or for another kind. Prefer these over reaching into a value's shape by hand.
109
+ *
110
+ * This is the constant-folding view: it answers "is this one known constant" and nothing else. It runs no
111
+ * fixpoint, knows no control flow, and widens nothing. For an abstract state that does, use the dedicated
112
+ * abstract interpretation in `src/abstract-interpretation/`.
113
+ */
114
+ exports.RValue = {
115
+ name: 'RValue',
116
+ /** The number the value stands for, collapsing an interval that admits a single one. */
117
+ numberOf(value) {
118
+ if (value.type === 'number') {
119
+ return isValue(value.value) && !value.value.complexNumber ? value.value.num : undefined;
120
+ }
121
+ else if (value.type === 'interval' && value.startInclusive && value.endInclusive) {
122
+ const start = exports.RValue.numberOf(value.start);
123
+ return start !== undefined && start === exports.RValue.numberOf(value.end) ? start : undefined;
124
+ }
125
+ return undefined;
126
+ },
127
+ /** The string the value stands for. */
128
+ stringOf(value) {
129
+ return value.type === 'string' && isValue(value.value) ? value.value.str : undefined;
130
+ }
131
+ };
106
132
  //# sourceMappingURL=r-value.js.map
@@ -25,6 +25,7 @@ const flowr_file_1 = require("../project/context/flowr-file");
25
25
  /** Round cap for the transitive-side-effect fixpoint. */
26
26
  const transitiveSideEffectRounds = 32;
27
27
  const identifier_1 = require("./environments/identifier");
28
+ const quoted_1 = require("./internal/process/functions/call/quoted");
28
29
  const range_1 = require("../util/range");
29
30
  const logger_1 = require("./logger");
30
31
  const gas_1 = require("../gas");
@@ -171,6 +172,7 @@ function produceDataFlowGraph(parser, completeAst, ctx) {
171
172
  }
172
173
  // link on-demand-materialized package exports back to their `library()` loaders
173
174
  (0, transitive_side_effects_1.linkMaterializedExportsToLoaders)(df.graph, df.environment);
175
+ quoted_1.Quoted.finalize(df.graph, completeAst.idMap, () => (0, extract_cfg_1.extractCfgQuick)(completeAst).graph);
174
176
  df.cfgQuick = resolveLinkToSideEffects(completeAst, df.graph, ctx);
175
177
  // performance optimization: return cfgQuick as part of the result to avoid recomputation
176
178
  return df;
@@ -4,10 +4,9 @@ exports.isFunctionHigherOrder = isFunctionHigherOrder;
4
4
  const vertex_1 = require("../graph/vertex");
5
5
  const assert_1 = require("../../util/assert");
6
6
  const edge_1 = require("../graph/edge");
7
- const alias_tracking_1 = require("../eval/resolve/alias-tracking");
7
+ const node_value_1 = require("../eval/resolve/node-value");
8
8
  const config_1 = require("../../config");
9
9
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
10
- const general_1 = require("../eval/values/general");
11
10
  function isAnyReturnAFunction(def, graph) {
12
11
  const workingQueue = def.exitPoints.map(d => graph.getVertex(d.nodeId)).filter(assert_1.isNotUndefined);
13
12
  const seen = new Set();
@@ -46,7 +45,7 @@ function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph) {
46
45
  if (arg === r_function_call_1.EmptyArgument) {
47
46
  continue;
48
47
  }
49
- const value = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(arg.nodeId, { graph, idMap: graph.idMap, resolve: config_1.VariableResolve.Alias, full: true, ctx }));
48
+ const value = node_value_1.NodeValue.inGraph.setOf(arg.nodeId, graph, ctx, { resolve: config_1.VariableResolve.Alias });
50
49
  if (value?.elements.some(e => e.type === 'function-definition')) {
51
50
  return true;
52
51
  }
@@ -101,7 +101,8 @@ export declare const Dataflow: {
101
101
  readonly toValue: typeof import("../eval/resolve/alias-tracking").resolveIdToValue;
102
102
  readonly toSingleString: typeof import("../eval/resolve/alias-tracking").resolveIdToSingleString;
103
103
  readonly argument: {
104
- readonly name: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgName;
104
+ readonly name: "argument";
105
+ readonly toName: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgName;
105
106
  readonly value: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgValue;
106
107
  readonly stringVector: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgStringVector;
107
108
  readonly symbolName: typeof import("../../abstract-interpretation/data-frame/resolve-args").resolveIdToArgValueSymbolName;
@@ -15,6 +15,7 @@ const identifier_1 = require("../environments/identifier");
15
15
  const diff_2 = require("../environments/diff");
16
16
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
17
17
  const info_1 = require("../info");
18
+ const diff_graph_1 = require("../../util/diff-graph");
18
19
  /**
19
20
  * This is the underlying function to calculate the difference based on a given context.
20
21
  * Use {@link Dataflow.diff} to calculate the diff of two graphs.
@@ -22,39 +23,7 @@ const info_1 = require("../info");
22
23
  function diffDataflowGraph(ctx) {
23
24
  diffRootVertices(ctx);
24
25
  diffVertices(ctx);
25
- diffOutgoingEdges(ctx);
26
- }
27
- function diffOutgoingEdges(ctx) {
28
- const lEdges = new Map(ctx.left.edges());
29
- const rEdges = new Map(ctx.right.edges());
30
- if (lEdges.size < rEdges.size && !ctx.config.leftIsSubgraph || lEdges.size > rEdges.size && !ctx.config.rightIsSubgraph) {
31
- ctx.report.addComment(`Detected different number of edges! ${ctx.leftname} has ${lEdges.size} (${JSON.stringify(lEdges, json_1.jsonReplacer)}). ${ctx.rightname} has ${rEdges.size} ${JSON.stringify(rEdges, json_1.jsonReplacer)}`);
32
- }
33
- for (const [id, edge] of lEdges) {
34
- /* This has nothing to do with the subset relation as we verify this in the same graph.
35
- * Yet we still do the check as a subgraph may not have to have all source vertices for edges.
36
- */
37
- if (!ctx.left.hasVertex(id)) {
38
- if (!ctx.config.leftIsSubgraph) {
39
- ctx.report.addComment(`The source ${id} of edges ${JSON.stringify(edge, json_1.jsonReplacer)} is not present in ${ctx.leftname}. This means that the graph contains an edge but not the corresponding vertex.`);
40
- continue;
41
- }
42
- }
43
- diffEdges(ctx, id, edge, rEdges.get(id));
44
- }
45
- // just to make it both ways in case the length differs
46
- for (const [id, edge] of rEdges) {
47
- if (!ctx.right.hasVertex(id)) {
48
- if (!ctx.config.rightIsSubgraph) {
49
- ctx.report.addComment(`The source ${id} of edges ${JSON.stringify(edge, json_1.jsonReplacer)} is not present in ${ctx.rightname}. This means that the graph contains an edge but not the corresponding vertex.`);
50
- continue;
51
- }
52
- }
53
- if (!ctx.config.leftIsSubgraph && !lEdges.has(id)) {
54
- diffEdges(ctx, id, undefined, edge);
55
- }
56
- /* otherwise, we already cover the edge above */
57
- }
26
+ diff_graph_1.GraphDiff.outgoingEdges(ctx, diffEdges);
58
27
  }
59
28
  function diffRootVertices(ctx) {
60
29
  (0, diff_1.setDifference)(ctx.left.rootIds(), ctx.right.rootIds(), { ...ctx, position: `${ctx.position}Root vertices differ in graphs. ` });
@@ -319,27 +288,6 @@ function diffEdge(edge, otherEdge, ctx, id, target) {
319
288
  * Compares two sets of outgoing edges and reports differences.
320
289
  */
321
290
  function diffEdges(ctx, id, lEdges, rEdges) {
322
- if (lEdges === undefined || rEdges === undefined) {
323
- if ((lEdges === undefined && !ctx.config.leftIsSubgraph)
324
- || (rEdges === undefined && !ctx.config.rightIsSubgraph)) {
325
- ctx.report.addComment(`Vertex ${id} has undefined outgoing edges. ${ctx.leftname}: ${JSON.stringify(lEdges, json_1.jsonReplacer)} vs ${ctx.rightname}: ${JSON.stringify(rEdges, json_1.jsonReplacer)}`, { tag: 'vertex', id });
326
- }
327
- return;
328
- }
329
- if (lEdges.size < rEdges.size && !ctx.config.leftIsSubgraph
330
- || lEdges.size > rEdges.size && !ctx.config.rightIsSubgraph) {
331
- ctx.report.addComment(`Vertex ${id} differs in number of outgoing edges. ${ctx.leftname}: [${[...lEdges.keys()].join(',')}] vs ${ctx.rightname}: [${[...rEdges.keys()].join(',')}] `, { tag: 'vertex', id });
332
- }
333
- // order independent compare
334
- for (const [target, edge] of lEdges) {
335
- const otherEdge = rEdges.get(target);
336
- if (otherEdge === undefined) {
337
- if (!ctx.config.rightIsSubgraph) {
338
- ctx.report.addComment(`Target of ${id}->${target} in ${ctx.leftname} is not present in ${ctx.rightname}`, { tag: 'edge', from: id, to: target });
339
- }
340
- continue;
341
- }
342
- diffEdge(edge, otherEdge, ctx, id, target);
343
- }
291
+ diff_graph_1.GraphDiff.edges(ctx, id, lEdges, rEdges, diffEdge);
344
292
  }
345
293
  //# sourceMappingURL=diff-dataflow-graph.js.map
@@ -277,6 +277,11 @@ export declare class DataflowGraph<Vertex extends DataflowGraphVertexInfo = Data
277
277
  */
278
278
  isRoot(id: NodeId): boolean;
279
279
  rootIds(): ReadonlySet<NodeId>;
280
+ /**
281
+ * Takes `type` off the edge `fromId -> toId`, dropping the edge itself once it states nothing.
282
+ * An edge with no type is no edge: every removal has to go through here so none is left behind.
283
+ */
284
+ removeEdgeType(fromId: NodeId, toId: NodeId, type: EdgeType | number): this;
280
285
  /**
281
286
  * Adds a new vertex to the graph, for ease of use, some arguments are optional and filled automatically.
282
287
  * @param vertex - The vertex to add
@@ -328,6 +328,33 @@ class DataflowGraph {
328
328
  rootIds() {
329
329
  return this.rootVertices;
330
330
  }
331
+ /**
332
+ * Takes `type` off the edge `fromId -> toId`, dropping the edge itself once it states nothing.
333
+ * An edge with no type is no edge: every removal has to go through here so none is left behind.
334
+ */
335
+ removeEdgeType(fromId, toId, type) {
336
+ const from = node_id_1.NodeId.normalize(fromId), to = node_id_1.NodeId.normalize(toId);
337
+ const targets = this.edgeInformation.get(from);
338
+ const edge = targets?.get(to);
339
+ if (edge === undefined || targets === undefined) {
340
+ return this;
341
+ }
342
+ edge.types &= ~type;
343
+ if (edge.types !== 0) {
344
+ /* the reverse index holds this very object, so a narrowed type is already visible through it */
345
+ return this;
346
+ }
347
+ targets.delete(to);
348
+ if (targets.size === 0) {
349
+ this.edgeInformation.delete(from);
350
+ }
351
+ const into = this.incomingIndex?.get(to);
352
+ into?.delete(from);
353
+ if (into?.size === 0) {
354
+ this.incomingIndex?.delete(to);
355
+ }
356
+ return this;
357
+ }
331
358
  /**
332
359
  * Adds a new vertex to the graph, for ease of use, some arguments are optional and filled automatically.
333
360
  * @param vertex - The vertex to add
@@ -1,6 +1,6 @@
1
1
  import type { DataflowProcessorInformation } from './processor';
2
2
  import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
3
- import type { IdentifierReference } from './environments/identifier';
3
+ import type { BrandedIdentifier, IdentifierReference } from './environments/identifier';
4
4
  import type { REnvironmentInformation } from './environments/environment';
5
5
  import { DataflowGraph } from './graph/graph';
6
6
  import type { GenericDifferenceInformation, WriteableDifferenceReport } from '../util/diff';
@@ -24,6 +24,10 @@ export interface ControlDependency {
24
24
  */
25
25
  readonly file?: string;
26
26
  }
27
+ /** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
28
+ export declare function appendCds(target: ControlDependency[], toAdd: readonly ControlDependency[] | undefined): void;
29
+ /** A copy of `base` with `toAdd` appended, skipping the control dependencies that are already in there. */
30
+ export declare function withCds(base: readonly ControlDependency[] | undefined, toAdd: readonly ControlDependency[] | undefined): ControlDependency[];
27
31
  /**
28
32
  * Negates the given control dependency (i.e., flips the `when` flag).
29
33
  * This keeps undefined `when` values intact as undefined.
@@ -92,11 +96,13 @@ export type KillReference =
92
96
  | {
93
97
  readonly kind: 'all';
94
98
  readonly cds?: readonly ControlDependency[];
99
+ readonly except?: ReadonlySet<BrandedIdentifier>;
95
100
  }
96
101
  /** a not statically resolvable set of names, e.g., `rm(list = someVector)` */
97
102
  | {
98
103
  readonly kind: 'unknown';
99
104
  readonly cds?: readonly ControlDependency[];
105
+ readonly except?: ReadonlySet<BrandedIdentifier>;
100
106
  };
101
107
  /** The control flow information for the current DataflowInformation. */
102
108
  export interface DataflowCfgInformation {
package/dataflow/info.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataflowInformation = void 0;
4
+ exports.appendCds = appendCds;
5
+ exports.withCds = withCds;
4
6
  exports.negateControlDependency = negateControlDependency;
5
7
  exports.doesExitPointPropagateCalls = doesExitPointPropagateCalls;
6
8
  exports.addNonDefaultExitPoints = addNonDefaultExitPoints;
@@ -13,6 +15,27 @@ exports.diffControlDependency = diffControlDependency;
13
15
  exports.diffControlDependencies = diffControlDependencies;
14
16
  const graph_1 = require("./graph/graph");
15
17
  const assert_1 = require("../util/assert");
18
+ /** Whether the two control dependencies trigger on the same condition and branch. */
19
+ function sameControlDependency(a, b) {
20
+ return a.id === b.id && a.when === b.when;
21
+ }
22
+ /** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
23
+ function appendCds(target, toAdd) {
24
+ if (!toAdd) {
25
+ return;
26
+ }
27
+ for (const add of toAdd) {
28
+ if (!target.some(have => sameControlDependency(have, add))) {
29
+ target.push(add);
30
+ }
31
+ }
32
+ }
33
+ /** A copy of `base` with `toAdd` appended, skipping the control dependencies that are already in there. */
34
+ function withCds(base, toAdd) {
35
+ const result = base ? Array.from(base) : [];
36
+ appendCds(result, toAdd);
37
+ return result;
38
+ }
16
39
  /**
17
40
  * Negates the given control dependency (i.e., flips the `when` flag).
18
41
  * This keeps undefined `when` values intact as undefined.
@@ -96,17 +119,23 @@ function happensInEveryBranch(cds) {
96
119
  return cds === undefined || (cds.length !== 0 && coversSet(cds));
97
120
  }
98
121
  function coversSet(cds) {
99
- const trues = new Set();
100
- const falses = new Set();
122
+ /* as deep as the surrounding branches, so the pairwise scan beats any set */
101
123
  for (const { id, when } of cds) {
102
- if (when) {
103
- trues.add(id);
124
+ if (when !== true && when !== false) {
125
+ continue;
126
+ }
127
+ let counterpart = false;
128
+ for (const other of cds) {
129
+ if (other.id === id && other.when === !when) {
130
+ counterpart = true;
131
+ break;
132
+ }
104
133
  }
105
- else if (when === false) {
106
- falses.add(id);
134
+ if (!counterpart) {
135
+ return false;
107
136
  }
108
137
  }
109
- return trues.symmetricDifference(falses).size === 0;
138
+ return true;
110
139
  }
111
140
  /**
112
141
  * Checks whether the given control dependencies are exhaustive (i.e. if for every control dependency on a boolean,
@@ -81,6 +81,20 @@ export declare function getAllFunctionCallTargets(call: NodeId, graph: DataflowG
81
81
  * To know what fdefs the definition of `x` in the first line links to, you can use {@link getAllLinkedFunctionDefinitions|this function}.
82
82
  */
83
83
  export declare function getAllLinkedFunctionDefinitions(functionDefinitionReadIds: ReadonlySet<NodeId>, dataflowGraph: DataflowGraph): [Set<Required<DataflowGraphVertexFunctionDefinition>>, Set<BuiltIn>];
84
+ /**
85
+ * This method links a set of read variables to definitions in an environment.
86
+ * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
87
+ * @param environmentInformation - The environment information to link against
88
+ * @param givenInputs - The existing list of inputs that might be extended
89
+ * @param graph - The graph to enter the found links
90
+ * @param maybeForRemaining - Each input that can not be linked, will be added to `givenInputs`. If this flag is `true`, it will be marked as `maybe`.
91
+ * @returns the given inputs, possibly extended with the remaining inputs (those of `referencesToLinkAgainstEnvironment` that could not be linked against the environment)
92
+ */
93
+ /**
94
+ * Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and
95
+ * hands back what stays unresolved. This is how an expression that was captured elsewhere is read here.
96
+ */
97
+ export declare function linkExpressionIn<Info>(this: void, graph: DataflowGraph, expr: NodeId, environment: REnvironmentInformation, idMap: AstIdMap<Info & ParentInformation>): readonly IdentifierReference[];
84
98
  /**
85
99
  * This method links a set of read variables to definitions in an environment.
86
100
  * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
@@ -110,3 +124,12 @@ export declare function linkCircularRedefinitionsWithinALoop(graph: DataflowGrap
110
124
  * Reapplies the loop exit points' control dependencies to the given identifier references.
111
125
  */
112
126
  export declare function reapplyLoopExitPoints(exits: readonly ExitPoint[], references: readonly IdentifierReference[], graph: DataflowGraph): void;
127
+ /** The open references a function definition still carries into its closure. */
128
+ export declare const ClosureRefs: {
129
+ readonly name: "ClosureRefs";
130
+ /**
131
+ * Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`,
132
+ * links what resolves, and leaves only the references that stay open.
133
+ */
134
+ readonly resolveOpenIngoing: (this: void, graph: DataflowGraph, callId: NodeId, definition: DataflowGraphVertexFunctionDefinition, environment: REnvironmentInformation) => void;
135
+ };
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClosureRefs = void 0;
3
4
  exports.findNonLocalReads = findNonLocalReads;
4
5
  exports.produceNameSharedIdMap = produceNameSharedIdMap;
5
6
  exports.linkArgumentsOnCall = linkArgumentsOnCall;
@@ -8,17 +9,19 @@ exports.linkFunctionCallWithSingleTarget = linkFunctionCallWithSingleTarget;
8
9
  exports.linkFunctionCalls = linkFunctionCalls;
9
10
  exports.getAllFunctionCallTargets = getAllFunctionCallTargets;
10
11
  exports.getAllLinkedFunctionDefinitions = getAllLinkedFunctionDefinitions;
12
+ exports.linkExpressionIn = linkExpressionIn;
11
13
  exports.linkInputs = linkInputs;
12
14
  exports.linkCircularRedefinitionsWithinALoop = linkCircularRedefinitionsWithinALoop;
13
15
  exports.reapplyLoopExitPoints = reapplyLoopExitPoints;
14
16
  const defaultmap_1 = require("../../util/collections/defaultmap");
17
+ const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
18
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
15
19
  const assert_1 = require("../../util/assert");
16
20
  const log_1 = require("../../util/log");
17
21
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
18
22
  const identifier_1 = require("../environments/identifier");
19
23
  const graph_1 = require("../graph/graph");
20
24
  const logger_1 = require("../logger");
21
- const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
22
25
  const edge_1 = require("../graph/edge");
23
26
  const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
24
27
  const vertex_1 = require("../graph/vertex");
@@ -366,6 +369,40 @@ function getAllLinkedFunctionDefinitions(functionDefinitionReadIds, dataflowGrap
366
369
  }
367
370
  return [result, builtIns];
368
371
  }
372
+ /**
373
+ * This method links a set of read variables to definitions in an environment.
374
+ * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
375
+ * @param environmentInformation - The environment information to link against
376
+ * @param givenInputs - The existing list of inputs that might be extended
377
+ * @param graph - The graph to enter the found links
378
+ * @param maybeForRemaining - Each input that can not be linked, will be added to `givenInputs`. If this flag is `true`, it will be marked as `maybe`.
379
+ * @returns the given inputs, possibly extended with the remaining inputs (those of `referencesToLinkAgainstEnvironment` that could not be linked against the environment)
380
+ */
381
+ /**
382
+ * Links every name in the expression rooted at `expr` against `environment`, as if it were written there, and
383
+ * hands back what stays unresolved. This is how an expression that was captured elsewhere is read here.
384
+ */
385
+ function linkExpressionIn(graph, expr, environment, idMap) {
386
+ const node = idMap.get(expr);
387
+ if (node === undefined) {
388
+ return [];
389
+ }
390
+ const references = [];
391
+ const callees = new Set();
392
+ model_1.RNode.visitAst(node, inner => {
393
+ if (r_function_call_1.RFunctionCall.isNamed(inner)) {
394
+ callees.add(inner.functionName.info.id);
395
+ references.push({ nodeId: inner.functionName.info.id, name: inner.functionName.content, cds: undefined, type: identifier_1.ReferenceType.Function });
396
+ }
397
+ else if (inner.type === type_1.RType.Symbol && !callees.has(inner.info.id)) {
398
+ references.push({ nodeId: inner.info.id, name: inner.content, cds: undefined, type: identifier_1.ReferenceType.Variable });
399
+ }
400
+ return false;
401
+ });
402
+ const unresolved = [];
403
+ linkInputs(references, environment, unresolved, graph, false);
404
+ return unresolved;
405
+ }
369
406
  /**
370
407
  * This method links a set of read variables to definitions in an environment.
371
408
  * @param referencesToLinkAgainstEnvironment - The set of references to link against the environment
@@ -494,4 +531,36 @@ function reapplyLoopExitPoints(exits, references, graph) {
494
531
  }
495
532
  }
496
533
  }
534
+ /** The open references a function definition still carries into its closure. */
535
+ exports.ClosureRefs = {
536
+ name: 'ClosureRefs',
537
+ /**
538
+ * Resolves the open ingoing references of a definition called anonymously at `callId` against `environment`,
539
+ * links what resolves, and leaves only the references that stay open.
540
+ */
541
+ resolveOpenIngoing(graph, callId, definition, environment) {
542
+ const remainingIn = [];
543
+ for (const ingoing of definition.subflow.in) {
544
+ const resolved = ingoing.name ? (0, resolve_by_name_1.resolveByName)(ingoing.name, environment, ingoing.type) : undefined;
545
+ if (resolved === undefined) {
546
+ remainingIn.push(ingoing);
547
+ continue;
548
+ }
549
+ (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Found ${resolved.length} references to open ref ${ingoing.nodeId} in closure of function definition ${callId}`);
550
+ let allBuiltIn = true;
551
+ const inId = ingoing.nodeId;
552
+ for (const { nodeId, type } of resolved) {
553
+ graph.addEdge(inId, nodeId, edge_1.EdgeType.Reads);
554
+ graph.addEdge(callId, nodeId, edge_1.EdgeType.Reads); // because the def. is the anonymous call
555
+ if (!(0, identifier_1.isReferenceType)(type, identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.BuiltInFunction)) {
556
+ allBuiltIn = false;
557
+ }
558
+ }
559
+ if (allBuiltIn) {
560
+ remainingIn.push(ingoing);
561
+ }
562
+ }
563
+ definition.subflow.in = remainingIn;
564
+ }
565
+ };
497
566
  //# sourceMappingURL=linker.js.map