@eagleoutice/flowr 2.17.11 → 2.17.13
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.
- package/abstract-interpretation/branch-paths-interpreter.js +12 -1
- package/benchmark/slicer.js +3 -1
- package/config.d.ts +1 -0
- package/config.js +4 -2
- package/dataflow/environments/default-builtin-config/base-functions.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/base-functions.js +2 -0
- package/dataflow/environments/default-builtin-config/database-access.d.ts +1 -1
- package/dataflow/environments/default-builtin-config/database-access.js +3 -0
- package/dataflow/environments/default-builtin-config/guards.js +3 -1
- package/dataflow/environments/default-builtin-config/index.d.ts +1 -1
- package/dataflow/extractor.js +66 -4
- package/dataflow/fn/guards/built-in-guards.js +4 -4
- package/dataflow/fn/guards/call-contracts.js +8 -8
- package/dataflow/fn/guards/condition-grouping.js +4 -3
- package/dataflow/fn/guards/function-guards.js +103 -97
- package/dataflow/fn/guards/group-method-guards.js +22 -12
- package/dataflow/fn/guards/guard-claims.js +152 -128
- package/dataflow/fn/guards/guard-knowledge.js +19 -18
- package/dataflow/fn/guards/guard-term-syntax.js +13 -12
- package/dataflow/fn/guards/guard-term.d.ts +71 -0
- package/dataflow/fn/guards/guard-term.js +183 -75
- package/dataflow/graph/graph.d.ts +9 -0
- package/dataflow/graph/graph.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +6 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +9 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +135 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +19 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +35 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +2 -1
- package/dataflow/internal/program-order.d.ts +9 -0
- package/dataflow/internal/program-order.js +38 -2
- package/documentation/wiki-interface.js +1 -0
- package/linter/linter-rules.d.ts +1 -0
- package/linter/rules/problematic-inputs.d.ts +3 -0
- package/linter/rules/problematic-inputs.js +12 -9
- package/linter/rules/undefined-symbol.js +3 -2
- package/package.json +5 -2
- package/project/sigdb/export-keys.d.ts +9 -0
- package/project/sigdb/export-keys.js +121 -0
- package/project/sigdb/reader.d.ts +7 -9
- package/project/sigdb/reader.js +24 -42
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +0 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +136 -38
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
- package/util/mermaid/mermaid.js +1 -1
|
@@ -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(
|
|
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,
|
|
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.
|
|
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(
|
|
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) ===
|
|
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
|
-
|
|
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 ===
|
|
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 ===
|
|
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,
|
|
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,
|
|
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,
|
|
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.
|
|
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,
|
|
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,
|
|
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,
|
|
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) ===
|
|
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 ===
|
|
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(
|
|
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 =
|
|
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 =
|
|
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 ?
|
|
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) ||
|
|
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(
|
|
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:
|
|
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 ?? []],
|
|
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
|
|
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 +
|
|
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 }))),
|
|
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.
|
|
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 ?? []],
|
|
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(
|
|
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:
|
|
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(
|
|
1062
|
-
const classes = new Set(
|
|
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(
|
|
1073
|
-
addMethodContracts(methods ?? [], bound, vertex.id, [], [notOfClass
|
|
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.
|
|
1079
|
-
const notOf = s4[0].signature.flatMap((e, at) => e.cls === 'ANY' ? [] : [guard_term_1.GuardTerm.known(
|
|
1080
|
-
addMethodContracts(s4[0].functions, bound, vertex.id, [], [notS4
|
|
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
|
-
|
|
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),
|
|
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 ===
|
|
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) ===
|
|
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(
|
|
1206
|
-
const isAny = (of) => term === undefined ? guard_term_1.GuardTerm.True : guard_term_1.GuardTerm.known(
|
|
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 :
|
|
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(
|
|
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:
|
|
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.
|
|
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 =
|
|
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 =
|
|
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) ===
|
|
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) ===
|
|
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) =>
|
|
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(
|
|
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(
|
|
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(
|
|
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 ===
|
|
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 ===
|
|
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(
|
|
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 ===
|
|
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 ===
|
|
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',
|
|
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 ===
|
|
1517
|
+
if (call !== undefined && name === guard_term_1.GuardFn.Switch) {
|
|
1515
1518
|
return;
|
|
1516
1519
|
}
|
|
1517
|
-
else if (call !== undefined && name ===
|
|
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 ===
|
|
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 ===
|
|
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',
|
|
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,
|
|
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) ===
|
|
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.
|
|
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 =
|
|
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,
|
|
1614
|
-
const asked = guard_term_1.GuardTerm.isCall(inner,
|
|
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,
|
|
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(
|
|
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(
|
|
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:
|
|
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) =>
|
|
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 =
|
|
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
|
|
1705
|
-
const
|
|
1706
|
-
|
|
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)(
|
|
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)(
|
|
1711
|
-
conditional: (0, guard_claims_1.conditionalClaimsOf)(
|
|
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
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
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.
|
|
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 =>
|
|
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);
|