@eagleoutice/flowr 2.13.3 → 2.13.4

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 (67) hide show
  1. package/README.md +11 -11
  2. package/abstract-interpretation/absint-visitor.js +2 -2
  3. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  4. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +1 -1
  5. package/abstract-interpretation/unsupported-functions.js +1 -1
  6. package/control-flow/cfg-dead-code.js +72 -11
  7. package/control-flow/extract-cfg.js +85 -8
  8. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  9. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  10. package/dataflow/environments/built-in-proc-name.js +4 -0
  11. package/dataflow/environments/built-in.d.ts +5 -1
  12. package/dataflow/environments/built-in.js +5 -1
  13. package/dataflow/environments/default-builtin-config.d.ts +59 -4
  14. package/dataflow/environments/default-builtin-config.js +23 -11
  15. package/dataflow/environments/identifier.d.ts +1 -0
  16. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
  17. package/dataflow/eval/resolve/alias-tracking.js +8 -1
  18. package/dataflow/eval/resolve/resolve.d.ts +14 -0
  19. package/dataflow/eval/resolve/resolve.js +47 -0
  20. package/dataflow/fn/higher-order-function.js +3 -3
  21. package/dataflow/fn/recursive-function.js +1 -1
  22. package/dataflow/graph/df-helper.js +1 -1
  23. package/dataflow/graph/vertex.d.ts +32 -25
  24. package/dataflow/graph/vertex.js +40 -36
  25. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  27. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  28. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  29. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  30. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  31. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  32. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +29 -0
  34. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
  35. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  36. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  37. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
  38. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  40. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  41. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
  42. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
  44. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  45. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  46. package/linter/rules/absolute-path.js +1 -1
  47. package/linter/rules/function-finder-util.js +1 -1
  48. package/linter/rules/no-leaked-credentials.js +1 -1
  49. package/linter/rules/undefined-symbol.js +1 -1
  50. package/linter/rules/unused-definition.js +15 -10
  51. package/linter/rules/useless-loop.js +1 -1
  52. package/package.json +1 -1
  53. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  54. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  55. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  56. package/queries/catalog/dependencies-query/function-info/write-functions.js +23 -24
  57. package/queries/catalog/input-sources-query/input-source-functions.d.ts +2 -1
  58. package/queries/catalog/input-sources-query/input-source-functions.js +14 -20
  59. package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
  60. package/queries/catalog/input-sources-query/input-sources-query-format.js +2 -1
  61. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
  62. package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
  63. package/r-bridge/data/data.d.ts +2 -2
  64. package/r-bridge/data/data.js +2 -2
  65. package/reconstruct/inline/source-inline-map.js +1 -1
  66. package/util/mermaid/dfg.js +1 -1
  67. package/util/version.js +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TempFileFunctions = exports.UserFunctions = exports.OptionsFunctions = exports.LangFunctions = exports.FfiFunctions = exports.SystemFunctions = exports.PureFunctions = exports.LinkedInputEntryPoints = exports.LinkedInputObjects = void 0;
3
+ exports.TempFileFunctions = exports.UserFunctions = exports.OptionsFunctions = exports.LangFunctions = exports.FfiFunctions = exports.SystemFunctions = exports.PureFunctions = exports.LinkedInputEntryPoints = exports.NarrowingFunctions = exports.LinkedInputObjects = void 0;
4
4
  const identifier_1 = require("../../../dataflow/environments/identifier");
5
5
  const simple_input_classifier_1 = require("./simple-input-classifier");
6
6
  /** shiny's ui-side control widgets, all taking the id of the `input` entry they feed as their first argument */
@@ -25,6 +25,18 @@ exports.LinkedInputObjects = [
25
25
  /* of the session only what the browser sends is user input, `userData` and `token` are the app's own */
26
26
  { name: 'session', type: simple_input_classifier_1.InputType.User, withParams: ['input', 'output'], requires: 'shiny', fields: ['clientData', 'request'] }
27
27
  ];
28
+ exports.NarrowingFunctions = [
29
+ /* bounded by an argument: the result is one element of that argument */
30
+ { call: identifier_1.Identifier.make('match.arg', 'base'), argName: 'choices', argIdx: 1 },
31
+ /* bounded content-independent results (counts, indices, logicals): the subject's taint cannot flow through */
32
+ ...[
33
+ 'nchar', 'length', 'lengths', 'nrow', 'ncol', 'NROW', 'NCOL',
34
+ 'which', 'which.max', 'which.min', 'match', 'pmatch', 'charmatch',
35
+ 'seq_along', 'seq_len',
36
+ 'is.na', 'is.null', 'is.numeric', 'is.character', 'is.logical', 'is.function', 'is.list', 'is.element',
37
+ 'nzchar', 'grepl', 'startsWith', 'endsWith'
38
+ ].map(name => ({ call: identifier_1.Identifier.make(name, 'base') }))
39
+ ];
28
40
  /** shiny binds `input`, `output`, and `session` positionally, so their names are up to whoever writes the server */
