@eagleoutice/flowr 2.15.10 → 2.16.0

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 (181) hide show
  1. package/README.md +23 -26
  2. package/abstract-interpretation/data-frame/arguments.js +11 -7
  3. package/control-flow/happens-before.d.ts +5 -0
  4. package/control-flow/happens-before.js +48 -34
  5. package/control-flow/useless-loop.d.ts +1 -1
  6. package/control-flow/useless-loop.js +29 -42
  7. package/dataflow/environments/built-in-props.d.ts +9 -0
  8. package/dataflow/environments/built-in-props.js +25 -19
  9. package/dataflow/environments/built-in.d.ts +2 -2
  10. package/dataflow/environments/built-in.js +41 -77
  11. package/dataflow/environments/default-builtin-config.d.ts +181 -29
  12. package/dataflow/environments/default-builtin-config.js +38 -24
  13. package/dataflow/environments/environment.d.ts +6 -4
  14. package/dataflow/environments/environment.js +54 -121
  15. package/dataflow/environments/identifier.d.ts +4 -2
  16. package/dataflow/environments/identifier.js +23 -69
  17. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  18. package/dataflow/environments/reference-to-maybe.js +23 -51
  19. package/dataflow/environments/resolve-by-name.js +37 -76
  20. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  21. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  22. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  23. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  24. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  25. package/dataflow/eval/resolve/resolve.js +23 -14
  26. package/dataflow/extractor.js +176 -59
  27. package/dataflow/fn/class-declaration.d.ts +8 -2
  28. package/dataflow/fn/class-declaration.js +96 -97
  29. package/dataflow/fn/exceptions-of-function.js +68 -37
  30. package/dataflow/fn/frame-reflection.d.ts +12 -4
  31. package/dataflow/fn/frame-reflection.js +51 -41
  32. package/dataflow/fn/function-props.js +15 -33
  33. package/dataflow/fn/function-semantics.d.ts +11 -3
  34. package/dataflow/fn/function-semantics.js +6 -0
  35. package/dataflow/fn/higher-order-function.js +13 -17
  36. package/dataflow/fn/strict-function.d.ts +13 -0
  37. package/dataflow/fn/strict-function.js +285 -122
  38. package/dataflow/graph/call-graph.d.ts +7 -6
  39. package/dataflow/graph/call-graph.js +35 -46
  40. package/dataflow/graph/graph.d.ts +6 -1
  41. package/dataflow/graph/graph.js +57 -66
  42. package/dataflow/info.d.ts +8 -1
  43. package/dataflow/info.js +24 -30
  44. package/dataflow/internal/control-flow.d.ts +31 -4
  45. package/dataflow/internal/control-flow.js +61 -39
  46. package/dataflow/internal/linker.d.ts +15 -9
  47. package/dataflow/internal/linker.js +253 -241
  48. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
  49. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +446 -78
  50. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  51. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
  52. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
  53. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
  54. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  55. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  56. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
  57. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
  58. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +289 -251
  59. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  60. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  61. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  62. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
  63. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  64. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
  65. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  66. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  67. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  68. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
  69. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
  70. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
  72. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  73. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
  74. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  75. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  76. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  77. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  78. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  79. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
  80. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  81. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  82. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  83. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  84. package/dataflow/internal/process/functions/call/common.d.ts +1 -3
  85. package/dataflow/internal/process/functions/call/common.js +36 -76
  86. package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
  87. package/dataflow/internal/process/functions/call/deferred.js +54 -57
  88. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  89. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  90. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  91. package/dataflow/internal/process/functions/call/named-call-handling.js +35 -21
  92. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  93. package/dataflow/internal/process/functions/call/quoted.js +162 -172
  94. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  95. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  96. package/dataflow/internal/process/process-symbol.js +3 -6
  97. package/dataflow/internal/program-order.d.ts +26 -0
  98. package/dataflow/internal/program-order.js +49 -0
  99. package/documentation/wiki-setup.js +23 -0
  100. package/linter/linter-rules.d.ts +17 -8
  101. package/linter/rules/absolute-path.js +63 -87
  102. package/linter/rules/file-path-validity.d.ts +4 -2
  103. package/linter/rules/file-path-validity.js +114 -80
  104. package/linter/rules/namespace-access.js +21 -33
  105. package/linter/rules/naming-convention.d.ts +1 -1
  106. package/linter/rules/naming-convention.js +60 -48
  107. package/linter/rules/network-functions.js +11 -7
  108. package/linter/rules/no-leaked-credentials.js +15 -18
  109. package/linter/rules/problematic-inputs.d.ts +2 -1
  110. package/linter/rules/problematic-inputs.js +39 -59
  111. package/linter/rules/roxygen-arguments.d.ts +9 -4
  112. package/linter/rules/roxygen-arguments.js +29 -48
  113. package/linter/rules/seeded-randomness.d.ts +7 -4
  114. package/linter/rules/seeded-randomness.js +128 -89
  115. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  116. package/linter/rules/stop-with-call-arg.js +25 -22
  117. package/linter/rules/unclosed-connection.js +31 -24
  118. package/linter/rules/undefined-symbol.d.ts +4 -6
  119. package/linter/rules/undefined-symbol.js +58 -75
  120. package/linter/rules/unescaped-arguments.js +18 -44
  121. package/linter/rules/unused-definition.d.ts +6 -0
  122. package/linter/rules/unused-definition.js +105 -145
  123. package/linter/rules/unused-import.d.ts +3 -0
  124. package/linter/rules/unused-import.js +25 -43
  125. package/package.json +5 -2
  126. package/project/flowr-analyzer.js +6 -2
  127. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  128. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  129. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  130. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  131. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +16 -41
  132. package/queries/base-query-format.js +1 -2
  133. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  134. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  135. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  136. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  137. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  138. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  139. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  140. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  141. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  142. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  143. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  144. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  145. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  146. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  147. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  148. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  149. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  150. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  151. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  152. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  153. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  154. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  155. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  156. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  157. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  158. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  159. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  160. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  161. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  162. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  163. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  164. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  165. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  166. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  167. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  168. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  169. package/r-bridge/shell.js +6 -0
  170. package/search/search-executor/search-enrichers.js +25 -37
  171. package/slicing/static/slice-call.d.ts +4 -3
  172. package/slicing/static/slice-call.js +56 -88
  173. package/slicing/static/static-slicer.js +115 -79
  174. package/slicing/static/visiting-queue.d.ts +4 -6
  175. package/slicing/static/visiting-queue.js +9 -13
  176. package/util/proc.js +2 -1
  177. package/util/r-base-packages.d.ts +2 -0
  178. package/util/r-base-packages.js +23 -13
  179. package/util/text/playground-link.d.ts +12 -3
  180. package/util/text/playground-link.js +18 -27
  181. package/util/version.js +4 -10
