@eagleoutice/flowr 2.17.12 → 2.17.14

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 (115) hide show
  1. package/README.md +15 -15
  2. package/cli/repl/core.js +9 -27
  3. package/config.d.ts +1 -0
  4. package/config.js +4 -2
  5. package/data/r-datasets.generated.js +2 -2
  6. package/dataflow/environments/ambient-effect.d.ts +4 -0
  7. package/dataflow/environments/ambient-effect.js +5 -4
  8. package/dataflow/environments/ambient-state-name.d.ts +2 -2
  9. package/dataflow/environments/ambient-state-name.js +3 -3
  10. package/dataflow/environments/built-in-props.d.ts +5 -0
  11. package/dataflow/environments/default-builtin-config/base-functions.d.ts +1 -1
  12. package/dataflow/environments/default-builtin-config/base-functions.js +6 -2
  13. package/dataflow/environments/default-builtin-config/base-language.d.ts +12 -1
  14. package/dataflow/environments/default-builtin-config/base-language.js +3 -2
  15. package/dataflow/environments/default-builtin-config/guards.js +3 -1
  16. package/dataflow/environments/default-builtin-config/index.d.ts +12 -2
  17. package/dataflow/environments/default-builtin-config/misc-packages.d.ts +1 -1
  18. package/dataflow/environments/default-builtin-config/misc-packages.js +2 -0
  19. package/dataflow/environments/default-builtin-config/shared-configs.d.ts +24 -0
  20. package/dataflow/environments/default-builtin-config/shared-configs.js +8 -6
  21. package/dataflow/environments/pkg-name.d.ts +1 -0
  22. package/dataflow/eval/resolve/alias-tracking.js +11 -12
  23. package/dataflow/extractor.js +58 -0
  24. package/dataflow/fn/guards/built-in-guards.js +4 -4
  25. package/dataflow/fn/guards/call-contracts.js +8 -8
  26. package/dataflow/fn/guards/condition-grouping.js +4 -3
  27. package/dataflow/fn/guards/function-guards.js +103 -97
  28. package/dataflow/fn/guards/group-method-guards.js +10 -8
  29. package/dataflow/fn/guards/guard-claims.js +152 -128
  30. package/dataflow/fn/guards/guard-knowledge.js +19 -18
  31. package/dataflow/fn/guards/guard-term-syntax.js +13 -12
  32. package/dataflow/fn/guards/guard-term.d.ts +71 -0
  33. package/dataflow/fn/guards/guard-term.js +183 -75
  34. package/dataflow/graph/df-helper.d.ts +6 -6
  35. package/dataflow/graph/df-helper.js +1 -1
  36. package/dataflow/graph/graph.d.ts +9 -0
  37. package/dataflow/graph/graph.js +19 -0
  38. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +18 -14
  39. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
  40. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +29 -0
  41. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +2 -1
  42. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -1
  43. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +6 -2
  44. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +9 -2
  45. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +1 -1
  46. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +12 -1
  47. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +24 -6
  48. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +10 -10
  49. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
  50. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +1 -1
  51. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +19 -9
  52. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +35 -3
  53. package/documentation/doc-readme.js +1 -2
  54. package/documentation/doc-util/doc-query.d.ts +1 -1
  55. package/documentation/doc-util/doc-query.js +4 -2
  56. package/documentation/wiki-interface.js +1 -0
  57. package/documentation/wiki-linter.d.ts +2 -0
  58. package/documentation/wiki-linter.js +7 -1
  59. package/documentation/wiki-query.js +28 -0
  60. package/linter/linter-format.d.ts +5 -1
  61. package/linter/linter-format.js +4 -0
  62. package/linter/linter-output.js +18 -16
  63. package/linter/linter-rules.d.ts +50 -0
  64. package/linter/linter-rules.js +5 -1
  65. package/linter/rules/notebook-cell-order.d.ts +43 -0
  66. package/linter/rules/notebook-cell-order.js +97 -0
  67. package/linter/rules/project-entry-point.d.ts +53 -0
  68. package/linter/rules/project-entry-point.js +62 -0
  69. package/linter/rules/undefined-symbol.d.ts +2 -0
  70. package/linter/rules/undefined-symbol.js +6 -1
  71. package/notebook/cell-graph.d.ts +23 -0
  72. package/notebook/cell-graph.js +48 -0
  73. package/notebook/cell-order-mermaid.d.ts +16 -0
  74. package/notebook/cell-order-mermaid.js +51 -0
  75. package/notebook/cell-order.d.ts +270 -0
  76. package/notebook/cell-order.js +1452 -0
  77. package/notebook/cell-split.d.ts +27 -0
  78. package/notebook/cell-split.js +99 -0
  79. package/package.json +1 -1
  80. package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -0
  81. package/project/context/flowr-analyzer-files-context.d.ts +2 -0
  82. package/project/flowr-analyzer.js +5 -1
  83. package/project/plugins/file-plugins/files/cell-runner.d.ts +22 -0
  84. package/project/plugins/file-plugins/files/cell-runner.js +32 -0
  85. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +4 -0
  86. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +22 -6
  87. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +22 -0
  88. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +63 -7
  89. package/project/plugins/file-plugins/files/flowr-rsession-file.d.ts +2 -0
  90. package/project/plugins/file-plugins/files/flowr-rsession-file.js +2 -0
  91. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +3 -5
  92. package/project/plugins/file-plugins/files/flowr-sweave-file.js +6 -0
  93. package/project/plugins/file-plugins/files/recorded-runs.d.ts +2 -0
  94. package/queries/catalog/aliases-query/aliases-query-executor.d.ts +6 -0
  95. package/queries/catalog/aliases-query/aliases-query-executor.js +108 -0
  96. package/queries/catalog/aliases-query/aliases-query-format.d.ts +21 -0
  97. package/queries/catalog/aliases-query/aliases-query-format.js +34 -0
  98. package/queries/catalog/cell-order-query/cell-order-query-format.d.ts +81 -0
  99. package/queries/catalog/cell-order-query/cell-order-query-format.js +82 -0
  100. package/queries/catalog/linter-query/linter-query-format.js +2 -1
  101. package/queries/query.d.ts +17 -2
  102. package/queries/query.js +6 -2
  103. package/queries/virtual-query/compound-query.d.ts +1 -1
  104. package/util/flowr-version.d.ts +1 -1
  105. package/util/flowr-version.js +2 -2
  106. package/util/mermaid/ast.js +4 -11
  107. package/util/mermaid/cfg.js +1 -2
  108. package/util/mermaid/dfg.d.ts +5 -0
  109. package/util/mermaid/dfg.js +23 -4
  110. package/util/mermaid/mermaid.d.ts +5 -0
  111. package/util/mermaid/mermaid.js +8 -0
  112. package/util/r-datasets.d.ts +2 -0
  113. package/util/r-datasets.js +3 -0
  114. package/util/text/playground-link.d.ts +2 -2
  115. package/util/text/playground-link.js +2 -2
@@ -62,6 +62,7 @@ const r_unary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-unary
62
62
  const r_access_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
63
63
  const r_pipe_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-pipe");
64
64
  const happens_before_1 = require("../../../control-flow/happens-before");
65
+ const objects_1 = require("../../../util/objects");
65
66
  const guard_claims_1 = require("./guard-claims");
66
67
  /** Nothing is known about why the code was reached, as with a loop body. */
67
68
  const UnknownStep = { holds: guard_term_1.GuardTerm.True, fails: guard_term_1.GuardTerm.True };
@@ -307,7 +308,7 @@ function bindingBesidesDots(vertex, names, graph, terms) {
307
308
  return bindingOfArguments(vertex, vertex.args.filter((a, at) => at < dots || namesFormal(a, names)), names, graph, terms);
308
309
  }
309
310
  /** Whether something the dots hand on bears a name, which only the function holding the dots can tell. */
310
- const DotsBearNames = guard_term_1.GuardTerm.known('!', guard_term_1.GuardTerm.known('is.null', guard_term_1.GuardTerm.known('...names')));
311
+ const DotsBearNames = guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Not, guard_term_1.GuardTerm.known(guard_term_1.GuardFn.IsNull, guard_term_1.GuardTerm.known(guard_term_1.GuardFn.DotsNames)));
311
312
  const DotsBearNamesText = guard_term_1.GuardTerm.render(DotsBearNames);
312
313
  /** Whether the dots of the callee are its own and a call leaves them without a name, as nothing it hands on could bear one: a name not spelled out in full may still end up in them. */
