@eagleoutice/flowr 2.13.5 → 2.13.7

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 (28) hide show
  1. package/README.md +28 -28
  2. package/config.d.ts +1 -1
  3. package/config.js +1 -0
  4. package/dataflow/environments/built-in-props.d.ts +1 -1
  5. package/dataflow/environments/built-in-props.js +1 -1
  6. package/dataflow/environments/default-builtin-config.d.ts +22 -2
  7. package/dataflow/environments/default-builtin-config.js +64 -3
  8. package/dataflow/eval/resolve/alias-tracking.d.ts +6 -5
  9. package/dataflow/eval/resolve/alias-tracking.js +41 -11
  10. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +1 -4
  11. package/documentation/wiki-core.js +34 -18
  12. package/linter/rules/seeded-randomness.js +1 -1
  13. package/linter/rules/unused-definition.js +29 -17
  14. package/package.json +2 -1
  15. package/project/context/classify-project-kind.js +1 -1
  16. package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -0
  17. package/project/context/flowr-analyzer-dependencies-context.js +28 -10
  18. package/project/context/flowr-analyzer-loading-order-context.d.ts +6 -0
  19. package/project/context/flowr-analyzer-loading-order-context.js +21 -0
  20. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +15 -0
  21. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +113 -16
  22. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin.js +2 -1
  23. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-included-files-plugin.d.ts +15 -0
  24. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-included-files-plugin.js +33 -0
  25. package/project/plugins/plugin-registry.d.ts +2 -1
  26. package/project/plugins/plugin-registry.js +2 -0
  27. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +1 -1
  28. package/util/version.js +1 -1
package/README.md CHANGED
@@ -43,7 +43,7 @@ It offers a wide variety of features, for example:
43
43
 
44
44
  ```shell
45
45
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
46
- flowR repl v2.13.4, R grammar v14 (tree-sitter engine)
46
+ flowR repl v2.13.6, R grammar v14 (tree-sitter engine)
47
47
  R> :query @linter "read.csv(\"/root/x.txt\")"
48
48
  ```
49
49
 
@@ -52,17 +52,17 @@ It offers a wide variety of features, for example:
52
52
 
53
53
 
54
54
  ```text
55
- Query: linter (17 ms)
55
+ Query: linter (10 ms)
56
56
  ╰ Deprecated Functions (deprecated-functions): no findings
57
57
  ╰ File Path Validity (file-path-validity):
58
58
  ╰ certain:
59
59
  ╰ Path `/root/x.txt` at 1.1-23
60
- ╰ Metadata: totalReads: 1, totalUnknown: 0, totalWritesBeforeAlways: 0, totalValid: 0, searchTimeMs: 2, processTimeMs: 3
60
+ ╰ Metadata: totalReads: 1, totalUnknown: 0, totalWritesBeforeAlways: 0, totalValid: 0, searchTimeMs: 0, processTimeMs: 1
61
61
  ╰ Seeded Randomness (seeded-randomness): no findings
62
62
  ╰ Absolute Paths (absolute-file-paths):
63
63
  ╰ certain:
64
64
  ╰ Path `/root/x.txt` at 1.1-23
65
- ╰ Metadata: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 1, processTimeMs: 0
65
+ ╰ Metadata: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 0, processTimeMs: 0
66
66
  ╰ Unused Definitions (unused-definitions): no findings
67
67
  ╰ Network Functions (network-functions): no findings
68
68
  ╰ Dataframe Access Validation (dataframe-access-validation): no findings
@@ -73,7 +73,7 @@ It offers a wide variety of features, for example:
73
73
  ╰ Roxygen Arguments (roxygen-arguments): no findings
74
74
  ╰ No Leaked Credentials (no-leaked-credentials): no findings
75
75
  ╰ Undefined Symbol (undefined-symbol): no findings
76
- All queries together required ≈17 ms (1ms accuracy, total 18 ms)
76
+ All queries together required ≈10 ms (1ms accuracy, total 10 ms)
77
77
  ```
78
78
 
79
79
 
@@ -95,17 +95,17 @@ It offers a wide variety of features, for example:
95
95
 
96
96
  _Results (prettified and summarized):_
97
97
 
98
- Query: **linter** (34 ms)\
98
+ Query: **linter** (14 ms)\
99
99
     ╰ **Deprecated Functions** (deprecated-functions): _no findings_\
100
100
     ╰ **File Path Validity** (file-path-validity):\
101
101
         ╰ certain:\
102
102
             ╰ Path `/root/x.txt` at 1.1-23\
103
-        ╰ _Metadata_: totalReads: 1, totalUnknown: 0, totalWritesBeforeAlways: 0, totalValid: 0, searchTimeMs: 2, processTimeMs: 1\
103
+        ╰ _Metadata_: totalReads: 1, totalUnknown: 0, totalWritesBeforeAlways: 0, totalValid: 0, searchTimeMs: 1, processTimeMs: 1\
104
104
     ╰ **Seeded Randomness** (seeded-randomness): _no findings_\
105
105
     ╰ **Absolute Paths** (absolute-file-paths):\
106
106
         ╰ certain:\
107
107
             ╰ Path `/root/x.txt` at 1.1-23\
108
-        ╰ _Metadata_: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 2, processTimeMs: 0\
108
+        ╰ _Metadata_: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 0, processTimeMs: 0\
109
109
     ╰ **Unused Definitions** (unused-definitions): _no findings_\
110
110
     ╰ **Network Functions** (network-functions): _no findings_\
