tla-ts 0.0.10-dev.c92e6a4ea → 0.0.10-dev.d166e0ae9
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 +54 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +13 -3
- package/dist/index.d.ts +13 -3
- 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 +68 -68
- package/dist/prove.js +78 -78
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +45 -43
- package/dist/transfer.js +45 -43
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +1 -1
- package/src/ast.ts +11 -1
- package/src/bags.ts +50 -29
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +9 -6
- package/src/check-trace.ts +116 -64
- package/src/check.ts +356 -173
- package/src/cli/tlc-output.ts +1 -0
- package/src/cli/tlc.ts +4 -3
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +34 -13
- package/src/coverage.ts +3 -0
- package/src/dependencies.ts +61 -13
- package/src/dfid.ts +22 -10
- package/src/environment.ts +71 -35
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +149 -54
- package/src/exit-codes.ts +29 -15
- package/src/instances.ts +16 -6
- package/src/java-hash.ts +14 -0
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +186 -97
- package/src/liveness-checker.ts +131 -83
- package/src/liveness.ts +52 -11
- 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/parser.ts +115 -145
- 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 +169 -58
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +63 -14
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- 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 +67 -13
- 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 +26 -15
- package/src/prover/smt/solver/diff-neq.ts +1 -2
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- 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 -11
- 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 +148 -39
- 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 +9 -2
- package/src/prover/smt/solver/lp/lp-settings.ts +5 -1
- package/src/prover/smt/solver/lp/nla-core.ts +1 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +2 -2
- package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
- package/src/prover/smt/solver/lp/pdd.ts +2 -3
- 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 -64
- 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 +4 -0
- package/src/prover/smt/solver/sat/config.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +81 -28
- package/src/prover/smt/solver/sat/model-converter.ts +1 -1
- package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
- package/src/prover/smt/solver/sat/sat-tactic.ts +17 -7
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/sat/simplifier.ts +1 -1
- package/src/prover/smt/solver/sat/solver.ts +25 -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 +2 -2
- 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 +96 -10
- package/src/prover/smt/solver/smtlib-parser.ts +589 -224
- package/src/prover/smt/solver/smtlib-script.ts +674 -195
- 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 +332 -189
- 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 +2 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
- 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/tseitin-cnf.ts +1 -0
- package/src/prover/tlapm/cache.ts +8 -8
- package/src/prover/zenon/index-table.ts +5 -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/resolve.ts +1071 -251
- package/src/runtime.ts +5 -1
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +2 -13
- package/src/sany/generator-definitions.ts +3 -1
- package/src/sany/generator-expressions.ts +38 -30
- package/src/sany/generator-proofs.ts +6 -3
- package/src/sany/generator.ts +2 -1
- package/src/sany/lexer.ts +3 -3
- 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 +197 -117
- package/src/simulate.ts +165 -102
- package/src/spec-description.ts +8 -6
- package/src/standard-modules.ts +56 -22
- package/src/subexpressions.ts +518 -123
- package/src/successors.ts +10 -3
- package/src/symmetry.ts +2 -1
- package/src/tlc/jar-data.ts +10 -0
- package/src/tlc/messages.ts +3 -3
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +27 -14
- package/src/tlc/tlc-operators.ts +10 -8
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +9 -22
- package/src/typed-tier.ts +44 -27
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +135 -78
package/src/successors.ts
CHANGED
|
@@ -274,6 +274,7 @@ const getUnchangedVariables = (
|
|
|
274
274
|
|
|
275
275
|
const ACTION_KINDS = new Set([
|
|
276
276
|
"Label",
|
|
277
|
+
"Selection",
|
|
277
278
|
"And",
|
|
278
279
|
"Or",
|
|
279
280
|
"Exists",
|
|
@@ -723,6 +724,7 @@ const compileIdentifier = (
|
|
|
723
724
|
!definition ||
|
|
724
725
|
(expression.location.range && getStartupValue(definition, environment) !== undefined)
|
|
725
726
|
) {
|
|
727
|
+
// Deviation from TLC: Tool#getInitStates prints an unassigned variable's declaration as the non-boolean value it found.
|
|
726
728
|
guard(run, scope, partial, action, isFixed, onComplete);
|
|
727
729
|
return;
|
|
728
730
|
}
|
|
@@ -1139,6 +1141,8 @@ const compileAction = (
|
|
|
1139
1141
|
);
|
|
1140
1142
|
case "Label":
|
|
1141
1143
|
return getChildRunner(expression.body);
|
|
1144
|
+
case "Selection":
|
|
1145
|
+
return getChildRunner(expression.expression);
|
|
1142
1146
|
case "Identifier":
|
|
1143
1147
|
return compileIdentifier(expression, environment, isInit);
|
|
1144
1148
|
case "FunctionApplication":
|
|
@@ -1203,7 +1207,9 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
1203
1207
|
);
|
|
1204
1208
|
}
|
|
1205
1209
|
const environment = context.environment;
|
|
1206
|
-
if (environment.callStack
|
|
1210
|
+
if (environment.callStack || (environment.coverage && environment.coverage.current !== -1)) {
|
|
1211
|
+
return replayEnabled(expression, context.scope, state, environment);
|
|
1212
|
+
}
|
|
1207
1213
|
const run: Run = {
|
|
1208
1214
|
environment,
|
|
1209
1215
|
isInit: false,
|
|
@@ -1340,6 +1346,7 @@ export const hasIncompleteSuccessor = (
|
|
|
1340
1346
|
generator: undefined,
|
|
1341
1347
|
successors: 0,
|
|
1342
1348
|
};
|
|
1349
|
+
// TLC's Tool#getState generates every successor of the action before it compares them.
|
|
1343
1350
|
getRunner(expression, environment, false)(
|
|
1344
1351
|
run,
|
|
1345
1352
|
scope,
|
|
@@ -1347,10 +1354,10 @@ export const hasIncompleteSuccessor = (
|
|
|
1347
1354
|
undefined,
|
|
1348
1355
|
false,
|
|
1349
1356
|
(partial) => {
|
|
1350
|
-
if (!isComplete(partial)) run.
|
|
1357
|
+
if (!isComplete(partial)) run.successors++;
|
|
1351
1358
|
},
|
|
1352
1359
|
);
|
|
1353
|
-
return run.
|
|
1360
|
+
return run.successors > 0;
|
|
1354
1361
|
};
|
|
1355
1362
|
|
|
1356
1363
|
export const getSuccessors = (
|
package/src/symmetry.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type Images = Map<string, ModelValue>;
|
|
|
24
24
|
|
|
25
25
|
const getPermutationKey = (permutation: Images) =>
|
|
26
26
|
[...permutation]
|
|
27
|
-
.map((
|
|
27
|
+
.map((entry) => `${entry[0]}>${entry[1].name}`)
|
|
28
28
|
.sort()
|
|
29
29
|
.join(",");
|
|
30
30
|
|
|
@@ -139,6 +139,7 @@ export const getSymmetryGroup = (
|
|
|
139
139
|
`The set${isPlural ? "s" : ""} ${names.join(", and ")} ${isPlural ? "have" : "has"} been defined to be a symmetry set but contain${isPlural ? "" : "s"} less than two elements.`,
|
|
140
140
|
);
|
|
141
141
|
};
|
|
142
|
+
// Deviation from TLC: MVPerms#permutationSubgroup sizes a util.Set one below the number of permutations, which throws for fewer than two.
|
|
142
143
|
if (permutedSets.length >= elements.length) {
|
|
143
144
|
warnSmallSets(permutedSets);
|
|
144
145
|
return undefined;
|
package/src/tlc/jar-data.ts
CHANGED
|
@@ -143,6 +143,16 @@ export const SANY_OPERATOR_SYNONYMS = [
|
|
|
143
143
|
["^+", "⁺"],
|
|
144
144
|
];
|
|
145
145
|
|
|
146
|
+
const SYNONYMS = new Map(
|
|
147
|
+
SANY_OPERATOR_SYNONYMS.flatMap((names) => names.slice(1).map((synonym) => [synonym, names[0]])),
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
export const resolveSynonym = (name: string) =>
|
|
151
|
+
name
|
|
152
|
+
.split("!")
|
|
153
|
+
.map((part) => SYNONYMS.get(part) ?? (part === "~" ? "\\lnot" : part))
|
|
154
|
+
.join("!");
|
|
155
|
+
|
|
146
156
|
export const TLC_STARTUP_STRINGS = [
|
|
147
157
|
"STRING",
|
|
148
158
|
"FALSE",
|
package/src/tlc/messages.ts
CHANGED
|
@@ -345,14 +345,14 @@ interface CodedMessage {
|
|
|
345
345
|
let codedMessagePatterns: { pattern: RegExp; message: CodedMessage }[] | undefined;
|
|
346
346
|
|
|
347
347
|
const getCodedMessagePatterns = () =>
|
|
348
|
-
(codedMessagePatterns ??= CODED_MESSAGES.map((
|
|
348
|
+
(codedMessagePatterns ??= CODED_MESSAGES.map((codedMessage) => ({
|
|
349
349
|
pattern: new RegExp(
|
|
350
|
-
`^${
|
|
350
|
+
`^${codedMessage[1]
|
|
351
351
|
.split(/%\d+%/)
|
|
352
352
|
.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
353
353
|
.join("[\\s\\S]*")}$`,
|
|
354
354
|
),
|
|
355
|
-
message: { code, isEvalException },
|
|
355
|
+
message: { code: codedMessage[0], isEvalException: codedMessage[2] },
|
|
356
356
|
})));
|
|
357
357
|
|
|
358
358
|
const UNCODED_MESSAGE_PATTERN =
|
package/src/tlc/random.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toEnumeratedSet } from "../builtins";
|
|
2
2
|
import { TlaEvaluationError } from "../errors";
|
|
3
|
+
import { prettyPrint } from "../pretty-print";
|
|
3
4
|
import type { TlcVersion } from "./version";
|
|
4
5
|
import {
|
|
5
6
|
createRecord,
|
|
@@ -226,7 +227,7 @@ export const getRandomElement = (set: Value, random: JavaRandom): Value => {
|
|
|
226
227
|
const offset = Math.floor(random.nextDouble() * size);
|
|
227
228
|
if (offset >= size) {
|
|
228
229
|
throw new TlaEvaluationError(
|
|
229
|
-
`Attempted to retrieve out-of-bounds element from the interval value ${formatValue(set)}.`,
|
|
230
|
+
`Attempted to retrieve out-of-bounds element from the interval value ${prettyPrint(formatValue(set))}.`,
|
|
230
231
|
);
|
|
231
232
|
}
|
|
232
233
|
return set.low + offset;
|
package/src/tlc/replay.ts
CHANGED
|
@@ -61,7 +61,7 @@ interface Replay {
|
|
|
61
61
|
isEnabled: boolean;
|
|
62
62
|
current: Value[] | undefined;
|
|
63
63
|
onState: (state: Value[]) => void;
|
|
64
|
-
onIncomplete: ((state: State) =>
|
|
64
|
+
onIncomplete: ((state: State) => boolean) | undefined;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const withFrame = <Result>(replay: Replay, expression: Expression, run: () => Result): Result => {
|
|
@@ -216,8 +216,7 @@ const proceedItems = (
|
|
|
216
216
|
): boolean => {
|
|
217
217
|
if (items === undefined) {
|
|
218
218
|
if (isComplete(partial)) return addState(replay, partial, node);
|
|
219
|
-
replay.onIncomplete?.(partial);
|
|
220
|
-
return false;
|
|
219
|
+
return replay.onIncomplete?.(partial) ?? false;
|
|
221
220
|
}
|
|
222
221
|
if (isComplete(partial) && isAssignedShortcut(replay)) {
|
|
223
222
|
return proceedAssigned(replay, items, partial, node);
|
|
@@ -319,6 +318,8 @@ const visitAt = (
|
|
|
319
318
|
}
|
|
320
319
|
case "Label":
|
|
321
320
|
return visit(replay, expression.body, items, scope, partial, node);
|
|
321
|
+
case "Selection":
|
|
322
|
+
return visit(replay, expression.expression, items, scope, partial, node);
|
|
322
323
|
default:
|
|
323
324
|
if (LITERAL_KINDS.has(expression.kind))
|
|
324
325
|
throw new TlaEvaluationError("The state relation is not a boolean expression.");
|
|
@@ -715,6 +716,7 @@ const visitUnchanged = (
|
|
|
715
716
|
if (index !== undefined) {
|
|
716
717
|
const value = replay.current?.[index];
|
|
717
718
|
if (value === undefined) return false;
|
|
719
|
+
if (replay.isEnabled && replay.coverage) countCoverage(replay.coverage, node);
|
|
718
720
|
const assigned = partial[index];
|
|
719
721
|
if (assigned !== undefined && !isEqualLikeTlc(assigned, value)) {
|
|
720
722
|
warnChangedUnchanged(replay.environment, index, expression);
|
|
@@ -779,11 +781,12 @@ const createReplay = (
|
|
|
779
781
|
kind: "init" | "next" | "enabled",
|
|
780
782
|
current: Value[] | undefined,
|
|
781
783
|
onState: (state: Value[]) => void,
|
|
782
|
-
onIncomplete?: (state: State) =>
|
|
784
|
+
onIncomplete?: (state: State) => boolean,
|
|
783
785
|
): Replay => ({
|
|
784
786
|
environment,
|
|
785
787
|
callStack: environment.callStack,
|
|
786
|
-
coverage:
|
|
788
|
+
coverage:
|
|
789
|
+
kind === "enabled" && environment.coverage?.current === -1 ? undefined : environment.coverage,
|
|
787
790
|
isInit: kind === "init",
|
|
788
791
|
isEnabled: kind === "enabled",
|
|
789
792
|
current,
|
|
@@ -799,17 +802,19 @@ export const replayEnabled = (
|
|
|
799
802
|
state: Value[],
|
|
800
803
|
environment: Environment,
|
|
801
804
|
) => {
|
|
802
|
-
const
|
|
805
|
+
const found = () => {
|
|
803
806
|
throw ENABLED_FOUND;
|
|
804
|
-
}
|
|
807
|
+
};
|
|
808
|
+
const node = environment.coverage?.current ?? -1;
|
|
809
|
+
const replay = createReplay(environment, "enabled", state, found, found);
|
|
805
810
|
const callStack = replay.callStack;
|
|
806
811
|
const depth = callStack?.expressions.length ?? 0;
|
|
807
812
|
try {
|
|
808
813
|
if (expression.kind === "AngleAction" && expression.location === expression.action.location) {
|
|
809
|
-
const changed = createItem("Changed", expression.subscript, scope,
|
|
810
|
-
visit(replay, expression.action, changed, scope, getEmptyState(environment),
|
|
814
|
+
const changed = createItem("Changed", expression.subscript, scope, node, undefined);
|
|
815
|
+
visit(replay, expression.action, changed, scope, getEmptyState(environment), node);
|
|
811
816
|
} else {
|
|
812
|
-
visit(replay, expression, undefined, scope, getEmptyState(environment),
|
|
817
|
+
visit(replay, expression, undefined, scope, getEmptyState(environment), node);
|
|
813
818
|
}
|
|
814
819
|
return false;
|
|
815
820
|
} catch (error) {
|
|
@@ -826,7 +831,7 @@ export const replayInitialStates = (
|
|
|
826
831
|
inits: (ReplayAction & { node?: number })[],
|
|
827
832
|
environment: Environment,
|
|
828
833
|
onState: (state: Value[]) => void,
|
|
829
|
-
onIncomplete?: (state: State) =>
|
|
834
|
+
onIncomplete?: (state: State) => boolean,
|
|
830
835
|
) => {
|
|
831
836
|
const [first, ...others] = inits;
|
|
832
837
|
if (first === undefined) return;
|
|
@@ -838,16 +843,21 @@ export const replayInitialStates = (
|
|
|
838
843
|
visit(replay, first.expression, rest, first.scope, getEmptyState(environment), first.node ?? -1);
|
|
839
844
|
};
|
|
840
845
|
|
|
841
|
-
export const replaySuccessors = <Action extends ReplayAction>(
|
|
846
|
+
export const replaySuccessors = <Action extends ReplayAction & { node?: number }>(
|
|
842
847
|
actions: Action[],
|
|
843
848
|
state: Value[],
|
|
844
849
|
environment: Environment,
|
|
845
850
|
onState: (state: Value[], action: Action) => void,
|
|
846
851
|
) => {
|
|
847
852
|
if (actions.some((action) => LITERAL_KINDS.has(action.expression.kind))) return;
|
|
853
|
+
const coverage = environment.coverage;
|
|
848
854
|
actions.forEach((action) => {
|
|
849
855
|
const successors: Value[][] = [];
|
|
850
|
-
|
|
856
|
+
const node = action.node ?? -1;
|
|
857
|
+
walkSuccessors(action, node, state, environment, (next) => {
|
|
858
|
+
if (coverage && node !== -1) coverage.primary[node]++;
|
|
859
|
+
successors.push(next);
|
|
860
|
+
});
|
|
851
861
|
successors.forEach((successor) => onState(successor, action));
|
|
852
862
|
});
|
|
853
863
|
};
|
|
@@ -858,7 +868,7 @@ export const walkSuccessors = (
|
|
|
858
868
|
state: Value[],
|
|
859
869
|
environment: Environment,
|
|
860
870
|
onState: (state: Value[]) => void,
|
|
861
|
-
onIncomplete?: (state: State) =>
|
|
871
|
+
onIncomplete?: (state: State) => boolean,
|
|
862
872
|
) => {
|
|
863
873
|
const replay = createReplay(environment, "next", state, onState, onIncomplete);
|
|
864
874
|
visit(replay, action.expression, undefined, action.scope, getEmptyState(environment), node);
|
|
@@ -907,6 +917,9 @@ export const getPrimedRanges = (actions: ReplayAction[], environment: Environmen
|
|
|
907
917
|
case "Label":
|
|
908
918
|
collect(expression.body, scope, visited);
|
|
909
919
|
return;
|
|
920
|
+
case "Selection":
|
|
921
|
+
collect(expression.expression, scope, visited);
|
|
922
|
+
return;
|
|
910
923
|
case "FunctionApplication":
|
|
911
924
|
collect(expression.function, scope, visited);
|
|
912
925
|
return;
|
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":
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
TlaUnsupportedError,
|
|
16
16
|
} from "../errors";
|
|
17
17
|
import { getTlcFingerprint } from "./fingerprint";
|
|
18
|
+
import { prettyPrint } from "../pretty-print";
|
|
18
19
|
import { formatMessage, formatNestedMessage, MESSAGE_CODE, MESSAGE_LEVEL } from "./messages";
|
|
19
20
|
import {
|
|
20
21
|
describeRange,
|
|
@@ -37,11 +38,14 @@ import {
|
|
|
37
38
|
createRecord,
|
|
38
39
|
createSet,
|
|
39
40
|
createTuple,
|
|
41
|
+
createWrittenFunction,
|
|
40
42
|
formatState,
|
|
41
43
|
formatValue,
|
|
42
44
|
getFingerprintError,
|
|
43
45
|
getSequenceElements,
|
|
44
46
|
getValueKey,
|
|
47
|
+
rankString,
|
|
48
|
+
setFunctionClass,
|
|
45
49
|
toFiniteSet,
|
|
46
50
|
type Value,
|
|
47
51
|
} from "../values";
|
|
@@ -63,19 +67,31 @@ export const createActionRecord = (action: string | undefined) =>
|
|
|
63
67
|
|
|
64
68
|
const counterExamples = new WeakSet<Value & object>();
|
|
65
69
|
|
|
66
|
-
const
|
|
67
|
-
|
|
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][] = [
|
|
68
77
|
["action", createSet(action)],
|
|
69
78
|
["state", createSet(states)],
|
|
70
|
-
]
|
|
79
|
+
];
|
|
80
|
+
const counterExample = createTlcRecord(isConsole ? fields : [...fields, ["console", false]]);
|
|
71
81
|
counterExamples.add(counterExample);
|
|
72
82
|
return counterExample;
|
|
73
83
|
};
|
|
74
84
|
|
|
85
|
+
export interface CounterExampleLoop {
|
|
86
|
+
start: number;
|
|
87
|
+
action: Value;
|
|
88
|
+
}
|
|
89
|
+
|
|
75
90
|
export const createCounterExample = (
|
|
76
91
|
stateRecords: Record<string, Value>[],
|
|
77
92
|
actions: Value[],
|
|
78
|
-
loop:
|
|
93
|
+
loop: CounterExampleLoop | undefined,
|
|
94
|
+
isConsole = true,
|
|
79
95
|
) => {
|
|
80
96
|
const states = stateRecords.map((state, index) =>
|
|
81
97
|
createTuple([index + 1, createRecord(Object.entries(state))]),
|
|
@@ -86,7 +102,7 @@ export const createCounterExample = (
|
|
|
86
102
|
const closing = loop
|
|
87
103
|
? [createTuple([states[states.length - 1], loop.action, states[loop.start]])]
|
|
88
104
|
: [];
|
|
89
|
-
return createCounterExampleRecord([...steps, ...closing], states);
|
|
105
|
+
return createCounterExampleRecord([...steps, ...closing], states, isConsole);
|
|
90
106
|
};
|
|
91
107
|
|
|
92
108
|
const getRegister = (runtime: CheckerRuntime, key: Value) => {
|
|
@@ -126,7 +142,7 @@ export const setTlcValue = (
|
|
|
126
142
|
return;
|
|
127
143
|
}
|
|
128
144
|
throw new TlaModuleError(
|
|
129
|
-
`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))}`,
|
|
130
146
|
);
|
|
131
147
|
};
|
|
132
148
|
|
|
@@ -232,7 +248,7 @@ export const createTlcExtOperators = (
|
|
|
232
248
|
const counterExample = getValue(args, 0, "ToTrace");
|
|
233
249
|
if (typeof counterExample !== "object" || !counterExamples.has(counterExample)) {
|
|
234
250
|
throw new TlaModuleError(
|
|
235
|
-
`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))}`,
|
|
236
252
|
);
|
|
237
253
|
}
|
|
238
254
|
const states = toFiniteSet(applyFunction(counterExample, "state")).elements.map(
|
|
@@ -246,7 +262,7 @@ export const createTlcExtOperators = (
|
|
|
246
262
|
const name = getValue(args, 0, "TLCModelValue");
|
|
247
263
|
if (typeof name !== "string") {
|
|
248
264
|
throw new TlaModuleError(
|
|
249
|
-
`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))}`,
|
|
250
266
|
);
|
|
251
267
|
}
|
|
252
268
|
return createModelValue(name);
|
|
@@ -361,7 +377,7 @@ export const createTlcExtOperators = (
|
|
|
361
377
|
const name = getThunk(args, 0, "TLCEvalDefinition")();
|
|
362
378
|
if (typeof name !== "string") {
|
|
363
379
|
throw new TlaModuleError(
|
|
364
|
-
`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))}`,
|
|
365
381
|
);
|
|
366
382
|
}
|
|
367
383
|
const definition = context ? getDefinition(name, context.environment) : undefined;
|
|
@@ -369,7 +385,7 @@ export const createTlcExtOperators = (
|
|
|
369
385
|
if (builtin?.arity === 0) return builtin.evaluate([], context);
|
|
370
386
|
if (!definition || !context) {
|
|
371
387
|
throw new TlaModuleError(
|
|
372
|
-
`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))}`,
|
|
373
389
|
);
|
|
374
390
|
}
|
|
375
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",
|
|
@@ -187,10 +173,11 @@ ${lassoStep}${variables
|
|
|
187
173
|
definition: `\n_view ==\n${INDENT}<<${variables.join(", ")}, IF TLCGet("level") = ${LASSO_END} + 1 THEN ${LASSO_START} ELSE TLCGet("level")>>\n`,
|
|
188
174
|
}
|
|
189
175
|
: { config: "", definition: "" };
|
|
190
|
-
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}`;
|
|
191
177
|
const traceFunction = `${INDENT}<<\n${states
|
|
192
178
|
.map(
|
|
193
|
-
(state) =>
|
|
179
|
+
(state) =>
|
|
180
|
+
`${INDENT}([${state.map((assignment) => `${assignment[0]} |-> ${assignment[1]}`).join(",")}])`,
|
|
194
181
|
)
|
|
195
182
|
.join(",\n")}\n${INDENT}>>${SEPARATOR}\n`;
|
|
196
183
|
|
|
@@ -217,7 +204,7 @@ ${lassoStep}${variables
|
|
|
217
204
|
" In this case, it is advised to uncomment the module below to deserialize the\n",
|
|
218
205
|
" trace from a generated binary file.\n",
|
|
219
206
|
`\n\\*${deserializedTrace.replaceAll("\n", "\n\\*")}\n\n`,
|
|
220
|
-
getPrimer(traceModule,
|
|
207
|
+
getPrimer(traceModule, getHashMapOrder([...constantModules, specName])),
|
|
221
208
|
`trace == \n${traceFunction}\n`,
|
|
222
209
|
...(teConstants.length > 0
|
|
223
210
|
? [
|