@@ -24,28 +24,14 @@ const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol"
24
24
  const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
25
25
  const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
26
26
  const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
27
+ const frame_reflection_1 = require("../../../dataflow/fn/frame-reflection");
27
28
  /** how far a function handed to an entry point may be passed along before we give up resolving it */
28
29
  const MaxFunctionResolveDepth = 4;
29
30
  function isConstantLike(type) {
30
31
  return type === input_types_1.InputType.Constant || type === input_types_1.InputType.DerivedConstant;
31
32
  }
32
- /** Returns the common value shared by all defined entries, or `undefined` if they disagree or all are `undefined`. */
33
- function singleValue(values) {
34
- let result;
35
- let seen = false;
36
- for (const v of values) {
37
- if (v === undefined) {
38
- return undefined;
39
- }
40
- if (!seen) {
41
- result = v;
42
- seen = true;
43
- }
44
- else if (v !== result) {
45
- return undefined;
46
- }
47
- }
48
- return result;
33
+ function sourceOf(id, type) {
34
+ return { id, types: [type], trace: input_types_1.InputTraceType.Unknown };
49
35
  }
50
36
  /**
51
37
  * Accumulates types, control-dependency types, values, and purity while traversing origin
@@ -57,59 +43,63 @@ class ClassificationAccumulator {
57
43
  values = [];
58
44
  allPure = true;
59
45
  merge(c) {
46
+ if (c === undefined) {
47
+ this.push(input_types_1.InputType.Unknown);
48
+ return;
49
+ }
60
50
  this.types.push(...c.types);
61
51
  this.values.push(c.value);
62
- if (c.cds) {
63
- this.cds.push(...c.cds);
64
- }
65
- if (c.trace !== input_types_1.InputTraceType.Pure) {
66
- this.allPure = false;
67
- }
52
+ this.cds.push(...c.cds ?? []);
53
+ this.allPure &&= c.trace === input_types_1.InputTraceType.Pure;
68
54
  }
69
- pushUnknown() {
70
- this.types.push(input_types_1.InputType.Unknown);
71
- this.values.push(undefined);
55
+ push(type, value) {
56
+ this.types.push(type);
57
+ this.values.push(value);
72
58
  }
73
59
  build(id) {
74
60
  const types = this.types.length === 0 ? [input_types_1.InputType.Unknown] : (0, arrays_1.uniqueArray)(this.types);
75
- const trace = this.allPure ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Alias;
76
- const src = { id, types, trace };
77
- const cds = this.cds.length === 0 ? undefined : (0, arrays_1.uniqueArray)(this.cds);
78
- if (cds) {
79
- src.cds = cds;
80
- }
81
- if (types.every(isConstantLike)) {
82
- const v = singleValue(this.values);
83
- if (v !== undefined) {
84
- src.value = v;
85
- }
86
- }
87
- return src;
61
+ const first = this.values[0];
62
+ const agreed = first !== undefined && this.values.every(v => v === first);
63
+ const value = agreed && types.every(isConstantLike) ? first : undefined;
64
+ return (0, objects_1.compactRecord)({
65
+ id,
66
+ types,
67
+ trace: this.allPure ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Alias,
68
+ cds: this.cds.length === 0 ? undefined : (0, arrays_1.uniqueArray)(this.cds),
69
+ value
70
+ });
88
71
  }
89
72
  }
90
73
  class InputClassifier {
91
74
  dfg;
92
75
  config;
93
- cache = new Map();
94
76
  fullDfg;
95
- /** the packages attached in the analyzed program, `undefined` if that is not known (then everything may match) */
96
77
  packages;
78
+ cache = new Map();
97
79
  fullClassifier;
98
80
  declarationIndex;
99
81
  entryPointIndex;
82
+ /** `packages` are the packages attached in the analyzed program, `undefined` if that is not known (then everything may match) */
100
83
  constructor(dfg, config, fullDfg, packages) {
101
84
  this.dfg = dfg;
102
85
  this.config = config;
103
86
  this.fullDfg = fullDfg;
104
87
  this.packages = packages;
105
88
  }
89
+ get whole() {
90
+ return this.fullDfg ?? this.dfg;
91
+ }
106
92
  matches(call, list) {
107
- return matchesList(call, list, this.packages);
93
+ return list?.some(id => call.id === id || (identifier_1.Identifier.is(id) && callMeans(call.name, id, this.packages))) ?? false;
108
94
  }
109
95
  /** whether the package the given entry needs is attached (unknown package information lets everything through) */
110
96
  hasPackage(name) {
111
97
  return name === undefined || this.packages === undefined || this.packages.has(name);
112
98
  }
99
+ classifyAt(ref, graph = this.dfg) {
100
+ const vtx = ref === undefined ? undefined : graph.getVertex(ref);
101
+ return vtx ? this.classifyEntry(vtx) : undefined;
102
+ }
113
103
  /**
114
104
  * Returns the specification of the {@link LinkedInputObject|linked input object} the given id refers to
115
105
  * (e.g., shiny's `input`), or `undefined` if it refers to something else.
@@ -120,12 +110,8 @@ class InputClassifier {
120
110
  if (idMap === undefined || !r_symbol_1.RSymbol.is(node)) {
121
111
  return undefined;
122
112
  }
123
- // the framework may bind the object by position, in a function it is handed (`shinyApp(ui, server)`)
124
- const positional = this.boundByEntryPoint(node, idMap);
125
- if (positional !== undefined) {
126
- return positional;
127
- }
128
- return this.config.linkedObjects?.find(o => o.name === node.content && this.hasPackage(o.requires) && isBoundAsLinkedObject(node, o, idMap));
113
+ /* the framework may bind the object by position, in a function it is handed (`shinyApp(ui, server)`) */
114
+ return this.boundByEntryPoint(node, idMap) ?? this.config.linkedObjects?.find(o => o.name === node.content && this.hasPackage(o.requires) && isBoundAsLinkedObject(node, o, idMap));
129
115
  }
