tla-ts 0.0.10-dev.3a85c3a9e → 0.0.10-dev.45c0eaef5
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/compile.cjs +3 -3
- package/dist/compile.js +1 -1
- package/dist/deciders.cjs +36 -36
- package/dist/deciders.js +53 -53
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- 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 +56 -56
- package/dist/prove.js +79 -79
- package/dist/run.cjs +40 -44
- package/dist/run.js +42 -46
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +97 -92
- package/dist/transfer.js +97 -92
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +31 -3
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +13 -11
- package/src/check-trace.ts +146 -107
- package/src/check.ts +535 -281
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +21 -7
- package/src/cli/tlc.ts +31 -11
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +23 -10
- package/src/coverage.ts +255 -18
- package/src/dependencies.ts +68 -15
- package/src/dfid.ts +101 -36
- package/src/environment.ts +131 -41
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +424 -135
- package/src/exit-codes.ts +28 -13
- package/src/instances.ts +135 -11
- package/src/java-hash.ts +14 -0
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +675 -236
- package/src/lexer.ts +12 -2
- package/src/liveness-checker.ts +204 -62
- package/src/liveness.ts +55 -10
- package/src/obligations/index.ts +1 -1
- package/src/obligations/normalize.ts +1 -4
- package/src/obligations/printer.ts +5 -5
- package/src/obligations/source.ts +2 -0
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/parser.ts +180 -149
- package/src/prover/isabelle/isar/attrib.ts +4 -4
- package/src/prover/isabelle/isar/rule-cases.ts +8 -6
- package/src/prover/isabelle/provers/clasimp.ts +1 -1
- package/src/prover/isabelle/provers/hypsubst.ts +2 -2
- package/src/prover/isabelle/pure/rewriter.ts +3 -3
- package/src/prover/isabelle/pure/term.ts +3 -3
- package/src/prover/prep/md5.ts +26 -29
- package/src/prover/smt/rewrite.ts +2 -7
- package/src/prover/smt/simplify.ts +1 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +171 -58
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +66 -14
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +27 -1
- package/src/prover/smt/solver/blast-term-ite.ts +47 -0
- package/src/prover/smt/solver/bound-simplifier.ts +11 -13
- package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
- package/src/prover/smt/solver/bv-rewriter.ts +1 -1
- package/src/prover/smt/solver/card2bv.ts +35 -18
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
- package/src/prover/smt/solver/context.ts +84 -15
- package/src/prover/smt/solver/ctx-simplify.ts +1 -2
- package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +28 -16
- package/src/prover/smt/solver/diff-neq.ts +1 -2
- package/src/prover/smt/solver/dt2bv-tactic.ts +57 -21
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +5 -8
- package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/egraph.ts +4 -10
- package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
- package/src/prover/smt/solver/euf/mam.ts +1 -5
- package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
- package/src/prover/smt/solver/euf/th-solver.ts +0 -7
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fd-solver.ts +608 -139
- package/src/prover/smt/solver/fix-dl-var.ts +1 -2
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
- package/src/prover/smt/solver/goal.ts +6 -3
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/hashtable.ts +4 -0
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/logic-tactics.ts +15 -5
- package/src/prover/smt/solver/lp/containers.ts +7 -1
- package/src/prover/smt/solver/lp/core-solver.ts +12 -8
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +6 -2
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -2
- package/src/prover/smt/solver/lp/nex.ts +2 -1
- package/src/prover/smt/solver/lp/nla-basics.ts +46 -1
- package/src/prover/smt/solver/lp/nla-core.ts +26 -6
- package/src/prover/smt/solver/lp/nla-grobner.ts +158 -81
- package/src/prover/smt/solver/lp/nra-solver.ts +138 -95
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -290
- package/src/prover/smt/solver/lp/union-find.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +1 -1
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-based-opt.ts +1 -1
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +85 -43
- package/src/prover/smt/solver/mpf.ts +2 -4
- package/src/prover/smt/solver/mus.ts +2 -3
- package/src/prover/smt/solver/muz/dl-context.ts +22 -44
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
- package/src/prover/smt/solver/muz/dl-rule.ts +8 -9
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
- package/src/prover/smt/solver/muz/horn-tactic.ts +15 -2
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/nlqsat.ts +1 -1
- package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
- package/src/prover/smt/solver/nlsat/solver.ts +74 -71
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
- package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
- package/src/prover/smt/solver/nnf.ts +6 -2
- package/src/prover/smt/solver/opt-context.ts +21 -7
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-preprocess.ts +1 -1
- package/src/prover/smt/solver/opt-solver.ts +10 -6
- package/src/prover/smt/solver/optsmt.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/pb-rewriter.ts +1 -4
- package/src/prover/smt/solver/poly-rewriter.ts +75 -18
- package/src/prover/smt/solver/probes.ts +88 -23
- package/src/prover/smt/solver/proto-model.ts +8 -8
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
- package/src/prover/smt/solver/qe-lite.ts +2 -2
- package/src/prover/smt/solver/qe.ts +3 -2
- package/src/prover/smt/solver/qsat.ts +23 -8
- package/src/prover/smt/solver/quantifier-manager.ts +14 -9
- package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/rlimit.ts +20 -3
- package/src/prover/smt/solver/sat/config.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +65 -12
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +129 -43
- package/src/prover/smt/solver/sat/model-converter.ts +1 -1
- package/src/prover/smt/solver/sat/pb-constraint.ts +7 -0
- package/src/prover/smt/solver/sat/pb-solver.ts +26 -7
- package/src/prover/smt/solver/sat/sat-tactic.ts +17 -7
- package/src/prover/smt/solver/sat/sat2goal.ts +72 -48
- package/src/prover/smt/solver/sat/simplifier.ts +1 -1
- package/src/prover/smt/solver/sat/solver.ts +27 -47
- package/src/prover/smt/solver/seq-axioms.ts +20 -35
- package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
- package/src/prover/smt/solver/seq-derive.ts +4 -7
- package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
- package/src/prover/smt/solver/seq-monadic.ts +7 -5
- package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
- package/src/prover/smt/solver/seq-re-util.ts +1 -1
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +2 -2
- package/src/prover/smt/solver/seq-rewriter.ts +31 -29
- package/src/prover/smt/solver/seq-skolem.ts +0 -23
- package/src/prover/smt/solver/seq-view-witness.ts +4 -4
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +48 -7
- package/src/prover/smt/solver/smt-setup.ts +106 -13
- package/src/prover/smt/solver/smtlib-parser.ts +589 -224
- package/src/prover/smt/solver/smtlib-script.ts +713 -210
- package/src/prover/smt/solver/solve-eqs.ts +36 -37
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +350 -195
- package/src/prover/smt/solver/theory-bv.ts +13 -3
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +10 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
- package/src/prover/smt/solver/theory-lra-state.ts +1 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -1
- package/src/prover/smt/solver/theory-pb.ts +24 -7
- package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
- package/src/prover/smt/solver/theory-seq-state.ts +2 -21
- package/src/prover/smt/solver/theory-without-terms.ts +24 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/prover/tlapm/cache.ts +8 -8
- package/src/prover/zenon/equality-rules.ts +24 -0
- package/src/prover/zenon/expr.ts +21 -0
- package/src/prover/zenon/index-table.ts +7 -2
- package/src/prover/zenon/isar-case.ts +1 -1
- package/src/prover/zenon/isar.ts +2 -2
- package/src/prover/zenon/phrase.ts +1 -1
- package/src/prover/zenon/rules.ts +2 -1
- package/src/resolve.ts +1274 -258
- package/src/runtime.ts +25 -2
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +5 -15
- package/src/sany/generator-def-entries.ts +123 -36
- package/src/sany/generator-definitions.ts +5 -3
- package/src/sany/generator-expressions.ts +60 -37
- package/src/sany/generator-proofs.ts +18 -12
- package/src/sany/generator.ts +12 -6
- package/src/sany/lexer.ts +15 -7
- package/src/sany/modules.ts +4 -2
- package/src/sany/nodes.ts +1 -1
- package/src/sany/selectors.ts +11 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +348 -153
- package/src/simulate.ts +250 -185
- package/src/spec-description.ts +15 -7
- package/src/standard-definitions.ts +5 -0
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +564 -138
- package/src/successors.ts +50 -20
- package/src/symmetry.ts +2 -1
- package/src/tlc/jar-data.ts +10 -0
- package/src/tlc/messages.ts +3 -3
- package/src/tlc/order.ts +14 -3
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +147 -46
- package/src/tlc/tlc-operators.ts +10 -8
- package/src/tlc/tlcext-operators.ts +87 -26
- package/src/tlc/trace-spec.ts +11 -25
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +52 -31
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +150 -79
package/src/tlc/tlc-operators.ts
CHANGED
|
@@ -16,12 +16,13 @@ import {
|
|
|
16
16
|
toEnumeratedSet,
|
|
17
17
|
} from "../builtins";
|
|
18
18
|
import { getNamedRegisters, NAMED_REGISTER_PREFIX, type CheckerRuntime } from "../runtime";
|
|
19
|
-
import { createActionRecord, setTlcValue } from "./tlcext-operators";
|
|
19
|
+
import { createActionRecord, createTlcRecord, setTlcValue } from "./tlcext-operators";
|
|
20
20
|
import { getRandomElement } from "./random";
|
|
21
21
|
import {
|
|
22
22
|
ANY_SET,
|
|
23
23
|
createFunction,
|
|
24
24
|
createSet,
|
|
25
|
+
createSortedFunction,
|
|
25
26
|
createTuple,
|
|
26
27
|
createWrittenFunction,
|
|
27
28
|
formatNormalizedCopies,
|
|
@@ -34,7 +35,6 @@ import {
|
|
|
34
35
|
toFiniteSet,
|
|
35
36
|
type Value,
|
|
36
37
|
rankString,
|
|
37
|
-
setFunctionClass,
|
|
38
38
|
} from "../values";
|
|
39
39
|
import { getFingerprintPolynomial } from "./fingerprint";
|
|
40
40
|
import { zeroPad } from "./messages";
|
|
@@ -43,10 +43,9 @@ const formatCalendarVersion = (date: Date) =>
|
|
|
43
43
|
`${date.getUTCFullYear()}.${zeroPad(date.getUTCMonth() + 1)}.${zeroPad(date.getUTCDate())}.${zeroPad(date.getUTCHours())}${zeroPad(date.getUTCMinutes())}${zeroPad(date.getUTCSeconds())}`;
|
|
44
44
|
|
|
45
45
|
const getRegisterFunction = <Key extends Value>(registers: Map<Key, Value>) =>
|
|
46
|
-
createFunction(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
setFunctionClass(createWrittenFunction(fields), "record");
|
|
46
|
+
createFunction(
|
|
47
|
+
[...registers].map((entry): [Value, Value] => [entry[0], createTuple([entry[1]])]),
|
|
48
|
+
);
|
|
50
49
|
|
|
51
50
|
const CHECKER_KEYS = new Set(["diameter", "generated", "distinct", "queue", "stats", "config"]);
|
|
52
51
|
const TLC_174_KEYS = new Set(["diameter", "distinct", "queue", "duration", "level"]);
|
|
@@ -133,7 +132,7 @@ const getTlcValue = (runtime: CheckerRuntime, key: Value, context: Context | und
|
|
|
133
132
|
}
|
|
134
133
|
if (typeof key !== "string") {
|
|
135
134
|
throw new TlaModuleError(
|
|
136
|
-
`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
135
|
+
`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${prettyPrint(formatValue(key))}`,
|
|
137
136
|
);
|
|
138
137
|
}
|
|
139
138
|
return getRuntimeValue(runtime, key, context?.state);
|
|
@@ -160,8 +159,11 @@ const normalizeDeeply = (value: Value): void => {
|
|
|
160
159
|
const convertLikeTlcEval = (value: Value): Value => {
|
|
161
160
|
if (typeof value !== "object") return value;
|
|
162
161
|
switch (value.kind) {
|
|
163
|
-
case "ModelValue":
|
|
164
162
|
case "Function":
|
|
163
|
+
return value.functionClass === undefined
|
|
164
|
+
? value
|
|
165
|
+
: createSortedFunction(value.domain, value.range);
|
|
166
|
+
case "ModelValue":
|
|
165
167
|
case "MixedSet":
|
|
166
168
|
case "InfiniteSet":
|
|
167
169
|
case "SequenceSet":
|
|
@@ -7,8 +7,15 @@ import {
|
|
|
7
7
|
getThunk,
|
|
8
8
|
getValue,
|
|
9
9
|
} from "../builtins";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
formatRange,
|
|
12
|
+
TlaEndOfInputError,
|
|
13
|
+
TlaEvaluationError,
|
|
14
|
+
TlaModuleError,
|
|
15
|
+
TlaUnsupportedError,
|
|
16
|
+
} from "../errors";
|
|
11
17
|
import { getTlcFingerprint } from "./fingerprint";
|
|
18
|
+
import { prettyPrint } from "../pretty-print";
|
|
12
19
|
import { formatMessage, formatNestedMessage, MESSAGE_CODE, MESSAGE_LEVEL } from "./messages";
|
|
13
20
|
import {
|
|
14
21
|
describeRange,
|
|
@@ -31,10 +38,14 @@ import {
|
|
|
31
38
|
createRecord,
|
|
32
39
|
createSet,
|
|
33
40
|
createTuple,
|
|
41
|
+
createWrittenFunction,
|
|
42
|
+
formatState,
|
|
34
43
|
formatValue,
|
|
35
44
|
getFingerprintError,
|
|
36
45
|
getSequenceElements,
|
|
37
46
|
getValueKey,
|
|
47
|
+
rankString,
|
|
48
|
+
setFunctionClass,
|
|
38
49
|
toFiniteSet,
|
|
39
50
|
type Value,
|
|
40
51
|
} from "../values";
|
|
@@ -56,19 +67,31 @@ export const createActionRecord = (action: string | undefined) =>
|
|
|
56
67
|
|
|
57
68
|
const counterExamples = new WeakSet<Value & object>();
|
|
58
69
|
|
|
59
|
-
const
|
|
60
|
-
|
|
70
|
+
export const createTlcRecord = (fields: [string, Value][]) =>
|
|
71
|
+
setFunctionClass(createWrittenFunction(fields), "record");
|
|
72
|
+
|
|
73
|
+
const createCounterExampleRecord = (action: Value[], states: Value[], isConsole = true) => {
|
|
74
|
+
// TLC's CounterExample interns its field names as the class loads, which orders them as strings.
|
|
75
|
+
["state", "action", "console"].forEach(rankString);
|
|
76
|
+
const fields: [string, Value][] = [
|
|
61
77
|
["action", createSet(action)],
|
|
62
78
|
["state", createSet(states)],
|
|
63
|
-
]
|
|
79
|
+
];
|
|
80
|
+
const counterExample = createTlcRecord(isConsole ? fields : [...fields, ["console", false]]);
|
|
64
81
|
counterExamples.add(counterExample);
|
|
65
82
|
return counterExample;
|
|
66
83
|
};
|
|
67
84
|
|
|
85
|
+
export interface CounterExampleLoop {
|
|
86
|
+
start: number;
|
|
87
|
+
action: Value;
|
|
88
|
+
}
|
|
89
|
+
|
|
68
90
|
export const createCounterExample = (
|
|
69
91
|
stateRecords: Record<string, Value>[],
|
|
70
92
|
actions: Value[],
|
|
71
|
-
loop:
|
|
93
|
+
loop: CounterExampleLoop | undefined,
|
|
94
|
+
isConsole = true,
|
|
72
95
|
) => {
|
|
73
96
|
const states = stateRecords.map((state, index) =>
|
|
74
97
|
createTuple([index + 1, createRecord(Object.entries(state))]),
|
|
@@ -79,7 +102,7 @@ export const createCounterExample = (
|
|
|
79
102
|
const closing = loop
|
|
80
103
|
? [createTuple([states[states.length - 1], loop.action, states[loop.start]])]
|
|
81
104
|
: [];
|
|
82
|
-
return createCounterExampleRecord([...steps, ...closing], states);
|
|
105
|
+
return createCounterExampleRecord([...steps, ...closing], states, isConsole);
|
|
83
106
|
};
|
|
84
107
|
|
|
85
108
|
const getRegister = (runtime: CheckerRuntime, key: Value) => {
|
|
@@ -119,7 +142,7 @@ export const setTlcValue = (
|
|
|
119
142
|
return;
|
|
120
143
|
}
|
|
121
144
|
throw new TlaModuleError(
|
|
122
|
-
`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
145
|
+
`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${prettyPrint(formatValue(key))}`,
|
|
123
146
|
);
|
|
124
147
|
};
|
|
125
148
|
|
|
@@ -225,7 +248,7 @@ export const createTlcExtOperators = (
|
|
|
225
248
|
const counterExample = getValue(args, 0, "ToTrace");
|
|
226
249
|
if (typeof counterExample !== "object" || !counterExamples.has(counterExample)) {
|
|
227
250
|
throw new TlaModuleError(
|
|
228
|
-
`The argument of ToTrace should be a CounterExample, but instead it is:\n${formatValue(counterExample)}`,
|
|
251
|
+
`The argument of ToTrace should be a CounterExample, but instead it is:\n${prettyPrint(formatValue(counterExample))}`,
|
|
229
252
|
);
|
|
230
253
|
}
|
|
231
254
|
const states = toFiniteSet(applyFunction(counterExample, "state")).elements.map(
|
|
@@ -239,7 +262,7 @@ export const createTlcExtOperators = (
|
|
|
239
262
|
const name = getValue(args, 0, "TLCModelValue");
|
|
240
263
|
if (typeof name !== "string") {
|
|
241
264
|
throw new TlaModuleError(
|
|
242
|
-
`The argument of ModelValue should be a string, but instead it is:\n${formatValue(name)}`,
|
|
265
|
+
`The argument of ModelValue should be a string, but instead it is:\n${prettyPrint(formatValue(name))}`,
|
|
243
266
|
);
|
|
244
267
|
}
|
|
245
268
|
return createModelValue(name);
|
|
@@ -256,10 +279,13 @@ export const createTlcExtOperators = (
|
|
|
256
279
|
defineOperator("TLCNoOp", 1, (args) => getValue(args, 0, "TLCNoOp")),
|
|
257
280
|
{
|
|
258
281
|
...defineLazyOperator("PickSuccessor", 1, (args, context) => {
|
|
259
|
-
// Deviation from TLC: TLCExt#pickSuccessor fingerprints a partial successor and fails, where TLCExt.tla promises TRUE.
|
|
260
282
|
const next = context?.next ?? (context?.environment.variables ?? []).map(() => undefined);
|
|
261
|
-
|
|
262
|
-
if (
|
|
283
|
+
// A simulation remembers no states, so TLC evaluates the guard before it looks at the successor.
|
|
284
|
+
if (runtime.getSimulationValue === undefined) {
|
|
285
|
+
// Deviation from TLC: TLCExt#pickSuccessor fingerprints a partial successor and fails, where TLCExt.tla promises TRUE.
|
|
286
|
+
if (!isCompleteState(next)) return true;
|
|
287
|
+
if (context?.next && runtime.isSeen(next)) return true;
|
|
288
|
+
}
|
|
263
289
|
const guard = getOperator(args, 0, "PickSuccessor");
|
|
264
290
|
const isPicked = guard.call([]);
|
|
265
291
|
if (typeof isPicked !== "boolean") {
|
|
@@ -267,20 +293,55 @@ export const createTlcExtOperators = (
|
|
|
267
293
|
`In evaluating TLCExt!PickSuccessor, a non-boolean expression (${getKindString(isPicked)}) was used as the condition of an IF.\n${guard.expression ? describeNode(guard.expression) : ""}`,
|
|
268
294
|
);
|
|
269
295
|
}
|
|
270
|
-
if (
|
|
296
|
+
if (
|
|
297
|
+
isPicked ||
|
|
298
|
+
!context?.next ||
|
|
299
|
+
!isCompleteState(next) ||
|
|
300
|
+
!context.state ||
|
|
301
|
+
!isCompleteState(context.state)
|
|
302
|
+
) {
|
|
271
303
|
return true;
|
|
272
304
|
}
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
305
|
+
const state = context.state;
|
|
306
|
+
const action = runtime.getSuccessorAction(state, next);
|
|
307
|
+
const printOverride = (text: string) =>
|
|
308
|
+
print(
|
|
309
|
+
formatMessage(
|
|
310
|
+
runtime.isTool,
|
|
311
|
+
MESSAGE_CODE.moduleOverrideStdout,
|
|
312
|
+
MESSAGE_LEVEL.none,
|
|
313
|
+
text,
|
|
314
|
+
),
|
|
315
|
+
);
|
|
316
|
+
while (true) {
|
|
317
|
+
printOverride(
|
|
318
|
+
`Extend behavior of length ${runtime.getLevel(state)} with a "${action?.name}" step [<Action ${action?.location.range && formatRange(action.location.range)}>]? (Yes/no/explored/states/diff):`,
|
|
319
|
+
);
|
|
320
|
+
const answer = runtime.readLine?.();
|
|
321
|
+
// Deviation from TLC: at the end of standard input, TLC's Scanner leaks a NoSuchElementException.
|
|
322
|
+
if (answer === undefined) throw new TlaEndOfInputError();
|
|
323
|
+
if (/^[\0-\x20]*$/.test(answer) || answer.toLowerCase().startsWith("y")) return true;
|
|
324
|
+
if (answer[0] === "s") {
|
|
325
|
+
printOverride(
|
|
326
|
+
`${formatState(runtime.toRecord(state)).trimEnd()}\n~>\n${formatState(runtime.toRecord(next)).trimEnd()}`,
|
|
327
|
+
);
|
|
328
|
+
} else if (answer[0] === "d") {
|
|
329
|
+
printOverride(formatState(runtime.toRecord(next), runtime.toRecord(state)));
|
|
330
|
+
} else if (answer[0] === "e") {
|
|
331
|
+
if (runtime.markExplored) {
|
|
332
|
+
runtime.markExplored(next);
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
if (runtime.getSimulationValue === undefined) {
|
|
336
|
+
throw new TlaUnsupportedError(
|
|
337
|
+
"tla-ts can't mark a state explored while it searches depth first.",
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
printOverride(
|
|
341
|
+
"Marking a state explored is unsupported by the current TLC mode. Is TLC running in simulation mode?",
|
|
342
|
+
);
|
|
343
|
+
} else if (answer[0] === "n") return false;
|
|
344
|
+
}
|
|
284
345
|
}),
|
|
285
346
|
isActionLevel: true,
|
|
286
347
|
},
|
|
@@ -316,7 +377,7 @@ export const createTlcExtOperators = (
|
|
|
316
377
|
const name = getThunk(args, 0, "TLCEvalDefinition")();
|
|
317
378
|
if (typeof name !== "string") {
|
|
318
379
|
throw new TlaModuleError(
|
|
319
|
-
`The argument of TLCEvalDefinition should be a string, but instead it is:\n${formatValue(name)}`,
|
|
380
|
+
`The argument of TLCEvalDefinition should be a string, but instead it is:\n${prettyPrint(formatValue(name))}`,
|
|
320
381
|
);
|
|
321
382
|
}
|
|
322
383
|
const definition = context ? getDefinition(name, context.environment) : undefined;
|
|
@@ -324,7 +385,7 @@ export const createTlcExtOperators = (
|
|
|
324
385
|
if (builtin?.arity === 0) return builtin.evaluate([], context);
|
|
325
386
|
if (!definition || !context) {
|
|
326
387
|
throw new TlaModuleError(
|
|
327
|
-
`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${formatValue(name)}`,
|
|
388
|
+
`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${prettyPrint(formatValue(name))}`,
|
|
328
389
|
);
|
|
329
390
|
}
|
|
330
391
|
if (definition.kind === "Operator" && definition.params.length > 0) {
|
package/src/tlc/trace-spec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getHashMapOrder } from "../java-hash";
|
|
2
2
|
import { formatValue, type Value } from "../values";
|
|
3
3
|
import { zeroPad } from "./messages";
|
|
4
4
|
|
|
@@ -18,20 +18,6 @@ const CLOSING_TAG = `${"=".repeat(77)}\n`;
|
|
|
18
18
|
const LASSO_START = "_TTraceLassoStart";
|
|
19
19
|
const LASSO_END = "_TTraceLassoEnd";
|
|
20
20
|
|
|
21
|
-
const getHashMapHash = (text: string) => {
|
|
22
|
-
const hash = getJavaHashCode(text);
|
|
23
|
-
return hash ^ (hash >>> 16);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const getHashOrder = (names: string[]) => {
|
|
27
|
-
const unique = [...new Set(names)];
|
|
28
|
-
const capacity = 2 ** Math.max(4, Math.ceil(Math.log2(unique.length / 0.75)));
|
|
29
|
-
return unique
|
|
30
|
-
.map((name, index) => ({ name, index, bucket: getHashMapHash(name) & (capacity - 1) }))
|
|
31
|
-
.sort((left, right) => left.bucket - right.bucket || left.index - right.index)
|
|
32
|
-
.map((entry) => entry.name);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
21
|
const formatJavaDate = (date: Date) => {
|
|
36
22
|
const getPart = (options: Intl.DateTimeFormatOptions, type: Intl.DateTimeFormatPartTypes) =>
|
|
37
23
|
new Intl.DateTimeFormat("en-US", options).formatToParts(date).find((part) => part.type === type)
|
|
@@ -57,7 +43,7 @@ const getConjunction = (state: [string, string][], prefix?: string) =>
|
|
|
57
43
|
indent(
|
|
58
44
|
[
|
|
59
45
|
...(prefix === undefined ? [] : [prefix]),
|
|
60
|
-
...state.map((
|
|
46
|
+
...state.map((assignment) => `${assignment[0]} = (${assignment[1]})`),
|
|
61
47
|
].join("\n/\\\n"),
|
|
62
48
|
2,
|
|
63
49
|
);
|
|
@@ -102,7 +88,7 @@ ${examples}`;
|
|
|
102
88
|
export const writeTraceSpec = (input: TraceSpecInput) => {
|
|
103
89
|
const loopStart = input.loopStart;
|
|
104
90
|
const states = input.states.map((state) =>
|
|
105
|
-
|
|
91
|
+
getHashMapOrder(Object.keys(state)).map((name): [string, string] => [
|
|
106
92
|
name,
|
|
107
93
|
formatValue(state[name]),
|
|
108
94
|
]),
|
|
@@ -127,11 +113,11 @@ export const writeTraceSpec = (input: TraceSpecInput) => {
|
|
|
127
113
|
...(isLasso ? [LASSO_START, LASSO_END] : []),
|
|
128
114
|
];
|
|
129
115
|
const teConstantsModule = `${specName}_TEConstants`;
|
|
130
|
-
const constantModules =
|
|
116
|
+
const constantModules = getHashMapOrder([
|
|
131
117
|
"TLC",
|
|
132
118
|
...(teConstants.length > 0 ? [teConstantsModule] : []),
|
|
133
119
|
]);
|
|
134
|
-
const extendedModules =
|
|
120
|
+
const extendedModules = getHashMapOrder([
|
|
135
121
|
"Toolbox",
|
|
136
122
|
"TLCExt",
|
|
137
123
|
"Naturals",
|
|
@@ -180,18 +166,18 @@ ${lassoStep}${variables
|
|
|
180
166
|
\\* IN J!JsonSerialize("${input.module}.json", _TETrace)
|
|
181
167
|
|
|
182
168
|
`;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const view = isViewed
|
|
169
|
+
// MCError#isLassoWithDuplicates counts the state a lasso goes back to, so TLC views every lasso.
|
|
170
|
+
const view = isLasso
|
|
186
171
|
? {
|
|
187
172
|
config: "\nVIEW\n _view\n",
|
|
188
173
|
definition: `\n_view ==\n${INDENT}<<${variables.join(", ")}, IF TLCGet("level") = ${LASSO_END} + 1 THEN ${LASSO_START} ELSE TLCGet("level")>>\n`,
|
|
189
174
|
}
|
|
190
175
|
: { config: "", definition: "" };
|
|
191
|
-
const deserializedTrace = `\n${getPrimer(traceModule,
|
|
176
|
+
const deserializedTrace = `\n${getPrimer(traceModule, getHashMapOrder(["IOUtils", ...constantModules, specName]))}trace == IODeserialize("${input.module}.bin", TRUE)\n\n${CLOSING_TAG}`;
|
|
192
177
|
const traceFunction = `${INDENT}<<\n${states
|
|
193
178
|
.map(
|
|
194
|
-
(state) =>
|
|
179
|
+
(state) =>
|
|
180
|
+
`${INDENT}([${state.map((assignment) => `${assignment[0]} |-> ${assignment[1]}`).join(",")}])`,
|
|
195
181
|
)
|
|
196
182
|
.join(",\n")}\n${INDENT}>>${SEPARATOR}\n`;
|
|
197
183
|
|
|
@@ -218,7 +204,7 @@ ${lassoStep}${variables
|
|
|
218
204
|
" In this case, it is advised to uncomment the module below to deserialize the\n",
|
|
219
205
|
" trace from a generated binary file.\n",
|
|
220
206
|
`\n\\*${deserializedTrace.replaceAll("\n", "\n\\*")}\n\n`,
|
|
221
|
-
getPrimer(traceModule,
|
|
207
|
+
getPrimer(traceModule, getHashMapOrder([...constantModules, specName])),
|
|
222
208
|
`trace == \n${traceFunction}\n`,
|
|
223
209
|
...(teConstants.length > 0
|
|
224
210
|
? [
|