@eagleoutice/flowr 2.13.2 → 2.13.3

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 (97) hide show
  1. package/README.md +46 -44
  2. package/abstract-interpretation/data-frame/mappers/access-mapper.js +1 -0
  3. package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +1 -1
  4. package/abstract-interpretation/data-frame/mappers/function-mapper.js +3 -0
  5. package/abstract-interpretation/domains/state-domain-like.d.ts +1 -1
  6. package/config.d.ts +8 -0
  7. package/config.js +9 -1
  8. package/control-flow/control-flow-graph.js +2 -1
  9. package/control-flow/semantic-cfg-guided-visitor.d.ts +1 -1
  10. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +1 -1
  11. package/dataflow/environments/append.d.ts +1 -1
  12. package/dataflow/environments/clone.d.ts +1 -1
  13. package/dataflow/environments/environment.d.ts +28 -4
  14. package/dataflow/environments/environment.js +66 -11
  15. package/dataflow/environments/overwrite.d.ts +1 -1
  16. package/dataflow/eval/resolve/alias-tracking.d.ts +1 -1
  17. package/dataflow/graph/dataflowgraph-builder.d.ts +1 -1
  18. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -1
  19. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +1 -1
  20. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -0
  21. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +51 -0
  22. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +1 -1
  23. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +1 -1
  24. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +1 -1
  25. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +5 -2
  26. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +15 -9
  27. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +1 -1
  28. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +1 -1
  29. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +1 -1
  30. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-dispatch.d.ts +1 -1
  31. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +7 -1
  32. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +9 -2
  33. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -1
  34. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +2 -2
  35. package/dataflow/internal/process/functions/call/built-in/built-in-vector.d.ts +1 -1
  36. package/documentation/doc-readme.js +14 -12
  37. package/documentation/doc-util/doc-normalized-ast.d.ts +1 -1
  38. package/documentation/wiki-dataflow-graph.js +4 -24
  39. package/documentation/wiki-query.js +47 -0
  40. package/documentation/wiki-signature-database.js +3 -2
  41. package/linter/rules/dataframe-access-validation.d.ts +1 -1
  42. package/linter/rules/undefined-symbol-util.js +3 -1
  43. package/linter/rules/undefined-symbol.js +3 -4
  44. package/package.json +21 -9
  45. package/project/context/flowr-analyzer-context.d.ts +4 -4
  46. package/project/context/flowr-analyzer-context.js +3 -3
  47. package/project/context/flowr-analyzer-dependencies-context.d.ts +11 -5
  48. package/project/context/flowr-analyzer-dependencies-context.js +8 -3
  49. package/project/context/flowr-analyzer-meta-context.d.ts +1 -0
  50. package/project/dependency-version-space.d.ts +118 -26
  51. package/project/dependency-version-space.js +343 -87
  52. package/project/plugins/file-plugins/files/flowr-description-file.d.ts +4 -0
  53. package/project/plugins/file-plugins/files/flowr-description-file.js +8 -1
  54. package/project/plugins/file-plugins/files/flowr-rda-file.js +27 -25
  55. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.d.ts +1 -1
  56. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.d.ts +1 -1
  57. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +2 -1
  58. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +1 -1
  59. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -4
  60. package/project/plugins/package-version-plugins/package.d.ts +27 -10
  61. package/project/plugins/package-version-plugins/package.js +50 -25
  62. package/project/sigdb/reader.d.ts +26 -16
  63. package/project/sigdb/reader.js +52 -21
  64. package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
  65. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +2 -2
  66. package/queries/catalog/dependencies-query/dependencies-query-format.js +2 -2
  67. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -1
  68. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +39 -77
  69. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +12 -0
  70. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +53 -23
  71. package/queries/catalog/input-sources-query/input-source-functions.d.ts +13 -0
  72. package/queries/catalog/input-sources-query/input-source-functions.js +96 -1
  73. package/queries/catalog/input-sources-query/input-sources-query-executor.js +40 -4
  74. package/queries/catalog/input-sources-query/input-sources-query-format.js +21 -3
  75. package/queries/catalog/input-sources-query/input-types.d.ts +58 -0
  76. package/queries/catalog/input-sources-query/input-types.js +64 -0
  77. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +62 -52
  78. package/queries/catalog/input-sources-query/simple-input-classifier.js +334 -101
  79. package/queries/catalog/project-query/project-query-executor.js +1 -1
  80. package/queries/catalog/signature-query/signature-query-executor.d.ts +7 -1
  81. package/queries/catalog/signature-query/signature-query-executor.js +112 -39
  82. package/queries/catalog/signature-query/signature-query-format.d.ts +5 -1
  83. package/queries/catalog/signature-query/signature-query-format.js +1 -1
  84. package/queries/catalog/signature-query/signature-query-render.js +8 -3
  85. package/r-bridge/lang-4.x/ast/parser/json/format.js +1 -1
  86. package/r-bridge/retriever.d.ts +1 -1
  87. package/search/flowr-search-printer.js +10 -8
  88. package/slicing/static/static-slicer.d.ts +2 -2
  89. package/util/objects.js +6 -4
  90. package/util/r-base-packages.d.ts +2 -0
  91. package/util/r-base-packages.js +3 -0
  92. package/util/r-license.js +1 -4
  93. package/util/r-version.d.ts +12 -0
  94. package/util/r-version.js +16 -0
  95. package/util/range.d.ts +6 -2
  96. package/util/range.js +33 -15
  97. package/util/version.js +1 -1
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InputTraceType = exports.InputType = void 0;
3
+ exports.InputType = exports.InputTraceType = void 0;
4
4
  exports.classifyInput = classifyInput;
