@eagleoutice/flowr 2.13.3 → 2.13.5

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 (176) hide show
  1. package/README.md +32 -32
  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/cli/repl/core.js +10 -2
  7. package/config.d.ts +4 -1
  8. package/config.js +10 -1
  9. package/control-flow/cfg-dead-code.js +91 -15
  10. package/control-flow/extract-cfg.js +93 -8
  11. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  12. package/dataflow/environments/built-in-config.d.ts +6 -3
  13. package/dataflow/environments/built-in-eval-name.d.ts +20 -0
  14. package/dataflow/environments/built-in-eval-name.js +25 -0
  15. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  16. package/dataflow/environments/built-in-proc-name.js +4 -0
  17. package/dataflow/environments/built-in-props.d.ts +175 -0
  18. package/dataflow/environments/built-in-props.js +207 -0
  19. package/dataflow/environments/built-in.d.ts +28 -20
  20. package/dataflow/environments/built-in.js +39 -8
  21. package/dataflow/environments/default-builtin-config.d.ts +1094 -86
  22. package/dataflow/environments/default-builtin-config.js +496 -212
  23. package/dataflow/environments/identifier.d.ts +25 -1
  24. package/dataflow/environments/identifier.js +24 -2
  25. package/dataflow/environments/query-fn-props.d.ts +102 -0
  26. package/dataflow/environments/query-fn-props.js +188 -0
  27. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
  28. package/dataflow/eval/resolve/alias-tracking.js +12 -2
  29. package/dataflow/eval/resolve/match-arguments.d.ts +15 -0
  30. package/dataflow/eval/resolve/match-arguments.js +77 -0
  31. package/dataflow/eval/resolve/resolve-numbers.d.ts +202 -0
  32. package/dataflow/eval/resolve/resolve-numbers.js +163 -0
  33. package/dataflow/eval/resolve/resolve-operators.d.ts +60 -0
  34. package/dataflow/eval/resolve/resolve-operators.js +115 -0
  35. package/dataflow/eval/resolve/resolve-strings.d.ts +98 -0
  36. package/dataflow/eval/resolve/resolve-strings.js +116 -0
  37. package/dataflow/eval/resolve/resolve.d.ts +5 -23
  38. package/dataflow/eval/resolve/resolve.js +56 -87
  39. package/dataflow/fn/higher-order-function.js +3 -3
  40. package/dataflow/fn/recursive-function.js +1 -1
  41. package/dataflow/graph/df-helper.js +1 -1
  42. package/dataflow/graph/vertex.d.ts +32 -25
  43. package/dataflow/graph/vertex.js +40 -36
  44. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  45. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  46. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  47. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  48. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  49. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  50. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
  52. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -0
  53. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
  54. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  55. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  56. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
  57. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  58. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  59. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  60. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
  61. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
  62. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
  63. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
  64. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +2 -1
  65. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  66. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  67. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  68. package/documentation/data/faq/faqs.js +11 -0
  69. package/documentation/doc-util/doc-types.js +1 -1
  70. package/documentation/wiki-analyzer.js +75 -0
  71. package/documentation/wiki-core.js +65 -16
  72. package/documentation/wiki-interface.js +3 -0
  73. package/linter/linter-rules.d.ts +10 -11
  74. package/linter/rules/absolute-path.js +1 -1
  75. package/linter/rules/deprecated-functions.js +5 -3
  76. package/linter/rules/function-finder-util.d.ts +2 -2
  77. package/linter/rules/function-finder-util.js +11 -4
  78. package/linter/rules/network-functions.d.ts +25 -5
  79. package/linter/rules/network-functions.js +51 -11
  80. package/linter/rules/no-leaked-credentials.js +1 -1
  81. package/linter/rules/problematic-inputs.d.ts +1 -1
  82. package/linter/rules/problematic-inputs.js +7 -1
  83. package/linter/rules/seeded-randomness.d.ts +5 -8
  84. package/linter/rules/seeded-randomness.js +17 -9
  85. package/linter/rules/undefined-symbol.js +1 -1
  86. package/linter/rules/unused-definition.js +15 -10
  87. package/linter/rules/useless-loop.js +1 -1
  88. package/package.json +3 -2
  89. package/project/cache/flowr-analyzer-cache.d.ts +4 -3
  90. package/project/cache/flowr-analyzer-cache.js +32 -13
  91. package/project/cache/flowr-cache.d.ts +39 -12
  92. package/project/cache/flowr-cache.js +5 -3
  93. package/project/context/flowr-analyzer-context.d.ts +8 -1
  94. package/project/context/flowr-analyzer-context.js +11 -1
  95. package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -2
  96. package/project/context/flowr-analyzer-dependencies-context.js +15 -1
  97. package/project/context/flowr-analyzer-files-context.d.ts +8 -4
  98. package/project/context/flowr-analyzer-files-context.js +20 -1
  99. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +33 -0
  100. package/project/context/flowr-analyzer-incremental-analysis-context.js +63 -0
  101. package/project/context/flowr-analyzer-meta-context.d.ts +3 -1
  102. package/project/context/flowr-analyzer-meta-context.js +14 -0
  103. package/project/context/flowr-file.d.ts +25 -3
  104. package/project/context/flowr-file.js +24 -2
  105. package/project/dependency-version-space.d.ts +37 -0
  106. package/project/dependency-version-space.js +118 -26
  107. package/project/flowr-analyzer.d.ts +6 -0
  108. package/project/flowr-analyzer.js +6 -2
  109. package/project/incremental/incremental-parse/edit-computation.d.ts +7 -0
  110. package/project/incremental/incremental-parse/edit-computation.js +61 -0
  111. package/project/incremental/incremental-parse/incremental-parse.d.ts +12 -0
  112. package/project/incremental/incremental-parse/incremental-parse.js +37 -0
  113. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +1 -1
  114. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +57 -0
  115. package/project/plugins/file-plugins/files/flowr-manifest-files.js +121 -0
  116. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -2
  117. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +2 -2
  118. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +1 -1
  119. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +33 -0
  120. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +53 -0
  121. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  122. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  123. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +27 -0
  124. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +47 -0
  125. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +7 -0
  126. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -3
  127. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +10 -4
  128. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +17 -4
  129. package/project/plugins/plugin-registry.d.ts +4 -4
  130. package/project/plugins/plugin-registry.js +7 -4
  131. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  132. package/project/sigdb/reader.d.ts +7 -0
  133. package/project/sigdb/reader.js +12 -0
  134. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  135. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  136. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +10 -0
  137. package/queries/catalog/dependencies-query/function-info/derived-functions.js +41 -0
  138. package/queries/catalog/dependencies-query/function-info/read-functions.js +14 -13
  139. package/queries/catalog/dependencies-query/function-info/write-functions.js +28 -36
  140. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +33 -3
  141. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +31 -0
  142. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +9 -2
  143. package/queries/catalog/input-sources-query/input-source-functions.d.ts +9 -10
  144. package/queries/catalog/input-sources-query/input-source-functions.js +23 -394
  145. package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
  146. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -0
  147. package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -10
  148. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
  149. package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
  150. package/queries/catalog/signature-query/signature-query-executor.d.ts +2 -1
  151. package/queries/catalog/signature-query/signature-query-executor.js +79 -3
  152. package/queries/catalog/signature-query/signature-query-format.d.ts +27 -0
  153. package/queries/catalog/signature-query/signature-query-render.js +21 -3
  154. package/r-bridge/data/data.d.ts +2 -2
  155. package/r-bridge/data/data.js +2 -2
  156. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +6 -2
  157. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +21 -2
  158. package/r-bridge/parser.d.ts +11 -1
  159. package/r-bridge/parser.js +7 -4
  160. package/r-bridge/shell-executor.d.ts +1 -0
  161. package/r-bridge/shell-executor.js +1 -0
  162. package/r-bridge/shell.d.ts +1 -0
  163. package/r-bridge/shell.js +1 -0
  164. package/reconstruct/inline/source-inline-map.js +1 -1
  165. package/search/flowr-search-filters.d.ts +1 -6
  166. package/search/flowr-search-filters.js +1 -8
  167. package/search/search-executor/search-enrichers.d.ts +2 -0
  168. package/search/search-executor/search-enrichers.js +29 -12
  169. package/util/mermaid/dfg.js +1 -1
  170. package/util/version.js +1 -1
  171. package/project/plugins/file-plugins/files/flowr-rproject-file.d.ts +0 -31
  172. package/project/plugins/file-plugins/files/flowr-rproject-file.js +0 -66
  173. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.d.ts +0 -22
  174. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.js +0 -36
  175. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.d.ts +0 -13
  176. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.js +0 -32
