@eagleoutice/flowr 2.15.10 → 2.16.1

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 (213) hide show
  1. package/README.md +23 -26
  2. package/abstract-interpretation/data-frame/arguments.js +11 -7
  3. package/cli/flowr-main-options.d.ts +15 -0
  4. package/cli/flowr-main-options.js +18 -0
  5. package/cli/flowr.d.ts +18 -0
  6. package/cli/flowr.js +13 -2
  7. package/cli/repl/commands/repl-clipboard.js +2 -1
  8. package/cli/repl/commands/repl-commands.js +2 -0
  9. package/cli/repl/commands/repl-main.d.ts +5 -0
  10. package/cli/repl/commands/repl-signature.js +2 -0
  11. package/cli/repl/core.d.ts +7 -1
  12. package/cli/repl/core.js +17 -8
  13. package/cli/repl/execute.js +2 -0
  14. package/cli/repl/server/connection.js +2 -1
  15. package/cli/repl/server/net.d.ts +10 -0
  16. package/cli/repl/server/net.js +34 -1
  17. package/cli/slicer-app.js +2 -1
  18. package/config.d.ts +12 -2
  19. package/config.js +91 -14
  20. package/control-flow/happens-before.d.ts +5 -0
  21. package/control-flow/happens-before.js +48 -34
  22. package/control-flow/useless-loop.d.ts +1 -1
  23. package/control-flow/useless-loop.js +29 -42
  24. package/dataflow/environments/built-in-props.d.ts +9 -0
  25. package/dataflow/environments/built-in-props.js +25 -19
  26. package/dataflow/environments/built-in.d.ts +2 -2
  27. package/dataflow/environments/built-in.js +41 -77
  28. package/dataflow/environments/default-builtin-config.d.ts +181 -29
  29. package/dataflow/environments/default-builtin-config.js +38 -24
  30. package/dataflow/environments/environment.d.ts +6 -4
  31. package/dataflow/environments/environment.js +54 -121
  32. package/dataflow/environments/identifier.d.ts +4 -2
  33. package/dataflow/environments/identifier.js +23 -69
  34. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  35. package/dataflow/environments/reference-to-maybe.js +23 -51
  36. package/dataflow/environments/resolve-by-name.js +37 -76
  37. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  38. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  39. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  40. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  41. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  42. package/dataflow/eval/resolve/resolve.js +23 -14
  43. package/dataflow/extractor.js +185 -59
  44. package/dataflow/fn/class-declaration.d.ts +8 -2
  45. package/dataflow/fn/class-declaration.js +96 -97
  46. package/dataflow/fn/exceptions-of-function.js +68 -37
  47. package/dataflow/fn/frame-reflection.d.ts +12 -4
  48. package/dataflow/fn/frame-reflection.js +64 -42
  49. package/dataflow/fn/function-props.js +15 -33
  50. package/dataflow/fn/function-semantics.d.ts +11 -3
  51. package/dataflow/fn/function-semantics.js +6 -0
  52. package/dataflow/fn/higher-order-function.js +13 -17
  53. package/dataflow/fn/strict-function.d.ts +13 -0
  54. package/dataflow/fn/strict-function.js +285 -122
  55. package/dataflow/graph/call-graph.d.ts +7 -6
  56. package/dataflow/graph/call-graph.js +35 -46
  57. package/dataflow/graph/graph.d.ts +6 -1
  58. package/dataflow/graph/graph.js +57 -66
  59. package/dataflow/info.d.ts +8 -1
  60. package/dataflow/info.js +24 -30
  61. package/dataflow/internal/control-flow.d.ts +42 -4
  62. package/dataflow/internal/control-flow.js +76 -39
  63. package/dataflow/internal/linker.d.ts +15 -9
  64. package/dataflow/internal/linker.js +253 -241
  65. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
  66. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +441 -79
  67. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  68. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
  69. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
  70. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
  71. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  72. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
  74. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
  75. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +290 -252
  76. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  78. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  79. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
  80. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
  82. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  84. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  85. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
  86. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
  91. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  92. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  93. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  94. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  95. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
  97. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  98. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  99. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +120 -93
  101. package/dataflow/internal/process/functions/call/common.d.ts +1 -3
  102. package/dataflow/internal/process/functions/call/common.js +36 -76
  103. package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
  104. package/dataflow/internal/process/functions/call/deferred.js +60 -58
  105. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  106. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  107. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  108. package/dataflow/internal/process/functions/call/named-call-handling.js +44 -21
  109. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  110. package/dataflow/internal/process/functions/call/quoted.js +162 -172
  111. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  112. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  113. package/dataflow/internal/process/process-symbol.js +3 -6
  114. package/dataflow/internal/program-order.d.ts +26 -0
  115. package/dataflow/internal/program-order.js +49 -0
  116. package/documentation/doc-capabilities.js +4 -1
  117. package/documentation/wiki-interface.js +4 -0
  118. package/documentation/wiki-setup.js +23 -0
  119. package/engines.js +11 -3
  120. package/linter/linter-executor.js +19 -1
  121. package/linter/linter-rules.d.ts +17 -8
  122. package/linter/rules/absolute-path.js +63 -87
  123. package/linter/rules/file-path-validity.d.ts +4 -2
  124. package/linter/rules/file-path-validity.js +117 -80
  125. package/linter/rules/namespace-access.js +21 -33
  126. package/linter/rules/naming-convention.d.ts +1 -1
  127. package/linter/rules/naming-convention.js +60 -48
  128. package/linter/rules/network-functions.js +11 -7
  129. package/linter/rules/no-leaked-credentials.js +15 -18
  130. package/linter/rules/problematic-inputs.d.ts +2 -1
  131. package/linter/rules/problematic-inputs.js +39 -59
  132. package/linter/rules/roxygen-arguments.d.ts +9 -4
  133. package/linter/rules/roxygen-arguments.js +29 -48
  134. package/linter/rules/seeded-randomness.d.ts +7 -4
  135. package/linter/rules/seeded-randomness.js +130 -89
  136. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  137. package/linter/rules/stop-with-call-arg.js +25 -22
  138. package/linter/rules/unclosed-connection.js +31 -24
  139. package/linter/rules/undefined-symbol.d.ts +4 -6
  140. package/linter/rules/undefined-symbol.js +58 -75
  141. package/linter/rules/unescaped-arguments.js +18 -44
  142. package/linter/rules/unused-definition.d.ts +6 -0
  143. package/linter/rules/unused-definition.js +105 -145
  144. package/linter/rules/unused-import.d.ts +3 -0
  145. package/linter/rules/unused-import.js +25 -43
  146. package/package.json +5 -2
  147. package/project/flowr-analyzer.js +6 -2
  148. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  149. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  150. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +14 -5
  151. package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
  152. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  153. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  154. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +18 -42
  155. package/project/sigdb/decompress.js +3 -1
  156. package/project/sigdb/sigdb-download.js +9 -6
  157. package/queries/base-query-format.js +1 -2
  158. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  159. package/queries/catalog/config-query/config-query-executor.js +9 -2
  160. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  161. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  162. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  163. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  164. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  165. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  166. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  167. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  168. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  169. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  170. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  171. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  172. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  173. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  174. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  175. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  176. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  177. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  178. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  179. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  180. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  181. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  182. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  183. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  184. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  185. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  186. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  187. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  188. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  189. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  190. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  191. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  192. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  193. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  194. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  195. package/r-bridge/shell-executor.js +2 -0
  196. package/r-bridge/shell.js +8 -0
  197. package/search/search-executor/search-enrichers.js +25 -37
  198. package/slicing/static/slice-call.d.ts +4 -3
  199. package/slicing/static/slice-call.js +56 -88
  200. package/slicing/static/static-slicer.js +120 -79
  201. package/slicing/static/visiting-queue.d.ts +4 -6
  202. package/slicing/static/visiting-queue.js +9 -13
  203. package/util/files.d.ts +6 -0
  204. package/util/files.js +12 -0
  205. package/util/parallel.js +2 -0
  206. package/util/proc.js +2 -1
  207. package/util/r-base-packages.d.ts +2 -0
  208. package/util/r-base-packages.js +23 -13
  209. package/util/secure-mode.d.ts +42 -0
  210. package/util/secure-mode.js +70 -0
  211. package/util/text/playground-link.d.ts +12 -3
  212. package/util/text/playground-link.js +18 -27
  213. package/util/version.js +4 -10
