tla-ts 0.0.10-dev.8aec06f77 → 0.0.10-dev.94c3dd828
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/dist/deciders.cjs +37 -36
- package/dist/deciders.js +55 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +146 -58
- package/dist/prove.js +142 -54
- package/dist/run.cjs +45 -43
- package/dist/run.js +47 -45
- package/dist/transfer.cjs +39 -36
- package/dist/transfer.js +23 -20
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/ast.ts +3 -3
- package/src/check.ts +203 -33
- package/src/cli/tlapm.ts +261 -68
- package/src/dependencies.ts +23 -2
- package/src/errors.ts +1 -1
- package/src/exit-codes.ts +1 -0
- package/src/liveness-checker.ts +530 -201
- package/src/liveness.ts +47 -32
- package/src/obligations/anonymize.ts +2 -4
- package/src/obligations/index.ts +5 -3
- package/src/obligations/pragma.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/parser.ts +151 -42
- package/src/prover/deciders.ts +1 -8
- package/src/prover/isabelle/isar/attrib.ts +86 -45
- package/src/prover/isabelle/isar/context.ts +25 -22
- package/src/prover/isabelle/isar/induct.ts +2 -5
- package/src/prover/isabelle/isar/method.ts +5 -7
- package/src/prover/isabelle/isar/proof.ts +33 -16
- package/src/prover/isabelle/isar/rule-cases.ts +6 -14
- package/src/prover/isabelle/isar/theory.ts +16 -17
- package/src/prover/isabelle/isar/toplevel.ts +46 -52
- package/src/prover/isabelle/provers/classical.ts +1 -1
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +1 -0
- package/src/prover/prep/methods.ts +50 -3
- package/src/prover/prep/normalize.ts +4 -1
- package/src/prover/prove.ts +58 -32
- package/src/prover/ptl/decide.ts +43 -63
- package/src/prover/smt/data.ts +51 -45
- package/src/prover/smt/encode.ts +1 -2
- package/src/prover/smt/rewrite.ts +1 -0
- package/src/prover/smt/solver/aig-tactic.ts +25 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -5
- package/src/prover/smt/solver/asserted-formulas.ts +1 -1
- package/src/prover/smt/solver/ast-util.ts +3 -1
- package/src/prover/smt/solver/ast.ts +110 -152
- package/src/prover/smt/solver/bound-manager.ts +39 -28
- package/src/prover/smt/solver/bv-bound-chk.ts +2 -8
- package/src/prover/smt/solver/bv-rewriter.ts +14 -16
- package/src/prover/smt/solver/bv1-blast.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +19 -14
- package/src/prover/smt/solver/check-logic.ts +6 -1
- package/src/prover/smt/solver/context.ts +20 -10
- package/src/prover/smt/solver/demodulator.ts +2 -2
- package/src/prover/smt/solver/dependent-expr-state.ts +16 -0
- package/src/prover/smt/solver/distribute-forall.ts +1 -10
- package/src/prover/smt/solver/dom-simplify.ts +1 -1
- package/src/prover/smt/solver/dt2bv-tactic.ts +2 -7
- package/src/prover/smt/solver/e-matching.ts +6 -6
- package/src/prover/smt/solver/elim-uncnstr.ts +3 -14
- package/src/prover/smt/solver/enode.ts +15 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +19 -8
- package/src/prover/smt/solver/euf/dt-solver.ts +19 -19
- package/src/prover/smt/solver/euf/egraph.ts +65 -32
- package/src/prover/smt/solver/euf/euf-solver.ts +35 -18
- package/src/prover/smt/solver/euf/fpa-solver.ts +37 -51
- package/src/prover/smt/solver/euf/mam.ts +6 -48
- package/src/prover/smt/solver/euf/q-ematch.ts +21 -94
- package/src/prover/smt/solver/euf/q-mbi.ts +4 -2
- package/src/prover/smt/solver/euf/q-model-fixer.ts +1 -1
- package/src/prover/smt/solver/euf/q-solver.ts +2 -0
- package/src/prover/smt/solver/euf/th-solver.ts +1 -1
- package/src/prover/smt/solver/factor.ts +1 -11
- package/src/prover/smt/solver/fd-solver.ts +1 -2
- package/src/prover/smt/solver/fm-tactic.ts +19 -13
- package/src/prover/smt/solver/fpa-rewriter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-converter.ts +10 -6
- package/src/prover/smt/solver/internalizer.ts +41 -2
- package/src/prover/smt/solver/lia2pb.ts +18 -4
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +144 -107
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +50 -17
- package/src/prover/smt/solver/macro-finder.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +13 -13
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +1 -11
- package/src/prover/smt/solver/maxcore.ts +4 -12
- package/src/prover/smt/solver/maxlex.ts +0 -7
- package/src/prover/smt/solver/maxsmt-base.ts +7 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +2 -11
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +9 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +1 -9
- package/src/prover/smt/solver/model-evaluator.ts +9 -5
- package/src/prover/smt/solver/model-macro-solver.ts +3 -3
- package/src/prover/smt/solver/muz/dl-context.ts +57 -3
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +68 -20
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +7 -1
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +39 -10
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +76 -13
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +9 -2
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +0 -2
- package/src/prover/smt/solver/muz/dl-rule.ts +93 -29
- package/src/prover/smt/solver/muz/hnf.ts +6 -5
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +178 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -3
- package/src/prover/smt/solver/muz/rule-properties.ts +194 -36
- package/src/prover/smt/solver/muz/spacer-context.ts +102 -84
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +15 -2
- package/src/prover/smt/solver/muz/spacer-pdr.ts +3 -3
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +2 -7
- package/src/prover/smt/solver/muz/spacer-util.ts +2 -2
- package/src/prover/smt/solver/muz/substitution.ts +88 -37
- package/src/prover/smt/solver/nlqsat.ts +2 -2
- package/src/prover/smt/solver/nlsat/algebraic.ts +1 -2
- package/src/prover/smt/solver/nlsat/explain.ts +5 -0
- package/src/prover/smt/solver/nlsat/solver.ts +36 -25
- package/src/prover/smt/solver/opt-context.ts +9 -8
- package/src/prover/smt/solver/opt-nlsat.ts +68 -58
- package/src/prover/smt/solver/opt-solver.ts +16 -7
- package/src/prover/smt/solver/optsmt.ts +12 -9
- package/src/prover/smt/solver/pattern-inference.ts +2 -2
- package/src/prover/smt/solver/pb-rewriter.ts +13 -13
- package/src/prover/smt/solver/poly-rewriter.ts +2 -2
- package/src/prover/smt/solver/probes.ts +1 -1
- package/src/prover/smt/solver/propagate-values.ts +4 -0
- package/src/prover/smt/solver/proto-model.ts +5 -5
- package/src/prover/smt/solver/purify-arith.ts +50 -15
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -1
- package/src/prover/smt/solver/qe-mbp.ts +13 -23
- package/src/prover/smt/solver/qe.ts +45 -53
- package/src/prover/smt/solver/qsat.ts +70 -90
- package/src/prover/smt/solver/quantifier-analyzer.ts +9 -9
- package/src/prover/smt/solver/quasi-macros.ts +9 -18
- package/src/prover/smt/solver/rational.ts +17 -0
- package/src/prover/smt/solver/recfun-decl-plugin.ts +33 -19
- package/src/prover/smt/solver/recfun-rewriter.ts +1 -1
- package/src/prover/smt/solver/rewriter-tpl.ts +6 -2
- package/src/prover/smt/solver/rewriter.ts +1 -1
- package/src/prover/smt/solver/sat/asymm-branch.ts +59 -46
- package/src/prover/smt/solver/sat/clause-use-list.ts +0 -6
- package/src/prover/smt/solver/sat/clause.ts +1 -3
- package/src/prover/smt/solver/sat/config.ts +3 -3
- package/src/prover/smt/solver/sat/consequences.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +1 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +4 -12
- package/src/prover/smt/solver/sat/model-converter.ts +1 -15
- package/src/prover/smt/solver/sat/pb-solver.ts +49 -23
- package/src/prover/smt/solver/sat/probing.ts +22 -19
- package/src/prover/smt/solver/sat/sat2goal.ts +9 -10
- package/src/prover/smt/solver/sat/simplifier.ts +15 -56
- package/src/prover/smt/solver/sat/solver.ts +20 -19
- package/src/prover/smt/solver/sat/watch-list.ts +7 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +7 -7
- package/src/prover/smt/solver/seq-derive.ts +6 -7
- package/src/prover/smt/solver/seq-eq-solver.ts +7 -7
- package/src/prover/smt/solver/seq-range-predicate.ts +14 -1
- package/src/prover/smt/solver/seq-re-rewriter.ts +1 -10
- package/src/prover/smt/solver/seq-re-util.ts +1 -2
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +4 -4
- package/src/prover/smt/solver/seq-rewriter.ts +1 -4
- package/src/prover/smt/solver/smt-setup.ts +15 -9
- package/src/prover/smt/solver/smtlib-parser.ts +1174 -579
- package/src/prover/smt/solver/smtlib-script.ts +866 -728
- package/src/prover/smt/solver/tactic.ts +66 -14
- package/src/prover/smt/solver/theory-array.ts +25 -58
- package/src/prover/smt/solver/theory-bv.ts +13 -50
- package/src/prover/smt/solver/theory-fpa.ts +46 -78
- package/src/prover/smt/solver/theory-pb.ts +10 -6
- package/src/prover/smt/solver/theory-recfun.ts +2 -2
- package/src/prover/smt/solver/theory-seq-regex.ts +3 -6
- package/src/prover/smt/solver/theory-seq-solve.ts +5 -5
- package/src/prover/smt/solver/theory-seq-state.ts +6 -3
- package/src/prover/smt/solver/theory-seq.ts +32 -54
- package/src/prover/smt/solver/theory.ts +16 -1
- package/src/prover/smt/solver/tseitin-cnf.ts +3 -3
- package/src/prover/smt/solver/var-subst.ts +2 -2
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/zenon/decide.ts +9 -11
- package/src/prover/zenon/node.ts +12 -11
- package/src/prover/zenon/tla/sets.ts +1 -1
- package/src/search.ts +131 -16
- package/src/successors.ts +1 -1
- package/src/symmetry.ts +2 -2
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +81 -9
- package/src/tlc/summary.ts +29 -14
- package/src/typed-tier.ts +6535 -0
- package/src/prover/smt/solver/seq-regex-witness.ts +0 -100
package/src/liveness.ts
CHANGED
|
@@ -37,8 +37,10 @@ import {
|
|
|
37
37
|
createPair,
|
|
38
38
|
createUnary,
|
|
39
39
|
getLiveLevel,
|
|
40
|
+
type LiveAction,
|
|
40
41
|
type LiveEnabled,
|
|
41
42
|
type LiveExpression,
|
|
43
|
+
type LiveState,
|
|
42
44
|
} from "./tableau";
|
|
43
45
|
import { isEqualLikeTlc, type Value } from "./values";
|
|
44
46
|
|
|
@@ -599,15 +601,50 @@ export const toLiveExpression = (
|
|
|
599
601
|
return convert(root, rootScope);
|
|
600
602
|
};
|
|
601
603
|
|
|
602
|
-
|
|
604
|
+
// Evaluates the atoms of a formula, which the interpreter and the typed tier evaluate differently.
|
|
605
|
+
export interface LiveAtoms<State> {
|
|
606
|
+
holdsState: (atom: LiveState | LiveEnabled, state: State) => boolean;
|
|
607
|
+
holdsAction: (atom: LiveAction, state: State, next: State) => boolean;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export const getInterpretedAtoms = (environment: Environment): LiveAtoms<Value[]> => ({
|
|
611
|
+
holdsState: (atom, state) => {
|
|
612
|
+
const context = { environment, scope: atom.scope, state, next: undefined };
|
|
613
|
+
const value =
|
|
614
|
+
atom.kind === "State" ? evaluate(atom.expression, context) : isEnabled(atom.step, context);
|
|
615
|
+
if (typeof value !== "boolean") {
|
|
616
|
+
throw new TlaEvaluationError("A state predicate was evaluated to a non-boolean value.");
|
|
617
|
+
}
|
|
618
|
+
return value;
|
|
619
|
+
},
|
|
620
|
+
holdsAction: (atom, state, next) => {
|
|
621
|
+
const scope = atom.scope;
|
|
622
|
+
const subscript = atom.subscript;
|
|
623
|
+
if (
|
|
624
|
+
subscript &&
|
|
625
|
+
isEqualLikeTlc(
|
|
626
|
+
evaluate(subscript, { environment, scope, state, next: undefined }),
|
|
627
|
+
evaluate(subscript, { environment, scope, state: next, next: undefined }),
|
|
628
|
+
)
|
|
629
|
+
)
|
|
630
|
+
return false;
|
|
631
|
+
const value = evaluate(atom.expression, { environment, scope, state, next });
|
|
632
|
+
if (typeof value !== "boolean") {
|
|
633
|
+
throw new TlaEvaluationError("Encountered an action predicate that's not a boolean.");
|
|
634
|
+
}
|
|
635
|
+
return value;
|
|
636
|
+
},
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
export const evaluateLive = <State>(
|
|
603
640
|
expression: LiveExpression,
|
|
604
|
-
state:
|
|
605
|
-
next:
|
|
606
|
-
|
|
641
|
+
state: State,
|
|
642
|
+
next: State | undefined,
|
|
643
|
+
atoms: LiveAtoms<State>,
|
|
607
644
|
stateCache: Map<LiveExpression, boolean>,
|
|
608
645
|
): boolean => {
|
|
609
646
|
const recurse = (operand: LiveExpression) =>
|
|
610
|
-
evaluateLive(operand, state, next,
|
|
647
|
+
evaluateLive(operand, state, next, atoms, stateCache);
|
|
611
648
|
switch (expression.kind) {
|
|
612
649
|
case "Boolean":
|
|
613
650
|
return expression.value;
|
|
@@ -615,35 +652,13 @@ export const evaluateLive = (
|
|
|
615
652
|
case "Enabled": {
|
|
616
653
|
const cached = stateCache.get(expression);
|
|
617
654
|
if (cached !== undefined) return cached;
|
|
618
|
-
const
|
|
619
|
-
const value =
|
|
620
|
-
expression.kind === "State"
|
|
621
|
-
? evaluate(expression.expression, context)
|
|
622
|
-
: isEnabled(expression.step, context);
|
|
623
|
-
if (typeof value !== "boolean") {
|
|
624
|
-
throw new TlaEvaluationError("A state predicate was evaluated to a non-boolean value.");
|
|
625
|
-
}
|
|
655
|
+
const value = atoms.holdsState(expression, state);
|
|
626
656
|
stateCache.set(expression, value);
|
|
627
657
|
return value;
|
|
628
658
|
}
|
|
629
|
-
case "Action":
|
|
659
|
+
case "Action":
|
|
630
660
|
if (expression.enabled && stateCache.get(expression.enabled) === false) return false;
|
|
631
|
-
|
|
632
|
-
const subscript = expression.subscript;
|
|
633
|
-
if (
|
|
634
|
-
subscript &&
|
|
635
|
-
isEqualLikeTlc(
|
|
636
|
-
evaluate(subscript, { environment, scope, state, next: undefined }),
|
|
637
|
-
evaluate(subscript, { environment, scope, state: next, next: undefined }),
|
|
638
|
-
)
|
|
639
|
-
)
|
|
640
|
-
return false;
|
|
641
|
-
const value = evaluate(expression.expression, { environment, scope, state, next });
|
|
642
|
-
if (typeof value !== "boolean") {
|
|
643
|
-
throw new TlaEvaluationError("Encountered an action predicate that's not a boolean.");
|
|
644
|
-
}
|
|
645
|
-
return value;
|
|
646
|
-
}
|
|
661
|
+
return next !== undefined && atoms.holdsAction(expression, state, next);
|
|
647
662
|
case "Not":
|
|
648
663
|
return !recurse(expression.body);
|
|
649
664
|
case "And":
|
|
@@ -651,7 +666,7 @@ export const evaluateLive = (
|
|
|
651
666
|
case "Or":
|
|
652
667
|
return expression.operands.some(recurse);
|
|
653
668
|
case "Next":
|
|
654
|
-
return evaluateLive(expression.body, next ?? state, undefined,
|
|
669
|
+
return evaluateLive(expression.body, next ?? state, undefined, atoms, new Map());
|
|
655
670
|
case "Always":
|
|
656
671
|
case "Eventually":
|
|
657
672
|
throw new TlaEvaluationError("TLC cannot evaluate a temporal formula in a single step");
|
|
@@ -688,7 +703,7 @@ export const evaluateOnLasso = (
|
|
|
688
703
|
expression,
|
|
689
704
|
path[position],
|
|
690
705
|
path[getNext(position)],
|
|
691
|
-
environment,
|
|
706
|
+
getInterpretedAtoms(environment),
|
|
692
707
|
new Map(),
|
|
693
708
|
);
|
|
694
709
|
}
|
|
@@ -44,8 +44,6 @@ import { resolveSubexpression } from "./subexpression";
|
|
|
44
44
|
import { getTime } from "./temporal";
|
|
45
45
|
import {
|
|
46
46
|
getStepName,
|
|
47
|
-
getUnique,
|
|
48
|
-
type Counter,
|
|
49
47
|
type Proof,
|
|
50
48
|
type Step,
|
|
51
49
|
type StepNumber,
|
|
@@ -80,7 +78,7 @@ interface AnonContext {
|
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
export const createAnonymizer = (
|
|
83
|
-
|
|
81
|
+
getStepLabel: () => string,
|
|
84
82
|
expandInstance: (
|
|
85
83
|
scope: Scope | undefined,
|
|
86
84
|
definition: Extract<Defn, { kind: "Instance" }>,
|
|
@@ -473,7 +471,7 @@ export const createAnonymizer = (
|
|
|
473
471
|
? {
|
|
474
472
|
kind: "Named",
|
|
475
473
|
level: original.step.level,
|
|
476
|
-
label:
|
|
474
|
+
label: getStepLabel(),
|
|
477
475
|
isAnonymous: true,
|
|
478
476
|
}
|
|
479
477
|
: original.step;
|
package/src/obligations/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { TlaProofError, TlaSyntaxError, type SyntaxFailure } from "../errors";
|
|
|
2
2
|
import { createAnonymizer } from "./anonymize";
|
|
3
3
|
import {
|
|
4
4
|
getAtPrefix,
|
|
5
|
+
getErrorNote,
|
|
5
6
|
getErrorSetting,
|
|
6
7
|
getLocusPosition,
|
|
7
8
|
getLocusPrefix,
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
import { compareNames, flatten, getDependencies, STANDARD_MODULES, type Mule } from "./module";
|
|
20
21
|
import { expandInstance, normalize, type Pipeline } from "./normalize";
|
|
21
22
|
import { formatObligation, type PrinterOptions } from "./printer";
|
|
22
|
-
import type
|
|
23
|
+
import { getUnique, type Counter, type ObligationKind } from "./proof";
|
|
23
24
|
import type { OldMethod } from "./pragma";
|
|
24
25
|
import { createSimplifier } from "./simplify";
|
|
25
26
|
import { createModuleConverter } from "./source";
|
|
@@ -139,7 +140,8 @@ const loadMule = (
|
|
|
139
140
|
endLine: proofFailure.stop.line,
|
|
140
141
|
endColumn: proofFailure.stop.column,
|
|
141
142
|
};
|
|
142
|
-
|
|
143
|
+
onWarning(getErrorNote(locus, proofFailure.printed));
|
|
144
|
+
onWarning(getErrorSetting(locus, parsed[0].reason));
|
|
143
145
|
throw new TlaProofError(parsed[0].reason, { failure: proofFailure.exception });
|
|
144
146
|
}
|
|
145
147
|
if (Array.isArray(parsed)) {
|
|
@@ -297,7 +299,7 @@ export const getObligations = (
|
|
|
297
299
|
});
|
|
298
300
|
const pipeline: Pipeline = {
|
|
299
301
|
anonymizer: createAnonymizer(
|
|
300
|
-
counter
|
|
302
|
+
() => `_a${getUnique(counter)}`,
|
|
301
303
|
(scope, definition) => expandInstance(pipeline, scope, definition),
|
|
302
304
|
onWarning,
|
|
303
305
|
),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// tlapm's method pragmas: the new (*{ by (prover:"zenon"; timeout:@) }*) after a definition,
|
|
2
|
-
// the old (*{ by (zenon) }*) of Method_prs.
|
|
1
|
+
// tlapm's method pragmas: the new (*{ by (prover:"zenon"; timeout:@) }*) after a definition, which
|
|
2
|
+
// E_parser.read_new_method reads, and the old (*{ by (zenon) }*) of Method_prs.
|
|
3
3
|
|
|
4
4
|
import type { Locus } from "./expression";
|
|
5
5
|
|
package/src/parallel.ts
CHANGED
|
@@ -179,13 +179,13 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
179
179
|
fingerprintDistance: getFingerprintDistance(
|
|
180
180
|
statistics.distinctStates,
|
|
181
181
|
statistics.generatedStates,
|
|
182
|
-
() => {
|
|
182
|
+
(visit) => {
|
|
183
183
|
const fingerprints = new BigInt64Array(statistics.distinctStates);
|
|
184
184
|
tlcFingerprints.reduce((offset, level) => {
|
|
185
185
|
fingerprints.set(level, offset);
|
|
186
186
|
return offset + level.length;
|
|
187
187
|
}, 0);
|
|
188
|
-
|
|
188
|
+
visit(fingerprints);
|
|
189
189
|
},
|
|
190
190
|
),
|
|
191
191
|
});
|
package/src/parser.ts
CHANGED
|
@@ -376,13 +376,30 @@ const getSpan = (range: SourceRange): Span => ({
|
|
|
376
376
|
stop: { line: range.end.line, column: range.end.column + 1 },
|
|
377
377
|
});
|
|
378
378
|
|
|
379
|
-
|
|
379
|
+
interface ProofErrorEnds {
|
|
380
|
+
printed: string;
|
|
381
|
+
set: string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const NO_NEWLINES: ProofErrorEnds = { printed: "", set: "" };
|
|
385
|
+
|
|
386
|
+
const PRINTED_NEWLINE: ProofErrorEnds = { printed: "\n", set: "" };
|
|
387
|
+
|
|
388
|
+
const NEWLINES: ProofErrorEnds = { printed: "\n", set: "\n" };
|
|
389
|
+
|
|
390
|
+
// p_parser.ml ends some of the messages it prints, and of those it sets, with a newline.
|
|
391
|
+
const createProofError = (
|
|
392
|
+
message: string,
|
|
393
|
+
span: Span,
|
|
394
|
+
ends: ProofErrorEnds,
|
|
395
|
+
exception = "Proof.Parser",
|
|
396
|
+
) =>
|
|
380
397
|
new TlaSyntaxError(message, undefined, {
|
|
381
|
-
reason: message
|
|
398
|
+
reason: `${message}${ends.set}`,
|
|
382
399
|
line: span.start.line,
|
|
383
400
|
column: span.start.column,
|
|
384
401
|
isEnd: false,
|
|
385
|
-
proof: { stop: span.stop, exception },
|
|
402
|
+
proof: { stop: span.stop, exception, printed: `${message}${ends.printed}` },
|
|
386
403
|
});
|
|
387
404
|
|
|
388
405
|
const FACT_KEYWORDS = new Set([
|
|
@@ -951,14 +968,19 @@ const parse = (
|
|
|
951
968
|
const bullet = advance();
|
|
952
969
|
offsideColumns.push(bullet.column);
|
|
953
970
|
const operands = [parseExpression()];
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
971
|
+
const parseItems = () => {
|
|
972
|
+
while (
|
|
973
|
+
isBullet(peekRaw()) &&
|
|
974
|
+
peekRaw().text === bullet.text &&
|
|
975
|
+
peekRaw().column === bullet.column
|
|
976
|
+
) {
|
|
977
|
+
cursor++;
|
|
978
|
+
operands.push(parseExpression());
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
// bulleted_list: a first item that fails leaves expr_or_op's other readings to fail after it.
|
|
982
|
+
if (isTlapm) commit(parseItems);
|
|
983
|
+
else parseItems();
|
|
962
984
|
offsideColumns.pop();
|
|
963
985
|
return {
|
|
964
986
|
kind: bullet.text === "/\\" ? "And" : "Or",
|
|
@@ -1551,6 +1573,57 @@ const parse = (
|
|
|
1551
1573
|
apply,
|
|
1552
1574
|
});
|
|
1553
1575
|
|
|
1576
|
+
// expr_or_op's non_test: a postfix operator before an expression in parentheses is an atom.
|
|
1577
|
+
const parseTlapmNonfixPostfix = (token: Token) =>
|
|
1578
|
+
token.kind === "Operator" && DEFINABLE_POSTFIX_OPERATORS.has(token.text) && isAt("(", 1)
|
|
1579
|
+
? attempt(() =>
|
|
1580
|
+
withBracketLayout(() => {
|
|
1581
|
+
advance();
|
|
1582
|
+
advance();
|
|
1583
|
+
const operand = parseExpression();
|
|
1584
|
+
const end = cursor - 1;
|
|
1585
|
+
expect(")");
|
|
1586
|
+
return { end, expression: getPostfixApplication(token, operand) };
|
|
1587
|
+
}),
|
|
1588
|
+
)
|
|
1589
|
+
: undefined;
|
|
1590
|
+
|
|
1591
|
+
// A comma directly inside the parentheses after the operator, without which non_test's
|
|
1592
|
+
// attempt at `(e, f)` fails. A selector's << or >> isn't a bracket.
|
|
1593
|
+
const hasNonfixComma = () => {
|
|
1594
|
+
let depth = 0;
|
|
1595
|
+
for (let index = cursor + 1; index < tokens.length; index++) {
|
|
1596
|
+
const token = tokens[index];
|
|
1597
|
+
if (token.kind !== "Operator") continue;
|
|
1598
|
+
if (depth === 1 && token.text === ",") return true;
|
|
1599
|
+
if (tokens[index - 1].text === "!") continue;
|
|
1600
|
+
if (OPENING_BRACKETS.has(token.text)) depth++;
|
|
1601
|
+
if (CLOSING_BRACKETS.has(token.text) && --depth === 0) return false;
|
|
1602
|
+
}
|
|
1603
|
+
return false;
|
|
1604
|
+
};
|
|
1605
|
+
|
|
1606
|
+
// expr_or_op's non_test: an infix operator before two expressions in parentheses is an atom.
|
|
1607
|
+
const parseTlapmNonfixInfix = (token: Token) =>
|
|
1608
|
+
isAt("(", 1) && hasNonfixComma()
|
|
1609
|
+
? attempt(() =>
|
|
1610
|
+
withBracketLayout((): Expression => {
|
|
1611
|
+
advance();
|
|
1612
|
+
advance();
|
|
1613
|
+
const left = parseExpression();
|
|
1614
|
+
expect(",");
|
|
1615
|
+
const right = parseExpression();
|
|
1616
|
+
expect(")");
|
|
1617
|
+
return {
|
|
1618
|
+
kind: "Apply",
|
|
1619
|
+
operator: token.text,
|
|
1620
|
+
args: [left, right],
|
|
1621
|
+
location: getLocation(token),
|
|
1622
|
+
};
|
|
1623
|
+
}),
|
|
1624
|
+
)
|
|
1625
|
+
: undefined;
|
|
1626
|
+
|
|
1554
1627
|
const parseTlapmItem = (isStart: boolean): TlapmItem | undefined => {
|
|
1555
1628
|
const start = cursor;
|
|
1556
1629
|
const token = peek();
|
|
@@ -1578,6 +1651,11 @@ const parse = (
|
|
|
1578
1651
|
}));
|
|
1579
1652
|
}
|
|
1580
1653
|
if (infix) {
|
|
1654
|
+
// Pco.resolve has no operator to put before that atom, so the expression ends here.
|
|
1655
|
+
if (parseTlapmNonfixInfix(token)) {
|
|
1656
|
+
cursor = start;
|
|
1657
|
+
return undefined;
|
|
1658
|
+
}
|
|
1581
1659
|
advance();
|
|
1582
1660
|
return {
|
|
1583
1661
|
...getTlapmOperator(start, "Infix", infix, (operands) =>
|
|
@@ -1595,28 +1673,25 @@ const parse = (
|
|
|
1595
1673
|
}
|
|
1596
1674
|
if (token.kind !== "Operator" || !DEFINABLE_POSTFIX_OPERATORS.has(token.text))
|
|
1597
1675
|
return undefined;
|
|
1676
|
+
// Pco.resolve has no operator to put before that atom, so the expression ends here.
|
|
1677
|
+
if (parseTlapmNonfixPostfix(token)) {
|
|
1678
|
+
cursor = start;
|
|
1679
|
+
return undefined;
|
|
1680
|
+
}
|
|
1598
1681
|
advance();
|
|
1599
1682
|
return getTlapmOperator(start, "Postfix", POSTFIX_PRECEDENCE, (operands) =>
|
|
1600
1683
|
getPostfixApplication(token, operands[0].expression),
|
|
1601
1684
|
);
|
|
1602
1685
|
}
|
|
1603
1686
|
if (token.kind === "Operator" && isBullet(token))
|
|
1604
|
-
return getTlapmOperand(
|
|
1605
|
-
const nonfix =
|
|
1606
|
-
infix && isAt("(", 1)
|
|
1607
|
-
? attempt(() =>
|
|
1608
|
-
withBracketLayout((): Expression => {
|
|
1609
|
-
advance();
|
|
1610
|
-
advance();
|
|
1611
|
-
const left = parseExpression();
|
|
1612
|
-
expect(",");
|
|
1613
|
-
const right = parseExpression();
|
|
1614
|
-
expect(")");
|
|
1615
|
-
return { kind: "Apply", operator: token.text, args: [left, right], location };
|
|
1616
|
-
}),
|
|
1617
|
-
)
|
|
1618
|
-
: undefined;
|
|
1687
|
+
return getTlapmOperand(parseJunctionList(), start);
|
|
1688
|
+
const nonfix = infix ? parseTlapmNonfixInfix(token) : undefined;
|
|
1619
1689
|
if (nonfix) return getTlapmOperand(nonfix, start);
|
|
1690
|
+
const nonfixPostfix = parseTlapmNonfixPostfix(token);
|
|
1691
|
+
if (nonfixPostfix) {
|
|
1692
|
+
nonfixPostfix.expression.location.range = getRange(start, nonfixPostfix.end);
|
|
1693
|
+
return { start, end: nonfixPostfix.end, expression: nonfixPostfix.expression };
|
|
1694
|
+
}
|
|
1620
1695
|
const prefix = isOperator ? TLAPM_PREFIX_OPERATORS.get(token.text) : undefined;
|
|
1621
1696
|
if (prefix) {
|
|
1622
1697
|
advance();
|
|
@@ -2156,23 +2231,50 @@ const parse = (
|
|
|
2156
2231
|
);
|
|
2157
2232
|
};
|
|
2158
2233
|
|
|
2234
|
+
const parseHypothesis = () => {
|
|
2235
|
+
if (peek().kind === "Identifier" && isAt("::", 1) && isAt("ASSUME", 2)) {
|
|
2236
|
+
advance();
|
|
2237
|
+
advance();
|
|
2238
|
+
}
|
|
2239
|
+
if (isAt("ASSUME")) return withProofScope(parseAssumeProve);
|
|
2240
|
+
if (peek().kind === "Keyword" && NEW_SYMBOL_STARTS.has(peek().text))
|
|
2241
|
+
return isTlapm ? commit(parseNewSymbol) : parseNewSymbol();
|
|
2242
|
+
if (!isTlapm) return parseExpression();
|
|
2243
|
+
// expr_or_sequent: where no expression starts, the sequent's ASSUME fails last.
|
|
2244
|
+
const expression = attempt(parseExpression);
|
|
2245
|
+
if (expression === undefined) throw createUnexpected("Expected a hypothesis");
|
|
2246
|
+
return expression;
|
|
2247
|
+
};
|
|
2248
|
+
|
|
2249
|
+
// comma1 (hyp b): Pco.star attempts the hypotheses after the first, each inside the one before,
|
|
2250
|
+
// so a failure that backtracks ends the list, and tlapm reports any other before the first comma.
|
|
2251
|
+
const parseTlapmHypotheses = () => {
|
|
2252
|
+
const assumptions = [parseHypothesis()];
|
|
2253
|
+
withRestorePoint(() => {
|
|
2254
|
+
while (true) {
|
|
2255
|
+
const assumption = attempt(() => {
|
|
2256
|
+
expect(",");
|
|
2257
|
+
return parseHypothesis();
|
|
2258
|
+
});
|
|
2259
|
+
if (assumption === undefined) break;
|
|
2260
|
+
assumptions.push(assumption);
|
|
2261
|
+
}
|
|
2262
|
+
});
|
|
2263
|
+
return assumptions;
|
|
2264
|
+
};
|
|
2265
|
+
|
|
2159
2266
|
const parseAssumeProve = (): AssumeProve => {
|
|
2160
2267
|
const start = cursor;
|
|
2161
2268
|
const location = getLocation(expect("ASSUME"));
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
expect("PROVE");
|
|
2172
|
-
return withRange(
|
|
2173
|
-
{ kind: "AssumeProve", assumptions, conclusion: parseExpression(), location },
|
|
2174
|
-
start,
|
|
2175
|
-
);
|
|
2269
|
+
const parseSequent = (): AssumeProve => {
|
|
2270
|
+
const assumptions = isTlapm ? parseTlapmHypotheses() : parseSeparated(parseHypothesis);
|
|
2271
|
+
expect("PROVE");
|
|
2272
|
+
return withRange(
|
|
2273
|
+
{ kind: "AssumeProve", assumptions, conclusion: parseExpression(), location },
|
|
2274
|
+
start,
|
|
2275
|
+
);
|
|
2276
|
+
};
|
|
2277
|
+
return isTlapm ? commit(parseSequent) : parseSequent();
|
|
2176
2278
|
};
|
|
2177
2279
|
|
|
2178
2280
|
const isNameListAhead = (terminator: string) => {
|
|
@@ -2384,20 +2486,26 @@ const parse = (
|
|
|
2384
2486
|
throw createProofError(
|
|
2385
2487
|
`Unexpected end of (sub)proof at level ${level} before QED step`,
|
|
2386
2488
|
levelSpan,
|
|
2489
|
+
NEWLINES,
|
|
2387
2490
|
);
|
|
2388
2491
|
}
|
|
2389
2492
|
if (item.kind === "Leaf") {
|
|
2390
2493
|
throw createProofError(
|
|
2391
2494
|
`Expecting a proof step but found a${LEAF_NAMES[item.proof.kind]} leaf proof`,
|
|
2392
2495
|
item.span,
|
|
2496
|
+
NEWLINES,
|
|
2393
2497
|
);
|
|
2394
2498
|
}
|
|
2395
2499
|
if (!isFirst && item.isProof) {
|
|
2396
|
-
throw createProofError(
|
|
2500
|
+
throw createProofError(
|
|
2501
|
+
"PROOF keyword found in step that does not begin subproof",
|
|
2502
|
+
item.span,
|
|
2503
|
+
PRINTED_NEWLINE,
|
|
2504
|
+
);
|
|
2397
2505
|
}
|
|
2398
2506
|
const implicit = item.token.text[1];
|
|
2399
2507
|
if (implicit === "+" && !isFirst) {
|
|
2400
|
-
throw createProofError("<+> used but no subproof expected", item.span);
|
|
2508
|
+
throw createProofError("<+> used but no subproof expected", item.span, PRINTED_NEWLINE);
|
|
2401
2509
|
}
|
|
2402
2510
|
const stepLevel =
|
|
2403
2511
|
implicit === "*"
|
|
@@ -2452,6 +2560,7 @@ const parse = (
|
|
|
2452
2560
|
throw createProofError(
|
|
2453
2561
|
"extra step(s) after finished proof",
|
|
2454
2562
|
extra.span,
|
|
2563
|
+
NO_NEWLINES,
|
|
2455
2564
|
"Proof.Parser.toplevel",
|
|
2456
2565
|
);
|
|
2457
2566
|
}
|
package/src/prover/deciders.ts
CHANGED
|
@@ -21,14 +21,7 @@ const DECIDERS: Record<
|
|
|
21
21
|
> = {
|
|
22
22
|
smt: decideZ3,
|
|
23
23
|
z3: decideZ3,
|
|
24
|
-
zenon:
|
|
25
|
-
const decision = decideZenon(text, options);
|
|
26
|
-
return {
|
|
27
|
-
verdict: decision.verdict,
|
|
28
|
-
...("proof" in decision && { output: decision.proof }),
|
|
29
|
-
...("error" in decision && { errorOutput: decision.error }),
|
|
30
|
-
};
|
|
31
|
-
},
|
|
24
|
+
zenon: decideZenon,
|
|
32
25
|
isabelle: (text, options) => ({ verdict: decideIsabelle(text, options) }),
|
|
33
26
|
ls4: (text, options) => ({ verdict: decidePtl(text, options) }),
|
|
34
27
|
};
|