313
314
  function leavesDotsUnnamed(vertex, names, graph) {
@@ -321,14 +322,14 @@ function callBinding(vertex, names, graph, terms) {
321
322
  const besides = bindingBesidesDots(vertex, names, graph, terms);
322
323
  /* with every formal bound and no dots to take more, anything further the dots hand on is an error, so nothing can move */
323
324
  const { binding, absent } = besides?.complete ? besides : bindingOf(vertex, names, graph, terms);
324
- return { binding, absent, ...(besides === undefined ? {} : { besides }), dotsUnnamed: leavesDotsUnnamed(vertex, names, graph) };
325
+ return (0, objects_1.compactRecord)({ binding, absent, besides, dotsUnnamed: leavesDotsUnnamed(vertex, names, graph) });
325
326
  }
326
327
  /**
327
328
  * A condition of a callee in the words of a caller binding its formals by `call`, see {@link callBinding}, with `outer` stating what the callee reads from outside:
328
329
  * `requires` holds for sure, and `unlessNamed`, if the call hands on dots, holds as long as they name nothing.
329
330
  */
330
331
  function atCall(condition, call, outer, facts) {
331
- const asked = call.dotsUnnamed ? guard_term_1.GuardTerm.any(...guard_term_1.GuardTerm.disjuncts(condition).filter(d => guard_term_1.GuardTerm.render(d) !== DotsBearNamesText)) : condition;
332
+ const asked = call.dotsUnnamed ? guard_term_1.GuardTerm.anyOf(guard_term_1.GuardTerm.disjuncts(condition).filter(d => guard_term_1.GuardTerm.render(d) !== DotsBearNamesText)) : condition;
332
333
  const requires = guard_term_1.GuardTerm.substituteCondition(asked, call.binding, outer, facts, call.absent);
333
334
  if (call.besides === undefined || call.besides.complete) {
334
335
  return { requires };
@@ -350,7 +351,7 @@ function statedBy(scope, state, depth = 0) {
350
351
  return term === undefined ? undefined : guard_term_1.GuardTerm.False;
351
352
  }
352
353
  const own = scope.definition.parameters.find(p => p.name.content === term.name);
353
- return own === undefined || own.defaultValue !== undefined || name.lexeme !== term.name ? undefined : guard_term_1.GuardTerm.known('missing', term);
354
+ return own === undefined || own.defaultValue !== undefined || name.lexeme !== term.name ? undefined : guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Missing, term);
354
355
  }
355
356
  };
356
357
  }