@@ -4,20 +4,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.NetServer = exports.WebSocketWrapper = exports.WebSocketServerWrapper = void 0;
7
+ exports.isAllowedWebSocketOrigin = isAllowedWebSocketOrigin;
7
8
  /**
8
9
  * This is just a simple layer to allow me to mock the server's behavior in tests.
9
10
  */
10
11
  const net_1 = __importDefault(require("net"));
11
12
  const ws_1 = require("ws");
12
13
  const server_1 = require("./server");
14
+ /**
15
+ * Whether a WebSocket client with the given `Origin` header may connect.
16
+ * Browsers send the origin of the page that opens the connection, so this keeps arbitrary web pages from talking to a
17
+ * local server (cross-site WebSocket hijacking). Clients that are no browser usually send no origin and are allowed,
18
+ * as are pages served from this machine and the origins in `allowed` (`*` allows all).
19
+ */
20
+ function isAllowedWebSocketOrigin(origin, allowed = []) {
21
+ if (origin === undefined || allowed.includes('*') || allowed.includes(origin)) {
22
+ return true;
23
+ }
24
+ try {
25
+ return ['localhost', '127.0.0.1', '[::1]'].includes(new URL(origin).hostname);
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
13
31
  class WebSocketServerWrapper {
32
+ allowedOrigins;
14
33
  server;
15
34
  connectHandler;
35
+ /** @param allowedOrigins - additional origins (besides the local ones) whose pages may connect, see {@link isAllowedWebSocketOrigin} */
36
+ constructor(allowedOrigins = []) {
37
+ this.allowedOrigins = allowedOrigins;
38
+ }
16
39
  onConnect(handler) {
17
40
  this.connectHandler = handler;
18
41
  }
19
42
  start(port) {
20
- this.server = new ws_1.WebSocketServer({ port, maxPayload: 1024 * 1024 * 1024 * 1024 });
43
+ this.server = new ws_1.WebSocketServer({
44
+ port,
45
+ maxPayload: 1024 * 1024 * 1024 * 1024,
46
+ verifyClient: ({ origin }) => {
47
+ const allowed = isAllowedWebSocketOrigin(origin, this.allowedOrigins);
48
+ if (!allowed) {
49
+ server_1.serverLog.warn(`Refusing a WebSocket connection from origin ${origin}, allow it with --ws-allow-origin`);
50
+ }
51
+ return allowed;
52
+ }
53
+ });
21
54
  this.server.on('error', (e) => reportListenFailure(port, e));
22
55
  server_1.serverLog.info('WebSocket-Server wrapper is active!');
23
56
  this.server.on('connection', c => this.connectHandler?.(new WebSocketWrapper(c)));
package/cli/slicer-app.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
7
8
  const assert_1 = require("../util/assert");
8
9
  const log_1 = require("../util/log");
9
10
  const process_1 = require("../benchmark/summarizer/first-phase/process");
@@ -32,7 +33,7 @@ async function getSlice() {
32
33
  (0, assert_1.guard)(options.input !== undefined, 'input must be given');
33
34
  (0, assert_1.guard)(options.criterion !== undefined, 'a slicing criterion must be given');
34
35
  const config = (options['config-json'] ? config_1.FlowrConfig.parse(options['config-json']) : undefined)
35
- ?? config_1.FlowrConfig.fromFile(options['config-file']);
36
+ ?? config_1.FlowrConfig.fromFile(options['config-file'] && path_1.default.resolve(options['config-file']));
36
37
  await slicer.init(options['input-is-text']
37
38
  ? { request: 'text', content: options.input.replaceAll('\\n', '\n') }
38
39
  : { request: 'file', content: options.input }, config, options['no-magic-comments'] ? auto_select_defaults_1.doNotAutoSelect : (0, magic_comments_1.makeMagicCommentHandler)(auto_select_defaults_1.doNotAutoSelect), undefined, options.inline, options['include-callees'], options['inline-full'] ? (options['inline-banner'] ? 'banner' : true) : undefined);
package/config.d.ts CHANGED
@@ -349,7 +349,15 @@ export declare const FlowrConfig: {
349
349
  /**
350
350
  * Parses the given JSON string as a flowR config file, returning the resulting config object if the parsing and validation were successful, or `undefined` if there was an error.
351
351
  */
352
- readonly parse: (this: void, jsonString: string) => FlowrConfig | undefined;
352
+ readonly parse: (this: void, jsonString: string, trusted?: boolean) => FlowrConfig | undefined;
353
+ /** Paths (`*` matching any key) of all {@link securitySensitive} options, also within `specializeConfig`. */
354
+ readonly securitySensitivePaths: (this: void) => readonly (readonly string[])[];
355
+ /** Paths of all {@link regexOption} options, see {@link FlowrConfig.securitySensitivePaths}. */
356
+ readonly regexPaths: (this: void) => readonly (readonly string[])[];
357
+ /** Removes all {@link FlowrConfig.securitySensitivePaths} from the raw config (in place), returns the removed paths. */
358
+ readonly dropSecuritySensitive: (this: void, raw: unknown) => string[];
359
+ /** Like {@link FlowrConfig.dropSecuritySensitive}, but in {@link SecureMode} also drops the {@link FlowrConfig.regexPaths}. */
360
+ readonly dropUntrusted: (this: void, raw: unknown) => string[];
353
361
  /**
354
362
  * Creates a new flowr config that has the updated values.
355
363
  */
@@ -363,8 +371,10 @@ export declare const FlowrConfig: {
363
371
  * Please note that you can also use this without a path parameter to
364
372
  * infer the config from flowR's default locations.
365
373
  * This is mostly useful for user-facing features.
374
+ * A relative `configFile` is searched for in the working directory and its parents. That file belongs to the analyzed
375
+ * project, so its {@link securitySensitive} options are dropped unless `trustProjectConfig` is set.
366
376
  */
367
- readonly fromFile: (this: void, configFile?: string, configWorkingDirectory?: string) => FlowrConfig;
377
+ readonly fromFile: (this: void, configFile?: string, configWorkingDirectory?: string, trustProjectConfig?: boolean) => FlowrConfig;
368
378
  /**
369
379
  * Resolves the configuration for the given {@link ProjectKind} by applying the matching
370
380
  * {@link FlowrConfig.specializeConfig} entry to every key it names. What you configured wins over the entry, which in
package/config.js CHANGED
@@ -20,6 +20,15 @@ const project_kind_1 = require("./project/context/project-kind");
20
20
  const gas_1 = require("./gas");
21
21
  const input_types_1 = require("./queries/catalog/input-sources-query/input-types");
22
22
  const arrays_1 = require("./util/collections/arrays");
23
+ const secure_mode_1 = require("./util/secure-mode");
24
+ /** Marks an option that decides what flowR executes or loads, it is dropped from untrusted configs (see {@link FlowrConfig.fromFile}). */
25
+ function securitySensitive(schema) {
26
+ return schema.meta({ securitySensitive: true });
27
+ }
28
+ /** Marks an option holding regular expressions, which the {@link SecureMode} drops from every config (ReDoS). */
29
+ function regexOption(schema) {
30
+ return schema.meta({ regex: true });
31
+ }
23
32
  var VariableResolve;
24
33
  (function (VariableResolve) {
25
34
  /** Don't resolve constants at all */
@@ -415,7 +424,7 @@ exports.FlowrConfig = {
415
424
  classification: joi_1.default.object({
416
425
  shinyDescriptionTypes: joi_1.default.array().items(joi_1.default.string()).optional().description('DESCRIPTION Type: values that mark a shiny app.'),
417
426
  shinyEntryFiles: joi_1.default.array().items(joi_1.default.string()).optional().description('File names a shiny app is assembled from.'),
418
- shinyUsagePattern: joi_1.default.string().optional().description('Regex source evidencing shiny usage in an entry file.'),
427
+ shinyUsagePattern: regexOption(joi_1.default.string().optional()).description('Regex source evidencing shiny usage in an entry file.'),
419
428
  notebookExtensions: joi_1.default.array().items(joi_1.default.string()).optional().description('File extensions marking a notebook.')
420
429
  }).optional().description('Overrides for the signals flowR uses to classify the project kind.')
421
430
  }).description('Project specific configuration options.'),
@@ -434,12 +443,12 @@ exports.FlowrConfig = {
434
443
  .description('Overwrite (parts of) the configuration depending on the project kind flowR detects, e.g. to give a shiny app its implicit sources.'),
435
444
  engines: joi_1.default.array().items(joi_1.default.alternatives(joi_1.default.object({
436
445
  type: joi_1.default.string().required().valid('tree-sitter').description('Use the tree sitter engine.'),
437
- wasmPath: joi_1.default.string().optional().description('The path to the tree-sitter-r WASM binary to use. If this is undefined, this uses the default path.'),
438
- treeSitterWasmPath: joi_1.default.string().optional().description('The path to the tree-sitter WASM binary to use. If this is undefined, this uses the default path.'),
446
+ wasmPath: securitySensitive(joi_1.default.string().optional()).description('The path to the tree-sitter-r WASM binary to use. If this is undefined, this uses the default path.'),
447
+ treeSitterWasmPath: securitySensitive(joi_1.default.string().optional()).description('The path to the tree-sitter WASM binary to use. If this is undefined, this uses the default path.'),
439
448
  lax: joi_1.default.boolean().optional().description('Whether to use the lax parser for parsing R code (allowing for syntax errors). If this is undefined, the strict parser will be used.')
440
449
  }).description('The configuration for the tree sitter engine.'), joi_1.default.object({
441
450
  type: joi_1.default.string().required().valid('r-shell').description('Use the R shell engine.'),
442
- rPath: joi_1.default.string().optional().description('The path to the R executable to use. If this is undefined, this uses the default path.'),
451
+ rPath: securitySensitive(joi_1.default.string().optional()).description('The path to the R executable to use. If this is undefined, this uses the default path.'),
443
452
  pipeBind: joi_1.default.boolean().optional().description('Whether to enable R\'s experimental pipe-bind operator "=>" by setting _R_USE_PIPEBIND_ for the R session (default false); R itself keeps this off by default, as it is experimental and has never shipped in a release version of R.')
444
453
  }).description('The configuration for the R shell engine.'))).description('The engine or set of engines to use for interacting with R code. An empty array means all available engines will be used.'),
445
454
  defaultEngine: joi_1.default.string().optional().valid('tree-sitter', 'r-shell').description('The default engine to use for interacting with R code. If this is undefined, an arbitrary engine from the specified list will be used.'),
@@ -458,16 +467,16 @@ exports.FlowrConfig = {
458
467
  linkPackageCalls: joi_1.default.boolean().optional().description('Add a lightweight Reads edge from a resolved package call to its signature-database function vertex (default false).'),
459
468
  linkDescriptionDependencies: joi_1.default.boolean().optional().description('Eagerly attach the namespaces of the project\'s declared DESCRIPTION dependencies (Imports/Depends) so their exports resolve without an explicit library() (default false).'),
460
469
  warmInBackground: joi_1.default.boolean().optional().description('Decompress the hot shards (base + most-downloaded) in a background task on startup so the first library() lookup is warm (default false; for long-running servers/REPLs).'),
461
- additionalPaths: joi_1.default.array().items(joi_1.default.string()).optional().description('Extra directories or bundle/manifest files searched for signature databases (alongside the shipped default and $FLOWR_SIGDB_DIR); a downloaded full-history bundle placed here is mounted automatically.'),
462
- downloadRepo: joi_1.default.string().optional().description('GitHub owner/repo the full-history bundle is downloaded from via ":signature download" (default "flowr-analysis/flowr", release tag "sigdb-v<flowR-version>").'),
470
+ additionalPaths: securitySensitive(joi_1.default.array().items(joi_1.default.string()).optional()).description('Extra directories or bundle/manifest files searched for signature databases (alongside the shipped default and $FLOWR_SIGDB_DIR); a downloaded full-history bundle placed here is mounted automatically.'),
471
+ downloadRepo: securitySensitive(joi_1.default.string().optional()).description('GitHub owner/repo the full-history bundle is downloaded from via ":signature download" (default "flowr-analysis/flowr", release tag "sigdb-v<flowR-version>").'),
463
472
  autoSync: joi_1.default.boolean().optional().description('On startup, re-download shards whose committed sigdb.remote.json hash no longer matches the cache, in the background (default false; opt-in network sync after a git pull).'),
464
473
  installedLibrary: joi_1.default.object({
465
474
  enabled: joi_1.default.boolean().required().description('Recover packages no signature database knows from their installed copy (default false).'),
466
- paths: joi_1.default.array().items(joi_1.default.string()).optional().description('Library directories to search; when empty they are discovered from the environment and the project.'),
475
+ paths: securitySensitive(joi_1.default.array().items(joi_1.default.string()).optional()).description('Library directories to search; when empty they are discovered from the environment and the project.'),
467
476
  useEnvironment: joi_1.default.boolean().optional().description('Search the libraries R_LIBS_USER/R_LIBS/R_LIBS_SITE name (default true).'),
468
477
  useProjectLibrary: joi_1.default.boolean().optional().description('Search a project-local renv/packrat library (default true).'),
469
478
  maxDepth: joi_1.default.number().optional().description('How far to descend into the nested layout of a project-local library (default 3).'),
470
- packages: joi_1.default.array().items(joi_1.default.string()).optional().description('Only recover packages whose name matches one of these regular expressions; empty means any.')
479
+ packages: regexOption(joi_1.default.array().items(joi_1.default.string()).optional()).description('Only recover packages whose name matches one of these regular expressions; empty means any.')
471
480
  }).optional().description('Recovering packages no signature database knows from the copy installed on this machine.'),
472
481
  blobCacheBudgetMb: joi_1.default.number().min(0).optional().description('How many MiB of decoded package blobs every open bundle may hold together (default 16).'),
473
482
  versionSelection: joi_1.default.string().valid(...Object.values(VersionSelection)).optional().description('When a project constrains a dependency, resolve to the newest (default), oldest, or system-installed version satisfying it; system needs R and falls back to newest. Base-R packages always resolve against the assumed R version.'),
@@ -488,7 +497,7 @@ exports.FlowrConfig = {
488
497
  inferWorkingDirectory: joi_1.default.string().valid(...Object.values(InferWorkingDirectory)).description('Try to infer the working directory from the main or any script to analyze.'),
489
498
  searchPath: joi_1.default.array().items(joi_1.default.string()).description('Additionally search in these paths.'),
490
499
  repeatedSourceLimit: joi_1.default.number().optional().description('How often the same file can be sourced within a single run? Please be aware: in case of cyclic sources this may not reach a fixpoint so give this a sensible limit.'),
491
- applyReplacements: joi_1.default.array().items(joi_1.default.object()).description('Provide name replacements for loaded files'),
500
+ applyReplacements: regexOption(joi_1.default.array().items(joi_1.default.object())).description('Provide name replacements for loaded files'),
492
501
  assumeFilesExist: joi_1.default.boolean().optional().description('Assume a sourced file is always there, making what it defines certain instead of conditional on the source call.')
493
502
  }).optional().description('If lax source calls are active, flowR searches for sourced files much more freely, based on the configurations you give it. This option is only in effect if `ignoreSourceCalls` is set to false.'),
494
503
  slicer: joi_1.default.object({
@@ -560,9 +569,15 @@ exports.FlowrConfig = {
560
569
  /**
561
570
  * Parses the given JSON string as a flowR config file, returning the resulting config object if the parsing and validation were successful, or `undefined` if there was an error.
562
571
  */
563
- parse(jsonString) {
572
+ parse(jsonString, trusted = true) {
564
573
  try {
565
574
  const parsed = JSON.parse(jsonString);
575
+ const dropped = trusted && !secure_mode_1.SecureMode.isEnabled() ? [] : exports.FlowrConfig.dropUntrusted(parsed);
576
+ if (dropped.length > 0) {
577
+ console.warn(secure_mode_1.SecureMode.isEnabled()
578
+ ? `[flowR] Ignoring ${dropped.join(', ')}, the secure mode does not allow them in any config.`
579
+ : `[flowR] Ignoring ${dropped.join(', ')} from the project config, pass --config-file or --trust-config to use them.`);
580
+ }
566
581
  const validate = exports.FlowrConfig.Schema.validate(parsed);
567
582
  if (!validate.error) {
568
583
  // assign default values to all config options except for the specified ones
@@ -577,6 +592,23 @@ exports.FlowrConfig = {
577
592
  log_1.log.error(`Failed to parse config ${jsonString}: ${e.message}`);
578
593
  }
579
594
  },
595
+ /** Paths (`*` matching any key) of all {@link securitySensitive} options, also within `specializeConfig`. */
596
+ securitySensitivePaths() {
597
+ return taggedPaths('securitySensitive');
598
+ },
599
+ /** Paths of all {@link regexOption} options, see {@link FlowrConfig.securitySensitivePaths}. */
600
+ regexPaths() {
601
+ return taggedPaths('regex');
602
+ },
603
+ /** Removes all {@link FlowrConfig.securitySensitivePaths} from the raw config (in place), returns the removed paths. */
604
+ dropSecuritySensitive(raw) {
605
+ return exports.FlowrConfig.securitySensitivePaths().flatMap(p => dropPath(raw, p, ''));
606
+ },
607
+ /** Like {@link FlowrConfig.dropSecuritySensitive}, but in {@link SecureMode} also drops the {@link FlowrConfig.regexPaths}. */
608
+ dropUntrusted(raw) {
609
+ const dropped = exports.FlowrConfig.dropSecuritySensitive(raw);
610
+ return secure_mode_1.SecureMode.isEnabled() ? [...dropped, ...exports.FlowrConfig.regexPaths().flatMap(p => dropPath(raw, p, ''))] : dropped;
611
+ },
580
612
  /**
581
613
  * Creates a new flowr config that has the updated values.
582
614
  */
@@ -596,11 +628,15 @@ exports.FlowrConfig = {
596
628
  * Please note that you can also use this without a path parameter to
597
629
  * infer the config from flowR's default locations.
598
630
  * This is mostly useful for user-facing features.
631
+ * A relative `configFile` is searched for in the working directory and its parents. That file belongs to the analyzed
632
+ * project, so its {@link securitySensitive} options are dropped unless `trustProjectConfig` is set.
599
633
  */
600
- fromFile(configFile, configWorkingDirectory = process.cwd()) {
634
+ fromFile(configFile, configWorkingDirectory = process.cwd(), trustProjectConfig = false) {
601
635
  let config;
602
636
  try {
603
- config = loadConfigFromFile(configFile, configWorkingDirectory);
637
+ // the secure mode never searches for a project config
638
+ const searched = configFile !== undefined && !path_1.default.isAbsolute(configFile);
639
+ config = loadConfigFromFile(searched && secure_mode_1.SecureMode.isEnabled() ? undefined : configFile, configWorkingDirectory, trustProjectConfig);
604
640
  }
605
641
  catch (e) {
606
642
  log_1.log.error(`Failed to load config: ${e.message}`);
@@ -740,7 +776,48 @@ function persistSigDbPathToGlobalConfig(dbPath) {
740
776
  fs_1.default.writeFileSync(file, JSON.stringify(raw, null, '\t') + '\n');
741
777
  return file;
742
778
  }
743
- function loadConfigFromFile(configFile, workingDirectory) {
779
+ const taggedPathsCache = new Map();
780
+ function taggedPaths(meta) {
781
+ let paths = taggedPathsCache.get(meta);
782
+ if (paths === undefined) {
783
+ const base = collectTaggedPaths(exports.FlowrConfig.Schema.describe(), meta);
784
+ paths = [...base, ...base.map(p => ['specializeConfig', '*', ...p])];
785
+ taggedPathsCache.set(meta, paths);
786
+ }
787
+ return paths;
788
+ }
789
+ function collectTaggedPaths(d, meta, at = []) {
790
+ if (!d) {
791
+ return [];
792
+ }
793
+ else if (d.metas?.some(m => m[meta] === true)) {
794
+ return [[...at]];
795
+ }
796
+ return [
797
+ ...Object.entries(d.keys ?? {}).flatMap(([k, v]) => collectTaggedPaths(v, meta, [...at, k])),
798
+ ...(d.items ?? []).flatMap(i => collectTaggedPaths(i, meta, [...at, '*'])),
799
+ ...(d.matches ?? []).flatMap(m => collectTaggedPaths(m.schema, meta, at))
800
+ ];
801
+ }
802
+ function dropPath(obj, path, at) {
803
+ if (obj === null || typeof obj !== 'object' || path.length === 0) {
804
+ return [];
805
+ }
806
+ const [head, ...rest] = path;
807
+ const record = obj;
808
+ const dropped = [];
809
+ for (const key of head === '*' ? Object.keys(record) : Object.hasOwn(record, head) ? [head] : []) {
810
+ const next = at === '' ? key : `${at}.${key}`;
811
+ if (rest.length > 0) {
812
+ dropped.push(...dropPath(record[key], rest, next));
813
+ }
814
+ else if (Reflect.deleteProperty(record, key)) {
815
+ dropped.push(next);
816
+ }
817
+ }
818
+ return dropped;
819
+ }
820
+ function loadConfigFromFile(configFile, workingDirectory, trustProjectConfig) {
744
821
  if (configFile !== undefined) {
745
822
  if (path_1.default.isAbsolute(configFile) && fs_1.default.existsSync(configFile)) {
746
823
  log_1.log.trace(`Found config at ${configFile} (absolute)`);
@@ -755,7 +832,7 @@ function loadConfigFromFile(configFile, workingDirectory) {
755
832
  const configPath = path_1.default.join(searchPath, configFile);
756
833
  if (fs_1.default.existsSync(configPath)) {
757
834
  log_1.log.trace(`Found config at ${configPath}`);
758
- const ret = exports.FlowrConfig.parse(fs_1.default.readFileSync(configPath, { encoding: 'utf-8' }));
835
+ const ret = exports.FlowrConfig.parse(fs_1.default.readFileSync(configPath, { encoding: 'utf-8' }), trustProjectConfig);
759
836
  if (ret) {
760
837
  log_1.log.info(`Using config ${JSON.stringify(ret)}`);
761
838
  return ret;
@@ -7,6 +7,11 @@ import { type ControlFlowGraph } from './control-flow-graph';
7
7
  export declare function happensBefore(cfg: ControlFlowGraph, a: NodeId, b: NodeId): Ternary;
8
8
  /** Whether one of the `candidates` always happens before `b`; one walk back from `b` settles all candidates at once. */
9
9
  export declare function someAlwaysBefore(cfg: ControlFlowGraph, candidates: ReadonlySet<NodeId>, b: NodeId): boolean;
10
+ /**
11
+ * The `candidates` none of the others always happens before, i.e. those some path reaches without passing another.
12
+ * With `within` (a function's body) the walk stays among those nodes; a region that is one cycle keeps every candidate.
13
+ */
14
+ export declare function firstOnSomePath(cfg: ControlFlowGraph, candidates: ReadonlySet<NodeId>, within?: ReadonlySet<NodeId>): ReadonlySet<NodeId>;
10
15
  /** Every node reachable from one of `from`, the seeds included: `happensBefore(cfg, from_i, to)` is not {@link Ternary#Never} for some seed exactly when `to` is in here. */
11
16
  export declare function reachableFrom(cfg: ControlFlowGraph, from: Iterable<NodeId>): ReadonlySet<NodeId>;
12
17
  /** @see {@link reachableFrom} - the other direction */
@@ -2,65 +2,79 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.happensBefore = happensBefore;
4
4
  exports.someAlwaysBefore = someAlwaysBefore;
5
+ exports.firstOnSomePath = firstOnSomePath;
5
6
  exports.reachableFrom = reachableFrom;
6
7
  exports.reachableTo = reachableTo;
7
8
  const logic_1 = require("../util/logic");
8
9
  const control_flow_graph_1 = require("./control-flow-graph");
9
- /**
10
- * Determines if node `a` happens before node `b` in the control flow graph.
11
- */
12
- function happensBefore(cfg, a, b) {
10
+ /** Walks back from `b`, handing each node the vertex its outermost open branch scope joins on, until `stop` says so. */
11
+ function walkBack(cfg, b, stop) {
13
12
  const visited = new Set();
14
13
  /* the first is the id we are currently at, the second one the vertex the current largest cd scope joins on */
15
14
  const stack = [[b, undefined]];
16
15
  while (stack.length > 0) {
17
16
  const [current, cd] = stack.pop();
18
- let useCd = cd;
19
- if (current === a) {
20
- return cd ? logic_1.Ternary.Maybe : logic_1.Ternary.Always;
17
+ if (stop(current, cd)) {
18
+ return true;
21
19
  }
22
20
  else if (visited.has(current)) {
23
21
  continue;
24
22
  }
25
- else if (cd && (current === cd || visited.has(cd))) {
26
- useCd = undefined;
27
- }
23
+ const useCd = cd && (current === cd || visited.has(cd)) ? undefined : cd;
28
24
  visited.add(current);
29
25
  for (const [id, t] of cfg.ingoingEdges(current) ?? []) {
30
26
  /* the vertex that caused the branch is where its arms join again, so it closes the scope */
31
- const joinsAt = control_flow_graph_1.CfgEdge.isControlDependency(t) ? control_flow_graph_1.CfgEdge.unpackCause(t) : useCd;
27
+ const joinsAt = control_flow_graph_1.CfgEdge.isControlDependency(t) ? control_flow_graph_1.CfgEdge.unpackCause(t) : undefined;
32
28
  stack.push([id, useCd ?? joinsAt]);
33
29
  }
34
30
  }
35
- return logic_1.Ternary.Never;
31
+ return false;
32
+ }
33
+ /**
34
+ * Determines if node `a` happens before node `b` in the control flow graph.
35
+ */
36
+ function happensBefore(cfg, a, b) {
37
+ let result = logic_1.Ternary.Never;
38
+ walkBack(cfg, b, (current, cd) => {
39
+ if (current === a) {
40
+ result = cd ? logic_1.Ternary.Maybe : logic_1.Ternary.Always;
41
+ }
42
+ return current === a;
43
+ });
44
+ return result;
36
45
  }
37
46
  /** Whether one of the `candidates` always happens before `b`; one walk back from `b` settles all candidates at once. */
38
47
  function someAlwaysBefore(cfg, candidates, b) {
39
- const visited = new Set();
40
48
  const met = new Set();
41
- const stack = [[b, undefined]];
42
- while (stack.length > 0) {
43
- const [current, cd] = stack.pop();
44
- let useCd = cd;
45
- if (current !== b && candidates.has(current) && !met.has(current)) {
46
- if (!cd) {
47
- return true;
48
- }
49
- met.add(current);
50
- }
51
- if (visited.has(current)) {
52
- continue;
53
- }
54
- else if (cd && (current === cd || visited.has(cd))) {
55
- useCd = undefined;
56
- }
57
- visited.add(current);
58
- for (const [id, t] of cfg.ingoingEdges(current) ?? []) {
59
- const joinsAt = control_flow_graph_1.CfgEdge.isControlDependency(t) ? control_flow_graph_1.CfgEdge.unpackCause(t) : useCd;
60
- stack.push([id, useCd ?? joinsAt]);
49
+ return walkBack(cfg, b, (current, cd) => {
50
+ if (current === b || !candidates.has(current) || met.has(current)) {
51
+ return false;
61
52
  }
53
+ met.add(current);
54
+ return !cd;
55
+ });
56
+ }
57
+ /**
58
+ * The `candidates` none of the others always happens before, i.e. those some path reaches without passing another.
59
+ * With `within` (a function's body) the walk stays among those nodes; a region that is one cycle keeps every candidate.
60
+ */
61
+ function firstOnSomePath(cfg, candidates, within) {
62
+ const inside = (id) => within === undefined || within.has(id);
63
+ const predecessors = (id) => [...cfg.ingoingEdges(id)?.keys() ?? []].filter(inside);
64
+ const region = closure(candidates, predecessors);
65
+ const starts = [...region].filter(id => predecessors(id).length === 0);
66
+ if (starts.length === 0) {
67
+ return candidates;
62
68
  }
63
- return false;
69
+ const first = new Set();
70
+ closure(starts, id => {
71
+ if (candidates.has(id)) {
72
+ first.add(id);
73
+ return [];
74
+ }
75
+ return [...cfg.outgoingEdges(id)?.keys() ?? []].filter(next => region.has(next));
76
+ });
77
+ return first;
64
78
  }
65
79
  function closure(seeds, step) {
66
80
  const seen = new Set(seeds);
@@ -12,6 +12,6 @@ export declare const loopyFunctions: Set<BuiltInProcName>;
12
12
  * @param controlflow - control flow graph
13
13
  * @param ast - normalized ast
14
14
  * @param ctx - current flowr analyzer context
15
- * @returns true if the given loop only iterates once
15
+ * @returns true if the given loop only iterates once, `undefined` if we cannot tell
16
16
  */
17
17
  export declare function onlyLoopsOnce(loop: NodeId, dataflow: DataflowGraph, controlflow: ControlFlowInformation, ast: NormalizedAst, ctx: ReadOnlyFlowrAnalyzerContext): boolean | undefined;
@@ -21,7 +21,7 @@ exports.loopyFunctions = new Set([built_in_proc_name_1.BuiltInProcName.ForLoop,
21
21
  * @param controlflow - control flow graph
22
22
  * @param ast - normalized ast
23
23
  * @param ctx - current flowr analyzer context
24
- * @returns true if the given loop only iterates once
24
+ * @returns true if the given loop only iterates once, `undefined` if we cannot tell
25
25
  */
26
26
  function onlyLoopsOnce(loop, dataflow, controlflow, ast, ctx) {
27
27
  const vertex = dataflow.getVertex(loop);
@@ -30,43 +30,43 @@ function onlyLoopsOnce(loop, dataflow, controlflow, ast, ctx) {
30
30
  }
31
31
  (0, assert_1.guard)(vertex_1.DfgVertex.isFunctionCall(vertex), 'invalid vertex type for onlyLoopsOnce');
32
32
  (0, assert_1.guard)(vertex.origin !== 'unnamed' && exports.loopyFunctions.has(vertex.origin[0]), 'onlyLoopsOnce can only be called with loops');
33
- // 1. In case of for loop, check if vector has only one element
33
+ /* a for loop over a vector of one element */
34
34
  if (vertex.origin[0] === built_in_proc_name_1.BuiltInProcName.ForLoop) {
35
- if (vertex.args.length < 2) {
36
- return undefined;
37
- }
38
35
  const vectorOfLoop = vertex.args[1];
39
- if (vectorOfLoop === r_function_call_1.EmptyArgument) {
36
+ if (vectorOfLoop === undefined || vectorOfLoop === r_function_call_1.EmptyArgument) {
40
37
  return undefined;
41
38
  }
42
39
  const vector = node_value_1.NodeValue.soleOf(vectorOfLoop.nodeId, resolve_helper_1.Resolve.info(dataflow, ctx));
43
- const once = vector === undefined ? false
44
- : vector.type === 'vector' ? (0, r_value_1.isValue)(vector.elements) && vector.elements.length === 1
45
- : vector.type === 'interval' ? (0, r_value_1.isValue)(vector.start) && (0, r_value_1.isValue)(vector.end) && vector.startInclusive && vector.endInclusive
46
- && (0, r_value_1.isValue)(vector.start.value) && (0, r_value_1.isValue)(vector.end.value) && vector.start.value.num === vector.end.value.num
47
- : vector.type === 'string' || vector.type === 'logical';
48
- if (once) {
40
+ if (vector !== undefined && holdsOneElement(vector)) {
49
41
  return true;
50
42
  }
51
43
  }
52
- // 2. Use CFG Visitor to determine if loop always exits after the first iteration
53
- const visitor = new CfgSingleIterationLoopDetector(loop, {
44
+ /* or a loop always left after the first iteration */
45
+ return new CfgSingleIterationLoopDetector(loop, {
54
46
  controlFlow: controlflow,
55
47
  normalizedAst: ast,
56
48
  dfg: dataflow,
57
- ctx: ctx,
49
+ ctx,
58
50
  defaultVisitingOrder: 'forward'
59
- });
60
- return visitor.loopsOnlyOnce();
51
+ }).loopsOnlyOnce();
52
+ }
53
+ function holdsOneElement(value, element = false) {
54
+ if (!(0, r_value_1.isValue)(value)) {
55
+ return false;
56
+ }
57
+ return value.type === 'vector' ? (0, r_value_1.isValue)(value.elements) && value.elements.length === 1 && holdsOneElement(value.elements[0], true)
58
+ : value.type === 'interval' ? (0, r_value_1.isValue)(value.start) && (0, r_value_1.isValue)(value.end) && value.startInclusive && value.endInclusive
59
+ && (0, r_value_1.isValue)(value.start.value) && (0, r_value_1.isValue)(value.end.value) && value.start.value.num === value.end.value.num
60
+ : (value.type === 'string' || value.type === 'logical' || (element && value.type === 'number')) && (0, r_value_1.isValue)(value.value);
61
61
  }
62
62
  class CfgSingleIterationLoopDetector extends semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor {
63
+ loopToCheck;
63
64
  loopCds = undefined;
64
65
  encounteredLoopBreaker = false;
65
66
  onlyLoopyOnce = false;
66
- loopToCheck;
67
- constructor(loop, config) {
67
+ constructor(loopToCheck, config) {
68
68
  super(config);
69
- this.loopToCheck = loop;
69
+ this.loopToCheck = loopToCheck;
70
70
  }
71
71
  startVisitor(_) {
72
72
  const g = this.config.controlFlow.graph;
@@ -92,38 +92,25 @@ class CfgSingleIterationLoopDetector extends semantic_cfg_guided_visitor_1.Seman
92
92
  }
93
93
  this.onlyLoopyOnce ||= this.encounteredLoopBreaker && (0, info_1.happensInEveryBranch)(this.loopCds?.filter(c => !c.byIteration));
94
94
  }
95
- app(cds) {
96
- if (cds === undefined) {
97
- return;
98
- }
99
- const filtered = cds.filter(c => c.id !== this.loopToCheck);
95
+ breaks({ call }) {
96
+ this.encounteredLoopBreaker = true;
97
+ const filtered = call.cds?.filter(c => c.id !== this.loopToCheck) ?? [];
100
98
  if (filtered.length > 0) {
101
- if (this.loopCds === undefined) {
102
- this.loopCds = filtered;
103
- }
104
- else {
105
- this.loopCds = this.loopCds.concat(filtered);
106
- }
99
+ this.loopCds = (this.loopCds ?? []).concat(filtered);
107
100
  }
108
101
  }
109
102
  onBreakCall(data) {
110
- this.encounteredLoopBreaker = true;
111
- this.app(data.call.cds);
103
+ this.breaks(data);
112
104
  }
113
105
  onReturnCall(data) {
114
- this.encounteredLoopBreaker = true;
115
- this.app(data.call.cds);
106
+ this.breaks(data);
116
107
  }
117
108
  onStopCall(data) {
118
- this.encounteredLoopBreaker = true;
119
- this.app(data.call.cds);
109
+ this.breaks(data);
120
110
  }
121
111
  onStopIfNotCall(data) {
122
- const arg = this.getBoolArgValue(data);
123
- if (arg === false) {
124
- this.encounteredLoopBreaker = true;
125
- this.app(data.call.cds);
126
- return;
112
+ if (this.getBoolArgValue(data) === false) {
113
+ this.breaks(data);
127
114
  }
128
115
  }
129
116
  loopsOnlyOnce() {
@@ -1,4 +1,5 @@
1
1
  import type { DecodedFunction } from '../../project/sigdb/decode';
2
+ import { Ternary } from '../../util/logic';
2
3
  /**
3
4
  * What a single argument of a call is used for, as a bitmask ({@link ArgProp.Forced}/{@link ArgProp.NoDefault}
4
5
  * lead, being the two bits the signature database can also state).
@@ -275,6 +276,8 @@ export declare const FnSig: {
275
276
  readonly posWith: typeof argsWith;
276
277
  /** Which of the first `count` arguments a call evaluates; see {@link forcedArgs}. */
277
278
  readonly forced: typeof forcedArgs;
279
+ /** How surely a call evaluates each of the first `count` arguments; see {@link argForcing}. */
280
+ readonly forcing: typeof argForcing;
278
281
  /** A signature saying only that the call evaluates every argument; see {@link ForcingEvery}. */
279
282
  readonly every: FnSig;
280
283
  /** A signature saying only that the call evaluates one argument; see {@link forcingOnly}. */
@@ -320,6 +323,7 @@ export interface SigLayout {
320
323
  /** the position of the {@link ArgProp.Alias} argument, handed back as the result, `-1` if there is none */
321
324
  readonly alias: number;
322
325
  forced?: (readonly boolean[])[];
326
+ forcing?: (readonly Ternary[])[];
323
327
  }
324
328
  /**
325
329
  * The positional view of a {@link FnSig}, computed on first use and cached per signature object,
@@ -338,6 +342,11 @@ declare function forcingOnly(this: void, index: number, name: string): FnSig;
338
342
  * A signature is the one place that says so, which is why nothing else may state it alongside.
339
343
  */
340
344
  declare function forcedArgs(this: void, sig: FnSig | undefined, count: number): readonly boolean[] | undefined;
345
+ /**
346
+ * How surely a call evaluates each of the first `count` arguments: {@link ArgProp.Forced} always,
347
+ * {@link ArgProp.Nse} and {@link ArgProp.Presence} never, anything else maybe; `undefined` without a signature.
348
+ */
349
+ declare function argForcing(this: void, sig: FnSig | undefined, count: number): readonly Ternary[] | undefined;
341
350
  /** The positions of the first `count` arguments that carry any of `prop`. */
342
351
  declare function argsWith(this: void, layout: SigLayout, count: number, prop: ArgProps): number[];
343
352
  /** the callees that make the calling function itself a generic ({@link CallProp.Generic}) */