tla-ts 0.0.3-dev.6979965 → 0.0.3-dev.6a30eee
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 +11 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +3 -2
- package/dist/run-cli.js +3 -2
- package/dist/transfer.cjs +19 -15
- package/dist/transfer.js +19 -15
- package/package.json +1 -1
- package/src/check.ts +70 -28
- package/src/errors.ts +5 -0
- package/src/evaluate.ts +41 -12
- package/src/exit-codes.ts +20 -30
- package/src/lexer.ts +5 -1
- package/src/live-check.ts +710 -0
- package/src/liveness.ts +4 -521
- package/src/parallel-worker.ts +100 -113
- package/src/parallel.ts +29 -21
- package/src/parser.ts +12 -1
- package/src/run-cli.ts +9 -2
- package/src/runtime.ts +1 -1
- package/src/successors.ts +10 -6
- package/src/symmetry.ts +14 -2
- package/src/tlc-order.ts +17 -3
- package/src/values.ts +7 -4
package/README.md
CHANGED
|
@@ -131,8 +131,9 @@ Workers run in Node, Bun, Deno, and cross-origin isolated pages in the browser.
|
|
|
131
131
|
- `SharedArrayBuffer` is unavailable, as on a page without cross-origin isolation.
|
|
132
132
|
- The spec has liveness properties.
|
|
133
133
|
- The spec uses impure operators such as `Print`.
|
|
134
|
+
- The configuration has `VIEW`, `POSTCONDITION`, or `_POSSIBLE`.
|
|
134
135
|
|
|
135
|
-
After a violation, `check` reruns on the calling thread to return
|
|
136
|
+
After a violation or an error, `check` reruns on the calling thread to return TLC's exact trace.
|
|
136
137
|
|
|
137
138
|
`check` supports:
|
|
138
139
|
|
|
@@ -196,6 +197,15 @@ Wall time on one worker, including JVM and Node startup. Both checkers report th
|
|
|
196
197
|
| [Bounded queue](packages/tla-ts/benchmarks/queue) | 44,044 | 0.37 s | 0.17 s | 2.2× |
|
|
197
198
|
| 542 conformance models | | 986.6 s | 403.3 s | 2.4× |
|
|
198
199
|
|
|
200
|
+
Wall time on 8 workers, also including startup. Each time is the median of 3 runs on an Apple M4 Pro.
|
|
201
|
+
|
|
202
|
+
| Spec | Distinct states | TLC | tla-ts | Speedup |
|
|
203
|
+
| --------------------------------------------------------------------------------------------------------------------- | --------------: | ------: | -----: | ------: |
|
|
204
|
+
| [Raft with reconfiguration](https://github.com/will62794/tla-web/blob/8193eb0/specs/RaftWithReconfigSingleServer.tla) | 298,493 | 10.50 s | 8.96 s | 1.2× |
|
|
205
|
+
| [Sailfish](https://github.com/tlaplus/Examples/tree/0cab2b3/specifications/dag-consensus) | 109,604 | 4.34 s | 4.07 s | 1.1× |
|
|
206
|
+
| [Fast Paxos](https://github.com/tlaplus/Examples/tree/0cab2b3/specifications/SimplifiedFastPaxos) | 25,617 | 3.91 s | 2.57 s | 1.5× |
|
|
207
|
+
| [Buffered random access file](https://github.com/tlaplus/Examples/tree/0cab2b3/specifications/braf) | 3,316 | 4.70 s | 3.61 s | 1.3× |
|
|
208
|
+
|
|
199
209
|
## Development
|
|
200
210
|
|
|
201
211
|
```shell
|
package/dist/index.d.cts
CHANGED
|
@@ -520,6 +520,7 @@ interface ModelValue {
|
|
|
520
520
|
kind: "ModelValue";
|
|
521
521
|
name: string;
|
|
522
522
|
type: string | undefined;
|
|
523
|
+
rank: number;
|
|
523
524
|
}
|
|
524
525
|
interface SetValue {
|
|
525
526
|
kind: "Set";
|
|
@@ -622,6 +623,7 @@ interface TraceStep {
|
|
|
622
623
|
}
|
|
623
624
|
interface Violation {
|
|
624
625
|
name: string;
|
|
626
|
+
properties?: string[];
|
|
625
627
|
trace: TraceStep[];
|
|
626
628
|
loopStart: number | undefined;
|
|
627
629
|
loopLabel?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -520,6 +520,7 @@ interface ModelValue {
|
|
|
520
520
|
kind: "ModelValue";
|
|
521
521
|
name: string;
|
|
522
522
|
type: string | undefined;
|
|
523
|
+
rank: number;
|
|
523
524
|
}
|
|
524
525
|
interface SetValue {
|
|
525
526
|
kind: "Set";
|
|
@@ -622,6 +623,7 @@ interface TraceStep {
|
|
|
622
623
|
}
|
|
623
624
|
interface Violation {
|
|
624
625
|
name: string;
|
|
626
|
+
properties?: string[];
|
|
625
627
|
trace: TraceStep[];
|
|
626
628
|
loopStart: number | undefined;
|
|
627
629
|
loopLabel?: string;
|
package/dist/parallel-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=require("./transfer.cjs"),t=
|
|
9
|
+
const e=require("./transfer.cjs"),t=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
10
10
|
/* @vite-ignore */
|
|
11
11
|
/* webpackIgnore: true */
|
|
12
|
-
`node:worker_threads`)).parentPort,
|
|
12
|
+
`node:worker_threads`)).parentPort,n=(t,n)=>{let r=new Map(t.modules),i=e=>r.get(e),a=new Map(t.classes);e.O(e._(t.source,t.config,i));let o=e.D(),s=e.y(t.config,{source:t.source,loadModule:i,loadClass:e=>a.get(e),print:()=>{},files:{readFile:void 0,writeFile:void 0}}).environment,c=e.u(t.config,s,()=>e.v(t.source,i)),l=c?.spec.next;if(!c||l===void 0)return n.postMessage({type:`abort`});let u=t.index,d=e.T(),f=e.t(s.variables.length),p={fingerprints:t.fingerprints},m=t.requests,h=t.remaining,g=c.isSymmetric?e.r():void 0,_=/* @__PURE__ */ new Int32Array(2),v={resume:()=>{},loot:e=>{}};t.ports.forEach(e=>{e?.addEventListener(`message`,e=>v.loot(e.data)),e?.start?.()});let y={states:f(t.seed).map(d)},b=(n,r)=>{let i=Atomics.load(m,u)-1,a=Math.floor((n.end-n.origin-1)/2),o=e.n(),s=n.states.slice(n.end-a,n.end),c=a>0&&s.every(o.encode);c&&(n.end-=a);let l=c?o.finish():e.n().finish();t.ports[i]?.postMessage(l,[l.words.buffer]),Atomics.store(m,u,r),Atomics.notify(m,u)},x=e=>{Atomics.store(h,u,0),Atomics.compareExchange(m,u,0,-1)!==0&&b(e,-1)},S=e=>{Atomics.store(h,u,e.end-e.origin),Atomics.store(m,u,0)},C=n=>{for(;n.origin<n.end;n.origin++){let r=n.states[n.origin];if(!n.successors&&(Atomics.load(m,u)>0&&b(n,0),Atomics.store(h,u,n.end-n.origin-1),n.successors=e.w(l,r,s,c.spec.scope),n.generated+=n.successors.length,n.successors.length===0&&t.config.checkDeadlock))return;let i=n.successors;for(;n.index<i.length;n.index++){if(e.s(p.fingerprints))return`paused`;let t=i[n.index];if(c.findViolatedActionProperty(r,t.state))return;if(!c.satisfiesActionConstraints(r,t.state)){if(c.findViolatedInvariant(t.state,r))return;continue}if(g&&(e.c(t.state,_),!g.insert(_[0],_[1])))continue;d(t.state);let a=c.getFingerprintState(t.state);if(e.c(a,_),e.o(p.fingerprints,_[0],_[1])){if(c.findViolatedInvariant(t.state,r))return;c.satisfiesConstraints(t.state,r)&&(n.next.push(t.state),n.fingerprintStates.push(a),n.added++)}}n.outDegrees[Math.min(n.added,31)]++,n.successors=void 0,n.index=0,n.added=0}return`done`},w=async e=>{let n=/* @__PURE__ */ new Set;for(;;){let r=t.ports.reduce((e,t,r)=>!t||n.has(r)||Atomics.load(h,r)<2?e:e===void 0||Atomics.load(h,r)>Atomics.load(h,e)?r:e,void 0);if(r===void 0)return!1;let i=Atomics.compareExchange(m,r,0,u+1);if(i===-1&&n.add(r),i>0&&Atomics.wait(m,r,i),i!==0)continue;let a=await new Promise(e=>v.loot=e);if(a.count===0)n.add(r);else return e.states=f(a).map(d),e.origin=0,e.end=e.states.length,S(e),!0}},T=e=>n.postMessage(e,e.type===`level`?[e.fingerprints.buffer]:[]),E=async t=>{let n={states:y.states,origin:0,end:y.states.length,successors:void 0,index:0,added:0,generated:0,outDegrees:Array.from({length:32},()=>0),next:[],fingerprintStates:[]};for(;;){let e=C(n);if(e===void 0)return;if(x(n),e===`paused`){let e=new Promise(e=>v.resume=e);T({type:`paused`}),await e,S(n)}else if(!await w(n))break}if(e.D()===o)return y.states=n.next,Atomics.store(h,u,y.states.length),{type:`level`,level:t,generated:n.generated,added:n.next.length,outDegrees:n.outDegrees,fingerprints:c.getStoredFingerprints(n.next,n.fingerprintStates)}},D=e=>{E(e).then(e=>T(e??{type:`abort`}),()=>T({type:`abort`}))};n.addEventListener(`message`,e=>{let t=e.data;t.type===`level`&&D(t.level),t.type===`resize`&&(p.fingerprints=t.fingerprints,v.resume())}),Atomics.store(h,u,y.states.length),T({type:`ready`})};t().then(e=>{let t=r=>{let i=r.data;if(i.type===`start`){e.removeEventListener?.(`message`,t);try{n(i,e)}catch{e.postMessage({type:`abort`})}}};e.addEventListener(`message`,t),e.start?.()});
|
package/dist/parallel-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
|
-
import{D as e,O as t,T as n,_ as r,c as i,n as a,o,r as s,s as c,t as l,u,v as d,w as f,y as p}from"./transfer.js";const m=
|
|
9
|
+
import{D as e,O as t,T as n,_ as r,c as i,n as a,o,r as s,s as c,t as l,u,v as d,w as f,y as p}from"./transfer.js";const m=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
10
10
|
/* @vite-ignore */
|
|
11
11
|
/* webpackIgnore: true */
|
|
12
|
-
`node:worker_threads`)).parentPort,
|
|
12
|
+
`node:worker_threads`)).parentPort,h=(m,h)=>{let g=new Map(m.modules),_=e=>g.get(e),v=new Map(m.classes);t(r(m.source,m.config,_));let y=e(),b=p(m.config,{source:m.source,loadModule:_,loadClass:e=>v.get(e),print:()=>{},files:{readFile:void 0,writeFile:void 0}}).environment,x=u(m.config,b,()=>d(m.source,_)),S=x?.spec.next;if(!x||S===void 0)return h.postMessage({type:`abort`});let C=m.index,w=n(),T=l(b.variables.length),E={fingerprints:m.fingerprints},D=m.requests,O=m.remaining,k=x.isSymmetric?s():void 0,A=/* @__PURE__ */ new Int32Array(2),j={resume:()=>{},loot:e=>{}};m.ports.forEach(e=>{e?.addEventListener(`message`,e=>j.loot(e.data)),e?.start?.()});let M={states:T(m.seed).map(w)},N=(e,t)=>{let n=Atomics.load(D,C)-1,r=Math.floor((e.end-e.origin-1)/2),i=a(),o=e.states.slice(e.end-r,e.end),s=r>0&&o.every(i.encode);s&&(e.end-=r);let c=s?i.finish():a().finish();m.ports[n]?.postMessage(c,[c.words.buffer]),Atomics.store(D,C,t),Atomics.notify(D,C)},P=e=>{Atomics.store(O,C,0),Atomics.compareExchange(D,C,0,-1)!==0&&N(e,-1)},F=e=>{Atomics.store(O,C,e.end-e.origin),Atomics.store(D,C,0)},I=e=>{for(;e.origin<e.end;e.origin++){let t=e.states[e.origin];if(!e.successors&&(Atomics.load(D,C)>0&&N(e,0),Atomics.store(O,C,e.end-e.origin-1),e.successors=f(S,t,b,x.spec.scope),e.generated+=e.successors.length,e.successors.length===0&&m.config.checkDeadlock))return;let n=e.successors;for(;e.index<n.length;e.index++){if(c(E.fingerprints))return`paused`;let r=n[e.index];if(x.findViolatedActionProperty(t,r.state))return;if(!x.satisfiesActionConstraints(t,r.state)){if(x.findViolatedInvariant(r.state,t))return;continue}if(k&&(i(r.state,A),!k.insert(A[0],A[1])))continue;w(r.state);let a=x.getFingerprintState(r.state);if(i(a,A),o(E.fingerprints,A[0],A[1])){if(x.findViolatedInvariant(r.state,t))return;x.satisfiesConstraints(r.state,t)&&(e.next.push(r.state),e.fingerprintStates.push(a),e.added++)}}e.outDegrees[Math.min(e.added,31)]++,e.successors=void 0,e.index=0,e.added=0}return`done`},L=async e=>{let t=/* @__PURE__ */ new Set;for(;;){let n=m.ports.reduce((e,n,r)=>!n||t.has(r)||Atomics.load(O,r)<2?e:e===void 0||Atomics.load(O,r)>Atomics.load(O,e)?r:e,void 0);if(n===void 0)return!1;let r=Atomics.compareExchange(D,n,0,C+1);if(r===-1&&t.add(n),r>0&&Atomics.wait(D,n,r),r!==0)continue;let i=await new Promise(e=>j.loot=e);if(i.count===0)t.add(n);else return e.states=T(i).map(w),e.origin=0,e.end=e.states.length,F(e),!0}},R=e=>h.postMessage(e,e.type===`level`?[e.fingerprints.buffer]:[]),z=async t=>{let n={states:M.states,origin:0,end:M.states.length,successors:void 0,index:0,added:0,generated:0,outDegrees:Array.from({length:32},()=>0),next:[],fingerprintStates:[]};for(;;){let e=I(n);if(e===void 0)return;if(P(n),e===`paused`){let e=new Promise(e=>j.resume=e);R({type:`paused`}),await e,F(n)}else if(!await L(n))break}if(e()===y)return M.states=n.next,Atomics.store(O,C,M.states.length),{type:`level`,level:t,generated:n.generated,added:n.next.length,outDegrees:n.outDegrees,fingerprints:x.getStoredFingerprints(n.next,n.fingerprintStates)}},B=e=>{z(e).then(e=>R(e??{type:`abort`}),()=>R({type:`abort`}))};h.addEventListener(`message`,e=>{let t=e.data;t.type===`level`&&B(t.level),t.type===`resize`&&(E.fingerprints=t.fingerprints,j.resume())}),Atomics.store(O,C,M.states.length),R({type:`ready`})};m().then(e=>{let t=n=>{let r=n.data;if(r.type===`start`){e.removeEventListener?.(`message`,t);try{h(r,e)}catch{e.postMessage({type:`abort`})}}};e.addEventListener(`message`,t),e.start?.()});
|
package/dist/parallel.cjs
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
const e=require("./transfer.cjs"),t=async e=>{if(typeof Worker==`function`){let t=new Worker(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href),{type:`module`});return t.addEventListener(`message`,t=>e(t.data)),t.addEventListener(`error`,()=>e({type:`abort`})),t}let t=new(await(import(
|
|
10
10
|
/* @vite-ignore */
|
|
11
11
|
/* webpackIgnore: true */
|
|
12
|
-
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},n=async n=>{let r=typeof n.config==`string`?e.A(n.config):n.config,i=()=>e.l({...n,config:r}),
|
|
12
|
+
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,require("url").pathToFileURL(__filename).href));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},n=async n=>{let r=typeof n.config==`string`?e.A(n.config):n.config,i=n.onPrint??console.log,a={count:0},o=()=>{let t={count:a.count};return e.l({...n,config:r,onPrint:e=>t.count-->0?void 0:i(e)})},s=n.workers??1;if(s<2||typeof SharedArrayBuffer!=`function`||r.view!==void 0||r.postconditions.length>0||r.possible.length>0)return o();let c=/* @__PURE__ */ new Map,l=e=>{let t=n.loadModule?.(e);return c.set(e,t),t},u=/* @__PURE__ */ new Map,d=e=>{let t=n.loadClass?.(e);return u.set(e,t),t};e.O(e._(n.source,r,l));let f=e.D(),p=e.y(r,{source:n.source,loadModule:l,loadClass:d,print:e=>{a.count++,i(e)},files:{readFile:n.readFile,writeFile:n.writeFile}}),m=p.environment,h=e.u(r,m,()=>e.v(n.source,l));if(e.d(p.assumptions,m)||!h||h.spec.init===void 0||h.spec.next===void 0||h.properties.liveness.length>0||e.S(m))return o();let g=e.T(),_={fingerprints:e.i()},v=/* @__PURE__ */ new Int32Array(2),y=Array.from({length:s},e.n),b={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,outDegrees:Array.from({length:32},()=>0)},x=[],S=()=>({status:`success`,violation:void 0,failure:void 0,...b,fingerprintDistance:e.m(b.distinctStates,b.generatedStates,()=>{let e=new BigInt64Array(b.distinctStates);return x.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),C=t=>{let n=[];for(let r of e.C(t,m,h.spec.scope))if(g(r),b.generatedStates++,e.c(h.getFingerprintState(r),v),e.s(_.fingerprints)&&(_.fingerprints=e.a(_.fingerprints)),e.o(_.fingerprints,v[0],v[1])){if(h.findViolatedInvariant(r)||h.findFailedInitialPredicate(r))return!1;if(h.satisfiesConstraints(r)){if(!y[n.length%s].encode(r))return!1;n.push(r),b.distinctStates++}}return x.push(BigInt64Array.from(n,e=>m.runtime.getFingerprint(e))),!0};try{if(!C(h.spec.init))return o()}catch(t){if(!(t instanceof e.P))throw t;return o()}if(e.D()!==f)return o();if(b.depth=b.generatedStates===0?0:1,b.distinctStates===0)return S();let w=[],T={count:s,resolve:e=>{}},E=e=>{w.push(e),(e.type===`abort`||w.length===T.count)&&T.resolve(w.splice(0))},D=e=>new Promise(t=>{T.count=e,T.resolve=t}),O=D(s),k=new Int32Array(new SharedArrayBuffer(s*4)),A=new Int32Array(new SharedArrayBuffer(s*4)),j=await Promise.all(Array.from({length:s},()=>t(E))),M=()=>j.forEach(e=>e.terminate()),N=/* @__PURE__ */ new Map,P=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=N.get(n)??new MessageChannel;return N.set(n,r),e<t?r.port1:r.port2};j.forEach((e,t)=>{let i=Array.from({length:s},(e,n)=>n===t?void 0:P(t,n)),a=y[t].finish(),o={type:`start`,source:n.source,config:r,modules:[...c],classes:[...u],index:t,ports:i,seed:a,fingerprints:_.fingerprints,requests:k,remaining:A};e.postMessage(o,[...i.filter(e=>e!==void 0),a.words.buffer])});let F=e=>e.some(e=>e.type===`abort`),I=e=>j.forEach(t=>t.postMessage(e)),L=async t=>{let n=t.filter(e=>e.type===`paused`).length;if(n===0||F(t))return t;_.fingerprints=e.a(_.fingerprints);let r=D(n);return I({type:`resize`,fingerprints:_.fingerprints}),[...t.filter(e=>e.type!==`paused`),...await L(await r)]};if(F(await O))return M(),o();for(let e=1;;e++){let t=D(s);k.forEach((e,t)=>Atomics.store(k,t,0)),I({type:`level`,level:e});let n=await L(await t);if(F(n))return M(),o();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(b.generatedStates+=r.reduce((e,t)=>e+t.generated,0),b.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>b.outDegrees[t]+=e),x.push(e.fingerprints)}),i===0)return M(),S();b.depth++}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
|
package/dist/parallel.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
|
-
import{A as e,C as t,D as n,O as r,P as i,S as a,T as o,_ as s,a as c,c as l,d as
|
|
9
|
+
import{A as e,C as t,D as n,O as r,P as i,S as a,T as o,_ as s,a as c,c as l,d as ee,i as te,l as u,m as d,n as f,o as ne,s as p,u as m,v as h,y as g}from"./transfer.js";const _=async e=>{if(typeof Worker==`function`){let t=new Worker(new URL(`./parallel-worker.js`,import.meta.url),{type:`module`});return t.addEventListener(`message`,t=>e(t.data)),t.addEventListener(`error`,()=>e({type:`abort`})),t}let t=new(await(import(
|
|
10
10
|
/* @vite-ignore */
|
|
11
11
|
/* webpackIgnore: true */
|
|
12
|
-
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,import.meta.url));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},
|
|
12
|
+
`node:worker_threads`))).Worker(new URL(`./parallel-worker.js`,import.meta.url));return t.on(`message`,e),t.on(`error`,()=>e({type:`abort`})),{postMessage:(e,n)=>t.postMessage(e,n),terminate:()=>void t.terminate()}},v=async v=>{let y=typeof v.config==`string`?e(v.config):v.config,b=v.onPrint??console.log,x={count:0},S=()=>{let e={count:x.count};return u({...v,config:y,onPrint:t=>e.count-->0?void 0:b(t)})},C=v.workers??1;if(C<2||typeof SharedArrayBuffer!=`function`||y.view!==void 0||y.postconditions.length>0||y.possible.length>0)return S();let w=/* @__PURE__ */ new Map,T=e=>{let t=v.loadModule?.(e);return w.set(e,t),t},E=/* @__PURE__ */ new Map,D=e=>{let t=v.loadClass?.(e);return E.set(e,t),t};r(s(v.source,y,T));let O=n(),k=g(y,{source:v.source,loadModule:T,loadClass:D,print:e=>{x.count++,b(e)},files:{readFile:v.readFile,writeFile:v.writeFile}}),A=k.environment,j=m(y,A,()=>h(v.source,T));if(ee(k.assumptions,A)||!j||j.spec.init===void 0||j.spec.next===void 0||j.properties.liveness.length>0||a(A))return S();let M=o(),N={fingerprints:te()},P=/* @__PURE__ */ new Int32Array(2),F=Array.from({length:C},f),I={generatedStates:0,distinctStates:0,queuedStates:0,depth:0,outDegrees:Array.from({length:32},()=>0)},L=[],R=()=>({status:`success`,violation:void 0,failure:void 0,...I,fingerprintDistance:d(I.distinctStates,I.generatedStates,()=>{let e=new BigInt64Array(I.distinctStates);return L.reduce((t,n)=>(e.set(n,t),t+n.length),0),e})}),z=e=>{let n=[];for(let r of t(e,A,j.spec.scope))if(M(r),I.generatedStates++,l(j.getFingerprintState(r),P),p(N.fingerprints)&&(N.fingerprints=c(N.fingerprints)),ne(N.fingerprints,P[0],P[1])){if(j.findViolatedInvariant(r)||j.findFailedInitialPredicate(r))return!1;if(j.satisfiesConstraints(r)){if(!F[n.length%C].encode(r))return!1;n.push(r),I.distinctStates++}}return L.push(BigInt64Array.from(n,e=>A.runtime.getFingerprint(e))),!0};try{if(!z(j.spec.init))return S()}catch(e){if(!(e instanceof i))throw e;return S()}if(n()!==O)return S();if(I.depth=I.generatedStates===0?0:1,I.distinctStates===0)return R();let B=[],V={count:C,resolve:e=>{}},H=e=>{B.push(e),(e.type===`abort`||B.length===V.count)&&V.resolve(B.splice(0))},U=e=>new Promise(t=>{V.count=e,V.resolve=t}),W=U(C),G=new Int32Array(new SharedArrayBuffer(C*4)),K=new Int32Array(new SharedArrayBuffer(C*4)),q=await Promise.all(Array.from({length:C},()=>_(H))),J=()=>q.forEach(e=>e.terminate()),Y=/* @__PURE__ */ new Map,X=(e,t)=>{let n=e<t?`${e}:${t}`:`${t}:${e}`,r=Y.get(n)??new MessageChannel;return Y.set(n,r),e<t?r.port1:r.port2};q.forEach((e,t)=>{let n=Array.from({length:C},(e,n)=>n===t?void 0:X(t,n)),r=F[t].finish(),i={type:`start`,source:v.source,config:y,modules:[...w],classes:[...E],index:t,ports:n,seed:r,fingerprints:N.fingerprints,requests:G,remaining:K};e.postMessage(i,[...n.filter(e=>e!==void 0),r.words.buffer])});let Z=e=>e.some(e=>e.type===`abort`),Q=e=>q.forEach(t=>t.postMessage(e)),$=async e=>{let t=e.filter(e=>e.type===`paused`).length;if(t===0||Z(e))return e;N.fingerprints=c(N.fingerprints);let n=U(t);return Q({type:`resize`,fingerprints:N.fingerprints}),[...e.filter(e=>e.type!==`paused`),...await $(await n)]};if(Z(await W))return J(),S();for(let e=1;;e++){let t=U(C);G.forEach((e,t)=>Atomics.store(G,t,0)),Q({type:`level`,level:e});let n=await $(await t);if(Z(n))return J(),S();let r=n.flatMap(e=>e.type===`level`?[e]:[]),i=r.reduce((e,t)=>e+t.added,0);if(I.generatedStates+=r.reduce((e,t)=>e+t.generated,0),I.distinctStates+=i,r.forEach(e=>{e.outDegrees.forEach((e,t)=>I.outDegrees[t]+=e),L.push(e.fingerprints)}),i===0)return J(),R();I.depth++}};export{v as t};
|
package/dist/run-cli.cjs
CHANGED
|
@@ -24,5 +24,6 @@ PROVE %a@]`,i)]};return{printSequent:p,printExpr:r}},Mt=(e,t)=>jt(e).printExpr(
|
|
|
24
24
|
`,o-1),l=n.findLast(e=>e.kind!==`End`&&(e.line<s||e.line===s&&e.column<c));return{offset:o,line:s,column:c,end:{reason:Lr,line:l?.line??s,column:l?l.endColumn+1:c,isEnd:!0}}},Br=t=>{try{return t()}catch(t){if(!(t instanceof e.I)||!t.failure)throw t;return t.failure}},Vr=e=>typeof e==`object`&&!!e&&`reason`in e,Hr=t=>{let n=Br(()=>zr(t));if(Vr(n))return[n];let r=Br(()=>e.x(n?t.slice(0,n.offset):t));return n&&(!Vr(r)||r.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:n.line,column:n.column,isEnd:!1},Vr(r)&&r.reason===Lr?r:n.end]:Vr(r)?[r]:r},Ur=(t,n,r,i,a)=>{if(!Ir.test(t.source))throw new e.F(`No tokens in file`);let o=Hr(t.source);if(Array.isArray(o)){o.forEach(e=>{let n=`File ${JSON.stringify(t.file)}, line ${e.line}, character ${e.column}\n${e.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`})});let n=`Could not parse ${JSON.stringify(t.file)} successfully.`;throw i({text:`${a}Error: ${n}`,channel:`stderr`}),new e.F(n,{failure:`Module.Parser.parse_file`})}let s=Pr(t.file,t.source,n,r).convertModule(o),c=t.file.slice(t.file.lastIndexOf(`/`)+1),l=c.replace(/\.tla$/,``);return s.name===l?s:(i({text:`${f(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},Wr=t=>{let n=new Map([...t].map(([e,t])=>[e,Hn(t).dependencies])),r=/* @__PURE__ */ new Set,i=[],a=o=>{if(r.has(o))return;r.add(o);let s=t.get(o);if(!s)throw new e.F(`Module "${o}" not found`);(n.get(o)??[]).forEach(a),i.push(s)};return[...t.keys()].sort(Wn).forEach(a),i},Gr=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${c(t)}`)],Kr=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?c({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...Gr(`missing`,e.absent,t),...Gr(`omitted`,e.omitted,n),` ====`]},qr=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...Kr(t,e.missing,e.omitted)],missing:e.missing+t.absent.length,omitted:e.omitted+t.omitted.length},{lines:[],missing:0,omitted:0});return[`---- summary of module ${JSON.stringify(e.name)} ----`,` obligations_count = ${t.total}`,...t.absent.length>0?[` missing_proofs_count = ${t.absent.length}`]:[],...t.omitted.length>0?[` omitted_proofs_count = ${t.omitted.length}`]:[],...n.lines,`====`].join(`
|
|
25
25
|
`)},Jr=(t,n,r={})=>{let i=r.lines??Fr,a=r.onWarning??(()=>{}),o={value:0},s=new Map(In);t.forEach(e=>{let t={...Ur(e,o,!0,a,`File "<unknown>":
|
|
26
26
|
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>Wn(e.name,t.name)),l=/* @__PURE__ */ new Map,f=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let t=Hn(c[e]);t.submodules.forEach((e,t)=>{f.add(t),s.has(t)||s.set(t,e)});for(let e of t.dependencies){if(s.has(e)&&!In.has(e))continue;let r=n(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,t.locations.get(e));continue}let i=Ur(r,o,!1,a,u(t.locations.get(e)));s.set(e,i),c.push(i)}}let p=[...l.keys()].filter(e=>!f.has(e)).sort(Wn);if(p.forEach(e=>a(d(l.get(e),`Unknown module ${JSON.stringify(e)}`))),p.length>0)throw new e.F(`Unknown module ${JSON.stringify(p[0])}`,{failure:`Module.Parser.load_module`});let m={anonymizer:ze(o,(e,t)=>ar(m,e,t),a),generator:rn(o,new Set(t.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},h=Wr(s).map(e=>e.isStandard?e:Vn(s,e,/* @__PURE__ */ new Set)),g=new Map(h.map(e=>[e.name,e]));return h.flatMap(e=>{if(e.isStandard)return[];let t=or(m,g,void 0,e);if(!e.isImportant)return[];let n=sr(m,[],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${Nt(e.sequent)}\n`;return[{id:t+1,location:Rr(n),text:r}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Yr={success:e.B.success,"assumption-violation":e.B.assumptionViolation,deadlock:e.B.deadlock,"invariant-violation":e.B.safetyViolation,"property-violation":e.B.safetyViolation,"liveness-violation":e.B.livenessViolation,"postcondition-violation":e.B.assumptionViolation,error:e.B.error},Xr=s(`tla-ts <Spec.tla|Spec.cfg|glob>... {options}`,[{flag:`-config <Spec.cfg>`},{flag:`-deadlock`},{flag:`-lncheck <final|default>`},{flag:`-seed <num>`},{flag:`-workers <count|auto>`}]),Zr=s(`tla-ts prove {options} <Module.tla|glob>...`,[{flag:`-N`,isRequired:!0},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--summary`},{flag:`--strict`},{flag:`-I <directory>`,isRepeatable:!0}]),Qr=[`Usage: ${Xr.usage}`,` ${Zr.usage}`,` tla-ts prove [<tlapm option>]... <Module.tla|glob>...`].join(`
|
|
27
|
-
`),$r=/[*?[{]/,ei=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),ti=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ni=e=>e?e[0]===`auto`?(0,a.availableParallelism)():Math.max(1,Number.parseInt(e[0],10)||1):1,ri=t=>{let n=Object.entries(t);n.forEach(([t,r])=>console.log(`${n.length===1?``:`/\\ `}${t} = ${e.k(e.E(r))}`)),console.log(``)},ii=(e,t=`Error: The behavior up to this point is:`)=>{e.length>0&&console.log(t),e.forEach((e,t)=>{console.log(`State ${t+1}: <${e.label??e.action??`Initial predicate`}>`),ri(e.state)})},ai=t=>{if(t.failure)console.log(`Error: ${t.failure.message}`),t.failure.initialState&&(console.log(`While working on the initial state:`),ri(t.failure.initialState)),ii(t.failure.trace);else if(t.violation){let e=t.violation,n=e.name,r=e.loopStart,i=r===void 0&&e.trace.length===1&&(t.status===`invariant-violation`||t.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":e.message?`Error: Evaluating assumption ${n} failed.\n${e.message}`:`Error: Assumption ${n} is false.`,deadlock:`Error: Deadlock reached.`,"invariant-violation":i?`Error: Invariant ${n} is violated by the initial state:`:`Error: Invariant ${n} is violated.`,"property-violation"
|
|
28
|
-
`);
|
|
27
|
+
`),$r=/[*?[{]/,ei=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),ti=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ni=e=>e?e[0]===`auto`?(0,a.availableParallelism)():Math.max(1,Number.parseInt(e[0],10)||1):1,ri=t=>{let n=Object.entries(t);n.forEach(([t,r])=>console.log(`${n.length===1?``:`/\\ `}${t} = ${e.k(e.E(r))}`)),console.log(``)},ii=(e,t=`Error: The behavior up to this point is:`)=>{e.length>0&&console.log(t),e.forEach((e,t)=>{console.log(`State ${t+1}: <${e.label??e.action??`Initial predicate`}>`),ri(e.state)})},ai=e=>e.length===1?`Error: Temporal property ${e[0]} was violated.\n`:`Error: Temporal properties ${e.slice(0,-1).join(`, `)}${e.length>2?`,`:``} and ${e[e.length-1]} were violated.\n`,oi=t=>{if(t.failure)console.log(`Error: ${t.failure.message}`),t.failure.initialState&&(console.log(`While working on the initial state:`),ri(t.failure.initialState)),ii(t.failure.trace);else if(t.violation){let e=t.violation,n=e.name,r=e.loopStart,i=r===void 0&&e.trace.length===1&&(t.status===`invariant-violation`||t.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":e.message?`Error: Evaluating assumption ${n} failed.\n${e.message}`:`Error: Assumption ${n} is false.`,deadlock:`Error: Deadlock reached.`,"invariant-violation":i?`Error: Invariant ${n} is violated by the initial state:`:`Error: Invariant ${n} is violated.`,"property-violation":ai(e.properties??[n]),"liveness-violation":r===void 0?i?`Error: Property ${n} is violated by the initial state:`:`Error: Action property ${n} is violated.`:ai(e.properties??[n]),"postcondition-violation":`Error: ${e.message??`Postcondition ${n} is false.`}`}[t.status];if(e.counts&&console.log(e.counts),console.log(a),i)ri(e.trace[0].state);else if(t.status===`property-violation`)ii(e.trace,`Error: The following behavior constitutes a counter-example:
|
|
28
|
+
`);else if(r===void 0)ii(e.trace);else{ii(e.trace,`Error: The following behavior constitutes a counter-example:
|
|
29
|
+
`);let t=r===e.trace.length-1;console.log(t?`State ${r+2}: Stuttering`:`Back to state ${r+1}${e.loopLabel?`: <${e.loopLabel}>\n`:``}`)}let o=e.unwitnessed;if(o?.counts&&console.log(o.counts),o&&console.log(`Error: ${o.message}`),i||t.status===`assumption-violation`)return}else{let n=e.h(t.distinctStates,t.generatedStates);if(console.log(`Model checking completed. No error has been found.`),console.log(` Estimates of the probability that TLC did not check all reachable states`),console.log(` because two distinct states had the same fingerprint:`),console.log(` calculated (optimistic): val = ${e.f(n)}`),t.fingerprintDistance!==void 0){let n=e.p(t.fingerprintDistance);console.log(` based on the actual fingerprints: val = ${e.f(n)}`)}}console.log(`${t.generatedStates} states generated, ${t.distinctStates} distinct states found, ${t.queuedStates} states left on queue.`),console.log(`The depth of the complete state graph search is ${t.depth}.`);let n=t.outDegrees&&e.g(t.outDegrees);n&&console.log(n)},si=async(r,a)=>{if(!(0,n.existsSync)(r))return console.error(`Cannot find the specification file ${r}`),e.B.configParseError;let o=a.get(`-config`)?.[0]??(a.has(`-config`)?void 0:r.replace(/\.tla$/,`.cfg`));if(!o||!(0,n.existsSync)(o))return console.error(`Cannot find the configuration file ${o??``}`),e.B.configParseError;let s=e.A((0,n.readFileSync)(o,`utf8`));a.has(`-deadlock`)&&(s.checkDeadlock=!1);let c=a.has(`-seed`)?a.get(`-seed`)?.[0]:`0`;if(c===void 0)return console.error(`Error: seed required.`),1;if(!ti(c))return console.error(`Error: An integer for seed required. But encountered ${c}`),1;let l=a.has(`-lncheck`)?a.get(`-lncheck`)?.[0]?.toLowerCase():`default`;if(l===void 0)return console.error(`Error: expect a strategy such as final for -lncheck option.`),1;let u=(0,i.dirname)(r);console.log(`Checking ${(0,i.basename)(r)} with ${(0,i.basename)(o)}`);let d=await t.t({workers:ni(a.get(`-workers`)),livenessCheck:[`final`,`seqfinal`,`off`].includes(l)?`final`:`default`,seed:BigInt(c),source:(0,n.readFileSync)(r,`utf8`),config:s,onPause:()=>(0,n.readSync)(0,Buffer.alloc(1)),loadModule:e=>{let t=(0,i.join)(u,`${e}.tla`);return(0,n.existsSync)(t)?(0,n.readFileSync)(t,`utf8`):void 0},loadClass:e=>{let t=(0,i.join)(u,`${e}.class`);return(0,n.existsSync)(t)?(0,n.readFileSync)(t):void 0},readFile:e=>(0,n.existsSync)(e)?(0,n.readFileSync)(e,`utf8`):void 0,writeFile:(e,t)=>{(0,n.mkdirSync)((0,i.dirname)((0,i.resolve)(e)),{recursive:!0}),(0,n.writeFileSync)(e,t)}});return oi(d),d.failure?.exitCode??Yr[d.status]},ci=t=>{if(t instanceof e.M||t instanceof e.P)return console.log(`Error: ${t.message}`);console.error(`${t.name}: ${t.message}`)},li=async t=>{try{return await t()}catch(t){if(!(t instanceof e.N))throw t;return ci(t),e.z(t)}},ui=async(t,n)=>{let r=[];for(let[e,i]of t.entries())e>0&&console.log(``),r.push(await li(()=>n(i)));return r.find(t=>t!==e.B.success)??e.B.success},di=()=>(process.env.PATH??``).split(i.delimiter).map(e=>(0,i.join)(e,`tlapm`)).filter(e=>(0,n.existsSync)(e)),fi=()=>di().map(e=>(0,i.join)((0,i.dirname)((0,i.dirname)((0,n.realpathSync)(e))),`lib/tlapm/stdlib`)).find(e=>(0,n.existsSync)(e)),pi=e=>e.flatMap(e=>$r.test(e)?(0,n.globSync)(e).sort():[e]),mi=e=>{let t=di()[0];return t===void 0?(console.error(`Error: tla-ts prove runs tlapm to prove obligations, but tlapm isn't on your PATH. Install tlapm, or pass -N to only generate the obligations.`),1):(0,r.spawnSync)(t,pi(e),{stdio:`inherit`}).status??1},hi=e=>(0,n.existsSync)(e)?{file:e,source:(0,n.readFileSync)(e,`utf8`)}:void 0,gi=e=>console.error(`@!!BEGIN\n${e.map(e=>`@!!${e}\n`).join(``)}@!!END\n`),_i=e=>/^[+,\-./0-9:=@A-Z_a-z]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`,vi=e=>{let t=/* @__PURE__ */ new Date,n=e=>String(e).padStart(2,`0`),r=`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`,i=`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`;console.log(`\n\\* TLAPM version 5f5037f\n\\* launched at ${r} ${i} with command line:\n\\* ${[`tla-ts`,`prove`,...e].map(_i).join(` `)}\n`)},yi={incomplete:11,emptyTarget:12},bi=(e,t,n)=>{let r=e.summary;n||(r.absent.forEach(e=>console.error(`Missing proof at ${l(e)}`)),r.omitted.forEach(e=>console.error(`Omitted proof at ${l(e)}`)));let i=r.absent.length+r.omitted.length>0;i&&console.error(`${u(e.location)}[ERROR]: Proof incomplete in module ${JSON.stringify(e.name)}: ${r.absent.length} missing, ${r.omitted.length} omitted proof step(s).`);let a=t&&e.obligations.length===0;return a&&console.error(`${u(e.location)}[ERROR]: No proof obligation found for the selected target.`),[...i?[yi.incomplete]:[],...a?[yi.emptyTarget]:[]]},xi=t=>{try{return t()}catch(t){if(!(t instanceof e.F))throw t;console.error(` tlapm ending abnormally with ${t.exception}\n`);return}},Si=t=>{if(!t.includes(`-N`)&&!t.includes(`--summary`))return mi(t);let r=Zr.parse(t),a=r.unknown[0];if(a!==void 0)return console.error(`Error: tla-ts prove does not support the tlapm option ${a}.`),1;if(r.incomplete)return console.error(`Error: option '${r.incomplete.name}' needs an argument.`),1;let o=r.options.find(e=>e.name!==`-I`&&e.values.some(e=>!/^-?\d+$/.test(e)));if(o)return console.error(`Error: option '${o.name}' expects an integer.`),1;let s=pi(r.positionals),c=s.map(e=>e.endsWith(`.tla`)?e:`${e}.tla`);if(c.length===0)return console.error(Qr),1;let l=r.has(`--toolbox`)||r.has(`--line`);l&&vi(t);let u=r.options.reduce((e,t)=>{let[n,r]=t.values.map(Number);return t.name===`--toolbox`?{start:n,end:r===0?1/0:r}:t.name===`--line`?n===0?Fr:{start:n,end:n}:e},Fr),d=fi(),f=r.options.flatMap(e=>e.name===`-I`?e.values:[]),p=c.reduce((e,t)=>e.includes((0,i.dirname)(t))?e:[(0,i.dirname)(t),...e],[`.`,...d?[d]:[],...f.toReversed()]),m=xi(()=>{let t=c.findIndex(e=>!(0,n.existsSync)(e));if(t!==-1){let n=s[t];throw console.error(`File "<unknown>":\nError: File ${JSON.stringify(n)} not found`),new e.F(`File ${n} not found`,{failure:`Module.Parser.parse_file`})}return Jr(c.map(e=>({file:`./${e}`,source:(0,n.readFileSync)(e,`utf8`)})),e=>p.map(t=>hi(`${t}/${e}.tla`)).find(Boolean),{lines:u,onWarning:e=>{if(e.channel===`stdout`)return console.log(e.text);let t=e.channel===`toolbox`||e.channel===`toolboxOnly`;if(l&&t)return gi([`type:warning`,`msg:${e.text}`]);e.channel!==`toolboxOnly`&&console.error(e.text)}})});if(!m)return 3;let h=m.flatMap(e=>(r.has(`--summary`)&&console.log(qr(e)),l&&(e.obligations.forEach(e=>gi([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:to be proved`,...r.has(`--printallobs`)?[`obl:${e.text}`]:[]])),gi([`type:obligationsnumber`,`count:${e.obligations.length}`])),r.has(`--strict`)?bi(e,u.start>0||u.end<1/0,r.has(`--summary`)):[]));return h.includes(yi.incomplete)?yi.incomplete:h[0]??e.B.success},Ci=async e=>{if(e[0]===`prove`)return li(()=>Si(e.slice(1)));let t=Xr.parse(e),r=ei(t.positionals),i=t.has(`-config`),a=r.map(e=>({...e,path:e.path.replace(/\.cfg$/,`.tla`)})).filter(e=>e.path.endsWith(`.tla`)&&(!e.isGlobbed||i||(0,n.existsSync)(e.path.replace(/\.tla$/,`.cfg`)))).map(e=>e.path);return a.length===0?(console.error(Qr),1):i&&a.length>1?(console.error(`Error: -config applies to one specification, but several were given.`),1):ui([...new Set(a)],e=>si(e,t))},wi=async()=>{process.exitCode=await Ci(process.argv.slice(2))};exports.runCli=wi;
|
package/dist/run-cli.js
CHANGED
|
@@ -24,5 +24,6 @@ PROVE %a@]`,i)]};return{printSequent:p,printExpr:n}},on=(e,t)=>an(e).printExpr(
|
|
|
24
24
|
`,a-1),c=t.findLast(e=>e.kind!==`End`&&(e.line<o||e.line===o&&e.column<s));return{offset:a,line:o,column:s,end:{reason:ui,line:c?.line??o,column:c?c.endColumn+1:s,isEnd:!0}}},pi=e=>{try{return e()}catch(e){if(!(e instanceof i)||!e.failure)throw e;return e.failure}},mi=e=>typeof e==`object`&&!!e&&`reason`in e,hi=e=>{let t=pi(()=>fi(e));if(mi(t))return[t];let n=pi(()=>g(t?e.slice(0,t.offset):e));return t&&(!mi(n)||n.isEnd)?[{reason:`Unexpected TAB character. TLAPS does not handle TAB characters in source files.`,line:t.line,column:t.column,isEnd:!1},mi(n)&&n.reason===ui?n:t.end]:mi(n)?[n]:n},gi=(e,t,n,i,a)=>{if(!li.test(e.source))throw new r(`No tokens in file`);let o=hi(e.source);if(Array.isArray(o)){o.forEach(t=>{let n=`File ${JSON.stringify(e.file)}, line ${t.line}, character ${t.column}\n${t.reason}`;i({text:n,channel:`stderr`}),i({text:`${n}\n`,channel:`toolboxOnly`})});let t=`Could not parse ${JSON.stringify(e.file)} successfully.`;throw i({text:`${a}Error: ${t}`,channel:`stderr`}),new r(t,{failure:`Module.Parser.parse_file`})}let s=si(e.file,e.source,t,n).convertModule(o),c=e.file.slice(e.file.lastIndexOf(`/`)+1),l=c.replace(/\.tla$/,``);return s.name===l?s:(i({text:`${de(s.location)}Warning: module name ${JSON.stringify(s.name)} does not match file name ${JSON.stringify(c)}.`,channel:`toolbox`}),{...s,name:l})},_i=e=>{let t=new Map([...e].map(([e,t])=>[e,hr(t).dependencies])),n=/* @__PURE__ */ new Set,i=[],a=o=>{if(n.has(o))return;n.add(o);let s=e.get(o);if(!s)throw new r(`Module "${o}" not found`);(t.get(o)??[]).forEach(a),i.push(s)};return[...e.keys()].sort(_r).forEach(a),i},vi=(e,t,n)=>t.length===0?[]:[` ${e}_proofs_count = ${t.length}`,...t.map((t,r)=>` ${e}_proof_${n+r+1} at ${ce(t)}`)],yi=(e,t,n)=>{let r=e.location;return[` ---- incomplete proof of theorem at ${r?ce({...r,endLine:r.startLine,endColumn:r.startColumn}):`<unknown location>`} ----`,...vi(`missing`,e.absent,t),...vi(`omitted`,e.omitted,n),` ====`]},bi=e=>{let t=e.summary,n=t.theorems.reduce((e,t)=>t.absent.length+t.omitted.length===0?e:{lines:[...e.lines,...yi(t,e.missing,e.omitted)],missing:e.missing+t.absent.length,omitted:e.omitted+t.omitted.length},{lines:[],missing:0,omitted:0});return[`---- summary of module ${JSON.stringify(e.name)} ----`,` obligations_count = ${t.total}`,...t.absent.length>0?[` missing_proofs_count = ${t.absent.length}`]:[],...t.omitted.length>0?[` omitted_proofs_count = ${t.omitted.length}`]:[],...n.lines,`====`].join(`
|
|
25
25
|
`)},xi=(e,t,n={})=>{let i=n.lines??ci,a=n.onWarning??(()=>{}),o={value:0},s=new Map(lr);e.forEach(e=>{let t={...gi(e,o,!0,a,`File "<unknown>":
|
|
26
26
|
`),isImportant:!0};s.set(t.name,t)});let c=[...s.values()].sort((e,t)=>_r(e.name,t.name)),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Set;for(let e=0;e<c.length;e++){let n=hr(c[e]);n.submodules.forEach((e,t)=>{u.add(t),s.has(t)||s.set(t,e)});for(let e of n.dependencies){if(s.has(e)&&!lr.has(e))continue;let r=t(e);if(!r){!s.has(e)&&!l.has(e)&&l.set(e,n.locations.get(e));continue}let i=gi(r,o,!1,a,ue(n.locations.get(e)));s.set(e,i),c.push(i)}}let d=[...l.keys()].filter(e=>!u.has(e)).sort(_r);if(d.forEach(e=>a(D(l.get(e),`Unknown module ${JSON.stringify(e)}`))),d.length>0)throw new r(`Unknown module ${JSON.stringify(d[0])}`,{failure:`Module.Parser.load_module`});let f={anonymizer:dt(o,(e,t)=>Mr(f,e,t),a),generator:jn(o,new Set(e.map(e=>e.file)),i,a),salts:{value:0},latestModules:/* @__PURE__ */ new Map,onWarning:a},p=_i(s).map(e=>e.isStandard?e:mr(s,e,/* @__PURE__ */ new Set)),m=new Map(p.map(e=>[e.name,e]));return p.flatMap(e=>{if(e.isStandard)return[];let t=Nr(f,m,void 0,e);if(!e.isImportant)return[];let n=Pr(f,[],t),r=n.obligations.flatMap((e,t)=>{let n=e.location;if(e.kind.kind===`Omitted`||n&&(n.startLine<i.start||n.endLine>i.end))return[];let r=e.kind.kind===`Error`?e.kind.message:`${sn(e.sequent)}\n`;return[{id:t+1,location:di(n),text:r}]});return[{name:e.name,location:e.location,obligations:r,summary:n.summary}]})},Si={success:t.success,"assumption-violation":t.assumptionViolation,deadlock:t.deadlock,"invariant-violation":t.safetyViolation,"property-violation":t.safetyViolation,"liveness-violation":t.livenessViolation,"postcondition-violation":t.assumptionViolation,error:t.error},Ci=se(`tla-ts <Spec.tla|Spec.cfg|glob>... {options}`,[{flag:`-config <Spec.cfg>`},{flag:`-deadlock`},{flag:`-lncheck <final|default>`},{flag:`-seed <num>`},{flag:`-workers <count|auto>`}]),wi=se(`tla-ts prove {options} <Module.tla|glob>...`,[{flag:`-N`,isRequired:!0},{flag:`--toolbox <start> <end>`},{flag:`--line <num>`},{flag:`--printallobs`},{flag:`--summary`},{flag:`--strict`},{flag:`-I <directory>`,isRepeatable:!0}]),Ti=[`Usage: ${Ci.usage}`,` ${wi.usage}`,` tla-ts prove [<tlapm option>]... <Module.tla|glob>...`].join(`
|
|
27
|
-
`),Ei=/[*?[{]/,Di=e=>e.flatMap(e=>Ei.test(e)?ee(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),Oi=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ki=e=>e?e[0]===`auto`?ae():Math.max(1,Number.parseInt(e[0],10)||1):1,Ai=e=>{let t=Object.entries(e);t.forEach(([e,r])=>console.log(`${t.length===1?``:`/\\ `}${e} = ${m(n(r))}`)),console.log(``)},ji=(e,t=`Error: The behavior up to this point is:`)=>{e.length>0&&console.log(t),e.forEach((e,t)=>{console.log(`State ${t+1}: <${e.label??e.action??`Initial predicate`}>`),Ai(e.state)})},Mi=e=>{if(e.failure)console.log(`Error: ${e.failure.message}`),e.failure.initialState&&(console.log(`While working on the initial state:`),Ai(e.failure.initialState)),ji(e.failure.trace);else if(e.violation){let t=e.violation,n=t.name,r=t.loopStart,i=r===void 0&&t.trace.length===1&&(e.status===`invariant-violation`||e.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":t.message?`Error: Evaluating assumption ${n} failed.\n${t.message}`:`Error: Assumption ${n} is false.`,deadlock:`Error: Deadlock reached.`,"invariant-violation":i?`Error: Invariant ${n} is violated by the initial state:`:`Error: Invariant ${n} is violated.`,"property-violation"
|
|
28
|
-
`);
|
|
27
|
+
`),Ei=/[*?[{]/,Di=e=>e.flatMap(e=>Ei.test(e)?ee(e).sort().map(e=>({path:e,isGlobbed:!0})):[{path:e,isGlobbed:!1}]),Oi=e=>/^[+-]?\d+$/.test(e)&&BigInt.asIntN(64,BigInt(e))===BigInt(e),ki=e=>e?e[0]===`auto`?ae():Math.max(1,Number.parseInt(e[0],10)||1):1,Ai=e=>{let t=Object.entries(e);t.forEach(([e,r])=>console.log(`${t.length===1?``:`/\\ `}${e} = ${m(n(r))}`)),console.log(``)},ji=(e,t=`Error: The behavior up to this point is:`)=>{e.length>0&&console.log(t),e.forEach((e,t)=>{console.log(`State ${t+1}: <${e.label??e.action??`Initial predicate`}>`),Ai(e.state)})},Mi=e=>e.length===1?`Error: Temporal property ${e[0]} was violated.\n`:`Error: Temporal properties ${e.slice(0,-1).join(`, `)}${e.length>2?`,`:``} and ${e[e.length-1]} were violated.\n`,Ni=e=>{if(e.failure)console.log(`Error: ${e.failure.message}`),e.failure.initialState&&(console.log(`While working on the initial state:`),Ai(e.failure.initialState)),ji(e.failure.trace);else if(e.violation){let t=e.violation,n=t.name,r=t.loopStart,i=r===void 0&&t.trace.length===1&&(e.status===`invariant-violation`||e.status===`liveness-violation`),a={success:``,error:``,"assumption-violation":t.message?`Error: Evaluating assumption ${n} failed.\n${t.message}`:`Error: Assumption ${n} is false.`,deadlock:`Error: Deadlock reached.`,"invariant-violation":i?`Error: Invariant ${n} is violated by the initial state:`:`Error: Invariant ${n} is violated.`,"property-violation":Mi(t.properties??[n]),"liveness-violation":r===void 0?i?`Error: Property ${n} is violated by the initial state:`:`Error: Action property ${n} is violated.`:Mi(t.properties??[n]),"postcondition-violation":`Error: ${t.message??`Postcondition ${n} is false.`}`}[e.status];if(t.counts&&console.log(t.counts),console.log(a),i)Ai(t.trace[0].state);else if(e.status===`property-violation`)ji(t.trace,`Error: The following behavior constitutes a counter-example:
|
|
28
|
+
`);else if(r===void 0)ji(t.trace);else{ji(t.trace,`Error: The following behavior constitutes a counter-example:
|
|
29
|
+
`);let e=r===t.trace.length-1;console.log(e?`State ${r+2}: Stuttering`:`Back to state ${r+1}${t.loopLabel?`: <${t.loopLabel}>\n`:``}`)}let o=t.unwitnessed;if(o?.counts&&console.log(o.counts),o&&console.log(`Error: ${o.message}`),i||e.status===`assumption-violation`)return}else{let t=f(e.distinctStates,e.generatedStates);if(console.log(`Model checking completed. No error has been found.`),console.log(` Estimates of the probability that TLC did not check all reachable states`),console.log(` because two distinct states had the same fingerprint:`),console.log(` calculated (optimistic): val = ${u(t)}`),e.fingerprintDistance!==void 0){let t=h(e.fingerprintDistance);console.log(` based on the actual fingerprints: val = ${u(t)}`)}}console.log(`${e.generatedStates} states generated, ${e.distinctStates} distinct states found, ${e.queuedStates} states left on queue.`),console.log(`The depth of the complete state graph search is ${e.depth}.`);let t=e.outDegrees&&d(e.outDegrees);t&&console.log(t)},Pi=async(n,r)=>{if(!y(n))return console.error(`Cannot find the specification file ${n}`),t.configParseError;let i=r.get(`-config`)?.[0]??(r.has(`-config`)?void 0:n.replace(/\.tla$/,`.cfg`));if(!i||!y(i))return console.error(`Cannot find the configuration file ${i??``}`),t.configParseError;let a=e(x(i,`utf8`));r.has(`-deadlock`)&&(a.checkDeadlock=!1);let o=r.has(`-seed`)?r.get(`-seed`)?.[0]:`0`;if(o===void 0)return console.error(`Error: seed required.`),1;if(!Oi(o))return console.error(`Error: An integer for seed required. But encountered ${o}`),1;let s=r.has(`-lncheck`)?r.get(`-lncheck`)?.[0]?.toLowerCase():`default`;if(s===void 0)return console.error(`Error: expect a strategy such as final for -lncheck option.`),1;let c=E(n);console.log(`Checking ${w(n)} with ${w(i)}`);let l=await v({workers:ki(r.get(`-workers`)),livenessCheck:[`final`,`seqfinal`,`off`].includes(s)?`final`:`default`,seed:BigInt(o),source:x(n,`utf8`),config:a,onPause:()=>S(0,Buffer.alloc(1)),loadModule:e=>{let t=re(c,`${e}.tla`);return y(t)?x(t,`utf8`):void 0},loadClass:e=>{let t=re(c,`${e}.class`);return y(t)?x(t):void 0},readFile:e=>y(e)?x(e,`utf8`):void 0,writeFile:(e,t)=>{b(E(ie(e)),{recursive:!0}),te(e,t)}});return Ni(l),l.failure?.exitCode??Si[l.status]},Fi=e=>{if(e instanceof o||e instanceof c)return console.log(`Error: ${e.message}`);console.error(`${e.name}: ${e.message}`)},Ii=async e=>{try{return await e()}catch(e){if(!(e instanceof s))throw e;return Fi(e),_(e)}},Li=async(e,n)=>{let r=[];for(let[t,i]of e.entries())t>0&&console.log(``),r.push(await Ii(()=>n(i)));return r.find(e=>e!==t.success)??t.success},Ri=()=>(process.env.PATH??``).split(T).map(e=>re(e,`tlapm`)).filter(e=>y(e)),zi=()=>Ri().map(e=>re(E(E(C(e))),`lib/tlapm/stdlib`)).find(e=>y(e)),Bi=e=>e.flatMap(e=>Ei.test(e)?ee(e).sort():[e]),Vi=e=>{let t=Ri()[0];return t===void 0?(console.error(`Error: tla-ts prove runs tlapm to prove obligations, but tlapm isn't on your PATH. Install tlapm, or pass -N to only generate the obligations.`),1):ne(t,Bi(e),{stdio:`inherit`}).status??1},Hi=e=>y(e)?{file:e,source:x(e,`utf8`)}:void 0,Ui=e=>console.error(`@!!BEGIN\n${e.map(e=>`@!!${e}\n`).join(``)}@!!END\n`),Wi=e=>/^[+,\-./0-9:=@A-Z_a-z]+$/.test(e)?e:`'${e.replaceAll(`'`,`'\\''`)}'`,Gi=e=>{let t=/* @__PURE__ */ new Date,n=e=>String(e).padStart(2,`0`),r=`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`,i=`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`;console.log(`\n\\* TLAPM version 5f5037f\n\\* launched at ${r} ${i} with command line:\n\\* ${[`tla-ts`,`prove`,...e].map(Wi).join(` `)}\n`)},Ki={incomplete:11,emptyTarget:12},qi=(e,t,n)=>{let r=e.summary;n||(r.absent.forEach(e=>console.error(`Missing proof at ${le(e)}`)),r.omitted.forEach(e=>console.error(`Omitted proof at ${le(e)}`)));let i=r.absent.length+r.omitted.length>0;i&&console.error(`${ue(e.location)}[ERROR]: Proof incomplete in module ${JSON.stringify(e.name)}: ${r.absent.length} missing, ${r.omitted.length} omitted proof step(s).`);let a=t&&e.obligations.length===0;return a&&console.error(`${ue(e.location)}[ERROR]: No proof obligation found for the selected target.`),[...i?[Ki.incomplete]:[],...a?[Ki.emptyTarget]:[]]},Ji=e=>{try{return e()}catch(e){if(!(e instanceof r))throw e;console.error(` tlapm ending abnormally with ${e.exception}\n`);return}},Yi=e=>{if(!e.includes(`-N`)&&!e.includes(`--summary`))return Vi(e);let n=wi.parse(e),i=n.unknown[0];if(i!==void 0)return console.error(`Error: tla-ts prove does not support the tlapm option ${i}.`),1;if(n.incomplete)return console.error(`Error: option '${n.incomplete.name}' needs an argument.`),1;let a=n.options.find(e=>e.name!==`-I`&&e.values.some(e=>!/^-?\d+$/.test(e)));if(a)return console.error(`Error: option '${a.name}' expects an integer.`),1;let o=Bi(n.positionals),s=o.map(e=>e.endsWith(`.tla`)?e:`${e}.tla`);if(s.length===0)return console.error(Ti),1;let c=n.has(`--toolbox`)||n.has(`--line`);c&&Gi(e);let l=n.options.reduce((e,t)=>{let[n,r]=t.values.map(Number);return t.name===`--toolbox`?{start:n,end:r===0?1/0:r}:t.name===`--line`?n===0?ci:{start:n,end:n}:e},ci),u=zi(),d=n.options.flatMap(e=>e.name===`-I`?e.values:[]),f=s.reduce((e,t)=>e.includes(E(t))?e:[E(t),...e],[`.`,...u?[u]:[],...d.toReversed()]),p=Ji(()=>{let e=s.findIndex(e=>!y(e));if(e!==-1){let t=o[e];throw console.error(`File "<unknown>":\nError: File ${JSON.stringify(t)} not found`),new r(`File ${t} not found`,{failure:`Module.Parser.parse_file`})}return xi(s.map(e=>({file:`./${e}`,source:x(e,`utf8`)})),e=>f.map(t=>Hi(`${t}/${e}.tla`)).find(Boolean),{lines:l,onWarning:e=>{if(e.channel===`stdout`)return console.log(e.text);let t=e.channel===`toolbox`||e.channel===`toolboxOnly`;if(c&&t)return Ui([`type:warning`,`msg:${e.text}`]);e.channel!==`toolboxOnly`&&console.error(e.text)}})});if(!p)return 3;let m=p.flatMap(e=>(n.has(`--summary`)&&console.log(bi(e)),c&&(e.obligations.forEach(e=>Ui([`type:obligation`,`id:${e.id}`,`loc:${e.location}`,`status:to be proved`,...n.has(`--printallobs`)?[`obl:${e.text}`]:[]])),Ui([`type:obligationsnumber`,`count:${e.obligations.length}`])),n.has(`--strict`)?qi(e,l.start>0||l.end<1/0,n.has(`--summary`)):[]));return m.includes(Ki.incomplete)?Ki.incomplete:m[0]??t.success},Xi=async e=>{if(e[0]===`prove`)return Ii(()=>Yi(e.slice(1)));let t=Ci.parse(e),n=Di(t.positionals),r=t.has(`-config`),i=n.map(e=>({...e,path:e.path.replace(/\.cfg$/,`.tla`)})).filter(e=>e.path.endsWith(`.tla`)&&(!e.isGlobbed||r||y(e.path.replace(/\.tla$/,`.cfg`)))).map(e=>e.path);return i.length===0?(console.error(Ti),1):r&&i.length>1?(console.error(`Error: -config applies to one specification, but several were given.`),1):Li([...new Set(i)],e=>Pi(e,t))},Zi=async()=>{process.exitCode=await Xi(process.argv.slice(2))};export{Zi as runCli};
|