tla-ts 0.0.10-dev.4a2a53c48 → 0.0.10-dev.5ffc55ce5
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 +35 -35
- package/dist/deciders.js +29 -29
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +25 -25
- package/dist/prove.js +57 -57
- package/dist/run.cjs +26 -28
- package/dist/run.js +42 -44
- package/dist/transfer.cjs +35 -35
- package/dist/transfer.js +28 -28
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/bags.ts +47 -28
- package/src/check-trace.ts +2 -16
- package/src/check.ts +143 -61
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +1 -2
- package/src/cli/tlc.ts +13 -8
- package/src/dfid.ts +9 -2
- package/src/environment.ts +18 -0
- package/src/evaluate.ts +9 -3
- package/src/exit-codes.ts +2 -0
- package/src/liveness-checker.ts +45 -4
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/prover/smt/solver/ast.ts +1 -1
- package/src/prover/smt/solver/context.ts +6 -2
- package/src/prover/smt/solver/euf/egraph.ts +1 -1
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- 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/goal.ts +2 -0
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/lp/containers.ts +7 -1
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
- 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 +156 -79
- 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 -289
- package/src/prover/smt/solver/muz/dl-context.ts +8 -2
- package/src/prover/smt/solver/muz/spacer-context.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +194 -89
- 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 +464 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2400 -680
- 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 +40 -17
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-solver.ts +2 -3
- package/src/prover/smt/solver/rlimit.ts +13 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +2 -1
- package/src/prover/smt/solver/seq-derive.ts +3 -6
- package/src/prover/smt/solver/smtlib-parser.ts +10 -10
- package/src/prover/smt/solver/smtlib-script.ts +91 -28
- package/src/prover/smt/solver/tactic.ts +14 -5
- package/src/prover/smt/solver/theory-lra-internalize.ts +8 -0
- package/src/prover/zenon/equality-rules.ts +24 -0
- package/src/prover/zenon/expr.ts +21 -0
- package/src/prover/zenon/index-table.ts +2 -0
- package/src/prover/zenon/rules.ts +2 -1
- package/src/resolve.ts +1 -1
- package/src/runtime.ts +2 -0
- package/src/sany/generator-expressions.ts +6 -13
- package/src/search.ts +40 -11
- package/src/tlc/order.ts +14 -3
- package/src/tlc/tlcext-operators.ts +18 -5
- package/src/tlc/trace-spec.ts +2 -3
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)),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,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}`,ne=(e,t)=>m([{location:_(t),message:e}]);var v=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`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)),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,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}`,ne=(e,t)=>m([{location:_(t),message:e}]);var v=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const b=`This was a Java StackOverflowError. It was probably the result
|
package/package.json
CHANGED
package/src/bags.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
defineConstant,
|
|
5
5
|
defineHigherOrderOperator,
|
|
6
6
|
defineOperator,
|
|
7
|
-
getJavaClassName,
|
|
8
7
|
getKindString,
|
|
9
8
|
getOperator,
|
|
10
9
|
getValue,
|
|
@@ -85,34 +84,43 @@ const findCount = (functionValue: FunctionValue, element: Value) => {
|
|
|
85
84
|
return position === -1 ? undefined : functionValue.range[position];
|
|
86
85
|
};
|
|
87
86
|
|
|
88
|
-
|
|
87
|
+
// Deviation from TLC: Bags.java casts a count to IntValue and leaks the ClassCastException, where tla-ts reports the argument as not a bag.
|
|
88
|
+
const toCount = (value: Value, createError: () => TlaModuleError) => {
|
|
89
89
|
if (typeof value === "number") return value;
|
|
90
|
-
|
|
91
|
-
throw new TlaEvaluationError(
|
|
92
|
-
`class ${javaClass} cannot be cast to class tlc2.value.impl.IntValue (${javaClass} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`,
|
|
93
|
-
);
|
|
90
|
+
throw createError();
|
|
94
91
|
};
|
|
95
92
|
|
|
96
|
-
const addCounts = (left: Value, right: Value) => {
|
|
97
|
-
const sum = toCount(left) + toCount(right);
|
|
93
|
+
const addCounts = (left: Value, right: Value, createError: () => TlaModuleError) => {
|
|
94
|
+
const sum = toCount(left, createError) + toCount(right, createError);
|
|
98
95
|
if (isOutOfRange(sum)) throw createOverflowError(`${left}+${right}`);
|
|
99
96
|
return sum;
|
|
100
97
|
};
|
|
101
98
|
|
|
102
|
-
// Deviation from TLC: Bags
|
|
103
|
-
const subtractCounts = (
|
|
104
|
-
|
|
99
|
+
// Deviation from TLC: Bags#BagDiff subtracts counts as Java ints that wrap, where tla-ts reports the overflow as - does.
|
|
100
|
+
const subtractCounts = (
|
|
101
|
+
functionValue: FunctionValue,
|
|
102
|
+
index: number,
|
|
103
|
+
other: FunctionValue,
|
|
104
|
+
createErrors: (() => TlaModuleError)[],
|
|
105
|
+
) => {
|
|
106
|
+
const count = toCount(functionValue.range[index], createErrors[0]);
|
|
105
107
|
const removed = findCount(other, functionValue.domain[index]);
|
|
106
108
|
if (removed === undefined) return count;
|
|
107
|
-
const difference = count - toCount(removed);
|
|
109
|
+
const difference = count - toCount(removed, createErrors[1]);
|
|
108
110
|
if (isOutOfRange(difference)) throw createOverflowError(`${count}-${removed}`);
|
|
109
111
|
return difference;
|
|
110
112
|
};
|
|
111
113
|
|
|
112
114
|
// BagCup looks up a key of its second bag only among the keys of its first.
|
|
113
|
-
const addToBag = (
|
|
115
|
+
const addToBag = (
|
|
116
|
+
pairs: [Value, Value][],
|
|
117
|
+
key: Value,
|
|
118
|
+
count: Value,
|
|
119
|
+
createError: () => TlaModuleError,
|
|
120
|
+
end = pairs.length,
|
|
121
|
+
) => {
|
|
114
122
|
const existing = pairs.slice(0, end).find((pair) => isEqualLikeTlc(key, pair[0]));
|
|
115
|
-
if (existing) existing[1] = addCounts(existing[1], count);
|
|
123
|
+
if (existing) existing[1] = addCounts(existing[1], count, createError);
|
|
116
124
|
else pairs.push([key, count]);
|
|
117
125
|
};
|
|
118
126
|
|
|
@@ -130,11 +138,10 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
|
|
|
130
138
|
defineOperator("BagCardinality", 1, (args) => {
|
|
131
139
|
const bag = getValue(args, 0, "BagCardinality");
|
|
132
140
|
const functionValue = getFunction(args, 0, "BagCardinality");
|
|
141
|
+
const createError = () => createWrongValueError("BagCardinality", "a bag", bag);
|
|
133
142
|
return functionValue.range.reduce<number>((total, count) => {
|
|
134
|
-
if (typeof count !== "number" || count <= 0)
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
return addCounts(total, count);
|
|
143
|
+
if (typeof count !== "number" || count <= 0) throw createError();
|
|
144
|
+
return addCounts(total, count, createError);
|
|
138
145
|
}, 0);
|
|
139
146
|
}),
|
|
140
147
|
defineOperator("BagIn", 2, (args) => {
|
|
@@ -147,8 +154,10 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
|
|
|
147
154
|
const left = getAddedBag(args, functions, 0);
|
|
148
155
|
const right = getAddedBag(args, functions, 1);
|
|
149
156
|
const pairs = getPairs(left);
|
|
157
|
+
const createError = () =>
|
|
158
|
+
createModuleArgumentError("second", "(+)", "bag", getValue(args, 1, "(+)"));
|
|
150
159
|
right.domain.forEach((key, index) =>
|
|
151
|
-
addToBag(pairs, key, right.range[index], left.domain.length),
|
|
160
|
+
addToBag(pairs, key, right.range[index], createError, left.domain.length),
|
|
152
161
|
);
|
|
153
162
|
return createFunction(pairs);
|
|
154
163
|
}),
|
|
@@ -159,9 +168,13 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
|
|
|
159
168
|
const right = toFunction(rightValue);
|
|
160
169
|
if (!left) throw createModuleArgumentError("first", "(-)", "bag", leftValue);
|
|
161
170
|
if (!right) throw createModuleArgumentError("second", "(-)", "bag", rightValue);
|
|
171
|
+
const createErrors = [
|
|
172
|
+
() => createModuleArgumentError("first", "(-)", "bag", leftValue),
|
|
173
|
+
() => createModuleArgumentError("second", "(-)", "bag", rightValue),
|
|
174
|
+
];
|
|
162
175
|
return createFunction(
|
|
163
176
|
left.domain.flatMap((key, index): [Value, Value][] => {
|
|
164
|
-
const count = subtractCounts(left, index, right);
|
|
177
|
+
const count = subtractCounts(left, index, right, createErrors);
|
|
165
178
|
return count > 0 ? [[key, count]] : [];
|
|
166
179
|
}),
|
|
167
180
|
);
|
|
@@ -172,20 +185,20 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
|
|
|
172
185
|
createWrongValueError("BagUnion", "a finite enumerable set", set),
|
|
173
186
|
);
|
|
174
187
|
if (elements.length < 2) return elements[0] ?? EMPTY_BAG;
|
|
188
|
+
const createUnionError = () =>
|
|
189
|
+
new TlaModuleError(
|
|
190
|
+
`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${formatValue(set)}`,
|
|
191
|
+
);
|
|
175
192
|
const getBag = (element: Value) => {
|
|
176
193
|
const functionValue = toFunction(element);
|
|
177
|
-
if (!functionValue)
|
|
178
|
-
throw new TlaModuleError(
|
|
179
|
-
`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${formatValue(set)}`,
|
|
180
|
-
);
|
|
181
|
-
}
|
|
194
|
+
if (!functionValue) throw createUnionError();
|
|
182
195
|
return functionValue;
|
|
183
196
|
};
|
|
184
197
|
const pairs = getPairs(getBag(elements[0]));
|
|
185
198
|
elements.slice(1).forEach((element) => {
|
|
186
199
|
const functionValue = getBag(element);
|
|
187
200
|
functionValue.domain.forEach((key, index) =>
|
|
188
|
-
addToBag(pairs, key, functionValue.range[index]),
|
|
201
|
+
addToBag(pairs, key, functionValue.range[index], createUnionError),
|
|
189
202
|
);
|
|
190
203
|
});
|
|
191
204
|
return createFunction(pairs);
|
|
@@ -197,9 +210,14 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
|
|
|
197
210
|
const right = toFunction(rightValue);
|
|
198
211
|
if (!left) throw createWrongValueError("\\sqsubseteq", FINITE_FUNCTION, leftValue);
|
|
199
212
|
if (!right) throw createWrongValueError("\\sqsubseteq", FINITE_FUNCTION, rightValue);
|
|
213
|
+
const createLeftError = () => createWrongValueError("\\sqsubseteq", "a bag", leftValue);
|
|
214
|
+
const createRightError = () => createWrongValueError("\\sqsubseteq", "a bag", rightValue);
|
|
200
215
|
return left.domain.every((key, index) => {
|
|
201
216
|
const count = findCount(right, key);
|
|
202
|
-
return
|
|
217
|
+
return (
|
|
218
|
+
toCount(left.range[index], createLeftError) <=
|
|
219
|
+
(count === undefined ? 0 : toCount(count, createRightError))
|
|
220
|
+
);
|
|
203
221
|
});
|
|
204
222
|
}),
|
|
205
223
|
defineHigherOrderOperator("BagOfAll", 2, (args) => {
|
|
@@ -210,8 +228,9 @@ export const createBagsOperators = (builtins: ReadonlyMap<string, Builtin>): Bui
|
|
|
210
228
|
throw createModuleArgumentError("second", "BagOfAll", "function with a finite domain", value);
|
|
211
229
|
}
|
|
212
230
|
const pairs: [Value, Value][] = [];
|
|
231
|
+
const createError = () => createModuleArgumentError("second", "BagOfAll", "bag", value);
|
|
213
232
|
functionValue.domain.forEach((key, index) =>
|
|
214
|
-
addToBag(pairs, operator.call([key]), functionValue.range[index]),
|
|
233
|
+
addToBag(pairs, operator.call([key]), functionValue.range[index], createError),
|
|
215
234
|
);
|
|
216
235
|
return createFunction(pairs);
|
|
217
236
|
}),
|
package/src/check-trace.ts
CHANGED
|
@@ -234,25 +234,11 @@ export const createTraceBuilder = (context: TraceContext) => {
|
|
|
234
234
|
: lastSuccessor.action;
|
|
235
235
|
return toTrace([...steps, { state: lastSuccessor.state, action }], path, { known: 2 });
|
|
236
236
|
};
|
|
237
|
-
//
|
|
237
|
+
// TLCTrace#printTrace prints a lone initial state without the alias it applies to every other trace.
|
|
238
238
|
const getStateTrace = (index: number): Behavior =>
|
|
239
239
|
context.parents[index] === -1
|
|
240
240
|
? {
|
|
241
|
-
trace: [
|
|
242
|
-
{
|
|
243
|
-
action: undefined,
|
|
244
|
-
label: undefined,
|
|
245
|
-
state:
|
|
246
|
-
config.alias === undefined
|
|
247
|
-
? toRecord(states[index])
|
|
248
|
-
: getAliasState(
|
|
249
|
-
config.alias,
|
|
250
|
-
[{ state: states[index], action: undefined }],
|
|
251
|
-
0,
|
|
252
|
-
undefined,
|
|
253
|
-
),
|
|
254
|
-
},
|
|
255
|
-
],
|
|
241
|
+
trace: [{ action: undefined, label: undefined, state: toRecord(states[index]) }],
|
|
256
242
|
traceOutput: is174 ? [] : captureOutput(context.getInitialStates).lines,
|
|
257
243
|
}
|
|
258
244
|
: getTrace(index);
|
package/src/check.ts
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
getStateHash,
|
|
48
48
|
isSameState,
|
|
49
49
|
markSeenState,
|
|
50
|
+
type StateTable,
|
|
50
51
|
} from "./fingerprints";
|
|
51
52
|
import type { JavaOverride } from "./java-overrides";
|
|
52
53
|
import {
|
|
@@ -205,7 +206,7 @@ export type CheckProgress =
|
|
|
205
206
|
branches: number;
|
|
206
207
|
/** Whether TLC checks the complete state graph. */
|
|
207
208
|
isComplete: boolean;
|
|
208
|
-
/** How many states of
|
|
209
|
+
/** How many states the graphs of all branches have together. */
|
|
209
210
|
states: number;
|
|
210
211
|
statistics: SearchStatistics;
|
|
211
212
|
}
|
|
@@ -414,6 +415,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
414
415
|
key.startsWith(`${name}${KEY_SEPARATOR}`),
|
|
415
416
|
),
|
|
416
417
|
});
|
|
418
|
+
const getCoverage = () =>
|
|
419
|
+
coverage?.relations.some((relation) => relation.kind === "next")
|
|
420
|
+
? getCoverageReport(
|
|
421
|
+
coverage,
|
|
422
|
+
environment,
|
|
423
|
+
specification.variableLocations,
|
|
424
|
+
search?.getTlcOrder() ?? [],
|
|
425
|
+
)
|
|
426
|
+
: undefined;
|
|
417
427
|
const createResult = (
|
|
418
428
|
status: CheckStatus,
|
|
419
429
|
violation?: ReportedViolation,
|
|
@@ -434,14 +444,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
434
444
|
initialStates: computedInitialStates,
|
|
435
445
|
outDegrees: undefined,
|
|
436
446
|
fingerprintDistance: undefined,
|
|
437
|
-
coverage:
|
|
438
|
-
? getCoverageReport(
|
|
439
|
-
coverage,
|
|
440
|
-
environment,
|
|
441
|
-
specification.variableLocations,
|
|
442
|
-
search?.getTlcOrder() ?? [],
|
|
443
|
-
)
|
|
444
|
-
: undefined,
|
|
447
|
+
coverage: getCoverage(),
|
|
445
448
|
...(traceSpec !== undefined && { traceSpec }),
|
|
446
449
|
};
|
|
447
450
|
};
|
|
@@ -465,7 +468,12 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
465
468
|
: getFingerprintDistance(runtime.distinctStates, runtime.generatedStates, (visit) =>
|
|
466
469
|
visit(
|
|
467
470
|
search
|
|
468
|
-
? search.getStoredFingerprints(
|
|
471
|
+
? search.getStoredFingerprints(
|
|
472
|
+
exploredStates.length === 0 ? states : states.concat(exploredStates),
|
|
473
|
+
exploredStates.length === 0
|
|
474
|
+
? fingerprintStates
|
|
475
|
+
: fingerprintStates.concat(exploredFingerprintStates),
|
|
476
|
+
)
|
|
469
477
|
: BigInt64Array.from(states, runtime.getFingerprint),
|
|
470
478
|
),
|
|
471
479
|
),
|
|
@@ -478,6 +486,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
478
486
|
() => created.order.getDeclarationOrder("variable"),
|
|
479
487
|
options.onProgress,
|
|
480
488
|
specification.moduleOperators,
|
|
489
|
+
specification.runtimeInvariants,
|
|
481
490
|
);
|
|
482
491
|
const findViolatedAssumption = () =>
|
|
483
492
|
findAssumptionViolation(specification.assumptions, environment);
|
|
@@ -554,12 +563,6 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
554
563
|
const getFingerprintState = search.getFingerprintState;
|
|
555
564
|
// Tool's constructor splits the next-state relation into actions before TLC checks anything.
|
|
556
565
|
const nextActions = getDescription().actions;
|
|
557
|
-
runtime.getSuccessorAction = (state, next) =>
|
|
558
|
-
nextActions.find((action) =>
|
|
559
|
-
getSuccessors(action.expression, state, environment, action.scope).some((successor) =>
|
|
560
|
-
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
561
|
-
),
|
|
562
|
-
);
|
|
563
566
|
const addCoverageRelations = (kind: "init" | "next", actions: SpecAction[]) =>
|
|
564
567
|
actions.map((action): CoveredAction => ({
|
|
565
568
|
...action,
|
|
@@ -609,6 +612,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
609
612
|
);
|
|
610
613
|
return successors;
|
|
611
614
|
};
|
|
615
|
+
// TLC generates the successors of each action again, which its coverage counts.
|
|
616
|
+
const findSuccessorAction = (state: Value[], isMatch: (successor: Successor) => boolean) =>
|
|
617
|
+
coverage
|
|
618
|
+
? coverageActions.find((item) => getCoveredSuccessors(item, state).some(isMatch))
|
|
619
|
+
: nextActions.find((item) =>
|
|
620
|
+
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
621
|
+
);
|
|
622
|
+
runtime.getSuccessorAction = (state, next) =>
|
|
623
|
+
findSuccessorAction(state, (successor) =>
|
|
624
|
+
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
625
|
+
);
|
|
612
626
|
const rejectIncompleteInitialState = (partial: (Value | undefined)[]) => {
|
|
613
627
|
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
614
628
|
};
|
|
@@ -627,8 +641,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
627
641
|
return (state: Value[], callStack: CallStack | undefined) => {
|
|
628
642
|
fingerprintReplayed(state, getFingerprintState(state), callStack);
|
|
629
643
|
const fingerprintState = getFingerprintState(state);
|
|
644
|
+
const hash = getStateHash(fingerprintState);
|
|
630
645
|
const isSeen =
|
|
631
|
-
findStateIndex(seenStates,
|
|
646
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
647
|
+
isExplored(hash, fingerprintState) ||
|
|
632
648
|
replayed.some((seen) => isSameState(seen, fingerprintState));
|
|
633
649
|
if (isSeen) return false;
|
|
634
650
|
replayed.push(fingerprintState);
|
|
@@ -715,28 +731,38 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
715
731
|
if (spec.next === undefined) return successors;
|
|
716
732
|
const livenessSource = current.livenessSource;
|
|
717
733
|
current.livenessSource = source;
|
|
734
|
+
const addSuccessor = (successor: Value[]) => {
|
|
735
|
+
canonicalizeState(successor);
|
|
736
|
+
const isInModel =
|
|
737
|
+
search.satisfiesConstraints(successor, state) &&
|
|
738
|
+
search.satisfiesActionConstraints(state, successor);
|
|
739
|
+
if (!isInModel) return;
|
|
740
|
+
const fingerprintState = getFingerprintState(successor);
|
|
741
|
+
const hash = getStateHash(fingerprintState);
|
|
742
|
+
const index = findStateIndex(seenStates, hash, fingerprintState);
|
|
743
|
+
successors.push({
|
|
744
|
+
index: index === -1 ? getPendingIndex(hash, fingerprintState) : index,
|
|
745
|
+
state: successor,
|
|
746
|
+
});
|
|
747
|
+
};
|
|
718
748
|
try {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
return false;
|
|
737
|
-
},
|
|
738
|
-
spec.scope,
|
|
739
|
-
);
|
|
749
|
+
// TLC's coverage counts the successors of each action the graph generates again.
|
|
750
|
+
if (coverage) {
|
|
751
|
+
coverageActions.forEach((action) =>
|
|
752
|
+
walkCoveredSuccessors(action, state, addSuccessor),
|
|
753
|
+
);
|
|
754
|
+
} else {
|
|
755
|
+
forEachSuccessor(
|
|
756
|
+
spec.next,
|
|
757
|
+
state,
|
|
758
|
+
environment,
|
|
759
|
+
(successor) => {
|
|
760
|
+
addSuccessor(successor.state);
|
|
761
|
+
return false;
|
|
762
|
+
},
|
|
763
|
+
spec.scope,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
740
766
|
} finally {
|
|
741
767
|
current.livenessSource = livenessSource;
|
|
742
768
|
}
|
|
@@ -755,6 +781,23 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
755
781
|
const actions: (string | undefined)[] = [];
|
|
756
782
|
const depths: number[] = [];
|
|
757
783
|
const seenStates = createStateTable(fingerprintStates);
|
|
784
|
+
const exploredStates: Value[][] = [];
|
|
785
|
+
const exploredFingerprintStates: Value[][] = [];
|
|
786
|
+
let exploredTable: StateTable | undefined;
|
|
787
|
+
const isExplored = (hash: number, fingerprintState: Value[]) =>
|
|
788
|
+
exploredTable !== undefined && findStateIndex(exploredTable, hash, fingerprintState) !== -1;
|
|
789
|
+
const pendingFingerprintStates: Value[][] = [];
|
|
790
|
+
let pendingStates: StateTable | undefined;
|
|
791
|
+
const getPendingIndex = (hash: number, fingerprintState: Value[]) => {
|
|
792
|
+
pendingStates ??= createStateTable(pendingFingerprintStates);
|
|
793
|
+
const found = findStateIndex(pendingStates, hash, fingerprintState);
|
|
794
|
+
const position = found === -1 ? pendingFingerprintStates.length : found;
|
|
795
|
+
if (found === -1) {
|
|
796
|
+
markSeenState(pendingStates, hash, position);
|
|
797
|
+
pendingFingerprintStates.push(fingerprintState);
|
|
798
|
+
}
|
|
799
|
+
return -2 - position;
|
|
800
|
+
};
|
|
758
801
|
const canonicalizeState = createCanonicalizer();
|
|
759
802
|
|
|
760
803
|
const toRecord = search.toRecord;
|
|
@@ -855,7 +898,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
855
898
|
};
|
|
856
899
|
let unstoredFingerprint: Value[] | undefined;
|
|
857
900
|
const countDistinctState = (depth: number) => {
|
|
858
|
-
runtime.distinctStates = states.length + 1;
|
|
901
|
+
runtime.distinctStates = states.length + exploredStates.length + 1;
|
|
859
902
|
searchDepth = Math.max(searchDepth, depth);
|
|
860
903
|
runtime.diameter = Math.max(runtime.diameter, depth);
|
|
861
904
|
};
|
|
@@ -896,18 +939,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
896
939
|
tracedSteps,
|
|
897
940
|
captureOutput,
|
|
898
941
|
getInitialStates: getSpecInitialStates,
|
|
899
|
-
findSuccessorAction
|
|
900
|
-
coverage
|
|
901
|
-
? coverageActions.find((item) => getCoveredSuccessors(item, state).some(isMatch))
|
|
902
|
-
: nextActions.find((item) =>
|
|
903
|
-
getSuccessors(item.expression, state, environment, item.scope).some(isMatch),
|
|
904
|
-
),
|
|
942
|
+
findSuccessorAction,
|
|
905
943
|
});
|
|
906
944
|
const getPath = (index: number): Value[][] =>
|
|
907
945
|
index === -1 ? [] : [...getPath(parents[index]), states[index]];
|
|
946
|
+
// TLC adds a successor's fingerprint to its set before it checks the invariants of the successor.
|
|
908
947
|
runtime.isSeen = (state) => {
|
|
909
948
|
const fingerprintState = getFingerprintState(state);
|
|
910
|
-
|
|
949
|
+
const hash = getStateHash(fingerprintState);
|
|
950
|
+
return (
|
|
951
|
+
findStateIndex(seenStates, hash, fingerprintState) !== -1 ||
|
|
952
|
+
isExplored(hash, fingerprintState) ||
|
|
953
|
+
(unstoredFingerprint !== undefined && isSameState(unstoredFingerprint, fingerprintState))
|
|
954
|
+
);
|
|
955
|
+
};
|
|
956
|
+
runtime.markExplored = (state) => {
|
|
957
|
+
const fingerprintState = getFingerprintState(state);
|
|
958
|
+
exploredTable ??= createStateTable(exploredFingerprintStates);
|
|
959
|
+
markSeenState(exploredTable, getStateHash(fingerprintState), exploredStates.length);
|
|
960
|
+
exploredStates.push(state);
|
|
961
|
+
exploredFingerprintStates.push(fingerprintState);
|
|
962
|
+
runtime.distinctStates++;
|
|
911
963
|
};
|
|
912
964
|
runtime.getBehavior = (state) => {
|
|
913
965
|
const index = state === current.candidate ? -1 : states.indexOf(state);
|
|
@@ -1012,7 +1064,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1012
1064
|
fingerprintModelState(fingerprintState);
|
|
1013
1065
|
successor.state.forEach(markFingerprinted);
|
|
1014
1066
|
}
|
|
1015
|
-
|
|
1067
|
+
const existing = isInModel ? foundIndex : -1;
|
|
1068
|
+
return {
|
|
1069
|
+
fingerprintState,
|
|
1070
|
+
hash,
|
|
1071
|
+
isInModel,
|
|
1072
|
+
existing,
|
|
1073
|
+
isSeen: existing !== -1 || (isInModel && isExplored(hash, fingerprintState)),
|
|
1074
|
+
};
|
|
1016
1075
|
};
|
|
1017
1076
|
const visitSuccessor = (
|
|
1018
1077
|
index: number,
|
|
@@ -1031,7 +1090,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1031
1090
|
stateWriter?.writeSuccessor(
|
|
1032
1091
|
source,
|
|
1033
1092
|
getGraphState(successor.state, depths[index] + 1),
|
|
1034
|
-
found.
|
|
1093
|
+
found.isSeen,
|
|
1035
1094
|
action && getGraphAction(action),
|
|
1036
1095
|
);
|
|
1037
1096
|
}
|
|
@@ -1053,7 +1112,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1053
1112
|
const isStored = stored.every((value, position) => value === successor.state[position]);
|
|
1054
1113
|
liveSuccessors.push({ index: found.existing, state: isStored ? stored : successor.state });
|
|
1055
1114
|
}
|
|
1056
|
-
|
|
1115
|
+
if (found.isSeen && found.existing === -1 && liveness) {
|
|
1116
|
+
liveSuccessors.push({
|
|
1117
|
+
index: getPendingIndex(found.hash, found.fingerprintState),
|
|
1118
|
+
state: successor.state,
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
const isNew = found.isInModel && !found.isSeen;
|
|
1057
1122
|
if (isNew && liveness) liveSuccessors.push({ index: states.length, state: successor.state });
|
|
1058
1123
|
unstoredFingerprint = isNew ? found.fingerprintState : undefined;
|
|
1059
1124
|
if (isNew) {
|
|
@@ -1061,7 +1126,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1061
1126
|
newStateCount++;
|
|
1062
1127
|
if (coverage) coverage.secondary[coveredNode]++;
|
|
1063
1128
|
}
|
|
1064
|
-
if (found.
|
|
1129
|
+
if (!found.isSeen) {
|
|
1065
1130
|
try {
|
|
1066
1131
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1067
1132
|
const violation = violated && { name: violated.name, ...traces.getTrace(index, successor) };
|
|
@@ -1092,6 +1157,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1092
1157
|
if (coverage) countCoverageVariables(coverage, successor.state);
|
|
1093
1158
|
if (!isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1094
1159
|
markSeenState(seenStates, found.hash, states.length);
|
|
1160
|
+
if (pendingStates) {
|
|
1161
|
+
const pending = findStateIndex(pendingStates, found.hash, found.fingerprintState);
|
|
1162
|
+
if (pending !== -1) liveness?.storeState(-2 - pending, states.length);
|
|
1163
|
+
}
|
|
1095
1164
|
addState(successor.state, found.fingerprintState, index, successor.action);
|
|
1096
1165
|
runtime.queueSize++;
|
|
1097
1166
|
return undefined;
|
|
@@ -1139,7 +1208,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1139
1208
|
kind: "liveness-started",
|
|
1140
1209
|
branches: liveness.branches,
|
|
1141
1210
|
isComplete: true,
|
|
1142
|
-
|
|
1211
|
+
// The tier stores and expands every successor, so the graph of each branch has every state.
|
|
1212
|
+
states: liveness.branches * typed.distinctStates,
|
|
1143
1213
|
statistics,
|
|
1144
1214
|
});
|
|
1145
1215
|
options.onProgress?.({ kind: "liveness-finished" });
|
|
@@ -1396,6 +1466,8 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1396
1466
|
return {
|
|
1397
1467
|
...result,
|
|
1398
1468
|
violation: appendTraceOutput(result.violation, live.lines),
|
|
1469
|
+
// TLC adds the state to the behavior graph before it reports the coverage.
|
|
1470
|
+
coverage: getCoverage(),
|
|
1399
1471
|
...(live.result && { liveCallStack: live.result }),
|
|
1400
1472
|
};
|
|
1401
1473
|
}
|
|
@@ -1527,24 +1599,31 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1527
1599
|
const startedAt = performance.now();
|
|
1528
1600
|
const periodic = {
|
|
1529
1601
|
at: startedAt + PERIODIC_START,
|
|
1530
|
-
size
|
|
1602
|
+
// The size of each branch's graph when TLC last checked it, which starts at 1.
|
|
1603
|
+
sizes: liveness?.getStateCounts().map(() => 1) ?? [],
|
|
1531
1604
|
time: 0,
|
|
1532
1605
|
coverageCount: Math.trunc(options.coverage ?? 0),
|
|
1533
1606
|
};
|
|
1534
|
-
|
|
1607
|
+
// TLC counts the states of the graphs of all branches, which can differ.
|
|
1608
|
+
const getGraphStates = (checker: LivenessChecker) =>
|
|
1609
|
+
checker.getStateCounts().reduce((sum, count) => sum + count, 0);
|
|
1610
|
+
const findPeriodicViolation = (checker: LivenessChecker) => {
|
|
1535
1611
|
const now = performance.now();
|
|
1536
|
-
const
|
|
1612
|
+
const counts = checker.getStateCounts();
|
|
1613
|
+
const isGrown = counts.some(
|
|
1614
|
+
(count, branch) =>
|
|
1615
|
+
(count - periodic.sizes[branch]) / periodic.sizes[branch] > LIVENESS_GROWTH,
|
|
1616
|
+
);
|
|
1537
1617
|
if (!isGrown || periodic.time > (now - startedAt) * LIVENESS_RATIO) return undefined;
|
|
1538
|
-
periodic.
|
|
1539
|
-
if (!liveness) return undefined;
|
|
1618
|
+
periodic.sizes = counts;
|
|
1540
1619
|
options.onProgress?.({
|
|
1541
1620
|
kind: "liveness-started",
|
|
1542
|
-
branches:
|
|
1621
|
+
branches: checker.branches,
|
|
1543
1622
|
isComplete: false,
|
|
1544
|
-
states:
|
|
1623
|
+
states: getGraphStates(checker),
|
|
1545
1624
|
statistics: createResult("success"),
|
|
1546
1625
|
});
|
|
1547
|
-
const lasso =
|
|
1626
|
+
const lasso = checker.findViolation();
|
|
1548
1627
|
if (!lasso) options.onProgress?.({ kind: "liveness-finished" });
|
|
1549
1628
|
periodic.time += performance.now() - now;
|
|
1550
1629
|
return lasso;
|
|
@@ -1670,7 +1749,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1670
1749
|
newStateCount = 0;
|
|
1671
1750
|
if ((isPeriodic || options.onProgress) && performance.now() >= periodic.at) {
|
|
1672
1751
|
periodic.at = performance.now() + PROGRESS_INTERVAL;
|
|
1673
|
-
const lasso = isPeriodic ? findPeriodicViolation(
|
|
1752
|
+
const lasso = isPeriodic && liveness ? findPeriodicViolation(liveness) : undefined;
|
|
1674
1753
|
if (liveness && lasso) return reportLasso(liveness, lasso);
|
|
1675
1754
|
const isCoverageDue = options.coverage !== undefined && periodic.coverageCount === 0;
|
|
1676
1755
|
periodic.coverageCount = isCoverageDue
|
|
@@ -1692,7 +1771,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1692
1771
|
kind: "liveness-started",
|
|
1693
1772
|
branches: finalLiveness.branches,
|
|
1694
1773
|
isComplete: true,
|
|
1695
|
-
|
|
1774
|
+
// The tier that found the lasso stored and expanded every successor, so each graph has every state.
|
|
1775
|
+
states: typedLasso
|
|
1776
|
+
? finalLiveness.branches * runtime.distinctStates
|
|
1777
|
+
: getGraphStates(finalLiveness),
|
|
1696
1778
|
statistics: createResult("success"),
|
|
1697
1779
|
});
|
|
1698
1780
|
}
|