130
116
  /**
131
117
  * The object a framework binds at this symbol's position, when the function binding it is handed to one of the
@@ -153,7 +139,7 @@ class InputClassifier {
153
139
  }
154
140
  const index = new Map();
155
141
  this.entryPointIndex = index;
156
- for (const [, call] of (this.fullDfg ?? this.dfg).verticesOfType(vertex_1.VertexType.FunctionCall)) {
142
+ for (const [, call] of this.whole.verticesOfType(vertex_1.VertexType.FunctionCall)) {
157
143
  for (const entry of this.config.linkedEntryPoints ?? []) {
158
144
  if (!this.matches(call, [entry.call])) {
159
145
  continue;
@@ -168,12 +154,8 @@ class InputClassifier {
168
154
  }
169
155
  /** the function definitions the given id may hold, be it one directly or a variable a definition was assigned to */
170
156
  *functionDefinitionsAt(id, depth = 0) {
171
- const graph = this.fullDfg ?? this.dfg;
172
- const vtx = id === undefined || depth > MaxFunctionResolveDepth ? undefined : graph.getVertex(id);
173
- if (vtx === undefined) {
174
- return;
175
- }
176
- else if (vertex_1.DfgVertex.isFunctionDefinition(vtx)) {
157
+ const vtx = id === undefined || depth > MaxFunctionResolveDepth ? undefined : this.whole.getVertex(id);
158
+ if (vertex_1.DfgVertex.isFunctionDefinition(vtx)) {
177
159
  yield vtx.id;
178
160
  }
179
161
  else if (vertex_1.DfgVertex.isVariableDefinition(vtx)) {
@@ -181,8 +163,8 @@ class InputClassifier {
181
163
  yield* this.functionDefinitionsAt(source, depth + 1);
182
164
  }
183
165
  }
184
- else {
185
- for (const origin of df_helper_1.Dataflow.origin(graph, vtx.id) ?? []) {
166
+ else if (vtx !== undefined) {
167
+ for (const origin of df_helper_1.Dataflow.origin(this.whole, vtx.id) ?? []) {
186
168
  if (origin.type === 0 /* OriginType.ReadVariableOrigin */ || origin.type === 1 /* OriginType.WriteVariableOrigin */ || origin.type === 2 /* OriginType.FunctionCallOrigin */) {
187
169
  yield* this.functionDefinitionsAt(origin.id, depth + 1);
188
170
  }
@@ -191,9 +173,9 @@ class InputClassifier {
191
173
  }
192
174
  /** the id of the argument named `argName`, or of the one at `argIdx` if it is passed positionally */
193
175
  argumentReference(call, argIdx, argName) {
194
- const named = call.args.find(a => graph_1.FunctionArgument.isNamed(a) && graph_1.FunctionArgument.getName(a) === argName);
176
+ const named = call.args.find(a => graph_1.FunctionArgument.hasName(a, argName));
195
177
  const arg = named ?? call.args[argIdx];
196
- if (arg === undefined || graph_1.FunctionArgument.isEmpty(arg) || (named === undefined && graph_1.FunctionArgument.isNamed(arg))) {
178
+ if (arg === undefined || (named === undefined && graph_1.FunctionArgument.isNamed(arg))) {
197
179
  return undefined;
198
180
  }
199
181
  return graph_1.FunctionArgument.getReference(arg);
@@ -205,7 +187,7 @@ class InputClassifier {
205
187
  }
206
188
  /**
207
189
  * All declarations of framework entries in the program, keyed by object and entry name, built once on first use.
208
- * This is what links a read of `input$n` back to the `textInput("n", …)` defining it.
190
+ * This is what links a read of `input$n` back to the `textInput("n", ...)` defining it.
209
191
  */
210
192
  declarations() {
211
193
  if (this.declarationIndex !== undefined) {
@@ -217,13 +199,13 @@ class InputClassifier {
217
199
  if (specs.length === 0) {
218
200
  return index;
219
201
  }
220
- for (const [, call] of (this.fullDfg ?? this.dfg).verticesOfType(vertex_1.VertexType.FunctionCall)) {
202
+ for (const [, call] of this.whole.verticesOfType(vertex_1.VertexType.FunctionCall)) {
221
203
  for (const obj of specs) {
222
204
  const spec = obj.declaredBy;
223
205
  if (!this.matches(call, spec.calls)) {
224
206
  continue;
225
207
  }
226
- const name = this.argumentValue(call, spec.argIdx, spec.argName);
208
+ const name = this.classifyAt(this.argumentReference(call, spec.argIdx, spec.argName), this.whole)?.value;
227
209
  if (typeof name === 'string') {
228
210
  const key = declarationKey(obj.name, name);
229
211
  index.set(key, [...(index.get(key) ?? []), call.id]);
@@ -232,20 +214,6 @@ class InputClassifier {
232
214
  }
233
215
  return index;
234
216
  }
235
- /** the value of the argument named `argName`, or of the one at `argIdx` if it is passed positionally */
236
- argumentValue(call, argIdx, argName) {
237
- const ref = this.argumentReference(call, argIdx, argName);
238
- const vtx = ref === undefined ? undefined : (this.fullDfg ?? this.dfg).getVertex(ref);
239
- return vtx === undefined ? undefined : this.classifyEntry(vtx).value;
240
- }
241
- isDefinedByOnCall(id) {
242
- return this.definedByOnCallTargets(id).length > 0;
243
- }
244
- /** the ids the given one is linked to by {@link EdgeType.DefinedByOnCall}, e.g. a parameter to the arguments it is bound to */
245
- definedByOnCallTargets(id) {
246
- const out = (this.fullDfg ?? this.dfg).outgoingEdges(id) ?? new Map();
247
- return out.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall)).map(([to]) => to).toArray();
248
- }
249
217
  /**
250
218
  * Classifies the given id against the full graph, for everything the reduced graph of the criterion cannot see
251
219
  * (the enclosing scopes and the callers of the function the criterion is in).
@@ -255,24 +223,20 @@ class InputClassifier {
255
223
  return undefined;
256
224
  }
257
225
  this.fullClassifier ??= new InputClassifier(this.fullDfg, this.config, undefined, this.packages);
258
- const vtx = this.fullDfg.getVertex(id);
259
- return vtx ? this.fullClassifier.classifyEntry(vtx) : undefined;
226
+ return this.fullClassifier.classifyAt(id);
260
227
  }
261
228
  extractConstantValue(id) {
262
229
  const node = this.dfg.idMap?.get(id);
263
- if (node === undefined) {
264
- return undefined;
265
- }
266
230
  if (r_number_1.RNumber.is(node)) {
267
231
  return node.content.num;
268
232
  }
269
- if (r_string_1.RString.is(node)) {
233
+ else if (r_string_1.RString.is(node)) {
270
234
  return node.content.str;
271
235
  }
272
- if (r_logical_1.RLogical.is(node)) {
236
+ else if (r_logical_1.RLogical.is(node)) {
273
237
  return node.content;
274
238
  }
275
- if (r_symbol_1.RSymbol.is(node) && node.content === convert_values_1.RNull) {
239
+ else if (r_symbol_1.RSymbol.is(node) && node.content === convert_values_1.RNull) {
276
240
  return null;
277
241
  }
278
242
  return undefined;
@@ -282,16 +246,12 @@ class InputClassifier {
282
246
  if (cached) {
283
247
  return cached;
284
248
  }
285
- // insert temporary unknown to break cycles
286
- this.cache.set(vertex.id, { id: vertex.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
249
+ /* a temporary unknown breaks cycles */
250
+ this.cache.set(vertex.id, sourceOf(vertex.id, input_types_1.InputType.Unknown));
287
251
  switch (vertex.tag) {
288
252
  case vertex_1.VertexType.Value: {
289
- const src = { id: vertex.id, types: [input_types_1.InputType.Constant], trace: input_types_1.InputTraceType.Unknown };
290
- const v = this.extractConstantValue(vertex.id);
291
- if (v !== undefined) {
292
- src.value = v;
293
- }
294
- return this.classifyCdsAndReturn(vertex, src);
253
+ const value = this.extractConstantValue(vertex.id);
254
+ return this.classifyCdsAndReturn(vertex, (0, objects_1.compactRecord)({ ...sourceOf(vertex.id, input_types_1.InputType.Constant), value }));
295
255
  }
296
256
  case vertex_1.VertexType.FunctionCall:
297
257
  return this.classifyFunctionCall(vertex);
@@ -300,9 +260,38 @@ class InputClassifier {
300
260
  case vertex_1.VertexType.Use:
301
261
  return this.classifyVariable(vertex);
302
262
  default:
303
- return this.classifyCdsAndReturn(vertex, { id: vertex.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
263
+ return this.classifyCdsAndReturn(vertex, sourceOf(vertex.id, input_types_1.InputType.Unknown));
304
264
  }
305
265
  }
266
+ /**
267
+ * Whether `call` quotes only the code written in its arguments: no name in them resolves outside of them
268
+ * (built-ins aside), as a `bquote(.(y))` splice would, and none names an enclosing parameter `substitute` would replace.
269
+ */
270
+ quotesOnlyWrittenCode(call) {
271
+ const idMap = this.dfg.idMap;
272
+ if (idMap === undefined) {
273
+ return false;
274
+ }
275
+ const enclosing = enclosingFunctions(idMap.get(call.id), idMap);
276
+ const parameters = new Set(enclosing.flatMap(fn => fn.parameters.map(p => identifier_1.Identifier.getName(p.name.content))));
277
+ for (const arg of call.args) {
278
+ const ref = graph_1.FunctionArgument.getReference(arg);
279
+ const within = model_1.RNode.collectAllIds(ref === undefined ? undefined : idMap.get(ref));
280
+ for (const id of within) {
281
+ const node = idMap.get(id);
282
+ if (r_symbol_1.RSymbol.is(node) && parameters.has(identifier_1.Identifier.getName(node.content))) {
283
+ return false;
284
+ }
285
+ for (const target of (0, frame_reflection_1.edgeTargets)(this.dfg, id, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedByOnCall)) {
286
+ /* the call evaluating the code is no input to it */
287
+ if (!within.has(target) && !node_id_1.NodeId.isBuiltIn(target) && !(0, frame_reflection_1.hasEdgeOfType)(this.dfg, target, id, edge_1.EdgeType.Returns)) {
288
+ return false;
289
+ }
290
+ }
291
+ }
292
+ }
293
+ return true;
294
+ }
306
295
  /**
307
296
  * Accesses like `input$n` or `input[["n"]]` are reported as a single source of the accessed object,
308
297
  * carrying the accessed field as its {@link InputSource.name|name}.
@@ -311,28 +300,20 @@ class InputClassifier {
311
300
  if (!call.origin.includes(built_in_proc_name_1.BuiltInProcName.Access)) {
312
301
  return undefined;
313
302
  }
314
- const accessed = graph_1.FunctionArgument.isEmpty(call.args[0]) ? undefined : graph_1.FunctionArgument.getReference(call.args[0]);
303
+ const accessed = graph_1.FunctionArgument.getReference(call.args[0]);
315
304
  const linked = accessed === undefined ? undefined : this.matchLinkedObject(accessed);
316
305
  const field = this.accessedField(call);
317
306
  if (linked === undefined || !fieldIsInput(linked, field)) {
318
307
  return undefined;
319
308
  }
320
- const src = { id: call.id, types: [linked.type], trace: input_types_1.InputTraceType.Unknown };
321
- if (field !== undefined) {
322
- src.name = field;
323
- const declaredAt = linked.declaredBy && this.declarations().get(declarationKey(linked.name, field));
324
- if (declaredAt) {
325
- src.declaredAt = declaredAt;
326
- }
327
- }
328
- return src;
309
+ return (0, objects_1.compactRecord)({
310
+ ...sourceOf(call.id, linked.type),
311
+ name: field,
312
+ declaredAt: field !== undefined && linked.declaredBy ? this.declarations().get(declarationKey(linked.name, field)) : undefined
313
+ });
329
314
  }
330
315
  accessedField(call) {
331
- const arg = call.args[1];
332
- if (arg === undefined || graph_1.FunctionArgument.isEmpty(arg)) {
333
- return undefined;
334
- }
335
- const ref = graph_1.FunctionArgument.getReference(arg);
316
+ const ref = call.args[1] === undefined ? undefined : graph_1.FunctionArgument.getReference(call.args[1]);
336
317
  const node = ref === undefined ? undefined : this.dfg.idMap?.get(ref);
337
318
  if (r_string_1.RString.is(node)) {
338
319
  return node.content.str;
@@ -342,45 +323,33 @@ class InputClassifier {
342
323
  }
343
324
  return undefined;
344
325
  }
345
- classifyFunctionCall(call) {
346
- const linkedAccess = this.classifyLinkedObjectAccess(call);
347
- if (linkedAccess) {
348
- return this.classifyCdsAndReturn(call, linkedAccess);
349
- }
326
+ /** the argument a built-in hands on: the value of a block or `get` (then `renamed`), the condition of a branch or loop */
327
+ passedOn(call) {
350
328
  if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ExpressionList)) {
351
329
  // `{ a; b }` evaluates to its last expression, just like in R
352
- const last = call.args.findLast(a => !graph_1.FunctionArgument.isEmpty(a));
353
- const value = last === undefined ? undefined : graph_1.FunctionArgument.getReference(last);
354
- const vtx = value === undefined ? undefined : this.dfg.getVertex(value);
355
- if (vtx) {
356
- return this.classifyCdsAndReturn(call, { ...this.classifyEntry(vtx), id: call.id });
357
- }
330
+ return { via: call.args.findLast(a => !graph_1.FunctionArgument.isEmpty(a)), renamed: true };
358
331
  }
359
332
  else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) || call.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
360
- const condition = graph_1.FunctionArgument.getReference(call.args[0]);
361
- if (condition) {
362
- const vtx = this.dfg.getVertex(condition);
363
- if (vtx) {
364
- return this.classifyCdsAndReturn(call, this.classifyEntry(vtx));
365
- }
366
- }
333
+ return { via: call.args[0], renamed: false };
367
334
  }
368
335
  else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop)) {
369
- const condition = graph_1.FunctionArgument.getReference(call.args[1]);
370
- if (condition) {
371
- const vtx = this.dfg.getVertex(condition);
372
- if (vtx) {
373
- return this.classifyCdsAndReturn(call, this.classifyEntry(vtx));
374
- }
375
- }
336
+ return { via: call.args[1], renamed: false };
376
337
  }
377
- else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !(this.fullDfg ?? this.dfg).unknownSideEffects.has(node_id_1.NodeId.normalize(call.id))) {
338
+ else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !this.whole.unknownSideEffects.has(node_id_1.NodeId.normalize(call.id))) {
378
339
  // a statically resolved `get("x")` yields the value of the retrieved variable, read via its first argument
379
- const ref = graph_1.FunctionArgument.getReference(call.args[0]);
380
- const vtx = ref === undefined ? undefined : this.dfg.getVertex(ref);
381
- if (vtx) {
382
- return this.classifyCdsAndReturn(call, { ...this.classifyEntry(vtx), id: call.id });
383
- }
340
+ return { via: call.args[0], renamed: true };
341
+ }
342
+ return undefined;
343
+ }
344
+ classifyFunctionCall(call) {
345
+ const linkedAccess = this.classifyLinkedObjectAccess(call);
346
+ if (linkedAccess) {
347
+ return this.classifyCdsAndReturn(call, linkedAccess);
348
+ }
349
+ const handed = this.passedOn(call);
350
+ const passed = this.classifyAt(handed?.via === undefined ? undefined : graph_1.FunctionArgument.getReference(handed.via));
351
+ if (passed) {
352
+ return this.classifyCdsAndReturn(call, handed?.renamed ? { ...passed, id: call.id } : passed);
384
353
  }
385
354
  // a narrowing function returns a bounded value: either one of a specific argument's values (e.g. `match.arg`
386
355
  // -> its `choices`), or - with no bounding argument - a content-independent value like a count/index/logical
@@ -389,87 +358,51 @@ class InputClassifier {
389
358
  continue;
390
359
  }
391
360
  if (narrow.argIdx === undefined) {
392
- return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: [input_types_1.InputType.DerivedConstant], trace: input_types_1.InputTraceType.Pure }));
361
+ return this.classifyCdsAndReturn(call, { id: call.id, types: [input_types_1.InputType.DerivedConstant], trace: input_types_1.InputTraceType.Pure });
393
362
  }
394
- const ref = this.argumentReference(call, narrow.argIdx, narrow.argName ?? '');
395
- const vtx = ref === undefined ? undefined : this.dfg.getVertex(ref);
396
- if (vtx) {
397
- return this.classifyCdsAndReturn(call, { ...this.classifyEntry(vtx), id: call.id });
363
+ const narrowed = this.classifyAt(this.argumentReference(call, narrow.argIdx, narrow.argName ?? ''));
364
+ if (narrowed) {
365
+ return this.classifyCdsAndReturn(call, { ...narrowed, id: call.id });
398
366
  }
399
367
  }
400
368
  if (!this.matches(call, this.config.pure)) {
401
- const types = [];
402
- for (const type of record_1.Record.values(input_types_1.InputType)) {
403
- if (this.matches(call, this.config[type])) {
404
- types.push(type);
405
- }
406
- }
369
+ const types = record_1.Record.values(input_types_1.InputType).filter(type => this.matches(call, this.config[type]));
407
370
  // if a File-typed call reads from a temp path, replace File with TempFile
408
- if (types.includes(input_types_1.InputType.File) && !types.includes(input_types_1.InputType.TempFile)) {
409
- for (const arg of call.args) {
410
- if (graph_1.FunctionArgument.isEmpty(arg)) {
411
- continue;
412
- }
413
- const ref = graph_1.FunctionArgument.getReference(arg);
414
- if (ref === undefined) {
415
- continue;
416
- }
417
- const argVtx = this.dfg.getVertex(ref);
418
- if (argVtx && this.classifyEntry(argVtx).types.includes(input_types_1.InputType.TempFile)) {
419
- types.splice(types.indexOf(input_types_1.InputType.File), 1);
420
- types.push(input_types_1.InputType.TempFile);
421
- break;
422
- }
423
- }
371
+ const readsFile = types.includes(input_types_1.InputType.File) && !types.includes(input_types_1.InputType.TempFile);
372
+ if (readsFile && call.args.some(arg => this.classifyAt(graph_1.FunctionArgument.getReference(arg))?.types.includes(input_types_1.InputType.TempFile))) {
373
+ types.splice(types.indexOf(input_types_1.InputType.File), 1);
374
+ types.push(input_types_1.InputType.TempFile);
375
+ }
376
+ /* `quote` yields written code, only capturing (`substitute(x)`) or splicing (`bquote(.(y))`) brings in other code */
377
+ if (types.includes(input_types_1.InputType.Lang) && this.quotesOnlyWrittenCode(call)) {
378
+ types.splice(types.indexOf(input_types_1.InputType.Lang), 1, input_types_1.InputType.DerivedConstant);
424
379
  }
425
380
  if (types.length === 0) {
426
- // a call of something the code produced itself, like a shiny `reactive()`, yields what that produced
427
- const callee = this.classifyCallee(call);
428
- if (callee !== undefined) {
429
- return this.classifyCdsAndReturn(call, { ...callee, id: call.id });
430
- }
431
- // a call of a function the code defines yields whatever that function returns
432
- const returned = this.classifyDefinitionResult(call);
433
- if (returned !== undefined) {
434
- return this.classifyCdsAndReturn(call, returned);
381
+ /* a call of something the code produced (a shiny `reactive()`) or defines yields what that produced or returns */
382
+ const produced = this.classifyCallee(call) ?? this.classifyDefinitionResult(call);
383
+ if (produced !== undefined) {
384
+ return this.classifyCdsAndReturn(call, { ...produced, id: call.id });
435
385
  }
436
386
  // if it is not pure, we cannot classify based on the inputs, in that case we do not know!
437
387
  types.push(input_types_1.InputType.Unknown);
438
388
  }
439
389
  return this.classifyCdsAndReturn(call, { id: call.id, types, trace: input_types_1.InputTraceType.Unknown });
440
390
  }
441
- // Otherwise, classify by arguments; pure functions get Known/Pure handling
442
391
  const argTypes = [];
443
392
  const cdTypes = [];
444
- for (const arg of call.args) {
445
- if (graph_1.FunctionArgument.isEmpty(arg)) {
446
- continue;
447
- }
448
- const ref = graph_1.FunctionArgument.getReference(arg);
449
- if (ref === undefined) {
450
- argTypes.push(input_types_1.InputType.Unknown);
451
- continue;
452
- }
453
- const argVtx = this.dfg.getVertex(ref);
454
- if (!argVtx) {
455
- argTypes.push(input_types_1.InputType.Unknown);
456
- continue;
457
- }
458
- const classified = this.classifyEntry(argVtx);
459
- // collect all observed types from this argument
460
- argTypes.push(...classified.types);
461
- if (classified.cds) {
462
- cdTypes.push(...classified.cds);
463
- }
393
+ for (const arg of call.args.filter(graph_1.FunctionArgument.isNotEmpty)) {
394
+ const classified = this.classifyAt(graph_1.FunctionArgument.getReference(arg));
395
+ argTypes.push(...classified?.types ?? [input_types_1.InputType.Unknown]);
396
+ cdTypes.push(...classified?.cds ?? []);
464
397
  }
465
- const cds = cdTypes.length > 0 ? (0, arrays_1.uniqueArray)(cdTypes) : undefined;
466
398
  // all arguments only contain constant-like types -> derived constant
467
- const allConstLike = argTypes.length > 0 && argTypes.every(isConstantLike);
468
- if (allConstLike) {
469
- return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: [input_types_1.InputType.DerivedConstant], trace: input_types_1.InputTraceType.Pure, cds }));
470
- }
471
- argTypes.push(input_types_1.InputType.DerivedConstant);
472
- return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: (0, arrays_1.uniqueArray)(argTypes), trace: input_types_1.InputTraceType.Known, cds }));
399
+ const constLike = argTypes.length > 0 && argTypes.every(isConstantLike);
400
+ return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({
401
+ id: call.id,
402
+ types: constLike ? [input_types_1.InputType.DerivedConstant] : (0, arrays_1.uniqueArray)([...argTypes, input_types_1.InputType.DerivedConstant]),
403
+ trace: constLike ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Known,
404
+ cds: cdTypes.length > 0 ? (0, arrays_1.uniqueArray)(cdTypes) : undefined
405
+ }));
473
406
  }