@@ -374,7 +375,7 @@ function inlined(id, vertex, scope, state, depth) {
374
375
  const callee = target === undefined || depth >= MaxTermDepth ? undefined : scopeOf(target, state);
375
376
  const single = callee === undefined ? undefined : singleExpression(callee.definition, state);
376
377
  /* a generic hands over to whichever method it dispatches to, what it says itself is no value of the call */
377
- const body = single !== undefined && r_function_call_1.RFunctionCall.isNamed(single) && identifier_1.Identifier.getName(single.functionName.content) === 'UseMethod' ? undefined : single;
378
+ const body = single !== undefined && r_function_call_1.RFunctionCall.isNamed(single) && identifier_1.Identifier.getName(single.functionName.content) === guard_term_1.GuardFn.UseMethod ? undefined : single;
378
379
  const term = callee === undefined || body === undefined ? undefined : termOf(body, callee, state, depth + 1);
379
380
  if (term === undefined || callee === undefined) {
380
381
  return undefined;
@@ -391,8 +392,7 @@ function callTerm(id, fn, args, state) {
391
392
  const known = vertex === undefined ? undefined : knownNameOf(id, vertex, state);
392
393
  /* the package is what the call resolves to, which a function of the program has none of */
393
394
  const pkg = vertex === undefined ? undefined : (known === undefined ? undefined : packageOf(state.facts(known))) ?? identifier_1.Identifier.getNamespace(df_helper_1.Dataflow.qualify(id, state.graph) ?? vertex.name);
394
- const named = { kind: 'call', fn: pkg === undefined || vertex === undefined ? fn : identifier_1.Identifier.getName(vertex.name), args, ...(pkg === undefined ? {} : { pkg }) };
395
- return known === undefined ? named : { ...named, known: true };
395
+ return (0, objects_1.compactRecord)({ kind: 'call', fn: pkg === undefined || vertex === undefined ? fn : identifier_1.Identifier.getName(vertex.name), args, pkg, known: known === undefined ? undefined : true });
396
396
  }
397
397
  /** The expression as a term in the formals of the function it is written in, `undefined` if it depends on what cannot be stated in them, worked out once while nothing has changed what the formals hold. */
398
398
  function termOf(node, scope, state, depth = 0) {
@@ -427,7 +427,7 @@ function termOfUncached(node, scope, state, depth) {
427
427
  return undefined;
428
428
  }
429
429
  /* only a numeric literal, as `-1` is a value */
430
- if (node.operator === '-' && operand.kind === 'constant' && typeof operand.value === 'number') {
430
+ if (node.operator === guard_term_1.GuardFn.Minus && operand.kind === 'constant' && typeof operand.value === 'number') {
431
431
  return { kind: 'constant', lexeme: `-${operand.lexeme}`, value: -operand.value };
432
432
  }
433
433
  return callTerm(node.info.id, node.operator, [{ value: operand }], state);
@@ -442,7 +442,7 @@ function termOfUncached(node, scope, state, depth) {
442
442
  if (accessed === undefined) {
443
443
  return undefined;
444
444
  }
445
- if (node.operator === '$' || node.operator === '@') {
445
+ if (node.operator === guard_term_1.GuardFn.Dollar || node.operator === guard_term_1.GuardFn.At) {
446
446
  const [field] = node.access;
447
447
  const lexeme = field.value?.lexeme;
448
448
  return lexeme === undefined ? undefined : callTerm(node.info.id, node.operator, [{ value: accessed }, { value: { kind: 'constant', lexeme } }], state);
@@ -473,7 +473,7 @@ function termOfUncached(node, scope, state, depth) {
473
473
  }
474
474
  const call = callTerm(node.info.id, identifier_1.Identifier.toString(node.functionName.content), args, state);
475
475
  /* a formal that got a value in the body is not missing anymore */
476
- return guard_term_1.GuardTerm.isCall(call, 'missing') && call.known && (args[0]?.value.kind === 'constant' || guard_term_1.GuardTerm.isCall(args[0]?.value)) ? guard_term_1.GuardTerm.False : call;
476
+ return guard_term_1.GuardTerm.isCall(call, guard_term_1.GuardFn.Missing) && call.known && (args[0]?.value.kind === 'constant' || guard_term_1.GuardTerm.isCall(args[0]?.value)) ? guard_term_1.GuardTerm.False : call;
477
477
  }
478
478
  default:
479
479
  return undefined;
@@ -481,15 +481,15 @@ function termOfUncached(node, scope, state, depth) {
481
481
  }
482
482
  /** Whether a condition only computes on constants, as `is.numeric(1)`: true or not, no call can change that. */
483
483
  function asksNothingOfCalls(term, state) {
484
- return !guard_term_1.GuardTerm.isFalse(term) && guard_term_1.GuardTerm.formalsOf(term).size === 0 && !guard_term_1.GuardTerm.readsFree(term) && isPureTerm(term, state) && !guard_term_1.GuardTerm.mentions(term, 'exists');
484
+ return !guard_term_1.GuardTerm.isFalse(term) && guard_term_1.GuardTerm.formalsOf(term).size === 0 && !guard_term_1.GuardTerm.readsFree(term) && isPureTerm(term, state) && !guard_term_1.GuardTerm.mentions(term, guard_term_1.GuardFn.Exists);
485
485
  }
486
486
  function addClause(run, path, condition, at, extra) {
487
487
  /* what R rejects on a path that has already made sure of it, like `x > 0` after `is.numeric(x) &&`, asks nothing */
488
488
  const reached = path.flatMap(step => guard_term_1.GuardTerm.conjuncts(step.holds));
489
- if (run.scope.frameIsOpen || (extra.kind === 'implicit' && (0, guard_claims_1.impliedBy)(condition, reached, [...run.scope.formals.values()], run.state.facts))) {
489
+ if (run.scope.frameIsOpen || (extra.kind === 'implicit' && (0, guard_claims_1.impliedBy)(condition, reached, run.scope.formals.values().toArray(), run.state.facts))) {
490
490
  return;
491
491
  }
492
- const all = guard_term_1.GuardTerm.any(...path.map(step => step.fails), condition);
492
+ const all = guard_term_1.GuardTerm.anyOf(path.map(step => step.fails).concat(condition));
493
493
  const under = path.map(step => step.holds).filter(holds => !guard_term_1.GuardTerm.isTrue(holds));
494
494
  for (const requires of guard_term_1.GuardTerm.conjuncts(all)) {
495
495
  if (guard_term_1.GuardTerm.isTrue(requires) || asksNothingOfCalls(requires, run.state)) {
@@ -500,7 +500,7 @@ function addClause(run, path, condition, at, extra) {
500
500
  const pure = (extra.pure ?? true) && !run.effects;
501
501
  /* the same condition may come up again in a place that is purer than where it was seen first */
502
502
  if (known === undefined || (!known.pure && pure)) {
503
- run.clauses.set(rendered, { requires, rendered, at, ...extra, pure, ...(under.length > 0 ? { under } : {}) });
503
+ run.clauses.set(rendered, (0, objects_1.compactRecord)({ requires, rendered, at, ...extra, pure, under: (0, objects_1.nonEmpty)(under) }));
504
504
  }
505
505
  }
506
506
  }
@@ -540,11 +540,11 @@ function mayReturnOnExit(definition) {
540
540
  const callees = new Set();
541
541
  let found = false;
542
542
  model_1.RNode.visitAst(definition.body, node => {
543
- if (r_function_call_1.RFunctionCall.isNamed(node, 'on.exit')) {
543
+ if (r_function_call_1.RFunctionCall.isNamed(node, guard_term_1.GuardFn.OnExit)) {
544
544
  callees.add(node.functionName.info.id);
545
- found ||= node.arguments.some(a => a !== r_function_call_1.EmptyArgument && a.value !== undefined && hasSymbol(a.value, 'return'));
545
+ found ||= node.arguments.some(a => a !== r_function_call_1.EmptyArgument && a.value !== undefined && hasSymbol(a.value, guard_term_1.GuardFn.Return));
546
546
  }
547
- else if ((r_symbol_1.RSymbol.is(node) && !callees.has(node.info.id) && identifier_1.Identifier.getName(node.content) === 'on.exit') || (r_string_1.RString.is(node) && node.content.str === 'on.exit')) {
547
+ else if ((r_symbol_1.RSymbol.is(node) && !callees.has(node.info.id) && identifier_1.Identifier.getName(node.content) === guard_term_1.GuardFn.OnExit) || (r_string_1.RString.is(node) && node.content.str === guard_term_1.GuardFn.OnExit)) {
548
548
  found = true;
549
549
  }
550
550
  });
@@ -570,7 +570,7 @@ function stepsOf(term, facts, fn) {
570
570
  if (term === undefined) {
571
571
  return [UnknownStep, UnknownStep];
572
572
  }
573
- const leading = guard_term_1.GuardTerm.firstOnly(facts, fn, fn === 'if' ? 'cond' : 'x');
573
+ const leading = guard_term_1.GuardTerm.firstOnly(facts, fn, fn === guard_term_1.GuardFn.If ? 'cond' : 'x');
574
574
  const [holds, fails] = [guard_term_1.GuardTerm.truth(term, true, facts, false, leading), guard_term_1.GuardTerm.truth(term, false, facts, false, leading)];
575
575
  return [{ holds, fails }, { holds: fails, fails: holds }];
576
576
  }
@@ -632,7 +632,7 @@ function closureMissingOk(name, formals, facts) {
632
632
  return [];
633
633
  }
634
634
  const asked = Object.entries(facts?.asks ?? {}).filter(([, failures]) => failures.some(f => f.when === undefined)).map(([formal]) => formal);
635
- const evaluated = new Set([...asked, ...stored?.required ?? [], ...stored?.dispatches === undefined ? [] : [String(stored.dispatches)]]);
635
+ const evaluated = new Set(asked.concat(stored?.required ?? [], stored?.dispatches === undefined ? [] : [String(stored.dispatches)]));
636
636
  return formals.filter(f => !evaluated.has(String(f)));
637
637
  }
638
638
  /** The arguments handed over which R evaluates for sure, in the order they are written, and those it may not. */
@@ -646,7 +646,7 @@ function evaluatedAndNot(vertex, state) {
646
646
  /* a special primitive matching its arguments itself takes a missing formal handed to some of its own as not given */
647
647
  const name = identifier_1.Identifier.getName(vertex.name);
648
648
  const facts = state.facts(name);
649
- const missingOk = [...facts?.missingOk ?? [], ...closureMissingOk(name, sig.map(([formal]) => formal), facts)];
649
+ const missingOk = (facts?.missingOk ?? []).concat(closureMissingOk(name, sig.map(([formal]) => formal), facts));
650
650
  const forcedIds = new Set(sig.filter(([, props]) => (props & built_in_props_1.ArgProp.Forced) !== 0).flatMap(([formal]) => (bound.get(formal) ?? []).filter(v => !missingOk.includes(formal) || !r_symbol_1.RSymbol.is(v))));
651
651
  return { forced: values.filter(v => forcedIds.has(v)), lazy: values.filter(v => !forcedIds.has(v)) };
652
652
  }
@@ -671,7 +671,7 @@ function builtInRequirements(name, vertex, path, run) {
671
671
  if (asks === undefined && facts?.recycles === undefined) {
672
672
  return;
673
673
  }
674
- const stated = [...Object.keys(asks ?? {}), ...(facts?.recycles ?? []).flatMap(r => [...r.among, ...[r.to, r.unless].filter(f => f !== undefined)])];
674
+ const stated = Object.keys(asks ?? {}).concat((facts?.recycles ?? []).flatMap(r => r.among.concat([r.to, r.unless].filter(f => f !== undefined))));
675
675
  const bound = boundArguments(vertex, state.info(vertex.name)?.sig?.map(([formal]) => formal) ?? (0, arrays_1.uniqueArray)(stated), state);
676
676
  const termOfNode = (n) => termOf(n, scope, state);
677
677
  recyclingRequirements(facts?.recycles ?? [], facts?.masks === true, bound, termOfNode, vertex, path, run);
@@ -679,7 +679,7 @@ function builtInRequirements(name, vertex, path, run) {
679
679
  return;
680
680
  }
681
681
  /* an operator also dispatches on its other operand, which has to be stated to be ruled out */
682
- const operands = Object.keys(asks).length === 2 ? [...bound.values()].flat() : [];
682
+ const operands = Object.keys(asks).length === 2 ? bound.values().flatMap(values => values).toArray() : [];
683
683
  /* what another formal was handed, as far as it is one of the caller's, as a literal would only spell out what is known of it */
684
684
  const formals = formal => {
685
685
  const values = bound.get(formal) ?? [];
@@ -747,7 +747,7 @@ function maskedNames(vertex, termOfNode, graph) {
747
747
  * a formal of that name the function never binds anew, whose value is what it was handed wherever the call is.
748
748
  */
749
749
  function maskedFormal(name, scope, state) {
750
- if (scope.frameIsOpen || !isFormalName(name, scope) || [...scope.formals].some(([id, formal]) => formal === name && scope.drifting.has(id))) {
750
+ if (scope.frameIsOpen || !isFormalName(name, scope) || scope.formals.entries().some(([id, formal]) => formal === name && scope.drifting.has(id))) {
751
751
  return undefined;
752
752
  }
753
753
  const rebinds = scope.vertex.subflow.graph.values().some(id => {
@@ -808,7 +808,7 @@ function groupMethodRequirements(name, asks, bound, termOfNode, vertex, path, ru
808
808
  const term = values.length === 1 ? termOfNode(values[0]) : undefined;
809
809
  return term?.kind === 'formal' || term?.kind === 'constant' ? term : undefined;
810
810
  });
811
- const excluded = new Set([...run.state.methodClasses(name), ...run.state.methodClasses(group)]);
811
+ const excluded = new Set(run.state.methodClasses(name).concat(run.state.methodClasses(group)));
812
812
  for (const condition of (0, group_method_guards_1.groupMethodConditions)(name, operands, excluded, run.state.facts)) {
813
813
  addClause(run, path, condition, vertex.id, { kind: 'implicit' });
814
814
  }
@@ -821,7 +821,7 @@ function isDefined(name, state) {
821
821
  function getRequirement(node, path, run) {
822
822
  const term = termOf(node, run.scope, run.state);
823
823
  if (guard_term_1.GuardTerm.isCall(term) && term.args.length > 0 && ((0, guard_knowledge_1.composesName)(term.args[0].value) || term.args[0].value.kind === 'formal')) {
824
- addClause(run, path, (0, guard_knowledge_1.getAsExists)({ ...term, fn: 'get' }), node.info.id, { kind: 'implicit' });
824
+ addClause(run, path, (0, guard_knowledge_1.getAsExists)({ ...term, fn: guard_term_1.GuardFn.Get }), node.info.id, { kind: 'implicit' });
825
825
  }
826
826
  }
827
827
  /** A check that only fails for an argument that was not given asks `missing` of what it is handed, as any callee does, see {@link statedBy}. */
@@ -876,7 +876,7 @@ function inherit(target, vertex, path, run) {
876
876
  return name === undefined ? undefined : guard_term_1.GuardTerm.formal(name);
877
877
  }
878
878
  for (const clause of contract.clauses) {
879
- const inherited = { kind: clause.kind, pure: clause.pure, via: [vertex.id, ...clause.via ?? []], ...(clause.message === undefined ? {} : { message: clause.message }) };
879
+ const inherited = { kind: clause.kind, pure: clause.pure, via: [vertex.id, ...clause.via ?? []], message: clause.message };
880
880
  const { requires, unlessNamed } = atCall(clause.requires, call, outer, state.facts);
881
881
  if (guard_term_1.GuardTerm.formalsOf(requires).size > 0 || guard_term_1.GuardTerm.isFalse(requires)) {
882
882
  addClause(run, path, requires, clause.at, inherited);
@@ -911,7 +911,7 @@ function definitionsNamed(name, state) {
911
911
  /** The methods of the generic a value without a class attribute may run, found by their names, `undefined` if one of them may come from outside the program. */
912
912
  function unclassedMethods(generic, state) {
913
913
  const methods = [];
914
- for (const cls of [...guard_knowledge_1.ImplicitClasses, 'default']) {
914
+ for (const cls of guard_knowledge_1.ImplicitClasses.concat('default')) {
915
915
  const name = `${generic}.${cls}`;
916
916
  const own = definitionsNamed(name, state);
917
917
  if (own === undefined || (own.length === 0 && (state.info(name) !== undefined || (0, r_base_packages_1.baseRExportOwner)(name) !== undefined))) {
@@ -927,7 +927,7 @@ function knowsClasses(dispatch) {
927
927
  }
928
928
  /** How many calls deep the narrowing of the dispatch per call goes, see {@link Contract.reach}: one for a `NextMethod`, which the dispatch running its method may decide. */
929
929
  function reachOf(dispatch) {
930
- const depth = (perCall) => perCall === undefined ? 0 : 1 + Math.max(0, ...perCall.map(p => depth(p.within)));
930
+ const depth = (perCall) => perCall === undefined ? 0 : 1 + perCall.reduce((deepest, p) => Math.max(deepest, depth(p.within)), 0);
931
931
  return Math.max(depth(dispatch.ruledOutAt), vertex_1.DfgVertex.hasOrigin(dispatch, built_in_proc_name_1.BuiltInProcName.S3DispatchNext) ? 1 : 0);
932
932
  }
933
933
  /**
@@ -977,7 +977,7 @@ const MaxJoined = 64;
977
977
  /** What holds whichever of the methods ran, given the clauses of each: one clause of each as alternatives, or, as those grow fast, the clauses all of them share. */
978
978
  function joined(of) {
979
979
  if (of.reduce((n, clauses) => n * clauses.length, 1) <= MaxJoined) {
980
- return of.slice(1).reduce((acc, clauses) => acc.flatMap(a => clauses.map(c => ({ ...a, requires: guard_term_1.GuardTerm.any(a.requires, c.requires), pure: a.pure && c.pure }))), [...of[0]]);
980
+ return of.slice(1).reduce((acc, clauses) => acc.flatMap(a => clauses.map(c => ({ ...a, requires: guard_term_1.GuardTerm.any(a.requires, c.requires), pure: a.pure && c.pure }))), of[0]);
981
981
  }
982
982
  const shared = of.slice(1).map(clauses => new Set(clauses.map(c => guard_term_1.GuardTerm.render(c.requires))));
983
983
  return of[0].filter(c => shared.every(s => s.has(guard_term_1.GuardTerm.render(c.requires))));
@@ -994,9 +994,9 @@ function addMethodContracts(methods, bindingOfMethod, at, via, unless, path, run
994
994
  return;
995
995
  }
996
996
  for (const clause of joined(contracts)) {
997
- const requires = guard_term_1.GuardTerm.any(...unless, clause.requires);
997
+ const requires = guard_term_1.GuardTerm.anyOf(unless.concat(clause.requires));
998
998
  if (guard_term_1.GuardTerm.formalsOf(clause.requires).size > 0 || guard_term_1.GuardTerm.isFalse(clause.requires)) {
999
- addClause(run, path, requires, clause.at, { kind: clause.kind, pure: clause.pure, via: [at, ...clause.via ?? []], ...(clause.message === undefined ? {} : { message: clause.message }) });
999
+ addClause(run, path, requires, clause.at, { kind: clause.kind, pure: clause.pure, via: [at, ...clause.via ?? []], message: clause.message });
1000
1000
  }
1001
1001
  }
1002
1002
  }
@@ -1018,7 +1018,7 @@ function dispatchedContracts(node, dispatch, unclassed, path, run) {
1018
1018
  return;
1019
1019
  }
1020
1020
  const changed = unclassed === undefined ? reboundFormals(scope, state) : new Set();
1021
- const unless = decided !== undefined || unclassed === undefined ? [] : [guard_term_1.GuardTerm.known('is.object', guard_term_1.GuardTerm.formal(unclassed.object))];
1021
+ const unless = decided !== undefined || unclassed === undefined ? [] : [guard_term_1.GuardTerm.known(guard_term_1.GuardFn.IsObject, guard_term_1.GuardTerm.formal(unclassed.object))];
1022
1022
  addMethodContracts(methods, callee => dispatchBinding(scope, callee, changed), node.info.id, dispatch === undefined ? [] : viaCall(dispatch.id, run), unless, path, run);
1023
1023
  }
1024
1024
  /** What flowR can say about the `UseMethod` of the function: it has to find a method, and what that asks. */
@@ -1037,7 +1037,7 @@ function dispatchRequirement(node, path, run) {
1037
1037
  if (name === undefined || first === undefined || first.special || state.bindsFunction(`${name}.default`) || state.info(`${name}.default`) !== undefined) {
1038
1038
  return;
1039
1039
  }
1040
- const call = { kind: 'call', fn: 'UseMethod', known: true, args: [{ value: guard_term_1.GuardTerm.string(name) }, { value: guard_term_1.GuardTerm.formal(first.name.content) }] };
1040
+ const call = { kind: 'call', fn: guard_term_1.GuardFn.UseMethod, known: true, args: [{ value: guard_term_1.GuardTerm.string(name) }, { value: guard_term_1.GuardTerm.formal(first.name.content) }] };
1041
1041
  addClause(run, path, (0, guard_knowledge_1.succeeds)(call), node.info.id, { kind: 'implicit' });
1042
1042
  }
1043
1043
  /** The S4 methods of the program by generic, found once per run. */
@@ -1058,8 +1058,8 @@ function operatorMethods(name, vertex, path, run) {
1058
1058
  }
1059
1059
  const terms = operands;
1060
1060
  const bound = (callee) => bindingOf(vertex, formalNamesOf(callee), state.graph, statedBy(scope, state)).binding;
1061
- const unclassed = (others) => others.filter(o => o.kind !== 'constant').map(o => guard_term_1.GuardTerm.known('is.object', o));
1062
- const classes = new Set([...state.methodClasses(name), ...state.methodClasses(group)]);
1061
+ const unclassed = (others) => others.filter(o => o.kind !== 'constant').map(o => guard_term_1.GuardTerm.known(guard_term_1.GuardFn.IsObject, o));
1062
+ const classes = new Set(state.methodClasses(name).concat(state.methodClasses(group)));
1063
1063
  if (s4.length === 0) {
1064
1064
  for (const cls of classes) {
1065
1065
  const own = definitionsNamed(`${name}.${cls}`, state);
@@ -1069,15 +1069,15 @@ function operatorMethods(name, vertex, path, run) {
1069
1069
  if (operand.kind === 'constant') {
1070
1070
  continue;
1071
1071
  }
1072
- const notOfClass = guard_term_1.GuardTerm.known('!', guard_term_1.GuardTerm.known('identical', guard_term_1.GuardTerm.known('oldClass', operand), guard_term_1.GuardTerm.string(cls)));
1073
- addMethodContracts(methods ?? [], bound, vertex.id, [], [notOfClass, ...group === 'Ops' ? unclassed(terms.filter((_, i) => i !== at)) : []], path, run);
1072
+ const notOfClass = guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Not, guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Identical, guard_term_1.GuardTerm.known(guard_term_1.GuardFn.OldClass, operand), guard_term_1.GuardTerm.string(cls)));
1073
+ addMethodContracts(methods ?? [], bound, vertex.id, [], [notOfClass].concat(group === 'Ops' ? unclassed(terms.filter((_, i) => i !== at)) : []), path, run);
1074
1074
  }
1075
1075
  }
1076
1076
  }
1077
1077
  else if (s4.length === 1 && classes.size === 0 && s4[0].signature !== undefined && s4[0].signature.length <= terms.length && s4[0].signature.every(e => e.name === undefined && e.cls !== 'missing')) {
1078
- const notS4 = guard_term_1.GuardTerm.all(...terms.map(t => guard_term_1.GuardTerm.known('!', guard_term_1.GuardTerm.known('isS4', t))));
1079
- const notOf = s4[0].signature.flatMap((e, at) => e.cls === 'ANY' ? [] : [guard_term_1.GuardTerm.known('!', guard_term_1.GuardTerm.known('is', terms[at], guard_term_1.GuardTerm.string(String(e.cls))))]);
1080
- addMethodContracts(s4[0].functions, bound, vertex.id, [], [notS4, ...notOf], path, run);
1078
+ const notS4 = guard_term_1.GuardTerm.allOf(terms.map(t => guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Not, guard_term_1.GuardTerm.known('isS4', t))));
1079
+ const notOf = s4[0].signature.flatMap((e, at) => e.cls === 'ANY' ? [] : [guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Not, guard_term_1.GuardTerm.known('is', terms[at], guard_term_1.GuardTerm.string(String(e.cls))))]);
1080
+ addMethodContracts(s4[0].functions, bound, vertex.id, [], [notS4].concat(notOf), path, run);
1081
1081
  }
1082
1082
  }
1083
1083
  /** `FUN(x)` for a formal `FUN`: a formal not holding a function makes R look for a function of the same name. */
@@ -1129,10 +1129,11 @@ function branchPathsOf(state) {
1129
1129
  /** Whether the node runs in the body of a loop of the function. */
1130
1130
  function inLoopOf(node, { state, scope }) {
1131
1131
  const idMap = state.graph.idMap;
1132
- return node !== undefined && [node, ...model_1.RNode.iterateParents(node, idMap)].some(n => {
1132
+ const isLoopBody = (n) => {
1133
1133
  const parent = model_1.RNode.directParent(n, idMap);
1134
1134
  return (r_for_loop_1.RForLoop.is(parent) || r_while_loop_1.RWhileLoop.is(parent) || r_repeat_loop_1.RRepeatLoop.is(parent)) && parent.body === n && within(parent, scope.definition.body, state);
1135
- });
1135
+ };
1136
+ return node !== undefined && (isLoopBody(node) || model_1.RNode.iterateParents(node, idMap).some(isLoopBody));
1136
1137
  }
1137
1138
  /**
1138
1139
  * Whether only blocks and the branches of `if`s lie between the node and the body, which the paths to what comes after tell apart:
@@ -1177,17 +1178,17 @@ function stepOf({ cause, when, target }, node, run) {
1177
1178
  if (other !== undefined && !within(node, construct, state) && alwaysFails(other, state)) {
1178
1179
  return undefined;
1179
1180
  }
1180
- return pick(termOf(construct.condition, scope, state), 'if');
1181
+ return pick(termOf(construct.condition, scope, state), guard_term_1.GuardFn.If);
1181
1182
  }
1182
1183
  else if (r_for_loop_1.RForLoop.is(construct) || r_while_loop_1.RWhileLoop.is(construct) || r_repeat_loop_1.RRepeatLoop.is(construct)) {
1183
1184
  /* what comes after a loop is reached either way, what runs within it is known nothing of, and a `return` in it is an exit of its own, see {@link pathsAt} */
1184
1185
  return undefined;
1185
1186
  }
1186
- else if (r_binary_op_1.RBinaryOp.is(construct) && (construct.operator === '&&' || construct.operator === '||')) {
1187
+ else if (r_binary_op_1.RBinaryOp.is(construct) && (construct.operator === guard_term_1.GuardFn.And || construct.operator === guard_term_1.GuardFn.Or)) {
1187
1188
  /* the left operand decides whether the right one runs, and nothing after */
1188
1189
  return within(node, construct.rhs, state) ? pick(termOf(construct.lhs, scope, state), construct.operator) : undefined;
1189
1190
  }
1190
- else if (r_function_call_1.RFunctionCall.is(construct) && knownNameOf(cause, callVertexOf(cause, state), state) === 'switch') {
1191
+ else if (r_function_call_1.RFunctionCall.is(construct) && knownNameOf(cause, callVertexOf(cause, state), state) === guard_term_1.GuardFn.Switch) {
1191
1192
  /* what comes after it was reached through whichever alternative did not leave, of which nothing is known */
1192
1193
  return within(node, construct, state) ? switchStep(construct, when ? target : undefined, run) : UnknownStep;
1193
1194
  }
@@ -1202,8 +1203,8 @@ function switchStep(node, entered, run) {
1202
1203
  const [selector, ...alternatives] = node.arguments;
1203
1204
  const term = selector === undefined || selector === r_function_call_1.EmptyArgument || selector.value === undefined ? undefined : termOf(selector.value, scope, state);
1204
1205
  const names = alternatives.flatMap(a => a === r_function_call_1.EmptyArgument || a.name === undefined ? [] : [guard_term_1.GuardTerm.string(String(a.name.content))]);
1205
- const notString = term === undefined ? guard_term_1.GuardTerm.True : guard_term_1.GuardTerm.known('!', guard_term_1.GuardTerm.known('is.character', term));
1206
- const isAny = (of) => term === undefined ? guard_term_1.GuardTerm.True : guard_term_1.GuardTerm.known('%in%', term, of.length === 1 ? of[0] : guard_term_1.GuardTerm.known('c', ...of));
1206
+ const notString = term === undefined ? guard_term_1.GuardTerm.True : guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Not, guard_term_1.GuardTerm.known(guard_term_1.GuardFn.IsCharacter, term));
1207
+ const isAny = (of) => term === undefined ? guard_term_1.GuardTerm.True : guard_term_1.GuardTerm.known(guard_term_1.GuardFn.In, term, of.length === 1 ? of[0] : guard_term_1.GuardTerm.knownOf(guard_term_1.GuardFn.Combine, of));
1207
1208
  const selected = term?.kind === 'constant' && typeof term.value === 'string' ? term.value : undefined;
1208
1209
  const enteredNode = entered === undefined ? undefined : nodeOf(entered, state);
1209
1210
  let falling = [];
@@ -1212,11 +1213,13 @@ function switchStep(node, entered, run) {
1212
1213
  continue;
1213
1214
  }
1214
1215
  const name = alternative.name === undefined ? undefined : guard_term_1.GuardTerm.string(String(alternative.name.content));
1216
+ if (name !== undefined) {
1217
+ falling.push(name);
1218
+ }
1215
1219
  if (alternative.value === undefined) {
1216
- falling = name === undefined ? falling : [...falling, name];
1217
1220
  continue;
1218
1221
  }
1219
- const reachedBy = name === undefined ? undefined : [...falling, name];
1222
+ const reachedBy = name === undefined ? undefined : falling;
1220
1223
  falling = [];
1221
1224
  if (enteredNode === undefined || !within(enteredNode, alternative.value, state)) {
1222
1225
  continue;
@@ -1224,7 +1227,7 @@ function switchStep(node, entered, run) {
1224
1227
  /* a literal string selects the alternative right away, as in a method with `.Generic` spelled out */
1225
1228
  const fails = selected !== undefined ? ((reachedBy ?? names).some(n => guard_term_1.GuardTerm.constantString(n) === selected) === (reachedBy !== undefined) ? guard_term_1.GuardTerm.False : guard_term_1.GuardTerm.True)
1226
1229
  : reachedBy === undefined ? guard_term_1.GuardTerm.any(notString, isAny(names))
1227
- : guard_term_1.GuardTerm.any(notString, guard_term_1.GuardTerm.known('!', isAny(reachedBy)));
1230
+ : guard_term_1.GuardTerm.any(notString, guard_term_1.GuardTerm.known(guard_term_1.GuardFn.Not, isAny(reachedBy)));
1228
1231
  return { holds: guard_term_1.GuardTerm.True, fails: names.length === 0 ? guard_term_1.GuardTerm.True : fails };
1229
1232
  }
1230
1233
  /* no alternative was taken: the selector names none of them */
@@ -1261,7 +1264,7 @@ function pathsAt(node, run) {
1261
1264
  if (order.unsureExits.size > 0 && (order.before(order.unsureExits, node.info.id).length > 0 || order.unsureExits.values().some(exit => positionOf(exit, run.state) < at))) {
1262
1265
  exits.push(UnknownStep);
1263
1266
  }
1264
- return stepsTo(node, run)?.map(({ path, skips }) => ({ path: [...path, ...exits], skips }));
1267
+ return stepsTo(node, run)?.map(({ path, skips }) => ({ path: path.concat(exits), skips }));
1265
1268
  }
1266
1269
  /**
1267
1270
  * What the control flow does not tell of a way out before `exit`: as it may have left the function there (a call of what may be
@@ -1269,7 +1272,7 @@ function pathsAt(node, run) {
1269
1272
  */
1270
1273
  function exitStep(exit, run) {
1271
1274
  const paths = stepsTo(nodeOf(exit, run.state), run);
1272
- return paths?.length === 1 ? { holds: guard_term_1.GuardTerm.True, fails: guard_term_1.GuardTerm.all(...paths[0].path.map(step => step.holds)) } : UnknownStep;
1275
+ return paths?.length === 1 ? { holds: guard_term_1.GuardTerm.True, fails: guard_term_1.GuardTerm.allOf(paths[0].path.map(step => step.holds)) } : UnknownStep;
1273
1276
  }
1274
1277
  /** Whether the condition the branch takes its way by can be stated, without which which way it went tells nothing apart. */
1275
1278
  function statesCondition(cause, run) {
@@ -1285,10 +1288,10 @@ function stepsTo(node, run) {
1285
1288
  const looped = inLoopOf(node, run);
1286
1289
  /* what flowR cannot tell how it is reached is reached in a way nothing is known of */
1287
1290
  return (found ?? [[]]).map(steps => {
1288
- const sorted = [...steps].sort((a, b) => positionOf(a.cause, state) - positionOf(b.cause, state));
1291
+ const sorted = steps.toSorted((a, b) => positionOf(a.cause, state) - positionOf(b.cause, state));
1289
1292
  const skips = untaken(sorted, state);
1290
1293
  scope.skips = skips;
1291
- const path = [...sorted.map(step => stepOf(step, node, run)).filter(assert_1.isNotUndefined), ...looped || found === undefined ? [UnknownStep] : []];
1294
+ const path = sorted.map(step => stepOf(step, node, run)).filter(assert_1.isNotUndefined).concat(looped || found === undefined ? [UnknownStep] : []);
1292
1295
  scope.skips = new Set();
1293
1296
  return { path, skips };
1294
1297
  });
@@ -1312,12 +1315,12 @@ function orderOf(run) {
1312
1315
  unsureExits.add(id);
1313
1316
  }
1314
1317
  }
1315
- else if (vertex !== undefined && isHandedOver(node) && knownNameOf(id, vertex, state) === 'return') {
1318
+ else if (vertex !== undefined && isHandedOver(node) && knownNameOf(id, vertex, state) === guard_term_1.GuardFn.Return) {
1316
1319
  /* `do.call(return, .)` */
1317
1320
  unsureExits.add(id);
1318
1321
  }
1319
1322
  /* what names the generic of a `UseMethod` is no call of its own, whatever the dataflow turns it into */
1320
- if (vertex !== undefined && knownNameOf(id, vertex, state) === 'UseMethod' && r_function_call_1.RFunctionCall.is(node)) {
1323
+ if (vertex !== undefined && knownNameOf(id, vertex, state) === guard_term_1.GuardFn.UseMethod && r_function_call_1.RFunctionCall.is(node)) {
1321
1324
  node.arguments.forEach(a => a !== r_function_call_1.EmptyArgument && a.value !== undefined && model_1.RNode.collectAllIds(a.value).forEach(i => inUseMethod.add(i)));
1322
1325
  }
1323
1326
  /* a name standing for a call, as the generic `UseMethod` names stands for the dispatch, does nothing of its own */
@@ -1339,7 +1342,7 @@ function orderOf(run) {
1339
1342
  return vertex !== undefined && !r_symbol_1.RSymbol.is(nodeOf(id, state)) && !onlyComputes(id, vertex, state);
1340
1343
  }));
1341
1344
  const cfg = branchPathsOf(state).controlFlow.graph;
1342
- return { effects, openers, effectfulDefaults, exits: new Set(exits), unsureExits, exitStep: (0, defaultmap_1.memoize)((exit) => exitStep(exit, run)), before: (candidates, node) => [...(0, happens_before_1.happensBeforeEach)(cfg, candidates, node).keys()].filter(c => c !== node) };
1345
+ return { effects, openers, effectfulDefaults, exits: new Set(exits), unsureExits, exitStep: (0, defaultmap_1.memoize)((exit) => exitStep(exit, run)), before: (candidates, node) => (0, happens_before_1.happensBeforeEach)(cfg, candidates, node).keys().filter(c => c !== node).toArray() };
1343
1346
  }
1344
1347
  /** Each path to the node, with what flowR cannot tell how the node is reached left without any. */
1345
1348
  function eachPath(node, run, fn) {
@@ -1399,19 +1402,19 @@ function guardVisitor() {
1399
1402
  const name = knownNameOf(id, vertex, state);
1400
1403
  const condition = (construct, part, decides) => this.evaluated.set(decides.info.id, () => eachPath(decides, run, path => conditionRequirement(construct, part, decides, path, run)));
1401
1404
  if (r_if_then_else_1.RIfThenElse.is(node)) {
1402
- condition('if', 'cond', node.condition);
1405
+ condition(guard_term_1.GuardFn.If, 'cond', node.condition);
1403
1406
  return;
1404
1407
  }
1405
1408
  else if (r_for_loop_1.RForLoop.is(node) || r_while_loop_1.RWhileLoop.is(node)) {
1406
1409
  if (r_for_loop_1.RForLoop.is(node) && runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.ForLoop)) {
1407
- condition('for', 'seq', node.vector);
1410
+ condition(guard_term_1.GuardFn.For, 'seq', node.vector);
1408
1411
  }
1409
1412
  else if (r_while_loop_1.RWhileLoop.is(node) && runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
1410
- condition('while', 'cond', node.condition);
1413
+ condition(guard_term_1.GuardFn.While, 'cond', node.condition);
1411
1414
  }
1412
1415
  return;
1413
1416
  }
1414
- else if (r_binary_op_1.RBinaryOp.is(node) && (node.operator === '&&' || node.operator === '||') && name !== undefined) {
1417
+ else if (r_binary_op_1.RBinaryOp.is(node) && (node.operator === guard_term_1.GuardFn.And || node.operator === guard_term_1.GuardFn.Or) && name !== undefined) {
1415
1418
  /* the path already states what makes R look at the right operand */
1416
1419
  const operand = (formal) => {
1417
1420
  return (state.facts(node.operator)?.asks?.[formal] ?? []).map(({ when: _, ...failure }) => failure);
@@ -1435,14 +1438,14 @@ function guardVisitor() {
1435
1438
  conditions?.forEach(expression => this.evaluated.set(expression.info.id, () => conditionClause(expression, asserting === undefined, run)));
1436
1439
  return;
1437
1440
  }
1438
- else if (call !== undefined && name === 'switch') {
1441
+ else if (call !== undefined && name === guard_term_1.GuardFn.Switch) {
1439
1442
  const [selector] = call.arguments;
1440
1443
  if (selector !== r_function_call_1.EmptyArgument && selector?.value !== undefined) {
1441
- condition('switch', 'EXPR', selector.value);
1444
+ condition(guard_term_1.GuardFn.Switch, 'EXPR', selector.value);
1442
1445
  }
1443
1446
  return;
1444
1447
  }
1445
- else if (r_expression_list_1.RExpressionList.is(node) || r_repeat_loop_1.RRepeatLoop.is(node) || (call !== undefined && (runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Return) || name === 'UseMethod'))) {
1448
+ else if (r_expression_list_1.RExpressionList.is(node) || r_repeat_loop_1.RRepeatLoop.is(node) || (call !== undefined && (runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Return) || name === guard_term_1.GuardFn.UseMethod))) {
1446
1449
  return;
1447
1450
  }
1448
1451
  const all = () => {
@@ -1491,11 +1494,11 @@ function callRequirements(node, vertex, run) {
1491
1494
  const { state } = run;
1492
1495
  const id = node.info.id;
1493
1496
  const call = r_function_call_1.RFunctionCall.is(node) ? node : undefined;
1494
- if (r_if_then_else_1.RIfThenElse.is(node) || r_for_loop_1.RForLoop.is(node) || r_while_loop_1.RWhileLoop.is(node) || (r_binary_op_1.RBinaryOp.is(node) && (node.operator === '&&' || node.operator === '||') && knownNameOf(id, vertex, state) !== undefined)) {
1497
+ if (r_if_then_else_1.RIfThenElse.is(node) || r_for_loop_1.RForLoop.is(node) || r_while_loop_1.RWhileLoop.is(node) || (r_binary_op_1.RBinaryOp.is(node) && (node.operator === guard_term_1.GuardFn.And || node.operator === guard_term_1.GuardFn.Or) && knownNameOf(id, vertex, state) !== undefined)) {
1495
1498
  return;
1496
1499
  }
1497
1500
  else if (call !== undefined && runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Stop)) {
1498
- eachPath(node, run, path => addClause(run, path, guard_term_1.GuardTerm.False, id, { kind: 'explicit', ...(messageOf(node) === undefined ? {} : { message: messageOf(node) }) }));
1501
+ eachPath(node, run, path => addClause(run, path, guard_term_1.GuardTerm.False, id, { kind: 'explicit', message: messageOf(node) }));
1499
1502
  return;
1500
1503
  }
1501
1504
  else if (call !== undefined && runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.StopIfNot)) {
@@ -1511,10 +1514,10 @@ function callRequirements(node, vertex, run) {
1511
1514
  return;
1512
1515
  }
1513
1516
  const name = knownNameOf(id, vertex, state);
1514
- if (call !== undefined && name === 'switch') {
1517
+ if (call !== undefined && name === guard_term_1.GuardFn.Switch) {
1515
1518
  return;
1516
1519
  }
1517
- else if (call !== undefined && name === 'UseMethod') {
1520
+ else if (call !== undefined && name === guard_term_1.GuardFn.UseMethod) {
1518
1521
  eachPath(node, run, path => {
1519
1522
  dispatchRequirement(call, path, run);
1520
1523
  /* whichever method it finds, flowR does not know what that does */
@@ -1535,13 +1538,13 @@ function callRequirements(node, vertex, run) {
1535
1538
  calledFormal(call, path, run);
1536
1539
  }
1537
1540
  if (name !== undefined) {
1538
- if (name === 'NextMethod' && call !== undefined) {
1541
+ if (name === guard_term_1.GuardFn.NextMethod && call !== undefined) {
1539
1542
  dispatchedContracts(call, vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.S3DispatchNext) ? vertex : undefined, undefined, path, run);
1540
1543
  }
1541
1544
  operatorMethods(name, vertex, path, run);
1542
1545
  builtInRequirements(name, vertex, path, run);
1543
1546
  nativeRequirements(vertex, path, run);
1544
- if (name === 'get') {
1547
+ if (name === guard_term_1.GuardFn.Get) {
1545
1548
  getRequirement(node, path, run);
1546
1549
  }
1547
1550
  else if (state.facts(name)?.check !== undefined) {
@@ -1558,7 +1561,7 @@ function conditionClause(expression, vector, run) {
1558
1561
  eachPath(expression, run, path => {
1559
1562
  const term = termOf(expression, run.scope, run.state);
1560
1563
  if (term !== undefined) {
1561
- addClause(run, path, guard_term_1.GuardTerm.truth(term, true, run.state.facts, vector), expression.info.id, { kind: 'explicit', ...(message === undefined ? {} : { message: String(message) }) });
1564
+ addClause(run, path, guard_term_1.GuardTerm.truth(term, true, run.state.facts, vector), expression.info.id, { kind: 'explicit', message: message === undefined ? undefined : String(message) });
1562
1565
  }
1563
1566
  });
1564
1567
  }
@@ -1571,7 +1574,7 @@ function tailReturns(run) {
1571
1574
  continue;
1572
1575
  }
1573
1576
  else if (tail === 1 /* Tail.Elseless */ && r_if_then_else_1.RIfThenElse.is(node)) {
1574
- eachPath(node.condition, run, path => returnsValue(NullValue, [...path, stepsOf(termOf(node.condition, run.scope, state), state.facts, 'if')[1]], run));
1577
+ eachPath(node.condition, run, path => returnsValue(NullValue, path.concat(stepsOf(termOf(node.condition, run.scope, state), state.facts, guard_term_1.GuardFn.If)[1]), run));
1575
1578
  }
1576
1579
  else if (tail === 0 /* Tail.Value */ && !endsRun(node, state)) {
1577
1580
  eachPath(node, run, path => returnsValue(termOf(node, run.scope, state), path, run));
@@ -1581,17 +1584,17 @@ function tailReturns(run) {
1581
1584
  /** Whether the node never hands back a value of its own, as it raises an error or returns from the function. */
1582
1585
  function endsRun(node, state) {
1583
1586
  const vertex = callVertexOf(node.info.id, state);
1584
- return runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Stop) || runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Return) || (vertex !== undefined && knownNameOf(node.info.id, vertex, state) === 'UseMethod');
1587
+ return runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Stop) || runsBuiltIn(vertex, built_in_proc_name_1.BuiltInProcName.Return) || (vertex !== undefined && knownNameOf(node.info.id, vertex, state) === guard_term_1.GuardFn.UseMethod);
1585
1588
  }
1586
1589
  /** Takes out of a clause what another one rules out: `is.null(x) || is.numeric(x)` is `is.numeric(x)` once `!is.null(x)` holds, as code reads `if(is.null(x)) stop() else if(!is.numeric(x)) stop()`. */
1587
1590
  function withUnitsApplied(clauses, facts) {
1588
- const isUnit = (term) => !guard_term_1.GuardTerm.isCall(term, '||');
1591
+ const isUnit = (term) => !guard_term_1.GuardTerm.isCall(term, guard_term_1.GuardFn.Or);
1589
1592
  const units = new Set(clauses.filter(c => isUnit(c.requires)).map(c => guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.truth(c.requires, false, facts))));
1590
1593
  const applied = clauses.map(clause => {
1591
1594
  if (isUnit(clause.requires)) {
1592
1595
  return clause;
1593
1596
  }
1594
- const requires = guard_term_1.GuardTerm.any(...guard_term_1.GuardTerm.disjuncts(clause.requires).filter(d => !units.has(guard_term_1.GuardTerm.render(d))));
1597
+ const requires = guard_term_1.GuardTerm.anyOf(guard_term_1.GuardTerm.disjuncts(clause.requires).filter(d => !units.has(guard_term_1.GuardTerm.render(d))));
1595
1598
  return { ...clause, requires, rendered: guard_term_1.GuardTerm.render(requires) };
1596
1599
  });
1597
1600
  /* of `a` and `a || b`, the former says it all */
@@ -1605,13 +1608,13 @@ function mergeClauses(a, b, requires) {
1605
1608
  /** The clauses without what R asks for that the function checked already, which adds nothing: `x > 0` needs no function to be ruled out after `is.numeric(x)`. */
1606
1609
  function withoutImplied(clauses, scope, facts) {
1607
1610
  const explicit = clauses.filter(c => c.kind === 'explicit').map(c => c.requires);
1608
- const formals = [...scope.formals.values()];
1611
+ const formals = scope.formals.values().toArray();
1609
1612
  return clauses.filter(c => c.kind === 'explicit' || !(0, guard_claims_1.impliedBy)(c.requires, explicit, formals, facts));
1610
1613
  }
1611
1614
  /** The formals the condition asks to be there, as `!missing(x)` does, whether or not they come with a default. */
1612
1615
  function demandsPresenceOf(condition) {
1613
- const inner = guard_term_1.GuardTerm.isCall(condition, '!') && condition.known ? condition.args[0].value : undefined;
1614
- const asked = guard_term_1.GuardTerm.isCall(inner, 'missing') ? inner.args[0]?.value : undefined;
1616
+ const inner = guard_term_1.GuardTerm.isCall(condition, guard_term_1.GuardFn.Not) && condition.known ? condition.args[0].value : undefined;
1617
+ const asked = guard_term_1.GuardTerm.isCall(inner, guard_term_1.GuardFn.Missing) ? inner.args[0]?.value : undefined;
1615
1618
  return asked?.kind === 'formal' ? [asked.name] : [];
1616
1619
  }
1617
1620
  /** What the given definition asks of its calls, for the calls `via` that run it if a dispatch within decides more for them, the innermost first. */
@@ -1629,7 +1632,7 @@ function contractOf(id, state, via = []) {
1629
1632
  }
1630
1633
  const scope = state.depth > MaxCalleeDepth ? undefined : scopeOf(id, state);
1631
1634
  /* a default returning from the function, as `y = return(1)`, does so wherever the formal is first read */
1632
- if (scope === undefined || mayReturnOnExit(scope.definition) || scope.definition.parameters.some(p => p.defaultValue !== undefined && hasSymbol(p.defaultValue, 'return'))) {
1635
+ if (scope === undefined || mayReturnOnExit(scope.definition) || scope.definition.parameters.some(p => p.defaultValue !== undefined && hasSymbol(p.defaultValue, guard_term_1.GuardFn.Return))) {
1633
1636
  return NoContract;
1634
1637
  }
1635
1638
  /* a recursive call counts for nothing, which only ever leaves out what the recursion could have added */
@@ -1642,13 +1645,13 @@ function contractOf(id, state, via = []) {
1642
1645
  new (guardVisitor())(run).walk();
1643
1646
  tailReturns(run);
1644
1647
  state.depth--;
1645
- const demanded = new Set([...run.clauses.values()].flatMap(c => demandsPresenceOf(c.requires)));
1648
+ const demanded = new Set(run.clauses.values().flatMap(c => demandsPresenceOf(c.requires)));
1646
1649
  /* a default that only fails, as `x = stop("x is needed")`, is as good as none */
1647
1650
  const failsForced = ({ defaultValue }) => defaultValue === undefined || alwaysFails(defaultValue, state);
1648
1651
  const contract = {
1649
- clauses: withoutImplied(guard_term_1.GuardTerm.resolved(withUnitsApplied([...run.clauses.values()], state.facts), c => c.requires, mergeClauses), scope, state.facts),
1652
+ clauses: withoutImplied(guard_term_1.GuardTerm.resolved(withUnitsApplied(run.clauses.values().toArray(), state.facts), c => c.requires, mergeClauses), scope, state.facts),
1650
1653
  required: scope.definition.parameters.filter(p => demanded.has(p.name.content) || (run.forced.has(p.name.content) && failsForced(p))).map(p => p.name.content),
1651
- forced: [...run.forced],
1654
+ forced: run.forced.values().toArray(),
1652
1655
  effects: order.effects.size > 0 || order.effectfulDefaults,
1653
1656
  opens: order.openers.size > 0,
1654
1657
  returned: run.returned,
@@ -1663,7 +1666,7 @@ function stateOf(graph, { ctx, natives = ctx === undefined ? [] : native_routine
1663
1666
  const info = (0, query_fn_props_1.builtInLookup)(ctx);
1664
1667
  const routineOf = native_routines_1.NativeRoutines.lookup(natives, graph, info, ctx);
1665
1668
  const bindsFunction = (0, defaultmap_1.memoize)((name) => bindings.get(name).some(id => (0, higher_order_function_1.definitionsBehind)(id, graph).size > 0));
1666
- const methodClasses = (0, defaultmap_1.memoize)((generic) => [...bindings.keys()].flatMap(fn => fn.startsWith(`${generic}.`) && bindsFunction(fn) ? [fn.slice(generic.length + 1)] : []));
1669
+ const methodClasses = (0, defaultmap_1.memoize)((generic) => bindings.keys().filter(fn => fn.startsWith(`${generic}.`) && bindsFunction(fn)).map(fn => fn.slice(generic.length + 1)).toArray());
1667
1670
  return { graph, info, facts: (0, guard_knowledge_1.guardFactsOf)(ctx), contracts: new Map(), terms: new Map(), bindings, bindsFunction, methodClasses, depth: 0, ctx: ctx ?? (0, flowr_analyzer_context_1.contextFromInput)(''), routineOf };
1668
1671
  }
1669
1672
  /** The claims with the cases of each formal. */
@@ -1678,9 +1681,10 @@ function withCandidates(claims, state) {
1678
1681
  return name;
1679
1682
  }
1680
1683
  const [start, end] = [prefix ?? '', suffix ?? ''];
1681
- const candidates = [...state.bindings.keys()]
1684
+ const candidates = state.bindings.keys()
1682
1685
  .filter(fn => fn.length > start.length + end.length && fn.startsWith(start) && fn.endsWith(end) && state.bindsFunction(fn))
1683
- .map(fn => fn.slice(start.length, fn.length - end.length));
1686
+ .map(fn => fn.slice(start.length, fn.length - end.length))
1687
+ .toArray();
1684
1688
  return candidates.length === 0 ? name : { ...name, candidates };
1685
1689
  }
1686
1690
  return Object.fromEntries(Object.entries(claims).map(([formal, claim]) => [formal, claim.resolves === undefined ? claim : { ...claim, resolves: claim.resolves.map(fill) }]));
@@ -1701,19 +1705,21 @@ function guardsOfFunctions(definitions, graph, options = {}) {
1701
1705
  continue;
1702
1706
  }
1703
1707
  const { clauses, required, returned } = contractOf(id, state);
1704
- const returns = (0, guard_claims_1.returnsOf)(returned, clauses.map(c => c.requires), state.facts);
1705
- const passes = (0, guard_claims_1.returnedFormalOf)(returned, state.facts);
1706
- result[id] = {
1708
+ const conditions = clauses.map(c => c.requires);
1709
+ const formals = scope.formals.values().toArray();
1710
+ const { requires, pure } = summarizeClauses(clauses);
1711
+ result[id] = (0, objects_1.compactRecord)({
1707
1712
  clauses,
1708
- formals: withCases(withCandidates((0, guard_claims_1.claimsOf)(clauses.map(c => c.requires), [...scope.formals.values()], state.facts), state), (0, guard_claims_1.casesOf)(clauses, [...scope.formals.values()], state.facts)),
1713
+ formals: withCases(withCandidates((0, guard_claims_1.claimsOf)(conditions, formals, state.facts), state), (0, guard_claims_1.casesOf)(clauses, formals, state.facts)),
1709
1714
  conditions: conditionsPerFormal(clauses),
1710
- relations: (0, guard_claims_1.relationsOf)(clauses.map(c => c.requires), state.facts),
1711
- conditional: (0, guard_claims_1.conditionalClaimsOf)(clauses.map(c => c.requires), [...scope.formals.values()], state.facts),
1715
+ relations: (0, guard_claims_1.relationsOf)(conditions, state.facts),
1716
+ conditional: (0, guard_claims_1.conditionalClaimsOf)(conditions, formals, state.facts),
1712
1717
  required,
1713
- ...summarizeClauses(clauses),
1714
- ...(returns === undefined ? {} : { returns }),
1715
- ...(passes === undefined ? {} : { passes })
1716
- };
1718
+ requires,
1719
+ pure,
1720
+ returns: (0, guard_claims_1.returnsOf)(returned, conditions, state.facts),
1721
+ passes: (0, guard_claims_1.returnedFormalOf)(returned, state.facts)
1722
+ });
1717
1723
  }
1718
1724
  return result;
1719
1725
  }
@@ -1731,7 +1737,7 @@ function conditionsPerFormal(clauses) {
1731
1737
  }
1732
1738
  /** All of the given clauses and those failing cleanly, in R syntax. */
1733
1739
  function summarizeClauses(clauses) {
1734
- const conjunction = (of) => guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.all(...of.map(c => c.requires)));
1740
+ const conjunction = (of) => guard_term_1.GuardTerm.render(guard_term_1.GuardTerm.allOf(of.map(c => c.requires)));
1735
1741
  return {
1736
1742
  requires: clauses.length === 0 ? '' : conjunction(clauses),
1737
1743
  pure: clauses.some(c => c.pure) ? conjunction(clauses.filter(c => c.pure)) : ''
@@ -1745,7 +1751,7 @@ function guardRoles(definitions, graph, options = {}) {
1745
1751
  if (!r_function_definition_1.RFunctionDefinition.is(definition)) {
1746
1752
  continue;
1747
1753
  }
1748
- const guarded = new Set(clauses.flatMap(c => [...guard_term_1.GuardTerm.formalsOf(c.requires)]));
1754
+ const guarded = new Set(clauses.values().flatMap(c => guard_term_1.GuardTerm.formalsOf(c.requires)));
1749
1755
  const mine = {};
1750
1756
  for (const { name, special } of definition.parameters) {
1751
1757
  const bits = special ? 0 : (required.includes(name.content) ? built_in_props_1.ArgProp.Required : 0) | (guarded.has(name.content) ? built_in_props_1.ArgProp.Guarded : 0);