tla-ts 0.0.8 → 0.0.9-dev.4ce0657
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +15 -15
- package/dist/deciders.js +48 -48
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +27 -9
- package/dist/index.d.ts +27 -9
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +17 -17
- package/dist/prove.js +32 -32
- package/dist/run.cjs +28 -28
- package/dist/run.js +31 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +1 -1
- package/dist/transfer.cjs +30 -33
- package/dist/transfer.js +30 -33
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +3 -1
- package/src/check.ts +77 -46
- package/src/cli/options.ts +2 -1
- package/src/cli/tlc.ts +26 -8
- package/src/cli/typescript.ts +26 -0
- package/src/codegen.ts +0 -5
- package/src/dependencies.ts +348 -24
- package/src/environment.ts +27 -11
- package/src/errors.ts +15 -0
- package/src/evaluate.ts +188 -712
- package/src/instances.ts +67 -6
- package/src/lexer.ts +140 -51
- package/src/liveness-checker.ts +6 -3
- package/src/liveness.ts +8 -18
- package/src/parallel-worker.ts +6 -3
- package/src/parallel.ts +15 -7
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/sany/generator.ts +9 -7
- package/src/sany/linter.ts +30 -21
- package/src/search.ts +48 -32
- package/src/spec-description.ts +1 -1
- package/src/successors.ts +6 -12
- package/src/symmetry.ts +32 -143
- package/src/tlc/fingerprint.ts +69 -116
- package/src/tlc/order.ts +27 -48
- package/src/tlc/replay.ts +1 -1
- package/src/typescript/actions.ts +494 -0
- package/src/typescript/collections.ts +615 -0
- package/src/typescript/compile.ts +70 -0
- package/src/typescript/context.ts +106 -0
- package/src/typescript/emit.ts +122 -0
- package/src/typescript/expressions.ts +508 -0
- package/src/typescript/formula.ts +160 -0
- package/src/typescript/functions.ts +295 -0
- package/src/typescript/model.ts +164 -0
- package/src/typescript/names.ts +116 -0
- package/src/typescript/program.ts +51 -0
- package/src/typescript/properties.ts +141 -0
- package/src/typescript/scope.ts +117 -0
- package/src/typescript/steps.ts +175 -0
- package/src/typescript/types.ts +178 -0
- package/src/values.ts +126 -82
package/dist/worker.cjs
CHANGED
|
@@ -12,13 +12,13 @@ const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenes
|
|
|
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 u{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends u{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
|
|
13
13
|
of an incorrect recursive function definition that caused TLC to enter
|
|
14
14
|
an infinite loop when trying to compute the function or its application
|
|
15
|
-
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const
|
|
15
|
+
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}},G=class extends u{constructor(e,t){let n=t?.getSourceFile(),r=n?.getLineAndCharacterOfPosition(t?.getStart()??0);super(n===void 0||r===void 0?e:`${n.fileName}:${r.line+1}:${r.character+1} ${e}`),this.name=`TlaTypeScriptError`}};const K=`node:worker_threads`,q=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,J=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
|
|
16
16
|
/* @vite-ignore */
|
|
17
17
|
/* webpackIgnore: true */
|
|
18
|
-
|
|
18
|
+
K))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},Y=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
19
19
|
/* @vite-ignore */
|
|
20
20
|
/* webpackIgnore: true */
|
|
21
|
-
|
|
21
|
+
K)).parentPort,X=()=>{let e=`Bun`in globalThis?import(
|
|
22
22
|
/* @vite-ignore */
|
|
23
23
|
/* webpackIgnore: true */
|
|
24
|
-
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return
|
|
24
|
+
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return C}});
|
package/dist/worker.js
CHANGED
|
@@ -12,13 +12,13 @@ const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenes
|
|
|
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 u{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},b=class extends u{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}};const x=`This was a Java StackOverflowError. It was probably the result
|
|
13
13
|
of an incorrect recursive function definition that caused TLC to enter
|
|
14
14
|
an infinite loop when trying to compute the function or its application
|
|
15
|
-
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}};const
|
|
15
|
+
to an element in its putative domain.`;var S=class extends b{constructor(){super(x)}};const C=()=>n(new S,e.error);var w=class extends b{state;action;variables;constructor(e,t,n,r){super(e),this.state=t,this.action=n,this.variables=r}},T=class extends b{variable;constructor(e,t){super(e),this.variable=t}},E=class extends b{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},D=class extends b{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},O=class extends u{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},k=class extends O{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},A=class extends u{constructor(e,t){super(e,t),this.name=`TlaProverError`}},j=class extends u{constructor(e,t){super(e,t),this.name=`TlaZenonError`}},M=class{name=`TlaIsabelleError`;exception;message;constructor(e,t){this.exception=e,this.message=t}},N=class extends u{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}},P=class extends u{constructor(e,t){super(e,t),this.name=`SmtUnsupportedError`}},F=class extends u{constructor(){super(`the SMT solver was canceled`),this.name=`SmtCanceledError`}},I=class extends u{constructor(e){super(e),this.name=`SmtInvariantError`}},L=class extends u{constructor(e){super(`nlsat does not implement ${e}`),this.name=`NlsatUnsupportedError`}},R=class extends u{constructor(){super(`the pdd manager ran out of nodes`),this.name=`PddMemoryOutError`}},z=class extends u{constructor(e,t){super(e,t),this.name=`SmtParseError`}},B=class extends N{unwound;constructor(e,t){super(e),this.name=`TlaJavaException`,this.unwound=t}};const V=t=>r(t)??(t instanceof d?e.specParseError:t instanceof y?e.configParseError:t instanceof b?e.specEvaluationFailure:e.error);var H=class extends u{node;constructor(e,t){super(e),this.name=`PcalError`,this.node=t}},U=class extends u{constructor(e){super(e),this.name=`PcalRuntimeError`}},W=class extends u{constructor(e){super(`You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${e}.`),this.name=`PcalBugError`}},G=class extends u{constructor(e,t){let n=t?.getSourceFile(),r=n?.getLineAndCharacterOfPosition(t?.getStart()??0);super(n===void 0||r===void 0?e:`${n.fileName}:${r.line+1}:${r.character+1} ${e}`),this.name=`TlaTypeScriptError`}};const K=`node:worker_threads`,q=()=>typeof Worker==`function`||typeof process<`u`&&process.versions?.node!==void 0,J=async(e,t,n)=>{if(typeof Worker==`function`){let r=new Worker(e,{type:`module`});return r.addEventListener(`message`,e=>t(e.data)),r.addEventListener(`error`,n),r}let r=new(await(import(
|
|
16
16
|
/* @vite-ignore */
|
|
17
17
|
/* webpackIgnore: true */
|
|
18
|
-
|
|
18
|
+
K))).Worker(e);return r.on(`message`,t),r.on(`error`,n),{postMessage:(e,t)=>r.postMessage(e,t),terminate:()=>void r.terminate()}},Y=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
19
19
|
/* @vite-ignore */
|
|
20
20
|
/* webpackIgnore: true */
|
|
21
|
-
|
|
21
|
+
K)).parentPort,X=()=>{let e=`Bun`in globalThis?import(
|
|
22
22
|
/* @vite-ignore */
|
|
23
23
|
/* webpackIgnore: true */
|
|
24
|
-
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};export{
|
|
24
|
+
`bun:jsc`):void 0;return async()=>{(await e)?.edenGC(),await new Promise(e=>typeof setImmediate==`function`?setImmediate(e):setTimeout(e,0))}};export{T as A,_ as B,E as C,S as D,f as E,s as F,e as G,V as H,h as I,a as J,r as K,m as L,j as M,k as N,d as O,c as P,v as R,p as S,A as T,o as U,g as V,l as W,b as _,L as a,M as b,U as c,F as d,I as f,u as g,y as h,J as i,N as j,G as k,R as l,P as m,Y as n,W as o,z as p,n as q,q as r,H as s,X as t,x as u,D as v,O as w,B as x,w as y,C as z};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tla-ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-dev.4ce0657",
|
|
4
4
|
"description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formal verification",
|
|
@@ -55,9 +55,11 @@
|
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
+
"@typescript/typescript6": "6.0.2",
|
|
58
59
|
"fflate": "^0.8.3"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
62
|
+
"@engine262/engine262": "0.0.1-d553e7b52501fbc47eae981c8d0fa7a5c26d0171",
|
|
61
63
|
"@types/node": "^22",
|
|
62
64
|
"publint": "^0.3.0",
|
|
63
65
|
"typescript": "^7.0.2",
|
package/src/check.ts
CHANGED
|
@@ -114,6 +114,9 @@ export interface CheckOptions {
|
|
|
114
114
|
dump?: StateDump;
|
|
115
115
|
// TLC's -tool, which changes the messages of TLC's errors.
|
|
116
116
|
isTool?: boolean;
|
|
117
|
+
// TLC's -continue: the search reports each violated invariant and action property through
|
|
118
|
+
// onProgress and goes on.
|
|
119
|
+
isContinued?: boolean;
|
|
117
120
|
// Whether TLC records a binary trace for its trace exploration spec, for which it loads Integers.
|
|
118
121
|
isTraceRecorded?: boolean;
|
|
119
122
|
// Whether the caller printed SANY's report, its warnings included, before the check.
|
|
@@ -163,8 +166,11 @@ export type CheckProgress =
|
|
|
163
166
|
statistics: SearchStatistics;
|
|
164
167
|
}
|
|
165
168
|
| { kind: "liveness-finished" }
|
|
169
|
+
| { kind: "sequential-fallback"; string: string }
|
|
166
170
|
// A warning TLC prints as it evaluates the spec, with its message code.
|
|
167
171
|
| { kind: "warning"; code: number; text: string }
|
|
172
|
+
// A violation that the search goes on past with -continue.
|
|
173
|
+
| { kind: "violation"; status: CheckStatus; violation: Violation }
|
|
168
174
|
// A method of the class named after a module, which TLC reports as it loads the class.
|
|
169
175
|
| ({ kind: "java-override" } & JavaOverride);
|
|
170
176
|
|
|
@@ -551,6 +557,13 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
551
557
|
...(checked.postcondition && { postcondition: checked.postcondition }),
|
|
552
558
|
});
|
|
553
559
|
};
|
|
560
|
+
// With -continue, TLC prints the trace of a violation without checking the postconditions.
|
|
561
|
+
const reportContinuedViolation = (status: CheckStatus, violation: Omit<Violation, "loopStart">) =>
|
|
562
|
+
options.onProgress?.({
|
|
563
|
+
kind: "violation",
|
|
564
|
+
status,
|
|
565
|
+
violation: { ...violation, loopStart: undefined },
|
|
566
|
+
});
|
|
554
567
|
const spec = search.spec;
|
|
555
568
|
const getFingerprintState = search.getFingerprintState;
|
|
556
569
|
const specNextActions = { value: undefined as SpecAction[] | undefined };
|
|
@@ -707,24 +720,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
707
720
|
// explored it.
|
|
708
721
|
const livenessSource = current.livenessSource;
|
|
709
722
|
current.livenessSource = source;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
723
|
+
try {
|
|
724
|
+
forEachSuccessor(
|
|
725
|
+
spec.next,
|
|
726
|
+
state,
|
|
727
|
+
environment,
|
|
728
|
+
(successor) => {
|
|
729
|
+
canonicalizeState(successor.state);
|
|
730
|
+
const isInModel =
|
|
731
|
+
search.satisfiesConstraints(successor.state, state) &&
|
|
732
|
+
search.satisfiesActionConstraints(state, successor.state);
|
|
733
|
+
if (!isInModel) return false;
|
|
734
|
+
const fingerprintState = getFingerprintState(successor.state);
|
|
735
|
+
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
736
|
+
successors.push({ index, state: successor.state });
|
|
737
|
+
return false;
|
|
738
|
+
},
|
|
739
|
+
spec.scope,
|
|
740
|
+
);
|
|
741
|
+
} finally {
|
|
742
|
+
current.livenessSource = livenessSource;
|
|
743
|
+
}
|
|
728
744
|
return successors;
|
|
729
745
|
},
|
|
730
746
|
}),
|
|
@@ -754,14 +770,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
754
770
|
position: number,
|
|
755
771
|
loopStart: number | undefined,
|
|
756
772
|
) => {
|
|
757
|
-
// TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace.
|
|
773
|
+
// TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace. The
|
|
774
|
+
// search reads them again once the alias is evaluated, as it goes on with -continue.
|
|
775
|
+
const searchLevel = runtime.getLevel;
|
|
776
|
+
const searchBehavior = runtime.getBehavior;
|
|
758
777
|
runtime.getLevel = () => position + 1;
|
|
759
778
|
runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
779
|
+
try {
|
|
780
|
+
return evaluateAlias(
|
|
781
|
+
alias,
|
|
782
|
+
steps[position].state,
|
|
783
|
+
(steps[position + 1] ?? steps[loopStart ?? position]).state,
|
|
784
|
+
);
|
|
785
|
+
} finally {
|
|
786
|
+
runtime.getLevel = searchLevel;
|
|
787
|
+
runtime.getBehavior = searchBehavior;
|
|
788
|
+
}
|
|
765
789
|
};
|
|
766
790
|
const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
|
|
767
791
|
try {
|
|
@@ -785,13 +809,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
785
809
|
Object.assign(current, { index, isExpanding: true, candidate: undefined });
|
|
786
810
|
const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
|
|
787
811
|
const key = getKey(state);
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
812
|
+
try {
|
|
813
|
+
return actions.find((item) =>
|
|
814
|
+
getSuccessors(item.expression, previous, environment, item.scope).some((successor) =>
|
|
815
|
+
isSameState(getKey(successor.state), key),
|
|
816
|
+
),
|
|
817
|
+
);
|
|
818
|
+
} finally {
|
|
819
|
+
Object.assign(current, expanding);
|
|
820
|
+
}
|
|
795
821
|
};
|
|
796
822
|
// Before TLC prints a trace, it rebuilds from the initial predicate the states it does not keep,
|
|
797
823
|
// all but the last `known` ones. As it prints each later step, it finds the action that takes
|
|
@@ -1164,7 +1190,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1164
1190
|
liveness?.addInitialState(states.length, state);
|
|
1165
1191
|
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
1166
1192
|
}
|
|
1167
|
-
|
|
1193
|
+
if (options.isContinued) {
|
|
1194
|
+
search.getViolatedInvariants(state).forEach((invariant) =>
|
|
1195
|
+
reportContinuedViolation("invariant-violation", {
|
|
1196
|
+
name: invariant.name,
|
|
1197
|
+
...toTrace([{ action: undefined, state }], []),
|
|
1198
|
+
}),
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
const violated = options.isContinued ? undefined : search.findViolatedInvariant(state);
|
|
1168
1202
|
if (violated) {
|
|
1169
1203
|
return reportViolation("invariant-violation", {
|
|
1170
1204
|
name: violated.name,
|
|
@@ -1231,14 +1265,11 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1231
1265
|
if (existing === -1) {
|
|
1232
1266
|
try {
|
|
1233
1267
|
const violated = search.findViolatedInvariant(successor.state, state);
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
name: violated.name,
|
|
1238
|
-
...getTrace(index, successor),
|
|
1239
|
-
}),
|
|
1240
|
-
);
|
|
1268
|
+
const violation = violated && { name: violated.name, ...getTrace(index, successor) };
|
|
1269
|
+
if (violation && !options.isContinued) {
|
|
1270
|
+
return withOutDegrees(reportViolation("invariant-violation", violation));
|
|
1241
1271
|
}
|
|
1272
|
+
if (violation) reportContinuedViolation("invariant-violation", violation);
|
|
1242
1273
|
} catch (error) {
|
|
1243
1274
|
if (isStackOverflow(error)) throw error;
|
|
1244
1275
|
// TLC replays the expansion and skips the invariants of a state it has seen, the failed one
|
|
@@ -1253,14 +1284,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1253
1284
|
}
|
|
1254
1285
|
}
|
|
1255
1286
|
const violatedProperty = search.findViolatedActionProperty(state, successor.state);
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
);
|
|
1287
|
+
const propertyViolation = violatedProperty && {
|
|
1288
|
+
name: violatedProperty.name,
|
|
1289
|
+
...getTrace(index, successor),
|
|
1290
|
+
};
|
|
1291
|
+
if (propertyViolation && !options.isContinued) {
|
|
1292
|
+
return withOutDegrees(reportViolation("liveness-violation", propertyViolation));
|
|
1263
1293
|
}
|
|
1294
|
+
if (propertyViolation) reportContinuedViolation("liveness-violation", propertyViolation);
|
|
1264
1295
|
if (!isNew) return undefined;
|
|
1265
1296
|
if (!isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1266
1297
|
markSeen(hash, states.length);
|
package/src/cli/options.ts
CHANGED
|
@@ -63,8 +63,9 @@ export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
export const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|glob>... {options}", [
|
|
66
|
+
export const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|spec.ts|glob>... {options}", [
|
|
67
67
|
{ flag: "-config <Spec.cfg>" },
|
|
68
|
+
{ flag: "-continue" },
|
|
68
69
|
{ flag: "-deadlock" },
|
|
69
70
|
// Like TLC, -dump takes a format only when the next argument starts with dot and a file follows.
|
|
70
71
|
{
|
package/src/cli/tlc.ts
CHANGED
|
@@ -75,6 +75,7 @@ import {
|
|
|
75
75
|
toLibraryPath,
|
|
76
76
|
type JavaProperties,
|
|
77
77
|
} from "./shared";
|
|
78
|
+
import { writeTypeScriptSpec } from "./typescript";
|
|
78
79
|
|
|
79
80
|
const EXIT_CODES: Record<CheckStatus, number> = {
|
|
80
81
|
success: EXIT_STATUS.success,
|
|
@@ -351,8 +352,16 @@ const printCheckProgress = (
|
|
|
351
352
|
case "liveness-finished":
|
|
352
353
|
printLivenessEnd(printer, timing);
|
|
353
354
|
return;
|
|
355
|
+
case "sequential-fallback":
|
|
356
|
+
process.stderr.write(
|
|
357
|
+
`Warning: the search created the string ${JSON.stringify(progress.string)}, so tla-ts checks the model again with one worker. Workers agree on the order of strings only when the strings exist before the search.\n`,
|
|
358
|
+
);
|
|
359
|
+
return;
|
|
354
360
|
case "warning":
|
|
355
361
|
print(progress.code, MESSAGE_LEVEL.warning, progress.text);
|
|
362
|
+
return;
|
|
363
|
+
case "violation":
|
|
364
|
+
printViolation(progress.status, progress.violation, printer);
|
|
356
365
|
}
|
|
357
366
|
};
|
|
358
367
|
|
|
@@ -823,6 +832,7 @@ const checkSpec = async (
|
|
|
823
832
|
seed: BigInt(seed),
|
|
824
833
|
dump: dumpValues && getStateDump(dumpValues),
|
|
825
834
|
isTool: printer.isTool,
|
|
835
|
+
isContinued: args.has("-continue"),
|
|
826
836
|
isTraceRecorded: isRecorded,
|
|
827
837
|
isSanyReported: true,
|
|
828
838
|
isWarningEnabled: !args.has("-nowarning"),
|
|
@@ -873,19 +883,21 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
873
883
|
const inputs = getInputPaths(parsed.positionals);
|
|
874
884
|
const isConfigured = parsed.has("-config");
|
|
875
885
|
// Like TLC, a spec named without an extension is the .tla file of that name. A glob also matches
|
|
876
|
-
// modules that only other specs import, which have no configuration.
|
|
886
|
+
// modules that only other specs import, which have no configuration. A TypeScript file compiles
|
|
887
|
+
// to a spec.
|
|
877
888
|
const specPaths = inputs
|
|
878
889
|
.map((input) => ({
|
|
879
890
|
...input,
|
|
880
891
|
path:
|
|
881
|
-
input.isGlobbed || /\.(tla|cfg)$/.test(input.path)
|
|
892
|
+
input.isGlobbed || /\.(tla|cfg|ts)$/.test(input.path)
|
|
882
893
|
? input.path.replace(/\.cfg$/, ".tla")
|
|
883
894
|
: `${input.path}.tla`,
|
|
884
895
|
}))
|
|
885
896
|
.filter(
|
|
886
897
|
(input) =>
|
|
887
|
-
input.path.endsWith(".
|
|
888
|
-
(
|
|
898
|
+
input.path.endsWith(".ts") ||
|
|
899
|
+
(input.path.endsWith(".tla") &&
|
|
900
|
+
(!input.isGlobbed || isConfigured || existsSync(input.path.replace(/\.tla$/, ".cfg")))),
|
|
889
901
|
)
|
|
890
902
|
.map((input) => input.path);
|
|
891
903
|
if (specPaths.length === 0) {
|
|
@@ -907,15 +919,21 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
907
919
|
const exitCodes: number[] = [];
|
|
908
920
|
for (const [index, path] of paths.entries()) {
|
|
909
921
|
if (index > 0) console.log("");
|
|
910
|
-
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
911
|
-
if (paths.length > 1)
|
|
912
|
-
console.log(`Checking ${basename(path)} with ${basename(path, ".tla")}.cfg`);
|
|
913
922
|
const printer = createMessagePrinter(
|
|
914
923
|
parsed.has("-tool"),
|
|
915
924
|
!parsed.has("-nowarning"),
|
|
916
925
|
java.tlcVersion ?? "master",
|
|
917
926
|
);
|
|
918
|
-
exitCodes.push(
|
|
927
|
+
exitCodes.push(
|
|
928
|
+
await reportErrors(async () => {
|
|
929
|
+
const specPath = path.endsWith(".ts") ? await writeTypeScriptSpec(path) : path;
|
|
930
|
+
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
931
|
+
if (paths.length > 1) {
|
|
932
|
+
console.log(`Checking ${basename(specPath)} with ${basename(specPath, ".tla")}.cfg`);
|
|
933
|
+
}
|
|
934
|
+
return checkSpec(specPath, parsed, java, printer);
|
|
935
|
+
}, printer),
|
|
936
|
+
);
|
|
919
937
|
}
|
|
920
938
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
921
939
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { TlaTypeScriptError } from "../errors";
|
|
4
|
+
|
|
5
|
+
// Compiles a TypeScript file to the TLA+ spec and config of its module, beside it, and returns the
|
|
6
|
+
// spec's path. A file there that tla-ts didn't generate is left alone.
|
|
7
|
+
export const writeTypeScriptSpec = async (path: string) => {
|
|
8
|
+
// The TypeScript compiler takes a while to load, so only a TypeScript input loads it.
|
|
9
|
+
const compiled = (await import("../typescript/compile")).compile(
|
|
10
|
+
readFileSync(path, "utf8"),
|
|
11
|
+
path,
|
|
12
|
+
);
|
|
13
|
+
const header = `\\* Generated by tla-ts from ${basename(path)}. Edit ${basename(path)} instead.`;
|
|
14
|
+
const specPath = join(dirname(path), `${compiled.name}.tla`);
|
|
15
|
+
const configPath = join(dirname(path), `${compiled.name}.cfg`);
|
|
16
|
+
for (const outputPath of [specPath, configPath]) {
|
|
17
|
+
if (existsSync(outputPath) && !readFileSync(outputPath, "utf8").startsWith(header)) {
|
|
18
|
+
throw new TlaTypeScriptError(
|
|
19
|
+
`${outputPath} already exists, and tla-ts didn't generate it from ${path}`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
writeFileSync(specPath, `${header}\n${compiled.source}\n`);
|
|
24
|
+
writeFileSync(configPath, `${header}\n${compiled.config}\n`);
|
|
25
|
+
return specPath;
|
|
26
|
+
};
|
package/src/codegen.ts
CHANGED
|
@@ -11,9 +11,7 @@ import {
|
|
|
11
11
|
getFieldSelector,
|
|
12
12
|
getMissingArgumentDescriber,
|
|
13
13
|
getQuantifierElements,
|
|
14
|
-
isClosedConstant,
|
|
15
14
|
isValueArgument,
|
|
16
|
-
isWorthCaching,
|
|
17
15
|
keepLazy,
|
|
18
16
|
resolveGlobalOperator,
|
|
19
17
|
expectFunction,
|
|
@@ -281,9 +279,6 @@ const isReadOnly = (expression: Expression): boolean => {
|
|
|
281
279
|
const generateExpression = (generator: Generator, expression: Expression, frame: Frame): string => {
|
|
282
280
|
const generate = (node: Expression, nodeFrame = frame) =>
|
|
283
281
|
generateExpression(generator, node, nodeFrame);
|
|
284
|
-
if (isWorthCaching(expression) && isClosedConstant(expression, generator.environment)) {
|
|
285
|
-
return generateDelegate(generator, expression, frame);
|
|
286
|
-
}
|
|
287
282
|
switch (expression.kind) {
|
|
288
283
|
case "Number":
|
|
289
284
|
if (isTlcInteger(expression.value)) {
|