474
407
  /**
475
408
  * What a call of a function the analyzed code defines yields: what its exit points do, as a function whose
@@ -477,28 +410,22 @@ class InputClassifier {
477
410
  * when the call names no definition here or when none of them says anything about what it returns.
478
411
  */
479
412
  classifyDefinitionResult(call) {
480
- const graph = this.fullDfg ?? this.dfg;
481
413
  const acc = new ClassificationAccumulator();
482
- let known = false;
483
414
  for (const fn of this.functionDefinitionsAt(call.id)) {
484
- const definition = graph.getVertex(fn);
485
- if (!vertex_1.DfgVertex.isFunctionDefinition(definition)) {
486
- continue;
487
- }
488
- for (const { nodeId } of definition.exitPoints) {
415
+ const definition = this.whole.getVertex(fn);
416
+ for (const { nodeId } of vertex_1.DfgVertex.isFunctionDefinition(definition) ? definition.exitPoints : []) {
489
417
  for (const value of this.exitValues(nodeId)) {
490
- const vtx = value === undefined ? undefined : this.dfg.getVertex(value) ?? graph.getVertex(value);
491
- const classified = vtx ? this.classifyEntry(vtx) : undefined;
492
- if (classified === undefined) {
418
+ const vtx = value === undefined ? undefined : this.dfg.getVertex(value) ?? this.whole.getVertex(value);
419
+ if (vtx === undefined) {
493
420
  /* an exit flowR cannot place says nothing about the call, so neither can the others */
494
421
  return undefined;
495
422
  }
496
- known = true;
497
- acc.merge(classified);
423
+ acc.merge(this.classifyEntry(vtx));
498
424
  }
499
425
  }
500
426
  }
501
- if (!known) {
427
+ /* every merge records one value, so none means no exit point was found */
428
+ if (acc.values.length === 0) {
502
429
  return undefined;
503
430
  }
504
431
  const built = acc.build(call.id);
@@ -510,17 +437,19 @@ class InputClassifier {
510
437
  * value flowR cannot name, a loop above all, so the caller stops rather than answers with the branches alone.
511
438
  */
512
439
  *exitValues(id, depth = 0) {
513
- const vtx = (this.dfg.getVertex(id) ?? (this.fullDfg ?? this.dfg).getVertex(id));
514
- if (vtx === undefined || !vertex_1.DfgVertex.isFunctionCall(vtx)) {
440
+ const vtx = this.dfg.getVertex(id) ?? this.whole.getVertex(id);
441
+ if (!vertex_1.DfgVertex.isFunctionCall(vtx)) {
515
442
  yield id;
516
443
  return;
517
444
  }
518
- if (vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop) || vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop) || vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.RepeatLoop)) {
445
+ const isLoop = vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop) || vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop)
446
+ || vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.RepeatLoop);
447
+ if (isLoop) {
519
448
  yield undefined;
520
449
  }
521
450
  else if (vtx.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) && depth <= MaxFunctionResolveDepth) {
522
451
  for (const branch of vtx.args.slice(1)) {
523
- const ref = graph_1.FunctionArgument.isEmpty(branch) ? undefined : graph_1.FunctionArgument.getReference(branch);
452
+ const ref = graph_1.FunctionArgument.getReference(branch);
524
453
  if (ref === undefined) {
525
454
  yield undefined;
526
455
  }
@@ -539,8 +468,7 @@ class InputClassifier {
539
468
  if (o.type !== 0 /* OriginType.ReadVariableOrigin */ && o.type !== 1 /* OriginType.WriteVariableOrigin */) {
540
469
  continue;
541
470
  }
542
- const vtx = this.dfg.getVertex(o.id);
543
- const classified = vtx ? this.classifyEntry(vtx) : this.classifyInFullGraph(o.id);
471
+ const classified = this.classifyAt(o.id) ?? this.classifyInFullGraph(o.id);
544
472
  if (classified !== undefined && !classified.types.includes(input_types_1.InputType.Unknown)) {
545
473
  return classified;
546
474
  }
@@ -550,35 +478,40 @@ class InputClassifier {
550
478
  classifyVariable(vtx) {
551
479
  const linked = this.matchWholeLinkedObject(vtx.id);
552
480
  if (linked) {
553
- return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [linked.type], trace: input_types_1.InputTraceType.Unknown });
481
+ return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, linked.type));
554
482
  }
555
483
  const origins = df_helper_1.Dataflow.origin(this.dfg, vtx.id);
556
484
  if (origins === undefined || origins.length === 0) {
557
- if (this.isDefinedByOnCall(vtx.id)) {
558
- return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [input_types_1.InputType.Scope], trace: input_types_1.InputTraceType.Unknown });
485
+ if ((0, frame_reflection_1.edgeTargets)(this.whole, vtx.id, edge_1.EdgeType.DefinedByOnCall).length > 0) {
486
+ return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, input_types_1.InputType.Scope));
559
487
  }