111
111
     ╰ **Dataframe Access Validation** (dataframe-access-validation): _no findings_\
@@ -116,11 +116,11 @@ It offers a wide variety of features, for example:
116
116
     ╰ **Roxygen Arguments** (roxygen-arguments): _no findings_\
117
117
     ╰ **No Leaked Credentials** (no-leaked-credentials): _no findings_\
118
118
     ╰ **Undefined Symbol** (undefined-symbol): _no findings_\
119
- _All queries together required ≈34 ms (1ms accuracy, total 37 ms)_
119
+ _All queries together required ≈14 ms (1ms accuracy, total 15 ms)_
120
120
 
121
121
  <details> <summary style="color:gray">Show Detailed Results as Json</summary>
122
122
 
123
- The analysis required _36.6 ms_ (including parsing and normalization and the query) within the generation environment.
123
+ The analysis required _15.0 ms_ (including parsing and normalization and the query) within the generation environment.
124
124
 
125
125
  In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR.
126
126
  Please consult the [Interface](https://github.com/flowr-analysis/flowr/wiki/Interface) wiki page for more information on how to get those.
@@ -137,8 +137,8 @@ It offers a wide variety of features, for example:
137
137
  ".meta": {
138
138
  "totalCalls": 0,
139
139
  "totalFunctionDefinitions": 0,
140
- "searchTimeMs": 7,
141
- "processTimeMs": 6
140
+ "searchTimeMs": 4,
141
+ "processTimeMs": 3
142
142
  }
143
143
  },
144
144
  "file-path-validity": {
@@ -160,7 +160,7 @@ It offers a wide variety of features, for example:
160
160
  "totalUnknown": 0,
161
161
  "totalWritesBeforeAlways": 0,
162
162
  "totalValid": 0,
163
- "searchTimeMs": 2,
163
+ "searchTimeMs": 1,
164
164
  "processTimeMs": 1
165
165
  }
166
166
  },
@@ -172,8 +172,8 @@ It offers a wide variety of features, for example:
172
172
  "callsWithAssignmentProducers": 0,
173
173
  "callsWithNonConstantProducers": 0,
174
174
  "callsWithOtherBranchProducers": 0,
175
- "searchTimeMs": 2,
176
- "processTimeMs": 0
175
+ "searchTimeMs": 0,
176
+ "processTimeMs": 1
177
177
  }
178
178
  },
179
179
  "absolute-file-paths": {
@@ -192,7 +192,7 @@ It offers a wide variety of features, for example:
192
192
  ".meta": {
193
193
  "totalConsidered": 1,
194
194
  "totalUnknown": 0,
195
- "searchTimeMs": 2,
195
+ "searchTimeMs": 0,
196
196
  "processTimeMs": 0
197
197
  }
198
198
  },
@@ -209,7 +209,7 @@ It offers a wide variety of features, for example:
209
209
  ".meta": {
210
210
  "totalCalls": 0,
211
211
  "totalFunctionDefinitions": 0,
212
- "searchTimeMs": 2,
212
+ "searchTimeMs": 1,
213
213
  "processTimeMs": 0
214
214
  }
215
215
  },
@@ -220,7 +220,7 @@ It offers a wide variety of features, for example:
220
220
  "numAccesses": 0,
221
221
  "totalAccessed": 0,
222
222
  "searchTimeMs": 0,
223
- "processTimeMs": 4
223
+ "processTimeMs": 1
224
224
  }
225
225
  },
226
226
  "dead-code": {
@@ -241,7 +241,7 @@ It offers a wide variety of features, for example:
241
241
  "problematic-inputs": {
242
242
  "results": [],
243
243
  ".meta": {
244
- "searchTimeMs": 1,
244
+ "searchTimeMs": 0,
245
245
  "processTimeMs": 0
246
246
  }
247
247
  },
@@ -256,7 +256,7 @@ It offers a wide variety of features, for example:
256
256
  "roxygen-arguments": {
257
257
  "results": [],
258
258
  ".meta": {
259
- "searchTimeMs": 0,
259
+ "searchTimeMs": 1,
260
260
  "processTimeMs": 0
261
261
  }
262
262
  },
@@ -281,16 +281,16 @@ It offers a wide variety of features, for example:
281
281
  "subscript": 0
282
282
  },
283
283
  "searchTimeMs": 0,
284
- "processTimeMs": 3
284
+ "processTimeMs": 1
285
285
  }
286
286
  }
287
287
  },
288
288
  ".meta": {
289
- "timing": 34
289
+ "timing": 14
290
290
  }
291
291
  },
292
292
  ".meta": {
293
- "timing": 34
293
+ "timing": 14
294
294
  }
295
295
  }
296
296
  ```
@@ -354,7 +354,7 @@ It offers a wide variety of features, for example:
354
354
 
355
355
  ```shell
356
356
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
357
- flowR repl v2.13.4, R grammar v14 (tree-sitter engine)
357
+ flowR repl v2.13.6, R grammar v14 (tree-sitter engine)
358
358
  R> :query @static-slice (11@sum) file://test/testfiles/example.R
359
359
  ```
360
360
 
@@ -368,7 +368,7 @@ It offers a wide variety of features, for example:
368
368
  N <- 10
369
369
  for(i in 1:(N-1)) sum <- sum + i + w
370
370
  sum
371
- All queries together required ≈8 ms (1ms accuracy, total 8 ms)
371
+ All queries together required ≈5 ms (1ms accuracy, total 6 ms)
372
372
  ```