29
41
  const ShinyServerParams = ['input', undefined, 'session'];
30
42
  /**
@@ -51,22 +63,19 @@ exports.PureFunctions = [
51
63
  identifier_1.Identifier.make('substr', 'base'),
52
64
  identifier_1.Identifier.make('substring', 'base'),
53
65
  identifier_1.Identifier.make('strsplit', 'base'),
54
- identifier_1.Identifier.make('startsWith', 'base'),
55
- identifier_1.Identifier.make('endsWith', 'base'),
56
66
  identifier_1.Identifier.make('strrep', 'base'),
57
67
  identifier_1.Identifier.make('chartr', 'base'),
58
68
  identifier_1.Identifier.make('strtoi', 'base'),
59
69
  identifier_1.Identifier.make('tolower', 'base'),
60
70
  identifier_1.Identifier.make('toupper', 'base'),
61
- identifier_1.Identifier.make('nchar', 'base'),
62
71
  identifier_1.Identifier.make('trimws', 'base'),
63
72
  identifier_1.Identifier.make('grep', 'base'),
64
- identifier_1.Identifier.make('grepl', 'base'),
65
73
  identifier_1.Identifier.make('sub', 'base'),
66
74
  identifier_1.Identifier.make('gsub', 'base'),
67
75
  identifier_1.Identifier.make('regexpr', 'base'),
68
76
  identifier_1.Identifier.make('gregexpr', 'base'),
69
77
  identifier_1.Identifier.make('regexec', 'base'),
78
+ // regmatches yields a substring of x, so x's taint propagates soundly - kept pure deliberately
70
79
  identifier_1.Identifier.make('regmatches', 'base'),
71
80
  identifier_1.Identifier.make('format', 'base'),
72
81
  identifier_1.Identifier.make('sprintf', 'base'),
@@ -123,18 +132,12 @@ exports.PureFunctions = [
123
132
  identifier_1.Identifier.make('diff', 'base'),
124
133
  identifier_1.Identifier.make('pmin', 'base'),
125
134
  identifier_1.Identifier.make('pmax', 'base'),
126
- identifier_1.Identifier.make('which', 'base'),
127
- identifier_1.Identifier.make('which.min', 'base'),
128
- identifier_1.Identifier.make('which.max', 'base'),
129
- identifier_1.Identifier.make('match', 'base'),
130
135
  identifier_1.Identifier.make('order', 'base'),
131
136
  identifier_1.Identifier.make('sort', 'base'),
132
137
  identifier_1.Identifier.make('unique', 'base'),
133
138
  identifier_1.Identifier.make('duplicated', 'base'),
134
139
  identifier_1.Identifier.make('seq', 'base'),
135
140
  identifier_1.Identifier.make('rep', 'base'),
136
- identifier_1.Identifier.make('seq_len', 'base'),
137
- identifier_1.Identifier.make('seq_along', 'base'),
138
141
  identifier_1.Identifier.make('rep.int', 'base'),
139
142
  /* base - data structures */
140
143
  identifier_1.Identifier.make('c', 'base'),