560
488
  // the definition is not part of the criterion's function, so it has to come from an enclosing scope
561
489
  const outer = this.classifyInFullGraph(vtx.id);
562
- return this.classifyCdsAndReturn(vtx, outer ? { ...outer, id: vtx.id } : { id: vtx.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
490
+ return this.classifyCdsAndReturn(vtx, outer ? { ...outer, id: vtx.id } : sourceOf(vtx.id, input_types_1.InputType.Unknown));
563
491
  }
564
492
  const acc = new ClassificationAccumulator();
565
493
  for (const o of origins) {
566
494
  if (o.type === 4 /* OriginType.ConstantOrigin */) {
567
- acc.types.push(input_types_1.InputType.DerivedConstant);
568
- acc.values.push(this.extractConstantValue(o.id));
495
+ acc.push(input_types_1.InputType.DerivedConstant, this.extractConstantValue(o.id));
569
496
  }
570
497
  else if (o.type === 0 /* OriginType.ReadVariableOrigin */ || o.type === 1 /* OriginType.WriteVariableOrigin */) {
571
498
  this.classifyVariableOrigin(o.id, acc);
572
499
  }
573
500
  else if (o.type === 2 /* OriginType.FunctionCallOrigin */ || o.type === 3 /* OriginType.BuiltInFunctionOrigin */) {
574
- this.classifyByVertex(o.id, acc);
501
+ acc.merge(this.classifyAt(o.id));
575
502
  }
576
503
  else {
577
- acc.pushUnknown();
504
+ acc.merge(undefined);
578
505
  }
579
506
  }
580
507
  return this.classifyCdsAndReturn(vtx, acc.build(vtx.id));
581
508
  }