373
373
 
374
374
 
@@ -383,7 +383,7 @@ It offers a wide variety of features, for example:
383
383
  </details>
384
384
 
385
385
  * 🚀 **fast call-graph, data-, and control-flow graphs**\
386
- Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">106.3 ms</span></i> (as of Jul 27, 2026)](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark),
386
+ Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">100.6 ms</span></i> (as of Jul 31, 2026)](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark),
387
387
  _flowR_ can analyze the data- and control-flow of the average real-world R&nbsp;script. See the [benchmarks](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark) for more information,
388
388
  and consult the [wiki pages](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph) for more details on the [dataflow graphs](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph) as well as [call graphs](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph#perspectives-cg).
389
389
 
@@ -419,7 +419,7 @@ It offers a wide variety of features, for example:
419
419
 
420
420
  ```shell
421
421
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
422
- flowR repl v2.13.4, R grammar v14 (tree-sitter engine)
422
+ flowR repl v2.13.6, R grammar v14 (tree-sitter engine)
423
423
  R> :dataflow* test/testfiles/example.R
424
424
  ```
425
425
 
@@ -692,7 +692,7 @@ It offers a wide variety of features, for example:
692
692
  ```
693
693
 
694
694
 
695
- (The analysis required _3.7 ms_ (including parse and normalize, using the [tree-sitter](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment. No [signature database](https://github.com/flowr-analysis/flowr/wiki/Signature-Database) is mounted for these generated graphs, so `library()` calls attach no package exports; base-R names are still qualified via the generated base-package store (e.g. `acf` as `stats::acf`).)
695
+ (The analysis required _3.0 ms_ (including parse and normalize, using the [tree-sitter](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment. No [signature database](https://github.com/flowr-analysis/flowr/wiki/Signature-Database) is mounted for these generated graphs, so `library()` calls attach no package exports; base-R names are still qualified via the generated base-package store (e.g. `acf` as `stats::acf`).)
696
696
 
697
697
 
698
698
 
package/config.d.ts CHANGED
@@ -193,7 +193,7 @@ export interface FlowrConfig extends MergeableRecord {
193
193
  shinyEntryFiles?: string[];
194
194
  /** Regex source evidencing shiny usage in an entry file. */
195
195
  shinyUsagePattern?: string;
196
- /** File extensions marking a notebook (default `ipynb`, `rmd`, `qmd`, `rnw`). */
196
+ /** File extensions marking a notebook (default `ipynb`, `rmd`, `rmarkdown`, `qmd`, `rnw`). */
197
197
  notebookExtensions?: string[];
198
198
  };
199
199
  };
package/config.js CHANGED
@@ -109,6 +109,7 @@ exports.FlowrDefaultPlugins = [
109
109
  'loading-order:description',
110
110
  'loading-order:implicit-sources',
111
111
  'loading-order:rprofile',
112
+ 'loading-order:included-files',
112
113
  'meta:description',
113
114
  'meta:rproject',
114
115
  'meta:uvr',
@@ -47,7 +47,7 @@ export declare enum CallProp {
47
47
  Throws = 4,
48
48
  /** returns invisibly, so the result is not auto-printed */
49
49
  Invisible = 8,
50
- /** dispatches on the class of its first argument (S3, S4, or S7) */
50
+ /** dispatches on the class of an argument (S3, S4, or S7), a group generic like `+` on either operand */
51
51
  Generic = 16,
52
52
  /** a method that is reached by dispatch, like `print.foo` (see {@link SigDbInferable}) */
53
53
  Method = 32,
@@ -55,7 +55,7 @@ var CallProp;
55
55
  CallProp[CallProp["Throws"] = 4] = "Throws";
56
56
  /** returns invisibly, so the result is not auto-printed */
57
57
  CallProp[CallProp["Invisible"] = 8] = "Invisible";
58
- /** dispatches on the class of its first argument (S3, S4, or S7) */
58
+ /** dispatches on the class of an argument (S3, S4, or S7), a group generic like `+` on either operand */
59
59
  CallProp[CallProp["Generic"] = 16] = "Generic";
60
60
  /** a method that is reached by dispatch, like `print.foo` (see {@link SigDbInferable}) */
61
61
  CallProp[CallProp["Method"] = 32] = "Method";
@@ -43,9 +43,25 @@ export declare const PlotFunctionsWithAddParam: Set<string>;
43
43
  export declare const GraphicsPlotAddons: string[];
44
44
  export declare const GgPlotAddons: string[];
45
45
  /**
46
- * Contains the built-in definitions recognized by flowR
46
+ * R's group generics: a class claims every member of a group at once, with an `Ops.cls` (S3) or a
47
+ * `setMethod('Arith', ...)` (S4), so a call to any member may dispatch to a method named after the group.
48
+ * `Ops` is what S3 calls the union of the three S4 groups it splits into.
49
+ */
50
+ export declare const RGroupGenerics: {
51
+ readonly Arith: readonly ["+", "-", "*", "/", "^", "**", "%%", "%/%"];
52
+ readonly Compare: readonly ["==", "!=", "<", "<=", ">", ">="];
53
+ readonly Logic: readonly ["&", "|"];
54
+ readonly Ops: readonly ["+", "-", "*", "/", "^", "**", "%%", "%/%", "==", "!=", "<", "<=", ">", ">=", "&", "|", "!"];
55
+ readonly Math: readonly ["abs", "sign", "sqrt", "floor", "ceiling", "trunc", "exp", "expm1", "log", "log2", "log10", "log1p", "cos", "sin", "tan", "cosh", "sinh", "tanh", "acos", "asin", "atan", "acosh", "asinh", "atanh", "cumsum", "cumprod", "cummax", "cummin"];
56
+ readonly Math2: readonly ["round", "signif"];
57
+ readonly Summary: readonly ["any", "sum", "prod", "min", "max", "range"];
58
+ readonly Complex: readonly ["Re", "Im", "Mod", "Arg", "Conj"];
59
+ };
60
+ /**
61
+ * Contains the built-in definitions recognized by flowR, as they are written down: {@link DefaultBuiltinConfig}
62
+ * is what {@link markGenerics} makes of them, and a test checks that this is all it changes.
47
63
  */
48
- export declare const DefaultBuiltinConfig: [{
64
+ export declare const WrittenBuiltinDefinitions: [{
49
65
  readonly type: "constant";
50
66
  readonly names: Identifier[];
51
67
  readonly value: null;
@@ -2392,6 +2408,10 @@ export declare const DefaultBuiltinConfig: [{
2392
2408
  readonly props: CallProp.Scope;
2393
2409
  };
2394
2410
  }];
2411
+ /**
2412
+ * Contains the built-in definitions recognized by flowR
2413
+ */
2414
+ export declare const DefaultBuiltinConfig: import("./built-in-config").BuiltInDefinition<BuiltInProcName.Access | BuiltInProcName.Apply | BuiltInProcName.Assignment | BuiltInProcName.AssignmentLike | BuiltInProcName.DefineArgument | BuiltInProcName.Default | BuiltInProcName.DefaultReadAllArgs | BuiltInProcName.Eval | BuiltInProcName.ExpressionList | BuiltInProcName.ForLoop | BuiltInProcName.FunctionDefinition | BuiltInProcName.Get | BuiltInProcName.IfThenElse | BuiltInProcName.Library | BuiltInProcName.List | BuiltInProcName.Load | BuiltInProcName.Local | BuiltInProcName.NamespaceAccess | BuiltInProcName.Pipe | BuiltInProcName.PurrrFormula | BuiltInProcName.Quote | BuiltInProcName.Recall | BuiltInProcName.RegisterHook | BuiltInProcName.RepeatLoop | BuiltInProcName.Replacement | BuiltInProcName.Rm | BuiltInProcName.S3Dispatch | BuiltInProcName.S7NewGeneric | BuiltInProcName.S7Dispatch | BuiltInProcName.S7MakeConstructor | BuiltInProcName.Source | BuiltInProcName.SpecialBinOp | BuiltInProcName.StackEnv | BuiltInProcName.StopIfNot | BuiltInProcName.Try | BuiltInProcName.Attach | BuiltInProcName.NewEnv | BuiltInProcName.ClassGenerator | BuiltInProcName.Vector | BuiltInProcName.WhileLoop | BuiltInProcName.With>[];
2395
2415
  /**
2396
2416
  * Expensive and naive lookup of the default processor for a built-in function name
2397
2417
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultBuiltinConfig = exports.GgPlotAddons = exports.GraphicsPlotAddons = exports.PlotFunctionsWithAddParam = exports.GgPlotImplicitAddons = exports.TinyPlotAddons = exports.PlotCreate = exports.GraphicsPlotCreate = exports.TinyPlotCrate = exports.GgPlotCreate = exports.StackEnvBuiltins = exports.StackEnvKind = void 0;
3
+ exports.DefaultBuiltinConfig = exports.WrittenBuiltinDefinitions = exports.RGroupGenerics = exports.GgPlotAddons = exports.GraphicsPlotAddons = exports.PlotFunctionsWithAddParam = exports.GgPlotImplicitAddons = exports.TinyPlotAddons = exports.PlotCreate = exports.GraphicsPlotCreate = exports.TinyPlotCrate = exports.GgPlotCreate = exports.StackEnvBuiltins = exports.StackEnvKind = void 0;
4
4
  exports.getDefaultProcessor = getDefaultProcessor;
5
5
  const identify_link_to_last_call_relation_1 = require("../../queries/catalog/call-context-query/identify-link-to-last-call-relation");
6
6
  const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
@@ -13,6 +13,7 @@ const built_in_eval_name_1 = require("./built-in-eval-name");
13
13
  const known_call_handling_1 = require("../internal/process/functions/call/known-call-handling");
14
14
  const data_masking_functions_1 = require("./data-masking-functions");
15
15
  const built_in_props_1 = require("./built-in-props");
16
+ const r_base_packages_1 = require("../../util/r-base-packages");
16
17
  /** Which stack environment an env-returning/-transforming builtin denotes (see {@link StackEnvBuiltins}). */
17
18
  var StackEnvKind;
18
19
  (function (StackEnvKind) {
@@ -135,10 +136,66 @@ const LinkToLastPlot = {
135
136
  type: 'link-to-last-call',
136
137
  callName: toRegex(GraphicDeviceOpen.concat(exports.PlotCreate, PlotAddons, exports.GgPlotAddons, exports.TinyPlotAddons))
137
138
  };
139
+ const Arith = ['+', '-', '*', '/', '^', '**', '%%', '%/%'];
140
+ const Compare = ['==', '!=', '<', '<=', '>', '>='];
141
+ const Logic = ['&', '|'];
138
142
  /**
139
- * Contains the built-in definitions recognized by flowR
143
+ * R's group generics: a class claims every member of a group at once, with an `Ops.cls` (S3) or a
144
+ * `setMethod('Arith', ...)` (S4), so a call to any member may dispatch to a method named after the group.
145
+ * `Ops` is what S3 calls the union of the three S4 groups it splits into.
146
+ */
147
+ exports.RGroupGenerics = {
148
+ Arith, Compare, Logic,
149
+ Ops: [...Arith, ...Compare, ...Logic, '!'],
150
+ Math: ['abs', 'sign', 'sqrt', 'floor', 'ceiling', 'trunc', 'exp', 'expm1', 'log', 'log2', 'log10', 'log1p',
151
+ 'cos', 'sin', 'tan', 'cosh', 'sinh', 'tanh', 'acos', 'asin', 'atan', 'acosh', 'asinh', 'atanh',
152
+ 'cumsum', 'cumprod', 'cummax', 'cummin'],
153
+ Math2: ['round', 'signif'],
154
+ Summary: ['any', 'sum', 'prod', 'min', 'max', 'range'],
155
+ Complex: ['Re', 'Im', 'Mod', 'Arg', 'Conj']
156
+ };
157
+ /**
158
+ * Every R generic flowR states a built-in for: the {@link RGroupGenerics} members, the `.S3PrimitiveGenerics` and
159
+ * internal generics (which have no R body, so {@link fnInfoFromSignature} could never see them), and the
160
+ * `UseMethod` closures flowR models itself, as its own definition hides the one in the signature database.
161
+ * The `<-` forms are left out, one replacement definition covers many names.
162
+ * `npm run check:generic-labels` (part of `checkup`) compares this against a synced database.
140
163
  */
141
- exports.DefaultBuiltinConfig = [
164
+ const RGenerics = new Set([
165
+ ...Object.values(exports.RGroupGenerics).flat(), '%*%',
166
+ 'c', 'length', 'dim', 'dimnames', 'names', 'rep', 'seq.int', '[', '[[', '$', '@',
167
+ 'as.call', 'as.character', 'as.complex', 'as.double', 'as.environment', 'as.integer', 'as.logical',
168
+ 'as.numeric', 'as.raw', 'is.na', 'is.nan', 'is.finite', 'is.infinite', 'is.matrix', 'is.numeric',
169
+ 'aperm', 'as.array', 'as.data.frame', 'as.expression', 'as.list', 'as.matrix', 'cbind', 'rbind', 'diff',
170
+ 'duplicated', 'format', 'head', 'tail', 'mean', 'median', 'na.omit', 'print', 'quantile', 'rev', 'seq',
171
+ 'simulate', 'solve', 'sort', 'subset', 't', 'transform', 'unique', 'with', 'within',
172
+ 'plot', 'lines', 'points', 'text', 'image', 'contour', 'persp', 'hist', 'barplot', 'boxplot', 'density',
173
+ 'pairs', 'qqnorm', 'mosaicplot', 'spineplot', 'stripchart', 'sunflowerplot'
174
+ ]);
175
+ /** Label every {@link RGenerics} {@link CallProp.Generic}, splitting an entry that mixes them with names that do not dispatch (`&` does, `&&` does not). */
176
+ function markGenerics(definitions) {
177
+ return definitions.flatMap((def) => {
178
+ if (def.type !== 'function') {
179
+ return [def];
180
+ }
181
+ /* the attached base packages are the ones whose namespace layer a registered built-in hides, so their
182
+ * label is the only thing left stating the dispatch */
183
+ const dispatches = (name) => RGenerics.has(identifier_1.Identifier.getName(name))
184
+ && r_base_packages_1.AttachedBasePackages.includes(identifier_1.Identifier.getNamespace(name) ?? "base" /* PkgName.Base */);
185
+ const generics = def.names.filter(dispatches);
186
+ if (generics.length === 0) {
187
+ return [def];
188
+ }
189
+ const rest = def.names.filter(n => !dispatches(n));
190
+ const labeled = { ...def, names: generics, config: { ...def.config, props: (def.config?.props ?? 0) | built_in_props_1.CallProp.Generic } };
191
+ return rest.length === 0 ? [labeled] : [labeled, { ...def, names: rest }];
192
+ });
193
+ }
194
+ /**
195
+ * Contains the built-in definitions recognized by flowR, as they are written down: {@link DefaultBuiltinConfig}
196
+ * is what {@link markGenerics} makes of them, and a test checks that this is all it changes.
197
+ */
198
+ exports.WrittenBuiltinDefinitions = [
142
199
  { type: 'constant', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['NULL', 'NA', 'NA_integer_', 'NA_real_', 'NA_complex_', 'NA_character_']), value: null, assumePrimitive: true },
143
200
  { type: 'constant', names: [identifier_1.Identifier.from(['NaN', "base" /* PkgName.Base */])], value: NaN, assumePrimitive: true },
144
201
  { type: 'constant', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['.GlobalEnv', '.BaseNamespaceEnv', '.BaseEnv']), value: null, assumePrimitive: true },
@@ -1057,6 +1114,10 @@ exports.DefaultBuiltinConfig = [
1057
1114
  config: { readIndices: false, props: built_in_props_1.CallProp.Scope }
1058
1115
  },
1059
1116
  ];
1117
+ /**
1118
+ * Contains the built-in definitions recognized by flowR
1119
+ */
1120
+ exports.DefaultBuiltinConfig = markGenerics(exports.WrittenBuiltinDefinitions);
1060
1121
  /**
1061
1122
  * Expensive and naive lookup of the default processor for a built-in function name
1062
1123
  */
@@ -76,13 +76,14 @@ export declare function trackAliasInEnvironments(identifier: Identifier | undefi
76
76
  * Please use {@link resolveIdToValue}
77
77
  *
78
78
  * Tries to resolve the value of a node by traversing the dataflow graph
79
- * @param id - node to resolve
80
- * @param ctx - analysis context
81
- * @param graph - dataflow graph
82
- * @param idMap - idmap of dataflow graph
79
+ * @param id - node to resolve
80
+ * @param ctx - analysis context
81
+ * @param graph - dataflow graph
82
+ * @param idMap - idmap of dataflow graph
83
+ * @param blocked - the ids already being resolved, so a cyclic definition stops
83
84
  * @returns Value of node or Top/Bottom
84
85
  */
85
- export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext, idMap?: AstIdMap): ResolveResult;
86
+ export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext, idMap?: AstIdMap, blocked?: Set<NodeId>): ResolveResult;
86
87
  /**
87
88
  * Please use {@link resolveIdToValue}
88
89
  *
@@ -146,7 +146,7 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, ctx, res
146
146
  return trackAliasInEnvironments(identifier_1.Identifier.toString(node.content), environment, { idMap, resolve, ctx, graph, blocked });
147
147
  }
148
148
  else if (graph && resolve === config_1.VariableResolve.Alias) {
149
- return trackAliasesInGraph(node.info.id, graph, ctx, idMap);
149
+ return trackAliasesInGraph(node.info.id, graph, ctx, idMap, blocked);
150
150
  }
151
151
  }
152
152
  return r_value_1.Top;
@@ -207,7 +207,15 @@ function trackAliasInEnvironments(identifier, environment, { blocked, idMap, res
207
207
  for (const alias of def.value) {
208
208
  const definitionOfAlias = idMap?.get(alias);
209
209
  if (definitionOfAlias !== undefined) {
210
- const value = (0, resolve_1.resolveNode)({ resolve, node: definitionOfAlias, ctx, environment, graph, idMap, blocked });
210
+ /* the environment attempt below marks what it visited as blocked, so the retry starts from a copy */
211
+ const beforeAttempt = blocked === undefined ? undefined : new Set(blocked);
212
+ let value = (0, resolve_1.resolveNode)({ resolve, node: definitionOfAlias, ctx, environment, graph, idMap, blocked });
213
+ if ((0, r_value_1.isTop)(value) && graph?.unknownSideEffects.size === 0) {
214
+ /* `x <- x + 1`: the environment holds only the definition we are resolving, so its own operand
215
+ * finds nothing there, while the graph still knows which definition that operand reads. Only
216
+ * when nothing unknown happened, as then the environment is right to give up */
217
+ value = (0, resolve_1.resolveNode)({ resolve, node: definitionOfAlias, ctx, graph, idMap, blocked: beforeAttempt });
218
+ }
211
219
  if ((0, r_value_1.isTop)(value)) {
212
220
  return r_value_1.Top;
213
221
  }
@@ -258,17 +266,23 @@ function trackAliasInEnvironments(identifier, environment, { blocked, idMap, res
258
266
  function isNestedInLoop(node, ast) {
259
267
  return model_1.RNode.iterateParents(node, ast).some(model_1.RLoopConstructs.is);
260
268
  }
269
+ /** whether the node is (or sits in) a parameter's default, which any call site may override */
270
+ function isParameterDefault(node, idMap) {
271
+ return node !== undefined && (node.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */
272
+ || model_1.RNode.iterateParents(node, idMap).some(p => p.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */));
273
+ }
261
274
  /**
262
275
  * Please use {@link resolveIdToValue}
263
276
  *
264
277
  * Tries to resolve the value of a node by traversing the dataflow graph
265
- * @param id - node to resolve
266
- * @param ctx - analysis context
267
- * @param graph - dataflow graph
268
- * @param idMap - idmap of dataflow graph
278
+ * @param id - node to resolve
279
+ * @param ctx - analysis context
280
+ * @param graph - dataflow graph
281
+ * @param idMap - idmap of dataflow graph
282
+ * @param blocked - the ids already being resolved, so a cyclic definition stops
269
283
  * @returns Value of node or Top/Bottom
270
284
  */
271
- function trackAliasesInGraph(id, graph, ctx, idMap) {
285
+ function trackAliasesInGraph(id, graph, ctx, idMap, blocked) {
272
286
  if (!graph.get(id)) {
273
287
  return r_value_1.Bottom;
274
288
  }
@@ -280,6 +294,8 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
280
294
  queue.add(id, clean, cleanFingerprint, false);
281
295
  let forceTop = false;
282
296
  const resultIds = [];
297
+ /* what a call the walk ended in folds to, see below */
298
+ const folded = [];
283
299
  while (queue.nonEmpty()) {
284
300
  const { id, baseEnvironment } = queue.next();
285
301
  const vertex = graph.getVertex(id);
@@ -304,6 +320,11 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
304
320
  break;
305
321
  }
306
322
  const t = vertex.tag;
323
+ /* a replacement (`df[1] <- v`) defines its target from just a part of it, so what it is defined by is not
324
+ * the value of the target */
325
+ if (t === vertex_1.VertexType.VariableDefinition && idMap.get(id)?.info.role === "acc" /* RoleInParent.Accessed */) {
326
+ return r_value_1.Top;
327
+ }
307
328
  if (t === vertex_1.VertexType.Value || t === vertex_1.VertexType.FunctionDefinition) {
308
329
  resultIds.push(id);
309
330
  continue;
@@ -326,13 +347,22 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
326
347
  }
327
348
  }
328
349
  if (isFn && !foundRetuns) {
329
- return r_value_1.Top;
350
+ /* a call that hands back none of its arguments has no `Returns` edge to follow, yet the value solver may
351
+ * well know what it produces (`p <- file.path("data", "x.csv")`), so we fold it instead of giving up */
352
+ const node = idMap.get(id);
353
+ const values = isParameterDefault(node, idMap) ? undefined
354
+ : (0, general_1.valueSetGuard)(resolveIdToValue(node, { graph, idMap, ctx, resolve: config_1.VariableResolve.Alias, blocked }));
355
+ if (values === undefined || values.elements.some(r_value_1.isTop)) {
356
+ return r_value_1.Top;
357
+ }
358
+ folded.push(...values.elements);
359
+ continue;
330
360
  }
331
361
  }
332
- if (forceTop || resultIds.length === 0) {
362
+ if (forceTop || (resultIds.length === 0 && folded.length === 0)) {
333
363
  return r_value_1.Top;
334
364
  }
335
- const values = new Set();
365
+ const values = new Set(folded);
336
366
  for (const id of resultIds) {
337
367
  const vertex = graph.getVertex(id);
338
368
  if (vertex_1.ValueVertex.is(vertex) && vertex.value !== undefined) {
@@ -341,7 +371,7 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
341
371
  }
342
372
  const node = idMap.get(id);
343
373
  if (node !== undefined) {
344
- if (node.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */ || model_1.RNode.iterateParents(node, idMap).some(p => p.info.role === "param-v" /* RoleInParent.ParameterDefaultValue */)) {
374
+ if (isParameterDefault(node, idMap)) {
345
375
  return r_value_1.Top;
346
376
  }
347
377
  values.add((0, general_1.valueFromRNodeConstant)(node));
@@ -155,15 +155,12 @@ function processLibrary(name, args, rootId, data, config = {}) {
155
155
  origin: built_in_proc_name_1.BuiltInProcName.Library
156
156
  }).information;
157
157
  for (const p of packetName) {
158
- const dependency = data.ctx.deps.getDependency(p);
158
+ const dependency = data.ctx.deps.loadDependency(p);
159
159
  if (dependency) {
160
160
  linkLibrary(dependency, info, rootId, data, spec);
161
161
  }
162
162
  else {
163
163
  info.graph.markIdForUnknownSideEffects(rootId);
164
- // no database resolves the package, but the load is syntactically known: record it so an explicit
165
- // `p::fn` can still link back to this call. requireNamespace/loadNamespace are recorded too, since
166
- // they equally make `p::fn` valid.
167
164
  if (info.environment.level >= 0) {
168
165
  info.environment = recordUnresolvedLibraryLoad(info.environment, p, rootId, spec.pos, data.cds);
169
166
  }
@@ -110,11 +110,8 @@ function propNames(mask) {
110
110
  return Object.entries(built_in_props_1.CallProp).filter(([, b]) => typeof b === 'number' && (b & mask) !== 0)
111
111
  .map(([n]) => `\`${n}\``).join(', ');