5
+ const input_types_1 = require("./input-types");
6
+ var input_types_2 = require("./input-types");
7
+ Object.defineProperty(exports, "InputTraceType", { enumerable: true, get: function () { return input_types_2.InputTraceType; } });
8
+ Object.defineProperty(exports, "InputType", { enumerable: true, get: function () { return input_types_2.InputType; } });
5
9
  const graph_1 = require("../../../dataflow/graph/graph");
6
10
  const objects_1 = require("../../../util/objects");
7
11
  const vertex_1 = require("../../../dataflow/graph/vertex");
@@ -17,8 +21,12 @@ const r_string_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-string"
17
21
  const r_logical_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-logical");
18
22
  const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
19
23
  const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
24
+ const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
25
+ const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
26
+ /** how far a function handed to an entry point may be passed along before we give up resolving it */
27
+ const MaxFunctionResolveDepth = 4;
20
28
  function isConstantLike(type) {
21
- return type === InputType.Constant || type === InputType.DerivedConstant;
29
+ return type === input_types_1.InputType.Constant || type === input_types_1.InputType.DerivedConstant;
22
30
  }
23
31
  /** Returns the common value shared by all defined entries, or `undefined` if they disagree or all are `undefined`. */
24
32
  function singleValue(values) {
@@ -53,17 +61,17 @@ class ClassificationAccumulator {
53
61
  if (c.cds) {
54
62
  this.cds.push(...c.cds);
55
63
  }
56
- if (c.trace !== InputTraceType.Pure) {
64
+ if (c.trace !== input_types_1.InputTraceType.Pure) {
57
65
  this.allPure = false;
58
66
  }
59
67
  }
60
68
  pushUnknown() {
61
- this.types.push(InputType.Unknown);
69
+ this.types.push(input_types_1.InputType.Unknown);
62
70
  this.values.push(undefined);
63
71
  }
64
72
  build(id) {
65
- const types = this.types.length === 0 ? [InputType.Unknown] : (0, arrays_1.uniqueArray)(this.types);
66
- const trace = this.allPure ? InputTraceType.Pure : InputTraceType.Alias;
73
+ const types = this.types.length === 0 ? [input_types_1.InputType.Unknown] : (0, arrays_1.uniqueArray)(this.types);
74
+ const trace = this.allPure ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Alias;
67
75
  const src = { id, types, trace };
68
76
  const cds = this.cds.length === 0 ? undefined : (0, arrays_1.uniqueArray)(this.cds);
69
77
  if (cds) {
@@ -83,14 +91,171 @@ class InputClassifier {
83
91
  config;
84
92
  cache = new Map();
85
93
  fullDfg;
86
- constructor(dfg, config, fullDfg) {
94
+ /** the packages attached in the analyzed program, `undefined` if that is not known (then everything may match) */
95
+ packages;
96
+ fullClassifier;
97
+ declarationIndex;
98
+ entryPointIndex;
99
+ constructor(dfg, config, fullDfg, packages) {
87
100
  this.dfg = dfg;
88
101
  this.config = config;
89
102
  this.fullDfg = fullDfg;
103
+ this.packages = packages;
104
+ }
105
+ matches(call, list) {
106
+ return matchesList(call, list, this.packages);
107
+ }
108
+ /** whether the package the given entry needs is attached (unknown package information lets everything through) */
109
+ hasPackage(name) {
110
+ return name === undefined || this.packages === undefined || this.packages.has(name);
111
+ }
112
+ /**
113
+ * Returns the specification of the {@link LinkedInputObject|linked input object} the given id refers to
114
+ * (e.g., shiny's `input`), or `undefined` if it refers to something else.
115
+ */
116
+ matchLinkedObject(id) {
117
+ const idMap = this.dfg.idMap;
118
+ const node = idMap?.get(id);
119
+ if (idMap === undefined || !r_symbol_1.RSymbol.is(node)) {
120
+ return undefined;
121
+ }
122
+ // the framework may bind the object by position, in a function it is handed (`shinyApp(ui, server)`)
123
+ const positional = this.boundByEntryPoint(node, idMap);
124
+ if (positional !== undefined) {
125
+ return positional;
126
+ }
127
+ return this.config.linkedObjects?.find(o => o.name === node.content && this.hasPackage(o.requires) && isBoundAsLinkedObject(node, o, idMap));
128
+ }
129
+ /**
130
+ * The object a framework binds at this symbol's position, when the function binding it is handed to one of the
131
+ * {@link LinkedInputEntryPoint|entry points} - this is how R passes them, so the parameter names do not matter.
132
+ */
133
+ boundByEntryPoint(node, idMap) {
134
+ if (!this.config.linkedEntryPoints?.length) {
135
+ return undefined;
136
+ }
137
+ for (const fn of enclosingFunctions(node, idMap)) {
138
+ const index = fn.parameters.findIndex(p => p.name.content === node.content);
139
+ if (index < 0) {
140
+ continue; // not bound by this function, so keep looking outwards
141
+ }
142
+ const bound = this.entryPoints().get(fn.info.id)?.[index];
143
+ // the entry point names the object, so it keeps its fields and declarations no matter what the parameter is called
144
+ return bound === undefined ? undefined : this.config.linkedObjects?.find(o => o.name === bound);
145
+ }
146
+ return undefined;
147
+ }
148
+ /** The function definitions handed to an {@link LinkedInputEntryPoint|entry point}, with how it binds their parameters. */
149
+ entryPoints() {
150
+ if (this.entryPointIndex !== undefined) {
151
+ return this.entryPointIndex;
152
+ }
153
+ const index = new Map();
154
+ this.entryPointIndex = index;
155
+ for (const [, call] of (this.fullDfg ?? this.dfg).verticesOfType(vertex_1.VertexType.FunctionCall)) {
156
+ for (const entry of this.config.linkedEntryPoints ?? []) {
157
+ if (!this.matches(call, [entry.call])) {
158
+ continue;
159
+ }
160
+ const handed = this.argumentReference(call, entry.argIdx, entry.argName);
161
+ for (const fn of this.functionDefinitionsAt(handed)) {
162
+ index.set(fn, entry.params);
163
+ }
164
+ }
165
+ }
166
+ return index;
167
+ }
168
+ /** the function definitions the given id may hold, be it one directly or a variable a definition was assigned to */
169
+ *functionDefinitionsAt(id, depth = 0) {
170
+ const graph = this.fullDfg ?? this.dfg;
171
+ const vtx = id === undefined || depth > MaxFunctionResolveDepth ? undefined : graph.getVertex(id);
172
+ if (vtx === undefined) {
173
+ return;
174
+ }
175
+ else if (vtx.tag === vertex_1.VertexType.FunctionDefinition) {
176
+ yield vtx.id;
177
+ }
178
+ else if (vtx.tag === vertex_1.VertexType.VariableDefinition) {
179
+ for (const source of vtx.source ?? []) {
180
+ yield* this.functionDefinitionsAt(source, depth + 1);
181
+ }
182
+ }
183
+ else {
184
+ for (const origin of df_helper_1.Dataflow.origin(graph, vtx.id) ?? []) {
185
+ if (origin.type === 0 /* OriginType.ReadVariableOrigin */ || origin.type === 1 /* OriginType.WriteVariableOrigin */ || origin.type === 2 /* OriginType.FunctionCallOrigin */) {
186
+ yield* this.functionDefinitionsAt(origin.id, depth + 1);
187
+ }
188
+ }
189
+ }
190
+ }
191
+ /** the id of the argument named `argName`, or of the one at `argIdx` if it is passed positionally */
192
+ argumentReference(call, argIdx, argName) {
193
+ const named = call.args.find(a => graph_1.FunctionArgument.isNamed(a) && graph_1.FunctionArgument.getName(a) === argName);
194
+ const arg = named ?? call.args[argIdx];
195
+ if (arg === undefined || graph_1.FunctionArgument.isEmpty(arg) || (named === undefined && graph_1.FunctionArgument.isNamed(arg))) {
196
+ return undefined;
197
+ }
198
+ return graph_1.FunctionArgument.getReference(arg);
199
+ }
200
+ /** the linked object the id refers to, but only where reading the object as a whole already is an input */
201
+ matchWholeLinkedObject(id) {
202
+ const obj = this.matchLinkedObject(id);
203
+ return obj !== undefined && fieldIsInput(obj, undefined) ? obj : undefined;
204
+ }
205
+ /**
206
+ * All declarations of framework entries in the program, keyed by object and entry name, built once on first use.
207
+ * This is what links a read of `input$n` back to the `textInput("n", …)` defining it.
208
+ */
209
+ declarations() {
210
+ if (this.declarationIndex !== undefined) {
211
+ return this.declarationIndex;
212
+ }
213
+ const index = new Map();
214
+ this.declarationIndex = index;
215
+ const specs = this.config.linkedObjects?.filter(o => o.declaredBy !== undefined) ?? [];
216
+ if (specs.length === 0) {
217
+ return index;
218
+ }
219
+ for (const [, call] of (this.fullDfg ?? this.dfg).verticesOfType(vertex_1.VertexType.FunctionCall)) {
220
+ for (const obj of specs) {
221
+ const spec = obj.declaredBy;
222
+ if (!this.matches(call, spec.calls)) {
223
+ continue;
224
+ }
225
+ const name = this.argumentValue(call, spec.argIdx, spec.argName);
226
+ if (typeof name === 'string') {
227
+ const key = declarationKey(obj.name, name);
228
+ index.set(key, [...(index.get(key) ?? []), call.id]);
229
+ }
230
+ }
231
+ }
232
+ return index;
233
+ }
234
+ /** the value of the argument named `argName`, or of the one at `argIdx` if it is passed positionally */
235
+ argumentValue(call, argIdx, argName) {
236
+ const ref = this.argumentReference(call, argIdx, argName);
237
+ const vtx = ref === undefined ? undefined : (this.fullDfg ?? this.dfg).getVertex(ref);
238
+ return vtx === undefined ? undefined : this.classifyEntry(vtx).value;
90
239
  }
91
240
  isDefinedByOnCall(id) {
241
+ return this.definedByOnCallTargets(id).length > 0;
242
+ }
243
+ /** the ids the given one is linked to by {@link EdgeType.DefinedByOnCall}, e.g. a parameter to the arguments it is bound to */
244
+ definedByOnCallTargets(id) {
92
245
  const out = (this.fullDfg ?? this.dfg).outgoingEdges(id) ?? new Map();
93
- return out.values().some(e => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall));
246
+ return out.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedByOnCall)).map(([to]) => to).toArray();
247
+ }
248
+ /**
249
+ * Classifies the given id against the full graph, for everything the reduced graph of the criterion cannot see
250
+ * (the enclosing scopes and the callers of the function the criterion is in).
251
+ */
252
+ classifyInFullGraph(id) {
253
+ if (this.fullDfg === undefined || this.fullDfg === this.dfg) {
254
+ return undefined;
255
+ }
256
+ this.fullClassifier ??= new InputClassifier(this.fullDfg, this.config, undefined, this.packages);
257
+ const vtx = this.fullDfg.getVertex(id);
258
+ return vtx ? this.fullClassifier.classifyEntry(vtx) : undefined;
94
259
  }
95
260
  extractConstantValue(id) {
96
261
  const node = this.dfg.idMap?.get(id);
@@ -117,10 +282,10 @@ class InputClassifier {
117
282
  return cached;
118
283
  }
119
284
  // insert temporary unknown to break cycles
120
- this.cache.set(vertex.id, { id: vertex.id, types: [InputType.Unknown], trace: InputTraceType.Unknown });
285
+ this.cache.set(vertex.id, { id: vertex.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
121
286
  switch (vertex.tag) {
122
287
  case vertex_1.VertexType.Value: {
123
- const src = { id: vertex.id, types: [InputType.Constant], trace: InputTraceType.Unknown };
288
+ const src = { id: vertex.id, types: [input_types_1.InputType.Constant], trace: input_types_1.InputTraceType.Unknown };
124
289
  const v = this.extractConstantValue(vertex.id);
125
290
  if (v !== undefined) {
126
291
  src.value = v;
@@ -134,11 +299,63 @@ class InputClassifier {
134
299
  case vertex_1.VertexType.Use:
135
300
  return this.classifyVariable(vertex);
136
301
  default:
137
- return this.classifyCdsAndReturn(vertex, { id: vertex.id, types: [InputType.Unknown], trace: InputTraceType.Unknown });
302
+ return this.classifyCdsAndReturn(vertex, { id: vertex.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
303
+ }
304
+ }
305
+ /**
306
+ * Accesses like `input$n` or `input[["n"]]` are reported as a single source of the accessed object,
307
+ * carrying the accessed field as its {@link InputSource.name|name}.
308
+ */
309
+ classifyLinkedObjectAccess(call) {
310
+ if (!call.origin.includes(built_in_proc_name_1.BuiltInProcName.Access)) {
311
+ return undefined;
312
+ }
313
+ const accessed = graph_1.FunctionArgument.isEmpty(call.args[0]) ? undefined : graph_1.FunctionArgument.getReference(call.args[0]);
314
+ const linked = accessed === undefined ? undefined : this.matchLinkedObject(accessed);
315
+ const field = this.accessedField(call);
316
+ if (linked === undefined || !fieldIsInput(linked, field)) {
317
+ return undefined;
318
+ }
319
+ const src = { id: call.id, types: [linked.type], trace: input_types_1.InputTraceType.Unknown };
320
+ if (field !== undefined) {
321
+ src.name = field;
322
+ const declaredAt = linked.declaredBy && this.declarations().get(declarationKey(linked.name, field));
323
+ if (declaredAt) {
324
+ src.declaredAt = declaredAt;
325
+ }
326
+ }
327
+ return src;
328
+ }
329
+ accessedField(call) {
330
+ const arg = call.args[1];
331
+ if (arg === undefined || graph_1.FunctionArgument.isEmpty(arg)) {
332
+ return undefined;
333
+ }
334
+ const ref = graph_1.FunctionArgument.getReference(arg);
335
+ const node = ref === undefined ? undefined : this.dfg.idMap?.get(ref);
336
+ if (r_string_1.RString.is(node)) {
337
+ return node.content.str;
138
338
  }
339
+ else if (r_symbol_1.RSymbol.is(node)) {
340
+ return identifier_1.Identifier.getName(node.content);
341
+ }
342
+ return undefined;
139
343
  }
140
344
  classifyFunctionCall(call) {
141
- if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) || call.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
345
+ const linkedAccess = this.classifyLinkedObjectAccess(call);
346
+ if (linkedAccess) {
347
+ return this.classifyCdsAndReturn(call, linkedAccess);
348
+ }
349
+ if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ExpressionList)) {
350
+ // `{ a; b }` evaluates to its last expression, just like in R
351
+ const last = call.args.findLast(a => !graph_1.FunctionArgument.isEmpty(a));
352
+ const value = last === undefined ? undefined : graph_1.FunctionArgument.getReference(last);
353
+ const vtx = value === undefined ? undefined : this.dfg.getVertex(value);
354
+ if (vtx) {
355
+ return this.classifyCdsAndReturn(call, { ...this.classifyEntry(vtx), id: call.id });
356
+ }
357
+ }
358
+ else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) || call.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
142
359
  const condition = graph_1.FunctionArgument.getReference(call.args[0]);
143
360
  if (condition) {
144
361
  const vtx = this.dfg.getVertex(condition);
@@ -156,15 +373,15 @@ class InputClassifier {
156
373
  }
157
374
  }
158
375
  }
159
- if (!matchesList(call, this.config.pure)) {
376
+ if (!this.matches(call, this.config.pure)) {
160
377
  const types = [];
161
- for (const [type, entry] of record_1.Record.entries(this.config)) {
162
- if (record_1.Record.values(InputType).includes(type) && matchesList(call, entry)) {
378
+ for (const type of record_1.Record.values(input_types_1.InputType)) {
379
+ if (this.matches(call, this.config[type])) {
163
380
  types.push(type);
164
381
  }
165
382
  }
166
383
  // if a File-typed call reads from a temp path, replace File with TempFile
167
- if (types.includes(InputType.File) && !types.includes(InputType.TempFile)) {
384
+ if (types.includes(input_types_1.InputType.File) && !types.includes(input_types_1.InputType.TempFile)) {
168
385
  for (const arg of call.args) {
169
386
  if (graph_1.FunctionArgument.isEmpty(arg)) {
170
387
  continue;
@@ -174,18 +391,23 @@ class InputClassifier {
174
391
  continue;
175
392
  }
176
393
  const argVtx = this.dfg.getVertex(ref);
177
- if (argVtx && this.classifyEntry(argVtx).types.includes(InputType.TempFile)) {
178
- types.splice(types.indexOf(InputType.File), 1);
179
- types.push(InputType.TempFile);
394
+ if (argVtx && this.classifyEntry(argVtx).types.includes(input_types_1.InputType.TempFile)) {
395
+ types.splice(types.indexOf(input_types_1.InputType.File), 1);
396
+ types.push(input_types_1.InputType.TempFile);
180
397
  break;
181
398
  }
182
399
  }
183
400
  }
184
401
  if (types.length === 0) {
402
+ // a call of something the code produced itself, like a shiny `reactive()`, yields what that produced
403
+ const callee = this.classifyCallee(call);
404
+ if (callee !== undefined) {
405
+ return this.classifyCdsAndReturn(call, { ...callee, id: call.id });
406
+ }
185
407
  // if it is not pure, we cannot classify based on the inputs, in that case we do not know!
186
- types.push(InputType.Unknown);
408
+ types.push(input_types_1.InputType.Unknown);
187
409
  }
188
- return this.classifyCdsAndReturn(call, { id: call.id, types, trace: InputTraceType.Unknown });
410
+ return this.classifyCdsAndReturn(call, { id: call.id, types, trace: input_types_1.InputTraceType.Unknown });
189
411
  }
190
412
  // Otherwise, classify by arguments; pure functions get Known/Pure handling
191
413
  const argTypes = [];
@@ -196,12 +418,12 @@ class InputClassifier {
196
418
  }
197
419
  const ref = graph_1.FunctionArgument.getReference(arg);
198
420
  if (ref === undefined) {
199
- argTypes.push(InputType.Unknown);
421
+ argTypes.push(input_types_1.InputType.Unknown);
200
422
  continue;
201
423
  }
202
424
  const argVtx = this.dfg.getVertex(ref);
203
425
  if (!argVtx) {
204
- argTypes.push(InputType.Unknown);
426
+ argTypes.push(input_types_1.InputType.Unknown);
205
427
  continue;
206
428
  }
207
429
  const classified = this.classifyEntry(argVtx);
@@ -215,20 +437,43 @@ class InputClassifier {
215
437
  // all arguments only contain constant-like types -> derived constant
216
438
  const allConstLike = argTypes.length > 0 && argTypes.every(isConstantLike);
217
439
  if (allConstLike) {
218
- return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: [InputType.DerivedConstant], trace: InputTraceType.Pure, cds }));
440
+ return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: [input_types_1.InputType.DerivedConstant], trace: input_types_1.InputTraceType.Pure, cds }));
219
441
  }
220
- argTypes.push(InputType.DerivedConstant);
221
- return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: (0, arrays_1.uniqueArray)(argTypes), trace: InputTraceType.Known, cds }));
442
+ argTypes.push(input_types_1.InputType.DerivedConstant);
443
+ return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({ id: call.id, types: (0, arrays_1.uniqueArray)(argTypes), trace: input_types_1.InputTraceType.Known, cds }));
444
+ }
445
+ /** classifies what a call of a variable (e.g. a shiny reactive `n()`) yields, by what that variable holds */
446
+ classifyCallee(call) {
447
+ for (const o of df_helper_1.Dataflow.origin(this.dfg, call.id) ?? []) {
448
+ if (o.type !== 0 /* OriginType.ReadVariableOrigin */ && o.type !== 1 /* OriginType.WriteVariableOrigin */) {
449
+ continue;
450
+ }
451
+ const vtx = this.dfg.getVertex(o.id);
452
+ const classified = vtx ? this.classifyEntry(vtx) : this.classifyInFullGraph(o.id);
453
+ if (classified !== undefined && !classified.types.includes(input_types_1.InputType.Unknown)) {
454
+ return classified;
455
+ }
456
+ }
457
+ return undefined;
222
458
  }
223
459
  classifyVariable(vtx) {
460
+ const linked = this.matchWholeLinkedObject(vtx.id);
461
+ if (linked) {
462
+ return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [linked.type], trace: input_types_1.InputTraceType.Unknown });
463
+ }
224
464
  const origins = df_helper_1.Dataflow.origin(this.dfg, vtx.id);
225
- if (origins === undefined) {
226
- return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: this.isDefinedByOnCall(vtx.id) ? [InputType.Scope] : [InputType.Unknown], trace: InputTraceType.Unknown });
465
+ if (origins === undefined || origins.length === 0) {
466
+ if (this.isDefinedByOnCall(vtx.id)) {
467
+ return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [input_types_1.InputType.Scope], trace: input_types_1.InputTraceType.Unknown });
468
+ }
469
+ // the definition is not part of the criterion's function, so it has to come from an enclosing scope
470
+ const outer = this.classifyInFullGraph(vtx.id);
471
+ return this.classifyCdsAndReturn(vtx, outer ? { ...outer, id: vtx.id } : { id: vtx.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
227
472
  }
228
473
  const acc = new ClassificationAccumulator();
229
474
  for (const o of origins) {
230
475
  if (o.type === 4 /* OriginType.ConstantOrigin */) {
231
- acc.types.push(InputType.DerivedConstant);
476
+ acc.types.push(input_types_1.InputType.DerivedConstant);
232
477
  acc.values.push(this.extractConstantValue(o.id));
233
478
  }
234
479
  else if (o.type === 0 /* OriginType.ReadVariableOrigin */ || o.type === 1 /* OriginType.WriteVariableOrigin */) {
@@ -253,16 +498,24 @@ class InputClassifier {
253
498
  acc.pushUnknown();
254
499
  return;
255
500
  }
256
- // if the referenced definition is linked via defined-by-on-call to another
257
- // id (e.g., a parameter linked to a caller argument), mark it as a Scope origin
258
- if (this.isDefinedByOnCall(v.id)) {
259
- acc.types.push(InputType.Scope);
501
+ // if the referenced definition is linked via defined-by-on-call to another id (e.g., a parameter linked to a
502
+ // caller argument), follow it into the caller; only if that leads nowhere is it an opaque Scope origin
503
+ const onCall = this.definedByOnCallTargets(v.id);
504
+ if (onCall.length > 0) {
505
+ const callers = onCall.map(t => this.classifyInFullGraph(t))
506
+ .filter(assert_1.isNotUndefined)
507
+ .filter(c => !c.types.includes(input_types_1.InputType.Unknown));
508
+ if (callers.length > 0) {
509
+ callers.forEach(c => acc.merge(c));
510
+ return;
511
+ }
512
+ acc.types.push(input_types_1.InputType.Scope);
260
513
  acc.values.push(undefined);
261
514
  acc.allPure = false;
262
515
  }
263
516
  // if this is a variable definition that is a parameter, classify as Parameter
264
517
  if (v.tag === vertex_1.VertexType.VariableDefinition && this.dfg.idMap?.get(v.id)?.info.role === "param-n" /* RoleInParent.ParameterName */) {
265
- acc.types.push(InputType.Parameter);
518
+ acc.types.push(this.matchWholeLinkedObject(v.id)?.type ?? input_types_1.InputType.Parameter);
266
519
  acc.values.push(undefined);
267
520
  return;
268
521
  }
@@ -280,12 +533,13 @@ class InputClassifier {
280
533
  classifyVariableDefinition(vtx) {
281
534
  // parameter definitions are classified as Parameter
282
535
  if (this.dfg.idMap?.get(vtx.id)?.info.role === "param-n" /* RoleInParent.ParameterName */) {
283
- return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [InputType.Parameter], trace: InputTraceType.Unknown });
536
+ const types = [this.matchWholeLinkedObject(vtx.id)?.type ?? input_types_1.InputType.Parameter];
537
+ return this.classifyCdsAndReturn(vtx, { id: vtx.id, types, trace: input_types_1.InputTraceType.Unknown });
284
538
  }
285
539
  const sources = vtx.source;
286
540
  if (sources === undefined || sources.length === 0) {
287
541
  // fallback to unknown if we cannot find the value
288
- return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [InputType.Unknown], trace: InputTraceType.Unknown });
542
+ return this.classifyCdsAndReturn(vtx, { id: vtx.id, types: [input_types_1.InputType.Unknown], trace: input_types_1.InputTraceType.Unknown });
289
543
  }
290
544
  const acc = new ClassificationAccumulator();
291
545
  for (const tid of sources) {
@@ -320,86 +574,65 @@ class InputClassifier {
320
574
  return src;
321
575
  }
322
576
  }
323
- /**
324
- * Lattice flattening until we have a taint engine :)
325
- * Please note that the classifier considers this basis with a set-lift,
326
- * joining differing lattice elements.
327
- *
328
- *```
329
- * [ Unknown ]
330
- * |
331
- * [Param] [File] [Net] [User], ...
332
- * | | | |
333
- * | [TempFile] | |
334
- * +---------+------+------+- ...
335
- * |
336
- * [ DerivedConstant ]
337
- * |
338
- * [ Constant ]
339
- *```
340
- *
341
- */
342
- var InputType;
343
- (function (InputType) {
344
- InputType["Parameter"] = "param";
345
- InputType["File"] = "file";
346
- /** Temporary file paths produced by tempfile()/tempdir() and equivalents; a sub-type of {@link File} */
347
- InputType["TempFile"] = "tempfile";
348
- InputType["Network"] = "net";
349
- InputType["Random"] = "rand";
350
- /** Calls to system/system2 and similar */
351
- InputType["System"] = "system";
352
- /** Calls to .C / Fortran interfaces (foreign function interfaces) */
353
- InputType["Ffi"] = "ffi";
354
- /** Language objects (quote/substitute/etc.) */
355
- InputType["Lang"] = "lang";
356
- /** Global options / option accessors (options, getOption) */
357
- InputType["Options"] = "options";
358
- /** Interactive user input (file choosers, prompts, dialogs, menu selections) */
359
- InputType["User"] = "user";
360
- InputType["Constant"] = "const";
361
- /** Read from environment/call scope */
362
- InputType["Scope"] = "scope";
363
- /** Pure calculations from constants that lead to a constant */
364
- InputType["DerivedConstant"] = "dconst";
365
- InputType["Unknown"] = "unknown";
366
- })(InputType || (exports.InputType = InputType = {}));
367
- var InputTraceType;
368
- (function (InputTraceType) {
369
- /** Derived only from aliasing */
370
- InputTraceType["Alias"] = "alias";
371
- /** Derived from pure function chains */
372
- InputTraceType["Pure"] = "pure";
373
- /** Derived from known but not necessarily all pure function chains */
374
- InputTraceType["Known"] = "known";
375
- /** Not fully known origin */
376
- InputTraceType["Unknown"] = "unknown";
377
- })(InputTraceType || (exports.InputTraceType = InputTraceType = {}));
378
- function matchesList(fn, list) {
379
- if (list === undefined || list.length === 0) {
380
- return false;
381
- }
382
- for (const id of list) {
383
- if (fn.id === id || (identifier_1.Identifier.is(id) && (identifier_1.Identifier.matches(id, fn.name) || (identifier_1.Identifier.getNamespace(fn.name) === undefined && identifier_1.Identifier.matches(fn.name, id))))) {
384
- return true;
577
+ /** the function definitions the given node is nested in, innermost first */
578
+ function* enclosingFunctions(node, idMap) {
579
+ for (const parent of model_1.RNode.iterateParents(node, idMap)) {
580
+ if (r_function_definition_1.RFunctionDefinition.is(parent)) {
581
+ yield parent;
582
+ }
583
+ }
584
+ }
585
+ /** whether the given occurrence of `obj` is bound by a function matching {@link LinkedInputObject.withParams} */
586
+ function isBoundAsLinkedObject(node, obj, idMap) {
587
+ if (!obj.withParams?.length) {
588
+ return true;
589
+ }
590
+ for (const fn of enclosingFunctions(node, idMap)) {
591
+ const params = new Set(fn.parameters.map(p => p.name.content));
592
+ if (params.has(obj.name)) {
593
+ return obj.withParams.every(p => params.has(p));
385
594
  }
386
595
  }
387
596
  return false;
388
597
  }
598
+ function declarationKey(object, field) {
599
+ return `${object}\u0000${field}`;
600
+ }
601
+ /** whether reading `field` of the given object is an input; an object restricted to {@link LinkedInputObject.fields} is none as a whole */
602
+ function fieldIsInput(obj, field) {
603
+ return obj.fields === undefined || (field !== undefined && obj.fields.includes(field));
604
+ }
605
+ /**
606
+ * Whether a call by the name `called` means `id`. A `pkg::fn` call has to match exactly, while a bare call only
607
+ * means a namespaced entry if that package is attached - just like in R, where the search path decides.
608
+ * With `packages` left out (no package information at all) any bare call may mean it.
609
+ */
610
+ function callMeans(called, id, packages) {
611
+ if (identifier_1.Identifier.matches(id, called)) {
612
+ return true;
613
+ }
614
+ const namespace = identifier_1.Identifier.getNamespace(id);
615
+ return identifier_1.Identifier.getNamespace(called) === undefined && identifier_1.Identifier.matches(called, id)
616
+ && (namespace === undefined || packages === undefined || packages.has(namespace));
617
+ }
618
+ function matchesList(fn, list, packages) {
619
+ return list?.some(id => fn.id === id || (identifier_1.Identifier.is(id) && callMeans(fn.name, id, packages))) ?? false;
620
+ }
389
621
  /**
390
622
  * Takes the given id which is expected to either be:
391
623
  * - 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)
392
624
  * - anything else - in that case the node itself is considered as an "input" - please note that in these scenarios the *return* value will only contain one mapping - that for the id you passed in.
393
625
  *
394
626
  * This method traces the dependencies in the dataflow graph using the specification of functions passed in.
395
- * For the scope escape analysis, pass on the full, non-reduced DFG as `fullDfg`.
627
+ * For the scope escape analysis, pass on the full, non-reduced DFG as `fullDfg`, and the packages attached in the
628
+ * program as `packages` so that bare calls only match the entries of packages that are actually in scope.
396
629
  */
397
- function classifyInput(id, dfg, config, fullDfg) {
630
+ function classifyInput(id, dfg, config, fullDfg, packages) {
398
631
  const vtx = dfg.getVertex(id);
399
632
  if (!vtx) {
400
633
  return [];
401
634
  }
402
- const c = new InputClassifier(dfg, config, fullDfg);
635
+ const c = new InputClassifier(dfg, config, fullDfg, packages);
403
636
  if (vtx.tag === vertex_1.VertexType.FunctionCall) {
404
637
  const ret = [];
405
638
  const args = vtx.args;
@@ -12,7 +12,7 @@ function collectDependencyStats(declared, deps, basePackages) {
12
12
  const imports = declared.imports ?? [];
13
13
  const dependsAll = declared.depends ?? [];
14
14
  const rEntry = dependsAll.find(d => d.name === 'R');
15
- const rVersion = rEntry?.derivedVersion?.raw;
15
+ const rVersion = rEntry?.derivedRange?.raw;
16
16
  const depends = dependsAll.filter(d => d.name !== 'R');
17
17
  const suggests = declared.suggests ?? [];
18
18
  const linkingTo = declared.linkingTo ?? [];
@@ -6,6 +6,12 @@ import type { CommandCompletions } from '../../../cli/repl/core';
6
6
  export declare function cranPageUrl(pkg: string): string;
7
7
  /** deep-link a definition into the CRAN mirror at the package's version tag (falling back to `HEAD`) */
8
8
  export declare function cranMirrorSourceUrl(pkg: string, version: string | undefined, file: string, line?: number): string;
9
+ /**
10
+ * The mirror ref holding an R version. The mirror carries no tags, only a `R-<major>-<minor>-branch` per release
11
+ * series, so a link is exact to the minor release and points at its latest patch; `trunk` stands in when the version
12
+ * is unknown.
13
+ */
14
+ export declare function rSourceRef(version: string | undefined): string;
9
15
  /** best-effort rdrr.io documentation link: `/r/<pkg>/<fn>` for base R, `/cran/<pkg>/man/<fn>` for CRAN */
10
16
  export declare function rdrrDocUrl(pkg: string, fn: string, opts: {
11
17
  base: boolean;
@@ -13,7 +19,7 @@ export declare function rdrrDocUrl(pkg: string, fn: string, opts: {
13
19
  }): string | undefined;
14
20
  /**
15
21
  * The detailed view of a single function within a package: its signature (parameters, forced/optional,
16
- * defaults), properties, definition location, call graph, and -- for a CRAN package -- a deep link into the
22
+ * defaults), properties, definition location, call graph, and for a CRAN package a deep link into the
17
23
  * read-only CRAN GitHub mirror. `version` defaults to the source's latest; `undefined` when the source does
18
24
  * not carry that function.
19
25
  */