509
+ parameterType(id) {
510
+ if (this.dfg.idMap?.get(id)?.info.role !== "param-n" /* RoleInParent.ParameterName */) {
511
+ return undefined;
512
+ }
513
+ return this.matchWholeLinkedObject(id)?.type ?? input_types_1.InputType.Parameter;
514
+ }
582
515
  /**
583
516
  * Resolves a variable definition or use origin, handling the special cases of
584
517
  * scope-escaped variables (DefinedByOnCall) and parameter definitions.
@@ -586,12 +519,12 @@ class InputClassifier {
586
519
  classifyVariableOrigin(definitionId, acc) {
587
520
  const v = this.dfg.getVertex(definitionId);
588
521
  if (!v) {
589
- acc.pushUnknown();
522
+ acc.merge(undefined);
590
523
  return;
591
524
  }
592
525
  // if the referenced definition is linked via defined-by-on-call to another id (e.g., a parameter linked to a
593
526
  // caller argument), follow it into the caller; only if that leads nowhere is it an opaque Scope origin
594
- const onCall = this.definedByOnCallTargets(v.id);
527
+ const onCall = (0, frame_reflection_1.edgeTargets)(this.whole, v.id, edge_1.EdgeType.DefinedByOnCall);
595
528
  if (onCall.length > 0) {
596
529
  const callers = onCall.map(t => this.classifyInFullGraph(t)).filter(assert_1.isNotUndefined);
597
530
  const known = callers.filter(c => !c.types.includes(input_types_1.InputType.Unknown));
@@ -599,60 +532,37 @@ class InputClassifier {
599
532
  if (known.length > 0 && known.length === callers.length) {
600
533
  return;
601
534
  }
602
- acc.types.push(input_types_1.InputType.Scope);
603
- acc.values.push(undefined);
535
+ acc.push(input_types_1.InputType.Scope);
604
536
  acc.allPure = false;
605
537
  }
606
- // if this is a variable definition that is a parameter, classify as Parameter
607
- if (vertex_1.DfgVertex.isVariableDefinition(v) && this.dfg.idMap?.get(v.id)?.info.role === "param-n" /* RoleInParent.ParameterName */) {
608
- acc.types.push(this.matchWholeLinkedObject(v.id)?.type ?? input_types_1.InputType.Parameter);
609
- acc.values.push(undefined);
610
- return;
611
- }
612
- acc.merge(this.classifyEntry(v));
613
- }
614
- classifyByVertex(id, acc) {
615
- const v = this.dfg.getVertex(id);
616
- if (v) {
617
- acc.merge(this.classifyEntry(v));
538
+ const parameter = vertex_1.DfgVertex.isVariableDefinition(v) ? this.parameterType(v.id) : undefined;
539
+ if (parameter !== undefined) {
540
+ acc.push(parameter);
618
541
  }
619
542
  else {
620
- acc.pushUnknown();
543
+ acc.merge(this.classifyEntry(v));
621
544
  }
622
545
  }
623
546
  classifyVariableDefinition(vtx) {
624
- // parameter definitions are classified as Parameter
625
- if (this.dfg.idMap?.get(vtx.id)?.info.role === "param-n" /* RoleInParent.ParameterName */) {
626
- const types = [this.matchWholeLinkedObject(vtx.id)?.type ?? input_types_1.InputType.Parameter];
627
- return this.classifyCdsAndReturn(vtx, { id: vtx.id, types, trace: input_types_1.InputTraceType.Unknown });
547
+ const parameter = this.parameterType(vtx.id);
548
+ if (parameter !== undefined) {
549
+ return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, parameter));
628
550
  }
629
- const sources = vtx.source;
630
- if (sources === undefined || sources.length === 0) {
551
+ else if (!vtx.source?.length) {
631
552
  // fallback to unknown if we cannot find the value
632
- return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
553
+ return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, input_types_1.InputType.Unknown));
633
554
  }