112
112
  }
113
- /**
114
- * A table per property enum, taken straight from the configuration: what each bit means (its own doc comment),
115
- * how many built-ins carry it, and which of them the signature database can state on its own.
116
- */
117
- function builtInPropsTables(ctx) {
113
+ /** The "Labeling the Built-Ins" section of the Core page, with a table per enum taken from the configuration. */
114
+ function builtInLabelsSection(ctx) {
118
115
  const index = query_fn_props_1.BuiltInIndex.default();
119
116
  /* the doc comment of a bit is its explanation, flattened to fit a table cell; bits nothing carries are left out */
120
117
  const table = (type, of) => [
@@ -130,7 +127,34 @@ function builtInPropsTables(ctx) {
130
127
  return `| \`${name}\`${db} | ${of(bit)} | ${doc} |`;
131
128
  })
132
129
  ].join('\n');
133
- return `${(0, doc_structure_1.details)('What each call property means', `<sup>db</sup> marks the bits the ${ctx.linkPage('wiki/Signature Database', 'signature database')}
130
+ return `#### Labeling the Built-Ins
131
+
132
+ Besides the processor, an entry says what the function *is*, in two label vocabularies:
133
+
134
+ * ${ctx.link('CallProp')} labels the call as a whole (\`props\`): whether it is pure, whether it throws, whether it
135
+ touches the file system, whether it dispatches, and so on. \`print\` is \`Invisible | Generic | Prints\`; R's
136
+ primitive generics (\`+\`, \`sin\`, \`length\`, ...) are \`Pure | Generic\`, and as they have no R body, the store is
137
+ the only place that can say they dispatch.
138
+ * ${ctx.link('ArgProp')} labels each parameter (\`sig\`), in the order R declares them: which one carries the data,
139
+ which one only selects a behavior, which one names a file, which one is called as a function.
140
+
141
+ For several analyses the labels are all they know about a call: ${ctx.link(query_fn_props_1.BuiltInIndex.name)} turns them into the
142
+ questions callers ask over and over (\`with\`, \`without\`, \`params\`), which is how the
143
+ ${ctx.linkPage('wiki/Query API', 'input-sources query')} knows which functions bring in data of their own, and how
144
+ ${ctx.linkPage('wiki/Linter', 'linting rules')} like *seeded randomness* find every call drawing from the RNG without
145
+ naming a single one of them. Labeling a built-in therefore teaches all of them at once.
146
+
147
+ So \`lapply\` is pure on its own but runs what it is handed, and says which argument that is:
148
+
149
+ ${(0, doc_code_1.codeBlock)('ts', `{ type: 'function', names: Identifier.fromAll(PkgName.Base, ['lapply', 'sapply', 'vapply']),
150
+ processor: BuiltInProcName.Apply,
151
+ config: { indexOfFunction: 1, nameOfFunctionArgument: 'FUN', unquoteFunction: true,
152
+ props: CallProp.MayPure, sig: [['X', ArgProp.Value], ['FUN', ArgProp.Callee]] } }`)}
153
+
154
+ The two tables below are generated from the configuration itself, so they always list every label that exists,
155
+ what it means, and how many built-ins carry it.
156
+
157
+ ${(0, doc_structure_1.details)('What each call property means', `<sup>db</sup> marks the bits the ${ctx.linkPage('wiki/Signature Database', 'signature database')}
134
158
  states for any package function on its own (${ctx.link(query_fn_props_1.inferFnProps.name)} reads them off an entry and carries what a
135
159
  function calls over to the function calling it).
136
160
 
@@ -150,13 +174,6 @@ them, with \`...\` covering every position from where it appears. The count is h
150
174
  parameter in that role.
151
175
 
152
176
  ${table('ArgProp', bit => new Set(index.params(bit).map(p => p.call)).size)}`)}