@@ -156,10 +159,7 @@ exports.PureFunctions = [
156
159
  identifier_1.Identifier.make('prop.table', 'base'),
157
160
  identifier_1.Identifier.make('rownames', 'base'),
158
161
  identifier_1.Identifier.make('colnames', 'base'),
159
- identifier_1.Identifier.make('length', 'base'),
160
162
  identifier_1.Identifier.make('dim', 'base'),
161
- identifier_1.Identifier.make('nrow', 'base'),
162
- identifier_1.Identifier.make('ncol', 'base'),
163
163
  identifier_1.Identifier.make('colSums', 'base'),
164
164
  identifier_1.Identifier.make('rowSums', 'base'),
165
165
  identifier_1.Identifier.make('colMeans', 'base'),
@@ -207,15 +207,10 @@ exports.PureFunctions = [
207
207
  identifier_1.Identifier.make('raw', 'base'),
208
208
  identifier_1.Identifier.make('complex', 'base'),
209
209
  /* base - type predicates */
210
- identifier_1.Identifier.make('is.na', 'base'),
211
- identifier_1.Identifier.make('is.null', 'base'),
212
- identifier_1.Identifier.make('is.numeric', 'base'),
213
- identifier_1.Identifier.make('is.character', 'base'),
214
210
  identifier_1.Identifier.make('is.finite', 'base'),
215
211
  identifier_1.Identifier.make('is.infinite', 'base'),
216
212
  identifier_1.Identifier.make('is.nan', 'base'),
217
213
  identifier_1.Identifier.make('is.factor', 'base'),
218
- identifier_1.Identifier.make('is.logical', 'base'),
219
214
  identifier_1.Identifier.make('is.vector', 'base'),
220
215
  identifier_1.Identifier.make('is.matrix', 'base'),
221
216
  identifier_1.Identifier.make('is.data.frame', 'base'),
@@ -227,7 +222,6 @@ exports.PureFunctions = [
227
222
  identifier_1.Identifier.make('return', 'base'),
228
223
  identifier_1.Identifier.make('force', 'base'),
229
224
  identifier_1.Identifier.make('missing', 'base'),
230
- identifier_1.Identifier.make('match.arg', 'base'),
231
225
  identifier_1.Identifier.make('print', 'base'),
232
226
  identifier_1.Identifier.make('cat', 'base'),
233
227
  identifier_1.Identifier.make('message', 'base'),
@@ -69,16 +69,21 @@ function addAll(base, extra) {
69
69
  }
70
70
  return result;
71
71
  }
72
+ /** Config fields that hold structured values (not function searches) and are carried over verbatim. */
73
+ const StructuredConfigKeys = ['linkedObjects', 'linkedEntryPoints', 'narrowing'];
74
+ function isStructuredConfigKey(key) {
75
+ return StructuredConfigKeys.includes(key);
76
+ }
72
77
  async function resolveSearches(analyzer, config) {
78
+ /* structured (non-search) fields are carried over as-is; everything else is a resolvable function search */
73
79
  const result = {};
74
- if (config.linkedObjects !== undefined) {
75
- result.linkedObjects = config.linkedObjects;
76
- }
77
- if (config.linkedEntryPoints !== undefined) {
78
- result.linkedEntryPoints = config.linkedEntryPoints;
80
+ for (const key of StructuredConfigKeys) {
81
+ if (config[key] !== undefined) {
82
+ result[key] = config[key];
83
+ }
79
84
  }
80
85
  for (const [key, value] of record_1.Record.entries(config)) {
81
- if (key === 'linkedObjects' || key === 'linkedEntryPoints') {
86
+ if (isStructuredConfigKey(key)) {
82
87
  continue;
83
88
  }
84
89
  else if (value === undefined || Array.isArray(value)) {
@@ -28,7 +28,8 @@ exports.DefaultInputClassifierConfig = {
28
28
  [simple_input_classifier_1.InputType.Options]: input_source_functions_1.OptionsFunctions,
29
29
  [simple_input_classifier_1.InputType.User]: input_source_functions_1.UserFunctions,
30
30
  linkedObjects: input_source_functions_1.LinkedInputObjects,
31
- linkedEntryPoints: input_source_functions_1.LinkedInputEntryPoints
31
+ linkedEntryPoints: input_source_functions_1.LinkedInputEntryPoints,
32
+ narrowing: input_source_functions_1.NarrowingFunctions
32
33
  };
33
34
  function inputSourcesQueryLineParser(output, line, _config) {
34
35
  const criterion = (0, slice_query_parser_1.sliceCriteriaParser)(line[0]);
@@ -1,4 +1,4 @@
1
- import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
1
+ import { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
2
2
  import { InputTraceType, InputType } from './input-types';
3
3
  export { InputTraceType, InputType } from './input-types';
4
4
  import type { DataflowGraph } from '../../../dataflow/graph/graph';
@@ -50,6 +50,14 @@ export interface LinkedInputEntryPoint {
50
50
  /** which {@link LinkedInputObject} the framework binds to each parameter, by position; `undefined` leaves one alone */
51
51
  readonly params: readonly (string | undefined)[];
52
52
  }
53
+ /** A function whose result is bounded by one argument (e.g. `match.arg` by its `choices`), classified by that argument alone. */
54
+ export interface NarrowingFunction {
55
+ readonly call: Identifier;
56
+ /** the name of the bounding argument; omit (with `argIdx`) for a result that is always a bounded, content-independent value */
57
+ readonly argName?: string;
58
+ /** the index of the bounding argument; omit (with `argName`) for an always-`DerivedConstant` result */
59
+ readonly argIdx?: number;
60
+ }
53
61
  /**
54
62
  * Scalar R constant values representable in TypeScript.
55
63
  * `null` corresponds to R's `NULL`.
@@ -103,6 +111,11 @@ export interface InputClassifierConfig<Functions extends InputClassifierFunction
103
111
  * @see {@link LinkedInputEntryPoint}
104
112
  */
105
113
  linkedEntryPoints?: readonly LinkedInputEntryPoint[];
114
+ /**
115
+ * Functions whose result is bounded by one of their arguments (classified by that argument alone).
116
+ * @see {@link NarrowingFunction}
117
+ */
118
+ narrowing?: readonly NarrowingFunction[];
106
119
  }
107
120
  /**
108
121
  * Takes the given id which is expected to either be:
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InputType = exports.InputTraceType = void 0;
4
4
  exports.classifyInput = classifyInput;
5
+ const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id");
5
6
  const input_types_1 = require("./input-types");
6
7
  var input_types_2 = require("./input-types");
7
8
  Object.defineProperty(exports, "InputTraceType", { enumerable: true, get: function () { return input_types_2.InputTraceType; } });
@@ -373,6 +374,29 @@ class InputClassifier {
373
374
  }
374
375
  }
375
376
  }
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))) {
378
+ // 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
+ }
384
+ }
385
+ // a narrowing function returns a bounded value: either one of a specific argument's values (e.g. `match.arg`
386
+ // -> its `choices`), or - with no bounding argument - a content-independent value like a count/index/logical
387
+ for (const narrow of this.config.narrowing ?? []) {
388
+ if (!this.matches(call, [narrow.call])) {
389
+ continue;
390
+ }
391
+ 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 }));
393
+ }
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 });
398
+ }
399
+ }
376
400
  if (!this.matches(call, this.config.pure)) {
377
401
  const types = [];
378
402
  for (const type of record_1.Record.values(input_types_1.InputType)) {
@@ -637,8 +637,8 @@ export declare const flowrCapabilities: {
637
637
  readonly name: string;
638
638
  readonly href: "https://adv-r.hadley.nz/r6.html";
639
639
  }];
640
- readonly supported: "not";
641
- readonly description: "_Handle R6 classes and methods as one unit. Including Dispatch and Inheritance, as well as its Reference Semantics, Access Control, Finalizers, and Introspection._ We do not support typing currently and do not handle objects of these classes \"as units.\"";
640
+ readonly supported: "partially";
641
+ readonly description: "_Handle R6 classes and methods as one unit. We do not support typing, inheritance, private/active bindings, or handling objects fully \"as units.\"";
642
642
  }, {
643
643
  readonly name: "R7/S7";
644
644
  readonly id: "oop-r7-s7";
@@ -799,8 +799,8 @@ ${await (0, doc_dfg_1.printDfGraphForCode)(parser, code, { simplified: true })}
799
799
  url: [
800
800
  { name: AdvancedR('R6'), href: 'https://adv-r.hadley.nz/r6.html' }
801
801
  ],
802
- supported: 'not',
803
- description: '_Handle R6 classes and methods as one unit. Including Dispatch and Inheritance, as well as its Reference Semantics, Access Control, Finalizers, and Introspection._ We do not support typing currently and do not handle objects of these classes "as units."'
802
+ supported: 'partially',
803
+ description: '_Handle R6 classes and methods as one unit. We do not support typing, inheritance, private/active bindings, or handling objects fully "as units."'
804
804
  },
805
805
  {
806
806
  name: 'R7/S7',
@@ -50,7 +50,7 @@ exports.SourceInlineMap = {
50
50
  const sourceArgs = new Map();
51
51
  const firstVertexByCd = new Map();
52
52
  for (const [id, vertex] of graph.vertices(true)) {
53
- if ((0, vertex_1.isFunctionCallVertex)(vertex) && Array.isArray(vertex.origin) && vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Source)) {
53
+ if (vertex_1.FunctionCallVertex.is(vertex) && Array.isArray(vertex.origin) && vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Source)) {
54
54
  sourceArgs.set(id, sourceArg(ast, id));
55
55
  }
56
56
  const cds = vertex.cds;
@@ -183,7 +183,7 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark, includeOnlyIds) {
183
183
  const node = mermaid.rootGraph.idMap?.get(info.id);
184
184
  const lexeme = node?.lexeme ?? (node?.type === type_1.RType.ExpressionList ? node?.grouping?.[0]?.lexeme : '') ?? '??';
185
185
  let display = lexeme;
186
- if (fCall && (0, vertex_1.isFunctionCallVertex)(info)) {
186
+ if (fCall && vertex_1.FunctionCallVertex.is(info)) {
187
187
  const q = identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(mermaid.rootGraph, origId), info.name, mermaid.qualifyBaseR !== false);
188
188
  const qs = q !== undefined ? identifier_1.Identifier.toString(q) : undefined;
189
189
  if (qs !== undefined && qs !== lexeme) {
package/util/version.js CHANGED
@@ -42,7 +42,7 @@ const assert_1 = require("./assert");
42
42
  const sigdb_download_1 = require("../project/sigdb/sigdb-download");
43
43
  const doc_files_1 = require("../documentation/doc-util/doc-files");
44
44
  // this is automatically replaced with the current version by release-it
45
- const version = '2.13.3';
45
+ const version = '2.13.4';
46
46
  // this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
47
47
  const versionDate = '2026-07-15T07:13:44Z';
48
48
  /**