@@ -13,9 +13,11 @@ const vertex_1 = require("../dataflow/graph/vertex");
13
13
  const control_flow_graph_1 = require("./control-flow-graph");
14
14
  const cfg_simplification_1 = require("./cfg-simplification");
15
15
  const assert_1 = require("../util/assert");
16
+ const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
16
17
  const stateful_fold_1 = require("../r-bridge/lang-4.x/ast/model/processing/stateful-fold");
17
18
  const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
18
19
  const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
20
+ const identifier_1 = require("../dataflow/environments/identifier");
19
21
  const cfgFolds = {
20
22
  down: (n, down) => {
21
23
  if (r_function_definition_1.RFunctionDefinition.is(n)) {
@@ -99,7 +101,7 @@ function getCallsInCfg(cfg, graph) {
99
101
  const calls = new Map();
100
102
  for (const vertexId of cfg.graph.vertices().keys()) {
101
103
  const vertex = graph.getVertex(vertexId);
102
- if ((0, vertex_1.isFunctionCallVertex)(vertex)) {
104
+ if (vertex_1.FunctionCallVertex.is(vertex)) {
103
105
  calls.set(vertexId, vertex);
104
106
  }
105
107
  }
@@ -332,11 +334,9 @@ function cfgFunctionDefinition(fn, params, body) {
332
334
  }
333
335
  return { graph: graph, breaks: [], nexts: [], returns: [], exitPoints: [fnId], entryPoints: [fnId] };
334
336
  }
337
+ /** operators whose rhs a driver evaluates as a per-iteration closure, so escapes stay within it */
338
+ const ClosureBodyOperators = new Set(['%do%', '%dopar%', '%dofuture%', '%dorng%', '%:%']);
335
339
  function cfgFunctionCall(call, name, args, down) {
336
- if (call.named && call.functionName.content === 'ifelse' && args.length > 1) {
337
- // special built-in handling for ifelse as it is an expression that does not short-circuit
338
- return cfgIfThenElse(call, args[0] === r_function_call_1.EmptyArgument ? (0, control_flow_graph_1.emptyControlFlowInformation)() : args[0], args[1] === r_function_call_1.EmptyArgument ? (0, control_flow_graph_1.emptyControlFlowInformation)() : args[1], args[2] === r_function_call_1.EmptyArgument ? (0, control_flow_graph_1.emptyControlFlowInformation)() : args[2]);
339
- }
340
340
  const callId = call.info.id;
341
341
  const graph = name.graph;
342
342
  const info = {
@@ -377,9 +377,80 @@ function cfgFunctionCall(call, name, args, down) {
377
377
  info.exitPoints.length = 0;
378
378
  }
379
379
  }
380
+ else if (call.named && ClosureBodyOperators.has(identifier_1.Identifier.getName(call.functionName.content))) {
381
+ return sealEscapes(info, control_flow_graph_1.CfgVertex.toExitId(callId));
382
+ }
380
383
  // should not contain any breaks, nexts, or returns, (except for the body if something like 'break()')
381
384
  return info;
382
385
  }
386
+ function cfgSwitch(call, name, args) {
387
+ const callId = call.info.id;
388
+ const exitId = control_flow_graph_1.CfgVertex.toExitId(callId);
389
+ const graph = name.graph;
390
+ const info = {
391
+ graph,
392
+ breaks: Array.from(name.breaks),
393
+ nexts: Array.from(name.nexts),
394
+ returns: Array.from(name.returns),
395
+ exitPoints: [exitId],
396
+ entryPoints: [callId]
397
+ };
398
+ graph.addVertex(control_flow_graph_1.CfgVertex.makeExprOrStm(callId, identifyMayStatementType(call), { mid: name.exitPoints, end: [exitId] }));
399
+ graph.addVertex(control_flow_graph_1.CfgVertex.makeExitMarker(callId));
400
+ for (const entry of name.entryPoints) {
401
+ graph.addEdge(entry, callId, control_flow_graph_1.CfgEdge.makeFd());
402
+ }
403
+ let selectorExits = name.exitPoints;
404
+ const selector = args[0];
405
+ if (selector !== undefined && selector !== r_function_call_1.EmptyArgument) {
406
+ graph.mergeWith(selector.graph);
407
+ info.breaks = info.breaks.concat(selector.breaks);
408
+ info.nexts = info.nexts.concat(selector.nexts);
409
+ info.returns = info.returns.concat(selector.returns);
410
+ for (const entry of selector.entryPoints) {
411
+ for (const exit of name.exitPoints) {
412
+ graph.addEdge(entry, exit, control_flow_graph_1.CfgEdge.makeFd());
413
+ }
414
+ }
415
+ selectorExits = selector.exitPoints;
416
+ }
417
+ const cd = control_flow_graph_1.CfgEdge.makeCdTrue(callId);
418
+ for (const arm of args.slice(1)) {
419
+ if (arm === r_function_call_1.EmptyArgument) {
420
+ continue;
421
+ }
422
+ graph.mergeWith(arm.graph);
423
+ info.breaks = info.breaks.concat(arm.breaks);
424
+ info.nexts = info.nexts.concat(arm.nexts);
425
+ info.returns = info.returns.concat(arm.returns);
426
+ for (const entry of arm.entryPoints) {
427
+ for (const exit of selectorExits) {
428
+ graph.addEdge(entry, exit, cd);
429
+ }
430
+ }
431
+ for (const exit of arm.exitPoints) {
432
+ graph.addEdge(exitId, exit, control_flow_graph_1.CfgEdge.makeFd());
433
+ }
434
+ }
435
+ const hasDefault = call.arguments.slice(1).some(a => a !== r_function_call_1.EmptyArgument && a.name === undefined);
436
+ if (!hasDefault) {
437
+ for (const exit of selectorExits) {
438
+ graph.addEdge(exitId, exit, control_flow_graph_1.CfgEdge.makeCdFalse(callId));
439
+ }
440
+ }
441
+ return info;
442
+ }
443
+ /** keeps a return/break/next from escaping a deferred body into the enclosing control flow */
444
+ function sealEscapes(base, exitId) {
445
+ for (const escape of base.returns.concat(base.breaks, base.nexts)) {
446
+ base.graph.addEdge(exitId, escape, control_flow_graph_1.CfgEdge.makeFd());
447
+ }
448
+ return { ...base, returns: [], breaks: [], nexts: [], exitPoints: base.exitPoints.length > 0 ? base.exitPoints : [exitId] };
449
+ }
450
+ // on.exit defers its expr, so seal a return/break/next inside it from escaping into enclosing control flow
451
+ function cfgRegisterHook(call, name, args, down) {
452
+ return sealEscapes(cfgFunctionCall(call, name, args, down), control_flow_graph_1.CfgVertex.toExitId(call.info.id));
453
+ }
383
454
  exports.ResolvedCallSuffix = control_flow_graph_1.CfgVertex.toExitId('-resolved-call');
384
455
  const OriginToFoldTypeMap = {
385
456
  [built_in_proc_name_1.BuiltInProcName.IfThenElse]: (folds, call, args, down) => {
@@ -392,10 +463,18 @@ function cfgFunctionCallWithDataflow(graph, folds) {
392
463
  return (call, name, args, down) => {
393
464
  const vtx = graph.getVertex(call.info.id);
394
465
  if (vtx?.tag === vertex_1.VertexType.FunctionCall && vtx.onlyBuiltin && vtx.origin.length === 1) {
395
- const mayMap = OriginToFoldTypeMap[vtx.origin[0]];
396
- if (mayMap) {
466
+ const origin = vtx.origin[0];
467
+ const mayMap = OriginToFoldTypeMap[origin];
468
+ // ifelse/fifelse/if_else share the IfThenElse origin but are eager calls, so only fold a real `if` node
469
+ if (mayMap && call.type === type_1.RType.IfThenElse) {
397
470
  return mayMap(folds, call, args, down, vtx);
398
471
  }
472
+ if (origin === built_in_proc_name_1.BuiltInProcName.Switch) {
473
+ return cfgSwitch(call, name, args);
474
+ }
475
+ if (origin === built_in_proc_name_1.BuiltInProcName.RegisterHook) {
476
+ return cfgRegisterHook(call, name, args, down);
477
+ }
399
478
  }
400
479
  const baseCfg = cfgFunctionCall(call, name, args, down);
401
480
  /* try to resolve the call and link the target definitions */
@@ -405,7 +484,7 @@ function cfgFunctionCallWithDataflow(graph, folds) {
405
484
  (0, assert_1.guard)(callVertex !== undefined, 'cfgFunctionCallWithDataflow: call vertex not found');
406
485
  for (const target of targets) {
407
486
  // we have to filter out non-func-call targets as the call targets contains names and call ids
408
- if ((0, vertex_1.isFunctionDefinitionVertex)(graph.getVertex(target))) {
487
+ if (vertex_1.FunctionDefinitionVertex.is(graph.getVertex(target))) {
409
488
  const ct = control_flow_graph_1.CfgVertex.getCallTargets(callVertex);
410
489
  if (!ct) {
411
490
  control_flow_graph_1.CfgVertex.setCallTargets(callVertex, new Set([target]));
@@ -485,6 +564,12 @@ function cfgBinaryOp(binOp, lhs, rhs) {
485
564
  for (const exitPoint of rhs.exitPoints) {
486
565
  graph.addEdge(binExit, exitPoint, fd);
487
566
  }
567
+ // `&&`/`||` short-circuit: the exit stays reachable via the lhs even when the rhs jumps
568
+ if (binOp.type === type_1.RType.BinaryOp && (binOp.operator === '&&' || binOp.operator === '||')) {
569
+ for (const exitPoint of lhs.exitPoints) {
570
+ graph.addEdge(binExit, exitPoint, fd);
571
+ }
572
+ }
488
573
  return result;
489
574
  }
490
575
  function cfgAccess(access, name, accessors) {
@@ -263,7 +263,9 @@ class SemanticCfgGuidedVisitor extends dfg_cfg_guided_visitor_1.DataflowAwareCfg
263
263
  case built_in_proc_name_1.BuiltInProcName.Function:
264
264
  case built_in_proc_name_1.BuiltInProcName.FunctionDefinition:
265
265
  case built_in_proc_name_1.BuiltInProcName.S7MakeConstructor:
266
+ case built_in_proc_name_1.BuiltInProcName.ClassGenerator:
266
267
  case built_in_proc_name_1.BuiltInProcName.DefineArgument:
268
+ case built_in_proc_name_1.BuiltInProcName.Switch:
267
269
  return this.onDefaultFunctionCall({ call });
268
270
  case built_in_proc_name_1.BuiltInProcName.Load:
269
271
  return this.onLoadCall({ call });
@@ -1,6 +1,8 @@
1
1
  import type { BuiltInProcessorMapper, ConfigOfBuiltInMappingName } from './built-in';
2
+ import type { BuiltInEvalName } from './built-in-eval-name';
2
3
  import { BuiltIns } from './built-in';
3
4
  import type { Identifier } from './identifier';
5
+ import type { BuiltInFnInfo } from './built-in-props';
4
6
  export interface BaseBuiltInDefinition {
5
7
  /** The type of the built-in configuration */
6
8
  readonly type: string;
@@ -25,10 +27,11 @@ export interface BuiltInConstantDefinition<Value> extends BaseBuiltInDefinition
25
27
  export interface BuiltInFunctionDefinition<BuiltInProcessor extends keyof typeof BuiltInProcessorMapper> extends BaseBuiltInDefinition {
26
28
  readonly type: 'function';
27
29
  readonly processor: BuiltInProcessor;
28
- readonly config?: ConfigOfBuiltInMappingName<BuiltInProcessor> & {
30
+ readonly config?: ConfigOfBuiltInMappingName<BuiltInProcessor> & BuiltInFnInfo & {
29
31
  libFn?: boolean;
30
32
  };
31
- readonly evalHandler?: string;
33
+ /** the value solver to use when folding a call to this function to a constant, see {@link BuiltInEvalHandlerMapper} */
34
+ readonly evalHandler?: BuiltInEvalName;
32
35
  }
33
36
  /**
34
37
  * Define a built-in replacement (like `[` or `$`) and the processor to use.
@@ -37,7 +40,7 @@ export interface BuiltInFunctionDefinition<BuiltInProcessor extends keyof typeof
37
40
  export interface BuiltInReplacementDefinition extends BaseBuiltInDefinition {
38
41
  readonly type: 'replacement';
39
42
  readonly suffixes: ('<<-' | '<-')[];
40
- readonly config: {
43
+ readonly config: BuiltInFnInfo & {
41
44
  readIndices: boolean;
42
45
  constructName?: 's7';
43
46
  };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The names of all value-solver handlers a built-in function may declare with
3
+ * {@link BuiltInFunctionDefinition#evalHandler}, see {@link BuiltInEvalHandlerMapper} for the implementations.
4
+ */
5
+ export declare enum BuiltInEvalName {
6
+ /** `c(...)`, see {@link resolveAsVector} */
7
+ Vector = "eval:vector",
8
+ /** the sequence operator `:`, see {@link resolveAsSeq} */
9
+ Seq = "eval:seq",
10
+ /** every numeric operator and function, from `+` to `sqrt`, see {@link resolveAsNumeric} */
11
+ Numeric = "eval:numeric",
12
+ /** the comparison operators, see {@link resolveAsComparison} */
13
+ Comparison = "eval:cmp",
14
+ /** `!` and the binary logical operators, see {@link resolveAsLogical} */
15
+ Logical = "eval:logical",
16
+ /** every string function, from `paste` to `basename`, see {@link resolveAsStringFn} */
17
+ StringFn = "eval:string-fn",
18
+ /** the grouping `(`, see {@link resolveAsGroup} */
19
+ Group = "eval:group"
20
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuiltInEvalName = void 0;
4
+ /**
5
+ * The names of all value-solver handlers a built-in function may declare with
6
+ * {@link BuiltInFunctionDefinition#evalHandler}, see {@link BuiltInEvalHandlerMapper} for the implementations.
7
+ */
8
+ var BuiltInEvalName;
9
+ (function (BuiltInEvalName) {
10
+ /** `c(...)`, see {@link resolveAsVector} */
11
+ BuiltInEvalName["Vector"] = "eval:vector";
12
+ /** the sequence operator `:`, see {@link resolveAsSeq} */
13
+ BuiltInEvalName["Seq"] = "eval:seq";
14
+ /** every numeric operator and function, from `+` to `sqrt`, see {@link resolveAsNumeric} */
15
+ BuiltInEvalName["Numeric"] = "eval:numeric";
16
+ /** the comparison operators, see {@link resolveAsComparison} */
17
+ BuiltInEvalName["Comparison"] = "eval:cmp";
18
+ /** `!` and the binary logical operators, see {@link resolveAsLogical} */
19
+ BuiltInEvalName["Logical"] = "eval:logical";
20
+ /** every string function, from `paste` to `basename`, see {@link resolveAsStringFn} */
21
+ BuiltInEvalName["StringFn"] = "eval:string-fn";
22
+ /** the grouping `(`, see {@link resolveAsGroup} */
23
+ BuiltInEvalName["Group"] = "eval:group";
24
+ })(BuiltInEvalName || (exports.BuiltInEvalName = BuiltInEvalName = {}));
25
+ //# sourceMappingURL=built-in-eval-name.js.map
@@ -86,6 +86,8 @@ export declare enum BuiltInProcName {
86
86
  StackEnv = "builtin:stack-env",
87
87
  /** for `stop` calls */
88
88
  Stop = "builtin:stop",
89
+ /** for `switch` calls */
90
+ Switch = "builtin:switch",
89
91
  /** for `stopifnot` calls, see {@link processStopIfNot} */
90
92
  StopIfNot = "builtin:stopifnot",
91
93
  /** support for `:=` in subsetting assignments, see {@link processAccess} */
@@ -96,6 +98,8 @@ export declare enum BuiltInProcName {
96
98
  Attach = "builtin:attach",
97
99
  /** for `new.env` and related environment-creation calls, see {@link processNewEnv} */
98
100
  NewEnv = "builtin:nenv",
101
+ /** for `R6Class`/`setRefClass` class generators whose methods back `$new()`-instance dispatch */
102
+ ClassGenerator = "builtin:class-gen",
99
103
  /** for unnamed directly-linked function calls */
100
104
  Unnamed = "unnamed",
101
105
  /** for vector construction calls, see {@link processVector} */
@@ -90,6 +90,8 @@ var BuiltInProcName;
90
90
  BuiltInProcName["StackEnv"] = "builtin:stack-env";
91
91
  /** for `stop` calls */
92
92
  BuiltInProcName["Stop"] = "builtin:stop";
93
+ /** for `switch` calls */
94
+ BuiltInProcName["Switch"] = "builtin:switch";
93
95
  /** for `stopifnot` calls, see {@link processStopIfNot} */
94
96
  BuiltInProcName["StopIfNot"] = "builtin:stopifnot";
95
97
  /** support for `:=` in subsetting assignments, see {@link processAccess} */
@@ -100,6 +102,8 @@ var BuiltInProcName;
100
102
  BuiltInProcName["Attach"] = "builtin:attach";
101
103
  /** for `new.env` and related environment-creation calls, see {@link processNewEnv} */
102
104
  BuiltInProcName["NewEnv"] = "builtin:nenv";
105
+ /** for `R6Class`/`setRefClass` class generators whose methods back `$new()`-instance dispatch */
106
+ BuiltInProcName["ClassGenerator"] = "builtin:class-gen";
103
107
  /** for unnamed directly-linked function calls */
104
108
  BuiltInProcName["Unnamed"] = "unnamed";
105
109
  /** for vector construction calls, see {@link processVector} */
@@ -0,0 +1,175 @@
1
+ import type { DecodedFunction } from '../../project/sigdb/decode';
2
+ /**
3
+ * What a single argument of a call is used for, as a bitmask.
4
+ * @see {@link BuiltInFnInfo#sig}
5
+ */
6
+ export declare enum ArgProp {
7
+ /** the result is this argument, handed back unchanged, like `x` in `identity(x)`; this is what draws the `Returns` edge */
8
+ Alias = 1,
9
+ /** the result is computed from the argument's value, like `x` in `sum(x)` */
10
+ Value = 2,
11
+ /** only the shape is used (length, dimensions, names, other attributes), like `x` in `nrow(x)` */
12
+ Shape = 4,
13
+ /** selects a behavior instead of carrying data, like `na.rm` in `sum(x, na.rm = TRUE)` */
14
+ Flag = 8,
15
+ /** names the resource the call reads or writes, like `file` in `write.csv(x, file)` */
16
+ Resource = 16,
17
+ /** what it refers to may be modified, like `envir` in `assign(x, v, envir = e)` */
18
+ Written = 32,
19
+ /** evaluated whenever the call happens, even if the result goes unused, like `x` in `force(x)` */
20
+ Forced = 64,
21
+ /** quoted or evaluated in another frame, like `expr` in `quote(expr)` */
22
+ Nse = 128,
23
+ /** called as a function, like `FUN` in `lapply(x, FUN)` */
24
+ Callee = 256,
25
+ /** only whether it was supplied matters, as with `missing()` */
26
+ Presence = 512,
27
+ /**
28
+ * the result is one of this argument's values, like `choices` in `match.arg(arg, choices)`. The bounding
29
+ * argument of a {@link CallProp.Narrows} call; without one such a call yields a value of its own making.
30
+ */
31
+ Bounds = 1024
32
+ }
33
+ /**
34
+ * What the call as a whole does, as a bitmask. The resource bits ({@link CallProp.File} and its neighbors)
35
+ * say where the call gets its data from, which is what {@link InputProps} collects.
36
+ * @see {@link BuiltInFnInfo#props}
37
+ */
38
+ export declare enum CallProp {
39
+ /** computes a result and nothing else, the positive counterpart of `hasUnknownSideEffects` (excludes {@link ImpureProps}) */
40
+ Pure = 1,
41
+ /**
42
+ * pure on its own, but it runs code it is handed, so whatever that code does happens too.
43
+ * The parameter it runs is marked {@link ArgProp.Callee} or {@link ArgProp.Nse}, as with `lapply(x, f)`.
44
+ */
45
+ MayPure = 2,
46
+ /** may signal an error, like `stop()` (see {@link SigDbInferable}) */
47
+ Throws = 4,
48
+ /** returns invisibly, so the result is not auto-printed */
49
+ Invisible = 8,
50
+ /** dispatches on the class of its first argument (S3, S4, or S7) */
51
+ Generic = 16,
52
+ /** a method that is reached by dispatch, like `print.foo` (see {@link SigDbInferable}) */
53
+ Method = 32,
54
+ /** binds, rebinds, or removes names outside of its own frame, like `assign` or `library` */
55
+ Scope = 64,
56
+ /** the result may differ between two identical calls for a reason neither `Random` nor `Ambient` covers (see {@link SigDbInferable}) */
57
+ NonDet = 128,
58
+ /** draws from the random number generator, or sets its state (stated instead of `NonDet`) */
59
+ Random = 256,
60
+ /** depends on ambient state like the clock, the locale, environment variables, or global options (stated instead of `NonDet`) */
61
+ Ambient = 512,
62
+ /** touches the file system */
63
+ File = 1024,
64
+ /** produces a temporary path; on its own this touches no file system, so a call that also does states `File` too */
65
+ TempFile = 2048,
66
+ /**
67
+ * always reaches the network, like `curl::curl_download`. Calls that only do so for some arguments, like
68
+ * `read.csv` of a URL, are left to the `network-functions` rule, which decides that per call site.
69
+ */
70
+ Network = 4096,
71
+ /** runs a system command */
72
+ Process = 8192,
73
+ /** calls native code through the foreign function interface, like `.Call` */
74
+ Ffi = 16384,
75
+ /** produces a language object, like `quote` or `deparse` */
76
+ Lang = 32768,
77
+ /** asks the user, like `readline` or a file chooser */
78
+ User = 65536,
79
+ /** draws on a graphics device */
80
+ Graphics = 131072,
81
+ /** talks to a database */
82
+ Database = 262144,
83
+ /** reads the resource its `Resource` arguments name */
84
+ Reads = 524288,
85
+ /** writes the resource its `Resource` arguments name */
86
+ Writes = 1048576,
87
+ /** may emit to standard output, like `print` or a `cat` without a `file`, and follows a `sink` when one is active */
88
+ Prints = 2097152,
89
+ /**
90
+ * the result is bounded no matter what flows in: a count, an index, a logical, or one of the values of the
91
+ * argument marked {@link ArgProp.Bounds}. So nothing an argument carries reaches the result, which is what
92
+ * lets the input-sources query stop tracing at `length(x)` or `match.arg(arg, choices)`.
93
+ */
94
+ Narrows = 4194304
95
+ }
96
+ /**
97
+ * The {@link CallProp} bits that state an effect beyond computing a result, so no {@link CallProp.Pure}
98
+ * definition may carry any of them.
99
+ */
100
+ export declare const ImpureProps: number;
101
+ /**
102
+ * Which {@link CallProp} bits rule each other out, as `[bit, everything stating it forbids]`. A definition
103
+ * that carries the left bit must carry none of the right ones; a test checks the {@link DefaultBuiltinConfig}
104
+ * (and any configured built-ins) against this. Every other pair of bits combines freely.
105
+ */
106
+ export declare const ExclusiveCallProps: readonly (readonly [bit: CallProp, forbidden: CallProps])[];
107
+ /**
108
+ * The {@link CallProp} bits of calls that bring in data of their own. A function that states its props and
109
+ * carries none of these derives its result from its arguments, which is what {@link BuiltInIndex#without}
110
+ * looks for.
111
+ */
112
+ export declare const InputProps: number;
113
+ /**
114
+ * The {@link CallProp} bits the signature database states itself, so {@link fnInfoFromSignature} can read them
115
+ * off any package function without anyone writing them down.
116
+ */
117
+ export declare const SigDbInferable: number;
118
+ /**
119
+ * The {@link CallProp} bits that say a call takes its data from a file, as {@link CallProp.File} alone also
120
+ * covers the calls that only write one.
121
+ */
122
+ export declare const FileInputProps: number;
123
+ /**
124
+ * The {@link CallProp} bits that carry over from a callee to its caller: what the called function does, the
125
+ * calling one does too. Purity does not travel this way, which is why it is not in here.
126
+ */
127
+ export declare const PropagatedProps: number;
128
+ /** a bitfield of {@link ArgProp} */
129
+ export type ArgProps = number;
130
+ /** a bitfield of {@link CallProp} */
131
+ export type CallProps = number;
132
+ /**
133
+ * The formals of a built-in, in the order they are declared in, each with what its argument is used for.
134
+ * A `...` entry stands for every argument from the position it appears at, and the entries behind it are matched
135
+ * by their full name only.
136
+ */
137
+ export type FnSig = [name: string, props: ArgProps][];
138
+ /**
139
+ * Semantics of a built-in that hold no matter which processor handles the call. The remaining facts already
140
+ * have a home: the exit behavior in `cfg`, whether flowR can fold the call in the `evalHandler` of the
141
+ * definition, and the fallback for everything unmodelled in `hasUnknownSideEffects`.
142
+ */
143
+ export interface BuiltInFnInfo {
144
+ /** the parameters and what each of their arguments is used for */
145
+ readonly sig?: FnSig;
146
+ /** bitfield of {@link CallProp} */
147
+ readonly props?: CallProps;
148
+ }
149
+ /** A {@link FnSig} in the form the call processors use it, see {@link sigLayout}. */
150
+ export interface SigLayout {
151
+ /** the props of each declared parameter, in order */
152
+ readonly props: readonly ArgProps[];
153
+ /** the position of the `...` parameter, `-1` if there is none */
154
+ readonly rest: number;
155
+ /** every bit some parameter carries, so a call can skip the bits nobody uses */
156
+ readonly any: ArgProps;
157
+ /** the position of the {@link ArgProp.Alias} argument, handed back as the result, `-1` if there is none */
158
+ readonly alias: number;
159
+ }
160
+ /**
161
+ * The positional view of a {@link FnSig}, computed on first use and cached per signature object,
162
+ * so declaring a signature costs nothing until a call actually needs it.
163
+ */
164
+ export declare function sigLayout(sig: FnSig): SigLayout;
165
+ /** The {@link ArgProp} bits of the argument at `index`, with `...` covering every position from where it appears. */
166
+ export declare function argProp({ props, rest }: SigLayout, index: number): ArgProps;
167
+ /** The positions of the first `count` arguments that carry any of `prop`. */
168
+ export declare function argsWith(layout: SigLayout, count: number, prop: ArgProps): number[];
169
+ /**
170
+ * The part of a {@link BuiltInFnInfo} that the signature database already knows: the parameter names in order
171
+ * (`...` included) with the ones R always forces, plus the properties listed in {@link SigDbProps}. Everything
172
+ * else the database records (`higher-order`, `deprecated`, `recursive`, ...) has no counterpart here and is
173
+ * dropped, and anything it cannot see (purity, resources, what an argument is used for) stays unset.
174
+ */
175
+ export declare function fnInfoFromSignature(fn: DecodedFunction): BuiltInFnInfo;