153
-
154
- So \`lapply\` is pure on its own but runs what it is handed, and says which argument that is:
155
-
156
- ${(0, doc_code_1.codeBlock)('ts', `{ type: 'function', names: Identifier.fromAll(PkgName.Base, ['lapply', 'sapply', 'vapply']),
157
- processor: BuiltInProcName.Apply,
158
- config: { indexOfFunction: 1, nameOfFunctionArgument: 'FUN', unquoteFunction: true,
159
- props: CallProp.MayPure, sig: [['X', ArgProp.Value], ['FUN', ArgProp.Callee]] } }`)}
160
177
  `;
161
178
  }
162
179
  /**
@@ -200,6 +217,7 @@ See the ${ctx.linkPage('wiki/FAQ', 'FAQ')} (*How to get flowR to talk?*) for mor
200
217
  * [Parsing](#parsing)
201
218
  * [Normalization](#normalization)
202
219
  * [Dataflow Graph Generation](#dataflow-graph-generation)
220
+ * [Labeling the Built-Ins](#labeling-the-built-ins)
203
221
  * [Beyond the Dataflow Graph](#beyond-the-dataflow-graph)
204
222
  * [Static Backward Slicing](#static-backward-slicing)
205
223
  * [Gas (Resource Guard)](#gas-resource-guard)
@@ -482,12 +500,10 @@ by mapping function names to ${ctx.link('BuiltInProcessorMapper')} functions.
482
500
  There you can find functions like ${ctx.link(built_in_access_1.processAccess)} which handles the (subset) access to a variable,
483
501
  or ${ctx.link(built_in_for_loop_1.processForLoop)} which handles the primitive for loop construct (whenever it is not overwritten).
484
502
 
485
- Besides the processor, an entry states what the function does with ${ctx.link('BuiltInFnInfo')}: its ${ctx.link('CallProp')} bits
486
- say what the call as a whole does, its ${ctx.link('FnSig')} says what each argument is used for (in the order R declares them,
487
- with \`...\` covering every position from where it appears). Anything you add there is picked up by ${ctx.link(query_fn_props_1.BuiltInIndex.name)},
488
- which is how the ${ctx.linkPage('wiki/Query API', 'input-sources query')} learns which functions bring in data of their own.
503
+ Besides the processor, an entry states what the function does with ${ctx.link('BuiltInFnInfo')} -- see
504
+ [Labeling the Built-Ins](#labeling-the-built-ins) below for the labels it may carry.
489
505
 
490
- ${builtInPropsTables(ctx)}
506
+ ${builtInLabelsSection(ctx)}
491
507
 
492
508
  Just as an example, we want to have a look at the ${ctx.link(built_in_repeat_loop_1.processRepeatLoop)} function, as it is one of the simplest built-in processors
493
509
  we have:
@@ -158,7 +158,7 @@ exports.SEEDED_RANDOMNESS = {
158
158
  }
159
159
  };
160
160
  function getDefaultAssignments() {
161
- return default_builtin_config_1.DefaultBuiltinConfig.filter(b => b.type === 'function' && (b.processor === built_in_proc_name_1.BuiltInProcName.Assignment || b.processor === built_in_proc_name_1.BuiltInProcName.AssignmentLike));
161
+ return default_builtin_config_1.DefaultBuiltinConfig.filter((b) => b.type === 'function' && (b.processor === built_in_proc_name_1.BuiltInProcName.Assignment || b.processor === built_in_proc_name_1.BuiltInProcName.AssignmentLike));
162
162
  }
163
163
  function isConstantArgument(graph, call, argIndex, ctx) {
164
164
  const args = call.args.filter(arg => arg !== r_function_call_1.EmptyArgument && !arg.name).map(graph_1.FunctionArgument.getReference);