tla-ts 0.0.4-dev.b254db0 → 0.0.4-dev.ca40dfe
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/README.md +31 -10
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +27 -27
- package/dist/deciders.js +34 -34
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -14
- package/dist/index.d.ts +12 -14
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +37 -27
- package/dist/prove.js +39 -29
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +76 -86
- package/dist/transfer.js +73 -83
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +1 -1
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1154
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/cli/tlc.ts +941 -0
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +17 -15
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +12 -36
- package/src/evaluate.ts +81 -101
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/obligations/action.ts +9 -45
- package/src/obligations/{anon.ts → anonymize.ts} +13 -25
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +42 -517
- package/src/obligations/generate.ts +88 -778
- package/src/obligations/index.ts +20 -22
- package/src/obligations/levels.ts +36 -41
- package/src/obligations/module.ts +88 -708
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +21 -15
- package/src/obligations/printer.ts +81 -188
- package/src/obligations/proof.ts +0 -1
- package/src/obligations/regroup.ts +100 -0
- package/src/obligations/simplify.ts +668 -0
- package/src/obligations/source.ts +25 -131
- package/src/obligations/{deref.ts → subexpression.ts} +48 -56
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +28 -26
- package/src/obligations/tuples.ts +37 -53
- package/src/parallel-worker.ts +37 -33
- package/src/parallel.ts +30 -24
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prove/decide-pool.ts +7 -12
- package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
- package/src/prove/isabelle/decide.ts +3 -6
- package/src/prove/isabelle/encode.ts +35 -93
- package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
- package/src/prove/isabelle/isar/method.ts +3 -3
- package/src/prove/isabelle/isar/type-check.ts +1 -1
- package/src/prove/isabelle/provers/blast/blast.ts +1 -1
- package/src/prove/isabelle/provers/blast/branch.ts +1 -1
- package/src/prove/isabelle/provers/blast/term.ts +3 -4
- package/src/prove/isabelle/provers/clasimp.ts +1 -1
- package/src/prove/isabelle/provers/classical.ts +3 -3
- package/src/prove/isabelle/provers/hypsubst.ts +1 -9
- package/src/prove/isabelle/pure/conv.ts +1 -1
- package/src/prove/isabelle/pure/drule.ts +2 -2
- package/src/prove/isabelle/pure/envir.ts +3 -35
- package/src/prove/isabelle/pure/logic.ts +4 -76
- package/src/prove/isabelle/pure/name.ts +1 -13
- package/src/prove/isabelle/pure/net.ts +2 -49
- package/src/prove/isabelle/pure/pattern.ts +3 -22
- package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
- package/src/prove/isabelle/pure/seq.ts +0 -23
- package/src/prove/isabelle/pure/simplifier.ts +2 -8
- package/src/prove/isabelle/pure/table.ts +1 -8
- package/src/prove/isabelle/pure/tactic.ts +5 -113
- package/src/prove/isabelle/pure/tactical.ts +1 -84
- package/src/prove/isabelle/pure/term-ord.ts +1 -55
- package/src/prove/isabelle/pure/term.ts +8 -128
- package/src/prove/isabelle/pure/thm.ts +4 -27
- package/src/prove/isabelle/pure/type.ts +0 -12
- package/src/prove/isabelle/pure/unify.ts +1 -1
- package/src/prove/isabelle/tla/classical-setup.ts +1 -1
- package/src/prove/ocaml.ts +1 -1
- package/src/prove/prep/action.ts +23 -36
- package/src/prove/prep/enabled-axioms.ts +2 -2
- package/src/prove/prep/fingerprint.ts +3 -3
- package/src/prove/prep/level-comparison.ts +9 -37
- package/src/prove/prep/md5.ts +2 -9
- package/src/prove/prep/normalize.ts +309 -0
- package/src/prove/prove-worker.ts +2 -5
- package/src/prove/prove.ts +98 -111
- package/src/prove/ptl/encode.ts +19 -31
- package/src/prove/smt/axioms.ts +45 -58
- package/src/prove/smt/encode.ts +124 -15
- package/src/prove/smt/instances.ts +2 -3
- package/src/prove/smt/rewrite.ts +24 -31
- package/src/prove/smt/solver/ast-util.ts +0 -56
- package/src/prove/smt/solver/case-split-queue.ts +1 -1
- package/src/prove/smt/solver/enode.ts +1 -1
- package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
- package/src/prove/smt/solver/model-macro-solver.ts +1 -1
- package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
- package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
- package/src/prove/smt/solver/nlsat/explain.ts +1 -1
- package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
- package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
- package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
- package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
- package/src/prove/smt/solver/pattern-inference.ts +1 -1
- package/src/prove/smt/solver/relevancy.ts +2 -2
- package/src/prove/smt/solver/rewriter.ts +1 -1
- package/src/prove/smt/solver/solver.ts +2 -2
- package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
- package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
- package/src/prove/verdict.ts +0 -5
- package/src/prove/zenon/decide.ts +5 -11
- package/src/prove/zenon/encode.ts +21 -80
- package/src/prove/zenon/eqrel.ts +1 -1
- package/src/prove/zenon/equality-rules.ts +1 -1
- package/src/prove/zenon/expr.ts +2 -2
- package/src/prove/zenon/index-table.ts +1 -1
- package/src/prove/zenon/isar.ts +1 -1
- package/src/prove/zenon/llproof.ts +1 -1
- package/src/prove/zenon/mltoll.ts +1 -1
- package/src/prove/zenon/node.ts +1 -1
- package/src/prove/zenon/search.ts +1 -1
- package/src/prove/zenon/tla/terms.ts +1 -20
- package/src/prove/zenon/tla/tla.ts +1 -1
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +16 -20
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +16 -19
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -213
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/transfer.ts +32 -32
- package/src/values.ts +72 -67
- package/src/worker.ts +1 -4
- package/dist/run-cli.cjs +0 -45
- package/dist/run-cli.js +0 -45
- package/src/canonical.ts +0 -40
- package/src/obligations/ctx.ts +0 -64
- package/src/prove/prep/defs.ts +0 -33
- package/src/prove/prep/elab.ts +0 -156
- package/src/prove/prep/enabled.ts +0 -43
- package/src/prove/prep/flatten.ts +0 -70
- package/src/prove/prep/trivial.ts +0 -22
- package/src/prove/smt/axiomatize.ts +0 -69
- package/src/prove/smt/simplify.ts +0 -57
- package/src/run-cli.ts +0 -1806
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
- /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
writeFileSync,
|
|
13
13
|
} from "node:fs";
|
|
14
14
|
import { basename, join } from "node:path";
|
|
15
|
-
import { version } from "
|
|
16
|
-
import { TlaProofError } from "
|
|
15
|
+
import { version } from "../../../package.json";
|
|
16
|
+
import { TlaProofError } from "../../errors";
|
|
17
17
|
import { block, isBlock, readMarshaled, writeMarshaled, type OcamlValue } from "./ocaml-marshal";
|
|
18
|
-
import type { ProofAttempt } from "
|
|
18
|
+
import type { ProofAttempt } from "../prove";
|
|
19
19
|
|
|
20
20
|
// One optional result per prover, in V13.str's order.
|
|
21
21
|
export type FingerprintTable = Map<string, OcamlValue[]>;
|
|
@@ -82,13 +82,13 @@ const readBucket = (entry: OcamlValue | undefined): [OcamlValue, OcamlValue][] =
|
|
|
82
82
|
export const loadFingerprints = (table: FingerprintTable, path: string, isSafe: boolean) => {
|
|
83
83
|
const bytes = readFileSync(path);
|
|
84
84
|
const magic = readMarshaled(bytes, 0);
|
|
85
|
-
const
|
|
86
|
-
if (magic.value !== MAGIC_NUMBER || !isBlock(
|
|
85
|
+
const contents = readMarshaled(bytes, magic.next).value;
|
|
86
|
+
if (magic.value !== MAGIC_NUMBER || !isBlock(contents) || contents.tag !== 0)
|
|
87
87
|
throw new TlaProofError("corrupted fingerprint file");
|
|
88
|
-
const buckets = getField(getField(
|
|
89
|
-
const isTrusted = (
|
|
88
|
+
const buckets = getField(getField(contents, 0), 1);
|
|
89
|
+
const isTrusted = (result: OcamlValue, field: number) => {
|
|
90
90
|
const index = CHECKED_VERSIONS.get(field);
|
|
91
|
-
return !isSafe || index === undefined || getField(getField(
|
|
91
|
+
return !isSafe || index === undefined || getField(getField(result, 0), index) === VERSION;
|
|
92
92
|
};
|
|
93
93
|
table.clear();
|
|
94
94
|
(buckets !== undefined && isBlock(buckets) ? buckets.fields : [])
|
|
@@ -98,13 +98,13 @@ export const loadFingerprints = (table: FingerprintTable, path: string, isSafe:
|
|
|
98
98
|
throw new TlaProofError("corrupted fingerprint file");
|
|
99
99
|
table.set(
|
|
100
100
|
key,
|
|
101
|
-
record.fields.map((
|
|
101
|
+
record.fields.map((result, field) => (isTrusted(result, field) ? result : 0)),
|
|
102
102
|
);
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
const decodeResult = (prover: string,
|
|
107
|
-
const status = getField(
|
|
106
|
+
const decodeResult = (prover: string, result: OcamlValue | undefined): ProofAttempt | undefined => {
|
|
107
|
+
const status = getField(result, 0);
|
|
108
108
|
const outcome = getField(status, 0);
|
|
109
109
|
const argument = getField(getField(status, 1), 0);
|
|
110
110
|
if (outcome === undefined || outcome === 1) return undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// OCaml's Marshal format, ported from runtime/intern.c and runtime/extern.c, for the values in
|
|
2
2
|
// tlapm's fingerprints file. It writes no sharing, which OCaml reads the same.
|
|
3
3
|
|
|
4
|
-
import { TlaProofError } from "
|
|
4
|
+
import { TlaProofError } from "../../errors";
|
|
5
5
|
|
|
6
6
|
interface OcamlBlock {
|
|
7
7
|
tag: number;
|
package/src/prove/verdict.ts
CHANGED
|
@@ -11,8 +11,3 @@ export interface DecideOptions {
|
|
|
11
11
|
timeLimitMs: number;
|
|
12
12
|
signal?: AbortSignal;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
// V8's error when a recursion runs out of stack. The backends run as their own processes, which grow
|
|
16
|
-
// their stacks or fail the obligation alone, so a backend ported in process answers unknown instead.
|
|
17
|
-
export const isStackOverflow = (error: unknown) =>
|
|
18
|
-
error instanceof RangeError && error.message === "Maximum call stack size exceeded";
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
// Ported from Zenon's main.ml, as shipped in tlapm. Copyright 1997 INRIA, see LICENSE.
|
|
2
2
|
//
|
|
3
|
-
// Runs Zenon
|
|
4
|
-
// accepts it.
|
|
5
|
-
//
|
|
6
|
-
// tlapm passes -max-time 1d, so Zenon's own clock never stops it. The time limit is tlapm's
|
|
7
|
-
// timeout instead: Schedule.run kills Zenon once the wall clock passes its launch time plus the
|
|
8
|
-
// timeout, whether Zenon is still reading the file, searching or printing the proof.
|
|
9
|
-
//
|
|
10
|
-
// tlapm also passes -oisar, so Zenon prints the proof as Isar text. tlapm writes that output,
|
|
11
|
-
// after a comment with Zenon's input, into the module's .thy file for Isabelle to check.
|
|
3
|
+
// Runs Zenon on a .znn file as tlapm does, with -oisar. A proof counts only once the independent
|
|
4
|
+
// checker accepts it. tlapm passes -max-time 1d and kills Zenon at its own timeout instead, whether
|
|
5
|
+
// Zenon is still reading, searching or printing the proof.
|
|
12
6
|
|
|
13
7
|
import { TlaZenonError } from "../../errors";
|
|
14
8
|
import type { DecideOptions } from "../verdict";
|
|
@@ -24,7 +18,7 @@ import type { Proof } from "./proof";
|
|
|
24
18
|
import { search, type SearchFailure } from "./search";
|
|
25
19
|
import { getBuiltInDefinitions, PREDEFINED_SYMBOLS } from "./tla/tla";
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
interface ZenonRun {
|
|
28
22
|
proof: Proof | undefined;
|
|
29
23
|
// Why Zenon gave up: in the search, or at the limits while it checked or printed the proof.
|
|
30
24
|
// "zenon error" stands for the exceptions that stop Zenon mid-search.
|
|
@@ -103,7 +97,7 @@ export const runZenon = (text: string, options: DecideOptions): ZenonRun => {
|
|
|
103
97
|
};
|
|
104
98
|
};
|
|
105
99
|
|
|
106
|
-
|
|
100
|
+
type ZenonDecision = { verdict: "unsat"; proof: string } | { verdict: "unknown" };
|
|
107
101
|
|
|
108
102
|
// Zenon's verdict on a .znn file: "unsat" with the Isar proof that tlapm writes, when Zenon refutes
|
|
109
103
|
// the hypotheses with a proof that the checker accepts and prints it within the time limit.
|
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
// each visible fact and a $goal, naming identifiers as Isabelle does.
|
|
3
3
|
|
|
4
4
|
import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../../errors";
|
|
5
|
-
import { createContext, getBoundName, popNames, pushName } from "../../obligations/
|
|
6
|
-
import {
|
|
7
|
-
shiftExpr,
|
|
8
|
-
type Bound,
|
|
9
|
-
type Builtin,
|
|
10
|
-
type Expr,
|
|
11
|
-
type Hyp,
|
|
12
|
-
type Sequent,
|
|
13
|
-
} from "../../obligations/expression";
|
|
5
|
+
import { createContext, getBoundName, popNames, pushName } from "../../obligations/printer";
|
|
6
|
+
import type { Bound, Builtin, Expr, Hyp, Sequent } from "../../obligations/expression";
|
|
14
7
|
import { format, formatDelimited, renderDoc, text, type Doc } from "../../obligations/format";
|
|
15
|
-
import { pickle } from "
|
|
8
|
+
import { getUnprintableError, pickle, printFact, splitFirstBound } from "../first-order";
|
|
16
9
|
|
|
17
10
|
const SPACE = format("@ ");
|
|
18
11
|
|
|
@@ -76,17 +69,6 @@ const OPERATORS: Partial<Record<Builtin, [string, number]>> = {
|
|
|
76
69
|
ToString: ["TLA.ToString", 1],
|
|
77
70
|
};
|
|
78
71
|
|
|
79
|
-
// The temporal operators Zenon has no counterpart for, by the name tlapm reports.
|
|
80
|
-
const TEMPORAL_OPERATORS: Partial<Record<Builtin, [string, number]>> = {
|
|
81
|
-
Leadsto: ["Leadsto", 2],
|
|
82
|
-
ENABLED: ["ENABLED", 1],
|
|
83
|
-
Cdot: ["\\cdot", 2],
|
|
84
|
-
Actplus: ["-+->", 2],
|
|
85
|
-
BoxTrue: ["[]", 1],
|
|
86
|
-
BoxFalse: ["[]", 1],
|
|
87
|
-
Diamond: ["<>", 1],
|
|
88
|
-
};
|
|
89
|
-
|
|
90
72
|
const getSuccessors = (integer: string) => {
|
|
91
73
|
const count = Number.parseInt(integer, 10);
|
|
92
74
|
return `${"(TLA.fapply TLA.Succ ".repeat(count)}0${")".repeat(count)}`;
|
|
@@ -104,9 +86,9 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
104
86
|
const nonatomic = (name: string, args: Expr[]) => format("(%s %a)", name, delimited(args));
|
|
105
87
|
|
|
106
88
|
// A binder's name binds in the body, and what comes before prints outside it.
|
|
107
|
-
const printBinder = (name: string, before: Doc, body: Expr
|
|
89
|
+
const printBinder = (name: string, before: Doc, body: Expr) => {
|
|
108
90
|
const bound = adjoin(name);
|
|
109
|
-
const doc = format("%a((%s) %a)
|
|
91
|
+
const doc = format("%a((%s) %a))", before, bound, printExpr(body));
|
|
110
92
|
popNames(context, 1);
|
|
111
93
|
return doc;
|
|
112
94
|
};
|
|
@@ -139,12 +121,7 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
139
121
|
}
|
|
140
122
|
}
|
|
141
123
|
if (builtin === "Unprimable" && args.length === 1) return printExpr(args[0]);
|
|
142
|
-
|
|
143
|
-
if (isFrontend && args.length === 1) throw new TlapmBugError();
|
|
144
|
-
const temporal = TEMPORAL_OPERATORS[builtin];
|
|
145
|
-
if (temporal && temporal[1] === args.length)
|
|
146
|
-
throw new TlaProverError(`Unsupported operator \`${temporal[0]}\`.\n`);
|
|
147
|
-
throw new TlaProverError("Backend.Zenon.fmt_apply");
|
|
124
|
+
throw getUnprintableError(builtin, args.length, "Backend.Zenon.fmt_apply");
|
|
148
125
|
};
|
|
149
126
|
|
|
150
127
|
const printApply = (operator: Expr, args: Expr[]): Doc => {
|
|
@@ -171,42 +148,18 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
171
148
|
}
|
|
172
149
|
};
|
|
173
150
|
|
|
174
|
-
// The first bound binds around a quantifier over the others, which move under it.
|
|
175
151
|
const printQuant = (quantifier: "Forall" | "Exists", bounds: Bound[], body: Expr): Doc => {
|
|
176
152
|
if (bounds.length === 0) return printExpr(body);
|
|
177
|
-
const
|
|
178
|
-
const rest = bounds.slice(1);
|
|
179
|
-
const undittoed =
|
|
180
|
-
rest[0]?.domain.kind === "Ditto"
|
|
181
|
-
? [{ ...rest[0], domain: bound.domain }, ...rest.slice(1)]
|
|
182
|
-
: rest;
|
|
183
|
-
const inner: Expr =
|
|
184
|
-
undittoed.length === 0
|
|
185
|
-
? body
|
|
186
|
-
: {
|
|
187
|
-
kind: "Quant",
|
|
188
|
-
quantifier,
|
|
189
|
-
bounds: undittoed.map((other) =>
|
|
190
|
-
other.domain.kind === "Domain"
|
|
191
|
-
? {
|
|
192
|
-
...other,
|
|
193
|
-
domain: { kind: "Domain", expression: shiftExpr(1, other.domain.expression) },
|
|
194
|
-
}
|
|
195
|
-
: other,
|
|
196
|
-
),
|
|
197
|
-
body,
|
|
198
|
-
location: body.location,
|
|
199
|
-
};
|
|
153
|
+
const split = splitFirstBound(quantifier, bounds, body);
|
|
200
154
|
const isForall = quantifier === "Forall";
|
|
201
|
-
if (
|
|
202
|
-
return printBinder(
|
|
203
|
-
if (
|
|
204
|
-
const domain = printExpr(
|
|
155
|
+
if (split.first.domain.kind === "NoDomain")
|
|
156
|
+
return printBinder(split.first.name, text(isForall ? "(A. " : "(E. "), split.inner);
|
|
157
|
+
if (split.first.domain.kind !== "Domain") throw new TlapmBugError();
|
|
158
|
+
const domain = printExpr(split.first.domain.expression);
|
|
205
159
|
return printBinder(
|
|
206
|
-
|
|
160
|
+
split.first.name,
|
|
207
161
|
format("(%s %a ", isForall ? "TLA.bAll" : "TLA.bEx", domain),
|
|
208
|
-
inner,
|
|
209
|
-
")",
|
|
162
|
+
split.inner,
|
|
210
163
|
);
|
|
211
164
|
};
|
|
212
165
|
|
|
@@ -219,7 +172,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
219
172
|
bound.name,
|
|
220
173
|
format("(%s %a ", name, printExpr(bound.domain.expression)),
|
|
221
174
|
body,
|
|
222
|
-
")",
|
|
223
175
|
);
|
|
224
176
|
};
|
|
225
177
|
|
|
@@ -293,15 +245,13 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
293
245
|
expression.name,
|
|
294
246
|
format("(TLA.bChoice %a ", printExpr(expression.domain)),
|
|
295
247
|
expression.body,
|
|
296
|
-
")",
|
|
297
248
|
)
|
|
298
|
-
: printBinder(expression.name, text("(t. "), expression.body
|
|
249
|
+
: printBinder(expression.name, text("(t. "), expression.body);
|
|
299
250
|
case "SetSt":
|
|
300
251
|
return printBinder(
|
|
301
252
|
expression.name,
|
|
302
253
|
format("(TLA.subsetOf %a ", printExpr(expression.domain)),
|
|
303
254
|
expression.body,
|
|
304
|
-
")",
|
|
305
255
|
);
|
|
306
256
|
case "SetOf":
|
|
307
257
|
return printOneBound("TLA.setOfAll", expression.bounds, expression.element, "Setof");
|
|
@@ -315,10 +265,10 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
315
265
|
text(")"),
|
|
316
266
|
];
|
|
317
267
|
case "FcnApp": {
|
|
318
|
-
const
|
|
268
|
+
const printedFunction = printExpr(expression.function);
|
|
319
269
|
return expression.args.length === 1
|
|
320
|
-
? format("(TLA.fapply %a %a)",
|
|
321
|
-
: format("(TLA.fapply %a (TLA.tuple %a))",
|
|
270
|
+
? format("(TLA.fapply %a %a)", printedFunction, printExpr(expression.args[0]))
|
|
271
|
+
: format("(TLA.fapply %a (TLA.tuple %a))", printedFunction, delimited(expression.args));
|
|
322
272
|
}
|
|
323
273
|
case "Arrow":
|
|
324
274
|
return format(
|
|
@@ -385,18 +335,6 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
385
335
|
}
|
|
386
336
|
};
|
|
387
337
|
|
|
388
|
-
// tlapm prints a fact to a formatter that drops its output first, to omit an unsupported one.
|
|
389
|
-
const getFactDoc = (expression: Expr) => {
|
|
390
|
-
const depth = context.stack.length;
|
|
391
|
-
try {
|
|
392
|
-
return printExpr(expression);
|
|
393
|
-
} catch (error) {
|
|
394
|
-
if (!(error instanceof TlaUnsupportedError)) throw error;
|
|
395
|
-
popNames(context, context.stack.length - depth);
|
|
396
|
-
return error;
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
338
|
const printHyp = (hyp: Hyp): Doc => {
|
|
401
339
|
switch (hyp.kind) {
|
|
402
340
|
case "Fresh": {
|
|
@@ -416,7 +354,10 @@ export const encodeZenon = (id: number, sequent: Sequent) => {
|
|
|
416
354
|
}
|
|
417
355
|
case "Fact": {
|
|
418
356
|
const count = String(context.stack.length);
|
|
419
|
-
const fact =
|
|
357
|
+
const fact =
|
|
358
|
+
hyp.visibility === "Visible"
|
|
359
|
+
? printFact(context, () => printExpr(hyp.expression))
|
|
360
|
+
: undefined;
|
|
420
361
|
bump();
|
|
421
362
|
if (fact instanceof TlaUnsupportedError)
|
|
422
363
|
return format("; omitted temporal assumption : %s @.", fact.message);
|
package/src/prove/zenon/eqrel.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { insertNode, type Priority, type Queue } from "./node";
|
|
|
20
20
|
import { makeRelationRule, makeRule } from "./proof";
|
|
21
21
|
import { insertAll, makeNode, unequal, type SearchContext, type SearchRule } from "./rules";
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const makeInstance = (
|
|
24
24
|
exprs: Expressions,
|
|
25
25
|
queue: Queue,
|
|
26
26
|
quantified: Expr,
|
package/src/prove/zenon/expr.ts
CHANGED
|
@@ -115,7 +115,7 @@ const isBinary = (expression: Expr): expression is BinaryExpr =>
|
|
|
115
115
|
expression.kind === "imply" ||
|
|
116
116
|
expression.kind === "equiv";
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
const isBinder = (expression: Expr): expression is BinderExpr =>
|
|
119
119
|
expression.kind === "all" ||
|
|
120
120
|
expression.kind === "ex" ||
|
|
121
121
|
expression.kind === "tau" ||
|
|
@@ -253,7 +253,7 @@ export const compareExprs = (left: Expr, right: Expr): number => {
|
|
|
253
253
|
return 0;
|
|
254
254
|
};
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
type Substitution = [Expr, Expr][];
|
|
257
257
|
|
|
258
258
|
const lookup = (map: Substitution, variable: Expr) => map.find((pair) => pair[0] === variable)?.[1];
|
|
259
259
|
|
|
@@ -45,7 +45,7 @@ const getLatestFirst = <Key, Value>(table: Map<Key, Value[]>, key: Key) =>
|
|
|
45
45
|
[...(table.get(key) ?? [])].reverse();
|
|
46
46
|
|
|
47
47
|
// Zenon's head of a term, or undefined for No_head. Taus and metavariables are heads by identity.
|
|
48
|
-
|
|
48
|
+
type Head = string | Expr;
|
|
49
49
|
|
|
50
50
|
export const getHead = (expression: Expr): Head | undefined => {
|
|
51
51
|
switch (expression.kind) {
|
package/src/prove/zenon/isar.ts
CHANGED
|
@@ -105,7 +105,7 @@ const increment = (indent: number) => (indent >= 15 ? indent : indent + 1);
|
|
|
105
105
|
// What the search knew when it found a proof: the .znn file's phrases, the proofs that it reused
|
|
106
106
|
// and the properties of relations that the hypotheses stated. The printer stops at the search's
|
|
107
107
|
// limits.
|
|
108
|
-
|
|
108
|
+
interface IsarContext {
|
|
109
109
|
exprs: Expressions;
|
|
110
110
|
phrases: Phrase[];
|
|
111
111
|
sharedProofs: ReadonlySet<MlProof>;
|
|
@@ -53,7 +53,7 @@ export const connect = (exprs: Expressions, connective: Connective, left: Expr,
|
|
|
53
53
|
? exprs.eimply(left, right)
|
|
54
54
|
: exprs.eequiv(left, right);
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
const getLemma = (lemmas: Map<string, Lemma>, name: string) => {
|
|
57
57
|
const lemma = lemmas.get(name);
|
|
58
58
|
if (lemma === undefined) throw new TlaZenonError(`Zenon: no lemma ${name}`);
|
|
59
59
|
return lemma;
|
|
@@ -30,7 +30,7 @@ export interface MlProof {
|
|
|
30
30
|
// A translated proof, with the hypotheses it uses that aren't conclusions of the node.
|
|
31
31
|
export type Translated = [LlProof, Expr[]];
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
interface TranslateContext {
|
|
34
34
|
exprs: Expressions;
|
|
35
35
|
// Zenon's Index.get_number, which also names the formulas in the Isar output.
|
|
36
36
|
getNumber: (expression: Expr) => number;
|
package/src/prove/zenon/node.ts
CHANGED
|
@@ -135,7 +135,7 @@ interface Frame {
|
|
|
135
135
|
current: number;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
interface SearchStatistics {
|
|
139
139
|
inferences: number;
|
|
140
140
|
proofNodes: number;
|
|
141
141
|
// The proofs that closed another branch from the lemma cache. Zenon counts the uses in mlrefc and
|
|
@@ -40,25 +40,6 @@ export const SET_CONSTRUCTORS = [
|
|
|
40
40
|
|
|
41
41
|
export const FUNCTION_CONSTRUCTORS = ["TLA.Fcn", "TLA.except", "TLA.oneArg", "TLA.extend"];
|
|
42
42
|
|
|
43
|
-
const OTHER_SYMBOLS = [
|
|
44
|
-
"TLA.in",
|
|
45
|
-
"TLA.isAFcn",
|
|
46
|
-
"TLA.cond",
|
|
47
|
-
"TLA.CASE",
|
|
48
|
-
"TLA.tuple",
|
|
49
|
-
"TLA.record",
|
|
50
|
-
"TLA.fapply",
|
|
51
|
-
"TLA.box",
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
// The symbols that hypotheses can't define, as Zenon's predef with the tla extension.
|
|
55
|
-
export const PREDEFINED_SYMBOLS = [
|
|
56
|
-
"=",
|
|
57
|
-
...SET_CONSTRUCTORS,
|
|
58
|
-
...FUNCTION_CONSTRUCTORS,
|
|
59
|
-
...OTHER_SYMBOLS,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
43
|
export const isVariable = (expression: Expr, name: string) =>
|
|
63
44
|
expression.kind === "var" && expression.symbol === name;
|
|
64
45
|
|
|
@@ -68,7 +49,7 @@ export const isConstructor = (constructors: string[], expression: Expr) =>
|
|
|
68
49
|
|
|
69
50
|
export const isNotEquiv = (expression: Expr) => isApp(expression, "$notequiv");
|
|
70
51
|
|
|
71
|
-
|
|
52
|
+
const isString = (expression: Expr) => isApp(expression, "$string");
|
|
72
53
|
|
|
73
54
|
export const equal = (exprs: Expressions, left: Expr, right: Expr) =>
|
|
74
55
|
exprs.eapp("=", [left, right]);
|
package/src/randomization.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createJavaOverrideError,
|
|
3
|
+
createModuleArgumentError,
|
|
4
|
+
defineStateOperator,
|
|
5
|
+
getValue,
|
|
6
|
+
} from "./builtins";
|
|
3
7
|
import type { Builtin, BuiltinArgument } from "./evaluate";
|
|
4
8
|
import type { CheckerRuntime } from "./runtime";
|
|
5
|
-
import { getEnumeratedFactors, getRandomSubset, type JavaRandom } from "./tlc
|
|
9
|
+
import { getEnumeratedFactors, getRandomSubset, type JavaRandom } from "./tlc/random";
|
|
6
10
|
import {
|
|
7
11
|
createSet,
|
|
8
12
|
createTuple,
|
|
9
|
-
formatValue,
|
|
10
13
|
isEmptySet,
|
|
11
14
|
isEnumerable,
|
|
12
15
|
isSetValue,
|
|
@@ -20,25 +23,13 @@ const RANDOM_SUBSET_SIGNATURE =
|
|
|
20
23
|
// TLCGlobals.setBound: TLC 1.7.4's ValueVec holds at most this many elements of a set.
|
|
21
24
|
const SET_BOUND_174 = 1000000;
|
|
22
25
|
|
|
23
|
-
const createArgumentError = (position: string, name: string, expected: string, value: string) =>
|
|
24
|
-
new TlaModuleError(
|
|
25
|
-
`The ${position} argument of ${name} should be a ${expected}, but instead it is:\n${value}`,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
26
|
const getCount = (value: Value, position: string, name: string) => {
|
|
29
27
|
if (typeof value !== "number" || value < 0) {
|
|
30
|
-
throw
|
|
28
|
+
throw createModuleArgumentError(position, name, "nonnegative integer", value);
|
|
31
29
|
}
|
|
32
30
|
return value;
|
|
33
31
|
};
|
|
34
32
|
|
|
35
|
-
const getFiniteElements = (value: Value, position: string, name: string, expected: string) => {
|
|
36
|
-
if (!isSetValue(value) || !isEnumerable(value)) {
|
|
37
|
-
throw createArgumentError(position, name, expected, formatValue(value));
|
|
38
|
-
}
|
|
39
|
-
return toFiniteSet(value).elements;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
33
|
// SubsetValue.CoinTossingSubsetEnumerator: each pick keeps each element with the probability.
|
|
43
34
|
const tossSubsets = (elements: Value[], picks: number, probability: number, random: JavaRandom) =>
|
|
44
35
|
createSet(
|
|
@@ -51,21 +42,25 @@ const getRandomSetOfSubsets = (args: BuiltinArgument[], runtime: CheckerRuntime)
|
|
|
51
42
|
const name = "RandomSetOfSubsets";
|
|
52
43
|
const picks = getCount(getValue(args, 0, name), "first", name);
|
|
53
44
|
const size = getCount(getValue(args, 1, name), "second", name);
|
|
54
|
-
const
|
|
45
|
+
const set = getValue(args, 2, name);
|
|
46
|
+
if (!isSetValue(set) || !isEnumerable(set)) {
|
|
47
|
+
throw createModuleArgumentError("third", name, "finite set", set);
|
|
48
|
+
}
|
|
49
|
+
const elements = toFiniteSet(set).elements;
|
|
55
50
|
if (elements.length < 31 && picks > 2 ** elements.length) {
|
|
56
|
-
throw
|
|
51
|
+
throw createModuleArgumentError(
|
|
57
52
|
"first",
|
|
58
53
|
name,
|
|
59
54
|
`nonnegative integer that is smaller than the subset's size of 2^${elements.length}`,
|
|
60
|
-
|
|
55
|
+
picks,
|
|
61
56
|
);
|
|
62
57
|
}
|
|
63
58
|
if (elements.length < size) {
|
|
64
|
-
throw
|
|
59
|
+
throw createModuleArgumentError(
|
|
65
60
|
"second",
|
|
66
61
|
name,
|
|
67
62
|
"nonnegative integer in range 0..Cardinality(S)",
|
|
68
|
-
|
|
63
|
+
size,
|
|
69
64
|
);
|
|
70
65
|
}
|
|
71
66
|
return tossSubsets(
|
|
@@ -80,14 +75,14 @@ export const createRandomizationOperators = (runtime: CheckerRuntime): Builtin[]
|
|
|
80
75
|
defineStateOperator("RandomSubset", 2, (args) => {
|
|
81
76
|
const count = getValue(args, 0, "RandomSubset");
|
|
82
77
|
if (typeof count !== "number") {
|
|
83
|
-
throw
|
|
78
|
+
throw createModuleArgumentError("first", "RandomSubset", "nonnegative integer", count);
|
|
84
79
|
}
|
|
85
80
|
if (count < 0) {
|
|
86
81
|
throw createJavaOverrideError(RANDOM_SUBSET_SIGNATURE, String(count));
|
|
87
82
|
}
|
|
88
83
|
const set = getValue(args, 1, "RandomSubset");
|
|
89
84
|
if (!isSetValue(set) || (!isEmptySet(set) && !isEnumerable(set))) {
|
|
90
|
-
throw
|
|
85
|
+
throw createModuleArgumentError("second", "RandomSubset", "a finite set", set);
|
|
91
86
|
}
|
|
92
87
|
const factors = getEnumeratedFactors(set, runtime.version);
|
|
93
88
|
if (factors) {
|
package/src/resolve.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type SymbolKind =
|
|
|
36
36
|
|
|
37
37
|
// range is where SANY reports the symbol, and two symbols at one range are one node to SANY. params
|
|
38
38
|
// holds the arity of each parameter of a defined operator.
|
|
39
|
-
|
|
39
|
+
interface Binding {
|
|
40
40
|
kind: SymbolKind;
|
|
41
41
|
arity: number;
|
|
42
42
|
params?: number[];
|
|
@@ -74,14 +74,7 @@ interface ModuleBinding extends Binding {
|
|
|
74
74
|
isPending?: boolean;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
//
|
|
78
|
-
// holds the names the module binds. A label may appear where hasLabelScope holds, in a definition, a
|
|
79
|
-
// named theorem, or a numbered step, except where isLabelForbidden holds, in the scope of a NEW in a
|
|
80
|
-
// nested ASSUME, or where isInExcept holds, in the new value of an EXCEPT. labelParams holds the
|
|
81
|
-
// names bound since the innermost definition, label, or step, which a label must take as parameters,
|
|
82
|
-
// and labels the labels there. isGenerated holds in a definition tla-ts generates for a LET INSTANCE,
|
|
83
|
-
// and in a subexpression that a name selects, which SANY analyzes where it is defined.
|
|
84
|
-
// getInstance gives what an INSTANCE in a LET or a proof instantiates.
|
|
77
|
+
// What SANY reports while it goes on analyzing a unit of a module, and the scope it analyzes it in.
|
|
85
78
|
interface Unit {
|
|
86
79
|
imported: Symbols;
|
|
87
80
|
getInstance: (instance: Instance) => InstancedModule;
|
|
@@ -94,11 +87,15 @@ interface Unit {
|
|
|
94
87
|
bindings: Map<string, ModuleBinding>;
|
|
95
88
|
errors: SanyError[];
|
|
96
89
|
warnings: SanyError[];
|
|
90
|
+
// In a definition, a named theorem, or a numbered step.
|
|
97
91
|
hasLabelScope: boolean;
|
|
92
|
+
// In the scope of a NEW in a nested ASSUME.
|
|
98
93
|
isLabelForbidden: boolean;
|
|
99
94
|
isInExcept: boolean;
|
|
95
|
+
// The names bound since the innermost definition, label, or step, which a label must take.
|
|
100
96
|
labelParams: string[];
|
|
101
97
|
labels: Set<string>;
|
|
98
|
+
// In a definition generated for a LET INSTANCE, or a subexpression analyzed where it is defined.
|
|
102
99
|
isGenerated: boolean;
|
|
103
100
|
}
|
|
104
101
|
|
|
@@ -168,10 +165,8 @@ const getModuleBinding = (name: string, unit: Unit, range: SourceRange | undefin
|
|
|
168
165
|
const isSameRange = (left: SourceRange | undefined, right: SourceRange | undefined) =>
|
|
169
166
|
left !== undefined && right !== undefined && formatRange(left) === formatRange(right);
|
|
170
167
|
|
|
171
|
-
// SymbolTable.addSymbol
|
|
172
|
-
// or
|
|
173
|
-
// of any other duplicate. tla-ts binds a symbol SANY never sees, such as one it generates. Tells
|
|
174
|
-
// whether to bind the added symbol.
|
|
168
|
+
// SymbolTable.addSymbol: rejects redefining a built-in, a bound name, or a symbol of another kind
|
|
169
|
+
// or arity, and warns of any other duplicate. A symbol SANY never sees, such as a generated one, binds.
|
|
175
170
|
const isBindable = (name: string, current: Binding | undefined, added: Binding, unit: Unit) => {
|
|
176
171
|
if (current === undefined) return true;
|
|
177
172
|
if (isSameRange(current.range, added.range)) return false;
|
|
@@ -1447,7 +1442,7 @@ const resolveTheorem = (theorem: Theorem, unit: Unit) => {
|
|
|
1447
1442
|
|
|
1448
1443
|
// The declarations of the module an INSTANCE instantiates, the names the INSTANCE adds, and the
|
|
1449
1444
|
// module that instantiates it.
|
|
1450
|
-
|
|
1445
|
+
interface InstancedModule {
|
|
1451
1446
|
declarations: Declaration[];
|
|
1452
1447
|
symbols: Symbols;
|
|
1453
1448
|
instancer: string;
|
|
@@ -1461,18 +1456,16 @@ export interface ModuleReport {
|
|
|
1461
1456
|
warnings: SanyError[];
|
|
1462
1457
|
}
|
|
1463
1458
|
|
|
1464
|
-
// bound holds the names in scope where the module starts: the built-in operators, the names of the
|
|
1465
|
-
// module that encloses it, and those of the modules it extends. instanced holds the names each
|
|
1466
|
-
// INSTANCE adds, getInstance what an INSTANCE in a LET or a proof instantiates, facts the theorems
|
|
1467
|
-
// and assumptions the modules it extends or instantiates export, and warnings the warnings SANY
|
|
1468
|
-
// reports for the spec.
|
|
1469
1459
|
export interface ModuleUnit {
|
|
1470
1460
|
imported: Symbols;
|
|
1471
1461
|
getInstance: (instance: Instance) => InstancedModule;
|
|
1462
|
+
// The built-in operators and the names of the enclosing and extended modules.
|
|
1472
1463
|
bound: Symbols;
|
|
1473
1464
|
definitions: Map<string, Definition>;
|
|
1474
1465
|
getKey: (definition: Definition) => string;
|
|
1466
|
+
// The names each INSTANCE adds.
|
|
1475
1467
|
instanced: Map<Instance, Symbols>;
|
|
1468
|
+
// The theorems and assumptions the extended and instantiated modules export.
|
|
1476
1469
|
facts: Set<string>;
|
|
1477
1470
|
reports: ModuleReport[];
|
|
1478
1471
|
warnings: SanyError[];
|
|
@@ -1631,7 +1624,7 @@ export const collectSemanticErrors = (
|
|
|
1631
1624
|
warnings: SanyError[],
|
|
1632
1625
|
) => {
|
|
1633
1626
|
const errors: SanyError[] = [];
|
|
1634
|
-
const
|
|
1627
|
+
const addUnique = (list: SanyError[], item: SanyError) => {
|
|
1635
1628
|
if (
|
|
1636
1629
|
list.every(
|
|
1637
1630
|
(existing) => existing.location !== item.location || existing.message !== item.message,
|
|
@@ -1659,8 +1652,8 @@ export const collectSemanticErrors = (
|
|
|
1659
1652
|
}
|
|
1660
1653
|
reported.push(...(error.sany?.errors ?? []));
|
|
1661
1654
|
}
|
|
1662
|
-
reported.forEach((item) =>
|
|
1663
|
-
warned.forEach((item) =>
|
|
1655
|
+
reported.forEach((item) => addUnique(errors, item));
|
|
1656
|
+
warned.forEach((item) => addUnique(warnings, item));
|
|
1664
1657
|
});
|
|
1665
1658
|
return errors;
|
|
1666
1659
|
};
|