634
555
  const acc = new ClassificationAccumulator();
635
- for (const tid of sources) {
636
- const tv = this.dfg.getVertex(tid);
637
- if (tv) {
638
- acc.merge(this.classifyEntry(tv));
639
- }
640
- else {
641
- acc.pushUnknown();
642
- }
643
- }
556
+ vtx.source.forEach(tid => acc.merge(this.classifyAt(tid)));
644
557
  return this.classifyCdsAndReturn(vtx, acc.build(vtx.id));
645
558
  }
646
559
  classifyCdsAndReturn(vtx, src) {
647
560
  if (vtx.cds) {
648
- const cds = (0, arrays_1.uniqueArray)(vtx.cds.flatMap(c => {
649
- const cv = this.dfg.getVertex(c.id);
650
- if (!cv) {
651
- return undefined;
652
- }
653
- const e = this.classifyEntry(cv);
654
- return e.cds ? [...e.types, ...e.cds] : [...e.types];
655
- }).filter(assert_1.isNotUndefined).concat(src.cds ?? []));
561
+ /* running only once a call forces it is no condition on the data */
562
+ const cds = (0, arrays_1.uniqueArray)(vtx.cds.filter(c => c.byPromise !== true).flatMap(c => {
563
+ const e = this.classifyAt(c.id);
564
+ return e ? [...e.types, ...e.cds ?? []] : [];
565
+ }).concat(src.cds ?? []));
656
566
  if (cds.length > 0) {
657
567
  src.cds = cds;
658
568
  }
@@ -705,9 +615,6 @@ function callMeans(called, id, packages) {
705
615
  return identifier_1.Identifier.getNamespace(called) === undefined && identifier_1.Identifier.matches(called, id)
706
616
  && (namespace === undefined || packages === undefined || packages.has(namespace));
707
617
  }
708
- function matchesList(fn, list, packages) {
709
- return list?.some(id => fn.id === id || (identifier_1.Identifier.is(id) && callMeans(fn.name, id, packages))) ?? false;
710
- }
711
618
  /**
712
619
  * Takes the given id which is expected to either be:
713
620
  * - a function call - in this case all arguments are considered to be inputs (additionally to all read edges from the function call in the dataflow graph)
@@ -719,35 +626,19 @@ function matchesList(fn, list, packages) {
719
626
  */
720
627
  function classifyInput(id, dfg, config, fullDfg, packages) {
721
628
  const vtx = dfg.getVertex(id);
722
- if (!vtx) {
723
- return [];
724
- }
725
629
  const c = new InputClassifier(dfg, config, fullDfg, packages);
726
- if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
727
- const ret = [];
728
- const args = vtx.args;
729
- for (const arg of args) {
730
- if (graph_1.FunctionArgument.isEmpty(arg)) {
731
- continue;
732
- }
733
- const ref = graph_1.FunctionArgument.getReference(arg);
734
- if (ref === undefined) {
735
- continue;
736
- }
737
- const argVtx = dfg.getVertex(ref);
738
- if (argVtx === undefined) {
739
- continue;
740
- }
741
- const entry = c.classifyEntry(argVtx);
742
- const argName = graph_1.FunctionArgument.getName(arg);
743
- ret.push(argName !== undefined ? { ...entry, name: argName } : entry);
744
- }
745
- return ret;
630
+ if (!vertex_1.DfgVertex.isFunctionCall(vtx)) {
631
+ return vtx ? [c.classifyEntry(vtx)] : [];
746
632
  }
747
- else {
748
- return [
749
- c.classifyEntry(vtx)
750
- ];
633
+ const ret = [];
634
+ for (const arg of vtx.args) {
635
+ const entry = c.classifyAt(graph_1.FunctionArgument.getReference(arg));
636
+ if (entry === undefined) {
637
+ continue;
638
+ }
639
+ const name = graph_1.FunctionArgument.getName(arg);
640
+ ret.push(name !== undefined ? { ...entry, name } : entry);
751
641
  }
642
+ return ret;
752
643
  }
753
644
  //# sourceMappingURL=simple-input-classifier.js.map