tla-ts 0.0.9-dev.5790648 → 0.0.9-dev.7fe4429
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 +22 -1
- 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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +29 -29
- package/dist/prove.js +20 -20
- 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 +27 -27
- package/dist/transfer.js +30 -30
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +3 -1
- package/src/check.ts +44 -31
- package/src/cli/options.ts +1 -1
- package/src/cli/tlc.ts +18 -9
- package/src/cli/typescript.ts +26 -0
- package/src/errors.ts +15 -0
- package/src/evaluate.ts +65 -10
- package/src/liveness-checker.ts +6 -3
- package/src/liveness.ts +7 -3
- package/src/parallel-worker.ts +5 -6
- package/src/parallel.ts +5 -4
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/successors.ts +3 -3
- 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 +148 -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 +39 -15
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.9-dev.
|
|
3
|
+
"version": "0.0.9-dev.7fe4429",
|
|
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
|
@@ -720,24 +720,27 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
720
720
|
// explored it.
|
|
721
721
|
const livenessSource = current.livenessSource;
|
|
722
722
|
current.livenessSource = source;
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
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
|
+
}
|
|
741
744
|
return successors;
|
|
742
745
|
},
|
|
743
746
|
}),
|
|
@@ -767,14 +770,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
767
770
|
position: number,
|
|
768
771
|
loopStart: number | undefined,
|
|
769
772
|
) => {
|
|
770
|
-
// 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;
|
|
771
777
|
runtime.getLevel = () => position + 1;
|
|
772
778
|
runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
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
|
+
}
|
|
778
789
|
};
|
|
779
790
|
const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
|
|
780
791
|
try {
|
|
@@ -798,13 +809,15 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
798
809
|
Object.assign(current, { index, isExpanding: true, candidate: undefined });
|
|
799
810
|
const getKey = isHeld ? (values: Value[]) => values : getFingerprintState;
|
|
800
811
|
const key = getKey(state);
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
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
|
+
}
|
|
808
821
|
};
|
|
809
822
|
// Before TLC prints a trace, it rebuilds from the initial predicate the states it does not keep,
|
|
810
823
|
// all but the last `known` ones. As it prints each later step, it finds the action that takes
|
package/src/cli/options.ts
CHANGED
|
@@ -63,7 +63,7 @@ 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
68
|
{ flag: "-continue" },
|
|
69
69
|
{ flag: "-deadlock" },
|
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,
|
|
@@ -353,7 +354,7 @@ const printCheckProgress = (
|
|
|
353
354
|
return;
|
|
354
355
|
case "sequential-fallback":
|
|
355
356
|
process.stderr.write(
|
|
356
|
-
`Warning: the search
|
|
357
|
+
`Warning: the search ordered the string ${JSON.stringify(progress.string)} against another string it created, so tla-ts checks the model again with one worker. Workers don't agree on the order of strings the search creates.\n`,
|
|
357
358
|
);
|
|
358
359
|
return;
|
|
359
360
|
case "warning":
|
|
@@ -882,19 +883,21 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
882
883
|
const inputs = getInputPaths(parsed.positionals);
|
|
883
884
|
const isConfigured = parsed.has("-config");
|
|
884
885
|
// Like TLC, a spec named without an extension is the .tla file of that name. A glob also matches
|
|
885
|
-
// 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.
|
|
886
888
|
const specPaths = inputs
|
|
887
889
|
.map((input) => ({
|
|
888
890
|
...input,
|
|
889
891
|
path:
|
|
890
|
-
input.isGlobbed || /\.(tla|cfg)$/.test(input.path)
|
|
892
|
+
input.isGlobbed || /\.(tla|cfg|ts)$/.test(input.path)
|
|
891
893
|
? input.path.replace(/\.cfg$/, ".tla")
|
|
892
894
|
: `${input.path}.tla`,
|
|
893
895
|
}))
|
|
894
896
|
.filter(
|
|
895
897
|
(input) =>
|
|
896
|
-
input.path.endsWith(".
|
|
897
|
-
(
|
|
898
|
+
input.path.endsWith(".ts") ||
|
|
899
|
+
(input.path.endsWith(".tla") &&
|
|
900
|
+
(!input.isGlobbed || isConfigured || existsSync(input.path.replace(/\.tla$/, ".cfg")))),
|
|
898
901
|
)
|
|
899
902
|
.map((input) => input.path);
|
|
900
903
|
if (specPaths.length === 0) {
|
|
@@ -916,15 +919,21 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
916
919
|
const exitCodes: number[] = [];
|
|
917
920
|
for (const [index, path] of paths.entries()) {
|
|
918
921
|
if (index > 0) console.log("");
|
|
919
|
-
// TLC checks one spec, so tla-ts names each of several it checks.
|
|
920
|
-
if (paths.length > 1)
|
|
921
|
-
console.log(`Checking ${basename(path)} with ${basename(path, ".tla")}.cfg`);
|
|
922
922
|
const printer = createMessagePrinter(
|
|
923
923
|
parsed.has("-tool"),
|
|
924
924
|
!parsed.has("-nowarning"),
|
|
925
925
|
java.tlcVersion ?? "master",
|
|
926
926
|
);
|
|
927
|
-
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
|
+
);
|
|
928
937
|
}
|
|
929
938
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
930
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/errors.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type ts from "@typescript/typescript6";
|
|
1
2
|
import type { SourceRange } from "./ast";
|
|
2
3
|
import { EXIT_STATUS, getExitCode, setExitCode } from "./exit-codes";
|
|
3
4
|
import type { PcalNode } from "./pcal/ast";
|
|
@@ -373,3 +374,17 @@ export class PcalBugError extends TlaError {
|
|
|
373
374
|
this.name = "PcalBugError";
|
|
374
375
|
}
|
|
375
376
|
}
|
|
377
|
+
|
|
378
|
+
// TypeScript that tla-ts can't compile to TLA+, at the file, line and column of the construct.
|
|
379
|
+
export class TlaTypeScriptError extends TlaError {
|
|
380
|
+
constructor(message: string, node?: ts.Node) {
|
|
381
|
+
const sourceFile = node?.getSourceFile();
|
|
382
|
+
const position = sourceFile?.getLineAndCharacterOfPosition(node?.getStart() ?? 0);
|
|
383
|
+
super(
|
|
384
|
+
sourceFile === undefined || position === undefined
|
|
385
|
+
? message
|
|
386
|
+
: `${sourceFile.fileName}:${position.line + 1}:${position.character + 1} ${message}`,
|
|
387
|
+
);
|
|
388
|
+
this.name = "TlaTypeScriptError";
|
|
389
|
+
}
|
|
390
|
+
}
|
package/src/evaluate.ts
CHANGED
|
@@ -119,6 +119,8 @@ export interface Thunk {
|
|
|
119
119
|
// Whether the expression may build a set that streams until TLC caches it, so that the thunk
|
|
120
120
|
// caches only a settled value.
|
|
121
121
|
isStreamed: boolean;
|
|
122
|
+
// Whether the thunk dropped its scope after caching a value that holds in every state.
|
|
123
|
+
isReleased?: boolean;
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
type Binding = { kind: "Value"; value: Value } | Thunk | { kind: "Operator"; operator: Operator };
|
|
@@ -818,9 +820,15 @@ export const evaluateStartupDefinitions = (definitions: Definition[], environmen
|
|
|
818
820
|
|
|
819
821
|
const forceThunk = (thunk: Thunk, context: Context) => {
|
|
820
822
|
const isSameState = thunk.state === context.state && thunk.next === context.next;
|
|
821
|
-
if (
|
|
823
|
+
if (thunk.cache !== undefined && (isSameState || thunk.isReleased)) return thunk.cache;
|
|
822
824
|
const value = evaluate(thunk.expression, withScope(context, thunk.scope));
|
|
823
825
|
if (isSameState && (!thunk.isStreamed || isSettledValue(value))) thunk.cache = value;
|
|
826
|
+
// A value a thunk cached with no state read no variable, so it holds in every state. Releasing
|
|
827
|
+
// its scope frees the evaluations the scope's bindings cached, which a long script keeps alive.
|
|
828
|
+
if (thunk.cache !== undefined && thunk.state === undefined && thunk.next === undefined) {
|
|
829
|
+
thunk.scope = undefined;
|
|
830
|
+
thunk.isReleased = true;
|
|
831
|
+
}
|
|
824
832
|
return value;
|
|
825
833
|
};
|
|
826
834
|
|
|
@@ -1026,6 +1034,24 @@ interface ReevaluatedDefinitions {
|
|
|
1026
1034
|
streamed: ReadonlySet<Definition>;
|
|
1027
1035
|
}
|
|
1028
1036
|
|
|
1037
|
+
// A LET's function definition has one function constructor, as in SANY, so its code compiles once
|
|
1038
|
+
// however often the LET is evaluated.
|
|
1039
|
+
const letFunctionConstructions = new WeakMap<FunctionDefinition, Expression>();
|
|
1040
|
+
|
|
1041
|
+
const getLetFunctionConstruction = (definition: FunctionDefinition): Expression => {
|
|
1042
|
+
const known = letFunctionConstructions.get(definition);
|
|
1043
|
+
if (known) return known;
|
|
1044
|
+
const construction: Expression = {
|
|
1045
|
+
kind: "FunctionConstruction",
|
|
1046
|
+
bounds: definition.bounds,
|
|
1047
|
+
body: definition.body,
|
|
1048
|
+
location: definition.location,
|
|
1049
|
+
isRecursive: true,
|
|
1050
|
+
};
|
|
1051
|
+
letFunctionConstructions.set(definition, construction);
|
|
1052
|
+
return construction;
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1029
1055
|
export const bindDefinitions = (
|
|
1030
1056
|
definitions: Definition[],
|
|
1031
1057
|
context: Context,
|
|
@@ -1040,13 +1066,7 @@ export const bindDefinitions = (
|
|
|
1040
1066
|
if (definition.kind === "Function") {
|
|
1041
1067
|
node.binding = {
|
|
1042
1068
|
kind: "Thunk",
|
|
1043
|
-
expression:
|
|
1044
|
-
kind: "FunctionConstruction",
|
|
1045
|
-
bounds: definition.bounds,
|
|
1046
|
-
body: definition.body,
|
|
1047
|
-
location: definition.location,
|
|
1048
|
-
isRecursive: true,
|
|
1049
|
-
},
|
|
1069
|
+
expression: getLetFunctionConstruction(definition),
|
|
1050
1070
|
scope: node,
|
|
1051
1071
|
state: context.state,
|
|
1052
1072
|
next: context.next,
|
|
@@ -1529,6 +1549,39 @@ export const keepLazy = (expression: Expression) => {
|
|
|
1529
1549
|
}
|
|
1530
1550
|
};
|
|
1531
1551
|
|
|
1552
|
+
// The names an expression may look up in its scope, or undefined when a subexpression selector may
|
|
1553
|
+
// look up others.
|
|
1554
|
+
const scopeNames = new WeakMap<Expression, string[] | undefined>();
|
|
1555
|
+
|
|
1556
|
+
const getScopeNames = (expression: Expression) => {
|
|
1557
|
+
if (scopeNames.has(expression)) return scopeNames.get(expression);
|
|
1558
|
+
const names = new Set<string>();
|
|
1559
|
+
const visit = (node: Expression): boolean => {
|
|
1560
|
+
if (node.kind === "Subexpression") return false;
|
|
1561
|
+
if (node.kind === "Identifier") names.add(node.name);
|
|
1562
|
+
if (node.kind === "Apply" || node.kind === "OperatorReference") names.add(node.operator);
|
|
1563
|
+
if (node.kind === "ExceptAt") names.add(EXCEPT_AT);
|
|
1564
|
+
return getChildren(node).every(visit);
|
|
1565
|
+
};
|
|
1566
|
+
const result = visit(expression) ? [...names] : undefined;
|
|
1567
|
+
scopeNames.set(expression, result);
|
|
1568
|
+
return result;
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
// The bindings of a scope that names look up, so that a lazy function keeps only those alive and
|
|
1572
|
+
// not the values its other bindings cached. An unnamed node ends the chain, since a TLCEval in the
|
|
1573
|
+
// body sorts its value only where no context binds a name.
|
|
1574
|
+
const trimScope = (scope: Scope | undefined, names: string[] | undefined) =>
|
|
1575
|
+
names === undefined || scope === undefined
|
|
1576
|
+
? scope
|
|
1577
|
+
: names.reduce<Scope>(
|
|
1578
|
+
(trimmed, name) => {
|
|
1579
|
+
const binding = lookupScope(scope, name);
|
|
1580
|
+
return binding ? { name, binding, parent: trimmed } : trimmed;
|
|
1581
|
+
},
|
|
1582
|
+
{ name: "", binding: { kind: "Value", value: false }, parent: undefined },
|
|
1583
|
+
);
|
|
1584
|
+
|
|
1532
1585
|
const compileFunctionConstruction = (
|
|
1533
1586
|
expression: Expression & { kind: "FunctionConstruction" },
|
|
1534
1587
|
environment: Environment,
|
|
@@ -1569,12 +1622,14 @@ const compileFunctionConstruction = (
|
|
|
1569
1622
|
return createFunction(pairs);
|
|
1570
1623
|
};
|
|
1571
1624
|
const template = getLazyFunctionTemplate(bounds, expression.body);
|
|
1625
|
+
const bodyNames = getScopeNames(expression.body);
|
|
1572
1626
|
const createLazy = (domain: Value, context: Context) => {
|
|
1573
|
-
const scope = context.scope;
|
|
1627
|
+
const scope = trimScope(context.scope, bodyNames);
|
|
1628
|
+
const lambdaContext = withScope(context, scope);
|
|
1574
1629
|
const functionValue = keepLambda({
|
|
1575
1630
|
value: createLazyFunction(
|
|
1576
1631
|
domain,
|
|
1577
|
-
(argument) => body(withScope(
|
|
1632
|
+
(argument) => body(withScope(lambdaContext, bindArgument(bounds, scope, argument))),
|
|
1578
1633
|
getLazyFunctionSource(template, bounds, domain),
|
|
1579
1634
|
),
|
|
1580
1635
|
bounds,
|
package/src/liveness-checker.ts
CHANGED
|
@@ -268,11 +268,14 @@ export const createLivenessChecker = (
|
|
|
268
268
|
return cache;
|
|
269
269
|
};
|
|
270
270
|
// TLCGet("level") reads the level of the state whose successors the checks run on.
|
|
271
|
+
// A check that fails leaves no source, so the failure's trace reads the levels of the search.
|
|
271
272
|
const evaluateFrom = <Result>(source: number | undefined, evaluate: () => Result) => {
|
|
272
273
|
environment.runtime.setLivenessSource(source);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
try {
|
|
275
|
+
return evaluate();
|
|
276
|
+
} finally {
|
|
277
|
+
environment.runtime.setLivenessSource(undefined);
|
|
278
|
+
}
|
|
276
279
|
};
|
|
277
280
|
const evaluateState = (predicate: LiveExpression, state: Value[]) =>
|
|
278
281
|
evaluateLive(
|
package/src/liveness.ts
CHANGED
|
@@ -92,7 +92,11 @@ export const getLevel = (
|
|
|
92
92
|
const binding = lookupScope(scope, name);
|
|
93
93
|
if (!binding) return undefined;
|
|
94
94
|
if (binding.kind === "Value") return CONSTANT_LEVEL;
|
|
95
|
-
if (binding.kind === "Thunk")
|
|
95
|
+
if (binding.kind === "Thunk") {
|
|
96
|
+
return binding.isReleased
|
|
97
|
+
? CONSTANT_LEVEL
|
|
98
|
+
: getLevel(binding.expression, binding.scope, environment);
|
|
99
|
+
}
|
|
96
100
|
const operator = binding.operator;
|
|
97
101
|
return operator.kind === "Closure"
|
|
98
102
|
? getLevel(operator.body, operator.scope, environment)
|
|
@@ -210,7 +214,7 @@ export const expandTemporal = (
|
|
|
210
214
|
}
|
|
211
215
|
if (expression.kind === "Identifier") {
|
|
212
216
|
const binding = isLocallyResolved(expression) ? lookupScope(scope, expression.name) : undefined;
|
|
213
|
-
if (binding?.kind === "Thunk") {
|
|
217
|
+
if (binding?.kind === "Thunk" && !binding.isReleased) {
|
|
214
218
|
return expand(binding.expression, binding.scope);
|
|
215
219
|
}
|
|
216
220
|
const definition = environment.constants.has(expression.name)
|
|
@@ -345,7 +349,7 @@ export const toLiveExpression = (
|
|
|
345
349
|
isLocallyResolved(expression) || getDefinition(name, environment) === undefined
|
|
346
350
|
? lookupScope(scope, name)
|
|
347
351
|
: undefined;
|
|
348
|
-
if (binding?.kind === "Thunk" && definitionThunks.has(binding)) {
|
|
352
|
+
if (binding?.kind === "Thunk" && !binding.isReleased && definitionThunks.has(binding)) {
|
|
349
353
|
return expandCall(expression, () =>
|
|
350
354
|
expand(binding.expression, binding.scope, expression, scope),
|
|
351
355
|
);
|
package/src/parallel-worker.ts
CHANGED
|
@@ -13,8 +13,8 @@ import { OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
|
13
13
|
import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
|
|
14
14
|
import {
|
|
15
15
|
createCanonicalizer,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
freezeStringOrder,
|
|
17
|
+
getUnorderedString,
|
|
18
18
|
setStringOrder,
|
|
19
19
|
setValueVersion,
|
|
20
20
|
type Value,
|
|
@@ -45,7 +45,7 @@ const runWorker = (start: StartMessage, parent: Port) => {
|
|
|
45
45
|
const order = createTlcOrder(start.source, loadModule);
|
|
46
46
|
setStringOrder(order.getStringOrder(start.config));
|
|
47
47
|
setValueVersion(start.version);
|
|
48
|
-
|
|
48
|
+
freezeStringOrder();
|
|
49
49
|
const specification = createEnvironment(start.config, {
|
|
50
50
|
source: start.source,
|
|
51
51
|
loadModule,
|
|
@@ -223,9 +223,8 @@ const runWorker = (start: StartMessage, parent: Port) => {
|
|
|
223
223
|
}
|
|
224
224
|
if (!(await steal(expansion))) break;
|
|
225
225
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
226
|
+
const unorderedString = getUnorderedString();
|
|
227
|
+
if (unorderedString !== undefined) return { type: "abort", string: unorderedString };
|
|
229
228
|
frontier.states = expansion.next;
|
|
230
229
|
Atomics.store(remaining, workerIndex, frontier.states.length);
|
|
231
230
|
return {
|
package/src/parallel.ts
CHANGED
|
@@ -31,8 +31,8 @@ import { createStateEncoder, type EncodedStates } from "./transfer";
|
|
|
31
31
|
import type { TlcVersion } from "./tlc/version";
|
|
32
32
|
import {
|
|
33
33
|
createCanonicalizer,
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
freezeStringOrder,
|
|
35
|
+
getUnorderedString,
|
|
36
36
|
setStringOrder,
|
|
37
37
|
setValueVersion,
|
|
38
38
|
type Value,
|
|
@@ -138,7 +138,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
138
138
|
const order = createTlcOrder(options.source, loadModule);
|
|
139
139
|
setStringOrder(order.getStringOrder(config));
|
|
140
140
|
setValueVersion(options.version);
|
|
141
|
-
|
|
141
|
+
freezeStringOrder();
|
|
142
142
|
const specification = createEnvironment(config, {
|
|
143
143
|
source: options.source,
|
|
144
144
|
loadModule,
|
|
@@ -237,7 +237,8 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
237
237
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
238
238
|
return fallBack();
|
|
239
239
|
}
|
|
240
|
-
|
|
240
|
+
const unorderedString = getUnorderedString();
|
|
241
|
+
if (unorderedString !== undefined) return fallBack(unorderedString);
|
|
241
242
|
statistics.depth = statistics.generatedStates === 0 ? 0 : 1;
|
|
242
243
|
statistics.initialStates = {
|
|
243
244
|
generated: statistics.generatedStates,
|
|
@@ -21,36 +21,40 @@ export const checkSmt = (text: string, options: DecideOptions): SmtCheck => {
|
|
|
21
21
|
const manager = new AstManager(
|
|
22
22
|
new ResourceLimit(Date.now() + options.timeLimitMs, options.signal),
|
|
23
23
|
);
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
// The limit stops watching the collector however the check ends, as an unsupported input or a
|
|
25
|
+
// problem without check-sat ends it early.
|
|
26
|
+
try {
|
|
27
|
+
// combined_solver gives each assertion to the incremental smt kernel as well, which rewrites it
|
|
28
|
+
// when it is asserted and keeps it, though check-sat then runs the tactic on the assertions. The
|
|
29
|
+
// kernel's model finder counts a step of the resource limit when it is made, and
|
|
30
|
+
// solver::assert_expr counts one for each assertion.
|
|
31
|
+
const incremental = new AssertedFormulas(manager);
|
|
31
32
|
manager.limit.inc();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const problem = parseSmtlib(text, manager, (assertion) => {
|
|
34
|
+
manager.limit.inc();
|
|
35
|
+
incremental.assertExpr(assertion);
|
|
36
|
+
});
|
|
37
|
+
if (!problem.hasCheckSat) return { verdict: "unknown", numInstances: 0 };
|
|
38
|
+
const goal = applyUfniaTactic(manager, problem.assertions);
|
|
39
|
+
// and_then runs smt_tactic only on a goal that the preprocessing left undecided.
|
|
40
|
+
if (goal.isInconsistent || goal.forms.size === 0) {
|
|
41
|
+
return { verdict: goal.isInconsistent ? "unsat" : "sat", numInstances: 0 };
|
|
42
|
+
}
|
|
43
|
+
// smt_tactic makes the context, which makes its asserted formulas first, and asserts the goal.
|
|
44
|
+
// setup_context then makes the theories, before the formulas are reduced.
|
|
45
|
+
const asserted = new AssertedFormulas(manager);
|
|
46
|
+
const context = new Context(manager, { isMbqi: true, relevancyLevel: 2 });
|
|
47
|
+
for (const assertion of goal.forms.items) asserted.assertExpr(assertion);
|
|
48
|
+
context.setupContext();
|
|
49
|
+
context.internalizeAssertions(asserted);
|
|
50
|
+
const result = context.search();
|
|
51
|
+
return {
|
|
52
|
+
verdict: result === L_FALSE ? "unsat" : result === L_TRUE ? "sat" : "unknown",
|
|
53
|
+
numInstances: context.qmanager.getNumInstances(),
|
|
54
|
+
};
|
|
55
|
+
} finally {
|
|
38
56
|
manager.limit.release();
|
|
39
|
-
return { verdict: goal.isInconsistent ? "unsat" : "sat", numInstances: 0 };
|
|
40
57
|
}
|
|
41
|
-
// smt_tactic makes the context, which makes its asserted formulas first, and asserts the goal.
|
|
42
|
-
// setup_context then makes the theories, before the formulas are reduced.
|
|
43
|
-
const asserted = new AssertedFormulas(manager);
|
|
44
|
-
const context = new Context(manager, { isMbqi: true, relevancyLevel: 2 });
|
|
45
|
-
for (const assertion of goal.forms.items) asserted.assertExpr(assertion);
|
|
46
|
-
context.setupContext();
|
|
47
|
-
context.internalizeAssertions(asserted);
|
|
48
|
-
const result = context.search();
|
|
49
|
-
manager.limit.release();
|
|
50
|
-
return {
|
|
51
|
-
verdict: result === L_FALSE ? "unsat" : result === L_TRUE ? "sat" : "unknown",
|
|
52
|
-
numInstances: context.qmanager.getNumInstances(),
|
|
53
|
-
};
|
|
54
58
|
};
|
|
55
59
|
|
|
56
60
|
// Throws SmtParseError on malformed input. Input outside the subset the solver supports is unknown,
|