tla-ts 0.0.10-dev.96638cd93 → 0.0.10-dev.a17d6d9fa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/deciders.cjs +30 -30
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +60 -60
- package/dist/prove.js +73 -73
- package/dist/run.cjs +42 -42
- package/dist/run.js +42 -42
- package/dist/transfer.cjs +34 -34
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +1 -1
- package/src/check-trace.ts +90 -51
- package/src/check.ts +251 -133
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +18 -5
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +25 -9
- package/src/exit-codes.ts +1 -0
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +63 -31
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -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 +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- 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/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +31 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +24 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +1 -1
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/opt-context.ts +11 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +3 -2
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +16 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +13 -4
- package/src/prover/smt/solver/sat/sat-tactic.ts +9 -2
- package/src/prover/smt/solver/smt-kernel.ts +30 -2
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +26 -3
- package/src/prover/smt/solver/smtlib-script.ts +34 -21
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +68 -41
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- 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 +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +120 -52
- package/src/runtime.ts +4 -0
- package/src/search.ts +117 -81
- package/src/simulate.ts +110 -50
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +15 -6
- package/src/subexpressions.ts +34 -9
- package/src/successors.ts +3 -2
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +3 -2
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +3 -2
- package/src/values.ts +95 -57
package/dist/worker.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,getStateCounts:t.getStateCounts,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
9
|
+
const e={success:0,abort:1,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,getStateCounts:t.getStateCounts,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
10
10
|
|
|
11
11
|
`),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),h=(e,t)=>m([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),g=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
|
|
12
12
|
`)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,v=(e,t)=>m([{location:_(t),message:e}]);var y=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
|
package/dist/worker.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,getStateCounts:t.getStateCounts,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
9
|
+
const e={success:0,abort:1,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=new Map([...[...Array.from({length:24},(e,t)=>2222+t),2272,2273,2274,2280,2281,...Array.from({length:7},(e,t)=>5001+t)].map(t=>[t,e.configParseError]),[2253,e.livenessEvaluationFailure],[2109,e.specEvaluationFailure],[2115,e.specEvaluationFailure],[2103,e.specEvaluationFailure],[2147,e.specEvaluationFailure],[2111,e.safetyEvaluationFailure],[2146,e.safetyEvaluationFailure],[2107,e.safetyViolation],[2110,e.safetyViolation],[2112,e.livenessViolation],[2113,e.livenessViolation],[2116,e.livenessViolation],[2108,e.livenessViolation],[2114,e.deadlock],[2104,e.assumptionViolation],[2105,e.assumptionViolation],[2404,e.assumptionViolation],[2405,e.assumptionViolation],[2780,e.assumptionViolation],[2132,e.assertViolation],[2171,e.specParseError],[3002,e.specParseError]]),n=n=>t.get(n)??e.error,r=/* @__PURE__ */ new WeakMap,i=(e,t)=>(e instanceof Error&&!r.has(e)&&r.set(e,t),e),a=e=>r.get(e),o=t=>{try{return t()}catch(t){throw i(t,e.error)}},s=e=>{let t=o(e);return t&&{branches:t.branches,solutions:t.solutions,addInitialState:(e,n,r)=>o(()=>t.addInitialState(e,n,r)),addState:(e,n,r,i)=>o(()=>t.addState(e,n,r,i)),storeState:t.storeState,getStateCounts:t.getStateCounts,findViolation:()=>o(()=>t.findViolation()),getViolatedProperties:(e,n)=>o(()=>t.getViolatedProperties(e,n))}},c=e=>`TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${e}\n: `,l=c(`java.lang.RuntimeException`),u=c(`tlc2.tool.EvalException`),ee=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`||e instanceof SyntaxError&&e.message.endsWith(`: Stack overflow`);var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}},p=class extends f{location;parseError;constructor(e,t,n){super(e),this.location=t,this.parseError=n}},te=class extends p{constructor(e,t,n=!0){super(`Cannot find source file for module ${e} imported in module ${t}.`,n?t:void 0)}};const m=(e,t=!1,n,r=[])=>new f(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
10
10
|
|
|
11
11
|
`),void 0,void 0,{errors:e,warnings:r,isFatal:t,parseError:n}),h=(e,t)=>m([{location:`In module ${t}`,message:`Cannot find source file for module ${e} imported in module ${t}.`}],!0),g=e=>`*** Warnings: ${e.length}\n\n${e.map(e=>`${e.location}\n\n${e.message}\n\n\n`).join(`
|
|
12
12
|
`)}`,_=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,v=(e,t)=>m([{location:_(t),message:e}]);var y=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
|
package/package.json
CHANGED
package/src/bags.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "./builtins";
|
|
12
12
|
import { TlaEvaluationError, TlaModuleError } from "./errors";
|
|
13
13
|
import type { Builtin, BuiltinArgument } from "./evaluate";
|
|
14
|
+
import { prettyPrint } from "./pretty-print";
|
|
14
15
|
import {
|
|
15
16
|
createEnumeratedSet,
|
|
16
17
|
createFunction,
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
|
|
31
32
|
const createWrongValueError = (name: string, expected: string, value: Value) =>
|
|
32
33
|
new TlaModuleError(
|
|
33
|
-
`Applying ${name} to the following value,\nwhich is not ${expected}:\n${formatValue(value)}`,
|
|
34
|
+
`Applying ${name} to the following value,\nwhich is not ${expected}:\n${prettyPrint(formatValue(value))}`,
|
|
34
35
|
);
|
|
35
36
|
|
|
36
37
|
const toFunction = (value: Value) => (isFunctionValue(value) ? toFiniteFunction(value) : undefined);
|
|
@@ -44,6 +45,7 @@ const getFunction = (args: BuiltinArgument[], index: number, name: string) => {
|
|
|
44
45
|
return functionValue;
|
|
45
46
|
};
|
|
46
47
|
|
|
48
|
+
// Deviation from TLC: Bags#BagIn and Bags#CopiesIn read the null that toFcnRcd gives for a value that isn't a function and leak a NullPointerException, where tla-ts reports the argument as not a bag.
|
|
47
49
|
const getCount = (args: BuiltinArgument[], name: string) => {
|
|
48
50
|
const bag = getValue(args, 1, name);
|
|
49
51
|
const functionValue = toFunction(bag);
|
|
@@ -54,6 +56,7 @@ const getCount = (args: BuiltinArgument[], name: string) => {
|
|
|
54
56
|
return count;
|
|
55
57
|
};
|
|
56
58
|
|
|
59
|
+
// Deviation from TLC: Bags#BagCup passes the null that toFcnRcd gives for a value that isn't a function to IsABag and leaks a NullPointerException, where tla-ts reports the argument as not a bag.
|
|
57
60
|
const getAddedBag = (
|
|
58
61
|
args: BuiltinArgument[],
|
|
59
62
|
functions: (FunctionValue | undefined)[],
|
|
@@ -186,7 +189,7 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
|
|
|
186
189
|
if (elements.length < 2) return elements[0] ?? EMPTY_BAG;
|
|
187
190
|
const createUnionError = () =>
|
|
188
191
|
new TlaModuleError(
|
|
189
|
-
`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${formatValue(set)}`,
|
|
192
|
+
`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${prettyPrint(formatValue(set))}`,
|
|
190
193
|
);
|
|
191
194
|
const getBag = (element: Value) => {
|
|
192
195
|
const functionValue = toFunction(element);
|
package/src/builtins.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TlaEndOfInputError, TlaEvaluationError, TlaModuleError } from "./errors";
|
|
2
2
|
import type { Builtin, BuiltinArgument, Context, OperatorValue } from "./evaluate";
|
|
3
|
+
import { prettyPrint } from "./pretty-print";
|
|
3
4
|
import {
|
|
4
5
|
formatValue,
|
|
5
6
|
getFunctionClass,
|
|
@@ -51,13 +52,13 @@ export const createModuleArgumentError = (
|
|
|
51
52
|
value: Value,
|
|
52
53
|
) =>
|
|
53
54
|
new TlaModuleError(
|
|
54
|
-
`The ${position} argument of ${name} should be a ${expected}, but instead it is:\n${formatValue(value)}`,
|
|
55
|
+
`The ${position} argument of ${name} should be a ${expected}, but instead it is:\n${prettyPrint(formatValue(value))}`,
|
|
55
56
|
);
|
|
56
57
|
|
|
57
58
|
export const toEnumeratedSet = (value: Value, name: string, reported = value) => {
|
|
58
59
|
if (!isSetValue(value) || isOverriddenSet(value)) {
|
|
59
60
|
throw new TlaModuleError(
|
|
60
|
-
`Applying ${name} to the following value,\nwhich is not a finite set:\n${formatValue(reported)}`,
|
|
61
|
+
`Applying ${name} to the following value,\nwhich is not a finite set:\n${prettyPrint(formatValue(reported))}`,
|
|
61
62
|
);
|
|
62
63
|
}
|
|
63
64
|
return toFiniteSet(value);
|
|
@@ -290,7 +291,7 @@ export const defineArithmetic = (
|
|
|
290
291
|
const getIntegerArgument = (value: Value, position: string, name: string) => {
|
|
291
292
|
if (typeof value !== "number") {
|
|
292
293
|
throw new TlaModuleError(
|
|
293
|
-
`The ${position} argument of ${name} should be an integer, but instead it is:\n${formatValue(value)}`,
|
|
294
|
+
`The ${position} argument of ${name} should be an integer, but instead it is:\n${prettyPrint(formatValue(value))}`,
|
|
294
295
|
);
|
|
295
296
|
}
|
|
296
297
|
return value;
|
package/src/check-failure.ts
CHANGED
|
@@ -57,7 +57,7 @@ export const getFailureExitCode = (
|
|
|
57
57
|
getExitCode(error) ?? (error instanceof TlaModuleError ? error.exitCode : EXIT_STATUS.error)
|
|
58
58
|
);
|
|
59
59
|
case "liveness":
|
|
60
|
-
return getErrorExitCode(error);
|
|
60
|
+
return error instanceof TlaModuleError ? error.exitCode : getErrorExitCode(error);
|
|
61
61
|
default:
|
|
62
62
|
if (!isReplayed) return getErrorExitCode(error);
|
|
63
63
|
return failureOptions.fingerprint
|
package/src/check-trace.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CheckOptions, OutputLine, TraceStep } from "./check";
|
|
2
2
|
import type { ModelConfig } from "./config";
|
|
3
3
|
import { TlaEvaluationError } from "./errors";
|
|
4
|
-
import { isImpure, type Environment } from "./evaluate";
|
|
5
|
-
import { isSameState } from "./fingerprints";
|
|
4
|
+
import { isImpure, type Environment, type State } from "./evaluate";
|
|
5
|
+
import { getStateHash, isSameState } from "./fingerprints";
|
|
6
6
|
import type { Search } from "./search";
|
|
7
7
|
import { getActionLabel, type SpecAction } from "./spec-description";
|
|
8
8
|
import { getSuccessors, type Successor } from "./successors";
|
|
9
|
-
import type
|
|
9
|
+
import { createModelValue, type Value } from "./values";
|
|
10
10
|
|
|
11
11
|
export interface Behavior {
|
|
12
12
|
trace: TraceStep[];
|
|
@@ -16,6 +16,7 @@ export interface Behavior {
|
|
|
16
16
|
interface TraceOptions {
|
|
17
17
|
loopStart?: number;
|
|
18
18
|
known?: number;
|
|
19
|
+
incomplete?: State;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface RebuiltState {
|
|
@@ -35,6 +36,7 @@ export interface SearchPosition {
|
|
|
35
36
|
export interface TracedStep {
|
|
36
37
|
state: Record<string, Value>;
|
|
37
38
|
action: SpecAction | undefined;
|
|
39
|
+
alias?: Record<string, Value>;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
interface TraceContext {
|
|
@@ -59,7 +61,7 @@ interface TraceContext {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
const INITIAL_RECOVERY_FAILURE = "Failed to recover the initial state from its fingerprint.";
|
|
62
|
-
const NEXT_RECOVERY_FAILURE = "Failed to recover the next state from its fingerprint.";
|
|
64
|
+
export const NEXT_RECOVERY_FAILURE = "Failed to recover the next state from its fingerprint.";
|
|
63
65
|
|
|
64
66
|
export const createTraceBuilder = (context: TraceContext) => {
|
|
65
67
|
const config = context.config;
|
|
@@ -78,34 +80,31 @@ export const createTraceBuilder = (context: TraceContext) => {
|
|
|
78
80
|
|
|
79
81
|
const getAliasState = (
|
|
80
82
|
alias: string,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
state: State,
|
|
84
|
+
successor: State,
|
|
85
|
+
level: number,
|
|
86
|
+
getBehavior: () => Value[][],
|
|
84
87
|
) => {
|
|
85
88
|
const searchLevel = runtime.getLevel;
|
|
86
89
|
const searchBehavior = runtime.getBehavior;
|
|
87
|
-
runtime.getLevel = () =>
|
|
88
|
-
runtime.getBehavior =
|
|
90
|
+
runtime.getLevel = () => level;
|
|
91
|
+
runtime.getBehavior = getBehavior;
|
|
89
92
|
try {
|
|
90
|
-
return search.evaluateAlias(
|
|
91
|
-
alias,
|
|
92
|
-
steps[position].state,
|
|
93
|
-
(steps[position + 1] ?? steps[loopStart ?? position]).state,
|
|
94
|
-
options.isTool ?? false,
|
|
95
|
-
);
|
|
93
|
+
return search.evaluateAlias(alias, state, successor, options.isTool ?? false);
|
|
96
94
|
} finally {
|
|
97
95
|
runtime.getLevel = searchLevel;
|
|
98
96
|
runtime.getBehavior = searchBehavior;
|
|
99
97
|
}
|
|
100
98
|
};
|
|
99
|
+
// Deviation from TLC: TLCTrace#printTrace rebuilds a step with the generator that already drew for its state, so it misses the step and leaks a NullPointerException.
|
|
100
|
+
const rebuildFrom = (state: Value[], level: number) => {
|
|
101
|
+
current.rebuilt = { state, level };
|
|
102
|
+
runtime.reseedRandom();
|
|
103
|
+
};
|
|
101
104
|
const findStepAction = (index: number, previous: Value[], state: Value[], isHeld: boolean) => {
|
|
102
105
|
const expanding = { ...current };
|
|
103
|
-
Object.assign(current, {
|
|
104
|
-
|
|
105
|
-
isExpanding: true,
|
|
106
|
-
candidate: undefined,
|
|
107
|
-
rebuilt: { state: previous, level: depths[index] },
|
|
108
|
-
});
|
|
106
|
+
Object.assign(current, { index, isExpanding: true, candidate: undefined });
|
|
107
|
+
rebuildFrom(previous, depths[index]);
|
|
109
108
|
const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
|
|
110
109
|
const key = getKey(state);
|
|
111
110
|
try {
|
|
@@ -166,7 +165,15 @@ export const createTraceBuilder = (context: TraceContext) => {
|
|
|
166
165
|
state:
|
|
167
166
|
alias === undefined
|
|
168
167
|
? toRecord(step.state)
|
|
169
|
-
: getAliasState(
|
|
168
|
+
: getAliasState(
|
|
169
|
+
alias,
|
|
170
|
+
step.state,
|
|
171
|
+
steps[position + 1]?.state ??
|
|
172
|
+
traceOptions.incomplete ??
|
|
173
|
+
steps[loopStart ?? position].state,
|
|
174
|
+
position + 1,
|
|
175
|
+
() => steps.slice(0, position + 1).map((inner) => inner.state),
|
|
176
|
+
),
|
|
170
177
|
output: position === 0 ? prefixOutput : position < rebuilt ? [] : outputs[position],
|
|
171
178
|
};
|
|
172
179
|
if (alias !== undefined || action) {
|
|
@@ -187,10 +194,24 @@ export const createTraceBuilder = (context: TraceContext) => {
|
|
|
187
194
|
}
|
|
188
195
|
return undefined;
|
|
189
196
|
}).result;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
// TLC's Tool#getState fingerprints each state it rebuilds, which sorts its records in place.
|
|
198
|
+
const hasFingerprint = (state: Value[], index: number) => {
|
|
199
|
+
const fingerprintState = getFingerprintState(state);
|
|
200
|
+
const stored = context.fingerprintStates[index];
|
|
201
|
+
return (
|
|
202
|
+
getStateHash(fingerprintState) === getStateHash(stored) &&
|
|
203
|
+
isSameState(fingerprintState, stored)
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
const findSuccessorWithFingerprint = (state: Value[], source: number, target: number) => {
|
|
207
|
+
const rebuilt = current.rebuilt;
|
|
208
|
+
rebuildFrom(state, depths[source]);
|
|
209
|
+
const successor = findTraceSuccessor(state, (candidate) =>
|
|
210
|
+
hasFingerprint(candidate.state, target),
|
|
211
|
+
);
|
|
212
|
+
current.rebuilt = rebuilt;
|
|
213
|
+
return successor;
|
|
214
|
+
};
|
|
194
215
|
const getPathStates = (path: number[], nextFailure: string) => {
|
|
195
216
|
const initial = captureOutput(() =>
|
|
196
217
|
isReducing || isImpure(environment)
|
|
@@ -205,16 +226,13 @@ export const createTraceBuilder = (context: TraceContext) => {
|
|
|
205
226
|
steps.push({ state: previous, action: "Stuttering" });
|
|
206
227
|
continue;
|
|
207
228
|
}
|
|
208
|
-
const
|
|
209
|
-
current.rebuilt = { state: previous, level: depths[path[position - 1]] };
|
|
210
|
-
const successor = findSuccessorWithFingerprint(previous, path[position]);
|
|
211
|
-
current.rebuilt = rebuilt;
|
|
229
|
+
const successor = findSuccessorWithFingerprint(previous, path[position - 1], path[position]);
|
|
212
230
|
if (!successor) throw new TlaEvaluationError(nextFailure);
|
|
213
231
|
steps.push(successor);
|
|
214
232
|
}
|
|
215
233
|
return steps;
|
|
216
234
|
};
|
|
217
|
-
const getTrace = (index: number, lastSuccessor?: Successor) => {
|
|
235
|
+
const getTrace = (index: number, lastSuccessor?: Successor, incomplete?: State) => {
|
|
218
236
|
const path: number[] = [];
|
|
219
237
|
for (let position = index; position !== -1; position = context.parents[position]) {
|
|
220
238
|
path.unshift(position);
|
|
@@ -226,7 +244,7 @@ export const createTraceBuilder = (context: TraceContext) => {
|
|
|
226
244
|
state: states[position],
|
|
227
245
|
action: context.actions[position],
|
|
228
246
|
}));
|
|
229
|
-
if (!lastSuccessor) return toTrace(steps, path);
|
|
247
|
+
if (!lastSuccessor) return toTrace(steps, path, { incomplete });
|
|
230
248
|
const action = isReducing
|
|
231
249
|
? findTraceSuccessor(states[index], (successor) =>
|
|
232
250
|
isSameState(successor.state, lastSuccessor.state),
|
|
@@ -234,34 +252,55 @@ export const createTraceBuilder = (context: TraceContext) => {
|
|
|
234
252
|
: lastSuccessor.action;
|
|
235
253
|
return toTrace([...steps, { state: lastSuccessor.state, action }], path, { known: 2 });
|
|
236
254
|
};
|
|
237
|
-
// TLCTrace#printTrace
|
|
238
|
-
const getStateTrace = (index: number): Behavior =>
|
|
239
|
-
context.parents[index]
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
255
|
+
// TLCTrace#printTrace applies the alias to every state but an initial one it prints without a successor.
|
|
256
|
+
const getStateTrace = (index: number, incomplete?: State): Behavior => {
|
|
257
|
+
if (context.parents[index] !== -1) return getTrace(index, undefined, incomplete);
|
|
258
|
+
const traceOutput = is174 ? [] : captureOutput(context.getInitialStates).lines;
|
|
259
|
+
const state = states[index];
|
|
260
|
+
if (incomplete !== undefined) {
|
|
261
|
+
return {
|
|
262
|
+
trace: toTrace([{ state, action: undefined }], [index], { incomplete }).trace,
|
|
263
|
+
traceOutput,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
const step = { action: undefined, label: undefined, state: toRecord(state) };
|
|
267
|
+
const alias = config.alias;
|
|
268
|
+
if (alias !== undefined) {
|
|
269
|
+
context.tracedSteps.set(step, {
|
|
270
|
+
state: step.state,
|
|
271
|
+
action: undefined,
|
|
272
|
+
alias: getAliasState(alias, state, state, 1, () => [state]),
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return { trace: [step], traceOutput };
|
|
276
|
+
};
|
|
277
|
+
const getIncompleteStep = (
|
|
278
|
+
incomplete: State,
|
|
279
|
+
level: number,
|
|
280
|
+
step: Omit<TraceStep, "state">,
|
|
281
|
+
action: SpecAction | undefined,
|
|
282
|
+
): TraceStep => {
|
|
283
|
+
const state = toRecord(incomplete.map((value) => value ?? createModelValue("null")));
|
|
284
|
+
const alias = config.alias;
|
|
285
|
+
const traceStep = {
|
|
286
|
+
...step,
|
|
287
|
+
state:
|
|
288
|
+
alias === undefined ? state : getAliasState(alias, incomplete, incomplete, level, () => []),
|
|
289
|
+
};
|
|
290
|
+
context.tracedSteps.set(traceStep, { state, action });
|
|
291
|
+
return traceStep;
|
|
292
|
+
};
|
|
245
293
|
const getFailedTrace = (index: number, successor: Successor): Behavior => ({
|
|
246
294
|
trace: getTrace(index, successor).trace,
|
|
247
295
|
});
|
|
248
|
-
const getPathSteps = (path: number[]
|
|
249
|
-
const steps = getPathStates(path, NEXT_RECOVERY_FAILURE);
|
|
250
|
-
const lastState = steps[steps.length - 1].state;
|
|
251
|
-
const isClosed =
|
|
252
|
-
!isReducing ||
|
|
253
|
-
loopStart === undefined ||
|
|
254
|
-
loopStart === path.length - 1 ||
|
|
255
|
-
findSuccessorWithFingerprint(lastState, path[loopStart]) !== undefined;
|
|
256
|
-
if (!isClosed) throw new TlaEvaluationError(NEXT_RECOVERY_FAILURE);
|
|
257
|
-
return steps;
|
|
258
|
-
};
|
|
296
|
+
const getPathSteps = (path: number[]) => getPathStates(path, NEXT_RECOVERY_FAILURE);
|
|
259
297
|
return {
|
|
260
298
|
toTrace,
|
|
261
299
|
findStepAction,
|
|
262
300
|
findSuccessorWithFingerprint,
|
|
263
301
|
getTrace,
|
|
264
302
|
getStateTrace,
|
|
303
|
+
getIncompleteStep,
|
|
265
304
|
getFailedTrace,
|
|
266
305
|
getPathSteps,
|
|
267
306
|
};
|